@ingestkorea/client-sens 1.5.3 → 1.7.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 (116) hide show
  1. package/README.md +38 -27
  2. package/dist-cjs/SensClient.js +17 -18
  3. package/dist-cjs/commands/GetAlimtalkResultCommand.js +3 -1
  4. package/dist-cjs/commands/GetAlimtalkStatusCommand.js +3 -1
  5. package/dist-cjs/commands/GetAlimtalkTemplateCommand.js +4 -1
  6. package/dist-cjs/commands/ListAlimtalkStatusCommand.js +43 -0
  7. package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +3 -1
  8. package/dist-cjs/commands/SendAlimtalkCommand.js +14 -10
  9. package/dist-cjs/commands/constants.js +12 -1
  10. package/dist-cjs/commands/index.js +1 -0
  11. package/dist-cjs/middleware/index.js +4 -2
  12. package/dist-cjs/middleware/{metadata-ingestkorea.js → middleware-metadata.js} +3 -12
  13. package/dist-cjs/middleware/middleware-retry.js +58 -0
  14. package/dist-cjs/middleware/middleware-sort-headers.js +25 -0
  15. package/dist-cjs/models/ListAlimtalkStatus.js +2 -0
  16. package/dist-cjs/models/MetadataBearer.js +2 -0
  17. package/dist-cjs/models/Middleware.js +2 -0
  18. package/dist-cjs/models/SendAlimtalk.js +2 -0
  19. package/dist-cjs/models/index.js +3 -0
  20. package/dist-cjs/protocols/GetAlimtalkResult.js +8 -28
  21. package/dist-cjs/protocols/GetAlimtalkStatus.js +22 -33
  22. package/dist-cjs/protocols/GetAlimtalkTemplate.js +81 -9
  23. package/dist-cjs/protocols/GetSMSResult.js +7 -9
  24. package/dist-cjs/protocols/GetSMSStatus.js +7 -9
  25. package/dist-cjs/protocols/ListAlimtalkChannels.js +6 -6
  26. package/dist-cjs/protocols/ListAlimtalkStatus.js +45 -0
  27. package/dist-cjs/protocols/ListAlimtalkTemplates.js +20 -54
  28. package/dist-cjs/protocols/SendAlimtalk.js +22 -22
  29. package/dist-cjs/protocols/SendMMS.js +6 -6
  30. package/dist-cjs/protocols/SendSMS.js +6 -6
  31. package/dist-cjs/protocols/constants.js +7 -1
  32. package/dist-cjs/protocols/index.js +2 -0
  33. package/dist-es/SensClient.js +20 -21
  34. package/dist-es/commands/GetAlimtalkResultCommand.js +1 -1
  35. package/dist-es/commands/GetAlimtalkStatusCommand.js +1 -1
  36. package/dist-es/commands/GetAlimtalkTemplateCommand.js +2 -1
  37. package/dist-es/commands/ListAlimtalkStatusCommand.js +38 -0
  38. package/dist-es/commands/ListAlimtalkTemplatesCommand.js +1 -1
  39. package/dist-es/commands/SendAlimtalkCommand.js +18 -14
  40. package/dist-es/commands/SendMMSCommand.js +1 -1
  41. package/dist-es/commands/SendSMSCommand.js +1 -1
  42. package/dist-es/commands/constants.js +10 -0
  43. package/dist-es/commands/index.js +1 -0
  44. package/dist-es/index.js +2 -2
  45. package/dist-es/middleware/index.js +4 -2
  46. package/dist-es/middleware/middleware-metadata.js +6 -0
  47. package/dist-es/middleware/middleware-retry.js +51 -0
  48. package/dist-es/middleware/middleware-sort-headers.js +12 -0
  49. package/dist-es/models/ListAlimtalkStatus.js +1 -0
  50. package/dist-es/models/MetadataBearer.js +1 -0
  51. package/dist-es/models/Middleware.js +1 -0
  52. package/dist-es/models/SendAlimtalk.js +2 -0
  53. package/dist-es/models/index.js +3 -0
  54. package/dist-es/protocols/GetAlimtalkResult.js +13 -26
  55. package/dist-es/protocols/GetAlimtalkStatus.js +34 -32
  56. package/dist-es/protocols/GetAlimtalkTemplate.js +81 -9
  57. package/dist-es/protocols/GetSMSResult.js +12 -10
  58. package/dist-es/protocols/GetSMSStatus.js +12 -10
  59. package/dist-es/protocols/ListAlimtalkChannels.js +11 -7
  60. package/dist-es/protocols/ListAlimtalkStatus.js +48 -0
  61. package/dist-es/protocols/ListAlimtalkTemplates.js +22 -51
  62. package/dist-es/protocols/SendAlimtalk.js +25 -22
  63. package/dist-es/protocols/SendMMS.js +11 -7
  64. package/dist-es/protocols/SendSMS.js +11 -7
  65. package/dist-es/protocols/constants.js +5 -0
  66. package/dist-es/protocols/index.js +2 -0
  67. package/dist-types/SensClient.d.ts +2 -2
  68. package/dist-types/commands/GetAlimtalkResultCommand.d.ts +6 -3
  69. package/dist-types/commands/GetAlimtalkStatusCommand.d.ts +6 -3
  70. package/dist-types/commands/GetAlimtalkTemplateCommand.d.ts +6 -3
  71. package/dist-types/commands/GetSMSResultCommand.d.ts +6 -3
  72. package/dist-types/commands/GetSMSStatusCommand.d.ts +6 -3
  73. package/dist-types/commands/ListAlimtalkChannelsCommand.d.ts +6 -3
  74. package/dist-types/commands/ListAlimtalkStatusCommand.d.ts +16 -0
  75. package/dist-types/commands/ListAlimtalkTemplatesCommand.d.ts +6 -3
  76. package/dist-types/commands/SendAlimtalkCommand.d.ts +6 -3
  77. package/dist-types/commands/SendMMSCommand.d.ts +6 -3
  78. package/dist-types/commands/SendSMSCommand.d.ts +6 -3
  79. package/dist-types/commands/constants.d.ts +4 -0
  80. package/dist-types/commands/index.d.ts +1 -0
  81. package/dist-types/index.d.ts +2 -2
  82. package/dist-types/middleware/index.d.ts +4 -2
  83. package/dist-types/middleware/middleware-metadata.d.ts +2 -0
  84. package/dist-types/middleware/middleware-retry.d.ts +2 -0
  85. package/dist-types/middleware/middleware-sign.d.ts +2 -0
  86. package/dist-types/middleware/middleware-sort-headers.d.ts +2 -0
  87. package/dist-types/models/GetAlimtalkResult.d.ts +0 -1
  88. package/dist-types/models/GetAlimtalkStatus.d.ts +5 -0
  89. package/dist-types/models/GetAlimtalkTemplate.d.ts +42 -3
  90. package/dist-types/models/ListAlimtalkStatus.d.ts +16 -0
  91. package/dist-types/models/ListAlimtalkTemplates.d.ts +0 -20
  92. package/dist-types/models/MetadataBearer.d.ts +8 -0
  93. package/dist-types/models/Middleware.d.ts +12 -0
  94. package/dist-types/models/SendAlimtalk.d.ts +13 -6
  95. package/dist-types/models/SensCommand.d.ts +5 -1
  96. package/dist-types/models/index.d.ts +3 -0
  97. package/dist-types/protocols/GetAlimtalkResult.d.ts +5 -2
  98. package/dist-types/protocols/GetAlimtalkStatus.d.ts +6 -2
  99. package/dist-types/protocols/GetAlimtalkTemplate.d.ts +10 -3
  100. package/dist-types/protocols/GetSMSResult.d.ts +5 -2
  101. package/dist-types/protocols/GetSMSStatus.d.ts +5 -2
  102. package/dist-types/protocols/ListAlimtalkChannels.d.ts +5 -2
  103. package/dist-types/protocols/ListAlimtalkStatus.d.ts +10 -0
  104. package/dist-types/protocols/ListAlimtalkTemplates.d.ts +8 -6
  105. package/dist-types/protocols/SendAlimtalk.d.ts +6 -2
  106. package/dist-types/protocols/SendMMS.d.ts +5 -2
  107. package/dist-types/protocols/SendSMS.d.ts +5 -2
  108. package/dist-types/protocols/constants.d.ts +2 -0
  109. package/dist-types/protocols/index.d.ts +2 -0
  110. package/package.json +3 -2
  111. package/.prettierignore +0 -3
  112. package/dist-es/middleware/metadata-ingestkorea.js +0 -19
  113. package/dist-types/middleware/metadata-ingestkorea.d.ts +0 -3
  114. package/dist-types/middleware/signer-ncp.d.ts +0 -3
  115. /package/dist-cjs/middleware/{signer-ncp.js → middleware-sign.js} +0 -0
  116. /package/dist-es/middleware/{signer-ncp.js → middleware-sign.js} +0 -0
package/README.md CHANGED
@@ -34,6 +34,7 @@ npm install @ingestkorea/client-sens
34
34
  - GetAlimtalkStatus
35
35
  - GetAlimtalkResult
36
36
  - GetAlimtalkTemplate
37
+ - ListAlimtalkStatus
37
38
  - ListAlimtalkTemplates
38
39
  - ListAlimtalkChannels
39
40
 
@@ -47,15 +48,7 @@ npm install @ingestkorea/client-sens
47
48
  ### Import
48
49
 
49
50
  ```ts
50
- import {
51
- SensClient,
52
- SendAlimtalkCommand,
53
- SendAlimtalkCommandInput,
54
- SendSMSCommand,
55
- SendSMSCommandInput,
56
- SendMMSCommand,
57
- SendMMSCommandInput,
58
- } from "@ingestkorea/client-sens";
51
+ import { SensClient, SendAlimtalkCommand, SendSMSCommand, SendMMSCommand } from "@ingestkorea/client-sens";
59
52
  ```
60
53
 
61
54
  ### Usage
@@ -91,36 +84,54 @@ const client = new SensClient({
91
84
  #### SendAlimtalk
92
85
 
93
86
  ```ts
94
- let params: SendAlimtalkCommandInput = {
87
+ let command = new SendAlimtalkCommand({
95
88
  plusFriendId: PLUS_FRIEND_ID,
96
89
  templateCode: TEMPLATE_CODE,
97
90
  messages: [{ to: "01012345678", content: CONTENT }],
98
- };
99
- let command = new SendAlimtalkCommand(params);
91
+ });
92
+ ```
93
+
94
+ #### ListAlimtalkStatus
95
+
96
+ ```ts
97
+ let command = new ListAlimtalkStatusCommand({
98
+ plusFriendId: CHANNEL_ID,
99
+ requestStartTime: "yyyy-MM-ddTHH:mm:ss.SSS", // Optional(KST) // default: current - 24hours
100
+ requestEndTime: "yyyy-MM-ddTHH:mm:ss.SSS", // Optional(KST) // default: current
101
+ });
102
+ ```
103
+
104
+ #### GetAlimtalkStatus
105
+
106
+ ```ts
107
+ let command = new GetAlimtalkStatusCommand({
108
+ requestId: REQUEST_ID,
109
+ });
100
110
  ```
101
111
 
102
112
  #### SendSMS (SMS, LMS)
103
113
 
104
114
  ```ts
105
- /**
106
- * Automatically set message type('SMS' | 'LMS') according to content-length(euc-kr)
107
- * SMS: max 90bytes
108
- * LMS: max 2000bytes
109
- */
110
- let params: SendSMSCommandInput = {
115
+ let command = new SendSMSCommand({
111
116
  from: '01012345678',
112
117
  content: DEFAULT_CONTENT,
113
118
  messages: [
114
119
  { to: '0109182xxxx' },
115
- { to: '0104321xxxx', content?: OPTIONAL_CONTENT_01 }
116
- { to: '0108765xxxx', content?: OPTIONAL_CONTENT_02, subject?: OPTIONAL_SUBJECT_01 },
120
+ { to: '0104321xxxx', content?: ONTENT_01 }
121
+ { to: '0108765xxxx', content?: CONTENT_02, subject?: SUBJECT_01 },
117
122
  ]
118
- };
123
+ });
124
+
125
+ /**
126
+ * Automatically set message type('SMS' | 'LMS') according to content-length(euc-kr)
127
+ * SMS: max 90bytes
128
+ * LMS: max 2000bytes
129
+ */
130
+
119
131
  /**
120
132
  * If you do not define the subject and content within the messages,
121
133
  * it is sent with the value specified as the default subject('제목없음') and content.
122
134
  */
123
- let command = new SendSMSCommand(params);
124
135
  ```
125
136
 
126
137
  #### SendMMS (MMS)
@@ -128,13 +139,13 @@ let command = new SendSMSCommand(params);
128
139
  ```ts
129
140
  import { readFileSync } from 'node:fs';
130
141
 
131
- let params: SendMMSCommandInput = {
142
+ let command = new SendMMSCommand({
132
143
  from: '01012345678',
133
144
  content: DEFAULT_CONTENT,
134
145
  messages: [
135
146
  { to: '0109182xxxx' },
136
- { to: '0104321xxxx', content?: OPTIONAL_CONTENT_01 }
137
- { to: '0108765xxxx', content?: OPTIONAL_CONTENT_02, subject?: OPTIONAL_SUBJECT_01 },
147
+ { to: '0104321xxxx', content?: CONTENT_01 }
148
+ { to: '0108765xxxx', content?: CONTENT_02, subject?: SUBJECT_01 },
138
149
  ],
139
150
  files: [ // support jpg, jpeg
140
151
  { name: '/your/absolute/path/sample-image-1.jpg' },
@@ -143,12 +154,12 @@ let params: SendMMSCommandInput = {
143
154
  body?: readFileSync('/your/absolute/path/sample-image-2.jpg', { encoding: 'base64' })
144
155
  }
145
156
  ]
146
- };
157
+ });
158
+
147
159
  /**
148
160
  * If you do not define the subject and content within the messages,
149
161
  * it is sent with the value specified as the default subject('제목없음') and content.
150
162
  */
151
- let command = new SendMMSCommand(params);
152
163
  ```
153
164
 
154
165
  #### Async/await
@@ -13,53 +13,52 @@ exports.SensClient = void 0;
13
13
  const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const util_error_handler_1 = require("@ingestkorea/util-error-handler");
15
15
  const middleware_1 = require("./middleware");
16
- ;
17
- ;
18
16
  class SensClient {
19
17
  constructor(config) {
20
- const resolvedCredentials = resolveCredentials(config);
21
- const resolvedServiceId = resolveServiceId(config);
22
18
  this.config = {
23
- credentials: Object.assign({}, resolvedCredentials),
24
- serviceId: Object.assign({}, resolvedServiceId)
19
+ credentials: resolveCredentials(config),
20
+ serviceId: resolveServiceId(config),
25
21
  };
26
22
  this.requestHandler = new util_http_handler_1.NodeHttpHandler({ connectionTimeout: 3000, socketTimeout: 3000 });
27
23
  }
28
- ;
29
24
  send(command) {
30
25
  return __awaiter(this, void 0, void 0, function* () {
31
26
  let input = command.input;
32
27
  let request = yield command.serialize(input, this.config);
33
28
  request = yield (0, middleware_1.middlewareNcpSigner)(request, this.config);
34
29
  request = yield (0, middleware_1.middlewareIngestkoreaMetadata)(request, this.config);
35
- let { response } = yield this.requestHandler.handle(request);
30
+ request = yield (0, middleware_1.middlewareSortHeaders)(request, this.config);
31
+ let response = yield (0, middleware_1.middlewareRetry)(request, this.config, this.requestHandler);
36
32
  let output = yield command.deserialize(response);
37
33
  return output;
38
34
  });
39
35
  }
40
- ;
41
36
  }
42
37
  exports.SensClient = SensClient;
43
- ;
44
38
  const resolveCredentials = (config) => {
45
39
  const { credentials } = config;
46
40
  if (!credentials)
47
41
  throw new util_error_handler_1.IngestkoreaError({
48
- code: 401, type: 'Unauthorized',
49
- message: 'Invalid Credentials', description: 'Invalid Credentials'
42
+ code: 401,
43
+ type: "Unauthorized",
44
+ message: "Invalid Credentials",
45
+ description: "Invalid Credentials",
50
46
  });
51
47
  return credentials;
52
48
  };
53
49
  const resolveServiceId = (config) => {
54
50
  const { serviceId } = config;
55
- if (!serviceId)
56
- throw new util_error_handler_1.IngestkoreaError({
57
- code: 401, type: 'Unauthorized',
58
- message: 'Invalid Credentials', description: 'Invalid ServiceId'
59
- });
51
+ const lastError = new util_error_handler_1.IngestkoreaError({
52
+ code: 401,
53
+ type: "Unauthorized",
54
+ message: "Invalid Credentials",
55
+ description: "Invalid ServiceId",
56
+ });
57
+ if (!serviceId || !Object.keys(serviceId).length)
58
+ throw lastError;
60
59
  return {
61
60
  push: serviceId.push != undefined ? serviceId.push : undefined,
62
61
  sms: serviceId.sms != undefined ? serviceId.sms : undefined,
63
- kakao: serviceId.kakao != undefined ? serviceId.kakao : undefined
62
+ kakao: serviceId.kakao != undefined ? serviceId.kakao : undefined,
64
63
  };
65
64
  };
@@ -16,7 +16,9 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
16
  class GetAlimtalkResultCommand extends models_1.SensCommand {
17
17
  constructor(input) {
18
18
  super(input);
19
- this.input = Object.assign({}, input);
19
+ this.input = {
20
+ messageId: input.messageId,
21
+ };
20
22
  }
21
23
  serialize(input, config) {
22
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -16,7 +16,9 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
16
  class GetAlimtalkStatusCommand extends models_1.SensCommand {
17
17
  constructor(input) {
18
18
  super(input);
19
- this.input = Object.assign({}, input);
19
+ this.input = {
20
+ requestId: input.requestId,
21
+ };
20
22
  }
21
23
  serialize(input, config) {
22
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -16,7 +16,10 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
16
  class GetAlimtalkTemplateCommand extends models_1.SensCommand {
17
17
  constructor(input) {
18
18
  super(input);
19
- this.input = Object.assign({}, input);
19
+ this.input = {
20
+ channelId: input.channelId,
21
+ templateCode: input.templateCode,
22
+ };
20
23
  }
21
24
  serialize(input, config) {
22
25
  return __awaiter(this, void 0, void 0, function* () {
@@ -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.ListAlimtalkStatusCommand = void 0;
13
+ const models_1 = require("../models");
14
+ const ListAlimtalkStatus_1 = require("../protocols/ListAlimtalkStatus");
15
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
+ const constants_1 = require("./constants");
17
+ class ListAlimtalkStatusCommand extends models_1.SensCommand {
18
+ constructor(input) {
19
+ super(input);
20
+ const { startTime, endTime } = (0, constants_1.getRequestDuration)();
21
+ this.input = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ plusFriendId: input.plusFriendId }, (input.requestId && { requestId: input.requestId })), (input.messageId && { messageId: input.messageId })), (input.requestStatusName && { requestStatusName: input.requestStatusName })), (input.messageStatusName && { messageStatusName: input.messageStatusName })), (input.templateCode && { templateCode: input.templateCode })), (input.to && { to: input.to.replace(/\-/gi, "") })), { requestStartTime: input.requestStartTime ? input.requestStartTime : startTime, requestEndTime: input.requestEndTime ? input.requestEndTime : endTime, pageIndex: input.pageIndex ? input.pageIndex : 0, pageSize: input.pageSize && input.pageSize <= 100 ? input.pageSize : 20 });
22
+ }
23
+ serialize(input, config) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (!config.serviceId.kakao)
26
+ throw new util_error_handler_1.IngestkoreaError({
27
+ code: 400,
28
+ type: "Bad Request",
29
+ message: "Invalid Params",
30
+ description: "Please Check Kakao ServiceId",
31
+ });
32
+ let request = yield (0, ListAlimtalkStatus_1.serializeIngestkorea_restJson_ListAlimtalkStatusCommand)(input, config);
33
+ return request;
34
+ });
35
+ }
36
+ deserialize(response) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ let output = yield (0, ListAlimtalkStatus_1.deserializeIngestkorea_restJson_ListAlimtalkStatusCommand)(response);
39
+ return output;
40
+ });
41
+ }
42
+ }
43
+ exports.ListAlimtalkStatusCommand = ListAlimtalkStatusCommand;
@@ -16,7 +16,9 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
16
  class ListAlimtalkTemplatesCommand extends models_1.SensCommand {
17
17
  constructor(input) {
18
18
  super(input);
19
- this.input = Object.assign({}, input);
19
+ this.input = {
20
+ channelId: input.channelId,
21
+ };
20
22
  }
21
23
  serialize(input, config) {
22
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -16,7 +16,7 @@ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
16
  class SendAlimtalkCommand extends models_1.SensCommand {
17
17
  constructor(input) {
18
18
  super(input);
19
- this.input = Object.assign(Object.assign({}, input), { plusFriendId: input.plusFriendId, templateCode: input.templateCode, messages: input.messages.map(resolveAlimtalkMessage) });
19
+ this.input = Object.assign(Object.assign({}, input), { plusFriendId: input.plusFriendId, templateCode: input.templateCode, messages: resolveAlimtalkMessage(input.messages) });
20
20
  }
21
21
  serialize(input, config) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -39,14 +39,18 @@ class SendAlimtalkCommand extends models_1.SensCommand {
39
39
  }
40
40
  }
41
41
  exports.SendAlimtalkCommand = SendAlimtalkCommand;
42
- const resolveAlimtalkMessage = (message) => {
42
+ const resolveAlimtalkMessage = (messages) => {
43
43
  const ALIMTALK_MAX = 1000;
44
- if (message.content.length > ALIMTALK_MAX)
45
- throw new util_error_handler_1.IngestkoreaError({
46
- code: 400,
47
- type: "Bad Request",
48
- message: "Invalid Params",
49
- description: `Maximum message length is ${ALIMTALK_MAX}`,
50
- });
51
- return Object.assign({ to: message.to.replace(/\-/gi, ""), content: message.content }, (message.buttons != undefined && { buttons: message.buttons }));
44
+ const lastError = new util_error_handler_1.IngestkoreaError({
45
+ code: 400,
46
+ type: "Bad Request",
47
+ message: "Invalid Params",
48
+ description: `Maximum message length is ${ALIMTALK_MAX}`,
49
+ });
50
+ const result = messages.map((message) => {
51
+ if (message.content.length > ALIMTALK_MAX)
52
+ throw lastError;
53
+ return Object.assign({ to: message.to.replace(/\-/gi, ""), content: message.content }, (message.buttons && message.buttons.length && { buttons: message.buttons }));
54
+ });
55
+ return result;
52
56
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentLength = exports.prettyPhoneNum = exports.trimText = exports.MMS_FILE_MAX = exports.LMS_MAX = exports.SMS_MAX = void 0;
3
+ exports.getRequestDuration = exports.getContentLength = exports.prettyPhoneNum = exports.trimText = exports.MMS_FILE_MAX = exports.LMS_MAX = exports.SMS_MAX = void 0;
4
4
  exports.SMS_MAX = 90;
5
5
  exports.LMS_MAX = 2000;
6
6
  exports.MMS_FILE_MAX = 300; // KiByte
@@ -18,3 +18,14 @@ const getContentLength = (input) => {
18
18
  }, 0);
19
19
  };
20
20
  exports.getContentLength = getContentLength;
21
+ const getRequestDuration = (input) => {
22
+ const OFFSET = 9 * 60 * 60 * 1000;
23
+ const hours = input ? Math.abs(input) : 24;
24
+ const hours_ms = hours * 60 * 60 * 1000;
25
+ const current_ms = new Date().getTime() + OFFSET;
26
+ const startTime_ms = current_ms - hours_ms;
27
+ let current_kst = new Date(current_ms).toISOString().replace(/\.\d{3}Z$/, "");
28
+ let startTime_kst = new Date(startTime_ms).toISOString().replace(/\.\d{3}Z$/, "");
29
+ return { startTime: startTime_kst, endTime: current_kst };
30
+ };
31
+ exports.getRequestDuration = getRequestDuration;
@@ -18,6 +18,7 @@ __exportStar(require("./SendAlimtalkCommand"), exports);
18
18
  __exportStar(require("./GetAlimtalkStatusCommand"), exports);
19
19
  __exportStar(require("./GetAlimtalkResultCommand"), exports);
20
20
  __exportStar(require("./GetAlimtalkTemplateCommand"), exports);
21
+ __exportStar(require("./ListAlimtalkStatusCommand"), exports);
21
22
  __exportStar(require("./ListAlimtalkTemplatesCommand"), exports);
22
23
  __exportStar(require("./ListAlimtalkChannelsCommand"), exports);
23
24
  __exportStar(require("./SendSMSCommand"), exports);
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./signer-ncp"), exports);
18
- __exportStar(require("./metadata-ingestkorea"), exports);
17
+ __exportStar(require("./middleware-sign"), exports);
18
+ __exportStar(require("./middleware-metadata"), exports);
19
+ __exportStar(require("./middleware-retry"), exports);
20
+ __exportStar(require("./middleware-sort-headers"), exports);
@@ -10,19 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.middlewareIngestkoreaMetadata = void 0;
13
+ const REQUEST_HEADER = "x-ingestkorea-request";
13
14
  const middlewareIngestkoreaMetadata = (request, config) => __awaiter(void 0, void 0, void 0, function* () {
14
- const { longDate } = yield convertFormatDate(request.headers["x-ncp-apigw-timestamp"]);
15
- request.headers = Object.assign(Object.assign({}, request.headers), { ["x-ingestkorea-date"]: longDate, ["x-ingestkorea-user-agent"]: "@ingestkorea/client-sens/1.5.x" });
15
+ request.headers["x-ingestkorea-user-agent"] = "@ingestkorea/client-sens/1.7.x";
16
+ request.headers[REQUEST_HEADER] = "attempt=1";
16
17
  return request;
17
18
  });
18
19
  exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
19
- /**
20
- * @param input milliseconds
21
- */
22
- const convertFormatDate = (input) => __awaiter(void 0, void 0, void 0, function* () {
23
- let milliseconds = input ? Number(input) : new Date().getTime();
24
- let iso8601 = new Date(milliseconds).toISOString().replace(/\.\d{3}Z$/, "Z");
25
- let longDate = iso8601.replace(/[\-:]/g, "");
26
- let shortDate = longDate.slice(0, 8);
27
- return { longDate, shortDate };
28
- });
@@ -0,0 +1,58 @@
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.middlewareRetry = void 0;
13
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
14
+ const REQUEST_HEADER = "x-ingestkorea-request";
15
+ const middlewareRetry = (request, config, handler) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const maxAttempts = 3;
17
+ let attempts = 0;
18
+ let totalRetryDelay = 0;
19
+ let lastError = new util_error_handler_1.IngestkoreaError({
20
+ code: 400,
21
+ type: "Bad Request",
22
+ message: "Invalid Request",
23
+ description: { attempts, maxAttempts, totalRetryDelay },
24
+ });
25
+ while (true) {
26
+ try {
27
+ request.headers[REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}; totalRetryDelay=${totalRetryDelay}`;
28
+ let { response } = yield handler.handle(request);
29
+ return {
30
+ output: {
31
+ $metadata: {
32
+ attempts: attempts + 1,
33
+ totalRetryDelay: totalRetryDelay,
34
+ },
35
+ },
36
+ response,
37
+ };
38
+ }
39
+ catch (err) {
40
+ attempts++;
41
+ if (attempts == maxAttempts) {
42
+ lastError.error.description.attempts = attempts;
43
+ throw lastError;
44
+ }
45
+ const delay = attempts * 1000;
46
+ totalRetryDelay += delay;
47
+ lastError.error.description = { attempts, maxAttempts, totalRetryDelay };
48
+ if (err instanceof util_error_handler_1.IngestkoreaError) {
49
+ lastError.error.description = Object.assign(Object.assign({}, lastError.error.description), { detail: err.error.description });
50
+ }
51
+ if (err instanceof Error) {
52
+ lastError.error.description = Object.assign(Object.assign({}, lastError.error.description), { detail: err.message });
53
+ }
54
+ yield new Promise((resolve) => setTimeout(resolve, delay));
55
+ }
56
+ }
57
+ });
58
+ exports.middlewareRetry = middlewareRetry;
@@ -0,0 +1,25 @@
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.middlewareSortHeaders = void 0;
13
+ const middlewareSortHeaders = (request, config) => __awaiter(void 0, void 0, void 0, function* () {
14
+ let { headers } = request;
15
+ let init = {};
16
+ const resolvedHeaders = Object.keys(headers)
17
+ .sort()
18
+ .reduce((acc, curr) => {
19
+ acc[curr] = headers[curr];
20
+ return acc;
21
+ }, init);
22
+ request.headers = resolvedHeaders;
23
+ return request;
24
+ });
25
+ exports.middlewareSortHeaders = middlewareSortHeaders;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ALIMTALK_BUTTON_TYPES = ["DS", "WL", "AL", "BK", "MD", "AC"];
4
+ const ALIMTALK_BUTTON_NAMES = ["배송 조회", "웹 링크", "앱 링크", "봇 키워드", "메시지 전달", "채널 추가"];
@@ -14,11 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MetadataBearer"), exports);
18
+ __exportStar(require("./Middleware"), exports);
17
19
  __exportStar(require("./SensCommand"), exports);
18
20
  __exportStar(require("./SendAlimtalk"), exports);
19
21
  __exportStar(require("./GetAlimtalkStatus"), exports);
20
22
  __exportStar(require("./GetAlimtalkResult"), exports);
21
23
  __exportStar(require("./GetAlimtalkTemplate"), exports);
24
+ __exportStar(require("./ListAlimtalkStatus"), exports);
22
25
  __exportStar(require("./ListAlimtalkTemplates"), exports);
23
26
  __exportStar(require("./ListAlimtalkChannels"), exports);
24
27
  __exportStar(require("./SendSMS"), exports);
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.deserializeIngestkorea_restJson_AlimtalkFailover = exports.deserializeIngestkorea_restJson_GetAlimtalkResultOutput = exports.deserializeIngestkorea_restJson_GetAlimtalkResultCommand = exports.serializeIngestkorea_restJson_GetAlimtalkResultCommand = void 0;
13
13
  const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
- const constants_1 = require("./constants");
14
+ const _1 = require("./");
15
15
  const serializeIngestkorea_restJson_GetAlimtalkResultCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const hostname = "sens.apigw.ntruss.com";
17
17
  const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages/" + input.messageId;
@@ -27,38 +27,18 @@ const serializeIngestkorea_restJson_GetAlimtalkResultCommand = (input, config) =
27
27
  });
28
28
  });
29
29
  exports.serializeIngestkorea_restJson_GetAlimtalkResultCommand = serializeIngestkorea_restJson_GetAlimtalkResultCommand;
30
- const deserializeIngestkorea_restJson_GetAlimtalkResultCommand = (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); // GetAlimtalkResultOutput
30
+ const deserializeIngestkorea_restJson_GetAlimtalkResultCommand = (response) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const { response: httpResponse, output } = response;
32
+ if (httpResponse.statusCode > 300)
33
+ yield (0, _1.parseErrorBody)(httpResponse);
34
+ const data = yield (0, _1.parseBody)(httpResponse);
34
35
  let contents = {};
35
36
  contents = yield (0, exports.deserializeIngestkorea_restJson_GetAlimtalkResultOutput)(data);
36
- const response = Object.assign({}, contents);
37
- return response;
37
+ return Object.assign({ $metadata: Object.assign(Object.assign({}, (0, _1.deserializeMetadata)(httpResponse)), output.$metadata) }, contents);
38
38
  });
39
39
  exports.deserializeIngestkorea_restJson_GetAlimtalkResultCommand = deserializeIngestkorea_restJson_GetAlimtalkResultCommand;
40
40
  const deserializeIngestkorea_restJson_GetAlimtalkResultOutput = (output) => __awaiter(void 0, void 0, void 0, function* () {
41
- return {
42
- requestId: output.requestId != undefined ? output.requestId : undefined,
43
- messageId: output.messageId != undefined ? output.messageId : undefined,
44
- to: output.to != undefined ? output.to : undefined,
45
- countryCode: output.countryCode != undefined ? output.countryCode : undefined,
46
- content: output.content != undefined ? output.content : undefined,
47
- requestStatusCode: output.requestStatusCode != undefined ? output.requestStatusCode : undefined,
48
- requestStatusName: output.requestStatusName != undefined ? output.requestStatusName : undefined,
49
- requestStatusDesc: output.requestStatusDesc != undefined ? output.requestStatusDesc : undefined,
50
- useSmsFailover: output.useSmsFailover != undefined ? output.useSmsFailover : undefined,
51
- requestTime: output.requestTime != undefined ? output.requestTime : undefined,
52
- plusFriendId: output.plusFriendId != undefined ? output.plusFriendId : undefined,
53
- templateCode: output.templateCode != undefined ? output.templateCode : undefined,
54
- completeTime: output.completeTime != undefined ? output.completeTime : undefined,
55
- messageStatusCode: output.messageStatusCode != undefined ? output.messageStatusCode : undefined,
56
- messageStatusName: output.messageStatusName != undefined ? output.messageStatusName : undefined,
57
- messageStatusDesc: output.messageStatusDesc != undefined ? output.messageStatusDesc : undefined,
58
- failover: output.failover != undefined
59
- ? (0, exports.deserializeIngestkorea_restJson_AlimtalkFailover)(output.failover)
60
- : undefined,
61
- };
41
+ return Object.assign(Object.assign({}, (0, _1.parseStatusMessage)(output)), { failover: output.failover != undefined ? (0, exports.deserializeIngestkorea_restJson_AlimtalkFailover)(output.failover) : undefined });
62
42
  });
63
43
  exports.deserializeIngestkorea_restJson_GetAlimtalkResultOutput = deserializeIngestkorea_restJson_GetAlimtalkResultOutput;
64
44
  const deserializeIngestkorea_restJson_AlimtalkFailover = (output) => {