@lonca/trendyol 0.5.0 → 0.6.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/dist/index.cjs +115 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +170 -12
- package/dist/index.d.ts +170 -12
- package/dist/index.js +114 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -451,15 +451,56 @@ interface DeleteInvoiceLinkInput {
|
|
|
451
451
|
[key: string]: unknown;
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
|
-
* One row from
|
|
455
|
-
*
|
|
454
|
+
* One row from Trendyol's current-account statement — returned by both
|
|
455
|
+
* `finance.getSettlements()` and `finance.getOtherFinancials()` (both
|
|
456
|
+
* endpoints share the `FinancialTransaction` wire schema).
|
|
457
|
+
*
|
|
458
|
+
* Field set verified against the spec on 2026-05-25. The SDK exposes the
|
|
459
|
+
* stable subset; anything Trendyol adds later remains accessible via `raw`.
|
|
456
460
|
*/
|
|
457
|
-
interface
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
interface FinancialTransaction {
|
|
462
|
+
/** Transaction ID (string per Trendyol). */
|
|
463
|
+
id: string;
|
|
464
|
+
/** ISO 8601 UTC (from ms-epoch `transactionDate`). */
|
|
465
|
+
transactionDate?: string;
|
|
466
|
+
/** Product barcode when the transaction is tied to a SKU. */
|
|
467
|
+
barcode?: string | null;
|
|
468
|
+
/** Transaction category (e.g. `'Satış'`, `'Ödeme'`). */
|
|
469
|
+
transactionType?: string;
|
|
470
|
+
/** Receipt ID ("dekont no") when applicable. */
|
|
471
|
+
receiptId?: number | null;
|
|
472
|
+
description?: string | null;
|
|
473
|
+
/** Debit amount on the seller's account. */
|
|
474
|
+
debt?: number;
|
|
475
|
+
/** Credit amount on the seller's account. */
|
|
476
|
+
credit?: number;
|
|
477
|
+
paymentPeriod?: number | null;
|
|
478
|
+
commissionRate?: number | null;
|
|
479
|
+
commissionAmount?: number | null;
|
|
480
|
+
commissionInvoiceSerialNumber?: string | null;
|
|
481
|
+
/** Net seller revenue after Trendyol's cut. */
|
|
482
|
+
sellerRevenue?: number | null;
|
|
483
|
+
orderNumber?: string | null;
|
|
484
|
+
paymentOrderId?: number | null;
|
|
485
|
+
/** ISO 8601 UTC (from ms-epoch `paymentDate`). */
|
|
486
|
+
paymentDate?: string;
|
|
487
|
+
sellerId?: number;
|
|
488
|
+
storeId?: number | null;
|
|
489
|
+
storeName?: string | null;
|
|
490
|
+
storeAddress?: string | null;
|
|
491
|
+
country?: string | null;
|
|
492
|
+
/** Untouched raw row — pull any undocumented fields from here. */
|
|
461
493
|
raw: Record<string, unknown>;
|
|
462
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Aliases preserved for source-compatibility with `0.5.0`. Both legacy
|
|
497
|
+
* names now resolve to the unified `FinancialTransaction`.
|
|
498
|
+
*
|
|
499
|
+
* @deprecated since `0.5.1` — use `FinancialTransaction`.
|
|
500
|
+
*/
|
|
501
|
+
type SettlementRow = FinancialTransaction;
|
|
502
|
+
/** @deprecated since `0.5.1` — use `FinancialTransaction`. */
|
|
503
|
+
type OtherFinancialRow = FinancialTransaction;
|
|
463
504
|
/**
|
|
464
505
|
* Shared filter shape for both finance endpoints.
|
|
465
506
|
* `transactionType` lets you scope to one settlement category.
|
|
@@ -476,7 +517,19 @@ interface CreateCommonLabelInput {
|
|
|
476
517
|
/** Volumetric height (height × width × depth / 3000 → desi). */
|
|
477
518
|
volumetricHeight?: number;
|
|
478
519
|
}
|
|
520
|
+
/** One label entry inside a `CommonLabel` response. */
|
|
521
|
+
interface CommonLabelEntry {
|
|
522
|
+
/** Encoded label payload (e.g. ZPL string `^XA...^XZ`). */
|
|
523
|
+
label: string;
|
|
524
|
+
format: 'ZPL' | (string & {});
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Response from `labels.getCommon()` — Trendyol's wire shape is
|
|
528
|
+
* `{ data: [{ label, format }] }`. SDK surfaces the array directly via
|
|
529
|
+
* `labels` for ergonomic access; `raw` is the untouched response.
|
|
530
|
+
*/
|
|
479
531
|
interface CommonLabel {
|
|
532
|
+
labels: CommonLabelEntry[];
|
|
480
533
|
raw: Record<string, unknown>;
|
|
481
534
|
}
|
|
482
535
|
/**
|
|
@@ -524,16 +577,16 @@ interface Neighborhood {
|
|
|
524
577
|
* Trendyol finance endpoints — current-account-statement settlements and
|
|
525
578
|
* "other financials" (cargo invoices, labor cost adjustments, etc.).
|
|
526
579
|
*
|
|
527
|
-
* Both
|
|
528
|
-
*
|
|
580
|
+
* Both endpoints return the same `FinancialTransaction` shape on the wire,
|
|
581
|
+
* so the SDK exposes one typed surface for them.
|
|
529
582
|
*/
|
|
530
583
|
declare class FinanceResource {
|
|
531
584
|
private readonly transport;
|
|
532
585
|
private readonly sellerId;
|
|
533
586
|
private readonly limiter;
|
|
534
587
|
constructor(transport: TrendyolTransport, sellerId: number, limiter?: TokenBucketRateLimiter);
|
|
535
|
-
getSettlements(params?: ListFinanceParams): Promise<CursorPage<
|
|
536
|
-
getOtherFinancials(params?: ListFinanceParams): Promise<CursorPage<
|
|
588
|
+
getSettlements(params?: ListFinanceParams): Promise<CursorPage<FinancialTransaction>>;
|
|
589
|
+
getOtherFinancials(params?: ListFinanceParams): Promise<CursorPage<FinancialTransaction>>;
|
|
537
590
|
private queryPage;
|
|
538
591
|
}
|
|
539
592
|
|
|
@@ -631,7 +684,14 @@ declare class LabelsResource {
|
|
|
631
684
|
* @throws {ValidationError} when `format` is missing.
|
|
632
685
|
*/
|
|
633
686
|
createCommon(cargoTrackingNumber: string | number, input: CreateCommonLabelInput): Promise<unknown>;
|
|
634
|
-
/**
|
|
687
|
+
/**
|
|
688
|
+
* Retrieve the previously-created common label. Trendyol returns
|
|
689
|
+
* `{ data: [{ label, format }] }`; the SDK surfaces the array as
|
|
690
|
+
* `labels[]` for ergonomic access.
|
|
691
|
+
*
|
|
692
|
+
* Typically `labels.length === 1` per tracking number, but kept as an
|
|
693
|
+
* array to match the wire shape.
|
|
694
|
+
*/
|
|
635
695
|
getCommon(cargoTrackingNumber: string | number): Promise<CommonLabel>;
|
|
636
696
|
}
|
|
637
697
|
|
|
@@ -1016,6 +1076,16 @@ interface ListOrdersParams extends CursorPaginationParams {
|
|
|
1016
1076
|
/** Filter packages updated on or before this date. */
|
|
1017
1077
|
endDate?: Date;
|
|
1018
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Normalize one raw Trendyol shipment-package node into the public
|
|
1081
|
+
* `ShipmentPackage` shape. Exported so consumers handling Trendyol
|
|
1082
|
+
* webhooks can reuse the SDK's normalization logic on the event body
|
|
1083
|
+
* (Trendyol POSTs the same shape it returns from `getShipmentPackages`).
|
|
1084
|
+
*
|
|
1085
|
+
* For full-webhook parsing use `parseWebhookEvent(rawBody)` from the
|
|
1086
|
+
* top-level package, which calls this internally per item.
|
|
1087
|
+
*/
|
|
1088
|
+
declare function normalizeShipmentPackage(rawNode: unknown): ShipmentPackage;
|
|
1019
1089
|
/**
|
|
1020
1090
|
* Trendyol order (shipment-package) endpoints.
|
|
1021
1091
|
*
|
|
@@ -2133,4 +2203,92 @@ interface TrendyolClient {
|
|
|
2133
2203
|
*/
|
|
2134
2204
|
declare function createTrendyolClient(opts: CreateClientOptions): TrendyolClient;
|
|
2135
2205
|
|
|
2136
|
-
|
|
2206
|
+
/**
|
|
2207
|
+
* Inbound webhook event payloads — what Trendyol POSTs to YOUR endpoint
|
|
2208
|
+
* when a subscribed shipment-package status event fires.
|
|
2209
|
+
*
|
|
2210
|
+
* Per Trendyol's "Webhook Model" doc:
|
|
2211
|
+
* - Method: POST, body: JSON
|
|
2212
|
+
* - Wire shape: identical to `getShipmentPackages` response envelope
|
|
2213
|
+
* (`{ totalElements, totalPages, page, size, content: [...] }`)
|
|
2214
|
+
* - Sent on every status transition for a subscribed status (see
|
|
2215
|
+
* `WebhookEventStatus` below) — the full order data is delivered
|
|
2216
|
+
* each time, not a delta.
|
|
2217
|
+
*
|
|
2218
|
+
* Trendyol authenticates against YOUR endpoint using the method you
|
|
2219
|
+
* configured on the subscription (BASIC_AUTHENTICATION or API_KEY). The
|
|
2220
|
+
* SDK does NOT validate auth on its end — handle that in your request
|
|
2221
|
+
* middleware before passing the body to `parseWebhookEvent`.
|
|
2222
|
+
*
|
|
2223
|
+
* Retry: on a non-2xx response, Trendyol retries every 5 minutes; after
|
|
2224
|
+
* persistent failures the subscription is auto-deactivated (you'll get
|
|
2225
|
+
* 2 emails). Reactivate via `client.webhooks.activate(id)` once your
|
|
2226
|
+
* endpoint is healthy again.
|
|
2227
|
+
*/
|
|
2228
|
+
|
|
2229
|
+
/**
|
|
2230
|
+
* Status values Trendyol sends as the event trigger. Note the
|
|
2231
|
+
* **upper-snake-case** spelling here, distinct from `ShipmentPackageStatus`
|
|
2232
|
+
* (which uses PascalCase on the API read responses).
|
|
2233
|
+
*/
|
|
2234
|
+
type WebhookEventStatus = 'CREATED' | 'PICKING' | 'INVOICED' | 'SHIPPED' | 'CANCELLED' | 'DELIVERED' | 'UNDELIVERED' | 'RETURNED' | 'UNSUPPLIED' | 'AWAITING' | 'UNPACKED' | 'AT_COLLECTION_POINT' | 'VERIFIED' | (string & {});
|
|
2235
|
+
/**
|
|
2236
|
+
* Origin of a package, surfaced as `ShipmentPackage.createdBy` on the
|
|
2237
|
+
* normalized event payload. Useful for routing logic (e.g. trigger a
|
|
2238
|
+
* different flow for `'split'` packages than `'order-creation'`).
|
|
2239
|
+
*/
|
|
2240
|
+
type PackageCreatedBy = 'order-creation' | 'cancel' | 'split' | 'transfer' | (string & {});
|
|
2241
|
+
/**
|
|
2242
|
+
* The parsed webhook event body. `packages` is the normalized
|
|
2243
|
+
* `content[]` from the inbound JSON; `pageInfo` carries Trendyol's
|
|
2244
|
+
* pagination envelope verbatim so you can log / surface it.
|
|
2245
|
+
*
|
|
2246
|
+
* In practice `packages.length === 1` for status-change events, but the
|
|
2247
|
+
* model is defined as a page so the same handler can absorb future
|
|
2248
|
+
* batch events without breaking.
|
|
2249
|
+
*/
|
|
2250
|
+
interface WebhookEvent {
|
|
2251
|
+
packages: ShipmentPackage[];
|
|
2252
|
+
pageInfo: {
|
|
2253
|
+
totalElements?: number;
|
|
2254
|
+
totalPages?: number;
|
|
2255
|
+
page?: number;
|
|
2256
|
+
size?: number;
|
|
2257
|
+
};
|
|
2258
|
+
/** Raw inbound body — fall back here for fields the SDK doesn't surface. */
|
|
2259
|
+
raw: Record<string, unknown>;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
/**
|
|
2263
|
+
* Top-level helper for parsing incoming Trendyol webhook event bodies
|
|
2264
|
+
* into the SDK's typed shape.
|
|
2265
|
+
*
|
|
2266
|
+
* Usage in an Express route:
|
|
2267
|
+
*
|
|
2268
|
+
* ```ts
|
|
2269
|
+
* import { parseWebhookEvent } from '@lonca/trendyol';
|
|
2270
|
+
*
|
|
2271
|
+
* app.post('/trendyol/webhook', express.json(), (req, res) => {
|
|
2272
|
+
* const event = parseWebhookEvent(req.body);
|
|
2273
|
+
* for (const pkg of event.packages) {
|
|
2274
|
+
* // pkg: typed ShipmentPackage — same shape as orders.list()
|
|
2275
|
+
* await myQueue.enqueue({ packageId: pkg.id, status: pkg.status });
|
|
2276
|
+
* }
|
|
2277
|
+
* res.sendStatus(200);
|
|
2278
|
+
* });
|
|
2279
|
+
* ```
|
|
2280
|
+
*/
|
|
2281
|
+
|
|
2282
|
+
/**
|
|
2283
|
+
* Parse an inbound webhook body into a typed `WebhookEvent`.
|
|
2284
|
+
*
|
|
2285
|
+
* Accepts either an already-parsed object or a JSON string. Returns
|
|
2286
|
+
* normalized `ShipmentPackage[]` (the same shape `orders.list()`
|
|
2287
|
+
* produces), plus the page envelope and the raw body for fallthrough.
|
|
2288
|
+
*
|
|
2289
|
+
* @throws {ValidationError} when the body isn't an object / valid JSON,
|
|
2290
|
+
* or when `content` is missing or not an array.
|
|
2291
|
+
*/
|
|
2292
|
+
declare function parseWebhookEvent(rawBody: unknown): WebhookEvent;
|
|
2293
|
+
|
|
2294
|
+
export { type ApproveClaimLineItemsInput, type BarcodeCategoryLookup, type BatchAcceptedResponse, type BatchRequestItemResult, type BatchRequestResult, type BatchRequestStatus, type Brand, BrandsResource, type BuyboxInfo, type CancelPackageItemInput, type CargoInvoiceItem, CategoriesResource, type Category, type CategoryAttribute, type CategoryAttributeValue, type City, type Claim, type ClaimIssueReason, type ClaimItemAudit, type ClaimItemStatus, ClaimsResource, type CommonLabel, type CommonLabelEntry, type CompensationItemDetail, type CompensationTicket, type CompensationTicketState, type Country, type CreateClaimInput, type CreateClaimIssueInput, type CreateClaimItemInput, type CreateClientOptions, type CreateCommonLabelInput, type CreateProductV2Input, type CreateTestOrderInput, type DeleteInvoiceLinkInput, type DeliveryOptionInput, type District, FinanceResource, type FinancialTransaction, InventoryResource, InvoicesResource, LabelsResource, type LaborCostInput, type ListCategoryAttributeValuesParams, type ListClaimsParams, type ListCompensationTicketsParams, type ListFinanceParams, type ListOrdersParams, type ListOrdersStreamParams, type ListProductsParams, type ListQuestionsParams, type ListUnapprovedProductsParams, LocationsResource, type NamedRef, type Neighborhood, type OrderAddress, type OrderAddressLines, type OrderCustomer, type OrderLine, type OrderLineDiscountDetail, OrdersResource, type OtherFinancialRow, type PackageCreatedBy, type PackageDetail, type PackageHistoryEntry, type PackageLineUpdate, type PriceInventoryUpdate, type ProcessAlternativeDeliveryInput, type Product, type ProductAttribute, type ProductAttributeV2Input, type ProductBase, type ProductImageInput, type ProductVariant, ProductsResource, type QuantitySplit, type Question, type QuestionAnswer, type QuestionStatus, QuestionsResource, type SendInvoiceLinkInput, type SettlementRow, type ShipmentPackage, type ShipmentPackageStatus, type SplitGroup, type SplitPackagePlan, type SupplierAddress, type SupplierAddressType, SuppliersResource, type SuppliersResourceOptions, type TestOrderStatus, TestOrdersResource, type TrendyolCargoProvider, type TrendyolClient, type TrendyolEnvironment, type UnapprovedDateQueryType, type UnapprovedProduct, type UnapprovedProductRejectReason, type UnapprovedProductStatus, type UpdateBoxInfoInput, type UpdateContentInput, type UpdateDeliveryInfoInput, type UpdatePackageStatusInput, type UpdatePriceInventoryResponse, type UpdateUnapprovedInput, type UpdateVariantInput, type UploadInvoiceFileInput, type Webhook, type WebhookAuthenticationType, type WebhookEvent, type WebhookEventStatus, type WebhookInput, WebhooksResource, createTrendyolClient, normalizeShipmentPackage, parseWebhookEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -451,15 +451,56 @@ interface DeleteInvoiceLinkInput {
|
|
|
451
451
|
[key: string]: unknown;
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
|
-
* One row from
|
|
455
|
-
*
|
|
454
|
+
* One row from Trendyol's current-account statement — returned by both
|
|
455
|
+
* `finance.getSettlements()` and `finance.getOtherFinancials()` (both
|
|
456
|
+
* endpoints share the `FinancialTransaction` wire schema).
|
|
457
|
+
*
|
|
458
|
+
* Field set verified against the spec on 2026-05-25. The SDK exposes the
|
|
459
|
+
* stable subset; anything Trendyol adds later remains accessible via `raw`.
|
|
456
460
|
*/
|
|
457
|
-
interface
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
interface FinancialTransaction {
|
|
462
|
+
/** Transaction ID (string per Trendyol). */
|
|
463
|
+
id: string;
|
|
464
|
+
/** ISO 8601 UTC (from ms-epoch `transactionDate`). */
|
|
465
|
+
transactionDate?: string;
|
|
466
|
+
/** Product barcode when the transaction is tied to a SKU. */
|
|
467
|
+
barcode?: string | null;
|
|
468
|
+
/** Transaction category (e.g. `'Satış'`, `'Ödeme'`). */
|
|
469
|
+
transactionType?: string;
|
|
470
|
+
/** Receipt ID ("dekont no") when applicable. */
|
|
471
|
+
receiptId?: number | null;
|
|
472
|
+
description?: string | null;
|
|
473
|
+
/** Debit amount on the seller's account. */
|
|
474
|
+
debt?: number;
|
|
475
|
+
/** Credit amount on the seller's account. */
|
|
476
|
+
credit?: number;
|
|
477
|
+
paymentPeriod?: number | null;
|
|
478
|
+
commissionRate?: number | null;
|
|
479
|
+
commissionAmount?: number | null;
|
|
480
|
+
commissionInvoiceSerialNumber?: string | null;
|
|
481
|
+
/** Net seller revenue after Trendyol's cut. */
|
|
482
|
+
sellerRevenue?: number | null;
|
|
483
|
+
orderNumber?: string | null;
|
|
484
|
+
paymentOrderId?: number | null;
|
|
485
|
+
/** ISO 8601 UTC (from ms-epoch `paymentDate`). */
|
|
486
|
+
paymentDate?: string;
|
|
487
|
+
sellerId?: number;
|
|
488
|
+
storeId?: number | null;
|
|
489
|
+
storeName?: string | null;
|
|
490
|
+
storeAddress?: string | null;
|
|
491
|
+
country?: string | null;
|
|
492
|
+
/** Untouched raw row — pull any undocumented fields from here. */
|
|
461
493
|
raw: Record<string, unknown>;
|
|
462
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Aliases preserved for source-compatibility with `0.5.0`. Both legacy
|
|
497
|
+
* names now resolve to the unified `FinancialTransaction`.
|
|
498
|
+
*
|
|
499
|
+
* @deprecated since `0.5.1` — use `FinancialTransaction`.
|
|
500
|
+
*/
|
|
501
|
+
type SettlementRow = FinancialTransaction;
|
|
502
|
+
/** @deprecated since `0.5.1` — use `FinancialTransaction`. */
|
|
503
|
+
type OtherFinancialRow = FinancialTransaction;
|
|
463
504
|
/**
|
|
464
505
|
* Shared filter shape for both finance endpoints.
|
|
465
506
|
* `transactionType` lets you scope to one settlement category.
|
|
@@ -476,7 +517,19 @@ interface CreateCommonLabelInput {
|
|
|
476
517
|
/** Volumetric height (height × width × depth / 3000 → desi). */
|
|
477
518
|
volumetricHeight?: number;
|
|
478
519
|
}
|
|
520
|
+
/** One label entry inside a `CommonLabel` response. */
|
|
521
|
+
interface CommonLabelEntry {
|
|
522
|
+
/** Encoded label payload (e.g. ZPL string `^XA...^XZ`). */
|
|
523
|
+
label: string;
|
|
524
|
+
format: 'ZPL' | (string & {});
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Response from `labels.getCommon()` — Trendyol's wire shape is
|
|
528
|
+
* `{ data: [{ label, format }] }`. SDK surfaces the array directly via
|
|
529
|
+
* `labels` for ergonomic access; `raw` is the untouched response.
|
|
530
|
+
*/
|
|
479
531
|
interface CommonLabel {
|
|
532
|
+
labels: CommonLabelEntry[];
|
|
480
533
|
raw: Record<string, unknown>;
|
|
481
534
|
}
|
|
482
535
|
/**
|
|
@@ -524,16 +577,16 @@ interface Neighborhood {
|
|
|
524
577
|
* Trendyol finance endpoints — current-account-statement settlements and
|
|
525
578
|
* "other financials" (cargo invoices, labor cost adjustments, etc.).
|
|
526
579
|
*
|
|
527
|
-
* Both
|
|
528
|
-
*
|
|
580
|
+
* Both endpoints return the same `FinancialTransaction` shape on the wire,
|
|
581
|
+
* so the SDK exposes one typed surface for them.
|
|
529
582
|
*/
|
|
530
583
|
declare class FinanceResource {
|
|
531
584
|
private readonly transport;
|
|
532
585
|
private readonly sellerId;
|
|
533
586
|
private readonly limiter;
|
|
534
587
|
constructor(transport: TrendyolTransport, sellerId: number, limiter?: TokenBucketRateLimiter);
|
|
535
|
-
getSettlements(params?: ListFinanceParams): Promise<CursorPage<
|
|
536
|
-
getOtherFinancials(params?: ListFinanceParams): Promise<CursorPage<
|
|
588
|
+
getSettlements(params?: ListFinanceParams): Promise<CursorPage<FinancialTransaction>>;
|
|
589
|
+
getOtherFinancials(params?: ListFinanceParams): Promise<CursorPage<FinancialTransaction>>;
|
|
537
590
|
private queryPage;
|
|
538
591
|
}
|
|
539
592
|
|
|
@@ -631,7 +684,14 @@ declare class LabelsResource {
|
|
|
631
684
|
* @throws {ValidationError} when `format` is missing.
|
|
632
685
|
*/
|
|
633
686
|
createCommon(cargoTrackingNumber: string | number, input: CreateCommonLabelInput): Promise<unknown>;
|
|
634
|
-
/**
|
|
687
|
+
/**
|
|
688
|
+
* Retrieve the previously-created common label. Trendyol returns
|
|
689
|
+
* `{ data: [{ label, format }] }`; the SDK surfaces the array as
|
|
690
|
+
* `labels[]` for ergonomic access.
|
|
691
|
+
*
|
|
692
|
+
* Typically `labels.length === 1` per tracking number, but kept as an
|
|
693
|
+
* array to match the wire shape.
|
|
694
|
+
*/
|
|
635
695
|
getCommon(cargoTrackingNumber: string | number): Promise<CommonLabel>;
|
|
636
696
|
}
|
|
637
697
|
|
|
@@ -1016,6 +1076,16 @@ interface ListOrdersParams extends CursorPaginationParams {
|
|
|
1016
1076
|
/** Filter packages updated on or before this date. */
|
|
1017
1077
|
endDate?: Date;
|
|
1018
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Normalize one raw Trendyol shipment-package node into the public
|
|
1081
|
+
* `ShipmentPackage` shape. Exported so consumers handling Trendyol
|
|
1082
|
+
* webhooks can reuse the SDK's normalization logic on the event body
|
|
1083
|
+
* (Trendyol POSTs the same shape it returns from `getShipmentPackages`).
|
|
1084
|
+
*
|
|
1085
|
+
* For full-webhook parsing use `parseWebhookEvent(rawBody)` from the
|
|
1086
|
+
* top-level package, which calls this internally per item.
|
|
1087
|
+
*/
|
|
1088
|
+
declare function normalizeShipmentPackage(rawNode: unknown): ShipmentPackage;
|
|
1019
1089
|
/**
|
|
1020
1090
|
* Trendyol order (shipment-package) endpoints.
|
|
1021
1091
|
*
|
|
@@ -2133,4 +2203,92 @@ interface TrendyolClient {
|
|
|
2133
2203
|
*/
|
|
2134
2204
|
declare function createTrendyolClient(opts: CreateClientOptions): TrendyolClient;
|
|
2135
2205
|
|
|
2136
|
-
|
|
2206
|
+
/**
|
|
2207
|
+
* Inbound webhook event payloads — what Trendyol POSTs to YOUR endpoint
|
|
2208
|
+
* when a subscribed shipment-package status event fires.
|
|
2209
|
+
*
|
|
2210
|
+
* Per Trendyol's "Webhook Model" doc:
|
|
2211
|
+
* - Method: POST, body: JSON
|
|
2212
|
+
* - Wire shape: identical to `getShipmentPackages` response envelope
|
|
2213
|
+
* (`{ totalElements, totalPages, page, size, content: [...] }`)
|
|
2214
|
+
* - Sent on every status transition for a subscribed status (see
|
|
2215
|
+
* `WebhookEventStatus` below) — the full order data is delivered
|
|
2216
|
+
* each time, not a delta.
|
|
2217
|
+
*
|
|
2218
|
+
* Trendyol authenticates against YOUR endpoint using the method you
|
|
2219
|
+
* configured on the subscription (BASIC_AUTHENTICATION or API_KEY). The
|
|
2220
|
+
* SDK does NOT validate auth on its end — handle that in your request
|
|
2221
|
+
* middleware before passing the body to `parseWebhookEvent`.
|
|
2222
|
+
*
|
|
2223
|
+
* Retry: on a non-2xx response, Trendyol retries every 5 minutes; after
|
|
2224
|
+
* persistent failures the subscription is auto-deactivated (you'll get
|
|
2225
|
+
* 2 emails). Reactivate via `client.webhooks.activate(id)` once your
|
|
2226
|
+
* endpoint is healthy again.
|
|
2227
|
+
*/
|
|
2228
|
+
|
|
2229
|
+
/**
|
|
2230
|
+
* Status values Trendyol sends as the event trigger. Note the
|
|
2231
|
+
* **upper-snake-case** spelling here, distinct from `ShipmentPackageStatus`
|
|
2232
|
+
* (which uses PascalCase on the API read responses).
|
|
2233
|
+
*/
|
|
2234
|
+
type WebhookEventStatus = 'CREATED' | 'PICKING' | 'INVOICED' | 'SHIPPED' | 'CANCELLED' | 'DELIVERED' | 'UNDELIVERED' | 'RETURNED' | 'UNSUPPLIED' | 'AWAITING' | 'UNPACKED' | 'AT_COLLECTION_POINT' | 'VERIFIED' | (string & {});
|
|
2235
|
+
/**
|
|
2236
|
+
* Origin of a package, surfaced as `ShipmentPackage.createdBy` on the
|
|
2237
|
+
* normalized event payload. Useful for routing logic (e.g. trigger a
|
|
2238
|
+
* different flow for `'split'` packages than `'order-creation'`).
|
|
2239
|
+
*/
|
|
2240
|
+
type PackageCreatedBy = 'order-creation' | 'cancel' | 'split' | 'transfer' | (string & {});
|
|
2241
|
+
/**
|
|
2242
|
+
* The parsed webhook event body. `packages` is the normalized
|
|
2243
|
+
* `content[]` from the inbound JSON; `pageInfo` carries Trendyol's
|
|
2244
|
+
* pagination envelope verbatim so you can log / surface it.
|
|
2245
|
+
*
|
|
2246
|
+
* In practice `packages.length === 1` for status-change events, but the
|
|
2247
|
+
* model is defined as a page so the same handler can absorb future
|
|
2248
|
+
* batch events without breaking.
|
|
2249
|
+
*/
|
|
2250
|
+
interface WebhookEvent {
|
|
2251
|
+
packages: ShipmentPackage[];
|
|
2252
|
+
pageInfo: {
|
|
2253
|
+
totalElements?: number;
|
|
2254
|
+
totalPages?: number;
|
|
2255
|
+
page?: number;
|
|
2256
|
+
size?: number;
|
|
2257
|
+
};
|
|
2258
|
+
/** Raw inbound body — fall back here for fields the SDK doesn't surface. */
|
|
2259
|
+
raw: Record<string, unknown>;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
/**
|
|
2263
|
+
* Top-level helper for parsing incoming Trendyol webhook event bodies
|
|
2264
|
+
* into the SDK's typed shape.
|
|
2265
|
+
*
|
|
2266
|
+
* Usage in an Express route:
|
|
2267
|
+
*
|
|
2268
|
+
* ```ts
|
|
2269
|
+
* import { parseWebhookEvent } from '@lonca/trendyol';
|
|
2270
|
+
*
|
|
2271
|
+
* app.post('/trendyol/webhook', express.json(), (req, res) => {
|
|
2272
|
+
* const event = parseWebhookEvent(req.body);
|
|
2273
|
+
* for (const pkg of event.packages) {
|
|
2274
|
+
* // pkg: typed ShipmentPackage — same shape as orders.list()
|
|
2275
|
+
* await myQueue.enqueue({ packageId: pkg.id, status: pkg.status });
|
|
2276
|
+
* }
|
|
2277
|
+
* res.sendStatus(200);
|
|
2278
|
+
* });
|
|
2279
|
+
* ```
|
|
2280
|
+
*/
|
|
2281
|
+
|
|
2282
|
+
/**
|
|
2283
|
+
* Parse an inbound webhook body into a typed `WebhookEvent`.
|
|
2284
|
+
*
|
|
2285
|
+
* Accepts either an already-parsed object or a JSON string. Returns
|
|
2286
|
+
* normalized `ShipmentPackage[]` (the same shape `orders.list()`
|
|
2287
|
+
* produces), plus the page envelope and the raw body for fallthrough.
|
|
2288
|
+
*
|
|
2289
|
+
* @throws {ValidationError} when the body isn't an object / valid JSON,
|
|
2290
|
+
* or when `content` is missing or not an array.
|
|
2291
|
+
*/
|
|
2292
|
+
declare function parseWebhookEvent(rawBody: unknown): WebhookEvent;
|
|
2293
|
+
|
|
2294
|
+
export { type ApproveClaimLineItemsInput, type BarcodeCategoryLookup, type BatchAcceptedResponse, type BatchRequestItemResult, type BatchRequestResult, type BatchRequestStatus, type Brand, BrandsResource, type BuyboxInfo, type CancelPackageItemInput, type CargoInvoiceItem, CategoriesResource, type Category, type CategoryAttribute, type CategoryAttributeValue, type City, type Claim, type ClaimIssueReason, type ClaimItemAudit, type ClaimItemStatus, ClaimsResource, type CommonLabel, type CommonLabelEntry, type CompensationItemDetail, type CompensationTicket, type CompensationTicketState, type Country, type CreateClaimInput, type CreateClaimIssueInput, type CreateClaimItemInput, type CreateClientOptions, type CreateCommonLabelInput, type CreateProductV2Input, type CreateTestOrderInput, type DeleteInvoiceLinkInput, type DeliveryOptionInput, type District, FinanceResource, type FinancialTransaction, InventoryResource, InvoicesResource, LabelsResource, type LaborCostInput, type ListCategoryAttributeValuesParams, type ListClaimsParams, type ListCompensationTicketsParams, type ListFinanceParams, type ListOrdersParams, type ListOrdersStreamParams, type ListProductsParams, type ListQuestionsParams, type ListUnapprovedProductsParams, LocationsResource, type NamedRef, type Neighborhood, type OrderAddress, type OrderAddressLines, type OrderCustomer, type OrderLine, type OrderLineDiscountDetail, OrdersResource, type OtherFinancialRow, type PackageCreatedBy, type PackageDetail, type PackageHistoryEntry, type PackageLineUpdate, type PriceInventoryUpdate, type ProcessAlternativeDeliveryInput, type Product, type ProductAttribute, type ProductAttributeV2Input, type ProductBase, type ProductImageInput, type ProductVariant, ProductsResource, type QuantitySplit, type Question, type QuestionAnswer, type QuestionStatus, QuestionsResource, type SendInvoiceLinkInput, type SettlementRow, type ShipmentPackage, type ShipmentPackageStatus, type SplitGroup, type SplitPackagePlan, type SupplierAddress, type SupplierAddressType, SuppliersResource, type SuppliersResourceOptions, type TestOrderStatus, TestOrdersResource, type TrendyolCargoProvider, type TrendyolClient, type TrendyolEnvironment, type UnapprovedDateQueryType, type UnapprovedProduct, type UnapprovedProductRejectReason, type UnapprovedProductStatus, type UpdateBoxInfoInput, type UpdateContentInput, type UpdateDeliveryInfoInput, type UpdatePackageStatusInput, type UpdatePriceInventoryResponse, type UpdateUnapprovedInput, type UpdateVariantInput, type UploadInvoiceFileInput, type Webhook, type WebhookAuthenticationType, type WebhookEvent, type WebhookEventStatus, type WebhookInput, WebhooksResource, createTrendyolClient, normalizeShipmentPackage, parseWebhookEvent };
|