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