@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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type Brand = {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
export type BrandsListResponse = {
|
|
6
|
+
brands?: Brand[];
|
|
7
|
+
content?: Brand[];
|
|
8
|
+
page?: number;
|
|
9
|
+
size?: number;
|
|
10
|
+
totalElements?: number;
|
|
11
|
+
totalPages?: number;
|
|
12
|
+
};
|
|
13
|
+
export type GetBrandsParams = {
|
|
14
|
+
page?: number;
|
|
15
|
+
size?: number;
|
|
16
|
+
};
|
|
17
|
+
export type GetBrandsByNameParams = {
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
export type CreateBrandParams = {
|
|
21
|
+
name: string;
|
|
22
|
+
/** 1–3 gorsel (resmi dokuman). */
|
|
23
|
+
images: Blob[];
|
|
24
|
+
};
|
|
25
|
+
export type CategoryAttribute = {
|
|
26
|
+
attributeId: number;
|
|
27
|
+
attributeName: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
allowCustom?: boolean;
|
|
30
|
+
varianter?: boolean;
|
|
31
|
+
slicer?: boolean;
|
|
32
|
+
attributeValues?: CategoryAttributeValue[];
|
|
33
|
+
};
|
|
34
|
+
export type CategoryAttributeValue = {
|
|
35
|
+
id: number;
|
|
36
|
+
name: string;
|
|
37
|
+
};
|
|
38
|
+
export type CategoryAttributesResponse = {
|
|
39
|
+
categoryAttributes?: CategoryAttribute[];
|
|
40
|
+
id?: number;
|
|
41
|
+
name?: string;
|
|
42
|
+
};
|
|
43
|
+
export type CategoryAttributeValuesResponse = {
|
|
44
|
+
attributeValues?: CategoryAttributeValue[];
|
|
45
|
+
};
|
|
46
|
+
export type SupplierAddress = {
|
|
47
|
+
id: number;
|
|
48
|
+
title?: string;
|
|
49
|
+
addressType?: string;
|
|
50
|
+
country?: string;
|
|
51
|
+
city?: string;
|
|
52
|
+
district?: string;
|
|
53
|
+
postalCode?: string;
|
|
54
|
+
fullAddress?: string;
|
|
55
|
+
isDefault?: boolean;
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
};
|
|
58
|
+
export type SupplierAddressesResponse = SupplierAddress[] | {
|
|
59
|
+
addresses?: SupplierAddress[];
|
|
60
|
+
};
|
|
61
|
+
export type CargoProvider = {
|
|
62
|
+
id: number;
|
|
63
|
+
name: string;
|
|
64
|
+
code?: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
export type CargoProvidersResponse = CargoProvider[] | {
|
|
68
|
+
cargoProviders?: CargoProvider[];
|
|
69
|
+
};
|
|
70
|
+
export type GeoItem = {
|
|
71
|
+
id: number;
|
|
72
|
+
name: string;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
};
|
|
75
|
+
export type GeoListResponse = GeoItem[] | {
|
|
76
|
+
content?: GeoItem[];
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../src/types/reference.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC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M,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,aAAa,EAAE,GAAG;IAAE,cAAc,CAAC,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,EAAE,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ShipmentPackage } from "./orders.js";
|
|
2
|
+
/** Trendyol webhook kayit API'sinde kullanilan auth tipi. */
|
|
3
|
+
export type WebhookAuthenticationType = "BASIC_AUTHENTICATION" | "API_KEY";
|
|
4
|
+
/** Portal webhook kayit durumu. */
|
|
5
|
+
export type WebhookRegistrationStatus = "ACTIVE" | "PASSIVE";
|
|
6
|
+
/**
|
|
7
|
+
* Webhook abonelik statuleri — API UPPER_SNAKE formati.
|
|
8
|
+
* Bos gonderilirse tum statuler otomatik atanir.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WEBHOOK_SUBSCRIBED_STATUSES: readonly ["CREATED", "PICKING", "INVOICED", "SHIPPED", "CANCELLED", "DELIVERED", "UNDELIVERED", "RETURNED", "UNSUPPLIED", "AWAITING", "UNPACKED", "AT_COLLECTION_POINT", "VERIFIED"];
|
|
11
|
+
export type WebhookSubscribedStatus = (typeof WEBHOOK_SUBSCRIBED_STATUSES)[number];
|
|
12
|
+
export type CreateWebhookBody = {
|
|
13
|
+
url: string;
|
|
14
|
+
authenticationType: WebhookAuthenticationType;
|
|
15
|
+
username?: string;
|
|
16
|
+
password?: string;
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
subscribedStatuses?: WebhookSubscribedStatus[] | string[];
|
|
19
|
+
};
|
|
20
|
+
export type UpdateWebhookBody = CreateWebhookBody;
|
|
21
|
+
export type CreateWebhookResponse = {
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
export type WebhookRegistration = {
|
|
25
|
+
id: string;
|
|
26
|
+
createdDate?: number;
|
|
27
|
+
lastModifiedDate?: number | null;
|
|
28
|
+
url?: string;
|
|
29
|
+
username?: string;
|
|
30
|
+
authenticationType?: WebhookAuthenticationType;
|
|
31
|
+
status?: WebhookRegistrationStatus;
|
|
32
|
+
subscribedStatuses?: string[] | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Inbound webhook POST govdesi — siparis paketi semasi ile ayni.
|
|
36
|
+
* @see https://developers.trendyol.com/docs/webhook-model.md
|
|
37
|
+
*/
|
|
38
|
+
export type WebhookPayload = ShipmentPackage;
|
|
39
|
+
export type WebhookParseErrorCode = "INVALID_PAYLOAD" | "INVALID_SCHEMA";
|
|
40
|
+
export type WebhookParseResult = {
|
|
41
|
+
ok: true;
|
|
42
|
+
data: WebhookPayload;
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
error: WebhookParseErrorCode;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/types/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,6DAA6D;AAC7D,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,GAAG,SAAS,CAAC;AAE3E,mCAAmC;AACnC,MAAM,MAAM,yBAAyB,GAAG,QAAQ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CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook abonelik statuleri — API UPPER_SNAKE formati.
|
|
3
|
+
* Bos gonderilirse tum statuler otomatik atanir.
|
|
4
|
+
*/
|
|
5
|
+
export const WEBHOOK_SUBSCRIBED_STATUSES = [
|
|
6
|
+
"CREATED",
|
|
7
|
+
"PICKING",
|
|
8
|
+
"INVOICED",
|
|
9
|
+
"SHIPPED",
|
|
10
|
+
"CANCELLED",
|
|
11
|
+
"DELIVERED",
|
|
12
|
+
"UNDELIVERED",
|
|
13
|
+
"RETURNED",
|
|
14
|
+
"UNSUPPLIED",
|
|
15
|
+
"AWAITING",
|
|
16
|
+
"UNPACKED",
|
|
17
|
+
"AT_COLLECTION_POINT",
|
|
18
|
+
"VERIFIED",
|
|
19
|
+
];
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type TrendyolEnv = "production" | "stage";
|
|
2
|
+
export type RetryPolicy = "safe" | "none";
|
|
3
|
+
export type TrendyolResult<T> = {
|
|
4
|
+
ok: true;
|
|
5
|
+
data: T;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
reason: string;
|
|
9
|
+
code?: string | number;
|
|
10
|
+
status?: number;
|
|
11
|
+
raw?: unknown;
|
|
12
|
+
retryable?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type TrendyolConfig = {
|
|
15
|
+
sellerId: string;
|
|
16
|
+
apiKey: string;
|
|
17
|
+
apiSecret: string;
|
|
18
|
+
env: TrendyolEnv;
|
|
19
|
+
integratorName: string;
|
|
20
|
+
storeFrontCode: string;
|
|
21
|
+
gatewayBase: string;
|
|
22
|
+
requestTimeoutMs: number;
|
|
23
|
+
debug: boolean;
|
|
24
|
+
maxRetries: number;
|
|
25
|
+
retryBaseMs: number;
|
|
26
|
+
enableClientSideLimiter: boolean;
|
|
27
|
+
maxWebhookBodyBytes: number;
|
|
28
|
+
};
|
|
29
|
+
export type HttpRequestOptions = {
|
|
30
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
31
|
+
path: string;
|
|
32
|
+
query?: Record<string, unknown>;
|
|
33
|
+
body?: unknown;
|
|
34
|
+
retryPolicy: RetryPolicy;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
};
|
|
38
|
+
export type PageParams = {
|
|
39
|
+
page?: number;
|
|
40
|
+
size?: number;
|
|
41
|
+
};
|
|
42
|
+
export type CursorPage<T> = {
|
|
43
|
+
items: T[];
|
|
44
|
+
nextCursor?: string;
|
|
45
|
+
};
|
|
46
|
+
export type TokenPage<T> = {
|
|
47
|
+
items: T[];
|
|
48
|
+
nextPageToken?: string;
|
|
49
|
+
totalElements?: number;
|
|
50
|
+
totalPages?: number;
|
|
51
|
+
};
|
|
52
|
+
export type TrendyolLogger = (level: "debug" | "info" | "warn" | "error", message: string, meta?: Record<string, unknown>) => void;
|
|
53
|
+
export type TrendyolHooks = {
|
|
54
|
+
onRetry?: (meta: {
|
|
55
|
+
attempt: number;
|
|
56
|
+
status?: number;
|
|
57
|
+
delayMs: number;
|
|
58
|
+
}) => void;
|
|
59
|
+
onRateLimitHit?: (meta: {
|
|
60
|
+
retryAfterMs?: number;
|
|
61
|
+
}) => void;
|
|
62
|
+
onBatchPoll?: (meta: {
|
|
63
|
+
batchRequestId: string;
|
|
64
|
+
attempt: number;
|
|
65
|
+
}) => void;
|
|
66
|
+
};
|
|
67
|
+
export type CategoryTreeNode = {
|
|
68
|
+
id: number;
|
|
69
|
+
name: string;
|
|
70
|
+
subCategories?: CategoryTreeNode[];
|
|
71
|
+
};
|
|
72
|
+
export type CategoryTreeResponse = CategoryTreeNode[];
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,M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AC;CACpC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,EAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PageLimitEndpoint } from "./constants/page-limits.js";
|
|
2
|
+
import type { TrendyolResult } from "./types.js";
|
|
3
|
+
export declare function validateSellerId(sellerId: string): TrendyolResult<void>;
|
|
4
|
+
export declare function validateEan13(barcode: string): TrendyolResult<void>;
|
|
5
|
+
export declare function validatePageSize(endpoint: PageLimitEndpoint, size: number): TrendyolResult<void>;
|
|
6
|
+
export declare function validateQuantity(quantity: number): TrendyolResult<void>;
|
|
7
|
+
export declare function validatePrices(listPrice: number, salePrice: number): TrendyolResult<void>;
|
|
8
|
+
export declare function validateBatchSize(count: number, max?: number): TrendyolResult<void>;
|
|
9
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAQvE;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAmBnE;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,MAAM,GACX,cAAc,CAAC,IAAI,CAAC,CAYtB;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAWvE;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAWzF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAKjF"}
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MAX_PAGE_SIZE, } from "./constants/page-limits.js";
|
|
2
|
+
export function validateSellerId(sellerId) {
|
|
3
|
+
if (!sellerId.trim()) {
|
|
4
|
+
return { ok: false, reason: "sellerId bos olamaz." };
|
|
5
|
+
}
|
|
6
|
+
if (!/^\d+$/.test(sellerId.trim())) {
|
|
7
|
+
return { ok: false, reason: "sellerId sayisal olmalidir." };
|
|
8
|
+
}
|
|
9
|
+
return { ok: true, data: undefined };
|
|
10
|
+
}
|
|
11
|
+
export function validateEan13(barcode) {
|
|
12
|
+
const normalized = barcode.trim();
|
|
13
|
+
if (!/^\d{13}$/.test(normalized)) {
|
|
14
|
+
return { ok: false, reason: "EAN-13 13 haneli sayisal olmalidir." };
|
|
15
|
+
}
|
|
16
|
+
const digits = normalized.split("").map(Number);
|
|
17
|
+
const check = digits.pop();
|
|
18
|
+
const sum = digits.reduce((acc, digit, index) => {
|
|
19
|
+
const weight = index % 2 === 0 ? 1 : 3;
|
|
20
|
+
return acc + digit * weight;
|
|
21
|
+
}, 0);
|
|
22
|
+
const calculated = (10 - (sum % 10)) % 10;
|
|
23
|
+
if (calculated !== check) {
|
|
24
|
+
return { ok: false, reason: "EAN-13 kontrol hanesi gecersiz." };
|
|
25
|
+
}
|
|
26
|
+
return { ok: true, data: undefined };
|
|
27
|
+
}
|
|
28
|
+
export function validatePageSize(endpoint, size) {
|
|
29
|
+
const max = MAX_PAGE_SIZE[endpoint];
|
|
30
|
+
if (!Number.isFinite(size) || size < 1) {
|
|
31
|
+
return { ok: false, reason: "page size en az 1 olmalidir." };
|
|
32
|
+
}
|
|
33
|
+
if (size > max) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
reason: `page size ${endpoint} icin en fazla ${max} olabilir.`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return { ok: true, data: undefined };
|
|
40
|
+
}
|
|
41
|
+
export function validateQuantity(quantity) {
|
|
42
|
+
if (!Number.isFinite(quantity)) {
|
|
43
|
+
return { ok: false, reason: "quantity sayisal olmalidir." };
|
|
44
|
+
}
|
|
45
|
+
if (quantity < 0) {
|
|
46
|
+
return { ok: false, reason: "quantity negatif olamaz." };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* quantity === 0 satisi durdurabilir — adapter uyariyi CONFORMANCE'tan okur.
|
|
50
|
+
*/
|
|
51
|
+
return { ok: true, data: undefined };
|
|
52
|
+
}
|
|
53
|
+
export function validatePrices(listPrice, salePrice) {
|
|
54
|
+
if (!Number.isFinite(listPrice) || listPrice <= 0) {
|
|
55
|
+
return { ok: false, reason: "listPrice pozitif olmalidir." };
|
|
56
|
+
}
|
|
57
|
+
if (!Number.isFinite(salePrice) || salePrice <= 0) {
|
|
58
|
+
return { ok: false, reason: "salePrice pozitif olmalidir." };
|
|
59
|
+
}
|
|
60
|
+
if (salePrice > listPrice) {
|
|
61
|
+
return { ok: false, reason: "salePrice listPrice degerini gecemez." };
|
|
62
|
+
}
|
|
63
|
+
return { ok: true, data: undefined };
|
|
64
|
+
}
|
|
65
|
+
export function validateBatchSize(count, max = 1000) {
|
|
66
|
+
if (count < 1 || count > max) {
|
|
67
|
+
return { ok: false, reason: `batch en fazla ${max} oge icerebilir.` };
|
|
68
|
+
}
|
|
69
|
+
return { ok: true, data: undefined };
|
|
70
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TrendyolHttpClient } from "../http.js";
|
|
2
|
+
import type { TrendyolConfig, TrendyolResult } from "../types.js";
|
|
3
|
+
type VideoOptions = {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
};
|
|
6
|
+
export type CreateVideoBody = {
|
|
7
|
+
contentIds: number[];
|
|
8
|
+
};
|
|
9
|
+
export type CreateVideoResponse = {
|
|
10
|
+
videoId?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type VideoListItem = {
|
|
14
|
+
videoId?: string;
|
|
15
|
+
status?: string;
|
|
16
|
+
contentIds?: number[];
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
export type ListVideosResponse = {
|
|
20
|
+
content?: VideoListItem[];
|
|
21
|
+
videos?: VideoListItem[];
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
export type WaitForVideoOptions = {
|
|
25
|
+
intervalMs?: number;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Video API — `/integration/video` gateway.
|
|
31
|
+
*/
|
|
32
|
+
export declare class VideoApi {
|
|
33
|
+
private readonly http;
|
|
34
|
+
private readonly config;
|
|
35
|
+
constructor(http: TrendyolHttpClient, config: TrendyolConfig);
|
|
36
|
+
/** POST /video/sellers/{id}/videos — max 100 contentId; async videoId doner. */
|
|
37
|
+
createVideo(body: CreateVideoBody, options?: VideoOptions): Promise<TrendyolResult<CreateVideoResponse>>;
|
|
38
|
+
/** GET /video/sellers/{id}/videos — durum sorgulama. */
|
|
39
|
+
listVideos(options?: VideoOptions): Promise<TrendyolResult<ListVideosResponse>>;
|
|
40
|
+
/**
|
|
41
|
+
* listVideos uzerinden poll — batch waitForResult simetrisi.
|
|
42
|
+
*/
|
|
43
|
+
waitForVideoReady(videoId: string, options?: WaitForVideoOptions): Promise<TrendyolResult<VideoListItem>>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/video/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kB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U,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAS/E;;OAEG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;CAkC1C"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { validateBatchSize } from "../validate.js";
|
|
2
|
+
import { videosPath } from "./paths.js";
|
|
3
|
+
const MAX_CONTENT_IDS = 100;
|
|
4
|
+
const DEFAULT_VIDEO_INTERVAL_MS = 3_000;
|
|
5
|
+
const DEFAULT_VIDEO_TIMEOUT_MS = 300_000;
|
|
6
|
+
const TERMINAL_VIDEO_STATUSES = new Set([
|
|
7
|
+
"READY",
|
|
8
|
+
"FAILED",
|
|
9
|
+
"REJECTED",
|
|
10
|
+
"CANCELLED",
|
|
11
|
+
"CANCELED",
|
|
12
|
+
"COMPLETED",
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Video API — `/integration/video` gateway.
|
|
16
|
+
*/
|
|
17
|
+
export class VideoApi {
|
|
18
|
+
http;
|
|
19
|
+
config;
|
|
20
|
+
constructor(http, config) {
|
|
21
|
+
this.http = http;
|
|
22
|
+
this.config = config;
|
|
23
|
+
}
|
|
24
|
+
/** POST /video/sellers/{id}/videos — max 100 contentId; async videoId doner. */
|
|
25
|
+
createVideo(body, options) {
|
|
26
|
+
const batchValidation = validateBatchSize(body.contentIds.length, MAX_CONTENT_IDS);
|
|
27
|
+
if (!batchValidation.ok) {
|
|
28
|
+
return Promise.resolve(batchValidation);
|
|
29
|
+
}
|
|
30
|
+
return this.http.requestJson({
|
|
31
|
+
method: "POST",
|
|
32
|
+
path: videosPath(this.config.sellerId),
|
|
33
|
+
body,
|
|
34
|
+
retryPolicy: "none",
|
|
35
|
+
signal: options?.signal,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** GET /video/sellers/{id}/videos — durum sorgulama. */
|
|
39
|
+
listVideos(options) {
|
|
40
|
+
return this.http.requestJson({
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: videosPath(this.config.sellerId),
|
|
43
|
+
retryPolicy: "safe",
|
|
44
|
+
signal: options?.signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* listVideos uzerinden poll — batch waitForResult simetrisi.
|
|
49
|
+
*/
|
|
50
|
+
async waitForVideoReady(videoId, options) {
|
|
51
|
+
const intervalMs = options?.intervalMs ?? DEFAULT_VIDEO_INTERVAL_MS;
|
|
52
|
+
const timeoutMs = options?.timeoutMs ?? DEFAULT_VIDEO_TIMEOUT_MS;
|
|
53
|
+
const deadline = Date.now() + timeoutMs;
|
|
54
|
+
while (Date.now() < deadline) {
|
|
55
|
+
if (options?.signal?.aborted) {
|
|
56
|
+
return { ok: false, reason: "Video poll iptal edildi.", code: "ABORTED" };
|
|
57
|
+
}
|
|
58
|
+
const listResult = await this.listVideos({ signal: options?.signal });
|
|
59
|
+
if (!listResult.ok) {
|
|
60
|
+
return listResult;
|
|
61
|
+
}
|
|
62
|
+
const items = normalizeVideoList(listResult.data);
|
|
63
|
+
const match = items.find((v) => v.videoId === videoId);
|
|
64
|
+
if (match) {
|
|
65
|
+
const status = match.status?.toUpperCase();
|
|
66
|
+
if (status && TERMINAL_VIDEO_STATUSES.has(status)) {
|
|
67
|
+
return { ok: true, data: match };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
await videoSleep(intervalMs, options?.signal);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
reason: `Video poll zaman asimi (${timeoutMs}ms): ${videoId}`,
|
|
75
|
+
code: "VIDEO_POLL_TIMEOUT",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function normalizeVideoList(response) {
|
|
80
|
+
return response.content ?? response.videos ?? [];
|
|
81
|
+
}
|
|
82
|
+
function videoSleep(ms, signal) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
if (signal?.aborted) {
|
|
85
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const timer = setTimeout(resolve, ms);
|
|
89
|
+
const onAbort = () => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
92
|
+
};
|
|
93
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/video/paths.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { WebhookParseResult, WebhookPayload } from "../types/webhooks.js";
|
|
2
|
+
export declare class WebhookPayloadTooLargeError extends Error {
|
|
3
|
+
readonly maxBytes: number;
|
|
4
|
+
readonly actualBytes: number;
|
|
5
|
+
constructor(actualBytes: number, maxBytes: number);
|
|
6
|
+
}
|
|
7
|
+
export type ParseWebhookPayloadOptions = {
|
|
8
|
+
maxWebhookBodyBytes?: number;
|
|
9
|
+
};
|
|
10
|
+
export type VerifyWebhookApiKeyOptions = {
|
|
11
|
+
headerName?: string;
|
|
12
|
+
};
|
|
13
|
+
export type WebhookHeaderSource = Record<string, string | string[] | undefined> | Headers;
|
|
14
|
+
/**
|
|
15
|
+
* Inbound webhook JSON govdesini parse eder.
|
|
16
|
+
* Boyut limiti asiminda {@link WebhookPayloadTooLargeError} firlatir.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseWebhookPayload(body: string | Buffer | Uint8Array, options?: ParseWebhookPayloadOptions): WebhookParseResult;
|
|
19
|
+
/** Webhook payload type guard — zorunlu alanlar: shipmentPackageId, status. */
|
|
20
|
+
export declare function isWebhookPayload(body: unknown): body is WebhookPayload;
|
|
21
|
+
/** Payload'dan paket statu degerini cikarir. */
|
|
22
|
+
export declare function extractPackageStatus(payload: WebhookPayload): string;
|
|
23
|
+
/**
|
|
24
|
+
* Inbound webhook API key dogrulama.
|
|
25
|
+
* Varsayilan header: `x-api-key` (Trendyol dokumani).
|
|
26
|
+
*/
|
|
27
|
+
export declare function verifyWebhookApiKey(headers: WebhookHeaderSource, expectedKey: string, options?: VerifyWebhookApiKeyOptions): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Inbound webhook Basic Authentication dogrulama.
|
|
30
|
+
* `Authorization: Basic base64(user:pass)` formatini bekler.
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifyWebhookBasicAuth(headers: WebhookHeaderSource, username: string, password: string): boolean;
|
|
33
|
+
//# sourceMappingURL=inbound.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound.d.ts","sourceRoot":"","sources":["../../src/webhooks/inbound.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAMlD;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GAC7C,OAAO,CAAC;AAiCZ;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,EAClC,OAAO,CAAC,EAAE,0BAA0B,GACnC,kBAAkB,CAyBpB;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAUtE;AAED,gDAAgD;AAChD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAEpE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,mBAAmB,EAC5B,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAKT;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAoBT"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { TRENDYOL_DEFAULT_MAX_WEBHOOK_BYTES } from "../constants.js";
|
|
2
|
+
export class WebhookPayloadTooLargeError extends Error {
|
|
3
|
+
maxBytes;
|
|
4
|
+
actualBytes;
|
|
5
|
+
constructor(actualBytes, maxBytes) {
|
|
6
|
+
super(`Webhook body ${actualBytes} byte — limit ${maxBytes} byte`);
|
|
7
|
+
this.name = "WebhookPayloadTooLargeError";
|
|
8
|
+
this.maxBytes = maxBytes;
|
|
9
|
+
this.actualBytes = actualBytes;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function bodyByteLength(body) {
|
|
13
|
+
if (typeof body === "string") {
|
|
14
|
+
return Buffer.byteLength(body, "utf8");
|
|
15
|
+
}
|
|
16
|
+
return body.byteLength;
|
|
17
|
+
}
|
|
18
|
+
function bodyToString(body) {
|
|
19
|
+
if (typeof body === "string")
|
|
20
|
+
return body;
|
|
21
|
+
return Buffer.from(body).toString("utf8");
|
|
22
|
+
}
|
|
23
|
+
function getHeaderValue(headers, name) {
|
|
24
|
+
const lower = name.toLowerCase();
|
|
25
|
+
if (headers instanceof Headers) {
|
|
26
|
+
return headers.get(name) ?? headers.get(lower) ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
29
|
+
if (key.toLowerCase() !== lower)
|
|
30
|
+
continue;
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
return Array.isArray(value) ? value[0] : value;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Inbound webhook JSON govdesini parse eder.
|
|
39
|
+
* Boyut limiti asiminda {@link WebhookPayloadTooLargeError} firlatir.
|
|
40
|
+
*/
|
|
41
|
+
export function parseWebhookPayload(body, options) {
|
|
42
|
+
const maxBytes = options?.maxWebhookBodyBytes ?? TRENDYOL_DEFAULT_MAX_WEBHOOK_BYTES;
|
|
43
|
+
const byteLength = bodyByteLength(body);
|
|
44
|
+
if (byteLength > maxBytes) {
|
|
45
|
+
throw new WebhookPayloadTooLargeError(byteLength, maxBytes);
|
|
46
|
+
}
|
|
47
|
+
const text = bodyToString(body).trim();
|
|
48
|
+
if (text.length === 0) {
|
|
49
|
+
return { ok: false, error: "INVALID_PAYLOAD" };
|
|
50
|
+
}
|
|
51
|
+
let parsed;
|
|
52
|
+
try {
|
|
53
|
+
parsed = JSON.parse(text);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return { ok: false, error: "INVALID_PAYLOAD" };
|
|
57
|
+
}
|
|
58
|
+
if (!isWebhookPayload(parsed)) {
|
|
59
|
+
return { ok: false, error: "INVALID_SCHEMA" };
|
|
60
|
+
}
|
|
61
|
+
return { ok: true, data: parsed };
|
|
62
|
+
}
|
|
63
|
+
/** Webhook payload type guard — zorunlu alanlar: shipmentPackageId, status. */
|
|
64
|
+
export function isWebhookPayload(body) {
|
|
65
|
+
if (!body || typeof body !== "object")
|
|
66
|
+
return false;
|
|
67
|
+
const record = body;
|
|
68
|
+
return (record.shipmentPackageId !== undefined &&
|
|
69
|
+
record.shipmentPackageId !== null &&
|
|
70
|
+
record.status !== undefined &&
|
|
71
|
+
record.status !== null &&
|
|
72
|
+
String(record.status).length > 0);
|
|
73
|
+
}
|
|
74
|
+
/** Payload'dan paket statu degerini cikarir. */
|
|
75
|
+
export function extractPackageStatus(payload) {
|
|
76
|
+
return String(payload.status);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Inbound webhook API key dogrulama.
|
|
80
|
+
* Varsayilan header: `x-api-key` (Trendyol dokumani).
|
|
81
|
+
*/
|
|
82
|
+
export function verifyWebhookApiKey(headers, expectedKey, options) {
|
|
83
|
+
const headerName = options?.headerName ?? "x-api-key";
|
|
84
|
+
const received = getHeaderValue(headers, headerName);
|
|
85
|
+
if (received === undefined)
|
|
86
|
+
return false;
|
|
87
|
+
return received === expectedKey;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Inbound webhook Basic Authentication dogrulama.
|
|
91
|
+
* `Authorization: Basic base64(user:pass)` formatini bekler.
|
|
92
|
+
*/
|
|
93
|
+
export function verifyWebhookBasicAuth(headers, username, password) {
|
|
94
|
+
const authorization = getHeaderValue(headers, "authorization");
|
|
95
|
+
if (!authorization)
|
|
96
|
+
return false;
|
|
97
|
+
const match = /^Basic\s+(.+)$/i.exec(authorization.trim());
|
|
98
|
+
if (!match)
|
|
99
|
+
return false;
|
|
100
|
+
let decoded;
|
|
101
|
+
try {
|
|
102
|
+
decoded = Buffer.from(match[1], "base64").toString("utf8");
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const colonIndex = decoded.indexOf(":");
|
|
108
|
+
if (colonIndex < 0)
|
|
109
|
+
return false;
|
|
110
|
+
const user = decoded.slice(0, colonIndex);
|
|
111
|
+
const pass = decoded.slice(colonIndex + 1);
|
|
112
|
+
return user === username && pass === password;
|
|
113
|
+
}
|