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