@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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { invokeSoapOperation } from "../soap/call.js";
|
|
2
|
+
import { parseSaveLinkSellerInvoiceResponse } from "./parse.js";
|
|
3
|
+
import { buildSaveLinkSellerInvoiceRequestBody } from "./soap-body.js";
|
|
4
|
+
import { validateInvoiceSendLinkParams } from "./validate.js";
|
|
5
|
+
export async function sendInvoiceLink(soap, config, params, options) {
|
|
6
|
+
const validation = validateInvoiceSendLinkParams(params);
|
|
7
|
+
if (!validation.ok) {
|
|
8
|
+
return validation;
|
|
9
|
+
}
|
|
10
|
+
const bodyXml = buildSaveLinkSellerInvoiceRequestBody({ appKey: config.appKey, appSecret: config.appSecret }, params);
|
|
11
|
+
const result = await invokeSoapOperation(soap, "SaveLinkSellerInvoice", bodyXml, options);
|
|
12
|
+
if (!result.ok) {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
return { ok: true, data: parseSaveLinkSellerInvoiceResponse(result.data) };
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soap-body.d.ts","sourceRoot":"","sources":["../../src/invoice/soap-body.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AASpE,wBAAgB,qCAAqC,CACnD,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAC3C,MAAM,EAAE,wBAAwB,GAC/B,MAAM,CAiBR"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { buildAuthBlock, xmlEscape } from "../soap/envelope.js";
|
|
2
|
+
function field(name, value) {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
return `<${name}>${xmlEscape(String(value))}</${name}>`;
|
|
7
|
+
}
|
|
8
|
+
export function buildSaveLinkSellerInvoiceRequestBody(auth, params) {
|
|
9
|
+
const parts = [
|
|
10
|
+
"<SaveLinkSellerInvoiceRequest>",
|
|
11
|
+
buildAuthBlock(auth.appKey, auth.appSecret),
|
|
12
|
+
field("url", params.url),
|
|
13
|
+
field("orderNumber", params.orderNumber),
|
|
14
|
+
];
|
|
15
|
+
if (params.invoiceNumber !== undefined) {
|
|
16
|
+
parts.push(field("invoiceNumber", params.invoiceNumber));
|
|
17
|
+
}
|
|
18
|
+
if (params.invoiceDateTime !== undefined) {
|
|
19
|
+
parts.push(field("invoiceDateTime", params.invoiceDateTime));
|
|
20
|
+
}
|
|
21
|
+
parts.push("</SaveLinkSellerInvoiceRequest>");
|
|
22
|
+
return parts.join("");
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { N11Result } from "../types.js";
|
|
2
|
+
import type { N11InvoiceSendLinkParams } from "../types/invoice.js";
|
|
3
|
+
export declare const N11_INVOICE_URL_MAX_LENGTH = 2048;
|
|
4
|
+
export declare function validateInvoiceUrl(url: string): N11Result<void>;
|
|
5
|
+
export declare function validateInvoiceNumber(invoiceNumber: string): N11Result<void>;
|
|
6
|
+
export declare function validateInvoiceSendLinkParams(params: N11InvoiceSendLinkParams): N11Result<void>;
|
|
7
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/invoice/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAK/C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CA0B/D;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAU5E;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,wBAAwB,GAC/B,SAAS,CAAC,IAAI,CAAC,CAoCjB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const N11_INVOICE_URL_MAX_LENGTH = 2048;
|
|
2
|
+
const INVOICE_URL_EXTENSION = /\.(pdf|png|jpe?g)(\?|$)/i;
|
|
3
|
+
const INVOICE_NUMBER_PATTERN = /^[A-Za-z0-9]{3}(20[2-9][0-9]|2099)[0-9]{9}$/;
|
|
4
|
+
export function validateInvoiceUrl(url) {
|
|
5
|
+
if (!url || url.trim().length === 0) {
|
|
6
|
+
return { ok: false, reason: "Fatura URL zorunludur.", code: "INVALID_INVOICE_URL" };
|
|
7
|
+
}
|
|
8
|
+
if (url.length > N11_INVOICE_URL_MAX_LENGTH) {
|
|
9
|
+
return {
|
|
10
|
+
ok: false,
|
|
11
|
+
reason: `Fatura URL en fazla ${N11_INVOICE_URL_MAX_LENGTH} karakter olabilir.`,
|
|
12
|
+
code: "INVALID_INVOICE_URL",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (!url.startsWith("https://")) {
|
|
16
|
+
return {
|
|
17
|
+
ok: false,
|
|
18
|
+
reason: "Fatura URL HTTPS ile baslamalidir.",
|
|
19
|
+
code: "INVALID_INVOICE_URL",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!INVOICE_URL_EXTENSION.test(url)) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
reason: "Fatura URL uzantisi pdf, png veya jpeg olmalidir.",
|
|
26
|
+
code: "INVALID_INVOICE_URL",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return { ok: true, data: undefined };
|
|
30
|
+
}
|
|
31
|
+
export function validateInvoiceNumber(invoiceNumber) {
|
|
32
|
+
if (!INVOICE_NUMBER_PATTERN.test(invoiceNumber)) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
reason: "invoiceNumber formati gecersiz: 3 alfanumerik + yil (2020-2099) + 9 numerik.",
|
|
36
|
+
code: "INVALID_INVOICE_NUMBER",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return { ok: true, data: undefined };
|
|
40
|
+
}
|
|
41
|
+
export function validateInvoiceSendLinkParams(params) {
|
|
42
|
+
if (!params.orderNumber || params.orderNumber.trim().length === 0) {
|
|
43
|
+
return { ok: false, reason: "orderNumber zorunludur.", code: "INVALID_INVOICE_PARAMS" };
|
|
44
|
+
}
|
|
45
|
+
const urlCheck = validateInvoiceUrl(params.url);
|
|
46
|
+
if (!urlCheck.ok) {
|
|
47
|
+
return urlCheck;
|
|
48
|
+
}
|
|
49
|
+
if (params.micro) {
|
|
50
|
+
if (params.invoiceNumber === undefined || params.invoiceNumber.trim().length === 0) {
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
reason: "e-ihracat siparislerinde invoiceNumber zorunludur.",
|
|
54
|
+
code: "INVALID_INVOICE_PARAMS",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (params.invoiceDateTime === undefined || !Number.isFinite(params.invoiceDateTime)) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
reason: "e-ihracat siparislerinde invoiceDateTime zorunludur.",
|
|
61
|
+
code: "INVALID_INVOICE_PARAMS",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return validateInvoiceNumber(params.invoiceNumber);
|
|
65
|
+
}
|
|
66
|
+
if (params.invoiceNumber !== undefined && params.invoiceNumber.length > 0) {
|
|
67
|
+
const numberCheck = validateInvoiceNumber(params.invoiceNumber);
|
|
68
|
+
if (!numberCheck.ok) {
|
|
69
|
+
return numberCheck;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { ok: true, data: undefined };
|
|
73
|
+
}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { N11Logger } from "./types.js";
|
|
2
|
+
export declare function setN11Logger(logger: N11Logger | null): void;
|
|
3
|
+
export declare function n11Log(enabled: boolean, level: "debug" | "info" | "warn" | "error", message: string, meta?: Record<string, unknown>): void;
|
|
4
|
+
export type HttpObservabilityMeta = {
|
|
5
|
+
correlationId: string;
|
|
6
|
+
resource: string;
|
|
7
|
+
method: string;
|
|
8
|
+
path: string;
|
|
9
|
+
host: string;
|
|
10
|
+
transport: "rest" | "soap";
|
|
11
|
+
status?: number;
|
|
12
|
+
durationMs?: number;
|
|
13
|
+
retryCount?: number;
|
|
14
|
+
rateLimitWaitMs?: number;
|
|
15
|
+
errorCode?: string | number;
|
|
16
|
+
operation?: string;
|
|
17
|
+
taskPollAttempt?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function buildHttpObservabilityMeta(meta: HttpObservabilityMeta): Record<string, unknown>;
|
|
20
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAM5C,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAE3D;AAiBD,wBAAgB,MAAM,CACpB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAC1C,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,IAAI,CAUN;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiB/F"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { maskPiiFields } from "./http/security.js";
|
|
2
|
+
let customLogger = null;
|
|
3
|
+
const SECRET_PATTERNS = [/secret/i, /appkey/i, /appsecret/i, /password/i];
|
|
4
|
+
export function setN11Logger(logger) {
|
|
5
|
+
customLogger = logger;
|
|
6
|
+
}
|
|
7
|
+
function redactMeta(meta) {
|
|
8
|
+
if (!meta)
|
|
9
|
+
return meta;
|
|
10
|
+
const clone = {};
|
|
11
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
12
|
+
if (SECRET_PATTERNS.some((pattern) => pattern.test(key))) {
|
|
13
|
+
clone[key] = "[REDACTED]";
|
|
14
|
+
}
|
|
15
|
+
else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
16
|
+
clone[key] = maskPiiFields(value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
clone[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return clone;
|
|
23
|
+
}
|
|
24
|
+
export function n11Log(enabled, level, message, meta) {
|
|
25
|
+
if (!enabled && level === "debug")
|
|
26
|
+
return;
|
|
27
|
+
const safeMeta = redactMeta(meta);
|
|
28
|
+
if (customLogger) {
|
|
29
|
+
customLogger(level, message, safeMeta);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (level === "debug" && !enabled)
|
|
33
|
+
return;
|
|
34
|
+
const payload = safeMeta ? ` ${JSON.stringify(safeMeta)}` : "";
|
|
35
|
+
console[level === "debug" ? "log" : level](`[n11] ${message}${payload}`);
|
|
36
|
+
}
|
|
37
|
+
export function buildHttpObservabilityMeta(meta) {
|
|
38
|
+
const out = {
|
|
39
|
+
correlationId: meta.correlationId,
|
|
40
|
+
resource: meta.resource,
|
|
41
|
+
method: meta.method,
|
|
42
|
+
path: meta.path,
|
|
43
|
+
host: meta.host,
|
|
44
|
+
transport: meta.transport,
|
|
45
|
+
};
|
|
46
|
+
if (meta.status != null)
|
|
47
|
+
out.status = meta.status;
|
|
48
|
+
if (meta.durationMs != null)
|
|
49
|
+
out.durationMs = meta.durationMs;
|
|
50
|
+
if (meta.retryCount != null)
|
|
51
|
+
out.retryCount = meta.retryCount;
|
|
52
|
+
if (meta.rateLimitWaitMs != null)
|
|
53
|
+
out.rateLimitWaitMs = meta.rateLimitWaitMs;
|
|
54
|
+
if (meta.errorCode != null)
|
|
55
|
+
out.errorCode = meta.errorCode;
|
|
56
|
+
if (meta.operation)
|
|
57
|
+
out.operation = meta.operation;
|
|
58
|
+
if (meta.taskPollAttempt != null)
|
|
59
|
+
out.taskPollAttempt = meta.taskPollAttempt;
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { N11HttpClient } from "../http.js";
|
|
2
|
+
import type { PollPackagesSinceOptions } from "../orders/reconciler.js";
|
|
3
|
+
import type { N11Config, N11Result } from "../types.js";
|
|
4
|
+
import type { N11CollectionRequestParams, N11CollectionRequestResponse, N11LaborCostUpdateParams, N11LaborCostUpdateResponse, N11OrderUpdateParams, N11OrderUpdateResponse, N11ShipmentPackagesListParams, N11ShipmentPackagesListResponse, N11SplitCombinePackageParams, N11SplitPackageByQuantityParams, N11SplitPackageResponse } from "../types/orders.js";
|
|
5
|
+
type OrderRequestOptions = {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
};
|
|
8
|
+
export type N11ShipmentPackageWire = N11ShipmentPackagesListResponse["content"][number];
|
|
9
|
+
export declare class OrdersApi {
|
|
10
|
+
private readonly http;
|
|
11
|
+
private readonly config;
|
|
12
|
+
constructor(http: N11HttpClient, config: N11Config);
|
|
13
|
+
list(params?: N11ShipmentPackagesListParams, options?: OrderRequestOptions): Promise<N11Result<N11ShipmentPackagesListResponse>>;
|
|
14
|
+
pollPackagesSince(options?: PollPackagesSinceOptions): AsyncGenerator<N11Result<N11ShipmentPackageWire>>;
|
|
15
|
+
update(params: N11OrderUpdateParams, options?: OrderRequestOptions): Promise<N11Result<N11OrderUpdateResponse>>;
|
|
16
|
+
collectionRequest(params: N11CollectionRequestParams, options?: OrderRequestOptions): Promise<N11Result<N11CollectionRequestResponse>>;
|
|
17
|
+
splitCombinePackage(params: N11SplitCombinePackageParams, options?: OrderRequestOptions): Promise<N11Result<N11SplitPackageResponse>>;
|
|
18
|
+
splitPackageByQuantity(params: N11SplitPackageByQuantityParams, options?: OrderRequestOptions): Promise<N11Result<N11SplitPackageResponse>>;
|
|
19
|
+
updateLaborCosts(params: N11LaborCostUpdateParams, options?: OrderRequestOptions): Promise<N11Result<N11LaborCostUpdateResponse>>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/orders/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAUhD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,+BAA+B,EAC/B,4BAA4B,EAC5B,+BAA+B,EAC/B,uBAAuB,EACxB,MAAM,oBAAoB,CAAC;AAE5B,KAAK,mBAAmB,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG,+BAA+B,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAExF,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,SAAS;IAKpC,IAAI,CACF,MAAM,CAAC,EAAE,6BAA6B,EACtC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC;IAItD,iBAAiB,CACf,OAAO,CAAC,EAAE,wBAAwB,GACjC,cAAc,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAWpD,MAAM,CACJ,MAAM,EAAE,oBAAoB,EAC5B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAI7C,iBAAiB,CACf,MAAM,EAAE,0BAA0B,EAClC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;IAInD,mBAAmB,CACjB,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;IAI9C,sBAAsB,CACpB,MAAM,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;IAI9C,gBAAgB,CACd,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;CAGlD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { N11_DEFAULT_ORDER_LOOKBACK_MS } from "../constants/defaults.js";
|
|
2
|
+
import { fetchShipmentPackagesPage, listShipmentPackages } from "../orders/list.js";
|
|
3
|
+
import { updateLaborCosts as updateLaborCostsImpl } from "../orders/labor-cost.js";
|
|
4
|
+
import { createCollectionRequest as createCollectionRequestImpl, splitCombinePackage as splitCombinePackageImpl, splitPackageByQuantity as splitPackageByQuantityImpl, } from "../orders/shipping.js";
|
|
5
|
+
import { updateOrderLines } from "../orders/update.js";
|
|
6
|
+
import { pollPackagesSince as pollPackagesSinceImpl } from "../orders/reconciler.js";
|
|
7
|
+
export class OrdersApi {
|
|
8
|
+
http;
|
|
9
|
+
config;
|
|
10
|
+
constructor(http, config) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
this.config = config;
|
|
13
|
+
void this.config;
|
|
14
|
+
}
|
|
15
|
+
list(params, options) {
|
|
16
|
+
return listShipmentPackages(this.http, params, options);
|
|
17
|
+
}
|
|
18
|
+
pollPackagesSince(options) {
|
|
19
|
+
return pollPackagesSinceImpl((params) => fetchShipmentPackagesPage(this.http, params), {
|
|
20
|
+
lookbackMs: N11_DEFAULT_ORDER_LOOKBACK_MS,
|
|
21
|
+
orderByField: true,
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
update(params, options) {
|
|
26
|
+
return updateOrderLines(this.http, params, options);
|
|
27
|
+
}
|
|
28
|
+
collectionRequest(params, options) {
|
|
29
|
+
return createCollectionRequestImpl(this.http, params, options);
|
|
30
|
+
}
|
|
31
|
+
splitCombinePackage(params, options) {
|
|
32
|
+
return splitCombinePackageImpl(this.http, params, options);
|
|
33
|
+
}
|
|
34
|
+
splitPackageByQuantity(params, options) {
|
|
35
|
+
return splitPackageByQuantityImpl(this.http, params, options);
|
|
36
|
+
}
|
|
37
|
+
updateLaborCosts(params, options) {
|
|
38
|
+
return updateLaborCostsImpl(this.http, params, options);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date → portal timestamp ms.
|
|
3
|
+
* Epoch ms timezone-agnostic olsa da, sunucu GMT+3 beklediği için
|
|
4
|
+
* yerel offset düzeltmesi uygulanır (orders-date-window testi ile kilitli).
|
|
5
|
+
*/
|
|
6
|
+
export declare function toN11Gmt3Timestamp(date: Date): number;
|
|
7
|
+
export declare function resolveN11Date(value: Date | number): Date;
|
|
8
|
+
export declare function buildLookbackWindow(lookbackMs: number, now?: Date): {
|
|
9
|
+
startDate: number;
|
|
10
|
+
endDate: number;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/orders/date.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAErD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAa,GAAG;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAOA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** n11 portal: timestamp ms, GMT+3 (Europe/Istanbul) bağlamında. */
|
|
2
|
+
const N11_GMT3_OFFSET_MS = 3 * 60 * 60 * 1000;
|
|
3
|
+
/**
|
|
4
|
+
* Date → portal timestamp ms.
|
|
5
|
+
* Epoch ms timezone-agnostic olsa da, sunucu GMT+3 beklediği için
|
|
6
|
+
* yerel offset düzeltmesi uygulanır (orders-date-window testi ile kilitli).
|
|
7
|
+
*/
|
|
8
|
+
export function toN11Gmt3Timestamp(date) {
|
|
9
|
+
return date.getTime() + date.getTimezoneOffset() * 60_000 + N11_GMT3_OFFSET_MS;
|
|
10
|
+
}
|
|
11
|
+
export function resolveN11Date(value) {
|
|
12
|
+
return typeof value === "number" ? new Date(value) : value;
|
|
13
|
+
}
|
|
14
|
+
export function buildLookbackWindow(lookbackMs, now = new Date()) {
|
|
15
|
+
const end = resolveN11Date(now);
|
|
16
|
+
const start = new Date(end.getTime() - lookbackMs);
|
|
17
|
+
return {
|
|
18
|
+
startDate: toN11Gmt3Timestamp(start),
|
|
19
|
+
endDate: toN11Gmt3Timestamp(end),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { N11HttpClient } from "../http.js";
|
|
2
|
+
import type { N11Result } from "../types.js";
|
|
3
|
+
import type { N11LaborCostUpdateParams, N11LaborCostUpdateResponse } from "../types/orders.js";
|
|
4
|
+
type LaborCostOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
export declare function updateLaborCosts(http: N11HttpClient, params: N11LaborCostUpdateParams, options?: LaborCostOptions): Promise<N11Result<N11LaborCostUpdateResponse>>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=labor-cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labor-cost.d.ts","sourceRoot":"","sources":["../../src/orders/labor-cost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAG/F,KAAK,gBAAgB,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEjD,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC,CAuBhD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LABOR_COSTS_PATH } from "../orders/paths.js";
|
|
2
|
+
import { normalizeLaborCostUpdateResponse } from "../wire/normalize.js";
|
|
3
|
+
export async function updateLaborCosts(http, params, options) {
|
|
4
|
+
if (params.laborCostDetails.length < 1) {
|
|
5
|
+
return {
|
|
6
|
+
ok: false,
|
|
7
|
+
reason: "En az bir laborCostDetail gerekli.",
|
|
8
|
+
code: "EMPTY_DETAILS",
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const result = await http.requestJson({
|
|
12
|
+
resource: "rest",
|
|
13
|
+
method: "PUT",
|
|
14
|
+
path: LABOR_COSTS_PATH,
|
|
15
|
+
body: params,
|
|
16
|
+
retryPolicy: "none",
|
|
17
|
+
signal: options?.signal,
|
|
18
|
+
});
|
|
19
|
+
if (!result.ok) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
return { ok: true, data: normalizeLaborCostUpdateResponse(result.data) };
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { N11HttpClient } from "../http.js";
|
|
2
|
+
import type { N11Result } from "../types.js";
|
|
3
|
+
import type { N11ShipmentPackagesListParams, N11ShipmentPackagesListResponse } from "../types/orders.js";
|
|
4
|
+
type ListOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
export declare function serializeShipmentPackagesQuery(params: N11ShipmentPackagesListParams): Record<string, unknown>;
|
|
8
|
+
export declare function listShipmentPackages(http: N11HttpClient, params?: N11ShipmentPackagesListParams, options?: ListOptions): Promise<N11Result<N11ShipmentPackagesListResponse>>;
|
|
9
|
+
export declare function fetchShipmentPackagesPage(http: N11HttpClient, params: {
|
|
10
|
+
startDate: Date;
|
|
11
|
+
endDate?: Date;
|
|
12
|
+
status?: string;
|
|
13
|
+
orderByField?: boolean;
|
|
14
|
+
orderByDirection?: "ASC" | "DESC";
|
|
15
|
+
page: number;
|
|
16
|
+
pageSize: number;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<N11Result<{
|
|
19
|
+
items: N11ShipmentPackagesListResponse["content"];
|
|
20
|
+
hasMore: boolean;
|
|
21
|
+
}>>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/orders/list.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,6BAA6B,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAOzG,KAAK,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAE5C,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,6BAA6B,GACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BzB;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,MAAM,GAAE,6BAAkC,EAC1C,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC,CAqBrD;AAED,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE;IACN,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GACA,OAAO,CACR,SAAS,CAAC;IACR,KAAK,EAAE,+BAA+B,CAAC,SAAS,CAAC,CAAC;IAClD,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CACH,CAuBA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { N11_SHIPMENT_PACKAGES_DEFAULT_SIZE, N11_SHIPMENT_PACKAGES_MAX_SIZE, } from "../constants/page-limits.js";
|
|
2
|
+
import { resolveN11Date, toN11Gmt3Timestamp } from "../orders/date.js";
|
|
3
|
+
import { SHIPMENT_PACKAGES_PATH } from "../orders/paths.js";
|
|
4
|
+
import { computeShipmentPackagesHasMore, normalizeShipmentPackagesResponse, } from "../wire/normalize.js";
|
|
5
|
+
import { validateShipmentPackagesPageSize } from "../wire/validate.js";
|
|
6
|
+
export function serializeShipmentPackagesQuery(params) {
|
|
7
|
+
const query = {};
|
|
8
|
+
if (params.startDate !== undefined) {
|
|
9
|
+
query.startDate = toN11Gmt3Timestamp(resolveN11Date(params.startDate));
|
|
10
|
+
}
|
|
11
|
+
if (params.endDate !== undefined) {
|
|
12
|
+
query.endDate = toN11Gmt3Timestamp(resolveN11Date(params.endDate));
|
|
13
|
+
}
|
|
14
|
+
if (params.page !== undefined)
|
|
15
|
+
query.page = params.page;
|
|
16
|
+
query.size = params.size ?? N11_SHIPMENT_PACKAGES_DEFAULT_SIZE;
|
|
17
|
+
if (params.orderNumber !== undefined)
|
|
18
|
+
query.orderNumber = params.orderNumber;
|
|
19
|
+
if (params.packageIds !== undefined) {
|
|
20
|
+
query.packageIds = Array.isArray(params.packageIds)
|
|
21
|
+
? params.packageIds.join(",")
|
|
22
|
+
: params.packageIds;
|
|
23
|
+
}
|
|
24
|
+
if (params.status !== undefined)
|
|
25
|
+
query.status = params.status;
|
|
26
|
+
if (params.orderByDirection !== undefined) {
|
|
27
|
+
query.orderByDirection = params.orderByDirection;
|
|
28
|
+
}
|
|
29
|
+
if (params.orderByField !== undefined) {
|
|
30
|
+
query.orderByField = params.orderByField;
|
|
31
|
+
}
|
|
32
|
+
if (params.sender !== undefined)
|
|
33
|
+
query.sender = params.sender;
|
|
34
|
+
return query;
|
|
35
|
+
}
|
|
36
|
+
export async function listShipmentPackages(http, params = {}, options) {
|
|
37
|
+
const size = params.size ?? N11_SHIPMENT_PACKAGES_DEFAULT_SIZE;
|
|
38
|
+
const sizeValidation = validateShipmentPackagesPageSize(size);
|
|
39
|
+
if (!sizeValidation.ok) {
|
|
40
|
+
return sizeValidation;
|
|
41
|
+
}
|
|
42
|
+
const result = await http.requestJson({
|
|
43
|
+
resource: "rest",
|
|
44
|
+
method: "GET",
|
|
45
|
+
path: SHIPMENT_PACKAGES_PATH,
|
|
46
|
+
query: serializeShipmentPackagesQuery({ ...params, size }),
|
|
47
|
+
retryPolicy: "safe",
|
|
48
|
+
signal: options?.signal,
|
|
49
|
+
});
|
|
50
|
+
if (!result.ok) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, data: normalizeShipmentPackagesResponse(result.data) };
|
|
54
|
+
}
|
|
55
|
+
export async function fetchShipmentPackagesPage(http, params) {
|
|
56
|
+
const listParams = {
|
|
57
|
+
startDate: params.startDate,
|
|
58
|
+
endDate: params.endDate,
|
|
59
|
+
status: params.status,
|
|
60
|
+
orderByField: params.orderByField,
|
|
61
|
+
orderByDirection: params.orderByDirection,
|
|
62
|
+
page: params.page,
|
|
63
|
+
size: Math.min(params.pageSize, N11_SHIPMENT_PACKAGES_MAX_SIZE),
|
|
64
|
+
};
|
|
65
|
+
const result = await listShipmentPackages(http, listParams, { signal: params.signal });
|
|
66
|
+
if (!result.ok) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
ok: true,
|
|
71
|
+
data: {
|
|
72
|
+
items: result.data.content,
|
|
73
|
+
hasMore: computeShipmentPackagesHasMore(result.data, params.page, listParams.size ?? params.pageSize),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const SHIPMENT_PACKAGES_PATH = "/delivery/v1/shipmentPackages";
|
|
2
|
+
export declare const ORDER_UPDATE_PATH = "/order/v1/update";
|
|
3
|
+
export declare const COLLECTION_REQUEST_PATH = "/delivery/v1/collectionRequest";
|
|
4
|
+
export declare const SPLIT_COMBINE_PACKAGE_PATH = "/delivery/v1/splitCombinePackage";
|
|
5
|
+
export declare const SPLIT_PACKAGE_BY_QUANTITY_PATH = "/delivery/v1/splitPackageByQuantity";
|
|
6
|
+
export declare const LABOR_COSTS_PATH = "/order/v1/labor-costs";
|
|
7
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/orders/paths.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,kCAAkC,CAAC;AACtE,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AACpD,eAAO,MAAM,uBAAuB,mCAAmC,CAAC;AACxE,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAC7E,eAAO,MAAM,8BAA8B,wCAAwC,CAAC;AACpF,eAAO,MAAM,gBAAgB,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const SHIPMENT_PACKAGES_PATH = "/delivery/v1/shipmentPackages";
|
|
2
|
+
export const ORDER_UPDATE_PATH = "/order/v1/update";
|
|
3
|
+
export const COLLECTION_REQUEST_PATH = "/delivery/v1/collectionRequest";
|
|
4
|
+
export const SPLIT_COMBINE_PACKAGE_PATH = "/delivery/v1/splitCombinePackage";
|
|
5
|
+
export const SPLIT_PACKAGE_BY_QUANTITY_PATH = "/delivery/v1/splitPackageByQuantity";
|
|
6
|
+
export const LABOR_COSTS_PATH = "/order/v1/labor-costs";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { N11Result, WireRow } from "../types.js";
|
|
2
|
+
import type { N11OrderByDirection, N11ShipmentPackageStatus } from "../types/orders.js";
|
|
3
|
+
export type PollPackagesSinceOptions = {
|
|
4
|
+
lookbackMs?: number;
|
|
5
|
+
status?: N11ShipmentPackageStatus;
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
/** true → lastModifiedDate penceresi (poll varsayilan) */
|
|
8
|
+
orderByField?: boolean;
|
|
9
|
+
orderByDirection?: N11OrderByDirection;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
export type PackagesListFetcher = (params: {
|
|
13
|
+
startDate: Date;
|
|
14
|
+
endDate: Date;
|
|
15
|
+
status?: string;
|
|
16
|
+
orderByField?: boolean;
|
|
17
|
+
orderByDirection?: N11OrderByDirection;
|
|
18
|
+
page: number;
|
|
19
|
+
pageSize: number;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}) => Promise<N11Result<{
|
|
22
|
+
items: WireRow<Record<string, unknown>>[];
|
|
23
|
+
hasMore: boolean;
|
|
24
|
+
}>>;
|
|
25
|
+
/**
|
|
26
|
+
* Poll-primary reconciler — webhook yok (G2).
|
|
27
|
+
* orderByField varsayilan true: lastModifiedDate penceresi.
|
|
28
|
+
*/
|
|
29
|
+
export declare function pollPackagesSince(fetchPage: PackagesListFetcher, options?: PollPackagesSinceOptions): AsyncGenerator<N11Result<WireRow<Record<string, unknown>>>>;
|
|
30
|
+
//# sourceMappingURL=reconciler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconciler.d.ts","sourceRoot":"","sources":["../../src/orders/reconciler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAExF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE;IACzC,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,KAAK,OAAO,CACX,SAAS,CAAC;IACR,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CACH,CAAC;AAEF;;;GAGG;AACH,wBAAuB,iBAAiB,CACtC,SAAS,EAAE,mBAAmB,EAC9B,OAAO,CAAC,EAAE,wBAAwB,GACjC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAoC7D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { N11_DEFAULT_ORDER_LOOKBACK_MS } from "../constants/defaults.js";
|
|
2
|
+
import { N11_SHIPMENT_PACKAGES_DEFAULT_SIZE } from "../constants/page-limits.js";
|
|
3
|
+
/**
|
|
4
|
+
* Poll-primary reconciler — webhook yok (G2).
|
|
5
|
+
* orderByField varsayilan true: lastModifiedDate penceresi.
|
|
6
|
+
*/
|
|
7
|
+
export async function* pollPackagesSince(fetchPage, options) {
|
|
8
|
+
const lookbackMs = options?.lookbackMs ?? N11_DEFAULT_ORDER_LOOKBACK_MS;
|
|
9
|
+
const endDate = new Date();
|
|
10
|
+
const startDate = new Date(endDate.getTime() - lookbackMs);
|
|
11
|
+
const pageSize = options?.pageSize ?? N11_SHIPMENT_PACKAGES_DEFAULT_SIZE;
|
|
12
|
+
const orderByField = options?.orderByField ?? true;
|
|
13
|
+
for (let page = 0;; page += 1) {
|
|
14
|
+
if (options?.signal?.aborted) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const result = await fetchPage({
|
|
18
|
+
startDate,
|
|
19
|
+
endDate,
|
|
20
|
+
status: options?.status,
|
|
21
|
+
orderByField,
|
|
22
|
+
orderByDirection: options?.orderByDirection,
|
|
23
|
+
page,
|
|
24
|
+
pageSize,
|
|
25
|
+
signal: options?.signal,
|
|
26
|
+
});
|
|
27
|
+
if (!result.ok) {
|
|
28
|
+
yield result;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const item of result.data.items) {
|
|
32
|
+
yield { ok: true, data: item };
|
|
33
|
+
}
|
|
34
|
+
if (!result.data.hasMore) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { N11HttpClient } from "../http.js";
|
|
2
|
+
import type { N11Result } from "../types.js";
|
|
3
|
+
import type { N11CollectionRequestParams, N11CollectionRequestResponse, N11SplitCombinePackageParams, N11SplitPackageByQuantityParams, N11SplitPackageResponse } from "../types/orders.js";
|
|
4
|
+
type ShippingOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
export declare function createCollectionRequest(http: N11HttpClient, params: N11CollectionRequestParams, options?: ShippingOptions): Promise<N11Result<N11CollectionRequestResponse>>;
|
|
8
|
+
export declare function splitCombinePackage(http: N11HttpClient, params: N11SplitCombinePackageParams, options?: ShippingOptions): Promise<N11Result<N11SplitPackageResponse>>;
|
|
9
|
+
export declare function splitPackageByQuantity(http: N11HttpClient, params: N11SplitPackageByQuantityParams, options?: ShippingOptions): Promise<N11Result<N11SplitPackageResponse>>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=shipping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shipping.d.ts","sourceRoot":"","sources":["../../src/orders/shipping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,+BAA+B,EAC/B,uBAAuB,EACxB,MAAM,oBAAoB,CAAC;AAM5B,KAAK,eAAe,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEhD,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,0BAA0B,EAClC,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC,CAuBlD;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,CAmB7C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,CAmB7C"}
|