diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a37872..e4a293f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,38 @@ ## Changes -## v1.0.5 ( 2021. 4. 19 ) +## v1.0.5 ( 2021. 4. 20 ) -#### [ SENS - SMS service ] SendSMS support Reservation +#### NCPClient will support service's unique error types -- If you want to use SMS Reservation, just pass the **nullable Reservation parameter** +- NCPClient's request module, `ApiRequest` can handle service's unique errors now + > **service's unique error** means almost parameter validation. + > + > If given parameter is incorrect with NCP-defined format, It will return **ApiClientResponse with error** and request won't send. + +#### [ SENS - SMS service ] SearchMessageRequest / SearchMessageResult now supported + +- Using **SendSMS API** , you can get `requestId` of request from response + +- **SearchMessageRequest** with requestId from **SendSMS API's response** will return the detail delivery request + + ~~~typescript + const { isSuccess, data } = await smsService.searchMessageRequest('requestId') ~~~ - + +- **SearchMessageResponse** with messageId from **SearchMessageRequest API's response** will return the detail delivery results + + ~~~typescript + const { isSuccess, data } = await smsService.searchMessageResult('messageId') ~~~ - +#### Dependency changed + +- **crypto** changed to built-in module, so deprecated in dependency -## v 1.0.4 ( 2021. 4. 18 ) +## v1.0.4 ( 2021. 4. 18 ) #### ApiRequest clarity guaranteed diff --git a/README.md b/README.md index 609d77c..ceacf73 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ An easy-to-use typescript wrapper for [Naver Cloud Platform API](https://api.ncl ## Dependency - axios -- crypto @@ -66,33 +65,60 @@ const smsService = sens.smsService(ncpAuthKey, smsAuthKey) - **SMS Send** -~~~javascript -// 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, errorMessage } = await smsService.sendSMS( sendSMSparam, countryCode ) - // write something after async function - if (isSuccess) { - // do something with data - } else { - // handle with errorMessage - } -} - -~~~ - - + ~~~javascript + // 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, errorMessage } = await smsService.sendSMS( sendSMSparam, countryCode ) + // write something after async function + if (isSuccess) { + // do something with data + } else { + // handle with errorMessage + } + } + ~~~ + +- **Search message delivery request** + + ~~~javascript + async function searchMessageDeliveryRequest() { + const {isSuccess, data, errorMessage } = await smsService.searchMessageRequest('requestId') + // write something after async function + if (isSuccess) { + // do something with data + } else { + // handle with errorMessage + } + } + ~~~ + +- **Search message delivery results** + + ~~~javascript + async function searchMessageDeliveryResults() { + const {isSuccess, data, errorMessage } = await smsService.searchMessageResult('messageId') + // write something after async function + if (isSuccess) { + // do something with data + } else { + // handle with errorMessage + } + } + ~~~ + + ## Types @@ -140,7 +166,57 @@ type SendSMSReturnType = { } ~~~ - +**Search message delivery request** + +~~~typescript +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** + +~~~typescript +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 +} +~~~ + + ## API Response statuses @@ -162,7 +238,9 @@ API Response status provided by Naver Cloud Platform #### (SENS) SMS API v2 -- **SMS Send** +- **Send SMS** +- **Search message delivery request** +- **Search message delivery results** diff --git a/src/__test__/sms/searchsmsrequest.test.ts b/src/__test__/sms/searchsmsrequest.test.ts index 49bf9eb..47de27b 100644 --- a/src/__test__/sms/searchsmsrequest.test.ts +++ b/src/__test__/sms/searchsmsrequest.test.ts @@ -1,7 +1,6 @@ const axios = require('axios') import { MockSMS } from '../mock/mock_smsClient'; -import { SendSMSParamType } from '../../types/param_types'; -import { SearchMessageRequestReturnType, SearchMessageResultReturnType, SendSMSReturnType } from '../../types/return_types'; +import { SearchMessageRequestReturnType } from '../../types/return_types'; import { NCPAuthKeyType, SMSserviceAuthType } from '../../types/auth_types'; jest.mock('axios') diff --git a/src/__test__/sms/searchsmsresult.test.ts b/src/__test__/sms/searchsmsresult.test.ts index 1fb6aa0..eb95cce 100644 --- a/src/__test__/sms/searchsmsresult.test.ts +++ b/src/__test__/sms/searchsmsresult.test.ts @@ -1,7 +1,6 @@ const axios = require('axios') import { MockSMS } from '../mock/mock_smsClient'; -import { SendSMSParamType } from '../../types/param_types'; -import { SearchMessageRequestReturnType, SearchMessageResultReturnType, SendSMSReturnType } from '../../types/return_types'; +import { SearchMessageResultReturnType } from '../../types/return_types'; import { NCPAuthKeyType, SMSserviceAuthType } from '../../types/auth_types'; jest.mock('axios') diff --git a/src/__test__/sms/smsclient.test.ts b/src/__test__/sms/sendsms.test.ts similarity index 97% rename from src/__test__/sms/smsclient.test.ts rename to src/__test__/sms/sendsms.test.ts index c3c253f..38b7f5f 100644 --- a/src/__test__/sms/smsclient.test.ts +++ b/src/__test__/sms/sendsms.test.ts @@ -1,7 +1,7 @@ const axios = require('axios') import { MockSMS } from '../mock/mock_smsClient'; import { SendSMSParamType } from '../../types/param_types'; -import { SearchMessageRequestReturnType, SearchMessageResultReturnType, SendSMSReturnType } from '../../types/return_types'; +import { SendSMSReturnType } from '../../types/return_types'; import { NCPAuthKeyType, SMSserviceAuthType } from '../../types/auth_types'; jest.mock('axios') diff --git a/src/clients/sens/sms.ts b/src/clients/sens/sms.ts index 4b2f763..5ccb383 100644 --- a/src/clients/sens/sms.ts +++ b/src/clients/sens/sms.ts @@ -125,11 +125,11 @@ export class SMS { /** * Construct searchMessageResult Service apiRequest. Generate signature for signing, pass requestId for search. - * return the requestData for given messageId. It also returns messages info refer to the request. - * It's response data is more detail than searchMessageRequest with completeTime, statuses, telcoCode, etc. + * return the requestData for given messageId. It also returns messages info refer to the message. + * It's response data is more detail than searchMessageResult with completeTime, statuses, telcoCode, etc. * @async * @access public - * @param {string} messageId - messageId which get from response of sendSMS API + * @param {string} messageId - messageId which get from response of searchMessageRequest API * @returns {Promise>} return Promise response of http request with current ApiRequest configs and handle errors * @memberof SMS */ diff --git a/src/types/return_types.ts b/src/types/return_types.ts index 68d0eea..cde7544 100644 --- a/src/types/return_types.ts +++ b/src/types/return_types.ts @@ -87,6 +87,4 @@ type MessageResultType = { completeTime: string // ISP telcoCode: string - // MMS only - files?: { name: string }[] } \ No newline at end of file