@ingestkorea/client-sens 1.7.0 → 1.9.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 (157) 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 +7 -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 +7 -33
  9. package/dist-cjs/commands/ListAlimtalkChannelsCommand.js +6 -33
  10. package/dist-cjs/commands/ListAlimtalkStatusCommand.js +29 -35
  11. package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +5 -32
  12. package/dist-cjs/commands/ListSMSStatusCommand.js +37 -0
  13. package/dist-cjs/commands/SendAlimtalkCommand.js +36 -44
  14. package/dist-cjs/commands/SendMMSCommand.js +67 -103
  15. package/dist-cjs/commands/SendSMSCommand.js +38 -71
  16. package/dist-cjs/commands/constants.js +57 -14
  17. package/dist-cjs/commands/index.js +12 -11
  18. package/dist-cjs/index.js +2 -2
  19. package/dist-cjs/middleware/constants.js +10 -0
  20. package/dist-cjs/middleware/index.js +3 -4
  21. package/dist-cjs/middleware/middleware-metadata.js +4 -5
  22. package/dist-cjs/middleware/middleware-retry.js +32 -27
  23. package/dist-cjs/middleware/middleware-sign.js +10 -9
  24. package/dist-cjs/models/SendAlimtalk.js +3 -0
  25. package/dist-cjs/models/SendMMS.js +3 -0
  26. package/dist-cjs/models/SensClient.js +2 -0
  27. package/dist-cjs/models/SensErrorInfo.js +13 -0
  28. package/dist-cjs/models/SensMiddleware.js +2 -0
  29. package/dist-cjs/models/index.js +17 -14
  30. package/dist-cjs/protocols/GetAlimtalkResult.js +19 -22
  31. package/dist-cjs/protocols/GetAlimtalkStatus.js +39 -40
  32. package/dist-cjs/protocols/GetAlimtalkTemplate.js +56 -90
  33. package/dist-cjs/protocols/GetSMSResult.js +31 -48
  34. package/dist-cjs/protocols/GetSMSStatus.js +51 -37
  35. package/dist-cjs/protocols/ListAlimtalkChannels.js +27 -31
  36. package/dist-cjs/protocols/ListAlimtalkStatus.js +22 -19
  37. package/dist-cjs/protocols/ListAlimtalkTemplates.js +33 -25
  38. package/dist-cjs/protocols/ListSMSStatus.js +48 -0
  39. package/dist-cjs/protocols/SendAlimtalk.js +23 -27
  40. package/dist-cjs/protocols/SendMMS.js +8 -38
  41. package/dist-cjs/protocols/SendSMS.js +20 -22
  42. package/dist-cjs/protocols/constants.js +103 -34
  43. package/dist-es/SensClient.js +63 -30
  44. package/dist-es/commands/GetAlimtalkResultCommand.js +9 -19
  45. package/dist-es/commands/GetAlimtalkStatusCommand.js +12 -19
  46. package/dist-es/commands/GetAlimtalkTemplateCommand.js +9 -19
  47. package/dist-es/commands/GetSMSResultCommand.js +10 -20
  48. package/dist-es/commands/GetSMSStatusCommand.js +13 -20
  49. package/dist-es/commands/ListAlimtalkChannelsCommand.js +10 -22
  50. package/dist-es/commands/ListAlimtalkStatusCommand.js +39 -28
  51. package/dist-es/commands/ListAlimtalkTemplatesCommand.js +9 -19
  52. package/dist-es/commands/ListSMSStatusCommand.js +48 -0
  53. package/dist-es/commands/SendAlimtalkCommand.js +35 -30
  54. package/dist-es/commands/SendMMSCommand.js +70 -100
  55. package/dist-es/commands/SendSMSCommand.js +51 -66
  56. package/dist-es/commands/constants.js +65 -15
  57. package/dist-es/commands/index.js +28 -11
  58. package/dist-es/index.js +18 -2
  59. package/dist-es/middleware/constants.js +10 -0
  60. package/dist-es/middleware/index.js +19 -4
  61. package/dist-es/middleware/middleware-metadata.js +11 -5
  62. package/dist-es/middleware/middleware-retry.js +39 -30
  63. package/dist-es/middleware/middleware-sign.js +19 -14
  64. package/dist-es/models/GetAlimtalkResult.js +2 -1
  65. package/dist-es/models/GetAlimtalkStatus.js +2 -1
  66. package/dist-es/models/GetAlimtalkTemplate.js +2 -1
  67. package/dist-es/models/GetSMSResult.js +2 -1
  68. package/dist-es/models/GetSMSStatus.js +2 -1
  69. package/dist-es/models/ListAlimtalkChannels.js +2 -1
  70. package/dist-es/models/ListAlimtalkStatus.js +2 -1
  71. package/dist-es/models/ListAlimtalkTemplates.js +2 -1
  72. package/dist-es/models/ListSMSStatus.js +2 -0
  73. package/dist-es/models/MetadataBearer.js +2 -1
  74. package/dist-es/models/SendAlimtalk.js +5 -1
  75. package/dist-es/models/SendMMS.js +5 -1
  76. package/dist-es/models/SendSMS.js +2 -1
  77. package/dist-es/models/SensClient.js +2 -0
  78. package/dist-es/models/SensCommand.js +5 -1
  79. package/dist-es/models/SensErrorInfo.js +13 -0
  80. package/dist-es/models/SensMiddleware.js +2 -0
  81. package/dist-es/models/index.js +33 -14
  82. package/dist-es/protocols/GetAlimtalkResult.js +24 -23
  83. package/dist-es/protocols/GetAlimtalkStatus.js +51 -47
  84. package/dist-es/protocols/GetAlimtalkTemplate.js +78 -87
  85. package/dist-es/protocols/GetSMSResult.js +40 -47
  86. package/dist-es/protocols/GetSMSStatus.js +55 -37
  87. package/dist-es/protocols/ListAlimtalkChannels.js +31 -31
  88. package/dist-es/protocols/ListAlimtalkStatus.js +26 -32
  89. package/dist-es/protocols/ListAlimtalkTemplates.js +37 -24
  90. package/dist-es/protocols/ListSMSStatus.js +42 -0
  91. package/dist-es/protocols/SendAlimtalk.js +27 -26
  92. package/dist-es/protocols/SendMMS.js +10 -49
  93. package/dist-es/protocols/SendSMS.js +24 -31
  94. package/dist-es/protocols/constants.js +119 -39
  95. package/dist-types/SensClient.d.ts +3 -20
  96. package/dist-types/commands/GetAlimtalkResultCommand.d.ts +5 -10
  97. package/dist-types/commands/GetAlimtalkStatusCommand.d.ts +5 -10
  98. package/dist-types/commands/GetAlimtalkTemplateCommand.d.ts +5 -10
  99. package/dist-types/commands/GetSMSResultCommand.d.ts +5 -10
  100. package/dist-types/commands/GetSMSStatusCommand.d.ts +5 -10
  101. package/dist-types/commands/ListAlimtalkChannelsCommand.d.ts +5 -10
  102. package/dist-types/commands/ListAlimtalkStatusCommand.d.ts +5 -10
  103. package/dist-types/commands/ListAlimtalkTemplatesCommand.d.ts +5 -10
  104. package/dist-types/commands/ListSMSStatusCommand.d.ts +11 -0
  105. package/dist-types/commands/SendAlimtalkCommand.d.ts +5 -10
  106. package/dist-types/commands/SendMMSCommand.d.ts +5 -10
  107. package/dist-types/commands/SendSMSCommand.d.ts +9 -10
  108. package/dist-types/commands/constants.d.ts +14 -4
  109. package/dist-types/commands/index.d.ts +12 -11
  110. package/dist-types/index.d.ts +2 -2
  111. package/dist-types/middleware/constants.d.ts +7 -0
  112. package/dist-types/middleware/index.d.ts +3 -4
  113. package/dist-types/middleware/middleware-metadata.d.ts +2 -2
  114. package/dist-types/middleware/middleware-retry.d.ts +2 -2
  115. package/dist-types/middleware/middleware-sign.d.ts +2 -2
  116. package/dist-types/models/GetAlimtalkResult.d.ts +3 -3
  117. package/dist-types/models/GetAlimtalkStatus.d.ts +8 -5
  118. package/dist-types/models/GetAlimtalkTemplate.d.ts +5 -5
  119. package/dist-types/models/GetSMSResult.d.ts +7 -15
  120. package/dist-types/models/GetSMSStatus.d.ts +19 -4
  121. package/dist-types/models/ListAlimtalkChannels.d.ts +4 -4
  122. package/dist-types/models/ListAlimtalkStatus.d.ts +8 -8
  123. package/dist-types/models/ListAlimtalkTemplates.d.ts +2 -2
  124. package/dist-types/models/ListSMSStatus.d.ts +15 -0
  125. package/dist-types/models/MetadataBearer.d.ts +3 -3
  126. package/dist-types/models/SendAlimtalk.d.ts +7 -4
  127. package/dist-types/models/SendMMS.d.ts +5 -3
  128. package/dist-types/models/SendSMS.d.ts +2 -2
  129. package/dist-types/models/SensClient.d.ts +17 -0
  130. package/dist-types/models/SensCommand.d.ts +4 -6
  131. package/dist-types/models/SensErrorInfo.d.ts +21 -0
  132. package/dist-types/models/SensMiddleware.d.ts +8 -0
  133. package/dist-types/models/index.d.ts +17 -14
  134. package/dist-types/protocols/GetAlimtalkResult.d.ts +4 -11
  135. package/dist-types/protocols/GetAlimtalkStatus.d.ts +6 -12
  136. package/dist-types/protocols/GetAlimtalkTemplate.d.ts +4 -14
  137. package/dist-types/protocols/GetSMSResult.d.ts +4 -12
  138. package/dist-types/protocols/GetSMSStatus.d.ts +6 -11
  139. package/dist-types/protocols/ListAlimtalkChannels.d.ts +4 -11
  140. package/dist-types/protocols/ListAlimtalkStatus.d.ts +4 -10
  141. package/dist-types/protocols/ListAlimtalkTemplates.d.ts +5 -12
  142. package/dist-types/protocols/ListSMSStatus.d.ts +4 -0
  143. package/dist-types/protocols/SendAlimtalk.d.ts +5 -12
  144. package/dist-types/protocols/SendMMS.d.ts +4 -10
  145. package/dist-types/protocols/SendSMS.d.ts +5 -10
  146. package/dist-types/protocols/constants.d.ts +4 -2
  147. package/package.json +20 -4
  148. package/.github/pull_request_template.md +0 -19
  149. package/dist-cjs/middleware/middleware-sort-headers.js +0 -25
  150. package/dist-cjs/protocols/index.js +0 -28
  151. package/dist-es/middleware/middleware-sort-headers.js +0 -12
  152. package/dist-es/models/Middleware.js +0 -1
  153. package/dist-es/protocols/index.js +0 -12
  154. package/dist-types/middleware/middleware-sort-headers.d.ts +0 -2
  155. package/dist-types/models/Middleware.d.ts +0 -12
  156. package/dist-types/protocols/index.d.ts +0 -12
  157. /package/dist-cjs/models/{Middleware.js → ListSMSStatus.js} +0 -0
@@ -1,80 +1,65 @@
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
- import { SMS_MAX, LMS_MAX, trimText, prettyPhoneNum, getContentLength } from "./constants";
5
- export class SendSMSCommand extends SensCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
6
+ const constants_1 = require("./constants");
7
+ class SendSMSCommand extends index_js_1.SensCommand {
6
8
  constructor(input) {
7
9
  super(input);
8
- const { content, messageType: defaultMessageType } = resolveInputContent(input.content);
9
- const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
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;
10
14
  this.input = {
11
- ...input,
12
- from: prettyPhoneNum(input.from),
13
- content: content,
14
- type: defaultMessageType === childMessageType ? defaultMessageType : "LMS",
15
- messages: messages,
15
+ from: (0, constants_1.prettyPhoneNum)(input.from),
16
+ content,
17
+ messages,
18
+ type: isLMS ? "LMS" : "SMS",
19
+ contentType: input.contentType ? input.contentType : "COMM",
20
+ countryCode: input.countryCode ? input.countryCode : "82",
21
+ ...(isLMS && { subject }),
16
22
  };
17
- }
18
- async serialize(input, config) {
19
- if (!config.serviceId.sms)
20
- throw new IngestkoreaError({
21
- code: 400,
22
- type: "Bad Request",
23
- message: "Invalid Params",
24
- description: "Please Check SMS ServiceId",
25
- });
26
- let request = await serializeIngestkorea_restJson_SendSMSCommand(input, config);
27
- return request;
28
- }
29
- async deserialize(response) {
30
- let output = await deserializeIngestkorea_restJson_SendSMSCommand(response);
31
- return output;
23
+ this.serializer = SendSMS_js_1.se_SendSMSCommand;
24
+ this.deserializer = SendSMS_js_1.de_SendSMSCommand;
32
25
  }
33
26
  }
27
+ exports.SendSMSCommand = SendSMSCommand;
28
+ const resolveInputMessages = (messages, config) => {
29
+ const output = messages
30
+ .filter((d) => !!d)
31
+ .map((message) => {
32
+ const content = message.content ? (0, constants_1.trimText)(message.content) : config.defaultContent;
33
+ const subject = message.subject ? (0, constants_1.trimText)(message.subject) : config.defaultSubject;
34
+ const msgType = getMessageType({ content });
35
+ return {
36
+ to: (0, constants_1.prettyPhoneNum)(message.to),
37
+ content,
38
+ ...(msgType === "LMS" && { subject }),
39
+ };
40
+ });
41
+ return output;
42
+ };
43
+ exports.resolveInputMessages = resolveInputMessages;
34
44
  const getMessageType = (input) => {
35
- const contentLength = getContentLength(input);
36
- if (!contentLength)
37
- throw new IngestkoreaError({
45
+ const SMS_MAX_CONTENT_LENGTH = 90;
46
+ const LMS_MAX_CONTENT_LENGTH = 2000;
47
+ const contentLength = (0, constants_1.getContentLength)(input.content);
48
+ if (!contentLength) {
49
+ throw new index_js_1.SensError({
38
50
  code: 400,
39
51
  type: "Bad Request",
40
- message: "Invalid Request",
41
- description: `Please check input message`,
52
+ message: "메세지 내용이 없습니다.",
53
+ invalidInputs: [{ type: "not-valid.args", message: "메세지 내용을 확인해주세요." }],
42
54
  });
43
- if (contentLength > LMS_MAX)
44
- throw new IngestkoreaError({
55
+ }
56
+ if (contentLength > LMS_MAX_CONTENT_LENGTH) {
57
+ throw new index_js_1.SensError({
45
58
  code: 400,
46
59
  type: "Bad Request",
47
- message: "Invalid Request",
48
- description: `Maximum message length is ${LMS_MAX}bytes`,
60
+ message: "메세지 최대 크기 초과",
61
+ invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다` }],
49
62
  });
50
- return contentLength > SMS_MAX ? "LMS" : "SMS";
51
- };
52
- const resolveInputContent = (content) => {
53
- const resolvedContent = trimText(content);
54
- const messageType = getMessageType(resolvedContent);
55
- return {
56
- content: resolvedContent,
57
- messageType: messageType,
58
- };
59
- };
60
- const resolveInputMessages = (messages) => {
61
- let init = {
62
- messages: [],
63
- messageType: "SMS",
64
- };
65
- const output = messages.reduce((acc, message) => {
66
- const to = prettyPhoneNum(message.to);
67
- const content = message.content != undefined ? trimText(message.content) : undefined;
68
- const subject = message.subject != undefined ? trimText(message.subject) : undefined;
69
- const messageType = content != undefined ? getMessageType(content) : "SMS";
70
- if (messageType == "LMS")
71
- acc.messageType = messageType;
72
- acc.messages.push({
73
- to: to,
74
- ...(content != undefined && { content: content }),
75
- ...(subject != undefined && acc.messageType === "LMS" && { subject: subject }),
76
- });
77
- return acc;
78
- }, init);
79
- return output;
63
+ }
64
+ return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS";
80
65
  };
@@ -1,10 +1,13 @@
1
- export const SMS_MAX = 90;
2
- export const LMS_MAX = 2000;
3
- export const MMS_FILE_MAX = 300; // KiByte
4
- export const trimText = (input) => input.trim();
5
- export const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRequestDuration = exports.getDefaultRequestDuration = exports.convertToKst = exports.convertToUtc = exports.getContentLength = exports.prettyPhoneNum = exports.trimText = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const trimText = (input) => input.trim();
6
+ exports.trimText = trimText;
7
+ const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
8
+ exports.prettyPhoneNum = prettyPhoneNum;
6
9
  /** @returns content-length(euc-kr) */
7
- export const getContentLength = (input) => {
10
+ const getContentLength = (input) => {
8
11
  return input.split("").reduce((acc, text) => {
9
12
  let byte = Buffer.from(text).length;
10
13
  let modulo = byte % 3;
@@ -12,13 +15,60 @@ export const getContentLength = (input) => {
12
15
  return acc;
13
16
  }, 0);
14
17
  };
15
- export const getRequestDuration = (input) => {
16
- const OFFSET = 9 * 60 * 60 * 1000;
17
- const hours = input ? Math.abs(input) : 24;
18
- const hours_ms = hours * 60 * 60 * 1000;
19
- const current_ms = new Date().getTime() + OFFSET;
20
- const startTime_ms = current_ms - hours_ms;
21
- let current_kst = new Date(current_ms).toISOString().replace(/\.\d{3}Z$/, "");
22
- let startTime_kst = new Date(startTime_ms).toISOString().replace(/\.\d{3}Z$/, "");
23
- return { startTime: startTime_kst, endTime: current_kst };
18
+ exports.getContentLength = getContentLength;
19
+ const convertToUtc = (input) => {
20
+ const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
21
+ return utcRegex.test(input) ? input : new Date(input.replace(" ", "T") + "+09:00").toISOString();
24
22
  };
23
+ exports.convertToUtc = convertToUtc;
24
+ const convertToKst = (input) => {
25
+ const KST_OFFSET = 9 * 3600000;
26
+ return new Date(input + KST_OFFSET).toISOString().replace(/\.\d{3}Z$/, "");
27
+ };
28
+ exports.convertToKst = convertToKst;
29
+ // UTC
30
+ const getDefaultRequestDuration = (config) => {
31
+ const now = Date.now();
32
+ return {
33
+ startTime: new Date(now - config.durationLimitMs).toISOString(),
34
+ endTime: new Date(now).toISOString(),
35
+ };
36
+ };
37
+ exports.getDefaultRequestDuration = getDefaultRequestDuration;
38
+ // UTC
39
+ const resolveRequestDuration = (input, config) => {
40
+ const start = new Date(input.startTime).getTime();
41
+ const end = new Date(input.endTime).getTime();
42
+ const diff = end - start;
43
+ if (diff < 0) {
44
+ throw new index_js_1.SensError({
45
+ code: 400,
46
+ type: "Bad Request",
47
+ message: `조회 가능 날짜 오류`,
48
+ invalidInputs: [
49
+ {
50
+ type: "not-valid.args",
51
+ message: "종료일이 시작일보다 빠를 수 없습니다.",
52
+ },
53
+ ],
54
+ });
55
+ }
56
+ if (diff > config.durationLimitMs) {
57
+ throw new index_js_1.SensError({
58
+ code: 400,
59
+ type: "Bad Request",
60
+ message: `조회 가능 날짜 범위 오류`,
61
+ invalidInputs: [
62
+ {
63
+ type: "not-valid.args",
64
+ message: `조회 가능한 날짜 범위는 최대 ${config.durationLimitMs / (24 * 3600000)}일 이내여야 합니다.`,
65
+ },
66
+ ],
67
+ });
68
+ }
69
+ return {
70
+ startTimeMs: start,
71
+ endTimeMs: end,
72
+ };
73
+ };
74
+ exports.resolveRequestDuration = resolveRequestDuration;
@@ -1,11 +1,28 @@
1
- export * from "./SendAlimtalkCommand";
2
- export * from "./GetAlimtalkStatusCommand";
3
- export * from "./GetAlimtalkResultCommand";
4
- export * from "./GetAlimtalkTemplateCommand";
5
- export * from "./ListAlimtalkStatusCommand";
6
- export * from "./ListAlimtalkTemplatesCommand";
7
- export * from "./ListAlimtalkChannelsCommand";
8
- export * from "./SendSMSCommand";
9
- export * from "./SendMMSCommand";
10
- export * from "./GetSMSStatusCommand";
11
- export * from "./GetSMSResultCommand";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
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("./ListSMSStatusCommand.js"), exports);
26
+ __exportStar(require("./SendAlimtalkCommand.js"), exports);
27
+ __exportStar(require("./SendMMSCommand.js"), exports);
28
+ __exportStar(require("./SendSMSCommand.js"), exports);
package/dist-es/index.js CHANGED
@@ -1,2 +1,18 @@
1
- export * from "./commands";
2
- export * from "./SensClient";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
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";
@@ -1,4 +1,19 @@
1
- export * from "./middleware-sign";
2
- export * from "./middleware-metadata";
3
- export * from "./middleware-retry";
4
- export * from "./middleware-sort-headers";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./middleware-metadata.js"), exports);
18
+ __exportStar(require("./middleware-retry.js"), exports);
19
+ __exportStar(require("./middleware-sign.js"), exports);
@@ -1,6 +1,12 @@
1
- const REQUEST_HEADER = "x-ingestkorea-request";
2
- export const middlewareIngestkoreaMetadata = async (request, config) => {
3
- request.headers["x-ingestkorea-user-agent"] = "@ingestkorea/client-sens/1.7.x";
4
- request.headers[REQUEST_HEADER] = "attempt=1";
5
- return request;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.middlewareIngestkoreaMetadata = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ const middlewareIngestkoreaMetadata = (next) => async (input, context) => {
6
+ input.request.headers = {
7
+ ...input.request.headers,
8
+ [constants_js_1.INGESTKOREA_USER_AGENT]: "@ingestkorea/client-sens/1.8.x",
9
+ };
10
+ return next(input, context);
6
11
  };
12
+ exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
@@ -1,51 +1,60 @@
1
- import { IngestkoreaError } from "@ingestkorea/util-error-handler";
2
- const REQUEST_HEADER = "x-ingestkorea-request";
3
- export const middlewareRetry = async (request, config, handler) => {
4
- const maxAttempts = 3;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.middlewareRetry = void 0;
4
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
5
+ const constants_js_1 = require("./constants.js");
6
+ const middlewareRetry = (next) => async (input, context) => {
7
+ var _a, _b;
8
+ var _c;
9
+ const MAX_RETRIES = 3;
10
+ const BASE_DELAY_MS = 500;
11
+ const MAX_DELAY_MS = 5000;
5
12
  let attempts = 0;
6
13
  let totalRetryDelay = 0;
7
- let lastError = new IngestkoreaError({
14
+ (_a = (_c = input.request).headers) !== null && _a !== void 0 ? _a : (_c.headers = {});
15
+ let lastError = new util_error_handler_1.IngestkoreaError({
8
16
  code: 400,
9
17
  type: "Bad Request",
10
18
  message: "Invalid Request",
11
- description: { attempts, maxAttempts, totalRetryDelay },
19
+ description: { attempts, maxRetries: MAX_RETRIES, totalRetryDelay },
12
20
  });
13
- while (true) {
21
+ while (attempts < MAX_RETRIES) {
22
+ const attemptNo = attempts + 1;
23
+ const requestLog = `attempt=${attemptNo}; max=${MAX_RETRIES}; totalRetryDelay=${totalRetryDelay}`;
24
+ input.request.headers[constants_js_1.INGESTKOREA_REQUEST_LOG] = requestLog;
14
25
  try {
15
- request.headers[REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}; totalRetryDelay=${totalRetryDelay}`;
16
- let { response } = await handler.handle(request);
17
- return {
18
- output: {
19
- $metadata: {
20
- attempts: attempts + 1,
21
- totalRetryDelay: totalRetryDelay,
22
- },
23
- },
24
- response,
25
- };
26
+ const { response } = await next(input, context);
27
+ response.headers[constants_js_1.INGESTKOREA_RETRY] = attemptNo.toString();
28
+ response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] = totalRetryDelay.toString();
29
+ return { response };
26
30
  }
27
- catch (err) {
31
+ catch (error) {
28
32
  attempts++;
29
- if (attempts == maxAttempts) {
30
- lastError.error.description.attempts = attempts;
31
- throw lastError;
32
- }
33
- const delay = attempts * 1000;
34
- totalRetryDelay += delay;
35
- lastError.error.description = { attempts, maxAttempts, totalRetryDelay };
36
- if (err instanceof IngestkoreaError) {
33
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
34
+ if (error instanceof util_error_handler_1.IngestkoreaError) {
37
35
  lastError.error.description = {
38
36
  ...lastError.error.description,
39
- detail: err.error.description,
37
+ detail: error.error.description,
40
38
  };
41
39
  }
42
- if (err instanceof Error) {
40
+ else {
43
41
  lastError.error.description = {
44
42
  ...lastError.error.description,
45
- detail: err.message,
43
+ detail: String((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error),
46
44
  };
47
45
  }
46
+ if (attempts >= MAX_RETRIES) {
47
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
48
+ throw lastError;
49
+ }
50
+ const exp = BASE_DELAY_MS * 2 ** (attempts - 1);
51
+ const capped = Math.min(MAX_DELAY_MS, exp);
52
+ const delay = Math.floor(Math.random() * capped);
53
+ totalRetryDelay += delay;
54
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
48
55
  await new Promise((resolve) => setTimeout(resolve, delay));
49
56
  }
50
57
  }
58
+ throw lastError;
51
59
  };
60
+ exports.middlewareRetry = middlewareRetry;
@@ -1,20 +1,25 @@
1
- import { createHmac } from "crypto";
2
- import { buildQueryString } from "@ingestkorea/util-http-handler";
3
- export const middlewareNcpSigner = async (request, config) => {
4
- const { accessKey, secretKey } = config.credentials;
5
- const method = request.method;
6
- const queryString = buildQueryString(request.query);
7
- const path = queryString ? `${request.path}?${queryString}` : request.path;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.middlewareNcpSign = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
6
+ const constants_js_1 = require("./constants.js");
7
+ const middlewareNcpSign = (next) => async (input, context) => {
8
+ const { accessKey, secretKey } = context.credentials;
9
+ const method = input.request.method;
10
+ const queryString = (0, util_http_handler_1.buildQueryString)(input.request.query);
11
+ const path = queryString ? `${input.request.path}?${queryString}` : input.request.path;
8
12
  const space = " ";
9
13
  const newLine = "\n";
10
14
  const timestamp = new Date().getTime().toString();
11
15
  const stringToSign = [method + space + path, timestamp, accessKey].join(newLine);
12
- const signature = createHmac("sha256", secretKey).update(stringToSign).digest("base64");
13
- request.headers = {
14
- ...request.headers,
15
- ["x-ncp-iam-access-key"]: accessKey,
16
- ["x-ncp-apigw-timestamp"]: timestamp,
17
- ["x-ncp-apigw-signature-v2"]: signature,
16
+ const signature = (0, crypto_1.createHmac)("sha256", secretKey).update(stringToSign).digest("base64");
17
+ input.request.headers = {
18
+ ...input.request.headers,
19
+ [constants_js_1.NCP_ACCESS_KEY]: accessKey,
20
+ [constants_js_1.NCP_TIMESTAMP]: timestamp,
21
+ [constants_js_1.NCP_SIGNATURE]: signature,
18
22
  };
19
- return request;
23
+ return next(input, context);
20
24
  };
25
+ exports.middlewareNcpSign = middlewareNcpSign;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
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 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALIMTALK_MAX_CONTENT_LENGTH = exports.ALIMTALK_MAX_RECIPIENTS = void 0;
4
+ exports.ALIMTALK_MAX_RECIPIENTS = 100;
5
+ exports.ALIMTALK_MAX_CONTENT_LENGTH = 1000;
1
6
  const ALIMTALK_BUTTON_TYPES = ["DS", "WL", "AL", "BK", "MD", "AC"];
2
7
  const ALIMTALK_BUTTON_NAMES = ["배송 조회", "웹 링크", "앱 링크", "봇 키워드", "메시지 전달", "채널 추가"];
3
- export {};
@@ -1 +1,5 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MMS_SUPPORT_FILE_EXTENSION = exports.MMS_MAX_SUPPORT_FILE_SIZE = void 0;
4
+ exports.MMS_MAX_SUPPORT_FILE_SIZE = 300; // KiByte
5
+ exports.MMS_SUPPORT_FILE_EXTENSION = [".jpg", ".jpeg"];
@@ -1 +1,2 @@
1
- export {};
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,5 +1,9 @@
1
- export class SensCommand {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SensCommand = void 0;
4
+ class SensCommand {
2
5
  constructor(input) {
3
6
  this.input = input;
4
7
  }
5
8
  }
9
+ exports.SensCommand = SensCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SensError = void 0;
4
+ class SensError extends Error {
5
+ constructor(info) {
6
+ super(info.message);
7
+ this.name = "SensError";
8
+ this.code = info.code;
9
+ this.type = info.type;
10
+ this.invalidInputs = info.invalidInputs || [];
11
+ }
12
+ }
13
+ exports.SensError = SensError;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +1,33 @@
1
- export * from "./MetadataBearer";
2
- export * from "./Middleware";
3
- export * from "./SensCommand";
4
- export * from "./SendAlimtalk";
5
- export * from "./GetAlimtalkStatus";
6
- export * from "./GetAlimtalkResult";
7
- export * from "./GetAlimtalkTemplate";
8
- export * from "./ListAlimtalkStatus";
9
- export * from "./ListAlimtalkTemplates";
10
- export * from "./ListAlimtalkChannels";
11
- export * from "./SendSMS";
12
- export * from "./SendMMS";
13
- export * from "./GetSMSStatus";
14
- export * from "./GetSMSResult";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./GetAlimtalkResult.js"), exports);
18
+ __exportStar(require("./GetAlimtalkStatus.js"), exports);
19
+ __exportStar(require("./GetAlimtalkTemplate.js"), exports);
20
+ __exportStar(require("./GetSMSResult.js"), exports);
21
+ __exportStar(require("./GetSMSStatus.js"), exports);
22
+ __exportStar(require("./ListAlimtalkChannels.js"), exports);
23
+ __exportStar(require("./ListAlimtalkStatus.js"), exports);
24
+ __exportStar(require("./ListAlimtalkTemplates.js"), exports);
25
+ __exportStar(require("./ListSMSStatus.js"), exports);
26
+ __exportStar(require("./MetadataBearer.js"), exports);
27
+ __exportStar(require("./SendAlimtalk.js"), exports);
28
+ __exportStar(require("./SendMMS.js"), exports);
29
+ __exportStar(require("./SendSMS.js"), exports);
30
+ __exportStar(require("./SensClient.js"), exports);
31
+ __exportStar(require("./SensCommand.js"), exports);
32
+ __exportStar(require("./SensErrorInfo.js"), exports);
33
+ __exportStar(require("./SensMiddleware.js"), exports);