@ingestkorea/client-sens 1.0.0 → 1.1.0

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 (40) hide show
  1. package/README.md +6 -1
  2. package/dist-cjs/SensClient.js +6 -2
  3. package/dist-cjs/commands/GetRequestResultCommand.js +5 -0
  4. package/dist-cjs/commands/GetRequestStatusCommand.js +5 -0
  5. package/dist-cjs/commands/ListChannelsCommand.js +5 -0
  6. package/dist-cjs/commands/SendAlimtalkCommand.js +15 -1
  7. package/dist-cjs/commands/SendSMSCommand.js +70 -0
  8. package/dist-cjs/commands/index.js +1 -0
  9. package/dist-cjs/models/SendSMS.js +4 -0
  10. package/dist-cjs/models/index.js +1 -0
  11. package/dist-cjs/protocols/GetRequestResult.js +1 -1
  12. package/dist-cjs/protocols/GetRequestStatus.js +1 -1
  13. package/dist-cjs/protocols/ListChannels.js +1 -1
  14. package/dist-cjs/protocols/SendAlimtalk.js +1 -1
  15. package/dist-cjs/protocols/SendSMS.js +51 -0
  16. package/dist-cjs/protocols/index.js +1 -0
  17. package/dist-es/SensClient.js +6 -2
  18. package/dist-es/commands/GetRequestResultCommand.js +5 -0
  19. package/dist-es/commands/GetRequestStatusCommand.js +5 -0
  20. package/dist-es/commands/ListChannelsCommand.js +5 -0
  21. package/dist-es/commands/SendAlimtalkCommand.js +22 -1
  22. package/dist-es/commands/SendSMSCommand.js +63 -0
  23. package/dist-es/commands/index.js +1 -0
  24. package/dist-es/models/SendSMS.js +3 -0
  25. package/dist-es/models/index.js +1 -0
  26. package/dist-es/protocols/GetRequestResult.js +1 -1
  27. package/dist-es/protocols/GetRequestStatus.js +1 -1
  28. package/dist-es/protocols/ListChannels.js +1 -1
  29. package/dist-es/protocols/SendAlimtalk.js +1 -1
  30. package/dist-es/protocols/SendSMS.js +46 -0
  31. package/dist-es/protocols/index.js +1 -0
  32. package/dist-types/SensClient.d.ts +5 -1
  33. package/dist-types/commands/SendSMSCommand.d.ts +13 -0
  34. package/dist-types/commands/index.d.ts +1 -0
  35. package/dist-types/models/SendAlimtalk.d.ts +2 -2
  36. package/dist-types/models/SendSMS.d.ts +23 -0
  37. package/dist-types/models/index.d.ts +1 -0
  38. package/dist-types/protocols/SendSMS.d.ts +7 -0
  39. package/dist-types/protocols/index.d.ts +1 -0
  40. package/package.json +1 -1
package/README.md CHANGED
@@ -25,6 +25,7 @@ npm install @ingestkorea/client-sens
25
25
  + GetRequestStatus
26
26
  + GetRequestResult
27
27
  + ListChannels
28
+ + SendSMS
28
29
 
29
30
  ### Import
30
31
  ```ts
@@ -47,7 +48,11 @@ const client = new SensClient({
47
48
  accessKey: ACCESS_KEY,
48
49
  secretKey: SECRET_KEY
49
50
  },
50
- serviceId: 'ncp:kkobizmsg:kr:1234567:your-service-name'
51
+ serviceId: { // at least one serviceId required
52
+ sms: 'ncp:sms:kr:123456789xxx:your-service-name', // optional
53
+ kakao: 'ncp:kkobizmsg:kr:9876xxx:your-service-name' // optional
54
+ // if you call send operation without serviceId, sdk throw error
55
+ }
51
56
  });
52
57
 
53
58
  let params: SendAlimtalkCommandInput = {
@@ -21,7 +21,7 @@ class SensClient {
21
21
  const resolvedServiceId = resolveServiceId(config);
22
22
  this.config = {
23
23
  credentials: Object.assign({}, resolvedCredentials),
24
- serviceId: resolvedServiceId
24
+ serviceId: Object.assign({}, resolvedServiceId)
25
25
  };
26
26
  this.httpHandler = new util_http_handler_1.NodeHttpHandler({ connectionTimeout: 3000, socketTimeout: 3000 });
27
27
  }
@@ -56,5 +56,9 @@ const resolveServiceId = (config) => {
56
56
  code: 401, type: 'Unauthorized',
57
57
  message: 'Invalid Credentials', description: 'Invalid ServiceId'
58
58
  });
59
- return serviceId;
59
+ return {
60
+ push: serviceId.push != undefined ? serviceId.push : undefined,
61
+ sms: serviceId.sms != undefined ? serviceId.sms : undefined,
62
+ kakao: serviceId.kakao != undefined ? serviceId.kakao : undefined
63
+ };
60
64
  };
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GetRequestResultCommand = void 0;
13
13
  const models_1 = require("../models");
14
14
  const GetRequestResult_1 = require("../protocols/GetRequestResult");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
15
16
  ;
16
17
  ;
17
18
  class GetRequestResultCommand extends models_1.SensCommand {
@@ -22,6 +23,10 @@ class GetRequestResultCommand extends models_1.SensCommand {
22
23
  ;
23
24
  serialize(input, config) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.kakao)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
29
+ });
25
30
  let request = yield (0, GetRequestResult_1.serializeIngestkorea_restJson_GetRequestResultCommand)(input, config);
26
31
  return request;
27
32
  });
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GetRequestStatusCommand = void 0;
13
13
  const models_1 = require("../models");
14
14
  const GetRequestStatus_1 = require("../protocols/GetRequestStatus");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
15
16
  ;
16
17
  ;
17
18
  class GetRequestStatusCommand extends models_1.SensCommand {
@@ -22,6 +23,10 @@ class GetRequestStatusCommand extends models_1.SensCommand {
22
23
  ;
23
24
  serialize(input, config) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.kakao)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
29
+ });
25
30
  let request = yield (0, GetRequestStatus_1.serializeIngestkorea_restJson_GetRequestStatusCommand)(input, config);
26
31
  return request;
27
32
  });
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ListChannelsCommand = void 0;
13
13
  const models_1 = require("../models");
14
14
  const ListChannels_1 = require("../protocols/ListChannels");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
15
16
  ;
16
17
  ;
17
18
  class ListChannelsCommand extends models_1.SensCommand {
@@ -22,6 +23,10 @@ class ListChannelsCommand extends models_1.SensCommand {
22
23
  ;
23
24
  serialize(input, config) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.kakao)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
29
+ });
25
30
  let request = yield (0, ListChannels_1.serializeIngestkorea_restJson_ListChannelsCommand)(input, config);
26
31
  return request;
27
32
  });
@@ -12,16 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SendAlimtalkCommand = void 0;
13
13
  const models_1 = require("../models");
14
14
  const SendAlimtalk_1 = require("../protocols/SendAlimtalk");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
15
16
  ;
16
17
  ;
17
18
  class SendAlimtalkCommand extends models_1.SensCommand {
18
19
  constructor(input) {
19
20
  super(input);
20
- this.input = Object.assign({}, input);
21
+ this.input = Object.assign(Object.assign({}, input), { plusFriendId: input.plusFriendId, templateCode: input.templateCode, messages: input.messages.map(resolveAlimtalkMessage) });
21
22
  }
22
23
  ;
23
24
  serialize(input, config) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
26
+ if (!config.serviceId.kakao)
27
+ throw new util_error_handler_1.IngestkoreaError({
28
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
29
+ });
25
30
  let request = yield (0, SendAlimtalk_1.serializeIngestkorea_restJson_SendAlimtalkCommand)(input, config);
26
31
  return request;
27
32
  });
@@ -37,3 +42,12 @@ class SendAlimtalkCommand extends models_1.SensCommand {
37
42
  }
38
43
  exports.SendAlimtalkCommand = SendAlimtalkCommand;
39
44
  ;
45
+ const resolveAlimtalkMessage = (message) => {
46
+ const MAXIMUM_STRING_LENGTH = 1000;
47
+ if (message.content.length > MAXIMUM_STRING_LENGTH)
48
+ throw new util_error_handler_1.IngestkoreaError({
49
+ code: 400, type: 'Bad Request',
50
+ message: 'Invalid Params', description: `Maximum message length is ${MAXIMUM_STRING_LENGTH}`
51
+ });
52
+ return Object.assign({ to: message.to.replace(/\-/gi, ""), content: message.content }, (message.buttons != undefined && { buttons: message.buttons }));
53
+ };
@@ -0,0 +1,70 @@
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.SendSMSCommand = void 0;
13
+ const models_1 = require("../models");
14
+ const SendSMS_1 = require("../protocols/SendSMS");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
+ ;
17
+ ;
18
+ class SendSMSCommand extends models_1.SensCommand {
19
+ constructor(input) {
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
+ }) });
26
+ }
27
+ ;
28
+ serialize(input, config) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ if (!config.serviceId.sms)
31
+ throw new util_error_handler_1.IngestkoreaError({
32
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
33
+ });
34
+ let request = yield (0, SendSMS_1.serializeIngestkorea_restJson_SendSMSCommand)(input, config);
35
+ return request;
36
+ });
37
+ }
38
+ ;
39
+ deserialize(response) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ let output = yield (0, SendSMS_1.deserializeIngestkorea_restJson_SendSMSCommand)(response);
42
+ return output;
43
+ });
44
+ }
45
+ ;
46
+ }
47
+ exports.SendSMSCommand = SendSMSCommand;
48
+ ;
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) => {
54
+ let byte = Buffer.from(text).length;
55
+ let modulo = byte % 3;
56
+ modulo ? acc += 1 : acc += 2;
57
+ return acc;
58
+ }, 0);
59
+ if (!euckrByte)
60
+ throw new util_error_handler_1.IngestkoreaError({
61
+ code: 400, type: 'Bad Request',
62
+ message: 'Invalid Request', description: `Please check input message`
63
+ });
64
+ if (euckrByte > MAXIMUM)
65
+ throw new util_error_handler_1.IngestkoreaError({
66
+ code: 400, type: 'Bad Request',
67
+ message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
68
+ });
69
+ return euckrByte > 80 ? 'LMS' : 'SMS';
70
+ };
@@ -18,3 +18,4 @@ __exportStar(require("./SendAlimtalkCommand"), exports);
18
18
  __exportStar(require("./GetRequestStatusCommand"), exports);
19
19
  __exportStar(require("./GetRequestResultCommand"), exports);
20
20
  __exportStar(require("./ListChannelsCommand"), exports);
21
+ __exportStar(require("./SendSMSCommand"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
@@ -19,3 +19,4 @@ __exportStar(require("./SendAlimtalk"), exports);
19
19
  __exportStar(require("./GetRequestStatus"), exports);
20
20
  __exportStar(require("./GetRequestResult"), exports);
21
21
  __exportStar(require("./ListChannels"), exports);
22
+ __exportStar(require("./SendSMS"), exports);
@@ -14,7 +14,7 @@ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const constants_1 = require("./constants");
15
15
  const serializeIngestkorea_restJson_GetRequestResultCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const hostname = "sens.apigw.ntruss.com";
17
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages/" + input.messageId;
17
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages/" + input.messageId;
18
18
  const headers = {
19
19
  "host": hostname
20
20
  };
@@ -14,7 +14,7 @@ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const constants_1 = require("./constants");
15
15
  const serializeIngestkorea_restJson_GetRequestStatusCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const hostname = "sens.apigw.ntruss.com";
17
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages";
17
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
18
18
  const headers = {
19
19
  "host": hostname
20
20
  };
@@ -14,7 +14,7 @@ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const constants_1 = require("./constants");
15
15
  const serializeIngestkorea_restJson_ListChannelsCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const hostname = "sens.apigw.ntruss.com";
17
- const path = "/alimtalk/v2/services/" + config.serviceId + "/channels";
17
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/channels";
18
18
  const headers = {
19
19
  "host": hostname
20
20
  };
@@ -14,7 +14,7 @@ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const constants_1 = require("./constants");
15
15
  const serializeIngestkorea_restJson_SendAlimtalkCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const hostname = "sens.apigw.ntruss.com";
17
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages";
17
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
18
18
  const headers = {
19
19
  "content-type": "application/json; charset=utf-8",
20
20
  "host": hostname
@@ -0,0 +1,51 @@
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_SendSMSOutput = exports.deserializeIngestkorea_restJson_SendSMSCommand = exports.serializeIngestkorea_restJson_SendSMSCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_1 = require("../protocols/constants");
15
+ const serializeIngestkorea_restJson_SendSMSCommand = (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
+ "content-type": "application/json; charset=utf-8",
20
+ "host": hostname
21
+ };
22
+ const body = JSON.stringify(Object.assign(Object.assign(Object.assign({ from: input.from, content: input.content, messages: input.messages, type: input.type != undefined ? input.type : 'SMS' }, (input.contentType != undefined && { contentType: input.contentType })), (input.countryCode != undefined && { countryCode: input.countryCode })), (input.subject != undefined && input.type === 'LMS' && { subject: input.subject })));
23
+ return new util_http_handler_1.HttpRequest({
24
+ protocol: 'https:',
25
+ method: 'POST',
26
+ hostname: hostname,
27
+ path: path,
28
+ headers: headers,
29
+ body: body
30
+ });
31
+ });
32
+ exports.serializeIngestkorea_restJson_SendSMSCommand = serializeIngestkorea_restJson_SendSMSCommand;
33
+ const deserializeIngestkorea_restJson_SendSMSCommand = (output) => __awaiter(void 0, void 0, void 0, function* () {
34
+ if (output.statusCode > 300)
35
+ yield (0, constants_1.parseErrorBody)(output);
36
+ const data = yield (0, constants_1.parseBody)(output); // SendSMSOutput
37
+ let contents = {};
38
+ contents = yield (0, exports.deserializeIngestkorea_restJson_SendSMSOutput)(data);
39
+ const response = Object.assign({}, contents);
40
+ return response;
41
+ });
42
+ exports.deserializeIngestkorea_restJson_SendSMSCommand = deserializeIngestkorea_restJson_SendSMSCommand;
43
+ const deserializeIngestkorea_restJson_SendSMSOutput = (output) => __awaiter(void 0, void 0, void 0, function* () {
44
+ return {
45
+ requestId: output.requestId ? output.requestId : undefined,
46
+ requestTime: output.requestTime ? output.requestTime : undefined,
47
+ statusCode: output.statusCode ? output.statusCode : undefined,
48
+ statusName: output.statusName ? output.statusName : undefined,
49
+ };
50
+ });
51
+ exports.deserializeIngestkorea_restJson_SendSMSOutput = deserializeIngestkorea_restJson_SendSMSOutput;
@@ -18,3 +18,4 @@ __exportStar(require("./SendAlimtalk"), exports);
18
18
  __exportStar(require("./GetRequestStatus"), exports);
19
19
  __exportStar(require("./GetRequestResult"), exports);
20
20
  __exportStar(require("./ListChannels"), exports);
21
+ __exportStar(require("./SendSMS"), exports);
@@ -9,7 +9,7 @@ export class SensClient {
9
9
  const resolvedServiceId = resolveServiceId(config);
10
10
  this.config = {
11
11
  credentials: { ...resolvedCredentials },
12
- serviceId: resolvedServiceId
12
+ serviceId: { ...resolvedServiceId }
13
13
  };
14
14
  this.httpHandler = new NodeHttpHandler({ connectionTimeout: 3000, socketTimeout: 3000 });
15
15
  }
@@ -41,5 +41,9 @@ const resolveServiceId = (config) => {
41
41
  code: 401, type: 'Unauthorized',
42
42
  message: 'Invalid Credentials', description: 'Invalid ServiceId'
43
43
  });
44
- return serviceId;
44
+ return {
45
+ push: serviceId.push != undefined ? serviceId.push : undefined,
46
+ sms: serviceId.sms != undefined ? serviceId.sms : undefined,
47
+ kakao: serviceId.kakao != undefined ? serviceId.kakao : undefined
48
+ };
45
49
  };
@@ -1,5 +1,6 @@
1
1
  import { SensCommand } from '../models';
2
2
  import { serializeIngestkorea_restJson_GetRequestResultCommand, deserializeIngestkorea_restJson_GetRequestResultCommand } from '../protocols/GetRequestResult';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
3
4
  ;
4
5
  ;
5
6
  export class GetRequestResultCommand extends SensCommand {
@@ -11,6 +12,10 @@ export class GetRequestResultCommand extends SensCommand {
11
12
  }
12
13
  ;
13
14
  async serialize(input, config) {
15
+ if (!config.serviceId.kakao)
16
+ throw new IngestkoreaError({
17
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
18
+ });
14
19
  let request = await serializeIngestkorea_restJson_GetRequestResultCommand(input, config);
15
20
  return request;
16
21
  }
@@ -1,5 +1,6 @@
1
1
  import { SensCommand } from '../models';
2
2
  import { serializeIngestkorea_restJson_GetRequestStatusCommand, deserializeIngestkorea_restJson_GetRequestStatusCommand } from '../protocols/GetRequestStatus';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
3
4
  ;
4
5
  ;
5
6
  export class GetRequestStatusCommand extends SensCommand {
@@ -11,6 +12,10 @@ export class GetRequestStatusCommand extends SensCommand {
11
12
  }
12
13
  ;
13
14
  async serialize(input, config) {
15
+ if (!config.serviceId.kakao)
16
+ throw new IngestkoreaError({
17
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
18
+ });
14
19
  let request = await serializeIngestkorea_restJson_GetRequestStatusCommand(input, config);
15
20
  return request;
16
21
  }
@@ -1,5 +1,6 @@
1
1
  import { SensCommand } from '../models';
2
2
  import { serializeIngestkorea_restJson_ListChannelsCommand, deserializeIngestkorea_restJson_ListChannelsCommand, } from '../protocols/ListChannels';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
3
4
  ;
4
5
  ;
5
6
  export class ListChannelsCommand extends SensCommand {
@@ -11,6 +12,10 @@ export class ListChannelsCommand extends SensCommand {
11
12
  }
12
13
  ;
13
14
  async serialize(input, config) {
15
+ if (!config.serviceId.kakao)
16
+ throw new IngestkoreaError({
17
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
18
+ });
14
19
  let request = await serializeIngestkorea_restJson_ListChannelsCommand(input, config);
15
20
  return request;
16
21
  }
@@ -1,16 +1,24 @@
1
1
  import { SensCommand } from '../models';
2
2
  import { serializeIngestkorea_restJson_SendAlimtalkCommand, deserializeIngestkorea_restJson_SendAlimtalkCommand } from '../protocols/SendAlimtalk';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
3
4
  ;
4
5
  ;
5
6
  export class SendAlimtalkCommand extends SensCommand {
6
7
  constructor(input) {
7
8
  super(input);
8
9
  this.input = {
9
- ...input
10
+ ...input,
11
+ plusFriendId: input.plusFriendId,
12
+ templateCode: input.templateCode,
13
+ messages: input.messages.map(resolveAlimtalkMessage)
10
14
  };
11
15
  }
12
16
  ;
13
17
  async serialize(input, config) {
18
+ if (!config.serviceId.kakao)
19
+ throw new IngestkoreaError({
20
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
21
+ });
14
22
  let request = await serializeIngestkorea_restJson_SendAlimtalkCommand(input, config);
15
23
  return request;
16
24
  }
@@ -22,3 +30,16 @@ export class SendAlimtalkCommand extends SensCommand {
22
30
  ;
23
31
  }
24
32
  ;
33
+ const resolveAlimtalkMessage = (message) => {
34
+ const MAXIMUM_STRING_LENGTH = 1000;
35
+ if (message.content.length > MAXIMUM_STRING_LENGTH)
36
+ throw new IngestkoreaError({
37
+ code: 400, type: 'Bad Request',
38
+ message: 'Invalid Params', description: `Maximum message length is ${MAXIMUM_STRING_LENGTH}`
39
+ });
40
+ return {
41
+ to: message.to.replace(/\-/gi, ""),
42
+ content: message.content,
43
+ ...(message.buttons != undefined && { buttons: message.buttons })
44
+ };
45
+ };
@@ -0,0 +1,63 @@
1
+ import { SensCommand } from '../models';
2
+ import { serializeIngestkorea_restJson_SendSMSCommand, deserializeIngestkorea_restJson_SendSMSCommand } from '../protocols/SendSMS';
3
+ import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
+ ;
5
+ ;
6
+ export class SendSMSCommand extends SensCommand {
7
+ constructor(input) {
8
+ super(input);
9
+ const content = textTrimming(input.content);
10
+ const messageType = messageTypeChecker(content);
11
+ this.input = {
12
+ ...input,
13
+ from: phoneNumPretty(input.from),
14
+ 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
+ })
23
+ };
24
+ }
25
+ ;
26
+ async serialize(input, config) {
27
+ if (!config.serviceId.sms)
28
+ throw new IngestkoreaError({
29
+ code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
30
+ });
31
+ let request = await serializeIngestkorea_restJson_SendSMSCommand(input, config);
32
+ return request;
33
+ }
34
+ ;
35
+ async deserialize(response) {
36
+ let output = await deserializeIngestkorea_restJson_SendSMSCommand(response);
37
+ return output;
38
+ }
39
+ ;
40
+ }
41
+ ;
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) => {
47
+ let byte = Buffer.from(text).length;
48
+ let modulo = byte % 3;
49
+ modulo ? acc += 1 : acc += 2;
50
+ return acc;
51
+ }, 0);
52
+ if (!euckrByte)
53
+ throw new IngestkoreaError({
54
+ code: 400, type: 'Bad Request',
55
+ message: 'Invalid Request', description: `Please check input message`
56
+ });
57
+ if (euckrByte > MAXIMUM)
58
+ throw new IngestkoreaError({
59
+ code: 400, type: 'Bad Request',
60
+ message: 'Invalid Request', description: `Maximum message length is ${MAXIMUM}bytes`
61
+ });
62
+ return euckrByte > 80 ? 'LMS' : 'SMS';
63
+ };
@@ -2,3 +2,4 @@ export * from './SendAlimtalkCommand';
2
2
  export * from './GetRequestStatusCommand';
3
3
  export * from './GetRequestResultCommand';
4
4
  export * from './ListChannelsCommand';
5
+ export * from './SendSMSCommand';
@@ -0,0 +1,3 @@
1
+ ;
2
+ ;
3
+ export {};
@@ -3,3 +3,4 @@ export * from './SendAlimtalk';
3
3
  export * from './GetRequestStatus';
4
4
  export * from './GetRequestResult';
5
5
  export * from './ListChannels';
6
+ export * from './SendSMS';
@@ -2,7 +2,7 @@ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
2
  import { parseBody, parseErrorBody } from './constants';
3
3
  export const serializeIngestkorea_restJson_GetRequestResultCommand = async (input, config) => {
4
4
  const hostname = "sens.apigw.ntruss.com";
5
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages/" + input.messageId;
5
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages/" + input.messageId;
6
6
  const headers = {
7
7
  "host": hostname
8
8
  };
@@ -2,7 +2,7 @@ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
2
  import { parseBody, parseErrorBody } from './constants';
3
3
  export const serializeIngestkorea_restJson_GetRequestStatusCommand = async (input, config) => {
4
4
  const hostname = "sens.apigw.ntruss.com";
5
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages";
5
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
6
6
  const headers = {
7
7
  "host": hostname
8
8
  };
@@ -2,7 +2,7 @@ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
2
  import { parseBody, parseErrorBody } from './constants';
3
3
  export const serializeIngestkorea_restJson_ListChannelsCommand = async (input, config) => {
4
4
  const hostname = "sens.apigw.ntruss.com";
5
- const path = "/alimtalk/v2/services/" + config.serviceId + "/channels";
5
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/channels";
6
6
  const headers = {
7
7
  "host": hostname
8
8
  };
@@ -2,7 +2,7 @@ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
2
  import { parseBody, parseErrorBody } from './constants';
3
3
  export const serializeIngestkorea_restJson_SendAlimtalkCommand = async (input, config) => {
4
4
  const hostname = "sens.apigw.ntruss.com";
5
- const path = "/alimtalk/v2/services/" + config.serviceId + "/messages";
5
+ const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
6
6
  const headers = {
7
7
  "content-type": "application/json; charset=utf-8",
8
8
  "host": hostname
@@ -0,0 +1,46 @@
1
+ import { HttpRequest } from '@ingestkorea/util-http-handler';
2
+ import { parseBody, parseErrorBody } from '../protocols/constants';
3
+ export const serializeIngestkorea_restJson_SendSMSCommand = async (input, config) => {
4
+ const hostname = "sens.apigw.ntruss.com";
5
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
6
+ const headers = {
7
+ "content-type": "application/json; charset=utf-8",
8
+ "host": hostname
9
+ };
10
+ const body = JSON.stringify({
11
+ from: input.from,
12
+ content: input.content,
13
+ messages: input.messages,
14
+ type: input.type != undefined ? input.type : 'SMS',
15
+ ...(input.contentType != undefined && { contentType: input.contentType }),
16
+ ...(input.countryCode != undefined && { countryCode: input.countryCode }),
17
+ ...(input.subject != undefined && input.type === 'LMS' && { subject: input.subject }),
18
+ });
19
+ return new HttpRequest({
20
+ protocol: 'https:',
21
+ method: 'POST',
22
+ hostname: hostname,
23
+ path: path,
24
+ headers: headers,
25
+ body: body
26
+ });
27
+ };
28
+ export const deserializeIngestkorea_restJson_SendSMSCommand = async (output) => {
29
+ if (output.statusCode > 300)
30
+ await parseErrorBody(output);
31
+ const data = await parseBody(output); // SendSMSOutput
32
+ let contents = {};
33
+ contents = await deserializeIngestkorea_restJson_SendSMSOutput(data);
34
+ const response = {
35
+ ...contents
36
+ };
37
+ return response;
38
+ };
39
+ export const deserializeIngestkorea_restJson_SendSMSOutput = async (output) => {
40
+ return {
41
+ requestId: output.requestId ? output.requestId : undefined,
42
+ requestTime: output.requestTime ? output.requestTime : undefined,
43
+ statusCode: output.statusCode ? output.statusCode : undefined,
44
+ statusName: output.statusName ? output.statusName : undefined,
45
+ };
46
+ };
@@ -2,3 +2,4 @@ export * from './SendAlimtalk';
2
2
  export * from './GetRequestStatus';
3
3
  export * from './GetRequestResult';
4
4
  export * from './ListChannels';
5
+ export * from './SendSMS';
@@ -4,7 +4,11 @@ export type Credentials = {
4
4
  accessKey: string;
5
5
  secretKey: string;
6
6
  };
7
- export type ServiceId = string;
7
+ export type ServiceId = {
8
+ push?: string;
9
+ sms?: string;
10
+ kakao?: string;
11
+ };
8
12
  export interface SensClientConfig {
9
13
  credentials?: Credentials;
10
14
  serviceId?: ServiceId;
@@ -0,0 +1,13 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { SensCommand, SendSMSInput, SendSMSOutput } from '../models';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ export interface SendSMSCommandInput extends SendSMSInput {
5
+ }
6
+ export interface SendSMSCommandOutput extends SendSMSOutput {
7
+ }
8
+ export declare class SendSMSCommand extends SensCommand<SendSMSCommandInput, SendSMSCommandOutput, SensClientResolvedConfig> {
9
+ input: SendSMSCommandInput;
10
+ constructor(input: SendSMSCommandInput);
11
+ serialize(input: SendSMSCommandInput, config: SensClientResolvedConfig): Promise<HttpRequest>;
12
+ deserialize(response: HttpResponse): Promise<SendSMSCommandOutput>;
13
+ }
@@ -2,3 +2,4 @@ export * from './SendAlimtalkCommand';
2
2
  export * from './GetRequestStatusCommand';
3
3
  export * from './GetRequestResultCommand';
4
4
  export * from './ListChannelsCommand';
5
+ export * from './SendSMSCommand';
@@ -1,7 +1,7 @@
1
1
  export interface SendAlimtalkInput {
2
2
  plusFriendId: string;
3
3
  templateCode: string;
4
- messages: SendMessage[];
4
+ messages: AlimtalkMessage[];
5
5
  }
6
6
  export interface SendAlimtalkOutput {
7
7
  requestId?: string;
@@ -10,7 +10,7 @@ export interface SendAlimtalkOutput {
10
10
  statusName?: string;
11
11
  messages?: ReceivedMessage[];
12
12
  }
13
- export interface SendMessage {
13
+ export interface AlimtalkMessage {
14
14
  to: string;
15
15
  content: string;
16
16
  buttons?: Buttons[];
@@ -0,0 +1,23 @@
1
+ export type MessageType = 'SMS' | 'LMS';
2
+ export type MessageContentType = 'COMM' | 'AD';
3
+ export type CountryCode = '1' | '886' | '81' | '86' | '65' | '852' | '82';
4
+ export type SMSMessage = {
5
+ to: string;
6
+ subject?: string;
7
+ content?: string;
8
+ };
9
+ export interface SendSMSInput {
10
+ from: string;
11
+ content: string;
12
+ messages: SMSMessage[];
13
+ type?: MessageType;
14
+ contentType?: MessageContentType;
15
+ countryCode?: CountryCode;
16
+ subject?: string;
17
+ }
18
+ export interface SendSMSOutput {
19
+ requestId?: string;
20
+ requestTime?: string;
21
+ statusCode?: string;
22
+ statusName?: string;
23
+ }
@@ -3,3 +3,4 @@ export * from './SendAlimtalk';
3
3
  export * from './GetRequestStatus';
4
4
  export * from './GetRequestResult';
5
5
  export * from './ListChannels';
6
+ export * from './SendSMS';
@@ -0,0 +1,7 @@
1
+ import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
2
+ import { SendSMSOutput } from '../models/SendSMS';
3
+ import { SensClientResolvedConfig } from '../SensClient';
4
+ import { SendSMSCommandInput, SendSMSCommandOutput } from '../commands/SendSMSCommand';
5
+ export declare const serializeIngestkorea_restJson_SendSMSCommand: (input: SendSMSCommandInput, config: SensClientResolvedConfig) => Promise<HttpRequest>;
6
+ export declare const deserializeIngestkorea_restJson_SendSMSCommand: (output: HttpResponse) => Promise<SendSMSCommandOutput>;
7
+ export declare const deserializeIngestkorea_restJson_SendSMSOutput: (output: any) => Promise<SendSMSOutput>;
@@ -2,3 +2,4 @@ export * from './SendAlimtalk';
2
2
  export * from './GetRequestStatus';
3
3
  export * from './GetRequestResult';
4
4
  export * from './ListChannels';
5
+ export * from './SendSMS';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingestkorea/client-sens",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "INGESTKOREA SDK NCP SENS Client for Node.js.",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",