@ingestkorea/client-sens 1.7.0 → 1.8.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 (148) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +98 -63
  3. package/dist-cjs/SensClient.js +57 -28
  4. package/dist-cjs/commands/GetAlimtalkResultCommand.js +5 -32
  5. package/dist-cjs/commands/GetAlimtalkStatusCommand.js +9 -35
  6. package/dist-cjs/commands/GetAlimtalkTemplateCommand.js +5 -32
  7. package/dist-cjs/commands/GetSMSResultCommand.js +8 -33
  8. package/dist-cjs/commands/GetSMSStatusCommand.js +8 -33
  9. package/dist-cjs/commands/ListAlimtalkChannelsCommand.js +6 -33
  10. package/dist-cjs/commands/ListAlimtalkStatusCommand.js +19 -35
  11. package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +5 -32
  12. package/dist-cjs/commands/SendAlimtalkCommand.js +35 -43
  13. package/dist-cjs/commands/SendMMSCommand.js +67 -103
  14. package/dist-cjs/commands/SendSMSCommand.js +38 -71
  15. package/dist-cjs/commands/constants.js +1 -15
  16. package/dist-cjs/commands/index.js +11 -11
  17. package/dist-cjs/index.js +2 -2
  18. package/dist-cjs/middleware/constants.js +10 -0
  19. package/dist-cjs/middleware/index.js +3 -4
  20. package/dist-cjs/middleware/middleware-metadata.js +4 -5
  21. package/dist-cjs/middleware/middleware-retry.js +32 -27
  22. package/dist-cjs/middleware/middleware-sign.js +10 -9
  23. package/dist-cjs/models/SendAlimtalk.js +3 -0
  24. package/dist-cjs/models/SendMMS.js +3 -0
  25. package/dist-cjs/models/SensErrorInfo.js +13 -0
  26. package/dist-cjs/models/SensMiddleware.js +2 -0
  27. package/dist-cjs/models/index.js +16 -14
  28. package/dist-cjs/protocols/GetAlimtalkResult.js +19 -22
  29. package/dist-cjs/protocols/GetAlimtalkStatus.js +36 -37
  30. package/dist-cjs/protocols/GetAlimtalkTemplate.js +56 -90
  31. package/dist-cjs/protocols/GetSMSResult.js +30 -48
  32. package/dist-cjs/protocols/GetSMSStatus.js +31 -34
  33. package/dist-cjs/protocols/ListAlimtalkChannels.js +27 -31
  34. package/dist-cjs/protocols/ListAlimtalkStatus.js +22 -19
  35. package/dist-cjs/protocols/ListAlimtalkTemplates.js +31 -23
  36. package/dist-cjs/protocols/SendAlimtalk.js +22 -26
  37. package/dist-cjs/protocols/SendMMS.js +8 -38
  38. package/dist-cjs/protocols/SendSMS.js +19 -21
  39. package/dist-cjs/protocols/constants.js +98 -34
  40. package/dist-es/SensClient.js +63 -30
  41. package/dist-es/commands/GetAlimtalkResultCommand.js +9 -19
  42. package/dist-es/commands/GetAlimtalkStatusCommand.js +14 -19
  43. package/dist-es/commands/GetAlimtalkTemplateCommand.js +9 -19
  44. package/dist-es/commands/GetSMSResultCommand.js +10 -20
  45. package/dist-es/commands/GetSMSStatusCommand.js +10 -20
  46. package/dist-es/commands/ListAlimtalkChannelsCommand.js +10 -22
  47. package/dist-es/commands/ListAlimtalkStatusCommand.js +28 -27
  48. package/dist-es/commands/ListAlimtalkTemplatesCommand.js +9 -19
  49. package/dist-es/commands/SendAlimtalkCommand.js +34 -30
  50. package/dist-es/commands/SendMMSCommand.js +70 -100
  51. package/dist-es/commands/SendSMSCommand.js +51 -66
  52. package/dist-es/commands/constants.js +9 -16
  53. package/dist-es/commands/index.js +27 -11
  54. package/dist-es/index.js +18 -2
  55. package/dist-es/middleware/constants.js +10 -0
  56. package/dist-es/middleware/index.js +19 -4
  57. package/dist-es/middleware/middleware-metadata.js +11 -5
  58. package/dist-es/middleware/middleware-retry.js +39 -30
  59. package/dist-es/middleware/middleware-sign.js +19 -14
  60. package/dist-es/models/GetAlimtalkResult.js +2 -1
  61. package/dist-es/models/GetAlimtalkStatus.js +2 -1
  62. package/dist-es/models/GetAlimtalkTemplate.js +2 -1
  63. package/dist-es/models/GetSMSResult.js +2 -1
  64. package/dist-es/models/GetSMSStatus.js +2 -1
  65. package/dist-es/models/ListAlimtalkChannels.js +2 -1
  66. package/dist-es/models/ListAlimtalkStatus.js +2 -1
  67. package/dist-es/models/ListAlimtalkTemplates.js +2 -1
  68. package/dist-es/models/MetadataBearer.js +2 -1
  69. package/dist-es/models/SendAlimtalk.js +5 -1
  70. package/dist-es/models/SendMMS.js +5 -1
  71. package/dist-es/models/SendSMS.js +2 -1
  72. package/dist-es/models/SensClient.js +2 -0
  73. package/dist-es/models/SensCommand.js +5 -1
  74. package/dist-es/models/SensErrorInfo.js +13 -0
  75. package/dist-es/models/SensMiddleware.js +2 -0
  76. package/dist-es/models/index.js +32 -14
  77. package/dist-es/protocols/GetAlimtalkResult.js +24 -23
  78. package/dist-es/protocols/GetAlimtalkStatus.js +40 -36
  79. package/dist-es/protocols/GetAlimtalkTemplate.js +78 -87
  80. package/dist-es/protocols/GetSMSResult.js +44 -47
  81. package/dist-es/protocols/GetSMSStatus.js +35 -34
  82. package/dist-es/protocols/ListAlimtalkChannels.js +31 -31
  83. package/dist-es/protocols/ListAlimtalkStatus.js +26 -32
  84. package/dist-es/protocols/ListAlimtalkTemplates.js +35 -22
  85. package/dist-es/protocols/SendAlimtalk.js +26 -25
  86. package/dist-es/protocols/SendMMS.js +10 -49
  87. package/dist-es/protocols/SendSMS.js +23 -30
  88. package/dist-es/protocols/constants.js +112 -37
  89. package/dist-types/SensClient.d.ts +3 -20
  90. package/dist-types/commands/GetAlimtalkResultCommand.d.ts +5 -10
  91. package/dist-types/commands/GetAlimtalkStatusCommand.d.ts +5 -10
  92. package/dist-types/commands/GetAlimtalkTemplateCommand.d.ts +5 -10
  93. package/dist-types/commands/GetSMSResultCommand.d.ts +5 -10
  94. package/dist-types/commands/GetSMSStatusCommand.d.ts +5 -10
  95. package/dist-types/commands/ListAlimtalkChannelsCommand.d.ts +5 -10
  96. package/dist-types/commands/ListAlimtalkStatusCommand.d.ts +5 -10
  97. package/dist-types/commands/ListAlimtalkTemplatesCommand.d.ts +5 -10
  98. package/dist-types/commands/SendAlimtalkCommand.d.ts +5 -10
  99. package/dist-types/commands/SendMMSCommand.d.ts +5 -10
  100. package/dist-types/commands/SendSMSCommand.d.ts +9 -10
  101. package/dist-types/commands/constants.d.ts +0 -7
  102. package/dist-types/commands/index.d.ts +11 -11
  103. package/dist-types/index.d.ts +2 -2
  104. package/dist-types/middleware/constants.d.ts +7 -0
  105. package/dist-types/middleware/index.d.ts +3 -4
  106. package/dist-types/middleware/middleware-metadata.d.ts +2 -2
  107. package/dist-types/middleware/middleware-retry.d.ts +2 -2
  108. package/dist-types/middleware/middleware-sign.d.ts +2 -2
  109. package/dist-types/models/GetAlimtalkResult.d.ts +3 -3
  110. package/dist-types/models/GetAlimtalkStatus.d.ts +8 -5
  111. package/dist-types/models/GetAlimtalkTemplate.d.ts +5 -5
  112. package/dist-types/models/GetSMSResult.d.ts +5 -9
  113. package/dist-types/models/GetSMSStatus.d.ts +4 -4
  114. package/dist-types/models/ListAlimtalkChannels.d.ts +4 -4
  115. package/dist-types/models/ListAlimtalkStatus.d.ts +8 -8
  116. package/dist-types/models/ListAlimtalkTemplates.d.ts +2 -2
  117. package/dist-types/models/MetadataBearer.d.ts +3 -3
  118. package/dist-types/models/SendAlimtalk.d.ts +6 -4
  119. package/dist-types/models/SendMMS.d.ts +5 -3
  120. package/dist-types/models/SendSMS.d.ts +2 -2
  121. package/dist-types/models/SensClient.d.ts +17 -0
  122. package/dist-types/models/SensCommand.d.ts +4 -6
  123. package/dist-types/models/SensErrorInfo.d.ts +21 -0
  124. package/dist-types/models/SensMiddleware.d.ts +8 -0
  125. package/dist-types/models/index.d.ts +16 -14
  126. package/dist-types/protocols/GetAlimtalkResult.d.ts +4 -11
  127. package/dist-types/protocols/GetAlimtalkStatus.d.ts +6 -12
  128. package/dist-types/protocols/GetAlimtalkTemplate.d.ts +4 -14
  129. package/dist-types/protocols/GetSMSResult.d.ts +4 -12
  130. package/dist-types/protocols/GetSMSStatus.d.ts +5 -11
  131. package/dist-types/protocols/ListAlimtalkChannels.d.ts +4 -11
  132. package/dist-types/protocols/ListAlimtalkStatus.d.ts +4 -10
  133. package/dist-types/protocols/ListAlimtalkTemplates.d.ts +5 -12
  134. package/dist-types/protocols/SendAlimtalk.d.ts +5 -12
  135. package/dist-types/protocols/SendMMS.d.ts +4 -10
  136. package/dist-types/protocols/SendSMS.d.ts +5 -10
  137. package/dist-types/protocols/constants.d.ts +3 -2
  138. package/package.json +20 -4
  139. package/.github/pull_request_template.md +0 -19
  140. package/dist-cjs/middleware/middleware-sort-headers.js +0 -25
  141. package/dist-cjs/protocols/index.js +0 -28
  142. package/dist-es/middleware/middleware-sort-headers.js +0 -12
  143. package/dist-es/models/Middleware.js +0 -1
  144. package/dist-es/protocols/index.js +0 -12
  145. package/dist-types/middleware/middleware-sort-headers.d.ts +0 -2
  146. package/dist-types/models/Middleware.d.ts +0 -12
  147. package/dist-types/protocols/index.d.ts +0 -12
  148. /package/dist-cjs/models/{Middleware.js → SensClient.js} +0 -0
@@ -1,43 +1,27 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  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 {
4
+ const index_js_1 = require("../models/index.js");
5
+ const ListAlimtalkStatus_js_1 = require("../protocols/ListAlimtalkStatus.js");
6
+ const KST_OFFSET = 9 * 60 * 60 * 1000;
7
+ const DURATION_LIMIT = 24 * 60 * 60 * 1000;
8
+ const MAX_LIMIT = 100;
9
+ const DEFAULT_LIMIT = 20;
10
+ class ListAlimtalkStatusCommand extends index_js_1.SensCommand {
18
11
  constructor(input) {
12
+ var _a;
19
13
  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
- });
14
+ const { startTime, endTime } = getDefaultRequestDurationKST({ durationLimit: DURATION_LIMIT });
15
+ this.input = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ plusFriendId: input.plusFriendId, requestStartTime: input.requestStartTime ? input.requestStartTime : startTime, requestEndTime: input.requestEndTime ? input.requestEndTime : endTime, pageSize: Math.min(MAX_LIMIT, Math.max(1, (_a = input.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_LIMIT)) }, (input.requestStatusName && { requestStatusName: input.requestStatusName })), (input.messageStatusName && { messageStatusName: input.messageStatusName })), (input.requestId && { requestId: input.requestId })), (input.messageId && { messageId: input.messageId })), (input.templateCode && { templateCode: input.templateCode })), (input.to && { to: input.to.replace(/\-/gi, "") })), (input.nextToken && { nextToken: input.nextToken }));
16
+ this.serializer = ListAlimtalkStatus_js_1.se_ListAlimtalkStatusCommand;
17
+ this.deserializer = ListAlimtalkStatus_js_1.de_ListAlimtalkStatusCommand;
41
18
  }
42
19
  }
43
20
  exports.ListAlimtalkStatusCommand = ListAlimtalkStatusCommand;
21
+ const getDefaultRequestDurationKST = (config) => {
22
+ const now = new Date().getTime() + KST_OFFSET;
23
+ return {
24
+ startTime: new Date(now - config.durationLimit).toISOString().replace(/\.\d{3}Z$/, ""),
25
+ endTime: new Date(now).toISOString().replace(/\.\d{3}Z$/, ""),
26
+ };
27
+ };
@@ -1,43 +1,16 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ListAlimtalkTemplatesCommand = void 0;
13
- const models_1 = require("../models");
14
- const ListAlimtalkTemplates_1 = require("../protocols/ListAlimtalkTemplates");
15
- const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
- class ListAlimtalkTemplatesCommand extends models_1.SensCommand {
4
+ const index_js_1 = require("../models/index.js");
5
+ const ListAlimtalkTemplates_js_1 = require("../protocols/ListAlimtalkTemplates.js");
6
+ class ListAlimtalkTemplatesCommand extends index_js_1.SensCommand {
17
7
  constructor(input) {
18
8
  super(input);
19
9
  this.input = {
20
10
  channelId: input.channelId,
21
11
  };
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, ListAlimtalkTemplates_1.serializeIngestkorea_restJson_ListAlimtalkTemplatesCommand)(input, config);
33
- return request;
34
- });
35
- }
36
- deserialize(response) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- let output = yield (0, ListAlimtalkTemplates_1.deserializeIngestkorea_restJson_ListAlimtalkTemplatesCommand)(response);
39
- return output;
40
- });
12
+ this.serializer = ListAlimtalkTemplates_js_1.se_ListAlimtalkTemplatesCommand;
13
+ this.deserializer = ListAlimtalkTemplates_js_1.de_ListAlimtalkTemplatesCommand;
41
14
  }
42
15
  }
43
16
  exports.ListAlimtalkTemplatesCommand = ListAlimtalkTemplatesCommand;
@@ -1,55 +1,47 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SendAlimtalkCommand = void 0;
13
- const models_1 = require("../models");
14
- const SendAlimtalk_1 = require("../protocols/SendAlimtalk");
15
- const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
- class SendAlimtalkCommand extends models_1.SensCommand {
4
+ const index_js_1 = require("../models/index.js");
5
+ const SendAlimtalk_js_1 = require("../protocols/SendAlimtalk.js");
6
+ class SendAlimtalkCommand extends index_js_1.SensCommand {
17
7
  constructor(input) {
18
8
  super(input);
19
- this.input = Object.assign(Object.assign({}, input), { plusFriendId: input.plusFriendId, templateCode: input.templateCode, messages: resolveAlimtalkMessage(input.messages) });
20
- }
21
- serialize(input, config) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- if (!config.serviceId.kakao)
24
- throw new util_error_handler_1.IngestkoreaError({
25
- code: 400,
26
- type: "Bad Request",
27
- message: "Invalid Params",
28
- description: "Please Check Kakao ServiceId",
29
- });
30
- let request = yield (0, SendAlimtalk_1.serializeIngestkorea_restJson_SendAlimtalkCommand)(input, config);
31
- return request;
32
- });
33
- }
34
- deserialize(response) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- let output = yield (0, SendAlimtalk_1.deserializeIngestkorea_restJson_SendAlimtalkCommand)(response);
37
- return output;
38
- });
9
+ this.input = {
10
+ plusFriendId: input.plusFriendId,
11
+ templateCode: input.templateCode,
12
+ messages: resolveAlimtalkMessages(input.messages, {
13
+ maxRecipients: index_js_1.ALIMTALK_MAX_RECIPIENTS,
14
+ maxContentLength: index_js_1.ALIMTALK_MAX_CONTENT_LENGTH,
15
+ }),
16
+ };
17
+ this.serializer = SendAlimtalk_js_1.se_SendAlimtalkCommand;
18
+ this.deserializer = SendAlimtalk_js_1.de_SendAlimtalkCommand;
39
19
  }
40
20
  }
41
21
  exports.SendAlimtalkCommand = SendAlimtalkCommand;
42
- const resolveAlimtalkMessage = (messages) => {
43
- const ALIMTALK_MAX = 1000;
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
- });
22
+ const resolveAlimtalkMessages = (messages, config) => {
23
+ if (!messages.length || messages.length > config.maxRecipients) {
24
+ throw new index_js_1.SensError({
25
+ code: 400,
26
+ type: "Bad Request",
27
+ message: "알림톡 동시 발송 범위 오류",
28
+ invalidInputs: [
29
+ {
30
+ type: "not-valid.args",
31
+ message: `메세지 동시 발송은 최소 1명, 최대 ${config.maxRecipients}명까지 가능합니다.`,
32
+ },
33
+ ],
34
+ });
35
+ }
50
36
  const result = messages.map((message) => {
51
- if (message.content.length > ALIMTALK_MAX)
52
- throw lastError;
37
+ if (message.content.length > config.maxContentLength) {
38
+ throw new index_js_1.SensError({
39
+ code: 400,
40
+ type: "Bad Request",
41
+ message: "알림톡 최대 길이 초과",
42
+ invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${config.maxContentLength}글자입니다` }],
43
+ });
44
+ }
53
45
  return Object.assign({ to: message.to.replace(/\-/gi, ""), content: message.content }, (message.buttons && message.buttons.length && { buttons: message.buttons }));
54
46
  });
55
47
  return result;
@@ -1,125 +1,89 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SendMMSCommand = void 0;
13
- const models_1 = require("../models");
14
- const SendMMS_1 = require("../protocols/SendMMS");
15
- const util_error_handler_1 = require("@ingestkorea/util-error-handler");
16
- const constants_1 = require("./constants");
17
4
  const node_path_1 = require("node:path");
18
5
  const node_crypto_1 = require("node:crypto");
19
6
  const node_fs_1 = require("node:fs");
20
- class SendMMSCommand extends models_1.SensCommand {
7
+ const index_js_1 = require("../models/index.js");
8
+ const SendMMS_js_1 = require("../protocols/SendMMS.js");
9
+ const constants_1 = require("./constants");
10
+ const SendSMSCommand_js_1 = require("./SendSMSCommand.js");
11
+ class SendMMSCommand extends index_js_1.SensCommand {
21
12
  constructor(input) {
22
13
  super(input);
23
- this.input = Object.assign(Object.assign({}, input), { from: (0, constants_1.prettyPhoneNum)(input.from), content: resolveInputContent(input.content), type: resolveInputMessageType(input.type), messages: resolveInputMessages(input.messages), files: resolveInputFiles(input.files) });
24
- }
25
- serialize(input, config) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- if (!config.serviceId.sms)
28
- throw new util_error_handler_1.IngestkoreaError({
29
- code: 400,
30
- type: "Bad Request",
31
- message: "Invalid Params",
32
- description: "Please Check SMS ServiceId",
33
- });
34
- let request = yield (0, SendMMS_1.serializeIngestkorea_restJson_SendMMSCommand)(input, config);
35
- return request;
36
- });
37
- }
38
- deserialize(response) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- let output = yield (0, SendMMS_1.deserializeIngestkorea_restJson_SendMMSCommand)(response);
41
- return output;
42
- });
14
+ const content = input.content ? (0, constants_1.trimText)(input.content) : "내용없음";
15
+ const subject = input.subject ? (0, constants_1.trimText)(input.subject) : "제목없음";
16
+ const messages = (0, SendSMSCommand_js_1.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
17
+ this.input = {
18
+ from: (0, constants_1.prettyPhoneNum)(input.from),
19
+ content,
20
+ messages,
21
+ type: "MMS",
22
+ contentType: input.contentType ? input.contentType : "COMM",
23
+ countryCode: input.countryCode ? input.countryCode : "82",
24
+ subject,
25
+ files: (input.files || []).map((file) => {
26
+ return resolveSendFile(file, { maxKiB: index_js_1.MMS_MAX_SUPPORT_FILE_SIZE, supportExt: index_js_1.MMS_SUPPORT_FILE_EXTENSION });
27
+ }),
28
+ };
29
+ this.serializer = SendMMS_js_1.se_SendMMSCommand;
30
+ this.deserializer = SendMMS_js_1.de_SendMMSCommand;
43
31
  }
44
32
  }
45
33
  exports.SendMMSCommand = SendMMSCommand;
46
- const resolveInputContent = (content) => {
47
- const resolvedContent = (0, constants_1.trimText)(content);
48
- const contentLength = (0, constants_1.getContentLength)(resolvedContent);
49
- if (!contentLength)
50
- throw new util_error_handler_1.IngestkoreaError({
51
- code: 400,
52
- type: "Bad Request",
53
- message: "Invalid Request",
54
- description: `Please check input message`,
55
- });
56
- if (contentLength > constants_1.LMS_MAX)
57
- throw new util_error_handler_1.IngestkoreaError({
34
+ const resolveSendFile = (file, options) => {
35
+ const parsed = (0, node_path_1.parse)(file.name); // { dir, name, ext, base }
36
+ const ext = parsed.ext.toLocaleLowerCase();
37
+ if (!options.supportExt.includes(ext)) {
38
+ throw new index_js_1.SensError({
58
39
  code: 400,
59
40
  type: "Bad Request",
60
- message: "Invalid Request",
61
- description: `Maximum message length is ${constants_1.LMS_MAX}bytes`,
41
+ message: "지원하지 않는 확장자입니다.",
42
+ invalidInputs: [
43
+ { type: "not-valid.args", message: `${options.supportExt.join(", ")} 형식의 첨부파일만 지원합니다.` },
44
+ ],
62
45
  });
63
- return resolvedContent;
64
- };
65
- const resolveInputMessages = (messages) => messages.map((message) => {
66
- return Object.assign(Object.assign({ to: (0, constants_1.prettyPhoneNum)(message.to) }, (message.content != undefined && { content: resolveInputContent(message.content) })), (message.subject != undefined && { subject: (0, constants_1.trimText)(message.subject) }));
67
- });
68
- const resolveInputMessageType = (type) => {
69
- if (type == "SMS" || type == "LMS")
70
- throw new util_error_handler_1.IngestkoreaError({
71
- code: 400,
72
- type: "Bad Request",
73
- message: "Invalid Request",
74
- description: `Please Call SendSMSCommand`,
75
- });
76
- return "MMS";
77
- };
78
- const resolveInputFiles = (files) => {
79
- if (!files.length)
80
- throw new util_error_handler_1.IngestkoreaError({
81
- code: 400,
82
- type: "Bad Request",
83
- message: "Invalid Request",
84
- description: `Please Check Input Files`,
85
- });
86
- const output = files.map((file) => {
87
- const resolvedFileName = verifyFileName(file.name);
88
- const resolvedFileBody = file.body != undefined ? file.body : getFileBody(file.name);
89
- let byte = Buffer.from(resolvedFileBody, "base64").length;
90
- let kib = Math.ceil(byte / 1024);
91
- if (kib > constants_1.MMS_FILE_MAX)
92
- throw new util_error_handler_1.IngestkoreaError({
93
- code: 400,
94
- type: "Bad Request",
95
- message: "Invalid Request",
96
- description: `Input File is ${kib}KiByte. Maximum File Size is ${constants_1.MMS_FILE_MAX}Kibyte`,
97
- });
98
- return { name: resolvedFileName, body: resolvedFileBody };
99
- });
100
- return output;
101
- };
102
- const verifyFileName = (fileName) => {
103
- let { ext } = (0, node_path_1.parse)(fileName);
104
- const uuid = (0, node_crypto_1.randomUUID)();
105
- const extension = ext.replace(/jpeg|jpg/gi, "jpg");
106
- if (extension != ".jpg")
107
- throw new util_error_handler_1.IngestkoreaError({
46
+ }
47
+ if (file.body) {
48
+ const buffer = Buffer.from(file.body, "base64");
49
+ checkSizeLimit(buffer, options.maxKiB);
50
+ const hash = (0, node_crypto_1.createHash)("md5").update(buffer).digest("hex");
51
+ return {
52
+ name: (0, node_path_1.format)({ name: hash, ext }),
53
+ body: file.body,
54
+ };
55
+ }
56
+ if (!(0, node_fs_1.existsSync)(file.name)) {
57
+ throw new index_js_1.SensError({
108
58
  code: 400,
109
59
  type: "Bad Request",
110
- message: "Invalid Request",
111
- description: `File Extension is not .jpg or .jpeg`,
60
+ message: "파일이 존재하지 않습니다.",
61
+ invalidInputs: [{ type: "not-valid.args", message: `${file.name} 파일이 존재하지 않습니다.` }],
112
62
  });
113
- return [uuid, extension].join("");
63
+ }
64
+ const buffer = (0, node_fs_1.readFileSync)(file.name);
65
+ checkSizeLimit(buffer, options.maxKiB);
66
+ const hash = (0, node_crypto_1.createHash)("md5").update(buffer).digest("hex");
67
+ return {
68
+ name: (0, node_path_1.format)({ name: hash, ext }),
69
+ body: buffer.toString("base64"),
70
+ };
114
71
  };
115
- /** @returns base64 */
116
- const getFileBody = (fileName) => {
117
- if (!(0, node_fs_1.existsSync)(fileName))
118
- throw new util_error_handler_1.IngestkoreaError({
72
+ const checkSizeLimit = (buffer, maxKiB) => {
73
+ const byteSize = buffer.length;
74
+ const kibSize = Math.ceil(byteSize / 1024);
75
+ if (kibSize > maxKiB) {
76
+ throw new index_js_1.SensError({
119
77
  code: 400,
120
78
  type: "Bad Request",
121
- message: "Invalid Request",
122
- description: `${fileName} does not exist.`,
79
+ message: `최대 첨부가능 용량이 초과되었습니다.`,
80
+ invalidInputs: [
81
+ {
82
+ type: "not-valid.args",
83
+ message: `최대 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
84
+ },
85
+ ],
123
86
  });
124
- return (0, node_fs_1.readFileSync)(fileName, { encoding: "base64" });
87
+ }
88
+ return;
125
89
  };
@@ -1,87 +1,54 @@
1
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
2
  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");
3
+ exports.resolveInputMessages = exports.SendSMSCommand = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const SendSMS_js_1 = require("../protocols/SendSMS.js");
16
6
  const constants_1 = require("./constants");
17
- class SendSMSCommand extends models_1.SensCommand {
7
+ class SendSMSCommand extends index_js_1.SensCommand {
18
8
  constructor(input) {
19
9
  super(input);
20
- const { content, messageType: defaultMessageType } = resolveInputContent(input.content);
21
- const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
22
- this.input = Object.assign(Object.assign({}, input), { from: (0, constants_1.prettyPhoneNum)(input.from), content: content, type: defaultMessageType === childMessageType ? defaultMessageType : "LMS", messages: messages });
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,
29
- type: "Bad Request",
30
- message: "Invalid Params",
31
- description: "Please Check SMS ServiceId",
32
- });
33
- let request = yield (0, SendSMS_1.serializeIngestkorea_restJson_SendSMSCommand)(input, config);
34
- return request;
35
- });
36
- }
37
- deserialize(response) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- let output = yield (0, SendSMS_1.deserializeIngestkorea_restJson_SendSMSCommand)(response);
40
- return output;
41
- });
10
+ const content = input.content ? (0, constants_1.trimText)(input.content) : "내용없음";
11
+ const subject = input.subject ? (0, constants_1.trimText)(input.subject) : "제목없음";
12
+ const messages = (0, exports.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
13
+ const isLMS = !!messages.filter((msg) => !!msg.subject).length;
14
+ this.input = Object.assign({ from: (0, constants_1.prettyPhoneNum)(input.from), content,
15
+ messages, type: isLMS ? "LMS" : "SMS", contentType: input.contentType ? input.contentType : "COMM", countryCode: input.countryCode ? input.countryCode : "82" }, (isLMS && { subject }));
16
+ this.serializer = SendSMS_js_1.se_SendSMSCommand;
17
+ this.deserializer = SendSMS_js_1.de_SendSMSCommand;
42
18
  }
43
19
  }
44
20
  exports.SendSMSCommand = SendSMSCommand;
21
+ const resolveInputMessages = (messages, config) => {
22
+ const output = messages
23
+ .filter((d) => !!d)
24
+ .map((message) => {
25
+ const content = message.content ? (0, constants_1.trimText)(message.content) : config.defaultContent;
26
+ const subject = message.subject ? (0, constants_1.trimText)(message.subject) : config.defaultSubject;
27
+ const msgType = getMessageType({ content });
28
+ return Object.assign({ to: (0, constants_1.prettyPhoneNum)(message.to), content }, (msgType === "LMS" && { subject }));
29
+ });
30
+ return output;
31
+ };
32
+ exports.resolveInputMessages = resolveInputMessages;
45
33
  const getMessageType = (input) => {
46
- const contentLength = (0, constants_1.getContentLength)(input);
47
- if (!contentLength)
48
- throw new util_error_handler_1.IngestkoreaError({
34
+ const SMS_MAX_CONTENT_LENGTH = 90;
35
+ const LMS_MAX_CONTENT_LENGTH = 2000;
36
+ const contentLength = (0, constants_1.getContentLength)(input.content);
37
+ if (!contentLength) {
38
+ throw new index_js_1.SensError({
49
39
  code: 400,
50
40
  type: "Bad Request",
51
- message: "Invalid Request",
52
- description: `Please check input message`,
41
+ message: "메세지 내용이 없습니다.",
42
+ invalidInputs: [{ type: "not-valid.args", message: "메세지 내용을 확인해주세요." }],
53
43
  });
54
- if (contentLength > constants_1.LMS_MAX)
55
- throw new util_error_handler_1.IngestkoreaError({
44
+ }
45
+ if (contentLength > LMS_MAX_CONTENT_LENGTH) {
46
+ throw new index_js_1.SensError({
56
47
  code: 400,
57
48
  type: "Bad Request",
58
- message: "Invalid Request",
59
- description: `Maximum message length is ${constants_1.LMS_MAX}bytes`,
49
+ message: "메세지 최대 크기 초과",
50
+ invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다` }],
60
51
  });
61
- return contentLength > constants_1.SMS_MAX ? "LMS" : "SMS";
62
- };
63
- const resolveInputContent = (content) => {
64
- const resolvedContent = (0, constants_1.trimText)(content);
65
- const messageType = getMessageType(resolvedContent);
66
- return {
67
- content: resolvedContent,
68
- messageType: messageType,
69
- };
70
- };
71
- const resolveInputMessages = (messages) => {
72
- let init = {
73
- messages: [],
74
- messageType: "SMS",
75
- };
76
- const output = messages.reduce((acc, message) => {
77
- const to = (0, constants_1.prettyPhoneNum)(message.to);
78
- const content = message.content != undefined ? (0, constants_1.trimText)(message.content) : undefined;
79
- const subject = message.subject != undefined ? (0, constants_1.trimText)(message.subject) : undefined;
80
- const messageType = content != undefined ? getMessageType(content) : "SMS";
81
- if (messageType == "LMS")
82
- acc.messageType = messageType;
83
- acc.messages.push(Object.assign(Object.assign({ to: to }, (content != undefined && { content: content })), (subject != undefined && acc.messageType === "LMS" && { subject: subject })));
84
- return acc;
85
- }, init);
86
- return output;
52
+ }
53
+ return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS";
87
54
  };
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRequestDuration = exports.getContentLength = exports.prettyPhoneNum = exports.trimText = exports.MMS_FILE_MAX = exports.LMS_MAX = exports.SMS_MAX = void 0;
4
- exports.SMS_MAX = 90;
5
- exports.LMS_MAX = 2000;
6
- exports.MMS_FILE_MAX = 300; // KiByte
3
+ exports.getContentLength = exports.prettyPhoneNum = exports.trimText = void 0;
7
4
  const trimText = (input) => input.trim();
8
5
  exports.trimText = trimText;
9
6
  const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
@@ -18,14 +15,3 @@ const getContentLength = (input) => {
18
15
  }, 0);
19
16
  };
20
17
  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;
@@ -14,14 +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("./SendAlimtalkCommand"), exports);
18
- __exportStar(require("./GetAlimtalkStatusCommand"), exports);
19
- __exportStar(require("./GetAlimtalkResultCommand"), exports);
20
- __exportStar(require("./GetAlimtalkTemplateCommand"), exports);
21
- __exportStar(require("./ListAlimtalkStatusCommand"), exports);
22
- __exportStar(require("./ListAlimtalkTemplatesCommand"), exports);
23
- __exportStar(require("./ListAlimtalkChannelsCommand"), exports);
24
- __exportStar(require("./SendSMSCommand"), exports);
25
- __exportStar(require("./SendMMSCommand"), exports);
26
- __exportStar(require("./GetSMSStatusCommand"), exports);
27
- __exportStar(require("./GetSMSResultCommand"), exports);
17
+ __exportStar(require("./GetAlimtalkResultCommand.js"), exports);
18
+ __exportStar(require("./GetAlimtalkStatusCommand.js"), exports);
19
+ __exportStar(require("./GetAlimtalkTemplateCommand.js"), exports);
20
+ __exportStar(require("./GetSMSResultCommand.js"), exports);
21
+ __exportStar(require("./GetSMSStatusCommand.js"), exports);
22
+ __exportStar(require("./ListAlimtalkChannelsCommand.js"), exports);
23
+ __exportStar(require("./ListAlimtalkStatusCommand.js"), exports);
24
+ __exportStar(require("./ListAlimtalkTemplatesCommand.js"), exports);
25
+ __exportStar(require("./SendAlimtalkCommand.js"), exports);
26
+ __exportStar(require("./SendMMSCommand.js"), exports);
27
+ __exportStar(require("./SendSMSCommand.js"), exports);
package/dist-cjs/index.js CHANGED
@@ -14,5 +14,5 @@ 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("./commands"), exports);
18
- __exportStar(require("./SensClient"), exports);
17
+ __exportStar(require("./commands/index.js"), exports);
18
+ __exportStar(require("./SensClient.js"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NCP_SIGNATURE = exports.NCP_TIMESTAMP = exports.NCP_ACCESS_KEY = exports.INGESTKOREA_RETRY_DELAY = exports.INGESTKOREA_RETRY = exports.INGESTKOREA_REQUEST_LOG = exports.INGESTKOREA_USER_AGENT = void 0;
4
+ exports.INGESTKOREA_USER_AGENT = "x-ingestkorea-user-agent";
5
+ exports.INGESTKOREA_REQUEST_LOG = "x-ingestkorea-request";
6
+ exports.INGESTKOREA_RETRY = "x-ingestkorea-attempts";
7
+ exports.INGESTKOREA_RETRY_DELAY = "x-ingestkorea-total-retry-delay";
8
+ exports.NCP_ACCESS_KEY = "x-ncp-iam-access-key";
9
+ exports.NCP_TIMESTAMP = "x-ncp-apigw-timestamp";
10
+ exports.NCP_SIGNATURE = "x-ncp-apigw-signature-v2";
@@ -14,7 +14,6 @@ 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("./middleware-sign"), exports);
18
- __exportStar(require("./middleware-metadata"), exports);
19
- __exportStar(require("./middleware-retry"), exports);
20
- __exportStar(require("./middleware-sort-headers"), exports);
17
+ __exportStar(require("./middleware-metadata.js"), exports);
18
+ __exportStar(require("./middleware-retry.js"), exports);
19
+ __exportStar(require("./middleware-sign.js"), exports);
@@ -10,10 +10,9 @@ 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";
14
- const middlewareIngestkoreaMetadata = (request, config) => __awaiter(void 0, void 0, void 0, function* () {
15
- request.headers["x-ingestkorea-user-agent"] = "@ingestkorea/client-sens/1.7.x";
16
- request.headers[REQUEST_HEADER] = "attempt=1";
17
- return request;
13
+ const constants_js_1 = require("./constants.js");
14
+ const middlewareIngestkoreaMetadata = (next) => (input, context) => __awaiter(void 0, void 0, void 0, function* () {
15
+ input.request.headers = Object.assign(Object.assign({}, input.request.headers), { [constants_js_1.INGESTKOREA_USER_AGENT]: "@ingestkorea/client-sens/1.8.x" });
16
+ return next(input, context);
18
17
  });
19
18
  exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;