@lonca/trendyol 0.10.0 → 0.11.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/testing.cjs CHANGED
@@ -1066,6 +1066,7 @@ var LocationsResource = class {
1066
1066
  };
1067
1067
  var MAX_PAGE_SIZE = 200;
1068
1068
  var DEFAULT_PAGE_SIZE2 = 50;
1069
+ var MAX_OFFSET_RECORDS = 1e4;
1069
1070
  function toIso3(epochMs) {
1070
1071
  if (typeof epochMs !== "number" || !Number.isFinite(epochMs) || epochMs === 0) {
1071
1072
  return void 0;
@@ -1239,6 +1240,11 @@ var OrdersResource = class {
1239
1240
  async list(params = {}) {
1240
1241
  const size = Math.min(params.limit ?? DEFAULT_PAGE_SIZE2, MAX_PAGE_SIZE);
1241
1242
  const page = params.cursor ? Number.parseInt(params.cursor, 10) : 0;
1243
+ if ((page + 1) * size > MAX_OFFSET_RECORDS) {
1244
+ throw new core.ValidationError({
1245
+ message: `getShipmentPackages can reach at most ${MAX_OFFSET_RECORDS} records (page ${page} \xD7 size ${size} exceeds it); use listStream() for full scans`
1246
+ });
1247
+ }
1242
1248
  const query = { page, size };
1243
1249
  if (params.status) query.status = params.status;
1244
1250
  if (params.orderNumber) query.orderNumber = params.orderNumber;
@@ -1692,6 +1698,7 @@ var OrdersResource = class {
1692
1698
  };
1693
1699
  var DEFAULT_PAGE_SIZE3 = 50;
1694
1700
  var MAX_PAGE_SIZE2 = 1e3;
1701
+ var MAX_INVENTORY_PAGE_SIZE = 100;
1695
1702
  var MAX_BUYBOX_BARCODES = 10;
1696
1703
  function normalizeRef(ref) {
1697
1704
  return {
@@ -1757,6 +1764,30 @@ function normalizeProduct(node) {
1757
1764
  if (node.lastModifiedBy !== void 0) out.lastModifiedBy = node.lastModifiedBy;
1758
1765
  return out;
1759
1766
  }
1767
+ function normalizeStockPriceVariant(node) {
1768
+ const out = {
1769
+ variantId: node.variantId !== void 0 ? String(node.variantId) : "",
1770
+ barcode: node.barcode ?? "",
1771
+ raw: node
1772
+ };
1773
+ if (typeof node.salePrice === "number") out.salePrice = node.salePrice;
1774
+ if (typeof node.listPrice === "number") out.listPrice = node.listPrice;
1775
+ if (typeof node.quantity === "number") out.quantity = node.quantity;
1776
+ if (node.stockCode !== void 0) out.stockCode = node.stockCode;
1777
+ if (node.stockLastModifiedDate !== void 0 && node.stockLastModifiedDate !== null) {
1778
+ const iso = toIso4(node.stockLastModifiedDate);
1779
+ if (iso) out.stockLastModifiedAt = iso;
1780
+ }
1781
+ return out;
1782
+ }
1783
+ function normalizeStockPrice(node) {
1784
+ return {
1785
+ contentId: node.contentId !== void 0 ? String(node.contentId) : "",
1786
+ productMainId: node.productMainId ?? "",
1787
+ variants: (node.variants ?? []).map(normalizeStockPriceVariant),
1788
+ raw: node
1789
+ };
1790
+ }
1760
1791
  function normalizeUnapprovedRejectReason(r) {
1761
1792
  const out = {};
1762
1793
  if (r.rejectReason !== void 0) out.rejectReason = r.rejectReason;
@@ -1947,6 +1978,63 @@ var ProductsResource = class {
1947
1978
  }
1948
1979
  return page;
1949
1980
  }
1981
+ /**
1982
+ * List **stock and price** for approved products — Trendyol's lightweight
1983
+ * `inventory-and-price` filter. A slim alternative to {@link list} when you
1984
+ * only need pricing + stock: the response carries `contentId`,
1985
+ * `productMainId`, and a `variants[]` array with `barcode`, `salePrice`,
1986
+ * `listPrice`, `quantity`, `stockCode`, and `stockLastModifiedAt` — nothing
1987
+ * else.
1988
+ *
1989
+ * Filter by `barcode`, `contentId`, `stockCode`, `productMainId`, or listing
1990
+ * `status`. Sort with `orderByDirection` (`SellerCreatedDate`). `size` caps
1991
+ * at **100** here (tighter than `list`'s 1000).
1992
+ *
1993
+ * Pagination follows the same convention as {@link list}: pass our opaque
1994
+ * `cursor` from the previous response and we forward it as `nextPageToken`
1995
+ * (required once the dataset exceeds 10,000 items).
1996
+ *
1997
+ * @example
1998
+ * ```ts
1999
+ * import { paginate } from '@lonca/core';
2000
+ * for await (const p of paginate((q) =>
2001
+ * client.products.listInventoryAndPrice({ ...q, status: 'onSale' }),
2002
+ * )) {
2003
+ * for (const v of p.variants) {
2004
+ * console.log(v.barcode, v.quantity, v.salePrice);
2005
+ * }
2006
+ * }
2007
+ * ```
2008
+ */
2009
+ async listInventoryAndPrice(params = {}) {
2010
+ const size = Math.min(params.limit ?? DEFAULT_PAGE_SIZE3, MAX_INVENTORY_PAGE_SIZE);
2011
+ const query = { size };
2012
+ if (params.cursor) {
2013
+ query.nextPageToken = params.cursor;
2014
+ } else {
2015
+ query.page = 0;
2016
+ }
2017
+ if (params.barcode) query.barcode = params.barcode;
2018
+ if (params.contentId) query.contentId = params.contentId;
2019
+ if (params.stockCode) query.stockCode = params.stockCode;
2020
+ if (params.productMainId) query.productMainId = params.productMainId;
2021
+ if (params.status) query.status = params.status;
2022
+ if (params.orderByDirection) query.orderByDirection = params.orderByDirection;
2023
+ const headers = params.storeFrontCode ? { storeFrontCode: params.storeFrontCode } : void 0;
2024
+ const data = await this.transport.request({
2025
+ method: "GET",
2026
+ path: `/integration/product/sellers/${this.transport.sellerId}/products/approved/inventory-and-price`,
2027
+ query,
2028
+ headers,
2029
+ rateLimiter: this.filterLimiter
2030
+ });
2031
+ const items = (data.content ?? []).map(normalizeStockPrice);
2032
+ const page = { items };
2033
+ if (data.nextPageToken) {
2034
+ page.nextCursor = data.nextPageToken;
2035
+ }
2036
+ return page;
2037
+ }
1950
2038
  /**
1951
2039
  * Poll a batch request returned by an async write (e.g. `createProducts`,
1952
2040
  * `updatePriceAndInventory`).
@@ -2730,7 +2818,7 @@ var TrendyolTransport = class {
2730
2818
  if (opts.rateLimiter) await opts.rateLimiter.acquire(opts.signal);
2731
2819
  const url = this.buildUrl(opts.path, opts.query);
2732
2820
  const correlationId = crypto.randomUUID();
2733
- const headers = this.buildHeaders(correlationId);
2821
+ const headers = { ...this.buildHeaders(correlationId), ...opts.headers };
2734
2822
  const init = {
2735
2823
  method: opts.method,
2736
2824
  headers,