@ingestkorea/client-sens 1.5.2 → 1.6.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 (133) hide show
  1. package/.github/pull_request_template.md +6 -1
  2. package/LICENSE +2 -2
  3. package/README.md +56 -38
  4. package/dist-cjs/SensClient.js +12 -12
  5. package/dist-cjs/commands/GetAlimtalkResultCommand.js +4 -7
  6. package/dist-cjs/commands/GetAlimtalkStatusCommand.js +4 -7
  7. package/dist-cjs/commands/GetAlimtalkTemplateCommand.js +4 -7
  8. package/dist-cjs/commands/GetSMSResultCommand.js +4 -6
  9. package/dist-cjs/commands/GetSMSStatusCommand.js +4 -6
  10. package/dist-cjs/commands/ListAlimtalkChannelsCommand.js +4 -7
  11. package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +4 -7
  12. package/dist-cjs/commands/SendAlimtalkCommand.js +8 -9
  13. package/dist-cjs/commands/SendMMSCommand.js +40 -30
  14. package/dist-cjs/commands/SendSMSCommand.js +19 -18
  15. package/dist-cjs/commands/constants.js +2 -2
  16. package/dist-cjs/middleware/index.js +4 -2
  17. package/dist-cjs/middleware/{metadata-ingestkorea.js → middleware-metadata.js} +3 -12
  18. package/dist-cjs/middleware/middleware-retry.js +58 -0
  19. package/dist-cjs/middleware/{signer-ncp.js → middleware-sign.js} +3 -7
  20. package/dist-cjs/middleware/middleware-sort-headers.js +25 -0
  21. package/dist-cjs/models/GetAlimtalkResult.js +0 -3
  22. package/dist-cjs/models/GetAlimtalkStatus.js +0 -3
  23. package/dist-cjs/models/GetAlimtalkTemplate.js +0 -2
  24. package/dist-cjs/models/GetSMSResult.js +0 -4
  25. package/dist-cjs/models/GetSMSStatus.js +0 -3
  26. package/dist-cjs/models/ListAlimtalkChannels.js +0 -3
  27. package/dist-cjs/models/ListAlimtalkTemplates.js +0 -5
  28. package/dist-cjs/models/MetadataBearer.js +2 -0
  29. package/dist-cjs/models/Middleware.js +2 -0
  30. package/dist-cjs/models/SendAlimtalk.js +0 -5
  31. package/dist-cjs/models/SendMMS.js +0 -2
  32. package/dist-cjs/models/SendSMS.js +0 -2
  33. package/dist-cjs/models/SensCommand.js +0 -2
  34. package/dist-cjs/models/index.js +2 -0
  35. package/dist-cjs/protocols/GetAlimtalkResult.js +11 -12
  36. package/dist-cjs/protocols/GetAlimtalkStatus.js +13 -14
  37. package/dist-cjs/protocols/GetAlimtalkTemplate.js +12 -12
  38. package/dist-cjs/protocols/GetSMSResult.js +15 -15
  39. package/dist-cjs/protocols/GetSMSStatus.js +13 -13
  40. package/dist-cjs/protocols/ListAlimtalkChannels.js +13 -13
  41. package/dist-cjs/protocols/ListAlimtalkTemplates.js +22 -21
  42. package/dist-cjs/protocols/SendAlimtalk.js +13 -14
  43. package/dist-cjs/protocols/SendMMS.js +11 -11
  44. package/dist-cjs/protocols/SendSMS.js +11 -11
  45. package/dist-cjs/protocols/constants.js +17 -8
  46. package/dist-es/SensClient.js +15 -15
  47. package/dist-es/commands/GetAlimtalkResultCommand.js +8 -11
  48. package/dist-es/commands/GetAlimtalkStatusCommand.js +8 -11
  49. package/dist-es/commands/GetAlimtalkTemplateCommand.js +8 -11
  50. package/dist-es/commands/GetSMSResultCommand.js +8 -10
  51. package/dist-es/commands/GetSMSStatusCommand.js +8 -10
  52. package/dist-es/commands/ListAlimtalkChannelsCommand.js +8 -11
  53. package/dist-es/commands/ListAlimtalkTemplatesCommand.js +8 -11
  54. package/dist-es/commands/SendAlimtalkCommand.js +13 -14
  55. package/dist-es/commands/SendMMSCommand.js +48 -38
  56. package/dist-es/commands/SendSMSCommand.js +23 -22
  57. package/dist-es/commands/constants.js +2 -2
  58. package/dist-es/commands/index.js +10 -10
  59. package/dist-es/index.js +2 -2
  60. package/dist-es/middleware/index.js +4 -2
  61. package/dist-es/middleware/middleware-metadata.js +6 -0
  62. package/dist-es/middleware/middleware-retry.js +51 -0
  63. package/dist-es/middleware/{signer-ncp.js → middleware-sign.js} +7 -11
  64. package/dist-es/middleware/middleware-sort-headers.js +12 -0
  65. package/dist-es/models/GetAlimtalkResult.js +0 -3
  66. package/dist-es/models/GetAlimtalkStatus.js +0 -3
  67. package/dist-es/models/GetAlimtalkTemplate.js +0 -2
  68. package/dist-es/models/GetSMSResult.js +0 -4
  69. package/dist-es/models/GetSMSStatus.js +0 -3
  70. package/dist-es/models/ListAlimtalkChannels.js +0 -3
  71. package/dist-es/models/ListAlimtalkTemplates.js +0 -5
  72. package/dist-es/models/MetadataBearer.js +1 -0
  73. package/dist-es/models/Middleware.js +1 -0
  74. package/dist-es/models/SendAlimtalk.js +0 -5
  75. package/dist-es/models/SendMMS.js +0 -2
  76. package/dist-es/models/SendSMS.js +0 -2
  77. package/dist-es/models/SensCommand.js +0 -2
  78. package/dist-es/models/index.js +13 -11
  79. package/dist-es/protocols/GetAlimtalkResult.js +18 -15
  80. package/dist-es/protocols/GetAlimtalkStatus.js +20 -17
  81. package/dist-es/protocols/GetAlimtalkTemplate.js +20 -16
  82. package/dist-es/protocols/GetSMSResult.js +22 -18
  83. package/dist-es/protocols/GetSMSStatus.js +20 -16
  84. package/dist-es/protocols/ListAlimtalkChannels.js +20 -16
  85. package/dist-es/protocols/ListAlimtalkTemplates.js +29 -24
  86. package/dist-es/protocols/SendAlimtalk.js +20 -17
  87. package/dist-es/protocols/SendMMS.js +18 -14
  88. package/dist-es/protocols/SendSMS.js +19 -15
  89. package/dist-es/protocols/constants.js +17 -9
  90. package/dist-es/protocols/index.js +10 -10
  91. package/dist-types/SensClient.d.ts +2 -2
  92. package/dist-types/commands/GetAlimtalkResultCommand.d.ts +8 -5
  93. package/dist-types/commands/GetAlimtalkStatusCommand.d.ts +8 -5
  94. package/dist-types/commands/GetAlimtalkTemplateCommand.d.ts +8 -5
  95. package/dist-types/commands/GetSMSResultCommand.d.ts +8 -5
  96. package/dist-types/commands/GetSMSStatusCommand.d.ts +8 -5
  97. package/dist-types/commands/ListAlimtalkChannelsCommand.d.ts +8 -5
  98. package/dist-types/commands/ListAlimtalkTemplatesCommand.d.ts +8 -5
  99. package/dist-types/commands/SendAlimtalkCommand.d.ts +8 -5
  100. package/dist-types/commands/SendMMSCommand.d.ts +8 -5
  101. package/dist-types/commands/SendSMSCommand.d.ts +8 -5
  102. package/dist-types/commands/index.d.ts +10 -10
  103. package/dist-types/index.d.ts +2 -2
  104. package/dist-types/middleware/index.d.ts +4 -2
  105. package/dist-types/middleware/middleware-metadata.d.ts +2 -0
  106. package/dist-types/middleware/middleware-retry.d.ts +2 -0
  107. package/dist-types/middleware/middleware-sign.d.ts +2 -0
  108. package/dist-types/middleware/middleware-sort-headers.d.ts +2 -0
  109. package/dist-types/models/GetAlimtalkResult.d.ts +1 -1
  110. package/dist-types/models/GetAlimtalkStatus.d.ts +1 -1
  111. package/dist-types/models/GetAlimtalkTemplate.d.ts +1 -1
  112. package/dist-types/models/MetadataBearer.d.ts +8 -0
  113. package/dist-types/models/Middleware.d.ts +12 -0
  114. package/dist-types/models/SendMMS.d.ts +1 -1
  115. package/dist-types/models/SendSMS.d.ts +3 -3
  116. package/dist-types/models/SensCommand.d.ts +6 -2
  117. package/dist-types/models/index.d.ts +13 -11
  118. package/dist-types/protocols/GetAlimtalkResult.d.ts +8 -5
  119. package/dist-types/protocols/GetAlimtalkStatus.d.ts +8 -5
  120. package/dist-types/protocols/GetAlimtalkTemplate.d.ts +8 -5
  121. package/dist-types/protocols/GetSMSResult.d.ts +8 -5
  122. package/dist-types/protocols/GetSMSStatus.d.ts +8 -5
  123. package/dist-types/protocols/ListAlimtalkChannels.d.ts +8 -5
  124. package/dist-types/protocols/ListAlimtalkTemplates.d.ts +8 -5
  125. package/dist-types/protocols/SendAlimtalk.d.ts +8 -5
  126. package/dist-types/protocols/SendMMS.d.ts +8 -5
  127. package/dist-types/protocols/SendSMS.d.ts +8 -5
  128. package/dist-types/protocols/constants.d.ts +3 -1
  129. package/dist-types/protocols/index.d.ts +10 -10
  130. package/package.json +4 -3
  131. package/dist-es/middleware/metadata-ingestkorea.js +0 -19
  132. package/dist-types/middleware/metadata-ingestkorea.d.ts +0 -3
  133. package/dist-types/middleware/signer-ncp.d.ts +0 -3
@@ -1,29 +1,26 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_GetAlimtalkTemplateCommand, deserializeIngestkorea_restJson_GetAlimtalkTemplateCommand } from '../protocols/GetAlimtalkTemplate';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_GetAlimtalkTemplateCommand, deserializeIngestkorea_restJson_GetAlimtalkTemplateCommand, } from "../protocols/GetAlimtalkTemplate";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class GetAlimtalkTemplateCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
9
7
  this.input = {
10
- ...input
8
+ ...input,
11
9
  };
12
10
  }
13
- ;
14
11
  async serialize(input, config) {
15
12
  if (!config.serviceId.kakao)
16
13
  throw new IngestkoreaError({
17
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
14
+ code: 400,
15
+ type: "Bad Request",
16
+ message: "Invalid Params",
17
+ description: "Please Check Kakao ServiceId",
18
18
  });
19
19
  let request = await serializeIngestkorea_restJson_GetAlimtalkTemplateCommand(input, config);
20
20
  return request;
21
21
  }
22
- ;
23
22
  async deserialize(response) {
24
23
  let output = await deserializeIngestkorea_restJson_GetAlimtalkTemplateCommand(response);
25
24
  return output;
26
25
  }
27
- ;
28
26
  }
29
- ;
@@ -1,28 +1,26 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_GetSMSResultCommand, deserializeIngestkorea_restJson_GetSMSResultCommand } from '../protocols/GetSMSResult';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_GetSMSResultCommand, deserializeIngestkorea_restJson_GetSMSResultCommand, } from "../protocols/GetSMSResult";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class GetSMSResultCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
9
7
  this.input = {
10
- ...input
8
+ ...input,
11
9
  };
12
10
  }
13
- ;
14
11
  async serialize(input, config) {
15
12
  if (!config.serviceId.sms)
16
13
  throw new IngestkoreaError({
17
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
14
+ code: 400,
15
+ type: "Bad Request",
16
+ message: "Invalid Params",
17
+ description: "Please Check SMS ServiceId",
18
18
  });
19
19
  let request = await serializeIngestkorea_restJson_GetSMSResultCommand(input, config);
20
20
  return request;
21
21
  }
22
- ;
23
22
  async deserialize(response) {
24
23
  let output = await deserializeIngestkorea_restJson_GetSMSResultCommand(response);
25
24
  return output;
26
25
  }
27
- ;
28
26
  }
@@ -1,28 +1,26 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_GetSMSStatusCommand, deserializeIngestkorea_restJson_GetSMSStatusCommand } from '../protocols/GetSMSStatus';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_GetSMSStatusCommand, deserializeIngestkorea_restJson_GetSMSStatusCommand, } from "../protocols/GetSMSStatus";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class GetSMSStatusCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
9
7
  this.input = {
10
- ...input
8
+ ...input,
11
9
  };
12
10
  }
13
- ;
14
11
  async serialize(input, config) {
15
12
  if (!config.serviceId.sms)
16
13
  throw new IngestkoreaError({
17
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
14
+ code: 400,
15
+ type: "Bad Request",
16
+ message: "Invalid Params",
17
+ description: "Please Check SMS ServiceId",
18
18
  });
19
19
  let request = await serializeIngestkorea_restJson_GetSMSStatusCommand(input, config);
20
20
  return request;
21
21
  }
22
- ;
23
22
  async deserialize(response) {
24
23
  let output = await deserializeIngestkorea_restJson_GetSMSStatusCommand(response);
25
24
  return output;
26
25
  }
27
- ;
28
26
  }
@@ -1,29 +1,26 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_ListAlimtalkChannelsCommand, deserializeIngestkorea_restJson_ListAlimtalkChannelsCommand, } from '../protocols/ListAlimtalkChannels';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_ListAlimtalkChannelsCommand, deserializeIngestkorea_restJson_ListAlimtalkChannelsCommand, } from "../protocols/ListAlimtalkChannels";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class ListAlimtalkChannelsCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
9
7
  this.input = {
10
- ...input
8
+ ...input,
11
9
  };
12
10
  }
13
- ;
14
11
  async serialize(input, config) {
15
12
  if (!config.serviceId.kakao)
16
13
  throw new IngestkoreaError({
17
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
14
+ code: 400,
15
+ type: "Bad Request",
16
+ message: "Invalid Params",
17
+ description: "Please Check Kakao ServiceId",
18
18
  });
19
19
  let request = await serializeIngestkorea_restJson_ListAlimtalkChannelsCommand(input, config);
20
20
  return request;
21
21
  }
22
- ;
23
22
  async deserialize(response) {
24
23
  let output = await deserializeIngestkorea_restJson_ListAlimtalkChannelsCommand(response);
25
24
  return output;
26
25
  }
27
- ;
28
26
  }
29
- ;
@@ -1,29 +1,26 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_ListAlimtalkTemplatesCommand, deserializeIngestkorea_restJson_ListAlimtalkTemplatesCommand } from '../protocols/ListAlimtalkTemplates';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_ListAlimtalkTemplatesCommand, deserializeIngestkorea_restJson_ListAlimtalkTemplatesCommand, } from "../protocols/ListAlimtalkTemplates";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class ListAlimtalkTemplatesCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
9
7
  this.input = {
10
- ...input
8
+ ...input,
11
9
  };
12
10
  }
13
- ;
14
11
  async serialize(input, config) {
15
12
  if (!config.serviceId.kakao)
16
13
  throw new IngestkoreaError({
17
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
14
+ code: 400,
15
+ type: "Bad Request",
16
+ message: "Invalid Params",
17
+ description: "Please Check Kakao ServiceId",
18
18
  });
19
19
  let request = await serializeIngestkorea_restJson_ListAlimtalkTemplatesCommand(input, config);
20
20
  return request;
21
21
  }
22
- ;
23
22
  async deserialize(response) {
24
23
  let output = await deserializeIngestkorea_restJson_ListAlimtalkTemplatesCommand(response);
25
24
  return output;
26
25
  }
27
- ;
28
26
  }
29
- ;
@@ -1,8 +1,6 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_SendAlimtalkCommand, deserializeIngestkorea_restJson_SendAlimtalkCommand } from '../protocols/SendAlimtalk';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- ;
5
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_SendAlimtalkCommand, deserializeIngestkorea_restJson_SendAlimtalkCommand, } from "../protocols/SendAlimtalk";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
6
4
  export class SendAlimtalkCommand extends SensCommand {
7
5
  constructor(input) {
8
6
  super(input);
@@ -10,36 +8,37 @@ export class SendAlimtalkCommand extends SensCommand {
10
8
  ...input,
11
9
  plusFriendId: input.plusFriendId,
12
10
  templateCode: input.templateCode,
13
- messages: input.messages.map(resolveAlimtalkMessage)
11
+ messages: input.messages.map(resolveAlimtalkMessage),
14
12
  };
15
13
  }
16
- ;
17
14
  async serialize(input, config) {
18
15
  if (!config.serviceId.kakao)
19
16
  throw new IngestkoreaError({
20
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check Kakao ServiceId'
17
+ code: 400,
18
+ type: "Bad Request",
19
+ message: "Invalid Params",
20
+ description: "Please Check Kakao ServiceId",
21
21
  });
22
22
  let request = await serializeIngestkorea_restJson_SendAlimtalkCommand(input, config);
23
23
  return request;
24
24
  }
25
- ;
26
25
  async deserialize(response) {
27
26
  let output = await deserializeIngestkorea_restJson_SendAlimtalkCommand(response);
28
27
  return output;
29
28
  }
30
- ;
31
29
  }
32
- ;
33
30
  const resolveAlimtalkMessage = (message) => {
34
31
  const ALIMTALK_MAX = 1000;
35
32
  if (message.content.length > ALIMTALK_MAX)
36
33
  throw new IngestkoreaError({
37
- code: 400, type: 'Bad Request',
38
- message: 'Invalid Params', description: `Maximum message length is ${ALIMTALK_MAX}`
34
+ code: 400,
35
+ type: "Bad Request",
36
+ message: "Invalid Params",
37
+ description: `Maximum message length is ${ALIMTALK_MAX}`,
39
38
  });
40
39
  return {
41
40
  to: message.to.replace(/\-/gi, ""),
42
41
  content: message.content,
43
- ...(message.buttons != undefined && { buttons: message.buttons })
42
+ ...(message.buttons != undefined && { buttons: message.buttons }),
44
43
  };
45
44
  };
@@ -1,12 +1,10 @@
1
- import { SensCommand } from '../models';
2
- import { serializeIngestkorea_restJson_SendMMSCommand, deserializeIngestkorea_restJson_SendMMSCommand } from '../protocols/SendMMS';
3
- import { IngestkoreaError } from '@ingestkorea/util-error-handler';
4
- import { LMS_MAX, MMS_FILE_MAX, trimText, prettyPhoneNum, getContentLength } from './constants';
5
- import { parse } from 'node:path';
6
- import { randomUUID } from 'node:crypto';
7
- import { readFileSync, existsSync } from 'node:fs';
8
- ;
9
- ;
1
+ import { SensCommand } from "../models";
2
+ import { serializeIngestkorea_restJson_SendMMSCommand, deserializeIngestkorea_restJson_SendMMSCommand, } from "../protocols/SendMMS";
3
+ import { IngestkoreaError } from "@ingestkorea/util-error-handler";
4
+ import { LMS_MAX, MMS_FILE_MAX, trimText, prettyPhoneNum, getContentLength } from "./constants";
5
+ import { parse } from "node:path";
6
+ import { randomUUID } from "node:crypto";
7
+ import { readFileSync, existsSync } from "node:fs";
10
8
  export class SendMMSCommand extends SensCommand {
11
9
  constructor(input) {
12
10
  super(input);
@@ -16,42 +14,45 @@ export class SendMMSCommand extends SensCommand {
16
14
  content: resolveInputContent(input.content),
17
15
  type: resolveInputMessageType(input.type),
18
16
  messages: resolveInputMessages(input.messages),
19
- files: resolveInputFiles(input.files)
17
+ files: resolveInputFiles(input.files),
20
18
  };
21
19
  }
22
- ;
23
20
  async serialize(input, config) {
24
21
  if (!config.serviceId.sms)
25
22
  throw new IngestkoreaError({
26
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
23
+ code: 400,
24
+ type: "Bad Request",
25
+ message: "Invalid Params",
26
+ description: "Please Check SMS ServiceId",
27
27
  });
28
28
  let request = await serializeIngestkorea_restJson_SendMMSCommand(input, config);
29
29
  return request;
30
30
  }
31
- ;
32
31
  async deserialize(response) {
33
32
  let output = await deserializeIngestkorea_restJson_SendMMSCommand(response);
34
33
  return output;
35
34
  }
36
- ;
37
35
  }
38
- ;
39
36
  const resolveInputContent = (content) => {
40
37
  const resolvedContent = trimText(content);
41
38
  const contentLength = getContentLength(resolvedContent);
42
39
  if (!contentLength)
43
40
  throw new IngestkoreaError({
44
- code: 400, type: 'Bad Request',
45
- message: 'Invalid Request', description: `Please check input message`
41
+ code: 400,
42
+ type: "Bad Request",
43
+ message: "Invalid Request",
44
+ description: `Please check input message`,
46
45
  });
47
46
  if (contentLength > LMS_MAX)
48
47
  throw new IngestkoreaError({
49
- code: 400, type: 'Bad Request',
50
- message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
48
+ code: 400,
49
+ type: "Bad Request",
50
+ message: "Invalid Request",
51
+ description: `Maximum message length is ${LMS_MAX}bytes`,
51
52
  });
52
53
  return resolvedContent;
53
54
  };
54
- const resolveInputMessages = (messages) => messages.map(message => {
55
+ const resolveInputMessages = (messages) => messages.map((message) => {
55
56
  return {
56
57
  to: prettyPhoneNum(message.to),
57
58
  ...(message.content != undefined && { content: resolveInputContent(message.content) }),
@@ -59,29 +60,34 @@ const resolveInputMessages = (messages) => messages.map(message => {
59
60
  };
60
61
  });
61
62
  const resolveInputMessageType = (type) => {
62
- if (type == 'SMS' || type == 'LMS')
63
+ if (type == "SMS" || type == "LMS")
63
64
  throw new IngestkoreaError({
64
- code: 400, type: 'Bad Request',
65
- message: 'Invalid Request', description: `Please Call SendSMSCommand`
65
+ code: 400,
66
+ type: "Bad Request",
67
+ message: "Invalid Request",
68
+ description: `Please Call SendSMSCommand`,
66
69
  });
67
- return 'MMS';
70
+ return "MMS";
68
71
  };
69
72
  const resolveInputFiles = (files) => {
70
73
  if (!files.length)
71
74
  throw new IngestkoreaError({
72
- code: 400, type: 'Bad Request',
73
- message: 'Invalid Request', description: `Please Check Input Files`
75
+ code: 400,
76
+ type: "Bad Request",
77
+ message: "Invalid Request",
78
+ description: `Please Check Input Files`,
74
79
  });
75
- const output = files.map(file => {
80
+ const output = files.map((file) => {
76
81
  const resolvedFileName = verifyFileName(file.name);
77
82
  const resolvedFileBody = file.body != undefined ? file.body : getFileBody(file.name);
78
- let byte = Buffer.from(resolvedFileBody, 'base64').length;
83
+ let byte = Buffer.from(resolvedFileBody, "base64").length;
79
84
  let kib = Math.ceil(byte / 1024);
80
85
  if (kib > MMS_FILE_MAX)
81
86
  throw new IngestkoreaError({
82
- code: 400, type: 'Bad Request',
83
- message: 'Invalid Request',
84
- description: `Input File is ${kib}KiByte. Maximum File Size is ${MMS_FILE_MAX}Kibyte`
87
+ code: 400,
88
+ type: "Bad Request",
89
+ message: "Invalid Request",
90
+ description: `Input File is ${kib}KiByte. Maximum File Size is ${MMS_FILE_MAX}Kibyte`,
85
91
  });
86
92
  return { name: resolvedFileName, body: resolvedFileBody };
87
93
  });
@@ -91,19 +97,23 @@ const verifyFileName = (fileName) => {
91
97
  let { ext } = parse(fileName);
92
98
  const uuid = randomUUID();
93
99
  const extension = ext.replace(/jpeg|jpg/gi, "jpg");
94
- if (extension != '.jpg')
100
+ if (extension != ".jpg")
95
101
  throw new IngestkoreaError({
96
- code: 400, type: 'Bad Request',
97
- message: 'Invalid Request', description: `File Extension is not .jpg or .jpeg`
102
+ code: 400,
103
+ type: "Bad Request",
104
+ message: "Invalid Request",
105
+ description: `File Extension is not .jpg or .jpeg`,
98
106
  });
99
- return [uuid, extension].join('');
107
+ return [uuid, extension].join("");
100
108
  };
101
109
  /** @returns base64 */
102
110
  const getFileBody = (fileName) => {
103
111
  if (!existsSync(fileName))
104
112
  throw new IngestkoreaError({
105
- code: 400, type: 'Bad Request',
106
- message: 'Invalid Request', description: `${fileName} does not exist.`
113
+ code: 400,
114
+ type: "Bad Request",
115
+ message: "Invalid Request",
116
+ description: `${fileName} does not exist.`,
107
117
  });
108
- return readFileSync(fileName, { encoding: 'base64' });
118
+ return readFileSync(fileName, { encoding: "base64" });
109
119
  };
@@ -1,9 +1,7 @@
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
- ;
6
- ;
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";
7
5
  export class SendSMSCommand extends SensCommand {
8
6
  constructor(input) {
9
7
  super(input);
@@ -13,65 +11,68 @@ export class SendSMSCommand extends SensCommand {
13
11
  ...input,
14
12
  from: prettyPhoneNum(input.from),
15
13
  content: content,
16
- type: defaultMessageType === childMessageType ? defaultMessageType : 'LMS',
14
+ type: defaultMessageType === childMessageType ? defaultMessageType : "LMS",
17
15
  messages: messages,
18
16
  };
19
17
  }
20
- ;
21
18
  async serialize(input, config) {
22
19
  if (!config.serviceId.sms)
23
20
  throw new IngestkoreaError({
24
- code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
21
+ code: 400,
22
+ type: "Bad Request",
23
+ message: "Invalid Params",
24
+ description: "Please Check SMS ServiceId",
25
25
  });
26
26
  let request = await serializeIngestkorea_restJson_SendSMSCommand(input, config);
27
27
  return request;
28
28
  }
29
- ;
30
29
  async deserialize(response) {
31
30
  let output = await deserializeIngestkorea_restJson_SendSMSCommand(response);
32
31
  return output;
33
32
  }
34
- ;
35
33
  }
36
- ;
37
34
  const getMessageType = (input) => {
38
35
  const contentLength = getContentLength(input);
39
36
  if (!contentLength)
40
37
  throw new IngestkoreaError({
41
- code: 400, type: 'Bad Request',
42
- message: 'Invalid Request', description: `Please check input message`
38
+ code: 400,
39
+ type: "Bad Request",
40
+ message: "Invalid Request",
41
+ description: `Please check input message`,
43
42
  });
44
43
  if (contentLength > LMS_MAX)
45
44
  throw new IngestkoreaError({
46
- code: 400, type: 'Bad Request',
47
- message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
45
+ code: 400,
46
+ type: "Bad Request",
47
+ message: "Invalid Request",
48
+ description: `Maximum message length is ${LMS_MAX}bytes`,
48
49
  });
49
- return contentLength > SMS_MAX ? 'LMS' : 'SMS';
50
+ return contentLength > SMS_MAX ? "LMS" : "SMS";
50
51
  };
51
52
  const resolveInputContent = (content) => {
52
53
  const resolvedContent = trimText(content);
53
54
  const messageType = getMessageType(resolvedContent);
54
55
  return {
55
56
  content: resolvedContent,
56
- messageType: messageType
57
+ messageType: messageType,
57
58
  };
58
59
  };
59
60
  const resolveInputMessages = (messages) => {
60
61
  let init = {
61
62
  messages: [],
62
- messageType: 'SMS'
63
+ messageType: "SMS",
63
64
  };
64
65
  const output = messages.reduce((acc, message) => {
65
66
  const to = prettyPhoneNum(message.to);
66
67
  const content = message.content != undefined ? trimText(message.content) : undefined;
67
68
  const subject = message.subject != undefined ? trimText(message.subject) : undefined;
68
- const messageType = content != undefined ? getMessageType(content) : 'SMS';
69
- if (messageType == 'LMS')
69
+ const messageType = content != undefined ? getMessageType(content) : "SMS";
70
+ if (messageType == "LMS")
70
71
  acc.messageType = messageType;
71
72
  acc.messages.push({
72
73
  to: to,
73
74
  ...(content != undefined && { content: content }),
74
- ...(subject != undefined && acc.messageType === 'LMS' && { subject: subject }),
75
+ ...(subject != undefined && acc.messageType === "LMS" && { subject: subject }),
75
76
  });
76
77
  return acc;
77
78
  }, init);
@@ -5,10 +5,10 @@ export const trimText = (input) => input.trim();
5
5
  export const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
6
6
  /** @returns content-length(euc-kr) */
7
7
  export const getContentLength = (input) => {
8
- return input.split('').reduce((acc, text) => {
8
+ return input.split("").reduce((acc, text) => {
9
9
  let byte = Buffer.from(text).length;
10
10
  let modulo = byte % 3;
11
- modulo ? acc += 1 : acc += 2;
11
+ modulo ? (acc += 1) : (acc += 2);
12
12
  return acc;
13
13
  }, 0);
14
14
  };
@@ -1,10 +1,10 @@
1
- export * from './SendAlimtalkCommand';
2
- export * from './GetAlimtalkStatusCommand';
3
- export * from './GetAlimtalkResultCommand';
4
- export * from './GetAlimtalkTemplateCommand';
5
- export * from './ListAlimtalkTemplatesCommand';
6
- export * from './ListAlimtalkChannelsCommand';
7
- export * from './SendSMSCommand';
8
- export * from './SendMMSCommand';
9
- export * from './GetSMSStatusCommand';
10
- export * from './GetSMSResultCommand';
1
+ export * from "./SendAlimtalkCommand";
2
+ export * from "./GetAlimtalkStatusCommand";
3
+ export * from "./GetAlimtalkResultCommand";
4
+ export * from "./GetAlimtalkTemplateCommand";
5
+ export * from "./ListAlimtalkTemplatesCommand";
6
+ export * from "./ListAlimtalkChannelsCommand";
7
+ export * from "./SendSMSCommand";
8
+ export * from "./SendMMSCommand";
9
+ export * from "./GetSMSStatusCommand";
10
+ export * from "./GetSMSResultCommand";
package/dist-es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './commands';
2
- export * from './SensClient';
1
+ export * from "./commands";
2
+ export * from "./SensClient";
@@ -1,2 +1,4 @@
1
- export * from './signer-ncp';
2
- export * from './metadata-ingestkorea';
1
+ export * from "./middleware-sign";
2
+ export * from "./middleware-metadata";
3
+ export * from "./middleware-retry";
4
+ export * from "./middleware-sort-headers";
@@ -0,0 +1,6 @@
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.6.x";
4
+ request.headers[REQUEST_HEADER] = "attempt=1";
5
+ return request;
6
+ };
@@ -0,0 +1,51 @@
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;
5
+ let attempts = 0;
6
+ let totalRetryDelay = 0;
7
+ let lastError = new IngestkoreaError({
8
+ code: 400,
9
+ type: "Bad Request",
10
+ message: "Invalid Request",
11
+ description: { attempts, maxAttempts, totalRetryDelay },
12
+ });
13
+ while (true) {
14
+ 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
+ }
27
+ catch (err) {
28
+ 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) {
37
+ lastError.error.description = {
38
+ ...lastError.error.description,
39
+ detail: err.error.description,
40
+ };
41
+ }
42
+ if (err instanceof Error) {
43
+ lastError.error.description = {
44
+ ...lastError.error.description,
45
+ detail: err.message,
46
+ };
47
+ }
48
+ await new Promise((resolve) => setTimeout(resolve, delay));
49
+ }
50
+ }
51
+ };
@@ -1,5 +1,5 @@
1
- import { createHmac } from 'crypto';
2
- import { buildQueryString } from '@ingestkorea/util-http-handler';
1
+ import { createHmac } from "crypto";
2
+ import { buildQueryString } from "@ingestkorea/util-http-handler";
3
3
  export const middlewareNcpSigner = async (request, config) => {
4
4
  const { accessKey, secretKey } = config.credentials;
5
5
  const method = request.method;
@@ -8,17 +8,13 @@ export const middlewareNcpSigner = async (request, config) => {
8
8
  const space = " ";
9
9
  const newLine = "\n";
10
10
  const timestamp = new Date().getTime().toString();
11
- const stringToSign = [
12
- method + space + path,
13
- timestamp,
14
- accessKey
15
- ].join(newLine);
16
- const signature = createHmac("sha256", secretKey).update(stringToSign).digest('base64');
11
+ const stringToSign = [method + space + path, timestamp, accessKey].join(newLine);
12
+ const signature = createHmac("sha256", secretKey).update(stringToSign).digest("base64");
17
13
  request.headers = {
18
14
  ...request.headers,
19
- ['x-ncp-iam-access-key']: accessKey,
20
- ['x-ncp-apigw-timestamp']: timestamp,
21
- ['x-ncp-apigw-signature-v2']: signature
15
+ ["x-ncp-iam-access-key"]: accessKey,
16
+ ["x-ncp-apigw-timestamp"]: timestamp,
17
+ ["x-ncp-apigw-signature-v2"]: signature,
22
18
  };
23
19
  return request;
24
20
  };