@lonca/trendyol 0.8.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/README.md +28 -26
- package/dist/index.cjs +326 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +271 -2
- package/dist/index.d.ts +271 -2
- package/dist/index.js +325 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -395,6 +395,269 @@ var ClaimsResource = class {
|
|
|
395
395
|
return rows.map((row) => ({ raw: row }));
|
|
396
396
|
}
|
|
397
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
|
+
}
|
|
398
661
|
function toIso2(epochMs) {
|
|
399
662
|
if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
|
|
400
663
|
return void 0;
|
|
@@ -440,11 +703,14 @@ var FinanceResource = class {
|
|
|
440
703
|
transport;
|
|
441
704
|
limiter;
|
|
442
705
|
async getSettlements(params = {}) {
|
|
443
|
-
return this.queryPage(
|
|
706
|
+
return this.queryPage(
|
|
707
|
+
`/integration/finance/che/sellers/${this.transport.sellerId}/settlements`,
|
|
708
|
+
params
|
|
709
|
+
);
|
|
444
710
|
}
|
|
445
711
|
async getOtherFinancials(params = {}) {
|
|
446
712
|
return this.queryPage(
|
|
447
|
-
`/integration/sellers/${this.transport.sellerId}/otherfinancials`,
|
|
713
|
+
`/integration/finance/che/sellers/${this.transport.sellerId}/otherfinancials`,
|
|
448
714
|
params
|
|
449
715
|
);
|
|
450
716
|
}
|
|
@@ -792,9 +1058,9 @@ function normalizeCustomer(node) {
|
|
|
792
1058
|
return out;
|
|
793
1059
|
}
|
|
794
1060
|
function normalizeShipmentPackage(rawNode) {
|
|
795
|
-
return
|
|
1061
|
+
return normalizePackage2(rawNode ?? {});
|
|
796
1062
|
}
|
|
797
|
-
function
|
|
1063
|
+
function normalizePackage2(node) {
|
|
798
1064
|
const pkgId = node.shipmentPackageId ?? node.id;
|
|
799
1065
|
const out = {
|
|
800
1066
|
id: pkgId !== void 0 ? String(pkgId) : "",
|
|
@@ -895,7 +1161,7 @@ var OrdersResource = class {
|
|
|
895
1161
|
query,
|
|
896
1162
|
rateLimiter: this.limiter
|
|
897
1163
|
});
|
|
898
|
-
const items = (data.content ?? []).map(
|
|
1164
|
+
const items = (data.content ?? []).map(normalizePackage2);
|
|
899
1165
|
const totalPages = typeof data.totalPages === "number" ? data.totalPages : 0;
|
|
900
1166
|
const result = { items };
|
|
901
1167
|
if (page + 1 < totalPages) {
|
|
@@ -1192,7 +1458,7 @@ var OrdersResource = class {
|
|
|
1192
1458
|
query,
|
|
1193
1459
|
rateLimiter: this.limiter
|
|
1194
1460
|
});
|
|
1195
|
-
const items = (data.content ?? []).map(
|
|
1461
|
+
const items = (data.content ?? []).map(normalizePackage2);
|
|
1196
1462
|
const result = { items };
|
|
1197
1463
|
if (data.hasMore && data.nextCursor) {
|
|
1198
1464
|
result.nextCursor = data.nextCursor;
|
|
@@ -2075,6 +2341,55 @@ var TestOrdersResource = class {
|
|
|
2075
2341
|
});
|
|
2076
2342
|
}
|
|
2077
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
|
+
};
|
|
2078
2393
|
function normalizeWebhook(node) {
|
|
2079
2394
|
const out = {
|
|
2080
2395
|
id: node.id !== void 0 ? String(node.id) : "",
|
|
@@ -2413,7 +2728,9 @@ function createTrendyolClient(opts) {
|
|
|
2413
2728
|
finance: new FinanceResource(transport),
|
|
2414
2729
|
labels: new LabelsResource(transport),
|
|
2415
2730
|
testOrders: new TestOrdersResource(transport),
|
|
2416
|
-
locations: new LocationsResource(transport)
|
|
2731
|
+
locations: new LocationsResource(transport),
|
|
2732
|
+
exportCenter: new ExportCenterResource(transport),
|
|
2733
|
+
videos: new VideosResource(transport)
|
|
2417
2734
|
};
|
|
2418
2735
|
}
|
|
2419
2736
|
function parseWebhookEvent(rawBody) {
|
|
@@ -2451,6 +2768,6 @@ function parseWebhookEvent(rawBody) {
|
|
|
2451
2768
|
};
|
|
2452
2769
|
}
|
|
2453
2770
|
|
|
2454
|
-
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 };
|
|
2455
2772
|
//# sourceMappingURL=index.js.map
|
|
2456
2773
|
//# sourceMappingURL=index.js.map
|