@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.cjs
CHANGED
|
@@ -408,6 +408,43 @@ var ClaimsResource = class {
|
|
|
408
408
|
return rows.map((row) => ({ raw: row }));
|
|
409
409
|
}
|
|
410
410
|
};
|
|
411
|
+
function toIso2(epochMs) {
|
|
412
|
+
if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
return new Date(epochMs).toISOString();
|
|
416
|
+
}
|
|
417
|
+
function normalizeRow(row) {
|
|
418
|
+
const out = {
|
|
419
|
+
id: row.id !== void 0 ? String(row.id) : "",
|
|
420
|
+
raw: row
|
|
421
|
+
};
|
|
422
|
+
const tx = toIso2(row.transactionDate);
|
|
423
|
+
if (tx) out.transactionDate = tx;
|
|
424
|
+
if (row.barcode !== void 0) out.barcode = row.barcode;
|
|
425
|
+
if (row.transactionType !== void 0) out.transactionType = row.transactionType;
|
|
426
|
+
if (row.receiptId !== void 0) out.receiptId = row.receiptId;
|
|
427
|
+
if (row.description !== void 0) out.description = row.description;
|
|
428
|
+
if (typeof row.debt === "number") out.debt = row.debt;
|
|
429
|
+
if (typeof row.credit === "number") out.credit = row.credit;
|
|
430
|
+
if (row.paymentPeriod !== void 0) out.paymentPeriod = row.paymentPeriod;
|
|
431
|
+
if (row.commissionRate !== void 0) out.commissionRate = row.commissionRate;
|
|
432
|
+
if (row.commissionAmount !== void 0) out.commissionAmount = row.commissionAmount;
|
|
433
|
+
if (row.commissionInvoiceSerialNumber !== void 0) {
|
|
434
|
+
out.commissionInvoiceSerialNumber = row.commissionInvoiceSerialNumber;
|
|
435
|
+
}
|
|
436
|
+
if (row.sellerRevenue !== void 0) out.sellerRevenue = row.sellerRevenue;
|
|
437
|
+
if (row.orderNumber !== void 0) out.orderNumber = row.orderNumber;
|
|
438
|
+
if (row.paymentOrderId !== void 0) out.paymentOrderId = row.paymentOrderId;
|
|
439
|
+
const pay = toIso2(row.paymentDate);
|
|
440
|
+
if (pay) out.paymentDate = pay;
|
|
441
|
+
if (typeof row.sellerId === "number") out.sellerId = row.sellerId;
|
|
442
|
+
if (row.storeId !== void 0) out.storeId = row.storeId;
|
|
443
|
+
if (row.storeName !== void 0) out.storeName = row.storeName;
|
|
444
|
+
if (row.storeAddress !== void 0) out.storeAddress = row.storeAddress;
|
|
445
|
+
if (row.country !== void 0) out.country = row.country;
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
411
448
|
var FinanceResource = class {
|
|
412
449
|
constructor(transport, sellerId, limiter) {
|
|
413
450
|
this.transport = transport;
|
|
@@ -436,7 +473,7 @@ var FinanceResource = class {
|
|
|
436
473
|
query,
|
|
437
474
|
rateLimiter: this.limiter
|
|
438
475
|
});
|
|
439
|
-
const items = (data.content ?? []).map(
|
|
476
|
+
const items = (data.content ?? []).map(normalizeRow);
|
|
440
477
|
const result = { items };
|
|
441
478
|
const totalPages = typeof data.totalPages === "number" ? data.totalPages : 0;
|
|
442
479
|
if (page + 1 < totalPages) {
|
|
@@ -571,14 +608,25 @@ var LabelsResource = class {
|
|
|
571
608
|
rateLimiter: this.limiter
|
|
572
609
|
});
|
|
573
610
|
}
|
|
574
|
-
/**
|
|
611
|
+
/**
|
|
612
|
+
* Retrieve the previously-created common label. Trendyol returns
|
|
613
|
+
* `{ data: [{ label, format }] }`; the SDK surfaces the array as
|
|
614
|
+
* `labels[]` for ergonomic access.
|
|
615
|
+
*
|
|
616
|
+
* Typically `labels.length === 1` per tracking number, but kept as an
|
|
617
|
+
* array to match the wire shape.
|
|
618
|
+
*/
|
|
575
619
|
async getCommon(cargoTrackingNumber) {
|
|
576
|
-
const
|
|
620
|
+
const raw = await this.transport.request({
|
|
577
621
|
method: "GET",
|
|
578
622
|
path: `/integration/sellers/${this.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
|
|
579
623
|
rateLimiter: this.limiter
|
|
580
624
|
});
|
|
581
|
-
|
|
625
|
+
const labels = (raw?.data ?? []).map((row) => ({
|
|
626
|
+
label: row.label ?? "",
|
|
627
|
+
format: row.format ?? "ZPL"
|
|
628
|
+
}));
|
|
629
|
+
return { labels, raw: raw ?? {} };
|
|
582
630
|
}
|
|
583
631
|
};
|
|
584
632
|
function n(rows, extract) {
|
|
@@ -678,7 +726,7 @@ var LocationsResource = class {
|
|
|
678
726
|
};
|
|
679
727
|
var MAX_PAGE_SIZE = 200;
|
|
680
728
|
var DEFAULT_PAGE_SIZE2 = 50;
|
|
681
|
-
function
|
|
729
|
+
function toIso3(epochMs) {
|
|
682
730
|
if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
|
|
683
731
|
return void 0;
|
|
684
732
|
}
|
|
@@ -746,7 +794,7 @@ function normalizeLine(node) {
|
|
|
746
794
|
function normalizeHistory(node) {
|
|
747
795
|
const out = { raw: node };
|
|
748
796
|
if (node.status !== void 0) out.status = node.status;
|
|
749
|
-
const createdAt =
|
|
797
|
+
const createdAt = toIso3(node.createdDate);
|
|
750
798
|
if (createdAt) out.createdAt = createdAt;
|
|
751
799
|
return out;
|
|
752
800
|
}
|
|
@@ -761,6 +809,9 @@ function normalizeCustomer(node) {
|
|
|
761
809
|
if (node.identityNumber !== void 0) out.identityNumber = node.identityNumber;
|
|
762
810
|
return out;
|
|
763
811
|
}
|
|
812
|
+
function normalizeShipmentPackage(rawNode) {
|
|
813
|
+
return normalizePackage(rawNode ?? {});
|
|
814
|
+
}
|
|
764
815
|
function normalizePackage(node) {
|
|
765
816
|
const pkgId = node.shipmentPackageId ?? node.id;
|
|
766
817
|
const out = {
|
|
@@ -768,8 +819,8 @@ function normalizePackage(node) {
|
|
|
768
819
|
orderNumber: node.orderNumber ?? "",
|
|
769
820
|
status: node.status ?? "",
|
|
770
821
|
customer: normalizeCustomer(node),
|
|
771
|
-
orderDate:
|
|
772
|
-
lastModifiedDate:
|
|
822
|
+
orderDate: toIso3(node.orderDate) ?? "",
|
|
823
|
+
lastModifiedDate: toIso3(node.lastModifiedDate) ?? "",
|
|
773
824
|
currencyCode: node.currencyCode ?? "",
|
|
774
825
|
packageTotalPrice: typeof node.packageTotalPrice === "number" ? node.packageTotalPrice : 0,
|
|
775
826
|
packageGrossAmount: typeof node.packageGrossAmount === "number" ? node.packageGrossAmount : 0,
|
|
@@ -789,13 +840,13 @@ function normalizePackage(node) {
|
|
|
789
840
|
if (node.shipmentPackageStatus !== void 0) {
|
|
790
841
|
out.shipmentPackageStatus = node.shipmentPackageStatus;
|
|
791
842
|
}
|
|
792
|
-
const agreed =
|
|
843
|
+
const agreed = toIso3(node.agreedDeliveryDate);
|
|
793
844
|
if (agreed) out.agreedDeliveryDate = agreed;
|
|
794
|
-
const estStart =
|
|
845
|
+
const estStart = toIso3(node.estimatedDeliveryStartDate);
|
|
795
846
|
if (estStart) out.estimatedDeliveryStartDate = estStart;
|
|
796
|
-
const estEnd =
|
|
847
|
+
const estEnd = toIso3(node.estimatedDeliveryEndDate);
|
|
797
848
|
if (estEnd) out.estimatedDeliveryEndDate = estEnd;
|
|
798
|
-
const origin =
|
|
849
|
+
const origin = toIso3(node.originShipmentDate);
|
|
799
850
|
if (origin) out.originShipmentDate = origin;
|
|
800
851
|
const invoice = normalizeAddress(node.invoiceAddress);
|
|
801
852
|
if (invoice) out.invoiceAddress = invoice;
|
|
@@ -1281,7 +1332,7 @@ var OrdersResource = class {
|
|
|
1281
1332
|
};
|
|
1282
1333
|
if (t.cargoProvider !== void 0) out.cargoProvider = t.cargoProvider;
|
|
1283
1334
|
if (t.compensateReason !== void 0) out.compensateReason = t.compensateReason;
|
|
1284
|
-
const createdAt =
|
|
1335
|
+
const createdAt = toIso3(t.createDate);
|
|
1285
1336
|
if (createdAt) out.createdAt = createdAt;
|
|
1286
1337
|
if (t.currentState !== void 0) {
|
|
1287
1338
|
out.currentState = t.currentState;
|
|
@@ -1349,7 +1400,7 @@ function normalizeVariant(variant) {
|
|
|
1349
1400
|
if (stock !== void 0) out.stock = stock;
|
|
1350
1401
|
return out;
|
|
1351
1402
|
}
|
|
1352
|
-
function
|
|
1403
|
+
function toIso4(epochMs) {
|
|
1353
1404
|
if (typeof epochMs !== "number" || !Number.isFinite(epochMs)) return void 0;
|
|
1354
1405
|
return new Date(epochMs).toISOString();
|
|
1355
1406
|
}
|
|
@@ -1363,8 +1414,8 @@ function normalizeProduct(node) {
|
|
|
1363
1414
|
images: normalizeImages(node.images),
|
|
1364
1415
|
attributes: (node.attributes ?? []).map(normalizeAttribute2),
|
|
1365
1416
|
variants: (node.variants ?? []).map(normalizeVariant),
|
|
1366
|
-
createdAt:
|
|
1367
|
-
updatedAt:
|
|
1417
|
+
createdAt: toIso4(node.creationDate) ?? "",
|
|
1418
|
+
updatedAt: toIso4(node.lastModifiedDate) ?? "",
|
|
1368
1419
|
raw: node
|
|
1369
1420
|
};
|
|
1370
1421
|
if (node.description !== void 0) out.description = node.description;
|
|
@@ -1410,13 +1461,13 @@ function normalizeUnapproved(node) {
|
|
|
1410
1461
|
out.specialConsumptionTax = node.specialConsumptionTax;
|
|
1411
1462
|
}
|
|
1412
1463
|
if (node.sgrPrice !== void 0) out.sgrPrice = node.sgrPrice;
|
|
1413
|
-
const createdAt =
|
|
1464
|
+
const createdAt = toIso4(node.createDateTime);
|
|
1414
1465
|
if (createdAt) out.createdAt = createdAt;
|
|
1415
|
-
const updatedAt =
|
|
1466
|
+
const updatedAt = toIso4(node.lastUpdateDate);
|
|
1416
1467
|
if (updatedAt) out.updatedAt = updatedAt;
|
|
1417
|
-
const priceChanged =
|
|
1468
|
+
const priceChanged = toIso4(node.lastPriceChangeDate);
|
|
1418
1469
|
if (priceChanged) out.lastPriceChangedAt = priceChanged;
|
|
1419
|
-
const stockChanged =
|
|
1470
|
+
const stockChanged = toIso4(node.lastStockChangeDate);
|
|
1420
1471
|
if (stockChanged) out.lastStockChangedAt = stockChanged;
|
|
1421
1472
|
return out;
|
|
1422
1473
|
}
|
|
@@ -1441,7 +1492,7 @@ function normalizeProductBase(data) {
|
|
|
1441
1492
|
archived: !!data.archived,
|
|
1442
1493
|
raw: data
|
|
1443
1494
|
};
|
|
1444
|
-
const approvedAt =
|
|
1495
|
+
const approvedAt = toIso4(data.approvedDate);
|
|
1445
1496
|
if (approvedAt) out.approvedAt = approvedAt;
|
|
1446
1497
|
if (data.listingId !== void 0) out.listingId = data.listingId;
|
|
1447
1498
|
if (data.contentId !== void 0) out.contentId = String(data.contentId);
|
|
@@ -1463,9 +1514,9 @@ function normalizeBatchResult(data) {
|
|
|
1463
1514
|
};
|
|
1464
1515
|
if (typeof data.itemCount === "number") out.itemCount = data.itemCount;
|
|
1465
1516
|
if (typeof data.failedItemCount === "number") out.failedItemCount = data.failedItemCount;
|
|
1466
|
-
const createdAt =
|
|
1517
|
+
const createdAt = toIso4(data.creationDate);
|
|
1467
1518
|
if (createdAt) out.createdAt = createdAt;
|
|
1468
|
-
const lastModifiedAt =
|
|
1519
|
+
const lastModifiedAt = toIso4(data.lastModification);
|
|
1469
1520
|
if (lastModifiedAt) out.lastModifiedAt = lastModifiedAt;
|
|
1470
1521
|
if (data.sourceType !== void 0) out.sourceType = data.sourceType;
|
|
1471
1522
|
if (data.batchRequestType !== void 0) out.batchRequestType = data.batchRequestType;
|
|
@@ -1811,7 +1862,7 @@ var ProductsResource = class {
|
|
|
1811
1862
|
return { batchRequestId: data?.batchRequestId ?? "" };
|
|
1812
1863
|
}
|
|
1813
1864
|
};
|
|
1814
|
-
function
|
|
1865
|
+
function toIso5(epochMs) {
|
|
1815
1866
|
if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
|
|
1816
1867
|
return void 0;
|
|
1817
1868
|
}
|
|
@@ -1821,7 +1872,7 @@ function normalizeAnswer(a) {
|
|
|
1821
1872
|
if (!a) return void 0;
|
|
1822
1873
|
const out = {};
|
|
1823
1874
|
if (a.text !== void 0) out.text = a.text;
|
|
1824
|
-
const createdAt =
|
|
1875
|
+
const createdAt = toIso5(a.creationDate);
|
|
1825
1876
|
if (createdAt) out.createdAt = createdAt;
|
|
1826
1877
|
if (a.status !== void 0) out.status = a.status;
|
|
1827
1878
|
return out;
|
|
@@ -1841,18 +1892,18 @@ function normalizeQuestion(node) {
|
|
|
1841
1892
|
if (node.productName !== void 0) out.productName = node.productName;
|
|
1842
1893
|
if (node.imageUrl !== void 0) out.imageUrl = node.imageUrl;
|
|
1843
1894
|
if (node.webUrl !== void 0) out.webUrl = node.webUrl;
|
|
1844
|
-
const createdAt =
|
|
1895
|
+
const createdAt = toIso5(node.creationDate);
|
|
1845
1896
|
if (createdAt) out.createdAt = createdAt;
|
|
1846
1897
|
if (node.answeredDateMessage !== void 0) out.answeredDateMessage = node.answeredDateMessage;
|
|
1847
1898
|
const answer = normalizeAnswer(node.answer);
|
|
1848
1899
|
if (answer) out.answer = answer;
|
|
1849
1900
|
const rejectedAnswer = normalizeAnswer(node.rejectedAnswer);
|
|
1850
1901
|
if (rejectedAnswer) out.rejectedAnswer = rejectedAnswer;
|
|
1851
|
-
const rejectedAt =
|
|
1902
|
+
const rejectedAt = toIso5(node.rejectedDate);
|
|
1852
1903
|
if (rejectedAt) out.rejectedAt = rejectedAt;
|
|
1853
1904
|
if (node.reason !== void 0) out.reason = node.reason;
|
|
1854
1905
|
if (node.reportReason !== void 0) out.reportReason = node.reportReason;
|
|
1855
|
-
const reportedAt =
|
|
1906
|
+
const reportedAt = toIso5(node.reportedDate);
|
|
1856
1907
|
if (reportedAt) out.reportedAt = reportedAt;
|
|
1857
1908
|
return out;
|
|
1858
1909
|
}
|
|
@@ -2392,6 +2443,40 @@ function createTrendyolClient(opts) {
|
|
|
2392
2443
|
locations: new LocationsResource(transport)
|
|
2393
2444
|
};
|
|
2394
2445
|
}
|
|
2446
|
+
function parseWebhookEvent(rawBody) {
|
|
2447
|
+
let body;
|
|
2448
|
+
if (typeof rawBody === "string") {
|
|
2449
|
+
try {
|
|
2450
|
+
body = JSON.parse(rawBody);
|
|
2451
|
+
} catch {
|
|
2452
|
+
throw new core.ValidationError({
|
|
2453
|
+
message: "parseWebhookEvent: rawBody is not valid JSON"
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
} else if (rawBody && typeof rawBody === "object") {
|
|
2457
|
+
body = rawBody;
|
|
2458
|
+
} else {
|
|
2459
|
+
throw new core.ValidationError({
|
|
2460
|
+
message: "parseWebhookEvent: rawBody must be an object or JSON string"
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
const content = body.content;
|
|
2464
|
+
if (!Array.isArray(content)) {
|
|
2465
|
+
throw new core.ValidationError({
|
|
2466
|
+
message: "parseWebhookEvent: body.content must be an array"
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
return {
|
|
2470
|
+
packages: content.map(normalizeShipmentPackage),
|
|
2471
|
+
pageInfo: {
|
|
2472
|
+
totalElements: typeof body.totalElements === "number" ? body.totalElements : void 0,
|
|
2473
|
+
totalPages: typeof body.totalPages === "number" ? body.totalPages : void 0,
|
|
2474
|
+
page: typeof body.page === "number" ? body.page : void 0,
|
|
2475
|
+
size: typeof body.size === "number" ? body.size : void 0
|
|
2476
|
+
},
|
|
2477
|
+
raw: body
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2395
2480
|
|
|
2396
2481
|
exports.BrandsResource = BrandsResource;
|
|
2397
2482
|
exports.CategoriesResource = CategoriesResource;
|
|
@@ -2408,5 +2493,7 @@ exports.SuppliersResource = SuppliersResource;
|
|
|
2408
2493
|
exports.TestOrdersResource = TestOrdersResource;
|
|
2409
2494
|
exports.WebhooksResource = WebhooksResource;
|
|
2410
2495
|
exports.createTrendyolClient = createTrendyolClient;
|
|
2496
|
+
exports.normalizeShipmentPackage = normalizeShipmentPackage;
|
|
2497
|
+
exports.parseWebhookEvent = parseWebhookEvent;
|
|
2411
2498
|
//# sourceMappingURL=index.cjs.map
|
|
2412
2499
|
//# sourceMappingURL=index.cjs.map
|