@ingestkorea/client-sens 1.10.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 +98 -57
- package/dist-cjs/SensClient.js +31 -35
- 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 +17 -3
- package/dist-cjs/commands/ListAlimtalkTemplatesCommand.js +3 -0
- package/dist-cjs/commands/ListSMSStatusCommand.js +16 -3
- package/dist-cjs/commands/SendAlimtalkCommand.js +9 -1
- package/dist-cjs/commands/SendMMSCommand.js +7 -4
- package/dist-cjs/commands/SendSMSCommand.js +23 -9
- package/dist-cjs/commands/constants.js +2 -2
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/middleware/constants.js +2 -1
- package/dist-cjs/middleware/middleware-metadata.js +7 -12
- package/dist-cjs/middleware/middleware-retry.js +37 -20
- package/dist-cjs/middleware/middleware-sign.js +8 -12
- package/dist-cjs/models/{SensErrorInfo.js → SensApiError.js} +1 -11
- package/dist-cjs/models/{SensError.js → SensClientError.js} +4 -0
- package/dist-cjs/models/SensCommand.js +1 -0
- package/dist-cjs/models/index.js +2 -2
- 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 +91 -75
- package/dist-es/SensClient.js +25 -22
- 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 +19 -21
- package/dist-es/commands/ListAlimtalkTemplatesCommand.js +8 -9
- package/dist-es/commands/ListSMSStatusCommand.js +20 -22
- package/dist-es/commands/SendAlimtalkCommand.js +12 -13
- package/dist-es/commands/SendMMSCommand.js +28 -29
- package/dist-es/commands/SendSMSCommand.js +20 -22
- package/dist-es/commands/constants.js +12 -22
- package/dist-es/commands/index.js +12 -28
- package/dist-es/index.js +3 -19
- 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 +39 -19
- 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/{SensError.js → SensClientError.js} +5 -5
- package/dist-es/models/SensCommand.js +2 -5
- package/dist-es/models/SensMiddleware.js +1 -2
- package/dist-es/models/index.js +18 -34
- 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 +96 -84
- package/dist-types/SensClient.d.ts +0 -1
- package/dist-types/index.d.ts +1 -1
- package/dist-types/middleware/constants.d.ts +1 -0
- package/dist-types/models/MetadataBearer.d.ts +1 -0
- package/dist-types/models/{SensErrorInfo.d.ts → SensApiError.d.ts} +0 -2
- package/dist-types/models/SensClient.d.ts +8 -0
- package/dist-types/models/{SensError.d.ts → SensClientError.d.ts} +3 -2
- package/dist-types/models/index.d.ts +2 -2
- package/package.json +4 -4
- package/dist-es/models/SensErrorInfo.js +0 -31
|
@@ -1,18 +1,9 @@
|
|
|
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_Template = exports.de_ListAlimtalkTemplatesCommand = exports.se_ListAlimtalkTemplatesCommand = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const constants_js_1 = require("./constants.js");
|
|
15
|
-
const se_ListAlimtalkTemplatesCommand = (input, config) =>
|
|
6
|
+
const se_ListAlimtalkTemplatesCommand = async (input, config) => {
|
|
16
7
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
8
|
const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/templates";
|
|
18
9
|
const headers = {
|
|
@@ -29,15 +20,18 @@ const se_ListAlimtalkTemplatesCommand = (input, config) => __awaiter(void 0, voi
|
|
|
29
20
|
query: query,
|
|
30
21
|
headers: headers,
|
|
31
22
|
});
|
|
32
|
-
}
|
|
23
|
+
};
|
|
33
24
|
exports.se_ListAlimtalkTemplatesCommand = se_ListAlimtalkTemplatesCommand;
|
|
34
|
-
const de_ListAlimtalkTemplatesCommand = (response, config) =>
|
|
25
|
+
const de_ListAlimtalkTemplatesCommand = async (response, config) => {
|
|
35
26
|
if (response.statusCode >= 300)
|
|
36
|
-
|
|
37
|
-
const data =
|
|
27
|
+
await (0, constants_js_1.parseErrorBody)(response);
|
|
28
|
+
const data = await (0, constants_js_1.parseBody)(response);
|
|
38
29
|
const contents = de_ListAlimtalkTemplatesResult(data);
|
|
39
|
-
return
|
|
40
|
-
|
|
30
|
+
return {
|
|
31
|
+
$metadata: (0, constants_js_1.deserializeMetadata)(response),
|
|
32
|
+
...(0, constants_js_1.compact)(contents),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
41
35
|
exports.de_ListAlimtalkTemplatesCommand = de_ListAlimtalkTemplatesCommand;
|
|
42
36
|
const de_ListAlimtalkTemplatesResult = (output) => {
|
|
43
37
|
return {
|
|
@@ -49,10 +43,9 @@ const de_TemplateList = (output) => {
|
|
|
49
43
|
.filter((e) => e != null)
|
|
50
44
|
.map((entry) => (0, exports.de_Template)(entry))
|
|
51
45
|
.sort((a, b) => {
|
|
52
|
-
var _a, _b;
|
|
53
46
|
// 생성 날짜 기준 내림차순
|
|
54
|
-
const dateA = (
|
|
55
|
-
const dateB = (
|
|
47
|
+
const dateA = (a.createTime ?? "").replace(/\.\d{3}Z?$/, "");
|
|
48
|
+
const dateB = (b.createTime ?? "").replace(/\.\d{3}Z?$/, "");
|
|
56
49
|
if (dateB < dateA)
|
|
57
50
|
return -1;
|
|
58
51
|
if (dateB > dateA)
|
|
@@ -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_ListSMSStatusCommand = exports.se_ListSMSStatusCommand = 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 GetSMSStatus_js_1 = require("./GetSMSStatus.js");
|
|
16
|
-
const se_ListSMSStatusCommand = (input, config) =>
|
|
7
|
+
const se_ListSMSStatusCommand = async (input, config) => {
|
|
17
8
|
const hostname = "sens.apigw.ntruss.com";
|
|
18
9
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
19
10
|
const headers = {
|
|
@@ -33,15 +24,18 @@ const se_ListSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, voi
|
|
|
33
24
|
query,
|
|
34
25
|
headers,
|
|
35
26
|
});
|
|
36
|
-
}
|
|
27
|
+
};
|
|
37
28
|
exports.se_ListSMSStatusCommand = se_ListSMSStatusCommand;
|
|
38
|
-
const de_ListSMSStatusCommand = (response, config) =>
|
|
29
|
+
const de_ListSMSStatusCommand = 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 = de_ListSMSStatusResult(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_ListSMSStatusCommand = de_ListSMSStatusCommand;
|
|
46
40
|
const de_ListSMSStatusResult = (output) => {
|
|
47
41
|
return (0, GetSMSStatus_js_1.de_GetSMSStatusResult)(output);
|
|
@@ -1,18 +1,9 @@
|
|
|
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_AlimtalkMessageRequestStatus = exports.de_SendAlimtalkCommand = exports.se_SendAlimtalkCommand = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const constants_js_1 = require("./constants.js");
|
|
15
|
-
const se_SendAlimtalkCommand = (input, config) =>
|
|
6
|
+
const se_SendAlimtalkCommand = async (input, config) => {
|
|
16
7
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
8
|
const path = "/alimtalk/v2/services/" + config.serviceId.kakao + "/messages";
|
|
18
9
|
const headers = {
|
|
@@ -32,15 +23,18 @@ const se_SendAlimtalkCommand = (input, config) => __awaiter(void 0, void 0, void
|
|
|
32
23
|
headers,
|
|
33
24
|
body,
|
|
34
25
|
});
|
|
35
|
-
}
|
|
26
|
+
};
|
|
36
27
|
exports.se_SendAlimtalkCommand = se_SendAlimtalkCommand;
|
|
37
|
-
const de_SendAlimtalkCommand = (response, config) =>
|
|
28
|
+
const de_SendAlimtalkCommand = async (response, config) => {
|
|
38
29
|
if (response.statusCode >= 300)
|
|
39
|
-
|
|
40
|
-
const data =
|
|
30
|
+
await (0, constants_js_1.parseErrorBody)(response);
|
|
31
|
+
const data = await (0, constants_js_1.parseBody)(response);
|
|
41
32
|
const contents = de_SendAlimtalkResult(data);
|
|
42
|
-
return
|
|
43
|
-
|
|
33
|
+
return {
|
|
34
|
+
$metadata: (0, constants_js_1.deserializeMetadata)(response),
|
|
35
|
+
...(0, constants_js_1.compact)(contents),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
44
38
|
exports.de_SendAlimtalkCommand = de_SendAlimtalkCommand;
|
|
45
39
|
const de_SendAlimtalkResult = (output) => {
|
|
46
40
|
return {
|
|
@@ -1,21 +1,12 @@
|
|
|
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_SendMMSCommand = exports.se_SendMMSCommand = void 0;
|
|
13
4
|
const SendSMS_js_1 = require("./SendSMS.js");
|
|
14
|
-
const se_SendMMSCommand = (input, config) =>
|
|
5
|
+
const se_SendMMSCommand = async (input, config) => {
|
|
15
6
|
return (0, SendSMS_js_1.se_SendSMSCommand)(input, config);
|
|
16
|
-
}
|
|
7
|
+
};
|
|
17
8
|
exports.se_SendMMSCommand = se_SendMMSCommand;
|
|
18
|
-
const de_SendMMSCommand = (response, config) =>
|
|
9
|
+
const de_SendMMSCommand = async (response, config) => {
|
|
19
10
|
return (0, SendSMS_js_1.de_SendSMSCommand)(response, config);
|
|
20
|
-
}
|
|
11
|
+
};
|
|
21
12
|
exports.de_SendMMSCommand = de_SendMMSCommand;
|
|
@@ -1,25 +1,16 @@
|
|
|
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_SendSMSResult = exports.de_SendSMSCommand = exports.se_SendSMSCommand = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const constants_js_1 = require("./constants.js");
|
|
15
|
-
const se_SendSMSCommand = (input, config) =>
|
|
6
|
+
const se_SendSMSCommand = async (input, config) => {
|
|
16
7
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
8
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
18
9
|
const headers = {
|
|
19
10
|
"content-type": "application/json; charset=utf-8",
|
|
20
11
|
host: hostname,
|
|
21
12
|
};
|
|
22
|
-
const body = JSON.stringify(
|
|
13
|
+
const body = JSON.stringify({ ...input });
|
|
23
14
|
return new util_http_handler_1.HttpRequest({
|
|
24
15
|
protocol: "https:",
|
|
25
16
|
method: "POST",
|
|
@@ -28,15 +19,18 @@ const se_SendSMSCommand = (input, config) => __awaiter(void 0, void 0, void 0, f
|
|
|
28
19
|
headers,
|
|
29
20
|
body,
|
|
30
21
|
});
|
|
31
|
-
}
|
|
22
|
+
};
|
|
32
23
|
exports.se_SendSMSCommand = se_SendSMSCommand;
|
|
33
|
-
const de_SendSMSCommand = (response, config) =>
|
|
24
|
+
const de_SendSMSCommand = async (response, config) => {
|
|
34
25
|
if (response.statusCode >= 300)
|
|
35
|
-
|
|
36
|
-
const data =
|
|
26
|
+
await (0, constants_js_1.parseErrorBody)(response);
|
|
27
|
+
const data = await (0, constants_js_1.parseBody)(response);
|
|
37
28
|
const contents = (0, exports.de_SendSMSResult)(data);
|
|
38
|
-
return
|
|
39
|
-
|
|
29
|
+
return {
|
|
30
|
+
$metadata: (0, constants_js_1.deserializeMetadata)(response),
|
|
31
|
+
...(0, constants_js_1.compact)(contents),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
40
34
|
exports.de_SendSMSCommand = de_SendSMSCommand;
|
|
41
35
|
const de_SendSMSResult = (output) => {
|
|
42
36
|
return {
|
|
@@ -1,97 +1,110 @@
|
|
|
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.convertToUtc = exports.compact = exports.parseErrorBody = exports.parseBody = exports.deserializeMetadata = void 0;
|
|
13
4
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
5
|
const index_js_1 = require("../models/index.js");
|
|
15
6
|
const constants_js_1 = require("../middleware/constants.js");
|
|
7
|
+
const ALLOWED_CONTENT_TYPES = ["application/json"];
|
|
8
|
+
const SENS_ERROR_BODY_SPEC = [
|
|
9
|
+
["status", "number", true],
|
|
10
|
+
["errorMessage", "string", false],
|
|
11
|
+
["errors", "object", false],
|
|
12
|
+
];
|
|
13
|
+
const NCLOUD_ERROR_BODY_SPEC = [
|
|
14
|
+
["errorCode", "string", true],
|
|
15
|
+
["message", "string", false],
|
|
16
|
+
["details", "string", false],
|
|
17
|
+
];
|
|
16
18
|
const deserializeMetadata = (response) => {
|
|
17
19
|
const attempts = response.headers[constants_js_1.INGESTKOREA_RETRY] || "1";
|
|
18
20
|
const totalRetryDelay = response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] || "0";
|
|
21
|
+
const traceId = response.headers[constants_js_1.NCP_TRACE_ID] || undefined;
|
|
19
22
|
return {
|
|
20
23
|
httpStatusCode: response.statusCode,
|
|
21
24
|
attempts: Number(attempts),
|
|
22
25
|
totalRetryDelay: Number(totalRetryDelay),
|
|
26
|
+
...(traceId && { traceId }),
|
|
23
27
|
};
|
|
24
28
|
};
|
|
25
29
|
exports.deserializeMetadata = deserializeMetadata;
|
|
26
|
-
const parseBody = (output) =>
|
|
30
|
+
const parseBody = async (output) => {
|
|
27
31
|
const { statusCode, headers, body: streamBody } = output;
|
|
28
|
-
if (!
|
|
29
|
-
|
|
32
|
+
if (!isSupportContentType(ALLOWED_CONTENT_TYPES, headers["content-type"])) {
|
|
33
|
+
await (0, util_http_handler_1.destroyStream)(streamBody);
|
|
30
34
|
throw new index_js_1.SensError({
|
|
31
|
-
code:
|
|
35
|
+
code: statusCode,
|
|
32
36
|
type: "SDK.REQUEST_ERROR",
|
|
33
|
-
message:
|
|
37
|
+
message: `response content-type is not ${ALLOWED_CONTENT_TYPES.join(" or ")}`,
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
try {
|
|
37
|
-
const data =
|
|
41
|
+
const data = await (0, util_http_handler_1.collectBodyString)(streamBody);
|
|
38
42
|
return data.length ? JSON.parse(data) : {};
|
|
39
43
|
}
|
|
40
44
|
catch (e) {
|
|
41
45
|
throw new index_js_1.SensError({
|
|
42
46
|
code: -1,
|
|
43
47
|
type: "SDK.REQUEST_ERROR",
|
|
44
|
-
message:
|
|
48
|
+
message: "parse response body error",
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
|
-
}
|
|
51
|
+
};
|
|
48
52
|
exports.parseBody = parseBody;
|
|
49
|
-
const parseErrorBody = (output) =>
|
|
53
|
+
const parseErrorBody = async (output) => {
|
|
50
54
|
const { statusCode, headers, body: streamBody } = output;
|
|
51
|
-
if (!
|
|
52
|
-
|
|
55
|
+
if (!isSupportContentType(ALLOWED_CONTENT_TYPES, headers["content-type"])) {
|
|
56
|
+
await (0, util_http_handler_1.destroyStream)(streamBody);
|
|
53
57
|
throw new index_js_1.SensError({
|
|
54
58
|
code: -1,
|
|
55
59
|
type: "SDK.REQUEST_ERROR",
|
|
56
|
-
message:
|
|
60
|
+
message: `response content-type is not ${ALLOWED_CONTENT_TYPES.join(" or ")}`,
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
if (nCloudErrorBody) {
|
|
72
|
-
const { errorCode } = nCloudErrorBody.error;
|
|
73
|
-
const errorType = isNCloudErrorCode(errorCode)
|
|
74
|
-
? index_js_1.NCLOUD_ERROR_CODE_SPEC[errorCode].type
|
|
75
|
-
: "SDK.UNKNOWN_ERROR";
|
|
63
|
+
try {
|
|
64
|
+
const data = await (0, util_http_handler_1.collectBodyString)(streamBody);
|
|
65
|
+
const sensContent = isSensErrorResponse(data);
|
|
66
|
+
const nCloudContent = isNCloudErrorResponse(data);
|
|
67
|
+
if (sensContent) {
|
|
68
|
+
throw handleSensError(sensContent, statusCode);
|
|
69
|
+
}
|
|
70
|
+
if (nCloudContent) {
|
|
71
|
+
throw handleNCloudError(nCloudContent, statusCode);
|
|
72
|
+
}
|
|
73
|
+
const summary = data ? data.slice(0, 100).trim() : "empty response";
|
|
76
74
|
throw new index_js_1.SensError({
|
|
77
|
-
code:
|
|
78
|
-
type:
|
|
79
|
-
message:
|
|
75
|
+
code: -1,
|
|
76
|
+
type: "SDK.UNKNOWN_ERROR",
|
|
77
|
+
message: "Invalid Naver Cloud Platform response format",
|
|
78
|
+
errors: [`HTTP ${statusCode} - ${summary}...`],
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
});
|
|
81
|
+
catch (e) {
|
|
82
|
+
await (0, util_http_handler_1.destroyStream)(streamBody);
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
89
86
|
exports.parseErrorBody = parseErrorBody;
|
|
90
|
-
const
|
|
91
|
-
|
|
87
|
+
const compact = (obj) => {
|
|
88
|
+
if (Array.isArray(obj)) {
|
|
89
|
+
return obj.map((item) => (0, exports.compact)(item));
|
|
90
|
+
}
|
|
91
|
+
if (typeof obj === "object" && obj !== null) {
|
|
92
|
+
return Object.fromEntries(Object.entries(obj)
|
|
93
|
+
.filter(([_, value]) => value !== undefined) // undefined 필드 제거
|
|
94
|
+
.map(([key, value]) => [key, (0, exports.compact)(value)]) // 내부 값 재귀 처리
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return obj;
|
|
92
98
|
};
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
exports.compact = compact;
|
|
100
|
+
const convertToUtc = (input) => {
|
|
101
|
+
const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
|
|
102
|
+
return utcRegex.test(input) ? input : new Date(input.replace(" ", "T") + "+09:00").toISOString();
|
|
103
|
+
};
|
|
104
|
+
exports.convertToUtc = convertToUtc;
|
|
105
|
+
const isSupportContentType = (allowedTypes, contentType) => {
|
|
106
|
+
const matchedType = allowedTypes.find((type) => contentType?.toLowerCase().includes(type));
|
|
107
|
+
return !!matchedType;
|
|
95
108
|
};
|
|
96
109
|
const isSensErrorResponse = (input) => {
|
|
97
110
|
if (typeof input !== "string")
|
|
@@ -100,7 +113,7 @@ const isSensErrorResponse = (input) => {
|
|
|
100
113
|
const data = JSON.parse(input);
|
|
101
114
|
if (!data || typeof data !== "object")
|
|
102
115
|
return null;
|
|
103
|
-
const isValid =
|
|
116
|
+
const isValid = SENS_ERROR_BODY_SPEC.every(([key, type, required]) => {
|
|
104
117
|
const value = data[key];
|
|
105
118
|
if (required && (value === undefined || value === null))
|
|
106
119
|
return false;
|
|
@@ -110,7 +123,7 @@ const isSensErrorResponse = (input) => {
|
|
|
110
123
|
});
|
|
111
124
|
return isValid ? data : null;
|
|
112
125
|
}
|
|
113
|
-
catch
|
|
126
|
+
catch {
|
|
114
127
|
return null;
|
|
115
128
|
}
|
|
116
129
|
};
|
|
@@ -121,7 +134,7 @@ const isNCloudErrorResponse = (input) => {
|
|
|
121
134
|
const data = JSON.parse(input);
|
|
122
135
|
if (!(data && typeof data == "object" && typeof data.error == "object"))
|
|
123
136
|
return null;
|
|
124
|
-
const isValid =
|
|
137
|
+
const isValid = NCLOUD_ERROR_BODY_SPEC.every(([key, type, required]) => {
|
|
125
138
|
const value = data.error[key];
|
|
126
139
|
if (required && (value === undefined || value === null))
|
|
127
140
|
return false;
|
|
@@ -131,29 +144,32 @@ const isNCloudErrorResponse = (input) => {
|
|
|
131
144
|
});
|
|
132
145
|
return isValid ? data : null;
|
|
133
146
|
}
|
|
134
|
-
catch
|
|
147
|
+
catch {
|
|
135
148
|
return null;
|
|
136
149
|
}
|
|
137
150
|
};
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
return obj.map((item) => (0, exports.compact)(item));
|
|
141
|
-
}
|
|
142
|
-
if (typeof obj === "object" && obj !== null) {
|
|
143
|
-
return Object.fromEntries(Object.entries(obj)
|
|
144
|
-
.filter(([_, value]) => value !== undefined) // undefined 필드 제거
|
|
145
|
-
.map(([key, value]) => [key, (0, exports.compact)(value)]) // 내부 값 재귀 처리
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
return obj;
|
|
151
|
+
const isSensErrorCode = (code) => {
|
|
152
|
+
return code in index_js_1.SENS_ERROR_CODE_SPEC;
|
|
149
153
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
|
|
153
|
-
return utcRegex.test(input) ? input : new Date(input.replace(" ", "T") + "+09:00").toISOString();
|
|
154
|
+
const isNCloudErrorCode = (code) => {
|
|
155
|
+
return code in index_js_1.NCLOUD_ERROR_CODE_SPEC;
|
|
154
156
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const handleSensError = (data, httpStatusCode) => {
|
|
158
|
+
return new index_js_1.SensError({
|
|
159
|
+
code: httpStatusCode,
|
|
160
|
+
type: isSensErrorCode(data.status) ? index_js_1.SENS_ERROR_CODE_SPEC[data.status] : "SDK.UNKNOWN_ERROR",
|
|
161
|
+
message: data.errorMessage || "something wrong",
|
|
162
|
+
...(Array.isArray(data?.errors) && {
|
|
163
|
+
errors: data.errors.filter((d) => !!d).map((d) => String(d)),
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const handleNCloudError = (data, httpStatusCode) => {
|
|
168
|
+
const { errorCode, message, details } = data.error;
|
|
169
|
+
throw new index_js_1.SensError({
|
|
170
|
+
code: httpStatusCode,
|
|
171
|
+
type: isNCloudErrorCode(errorCode) ? index_js_1.NCLOUD_ERROR_CODE_SPEC[errorCode].type : "SDK.UNKNOWN_ERROR",
|
|
172
|
+
message: message || "something wrong",
|
|
173
|
+
...(typeof details == "string" && { errors: [details] }),
|
|
174
|
+
});
|
|
159
175
|
};
|
package/dist-es/SensClient.js
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class SensClient {
|
|
1
|
+
import { NodeHttpHandler } from "@ingestkorea/util-http-handler";
|
|
2
|
+
import { SensError, } from "./models/index.js";
|
|
3
|
+
import { middlewareIngestkoreaMetadata, middlewareNcpSign, middlewareRetry } from "./middleware/index.js";
|
|
4
|
+
export class SensClient {
|
|
5
|
+
config;
|
|
6
|
+
httpHandler;
|
|
8
7
|
constructor(config) {
|
|
9
|
-
this.httpHandler = new util_http_handler_1.NodeHttpHandler({ connectionTimeout: 3000, socketTimeout: 3000 });
|
|
10
|
-
this.requestHandler = async (input, context) => this.httpHandler.handle(input.request);
|
|
11
8
|
this.config = {
|
|
12
9
|
credentials: resolveCredentials(config),
|
|
13
10
|
serviceId: resolveServiceId(config),
|
|
11
|
+
httpHandler: {
|
|
12
|
+
connectionTimeout: config.httpHandler?.connectionTimeout ?? 2000,
|
|
13
|
+
socketTimeout: config.httpHandler?.socketTimeout ?? 3000,
|
|
14
|
+
keepAlive: config.httpHandler?.keepAlive ?? false,
|
|
15
|
+
family: 4,
|
|
16
|
+
},
|
|
14
17
|
};
|
|
18
|
+
this.httpHandler = new NodeHttpHandler(this.config.httpHandler);
|
|
15
19
|
}
|
|
16
20
|
async send(command) {
|
|
17
21
|
const { input, serializer, deserializer } = command;
|
|
18
|
-
const middlewares = [
|
|
19
|
-
const
|
|
22
|
+
const middlewares = [middlewareIngestkoreaMetadata, middlewareNcpSign, middlewareRetry];
|
|
23
|
+
const finalHandler = async (input, context) => this.httpHandler.handle(input.request);
|
|
24
|
+
const handler = composeMiddleware(middlewares, finalHandler);
|
|
20
25
|
try {
|
|
21
26
|
const request = await serializer(input, this.config);
|
|
22
27
|
const { response } = await handler({ request }, this.config);
|
|
23
28
|
const output = await deserializer(response, this.config);
|
|
24
29
|
return output;
|
|
25
30
|
}
|
|
26
|
-
catch (
|
|
27
|
-
if (
|
|
28
|
-
throw
|
|
29
|
-
throw new
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof SensError)
|
|
33
|
+
throw error;
|
|
34
|
+
throw new SensError({
|
|
30
35
|
code: -1,
|
|
31
36
|
type: "SDK.UNKNOWN_ERROR",
|
|
32
|
-
message:
|
|
37
|
+
message: error instanceof Error ? error.message : "unknown error",
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
exports.SensClient = SensClient;
|
|
38
42
|
const composeMiddleware = (middlewares, finalHandler) => {
|
|
39
43
|
const handler = middlewares.reduceRight((next, middleware) => {
|
|
40
44
|
return middleware(next);
|
|
@@ -43,7 +47,7 @@ const composeMiddleware = (middlewares, finalHandler) => {
|
|
|
43
47
|
};
|
|
44
48
|
const resolveCredentials = (config) => {
|
|
45
49
|
const { credentials } = config;
|
|
46
|
-
const error = new
|
|
50
|
+
const error = new SensError({
|
|
47
51
|
code: -1,
|
|
48
52
|
type: "SDK.AUTH_ERROR",
|
|
49
53
|
message: "SensClient 초기화시 인증 정보를 입력해주세요.",
|
|
@@ -64,9 +68,8 @@ const resolveCredentials = (config) => {
|
|
|
64
68
|
};
|
|
65
69
|
};
|
|
66
70
|
const resolveServiceId = (config) => {
|
|
67
|
-
var _a, _b;
|
|
68
71
|
const { serviceId } = config;
|
|
69
|
-
const error = new
|
|
72
|
+
const error = new SensError({
|
|
70
73
|
code: -1,
|
|
71
74
|
type: "SDK.GENERAL_ERROR",
|
|
72
75
|
message: "SensClient 초기화시 사용할 서비스 정보를 입력해주세요.",
|
|
@@ -79,7 +82,7 @@ const resolveServiceId = (config) => {
|
|
|
79
82
|
throw error;
|
|
80
83
|
}
|
|
81
84
|
return {
|
|
82
|
-
kakao:
|
|
83
|
-
sms:
|
|
85
|
+
kakao: serviceId.kakao ?? "",
|
|
86
|
+
sms: serviceId.sms ?? "",
|
|
84
87
|
};
|
|
85
88
|
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { SensCommand, } from "../models/index.js";
|
|
2
|
+
import { se_GetAlimtalkResultCommand, de_GetAlimtalkResultCommand } from "../protocols/GetAlimtalkResult.js";
|
|
3
|
+
export class GetAlimtalkResultCommand extends SensCommand {
|
|
4
|
+
input;
|
|
5
|
+
serializer;
|
|
6
|
+
deserializer;
|
|
7
7
|
constructor(input) {
|
|
8
8
|
super(input);
|
|
9
9
|
this.input = {
|
|
10
10
|
messageId: input.messageId,
|
|
11
11
|
};
|
|
12
|
-
this.serializer =
|
|
13
|
-
this.deserializer =
|
|
12
|
+
this.serializer = se_GetAlimtalkResultCommand;
|
|
13
|
+
this.deserializer = de_GetAlimtalkResultCommand;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
exports.GetAlimtalkResultCommand = GetAlimtalkResultCommand;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.GetAlimtalkStatusCommand = void 0;
|
|
4
|
-
const index_js_1 = require("../models/index.js");
|
|
5
|
-
const GetAlimtalkStatus_js_1 = require("../protocols/GetAlimtalkStatus.js");
|
|
1
|
+
import { SensCommand, } from "../models/index.js";
|
|
2
|
+
import { se_GetAlimtalkStatusCommand, de_GetAlimtalkStatusCommand } from "../protocols/GetAlimtalkStatus.js";
|
|
6
3
|
const MAX_LIMIT = 100;
|
|
7
|
-
class GetAlimtalkStatusCommand extends
|
|
4
|
+
export class GetAlimtalkStatusCommand extends SensCommand {
|
|
5
|
+
input;
|
|
6
|
+
serializer;
|
|
7
|
+
deserializer;
|
|
8
8
|
constructor(input) {
|
|
9
9
|
super(input);
|
|
10
10
|
this.input = {
|
|
@@ -12,8 +12,7 @@ class GetAlimtalkStatusCommand extends index_js_1.SensCommand {
|
|
|
12
12
|
pageSize: input.pageSize ? Math.min(MAX_LIMIT, Math.max(1, input.pageSize)) : MAX_LIMIT,
|
|
13
13
|
...(input.nextToken && { nextToken: input.nextToken }),
|
|
14
14
|
};
|
|
15
|
-
this.serializer =
|
|
16
|
-
this.deserializer =
|
|
15
|
+
this.serializer = se_GetAlimtalkStatusCommand;
|
|
16
|
+
this.deserializer = de_GetAlimtalkStatusCommand;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
exports.GetAlimtalkStatusCommand = GetAlimtalkStatusCommand;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { SensCommand, } from "../models/index.js";
|
|
2
|
+
import { se_GetAlimtalkTemplateCommand, de_GetAlimtalkTemplateCommand } from "../protocols/GetAlimtalkTemplate.js";
|
|
3
|
+
export class GetAlimtalkTemplateCommand extends SensCommand {
|
|
4
|
+
input;
|
|
5
|
+
serializer;
|
|
6
|
+
deserializer;
|
|
7
7
|
constructor(input) {
|
|
8
8
|
super(input);
|
|
9
9
|
this.input = {
|
|
10
10
|
channelId: input.channelId,
|
|
11
11
|
templateCode: input.templateCode,
|
|
12
12
|
};
|
|
13
|
-
this.serializer =
|
|
14
|
-
this.deserializer =
|
|
13
|
+
this.serializer = se_GetAlimtalkTemplateCommand;
|
|
14
|
+
this.deserializer = de_GetAlimtalkTemplateCommand;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
exports.GetAlimtalkTemplateCommand = GetAlimtalkTemplateCommand;
|