npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ncp-client

v1.2.0

Published

Naver Cloud Platform Applications' OpenAPI Wrapper built in TS

Downloads

136

Readme

NCP-Client

npm version travisici install size npm downloads

An easy-to-use typescript wrapper for Naver Cloud Platform API. With VersionUps, API wrappers will be added and updates.

Notice ) Always welcome contributions for user's Productivity

Table of Contents

Dependency

  • axios

Installation

with npm

$ npm install ncp-client

Usage

Import API Wrapper

var { SENS, PAPAGO } = require('ncp-client')

[ SENS ] SMS API

  • Common
// type your NCP API Authentication key pair
const ncpAuthKey = {
    accessKey: 'accessKey',
    secretKey: 'secretKey',
}
// type your SMS service key pair
const smsAuthKey = {
    phone: 'phoneNumber',
    serviceId: 'serviceId'
}
// create SENS api container and get smsService agent.
const sens = new SENS()
const smsService = sens.smsService(ncpAuthKey, smsAuthKey)
  • SMS Send

    // type your SMS send parameter 
    const sendSMSparam = {
        to: 'recipient phoneNumber',
        content: 'message to send'
    }
    // to send to multiple people 
    const multipleSMSparam = [
      { to: 'r1', content: 'c1'},
      { to: 'r2', content: 'c2'},
      { to: 'r3', content: 'c3'}
    ]
      
    async function sendMessage() {
      	// if you don't pass countryCode, default countryCode is 82.
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.sendSMS( sendSMSparam, countryCode )
        // write something after async function
        if (isSuccess) {
          	const { result, requestId } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Search message delivery request

    async function searchMessageDeliveryRequest(requestId: string) {
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.searchMessageRequest(requestId)
        // write something after async function
        if (isSuccess) {
          	// messageIds: string[]
          	const { result, requestId, messageIds } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Search message delivery results

    async function searchMessageDeliveryResults(messageId: string) {
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.searchMessageResult(messageId)
        // write something after async function
        if (isSuccess) {
          	// messages: MessageResultType[]
          	const { result, messages } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }

[ NaverOpenAPI ] Papago NMT API

  • Common
// type your NaverOpenAPI Client key pair
let openApiClientAuth = {
    clientId: 'clientId',
    clientSecret: 'clientSecret'
}
// create NaverOpenAPI api container and get papagoService agent.
const naverOpenAPI = new NaverOpenAPI()
const papagoClient = naverOpenAPI.papagoService(openApiClientAuth)
  • Translation

    async function translation(source: string, target: string, text: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.translation(src, target, text)
        // write something after async function
        if (isSuccess) {
          	const { source, target, translated } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Language Detection

    async function detectLanguage(text: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.detectLanguage(text)
        // write something after async function
        if (isSuccess) {
          	const { detected } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Korean Name Romanizer

    async function koreanNameRomanizer(koreanName: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.koreanNameRominizer(name)
      	// write something after async function
        if (isSuccess) {
          	const { firstName, bestMatched } = preprocessed
          	// do something with data
        } else {
            // handle with errorMessage
        }
    }

Types

Note) Introduced types are what you have to create or handle in use NCP-Client

Based on Typescript's type alias, several types for api are declared. At this step, you can only show what you will use at each usage.

Common & Authentification

// NCP api authentication key pair
type NCPAuthKeyType = {
  accessKey: string
  secretKey: string
}

// Naver Open API client key pair
export type NaverOpenApiAuthType = {
  clientId: string
  clientSecret: string
}

// Common return value for all NCP api request
type ApiClientResponse<T> = {
  isSuccess: boolean
  // If success, handle with it
  data?: T
  // If failed, handle with it
  errorMessage?: {}
}

( SENS ) SMS

  • Send SMS

    type SendSMSParamType = {
      // `to` is recipient's phone number
      to:	string
      // `content` is text content what you want to send
      content:	string
    }
      
    type SendSMSReturnType = {
      // `statusCode` and `statusText` are the HTTP status code / message from the server response
      statusCode: string
      statusText: string
      // `requestId` represents current succesful request's key, `requestTime` represents Datetime string
      requestId:	string
      requestTime: string
    }
  • Search message delivery request

    export type SearchMessageRequestReturnType = {
      requestId: string
      statusCode: string
      statusName: string
      // `messages` contains messages associated with requestId
      messages: MessageRequestType[]
    }
    // Each message's summary
    type MessageRequestType = {
      messageId: string
      requestTime: string
      contentType: string
      countryCode: string
      from: string
      to: string
    }
  • Search message delivery results

    export type SearchMessageResultReturnType = {
      statusCode: string
      statusName: string
      // `messages` contains messages associated with messageId
      messages: MessageResultType[]
    }
    // Each message's detail
    type MessageResultType = {
      requestTime: string
      // `contentType` will be 'COMM' | 'AD', but currently not supported with AD message api
      contentType: string
      content: string
      countryCode: string
      from: string
      to: string
      status: string
      statusCode: string
      statusMessage: string
      statusName: string
      // `completeTime` means the time when request completed
      completeTime: string
      // `telcoCode` means telecommunication Provider Info
      telcoCode: string
    }

( NaverOpenAPI ) Papago NMT

  • Translation

    export type PapagoTranslationReturnType = {
      message: PapagoTranslationMessageType
    }
    type PapagoTranslationMessageType = {
      // current Papago NMT responses
      '@type': string,
      '@service': string,
      '@version': string,
      result: PapagoTranslationResultType
    }
    // translation Report
    type PapagoTranslationResultType = {
      srcLangType: string
      tarLangType: string
      translatedText: string
    }
  • Language Detection

    export type PapagoDetectLanguageReturnType = {
      // detected language code from api
      langCode: string
    }
  • Korean Name Romanizer

    export type PapagoKoreanNameRomanizerReturnType = {
      aResult : PapagoKoreanNameRomanizerResultType[]
    }
    type PapagoKoreanNameRomanizerResultType = {
      // detected firstName
      sFirstName: string
      // array of romanized names
      aItems: PapagoKoreanNameRomanizerItemType[]
    }
    type PapagoKoreanNameRomanizerItemType = {
      // romanized korean name
      name: string
      // frequency integer values
      score: string
    }

API Response statuses

API Response status provided by Naver Cloud Platform

| HTTP Status | Desc | | :---------: | :-----------------------------: | | 202 | Accept (Successfully requested) | | 400 | Bad Request | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | | 429 | Too Many Requests | | 500 | Internal Server Error |

Current Support

(SENS) SMS API v2

  • Send SMS
  • Search message delivery request
  • Search message delivery results

(NaverOpenAPI) Papago NMT API v1

  • Translation
  • Language Detection
  • Korean Name Romanizer

Credits

License

MIT License