@omni-commerce/sdk 0.28.0 → 0.29.1

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 CHANGED
@@ -260,7 +260,7 @@ const filters = {
260
260
  const count = await client.products.count(filters);
261
261
  console.log(count.count, count.unit); // catalog_products
262
262
 
263
- // Download records only when needed. Each chunk defaults to one page (up to 50 rows).
263
+ // Download records only when needed. Each chunk defaults to one page (up to 20 rows).
264
264
  const chunk = await client.products.scan(filters, {
265
265
  maxPages: 1,
266
266
  onProgress: async (progress, items) => {
@@ -276,7 +276,7 @@ const chunk = await client.products.scan(filters, {
276
276
 
277
277
  Continuation requests retain the original filters, use a server cursor when available, and otherwise use `nextOffset`. The cursor is bound to the credential organization and filter scope; resume under the same scope. Default `created_desc` order without search supports cursors. Other sorts use offsets and can shift if the catalog changes. Scans are not immutable database snapshots. Never persist API keys with a checkpoint. Per-request timeouts, retry settings and cancellation use the normal request options.
278
278
 
279
- For manual paging, `products.list({ ...filters, includeSummary: false })` omits `summary` and returns `pagination.total: null`. Use `products.count(filters)` when a total is needed. The default list response keeps its summary and total.
279
+ For manual paging, `products.list(filters)` returns 20 rows per page. Follow `pagination.nextCursor` (default and `updated_desc` sorts without `q`); other sorts and searches page by `nextOffset` up to `pagination.maxOffset` (1000). Counts are omitted unless you pass `includeSummary: true`; `products.count(filters)` returns a count alone.
280
280
 
281
281
  ## Resources
282
282
 
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ function normalizeClientOptions(options = {}) {
35
35
  }
36
36
 
37
37
  // src/version.ts
38
- var SDK_VERSION = "0.28.0";
38
+ var SDK_VERSION = "0.29.1";
39
39
  var SDK_USER_AGENT = `omnicommerce-js/${SDK_VERSION}`;
40
40
 
41
41
  // src/environments.ts
@@ -465,7 +465,7 @@ function encodePathParam(name, value) {
465
465
  var ProductScanError = class extends Error {
466
466
  constructor(partial, cause) {
467
467
  super(
468
- "Product scan failed. Resume from partial.next after saving partial.items."
468
+ partial.next ? "Product scan failed. Resume from partial.next after saving partial.items." : "Product scan failed. See the cause and the pages saved in partial.items."
469
469
  );
470
470
  __publicField(this, "partial", partial);
471
471
  __publicField(this, "cause", cause);
@@ -478,13 +478,14 @@ async function scanProducts(list, request, options = {}) {
478
478
  throw new RangeError("maxPages must be an integer between 1 and 100.");
479
479
  if ("queryParams" in requestOptions)
480
480
  throw new TypeError("Pass scan filters in the request, not queryParams.");
481
- let next = { limit: 50, offset: 0, ...request };
481
+ let next = { ...request };
482
482
  const items = [];
483
483
  let pagesRead = 0;
484
+ let complete = false;
484
485
  const progress = () => ({
485
486
  pagesRead,
486
487
  itemsRead: items.length,
487
- complete: next === null,
488
+ complete,
488
489
  next: next ? { ...next } : null
489
490
  });
490
491
  try {
@@ -499,19 +500,29 @@ async function scanProducts(list, request, options = {}) {
499
500
  if (!Array.isArray(page.items) || typeof pagination?.hasMore !== "boolean")
500
501
  throw new Error("Invalid product page response.");
501
502
  if (pagination.hasMore) {
502
- if (!page.items.length || !Number.isInteger(pagination.nextOffset) || pagination.nextOffset <= (current.offset ?? 0) || pagination.nextCursor != null && (typeof pagination.nextCursor !== "string" || !pagination.nextCursor || pagination.nextCursor === current.cursor))
503
+ if (!page.items.length)
503
504
  throw new Error("Product pagination did not advance.");
504
- const continuation = {
505
- ...current,
506
- offset: pagination.nextOffset
507
- };
508
- if (pagination.nextCursor) continuation.cursor = pagination.nextCursor;
509
- else delete continuation.cursor;
510
- next = continuation;
505
+ const scope = { ...current };
506
+ delete scope.cursor;
507
+ delete scope.offset;
508
+ if (typeof pagination.nextCursor === "string" && pagination.nextCursor) {
509
+ if (pagination.nextCursor === current.cursor)
510
+ throw new Error("Product pagination did not advance.");
511
+ next = { ...scope, cursor: pagination.nextCursor };
512
+ } else if (Number.isInteger(pagination.nextOffset)) {
513
+ if (pagination.nextOffset <= (current.offset ?? 0))
514
+ throw new Error("Product pagination did not advance.");
515
+ next = { ...scope, offset: pagination.nextOffset };
516
+ } else next = null;
511
517
  } else next = null;
518
+ complete = !pagination.hasMore;
512
519
  items.push(...page.items);
513
520
  pagesRead++;
514
521
  await onProgress?.(progress(), [...page.items]);
522
+ if (!next && !complete)
523
+ throw new Error(
524
+ "Product pagination reached maxOffset. Scan with sortBy created_desc or updated_desc and no q to use a cursor, or narrow the filters."
525
+ );
515
526
  }
516
527
  return { ...progress(), items };
517
528
  } catch (cause) {
@@ -3404,7 +3415,7 @@ var ProductsClient = class {
3404
3415
  /**
3405
3416
  * List Products
3406
3417
  *
3407
- * List products for the authenticated organization with optional filters and pagination. Authenticate with an API key or OAuth bearer token. The organization is taken from that credential; do not send `organizationId`.
3418
+ * List products for the authenticated organization with optional filters and pagination. Requires `catalog:read`. The organization comes from the API key or OAuth bearer token.
3408
3419
 
3409
3420
  ### Stock and variants
3410
3421
 
@@ -3412,7 +3423,7 @@ var ProductsClient = class {
3412
3423
 
3413
3424
  ### Duplicate discovery and merge
3414
3425
 
3415
- Use status=duplicates, duplicateType=sku and detail=full for exact-SKU candidates. Each root ro
3426
+ Use status=duplicates, duplicateType=sku and detail=full for exact-SKU candidates. Each root row includes duplicateMatches with peer prod
3416
3427
  *
3417
3428
  * `GET /api/v1/products`
3418
3429
  */
@@ -3426,7 +3437,6 @@ var ProductsClient = class {
3426
3437
  minPrice,
3427
3438
  maxPrice,
3428
3439
  sortBy,
3429
- limit,
3430
3440
  offset,
3431
3441
  store,
3432
3442
  storeKeys,
@@ -3456,7 +3466,6 @@ var ProductsClient = class {
3456
3466
  minPrice,
3457
3467
  maxPrice,
3458
3468
  sortBy,
3459
- limit,
3460
3469
  offset,
3461
3470
  store,
3462
3471
  storeKeys,