@ingestkorea/client-sens 1.9.0 → 1.11.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.
- package/README.md +99 -57
- package/dist-cjs/SensClient.js +42 -43
- package/dist-cjs/commands/GetAlimtalkResultCommand.js +3 -0
- package/dist-cjs/commands/GetAlimtalkStatusCommand.js +8 -1
- package/dist-cjs/commands/GetAlimtalkTemplateCommand.js +3 -0
- package/dist-cjs/commands/GetSMSResultCommand.js +3 -0
- package/dist-cjs/commands/GetSMSStatusCommand.js +8 -1
- package/dist-cjs/commands/ListAlimtalkChannelsCommand.js +3 -0
- package/dist-cjs/commands/ListAlimtalkStatusCommand.js +22 -10
- package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +3 -0
- package/dist-cjs/commands/ListSMSStatusCommand.js +21 -10
- package/dist-cjs/commands/SendAlimtalkCommand.js +15 -14
- package/dist-cjs/commands/SendMMSCommand.js +16 -23
- package/dist-cjs/commands/SendSMSCommand.js +28 -16
- package/dist-cjs/commands/constants.js +8 -19
- package/dist-cjs/index.js +1 -0
- package/dist-cjs/middleware/constants.js +2 -1
- package/dist-cjs/middleware/middleware-metadata.js +7 -12
- package/dist-cjs/middleware/middleware-retry.js +48 -38
- package/dist-cjs/middleware/middleware-sign.js +8 -12
- package/dist-cjs/models/SensApiError.js +21 -0
- package/dist-cjs/models/{SensErrorInfo.js → SensClientError.js} +6 -1
- package/dist-cjs/models/SensCommand.js +1 -0
- package/dist-cjs/models/index.js +2 -1
- package/dist-cjs/protocols/GetAlimtalkResult.js +14 -17
- package/dist-cjs/protocols/GetAlimtalkStatus.js +21 -17
- package/dist-cjs/protocols/GetAlimtalkTemplate.js +29 -17
- package/dist-cjs/protocols/GetSMSResult.js +16 -17
- package/dist-cjs/protocols/GetSMSStatus.js +10 -16
- package/dist-cjs/protocols/ListAlimtalkChannels.js +10 -16
- package/dist-cjs/protocols/ListAlimtalkStatus.js +10 -16
- package/dist-cjs/protocols/ListAlimtalkTemplates.js +12 -19
- package/dist-cjs/protocols/ListSMSStatus.js +10 -16
- package/dist-cjs/protocols/SendAlimtalk.js +10 -16
- package/dist-cjs/protocols/SendMMS.js +4 -13
- package/dist-cjs/protocols/SendSMS.js +11 -17
- package/dist-cjs/protocols/constants.js +124 -82
- package/dist-es/SensClient.js +37 -31
- package/dist-es/commands/GetAlimtalkResultCommand.js +8 -9
- package/dist-es/commands/GetAlimtalkStatusCommand.js +8 -9
- package/dist-es/commands/GetAlimtalkTemplateCommand.js +8 -9
- package/dist-es/commands/GetSMSResultCommand.js +8 -9
- package/dist-es/commands/GetSMSStatusCommand.js +8 -9
- package/dist-es/commands/ListAlimtalkChannelsCommand.js +8 -9
- package/dist-es/commands/ListAlimtalkStatusCommand.js +24 -28
- package/dist-es/commands/ListAlimtalkTemplatesCommand.js +8 -9
- package/dist-es/commands/ListSMSStatusCommand.js +25 -29
- package/dist-es/commands/SendAlimtalkCommand.js +18 -26
- package/dist-es/commands/SendMMSCommand.js +37 -48
- package/dist-es/commands/SendSMSCommand.js +25 -29
- package/dist-es/commands/constants.js +18 -39
- package/dist-es/commands/index.js +12 -28
- package/dist-es/index.js +3 -18
- package/dist-es/middleware/constants.js +8 -10
- package/dist-es/middleware/index.js +3 -19
- package/dist-es/middleware/middleware-metadata.js +4 -7
- package/dist-es/middleware/middleware-retry.js +47 -38
- package/dist-es/middleware/middleware-sign.js +9 -13
- package/dist-es/models/GetAlimtalkResult.js +1 -2
- package/dist-es/models/GetAlimtalkStatus.js +1 -2
- package/dist-es/models/GetAlimtalkTemplate.js +1 -2
- package/dist-es/models/GetSMSResult.js +1 -2
- package/dist-es/models/GetSMSStatus.js +1 -2
- package/dist-es/models/ListAlimtalkChannels.js +1 -2
- package/dist-es/models/ListAlimtalkStatus.js +1 -2
- package/dist-es/models/ListAlimtalkTemplates.js +1 -2
- package/dist-es/models/ListSMSStatus.js +1 -2
- package/dist-es/models/MetadataBearer.js +1 -2
- package/dist-es/models/SendAlimtalk.js +2 -5
- package/dist-es/models/SendMMS.js +2 -5
- package/dist-es/models/SendSMS.js +1 -2
- package/dist-es/models/SensApiError.js +18 -0
- package/dist-es/models/SensClient.js +1 -2
- package/dist-es/models/SensClientError.js +14 -0
- package/dist-es/models/SensCommand.js +2 -5
- package/dist-es/models/SensMiddleware.js +1 -2
- package/dist-es/models/index.js +18 -33
- package/dist-es/protocols/GetAlimtalkResult.js +11 -16
- package/dist-es/protocols/GetAlimtalkStatus.js +17 -24
- package/dist-es/protocols/GetAlimtalkTemplate.js +12 -17
- package/dist-es/protocols/GetSMSResult.js +11 -16
- package/dist-es/protocols/GetSMSStatus.js +15 -22
- package/dist-es/protocols/ListAlimtalkChannels.js +11 -16
- package/dist-es/protocols/ListAlimtalkStatus.js +11 -16
- package/dist-es/protocols/ListAlimtalkTemplates.js +15 -22
- package/dist-es/protocols/ListSMSStatus.js +11 -16
- package/dist-es/protocols/SendAlimtalk.js +12 -18
- package/dist-es/protocols/SendMMS.js +5 -10
- package/dist-es/protocols/SendSMS.js +12 -18
- package/dist-es/protocols/constants.js +126 -88
- package/dist-types/SensClient.d.ts +0 -1
- package/dist-types/index.d.ts +1 -0
- package/dist-types/middleware/constants.d.ts +1 -0
- package/dist-types/models/MetadataBearer.d.ts +1 -0
- package/dist-types/models/SensApiError.d.ts +55 -0
- package/dist-types/models/SensClient.d.ts +8 -1
- package/dist-types/models/SensClientError.d.ts +18 -0
- package/dist-types/models/index.d.ts +2 -1
- package/dist-types/protocols/constants.d.ts +1 -1
- package/package.json +4 -5
- package/dist-es/models/SensErrorInfo.js +0 -13
- package/dist-types/models/SensErrorInfo.d.ts +0 -21
|
@@ -6,16 +6,19 @@ const node_crypto_1 = require("node:crypto");
|
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const index_js_1 = require("../models/index.js");
|
|
8
8
|
const SendMMS_js_1 = require("../protocols/SendMMS.js");
|
|
9
|
-
const
|
|
9
|
+
const constants_js_1 = require("./constants.js");
|
|
10
10
|
const SendSMSCommand_js_1 = require("./SendSMSCommand.js");
|
|
11
11
|
class SendMMSCommand extends index_js_1.SensCommand {
|
|
12
|
+
input;
|
|
13
|
+
serializer;
|
|
14
|
+
deserializer;
|
|
12
15
|
constructor(input) {
|
|
13
16
|
super(input);
|
|
14
|
-
const content = input.content ? (0,
|
|
15
|
-
const subject = input.subject ? (0,
|
|
17
|
+
const content = input.content ? (0, constants_js_1.trimText)(input.content) : "내용없음";
|
|
18
|
+
const subject = input.subject ? (0, constants_js_1.trimText)(input.subject) : "제목없음";
|
|
16
19
|
const messages = (0, SendSMSCommand_js_1.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
17
20
|
this.input = {
|
|
18
|
-
from: (0,
|
|
21
|
+
from: (0, constants_js_1.prettyPhoneNum)(input.from),
|
|
19
22
|
content,
|
|
20
23
|
messages,
|
|
21
24
|
type: "MMS",
|
|
@@ -36,12 +39,9 @@ const resolveSendFile = (file, options) => {
|
|
|
36
39
|
const ext = parsed.ext.toLocaleLowerCase();
|
|
37
40
|
if (!options.supportExt.includes(ext)) {
|
|
38
41
|
throw new index_js_1.SensError({
|
|
39
|
-
code:
|
|
40
|
-
type: "
|
|
41
|
-
message: "
|
|
42
|
-
invalidInputs: [
|
|
43
|
-
{ type: "not-valid.args", message: `${options.supportExt.join(", ")} 형식의 첨부파일만 지원합니다.` },
|
|
44
|
-
],
|
|
42
|
+
code: -1,
|
|
43
|
+
type: "SDK.GENERAL_ERROR",
|
|
44
|
+
message: `MMS는 ${options.supportExt.join(", ")} 형식의 첨부파일만 보낼 수 있습니다.`,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
if (file.body) {
|
|
@@ -55,10 +55,9 @@ const resolveSendFile = (file, options) => {
|
|
|
55
55
|
}
|
|
56
56
|
if (!(0, node_fs_1.existsSync)(file.name)) {
|
|
57
57
|
throw new index_js_1.SensError({
|
|
58
|
-
code:
|
|
59
|
-
type: "
|
|
60
|
-
message:
|
|
61
|
-
invalidInputs: [{ type: "not-valid.args", message: `${file.name} 파일이 존재하지 않습니다.` }],
|
|
58
|
+
code: -1,
|
|
59
|
+
type: "SDK.GENERAL_ERROR",
|
|
60
|
+
message: `${file.name} 첨부파일이 존재하지 않습니다.`,
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
63
|
const buffer = (0, node_fs_1.readFileSync)(file.name);
|
|
@@ -74,15 +73,9 @@ const checkSizeLimit = (buffer, maxKiB) => {
|
|
|
74
73
|
const kibSize = Math.ceil(byteSize / 1024);
|
|
75
74
|
if (kibSize > maxKiB) {
|
|
76
75
|
throw new index_js_1.SensError({
|
|
77
|
-
code:
|
|
78
|
-
type: "
|
|
79
|
-
message:
|
|
80
|
-
invalidInputs: [
|
|
81
|
-
{
|
|
82
|
-
type: "not-valid.args",
|
|
83
|
-
message: `최대 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
76
|
+
code: -1,
|
|
77
|
+
type: "SDK.GENERAL_ERROR",
|
|
78
|
+
message: `첨부파일은 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
|
|
86
79
|
});
|
|
87
80
|
}
|
|
88
81
|
return;
|
|
@@ -3,16 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resolveInputMessages = exports.SendSMSCommand = void 0;
|
|
4
4
|
const index_js_1 = require("../models/index.js");
|
|
5
5
|
const SendSMS_js_1 = require("../protocols/SendSMS.js");
|
|
6
|
-
const
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
7
|
class SendSMSCommand extends index_js_1.SensCommand {
|
|
8
|
+
input;
|
|
9
|
+
serializer;
|
|
10
|
+
deserializer;
|
|
8
11
|
constructor(input) {
|
|
9
12
|
super(input);
|
|
10
|
-
const content = input.content ? (0,
|
|
11
|
-
const subject = input.subject ? (0,
|
|
13
|
+
const content = input.content ? (0, constants_js_1.trimText)(input.content) : "내용없음";
|
|
14
|
+
const subject = input.subject ? (0, constants_js_1.trimText)(input.subject) : "제목없음";
|
|
12
15
|
const messages = (0, exports.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
13
16
|
const isLMS = !!messages.filter((msg) => !!msg.subject).length;
|
|
14
|
-
this.input =
|
|
15
|
-
|
|
17
|
+
this.input = {
|
|
18
|
+
from: (0, constants_js_1.prettyPhoneNum)(input.from),
|
|
19
|
+
content,
|
|
20
|
+
messages,
|
|
21
|
+
type: isLMS ? "LMS" : "SMS",
|
|
22
|
+
contentType: input.contentType ? input.contentType : "COMM",
|
|
23
|
+
countryCode: input.countryCode ? input.countryCode : "82",
|
|
24
|
+
...(isLMS && { subject }),
|
|
25
|
+
};
|
|
16
26
|
this.serializer = SendSMS_js_1.se_SendSMSCommand;
|
|
17
27
|
this.deserializer = SendSMS_js_1.de_SendSMSCommand;
|
|
18
28
|
}
|
|
@@ -22,10 +32,14 @@ const resolveInputMessages = (messages, config) => {
|
|
|
22
32
|
const output = messages
|
|
23
33
|
.filter((d) => !!d)
|
|
24
34
|
.map((message) => {
|
|
25
|
-
const content = message.content ? (0,
|
|
26
|
-
const subject = message.subject ? (0,
|
|
35
|
+
const content = message.content ? (0, constants_js_1.trimText)(message.content) : config.defaultContent;
|
|
36
|
+
const subject = message.subject ? (0, constants_js_1.trimText)(message.subject) : config.defaultSubject;
|
|
27
37
|
const msgType = getMessageType({ content });
|
|
28
|
-
return
|
|
38
|
+
return {
|
|
39
|
+
to: (0, constants_js_1.prettyPhoneNum)(message.to),
|
|
40
|
+
content,
|
|
41
|
+
...(msgType === "LMS" && { subject }),
|
|
42
|
+
};
|
|
29
43
|
});
|
|
30
44
|
return output;
|
|
31
45
|
};
|
|
@@ -33,21 +47,19 @@ exports.resolveInputMessages = resolveInputMessages;
|
|
|
33
47
|
const getMessageType = (input) => {
|
|
34
48
|
const SMS_MAX_CONTENT_LENGTH = 90;
|
|
35
49
|
const LMS_MAX_CONTENT_LENGTH = 2000;
|
|
36
|
-
const contentLength = (0,
|
|
50
|
+
const contentLength = (0, constants_js_1.getContentLength)(input.content);
|
|
37
51
|
if (!contentLength) {
|
|
38
52
|
throw new index_js_1.SensError({
|
|
39
|
-
code:
|
|
40
|
-
type: "
|
|
53
|
+
code: -1,
|
|
54
|
+
type: "SDK.GENERAL_ERROR",
|
|
41
55
|
message: "메세지 내용이 없습니다.",
|
|
42
|
-
invalidInputs: [{ type: "not-valid.args", message: "메세지 내용을 확인해주세요." }],
|
|
43
56
|
});
|
|
44
57
|
}
|
|
45
58
|
if (contentLength > LMS_MAX_CONTENT_LENGTH) {
|
|
46
59
|
throw new index_js_1.SensError({
|
|
47
|
-
code:
|
|
48
|
-
type: "
|
|
49
|
-
message:
|
|
50
|
-
invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다` }],
|
|
60
|
+
code: -1,
|
|
61
|
+
type: "SDK.GENERAL_ERROR",
|
|
62
|
+
message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다`,
|
|
51
63
|
});
|
|
52
64
|
}
|
|
53
65
|
return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS";
|
|
@@ -22,7 +22,7 @@ const convertToUtc = (input) => {
|
|
|
22
22
|
};
|
|
23
23
|
exports.convertToUtc = convertToUtc;
|
|
24
24
|
const convertToKst = (input) => {
|
|
25
|
-
const KST_OFFSET = 9 *
|
|
25
|
+
const KST_OFFSET = 9 * 3_600_000;
|
|
26
26
|
return new Date(input + KST_OFFSET).toISOString().replace(/\.\d{3}Z$/, "");
|
|
27
27
|
};
|
|
28
28
|
exports.convertToKst = convertToKst;
|
|
@@ -42,28 +42,17 @@ const resolveRequestDuration = (input, config) => {
|
|
|
42
42
|
const diff = end - start;
|
|
43
43
|
if (diff < 0) {
|
|
44
44
|
throw new index_js_1.SensError({
|
|
45
|
-
code:
|
|
46
|
-
type: "
|
|
47
|
-
message:
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
type: "not-valid.args",
|
|
51
|
-
message: "종료일이 시작일보다 빠를 수 없습니다.",
|
|
52
|
-
},
|
|
53
|
-
],
|
|
45
|
+
code: -1,
|
|
46
|
+
type: "SDK.GENERAL_ERROR",
|
|
47
|
+
message: "조회 가능 날짜 오류. 종료일이 시작일보다 빠를 수 없습니다.",
|
|
48
|
+
errors: [`종료일: ${input.endTime}`, `시작일: ${input.startTime}`],
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
51
|
if (diff > config.durationLimitMs) {
|
|
57
52
|
throw new index_js_1.SensError({
|
|
58
|
-
code:
|
|
59
|
-
type: "
|
|
60
|
-
message:
|
|
61
|
-
invalidInputs: [
|
|
62
|
-
{
|
|
63
|
-
type: "not-valid.args",
|
|
64
|
-
message: `조회 가능한 날짜 범위는 최대 ${config.durationLimitMs / (24 * 3600000)}일 이내여야 합니다.`,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
53
|
+
code: -1,
|
|
54
|
+
type: "SDK.GENERAL_ERROR",
|
|
55
|
+
message: `최대 ${config.durationLimitMs / (24 * 3_600_000)}일 이내에서 조회 가능합니다.`,
|
|
67
56
|
});
|
|
68
57
|
}
|
|
69
58
|
return {
|
package/dist-cjs/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./commands/index.js"), exports);
|
|
18
18
|
__exportStar(require("./SensClient.js"), exports);
|
|
19
|
+
__exportStar(require("./models/SensClientError.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.NCP_TRACE_ID = 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
4
|
exports.INGESTKOREA_USER_AGENT = "x-ingestkorea-user-agent";
|
|
5
5
|
exports.INGESTKOREA_REQUEST_LOG = "x-ingestkorea-request";
|
|
6
6
|
exports.INGESTKOREA_RETRY = "x-ingestkorea-attempts";
|
|
@@ -8,3 +8,4 @@ exports.INGESTKOREA_RETRY_DELAY = "x-ingestkorea-total-retry-delay";
|
|
|
8
8
|
exports.NCP_ACCESS_KEY = "x-ncp-iam-access-key";
|
|
9
9
|
exports.NCP_TIMESTAMP = "x-ncp-apigw-timestamp";
|
|
10
10
|
exports.NCP_SIGNATURE = "x-ncp-apigw-signature-v2";
|
|
11
|
+
exports.NCP_TRACE_ID = "x-ncp-trace-id";
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.middlewareIngestkoreaMetadata = void 0;
|
|
13
4
|
const constants_js_1 = require("./constants.js");
|
|
14
|
-
const middlewareIngestkoreaMetadata = (next) => (input, context) =>
|
|
15
|
-
input.request.headers =
|
|
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.11.x",
|
|
9
|
+
connection: context.httpHandler.keepAlive ? "keep-alive" : "close", // temp
|
|
10
|
+
};
|
|
16
11
|
return next(input, context);
|
|
17
|
-
}
|
|
12
|
+
};
|
|
18
13
|
exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
|
|
@@ -1,63 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.middlewareRetry = void 0;
|
|
13
|
-
const
|
|
4
|
+
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
5
|
+
const index_js_1 = require("../models/index.js");
|
|
14
6
|
const constants_js_1 = require("./constants.js");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const RETRYABLE_ERROR_TYPE = [
|
|
8
|
+
"SDK.TIMEOUT",
|
|
9
|
+
"SDK.NETWORK_ERROR",
|
|
10
|
+
"Too Many Requests",
|
|
11
|
+
"Internal Server Error",
|
|
12
|
+
];
|
|
13
|
+
const middlewareRetry = (next) => async (input, context) => {
|
|
18
14
|
const MAX_RETRIES = 3;
|
|
15
|
+
const MIN_DELAY_MS = 300;
|
|
19
16
|
const BASE_DELAY_MS = 500;
|
|
20
|
-
const MAX_DELAY_MS =
|
|
17
|
+
const MAX_DELAY_MS = 5_000;
|
|
21
18
|
let attempts = 0;
|
|
22
19
|
let totalRetryDelay = 0;
|
|
23
|
-
|
|
24
|
-
let lastError = new util_error_handler_1.IngestkoreaError({
|
|
25
|
-
code: 400,
|
|
26
|
-
type: "Bad Request",
|
|
27
|
-
message: "Invalid Request",
|
|
28
|
-
description: { attempts, maxRetries: MAX_RETRIES, totalRetryDelay },
|
|
29
|
-
});
|
|
20
|
+
input.request.headers = input.request.headers ?? {};
|
|
30
21
|
while (attempts < MAX_RETRIES) {
|
|
31
|
-
|
|
32
|
-
const requestLog = `attempt=${
|
|
22
|
+
attempts++;
|
|
23
|
+
const requestLog = `attempt=${attempts}; max=${MAX_RETRIES}; totalRetryDelay=${totalRetryDelay}`;
|
|
33
24
|
input.request.headers[constants_js_1.INGESTKOREA_REQUEST_LOG] = requestLog;
|
|
34
25
|
try {
|
|
35
|
-
const { response } =
|
|
36
|
-
response.headers[constants_js_1.INGESTKOREA_RETRY] =
|
|
26
|
+
const { response } = await next(input, context);
|
|
27
|
+
response.headers[constants_js_1.INGESTKOREA_RETRY] = attempts.toString();
|
|
37
28
|
response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] = totalRetryDelay.toString();
|
|
38
29
|
return { response };
|
|
39
30
|
}
|
|
40
31
|
catch (error) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
let currentError;
|
|
33
|
+
if (error instanceof index_js_1.SensError) {
|
|
34
|
+
currentError = error;
|
|
35
|
+
}
|
|
36
|
+
else if (error instanceof util_http_handler_1.HttpHandlerError) {
|
|
37
|
+
currentError = new index_js_1.SensError({
|
|
38
|
+
code: -1,
|
|
39
|
+
type: error.code,
|
|
40
|
+
message: error.message,
|
|
41
|
+
});
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
|
|
44
|
+
currentError = new index_js_1.SensError({
|
|
45
|
+
code: -1,
|
|
46
|
+
type: "SDK.UNKNOWN_ERROR",
|
|
47
|
+
message: error instanceof Error ? error.message : String(error),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const isRetryable = RETRYABLE_ERROR_TYPE.some((type) => currentError.type.startsWith(type));
|
|
51
|
+
if (!isRetryable) {
|
|
52
|
+
throw currentError;
|
|
48
53
|
}
|
|
49
54
|
if (attempts >= MAX_RETRIES) {
|
|
50
|
-
|
|
51
|
-
throw
|
|
55
|
+
currentError.errors.push(requestLog);
|
|
56
|
+
throw currentError;
|
|
52
57
|
}
|
|
53
|
-
const exp = BASE_DELAY_MS *
|
|
58
|
+
const exp = BASE_DELAY_MS * 2 ** (attempts - 1);
|
|
54
59
|
const capped = Math.min(MAX_DELAY_MS, exp);
|
|
55
|
-
const
|
|
60
|
+
const baseWait = Math.max(MIN_DELAY_MS, Math.floor(capped / 2));
|
|
61
|
+
const jitter = Math.floor(Math.random() * (capped - baseWait));
|
|
62
|
+
const delay = baseWait + jitter;
|
|
56
63
|
totalRetryDelay += delay;
|
|
57
|
-
|
|
58
|
-
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
64
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
|
-
throw
|
|
62
|
-
|
|
67
|
+
throw new index_js_1.SensError({
|
|
68
|
+
code: -1,
|
|
69
|
+
type: "SDK.UNKNOWN_ERROR",
|
|
70
|
+
message: "Unexpected retry loop termination",
|
|
71
|
+
});
|
|
72
|
+
};
|
|
63
73
|
exports.middlewareRetry = middlewareRetry;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.middlewareNcpSign = void 0;
|
|
13
4
|
const crypto_1 = require("crypto");
|
|
14
5
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
15
6
|
const constants_js_1 = require("./constants.js");
|
|
16
|
-
const middlewareNcpSign = (next) => (input, context) =>
|
|
7
|
+
const middlewareNcpSign = (next) => async (input, context) => {
|
|
17
8
|
const { accessKey, secretKey } = context.credentials;
|
|
18
9
|
const method = input.request.method;
|
|
19
10
|
const queryString = (0, util_http_handler_1.buildQueryString)(input.request.query);
|
|
@@ -23,7 +14,12 @@ const middlewareNcpSign = (next) => (input, context) => __awaiter(void 0, void 0
|
|
|
23
14
|
const timestamp = new Date().getTime().toString();
|
|
24
15
|
const stringToSign = [method + space + path, timestamp, accessKey].join(newLine);
|
|
25
16
|
const signature = (0, crypto_1.createHmac)("sha256", secretKey).update(stringToSign).digest("base64");
|
|
26
|
-
input.request.headers =
|
|
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,
|
|
22
|
+
};
|
|
27
23
|
return next(input, context);
|
|
28
|
-
}
|
|
24
|
+
};
|
|
29
25
|
exports.middlewareNcpSign = middlewareNcpSign;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NCLOUD_ERROR_CODE_SPEC = exports.SENS_ERROR_CODE_SPEC = void 0;
|
|
4
|
+
exports.SENS_ERROR_CODE_SPEC = {
|
|
5
|
+
400: "Bad Request",
|
|
6
|
+
401: "Unauthorized",
|
|
7
|
+
403: "Forbidden",
|
|
8
|
+
404: "Not Found",
|
|
9
|
+
429: "Too Many Requests",
|
|
10
|
+
500: "Internal Server Error",
|
|
11
|
+
};
|
|
12
|
+
exports.NCLOUD_ERROR_CODE_SPEC = {
|
|
13
|
+
"100": { status: 400, type: exports.SENS_ERROR_CODE_SPEC["400"] },
|
|
14
|
+
"200": { status: 401, type: exports.SENS_ERROR_CODE_SPEC["401"] },
|
|
15
|
+
"210": { status: 403, type: exports.SENS_ERROR_CODE_SPEC["403"] },
|
|
16
|
+
"300": { status: 404, type: exports.SENS_ERROR_CODE_SPEC["404"] },
|
|
17
|
+
"400": { status: 429, type: exports.SENS_ERROR_CODE_SPEC["429"] },
|
|
18
|
+
"410": { status: 429, type: exports.SENS_ERROR_CODE_SPEC["429"] },
|
|
19
|
+
"420": { status: 429, type: exports.SENS_ERROR_CODE_SPEC["429"] },
|
|
20
|
+
"900": { status: 500, type: exports.SENS_ERROR_CODE_SPEC["500"] },
|
|
21
|
+
};
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SensError = void 0;
|
|
4
4
|
class SensError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
type;
|
|
7
|
+
errors;
|
|
8
|
+
timestamp;
|
|
5
9
|
constructor(info) {
|
|
6
10
|
super(info.message);
|
|
7
11
|
this.name = "SensError";
|
|
8
12
|
this.code = info.code;
|
|
9
13
|
this.type = info.type;
|
|
10
|
-
this.
|
|
14
|
+
this.errors = info.errors || [];
|
|
15
|
+
this.timestamp = new Date().toISOString();
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
exports.SensError = SensError;
|
package/dist-cjs/models/index.js
CHANGED
|
@@ -27,7 +27,8 @@ __exportStar(require("./MetadataBearer.js"), exports);
|
|
|
27
27
|
__exportStar(require("./SendAlimtalk.js"), exports);
|
|
28
28
|
__exportStar(require("./SendMMS.js"), exports);
|
|
29
29
|
__exportStar(require("./SendSMS.js"), exports);
|
|
30
|
+
__exportStar(require("./SensApiError.js"), exports);
|
|
30
31
|
__exportStar(require("./SensClient.js"), exports);
|
|
32
|
+
__exportStar(require("./SensClientError.js"), exports);
|
|
31
33
|
__exportStar(require("./SensCommand.js"), exports);
|
|
32
|
-
__exportStar(require("./SensErrorInfo.js"), exports);
|
|
33
34
|
__exportStar(require("./SensMiddleware.js"), exports);
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.de_GetAlimtalkResultCommand = exports.se_GetAlimtalkResultCommand = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const constants_js_1 = require("./constants.js");
|
|
15
6
|
const GetAlimtalkStatus_js_1 = require("./GetAlimtalkStatus.js");
|
|
16
|
-
const se_GetAlimtalkResultCommand = (input, config) =>
|
|
7
|
+
const se_GetAlimtalkResultCommand = async (input, config) => {
|
|
17
8
|
const hostname = "sens.apigw.ntruss.com";
|
|
18
9
|
const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages/" + input.messageId;
|
|
19
10
|
const headers = {
|
|
@@ -26,18 +17,24 @@ const se_GetAlimtalkResultCommand = (input, config) => __awaiter(void 0, void 0,
|
|
|
26
17
|
path,
|
|
27
18
|
headers,
|
|
28
19
|
});
|
|
29
|
-
}
|
|
20
|
+
};
|
|
30
21
|
exports.se_GetAlimtalkResultCommand = se_GetAlimtalkResultCommand;
|
|
31
|
-
const de_GetAlimtalkResultCommand = (response, config) =>
|
|
22
|
+
const de_GetAlimtalkResultCommand = async (response, config) => {
|
|
32
23
|
if (response.statusCode >= 300)
|
|
33
|
-
|
|
34
|
-
const data =
|
|
24
|
+
await (0, constants_js_1.parseErrorBody)(response);
|
|
25
|
+
const data = await (0, constants_js_1.parseBody)(response);
|
|
35
26
|
const contents = de_GetAlimtalkResultResult(data);
|
|
36
|
-
return
|
|
37
|
-
|
|
27
|
+
return {
|
|
28
|
+
$metadata: (0, constants_js_1.deserializeMetadata)(response),
|
|
29
|
+
...(0, constants_js_1.compact)(contents),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
38
32
|
exports.de_GetAlimtalkResultCommand = de_GetAlimtalkResultCommand;
|
|
39
33
|
const de_GetAlimtalkResultResult = (output) => {
|
|
40
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
...(0, GetAlimtalkStatus_js_1.de_AlimtalkMessageStatus)(output),
|
|
36
|
+
failover: output.failover ? de_Failover(output.failover) : undefined,
|
|
37
|
+
};
|
|
41
38
|
};
|
|
42
39
|
const de_Failover = (output) => {
|
|
43
40
|
return {
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.de_AlimtalkMessageStatus = exports.de_GetAlimtalkStatusResult = exports.de_GetAlimtalkStatusCommand = exports.se_GetAlimtalkStatusCommand = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const constants_js_1 = require("./constants.js");
|
|
15
6
|
const SendAlimtalk_js_1 = require("./SendAlimtalk.js");
|
|
16
|
-
const se_GetAlimtalkStatusCommand = (input, config) =>
|
|
7
|
+
const se_GetAlimtalkStatusCommand = async (input, config) => {
|
|
17
8
|
const hostname = "sens.apigw.ntruss.com";
|
|
18
9
|
const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
|
|
19
10
|
const headers = {
|
|
@@ -33,15 +24,18 @@ const se_GetAlimtalkStatusCommand = (input, config) => __awaiter(void 0, void 0,
|
|
|
33
24
|
headers,
|
|
34
25
|
query,
|
|
35
26
|
});
|
|
36
|
-
}
|
|
27
|
+
};
|
|
37
28
|
exports.se_GetAlimtalkStatusCommand = se_GetAlimtalkStatusCommand;
|
|
38
|
-
const de_GetAlimtalkStatusCommand = (response, config) =>
|
|
29
|
+
const de_GetAlimtalkStatusCommand = async (response, config) => {
|
|
39
30
|
if (response.statusCode >= 300)
|
|
40
|
-
|
|
41
|
-
const data =
|
|
31
|
+
await (0, constants_js_1.parseErrorBody)(response);
|
|
32
|
+
const data = await (0, constants_js_1.parseBody)(response);
|
|
42
33
|
const contents = (0, exports.de_GetAlimtalkStatusResult)(data);
|
|
43
|
-
return
|
|
44
|
-
|
|
34
|
+
return {
|
|
35
|
+
$metadata: (0, constants_js_1.deserializeMetadata)(response),
|
|
36
|
+
...(0, constants_js_1.compact)(contents),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
45
39
|
exports.de_GetAlimtalkStatusCommand = de_GetAlimtalkStatusCommand;
|
|
46
40
|
const de_GetAlimtalkStatusResult = (output) => {
|
|
47
41
|
return {
|
|
@@ -61,6 +55,16 @@ const de_AlimtalkMessageStatusList = (output) => {
|
|
|
61
55
|
return (output || []).filter((e) => e != null).map((entry) => (0, exports.de_AlimtalkMessageStatus)(entry));
|
|
62
56
|
};
|
|
63
57
|
const de_AlimtalkMessageStatus = (output) => {
|
|
64
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
...(0, SendAlimtalk_js_1.de_AlimtalkMessageRequestStatus)(output),
|
|
60
|
+
requestId: output.requestId ? output.requestId : undefined,
|
|
61
|
+
requestTime: output.requestTime ? (0, constants_js_1.convertToUtc)(output.requestTime) : undefined,
|
|
62
|
+
plusFriendId: output.plusFriendId ? output.plusFriendId : undefined,
|
|
63
|
+
templateCode: output.templateCode ? output.templateCode : undefined,
|
|
64
|
+
completeTime: output.completeTime ? (0, constants_js_1.convertToUtc)(output.completeTime) : undefined,
|
|
65
|
+
messageStatusCode: output.messageStatusCode ? output.messageStatusCode : undefined,
|
|
66
|
+
messageStatusName: output.messageStatusName ? output.messageStatusName : undefined,
|
|
67
|
+
messageStatusDesc: output.messageStatusDesc ? output.messageStatusDesc : undefined,
|
|
68
|
+
};
|
|
65
69
|
};
|
|
66
70
|
exports.de_AlimtalkMessageStatus = de_AlimtalkMessageStatus;
|