@ingestkorea/client-naver-commerce 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +160 -0
  3. package/dist-cjs/NaverCommerceClient.js +77 -0
  4. package/dist-cjs/commands/CreateAccessTokenCommand.js +14 -0
  5. package/dist-cjs/commands/GetAccountInfoCommand.js +14 -0
  6. package/dist-cjs/commands/ListChangedOrderStatusesCommand.js +44 -0
  7. package/dist-cjs/commands/index.js +19 -0
  8. package/dist-cjs/index.js +18 -0
  9. package/dist-cjs/middleware/constants.js +9 -0
  10. package/dist-cjs/middleware/index.js +19 -0
  11. package/dist-cjs/middleware/middleware-auth.js +18 -0
  12. package/dist-cjs/middleware/middleware-metadata.js +18 -0
  13. package/dist-cjs/middleware/middleware-retry.js +64 -0
  14. package/dist-cjs/models/CommerceClient.js +2 -0
  15. package/dist-cjs/models/CommerceCommand.js +9 -0
  16. package/dist-cjs/models/CommerceErrorInfo.js +14 -0
  17. package/dist-cjs/models/CommerceMiddleware.js +2 -0
  18. package/dist-cjs/models/CreateAccessToken.js +2 -0
  19. package/dist-cjs/models/GetAccountInfo.js +2 -0
  20. package/dist-cjs/models/ListChangedOrderStatuses.js +36 -0
  21. package/dist-cjs/models/MetadataBearer.js +2 -0
  22. package/dist-cjs/models/index.js +24 -0
  23. package/dist-cjs/protocols/CreateAccessToken.js +61 -0
  24. package/dist-cjs/protocols/GetAccountInfo.js +47 -0
  25. package/dist-cjs/protocols/ListChangedOrderStatuses.js +81 -0
  26. package/dist-cjs/protocols/constants.js +116 -0
  27. package/dist-es/NaverCommerceClient.js +66 -0
  28. package/dist-es/commands/CreateAccessTokenCommand.js +14 -0
  29. package/dist-es/commands/GetAccountInfoCommand.js +14 -0
  30. package/dist-es/commands/ListChangedOrderStatusesCommand.js +49 -0
  31. package/dist-es/commands/index.js +19 -0
  32. package/dist-es/index.js +18 -0
  33. package/dist-es/middleware/constants.js +9 -0
  34. package/dist-es/middleware/index.js +19 -0
  35. package/dist-es/middleware/middleware-auth.js +12 -0
  36. package/dist-es/middleware/middleware-metadata.js +12 -0
  37. package/dist-es/middleware/middleware-retry.js +61 -0
  38. package/dist-es/models/CommerceClient.js +2 -0
  39. package/dist-es/models/CommerceCommand.js +9 -0
  40. package/dist-es/models/CommerceErrorInfo.js +14 -0
  41. package/dist-es/models/CommerceMiddleware.js +2 -0
  42. package/dist-es/models/CreateAccessToken.js +2 -0
  43. package/dist-es/models/GetAccountInfo.js +2 -0
  44. package/dist-es/models/ListChangedOrderStatuses.js +36 -0
  45. package/dist-es/models/MetadataBearer.js +2 -0
  46. package/dist-es/models/index.js +24 -0
  47. package/dist-es/protocols/CreateAccessToken.js +55 -0
  48. package/dist-es/protocols/GetAccountInfo.js +41 -0
  49. package/dist-es/protocols/ListChangedOrderStatuses.js +79 -0
  50. package/dist-es/protocols/constants.js +113 -0
  51. package/dist-types/NaverCommerceClient.d.ts +8 -0
  52. package/dist-types/commands/CreateAccessTokenCommand.d.ts +11 -0
  53. package/dist-types/commands/GetAccountInfoCommand.d.ts +11 -0
  54. package/dist-types/commands/ListChangedOrderStatusesCommand.d.ts +11 -0
  55. package/dist-types/commands/index.d.ts +3 -0
  56. package/dist-types/index.d.ts +2 -0
  57. package/dist-types/middleware/constants.d.ts +6 -0
  58. package/dist-types/middleware/index.d.ts +3 -0
  59. package/dist-types/middleware/middleware-auth.d.ts +2 -0
  60. package/dist-types/middleware/middleware-metadata.d.ts +2 -0
  61. package/dist-types/middleware/middleware-retry.d.ts +2 -0
  62. package/dist-types/models/CommerceClient.d.ts +13 -0
  63. package/dist-types/models/CommerceCommand.d.ts +9 -0
  64. package/dist-types/models/CommerceErrorInfo.d.ts +19 -0
  65. package/dist-types/models/CommerceMiddleware.d.ts +8 -0
  66. package/dist-types/models/CreateAccessToken.d.ts +7 -0
  67. package/dist-types/models/GetAccountInfo.d.ts +7 -0
  68. package/dist-types/models/ListChangedOrderStatuses.d.ts +68 -0
  69. package/dist-types/models/MetadataBearer.d.ts +10 -0
  70. package/dist-types/models/index.d.ts +8 -0
  71. package/dist-types/protocols/CreateAccessToken.d.ts +4 -0
  72. package/dist-types/protocols/GetAccountInfo.d.ts +4 -0
  73. package/dist-types/protocols/ListChangedOrderStatuses.d.ts +4 -0
  74. package/dist-types/protocols/constants.d.ts +5 -0
  75. package/package.json +56 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.de_CreateAccessTokenCommand = exports.se_CreateAccessTokenCommand = void 0;
13
+ const bcrypt_1 = require("bcrypt");
14
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
15
+ const constants_js_1 = require("./constants.js");
16
+ const se_CreateAccessTokenCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const hostname = "api.commerce.naver.com";
18
+ const path = "/external/v1/oauth2/token";
19
+ const headers = {
20
+ host: hostname,
21
+ accept: "application/json",
22
+ "content-type": "application/x-www-form-urlencoded",
23
+ };
24
+ const timestamp = new Date().getTime().toString();
25
+ const password = `${config.credentials.appId}_${timestamp}`;
26
+ const hashed = (0, bcrypt_1.hashSync)(password, config.credentials.appSecret);
27
+ const signature = Buffer.from(hashed, "utf-8").toString("base64");
28
+ const body = (0, util_http_handler_1.buildQueryString)({
29
+ type: "SELF",
30
+ timestamp,
31
+ client_id: config.credentials.appId,
32
+ client_secret_sign: signature,
33
+ grant_type: "client_credentials",
34
+ });
35
+ return new util_http_handler_1.HttpRequest({
36
+ protocol: "https:",
37
+ method: "POST",
38
+ hostname: hostname,
39
+ path: path,
40
+ headers: headers,
41
+ body: body,
42
+ });
43
+ });
44
+ exports.se_CreateAccessTokenCommand = se_CreateAccessTokenCommand;
45
+ const de_CreateAccessTokenCommand = (response, config) => __awaiter(void 0, void 0, void 0, function* () {
46
+ if (response.statusCode >= 300)
47
+ yield (0, constants_js_1.parseErrorBody)(response);
48
+ let data = yield (0, constants_js_1.parseBody)(response);
49
+ let contents = {};
50
+ contents = de_CreateAccessTokenResult(data);
51
+ return Object.assign({ $metadata: (0, constants_js_1.deserializeMetadata)(response) }, contents);
52
+ });
53
+ exports.de_CreateAccessTokenCommand = de_CreateAccessTokenCommand;
54
+ const de_CreateAccessTokenResult = (output) => {
55
+ var _a, _b, _c;
56
+ return {
57
+ access_token: (_a = output.access_token) !== null && _a !== void 0 ? _a : "",
58
+ expires_in: (_b = Number(output.expires_in)) !== null && _b !== void 0 ? _b : 0,
59
+ token_type: (_c = output.token_type) !== null && _c !== void 0 ? _c : "",
60
+ };
61
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.de_GetAccountInfoCommand = exports.se_GetAccountInfoCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_js_1 = require("./constants.js");
15
+ const se_GetAccountInfoCommand = (input, coifng) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const hostname = "api.commerce.naver.com";
17
+ const path = "/external/v1/seller/account";
18
+ const headers = {
19
+ host: hostname,
20
+ accept: "application/json",
21
+ };
22
+ return new util_http_handler_1.HttpRequest({
23
+ protocol: "https:",
24
+ method: "GET",
25
+ hostname: hostname,
26
+ path: path,
27
+ headers: headers,
28
+ });
29
+ });
30
+ exports.se_GetAccountInfoCommand = se_GetAccountInfoCommand;
31
+ const de_GetAccountInfoCommand = (response, config) => __awaiter(void 0, void 0, void 0, function* () {
32
+ if (response.statusCode >= 300)
33
+ yield (0, constants_js_1.parseErrorBody)(response);
34
+ let data = yield (0, constants_js_1.parseBody)(response);
35
+ let contents = {};
36
+ contents = de_GetAccountInfoResult(data);
37
+ return Object.assign({ $metadata: (0, constants_js_1.deserializeMetadata)(response) }, contents);
38
+ });
39
+ exports.de_GetAccountInfoCommand = de_GetAccountInfoCommand;
40
+ const de_GetAccountInfoResult = (output) => {
41
+ var _a, _b, _c;
42
+ return {
43
+ accountId: (_a = output.accountId) !== null && _a !== void 0 ? _a : "",
44
+ accountUid: (_b = output.accountUid) !== null && _b !== void 0 ? _b : "",
45
+ grade: (_c = output.grade) !== null && _c !== void 0 ? _c : "",
46
+ };
47
+ };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.de_ListChangedOrderStatusesCommand = exports.se_ListChangedOrderStatusesCommand = void 0;
13
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
14
+ const constants_js_1 = require("./constants.js");
15
+ const se_ListChangedOrderStatusesCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const hostname = "api.commerce.naver.com";
17
+ const path = "/external/v1/pay-order/seller/product-orders/last-changed-statuses";
18
+ const headers = {
19
+ host: hostname,
20
+ accept: "application/json",
21
+ };
22
+ const query = Object.entries(input).reduce((acc, [key, value]) => {
23
+ if (value !== undefined && value !== null) {
24
+ acc[key] = String(value); // 숫자(limitCount)나 Enum도 여기서 문자열이 됨
25
+ }
26
+ return acc;
27
+ }, {});
28
+ return new util_http_handler_1.HttpRequest({
29
+ protocol: "https:",
30
+ method: "GET",
31
+ hostname,
32
+ path,
33
+ headers,
34
+ query,
35
+ });
36
+ });
37
+ exports.se_ListChangedOrderStatusesCommand = se_ListChangedOrderStatusesCommand;
38
+ const de_ListChangedOrderStatusesCommand = (response, config) => __awaiter(void 0, void 0, void 0, function* () {
39
+ if (response.statusCode >= 300)
40
+ yield (0, constants_js_1.parseErrorBody)(response);
41
+ const data = yield (0, constants_js_1.parseBody)(response);
42
+ const contents = de_ListChangedOrderStatusesResult(data);
43
+ return Object.assign({ $metadata: (0, constants_js_1.deserializeMetadata)(response) }, contents);
44
+ });
45
+ exports.de_ListChangedOrderStatusesCommand = de_ListChangedOrderStatusesCommand;
46
+ const de_ListChangedOrderStatusesResult = (output) => {
47
+ var _a, _b, _c, _d, _e;
48
+ return {
49
+ timestamp: new Date((_a = output.timestamp) !== null && _a !== void 0 ? _a : new Date().getTime()).toISOString(),
50
+ traceId: (_b = output.traceId) !== null && _b !== void 0 ? _b : "",
51
+ data: Object.assign({ count: (_d = (_c = output.data) === null || _c === void 0 ? void 0 : _c.count) !== null && _d !== void 0 ? _d : 0, lastChangeStatuses: ((_e = output.data) === null || _e === void 0 ? void 0 : _e.lastChangedStatuses)
52
+ ? de_ChangedOrderStatusList(output.data.lastChangedStatuses)
53
+ : [] }, (output.more && { more: de_More(output.more) })),
54
+ };
55
+ };
56
+ const de_ChangedOrderStatusList = (output) => {
57
+ const result = (output || []).filter((e) => e != null).map((entry) => de_ChangedOrderStatus(entry));
58
+ return result;
59
+ };
60
+ const de_ChangedOrderStatus = (output) => {
61
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
62
+ return {
63
+ orderId: (_a = output.orderId) !== null && _a !== void 0 ? _a : "",
64
+ lastChangedDate: output.lastChangedDate ? new Date(output.lastChangedDate).toISOString() : "",
65
+ lastChangedType: (_b = output.lastChangedType) !== null && _b !== void 0 ? _b : "",
66
+ productOrderId: (_c = output.productOrderId) !== null && _c !== void 0 ? _c : "",
67
+ productOrderStatus: (_d = output.productOrderStatus) !== null && _d !== void 0 ? _d : "",
68
+ receiverAddressChanged: (_e = output.receiverAddressChanged) !== null && _e !== void 0 ? _e : false,
69
+ paymentDate: (_f = output.paymentDate) !== null && _f !== void 0 ? _f : "",
70
+ claimType: (_g = output.claimType) !== null && _g !== void 0 ? _g : "",
71
+ claimStatus: (_h = output.claimStatus) !== null && _h !== void 0 ? _h : "",
72
+ giftReceivingStatus: (_j = output.giftReceivingStatus) !== null && _j !== void 0 ? _j : "",
73
+ };
74
+ };
75
+ const de_More = (output) => {
76
+ var _a;
77
+ return {
78
+ moreFrom: output.moreFrom ? new Date(output.moreFrom).toISOString() : "",
79
+ moreSequence: (_a = output.moreSequence) !== null && _a !== void 0 ? _a : "",
80
+ };
81
+ };
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.parseErrorBody = exports.parseBody = exports.deserializeMetadata = void 0;
13
+ const util_error_handler_1 = require("@ingestkorea/util-error-handler");
14
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
15
+ const index_js_1 = require("../models/index.js");
16
+ const constants_js_1 = require("../middleware/constants.js");
17
+ const deserializeMetadata = (response) => {
18
+ const attempts = response.headers[constants_js_1.INGESTKOREA_RETRY] || undefined;
19
+ const totalRetryDelay = response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] || undefined;
20
+ const traceId = response.headers[constants_js_1.NAVER_COMMERCE_TRACE_ID] || undefined;
21
+ const rateLimit = response.headers[constants_js_1.NAVER_COMMERCE_RATE_LIMIT] || undefined;
22
+ return Object.assign(Object.assign(Object.assign(Object.assign({ httpStatusCode: response.statusCode }, (attempts && { attempts: Number(attempts) })), (totalRetryDelay && { totalRetryDelay: Number(totalRetryDelay) })), (traceId && { traceId })), (rateLimit && { rateLimit: Number(rateLimit) }));
23
+ };
24
+ exports.deserializeMetadata = deserializeMetadata;
25
+ const parseBody = (output) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const { statusCode, headers, body: streamBody } = output;
27
+ if (!isJsonResponse(headers["content-type"])) {
28
+ yield (0, util_http_handler_1.destroyStream)(streamBody);
29
+ throw new util_error_handler_1.IngestkoreaError({
30
+ code: (0, util_error_handler_1.ingestkoreaErrorCodeChecker)(statusCode) ? statusCode : 400,
31
+ type: "Bad Request",
32
+ message: "Invalid Request",
33
+ description: "response content-type is not application/json",
34
+ });
35
+ }
36
+ const data = yield (0, util_http_handler_1.collectBodyString)(streamBody);
37
+ if (data.length) {
38
+ try {
39
+ return JSON.parse(data);
40
+ }
41
+ catch (e) {
42
+ yield (0, util_http_handler_1.destroyStream)(streamBody);
43
+ throw new util_error_handler_1.IngestkoreaError({
44
+ code: 500,
45
+ type: "Bad Request",
46
+ message: "Invalid Request",
47
+ description: "parse response body error",
48
+ });
49
+ }
50
+ }
51
+ return {};
52
+ });
53
+ exports.parseBody = parseBody;
54
+ const parseErrorBody = (output) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const { statusCode, headers, body: streamBody } = output;
56
+ if (!isJsonResponse(headers["content-type"])) {
57
+ yield (0, util_http_handler_1.destroyStream)(streamBody);
58
+ throw new util_error_handler_1.IngestkoreaError({
59
+ code: (0, util_error_handler_1.ingestkoreaErrorCodeChecker)(statusCode) ? statusCode : 400,
60
+ type: "Bad Request",
61
+ message: "Invalid Request",
62
+ description: "response content-type is not application/json",
63
+ });
64
+ }
65
+ const data = yield (0, util_http_handler_1.collectBodyString)(streamBody);
66
+ yield (0, util_http_handler_1.destroyStream)(streamBody);
67
+ const commerceError = isCommerceErrorInfo(data);
68
+ if (commerceError) {
69
+ throw new index_js_1.NaverCommerceError(commerceError);
70
+ }
71
+ throw new util_error_handler_1.IngestkoreaError({
72
+ code: (0, util_error_handler_1.ingestkoreaErrorCodeChecker)(statusCode) ? statusCode : 400,
73
+ type: "Bad Request",
74
+ message: "Invalid Request",
75
+ description: "something wrong",
76
+ });
77
+ });
78
+ exports.parseErrorBody = parseErrorBody;
79
+ const commerceErrorInfoSpec = [
80
+ ["code", "string"],
81
+ ["message", "string"],
82
+ ["timestamp", "string"],
83
+ ];
84
+ const isJsonResponse = (contentType) => {
85
+ return /application\/json/gi.exec(contentType || "") ? true : false;
86
+ };
87
+ const isCommerceErrorInfo = (input) => {
88
+ if (input === undefined || input === null || typeof input !== "string")
89
+ return null;
90
+ try {
91
+ const obj = JSON.parse(input);
92
+ for (const [key, expectedType] of commerceErrorInfoSpec) {
93
+ if (!(key in obj) || typeof obj[key] !== expectedType) {
94
+ return null;
95
+ }
96
+ }
97
+ const result = {
98
+ code: obj.code,
99
+ message: obj.message,
100
+ timestamp: obj.timestamp,
101
+ };
102
+ if (typeof obj.traceId === "string") {
103
+ result.traceId = obj.traceId;
104
+ }
105
+ if (Array.isArray(obj.invalidInputs)) {
106
+ const isValidArray = obj.invalidInputs.every((item) => typeof (item === null || item === void 0 ? void 0 : item.name) === "string" && typeof (item === null || item === void 0 ? void 0 : item.type) === "string" && typeof (item === null || item === void 0 ? void 0 : item.message) === "string");
107
+ if (isValidArray) {
108
+ result.invalidInputs = obj.invalidInputs;
109
+ }
110
+ }
111
+ return result;
112
+ }
113
+ catch (_a) {
114
+ return null;
115
+ }
116
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NaverCommerceClient = void 0;
4
+ const util_http_handler_1 = require("@ingestkorea/util-http-handler");
5
+ const index_js_1 = require("./models/index.js");
6
+ const index_js_2 = require("./middleware/index.js");
7
+ class NaverCommerceClient {
8
+ 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
+ this.config = {
12
+ credentials: resolveCredentials(config),
13
+ };
14
+ }
15
+ async send(command) {
16
+ const { input, serializer, deserializer } = command;
17
+ const middlewares = [index_js_2.middlewareAuth, index_js_2.middlewareIngestkoreaMetadata, index_js_2.middlewareRetry];
18
+ const handler = composeMiddleware(middlewares, this.requestHandler);
19
+ try {
20
+ const request = await serializer(input, this.config);
21
+ const { response } = await handler({ request }, this.config);
22
+ const output = await deserializer(response, this.config);
23
+ return output;
24
+ }
25
+ catch (e) {
26
+ throw e;
27
+ }
28
+ }
29
+ }
30
+ exports.NaverCommerceClient = NaverCommerceClient;
31
+ const composeMiddleware = (middlewares, finalHandler) => {
32
+ const handler = middlewares.reduceRight((next, middleware) => {
33
+ return middleware(next);
34
+ }, finalHandler);
35
+ return handler;
36
+ };
37
+ const resolveCredentials = (config) => {
38
+ const { credentials } = config;
39
+ let error = new index_js_1.NaverCommerceError({
40
+ code: "GENERAL_ERROR",
41
+ message: "자격 증명이 유효하지 않습니다.",
42
+ timestamp: new Date().toISOString(),
43
+ invalidInputs: [
44
+ {
45
+ name: "credentials",
46
+ type: "not-valid.args",
47
+ message: "NaverCommerceClient 초기화시 인증 정보를 확인해주세요.",
48
+ },
49
+ ],
50
+ });
51
+ if (!credentials)
52
+ throw error;
53
+ if (!credentials.appId) {
54
+ error.invalidInputs[0].message = "Application ID 정보를 확인해주세요.";
55
+ throw error;
56
+ }
57
+ if (!credentials.appSecret) {
58
+ error.invalidInputs[0].message = "Application Secret 정보를 확인해주세요.";
59
+ throw error;
60
+ }
61
+ return {
62
+ appId: credentials.appId,
63
+ appSecret: credentials.appSecret,
64
+ accessToken: credentials.accessToken || "",
65
+ };
66
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateAccessTokenCommand = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const CreateAccessToken_js_1 = require("../protocols/CreateAccessToken.js");
6
+ class CreateAccessTokenCommand extends index_js_1.CommerceCommand {
7
+ constructor(input) {
8
+ super(input);
9
+ this.input = {};
10
+ this.serializer = CreateAccessToken_js_1.se_CreateAccessTokenCommand;
11
+ this.deserializer = CreateAccessToken_js_1.de_CreateAccessTokenCommand;
12
+ }
13
+ }
14
+ exports.CreateAccessTokenCommand = CreateAccessTokenCommand;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetAccountInfoCommand = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const GetAccountInfo_js_1 = require("../protocols/GetAccountInfo.js");
6
+ class GetAccountInfoCommand extends index_js_1.CommerceCommand {
7
+ constructor(input) {
8
+ super(input);
9
+ this.input = {};
10
+ this.serializer = GetAccountInfo_js_1.se_GetAccountInfoCommand;
11
+ this.deserializer = GetAccountInfo_js_1.de_GetAccountInfoCommand;
12
+ }
13
+ }
14
+ exports.GetAccountInfoCommand = GetAccountInfoCommand;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListChangedOrderStatusesCommand = void 0;
4
+ const index_js_1 = require("../models/index.js");
5
+ const ListChangedOrderStatuses_js_1 = require("../protocols/ListChangedOrderStatuses.js");
6
+ const LAST_CHANGED_TYPE_SET = new Set(Object.values(index_js_1.LAST_CHANGED_TYPE));
7
+ const DEFAULT_LIMIT = 10;
8
+ const MAX_LIMIT = 300;
9
+ class ListChangedOrderStatusesCommand extends index_js_1.CommerceCommand {
10
+ constructor(input) {
11
+ var _a;
12
+ super(input);
13
+ const now = new Date();
14
+ const lastChangedFrom = isUtcTimeFormat(input.lastChangedFrom) ? input.lastChangedFrom : null;
15
+ if (!lastChangedFrom) {
16
+ throw new index_js_1.NaverCommerceError({
17
+ code: "GENERAL_ERROR",
18
+ message: "lastChangedFrom must be UTC format (ISO 8601). 2026-01-01T12:34:56.789Z",
19
+ timestamp: now.toISOString(),
20
+ });
21
+ }
22
+ const lastChangedTo = isUtcTimeFormat(input.lastChangedTo) ? input.lastChangedTo : now.toISOString();
23
+ const lastChangedType = isLastChangedType(input.lastChangedType) ? input.lastChangedType : null;
24
+ this.input = {
25
+ lastChangedFrom,
26
+ lastChangedTo,
27
+ ...(lastChangedType && { lastChangedType }),
28
+ ...(input.moreSequence && { moreSequence: input.moreSequence }),
29
+ limitCount: Math.min(MAX_LIMIT, Math.max(1, (_a = input.limitCount) !== null && _a !== void 0 ? _a : DEFAULT_LIMIT)),
30
+ };
31
+ this.serializer = ListChangedOrderStatuses_js_1.se_ListChangedOrderStatusesCommand;
32
+ this.deserializer = ListChangedOrderStatuses_js_1.de_ListChangedOrderStatusesCommand;
33
+ }
34
+ }
35
+ exports.ListChangedOrderStatusesCommand = ListChangedOrderStatusesCommand;
36
+ const isUtcTimeFormat = (input) => {
37
+ if (!input || typeof input !== "string")
38
+ return false;
39
+ const utcZRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
40
+ if (!utcZRegex.test(input))
41
+ return false;
42
+ const date = new Date(input);
43
+ return !isNaN(date.getTime());
44
+ };
45
+ const isLastChangedType = (input) => {
46
+ if (!input || typeof input !== "string")
47
+ return false;
48
+ return LAST_CHANGED_TYPE_SET.has(input);
49
+ };
@@ -0,0 +1,19 @@
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("./CreateAccessTokenCommand.js"), exports);
18
+ __exportStar(require("./GetAccountInfoCommand.js"), exports);
19
+ __exportStar(require("./ListChangedOrderStatusesCommand.js"), exports);
@@ -0,0 +1,18 @@
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("./NaverCommerceClient.js"), exports);
18
+ __exportStar(require("./commands/index.js"), exports);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NAVER_COMMERCE_RATE_LIMIT = exports.NAVER_COMMERCE_TRACE_ID = 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.NAVER_COMMERCE_TRACE_ID = "gncp-gw-trace-id";
9
+ exports.NAVER_COMMERCE_RATE_LIMIT = "gncp-gw-ratelimit-remaining";
@@ -0,0 +1,19 @@
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-auth.js"), exports);
18
+ __exportStar(require("./middleware-metadata.js"), exports);
19
+ __exportStar(require("./middleware-retry.js"), exports);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.middlewareAuth = void 0;
4
+ const middlewareAuth = (next) => async (input, context) => {
5
+ const { credentials } = context;
6
+ input.request.headers = {
7
+ ...input.request.headers,
8
+ ...(credentials.accessToken && { authorization: "Bearer " + credentials.accessToken }),
9
+ };
10
+ return next(input, context);
11
+ };
12
+ exports.middlewareAuth = middlewareAuth;
@@ -0,0 +1,12 @@
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-naver-commerce/0.3.x",
9
+ };
10
+ return next(input, context);
11
+ };
12
+ exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
@@ -0,0 +1,61 @@
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;
12
+ let attempts = 0;
13
+ let totalRetryDelay = 0;
14
+ (_a = (_c = input.request).headers) !== null && _a !== void 0 ? _a : (_c.headers = {});
15
+ let lastError = new util_error_handler_1.IngestkoreaError({
16
+ code: 400,
17
+ type: "Bad Request",
18
+ message: "Invalid Request",
19
+ description: { attempts, maxRetries: MAX_RETRIES, totalRetryDelay },
20
+ });
21
+ while (attempts < MAX_RETRIES) {
22
+ const attemptNo = attempts + 1;
23
+ // 요청에 현재 상태 로깅
24
+ const requestLog = `attempt=${attemptNo}; max=${MAX_RETRIES}; totalRetryDelay=${totalRetryDelay}`;
25
+ input.request.headers[constants_js_1.INGESTKOREA_REQUEST_LOG] = requestLog;
26
+ try {
27
+ const { response } = await next(input, context);
28
+ response.headers[constants_js_1.INGESTKOREA_RETRY] = attemptNo.toString();
29
+ response.headers[constants_js_1.INGESTKOREA_RETRY_DELAY] = totalRetryDelay.toString();
30
+ return { response };
31
+ }
32
+ catch (error) {
33
+ attempts++;
34
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
35
+ if (error instanceof util_error_handler_1.IngestkoreaError) {
36
+ lastError.error.description = {
37
+ ...lastError.error.description,
38
+ detail: error.error.description,
39
+ };
40
+ }
41
+ else {
42
+ lastError.error.description = {
43
+ ...lastError.error.description,
44
+ detail: String((_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error),
45
+ };
46
+ }
47
+ if (attempts >= MAX_RETRIES) {
48
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
49
+ throw lastError;
50
+ }
51
+ const exp = BASE_DELAY_MS * 2 ** (attempts - 1);
52
+ const capped = Math.min(MAX_DELAY_MS, exp);
53
+ const delay = Math.floor(Math.random() * capped);
54
+ totalRetryDelay += delay;
55
+ lastError.error.description = { attempts, maxRetries: MAX_RETRIES, totalRetryDelay };
56
+ await new Promise((resolve) => setTimeout(resolve, delay));
57
+ }
58
+ }
59
+ throw lastError;
60
+ };
61
+ exports.middlewareRetry = middlewareRetry;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommerceCommand = void 0;
4
+ class CommerceCommand {
5
+ constructor(input) {
6
+ this.input = input;
7
+ }
8
+ }
9
+ exports.CommerceCommand = CommerceCommand;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NaverCommerceError = void 0;
4
+ class NaverCommerceError extends Error {
5
+ constructor(info) {
6
+ super(info.message);
7
+ this.name = "NaverCommerceError";
8
+ this.code = info.code;
9
+ this.timestamp = new Date(info.timestamp).toISOString();
10
+ this.traceId = info.traceId || "local";
11
+ this.invalidInputs = info.invalidInputs || [];
12
+ }
13
+ }
14
+ exports.NaverCommerceError = NaverCommerceError;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });