@usethrottle/catalog 0.1.1 → 1.1.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.d.cts CHANGED
@@ -1,7 +1,8 @@
1
- import { S as StorefrontCategoryNode, a as StorefrontListAnswer, b as StorefrontListProduct, c as StorefrontProductAnswer } from './types-DYfIvIaI.cjs';
2
- export { C as CallOptions, d as CartCheckAnswer, e as CartCheckRequest, f as CartCheckout, g as CartCheckoutInput, h as CartCreateAnswer, i as CartCreateRequest, j as CartSession, k as CartSessionBranding, l as CartSessionDetail, m as CartSessionSnapshot, n as CartsNamespace, o as CatalogClientOptions, p as CatalogContractErrorCode, q as CatalogHttpCache, r as CatalogHttpCacheEntry, s as CatalogNamespaces, t as CategoriesNamespace, u as CollectionsNamespace, v as CustomerTokenSource, F as FieldsOption, w as FiltersNamespace, N as NextFetchOptions, P as ProductsNamespace, x as ProductsQuery, R as Redirect, y as ReviewEligibilityAnswer, z as ReviewSubmitAnswer, A as ReviewSubmitInput, B as ReviewsNamespace, D as SessionCallOptions, E as StorefrontCategoriesAnswer, G as StorefrontCategoryAnswer, H as StorefrontCollectionAnswer, I as StorefrontCollectionsAnswer, J as StorefrontConfigAnswer, K as StorefrontFilterValuesAnswer, L as StorefrontRelatedAnswer, M as StorefrontReviewsAnswer, O as StorefrontSort, Q as StorefrontSuggestAnswer, T as StorefrontTagsAnswer, U as TagsNamespace, V as ThrottleCart, W as ThrottleLine } from './types-DYfIvIaI.cjs';
3
- export { C as CatalogClient, S as SDK_VERSION, c as createCatalogClient } from './client-BNtBTEyh.cjs';
4
- export { C as CartLineError, a as CartLineProblem, b as CatalogError, c as CatalogErrorCode, d as CatalogErrorInit, e as CatalogErrorIssue, f as CatalogErrorSource, g as ClientErrorCode, h as CustomerTokenInvalidError, F as FeatureUnavailableError, N as NetworkError, O as OriginNotAllowedError, R as RateLimitedError, T as ThrottleCartCode, i as TimeoutError, j as isCatalogError } from './catalog-error-DO6ANrGR.cjs';
1
+ import { S as StorefrontCategoryNode, a as StorefrontListAnswer, b as StorefrontListProduct, c as StorefrontProductAnswer } from './contract-types-DhiThMEr.cjs';
2
+ export { C as CartCheckAnswer, d as CartCheckRequest, e as CartCreateAnswer, f as CartCreateRequest, g as CatalogContractErrorCode, R as ReviewEligibilityAnswer, h as ReviewSubmitAnswer, i as ReviewSubmitInput, j as StorefrontCategoriesAnswer, k as StorefrontCategoryAnswer, l as StorefrontCollectionAnswer, m as StorefrontCollectionsAnswer, n as StorefrontConfigAnswer, o as StorefrontFilterValuesAnswer, p as StorefrontRelatedAnswer, q as StorefrontReviewsAnswer, r as StorefrontSuggestAnswer, s as StorefrontTagsAnswer } from './contract-types-DhiThMEr.cjs';
3
+ export { C as CatalogClient, S as SDK_VERSION, c as createCatalogClient } from './client-BAoq6jmM.cjs';
4
+ export { C as CallOptions, a as CartCheckout, b as CartCheckoutInput, c as CartSession, d as CartSessionBranding, e as CartSessionDetail, f as CartSessionSnapshot, g as CartsNamespace, h as CatalogClientOptions, i as CatalogHttpCache, j as CatalogHttpCacheEntry, k as CatalogNamespaces, l as CategoriesNamespace, m as CategoryTreeDepth, n as CollectionsNamespace, o as CustomerTokenSource, F as FieldsOption, p as FiltersNamespace, N as NextFetchOptions, P as ProductsNamespace, q as ProductsQuery, R as Redirect, r as ReviewsNamespace, S as SessionCallOptions, s as StorefrontSort, T as TagsNamespace, t as ThrottleCart, u as ThrottleLine } from './types-DsjoG8ce.cjs';
5
+ export { C as CartLineError, a as CartLineProblem, b as CatalogError, c as CatalogErrorCode, d as CatalogErrorInit, e as CatalogErrorIssue, f as CatalogErrorSource, g as ClientErrorCode, h as CustomerTokenInvalidError, F as FeatureUnavailableError, N as NetworkError, O as OriginNotAllowedError, R as RateLimitedError, j as ThrottleCartCode, T as TimeoutError, i as isCatalogError } from './catalog-error-s1BINNkt.cjs';
5
6
 
6
7
  /** A product as `products.get` answers it (the full projection). */
7
8
  type StorefrontProduct = StorefrontProductAnswer['product'];
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { S as StorefrontCategoryNode, a as StorefrontListAnswer, b as StorefrontListProduct, c as StorefrontProductAnswer } from './types-DYfIvIaI.js';
2
- export { C as CallOptions, d as CartCheckAnswer, e as CartCheckRequest, f as CartCheckout, g as CartCheckoutInput, h as CartCreateAnswer, i as CartCreateRequest, j as CartSession, k as CartSessionBranding, l as CartSessionDetail, m as CartSessionSnapshot, n as CartsNamespace, o as CatalogClientOptions, p as CatalogContractErrorCode, q as CatalogHttpCache, r as CatalogHttpCacheEntry, s as CatalogNamespaces, t as CategoriesNamespace, u as CollectionsNamespace, v as CustomerTokenSource, F as FieldsOption, w as FiltersNamespace, N as NextFetchOptions, P as ProductsNamespace, x as ProductsQuery, R as Redirect, y as ReviewEligibilityAnswer, z as ReviewSubmitAnswer, A as ReviewSubmitInput, B as ReviewsNamespace, D as SessionCallOptions, E as StorefrontCategoriesAnswer, G as StorefrontCategoryAnswer, H as StorefrontCollectionAnswer, I as StorefrontCollectionsAnswer, J as StorefrontConfigAnswer, K as StorefrontFilterValuesAnswer, L as StorefrontRelatedAnswer, M as StorefrontReviewsAnswer, O as StorefrontSort, Q as StorefrontSuggestAnswer, T as StorefrontTagsAnswer, U as TagsNamespace, V as ThrottleCart, W as ThrottleLine } from './types-DYfIvIaI.js';
3
- export { C as CatalogClient, S as SDK_VERSION, c as createCatalogClient } from './client-CHLvULRQ.js';
4
- export { C as CartLineError, a as CartLineProblem, b as CatalogError, c as CatalogErrorCode, d as CatalogErrorInit, e as CatalogErrorIssue, f as CatalogErrorSource, g as ClientErrorCode, h as CustomerTokenInvalidError, F as FeatureUnavailableError, N as NetworkError, O as OriginNotAllowedError, R as RateLimitedError, T as ThrottleCartCode, i as TimeoutError, j as isCatalogError } from './catalog-error-BWUoZCzY.js';
1
+ import { S as StorefrontCategoryNode, a as StorefrontListAnswer, b as StorefrontListProduct, c as StorefrontProductAnswer } from './contract-types-DhiThMEr.js';
2
+ export { C as CartCheckAnswer, d as CartCheckRequest, e as CartCreateAnswer, f as CartCreateRequest, g as CatalogContractErrorCode, R as ReviewEligibilityAnswer, h as ReviewSubmitAnswer, i as ReviewSubmitInput, j as StorefrontCategoriesAnswer, k as StorefrontCategoryAnswer, l as StorefrontCollectionAnswer, m as StorefrontCollectionsAnswer, n as StorefrontConfigAnswer, o as StorefrontFilterValuesAnswer, p as StorefrontRelatedAnswer, q as StorefrontReviewsAnswer, r as StorefrontSuggestAnswer, s as StorefrontTagsAnswer } from './contract-types-DhiThMEr.js';
3
+ export { C as CatalogClient, S as SDK_VERSION, c as createCatalogClient } from './client-c2F-eCaL.js';
4
+ export { C as CallOptions, a as CartCheckout, b as CartCheckoutInput, c as CartSession, d as CartSessionBranding, e as CartSessionDetail, f as CartSessionSnapshot, g as CartsNamespace, h as CatalogClientOptions, i as CatalogHttpCache, j as CatalogHttpCacheEntry, k as CatalogNamespaces, l as CategoriesNamespace, m as CategoryTreeDepth, n as CollectionsNamespace, o as CustomerTokenSource, F as FieldsOption, p as FiltersNamespace, N as NextFetchOptions, P as ProductsNamespace, q as ProductsQuery, R as Redirect, r as ReviewsNamespace, S as SessionCallOptions, s as StorefrontSort, T as TagsNamespace, t as ThrottleCart, u as ThrottleLine } from './types-xQLID-4j.js';
5
+ export { C as CartLineError, a as CartLineProblem, b as CatalogError, c as CatalogErrorCode, d as CatalogErrorInit, e as CatalogErrorIssue, f as CatalogErrorSource, g as ClientErrorCode, h as CustomerTokenInvalidError, F as FeatureUnavailableError, N as NetworkError, O as OriginNotAllowedError, R as RateLimitedError, j as ThrottleCartCode, T as TimeoutError, i as isCatalogError } from './catalog-error-C_zLOtYA.js';
5
6
 
6
7
  /** A product as `products.get` answers it (the full projection). */
7
8
  type StorefrontProduct = StorefrontProductAnswer['product'];
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  TimeoutError,
11
11
  createCatalogClient,
12
12
  isCatalogError
13
- } from "./chunk-I3QRBPWD.js";
13
+ } from "./chunk-JK2UY4CD.js";
14
14
  import "./chunk-PKBMQBKP.js";
15
15
  export {
16
16
  CartLineError,
package/dist/react.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkCR7ILYCTcjs = require('./chunk-CR7ILYCT.cjs');
14
+ var _chunk4ORXUW2Ucjs = require('./chunk-4ORXUW2U.cjs');
15
15
  require('./chunk-ETV4XYOV.cjs');
16
16
 
17
17
  // src/react/provider.tsx
@@ -38,7 +38,7 @@ function createStore(client, options = {}) {
38
38
  let until = 0;
39
39
  let cause;
40
40
  let pauseTimer;
41
- const pausedError = () => new (0, _chunkCR7ILYCTcjs.RateLimitedError)({
41
+ const pausedError = () => new (0, _chunk4ORXUW2Ucjs.RateLimitedError)({
42
42
  code: _nullishCoalesce(_optionalChain([cause, 'optionalAccess', _ => _.code]), () => ( "RATE_LIMITED")),
43
43
  message: _nullishCoalesce(_optionalChain([cause, 'optionalAccess', _2 => _2.message]), () => ( "Too many requests.")),
44
44
  statusCode: 429,
@@ -59,7 +59,7 @@ function createStore(client, options = {}) {
59
59
  subs: /* @__PURE__ */ new Set()
60
60
  };
61
61
  for (const [oldKey, old] of entries) {
62
- if (entries.size < _chunkCR7ILYCTcjs.CACHE_MAX_ENTRIES) break;
62
+ if (entries.size < _chunk4ORXUW2Ucjs.CACHE_MAX_ENTRIES) break;
63
63
  if (old.subs.size === 0 && old.flight === void 0) {
64
64
  clearTimeout(old.timer);
65
65
  entries.delete(oldKey);
@@ -78,7 +78,7 @@ function createStore(client, options = {}) {
78
78
  else entry.indexing = false;
79
79
  }, ms);
80
80
  };
81
- function fetchKey(key, run, { force = false, staleMs = _chunkCR7ILYCTcjs.STALE_MS } = {}) {
81
+ function fetchKey(key, run, { force = false, staleMs = _chunk4ORXUW2Ucjs.STALE_MS } = {}) {
82
82
  const entry = touch(key);
83
83
  entry.run = run;
84
84
  if (entry.promise !== void 0 && !_optionalChain([entry, 'access', _4 => _4.flight, 'optionalAccess', _5 => _5.signal, 'access', _6 => _6.aborted]))
@@ -128,7 +128,7 @@ function createStore(client, options = {}) {
128
128
  return;
129
129
  }
130
130
  if (_optionalChain([result, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.indexing]) === true) {
131
- if (!entry.indexing) later(key, entry, _chunkCR7ILYCTcjs.INDEXING_REVALIDATE_MS);
131
+ if (!entry.indexing) later(key, entry, _chunk4ORXUW2Ucjs.INDEXING_REVALIDATE_MS);
132
132
  } else {
133
133
  entry.indexing = false;
134
134
  }
@@ -141,7 +141,7 @@ function createStore(client, options = {}) {
141
141
  },
142
142
  (error) => {
143
143
  if (!current()) return;
144
- const retryMs = (_nullishCoalesce(error.retryAfterSeconds, () => ( _chunkCR7ILYCTcjs.RATE_LIMIT_DEFAULT_RETRY_S))) * 1e3;
144
+ const retryMs = (_nullishCoalesce(error.retryAfterSeconds, () => ( _chunk4ORXUW2Ucjs.RATE_LIMIT_DEFAULT_RETRY_S))) * 1e3;
145
145
  if (error.statusCode === 429 && error.code === "RATE_LIMITED")
146
146
  pause(now() + retryMs, error);
147
147
  else if (error.code === "STOREFRONT_INDEXING" && !entry.indexing)
@@ -389,9 +389,9 @@ function useDebounced(q, ms) {
389
389
  return _react.useSyncExternalStore.call(void 0, box.subscribe, box.get, box.get);
390
390
  }
391
391
  function useSuggest(q, options = {}) {
392
- const settled = useDebounced(q, _nullishCoalesce(options.debounceMs, () => ( _chunkCR7ILYCTcjs.SUGGEST_DEBOUNCE_MS)));
392
+ const settled = useDebounced(q, _nullishCoalesce(options.debounceMs, () => ( _chunk4ORXUW2Ucjs.SUGGEST_DEBOUNCE_MS)));
393
393
  const extra = defined({ limit: options.limit });
394
- const long = (value) => value.trim().length >= _chunkCR7ILYCTcjs.SUGGEST_MIN_CHARS;
394
+ const long = (value) => value.trim().length >= _chunk4ORXUW2Ucjs.SUGGEST_MIN_CHARS;
395
395
  return useQuery(
396
396
  "suggest",
397
397
  { q: settled, ...extra },
@@ -461,7 +461,7 @@ function newKey() {
461
461
  return out;
462
462
  }
463
463
  function refuse(message, path) {
464
- return new (0, _chunkCR7ILYCTcjs.CatalogError)({
464
+ return new (0, _chunk4ORXUW2Ucjs.CatalogError)({
465
465
  code: "INVALID_REQUEST",
466
466
  message,
467
467
  statusCode: 0,
@@ -474,7 +474,7 @@ var UNSAFE = /[\x00-\x20\x7f]/u;
474
474
  function isHttpUrl(value) {
475
475
  return typeof value === "string" && /^https?:\/\/[^/?#\\]/iu.test(value) && !UNSAFE.test(value);
476
476
  }
477
- var wrap = (error) => _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) ? error : new (0, _chunkCR7ILYCTcjs.CatalogError)({
477
+ var wrap = (error) => _chunk4ORXUW2Ucjs.isCatalogError.call(void 0, error) ? error : new (0, _chunk4ORXUW2Ucjs.CatalogError)({
478
478
  code: "CLIENT_ERROR",
479
479
  message: "The action failed.",
480
480
  statusCode: 0,
@@ -485,7 +485,7 @@ var wrap = (error) => _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) ? err
485
485
  function checkPause(store) {
486
486
  const until = store.pausedUntil();
487
487
  if (until > 0) {
488
- throw new (0, _chunkCR7ILYCTcjs.RateLimitedError)({
488
+ throw new (0, _chunk4ORXUW2Ucjs.RateLimitedError)({
489
489
  code: "RATE_LIMITED",
490
490
  message: "Too many requests.",
491
491
  statusCode: 429,
@@ -495,7 +495,7 @@ function checkPause(store) {
495
495
  }
496
496
  }
497
497
  function notePause(store, error) {
498
- if (error instanceof _chunkCR7ILYCTcjs.RateLimitedError && error.source === "catalog" && error.code === "RATE_LIMITED")
498
+ if (error instanceof _chunk4ORXUW2Ucjs.RateLimitedError && error.source === "catalog" && error.code === "RATE_LIMITED")
499
499
  store.pause(Date.now() + error.retryAfterSeconds * 1e3, error);
500
500
  }
501
501
  function createBox(initial) {
@@ -529,7 +529,7 @@ var ENDED = /* @__PURE__ */ new Set([
529
529
  "cart_not_open",
530
530
  "cart_not_found"
531
531
  ]);
532
- var ended = (error) => _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) && ENDED.has(error.code);
532
+ var ended = (error) => _chunk4ORXUW2Ucjs.isCatalogError.call(void 0, error) && ENDED.has(error.code);
533
533
  var converted = (error) => _optionalChain([error, 'access', _23 => _23.details, 'optionalAccess', _24 => _24.reason]) === "converted";
534
534
  function itemsOf(cart) {
535
535
  const items = /* @__PURE__ */ new Map();
@@ -568,7 +568,7 @@ function createController(home) {
568
568
  throttleBaseUrl === void 0 ? void 0 : { throttleBaseUrl }
569
569
  );
570
570
  };
571
- const fallbackUrl = (id) => `${(_nullishCoalesce(ctx().throttleCheckoutUrl, () => ( _chunkCR7ILYCTcjs.THROTTLE_CHECKOUT_URL))).replace(/\/+$/u, "")}/cart/${encodeURIComponent(id)}`;
571
+ const fallbackUrl = (id) => `${(_nullishCoalesce(ctx().throttleCheckoutUrl, () => ( _chunk4ORXUW2Ucjs.THROTTLE_CHECKOUT_URL))).replace(/\/+$/u, "")}/cart/${encodeURIComponent(id)}`;
572
572
  const live = async (signal, value) => {
573
573
  const out = await value;
574
574
  if (signal.aborted) throw signal.reason;
@@ -579,7 +579,7 @@ function createController(home) {
579
579
  if (converted(error)) reset();
580
580
  else box.set({ sessionId: null, cartUrl: null });
581
581
  }
582
- async function create(signal, options, items) {
582
+ async function create(signal, options, items, whole = false) {
583
583
  const context = ctx();
584
584
  const body = {
585
585
  items: [...items].map(([sku, quantity]) => ({ sku, quantity }))
@@ -603,10 +603,22 @@ function createController(home) {
603
603
  throw error;
604
604
  }
605
605
  const id = answer.sessionId;
606
- box.set({
607
- sessionId: id,
608
- cartUrl: isHttpUrl(answer.cartUrl) ? answer.cartUrl : fallbackUrl(id)
609
- });
606
+ const cartUrl = isHttpUrl(answer.cartUrl) ? answer.cartUrl : fallbackUrl(id);
607
+ if (whole) {
608
+ const snapshot = await live(signal, session(id).get({ signal }));
609
+ const write = context.cartStorage.set(id);
610
+ me.writing = Promise.resolve(write).catch(() => void 0);
611
+ await live(signal, write);
612
+ box.set({
613
+ sessionId: id,
614
+ cartUrl,
615
+ cart: snapshot.cart,
616
+ status: "ready",
617
+ error: void 0
618
+ });
619
+ return;
620
+ }
621
+ box.set({ sessionId: id, cartUrl });
610
622
  let unsaved;
611
623
  try {
612
624
  const write = context.cartStorage.set(id);
@@ -800,11 +812,10 @@ function createController(home) {
800
812
  reset();
801
813
  return;
802
814
  }
803
- const prior = box.get().sessionId;
804
815
  try {
805
- await create(signal, options, items);
816
+ await create(signal, options, items, true);
806
817
  } catch (error) {
807
- if (!signal.aborted && box.get().sessionId === prior) currency = before;
818
+ if (!signal.aborted) currency = before;
808
819
  throw error;
809
820
  }
810
821
  },
@@ -886,7 +897,7 @@ function useCart(options = {}) {
886
897
  { signal: callSignal }
887
898
  );
888
899
  } catch (error) {
889
- const repriced = _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) && error.code === "cart_prices_changed" ? _optionalChain([error, 'access', _37 => _37.details, 'optionalAccess', _38 => _38.cart]) : void 0;
900
+ const repriced = _chunk4ORXUW2Ucjs.isCatalogError.call(void 0, error) && error.code === "cart_prices_changed" ? _optionalChain([error, 'access', _37 => _37.details, 'optionalAccess', _38 => _38.cart]) : void 0;
890
901
  if (!callSignal.aborted && typeof repriced === "object" && repriced !== null)
891
902
  controller.box.set({ cart: repriced });
892
903
  throw error;
@@ -906,7 +917,7 @@ function useCart(options = {}) {
906
917
  if (out === void 0)
907
918
  throw _nullishCoalesce(met, () => ( refuse("There is no cart to check out.")));
908
919
  if (!isHttpUrl(out.checkoutUrl))
909
- throw new (0, _chunkCR7ILYCTcjs.CatalogError)({
920
+ throw new (0, _chunk4ORXUW2Ucjs.CatalogError)({
910
921
  code: "INVALID_RESPONSE",
911
922
  message: "Throttle answered a checkout URL that is not http or https.",
912
923
  statusCode: 200,
@@ -1004,4 +1015,4 @@ function useSubmitReview(handle) {
1004
1015
 
1005
1016
 
1006
1017
 
1007
- exports.CatalogProvider = CatalogProvider; exports.SDK_VERSION = _chunkCR7ILYCTcjs.SDK_VERSION; exports.catalogQueryKey = catalogQueryKey; exports.createMemoryCartStorage = createMemoryCartStorage; exports.useCart = useCart; exports.useCatalog = useCatalog; exports.useCategories = useCategories; exports.useCollection = useCollection; exports.useConfig = useConfig; exports.useFilterValues = useFilterValues; exports.useProduct = useProduct; exports.useProducts = useProducts; exports.useRelated = useRelated; exports.useReviews = useReviews; exports.useSubmitReview = useSubmitReview; exports.useSuggest = useSuggest;
1018
+ exports.CatalogProvider = CatalogProvider; exports.SDK_VERSION = _chunk4ORXUW2Ucjs.SDK_VERSION; exports.catalogQueryKey = catalogQueryKey; exports.createMemoryCartStorage = createMemoryCartStorage; exports.useCart = useCart; exports.useCatalog = useCatalog; exports.useCategories = useCategories; exports.useCollection = useCollection; exports.useConfig = useConfig; exports.useFilterValues = useFilterValues; exports.useProduct = useProduct; exports.useProducts = useProducts; exports.useRelated = useRelated; exports.useReviews = useReviews; exports.useSubmitReview = useSubmitReview; exports.useSuggest = useSuggest;
package/dist/react.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { CatalogClient } from './index.cjs';
2
- export { S as SDK_VERSION } from './client-BNtBTEyh.cjs';
2
+ export { S as SDK_VERSION } from './client-BAoq6jmM.cjs';
3
3
  import { ReactNode } from 'react';
4
- import { CatalogError } from './index.cjs';
5
- import { ProductsQuery, ThrottleCart, ReviewSubmitAnswer, ReviewSubmitInput } from './index.cjs';
4
+ import { CatalogError } from './admin.cjs';
5
+ import { CategoryTreeDepth, ProductsQuery, ThrottleCart } from './index.cjs';
6
+ import { ReviewSubmitAnswer, ReviewSubmitInput } from './index.cjs';
6
7
 
7
8
  /** Where `useCart` keeps the cart session id (P6-R15). The default is memory only. */
8
9
  type CartStorage = {
@@ -91,7 +92,7 @@ declare function useSuggest(q: string, options?: QueryOptions<Answer<CatalogClie
91
92
  limit?: number;
92
93
  }): QueryResult<Answer<CatalogClient['suggest']>>;
93
94
  declare function useCategories(options?: QueryOptions<Answer<CatalogClient['categories']['tree']>> & {
94
- depth?: 1 | 2 | 3;
95
+ depth?: CategoryTreeDepth;
95
96
  }): QueryResult<Answer<CatalogClient['categories']['tree']>>;
96
97
  /** The collection, or `{ redirectTo }` for a renamed handle. */
97
98
  declare function useCollection(handle: string | null, options?: QueryOptions<Answer<CatalogClient['collections']['get']>>): QueryResult<Answer<CatalogClient['collections']['get']>>;
@@ -136,7 +137,12 @@ type UseCartResult = CartState & {
136
137
  }): Promise<{
137
138
  checkoutUrl: string;
138
139
  }>;
139
- /** A new cart with the current lines in `currency` (BC4); the old one is left to Throttle. */
140
+ /**
141
+ * A new cart with the current lines in `currency` (BC4); the old one is
142
+ * left to Throttle. It lands whole or not at all: if the new cart cannot be
143
+ * made, read back or saved, it rejects and the old cart, its stored id and
144
+ * the old currency stay (the unused new cart is left to Throttle).
145
+ */
140
146
  switchCurrency(currency: string): Promise<void>;
141
147
  /** Forgets the cart (no request). */
142
148
  clear(): Promise<void>;
package/dist/react.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { CatalogClient } from './index.js';
2
- export { S as SDK_VERSION } from './client-CHLvULRQ.js';
2
+ export { S as SDK_VERSION } from './client-c2F-eCaL.js';
3
3
  import { ReactNode } from 'react';
4
- import { CatalogError } from './index.js';
5
- import { ProductsQuery, ThrottleCart, ReviewSubmitAnswer, ReviewSubmitInput } from './index.js';
4
+ import { CatalogError } from './admin.js';
5
+ import { CategoryTreeDepth, ProductsQuery, ThrottleCart } from './index.js';
6
+ import { ReviewSubmitAnswer, ReviewSubmitInput } from './index.js';
6
7
 
7
8
  /** Where `useCart` keeps the cart session id (P6-R15). The default is memory only. */
8
9
  type CartStorage = {
@@ -91,7 +92,7 @@ declare function useSuggest(q: string, options?: QueryOptions<Answer<CatalogClie
91
92
  limit?: number;
92
93
  }): QueryResult<Answer<CatalogClient['suggest']>>;
93
94
  declare function useCategories(options?: QueryOptions<Answer<CatalogClient['categories']['tree']>> & {
94
- depth?: 1 | 2 | 3;
95
+ depth?: CategoryTreeDepth;
95
96
  }): QueryResult<Answer<CatalogClient['categories']['tree']>>;
96
97
  /** The collection, or `{ redirectTo }` for a renamed handle. */
97
98
  declare function useCollection(handle: string | null, options?: QueryOptions<Answer<CatalogClient['collections']['get']>>): QueryResult<Answer<CatalogClient['collections']['get']>>;
@@ -136,7 +137,12 @@ type UseCartResult = CartState & {
136
137
  }): Promise<{
137
138
  checkoutUrl: string;
138
139
  }>;
139
- /** A new cart with the current lines in `currency` (BC4); the old one is left to Throttle. */
140
+ /**
141
+ * A new cart with the current lines in `currency` (BC4); the old one is
142
+ * left to Throttle. It lands whole or not at all: if the new cart cannot be
143
+ * made, read back or saved, it rejects and the old cart, its stored id and
144
+ * the old currency stay (the unused new cart is left to Throttle).
145
+ */
140
146
  switchCurrency(currency: string): Promise<void>;
141
147
  /** Forgets the cart (no request). */
142
148
  clear(): Promise<void>;
package/dist/react.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  SUGGEST_MIN_CHARS,
12
12
  THROTTLE_CHECKOUT_URL,
13
13
  isCatalogError
14
- } from "./chunk-I3QRBPWD.js";
14
+ } from "./chunk-JK2UY4CD.js";
15
15
  import "./chunk-PKBMQBKP.js";
16
16
 
17
17
  // src/react/provider.tsx
@@ -579,7 +579,7 @@ function createController(home) {
579
579
  if (converted(error)) reset();
580
580
  else box.set({ sessionId: null, cartUrl: null });
581
581
  }
582
- async function create(signal, options, items) {
582
+ async function create(signal, options, items, whole = false) {
583
583
  const context = ctx();
584
584
  const body = {
585
585
  items: [...items].map(([sku, quantity]) => ({ sku, quantity }))
@@ -603,10 +603,22 @@ function createController(home) {
603
603
  throw error;
604
604
  }
605
605
  const id = answer.sessionId;
606
- box.set({
607
- sessionId: id,
608
- cartUrl: isHttpUrl(answer.cartUrl) ? answer.cartUrl : fallbackUrl(id)
609
- });
606
+ const cartUrl = isHttpUrl(answer.cartUrl) ? answer.cartUrl : fallbackUrl(id);
607
+ if (whole) {
608
+ const snapshot = await live(signal, session(id).get({ signal }));
609
+ const write = context.cartStorage.set(id);
610
+ me.writing = Promise.resolve(write).catch(() => void 0);
611
+ await live(signal, write);
612
+ box.set({
613
+ sessionId: id,
614
+ cartUrl,
615
+ cart: snapshot.cart,
616
+ status: "ready",
617
+ error: void 0
618
+ });
619
+ return;
620
+ }
621
+ box.set({ sessionId: id, cartUrl });
610
622
  let unsaved;
611
623
  try {
612
624
  const write = context.cartStorage.set(id);
@@ -800,11 +812,10 @@ function createController(home) {
800
812
  reset();
801
813
  return;
802
814
  }
803
- const prior = box.get().sessionId;
804
815
  try {
805
- await create(signal, options, items);
816
+ await create(signal, options, items, true);
806
817
  } catch (error) {
807
- if (!signal.aborted && box.get().sessionId === prior) currency = before;
818
+ if (!signal.aborted) currency = before;
808
819
  throw error;
809
820
  }
810
821
  },
package/dist/server.cjs CHANGED
@@ -8,14 +8,15 @@
8
8
 
9
9
 
10
10
 
11
- var _chunkCR7ILYCTcjs = require('./chunk-CR7ILYCT.cjs');
11
+
12
+ var _chunk4ORXUW2Ucjs = require('./chunk-4ORXUW2U.cjs');
12
13
  require('./chunk-ETV4XYOV.cjs');
13
14
 
14
15
  // src/server/tags.ts
15
16
  function catalogTags(route, handle) {
16
- const tags = [_chunkCR7ILYCTcjs.CACHE_TAG, `${_chunkCR7ILYCTcjs.CACHE_TAG}:${route}`];
17
- if (handle !== void 0) tags.push(`${_chunkCR7ILYCTcjs.CACHE_TAG}:${route}:${handle}`);
18
- return tags.filter((tag) => tag.length <= _chunkCR7ILYCTcjs.TAG_MAX_CHARS);
17
+ const tags = [_chunk4ORXUW2Ucjs.CACHE_TAG, `${_chunk4ORXUW2Ucjs.CACHE_TAG}:${route}`];
18
+ if (handle !== void 0) tags.push(`${_chunk4ORXUW2Ucjs.CACHE_TAG}:${route}:${handle}`);
19
+ return tags.filter((tag) => tag.length <= _chunk4ORXUW2Ucjs.TAG_MAX_CHARS);
19
20
  }
20
21
  function decode(segment) {
21
22
  try {
@@ -72,9 +73,9 @@ function serverInit(url, init, storefront, revalidate, extraTags) {
72
73
  }
73
74
  function createServerCatalogClient(options) {
74
75
  const { next, ...rest } = options;
75
- const revalidate = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _ => _.revalidate]), () => ( _chunkCR7ILYCTcjs.DEFAULT_REVALIDATE_S));
76
+ const revalidate = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _ => _.revalidate]), () => ( _chunk4ORXUW2Ucjs.DEFAULT_REVALIDATE_S));
76
77
  const extraTags = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _2 => _2.tags]), () => ( []));
77
- const storefront = `${(_nullishCoalesce(rest.baseUrl, () => ( _chunkCR7ILYCTcjs.DEFAULT_BASE_URL))).replace(/\/+$/u, "")}/v1/storefront/`;
78
+ const storefront = `${(_nullishCoalesce(rest.baseUrl, () => ( _chunk4ORXUW2Ucjs.DEFAULT_BASE_URL))).replace(/\/+$/u, "")}/v1/storefront/`;
78
79
  const base = rest.fetch;
79
80
  const serverFetch = (input, init = {}) => {
80
81
  const out = serverInit(
@@ -86,7 +87,7 @@ function createServerCatalogClient(options) {
86
87
  );
87
88
  return base !== void 0 ? base(input, out) : globalThis.fetch(input, out);
88
89
  };
89
- return _chunkCR7ILYCTcjs.createCatalogClient.call(void 0, {
90
+ return _chunk4ORXUW2Ucjs.createCatalogClient.call(void 0, {
90
91
  ...rest,
91
92
  fetch: serverFetch
92
93
  });
@@ -106,16 +107,16 @@ async function syncCatalogGeneration(input) {
106
107
 
107
108
  // src/server/paging.ts
108
109
  function bounds(opts) {
109
- const pageSize = _nullishCoalesce(opts.pageSize, () => ( _chunkCR7ILYCTcjs.LIST_PAGE_SIZE));
110
- const max = _nullishCoalesce(opts.max, () => ( _chunkCR7ILYCTcjs.LIST_MAX_HANDLES));
111
- if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > _chunkCR7ILYCTcjs.LIST_PAGE_SIZE)
110
+ const pageSize = _nullishCoalesce(opts.pageSize, () => ( _chunk4ORXUW2Ucjs.LIST_PAGE_SIZE));
111
+ const max = _nullishCoalesce(opts.max, () => ( _chunk4ORXUW2Ucjs.LIST_MAX_HANDLES));
112
+ if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > _chunk4ORXUW2Ucjs.LIST_PAGE_SIZE)
112
113
  throw invalid("pageSize must be a whole number from 1 to 100.");
113
114
  if (!Number.isInteger(max) || max < 0)
114
115
  throw invalid("max must be a whole number of 0 or more.");
115
116
  return { pageSize, max };
116
117
  }
117
118
  function invalid(message) {
118
- return new (0, _chunkCR7ILYCTcjs.CatalogError)({
119
+ return new (0, _chunk4ORXUW2Ucjs.CatalogError)({
119
120
  code: "INVALID_REQUEST",
120
121
  message,
121
122
  statusCode: 0,
@@ -185,7 +186,7 @@ function listAllCollectionHandles(client, opts = {}) {
185
186
  }
186
187
  async function listAllCategoryHandles(client, opts = {}) {
187
188
  const { categories } = await client.categories.tree({
188
- depth: 3,
189
+ depth: _chunk4ORXUW2Ucjs.CATEGORY_TREE_MAX_DEPTH,
189
190
  ...call(opts.signal)
190
191
  });
191
192
  const out = [];
@@ -207,4 +208,4 @@ async function listAllCategoryHandles(client, opts = {}) {
207
208
 
208
209
 
209
210
 
210
- exports.SDK_VERSION = _chunkCR7ILYCTcjs.SDK_VERSION; exports.catalogTags = catalogTags; exports.createServerCatalogClient = createServerCatalogClient; exports.listAllCategoryHandles = listAllCategoryHandles; exports.listAllCollectionHandles = listAllCollectionHandles; exports.listAllProductHandles = listAllProductHandles; exports.staticProductParams = staticProductParams; exports.syncCatalogGeneration = syncCatalogGeneration;
211
+ exports.SDK_VERSION = _chunk4ORXUW2Ucjs.SDK_VERSION; exports.catalogTags = catalogTags; exports.createServerCatalogClient = createServerCatalogClient; exports.listAllCategoryHandles = listAllCategoryHandles; exports.listAllCollectionHandles = listAllCollectionHandles; exports.listAllProductHandles = listAllProductHandles; exports.staticProductParams = staticProductParams; exports.syncCatalogGeneration = syncCatalogGeneration;
package/dist/server.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { CatalogClient } from './index.cjs';
2
- export { S as SDK_VERSION } from './client-BNtBTEyh.cjs';
2
+ export { S as SDK_VERSION } from './client-BAoq6jmM.cjs';
3
3
  import { CatalogClientOptions, NextFetchOptions } from './index.cjs';
4
+ import './contract-types-DhiThMEr.cjs';
4
5
 
5
6
  type ServerCatalogClientOptions = CatalogClientOptions & {
6
7
  /** `revalidate` defaults to 60 seconds; `tags` are appended to the route's own. */
@@ -70,7 +71,7 @@ declare function staticProductParams(client: CatalogClient, opts?: {
70
71
  }[]>;
71
72
  /** Every listed collection handle, following `nextCursor`. */
72
73
  declare function listAllCollectionHandles(client: CatalogClient, opts?: ListHandlesOptions): AsyncIterable<string>;
73
- /** Every listed category handle: the tree at depth 3, depth-first. */
74
+ /** Every listed category handle: the tree at its deepest level, depth-first. */
74
75
  declare function listAllCategoryHandles(client: CatalogClient, opts?: {
75
76
  signal?: AbortSignal;
76
77
  }): Promise<string[]>;
package/dist/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { CatalogClient } from './index.js';
2
- export { S as SDK_VERSION } from './client-CHLvULRQ.js';
2
+ export { S as SDK_VERSION } from './client-c2F-eCaL.js';
3
3
  import { CatalogClientOptions, NextFetchOptions } from './index.js';
4
+ import './contract-types-DhiThMEr.js';
4
5
 
5
6
  type ServerCatalogClientOptions = CatalogClientOptions & {
6
7
  /** `revalidate` defaults to 60 seconds; `tags` are appended to the route's own. */
@@ -70,7 +71,7 @@ declare function staticProductParams(client: CatalogClient, opts?: {
70
71
  }[]>;
71
72
  /** Every listed collection handle, following `nextCursor`. */
72
73
  declare function listAllCollectionHandles(client: CatalogClient, opts?: ListHandlesOptions): AsyncIterable<string>;
73
- /** Every listed category handle: the tree at depth 3, depth-first. */
74
+ /** Every listed category handle: the tree at its deepest level, depth-first. */
74
75
  declare function listAllCategoryHandles(client: CatalogClient, opts?: {
75
76
  signal?: AbortSignal;
76
77
  }): Promise<string[]>;
package/dist/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CACHE_TAG,
3
+ CATEGORY_TREE_MAX_DEPTH,
3
4
  CatalogError,
4
5
  DEFAULT_BASE_URL,
5
6
  DEFAULT_REVALIDATE_S,
@@ -8,7 +9,7 @@ import {
8
9
  SDK_VERSION,
9
10
  TAG_MAX_CHARS,
10
11
  createCatalogClient
11
- } from "./chunk-I3QRBPWD.js";
12
+ } from "./chunk-JK2UY4CD.js";
12
13
  import "./chunk-PKBMQBKP.js";
13
14
 
14
15
  // src/server/tags.ts
@@ -185,7 +186,7 @@ function listAllCollectionHandles(client, opts = {}) {
185
186
  }
186
187
  async function listAllCategoryHandles(client, opts = {}) {
187
188
  const { categories } = await client.categories.tree({
188
- depth: 3,
189
+ depth: CATEGORY_TREE_MAX_DEPTH,
189
190
  ...call(opts.signal)
190
191
  });
191
192
  const out = [];