@ingestkorea/client-sens 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.github/pull_request_template.md +14 -0
  2. package/README.md +12 -3
  3. package/dist-cjs/commands/GetSMSResultCommand.js +43 -0
  4. package/dist-cjs/commands/GetSMSStatusCommand.js +43 -0
  5. package/dist-cjs/commands/SendSMSCommand.js +29 -14
  6. package/dist-cjs/commands/index.js +2 -0
  7. package/dist-cjs/models/GetSMSResult.js +6 -0
  8. package/dist-cjs/models/GetSMSStatus.js +5 -0
  9. package/dist-cjs/models/index.js +2 -0
  10. package/dist-cjs/protocols/GetSMSResult.js +77 -0
  11. package/dist-cjs/protocols/GetSMSStatus.js +66 -0
  12. package/dist-cjs/protocols/index.js +2 -0
  13. package/dist-es/commands/GetSMSResultCommand.js +28 -0
  14. package/dist-es/commands/GetSMSStatusCommand.js +28 -0
  15. package/dist-es/commands/SendSMSCommand.js +35 -20
  16. package/dist-es/commands/index.js +2 -0
  17. package/dist-es/models/GetSMSResult.js +5 -0
  18. package/dist-es/models/GetSMSStatus.js +4 -0
  19. package/dist-es/models/index.js +2 -0
  20. package/dist-es/protocols/GetSMSResult.js +62 -0
  21. package/dist-es/protocols/GetSMSStatus.js +52 -0
  22. package/dist-es/protocols/index.js +2 -0
  23. package/dist-types/commands/GetSMSResultCommand.d.ts +13 -0
  24. package/dist-types/commands/GetSMSStatusCommand.d.ts +13 -0
  25. package/dist-types/commands/index.d.ts +2 -0
  26. package/dist-types/models/GetSMSResult.d.ts +26 -0
  27. package/dist-types/models/GetSMSStatus.d.ts +17 -0
  28. package/dist-types/models/index.d.ts +2 -0
  29. package/dist-types/protocols/GetSMSResult.d.ts +9 -0
  30. package/dist-types/protocols/GetSMSStatus.d.ts +8 -0
  31. package/dist-types/protocols/index.d.ts +2 -0
  32. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ ### Issue
2
+ Issue number, if available, prefixed with "#"
3
+
4
+ ### Description
5
+ What does this implement/fix? Explain your changes.
6
+
7
+ ### Testing
8
+ How was this change tested?
9
+
10
+ ### Additional context
11
+ Add any other context about the PR here.
12
+
13
+ ---
14
+ By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
package/README.md CHANGED
@@ -22,13 +22,19 @@ npm install @ingestkorea/client-sens
22
22
  ```
23
23
 
24
24
  ### Support Commands
25
+
26
+ #### Kakao Alimtalk
25
27
  + SendAlimtalk
26
28
  + GetAlimtalkStatus (`GetRequestStatus` is deprecated)
27
29
  + GetAlimtalkResult (`GetRequestResult` is deprecated)
28
30
  + GetAlimtalkTemplate (`GetTemplate` is deprecated)
29
31
  + ListAlimtalkTemplates (`ListTemplates` is deprecated)
30
32
  + ListAlimtalkChannels (`ListChannels` is deprecated)
33
+
34
+ #### SMS(LMS)
31
35
  + SendSMS
36
+ + GetSMSStatus
37
+ + GetSMSResult
32
38
 
33
39
  ### Import
34
40
  ```ts
@@ -77,14 +83,17 @@ let command = new SendAlimtalkCommand(params);
77
83
  ```ts
78
84
  /**
79
85
  * Automatically set message type('SMS' | 'LMS') according to content-length(euc-kr)
80
- * SMS: max 80bytes
86
+ * SMS: max 90bytes
81
87
  * LMS: max 2000bytes
82
88
  */
83
89
  let params: SendSMSCommandInput = {
84
90
  from: '01012345678',
85
- content: CONTENT,
91
+ content: DEFAULT_CONTENT,
86
92
  messages: [
87
- { to: '01087654321' }
93
+ {
94
+ to: '01087654321',
95
+ content: OPTIONAL_CONTENT // optional // this OPTIONAL_CONTENT override above DEFAULT_CONTENT
96
+ }
88
97
  ]
89
98
  };
90
99
  let command = new SendSMSCommand(params);
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GetSMSResultCommand = void 0;
13
+ const models_1 = require("../models");
14
+ const GetSMSResult_1 = require("../protocols/GetSMSResult");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
+ ;
17
+ ;
18
+ class GetSMSResultCommand extends models_1.SensCommand {
19
+ constructor(input) {
20
+ super(input);
21
+ this.input = Object.assign({}, input);
22
+ }
23
+ ;
24
+ serialize(input, config) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.sms)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
29
+ });
30
+ let request = yield (0, GetSMSResult_1.serializeIngestkorea_restJson_GetSMSResultCommand)(input, config);
31
+ return request;
32
+ });
33
+ }
34
+ ;
35
+ deserialize(response) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ let output = yield (0, GetSMSResult_1.deserializeIngestkorea_restJson_GetSMSResultCommand)(response);
38
+ return output;
39
+ });
40
+ }
41
+ ;
42
+ }
43
+ exports.GetSMSResultCommand = GetSMSResultCommand;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GetSMSStatusCommand = void 0;
13
+ const models_1 = require("../models");
14
+ const GetSMSStatus_1 = require("../protocols/GetSMSStatus");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
+ ;
17
+ ;
18
+ class GetSMSStatusCommand extends models_1.SensCommand {
19
+ constructor(input) {
20
+ super(input);
21
+ this.input = Object.assign({}, input);
22
+ }
23
+ ;
24
+ serialize(input, config) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.sms)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
29
+ });
30
+ let request = yield (0, GetSMSStatus_1.serializeIngestkorea_restJson_GetSMSStatusCommand)(input, config);
31
+ return request;
32
+ });
33
+ }
34
+ ;
35
+ deserialize(response) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ let output = yield (0, GetSMSStatus_1.deserializeIngestkorea_restJson_GetSMSStatusCommand)(response);
38
+ return output;
39
+ });
40
+ }
41
+ ;
42
+ }
43
+ exports.GetSMSStatusCommand = GetSMSStatusCommand;
@@ -18,11 +18,10 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
18
18
  class SendSMSCommand extends models_1.SensCommand {
19
19
  constructor(input) {
20
20
  super(input);
21
- const content = textTrimming(input.content);
22
- const messageType = messageTypeChecker(content);
23
- this.input = Object.assign(Object.assign({}, input), { from: phoneNumPretty(input.from), content: content, type: input.type === messageType ? input.type : messageType, messages: input.messages.map(message => {
24
- return Object.assign(Object.assign({ to: phoneNumPretty(message.to) }, (message.content != undefined && { content: textTrimming(message.content) })), (message.subject != undefined && messageType === 'LMS' && { subject: textTrimming(message.subject) }));
25
- }) });
21
+ const content = trimText(input.content);
22
+ const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
23
+ const messageType = childMessageType == 'LMS' ? childMessageType : checkMessageType(content);
24
+ this.input = Object.assign(Object.assign({}, input), { from: prettyPhoneNum(input.from), content: content, type: messageType, messages: messages });
26
25
  }
27
26
  ;
28
27
  serialize(input, config) {
@@ -46,25 +45,41 @@ class SendSMSCommand extends models_1.SensCommand {
46
45
  }
47
46
  exports.SendSMSCommand = SendSMSCommand;
48
47
  ;
49
- const textTrimming = (input) => input.trim();
50
- const phoneNumPretty = (input) => input.replace(/\-/gi, "");
51
- const messageTypeChecker = (input) => {
52
- const MAXIMUM = 2000;
53
- const euckrByte = input.split('').reduce((acc, text) => {
48
+ const trimText = (input) => input.trim();
49
+ const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
50
+ const getTextBytes = (input) => {
51
+ return input.split('').reduce((acc, text) => {
54
52
  let byte = Buffer.from(text).length;
55
53
  let modulo = byte % 3;
56
54
  modulo ? acc += 1 : acc += 2;
57
55
  return acc;
58
56
  }, 0);
59
- if (!euckrByte)
57
+ };
58
+ const checkMessageType = (input) => {
59
+ const SMS_MAX = 90;
60
+ const LMS_MAX = 2000;
61
+ const euckrBytes = getTextBytes(input);
62
+ if (!euckrBytes)
60
63
  throw new util_error_handler_1.IngestkoreaError({
61
64
  code: 400, type: 'Bad Request',
62
65
  message: 'Invalid Request', description: `Please check input message`
63
66
  });
64
- if (euckrByte > MAXIMUM)
67
+ if (euckrBytes > LMS_MAX)
65
68
  throw new util_error_handler_1.IngestkoreaError({
66
69
  code: 400, type: 'Bad Request',
67
- message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
70
+ message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
68
71
  });
69
- return euckrByte > 80 ? 'LMS' : 'SMS';
72
+ return euckrBytes > SMS_MAX ? 'LMS' : 'SMS';
73
+ };
74
+ const resolveInputMessages = (messages) => {
75
+ let resolvedMessageType = 'SMS';
76
+ let resolvedMessages = messages.map(message => {
77
+ const resolvedContent = message.content != undefined ? trimText(message.content) : '';
78
+ const resolvedSubject = message.subject != undefined ? trimText(message.subject) : '';
79
+ const messageType = !!resolvedContent != false ? checkMessageType(resolvedContent) : 'SMS';
80
+ if (messageType === 'LMS')
81
+ resolvedMessageType = messageType;
82
+ return Object.assign(Object.assign({ to: prettyPhoneNum(message.to) }, (!!resolvedContent != false && { content: resolvedContent })), (!!resolvedSubject != false && messageType === 'LMS' && { subject: resolvedSubject }));
83
+ });
84
+ return { messages: resolvedMessages, messageType: resolvedMessageType };
70
85
  };
@@ -21,3 +21,5 @@ __exportStar(require("./GetAlimtalkTemplateCommand"), exports);
21
21
  __exportStar(require("./ListAlimtalkTemplatesCommand"), exports);
22
22
  __exportStar(require("./ListAlimtalkChannelsCommand"), exports);
23
23
  __exportStar(require("./SendSMSCommand"), exports);
24
+ __exportStar(require("./GetSMSStatusCommand"), exports);
25
+ __exportStar(require("./GetSMSResultCommand"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
5
+ ;
6
+ ;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
5
+ ;
@@ -22,3 +22,5 @@ __exportStar(require("./GetAlimtalkTemplate"), exports);
22
22
  __exportStar(require("./ListAlimtalkTemplates"), exports);
23
23
  __exportStar(require("./ListAlimtalkChannels"), exports);
24
24
  __exportStar(require("./SendSMS"), exports);
25
+ __exportStar(require("./GetSMSStatus"), exports);
26
+ __exportStar(require("./GetSMSResult"), exports);
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.deserializeIngestkorea_restJson_File = exports.deserializeIngestkorea_restJson_SMSResultMessage = exports.deserializeIngestkorea_restJson_GetSMSResultOutput = exports.deserializeIngestkorea_restJson_GetSMSResultCommand = exports.serializeIngestkorea_restJson_GetSMSResultCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_1 = require("../protocols/constants");
15
+ const serializeIngestkorea_restJson_GetSMSResultCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const hostname = "sens.apigw.ntruss.com";
17
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages" + '/' + input.messageId;
18
+ const headers = {
19
+ "host": hostname
20
+ };
21
+ return new util_http_handler_1.HttpRequest({
22
+ protocol: 'https:',
23
+ method: 'GET',
24
+ hostname: hostname,
25
+ path: path,
26
+ headers: headers,
27
+ });
28
+ });
29
+ exports.serializeIngestkorea_restJson_GetSMSResultCommand = serializeIngestkorea_restJson_GetSMSResultCommand;
30
+ const deserializeIngestkorea_restJson_GetSMSResultCommand = (output) => __awaiter(void 0, void 0, void 0, function* () {
31
+ if (output.statusCode > 300)
32
+ yield (0, constants_1.parseErrorBody)(output);
33
+ const data = yield (0, constants_1.parseBody)(output); // GetSMSResultOutput
34
+ let contents = {};
35
+ contents = yield (0, exports.deserializeIngestkorea_restJson_GetSMSResultOutput)(data);
36
+ const response = Object.assign({}, contents);
37
+ return response;
38
+ });
39
+ exports.deserializeIngestkorea_restJson_GetSMSResultCommand = deserializeIngestkorea_restJson_GetSMSResultCommand;
40
+ const deserializeIngestkorea_restJson_GetSMSResultOutput = (output) => __awaiter(void 0, void 0, void 0, function* () {
41
+ return {
42
+ statusCode: output.statusCode ? output.statusCode : undefined,
43
+ statusName: output.statusName ? output.statusName : undefined,
44
+ messages: output.messages ? (0, exports.deserializeIngestkorea_restJson_SMSResultMessage)(output.messages) : undefined
45
+ };
46
+ });
47
+ exports.deserializeIngestkorea_restJson_GetSMSResultOutput = deserializeIngestkorea_restJson_GetSMSResultOutput;
48
+ const deserializeIngestkorea_restJson_SMSResultMessage = (outputs) => {
49
+ let result = outputs.map(output => {
50
+ return {
51
+ requestTime: output.requestTime != undefined ? output.requestTime : undefined,
52
+ contentType: output.contentType != undefined ? output.contentType : undefined,
53
+ content: output.content != undefined ? output.content : undefined,
54
+ countryCode: output.countryCode != undefined ? output.countryCode : undefined,
55
+ from: output.from != undefined ? output.from : undefined,
56
+ to: output.to != undefined ? output.to : undefined,
57
+ status: output.status != undefined ? output.status : undefined,
58
+ statusCode: output.statusCode != undefined ? output.statusCode : undefined,
59
+ statusMessage: output.statusMessage != undefined ? output.statusMessage : undefined,
60
+ statusName: output.statusName != undefined ? output.statusName : undefined,
61
+ completeTime: output.completeTime != undefined ? output.completeTime : undefined,
62
+ telcoCode: output.telcoCode != undefined ? output.telcoCode : undefined,
63
+ files: output.files != undefined ? (0, exports.deserializeIngestkorea_restJson_File)(output.files) : undefined
64
+ };
65
+ });
66
+ return result;
67
+ };
68
+ exports.deserializeIngestkorea_restJson_SMSResultMessage = deserializeIngestkorea_restJson_SMSResultMessage;
69
+ const deserializeIngestkorea_restJson_File = (outputs) => {
70
+ let result = outputs.map(output => {
71
+ return {
72
+ name: output.name != undefined ? output.name : undefined
73
+ };
74
+ });
75
+ return result;
76
+ };
77
+ exports.deserializeIngestkorea_restJson_File = deserializeIngestkorea_restJson_File;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.deserializeIngestkorea_restJson_SMSStatusMessage = exports.deserializeIngestkorea_restJson_GetSMSStatusOutput = exports.deserializeIngestkorea_restJson_GetSMSStatusCommand = exports.serializeIngestkorea_restJson_GetSMSStatusCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_1 = require("../protocols/constants");
15
+ const serializeIngestkorea_restJson_GetSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const hostname = "sens.apigw.ntruss.com";
17
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
18
+ const headers = {
19
+ "host": hostname
20
+ };
21
+ const query = {
22
+ requestId: input.requestId
23
+ };
24
+ return new util_http_handler_1.HttpRequest({
25
+ protocol: 'https:',
26
+ method: 'GET',
27
+ hostname: hostname,
28
+ path: path,
29
+ query: query,
30
+ headers: headers,
31
+ });
32
+ });
33
+ exports.serializeIngestkorea_restJson_GetSMSStatusCommand = serializeIngestkorea_restJson_GetSMSStatusCommand;
34
+ const deserializeIngestkorea_restJson_GetSMSStatusCommand = (output) => __awaiter(void 0, void 0, void 0, function* () {
35
+ if (output.statusCode > 300)
36
+ yield (0, constants_1.parseErrorBody)(output);
37
+ const data = yield (0, constants_1.parseBody)(output); // GetSMSStatusOutput
38
+ let contents = {};
39
+ contents = yield (0, exports.deserializeIngestkorea_restJson_GetSMSStatusOutput)(data);
40
+ const response = Object.assign({}, contents);
41
+ return response;
42
+ });
43
+ exports.deserializeIngestkorea_restJson_GetSMSStatusCommand = deserializeIngestkorea_restJson_GetSMSStatusCommand;
44
+ const deserializeIngestkorea_restJson_GetSMSStatusOutput = (output) => __awaiter(void 0, void 0, void 0, function* () {
45
+ return {
46
+ requestId: output.requestId ? output.requestId : undefined,
47
+ statusCode: output.statusCode ? output.statusCode : undefined,
48
+ statusName: output.statusName ? output.statusName : undefined,
49
+ messages: output.messages ? (0, exports.deserializeIngestkorea_restJson_SMSStatusMessage)(output.messages) : undefined
50
+ };
51
+ });
52
+ exports.deserializeIngestkorea_restJson_GetSMSStatusOutput = deserializeIngestkorea_restJson_GetSMSStatusOutput;
53
+ const deserializeIngestkorea_restJson_SMSStatusMessage = (outputs) => {
54
+ let result = outputs.map(output => {
55
+ return {
56
+ messageId: output.messageId != undefined ? output.messageId : undefined,
57
+ requestTime: output.requestTime != undefined ? output.requestTime : undefined,
58
+ contentType: output.contentType != undefined ? output.contentType : undefined,
59
+ countryCode: output.countryCode != undefined ? output.countryCode : undefined,
60
+ from: output.from != undefined ? output.from : undefined,
61
+ to: output.to != undefined ? output.to : undefined
62
+ };
63
+ });
64
+ return result;
65
+ };
66
+ exports.deserializeIngestkorea_restJson_SMSStatusMessage = deserializeIngestkorea_restJson_SMSStatusMessage;
@@ -21,3 +21,5 @@ __exportStar(require("./GetAlimtalkTemplate"), exports);
21
21
  __exportStar(require("./ListAlimtalkTemplates"), exports);
22
22
  __exportStar(require("./ListAlimtalkChannels"), exports);
23
23
  __exportStar(require("./SendSMS"), exports);
24
+ __exportStar(require("./GetSMSStatus"), exports);
25
+ __exportStar(require("./GetSMSResult"), exports);
@@ -0,0 +1,28 @@
1
+ import { SensCommand } from '../models';
2
+ import { serializeIngestkorea_restJson_GetSMSResultCommand, deserializeIngestkorea_restJson_GetSMSResultCommand } from '../protocols/GetSMSResult';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
+ ;
5
+ ;
6
+ export class GetSMSResultCommand extends SensCommand {
7
+ constructor(input) {
8
+ super(input);
9
+ this.input = {
10
+ ...input
11
+ };
12
+ }
13
+ ;
14
+ async serialize(input, config) {
15
+ if (!config.serviceId.sms)
16
+ throw new IngestkoreaError({
17
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
18
+ });
19
+ let request = await serializeIngestkorea_restJson_GetSMSResultCommand(input, config);
20
+ return request;
21
+ }
22
+ ;
23
+ async deserialize(response) {
24
+ let output = await deserializeIngestkorea_restJson_GetSMSResultCommand(response);
25
+ return output;
26
+ }
27
+ ;
28
+ }
@@ -0,0 +1,28 @@
1
+ import { SensCommand } from '../models';
2
+ import { serializeIngestkorea_restJson_GetSMSStatusCommand, deserializeIngestkorea_restJson_GetSMSStatusCommand } from '../protocols/GetSMSStatus';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
+ ;
5
+ ;
6
+ export class GetSMSStatusCommand extends SensCommand {
7
+ constructor(input) {
8
+ super(input);
9
+ this.input = {
10
+ ...input
11
+ };
12
+ }
13
+ ;
14
+ async serialize(input, config) {
15
+ if (!config.serviceId.sms)
16
+ throw new IngestkoreaError({
17
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
18
+ });
19
+ let request = await serializeIngestkorea_restJson_GetSMSStatusCommand(input, config);
20
+ return request;
21
+ }
22
+ ;
23
+ async deserialize(response) {
24
+ let output = await deserializeIngestkorea_restJson_GetSMSStatusCommand(response);
25
+ return output;
26
+ }
27
+ ;
28
+ }
@@ -6,20 +6,15 @@ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
6
6
  export class SendSMSCommand extends SensCommand {
7
7
  constructor(input) {
8
8
  super(input);
9
- const content = textTrimming(input.content);
10
- const messageType = messageTypeChecker(content);
9
+ const content = trimText(input.content);
10
+ const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
11
+ const messageType = childMessageType == 'LMS' ? childMessageType : checkMessageType(content);
11
12
  this.input = {
12
13
  ...input,
13
- from: phoneNumPretty(input.from),
14
+ from: prettyPhoneNum(input.from),
14
15
  content: content,
15
- type: input.type === messageType ? input.type : messageType,
16
- messages: input.messages.map(message => {
17
- return {
18
- to: phoneNumPretty(message.to),
19
- ...(message.content != undefined && { content: textTrimming(message.content) }),
20
- ...(message.subject != undefined && messageType === 'LMS' && { subject: textTrimming(message.subject) }),
21
- };
22
- })
16
+ type: messageType,
17
+ messages: messages
23
18
  };
24
19
  }
25
20
  ;
@@ -39,25 +34,45 @@ export class SendSMSCommand extends SensCommand {
39
34
  ;
40
35
  }
41
36
  ;
42
- const textTrimming = (input) => input.trim();
43
- const phoneNumPretty = (input) => input.replace(/\-/gi, "");
44
- const messageTypeChecker = (input) => {
45
- const MAXIMUM = 2000;
46
- const euckrByte = input.split('').reduce((acc, text) => {
37
+ const trimText = (input) => input.trim();
38
+ const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
39
+ const getTextBytes = (input) => {
40
+ return input.split('').reduce((acc, text) => {
47
41
  let byte = Buffer.from(text).length;
48
42
  let modulo = byte % 3;
49
43
  modulo ? acc += 1 : acc += 2;
50
44
  return acc;
51
45
  }, 0);
52
- if (!euckrByte)
46
+ };
47
+ const checkMessageType = (input) => {
48
+ const SMS_MAX = 90;
49
+ const LMS_MAX = 2000;
50
+ const euckrBytes = getTextBytes(input);
51
+ if (!euckrBytes)
53
52
  throw new IngestkoreaError({
54
53
  code: 400, type: 'Bad Request',
55
54
  message: 'Invalid Request', description: `Please check input message`
56
55
  });
57
- if (euckrByte > MAXIMUM)
56
+ if (euckrBytes > LMS_MAX)
58
57
  throw new IngestkoreaError({
59
58
  code: 400, type: 'Bad Request',
60
- message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
59
+ message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
61
60
  });
62
- return euckrByte > 80 ? 'LMS' : 'SMS';
61
+ return euckrBytes > SMS_MAX ? 'LMS' : 'SMS';
62
+ };
63
+ const resolveInputMessages = (messages) => {
64
+ let resolvedMessageType = 'SMS';
65
+ let resolvedMessages = messages.map(message => {
66
+ const resolvedContent = message.content != undefined ? trimText(message.content) : '';
67
+ const resolvedSubject = message.subject != undefined ? trimText(message.subject) : '';
68
+ const messageType = !!resolvedContent != false ? checkMessageType(resolvedContent) : 'SMS';
69
+ if (messageType === 'LMS')
70
+ resolvedMessageType = messageType;
71
+ return {
72
+ to: prettyPhoneNum(message.to),
73
+ ...(!!resolvedContent != false && { content: resolvedContent }),
74
+ ...(!!resolvedSubject != false && messageType === 'LMS' && { subject: resolvedSubject }),
75
+ };
76
+ });
77
+ return { messages: resolvedMessages, messageType: resolvedMessageType };
63
78
  };
@@ -5,3 +5,5 @@ export * from './GetAlimtalkTemplateCommand';
5
5
  export * from './ListAlimtalkTemplatesCommand';
6
6
  export * from './ListAlimtalkChannelsCommand';
7
7
  export * from './SendSMSCommand';
8
+ export * from './GetSMSStatusCommand';
9
+ export * from './GetSMSResultCommand';
@@ -0,0 +1,5 @@
1
+ ;
2
+ ;
3
+ ;
4
+ ;
5
+ export {};
@@ -0,0 +1,4 @@
1
+ ;
2
+ ;
3
+ ;
4
+ export {};
@@ -6,3 +6,5 @@ export * from './GetAlimtalkTemplate';
6
6
  export * from './ListAlimtalkTemplates';
7
7
  export * from './ListAlimtalkChannels';
8
8
  export * from './SendSMS';
9
+ export * from './GetSMSStatus';
10
+ export * from './GetSMSResult';
@@ -0,0 +1,62 @@
1
+ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
+ import { parseBody, parseErrorBody } from '../protocols/constants';
3
+ export const serializeIngestkorea_restJson_GetSMSResultCommand = async (input, config) => {
4
+ const hostname = "sens.apigw.ntruss.com";
5
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages" + '/' + input.messageId;
6
+ const headers = {
7
+ "host": hostname
8
+ };
9
+ return new HttpRequest({
10
+ protocol: 'https:',
11
+ method: 'GET',
12
+ hostname: hostname,
13
+ path: path,
14
+ headers: headers,
15
+ });
16
+ };
17
+ export const deserializeIngestkorea_restJson_GetSMSResultCommand = async (output) => {
18
+ if (output.statusCode > 300)
19
+ await parseErrorBody(output);
20
+ const data = await parseBody(output); // GetSMSResultOutput
21
+ let contents = {};
22
+ contents = await deserializeIngestkorea_restJson_GetSMSResultOutput(data);
23
+ const response = {
24
+ ...contents
25
+ };
26
+ return response;
27
+ };
28
+ export const deserializeIngestkorea_restJson_GetSMSResultOutput = async (output) => {
29
+ return {
30
+ statusCode: output.statusCode ? output.statusCode : undefined,
31
+ statusName: output.statusName ? output.statusName : undefined,
32
+ messages: output.messages ? deserializeIngestkorea_restJson_SMSResultMessage(output.messages) : undefined
33
+ };
34
+ };
35
+ export const deserializeIngestkorea_restJson_SMSResultMessage = (outputs) => {
36
+ let result = outputs.map(output => {
37
+ return {
38
+ requestTime: output.requestTime != undefined ? output.requestTime : undefined,
39
+ contentType: output.contentType != undefined ? output.contentType : undefined,
40
+ content: output.content != undefined ? output.content : undefined,
41
+ countryCode: output.countryCode != undefined ? output.countryCode : undefined,
42
+ from: output.from != undefined ? output.from : undefined,
43
+ to: output.to != undefined ? output.to : undefined,
44
+ status: output.status != undefined ? output.status : undefined,
45
+ statusCode: output.statusCode != undefined ? output.statusCode : undefined,
46
+ statusMessage: output.statusMessage != undefined ? output.statusMessage : undefined,
47
+ statusName: output.statusName != undefined ? output.statusName : undefined,
48
+ completeTime: output.completeTime != undefined ? output.completeTime : undefined,
49
+ telcoCode: output.telcoCode != undefined ? output.telcoCode : undefined,
50
+ files: output.files != undefined ? deserializeIngestkorea_restJson_File(output.files) : undefined
51
+ };
52
+ });
53
+ return result;
54
+ };
55
+ export const deserializeIngestkorea_restJson_File = (outputs) => {
56
+ let result = outputs.map(output => {
57
+ return {
58
+ name: output.name != undefined ? output.name : undefined
59
+ };
60
+ });
61
+ return result;
62
+ };
@@ -0,0 +1,52 @@
1
+ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
+ import { parseBody, parseErrorBody } from '../protocols/constants';
3
+ export const serializeIngestkorea_restJson_GetSMSStatusCommand = async (input, config) => {
4
+ const hostname = "sens.apigw.ntruss.com";
5
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
6
+ const headers = {
7
+ "host": hostname
8
+ };
9
+ const query = {
10
+ requestId: input.requestId
11
+ };
12
+ return new HttpRequest({
13
+ protocol: 'https:',
14
+ method: 'GET',
15
+ hostname: hostname,
16
+ path: path,
17
+ query: query,
18
+ headers: headers,
19
+ });
20
+ };
21
+ export const deserializeIngestkorea_restJson_GetSMSStatusCommand = async (output) => {
22
+ if (output.statusCode > 300)
23
+ await parseErrorBody(output);
24
+ const data = await parseBody(output); // GetSMSStatusOutput
25
+ let contents = {};
26
+ contents = await deserializeIngestkorea_restJson_GetSMSStatusOutput(data);
27
+ const response = {
28
+ ...contents
29
+ };
30
+ return response;
31
+ };
32
+ export const deserializeIngestkorea_restJson_GetSMSStatusOutput = async (output) => {
33
+ return {
34
+ requestId: output.requestId ? output.requestId : undefined,
35
+ statusCode: output.statusCode ? output.statusCode : undefined,
36
+ statusName: output.statusName ? output.statusName : undefined,
37
+ messages: output.messages ? deserializeIngestkorea_restJson_SMSStatusMessage(output.messages) : undefined
38
+ };
39
+ };
40
+ export const deserializeIngestkorea_restJson_SMSStatusMessage = (outputs) => {
41
+ let result = outputs.map(output => {
42
+ return {
43
+ messageId: output.messageId != undefined ? output.messageId : undefined,
44
+ requestTime: output.requestTime != undefined ? output.requestTime : undefined,
45
+ contentType: output.contentType != undefined ? output.contentType : undefined,
46
+ countryCode: output.countryCode != undefined ? output.countryCode : undefined,
47
+ from: output.from != undefined ? output.from : undefined,
48
+ to: output.to != undefined ? output.to : undefined
49
+ };
50
+ });
51
+ return result;
52
+ };
@@ -5,3 +5,5 @@ export * from './GetAlimtalkTemplate';
5
5
  export * from './ListAlimtalkTemplates';
6
6
  export * from './ListAlimtalkChannels';
7
7
  export * from './SendSMS';
8
+ export * from './GetSMSStatus';
9
+ export * from './GetSMSResult';
@@ -0,0 +1,13 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { SensCommand, GetSMSResultInput, GetSMSResultOutput } from '../models';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ export interface GetSMSResultCommandInput extends GetSMSResultInput {
5
+ }
6
+ export interface GetSMSResultCommandOutput extends GetSMSResultOutput {
7
+ }
8
+ export declare class GetSMSResultCommand extends SensCommand<GetSMSResultCommandInput, GetSMSResultCommandOutput, SensClientResolvedConfig> {
9
+ input: GetSMSResultCommandInput;
10
+ constructor(input: GetSMSResultCommandInput);
11
+ serialize(input: GetSMSResultCommandInput, config: SensClientResolvedConfig): Promise<HttpRequest>;
12
+ deserialize(response: HttpResponse): Promise<GetSMSResultCommandOutput>;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { SensCommand, GetSMSStatusInput, GetSMSStatusOutput } from '../models';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ export interface GetSMSStatusCommandInput extends GetSMSStatusInput {
5
+ }
6
+ export interface GetSMSStatusCommandOutput extends GetSMSStatusOutput {
7
+ }
8
+ export declare class GetSMSStatusCommand extends SensCommand<GetSMSStatusCommandInput, GetSMSStatusCommandOutput, SensClientResolvedConfig> {
9
+ input: GetSMSStatusCommandInput;
10
+ constructor(input: GetSMSStatusCommandInput);
11
+ serialize(input: GetSMSStatusCommandInput, config: SensClientResolvedConfig): Promise<HttpRequest>;
12
+ deserialize(response: HttpResponse): Promise<GetSMSStatusCommandOutput>;
13
+ }
@@ -5,3 +5,5 @@ export * from './GetAlimtalkTemplateCommand';
5
5
  export * from './ListAlimtalkTemplatesCommand';
6
6
  export * from './ListAlimtalkChannelsCommand';
7
7
  export * from './SendSMSCommand';
8
+ export * from './GetSMSStatusCommand';
9
+ export * from './GetSMSResultCommand';
@@ -0,0 +1,26 @@
1
+ export interface GetSMSResultInput {
2
+ messageId: string;
3
+ }
4
+ export interface GetSMSResultOutput {
5
+ statusCode?: string;
6
+ statusName?: string;
7
+ messages?: SMSResultMessage[];
8
+ }
9
+ export interface SMSResultMessage {
10
+ requestTime?: string;
11
+ contentType?: string;
12
+ content?: string;
13
+ countryCode?: string;
14
+ from?: string;
15
+ to?: string;
16
+ status?: string;
17
+ statusCode?: string;
18
+ statusMessage?: string;
19
+ statusName?: string;
20
+ completeTime?: string;
21
+ telcoCode?: string;
22
+ files?: File[];
23
+ }
24
+ export interface File {
25
+ name?: string;
26
+ }
@@ -0,0 +1,17 @@
1
+ export interface GetSMSStatusInput {
2
+ requestId: string;
3
+ }
4
+ export interface GetSMSStatusOutput {
5
+ requestId?: string;
6
+ statusCode?: string;
7
+ statusName?: string;
8
+ messages?: SMSStatusMessage[];
9
+ }
10
+ export interface SMSStatusMessage {
11
+ messageId?: string;
12
+ requestTime?: string;
13
+ contentType?: string;
14
+ countryCode?: string;
15
+ from?: string;
16
+ to?: string;
17
+ }
@@ -6,3 +6,5 @@ export * from './GetAlimtalkTemplate';
6
6
  export * from './ListAlimtalkTemplates';
7
7
  export * from './ListAlimtalkChannels';
8
8
  export * from './SendSMS';
9
+ export * from './GetSMSStatus';
10
+ export * from './GetSMSResult';
@@ -0,0 +1,9 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { GetSMSResultOutput, SMSResultMessage, File } from '../models/GetSMSResult';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ import { GetSMSResultCommandInput, GetSMSResultCommandOutput } from '../commands/GetSMSResultCommand';
5
+ export declare const serializeIngestkorea_restJson_GetSMSResultCommand: (input: GetSMSResultCommandInput, config: SensClientResolvedConfig) => Promise<HttpRequest>;
6
+ export declare const deserializeIngestkorea_restJson_GetSMSResultCommand: (output: HttpResponse) => Promise<GetSMSResultCommandOutput>;
7
+ export declare const deserializeIngestkorea_restJson_GetSMSResultOutput: (output: any) => Promise<GetSMSResultOutput>;
8
+ export declare const deserializeIngestkorea_restJson_SMSResultMessage: (outputs: any[]) => SMSResultMessage[];
9
+ export declare const deserializeIngestkorea_restJson_File: (outputs: any[]) => File[];
@@ -0,0 +1,8 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { GetSMSStatusOutput, SMSStatusMessage } from '../models/GetSMSStatus';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ import { GetSMSStatusCommandInput, GetSMSStatusCommandOutput } from '../commands/GetSMSStatusCommand';
5
+ export declare const serializeIngestkorea_restJson_GetSMSStatusCommand: (input: GetSMSStatusCommandInput, config: SensClientResolvedConfig) => Promise<HttpRequest>;
6
+ export declare const deserializeIngestkorea_restJson_GetSMSStatusCommand: (output: HttpResponse) => Promise<GetSMSStatusCommandOutput>;
7
+ export declare const deserializeIngestkorea_restJson_GetSMSStatusOutput: (output: any) => Promise<GetSMSStatusOutput>;
8
+ export declare const deserializeIngestkorea_restJson_SMSStatusMessage: (outputs: any[]) => SMSStatusMessage[];
@@ -5,3 +5,5 @@ export * from './GetAlimtalkTemplate';
5
5
  export * from './ListAlimtalkTemplates';
6
6
  export * from './ListAlimtalkChannels';
7
7
  export * from './SendSMS';
8
+ export * from './GetSMSStatus';
9
+ export * from './GetSMSResult';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingestkorea/client-sens",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "INGESTKOREA SDK Naver Cloud Platform SENS Client for Node.js.",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",