@hubcommerce/trendyol 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 +47 -0
- package/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/batch/poller.d.ts +23 -0
- package/dist/batch/poller.d.ts.map +1 -0
- package/dist/batch/poller.js +85 -0
- package/dist/batch/report.d.ts +15 -0
- package/dist/batch/report.d.ts.map +1 -0
- package/dist/batch/report.js +41 -0
- package/dist/batch/types.d.ts +4 -0
- package/dist/batch/types.d.ts.map +1 -0
- package/dist/batch/types.js +2 -0
- package/dist/claims/api.d.ts +48 -0
- package/dist/claims/api.d.ts.map +1 -0
- package/dist/claims/api.js +116 -0
- package/dist/claims/form.d.ts +9 -0
- package/dist/claims/form.d.ts.map +1 -0
- package/dist/claims/form.js +20 -0
- package/dist/claims/paths.d.ts +3 -0
- package/dist/claims/paths.d.ts.map +1 -0
- package/dist/claims/paths.js +8 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +66 -0
- package/dist/compensation/api.d.ts +17 -0
- package/dist/compensation/api.d.ts.map +1 -0
- package/dist/compensation/api.js +37 -0
- package/dist/compensation/paths.d.ts +2 -0
- package/dist/compensation/paths.d.ts.map +1 -0
- package/dist/compensation/paths.js +4 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +78 -0
- package/dist/connection.d.ts +4 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +8 -0
- package/dist/constants/claim-reasons.d.ts +10 -0
- package/dist/constants/claim-reasons.d.ts.map +1 -0
- package/dist/constants/claim-reasons.js +43 -0
- package/dist/constants/error-codes.d.ts +3 -0
- package/dist/constants/error-codes.d.ts.map +1 -0
- package/dist/constants/error-codes.js +9 -0
- package/dist/constants/origins.d.ts +6 -0
- package/dist/constants/origins.d.ts.map +1 -0
- package/dist/constants/origins.js +6 -0
- package/dist/constants/package-status.d.ts +3 -0
- package/dist/constants/package-status.d.ts.map +1 -0
- package/dist/constants/package-status.js +15 -0
- package/dist/constants/page-limits.d.ts +3 -0
- package/dist/constants/page-limits.d.ts.map +1 -0
- package/dist/constants/page-limits.js +9 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +17 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +113 -0
- package/dist/finance/api.d.ts +39 -0
- package/dist/finance/api.d.ts.map +1 -0
- package/dist/finance/api.js +165 -0
- package/dist/finance/paths.d.ts +6 -0
- package/dist/finance/paths.d.ts.map +1 -0
- package/dist/finance/paths.js +16 -0
- package/dist/http/multipart.d.ts +10 -0
- package/dist/http/multipart.d.ts.map +1 -0
- package/dist/http/multipart.js +1 -0
- package/dist/http/query.d.ts +5 -0
- package/dist/http/query.d.ts.map +1 -0
- package/dist/http/query.js +24 -0
- package/dist/http/response.d.ts +9 -0
- package/dist/http/response.d.ts.map +1 -0
- package/dist/http/response.js +37 -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 +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +180 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/inventory/api.d.ts +26 -0
- package/dist/inventory/api.d.ts.map +1 -0
- package/dist/inventory/api.js +51 -0
- package/dist/inventory/paths.d.ts +2 -0
- package/dist/inventory/paths.d.ts.map +1 -0
- package/dist/inventory/paths.js +4 -0
- package/dist/invoices/api.d.ts +23 -0
- package/dist/invoices/api.d.ts.map +1 -0
- package/dist/invoices/api.js +52 -0
- package/dist/labels/api.d.ts +45 -0
- package/dist/labels/api.d.ts.map +1 -0
- package/dist/labels/api.js +89 -0
- package/dist/labels/paths.d.ts +3 -0
- package/dist/labels/paths.d.ts.map +1 -0
- package/dist/labels/paths.js +7 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +47 -0
- package/dist/orders/api.d.ts +68 -0
- package/dist/orders/api.d.ts.map +1 -0
- package/dist/orders/api.js +69 -0
- package/dist/orders/created-by.d.ts +4 -0
- package/dist/orders/created-by.d.ts.map +1 -0
- package/dist/orders/created-by.js +9 -0
- package/dist/orders/mutations.d.ts +31 -0
- package/dist/orders/mutations.d.ts.map +1 -0
- package/dist/orders/mutations.js +139 -0
- package/dist/orders/paths.d.ts +4 -0
- package/dist/orders/paths.d.ts.map +1 -0
- package/dist/orders/paths.js +12 -0
- package/dist/orders/read.d.ts +35 -0
- package/dist/orders/read.d.ts.map +1 -0
- package/dist/orders/read.js +140 -0
- package/dist/orders/split.d.ts +17 -0
- package/dist/orders/split.d.ts.map +1 -0
- package/dist/orders/split.js +45 -0
- package/dist/orders/status.d.ts +9 -0
- package/dist/orders/status.d.ts.map +1 -0
- package/dist/orders/status.js +20 -0
- package/dist/orders/stream.d.ts +19 -0
- package/dist/orders/stream.d.ts.map +1 -0
- package/dist/orders/stream.js +26 -0
- package/dist/orders/warranty.d.ts +24 -0
- package/dist/orders/warranty.d.ts.map +1 -0
- package/dist/orders/warranty.js +30 -0
- package/dist/pagination.d.ts +23 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +34 -0
- package/dist/products/api.d.ts +52 -0
- package/dist/products/api.d.ts.map +1 -0
- package/dist/products/api.js +222 -0
- package/dist/products/builder.d.ts +22 -0
- package/dist/products/builder.d.ts.map +1 -0
- package/dist/products/builder.js +89 -0
- package/dist/products/paths.d.ts +7 -0
- package/dist/products/paths.d.ts.map +1 -0
- package/dist/products/paths.js +20 -0
- package/dist/qna/api.d.ts +32 -0
- package/dist/qna/api.d.ts.map +1 -0
- package/dist/qna/api.js +78 -0
- package/dist/qna/paths.d.ts +5 -0
- package/dist/qna/paths.d.ts.map +1 -0
- package/dist/qna/paths.js +13 -0
- package/dist/rate-limit/governor.d.ts +11 -0
- package/dist/rate-limit/governor.d.ts.map +1 -0
- package/dist/rate-limit/governor.js +25 -0
- package/dist/rate-limit/groups.d.ts +15 -0
- package/dist/rate-limit/groups.d.ts.map +1 -0
- package/dist/rate-limit/groups.js +14 -0
- package/dist/reference/addresses-cache.d.ts +13 -0
- package/dist/reference/addresses-cache.d.ts.map +1 -0
- package/dist/reference/addresses-cache.js +33 -0
- package/dist/reference/api.d.ts +48 -0
- package/dist/reference/api.d.ts.map +1 -0
- package/dist/reference/api.js +215 -0
- package/dist/reference/paths.d.ts +12 -0
- package/dist/reference/paths.d.ts.map +1 -0
- package/dist/reference/paths.js +34 -0
- package/dist/retry.d.ts +6 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +37 -0
- package/dist/testing/fixtures/batch-partial-fail.json +12 -0
- package/dist/testing/fixtures/shipment-package.json +5 -0
- package/dist/testing/fixtures/webhook-payload.json +4 -0
- package/dist/testing/fixtures.d.ts +23 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +9 -0
- package/dist/testing/guard.d.ts +13 -0
- package/dist/testing/guard.d.ts.map +1 -0
- package/dist/testing/guard.js +32 -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/paths.d.ts +5 -0
- package/dist/testing/paths.d.ts.map +1 -0
- package/dist/testing/paths.js +14 -0
- package/dist/testing/stage-helpers.d.ts +24 -0
- package/dist/testing/stage-helpers.d.ts.map +1 -0
- package/dist/testing/stage-helpers.js +64 -0
- package/dist/testing/types.d.ts +66 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +1 -0
- package/dist/types/claims.d.ts +132 -0
- package/dist/types/claims.d.ts.map +1 -0
- package/dist/types/claims.js +1 -0
- package/dist/types/compensation.d.ts +32 -0
- package/dist/types/compensation.d.ts.map +1 -0
- package/dist/types/compensation.js +20 -0
- package/dist/types/finance.d.ts +98 -0
- package/dist/types/finance.d.ts.map +1 -0
- package/dist/types/finance.js +1 -0
- package/dist/types/inventory.d.ts +12 -0
- package/dist/types/inventory.d.ts.map +1 -0
- package/dist/types/inventory.js +1 -0
- package/dist/types/labels.d.ts +19 -0
- package/dist/types/labels.d.ts.map +1 -0
- package/dist/types/labels.js +1 -0
- package/dist/types/orders.d.ts +276 -0
- package/dist/types/orders.d.ts.map +1 -0
- package/dist/types/orders.js +1 -0
- package/dist/types/products.d.ts +99 -0
- package/dist/types/products.d.ts.map +1 -0
- package/dist/types/products.js +1 -0
- package/dist/types/qna.d.ts +51 -0
- package/dist/types/qna.d.ts.map +1 -0
- package/dist/types/qna.js +6 -0
- package/dist/types/reference.d.ts +78 -0
- package/dist/types/reference.d.ts.map +1 -0
- package/dist/types/reference.js +1 -0
- package/dist/types/webhooks.d.ts +47 -0
- package/dist/types/webhooks.d.ts.map +1 -0
- package/dist/types/webhooks.js +19 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/validate.d.ts +9 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +70 -0
- package/dist/video/api.d.ts +46 -0
- package/dist/video/api.d.ts.map +1 -0
- package/dist/video/api.js +95 -0
- package/dist/video/paths.d.ts +3 -0
- package/dist/video/paths.d.ts.map +1 -0
- package/dist/video/paths.js +7 -0
- package/dist/webhooks/inbound.d.ts +33 -0
- package/dist/webhooks/inbound.d.ts.map +1 -0
- package/dist/webhooks/inbound.js +113 -0
- package/dist/webhooks/management.d.ts +49 -0
- package/dist/webhooks/management.d.ts.map +1 -0
- package/dist/webhooks/management.js +89 -0
- package/dist/webhooks/paths.d.ts +5 -0
- package/dist/webhooks/paths.d.ts.map +1 -0
- package/dist/webhooks/paths.js +13 -0
- package/package.json +47 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { lookupErrorMessage } from "./constants/error-codes.js";
|
|
2
|
+
export class TrendyolApiError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
raw;
|
|
6
|
+
retryable;
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "TrendyolApiError";
|
|
10
|
+
this.status = options.status;
|
|
11
|
+
this.code = options.code;
|
|
12
|
+
this.raw = options.raw;
|
|
13
|
+
this.retryable = options.retryable ?? false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class TrendyolTransportError extends Error {
|
|
17
|
+
retryable;
|
|
18
|
+
constructor(message, options) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "TrendyolTransportError";
|
|
21
|
+
this.retryable = options?.retryable ?? true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function isHtmlErrorBody(body) {
|
|
25
|
+
if (typeof body !== "string")
|
|
26
|
+
return false;
|
|
27
|
+
const trimmed = body.trim().toLowerCase();
|
|
28
|
+
return trimmed.startsWith("<!doctype html") || trimmed.startsWith("<html");
|
|
29
|
+
}
|
|
30
|
+
export function isHtmlGatewayError(error) {
|
|
31
|
+
if (error instanceof TrendyolApiError) {
|
|
32
|
+
if (typeof error.raw === "string" && isHtmlErrorBody(error.raw)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (error.status === 403 && typeof error.raw === "string") {
|
|
36
|
+
return isHtmlErrorBody(error.raw);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
export function isTransientGatewayError(error) {
|
|
42
|
+
if (error instanceof TrendyolApiError) {
|
|
43
|
+
return isHtmlGatewayError(error) || error.status === 429 || error.status >= 500;
|
|
44
|
+
}
|
|
45
|
+
return isRetryableError(error);
|
|
46
|
+
}
|
|
47
|
+
export function parseApiError(status, body, headers) {
|
|
48
|
+
void headers;
|
|
49
|
+
const record = body && typeof body === "object" ? body : {};
|
|
50
|
+
const code = record.code ??
|
|
51
|
+
record.errorCode ??
|
|
52
|
+
record.error_code;
|
|
53
|
+
const mapped = lookupErrorMessage(code);
|
|
54
|
+
const message = mapped ??
|
|
55
|
+
(typeof record.message === "string" ? record.message : undefined) ??
|
|
56
|
+
(typeof record.errorMessage === "string" ? record.errorMessage : undefined) ??
|
|
57
|
+
(typeof body === "string" && !isHtmlErrorBody(body) ? body : undefined) ??
|
|
58
|
+
`Trendyol API hatasi (HTTP ${status}).`;
|
|
59
|
+
return new TrendyolApiError(message, {
|
|
60
|
+
status,
|
|
61
|
+
code,
|
|
62
|
+
raw: body,
|
|
63
|
+
retryable: isRetryableStatus(status) || isHtmlErrorBody(body),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function isRetryableStatus(status) {
|
|
67
|
+
return status === 429 || status >= 500;
|
|
68
|
+
}
|
|
69
|
+
export function isRetryableError(error) {
|
|
70
|
+
if (error instanceof TrendyolApiError) {
|
|
71
|
+
return error.retryable || isHtmlGatewayError(error);
|
|
72
|
+
}
|
|
73
|
+
if (error instanceof TrendyolTransportError) {
|
|
74
|
+
return error.retryable;
|
|
75
|
+
}
|
|
76
|
+
if (error instanceof Error) {
|
|
77
|
+
if (error.name === "AbortError" || error.name === "TimeoutError") {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const msg = error.message.toLowerCase();
|
|
81
|
+
if (msg.includes("timeout") || msg.includes("network") || msg.includes("fetch failed")) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
export function toFailure(error, fallbackReason = "Trendyol istegi basarisiz.") {
|
|
88
|
+
if (error instanceof TrendyolApiError) {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
reason: error.message,
|
|
92
|
+
code: error.code,
|
|
93
|
+
status: error.status,
|
|
94
|
+
raw: error.raw,
|
|
95
|
+
retryable: error.retryable,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (error instanceof TrendyolTransportError) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
reason: error.message,
|
|
102
|
+
retryable: error.retryable,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (error instanceof Error) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
reason: error.message || fallbackReason,
|
|
109
|
+
retryable: isRetryableError(error),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { ok: false, reason: fallbackReason, retryable: false };
|
|
113
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TrendyolHttpClient } from "../http.js";
|
|
2
|
+
import type { TrendyolConfig, TrendyolResult } from "../types.js";
|
|
3
|
+
import type { CargoInvoiceItemsResponse, FinancePageResponse, GetCargoInvoiceItemsParams, GetOtherFinancialsParams, GetPaymentOrdersParams, GetSettlementDetailsParams, GetSettlementsParams, PaymentOrdersResponse, SettlementDetails } from "../types/finance.js";
|
|
4
|
+
/**
|
|
5
|
+
* Finans (cari hesap ekstresi) API.
|
|
6
|
+
* Base: /integration/finance/che/sellers/{sellerId}
|
|
7
|
+
*/
|
|
8
|
+
export declare class FinanceApi {
|
|
9
|
+
private readonly http;
|
|
10
|
+
private readonly config;
|
|
11
|
+
constructor(http: TrendyolHttpClient, config: TrendyolConfig);
|
|
12
|
+
/**
|
|
13
|
+
* PAID odeme emirlerini sayfali listeler (size max 10).
|
|
14
|
+
* GET .../payment-order
|
|
15
|
+
*/
|
|
16
|
+
getPaymentOrders(params?: GetPaymentOrdersParams): Promise<TrendyolResult<PaymentOrdersResponse>>;
|
|
17
|
+
/**
|
|
18
|
+
* Satis, iade, indirim, kupon, provizyon islemleri.
|
|
19
|
+
* GET .../settlements
|
|
20
|
+
*/
|
|
21
|
+
getSettlements(params?: GetSettlementsParams): Promise<TrendyolResult<FinancePageResponse>>;
|
|
22
|
+
/**
|
|
23
|
+
* Tedarikci finansmani, virman, odemeler, faturalar vb.
|
|
24
|
+
* GET .../otherfinancials
|
|
25
|
+
*/
|
|
26
|
+
getOtherFinancials(params?: GetOtherFinancialsParams): Promise<TrendyolResult<FinancePageResponse>>;
|
|
27
|
+
/**
|
|
28
|
+
* Kargo faturasi satir detaylari.
|
|
29
|
+
* GET .../cargo-invoice/{invoiceSerialNumber}/items
|
|
30
|
+
*
|
|
31
|
+
* Seri numarasi: otherfinancials DeductionInvoices kayitlarindan.
|
|
32
|
+
*/
|
|
33
|
+
getCargoInvoiceItems(invoiceSerialNumber: string, params?: GetCargoInvoiceItemsParams): Promise<TrendyolResult<CargoInvoiceItemsResponse>>;
|
|
34
|
+
/**
|
|
35
|
+
* paymentOrderId ile settlements + otherfinancials birlestirir.
|
|
36
|
+
*/
|
|
37
|
+
getSettlementDetails(paymentOrderId: number, params?: GetSettlementDetailsParams): Promise<TrendyolResult<SettlementDetails>>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/finance/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACnB,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAsD7B;;;GAGG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,cAAc;IAGzC;;;OAGG;IACH,gBAAgB,CACd,MAAM,CAAC,EAAE,sBAAsB,GAC9B,OAAO,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;IAsBjD;;;OAGG;IACH,cAAc,CACZ,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAkB/C;;;OAGG;IACH,kBAAkB,CAChB,MAAM,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAkB/C;;;;;OAKG;IACH,oBAAoB,CAClB,mBAAmB,EAAE,MAAM,EAC3B,MAAM,CAAC,EAAE,0BAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC;IAcrD;;OAEG;IACG,oBAAoB,CACxB,cAAc,EAAE,MAAM,EACtB,MAAM,CAAC,EAAE,0BAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;CAiC9C"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { validatePageSize } from "../validate.js";
|
|
2
|
+
import { cargoInvoiceItemsPath, otherFinancialsPath, paymentOrdersPath, settlementsPath, } from "./paths.js";
|
|
3
|
+
const MAX_FINANCE_DATE_RANGE_MS = 15 * 24 * 60 * 60 * 1000;
|
|
4
|
+
function buildFinanceQuery(params) {
|
|
5
|
+
const query = {};
|
|
6
|
+
if (params.transactionType !== undefined) {
|
|
7
|
+
query.transactionType = params.transactionType;
|
|
8
|
+
}
|
|
9
|
+
if (params.transactionTypes !== undefined) {
|
|
10
|
+
query.transactionTypes = params.transactionTypes;
|
|
11
|
+
}
|
|
12
|
+
if ("transactionSubType" in params && params.transactionSubType !== undefined) {
|
|
13
|
+
query.transactionSubType = params.transactionSubType;
|
|
14
|
+
}
|
|
15
|
+
if (params.startDate !== undefined)
|
|
16
|
+
query.startDate = params.startDate;
|
|
17
|
+
if (params.endDate !== undefined)
|
|
18
|
+
query.endDate = params.endDate;
|
|
19
|
+
if (params.paymentDate !== undefined)
|
|
20
|
+
query.paymentDate = params.paymentDate;
|
|
21
|
+
if (params.paymentOrderId !== undefined) {
|
|
22
|
+
query.paymentOrderId = params.paymentOrderId;
|
|
23
|
+
}
|
|
24
|
+
if (params.page !== undefined)
|
|
25
|
+
query.page = params.page;
|
|
26
|
+
if (params.size !== undefined)
|
|
27
|
+
query.size = params.size;
|
|
28
|
+
return query;
|
|
29
|
+
}
|
|
30
|
+
function validateFinanceDateRange(startDate, endDate) {
|
|
31
|
+
if (startDate === undefined || endDate === undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (endDate < startDate) {
|
|
35
|
+
return { ok: false, reason: "endDate startDate degerinden once olamaz." };
|
|
36
|
+
}
|
|
37
|
+
if (endDate - startDate > MAX_FINANCE_DATE_RANGE_MS) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reason: "startDate ve endDate arasi en fazla 15 gun olabilir.",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return { ok: true, data: undefined };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Finans (cari hesap ekstresi) API.
|
|
47
|
+
* Base: /integration/finance/che/sellers/{sellerId}
|
|
48
|
+
*/
|
|
49
|
+
export class FinanceApi {
|
|
50
|
+
http;
|
|
51
|
+
config;
|
|
52
|
+
constructor(http, config) {
|
|
53
|
+
this.http = http;
|
|
54
|
+
this.config = config;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* PAID odeme emirlerini sayfali listeler (size max 10).
|
|
58
|
+
* GET .../payment-order
|
|
59
|
+
*/
|
|
60
|
+
getPaymentOrders(params) {
|
|
61
|
+
const size = params?.size ?? 10;
|
|
62
|
+
const pageValidation = validatePageSize("finance.paymentOrder", size);
|
|
63
|
+
if (!pageValidation.ok) {
|
|
64
|
+
return Promise.resolve(pageValidation);
|
|
65
|
+
}
|
|
66
|
+
const query = {};
|
|
67
|
+
if (params?.page !== undefined)
|
|
68
|
+
query.page = params.page;
|
|
69
|
+
query.size = size;
|
|
70
|
+
return this.http.requestJson({
|
|
71
|
+
method: "GET",
|
|
72
|
+
path: paymentOrdersPath(this.config.sellerId),
|
|
73
|
+
query,
|
|
74
|
+
retryPolicy: "safe",
|
|
75
|
+
signal: params?.signal,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Satis, iade, indirim, kupon, provizyon islemleri.
|
|
80
|
+
* GET .../settlements
|
|
81
|
+
*/
|
|
82
|
+
getSettlements(params) {
|
|
83
|
+
const rangeValidation = validateFinanceDateRange(params?.startDate, params?.endDate);
|
|
84
|
+
if (rangeValidation && !rangeValidation.ok) {
|
|
85
|
+
return Promise.resolve(rangeValidation);
|
|
86
|
+
}
|
|
87
|
+
return this.http.requestJson({
|
|
88
|
+
method: "GET",
|
|
89
|
+
path: settlementsPath(this.config.sellerId),
|
|
90
|
+
query: buildFinanceQuery(params ?? {}),
|
|
91
|
+
retryPolicy: "safe",
|
|
92
|
+
signal: params?.signal,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Tedarikci finansmani, virman, odemeler, faturalar vb.
|
|
97
|
+
* GET .../otherfinancials
|
|
98
|
+
*/
|
|
99
|
+
getOtherFinancials(params) {
|
|
100
|
+
const rangeValidation = validateFinanceDateRange(params?.startDate, params?.endDate);
|
|
101
|
+
if (rangeValidation && !rangeValidation.ok) {
|
|
102
|
+
return Promise.resolve(rangeValidation);
|
|
103
|
+
}
|
|
104
|
+
return this.http.requestJson({
|
|
105
|
+
method: "GET",
|
|
106
|
+
path: otherFinancialsPath(this.config.sellerId),
|
|
107
|
+
query: buildFinanceQuery(params ?? {}),
|
|
108
|
+
retryPolicy: "safe",
|
|
109
|
+
signal: params?.signal,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Kargo faturasi satir detaylari.
|
|
114
|
+
* GET .../cargo-invoice/{invoiceSerialNumber}/items
|
|
115
|
+
*
|
|
116
|
+
* Seri numarasi: otherfinancials DeductionInvoices kayitlarindan.
|
|
117
|
+
*/
|
|
118
|
+
getCargoInvoiceItems(invoiceSerialNumber, params) {
|
|
119
|
+
const query = {};
|
|
120
|
+
if (params?.page !== undefined)
|
|
121
|
+
query.page = params.page;
|
|
122
|
+
if (params?.size !== undefined)
|
|
123
|
+
query.size = params.size;
|
|
124
|
+
return this.http.requestJson({
|
|
125
|
+
method: "GET",
|
|
126
|
+
path: cargoInvoiceItemsPath(this.config.sellerId, invoiceSerialNumber),
|
|
127
|
+
query,
|
|
128
|
+
retryPolicy: "safe",
|
|
129
|
+
signal: params?.signal,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* paymentOrderId ile settlements + otherfinancials birlestirir.
|
|
134
|
+
*/
|
|
135
|
+
async getSettlementDetails(paymentOrderId, params) {
|
|
136
|
+
const baseQuery = {
|
|
137
|
+
paymentOrderId,
|
|
138
|
+
signal: params?.signal,
|
|
139
|
+
};
|
|
140
|
+
const [settlementsResult, otherFinancialsResult] = await Promise.all([
|
|
141
|
+
this.getSettlements({
|
|
142
|
+
...baseQuery,
|
|
143
|
+
transactionTypes: params?.settlementTransactionTypes,
|
|
144
|
+
}),
|
|
145
|
+
this.getOtherFinancials({
|
|
146
|
+
...baseQuery,
|
|
147
|
+
transactionTypes: params?.otherFinancialTransactionTypes,
|
|
148
|
+
}),
|
|
149
|
+
]);
|
|
150
|
+
if (!settlementsResult.ok) {
|
|
151
|
+
return settlementsResult;
|
|
152
|
+
}
|
|
153
|
+
if (!otherFinancialsResult.ok) {
|
|
154
|
+
return otherFinancialsResult;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
ok: true,
|
|
158
|
+
data: {
|
|
159
|
+
paymentOrderId,
|
|
160
|
+
settlements: settlementsResult.data.content ?? [],
|
|
161
|
+
otherFinancials: otherFinancialsResult.data.content ?? [],
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function financeSellerBase(sellerId: string): string;
|
|
2
|
+
export declare function paymentOrdersPath(sellerId: string): string;
|
|
3
|
+
export declare function settlementsPath(sellerId: string): string;
|
|
4
|
+
export declare function otherFinancialsPath(sellerId: string): string;
|
|
5
|
+
export declare function cargoInvoiceItemsPath(sellerId: string, invoiceSerialNumber: string): string;
|
|
6
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/finance/paths.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,GAC1B,MAAM,CAER"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TRENDYOL_FINANCE_PREFIX } from "../constants.js";
|
|
2
|
+
export function financeSellerBase(sellerId) {
|
|
3
|
+
return `${TRENDYOL_FINANCE_PREFIX}/sellers/${sellerId}`;
|
|
4
|
+
}
|
|
5
|
+
export function paymentOrdersPath(sellerId) {
|
|
6
|
+
return `${financeSellerBase(sellerId)}/payment-order`;
|
|
7
|
+
}
|
|
8
|
+
export function settlementsPath(sellerId) {
|
|
9
|
+
return `${financeSellerBase(sellerId)}/settlements`;
|
|
10
|
+
}
|
|
11
|
+
export function otherFinancialsPath(sellerId) {
|
|
12
|
+
return `${financeSellerBase(sellerId)}/otherfinancials`;
|
|
13
|
+
}
|
|
14
|
+
export function cargoInvoiceItemsPath(sellerId, invoiceSerialNumber) {
|
|
15
|
+
return `${financeSellerBase(sellerId)}/cargo-invoice/${encodeURIComponent(invoiceSerialNumber)}/items`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type MultipartRequestOptions = {
|
|
2
|
+
method: "POST" | "PUT" | "PATCH";
|
|
3
|
+
path: string;
|
|
4
|
+
formData: FormData;
|
|
5
|
+
query?: Record<string, unknown>;
|
|
6
|
+
retryPolicy: "safe" | "none";
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/http/multipart.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/http/query.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAwBlE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query builder — Date → unix ms; string[] → comma-separated; null/undefined omit.
|
|
3
|
+
*/
|
|
4
|
+
export function buildQuery(params) {
|
|
5
|
+
const parts = [];
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
if (value === undefined || value === null) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (value instanceof Date) {
|
|
11
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value.getTime()))}`);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
if (value.length === 0)
|
|
16
|
+
continue;
|
|
17
|
+
const serialized = value.map((item) => String(item)).join(",");
|
|
18
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(serialized)}`);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
22
|
+
}
|
|
23
|
+
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ParsedResponse<T> = {
|
|
2
|
+
data: T | null;
|
|
3
|
+
status: number;
|
|
4
|
+
headers: Headers;
|
|
5
|
+
rawText: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function readResponseBody(response: Response): Promise<string>;
|
|
8
|
+
export declare function parseJsonResponse<T>(response: Response, rawText?: string): Promise<ParsedResponse<T>>;
|
|
9
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/http/response.ts"],"names":[],"mappings":"AAEA,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;CACjB,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1E;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAiC5B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TrendyolApiError } from "../errors.js";
|
|
2
|
+
export async function readResponseBody(response) {
|
|
3
|
+
return response.text();
|
|
4
|
+
}
|
|
5
|
+
export async function parseJsonResponse(response, rawText) {
|
|
6
|
+
const text = rawText ?? (await readResponseBody(response));
|
|
7
|
+
const contentType = response.headers.get("content-type")?.toLowerCase() ?? "";
|
|
8
|
+
if (response.status === 204 || text.length === 0) {
|
|
9
|
+
return { data: null, status: response.status, headers: response.headers, rawText: text };
|
|
10
|
+
}
|
|
11
|
+
if (contentType.includes("application/json") || contentType.includes("+json") || !contentType) {
|
|
12
|
+
try {
|
|
13
|
+
const data = JSON.parse(text);
|
|
14
|
+
return { data, status: response.status, headers: response.headers, rawText: text };
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new TrendyolApiError("Gecersiz JSON yaniti.", {
|
|
18
|
+
status: response.status,
|
|
19
|
+
code: "INVALID_JSON",
|
|
20
|
+
raw: text,
|
|
21
|
+
retryable: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const data = JSON.parse(text);
|
|
27
|
+
return { data, status: response.status, headers: response.headers, rawText: text };
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new TrendyolApiError("Beklenmeyen Content-Type.", {
|
|
31
|
+
status: response.status,
|
|
32
|
+
code: "UNEXPECTED_CONTENT_TYPE",
|
|
33
|
+
raw: text,
|
|
34
|
+
retryable: false,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -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,14 @@
|
|
|
1
|
+
import type { MultipartRequestOptions } from "./http/multipart.js";
|
|
2
|
+
import type { RateLimitGovernor } from "./rate-limit/governor.js";
|
|
3
|
+
import type { HttpRequestOptions, TrendyolConfig, TrendyolHooks, TrendyolResult } from "./types.js";
|
|
4
|
+
export declare class TrendyolHttpClient {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly governor?;
|
|
7
|
+
private hooks;
|
|
8
|
+
constructor(config: TrendyolConfig, governor?: RateLimitGovernor | undefined);
|
|
9
|
+
setHooks(hooks: TrendyolHooks): void;
|
|
10
|
+
getHooks(): TrendyolHooks;
|
|
11
|
+
requestJson<T>(options: HttpRequestOptions): Promise<TrendyolResult<T>>;
|
|
12
|
+
requestMultipart<T>(options: MultipartRequestOptions): Promise<TrendyolResult<T>>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAKnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,qBAAa,kBAAkB;IAI3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAJ5B,OAAO,CAAC,KAAK,CAAqB;gBAGf,MAAM,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,iBAAiB,YAAA;IAG/C,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAIpC,QAAQ,IAAI,aAAa;IAInB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IA6HvE,gBAAgB,CAAC,CAAC,EACtB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;CA+E9B"}
|