@hubcommerce/n11 1.0.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/CHANGELOG.md +48 -0
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/categories/api.d.ts +12 -0
- package/dist/categories/api.d.ts.map +1 -0
- package/dist/categories/api.js +34 -0
- package/dist/client.d.ts +37 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +70 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +58 -0
- package/dist/connection.d.ts +5 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +4 -0
- package/dist/constants/defaults.d.ts +16 -0
- package/dist/constants/defaults.d.ts.map +1 -0
- package/dist/constants/defaults.js +15 -0
- package/dist/constants/hosts.d.ts +9 -0
- package/dist/constants/hosts.d.ts.map +1 -0
- package/dist/constants/hosts.js +25 -0
- package/dist/constants/page-limits.d.ts +15 -0
- package/dist/constants/page-limits.d.ts.map +1 -0
- package/dist/constants/page-limits.js +14 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +162 -0
- package/dist/http/query.d.ts +2 -0
- package/dist/http/query.d.ts.map +1 -0
- package/dist/http/query.js +10 -0
- package/dist/http/response.d.ts +12 -0
- package/dist/http/response.d.ts.map +1 -0
- package/dist/http/response.js +43 -0
- package/dist/http/security.d.ts +6 -0
- package/dist/http/security.d.ts.map +1 -0
- package/dist/http/security.js +29 -0
- package/dist/http/signals.d.ts +5 -0
- package/dist/http/signals.d.ts.map +1 -0
- package/dist/http/signals.js +26 -0
- package/dist/http.d.ts +12 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +143 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/invoice/api.d.ts +14 -0
- package/dist/invoice/api.d.ts.map +1 -0
- package/dist/invoice/api.js +12 -0
- package/dist/invoice/parse.d.ts +3 -0
- package/dist/invoice/parse.d.ts.map +1 -0
- package/dist/invoice/parse.js +12 -0
- package/dist/invoice/send-link.d.ts +9 -0
- package/dist/invoice/send-link.d.ts.map +1 -0
- package/dist/invoice/send-link.js +16 -0
- package/dist/invoice/soap-body.d.ts +6 -0
- package/dist/invoice/soap-body.d.ts.map +1 -0
- package/dist/invoice/soap-body.js +23 -0
- package/dist/invoice/validate.d.ts +7 -0
- package/dist/invoice/validate.d.ts.map +1 -0
- package/dist/invoice/validate.js +73 -0
- package/dist/logger.d.ts +20 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +61 -0
- package/dist/orders/api.d.ts +22 -0
- package/dist/orders/api.d.ts.map +1 -0
- package/dist/orders/api.js +40 -0
- package/dist/orders/date.d.ts +12 -0
- package/dist/orders/date.d.ts.map +1 -0
- package/dist/orders/date.js +21 -0
- package/dist/orders/labor-cost.d.ts +9 -0
- package/dist/orders/labor-cost.d.ts.map +1 -0
- package/dist/orders/labor-cost.js +23 -0
- package/dist/orders/list.d.ts +23 -0
- package/dist/orders/list.d.ts.map +1 -0
- package/dist/orders/list.js +76 -0
- package/dist/orders/paths.d.ts +7 -0
- package/dist/orders/paths.d.ts.map +1 -0
- package/dist/orders/paths.js +6 -0
- package/dist/orders/reconciler.d.ts +30 -0
- package/dist/orders/reconciler.d.ts.map +1 -0
- package/dist/orders/reconciler.js +38 -0
- package/dist/orders/shipping.d.ts +11 -0
- package/dist/orders/shipping.d.ts.map +1 -0
- package/dist/orders/shipping.js +57 -0
- package/dist/orders/update.d.ts +15 -0
- package/dist/orders/update.d.ts.map +1 -0
- package/dist/orders/update.js +25 -0
- package/dist/products/api.d.ts +21 -0
- package/dist/products/api.d.ts.map +1 -0
- package/dist/products/api.js +35 -0
- package/dist/products/builder.d.ts +18 -0
- package/dist/products/builder.d.ts.map +1 -0
- package/dist/products/builder.js +138 -0
- package/dist/products/paths.d.ts +6 -0
- package/dist/products/paths.d.ts.map +1 -0
- package/dist/products/paths.js +5 -0
- package/dist/products/query.d.ts +9 -0
- package/dist/products/query.d.ts.map +1 -0
- package/dist/products/query.js +49 -0
- package/dist/products/tasks.d.ts +12 -0
- package/dist/products/tasks.d.ts.map +1 -0
- package/dist/products/tasks.js +49 -0
- package/dist/qna/answer.d.ts +10 -0
- package/dist/qna/answer.d.ts.map +1 -0
- package/dist/qna/answer.js +23 -0
- package/dist/qna/api.d.ts +17 -0
- package/dist/qna/api.d.ts.map +1 -0
- package/dist/qna/api.js +20 -0
- package/dist/qna/detail.d.ts +9 -0
- package/dist/qna/detail.d.ts.map +1 -0
- package/dist/qna/detail.js +18 -0
- package/dist/qna/list.d.ts +9 -0
- package/dist/qna/list.d.ts.map +1 -0
- package/dist/qna/list.js +16 -0
- package/dist/qna/parse.d.ts +6 -0
- package/dist/qna/parse.d.ts.map +1 -0
- package/dist/qna/parse.js +65 -0
- package/dist/qna/soap-body.d.ts +14 -0
- package/dist/qna/soap-body.d.ts.map +1 -0
- package/dist/qna/soap-body.js +48 -0
- package/dist/qna/validate.d.ts +7 -0
- package/dist/qna/validate.d.ts.map +1 -0
- package/dist/qna/validate.js +75 -0
- package/dist/rate-limit/governor.d.ts +8 -0
- package/dist/rate-limit/governor.d.ts.map +1 -0
- package/dist/rate-limit/governor.js +30 -0
- package/dist/rate-limit/groups.d.ts +34 -0
- package/dist/rate-limit/groups.d.ts.map +1 -0
- package/dist/rate-limit/groups.js +32 -0
- package/dist/retry.d.ts +5 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +22 -0
- package/dist/returns/api.d.ts +21 -0
- package/dist/returns/api.d.ts.map +1 -0
- package/dist/returns/api.js +36 -0
- package/dist/returns/call.d.ts +2 -0
- package/dist/returns/call.d.ts.map +1 -0
- package/dist/returns/call.js +1 -0
- package/dist/returns/cancel-partial.d.ts +9 -0
- package/dist/returns/cancel-partial.d.ts.map +1 -0
- package/dist/returns/cancel-partial.js +18 -0
- package/dist/returns/list.d.ts +9 -0
- package/dist/returns/list.d.ts.map +1 -0
- package/dist/returns/list.js +16 -0
- package/dist/returns/mutations.d.ts +11 -0
- package/dist/returns/mutations.d.ts.map +1 -0
- package/dist/returns/mutations.js +22 -0
- package/dist/returns/parse.d.ts +6 -0
- package/dist/returns/parse.d.ts.map +1 -0
- package/dist/returns/parse.js +89 -0
- package/dist/returns/reasons.d.ts +11 -0
- package/dist/returns/reasons.d.ts.map +1 -0
- package/dist/returns/reasons.js +20 -0
- package/dist/returns/soap-body.d.ts +26 -0
- package/dist/returns/soap-body.d.ts.map +1 -0
- package/dist/returns/soap-body.js +95 -0
- package/dist/soap/call.d.ts +8 -0
- package/dist/soap/call.d.ts.map +1 -0
- package/dist/soap/call.js +22 -0
- package/dist/soap/client.d.ts +13 -0
- package/dist/soap/client.d.ts.map +1 -0
- package/dist/soap/client.js +125 -0
- package/dist/soap/envelope.d.ts +10 -0
- package/dist/soap/envelope.d.ts.map +1 -0
- package/dist/soap/envelope.js +47 -0
- package/dist/soap/operations.d.ts +6 -0
- package/dist/soap/operations.d.ts.map +1 -0
- package/dist/soap/operations.js +91 -0
- package/dist/soap/parse.d.ts +17 -0
- package/dist/soap/parse.d.ts.map +1 -0
- package/dist/soap/parse.js +37 -0
- package/dist/tasks/api.d.ts +11 -0
- package/dist/tasks/api.d.ts.map +1 -0
- package/dist/tasks/api.js +44 -0
- package/dist/tasks/module.d.ts +14 -0
- package/dist/tasks/module.d.ts.map +1 -0
- package/dist/tasks/module.js +15 -0
- package/dist/tasks/poller.d.ts +12 -0
- package/dist/tasks/poller.d.ts.map +1 -0
- package/dist/tasks/poller.js +133 -0
- package/dist/tasks/types.d.ts +27 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/types.js +2 -0
- package/dist/testing/fixtures/category-leaf.json +11 -0
- package/dist/testing/fixtures/order-package.json +12 -0
- package/dist/testing/fixtures/task-partial-fail.json +18 -0
- package/dist/testing/fixtures.d.ts +76 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +85 -0
- package/dist/testing/guard.d.ts +21 -0
- package/dist/testing/guard.d.ts.map +1 -0
- package/dist/testing/guard.js +50 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/mock-client.d.ts +49 -0
- package/dist/testing/mock-client.d.ts.map +1 -0
- package/dist/testing/mock-client.js +100 -0
- package/dist/types/invoice.d.ts +21 -0
- package/dist/types/invoice.d.ts.map +1 -0
- package/dist/types/invoice.js +1 -0
- package/dist/types/orders.d.ts +127 -0
- package/dist/types/orders.d.ts.map +1 -0
- package/dist/types/orders.js +1 -0
- package/dist/types/products.d.ts +146 -0
- package/dist/types/products.d.ts.map +1 -0
- package/dist/types/products.js +1 -0
- package/dist/types/qna.d.ts +61 -0
- package/dist/types/qna.d.ts.map +1 -0
- package/dist/types/qna.js +1 -0
- package/dist/types/returns.d.ts +96 -0
- package/dist/types/returns.d.ts.map +1 -0
- package/dist/types/returns.js +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/wire/normalize.d.ts +20 -0
- package/dist/wire/normalize.d.ts.map +1 -0
- package/dist/wire/normalize.js +158 -0
- package/dist/wire/validate.d.ts +6 -0
- package/dist/wire/validate.d.ts.map +1 -0
- package/dist/wire/validate.js +53 -0
- package/package.json +53 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export class N11ApiError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
status;
|
|
4
|
+
raw;
|
|
5
|
+
retryable;
|
|
6
|
+
constructor(message, options) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "N11ApiError";
|
|
9
|
+
this.status = options.status;
|
|
10
|
+
this.code = options.code;
|
|
11
|
+
this.raw = options.raw;
|
|
12
|
+
this.retryable = options.retryable ?? false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class N11TransportError extends Error {
|
|
16
|
+
retryable;
|
|
17
|
+
constructor(message, options) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "N11TransportError";
|
|
20
|
+
this.retryable = options?.retryable ?? true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class TaskTimeoutError extends Error {
|
|
24
|
+
taskId;
|
|
25
|
+
lastStatus;
|
|
26
|
+
constructor(taskId, timeoutMs, lastStatus) {
|
|
27
|
+
super(`Task poll zaman asimi (${timeoutMs}ms): ${taskId}`);
|
|
28
|
+
this.name = "TaskTimeoutError";
|
|
29
|
+
this.taskId = taskId;
|
|
30
|
+
this.lastStatus = lastStatus;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class TaskPollAbortedError extends Error {
|
|
34
|
+
constructor(taskId) {
|
|
35
|
+
super(`Task poll iptal edildi: ${taskId}`);
|
|
36
|
+
this.name = "TaskPollAbortedError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class UnknownTaskStatusError extends Error {
|
|
40
|
+
constructor(status, taskId) {
|
|
41
|
+
super(`Bilinmeyen task status (${status}): ${taskId}`);
|
|
42
|
+
this.name = "UnknownTaskStatusError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class NotImplementedError extends Error {
|
|
46
|
+
endpoint;
|
|
47
|
+
constructor(endpoint) {
|
|
48
|
+
super(`Endpoint henuz implement edilmedi: ${endpoint}`);
|
|
49
|
+
this.name = "NotImplementedError";
|
|
50
|
+
this.endpoint = endpoint;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function isHtmlErrorBody(body) {
|
|
54
|
+
if (typeof body !== "string")
|
|
55
|
+
return false;
|
|
56
|
+
const trimmed = body.trim().toLowerCase();
|
|
57
|
+
return trimmed.startsWith("<!doctype html") || trimmed.startsWith("<html");
|
|
58
|
+
}
|
|
59
|
+
export function isHtmlGatewayError(error) {
|
|
60
|
+
if (error instanceof N11ApiError) {
|
|
61
|
+
if (typeof error.raw === "string" && isHtmlErrorBody(error.raw)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (error.status === 403 && typeof error.raw === "string") {
|
|
65
|
+
return isHtmlErrorBody(error.raw);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
export function parseApiError(status, body) {
|
|
71
|
+
const record = body && typeof body === "object" ? body : {};
|
|
72
|
+
const code = record.code ??
|
|
73
|
+
record.errorCode ??
|
|
74
|
+
record.error_code;
|
|
75
|
+
const message = (typeof record.message === "string" && record.message) ||
|
|
76
|
+
(typeof record.errorMessage === "string" && record.errorMessage) ||
|
|
77
|
+
(typeof record.reason === "string" && record.reason) ||
|
|
78
|
+
`n11 API hatasi (HTTP ${status})`;
|
|
79
|
+
if (typeof body === "string" && isHtmlErrorBody(body)) {
|
|
80
|
+
return new N11ApiError("Gateway HTML hatasi.", {
|
|
81
|
+
status,
|
|
82
|
+
code: "HTML_GATEWAY",
|
|
83
|
+
raw: body,
|
|
84
|
+
retryable: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return new N11ApiError(message, {
|
|
88
|
+
status,
|
|
89
|
+
code,
|
|
90
|
+
raw: body,
|
|
91
|
+
retryable: status === 429 || status >= 500,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function parseSoapFailure(rawBody, status) {
|
|
95
|
+
const statusMatch = rawBody.match(/<(?:\w+:)?status[^>]*>([^<]+)<\//i);
|
|
96
|
+
const messageMatch = rawBody.match(/<(?:\w+:)?errorMessage[^>]*>([^<]+)<\//i);
|
|
97
|
+
const faultMatch = rawBody.match(/<faultstring[^>]*>([^<]+)<\//i);
|
|
98
|
+
const soapStatus = statusMatch?.[1]?.trim().toLowerCase();
|
|
99
|
+
if (soapStatus === "failure") {
|
|
100
|
+
return new N11ApiError(messageMatch?.[1]?.trim() ?? "SOAP failure", {
|
|
101
|
+
status,
|
|
102
|
+
code: "SOAP_FAILURE",
|
|
103
|
+
raw: rawBody,
|
|
104
|
+
retryable: false,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (faultMatch?.[1]) {
|
|
108
|
+
return new N11ApiError(faultMatch[1].trim(), {
|
|
109
|
+
status,
|
|
110
|
+
code: "SOAP_FAULT",
|
|
111
|
+
raw: rawBody,
|
|
112
|
+
retryable: false,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return new N11ApiError("SOAP yanit hatasi.", {
|
|
116
|
+
status,
|
|
117
|
+
code: "SOAP_ERROR",
|
|
118
|
+
raw: rawBody,
|
|
119
|
+
retryable: status >= 500,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export function isRetryableError(error) {
|
|
123
|
+
if (error instanceof N11TransportError)
|
|
124
|
+
return error.retryable;
|
|
125
|
+
if (error instanceof N11ApiError)
|
|
126
|
+
return error.retryable;
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
export function toFailure(error) {
|
|
130
|
+
if (error instanceof N11ApiError) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
reason: error.message,
|
|
134
|
+
code: error.code,
|
|
135
|
+
status: error.status,
|
|
136
|
+
raw: error.raw,
|
|
137
|
+
retryable: error.retryable,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (error instanceof N11TransportError) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
reason: error.message,
|
|
144
|
+
code: error.name,
|
|
145
|
+
retryable: error.retryable,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (error instanceof NotImplementedError) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
reason: error.message,
|
|
152
|
+
code: "NOT_IMPLEMENTED",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (error instanceof Error) {
|
|
156
|
+
return { ok: false, reason: error.message, code: error.name };
|
|
157
|
+
}
|
|
158
|
+
return { ok: false, reason: "Bilinmeyen hata." };
|
|
159
|
+
}
|
|
160
|
+
export function notImplemented(endpoint) {
|
|
161
|
+
return toFailure(new NotImplementedError(endpoint));
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/http/query.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAQjE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function buildQuery(query) {
|
|
2
|
+
const params = new URLSearchParams();
|
|
3
|
+
for (const [key, value] of Object.entries(query)) {
|
|
4
|
+
if (value === undefined || value === null)
|
|
5
|
+
continue;
|
|
6
|
+
params.set(key, String(value));
|
|
7
|
+
}
|
|
8
|
+
const serialized = params.toString();
|
|
9
|
+
return serialized ? `?${serialized}` : "";
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ParsedResponse<T> = {
|
|
2
|
+
data: T | null;
|
|
3
|
+
status: number;
|
|
4
|
+
headers: Headers;
|
|
5
|
+
rawText: string;
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseJsonResponse<T>(response: Response, options?: {
|
|
9
|
+
maxResponseBodyBytes?: number;
|
|
10
|
+
rawText?: string;
|
|
11
|
+
}): Promise<ParsedResponse<T>>;
|
|
12
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/http/response.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE;IAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CA2C5B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { N11ApiError } from "../errors.js";
|
|
2
|
+
import { truncateResponseBody } from "./security.js";
|
|
3
|
+
export async function parseJsonResponse(response, options) {
|
|
4
|
+
const text = options?.rawText ?? (await response.text());
|
|
5
|
+
const maxBytes = options?.maxResponseBodyBytes;
|
|
6
|
+
const { text: boundedText, truncated } = maxBytes != null ? truncateResponseBody(text, maxBytes) : { text, truncated: false };
|
|
7
|
+
if (response.status === 204 || boundedText.length === 0) {
|
|
8
|
+
return {
|
|
9
|
+
data: null,
|
|
10
|
+
status: response.status,
|
|
11
|
+
headers: response.headers,
|
|
12
|
+
rawText: boundedText,
|
|
13
|
+
truncated,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (truncated) {
|
|
17
|
+
return {
|
|
18
|
+
data: null,
|
|
19
|
+
status: response.status,
|
|
20
|
+
headers: response.headers,
|
|
21
|
+
rawText: boundedText,
|
|
22
|
+
truncated: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const data = JSON.parse(boundedText);
|
|
27
|
+
return {
|
|
28
|
+
data,
|
|
29
|
+
status: response.status,
|
|
30
|
+
headers: response.headers,
|
|
31
|
+
rawText: boundedText,
|
|
32
|
+
truncated,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new N11ApiError("Gecersiz JSON yaniti.", {
|
|
37
|
+
status: response.status,
|
|
38
|
+
code: "INVALID_JSON",
|
|
39
|
+
raw: boundedText,
|
|
40
|
+
retryable: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/http/security.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAQtC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBtF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function truncateResponseBody(text, maxBytes) {
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const bytes = encoder.encode(text);
|
|
4
|
+
if (bytes.length <= maxBytes) {
|
|
5
|
+
return { text, truncated: false };
|
|
6
|
+
}
|
|
7
|
+
const slice = bytes.slice(0, maxBytes);
|
|
8
|
+
return { text: new TextDecoder().decode(slice), truncated: true };
|
|
9
|
+
}
|
|
10
|
+
export function maskPiiFields(record) {
|
|
11
|
+
const clone = {};
|
|
12
|
+
for (const [key, value] of Object.entries(record)) {
|
|
13
|
+
const lower = key.toLowerCase();
|
|
14
|
+
if (lower.includes("phone") ||
|
|
15
|
+
lower.includes("email") ||
|
|
16
|
+
lower.includes("address") ||
|
|
17
|
+
lower.includes("secret") ||
|
|
18
|
+
lower.includes("password")) {
|
|
19
|
+
clone[key] = "[REDACTED]";
|
|
20
|
+
}
|
|
21
|
+
else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
22
|
+
clone[key] = maskPiiFields(value);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
clone[key] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return clone;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/http/signals.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,OAAO,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,GACzC,WAAW,CAyBb"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AbortSignal.any yerine Node 20.10 uyumlu birlestirme.
|
|
3
|
+
*/
|
|
4
|
+
export function combineAbortSignals(...signals) {
|
|
5
|
+
const active = signals.filter((signal) => signal != null);
|
|
6
|
+
if (active.length === 0) {
|
|
7
|
+
return AbortSignal.timeout(Number.MAX_SAFE_INTEGER);
|
|
8
|
+
}
|
|
9
|
+
if (active.length === 1) {
|
|
10
|
+
return active[0];
|
|
11
|
+
}
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
const onAbort = (source) => {
|
|
14
|
+
if (!controller.signal.aborted) {
|
|
15
|
+
controller.abort(source.reason);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
for (const signal of active) {
|
|
19
|
+
if (signal.aborted) {
|
|
20
|
+
controller.abort(signal.reason);
|
|
21
|
+
return controller.signal;
|
|
22
|
+
}
|
|
23
|
+
signal.addEventListener("abort", () => onAbort(signal), { once: true });
|
|
24
|
+
}
|
|
25
|
+
return controller.signal;
|
|
26
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RateLimitGovernor } from "./rate-limit/governor.js";
|
|
2
|
+
import type { N11Config, N11Hooks, N11Result, HttpRequestOptions } from "./types.js";
|
|
3
|
+
export declare class N11HttpClient {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly governor?;
|
|
6
|
+
private hooks;
|
|
7
|
+
constructor(config: N11Config, governor?: RateLimitGovernor | undefined);
|
|
8
|
+
setHooks(hooks: N11Hooks): void;
|
|
9
|
+
getHooks(): N11Hooks;
|
|
10
|
+
requestJson<T>(options: HttpRequestOptions): Promise<N11Result<T>>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EACT,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAJ5B,OAAO,CAAC,KAAK,CAAgB;gBAGV,MAAM,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,iBAAiB,YAAA;IAG/C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,QAAQ,IAAI,QAAQ;IAId,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CA8IzE"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { buildRestAuthHeaders } from "./config.js";
|
|
3
|
+
import { N11_API_HOST, buildRestUrl } from "./constants/hosts.js";
|
|
4
|
+
import { N11_CORRELATION_HEADER } from "./constants/defaults.js";
|
|
5
|
+
import { isHtmlGatewayError, parseApiError, toFailure, N11TransportError, } from "./errors.js";
|
|
6
|
+
import { buildQuery } from "./http/query.js";
|
|
7
|
+
import { parseJsonResponse } from "./http/response.js";
|
|
8
|
+
import { combineAbortSignals } from "./http/signals.js";
|
|
9
|
+
import { buildHttpObservabilityMeta, n11Log } from "./logger.js";
|
|
10
|
+
import { computeRetryDelayMs, shouldRetryStatus, sleep } from "./retry.js";
|
|
11
|
+
export class N11HttpClient {
|
|
12
|
+
config;
|
|
13
|
+
governor;
|
|
14
|
+
hooks = {};
|
|
15
|
+
constructor(config, governor) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.governor = governor;
|
|
18
|
+
}
|
|
19
|
+
setHooks(hooks) {
|
|
20
|
+
this.hooks = hooks;
|
|
21
|
+
}
|
|
22
|
+
getHooks() {
|
|
23
|
+
return this.hooks;
|
|
24
|
+
}
|
|
25
|
+
async requestJson(options) {
|
|
26
|
+
const query = options.query ? buildQuery(options.query) : "";
|
|
27
|
+
const baseUrl = buildRestUrl(options.resource, options.path);
|
|
28
|
+
const url = `${baseUrl}${query}`;
|
|
29
|
+
const correlationId = randomUUID();
|
|
30
|
+
const host = N11_API_HOST;
|
|
31
|
+
if (this.config.enableClientSideLimiter && this.governor) {
|
|
32
|
+
const waitMs = await this.governor.acquire(options.path);
|
|
33
|
+
if (waitMs > 0) {
|
|
34
|
+
this.hooks.onRateLimitHit?.({ retryAfterMs: waitMs, resource: options.resource });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (let attempt = 0; attempt <= this.config.maxRetries; attempt += 1) {
|
|
38
|
+
const started = Date.now();
|
|
39
|
+
const timeoutSignal = AbortSignal.timeout(this.config.requestTimeoutMs);
|
|
40
|
+
const signal = combineAbortSignals(timeoutSignal, options.signal);
|
|
41
|
+
this.hooks.onRequestStart?.({
|
|
42
|
+
correlationId,
|
|
43
|
+
resource: options.resource,
|
|
44
|
+
method: options.method,
|
|
45
|
+
path: options.path,
|
|
46
|
+
host,
|
|
47
|
+
transport: "rest",
|
|
48
|
+
});
|
|
49
|
+
n11Log(this.config.debug, "debug", "REST istegi", buildHttpObservabilityMeta({
|
|
50
|
+
correlationId,
|
|
51
|
+
resource: options.resource,
|
|
52
|
+
method: options.method,
|
|
53
|
+
path: options.path,
|
|
54
|
+
host,
|
|
55
|
+
transport: "rest",
|
|
56
|
+
retryCount: attempt > 0 ? attempt : undefined,
|
|
57
|
+
}));
|
|
58
|
+
try {
|
|
59
|
+
const headers = {
|
|
60
|
+
...buildRestAuthHeaders(this.config),
|
|
61
|
+
[N11_CORRELATION_HEADER]: correlationId,
|
|
62
|
+
Accept: "application/json",
|
|
63
|
+
...options.headers,
|
|
64
|
+
};
|
|
65
|
+
if (options.body !== undefined) {
|
|
66
|
+
headers["Content-Type"] = "application/json";
|
|
67
|
+
}
|
|
68
|
+
const response = await fetch(url, {
|
|
69
|
+
method: options.method,
|
|
70
|
+
headers,
|
|
71
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
72
|
+
signal,
|
|
73
|
+
});
|
|
74
|
+
const parsed = await parseJsonResponse(response, {
|
|
75
|
+
maxResponseBodyBytes: this.config.maxResponseBodyBytes,
|
|
76
|
+
});
|
|
77
|
+
if (parsed.truncated) {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
reason: "Yanit boyutu limiti asildi.",
|
|
81
|
+
code: "RESPONSE_TOO_LARGE",
|
|
82
|
+
status: response.status,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const durationMs = Date.now() - started;
|
|
86
|
+
this.hooks.onRequestEnd?.({
|
|
87
|
+
correlationId,
|
|
88
|
+
resource: options.resource,
|
|
89
|
+
method: options.method,
|
|
90
|
+
path: options.path,
|
|
91
|
+
host,
|
|
92
|
+
transport: "rest",
|
|
93
|
+
status: response.status,
|
|
94
|
+
durationMs,
|
|
95
|
+
});
|
|
96
|
+
if (shouldRetryStatus(response.status, options.retryPolicy) &&
|
|
97
|
+
attempt < this.config.maxRetries) {
|
|
98
|
+
const delay = computeRetryDelayMs(this.config, attempt, response.headers.get("Retry-After"));
|
|
99
|
+
this.hooks.onRetry?.({ attempt, status: response.status, delayMs: delay });
|
|
100
|
+
if (response.status === 429) {
|
|
101
|
+
this.hooks.onRateLimitHit?.({
|
|
102
|
+
retryAfterMs: delay,
|
|
103
|
+
resource: options.resource,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
await sleep(delay);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
const apiError = parseApiError(response.status, parsed.data ?? parsed.rawText);
|
|
111
|
+
if (isHtmlGatewayError(apiError) &&
|
|
112
|
+
options.retryPolicy === "safe" &&
|
|
113
|
+
attempt < this.config.maxRetries) {
|
|
114
|
+
const delay = computeRetryDelayMs(this.config, attempt);
|
|
115
|
+
this.hooks.onRetry?.({ attempt, status: response.status, delayMs: delay });
|
|
116
|
+
await sleep(delay);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
return toFailure(apiError);
|
|
120
|
+
}
|
|
121
|
+
return { ok: true, data: parsed.data ?? null };
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
const retryable = options.retryPolicy === "safe";
|
|
125
|
+
const transport = error instanceof Error
|
|
126
|
+
? new N11TransportError(error.message, { retryable })
|
|
127
|
+
: new N11TransportError("n11 transport hatasi.", { retryable });
|
|
128
|
+
if (retryable && attempt < this.config.maxRetries) {
|
|
129
|
+
const delay = computeRetryDelayMs(this.config, attempt);
|
|
130
|
+
this.hooks.onRetry?.({ attempt, delayMs: delay });
|
|
131
|
+
await sleep(delay);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
return toFailure(transport);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
reason: "n11 istegi maksimum deneme sayisina ulasti.",
|
|
140
|
+
retryable: options.retryPolicy === "safe",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export { createN11Client, N11Client } from "./client.js";
|
|
2
|
+
export { getN11Config, isN11Configured, buildRestAuthHeaders, N11ConfigError } from "./config.js";
|
|
3
|
+
export { testConnection } from "./connection.js";
|
|
4
|
+
export { CategoriesApi } from "./categories/api.js";
|
|
5
|
+
export { ProductsApi } from "./products/api.js";
|
|
6
|
+
export { buildProductCreatePayload, buildCatalogFastPathSku, isCatalogFastPathSku, } from "./products/builder.js";
|
|
7
|
+
export type { BuildProductPayloadOptions } from "./products/builder.js";
|
|
8
|
+
export { OrdersApi } from "./orders/api.js";
|
|
9
|
+
export { ReturnsApi } from "./returns/api.js";
|
|
10
|
+
export { InvoiceApi } from "./invoice/api.js";
|
|
11
|
+
export { QnaApi } from "./qna/api.js";
|
|
12
|
+
export { TasksApi } from "./tasks/api.js";
|
|
13
|
+
export { TaskPoller } from "./tasks/poller.js";
|
|
14
|
+
export { N11TasksModule } from "./tasks/module.js";
|
|
15
|
+
export { pollPackagesSince } from "./orders/reconciler.js";
|
|
16
|
+
export { N11HttpClient } from "./http.js";
|
|
17
|
+
export { N11SoapClient } from "./soap/client.js";
|
|
18
|
+
export { SOAP_OPERATIONS, SOAP_OPERATION_COUNT, findSoapOperation } from "./soap/operations.js";
|
|
19
|
+
export { xmlEscape, buildSoapEnvelope, buildAuthBlock } from "./soap/envelope.js";
|
|
20
|
+
export { extractXmlTag, extractXmlElements, parseSoapResult, isSoapFailure, } from "./soap/parse.js";
|
|
21
|
+
export { combineAbortSignals } from "./http/signals.js";
|
|
22
|
+
export { RATE_LIMIT_GROUPS } from "./rate-limit/groups.js";
|
|
23
|
+
export { N11_API_HOST, buildRestUrl } from "./constants/hosts.js";
|
|
24
|
+
export { N11_TASK_TERMINAL_STATUSES, N11_TASK_IN_PROGRESS_STATUS, N11_DEFAULT_ORDER_LOOKBACK_MS, } from "./constants/defaults.js";
|
|
25
|
+
export { N11_PRODUCT_QUERY_DEFAULT_SIZE, N11_PRODUCT_QUERY_MAX_SIZE, N11_PRODUCT_TASK_MAX_SKUS, N11_SHIPMENT_PACKAGES_DEFAULT_SIZE, N11_SHIPMENT_PACKAGES_MAX_SIZE, N11_RETURN_LIST_PAGE_SIZE, } from "./constants/page-limits.js";
|
|
26
|
+
export { N11ApiError, N11TransportError, TaskTimeoutError, TaskPollAbortedError, UnknownTaskStatusError, NotImplementedError, isHtmlGatewayError, isRetryableError, parseApiError, parseSoapFailure, toFailure, notImplemented, } from "./errors.js";
|
|
27
|
+
export { computeRetryDelayMs, shouldRetryStatus, sleep } from "./retry.js";
|
|
28
|
+
export type { N11Config, N11Result, N11RestResource, N11Hooks, WireRow, N11Category, CategoryListResponse, SoapCallOptions, SoapCallResult, SoapOperationDef, TestConnectionResult, } from "./types.js";
|
|
29
|
+
export type { TaskKind, TaskPollOptions, TaskPollResult } from "./tasks/types.js";
|
|
30
|
+
export type { N11ProductCreateSku, N11ProductUpdateSku, N11PriceStockSku, N11ProductDeleteSku, N11CatalogFastPathInput, N11TaskSubmitResponse, N11ProductQueryParams, N11ProductQueryResponse, N11ProductQueryItem, N11CategoryAttributesResponse, N11CategoryAttribute, N11TaskDetailRow, } from "./types/products.js";
|
|
31
|
+
export type { PollPackagesSinceOptions } from "./orders/reconciler.js";
|
|
32
|
+
export { toN11Gmt3Timestamp, buildLookbackWindow } from "./orders/date.js";
|
|
33
|
+
export { buildOrderUpdateBody } from "./orders/update.js";
|
|
34
|
+
export { serializeShipmentPackagesQuery } from "./orders/list.js";
|
|
35
|
+
export type { N11ShipmentPackageStatus, N11OrderByDirection, N11ShipmentPackageSender, N11ShipmentPackagesListParams, N11ShipmentPackage, N11ShipmentPackagesListResponse, N11OrderLineUpdateInput, N11OrderUpdateParams, N11OrderUpdateLineResult, N11OrderUpdateResponse, N11CollectionRequestDetail, N11CollectionRequestParams, N11CollectionRequestResponse, N11SplitCombineGroup, N11SplitCombinePackageParams, N11SplitPackageDetail, N11SplitPackageGroup, N11SplitCancelledItem, N11SplitPackageByQuantityParams, N11SplitPackageOrderItem, N11SplitPackageResponse, N11LaborCostDetail, N11LaborCostUpdateParams, N11LaborCostLineResult, N11LaborCostUpdateResponse, } from "./types/orders.js";
|
|
36
|
+
export type { N11ClaimReturnStatus, N11ClaimReturnExecuter, N11ClaimReturnSearchInfoType, N11ClaimReturnSender, N11ClaimReturnListParams, N11ClaimReturn, N11ClaimReturnPaging, N11ClaimReturnListResponse, N11ReasonType, N11ReasonTypeListResponse, N11SoapMutationResult, N11ClaimReturnApproveParams, N11ClaimReturnPendingParams, N11ReturnShipmentType, N11ClaimReturnDenyParams, N11ClaimCancelPartialParams, } from "./types/returns.js";
|
|
37
|
+
export { parseClaimReturnListResponse, parseReasonTypeListResponse } from "./returns/parse.js";
|
|
38
|
+
export { invokeSoapOperation } from "./soap/call.js";
|
|
39
|
+
export { buildSaveLinkSellerInvoiceRequestBody } from "./invoice/soap-body.js";
|
|
40
|
+
export { parseSaveLinkSellerInvoiceResponse } from "./invoice/parse.js";
|
|
41
|
+
export { validateInvoiceSendLinkParams, validateInvoiceUrl, validateInvoiceNumber, N11_INVOICE_URL_MAX_LENGTH, } from "./invoice/validate.js";
|
|
42
|
+
export { buildGetProductQuestionListRequestBody, buildGetProductQuestionDetailRequestBody, buildSaveProductAnswerRequestBody, } from "./qna/soap-body.js";
|
|
43
|
+
export { parseProductQuestionListResponse, parseProductQuestionDetailResponse, parseSaveProductAnswerResponse, } from "./qna/parse.js";
|
|
44
|
+
export { validateDdMmYyyyDate, validateProductQuestionListParams, validateProductQuestionAnswer, N11_QNA_ANSWER_MAX_LENGTH, } from "./qna/validate.js";
|
|
45
|
+
export type { N11InvoiceSendLinkParams, N11InvoiceLinkResult, N11InvoiceSendLinkResponse, } from "./types/invoice.js";
|
|
46
|
+
export type { N11ProductQuestionStatus, N11ProductQuestionListParams, N11ProductQuestion, N11ProductQuestionPaging, N11ProductQuestionListResponse, N11ProductQuestionDetailParams, N11ProductQuestionDetail, N11ProductQuestionDetailResponse, N11ProductQuestionAnswerParams, } from "./types/qna.js";
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,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,mBAAmB,CAAC;AAC3B,YAAY,EACV,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,8BAA8B,EAC9B,8BAA8B,EAC9B,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { createN11Client, N11Client } from "./client.js";
|
|
2
|
+
export { getN11Config, isN11Configured, buildRestAuthHeaders, N11ConfigError } from "./config.js";
|
|
3
|
+
export { testConnection } from "./connection.js";
|
|
4
|
+
export { CategoriesApi } from "./categories/api.js";
|
|
5
|
+
export { ProductsApi } from "./products/api.js";
|
|
6
|
+
export { buildProductCreatePayload, buildCatalogFastPathSku, isCatalogFastPathSku, } from "./products/builder.js";
|
|
7
|
+
export { OrdersApi } from "./orders/api.js";
|
|
8
|
+
export { ReturnsApi } from "./returns/api.js";
|
|
9
|
+
export { InvoiceApi } from "./invoice/api.js";
|
|
10
|
+
export { QnaApi } from "./qna/api.js";
|
|
11
|
+
export { TasksApi } from "./tasks/api.js";
|
|
12
|
+
export { TaskPoller } from "./tasks/poller.js";
|
|
13
|
+
export { N11TasksModule } from "./tasks/module.js";
|
|
14
|
+
export { pollPackagesSince } from "./orders/reconciler.js";
|
|
15
|
+
export { N11HttpClient } from "./http.js";
|
|
16
|
+
export { N11SoapClient } from "./soap/client.js";
|
|
17
|
+
export { SOAP_OPERATIONS, SOAP_OPERATION_COUNT, findSoapOperation } from "./soap/operations.js";
|
|
18
|
+
export { xmlEscape, buildSoapEnvelope, buildAuthBlock } from "./soap/envelope.js";
|
|
19
|
+
export { extractXmlTag, extractXmlElements, parseSoapResult, isSoapFailure, } from "./soap/parse.js";
|
|
20
|
+
export { combineAbortSignals } from "./http/signals.js";
|
|
21
|
+
export { RATE_LIMIT_GROUPS } from "./rate-limit/groups.js";
|
|
22
|
+
export { N11_API_HOST, buildRestUrl } from "./constants/hosts.js";
|
|
23
|
+
export { N11_TASK_TERMINAL_STATUSES, N11_TASK_IN_PROGRESS_STATUS, N11_DEFAULT_ORDER_LOOKBACK_MS, } from "./constants/defaults.js";
|
|
24
|
+
export { N11_PRODUCT_QUERY_DEFAULT_SIZE, N11_PRODUCT_QUERY_MAX_SIZE, N11_PRODUCT_TASK_MAX_SKUS, N11_SHIPMENT_PACKAGES_DEFAULT_SIZE, N11_SHIPMENT_PACKAGES_MAX_SIZE, N11_RETURN_LIST_PAGE_SIZE, } from "./constants/page-limits.js";
|
|
25
|
+
export { N11ApiError, N11TransportError, TaskTimeoutError, TaskPollAbortedError, UnknownTaskStatusError, NotImplementedError, isHtmlGatewayError, isRetryableError, parseApiError, parseSoapFailure, toFailure, notImplemented, } from "./errors.js";
|
|
26
|
+
export { computeRetryDelayMs, shouldRetryStatus, sleep } from "./retry.js";
|
|
27
|
+
export { toN11Gmt3Timestamp, buildLookbackWindow } from "./orders/date.js";
|
|
28
|
+
export { buildOrderUpdateBody } from "./orders/update.js";
|
|
29
|
+
export { serializeShipmentPackagesQuery } from "./orders/list.js";
|
|
30
|
+
export { parseClaimReturnListResponse, parseReasonTypeListResponse } from "./returns/parse.js";
|
|
31
|
+
export { invokeSoapOperation } from "./soap/call.js";
|
|
32
|
+
export { buildSaveLinkSellerInvoiceRequestBody } from "./invoice/soap-body.js";
|
|
33
|
+
export { parseSaveLinkSellerInvoiceResponse } from "./invoice/parse.js";
|
|
34
|
+
export { validateInvoiceSendLinkParams, validateInvoiceUrl, validateInvoiceNumber, N11_INVOICE_URL_MAX_LENGTH, } from "./invoice/validate.js";
|
|
35
|
+
export { buildGetProductQuestionListRequestBody, buildGetProductQuestionDetailRequestBody, buildSaveProductAnswerRequestBody, } from "./qna/soap-body.js";
|
|
36
|
+
export { parseProductQuestionListResponse, parseProductQuestionDetailResponse, parseSaveProductAnswerResponse, } from "./qna/parse.js";
|
|
37
|
+
export { validateDdMmYyyyDate, validateProductQuestionListParams, validateProductQuestionAnswer, N11_QNA_ANSWER_MAX_LENGTH, } from "./qna/validate.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { N11SoapClient } from "../soap/client.js";
|
|
2
|
+
import type { N11Config, N11Result } from "../types.js";
|
|
3
|
+
import type { N11InvoiceSendLinkParams, N11InvoiceSendLinkResponse } from "../types/invoice.js";
|
|
4
|
+
type InvoiceRequestOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
export declare class InvoiceApi {
|
|
8
|
+
private readonly soap;
|
|
9
|
+
private readonly config;
|
|
10
|
+
constructor(soap: N11SoapClient, config: N11Config);
|
|
11
|
+
sendLink(params: N11InvoiceSendLinkParams, options?: InvoiceRequestOptions): Promise<N11Result<N11InvoiceSendLinkResponse>>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/invoice/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAGhG,KAAK,qBAAqB,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEtD,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,SAAS;IAGpC,QAAQ,CACN,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;CAGlD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { sendInvoiceLink as sendInvoiceLinkImpl } from "./send-link.js";
|
|
2
|
+
export class InvoiceApi {
|
|
3
|
+
soap;
|
|
4
|
+
config;
|
|
5
|
+
constructor(soap, config) {
|
|
6
|
+
this.soap = soap;
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
sendLink(params, options) {
|
|
10
|
+
return sendInvoiceLinkImpl(this.soap, this.config, params, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/invoice/parse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAGtE,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,MAAM,GAAG,0BAA0B,CAS1F"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { extractXmlTag, parseSoapResult } from "../soap/parse.js";
|
|
2
|
+
import { attachRaw } from "../wire/normalize.js";
|
|
3
|
+
export function parseSaveLinkSellerInvoiceResponse(xml) {
|
|
4
|
+
const result = parseSoapResult(xml);
|
|
5
|
+
return attachRaw({
|
|
6
|
+
status: result.status,
|
|
7
|
+
url: extractXmlTag(xml, "url"),
|
|
8
|
+
orderNumber: extractXmlTag(xml, "orderNumber"),
|
|
9
|
+
invoiceNumber: extractXmlTag(xml, "invoiceNumber"),
|
|
10
|
+
invoiceDateTime: extractXmlTag(xml, "invoiceDateTime"),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { N11SoapClient } from "../soap/client.js";
|
|
2
|
+
import type { N11Config, N11Result } from "../types.js";
|
|
3
|
+
import type { N11InvoiceSendLinkParams, N11InvoiceSendLinkResponse } from "../types/invoice.js";
|
|
4
|
+
type SendLinkOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
export declare function sendInvoiceLink(soap: N11SoapClient, config: N11Config, params: N11InvoiceSendLinkParams, options?: SendLinkOptions): Promise<N11Result<N11InvoiceSendLinkResponse>>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=send-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-link.d.ts","sourceRoot":"","sources":["../../src/invoice/send-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAKhG,KAAK,eAAe,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEhD,wBAAsB,eAAe,CACnC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC,CAiBhD"}
|