@lonca/trendyol 0.7.0 → 0.9.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.js CHANGED
@@ -89,13 +89,11 @@ function normalizeAttribute(node) {
89
89
  var MAX_ATTR_VALUES_PAGE_SIZE = 1e3;
90
90
  var DEFAULT_ATTR_VALUES_PAGE_SIZE = 100;
91
91
  var CategoriesResource = class {
92
- constructor(transport, limiter, sellerId) {
92
+ constructor(transport, limiter) {
93
93
  this.transport = transport;
94
- this.sellerId = sellerId;
95
94
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 50, intervalMs: 6e4 });
96
95
  }
97
96
  transport;
98
- sellerId;
99
97
  limiter;
100
98
  /**
101
99
  * Fetch the full Trendyol category tree.
@@ -191,21 +189,14 @@ var CategoriesResource = class {
191
189
  *
192
190
  * @param barcodes 1–N barcodes to look up.
193
191
  * @throws {ValidationError} when `barcodes` is empty.
194
- * @throws Error when the client was created without a `sellerId` and this
195
- * method is called directly (use `createTrendyolClient` to wire it).
196
192
  */
197
193
  async getByBarcodes(barcodes) {
198
194
  if (!Array.isArray(barcodes) || barcodes.length === 0) {
199
195
  throw new ValidationError({ message: "getByBarcodes: barcodes must not be empty" });
200
196
  }
201
- if (this.sellerId === void 0) {
202
- throw new Error(
203
- "CategoriesResource.getByBarcodes requires a sellerId; instantiate via createTrendyolClient"
204
- );
205
- }
206
197
  const data = await this.transport.request({
207
198
  method: "POST",
208
- path: `/integration/ecgw/v1/${this.sellerId}/lookup/product-categories/by-barcodes`,
199
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/lookup/product-categories/by-barcodes`,
209
200
  body: { barcodes },
210
201
  rateLimiter: this.limiter
211
202
  });
@@ -253,13 +244,11 @@ function normalizeClaim(node) {
253
244
  return out;
254
245
  }
255
246
  var ClaimsResource = class {
256
- constructor(transport, sellerId, limiter) {
247
+ constructor(transport, limiter) {
257
248
  this.transport = transport;
258
- this.sellerId = sellerId;
259
249
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
260
250
  }
261
251
  transport;
262
- sellerId;
263
252
  limiter;
264
253
  /**
265
254
  * Create a return claim against an order. Use this to file a return on
@@ -277,7 +266,7 @@ var ClaimsResource = class {
277
266
  }
278
267
  return this.transport.request({
279
268
  method: "POST",
280
- path: `/integration/order/sellers/${this.sellerId}/claims/create`,
269
+ path: `/integration/order/sellers/${this.transport.sellerId}/claims/create`,
281
270
  body: input,
282
271
  rateLimiter: this.limiter
283
272
  });
@@ -315,7 +304,7 @@ var ClaimsResource = class {
315
304
  }
316
305
  return this.transport.request({
317
306
  method: "POST",
318
- path: `/integration/order/sellers/${this.sellerId}/claims/${encodeURIComponent(claimId)}/issue`,
307
+ path: `/integration/order/sellers/${this.transport.sellerId}/claims/${encodeURIComponent(claimId)}/issue`,
319
308
  body: form,
320
309
  rateLimiter: this.limiter
321
310
  });
@@ -334,7 +323,7 @@ var ClaimsResource = class {
334
323
  }
335
324
  return this.transport.request({
336
325
  method: "PUT",
337
- path: `/integration/order/sellers/${this.sellerId}/claims/${encodeURIComponent(claimId)}/items/approve`,
326
+ path: `/integration/order/sellers/${this.transport.sellerId}/claims/${encodeURIComponent(claimId)}/items/approve`,
338
327
  body: input,
339
328
  rateLimiter: this.limiter
340
329
  });
@@ -361,7 +350,7 @@ var ClaimsResource = class {
361
350
  if (params.claimItemStatus) query.claimItemStatus = params.claimItemStatus;
362
351
  const data = await this.transport.request({
363
352
  method: "GET",
364
- path: `/integration/order/sellers/${this.sellerId}/claims`,
353
+ path: `/integration/order/sellers/${this.transport.sellerId}/claims`,
365
354
  query,
366
355
  rateLimiter: this.limiter
367
356
  });
@@ -399,13 +388,276 @@ var ClaimsResource = class {
399
388
  async getItemAudits(claimItemId) {
400
389
  const data = await this.transport.request({
401
390
  method: "GET",
402
- path: `/integration/order/sellers/${this.sellerId}/claims/items/${encodeURIComponent(claimItemId)}/audit`,
391
+ path: `/integration/order/sellers/${this.transport.sellerId}/claims/items/${encodeURIComponent(claimItemId)}/audit`,
403
392
  rateLimiter: this.limiter
404
393
  });
405
394
  const rows = Array.isArray(data) ? data : Array.isArray(data?.content) ? data.content : [];
406
395
  return rows.map((row) => ({ raw: row }));
407
396
  }
408
397
  };
398
+ var MAX_BATCH_ITEMS = 5e3;
399
+ var ExportCenterResource = class {
400
+ constructor(transport, limiter) {
401
+ this.transport = transport;
402
+ this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
403
+ }
404
+ transport;
405
+ limiter;
406
+ // ─── Products ────────────────────────────────────────────────────────────
407
+ /**
408
+ * List Export Center-approved products. Uses Trendyol's `pageKey`
409
+ * pagination — the first call leaves `pageKey` empty; subsequent
410
+ * calls pass the `x-paging-key` value from the previous response.
411
+ */
412
+ async listProducts(params = {}) {
413
+ const query = {};
414
+ if (params.barcodes && params.barcodes.length > 0) query.barcodes = params.barcodes.join(",");
415
+ if (params.pageKey) query.pageKey = params.pageKey;
416
+ if (params.size !== void 0) query.size = params.size;
417
+ const data = await this.transport.request({
418
+ method: "GET",
419
+ path: `/integration/ecgw/v2/${this.transport.sellerId}/products`,
420
+ query: Object.keys(query).length ? query : void 0,
421
+ rateLimiter: this.limiter
422
+ });
423
+ const rows = pickArray(data);
424
+ return rows.map((r) => ({ raw: r ?? {} }));
425
+ }
426
+ /**
427
+ * Create Export Center products. Maximum 5000 per call. Returns a
428
+ * `batchId` you can poll via `getBatchStatus(batchId)`.
429
+ *
430
+ * @throws {ValidationError} when `products` is empty / oversized.
431
+ */
432
+ async createProducts(products) {
433
+ this.assertBatch(products, "createProducts");
434
+ const data = await this.transport.request({
435
+ method: "POST",
436
+ path: `/integration/ecgw/v2/${this.transport.sellerId}/products`,
437
+ body: { products },
438
+ rateLimiter: this.limiter
439
+ });
440
+ return normalizeBatchResponse(data);
441
+ }
442
+ /**
443
+ * Update Export Center prices. **Trendyol allows one price update per
444
+ * barcode per day.** Returns a `batchId`.
445
+ *
446
+ * @throws {ValidationError} when `priceInfos` is empty / oversized.
447
+ */
448
+ async updatePrices(priceInfos) {
449
+ this.assertBatch(priceInfos, "updatePrices");
450
+ const data = await this.transport.request({
451
+ method: "POST",
452
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/prices`,
453
+ body: { priceInfos },
454
+ rateLimiter: this.limiter
455
+ });
456
+ return normalizeBatchResponse(data);
457
+ }
458
+ /**
459
+ * Update Export Center stocks. Returns a `batchId`. Sellers using
460
+ * Trendyol's shared inventory cannot use this endpoint (per portal docs).
461
+ *
462
+ * @throws {ValidationError} when `items` is empty / oversized.
463
+ */
464
+ async updateStocks(items) {
465
+ this.assertBatch(items, "updateStocks");
466
+ const data = await this.transport.request({
467
+ method: "POST",
468
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/stocks`,
469
+ body: { items },
470
+ rateLimiter: this.limiter
471
+ });
472
+ return normalizeBatchResponse(data);
473
+ }
474
+ // ─── Batch status ────────────────────────────────────────────────────────
475
+ /**
476
+ * Look up the status of a previously-submitted batch. Trendyol retains
477
+ * batch records for **24 hours** only — older `batchId`s return `404`.
478
+ */
479
+ async getBatchStatus(batchId) {
480
+ if (!batchId) {
481
+ throw new ValidationError({ message: "exportCenter.getBatchStatus: batchId is required" });
482
+ }
483
+ const data = await this.transport.request({
484
+ method: "GET",
485
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/check-status`,
486
+ query: { batchId },
487
+ rateLimiter: this.limiter
488
+ });
489
+ return normalizeBatchStatus(data);
490
+ }
491
+ // ─── Packages ────────────────────────────────────────────────────────────
492
+ /** List daily Export Center packages (V2 — query-based filters). */
493
+ async listPackagesV2(params = {}) {
494
+ const data = await this.transport.request({
495
+ method: "GET",
496
+ path: `/integration/ecgw/v2/${this.transport.sellerId}/packages`,
497
+ query: {
498
+ trackingNumber: params.trackingNumber,
499
+ status: params.status,
500
+ creationStartDate: params.creationStartDate,
501
+ creationEndDate: params.creationEndDate,
502
+ size: params.size,
503
+ boutiqueId: params.boutiqueId
504
+ },
505
+ rateLimiter: this.limiter
506
+ });
507
+ return pickArray(data).map(normalizePackage);
508
+ }
509
+ /** List Export Center packages (V3 — consolidated, page-based). */
510
+ async listPackagesV3(params = {}) {
511
+ const data = await this.transport.request({
512
+ method: "GET",
513
+ path: `/integration/ecgw/v3/${this.transport.sellerId}/packages`,
514
+ query: {
515
+ status: params.status,
516
+ page: params.offset !== void 0 ? params.offset : void 0,
517
+ size: params.limit,
518
+ creationStartDate: params.creationStartDate,
519
+ creationEndDate: params.creationEndDate
520
+ },
521
+ rateLimiter: this.limiter
522
+ });
523
+ return pickArray(data).map(normalizePackage);
524
+ }
525
+ /** Get the line items inside an Export Center package. */
526
+ async getPackageItems(params) {
527
+ if (!params || !params.packageId) {
528
+ throw new ValidationError({
529
+ message: "exportCenter.getPackageItems: packageId is required"
530
+ });
531
+ }
532
+ const data = await this.transport.request({
533
+ method: "GET",
534
+ path: `/integration/ecgw/v2/${this.transport.sellerId}/packages/items`,
535
+ query: {
536
+ packageId: params.packageId,
537
+ status: params.status,
538
+ page: params.offset,
539
+ size: params.limit
540
+ },
541
+ rateLimiter: this.limiter
542
+ });
543
+ return pickArray(data).map((r) => ({ raw: r ?? {} }));
544
+ }
545
+ // ─── Lookup ──────────────────────────────────────────────────────────────
546
+ /** Get the required attributes for an Export Center category. */
547
+ async getCategoryAttributes(categoryId) {
548
+ if (categoryId === void 0 || categoryId === null || categoryId === "") {
549
+ throw new ValidationError({
550
+ message: "exportCenter.getCategoryAttributes: categoryId is required"
551
+ });
552
+ }
553
+ const data = await this.transport.request({
554
+ method: "GET",
555
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/lookup/product-categories/${encodeURIComponent(String(categoryId))}/attributes`,
556
+ rateLimiter: this.limiter
557
+ });
558
+ return pickArray(data).map((r) => {
559
+ const row = r ?? {};
560
+ const out = { raw: row };
561
+ if (typeof row.attributeId === "number" || typeof row.attributeId === "string") {
562
+ out.attributeId = row.attributeId;
563
+ }
564
+ if (typeof row.attributeName === "string") out.attributeName = row.attributeName;
565
+ if (typeof row.required === "boolean") out.required = row.required;
566
+ if (Array.isArray(row.values)) out.values = row.values;
567
+ return out;
568
+ });
569
+ }
570
+ /** Get the care-instruction lookup values used by `createProducts`. */
571
+ async getCareInstructions() {
572
+ const data = await this.transport.request({
573
+ method: "GET",
574
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/lookup/care-instructions`,
575
+ rateLimiter: this.limiter
576
+ });
577
+ return pickArray(data).map(normalizeNamedRef);
578
+ }
579
+ /** Get the material-composition lookup values used by `createProducts`. */
580
+ async getCompositions() {
581
+ const data = await this.transport.request({
582
+ method: "GET",
583
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/lookup/compositions`,
584
+ rateLimiter: this.limiter
585
+ });
586
+ return pickArray(data).map(normalizeNamedRef);
587
+ }
588
+ /** Get the country-of-origin lookup values used by `createProducts`. */
589
+ async getOrigins() {
590
+ const data = await this.transport.request({
591
+ method: "GET",
592
+ path: `/integration/ecgw/v1/${this.transport.sellerId}/lookup/origins`,
593
+ rateLimiter: this.limiter
594
+ });
595
+ return pickArray(data).map((r) => {
596
+ const row = r ?? {};
597
+ const out = { raw: row };
598
+ if (typeof row.id === "number" || typeof row.id === "string") out.id = row.id;
599
+ if (typeof row.name === "string") out.name = row.name;
600
+ if (typeof row.countryCode === "string") out.countryCode = row.countryCode;
601
+ return out;
602
+ });
603
+ }
604
+ // ─── Helpers ─────────────────────────────────────────────────────────────
605
+ assertBatch(items, methodLabel) {
606
+ if (!Array.isArray(items) || items.length === 0) {
607
+ throw new ValidationError({
608
+ message: `exportCenter.${methodLabel}: items must not be empty`
609
+ });
610
+ }
611
+ if (items.length > MAX_BATCH_ITEMS) {
612
+ throw new ValidationError({
613
+ message: `exportCenter.${methodLabel}: max ${MAX_BATCH_ITEMS} items per call (got ${items.length})`
614
+ });
615
+ }
616
+ }
617
+ };
618
+ function pickArray(data) {
619
+ if (Array.isArray(data)) return data;
620
+ if (data && typeof data === "object") {
621
+ const obj = data;
622
+ if (Array.isArray(obj.content)) return obj.content;
623
+ if (Array.isArray(obj.items)) return obj.items;
624
+ if (Array.isArray(obj.data)) return obj.data;
625
+ if (Array.isArray(obj.products)) return obj.products;
626
+ if (Array.isArray(obj.packages)) return obj.packages;
627
+ }
628
+ return [];
629
+ }
630
+ function normalizeBatchResponse(data) {
631
+ const obj = data && typeof data === "object" ? data : {};
632
+ return {
633
+ batchId: String(obj.batchId ?? obj.batchRequestId ?? obj.id ?? ""),
634
+ raw: obj
635
+ };
636
+ }
637
+ function normalizeBatchStatus(data) {
638
+ const obj = data && typeof data === "object" ? data : {};
639
+ const out = { raw: obj };
640
+ if (typeof obj.batchId === "string") out.batchId = obj.batchId;
641
+ if (typeof obj.status === "string") out.status = obj.status;
642
+ if (typeof obj.itemCount === "number") out.itemCount = obj.itemCount;
643
+ if (typeof obj.failedItemCount === "number") out.failedItemCount = obj.failedItemCount;
644
+ if (Array.isArray(obj.items)) out.items = obj.items;
645
+ return out;
646
+ }
647
+ function normalizePackage(row) {
648
+ const r = row ?? {};
649
+ const out = { raw: r };
650
+ if (typeof r.packageNumber === "string") out.packageNumber = r.packageNumber;
651
+ if (typeof r.status === "string") out.status = r.status;
652
+ return out;
653
+ }
654
+ function normalizeNamedRef(row) {
655
+ const r = row ?? {};
656
+ const out = { raw: r };
657
+ if (typeof r.id === "number" || typeof r.id === "string") out.id = r.id;
658
+ if (typeof r.name === "string") out.name = r.name;
659
+ return out;
660
+ }
409
661
  function toIso2(epochMs) {
410
662
  if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
411
663
  return void 0;
@@ -444,19 +696,23 @@ function normalizeRow(row) {
444
696
  return out;
445
697
  }
446
698
  var FinanceResource = class {
447
- constructor(transport, sellerId, limiter) {
699
+ constructor(transport, limiter) {
448
700
  this.transport = transport;
449
- this.sellerId = sellerId;
450
701
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 100, intervalMs: 6e4 });
451
702
  }
452
703
  transport;
453
- sellerId;
454
704
  limiter;
455
705
  async getSettlements(params = {}) {
456
- return this.queryPage(`/integration/sellers/${this.sellerId}/settlements`, params);
706
+ return this.queryPage(
707
+ `/integration/finance/che/sellers/${this.transport.sellerId}/settlements`,
708
+ params
709
+ );
457
710
  }
458
711
  async getOtherFinancials(params = {}) {
459
- return this.queryPage(`/integration/sellers/${this.sellerId}/otherfinancials`, params);
712
+ return this.queryPage(
713
+ `/integration/finance/che/sellers/${this.transport.sellerId}/otherfinancials`,
714
+ params
715
+ );
460
716
  }
461
717
  async queryPage(path, params) {
462
718
  const size = Math.min(params.limit ?? 50, 200);
@@ -482,12 +738,10 @@ var FinanceResource = class {
482
738
  };
483
739
  var MAX_ITEMS_PER_REQUEST = 1e3;
484
740
  var InventoryResource = class {
485
- constructor(transport, sellerId) {
741
+ constructor(transport) {
486
742
  this.transport = transport;
487
- this.sellerId = sellerId;
488
743
  }
489
744
  transport;
490
- sellerId;
491
745
  /**
492
746
  * Update price and/or stock for one or more SKUs (by barcode).
493
747
  *
@@ -513,20 +767,18 @@ var InventoryResource = class {
513
767
  }
514
768
  const data = await this.transport.request({
515
769
  method: "POST",
516
- path: `/integration/inventory/sellers/${this.sellerId}/products/price-and-inventory`,
770
+ path: `/integration/inventory/sellers/${this.transport.sellerId}/products/price-and-inventory`,
517
771
  body: { items }
518
772
  });
519
773
  return { batchRequestId: data.batchRequestId ?? "" };
520
774
  }
521
775
  };
522
776
  var InvoicesResource = class {
523
- constructor(transport, sellerId, limiter) {
777
+ constructor(transport, limiter) {
524
778
  this.transport = transport;
525
- this.sellerId = sellerId;
526
779
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 500, intervalMs: 6e4 });
527
780
  }
528
781
  transport;
529
- sellerId;
530
782
  limiter;
531
783
  /**
532
784
  * Upload an invoice file for a shipment package. **Multipart**: the
@@ -552,7 +804,7 @@ var InvoicesResource = class {
552
804
  }
553
805
  return this.transport.request({
554
806
  method: "POST",
555
- path: `/integration/sellers/${this.sellerId}/seller-invoice-file`,
807
+ path: `/integration/sellers/${this.transport.sellerId}/seller-invoice-file`,
556
808
  body: form,
557
809
  rateLimiter: this.limiter
558
810
  });
@@ -564,7 +816,7 @@ var InvoicesResource = class {
564
816
  }
565
817
  return this.transport.request({
566
818
  method: "POST",
567
- path: `/integration/sellers/${this.sellerId}/seller-invoice-links`,
819
+ path: `/integration/sellers/${this.transport.sellerId}/seller-invoice-links`,
568
820
  body: input,
569
821
  rateLimiter: this.limiter
570
822
  });
@@ -573,20 +825,18 @@ var InvoicesResource = class {
573
825
  async deleteLink(input) {
574
826
  return this.transport.request({
575
827
  method: "POST",
576
- path: `/integration/sellers/${this.sellerId}/seller-invoice-links/delete`,
828
+ path: `/integration/sellers/${this.transport.sellerId}/seller-invoice-links/delete`,
577
829
  body: input,
578
830
  rateLimiter: this.limiter
579
831
  });
580
832
  }
581
833
  };
582
834
  var LabelsResource = class {
583
- constructor(transport, sellerId, limiter) {
835
+ constructor(transport, limiter) {
584
836
  this.transport = transport;
585
- this.sellerId = sellerId;
586
837
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 100, intervalMs: 6e4 });
587
838
  }
588
839
  transport;
589
- sellerId;
590
840
  limiter;
591
841
  /**
592
842
  * Request a common ZPL label for a cargo tracking number. After this
@@ -601,7 +851,7 @@ var LabelsResource = class {
601
851
  }
602
852
  return this.transport.request({
603
853
  method: "POST",
604
- path: `/integration/sellers/${this.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
854
+ path: `/integration/sellers/${this.transport.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
605
855
  body: input,
606
856
  rateLimiter: this.limiter
607
857
  });
@@ -617,7 +867,7 @@ var LabelsResource = class {
617
867
  async getCommon(cargoTrackingNumber) {
618
868
  const raw = await this.transport.request({
619
869
  method: "GET",
620
- path: `/integration/sellers/${this.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
870
+ path: `/integration/sellers/${this.transport.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
621
871
  rateLimiter: this.limiter
622
872
  });
623
873
  const labels = (raw?.data ?? []).map((row) => ({
@@ -808,9 +1058,9 @@ function normalizeCustomer(node) {
808
1058
  return out;
809
1059
  }
810
1060
  function normalizeShipmentPackage(rawNode) {
811
- return normalizePackage(rawNode ?? {});
1061
+ return normalizePackage2(rawNode ?? {});
812
1062
  }
813
- function normalizePackage(node) {
1063
+ function normalizePackage2(node) {
814
1064
  const pkgId = node.shipmentPackageId ?? node.id;
815
1065
  const out = {
816
1066
  id: pkgId !== void 0 ? String(pkgId) : "",
@@ -880,13 +1130,11 @@ function normalizePackage(node) {
880
1130
  return out;
881
1131
  }
882
1132
  var OrdersResource = class {
883
- constructor(transport, sellerId, limiter) {
1133
+ constructor(transport, limiter) {
884
1134
  this.transport = transport;
885
- this.sellerId = sellerId;
886
1135
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
887
1136
  }
888
1137
  transport;
889
- sellerId;
890
1138
  limiter;
891
1139
  /**
892
1140
  * List shipment packages for the seller.
@@ -909,11 +1157,11 @@ var OrdersResource = class {
909
1157
  if (params.endDate) query.endDate = params.endDate.getTime();
910
1158
  const data = await this.transport.request({
911
1159
  method: "GET",
912
- path: `/integration/order/sellers/${this.sellerId}/orders`,
1160
+ path: `/integration/order/sellers/${this.transport.sellerId}/orders`,
913
1161
  query,
914
1162
  rateLimiter: this.limiter
915
1163
  });
916
- const items = (data.content ?? []).map(normalizePackage);
1164
+ const items = (data.content ?? []).map(normalizePackage2);
917
1165
  const totalPages = typeof data.totalPages === "number" ? data.totalPages : 0;
918
1166
  const result = { items };
919
1167
  if (page + 1 < totalPages) {
@@ -1118,7 +1366,7 @@ var OrdersResource = class {
1118
1366
  async manualDeliverByTrackingNumber(cargoTrackingNumber) {
1119
1367
  await this.transport.request({
1120
1368
  method: "PUT",
1121
- path: `/integration/order/sellers/${this.sellerId}/shipment-packages/manual-invoice-delivery-by-tracking-number/${encodeURIComponent(String(cargoTrackingNumber))}`,
1369
+ path: `/integration/order/sellers/${this.transport.sellerId}/shipment-packages/manual-invoice-delivery-by-tracking-number/${encodeURIComponent(String(cargoTrackingNumber))}`,
1122
1370
  rateLimiter: this.limiter
1123
1371
  });
1124
1372
  }
@@ -1206,11 +1454,11 @@ var OrdersResource = class {
1206
1454
  }
1207
1455
  const data = await this.transport.request({
1208
1456
  method: "GET",
1209
- path: `/integration/order/sellers/${this.sellerId}/orders/stream`,
1457
+ path: `/integration/order/sellers/${this.transport.sellerId}/orders/stream`,
1210
1458
  query,
1211
1459
  rateLimiter: this.limiter
1212
1460
  });
1213
- const items = (data.content ?? []).map(normalizePackage);
1461
+ const items = (data.content ?? []).map(normalizePackage2);
1214
1462
  const result = { items };
1215
1463
  if (data.hasMore && data.nextCursor) {
1216
1464
  result.nextCursor = data.nextCursor;
@@ -1232,7 +1480,7 @@ var OrdersResource = class {
1232
1480
  const page = params.cursor ? Number.parseInt(params.cursor, 10) : 0;
1233
1481
  const data = await this.transport.request({
1234
1482
  method: "GET",
1235
- path: `/integration/finance/che/sellers/${this.sellerId}/cargo-invoice/${encodeURIComponent(invoiceSerialNumber)}/items`,
1483
+ path: `/integration/finance/che/sellers/${this.transport.sellerId}/cargo-invoice/${encodeURIComponent(invoiceSerialNumber)}/items`,
1236
1484
  query: { page, size },
1237
1485
  rateLimiter: this.limiter
1238
1486
  });
@@ -1278,7 +1526,7 @@ var OrdersResource = class {
1278
1526
  async manualReturnByTrackingNumber(cargoTrackingNumber) {
1279
1527
  await this.transport.request({
1280
1528
  method: "PUT",
1281
- path: `/integration/order/sellers/${this.sellerId}/shipment-packages/manual-return-by-tracking-number/${encodeURIComponent(String(cargoTrackingNumber))}`,
1529
+ path: `/integration/order/sellers/${this.transport.sellerId}/shipment-packages/manual-return-by-tracking-number/${encodeURIComponent(String(cargoTrackingNumber))}`,
1282
1530
  rateLimiter: this.limiter
1283
1531
  });
1284
1532
  }
@@ -1310,7 +1558,7 @@ var OrdersResource = class {
1310
1558
  if (params.endDate) query.endDate = params.endDate.getTime();
1311
1559
  const res = await this.transport.request({
1312
1560
  method: "GET",
1313
- path: `/integration/tex/compensation/sellers/${this.sellerId}/tickets`,
1561
+ path: `/integration/tex/compensation/sellers/${this.transport.sellerId}/tickets`,
1314
1562
  query,
1315
1563
  rateLimiter: this.limiter
1316
1564
  });
@@ -1350,7 +1598,7 @@ var OrdersResource = class {
1350
1598
  return result;
1351
1599
  }
1352
1600
  packagePath(packageId) {
1353
- return `/integration/order/sellers/${this.sellerId}/shipment-packages/${encodeURIComponent(String(packageId))}`;
1601
+ return `/integration/order/sellers/${this.transport.sellerId}/shipment-packages/${encodeURIComponent(String(packageId))}`;
1354
1602
  }
1355
1603
  };
1356
1604
  var DEFAULT_PAGE_SIZE3 = 50;
@@ -1526,9 +1774,8 @@ function normalizeBatchResult(data) {
1526
1774
  var MAX_WRITE_ITEMS = 1e3;
1527
1775
  var DELETE_RATE_PER_MIN = 100;
1528
1776
  var ProductsResource = class {
1529
- constructor(transport, sellerId, options = {}) {
1777
+ constructor(transport, options = {}) {
1530
1778
  this.transport = transport;
1531
- this.sellerId = sellerId;
1532
1779
  this.filterLimiter = options.filterLimiter ?? new TokenBucketRateLimiter({ capacity: 2e3, intervalMs: 6e4 });
1533
1780
  this.batchLimiter = options.batchLimiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
1534
1781
  this.buyboxLimiter = options.buyboxLimiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
@@ -1536,7 +1783,6 @@ var ProductsResource = class {
1536
1783
  this.deleteLimiter = options.deleteLimiter ?? new TokenBucketRateLimiter({ capacity: DELETE_RATE_PER_MIN, intervalMs: 6e4 });
1537
1784
  }
1538
1785
  transport;
1539
- sellerId;
1540
1786
  filterLimiter;
1541
1787
  batchLimiter;
1542
1788
  buyboxLimiter;
@@ -1563,7 +1809,7 @@ var ProductsResource = class {
1563
1809
  }
1564
1810
  const data = await this.transport.request({
1565
1811
  method: "POST",
1566
- path: `/integration/product/sellers/${this.sellerId}${endpoint}`,
1812
+ path: `/integration/product/sellers/${this.transport.sellerId}${endpoint}`,
1567
1813
  body: { items },
1568
1814
  rateLimiter: this.writeLimiter
1569
1815
  });
@@ -1601,7 +1847,7 @@ var ProductsResource = class {
1601
1847
  if (params.endDate) query.endDate = params.endDate.getTime();
1602
1848
  const data = await this.transport.request({
1603
1849
  method: "GET",
1604
- path: `/integration/product/sellers/${this.sellerId}/products/approved`,
1850
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/approved`,
1605
1851
  query,
1606
1852
  rateLimiter: this.filterLimiter
1607
1853
  });
@@ -1625,7 +1871,7 @@ var ProductsResource = class {
1625
1871
  const id = encodeURIComponent(batchRequestId);
1626
1872
  const data = await this.transport.request({
1627
1873
  method: "GET",
1628
- path: `/integration/product/sellers/${this.sellerId}/products/batch-requests/${id}`,
1874
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/batch-requests/${id}`,
1629
1875
  rateLimiter: this.batchLimiter
1630
1876
  });
1631
1877
  return normalizeBatchResult(data);
@@ -1666,7 +1912,7 @@ var ProductsResource = class {
1666
1912
  if (params.supplierId !== void 0) query.supplierId = params.supplierId;
1667
1913
  const data = await this.transport.request({
1668
1914
  method: "GET",
1669
- path: `/integration/product/sellers/${this.sellerId}/products/unapproved`,
1915
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/unapproved`,
1670
1916
  query,
1671
1917
  rateLimiter: this.filterLimiter
1672
1918
  });
@@ -1690,7 +1936,7 @@ var ProductsResource = class {
1690
1936
  const code = encodeURIComponent(barcode);
1691
1937
  const data = await this.transport.request({
1692
1938
  method: "GET",
1693
- path: `/integration/product/sellers/${this.sellerId}/product/${code}`,
1939
+ path: `/integration/product/sellers/${this.transport.sellerId}/product/${code}`,
1694
1940
  rateLimiter: this.filterLimiter
1695
1941
  });
1696
1942
  return normalizeProductBase(data);
@@ -1718,7 +1964,7 @@ var ProductsResource = class {
1718
1964
  }
1719
1965
  const data = await this.transport.request({
1720
1966
  method: "POST",
1721
- path: `/integration/product/sellers/${this.sellerId}/products/buybox-information`,
1967
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/buybox-information`,
1722
1968
  body: { barcodes },
1723
1969
  rateLimiter: this.buyboxLimiter
1724
1970
  });
@@ -1803,7 +2049,7 @@ var ProductsResource = class {
1803
2049
  this.validateBarcodes(barcodes, "delete");
1804
2050
  const data = await this.transport.request({
1805
2051
  method: "DELETE",
1806
- path: `/integration/product/sellers/${this.sellerId}/products`,
2052
+ path: `/integration/product/sellers/${this.transport.sellerId}/products`,
1807
2053
  body: { items: barcodes.map((barcode) => ({ barcode })) },
1808
2054
  rateLimiter: this.deleteLimiter
1809
2055
  });
@@ -1834,7 +2080,7 @@ var ProductsResource = class {
1834
2080
  this.validateBarcodes(barcodes, methodLabel);
1835
2081
  const data = await this.transport.request({
1836
2082
  method: "PUT",
1837
- path: `/integration/product/sellers/${this.sellerId}/products/archive-state`,
2083
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/archive-state`,
1838
2084
  body: { items: barcodes.map((barcode) => ({ barcode, archived })) },
1839
2085
  rateLimiter: this.writeLimiter
1840
2086
  });
@@ -1853,7 +2099,7 @@ var ProductsResource = class {
1853
2099
  this.validateBarcodes(barcodes, "unlock");
1854
2100
  const data = await this.transport.request({
1855
2101
  method: "PUT",
1856
- path: `/integration/product/sellers/${this.sellerId}/products/unlock`,
2102
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/unlock`,
1857
2103
  body: { items: barcodes.map((barcode) => ({ barcode })) },
1858
2104
  rateLimiter: this.writeLimiter
1859
2105
  });
@@ -1906,19 +2152,17 @@ function normalizeQuestion(node) {
1906
2152
  return out;
1907
2153
  }
1908
2154
  var QuestionsResource = class {
1909
- constructor(transport, sellerId, limiter) {
2155
+ constructor(transport, limiter) {
1910
2156
  this.transport = transport;
1911
- this.sellerId = sellerId;
1912
2157
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 500, intervalMs: 6e4 });
1913
2158
  }
1914
2159
  transport;
1915
- sellerId;
1916
2160
  limiter;
1917
2161
  /** Fetch a single question by its numeric ID. */
1918
2162
  async get(questionId) {
1919
2163
  const data = await this.transport.request({
1920
2164
  method: "GET",
1921
- path: `/integration/qna/sellers/${this.sellerId}/questions/${encodeURIComponent(String(questionId))}`,
2165
+ path: `/integration/qna/sellers/${this.transport.sellerId}/questions/${encodeURIComponent(String(questionId))}`,
1922
2166
  rateLimiter: this.limiter
1923
2167
  });
1924
2168
  return normalizeQuestion(data);
@@ -1937,7 +2181,7 @@ var QuestionsResource = class {
1937
2181
  if (params.status) query.status = params.status;
1938
2182
  const data = await this.transport.request({
1939
2183
  method: "GET",
1940
- path: `/integration/qna/sellers/${this.sellerId}/questions/filter`,
2184
+ path: `/integration/qna/sellers/${this.transport.sellerId}/questions/filter`,
1941
2185
  query,
1942
2186
  rateLimiter: this.limiter
1943
2187
  });
@@ -1968,7 +2212,7 @@ var QuestionsResource = class {
1968
2212
  }
1969
2213
  return this.transport.request({
1970
2214
  method: "POST",
1971
- path: `/integration/qna/sellers/${this.sellerId}/questions/${encodeURIComponent(String(questionId))}/answers`,
2215
+ path: `/integration/qna/sellers/${this.transport.sellerId}/questions/${encodeURIComponent(String(questionId))}/answers`,
1972
2216
  body: { text },
1973
2217
  rateLimiter: this.limiter
1974
2218
  });
@@ -2008,9 +2252,8 @@ function normalizeAddress2(node) {
2008
2252
  }
2009
2253
  var DEFAULT_CACHE_TTL_MS = 60 * 60 * 1e3;
2010
2254
  var SuppliersResource = class {
2011
- constructor(transport, sellerId, options = {}) {
2255
+ constructor(transport, options = {}) {
2012
2256
  this.transport = transport;
2013
- this.sellerId = sellerId;
2014
2257
  this.cacheTtlMs = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
2015
2258
  this.limiter = new TokenBucketRateLimiter({
2016
2259
  capacity: 1,
@@ -2018,7 +2261,6 @@ var SuppliersResource = class {
2018
2261
  });
2019
2262
  }
2020
2263
  transport;
2021
- sellerId;
2022
2264
  cache = null;
2023
2265
  cacheTtlMs;
2024
2266
  limiter;
@@ -2046,7 +2288,7 @@ var SuppliersResource = class {
2046
2288
  async fetchFresh() {
2047
2289
  const data = await this.transport.request({
2048
2290
  method: "GET",
2049
- path: `/integration/sellers/${this.sellerId}/addresses`,
2291
+ path: `/integration/sellers/${this.transport.sellerId}/addresses`,
2050
2292
  rateLimiter: this.limiter
2051
2293
  });
2052
2294
  const items = data.supplierAddresses.map(normalizeAddress2);
@@ -2055,13 +2297,11 @@ var SuppliersResource = class {
2055
2297
  }
2056
2298
  };
2057
2299
  var TestOrdersResource = class {
2058
- constructor(transport, sellerId, limiter) {
2300
+ constructor(transport, limiter) {
2059
2301
  this.transport = transport;
2060
- this.sellerId = sellerId;
2061
2302
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 60, intervalMs: 6e4 });
2062
2303
  }
2063
2304
  transport;
2064
- sellerId;
2065
2305
  limiter;
2066
2306
  /**
2067
2307
  * Create a test order with the given customer / addresses / lines. The
@@ -2087,7 +2327,7 @@ var TestOrdersResource = class {
2087
2327
  async updateStatus(packageId, status) {
2088
2328
  return this.transport.request({
2089
2329
  method: "PUT",
2090
- path: `/integration/test/order/sellers/${this.sellerId}/shipment-packages/${encodeURIComponent(String(packageId))}/status`,
2330
+ path: `/integration/test/order/sellers/${this.transport.sellerId}/shipment-packages/${encodeURIComponent(String(packageId))}/status`,
2091
2331
  body: { status },
2092
2332
  rateLimiter: this.limiter
2093
2333
  });
@@ -2096,11 +2336,60 @@ var TestOrdersResource = class {
2096
2336
  async setClaimsWaitingInAction() {
2097
2337
  return this.transport.request({
2098
2338
  method: "PUT",
2099
- path: `/integration/test/order/sellers/${this.sellerId}/claims/waiting-in-action`,
2339
+ path: `/integration/test/order/sellers/${this.transport.sellerId}/claims/waiting-in-action`,
2100
2340
  rateLimiter: this.limiter
2101
2341
  });
2102
2342
  }
2103
2343
  };
2344
+ var VideosResource = class {
2345
+ constructor(transport, options = {}) {
2346
+ this.transport = transport;
2347
+ this.createLimiter = options.createLimiter ?? new TokenBucketRateLimiter({ capacity: 200, intervalMs: 6e4 });
2348
+ this.listLimiter = options.listLimiter ?? new TokenBucketRateLimiter({ capacity: 1e3, intervalMs: 6e4 });
2349
+ }
2350
+ transport;
2351
+ createLimiter;
2352
+ listLimiter;
2353
+ /**
2354
+ * Queue a video for upload. Trendyol downloads from the URL in the
2355
+ * body asynchronously; poll `list()` (filtered by id) for status.
2356
+ *
2357
+ * @throws {ValidationError} when `input` is empty / not an object.
2358
+ */
2359
+ async create(input) {
2360
+ if (!input || typeof input !== "object") {
2361
+ throw new ValidationError({ message: "videos.create: input is required" });
2362
+ }
2363
+ return this.transport.request({
2364
+ method: "POST",
2365
+ path: `/integration/video/sellers/${this.transport.sellerId}/videos`,
2366
+ body: input,
2367
+ rateLimiter: this.createLimiter
2368
+ });
2369
+ }
2370
+ /** List the seller's integration videos (optionally filtered by id / status). */
2371
+ async list(params = {}) {
2372
+ const data = await this.transport.request({
2373
+ method: "GET",
2374
+ path: `/integration/video/sellers/${this.transport.sellerId}/videos`,
2375
+ query: {
2376
+ id: params.id,
2377
+ sellerIntegrationStatus: params.sellerIntegrationStatus,
2378
+ page: params.offset,
2379
+ size: params.limit
2380
+ },
2381
+ rateLimiter: this.listLimiter
2382
+ });
2383
+ const rows = Array.isArray(data) ? data : Array.isArray(data?.content) ? data.content : Array.isArray(data?.items) ? data.items : [];
2384
+ return rows.map((r) => {
2385
+ const row = r ?? {};
2386
+ const out = { raw: row };
2387
+ if (typeof row.id === "string") out.id = row.id;
2388
+ if (typeof row.status === "string") out.status = row.status;
2389
+ return out;
2390
+ });
2391
+ }
2392
+ };
2104
2393
  function normalizeWebhook(node) {
2105
2394
  const out = {
2106
2395
  id: node.id !== void 0 ? String(node.id) : "",
@@ -2117,13 +2406,11 @@ function normalizeWebhook(node) {
2117
2406
  return out;
2118
2407
  }
2119
2408
  var WebhooksResource = class {
2120
- constructor(transport, sellerId, limiter) {
2409
+ constructor(transport, limiter) {
2121
2410
  this.transport = transport;
2122
- this.sellerId = sellerId;
2123
2411
  this.limiter = limiter ?? new TokenBucketRateLimiter({ capacity: 50, intervalMs: 6e4 });
2124
2412
  }
2125
2413
  transport;
2126
- sellerId;
2127
2414
  limiter;
2128
2415
  /**
2129
2416
  * Create a new webhook subscription. Trendyol caps subscriptions at 15
@@ -2136,7 +2423,7 @@ var WebhooksResource = class {
2136
2423
  this.validateInput(input, "create");
2137
2424
  return this.transport.request({
2138
2425
  method: "POST",
2139
- path: `/integration/sellers/${this.sellerId}/webhooks`,
2426
+ path: `/integration/sellers/${this.transport.sellerId}/webhooks`,
2140
2427
  body: input,
2141
2428
  rateLimiter: this.limiter
2142
2429
  });
@@ -2145,7 +2432,7 @@ var WebhooksResource = class {
2145
2432
  async list() {
2146
2433
  const data = await this.transport.request({
2147
2434
  method: "GET",
2148
- path: `/integration/sellers/${this.sellerId}/webhooks`,
2435
+ path: `/integration/sellers/${this.transport.sellerId}/webhooks`,
2149
2436
  rateLimiter: this.limiter
2150
2437
  });
2151
2438
  const rows = Array.isArray(data) ? data : Array.isArray(data?.webhooks) ? data.webhooks : Array.isArray(data?.content) ? data.content : [];
@@ -2215,7 +2502,7 @@ var WebhooksResource = class {
2215
2502
  if (input.subscribedStatuses && input.subscribedStatuses.length === 0) ;
2216
2503
  }
2217
2504
  webhookPath(webhookId) {
2218
- return `/integration/sellers/${this.sellerId}/webhooks/${encodeURIComponent(String(webhookId))}`;
2505
+ return `/integration/sellers/${this.transport.sellerId}/webhooks/${encodeURIComponent(String(webhookId))}`;
2219
2506
  }
2220
2507
  };
2221
2508
 
@@ -2297,6 +2584,10 @@ var TrendyolTransport = class {
2297
2584
  logger;
2298
2585
  timeoutMs;
2299
2586
  fetchImpl;
2587
+ /** Seller ID this transport is configured with. Resources read it for path-building. */
2588
+ get sellerId() {
2589
+ return this.config.sellerId;
2590
+ }
2300
2591
  async request(opts) {
2301
2592
  return retry(
2302
2593
  async (attempt) => {
@@ -2425,19 +2716,21 @@ function createTrendyolClient(opts) {
2425
2716
  });
2426
2717
  return {
2427
2718
  brands: new BrandsResource(transport),
2428
- categories: new CategoriesResource(transport, void 0, opts.sellerId),
2429
- suppliers: new SuppliersResource(transport, opts.sellerId),
2430
- products: new ProductsResource(transport, opts.sellerId),
2431
- inventory: new InventoryResource(transport, opts.sellerId),
2432
- orders: new OrdersResource(transport, opts.sellerId),
2433
- claims: new ClaimsResource(transport, opts.sellerId),
2434
- webhooks: new WebhooksResource(transport, opts.sellerId),
2435
- questions: new QuestionsResource(transport, opts.sellerId),
2436
- invoices: new InvoicesResource(transport, opts.sellerId),
2437
- finance: new FinanceResource(transport, opts.sellerId),
2438
- labels: new LabelsResource(transport, opts.sellerId),
2439
- testOrders: new TestOrdersResource(transport, opts.sellerId),
2440
- locations: new LocationsResource(transport)
2719
+ categories: new CategoriesResource(transport),
2720
+ suppliers: new SuppliersResource(transport),
2721
+ products: new ProductsResource(transport),
2722
+ inventory: new InventoryResource(transport),
2723
+ orders: new OrdersResource(transport),
2724
+ claims: new ClaimsResource(transport),
2725
+ webhooks: new WebhooksResource(transport),
2726
+ questions: new QuestionsResource(transport),
2727
+ invoices: new InvoicesResource(transport),
2728
+ finance: new FinanceResource(transport),
2729
+ labels: new LabelsResource(transport),
2730
+ testOrders: new TestOrdersResource(transport),
2731
+ locations: new LocationsResource(transport),
2732
+ exportCenter: new ExportCenterResource(transport),
2733
+ videos: new VideosResource(transport)
2441
2734
  };
2442
2735
  }
2443
2736
  function parseWebhookEvent(rawBody) {
@@ -2475,6 +2768,6 @@ function parseWebhookEvent(rawBody) {
2475
2768
  };
2476
2769
  }
2477
2770
 
2478
- export { BrandsResource, CategoriesResource, ClaimsResource, FinanceResource, InventoryResource, InvoicesResource, LabelsResource, LocationsResource, OrdersResource, ProductsResource, QuestionsResource, SuppliersResource, TestOrdersResource, WebhooksResource, createTrendyolClient, normalizeShipmentPackage, parseWebhookEvent };
2771
+ export { BrandsResource, CategoriesResource, ClaimsResource, ExportCenterResource, FinanceResource, InventoryResource, InvoicesResource, LabelsResource, LocationsResource, OrdersResource, ProductsResource, QuestionsResource, SuppliersResource, TestOrdersResource, VideosResource, WebhooksResource, createTrendyolClient, normalizeShipmentPackage, parseWebhookEvent };
2479
2772
  //# sourceMappingURL=index.js.map
2480
2773
  //# sourceMappingURL=index.js.map