@ingestkorea/client-sens 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +114 -68
- package/dist-cjs/SensClient.js +59 -31
- package/dist-cjs/commands/GetAlimtalkResultCommand.js +8 -33
- package/dist-cjs/commands/GetAlimtalkStatusCommand.js +9 -33
- package/dist-cjs/commands/GetAlimtalkTemplateCommand.js +9 -33
- package/dist-cjs/commands/GetSMSResultCommand.js +8 -33
- package/dist-cjs/commands/GetSMSStatusCommand.js +8 -33
- package/dist-cjs/commands/ListAlimtalkChannelsCommand.js +6 -33
- package/dist-cjs/commands/ListAlimtalkStatusCommand.js +27 -0
- package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +8 -33
- package/dist-cjs/commands/SendAlimtalkCommand.js +36 -40
- package/dist-cjs/commands/SendMMSCommand.js +67 -103
- package/dist-cjs/commands/SendSMSCommand.js +38 -71
- package/dist-cjs/commands/constants.js +1 -4
- package/dist-cjs/commands/index.js +11 -10
- package/dist-cjs/index.js +2 -2
- package/dist-cjs/middleware/constants.js +10 -0
- package/dist-cjs/middleware/index.js +3 -4
- package/dist-cjs/middleware/middleware-metadata.js +4 -5
- package/dist-cjs/middleware/middleware-retry.js +32 -27
- package/dist-cjs/middleware/middleware-sign.js +10 -9
- package/dist-cjs/models/SendAlimtalk.js +5 -0
- package/dist-cjs/models/SendMMS.js +3 -0
- package/dist-cjs/models/SensClient.js +2 -0
- package/dist-cjs/models/SensErrorInfo.js +13 -0
- package/dist-cjs/models/SensMiddleware.js +2 -0
- package/dist-cjs/models/index.js +16 -13
- package/dist-cjs/protocols/GetAlimtalkResult.js +19 -40
- package/dist-cjs/protocols/GetAlimtalkStatus.js +40 -50
- package/dist-cjs/protocols/GetAlimtalkTemplate.js +60 -22
- package/dist-cjs/protocols/GetSMSResult.js +30 -48
- package/dist-cjs/protocols/GetSMSStatus.js +31 -34
- package/dist-cjs/protocols/ListAlimtalkChannels.js +27 -31
- package/dist-cjs/protocols/ListAlimtalkStatus.js +48 -0
- package/dist-cjs/protocols/ListAlimtalkTemplates.js +36 -62
- package/dist-cjs/protocols/SendAlimtalk.js +33 -35
- package/dist-cjs/protocols/SendMMS.js +8 -38
- package/dist-cjs/protocols/SendSMS.js +19 -21
- package/dist-cjs/protocols/constants.js +98 -34
- package/dist-es/SensClient.js +65 -33
- package/dist-es/commands/GetAlimtalkResultCommand.js +10 -20
- package/dist-es/commands/GetAlimtalkStatusCommand.js +15 -20
- package/dist-es/commands/GetAlimtalkTemplateCommand.js +11 -20
- package/dist-es/commands/GetSMSResultCommand.js +10 -20
- package/dist-es/commands/GetSMSStatusCommand.js +10 -20
- package/dist-es/commands/ListAlimtalkChannelsCommand.js +10 -22
- package/dist-es/commands/ListAlimtalkStatusCommand.js +39 -0
- package/dist-es/commands/ListAlimtalkTemplatesCommand.js +10 -20
- package/dist-es/commands/SendAlimtalkCommand.js +40 -32
- package/dist-es/commands/SendMMSCommand.js +70 -100
- package/dist-es/commands/SendSMSCommand.js +51 -66
- package/dist-es/commands/constants.js +9 -6
- package/dist-es/commands/index.js +27 -10
- package/dist-es/index.js +18 -2
- package/dist-es/middleware/constants.js +10 -0
- package/dist-es/middleware/index.js +19 -4
- package/dist-es/middleware/middleware-metadata.js +11 -5
- package/dist-es/middleware/middleware-retry.js +39 -30
- package/dist-es/middleware/middleware-sign.js +19 -14
- package/dist-es/models/GetAlimtalkResult.js +2 -1
- package/dist-es/models/GetAlimtalkStatus.js +2 -1
- package/dist-es/models/GetAlimtalkTemplate.js +2 -1
- package/dist-es/models/GetSMSResult.js +2 -1
- package/dist-es/models/GetSMSStatus.js +2 -1
- package/dist-es/models/ListAlimtalkChannels.js +2 -1
- package/dist-es/models/ListAlimtalkStatus.js +2 -0
- package/dist-es/models/ListAlimtalkTemplates.js +2 -1
- package/dist-es/models/MetadataBearer.js +2 -1
- package/dist-es/models/SendAlimtalk.js +7 -1
- package/dist-es/models/SendMMS.js +5 -1
- package/dist-es/models/SendSMS.js +2 -1
- package/dist-es/models/SensClient.js +2 -0
- package/dist-es/models/SensCommand.js +5 -1
- package/dist-es/models/SensErrorInfo.js +13 -0
- package/dist-es/models/SensMiddleware.js +2 -0
- package/dist-es/models/index.js +32 -13
- package/dist-es/protocols/GetAlimtalkResult.js +24 -38
- package/dist-es/protocols/GetAlimtalkStatus.js +54 -50
- package/dist-es/protocols/GetAlimtalkTemplate.js +82 -23
- package/dist-es/protocols/GetSMSResult.js +44 -47
- package/dist-es/protocols/GetSMSStatus.js +35 -34
- package/dist-es/protocols/ListAlimtalkChannels.js +31 -31
- package/dist-es/protocols/ListAlimtalkStatus.js +42 -0
- package/dist-es/protocols/ListAlimtalkTemplates.js +41 -61
- package/dist-es/protocols/SendAlimtalk.js +37 -35
- package/dist-es/protocols/SendMMS.js +10 -49
- package/dist-es/protocols/SendSMS.js +23 -30
- package/dist-es/protocols/constants.js +112 -37
- package/dist-types/SensClient.d.ts +3 -20
- package/dist-types/commands/GetAlimtalkResultCommand.d.ts +5 -10
- package/dist-types/commands/GetAlimtalkStatusCommand.d.ts +5 -10
- package/dist-types/commands/GetAlimtalkTemplateCommand.d.ts +5 -10
- package/dist-types/commands/GetSMSResultCommand.d.ts +5 -10
- package/dist-types/commands/GetSMSStatusCommand.d.ts +5 -10
- package/dist-types/commands/ListAlimtalkChannelsCommand.d.ts +5 -10
- package/dist-types/commands/ListAlimtalkStatusCommand.d.ts +11 -0
- package/dist-types/commands/ListAlimtalkTemplatesCommand.d.ts +5 -10
- package/dist-types/commands/SendAlimtalkCommand.d.ts +5 -10
- package/dist-types/commands/SendMMSCommand.d.ts +5 -10
- package/dist-types/commands/SendSMSCommand.d.ts +9 -10
- package/dist-types/commands/constants.d.ts +0 -3
- package/dist-types/commands/index.d.ts +11 -10
- package/dist-types/index.d.ts +2 -2
- package/dist-types/middleware/constants.d.ts +7 -0
- package/dist-types/middleware/index.d.ts +3 -4
- package/dist-types/middleware/middleware-metadata.d.ts +2 -2
- package/dist-types/middleware/middleware-retry.d.ts +2 -2
- package/dist-types/middleware/middleware-sign.d.ts +2 -2
- package/dist-types/models/GetAlimtalkResult.d.ts +3 -4
- package/dist-types/models/GetAlimtalkStatus.d.ts +13 -5
- package/dist-types/models/GetAlimtalkTemplate.d.ts +42 -3
- package/dist-types/models/GetSMSResult.d.ts +5 -9
- package/dist-types/models/GetSMSStatus.d.ts +4 -4
- package/dist-types/models/ListAlimtalkChannels.d.ts +4 -4
- package/dist-types/models/ListAlimtalkStatus.d.ts +16 -0
- package/dist-types/models/ListAlimtalkTemplates.d.ts +2 -22
- package/dist-types/models/MetadataBearer.d.ts +3 -3
- package/dist-types/models/SendAlimtalk.d.ts +19 -10
- package/dist-types/models/SendMMS.d.ts +5 -3
- package/dist-types/models/SendSMS.d.ts +2 -2
- package/dist-types/models/SensClient.d.ts +17 -0
- package/dist-types/models/SensCommand.d.ts +4 -6
- package/dist-types/models/SensErrorInfo.d.ts +21 -0
- package/dist-types/models/SensMiddleware.d.ts +8 -0
- package/dist-types/models/index.d.ts +16 -13
- package/dist-types/protocols/GetAlimtalkResult.d.ts +4 -11
- package/dist-types/protocols/GetAlimtalkStatus.d.ts +6 -11
- package/dist-types/protocols/GetAlimtalkTemplate.d.ts +4 -10
- package/dist-types/protocols/GetSMSResult.d.ts +4 -12
- package/dist-types/protocols/GetSMSStatus.d.ts +5 -11
- package/dist-types/protocols/ListAlimtalkChannels.d.ts +4 -11
- package/dist-types/protocols/ListAlimtalkStatus.d.ts +4 -0
- package/dist-types/protocols/ListAlimtalkTemplates.d.ts +5 -13
- package/dist-types/protocols/SendAlimtalk.d.ts +5 -11
- package/dist-types/protocols/SendMMS.d.ts +4 -10
- package/dist-types/protocols/SendSMS.d.ts +5 -10
- package/dist-types/protocols/constants.d.ts +3 -2
- package/package.json +22 -5
- package/.github/pull_request_template.md +0 -19
- package/dist-cjs/middleware/middleware-sort-headers.js +0 -25
- package/dist-cjs/protocols/index.js +0 -26
- package/dist-es/middleware/middleware-sort-headers.js +0 -12
- package/dist-es/models/Middleware.js +0 -1
- package/dist-es/protocols/index.js +0 -10
- package/dist-types/middleware/middleware-sort-headers.d.ts +0 -2
- package/dist-types/models/Middleware.d.ts +0 -12
- package/dist-types/protocols/index.d.ts +0 -10
- /package/dist-cjs/models/{Middleware.js → ListAlimtalkStatus.js} +0 -0
|
@@ -1,44 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendAlimtalkCommand = void 0;
|
|
4
|
+
const index_js_1 = require("../models/index.js");
|
|
5
|
+
const SendAlimtalk_js_1 = require("../protocols/SendAlimtalk.js");
|
|
6
|
+
class SendAlimtalkCommand extends index_js_1.SensCommand {
|
|
5
7
|
constructor(input) {
|
|
6
8
|
super(input);
|
|
7
9
|
this.input = {
|
|
8
|
-
...input,
|
|
9
10
|
plusFriendId: input.plusFriendId,
|
|
10
11
|
templateCode: input.templateCode,
|
|
11
|
-
messages: input.messages
|
|
12
|
+
messages: resolveAlimtalkMessages(input.messages, {
|
|
13
|
+
maxRecipients: index_js_1.ALIMTALK_MAX_RECIPIENTS,
|
|
14
|
+
maxContentLength: index_js_1.ALIMTALK_MAX_CONTENT_LENGTH,
|
|
15
|
+
}),
|
|
12
16
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!config.serviceId.kakao)
|
|
16
|
-
throw new IngestkoreaError({
|
|
17
|
-
code: 400,
|
|
18
|
-
type: "Bad Request",
|
|
19
|
-
message: "Invalid Params",
|
|
20
|
-
description: "Please Check Kakao ServiceId",
|
|
21
|
-
});
|
|
22
|
-
let request = await serializeIngestkorea_restJson_SendAlimtalkCommand(input, config);
|
|
23
|
-
return request;
|
|
24
|
-
}
|
|
25
|
-
async deserialize(response) {
|
|
26
|
-
let output = await deserializeIngestkorea_restJson_SendAlimtalkCommand(response);
|
|
27
|
-
return output;
|
|
17
|
+
this.serializer = SendAlimtalk_js_1.se_SendAlimtalkCommand;
|
|
18
|
+
this.deserializer = SendAlimtalk_js_1.de_SendAlimtalkCommand;
|
|
28
19
|
}
|
|
29
20
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
throw new
|
|
21
|
+
exports.SendAlimtalkCommand = SendAlimtalkCommand;
|
|
22
|
+
const resolveAlimtalkMessages = (messages, config) => {
|
|
23
|
+
if (!messages.length || messages.length > config.maxRecipients) {
|
|
24
|
+
throw new index_js_1.SensError({
|
|
34
25
|
code: 400,
|
|
35
26
|
type: "Bad Request",
|
|
36
|
-
message: "
|
|
37
|
-
|
|
27
|
+
message: "알림톡 동시 발송 범위 오류",
|
|
28
|
+
invalidInputs: [
|
|
29
|
+
{
|
|
30
|
+
type: "not-valid.args",
|
|
31
|
+
message: `메세지 동시 발송은 최소 1명, 최대 ${config.maxRecipients}명까지 가능합니다.`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
38
34
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
}
|
|
36
|
+
const result = messages.map((message) => {
|
|
37
|
+
if (message.content.length > config.maxContentLength) {
|
|
38
|
+
throw new index_js_1.SensError({
|
|
39
|
+
code: 400,
|
|
40
|
+
type: "Bad Request",
|
|
41
|
+
message: "알림톡 최대 길이 초과",
|
|
42
|
+
invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${config.maxContentLength}글자입니다` }],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
to: message.to.replace(/\-/gi, ""),
|
|
47
|
+
content: message.content,
|
|
48
|
+
...(message.buttons && message.buttons.length && { buttons: message.buttons }),
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
44
52
|
};
|
|
@@ -1,119 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SendMMSCommand = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const index_js_1 = require("../models/index.js");
|
|
8
|
+
const SendMMS_js_1 = require("../protocols/SendMMS.js");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const SendSMSCommand_js_1 = require("./SendSMSCommand.js");
|
|
11
|
+
class SendMMSCommand extends index_js_1.SensCommand {
|
|
9
12
|
constructor(input) {
|
|
10
13
|
super(input);
|
|
14
|
+
const content = input.content ? (0, constants_1.trimText)(input.content) : "내용없음";
|
|
15
|
+
const subject = input.subject ? (0, constants_1.trimText)(input.subject) : "제목없음";
|
|
16
|
+
const messages = (0, SendSMSCommand_js_1.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
11
17
|
this.input = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
from: (0, constants_1.prettyPhoneNum)(input.from),
|
|
19
|
+
content,
|
|
20
|
+
messages,
|
|
21
|
+
type: "MMS",
|
|
22
|
+
contentType: input.contentType ? input.contentType : "COMM",
|
|
23
|
+
countryCode: input.countryCode ? input.countryCode : "82",
|
|
24
|
+
subject,
|
|
25
|
+
files: (input.files || []).map((file) => {
|
|
26
|
+
return resolveSendFile(file, { maxKiB: index_js_1.MMS_MAX_SUPPORT_FILE_SIZE, supportExt: index_js_1.MMS_SUPPORT_FILE_EXTENSION });
|
|
27
|
+
}),
|
|
18
28
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!config.serviceId.sms)
|
|
22
|
-
throw new IngestkoreaError({
|
|
23
|
-
code: 400,
|
|
24
|
-
type: "Bad Request",
|
|
25
|
-
message: "Invalid Params",
|
|
26
|
-
description: "Please Check SMS ServiceId",
|
|
27
|
-
});
|
|
28
|
-
let request = await serializeIngestkorea_restJson_SendMMSCommand(input, config);
|
|
29
|
-
return request;
|
|
30
|
-
}
|
|
31
|
-
async deserialize(response) {
|
|
32
|
-
let output = await deserializeIngestkorea_restJson_SendMMSCommand(response);
|
|
33
|
-
return output;
|
|
29
|
+
this.serializer = SendMMS_js_1.se_SendMMSCommand;
|
|
30
|
+
this.deserializer = SendMMS_js_1.de_SendMMSCommand;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
exports.SendMMSCommand = SendMMSCommand;
|
|
34
|
+
const resolveSendFile = (file, options) => {
|
|
35
|
+
const parsed = (0, node_path_1.parse)(file.name); // { dir, name, ext, base }
|
|
36
|
+
const ext = parsed.ext.toLocaleLowerCase();
|
|
37
|
+
if (!options.supportExt.includes(ext)) {
|
|
38
|
+
throw new index_js_1.SensError({
|
|
41
39
|
code: 400,
|
|
42
40
|
type: "Bad Request",
|
|
43
|
-
message: "
|
|
44
|
-
|
|
41
|
+
message: "지원하지 않는 확장자입니다.",
|
|
42
|
+
invalidInputs: [
|
|
43
|
+
{ type: "not-valid.args", message: `${options.supportExt.join(", ")} 형식의 첨부파일만 지원합니다.` },
|
|
44
|
+
],
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
}
|
|
47
|
+
if (file.body) {
|
|
48
|
+
const buffer = Buffer.from(file.body, "base64");
|
|
49
|
+
checkSizeLimit(buffer, options.maxKiB);
|
|
50
|
+
const hash = (0, node_crypto_1.createHash)("md5").update(buffer).digest("hex");
|
|
51
|
+
return {
|
|
52
|
+
name: (0, node_path_1.format)({ name: hash, ext }),
|
|
53
|
+
body: file.body,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!(0, node_fs_1.existsSync)(file.name)) {
|
|
57
|
+
throw new index_js_1.SensError({
|
|
48
58
|
code: 400,
|
|
49
59
|
type: "Bad Request",
|
|
50
|
-
message: "
|
|
51
|
-
|
|
60
|
+
message: "파일이 존재하지 않습니다.",
|
|
61
|
+
invalidInputs: [{ type: "not-valid.args", message: `${file.name} 파일이 존재하지 않습니다.` }],
|
|
52
62
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
}
|
|
64
|
+
const buffer = (0, node_fs_1.readFileSync)(file.name);
|
|
65
|
+
checkSizeLimit(buffer, options.maxKiB);
|
|
66
|
+
const hash = (0, node_crypto_1.createHash)("md5").update(buffer).digest("hex");
|
|
56
67
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
...(message.subject != undefined && { subject: trimText(message.subject) }),
|
|
68
|
+
name: (0, node_path_1.format)({ name: hash, ext }),
|
|
69
|
+
body: buffer.toString("base64"),
|
|
60
70
|
};
|
|
61
|
-
});
|
|
62
|
-
const resolveInputMessageType = (type) => {
|
|
63
|
-
if (type == "SMS" || type == "LMS")
|
|
64
|
-
throw new IngestkoreaError({
|
|
65
|
-
code: 400,
|
|
66
|
-
type: "Bad Request",
|
|
67
|
-
message: "Invalid Request",
|
|
68
|
-
description: `Please Call SendSMSCommand`,
|
|
69
|
-
});
|
|
70
|
-
return "MMS";
|
|
71
71
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const checkSizeLimit = (buffer, maxKiB) => {
|
|
73
|
+
const byteSize = buffer.length;
|
|
74
|
+
const kibSize = Math.ceil(byteSize / 1024);
|
|
75
|
+
if (kibSize > maxKiB) {
|
|
76
|
+
throw new index_js_1.SensError({
|
|
75
77
|
code: 400,
|
|
76
78
|
type: "Bad Request",
|
|
77
|
-
message:
|
|
78
|
-
|
|
79
|
+
message: `최대 첨부가능 용량이 초과되었습니다.`,
|
|
80
|
+
invalidInputs: [
|
|
81
|
+
{
|
|
82
|
+
type: "not-valid.args",
|
|
83
|
+
message: `최대 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
79
86
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const resolvedFileBody = file.body != undefined ? file.body : getFileBody(file.name);
|
|
83
|
-
let byte = Buffer.from(resolvedFileBody, "base64").length;
|
|
84
|
-
let kib = Math.ceil(byte / 1024);
|
|
85
|
-
if (kib > MMS_FILE_MAX)
|
|
86
|
-
throw new IngestkoreaError({
|
|
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`,
|
|
91
|
-
});
|
|
92
|
-
return { name: resolvedFileName, body: resolvedFileBody };
|
|
93
|
-
});
|
|
94
|
-
return output;
|
|
95
|
-
};
|
|
96
|
-
const verifyFileName = (fileName) => {
|
|
97
|
-
let { ext } = parse(fileName);
|
|
98
|
-
const uuid = randomUUID();
|
|
99
|
-
const extension = ext.replace(/jpeg|jpg/gi, "jpg");
|
|
100
|
-
if (extension != ".jpg")
|
|
101
|
-
throw new IngestkoreaError({
|
|
102
|
-
code: 400,
|
|
103
|
-
type: "Bad Request",
|
|
104
|
-
message: "Invalid Request",
|
|
105
|
-
description: `File Extension is not .jpg or .jpeg`,
|
|
106
|
-
});
|
|
107
|
-
return [uuid, extension].join("");
|
|
108
|
-
};
|
|
109
|
-
/** @returns base64 */
|
|
110
|
-
const getFileBody = (fileName) => {
|
|
111
|
-
if (!existsSync(fileName))
|
|
112
|
-
throw new IngestkoreaError({
|
|
113
|
-
code: 400,
|
|
114
|
-
type: "Bad Request",
|
|
115
|
-
message: "Invalid Request",
|
|
116
|
-
description: `${fileName} does not exist.`,
|
|
117
|
-
});
|
|
118
|
-
return readFileSync(fileName, { encoding: "base64" });
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
119
89
|
};
|
|
@@ -1,80 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveInputMessages = exports.SendSMSCommand = void 0;
|
|
4
|
+
const index_js_1 = require("../models/index.js");
|
|
5
|
+
const SendSMS_js_1 = require("../protocols/SendSMS.js");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
class SendSMSCommand extends index_js_1.SensCommand {
|
|
6
8
|
constructor(input) {
|
|
7
9
|
super(input);
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
+
const content = input.content ? (0, constants_1.trimText)(input.content) : "내용없음";
|
|
11
|
+
const subject = input.subject ? (0, constants_1.trimText)(input.subject) : "제목없음";
|
|
12
|
+
const messages = (0, exports.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
13
|
+
const isLMS = !!messages.filter((msg) => !!msg.subject).length;
|
|
10
14
|
this.input = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type:
|
|
15
|
-
|
|
15
|
+
from: (0, constants_1.prettyPhoneNum)(input.from),
|
|
16
|
+
content,
|
|
17
|
+
messages,
|
|
18
|
+
type: isLMS ? "LMS" : "SMS",
|
|
19
|
+
contentType: input.contentType ? input.contentType : "COMM",
|
|
20
|
+
countryCode: input.countryCode ? input.countryCode : "82",
|
|
21
|
+
...(isLMS && { subject }),
|
|
16
22
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!config.serviceId.sms)
|
|
20
|
-
throw new IngestkoreaError({
|
|
21
|
-
code: 400,
|
|
22
|
-
type: "Bad Request",
|
|
23
|
-
message: "Invalid Params",
|
|
24
|
-
description: "Please Check SMS ServiceId",
|
|
25
|
-
});
|
|
26
|
-
let request = await serializeIngestkorea_restJson_SendSMSCommand(input, config);
|
|
27
|
-
return request;
|
|
28
|
-
}
|
|
29
|
-
async deserialize(response) {
|
|
30
|
-
let output = await deserializeIngestkorea_restJson_SendSMSCommand(response);
|
|
31
|
-
return output;
|
|
23
|
+
this.serializer = SendSMS_js_1.se_SendSMSCommand;
|
|
24
|
+
this.deserializer = SendSMS_js_1.de_SendSMSCommand;
|
|
32
25
|
}
|
|
33
26
|
}
|
|
27
|
+
exports.SendSMSCommand = SendSMSCommand;
|
|
28
|
+
const resolveInputMessages = (messages, config) => {
|
|
29
|
+
const output = messages
|
|
30
|
+
.filter((d) => !!d)
|
|
31
|
+
.map((message) => {
|
|
32
|
+
const content = message.content ? (0, constants_1.trimText)(message.content) : config.defaultContent;
|
|
33
|
+
const subject = message.subject ? (0, constants_1.trimText)(message.subject) : config.defaultSubject;
|
|
34
|
+
const msgType = getMessageType({ content });
|
|
35
|
+
return {
|
|
36
|
+
to: (0, constants_1.prettyPhoneNum)(message.to),
|
|
37
|
+
content,
|
|
38
|
+
...(msgType === "LMS" && { subject }),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
return output;
|
|
42
|
+
};
|
|
43
|
+
exports.resolveInputMessages = resolveInputMessages;
|
|
34
44
|
const getMessageType = (input) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
const SMS_MAX_CONTENT_LENGTH = 90;
|
|
46
|
+
const LMS_MAX_CONTENT_LENGTH = 2000;
|
|
47
|
+
const contentLength = (0, constants_1.getContentLength)(input.content);
|
|
48
|
+
if (!contentLength) {
|
|
49
|
+
throw new index_js_1.SensError({
|
|
38
50
|
code: 400,
|
|
39
51
|
type: "Bad Request",
|
|
40
|
-
message: "
|
|
41
|
-
|
|
52
|
+
message: "메세지 내용이 없습니다.",
|
|
53
|
+
invalidInputs: [{ type: "not-valid.args", message: "메세지 내용을 확인해주세요." }],
|
|
42
54
|
});
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
}
|
|
56
|
+
if (contentLength > LMS_MAX_CONTENT_LENGTH) {
|
|
57
|
+
throw new index_js_1.SensError({
|
|
45
58
|
code: 400,
|
|
46
59
|
type: "Bad Request",
|
|
47
|
-
message: "
|
|
48
|
-
|
|
60
|
+
message: "메세지 최대 크기 초과",
|
|
61
|
+
invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다` }],
|
|
49
62
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const resolveInputContent = (content) => {
|
|
53
|
-
const resolvedContent = trimText(content);
|
|
54
|
-
const messageType = getMessageType(resolvedContent);
|
|
55
|
-
return {
|
|
56
|
-
content: resolvedContent,
|
|
57
|
-
messageType: messageType,
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
const resolveInputMessages = (messages) => {
|
|
61
|
-
let init = {
|
|
62
|
-
messages: [],
|
|
63
|
-
messageType: "SMS",
|
|
64
|
-
};
|
|
65
|
-
const output = messages.reduce((acc, message) => {
|
|
66
|
-
const to = prettyPhoneNum(message.to);
|
|
67
|
-
const content = message.content != undefined ? trimText(message.content) : undefined;
|
|
68
|
-
const subject = message.subject != undefined ? trimText(message.subject) : undefined;
|
|
69
|
-
const messageType = content != undefined ? getMessageType(content) : "SMS";
|
|
70
|
-
if (messageType == "LMS")
|
|
71
|
-
acc.messageType = messageType;
|
|
72
|
-
acc.messages.push({
|
|
73
|
-
to: to,
|
|
74
|
-
...(content != undefined && { content: content }),
|
|
75
|
-
...(subject != undefined && acc.messageType === "LMS" && { subject: subject }),
|
|
76
|
-
});
|
|
77
|
-
return acc;
|
|
78
|
-
}, init);
|
|
79
|
-
return output;
|
|
63
|
+
}
|
|
64
|
+
return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS";
|
|
80
65
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentLength = exports.prettyPhoneNum = exports.trimText = void 0;
|
|
4
|
+
const trimText = (input) => input.trim();
|
|
5
|
+
exports.trimText = trimText;
|
|
6
|
+
const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
|
|
7
|
+
exports.prettyPhoneNum = prettyPhoneNum;
|
|
6
8
|
/** @returns content-length(euc-kr) */
|
|
7
|
-
|
|
9
|
+
const getContentLength = (input) => {
|
|
8
10
|
return input.split("").reduce((acc, text) => {
|
|
9
11
|
let byte = Buffer.from(text).length;
|
|
10
12
|
let modulo = byte % 3;
|
|
@@ -12,3 +14,4 @@ export const getContentLength = (input) => {
|
|
|
12
14
|
return acc;
|
|
13
15
|
}, 0);
|
|
14
16
|
};
|
|
17
|
+
exports.getContentLength = getContentLength;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GetAlimtalkResultCommand.js"), exports);
|
|
18
|
+
__exportStar(require("./GetAlimtalkStatusCommand.js"), exports);
|
|
19
|
+
__exportStar(require("./GetAlimtalkTemplateCommand.js"), exports);
|
|
20
|
+
__exportStar(require("./GetSMSResultCommand.js"), exports);
|
|
21
|
+
__exportStar(require("./GetSMSStatusCommand.js"), exports);
|
|
22
|
+
__exportStar(require("./ListAlimtalkChannelsCommand.js"), exports);
|
|
23
|
+
__exportStar(require("./ListAlimtalkStatusCommand.js"), exports);
|
|
24
|
+
__exportStar(require("./ListAlimtalkTemplatesCommand.js"), exports);
|
|
25
|
+
__exportStar(require("./SendAlimtalkCommand.js"), exports);
|
|
26
|
+
__exportStar(require("./SendMMSCommand.js"), exports);
|
|
27
|
+
__exportStar(require("./SendSMSCommand.js"), exports);
|
package/dist-es/index.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./commands/index.js"), exports);
|
|
18
|
+
__exportStar(require("./SensClient.js"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NCP_SIGNATURE = exports.NCP_TIMESTAMP = exports.NCP_ACCESS_KEY = exports.INGESTKOREA_RETRY_DELAY = exports.INGESTKOREA_RETRY = exports.INGESTKOREA_REQUEST_LOG = exports.INGESTKOREA_USER_AGENT = void 0;
|
|
4
|
+
exports.INGESTKOREA_USER_AGENT = "x-ingestkorea-user-agent";
|
|
5
|
+
exports.INGESTKOREA_REQUEST_LOG = "x-ingestkorea-request";
|
|
6
|
+
exports.INGESTKOREA_RETRY = "x-ingestkorea-attempts";
|
|
7
|
+
exports.INGESTKOREA_RETRY_DELAY = "x-ingestkorea-total-retry-delay";
|
|
8
|
+
exports.NCP_ACCESS_KEY = "x-ncp-iam-access-key";
|
|
9
|
+
exports.NCP_TIMESTAMP = "x-ncp-apigw-timestamp";
|
|
10
|
+
exports.NCP_SIGNATURE = "x-ncp-apigw-signature-v2";
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./middleware-metadata.js"), exports);
|
|
18
|
+
__exportStar(require("./middleware-retry.js"), exports);
|
|
19
|
+
__exportStar(require("./middleware-sign.js"), exports);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.middlewareIngestkoreaMetadata = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const middlewareIngestkoreaMetadata = (next) => async (input, context) => {
|
|
6
|
+
input.request.headers = {
|
|
7
|
+
...input.request.headers,
|
|
8
|
+
[constants_js_1.INGESTKOREA_USER_AGENT]: "@ingestkorea/client-sens/1.8.x",
|
|
9
|
+
};
|
|
10
|
+
return next(input, context);
|
|
6
11
|
};
|
|
12
|
+
exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
|
|
@@ -1,51 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.middlewareRetry = void 0;
|
|
4
|
+
const util_error_handler_1 = require("@ingestkorea/util-error-handler");
|
|
5
|
+
const constants_js_1 = require("./constants.js");
|
|
6
|
+
const middlewareRetry = (next) => async (input, context) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
var _c;
|
|
9
|
+
const MAX_RETRIES = 3;
|
|
10
|
+
const BASE_DELAY_MS = 500;
|
|
11
|
+
const MAX_DELAY_MS = 5000;
|
|
5
12
|
let attempts = 0;
|
|
6
13
|
let totalRetryDelay = 0;
|
|
7
|
-
|
|
14
|
+
(_a = (_c = input.request).headers) !== null && _a !== void 0 ? _a : (_c.headers = {});
|
|
15
|
+
let lastError = new util_error_handler_1.IngestkoreaError({
|
|
8
16
|
code: 400,
|
|
9
17
|
type: "Bad Request",
|
|
10
18
|
message: "Invalid Request",
|
|
11
|
-
description: { attempts,
|
|
19
|
+
description: { attempts, maxRetries: MAX_RETRIES, totalRetryDelay },
|
|
12
20
|
});
|
|
13
|
-
while (
|
|
21
|
+
while (attempts < MAX_RETRIES) {
|
|
22
|
+
const attemptNo = attempts + 1;
|
|
23
|
+
const requestLog = `attempt=${attemptNo}; max=${MAX_RETRIES}; totalRetryDelay=${totalRetryDelay}`;
|
|
24
|
+
input.request.headers[constants_js_1.INGESTKOREA_REQUEST_LOG] = requestLog;
|
|
14
25
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
$metadata: {
|
|
20
|
-
attempts: attempts + 1,
|
|
21
|
-
totalRetryDelay: totalRetryDelay,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
response,
|
|
25
|
-
};
|
|
26
|
+
const { response } = await next(input, context);
|
|
27
|
+
response.headers[constants_js_1.INGESTKOREA_RETRY] = attemptNo.toString();
|
|
28
|
+
response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] = totalRetryDelay.toString();
|
|
29
|
+
return { response };
|
|
26
30
|
}
|
|
27
|
-
catch (
|
|
31
|
+
catch (error) {
|
|
28
32
|
attempts++;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
throw lastError;
|
|
32
|
-
}
|
|
33
|
-
const delay = attempts * 1000;
|
|
34
|
-
totalRetryDelay += delay;
|
|
35
|
-
lastError.error.description = { attempts, maxAttempts, totalRetryDelay };
|
|
36
|
-
if (err instanceof IngestkoreaError) {
|
|
33
|
+
lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
|
|
34
|
+
if (error instanceof util_error_handler_1.IngestkoreaError) {
|
|
37
35
|
lastError.error.description = {
|
|
38
36
|
...lastError.error.description,
|
|
39
|
-
detail:
|
|
37
|
+
detail: error.error.description,
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
|
-
|
|
40
|
+
else {
|
|
43
41
|
lastError.error.description = {
|
|
44
42
|
...lastError.error.description,
|
|
45
|
-
detail:
|
|
43
|
+
detail: String((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error),
|
|
46
44
|
};
|
|
47
45
|
}
|
|
46
|
+
if (attempts >= MAX_RETRIES) {
|
|
47
|
+
lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
|
|
48
|
+
throw lastError;
|
|
49
|
+
}
|
|
50
|
+
const exp = BASE_DELAY_MS * 2 ** (attempts - 1);
|
|
51
|
+
const capped = Math.min(MAX_DELAY_MS, exp);
|
|
52
|
+
const delay = Math.floor(Math.random() * capped);
|
|
53
|
+
totalRetryDelay += delay;
|
|
54
|
+
lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
|
|
48
55
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
49
56
|
}
|
|
50
57
|
}
|
|
58
|
+
throw lastError;
|
|
51
59
|
};
|
|
60
|
+
exports.middlewareRetry = middlewareRetry;
|