@ingestkorea/client-sens 1.8.0 → 1.10.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 (71) hide show
  1. package/README.md +1 -0
  2. package/dist-cjs/SensClient.js +21 -18
  3. package/dist-cjs/commands/GetAlimtalkStatusCommand.js +1 -3
  4. package/dist-cjs/commands/GetSMSStatusCommand.js +2 -3
  5. package/dist-cjs/commands/ListAlimtalkStatusCommand.js +19 -11
  6. package/dist-cjs/commands/ListSMSStatusCommand.js +35 -0
  7. package/dist-cjs/commands/SendAlimtalkCommand.js +7 -14
  8. package/dist-cjs/commands/SendMMSCommand.js +9 -19
  9. package/dist-cjs/commands/SendSMSCommand.js +5 -7
  10. package/dist-cjs/commands/constants.js +47 -1
  11. package/dist-cjs/commands/index.js +1 -0
  12. package/dist-cjs/index.js +1 -0
  13. package/dist-cjs/middleware/middleware-metadata.js +1 -1
  14. package/dist-cjs/middleware/middleware-retry.js +19 -26
  15. package/dist-cjs/models/ListSMSStatus.js +2 -0
  16. package/dist-cjs/models/SensError.js +14 -0
  17. package/dist-cjs/models/SensErrorInfo.js +29 -11
  18. package/dist-cjs/models/index.js +2 -0
  19. package/dist-cjs/protocols/GetAlimtalkStatus.js +5 -5
  20. package/dist-cjs/protocols/GetAlimtalkTemplate.js +1 -1
  21. package/dist-cjs/protocols/GetSMSResult.js +3 -2
  22. package/dist-cjs/protocols/GetSMSStatus.js +28 -11
  23. package/dist-cjs/protocols/ListAlimtalkChannels.js +2 -2
  24. package/dist-cjs/protocols/ListAlimtalkTemplates.js +2 -2
  25. package/dist-cjs/protocols/ListSMSStatus.js +48 -0
  26. package/dist-cjs/protocols/SendAlimtalk.js +1 -1
  27. package/dist-cjs/protocols/SendSMS.js +1 -1
  28. package/dist-cjs/protocols/constants.js +80 -49
  29. package/dist-es/SensClient.js +21 -18
  30. package/dist-es/commands/GetAlimtalkStatusCommand.js +1 -3
  31. package/dist-es/commands/GetSMSStatusCommand.js +3 -0
  32. package/dist-es/commands/ListAlimtalkStatusCommand.js +22 -14
  33. package/dist-es/commands/ListSMSStatusCommand.js +46 -0
  34. package/dist-es/commands/SendAlimtalkCommand.js +7 -13
  35. package/dist-es/commands/SendMMSCommand.js +9 -19
  36. package/dist-es/commands/SendSMSCommand.js +5 -7
  37. package/dist-es/commands/constants.js +47 -1
  38. package/dist-es/commands/index.js +1 -0
  39. package/dist-es/index.js +1 -0
  40. package/dist-es/middleware/middleware-metadata.js +1 -1
  41. package/dist-es/middleware/middleware-retry.js +21 -32
  42. package/dist-es/models/ListSMSStatus.js +2 -0
  43. package/dist-es/models/SensError.js +14 -0
  44. package/dist-es/models/SensErrorInfo.js +29 -11
  45. package/dist-es/models/index.js +2 -0
  46. package/dist-es/protocols/GetAlimtalkStatus.js +12 -12
  47. package/dist-es/protocols/GetAlimtalkTemplate.js +1 -1
  48. package/dist-es/protocols/GetSMSResult.js +5 -9
  49. package/dist-es/protocols/GetSMSStatus.js +28 -11
  50. package/dist-es/protocols/ListAlimtalkChannels.js +2 -2
  51. package/dist-es/protocols/ListAlimtalkTemplates.js +2 -2
  52. package/dist-es/protocols/ListSMSStatus.js +42 -0
  53. package/dist-es/protocols/SendAlimtalk.js +1 -1
  54. package/dist-es/protocols/SendSMS.js +1 -1
  55. package/dist-es/protocols/constants.js +83 -52
  56. package/dist-types/commands/ListSMSStatusCommand.d.ts +11 -0
  57. package/dist-types/commands/constants.d.ts +17 -0
  58. package/dist-types/commands/index.d.ts +1 -0
  59. package/dist-types/index.d.ts +1 -0
  60. package/dist-types/models/GetSMSResult.d.ts +2 -6
  61. package/dist-types/models/GetSMSStatus.d.ts +15 -0
  62. package/dist-types/models/ListSMSStatus.d.ts +15 -0
  63. package/dist-types/models/SendAlimtalk.d.ts +1 -0
  64. package/dist-types/models/SensClient.d.ts +0 -1
  65. package/dist-types/models/SensError.d.ts +17 -0
  66. package/dist-types/models/SensErrorInfo.d.ts +51 -15
  67. package/dist-types/models/index.d.ts +2 -0
  68. package/dist-types/protocols/GetSMSStatus.d.ts +2 -1
  69. package/dist-types/protocols/ListSMSStatus.d.ts +4 -0
  70. package/dist-types/protocols/constants.d.ts +2 -1
  71. package/package.json +2 -3
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.de_SMSMessageRequestStatus = exports.de_GetSMSStatusCommand = exports.se_GetSMSStatusCommand = void 0;
12
+ exports.de_SMSMessageRequestStatus = exports.de_GetSMSStatusResult = exports.de_GetSMSStatusCommand = exports.se_GetSMSStatusCommand = void 0;
13
13
  const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const constants_js_1 = require("./constants.js");
15
15
  const se_GetSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
@@ -18,9 +18,12 @@ const se_GetSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, void
18
18
  const headers = {
19
19
  host: hostname,
20
20
  };
21
- const query = {
22
- requestId: input.requestId,
23
- };
21
+ const query = Object.entries(input).reduce((acc, [key, value]) => {
22
+ if (value !== undefined && value !== null) {
23
+ acc[key] = String(value);
24
+ }
25
+ return acc;
26
+ }, {});
24
27
  return new util_http_handler_1.HttpRequest({
25
28
  protocol: "https:",
26
29
  method: "GET",
@@ -35,7 +38,7 @@ const de_GetSMSStatusCommand = (response, config) => __awaiter(void 0, void 0, v
35
38
  if (response.statusCode >= 300)
36
39
  yield (0, constants_js_1.parseErrorBody)(response);
37
40
  const data = yield (0, constants_js_1.parseBody)(response);
38
- const contents = de_GetSMSStatusResult(data);
41
+ const contents = (0, exports.de_GetSMSStatusResult)(data);
39
42
  return Object.assign({ $metadata: (0, constants_js_1.deserializeMetadata)(response) }, (0, constants_js_1.compact)(contents));
40
43
  });
41
44
  exports.de_GetSMSStatusCommand = de_GetSMSStatusCommand;
@@ -45,19 +48,33 @@ const de_GetSMSStatusResult = (output) => {
45
48
  statusCode: output.statusCode ? output.statusCode : undefined,
46
49
  statusName: output.statusName ? output.statusName : undefined,
47
50
  messages: output.messages ? de_SMSMessageRequestStatusList(output.messages) : [],
51
+ pageSize: output.pageSize !== undefined ? output.pageSize : undefined,
52
+ pageIndex: output.pageIndex !== undefined ? output.pageIndex : undefined,
53
+ itemCount: output.itemCount !== undefined ? output.itemCount : undefined,
54
+ hasMore: output.hasMore !== undefined ? output.hasMore : undefined,
55
+ nextToken: output.nextToken ? output.nextToken : undefined,
48
56
  };
49
57
  };
58
+ exports.de_GetSMSStatusResult = de_GetSMSStatusResult;
50
59
  const de_SMSMessageRequestStatusList = (output) => {
51
60
  return (output || []).filter((e) => e != null).map((entry) => (0, exports.de_SMSMessageRequestStatus)(entry));
52
61
  };
53
62
  const de_SMSMessageRequestStatus = (output) => {
54
63
  return {
55
- messageId: output.messageId != undefined ? output.messageId : undefined,
56
- requestTime: output.requestTime != undefined ? output.requestTime : undefined,
57
- contentType: output.contentType != undefined ? output.contentType : undefined,
58
- countryCode: output.countryCode != undefined ? output.countryCode : undefined,
59
- from: output.from != undefined ? output.from : undefined,
60
- to: output.to != undefined ? output.to : undefined,
64
+ requestId: output.requestId ? output.requestId : undefined,
65
+ messageId: output.messageId ? output.messageId : undefined,
66
+ requestTime: output.requestTime ? (0, constants_js_1.convertToUtc)(output.requestTime) : undefined,
67
+ contentType: output.contentType ? output.contentType : undefined,
68
+ type: output.type ? output.type : undefined,
69
+ countryCode: output.countryCode ? output.countryCode : undefined,
70
+ from: output.from ? output.from : undefined,
71
+ to: output.to ? output.to : undefined,
72
+ completeTime: output.completeTime ? (0, constants_js_1.convertToUtc)(output.completeTime) : undefined,
73
+ telcoCode: output.telcoCode ? output.telcoCode : undefined,
74
+ status: output.status ? output.status : undefined,
75
+ statusCode: output.statusCode ? output.statusCode : undefined,
76
+ statusName: output.statusName ? output.statusName : undefined,
77
+ statusMessage: output.statusMessage ? output.statusMessage : undefined,
61
78
  };
62
79
  };
63
80
  exports.de_SMSMessageRequestStatus = de_SMSMessageRequestStatus;
@@ -45,8 +45,8 @@ const de_AlimtalkChannelList = (output) => {
45
45
  };
46
46
  const de_AlimtalkChannel = (output) => {
47
47
  return {
48
- createTime: output.createTime != undefined ? output.createTime : undefined,
49
- updateTime: output.updateTime != undefined ? output.updateTime : undefined,
48
+ createTime: output.createTime != undefined ? (0, constants_js_1.convertToUtc)(output.createTime) : undefined,
49
+ updateTime: output.updateTime != undefined ? (0, constants_js_1.convertToUtc)(output.updateTime) : undefined,
50
50
  serviceId: output.serviceId != undefined ? output.serviceId : undefined,
51
51
  channelId: output.channelId != undefined ? output.channelId : undefined,
52
52
  channelName: output.channelName != undefined ? output.channelName : undefined,
@@ -62,8 +62,8 @@ const de_TemplateList = (output) => {
62
62
  };
63
63
  const de_Template = (output) => {
64
64
  return {
65
- createTime: output.createTime != undefined ? output.createTime : undefined,
66
- updateTime: output.updateTime != undefined ? output.updateTime : undefined,
65
+ createTime: output.createTime ? (0, constants_js_1.convertToUtc)(output.createTime) : undefined,
66
+ updateTime: output.updateTime ? (0, constants_js_1.convertToUtc)(output.updateTime) : undefined,
67
67
  channelId: output.channelId != undefined ? output.channelId : undefined,
68
68
  templateCode: output.templateCode != undefined ? output.templateCode : undefined,
69
69
  templateName: output.templateName != undefined ? output.templateName : undefined,
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.de_ListSMSStatusCommand = exports.se_ListSMSStatusCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_js_1 = require("./constants.js");
15
+ const GetSMSStatus_js_1 = require("./GetSMSStatus.js");
16
+ const se_ListSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const hostname = "sens.apigw.ntruss.com";
18
+ const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
19
+ const headers = {
20
+ host: hostname,
21
+ };
22
+ const query = Object.entries(input).reduce((acc, [key, value]) => {
23
+ if (value !== undefined && value !== null) {
24
+ acc[key] = String(value);
25
+ }
26
+ return acc;
27
+ }, {});
28
+ return new util_http_handler_1.HttpRequest({
29
+ protocol: "https:",
30
+ method: "GET",
31
+ hostname,
32
+ path,
33
+ query,
34
+ headers,
35
+ });
36
+ });
37
+ exports.se_ListSMSStatusCommand = se_ListSMSStatusCommand;
38
+ const de_ListSMSStatusCommand = (response, config) => __awaiter(void 0, void 0, void 0, function* () {
39
+ if (response.statusCode >= 300)
40
+ yield (0, constants_js_1.parseErrorBody)(response);
41
+ const data = yield (0, constants_js_1.parseBody)(response);
42
+ const contents = de_ListSMSStatusResult(data);
43
+ return Object.assign({ $metadata: (0, constants_js_1.deserializeMetadata)(response) }, (0, constants_js_1.compact)(contents));
44
+ });
45
+ exports.de_ListSMSStatusCommand = de_ListSMSStatusCommand;
46
+ const de_ListSMSStatusResult = (output) => {
47
+ return (0, GetSMSStatus_js_1.de_GetSMSStatusResult)(output);
48
+ };
@@ -45,7 +45,7 @@ exports.de_SendAlimtalkCommand = de_SendAlimtalkCommand;
45
45
  const de_SendAlimtalkResult = (output) => {
46
46
  return {
47
47
  requestId: output.requestId != undefined ? output.requestId : undefined,
48
- requestTime: output.requestTime != undefined ? output.requestTime : undefined,
48
+ requestTime: output.requestTime != undefined ? (0, constants_js_1.convertToUtc)(output.requestTime) : undefined,
49
49
  statusCode: output.statusCode != undefined ? output.statusCode : undefined,
50
50
  statusName: output.statusName != undefined ? output.statusName : undefined,
51
51
  messages: output.messages ? de_AlimtalkMessageRequestStatusList(output.messages) : [],
@@ -41,7 +41,7 @@ exports.de_SendSMSCommand = de_SendSMSCommand;
41
41
  const de_SendSMSResult = (output) => {
42
42
  return {
43
43
  requestId: output.requestId ? output.requestId : undefined,
44
- requestTime: output.requestTime ? output.requestTime : undefined,
44
+ requestTime: output.requestTime ? (0, constants_js_1.convertToUtc)(output.requestTime) : undefined,
45
45
  statusCode: output.statusCode ? output.statusCode : undefined,
46
46
  statusName: output.statusName ? output.statusName : undefined,
47
47
  };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.compact = exports.parseErrorBody = exports.parseBody = exports.deserializeMetadata = void 0;
12
+ exports.convertToUtc = exports.compact = exports.parseErrorBody = exports.parseBody = exports.deserializeMetadata = void 0;
13
13
  const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
14
  const index_js_1 = require("../models/index.js");
15
15
  const constants_js_1 = require("../middleware/constants.js");
@@ -28,75 +28,79 @@ const parseBody = (output) => __awaiter(void 0, void 0, void 0, function* () {
28
28
  if (!isJsonResponse(headers["content-type"])) {
29
29
  yield (0, util_http_handler_1.destroyStream)(streamBody);
30
30
  throw new index_js_1.SensError({
31
- code: statusCode !== null && statusCode !== void 0 ? statusCode : 400,
32
- type: "Bad Request",
31
+ code: -1,
32
+ type: "SDK.REQUEST_ERROR",
33
33
  message: "response content-type is not application/json",
34
34
  });
35
35
  }
36
- const data = yield (0, util_http_handler_1.collectBodyString)(streamBody);
37
- if (data.length) {
38
- try {
39
- return JSON.parse(data);
40
- }
41
- catch (e) {
42
- yield (0, util_http_handler_1.destroyStream)(streamBody);
43
- throw new index_js_1.SensError({
44
- code: statusCode !== null && statusCode !== void 0 ? statusCode : 400,
45
- type: "Bad Request",
46
- message: "parse response body error",
47
- });
48
- }
36
+ try {
37
+ const data = yield (0, util_http_handler_1.collectBodyString)(streamBody);
38
+ return data.length ? JSON.parse(data) : {};
39
+ }
40
+ catch (e) {
41
+ throw new index_js_1.SensError({
42
+ code: -1,
43
+ type: "SDK.REQUEST_ERROR",
44
+ message: e instanceof Error ? e.message : "parse response body error",
45
+ });
49
46
  }
50
- return {};
51
47
  });
52
48
  exports.parseBody = parseBody;
53
49
  const parseErrorBody = (output) => __awaiter(void 0, void 0, void 0, function* () {
54
50
  const { statusCode, headers, body: streamBody } = output;
55
- const error = new index_js_1.SensError({
56
- code: statusCode !== null && statusCode !== void 0 ? statusCode : 400,
57
- type: "Bad Request",
58
- message: "something wrong",
59
- });
60
51
  if (!isJsonResponse(headers["content-type"])) {
61
52
  yield (0, util_http_handler_1.destroyStream)(streamBody);
62
- error.message = "response content-type is not application/json";
63
- throw error;
53
+ throw new index_js_1.SensError({
54
+ code: -1,
55
+ type: "SDK.REQUEST_ERROR",
56
+ message: "response content-type is not application/json",
57
+ });
64
58
  }
65
59
  const data = yield (0, util_http_handler_1.collectBodyString)(streamBody);
66
- yield (0, util_http_handler_1.destroyStream)(streamBody);
67
- const sensErrorBody = isSensErrorBody(data);
68
- if (!sensErrorBody) {
69
- throw error;
60
+ const sensErrorBody = isSensErrorResponse(data);
61
+ const nCloudErrorBody = isNCloudErrorResponse(data);
62
+ if (sensErrorBody) {
63
+ const errorType = isSensErrorCode(sensErrorBody.status)
64
+ ? index_js_1.SENS_ERROR_CODE_SPEC[sensErrorBody.status]
65
+ : "SDK.UNKNOWN_ERROR";
66
+ throw new index_js_1.SensError(Object.assign({ code: isSensErrorCode(sensErrorBody.status) ? sensErrorBody.status : statusCode, type: errorType, message: sensErrorBody.errorMessage || errorType }, (sensErrorBody.errors &&
67
+ Array.isArray(sensErrorBody.errors) && {
68
+ errors: sensErrorBody.errors.filter((d) => !!d),
69
+ })));
70
+ }
71
+ if (nCloudErrorBody) {
72
+ const { errorCode } = nCloudErrorBody.error;
73
+ const errorType = isNCloudErrorCode(errorCode)
74
+ ? index_js_1.NCLOUD_ERROR_CODE_SPEC[errorCode].type
75
+ : "SDK.UNKNOWN_ERROR";
76
+ throw new index_js_1.SensError({
77
+ code: isNCloudErrorCode(errorCode) ? index_js_1.NCLOUD_ERROR_CODE_SPEC[errorCode].status : statusCode,
78
+ type: errorType,
79
+ message: nCloudErrorBody.error.details || "Something wrong",
80
+ });
70
81
  }
71
- throw new index_js_1.SensError(Object.assign({ code: sensErrorBody.status, type: SENS_ERROR_CODE_SPEC[sensErrorBody.status] || "Unknown Error", message: sensErrorBody.errorMessage || "Something wrong" }, (sensErrorBody.errors &&
72
- Array.isArray(sensErrorBody.errors) && {
73
- invalidInputs: sensErrorBody.errors.map((msg) => {
74
- return { type: "not-valid.args", message: msg };
75
- }),
76
- })));
82
+ throw new index_js_1.SensError({
83
+ code: -1,
84
+ type: "SDK.UNKNOWN_ERROR",
85
+ message: "Invalid Naver Cloud Platform response format",
86
+ errors: [`${statusCode} - ${data.slice(0, 120)}...`],
87
+ });
77
88
  });
78
89
  exports.parseErrorBody = parseErrorBody;
79
- const SENS_ERROR_CODE_SPEC = {
80
- 400: "Bad Request",
81
- 401: "Unauthorized",
82
- 403: "Forbidden",
83
- 404: "Not Found",
84
- 429: "Too Many Requests",
85
- 500: "Internal Server Error",
90
+ const isSensErrorCode = (code) => {
91
+ return code in index_js_1.SENS_ERROR_CODE_SPEC;
92
+ };
93
+ const isNCloudErrorCode = (code) => {
94
+ return code in index_js_1.NCLOUD_ERROR_CODE_SPEC;
86
95
  };
87
- const SENS_ERROR_BODY_SPEC = [
88
- ["status", "number", true],
89
- ["errorMessage", "string", false],
90
- ["errors", "object", false],
91
- ];
92
- const isSensErrorBody = (input) => {
96
+ const isSensErrorResponse = (input) => {
93
97
  if (typeof input !== "string")
94
98
  return null;
95
99
  try {
96
100
  const data = JSON.parse(input);
97
101
  if (!data || typeof data !== "object")
98
102
  return null;
99
- const isValid = SENS_ERROR_BODY_SPEC.every(([key, type, required]) => {
103
+ const isValid = index_js_1.SENS_ERROR_BODY_SPEC.every(([key, type, required]) => {
100
104
  const value = data[key];
101
105
  if (required && (value === undefined || value === null))
102
106
  return false;
@@ -110,6 +114,27 @@ const isSensErrorBody = (input) => {
110
114
  return null;
111
115
  }
112
116
  };
117
+ const isNCloudErrorResponse = (input) => {
118
+ if (typeof input !== "string")
119
+ return null;
120
+ try {
121
+ const data = JSON.parse(input);
122
+ if (!(data && typeof data == "object" && typeof data.error == "object"))
123
+ return null;
124
+ const isValid = index_js_1.NCLOUD_ERROR_BODY_SPEC.every(([key, type, required]) => {
125
+ const value = data.error[key];
126
+ if (required && (value === undefined || value === null))
127
+ return false;
128
+ if (value !== undefined && typeof value !== type)
129
+ return false;
130
+ return true;
131
+ });
132
+ return isValid ? data : null;
133
+ }
134
+ catch (_a) {
135
+ return null;
136
+ }
137
+ };
113
138
  const compact = (obj) => {
114
139
  if (Array.isArray(obj)) {
115
140
  return obj.map((item) => (0, exports.compact)(item));
@@ -123,6 +148,12 @@ const compact = (obj) => {
123
148
  return obj;
124
149
  };
125
150
  exports.compact = compact;
151
+ const convertToUtc = (input) => {
152
+ const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
153
+ return utcRegex.test(input) ? input : new Date(input.replace(" ", "T") + "+09:00").toISOString();
154
+ };
155
+ exports.convertToUtc = convertToUtc;
126
156
  const isJsonResponse = (contentType) => {
127
- return /application\/json/gi.exec(contentType || "") ? true : false;
157
+ var _a;
158
+ return (_a = contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().includes("application/json")) !== null && _a !== void 0 ? _a : false;
128
159
  };
@@ -23,8 +23,14 @@ class SensClient {
23
23
  const output = await deserializer(response, this.config);
24
24
  return output;
25
25
  }
26
- catch (e) {
27
- throw e;
26
+ catch (err) {
27
+ if (err instanceof index_js_1.SensError)
28
+ throw err;
29
+ throw new index_js_1.SensError({
30
+ code: -1,
31
+ type: "SDK.UNKNOWN_ERROR",
32
+ message: err instanceof Error ? err.message : "unknown error",
33
+ });
28
34
  }
29
35
  }
30
36
  }
@@ -37,20 +43,19 @@ const composeMiddleware = (middlewares, finalHandler) => {
37
43
  };
38
44
  const resolveCredentials = (config) => {
39
45
  const { credentials } = config;
40
- let error = new index_js_1.SensError({
41
- code: 401,
42
- type: "Unauthorized",
43
- message: "Invalid Credentials",
44
- invalidInputs: [{ type: "not-valid.args", message: "SensClient 초기화시 인증 정보를 확인해주세요" }],
46
+ const error = new index_js_1.SensError({
47
+ code: -1,
48
+ type: "SDK.AUTH_ERROR",
49
+ message: "SensClient 초기화시 인증 정보를 입력해주세요.",
45
50
  });
46
51
  if (!credentials)
47
52
  throw error;
48
53
  if (!credentials.accessKey) {
49
- error.invalidInputs[0].message = "AccessKey 정보를 확인해주세요";
54
+ error.message = "AccessKey 정보를 확인해주세요.";
50
55
  throw error;
51
56
  }
52
57
  if (!credentials.secretKey) {
53
- error.invalidInputs[0].message = "SecretKey 정보를 확인해주세요";
58
+ error.message = "SecretKey 정보를 확인해주세요.";
54
59
  throw error;
55
60
  }
56
61
  return {
@@ -59,24 +64,22 @@ const resolveCredentials = (config) => {
59
64
  };
60
65
  };
61
66
  const resolveServiceId = (config) => {
62
- var _a, _b, _c;
67
+ var _a, _b;
63
68
  const { serviceId } = config;
64
- let error = new index_js_1.SensError({
65
- code: 400,
66
- type: "Bad Request",
67
- message: "Invalid ServiceId",
68
- invalidInputs: [{ type: "not-valid.args", message: "SensClient 초기화시 서비스 정보를 확인해주세요" }],
69
+ const error = new index_js_1.SensError({
70
+ code: -1,
71
+ type: "SDK.GENERAL_ERROR",
72
+ message: "SensClient 초기화시 사용할 서비스 정보를 입력해주세요.",
69
73
  });
70
74
  if (!serviceId)
71
75
  throw error;
72
76
  const isReady = !!Object.values(serviceId).filter((d) => !!d).length;
73
77
  if (!isReady) {
74
- error.invalidInputs[0].message = "최소 1개 이상의 서비스 정보가 필요합니다";
78
+ error.message = "최소 1개 이상의 서비스 정보가 필요합니다";
75
79
  throw error;
76
80
  }
77
81
  return {
78
82
  kakao: (_a = serviceId.kakao) !== null && _a !== void 0 ? _a : "",
79
- push: (_b = serviceId.push) !== null && _b !== void 0 ? _b : "",
80
- sms: (_c = serviceId.sms) !== null && _c !== void 0 ? _c : "",
83
+ sms: (_b = serviceId.sms) !== null && _b !== void 0 ? _b : "",
81
84
  };
82
85
  };
@@ -4,14 +4,12 @@ exports.GetAlimtalkStatusCommand = void 0;
4
4
  const index_js_1 = require("../models/index.js");
5
5
  const GetAlimtalkStatus_js_1 = require("../protocols/GetAlimtalkStatus.js");
6
6
  const MAX_LIMIT = 100;
7
- const DEFAULT_LIMIT = 20;
8
7
  class GetAlimtalkStatusCommand extends index_js_1.SensCommand {
9
8
  constructor(input) {
10
- var _a;
11
9
  super(input);
12
10
  this.input = {
13
11
  requestId: input.requestId,
14
- pageSize: Math.min(MAX_LIMIT, Math.max(1, (_a = input.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_LIMIT)),
12
+ pageSize: input.pageSize ? Math.min(MAX_LIMIT, Math.max(1, input.pageSize)) : MAX_LIMIT,
15
13
  ...(input.nextToken && { nextToken: input.nextToken }),
16
14
  };
17
15
  this.serializer = GetAlimtalkStatus_js_1.se_GetAlimtalkStatusCommand;
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetSMSStatusCommand = void 0;
4
4
  const index_js_1 = require("../models/index.js");
5
5
  const GetSMSStatus_js_1 = require("../protocols/GetSMSStatus.js");
6
+ const MAX_LIMIT = 100;
6
7
  class GetSMSStatusCommand extends index_js_1.SensCommand {
7
8
  constructor(input) {
8
9
  super(input);
9
10
  this.input = {
10
11
  requestId: input.requestId,
12
+ pageSize: input.pageSize ? Math.min(MAX_LIMIT, Math.max(1, input.pageSize)) : MAX_LIMIT,
13
+ ...(input.nextToken && { nextToken: input.nextToken }),
11
14
  };
12
15
  this.serializer = GetSMSStatus_js_1.se_GetSMSStatusCommand;
13
16
  this.deserializer = GetSMSStatus_js_1.de_GetSMSStatusCommand;
@@ -3,26 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ListAlimtalkStatusCommand = void 0;
4
4
  const index_js_1 = require("../models/index.js");
5
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;
6
+ const constants_js_1 = require("./constants.js");
7
+ const DURATION_LIMIT_MS = 30 * 24 * 3600000; // 30일 이내만 조회 가능
8
8
  const MAX_LIMIT = 100;
9
9
  const DEFAULT_LIMIT = 20;
10
10
  class ListAlimtalkStatusCommand extends index_js_1.SensCommand {
11
11
  constructor(input) {
12
12
  var _a;
13
13
  super(input);
14
- const { startTime, endTime } = getDefaultRequestDurationKST({ durationLimit: DURATION_LIMIT });
14
+ if (input.nextToken && (!input.requestStartTime || !input.requestEndTime)) {
15
+ throw new index_js_1.SensError({
16
+ code: -1,
17
+ type: "SDK.GENERAL_ERROR",
18
+ message: "페이지네이션 검색 조건 불일치",
19
+ errors: [
20
+ "nextToken 사용 시 데이터 일관성을 위해 최초 요청 시의 옵션이 모두 동일하게 유지되어야 합니다.",
21
+ "requestStartTime, requestEndTime, pageSize 옵션을 확인해주세요.",
22
+ ],
23
+ });
24
+ }
25
+ const defaultDuration = (0, constants_js_1.getDefaultRequestDuration)({ durationLimitMs: DURATION_LIMIT_MS });
26
+ const { startTimeMs, endTimeMs } = (0, constants_js_1.resolveRequestDuration)({
27
+ startTime: input.requestStartTime ? (0, constants_js_1.convertToUtc)(input.requestStartTime) : defaultDuration.startTime,
28
+ endTime: input.requestEndTime ? (0, constants_js_1.convertToUtc)(input.requestEndTime) : defaultDuration.endTime,
29
+ }, { durationLimitMs: DURATION_LIMIT_MS });
15
30
  this.input = {
16
31
  plusFriendId: input.plusFriendId,
17
- requestStartTime: input.requestStartTime ? input.requestStartTime : startTime,
18
- requestEndTime: input.requestEndTime ? input.requestEndTime : endTime,
32
+ requestStartTime: (0, constants_js_1.convertToKst)(startTimeMs),
33
+ requestEndTime: (0, constants_js_1.convertToKst)(endTimeMs),
19
34
  pageSize: Math.min(MAX_LIMIT, Math.max(1, (_a = input.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_LIMIT)),
20
35
  ...(input.requestStatusName && { requestStatusName: input.requestStatusName }),
21
36
  ...(input.messageStatusName && { messageStatusName: input.messageStatusName }),
22
- ...(input.requestId && { requestId: input.requestId }),
37
+ ...(input.requestId && { requestId: input.requestId, pageSize: MAX_LIMIT }),
23
38
  ...(input.messageId && { messageId: input.messageId }),
24
39
  ...(input.templateCode && { templateCode: input.templateCode }),
25
- ...(input.to && { to: input.to.replace(/\-/gi, "") }),
40
+ ...(input.to && { to: (0, constants_js_1.prettyPhoneNum)(input.to) }),
26
41
  ...(input.nextToken && { nextToken: input.nextToken }),
27
42
  };
28
43
  this.serializer = ListAlimtalkStatus_js_1.se_ListAlimtalkStatusCommand;
@@ -30,10 +45,3 @@ class ListAlimtalkStatusCommand extends index_js_1.SensCommand {
30
45
  }
31
46
  }
32
47
  exports.ListAlimtalkStatusCommand = ListAlimtalkStatusCommand;
33
- const getDefaultRequestDurationKST = (config) => {
34
- const now = new Date().getTime() + KST_OFFSET;
35
- return {
36
- startTime: new Date(now - config.durationLimit).toISOString().replace(/\.\d{3}Z$/, ""),
37
- endTime: new Date(now).toISOString().replace(/\.\d{3}Z$/, ""),
38
- };
39
- };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListSMSStatusCommand = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const ListSMSStatus_js_1 = require("../protocols/ListSMSStatus.js");
6
+ const constants_js_1 = require("./constants.js");
7
+ const DURATION_LIMIT_MS = 30 * 24 * 3600000; // 30일 이내만 조회 가능
8
+ const MAX_LIMIT = 100;
9
+ const DEFAULT_LIMIT = 20;
10
+ class ListSMSStatusCommand extends index_js_1.SensCommand {
11
+ constructor(input) {
12
+ var _a;
13
+ super(input);
14
+ if (input.nextToken && (!input.requestStartTime || !input.requestEndTime)) {
15
+ throw new index_js_1.SensError({
16
+ code: -1,
17
+ type: "SDK.GENERAL_ERROR",
18
+ message: "페이지네이션 검색 조건 불일치",
19
+ errors: [
20
+ "nextToken 사용 시 데이터 일관성을 위해 최초 요청 시의 옵션이 모두 동일하게 유지되어야 합니다.",
21
+ "requestStartTime, requestEndTime, pageSize 옵션을 확인해주세요.",
22
+ ],
23
+ });
24
+ }
25
+ const defaultDuration = (0, constants_js_1.getDefaultRequestDuration)({ durationLimitMs: DURATION_LIMIT_MS });
26
+ const { startTimeMs, endTimeMs } = (0, constants_js_1.resolveRequestDuration)({
27
+ startTime: input.requestStartTime ? (0, constants_js_1.convertToUtc)(input.requestStartTime) : defaultDuration.startTime,
28
+ endTime: input.requestEndTime ? (0, constants_js_1.convertToUtc)(input.requestEndTime) : defaultDuration.endTime,
29
+ }, { durationLimitMs: DURATION_LIMIT_MS });
30
+ this.input = {
31
+ requestStartTime: (0, constants_js_1.convertToKst)(startTimeMs),
32
+ requestEndTime: (0, constants_js_1.convertToKst)(endTimeMs),
33
+ pageSize: Math.min(MAX_LIMIT, Math.max(1, (_a = input.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_LIMIT)),
34
+ ...(input.type && { type: input.type }),
35
+ ...(input.contentType && { contentType: input.contentType }),
36
+ ...(input.status && { status: input.status }),
37
+ ...(input.from && { from: (0, constants_js_1.prettyPhoneNum)(input.from) }),
38
+ ...(input.to && { to: (0, constants_js_1.prettyPhoneNum)(input.to) }),
39
+ ...(input.statusName && { statusName: input.statusName }),
40
+ ...(input.nextToken && { nextToken: input.nextToken }),
41
+ };
42
+ this.serializer = ListSMSStatus_js_1.se_ListSMSStatusCommand;
43
+ this.deserializer = ListSMSStatus_js_1.de_ListSMSStatusCommand;
44
+ }
45
+ }
46
+ exports.ListSMSStatusCommand = ListSMSStatusCommand;
@@ -22,29 +22,23 @@ exports.SendAlimtalkCommand = SendAlimtalkCommand;
22
22
  const resolveAlimtalkMessages = (messages, config) => {
23
23
  if (!messages.length || messages.length > config.maxRecipients) {
24
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
- ],
25
+ code: -1,
26
+ type: "SDK.GENERAL_ERROR",
27
+ message: `알림톡 동시 발송은 최소 1명, 최대 ${config.maxRecipients}명까지 가능합니다.`,
34
28
  });
35
29
  }
36
30
  const result = messages.map((message) => {
37
31
  if (message.content.length > config.maxContentLength) {
38
32
  throw new index_js_1.SensError({
39
- code: 400,
40
- type: "Bad Request",
41
- message: "알림톡 최대 길이 초과",
42
- invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${config.maxContentLength}글자입니다` }],
33
+ code: -1,
34
+ type: "SDK.GENERAL_ERROR",
35
+ message: `알림톡 최대 길이는 ${config.maxContentLength}글자입니다`,
43
36
  });
44
37
  }
45
38
  return {
46
39
  to: message.to.replace(/\-/gi, ""),
47
40
  content: message.content,
41
+ useSmsFailover: message.useSmsFailover != undefined ? message.useSmsFailover : false,
48
42
  ...(message.buttons && message.buttons.length && { buttons: message.buttons }),
49
43
  };
50
44
  });
@@ -36,12 +36,9 @@ const resolveSendFile = (file, options) => {
36
36
  const ext = parsed.ext.toLocaleLowerCase();
37
37
  if (!options.supportExt.includes(ext)) {
38
38
  throw new index_js_1.SensError({
39
- code: 400,
40
- type: "Bad Request",
41
- message: "지원하지 않는 확장자입니다.",
42
- invalidInputs: [
43
- { type: "not-valid.args", message: `${options.supportExt.join(", ")} 형식의 첨부파일만 지원합니다.` },
44
- ],
39
+ code: -1,
40
+ type: "SDK.GENERAL_ERROR",
41
+ message: `MMS는 ${options.supportExt.join(", ")} 형식의 첨부파일만 보낼 수 있습니다.`,
45
42
  });
46
43
  }
47
44
  if (file.body) {
@@ -55,10 +52,9 @@ const resolveSendFile = (file, options) => {
55
52
  }
56
53
  if (!(0, node_fs_1.existsSync)(file.name)) {
57
54
  throw new index_js_1.SensError({
58
- code: 400,
59
- type: "Bad Request",
60
- message: "파일이 존재하지 않습니다.",
61
- invalidInputs: [{ type: "not-valid.args", message: `${file.name} 파일이 존재하지 않습니다.` }],
55
+ code: -1,
56
+ type: "SDK.GENERAL_ERROR",
57
+ message: `${file.name} 첨부파일이 존재하지 않습니다.`,
62
58
  });
63
59
  }
64
60
  const buffer = (0, node_fs_1.readFileSync)(file.name);
@@ -74,15 +70,9 @@ const checkSizeLimit = (buffer, maxKiB) => {
74
70
  const kibSize = Math.ceil(byteSize / 1024);
75
71
  if (kibSize > maxKiB) {
76
72
  throw new index_js_1.SensError({
77
- code: 400,
78
- type: "Bad Request",
79
- message: `최대 첨부가능 용량이 초과되었습니다.`,
80
- invalidInputs: [
81
- {
82
- type: "not-valid.args",
83
- message: `최대 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
84
- },
85
- ],
73
+ code: -1,
74
+ type: "SDK.GENERAL_ERROR",
75
+ message: `첨부파일은 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
86
76
  });
87
77
  }
88
78
  return;