@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
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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일 이내만 조회 가능
|
|
1
|
+
import { SensCommand, SensError, } from "../models/index.js";
|
|
2
|
+
import { se_ListSMSStatusCommand, de_ListSMSStatusCommand } from "../protocols/ListSMSStatus.js";
|
|
3
|
+
import { getDefaultRequestDuration, resolveRequestDuration, convertToUtc, convertToKst, prettyPhoneNum, } from "./constants.js";
|
|
4
|
+
const DURATION_LIMIT_MS = 30 * 24 * 3_600_000; // 30일 이내만 조회 가능
|
|
8
5
|
const MAX_LIMIT = 100;
|
|
9
6
|
const DEFAULT_LIMIT = 20;
|
|
10
|
-
class ListSMSStatusCommand extends
|
|
7
|
+
export class ListSMSStatusCommand extends SensCommand {
|
|
8
|
+
input;
|
|
9
|
+
serializer;
|
|
10
|
+
deserializer;
|
|
11
11
|
constructor(input) {
|
|
12
|
-
var _a;
|
|
13
12
|
super(input);
|
|
14
13
|
if (input.nextToken && (!input.requestStartTime || !input.requestEndTime)) {
|
|
15
|
-
throw new
|
|
16
|
-
code:
|
|
17
|
-
type: "
|
|
14
|
+
throw new SensError({
|
|
15
|
+
code: -1,
|
|
16
|
+
type: "SDK.GENERAL_ERROR",
|
|
18
17
|
message: "페이지네이션 검색 조건 불일치",
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
message: "nextToken 사용 시 데이터 일관성을 위해 최초 요청 시의 옵션(requestStartTime, requestEndTime, pageSize 등)이 모두 동일하게 유지되어야 합니다.",
|
|
23
|
-
},
|
|
18
|
+
errors: [
|
|
19
|
+
"nextToken 사용 시 데이터 일관성을 위해 최초 요청 시의 옵션이 모두 동일하게 유지되어야 합니다.",
|
|
20
|
+
"requestStartTime, requestEndTime, pageSize 옵션을 확인해주세요.",
|
|
24
21
|
],
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
|
-
const defaultDuration =
|
|
28
|
-
const { startTimeMs, endTimeMs } =
|
|
29
|
-
startTime: input.requestStartTime ?
|
|
30
|
-
endTime: input.requestEndTime ?
|
|
24
|
+
const defaultDuration = getDefaultRequestDuration({ durationLimitMs: DURATION_LIMIT_MS });
|
|
25
|
+
const { startTimeMs, endTimeMs } = resolveRequestDuration({
|
|
26
|
+
startTime: input.requestStartTime ? convertToUtc(input.requestStartTime) : defaultDuration.startTime,
|
|
27
|
+
endTime: input.requestEndTime ? convertToUtc(input.requestEndTime) : defaultDuration.endTime,
|
|
31
28
|
}, { durationLimitMs: DURATION_LIMIT_MS });
|
|
32
29
|
this.input = {
|
|
33
|
-
requestStartTime:
|
|
34
|
-
requestEndTime:
|
|
35
|
-
pageSize: Math.min(MAX_LIMIT, Math.max(1,
|
|
30
|
+
requestStartTime: convertToKst(startTimeMs),
|
|
31
|
+
requestEndTime: convertToKst(endTimeMs),
|
|
32
|
+
pageSize: Math.min(MAX_LIMIT, Math.max(1, input.pageSize ?? DEFAULT_LIMIT)),
|
|
36
33
|
...(input.type && { type: input.type }),
|
|
37
34
|
...(input.contentType && { contentType: input.contentType }),
|
|
38
35
|
...(input.status && { status: input.status }),
|
|
39
|
-
...(input.from && { from:
|
|
40
|
-
...(input.to && { to:
|
|
36
|
+
...(input.from && { from: prettyPhoneNum(input.from) }),
|
|
37
|
+
...(input.to && { to: prettyPhoneNum(input.to) }),
|
|
41
38
|
...(input.statusName && { statusName: input.statusName }),
|
|
42
39
|
...(input.nextToken && { nextToken: input.nextToken }),
|
|
43
40
|
};
|
|
44
|
-
this.serializer =
|
|
45
|
-
this.deserializer =
|
|
41
|
+
this.serializer = se_ListSMSStatusCommand;
|
|
42
|
+
this.deserializer = de_ListSMSStatusCommand;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
exports.ListSMSStatusCommand = ListSMSStatusCommand;
|
|
@@ -1,45 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { SensCommand, ALIMTALK_MAX_RECIPIENTS, ALIMTALK_MAX_CONTENT_LENGTH, SensError, } from "../models/index.js";
|
|
2
|
+
import { se_SendAlimtalkCommand, de_SendAlimtalkCommand } from "../protocols/SendAlimtalk.js";
|
|
3
|
+
export class SendAlimtalkCommand extends SensCommand {
|
|
4
|
+
input;
|
|
5
|
+
serializer;
|
|
6
|
+
deserializer;
|
|
7
7
|
constructor(input) {
|
|
8
8
|
super(input);
|
|
9
9
|
this.input = {
|
|
10
10
|
plusFriendId: input.plusFriendId,
|
|
11
11
|
templateCode: input.templateCode,
|
|
12
12
|
messages: resolveAlimtalkMessages(input.messages, {
|
|
13
|
-
maxRecipients:
|
|
14
|
-
maxContentLength:
|
|
13
|
+
maxRecipients: ALIMTALK_MAX_RECIPIENTS,
|
|
14
|
+
maxContentLength: ALIMTALK_MAX_CONTENT_LENGTH,
|
|
15
15
|
}),
|
|
16
16
|
};
|
|
17
|
-
this.serializer =
|
|
18
|
-
this.deserializer =
|
|
17
|
+
this.serializer = se_SendAlimtalkCommand;
|
|
18
|
+
this.deserializer = de_SendAlimtalkCommand;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.SendAlimtalkCommand = SendAlimtalkCommand;
|
|
22
21
|
const resolveAlimtalkMessages = (messages, config) => {
|
|
23
22
|
if (!messages.length || messages.length > config.maxRecipients) {
|
|
24
|
-
throw new
|
|
25
|
-
code:
|
|
26
|
-
type: "
|
|
27
|
-
message:
|
|
28
|
-
invalidInputs: [
|
|
29
|
-
{
|
|
30
|
-
type: "not-valid.args",
|
|
31
|
-
message: `메세지 동시 발송은 최소 1명, 최대 ${config.maxRecipients}명까지 가능합니다.`,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
23
|
+
throw new SensError({
|
|
24
|
+
code: -1,
|
|
25
|
+
type: "SDK.GENERAL_ERROR",
|
|
26
|
+
message: `알림톡 동시 발송은 최소 1명, 최대 ${config.maxRecipients}명까지 가능합니다.`,
|
|
34
27
|
});
|
|
35
28
|
}
|
|
36
29
|
const result = messages.map((message) => {
|
|
37
30
|
if (message.content.length > config.maxContentLength) {
|
|
38
|
-
throw new
|
|
39
|
-
code:
|
|
40
|
-
type: "
|
|
41
|
-
message:
|
|
42
|
-
invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${config.maxContentLength}글자입니다` }],
|
|
31
|
+
throw new SensError({
|
|
32
|
+
code: -1,
|
|
33
|
+
type: "SDK.GENERAL_ERROR",
|
|
34
|
+
message: `알림톡 최대 길이는 ${config.maxContentLength}글자입니다`,
|
|
43
35
|
});
|
|
44
36
|
}
|
|
45
37
|
return {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { parse, format } from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
4
|
+
import { SensCommand, MMS_MAX_SUPPORT_FILE_SIZE, MMS_SUPPORT_FILE_EXTENSION, SensError, } from "../models/index.js";
|
|
5
|
+
import { se_SendMMSCommand, de_SendMMSCommand } from "../protocols/SendMMS.js";
|
|
6
|
+
import { trimText, prettyPhoneNum } from "./constants.js";
|
|
7
|
+
import { resolveInputMessages } from "./SendSMSCommand.js";
|
|
8
|
+
export class SendMMSCommand extends SensCommand {
|
|
9
|
+
input;
|
|
10
|
+
serializer;
|
|
11
|
+
deserializer;
|
|
12
12
|
constructor(input) {
|
|
13
13
|
super(input);
|
|
14
|
-
const content = input.content ?
|
|
15
|
-
const subject = input.subject ?
|
|
16
|
-
const messages =
|
|
14
|
+
const content = input.content ? trimText(input.content) : "내용없음";
|
|
15
|
+
const subject = input.subject ? trimText(input.subject) : "제목없음";
|
|
16
|
+
const messages = resolveInputMessages(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
17
17
|
this.input = {
|
|
18
|
-
from:
|
|
18
|
+
from: prettyPhoneNum(input.from),
|
|
19
19
|
content,
|
|
20
20
|
messages,
|
|
21
21
|
type: "MMS",
|
|
@@ -23,49 +23,44 @@ class SendMMSCommand extends index_js_1.SensCommand {
|
|
|
23
23
|
countryCode: input.countryCode ? input.countryCode : "82",
|
|
24
24
|
subject,
|
|
25
25
|
files: (input.files || []).map((file) => {
|
|
26
|
-
return resolveSendFile(file, { maxKiB:
|
|
26
|
+
return resolveSendFile(file, { maxKiB: MMS_MAX_SUPPORT_FILE_SIZE, supportExt: MMS_SUPPORT_FILE_EXTENSION });
|
|
27
27
|
}),
|
|
28
28
|
};
|
|
29
|
-
this.serializer =
|
|
30
|
-
this.deserializer =
|
|
29
|
+
this.serializer = se_SendMMSCommand;
|
|
30
|
+
this.deserializer = de_SendMMSCommand;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
exports.SendMMSCommand = SendMMSCommand;
|
|
34
33
|
const resolveSendFile = (file, options) => {
|
|
35
|
-
const parsed =
|
|
34
|
+
const parsed = parse(file.name); // { dir, name, ext, base }
|
|
36
35
|
const ext = parsed.ext.toLocaleLowerCase();
|
|
37
36
|
if (!options.supportExt.includes(ext)) {
|
|
38
|
-
throw new
|
|
39
|
-
code:
|
|
40
|
-
type: "
|
|
41
|
-
message: "
|
|
42
|
-
invalidInputs: [
|
|
43
|
-
{ type: "not-valid.args", message: `${options.supportExt.join(", ")} 형식의 첨부파일만 지원합니다.` },
|
|
44
|
-
],
|
|
37
|
+
throw new SensError({
|
|
38
|
+
code: -1,
|
|
39
|
+
type: "SDK.GENERAL_ERROR",
|
|
40
|
+
message: `MMS는 ${options.supportExt.join(", ")} 형식의 첨부파일만 보낼 수 있습니다.`,
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
43
|
if (file.body) {
|
|
48
44
|
const buffer = Buffer.from(file.body, "base64");
|
|
49
45
|
checkSizeLimit(buffer, options.maxKiB);
|
|
50
|
-
const hash =
|
|
46
|
+
const hash = createHash("md5").update(buffer).digest("hex");
|
|
51
47
|
return {
|
|
52
|
-
name:
|
|
48
|
+
name: format({ name: hash, ext }),
|
|
53
49
|
body: file.body,
|
|
54
50
|
};
|
|
55
51
|
}
|
|
56
|
-
if (!
|
|
57
|
-
throw new
|
|
58
|
-
code:
|
|
59
|
-
type: "
|
|
60
|
-
message:
|
|
61
|
-
invalidInputs: [{ type: "not-valid.args", message: `${file.name} 파일이 존재하지 않습니다.` }],
|
|
52
|
+
if (!existsSync(file.name)) {
|
|
53
|
+
throw new SensError({
|
|
54
|
+
code: -1,
|
|
55
|
+
type: "SDK.GENERAL_ERROR",
|
|
56
|
+
message: `${file.name} 첨부파일이 존재하지 않습니다.`,
|
|
62
57
|
});
|
|
63
58
|
}
|
|
64
|
-
const buffer =
|
|
59
|
+
const buffer = readFileSync(file.name);
|
|
65
60
|
checkSizeLimit(buffer, options.maxKiB);
|
|
66
|
-
const hash =
|
|
61
|
+
const hash = createHash("md5").update(buffer).digest("hex");
|
|
67
62
|
return {
|
|
68
|
-
name:
|
|
63
|
+
name: format({ name: hash, ext }),
|
|
69
64
|
body: buffer.toString("base64"),
|
|
70
65
|
};
|
|
71
66
|
};
|
|
@@ -73,16 +68,10 @@ const checkSizeLimit = (buffer, maxKiB) => {
|
|
|
73
68
|
const byteSize = buffer.length;
|
|
74
69
|
const kibSize = Math.ceil(byteSize / 1024);
|
|
75
70
|
if (kibSize > maxKiB) {
|
|
76
|
-
throw new
|
|
77
|
-
code:
|
|
78
|
-
type: "
|
|
79
|
-
message:
|
|
80
|
-
invalidInputs: [
|
|
81
|
-
{
|
|
82
|
-
type: "not-valid.args",
|
|
83
|
-
message: `최대 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
71
|
+
throw new SensError({
|
|
72
|
+
code: -1,
|
|
73
|
+
type: "SDK.GENERAL_ERROR",
|
|
74
|
+
message: `첨부파일은 ${maxKiB}KiB까지 전송 가능합니다. 현재 ${kibSize}KiB`,
|
|
86
75
|
});
|
|
87
76
|
}
|
|
88
77
|
return;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { SensCommand, SensError, } from "../models/index.js";
|
|
2
|
+
import { se_SendSMSCommand, de_SendSMSCommand } from "../protocols/SendSMS.js";
|
|
3
|
+
import { trimText, prettyPhoneNum, getContentLength } from "./constants.js";
|
|
4
|
+
export class SendSMSCommand extends SensCommand {
|
|
5
|
+
input;
|
|
6
|
+
serializer;
|
|
7
|
+
deserializer;
|
|
8
8
|
constructor(input) {
|
|
9
9
|
super(input);
|
|
10
|
-
const content = input.content ?
|
|
11
|
-
const subject = input.subject ?
|
|
12
|
-
const messages =
|
|
10
|
+
const content = input.content ? trimText(input.content) : "내용없음";
|
|
11
|
+
const subject = input.subject ? trimText(input.subject) : "제목없음";
|
|
12
|
+
const messages = resolveInputMessages(input.messages, { defaultContent: content, defaultSubject: subject });
|
|
13
13
|
const isLMS = !!messages.filter((msg) => !!msg.subject).length;
|
|
14
14
|
this.input = {
|
|
15
|
-
from:
|
|
15
|
+
from: prettyPhoneNum(input.from),
|
|
16
16
|
content,
|
|
17
17
|
messages,
|
|
18
18
|
type: isLMS ? "LMS" : "SMS",
|
|
@@ -20,45 +20,41 @@ class SendSMSCommand extends index_js_1.SensCommand {
|
|
|
20
20
|
countryCode: input.countryCode ? input.countryCode : "82",
|
|
21
21
|
...(isLMS && { subject }),
|
|
22
22
|
};
|
|
23
|
-
this.serializer =
|
|
24
|
-
this.deserializer =
|
|
23
|
+
this.serializer = se_SendSMSCommand;
|
|
24
|
+
this.deserializer = de_SendSMSCommand;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const resolveInputMessages = (messages, config) => {
|
|
27
|
+
export const resolveInputMessages = (messages, config) => {
|
|
29
28
|
const output = messages
|
|
30
29
|
.filter((d) => !!d)
|
|
31
30
|
.map((message) => {
|
|
32
|
-
const content = message.content ?
|
|
33
|
-
const subject = message.subject ?
|
|
31
|
+
const content = message.content ? trimText(message.content) : config.defaultContent;
|
|
32
|
+
const subject = message.subject ? trimText(message.subject) : config.defaultSubject;
|
|
34
33
|
const msgType = getMessageType({ content });
|
|
35
34
|
return {
|
|
36
|
-
to:
|
|
35
|
+
to: prettyPhoneNum(message.to),
|
|
37
36
|
content,
|
|
38
37
|
...(msgType === "LMS" && { subject }),
|
|
39
38
|
};
|
|
40
39
|
});
|
|
41
40
|
return output;
|
|
42
41
|
};
|
|
43
|
-
exports.resolveInputMessages = resolveInputMessages;
|
|
44
42
|
const getMessageType = (input) => {
|
|
45
43
|
const SMS_MAX_CONTENT_LENGTH = 90;
|
|
46
44
|
const LMS_MAX_CONTENT_LENGTH = 2000;
|
|
47
|
-
const contentLength =
|
|
45
|
+
const contentLength = getContentLength(input.content);
|
|
48
46
|
if (!contentLength) {
|
|
49
|
-
throw new
|
|
50
|
-
code:
|
|
51
|
-
type: "
|
|
47
|
+
throw new SensError({
|
|
48
|
+
code: -1,
|
|
49
|
+
type: "SDK.GENERAL_ERROR",
|
|
52
50
|
message: "메세지 내용이 없습니다.",
|
|
53
|
-
invalidInputs: [{ type: "not-valid.args", message: "메세지 내용을 확인해주세요." }],
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
if (contentLength > LMS_MAX_CONTENT_LENGTH) {
|
|
57
|
-
throw new
|
|
58
|
-
code:
|
|
59
|
-
type: "
|
|
60
|
-
message:
|
|
61
|
-
invalidInputs: [{ type: "not-valid.args", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다` }],
|
|
54
|
+
throw new SensError({
|
|
55
|
+
code: -1,
|
|
56
|
+
type: "SDK.GENERAL_ERROR",
|
|
57
|
+
message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다`,
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
60
|
return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS";
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const index_js_1 = require("../models/index.js");
|
|
5
|
-
const trimText = (input) => input.trim();
|
|
6
|
-
exports.trimText = trimText;
|
|
7
|
-
const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
|
|
8
|
-
exports.prettyPhoneNum = prettyPhoneNum;
|
|
1
|
+
import { SensError } from "../models/index.js";
|
|
2
|
+
export const trimText = (input) => input.trim();
|
|
3
|
+
export const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
|
|
9
4
|
/** @returns content-length(euc-kr) */
|
|
10
|
-
const getContentLength = (input) => {
|
|
5
|
+
export const getContentLength = (input) => {
|
|
11
6
|
return input.split("").reduce((acc, text) => {
|
|
12
7
|
let byte = Buffer.from(text).length;
|
|
13
8
|
let modulo = byte % 3;
|
|
@@ -15,55 +10,40 @@ const getContentLength = (input) => {
|
|
|
15
10
|
return acc;
|
|
16
11
|
}, 0);
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
const convertToUtc = (input) => {
|
|
13
|
+
export const convertToUtc = (input) => {
|
|
20
14
|
const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
|
|
21
15
|
return utcRegex.test(input) ? input : new Date(input.replace(" ", "T") + "+09:00").toISOString();
|
|
22
16
|
};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const KST_OFFSET = 9 * 3600000;
|
|
17
|
+
export const convertToKst = (input) => {
|
|
18
|
+
const KST_OFFSET = 9 * 3_600_000;
|
|
26
19
|
return new Date(input + KST_OFFSET).toISOString().replace(/\.\d{3}Z$/, "");
|
|
27
20
|
};
|
|
28
|
-
exports.convertToKst = convertToKst;
|
|
29
21
|
// UTC
|
|
30
|
-
const getDefaultRequestDuration = (config) => {
|
|
22
|
+
export const getDefaultRequestDuration = (config) => {
|
|
31
23
|
const now = Date.now();
|
|
32
24
|
return {
|
|
33
25
|
startTime: new Date(now - config.durationLimitMs).toISOString(),
|
|
34
26
|
endTime: new Date(now).toISOString(),
|
|
35
27
|
};
|
|
36
28
|
};
|
|
37
|
-
exports.getDefaultRequestDuration = getDefaultRequestDuration;
|
|
38
29
|
// UTC
|
|
39
|
-
const resolveRequestDuration = (input, config) => {
|
|
30
|
+
export const resolveRequestDuration = (input, config) => {
|
|
40
31
|
const start = new Date(input.startTime).getTime();
|
|
41
32
|
const end = new Date(input.endTime).getTime();
|
|
42
33
|
const diff = end - start;
|
|
43
34
|
if (diff < 0) {
|
|
44
|
-
throw new
|
|
45
|
-
code:
|
|
46
|
-
type: "
|
|
47
|
-
message:
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
type: "not-valid.args",
|
|
51
|
-
message: "종료일이 시작일보다 빠를 수 없습니다.",
|
|
52
|
-
},
|
|
53
|
-
],
|
|
35
|
+
throw new SensError({
|
|
36
|
+
code: -1,
|
|
37
|
+
type: "SDK.GENERAL_ERROR",
|
|
38
|
+
message: "조회 가능 날짜 오류. 종료일이 시작일보다 빠를 수 없습니다.",
|
|
39
|
+
errors: [`종료일: ${input.endTime}`, `시작일: ${input.startTime}`],
|
|
54
40
|
});
|
|
55
41
|
}
|
|
56
42
|
if (diff > config.durationLimitMs) {
|
|
57
|
-
throw new
|
|
58
|
-
code:
|
|
59
|
-
type: "
|
|
60
|
-
message:
|
|
61
|
-
invalidInputs: [
|
|
62
|
-
{
|
|
63
|
-
type: "not-valid.args",
|
|
64
|
-
message: `조회 가능한 날짜 범위는 최대 ${config.durationLimitMs / (24 * 3600000)}일 이내여야 합니다.`,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
43
|
+
throw new SensError({
|
|
44
|
+
code: -1,
|
|
45
|
+
type: "SDK.GENERAL_ERROR",
|
|
46
|
+
message: `최대 ${config.durationLimitMs / (24 * 3_600_000)}일 이내에서 조회 가능합니다.`,
|
|
67
47
|
});
|
|
68
48
|
}
|
|
69
49
|
return {
|
|
@@ -71,4 +51,3 @@ const resolveRequestDuration = (input, config) => {
|
|
|
71
51
|
endTimeMs: end,
|
|
72
52
|
};
|
|
73
53
|
};
|
|
74
|
-
exports.resolveRequestDuration = resolveRequestDuration;
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./GetAlimtalkResultCommand.js"), exports);
|
|
18
|
-
__exportStar(require("./GetAlimtalkStatusCommand.js"), exports);
|
|
19
|
-
__exportStar(require("./GetAlimtalkTemplateCommand.js"), exports);
|
|
20
|
-
__exportStar(require("./GetSMSResultCommand.js"), exports);
|
|
21
|
-
__exportStar(require("./GetSMSStatusCommand.js"), exports);
|
|
22
|
-
__exportStar(require("./ListAlimtalkChannelsCommand.js"), exports);
|
|
23
|
-
__exportStar(require("./ListAlimtalkStatusCommand.js"), exports);
|
|
24
|
-
__exportStar(require("./ListAlimtalkTemplatesCommand.js"), exports);
|
|
25
|
-
__exportStar(require("./ListSMSStatusCommand.js"), exports);
|
|
26
|
-
__exportStar(require("./SendAlimtalkCommand.js"), exports);
|
|
27
|
-
__exportStar(require("./SendMMSCommand.js"), exports);
|
|
28
|
-
__exportStar(require("./SendSMSCommand.js"), exports);
|
|
1
|
+
export * from "./GetAlimtalkResultCommand.js";
|
|
2
|
+
export * from "./GetAlimtalkStatusCommand.js";
|
|
3
|
+
export * from "./GetAlimtalkTemplateCommand.js";
|
|
4
|
+
export * from "./GetSMSResultCommand.js";
|
|
5
|
+
export * from "./GetSMSStatusCommand.js";
|
|
6
|
+
export * from "./ListAlimtalkChannelsCommand.js";
|
|
7
|
+
export * from "./ListAlimtalkStatusCommand.js";
|
|
8
|
+
export * from "./ListAlimtalkTemplatesCommand.js";
|
|
9
|
+
export * from "./ListSMSStatusCommand.js";
|
|
10
|
+
export * from "./SendAlimtalkCommand.js";
|
|
11
|
+
export * from "./SendMMSCommand.js";
|
|
12
|
+
export * from "./SendSMSCommand.js";
|
package/dist-es/index.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
1
|
+
export * from "./commands/index.js";
|
|
2
|
+
export * from "./SensClient.js";
|
|
3
|
+
export * from "./models/SensClientError.js";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.NCP_TIMESTAMP = "x-ncp-apigw-timestamp";
|
|
10
|
-
exports.NCP_SIGNATURE = "x-ncp-apigw-signature-v2";
|
|
1
|
+
export const INGESTKOREA_USER_AGENT = "x-ingestkorea-user-agent";
|
|
2
|
+
export const INGESTKOREA_REQUEST_LOG = "x-ingestkorea-request";
|
|
3
|
+
export const INGESTKOREA_RETRY = "x-ingestkorea-attempts";
|
|
4
|
+
export const INGESTKOREA_RETRY_DELAY = "x-ingestkorea-total-retry-delay";
|
|
5
|
+
export const NCP_ACCESS_KEY = "x-ncp-iam-access-key";
|
|
6
|
+
export const NCP_TIMESTAMP = "x-ncp-apigw-timestamp";
|
|
7
|
+
export const NCP_SIGNATURE = "x-ncp-apigw-signature-v2";
|
|
8
|
+
export const NCP_TRACE_ID = "x-ncp-trace-id";
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
export * from "./middleware-metadata.js";
|
|
2
|
+
export * from "./middleware-retry.js";
|
|
3
|
+
export * from "./middleware-sign.js";
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.middlewareIngestkoreaMetadata = void 0;
|
|
4
|
-
const constants_js_1 = require("./constants.js");
|
|
5
|
-
const middlewareIngestkoreaMetadata = (next) => async (input, context) => {
|
|
1
|
+
import { INGESTKOREA_USER_AGENT } from "./constants.js";
|
|
2
|
+
export const middlewareIngestkoreaMetadata = (next) => async (input, context) => {
|
|
6
3
|
input.request.headers = {
|
|
7
4
|
...input.request.headers,
|
|
8
|
-
[
|
|
5
|
+
[INGESTKOREA_USER_AGENT]: "@ingestkorea/client-sens/1.11.x",
|
|
6
|
+
connection: context.httpHandler.keepAlive ? "keep-alive" : "close", // temp
|
|
9
7
|
};
|
|
10
8
|
return next(input, context);
|
|
11
9
|
};
|
|
12
|
-
exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
|