@usethrottle/catalog 0.1.0 → 0.1.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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/{chunk-O2OYOK2A.cjs → chunk-CR7ILYCT.cjs} +1 -1
- package/dist/{chunk-PSCFHVZZ.js → chunk-I3QRBPWD.js} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/react.cjs +25 -24
- package/dist/react.d.cts +5 -1
- package/dist/react.d.ts +5 -1
- package/dist/react.js +9 -8
- package/dist/server.cjs +12 -12
- package/dist/server.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -185,7 +185,7 @@ function ProductGrid() {
|
|
|
185
185
|
}
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
- **Hooks:** `useProducts`, `useProduct`, `useRelated`, `useFilterValues`, `useCategories`, `useCollection`, `useSuggest` (debounced 200 ms, 2 characters at least), `useReviews` and `useConfig`, each answering `{ data, error, isLoading, isValidating, refetch }` and taking `enabled`, `initialData` (for an SSR hand-off) and `staleTimeMs`.
|
|
188
|
+
- **Hooks:** `useProducts`, `useProduct`, `useRelated`, `useFilterValues`, `useCategories`, `useCollection`, `useSuggest` (debounced 200 ms, 2 characters at least), `useReviews` and `useConfig`, each answering `{ data, error, isLoading, isValidating, refetch }` and taking `enabled`, `initialData` (for an SSR hand-off) and `staleTimeMs`. With a signed-in customer (`customerKey` set), `initialData` is shown and revalidated at once, since a server render with the server key is anonymous; to avoid the brief list-price paint, render the server side with the customer's token.
|
|
189
189
|
- **The cache** is per provider: answers are shown at once and refetched when older than 60 seconds, and calls for one key share one request. Two providers never share it.
|
|
190
190
|
- **`customerKey`** partitions the cache by customer. Change it in the same update as the token: a change starts an empty cache and every mounted hook refetches, so one customer never sees another's prices. It is required whenever `customerToken` can return a token: `useCart` drops the cart on a sign-out or a customer change only by watching it, so without it one customer's cart stays for the next shopper. Keep one `client` for the app's life and pass `customerToken` as a function.
|
|
191
191
|
- **`useCart`** keeps one cart per provider and runs its changes one at a time. It creates the cart on the first `add`, recreates it once if Throttle ended the session, and makes a new cart on `switchCurrency`. The cart is dropped when the signed-in customer signs out or changes, and kept on sign-in. `checkout()` uses the provider's `cartUrls` unless given URLs, and answers the checkout URL. `cartUrls` go on every cart create, so they must be absolute `https` URLs on the store's Allowed return websites, or every `add` fails; otherwise (on `http://localhost`, say) leave them out and pass the URLs to `checkout(input)`. The default `cartStorage` is memory only; key a persistent one by customer, as above: a new adapter object per customer, never one stable object that reads the current customer when called (a drop removes the outgoing customer's entry through the outgoing object, so such an adapter would delete the incoming customer's cart instead).
|
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkCR7ILYCTcjs = require('./chunk-CR7ILYCT.cjs');
|
|
14
14
|
require('./chunk-ETV4XYOV.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
@@ -24,4 +24,4 @@ require('./chunk-ETV4XYOV.cjs');
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
exports.CartLineError =
|
|
27
|
+
exports.CartLineError = _chunkCR7ILYCTcjs.CartLineError; exports.CatalogError = _chunkCR7ILYCTcjs.CatalogError; exports.CustomerTokenInvalidError = _chunkCR7ILYCTcjs.CustomerTokenInvalidError; exports.FeatureUnavailableError = _chunkCR7ILYCTcjs.FeatureUnavailableError; exports.NetworkError = _chunkCR7ILYCTcjs.NetworkError; exports.OriginNotAllowedError = _chunkCR7ILYCTcjs.OriginNotAllowedError; exports.RateLimitedError = _chunkCR7ILYCTcjs.RateLimitedError; exports.SDK_VERSION = _chunkCR7ILYCTcjs.SDK_VERSION; exports.TimeoutError = _chunkCR7ILYCTcjs.TimeoutError; exports.createCatalogClient = _chunkCR7ILYCTcjs.createCatalogClient; exports.isCatalogError = _chunkCR7ILYCTcjs.isCatalogError;
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkCR7ILYCTcjs = require('./chunk-CR7ILYCT.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,
|
|
41
|
+
const pausedError = () => new (0, _chunkCR7ILYCTcjs.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,
|
|
@@ -49,17 +49,17 @@ function createStore(client, options = {}) {
|
|
|
49
49
|
entry.snap = { ...entry.snap, ...patch };
|
|
50
50
|
for (const listener of [...entry.subs]) listener();
|
|
51
51
|
};
|
|
52
|
-
const touch = (key, initial) => {
|
|
52
|
+
const touch = (key, initial, stale = false) => {
|
|
53
53
|
let entry = entries.get(key);
|
|
54
54
|
if (entry !== void 0) {
|
|
55
55
|
entries.delete(key);
|
|
56
56
|
} else {
|
|
57
57
|
entry = {
|
|
58
|
-
snap: initial === void 0 ? EMPTY : { ...EMPTY, data: initial, fetchedAt: now() },
|
|
58
|
+
snap: initial === void 0 ? EMPTY : { ...EMPTY, data: initial, fetchedAt: stale ? void 0 : now() },
|
|
59
59
|
subs: /* @__PURE__ */ new Set()
|
|
60
60
|
};
|
|
61
61
|
for (const [oldKey, old] of entries) {
|
|
62
|
-
if (entries.size <
|
|
62
|
+
if (entries.size < _chunkCR7ILYCTcjs.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 =
|
|
81
|
+
function fetchKey(key, run, { force = false, staleMs = _chunkCR7ILYCTcjs.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,
|
|
131
|
+
if (!entry.indexing) later(key, entry, _chunkCR7ILYCTcjs.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, () => (
|
|
144
|
+
const retryMs = (_nullishCoalesce(error.retryAfterSeconds, () => ( _chunkCR7ILYCTcjs.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)
|
|
@@ -189,10 +189,10 @@ function createStore(client, options = {}) {
|
|
|
189
189
|
});
|
|
190
190
|
};
|
|
191
191
|
},
|
|
192
|
-
get: (key, initial) => key === null ? EMPTY : _nullishCoalesce(_optionalChain([(_nullishCoalesce(entries.get(key), () => ( (initial === void 0 ? void 0 : touch(key, initial))))), 'optionalAccess', _15 => _15.snap]), () => ( EMPTY)),
|
|
193
|
-
getServer(key, initial) {
|
|
192
|
+
get: (key, initial, stale) => key === null ? EMPTY : _nullishCoalesce(_optionalChain([(_nullishCoalesce(entries.get(key), () => ( (initial === void 0 ? void 0 : touch(key, initial, stale))))), 'optionalAccess', _15 => _15.snap]), () => ( EMPTY)),
|
|
193
|
+
getServer(key, initial, stale) {
|
|
194
194
|
if (key === null || initial === void 0) return EMPTY;
|
|
195
|
-
const entry = _nullishCoalesce(entries.get(key), () => ( touch(key, initial)));
|
|
195
|
+
const entry = _nullishCoalesce(entries.get(key), () => ( touch(key, initial, stale)));
|
|
196
196
|
return _nullishCoalesce(entry.server, () => ( (entry.server = { ...EMPTY, data: initial })));
|
|
197
197
|
},
|
|
198
198
|
fetch: fetchKey,
|
|
@@ -307,10 +307,11 @@ function useQuery(route, params, run, options = {}) {
|
|
|
307
307
|
(listener) => key === null ? unsubscribe() : store.subscribe(key, listener),
|
|
308
308
|
[store, key]
|
|
309
309
|
);
|
|
310
|
+
const stale = customerKey !== null;
|
|
310
311
|
const snap = _react.useSyncExternalStore.call(void 0,
|
|
311
312
|
subscribe,
|
|
312
|
-
() => store.get(key, initial),
|
|
313
|
-
() => store.getServer(key, initial)
|
|
313
|
+
() => store.get(key, initial, stale),
|
|
314
|
+
() => store.getServer(key, initial, stale)
|
|
314
315
|
);
|
|
315
316
|
const staleMs = options.staleTimeMs;
|
|
316
317
|
_react.useEffect.call(void 0, () => {
|
|
@@ -388,9 +389,9 @@ function useDebounced(q, ms) {
|
|
|
388
389
|
return _react.useSyncExternalStore.call(void 0, box.subscribe, box.get, box.get);
|
|
389
390
|
}
|
|
390
391
|
function useSuggest(q, options = {}) {
|
|
391
|
-
const settled = useDebounced(q, _nullishCoalesce(options.debounceMs, () => (
|
|
392
|
+
const settled = useDebounced(q, _nullishCoalesce(options.debounceMs, () => ( _chunkCR7ILYCTcjs.SUGGEST_DEBOUNCE_MS)));
|
|
392
393
|
const extra = defined({ limit: options.limit });
|
|
393
|
-
const long = (value) => value.trim().length >=
|
|
394
|
+
const long = (value) => value.trim().length >= _chunkCR7ILYCTcjs.SUGGEST_MIN_CHARS;
|
|
394
395
|
return useQuery(
|
|
395
396
|
"suggest",
|
|
396
397
|
{ q: settled, ...extra },
|
|
@@ -460,7 +461,7 @@ function newKey() {
|
|
|
460
461
|
return out;
|
|
461
462
|
}
|
|
462
463
|
function refuse(message, path) {
|
|
463
|
-
return new (0,
|
|
464
|
+
return new (0, _chunkCR7ILYCTcjs.CatalogError)({
|
|
464
465
|
code: "INVALID_REQUEST",
|
|
465
466
|
message,
|
|
466
467
|
statusCode: 0,
|
|
@@ -473,7 +474,7 @@ var UNSAFE = /[\x00-\x20\x7f]/u;
|
|
|
473
474
|
function isHttpUrl(value) {
|
|
474
475
|
return typeof value === "string" && /^https?:\/\/[^/?#\\]/iu.test(value) && !UNSAFE.test(value);
|
|
475
476
|
}
|
|
476
|
-
var wrap = (error) =>
|
|
477
|
+
var wrap = (error) => _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) ? error : new (0, _chunkCR7ILYCTcjs.CatalogError)({
|
|
477
478
|
code: "CLIENT_ERROR",
|
|
478
479
|
message: "The action failed.",
|
|
479
480
|
statusCode: 0,
|
|
@@ -484,7 +485,7 @@ var wrap = (error) => _chunkO2OYOK2Acjs.isCatalogError.call(void 0, error) ? err
|
|
|
484
485
|
function checkPause(store) {
|
|
485
486
|
const until = store.pausedUntil();
|
|
486
487
|
if (until > 0) {
|
|
487
|
-
throw new (0,
|
|
488
|
+
throw new (0, _chunkCR7ILYCTcjs.RateLimitedError)({
|
|
488
489
|
code: "RATE_LIMITED",
|
|
489
490
|
message: "Too many requests.",
|
|
490
491
|
statusCode: 429,
|
|
@@ -494,7 +495,7 @@ function checkPause(store) {
|
|
|
494
495
|
}
|
|
495
496
|
}
|
|
496
497
|
function notePause(store, error) {
|
|
497
|
-
if (error instanceof
|
|
498
|
+
if (error instanceof _chunkCR7ILYCTcjs.RateLimitedError && error.source === "catalog" && error.code === "RATE_LIMITED")
|
|
498
499
|
store.pause(Date.now() + error.retryAfterSeconds * 1e3, error);
|
|
499
500
|
}
|
|
500
501
|
function createBox(initial) {
|
|
@@ -528,7 +529,7 @@ var ENDED = /* @__PURE__ */ new Set([
|
|
|
528
529
|
"cart_not_open",
|
|
529
530
|
"cart_not_found"
|
|
530
531
|
]);
|
|
531
|
-
var ended = (error) =>
|
|
532
|
+
var ended = (error) => _chunkCR7ILYCTcjs.isCatalogError.call(void 0, error) && ENDED.has(error.code);
|
|
532
533
|
var converted = (error) => _optionalChain([error, 'access', _23 => _23.details, 'optionalAccess', _24 => _24.reason]) === "converted";
|
|
533
534
|
function itemsOf(cart) {
|
|
534
535
|
const items = /* @__PURE__ */ new Map();
|
|
@@ -567,7 +568,7 @@ function createController(home) {
|
|
|
567
568
|
throttleBaseUrl === void 0 ? void 0 : { throttleBaseUrl }
|
|
568
569
|
);
|
|
569
570
|
};
|
|
570
|
-
const fallbackUrl = (id) => `${(_nullishCoalesce(ctx().throttleCheckoutUrl, () => (
|
|
571
|
+
const fallbackUrl = (id) => `${(_nullishCoalesce(ctx().throttleCheckoutUrl, () => ( _chunkCR7ILYCTcjs.THROTTLE_CHECKOUT_URL))).replace(/\/+$/u, "")}/cart/${encodeURIComponent(id)}`;
|
|
571
572
|
const live = async (signal, value) => {
|
|
572
573
|
const out = await value;
|
|
573
574
|
if (signal.aborted) throw signal.reason;
|
|
@@ -885,7 +886,7 @@ function useCart(options = {}) {
|
|
|
885
886
|
{ signal: callSignal }
|
|
886
887
|
);
|
|
887
888
|
} catch (error) {
|
|
888
|
-
const repriced =
|
|
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;
|
|
889
890
|
if (!callSignal.aborted && typeof repriced === "object" && repriced !== null)
|
|
890
891
|
controller.box.set({ cart: repriced });
|
|
891
892
|
throw error;
|
|
@@ -905,7 +906,7 @@ function useCart(options = {}) {
|
|
|
905
906
|
if (out === void 0)
|
|
906
907
|
throw _nullishCoalesce(met, () => ( refuse("There is no cart to check out.")));
|
|
907
908
|
if (!isHttpUrl(out.checkoutUrl))
|
|
908
|
-
throw new (0,
|
|
909
|
+
throw new (0, _chunkCR7ILYCTcjs.CatalogError)({
|
|
909
910
|
code: "INVALID_RESPONSE",
|
|
910
911
|
message: "Throttle answered a checkout URL that is not http or https.",
|
|
911
912
|
statusCode: 200,
|
|
@@ -1003,4 +1004,4 @@ function useSubmitReview(handle) {
|
|
|
1003
1004
|
|
|
1004
1005
|
|
|
1005
1006
|
|
|
1006
|
-
exports.CatalogProvider = CatalogProvider; exports.SDK_VERSION =
|
|
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;
|
package/dist/react.d.cts
CHANGED
|
@@ -57,7 +57,11 @@ type QueryResult<T> = {
|
|
|
57
57
|
type QueryOptions<T> = {
|
|
58
58
|
/** `false` makes no request; `data` stays `undefined`. */
|
|
59
59
|
enabled?: boolean;
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Shown at once (SSR hand-off). Treated as fetched at mount when the
|
|
62
|
+
* provider has no `customerKey`; under a signed-in customer it is
|
|
63
|
+
* revalidated at once, since a server render is usually anonymous (P6-R51).
|
|
64
|
+
*/
|
|
61
65
|
initialData?: T;
|
|
62
66
|
/** Cached data younger than this is not fetched again; default `STALE_MS`. */
|
|
63
67
|
staleTimeMs?: number;
|
package/dist/react.d.ts
CHANGED
|
@@ -57,7 +57,11 @@ type QueryResult<T> = {
|
|
|
57
57
|
type QueryOptions<T> = {
|
|
58
58
|
/** `false` makes no request; `data` stays `undefined`. */
|
|
59
59
|
enabled?: boolean;
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Shown at once (SSR hand-off). Treated as fetched at mount when the
|
|
62
|
+
* provider has no `customerKey`; under a signed-in customer it is
|
|
63
|
+
* revalidated at once, since a server render is usually anonymous (P6-R51).
|
|
64
|
+
*/
|
|
61
65
|
initialData?: T;
|
|
62
66
|
/** Cached data younger than this is not fetched again; default `STALE_MS`. */
|
|
63
67
|
staleTimeMs?: number;
|
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-
|
|
14
|
+
} from "./chunk-I3QRBPWD.js";
|
|
15
15
|
import "./chunk-PKBMQBKP.js";
|
|
16
16
|
|
|
17
17
|
// src/react/provider.tsx
|
|
@@ -49,13 +49,13 @@ function createStore(client, options = {}) {
|
|
|
49
49
|
entry.snap = { ...entry.snap, ...patch };
|
|
50
50
|
for (const listener of [...entry.subs]) listener();
|
|
51
51
|
};
|
|
52
|
-
const touch = (key, initial) => {
|
|
52
|
+
const touch = (key, initial, stale = false) => {
|
|
53
53
|
let entry = entries.get(key);
|
|
54
54
|
if (entry !== void 0) {
|
|
55
55
|
entries.delete(key);
|
|
56
56
|
} else {
|
|
57
57
|
entry = {
|
|
58
|
-
snap: initial === void 0 ? EMPTY : { ...EMPTY, data: initial, fetchedAt: now() },
|
|
58
|
+
snap: initial === void 0 ? EMPTY : { ...EMPTY, data: initial, fetchedAt: stale ? void 0 : now() },
|
|
59
59
|
subs: /* @__PURE__ */ new Set()
|
|
60
60
|
};
|
|
61
61
|
for (const [oldKey, old] of entries) {
|
|
@@ -189,10 +189,10 @@ function createStore(client, options = {}) {
|
|
|
189
189
|
});
|
|
190
190
|
};
|
|
191
191
|
},
|
|
192
|
-
get: (key, initial) => key === null ? EMPTY : (entries.get(key) ?? (initial === void 0 ? void 0 : touch(key, initial)))?.snap ?? EMPTY,
|
|
193
|
-
getServer(key, initial) {
|
|
192
|
+
get: (key, initial, stale) => key === null ? EMPTY : (entries.get(key) ?? (initial === void 0 ? void 0 : touch(key, initial, stale)))?.snap ?? EMPTY,
|
|
193
|
+
getServer(key, initial, stale) {
|
|
194
194
|
if (key === null || initial === void 0) return EMPTY;
|
|
195
|
-
const entry = entries.get(key) ?? touch(key, initial);
|
|
195
|
+
const entry = entries.get(key) ?? touch(key, initial, stale);
|
|
196
196
|
return entry.server ?? (entry.server = { ...EMPTY, data: initial });
|
|
197
197
|
},
|
|
198
198
|
fetch: fetchKey,
|
|
@@ -307,10 +307,11 @@ function useQuery(route, params, run, options = {}) {
|
|
|
307
307
|
(listener) => key === null ? unsubscribe() : store.subscribe(key, listener),
|
|
308
308
|
[store, key]
|
|
309
309
|
);
|
|
310
|
+
const stale = customerKey !== null;
|
|
310
311
|
const snap = useSyncExternalStore(
|
|
311
312
|
subscribe,
|
|
312
|
-
() => store.get(key, initial),
|
|
313
|
-
() => store.getServer(key, initial)
|
|
313
|
+
() => store.get(key, initial, stale),
|
|
314
|
+
() => store.getServer(key, initial, stale)
|
|
314
315
|
);
|
|
315
316
|
const staleMs = options.staleTimeMs;
|
|
316
317
|
useEffect2(() => {
|
package/dist/server.cjs
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkCR7ILYCTcjs = require('./chunk-CR7ILYCT.cjs');
|
|
12
12
|
require('./chunk-ETV4XYOV.cjs');
|
|
13
13
|
|
|
14
14
|
// src/server/tags.ts
|
|
15
15
|
function catalogTags(route, handle) {
|
|
16
|
-
const tags = [
|
|
17
|
-
if (handle !== void 0) tags.push(`${
|
|
18
|
-
return tags.filter((tag) => tag.length <=
|
|
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);
|
|
19
19
|
}
|
|
20
20
|
function decode(segment) {
|
|
21
21
|
try {
|
|
@@ -72,9 +72,9 @@ function serverInit(url, init, storefront, revalidate, extraTags) {
|
|
|
72
72
|
}
|
|
73
73
|
function createServerCatalogClient(options) {
|
|
74
74
|
const { next, ...rest } = options;
|
|
75
|
-
const revalidate = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _ => _.revalidate]), () => (
|
|
75
|
+
const revalidate = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _ => _.revalidate]), () => ( _chunkCR7ILYCTcjs.DEFAULT_REVALIDATE_S));
|
|
76
76
|
const extraTags = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _2 => _2.tags]), () => ( []));
|
|
77
|
-
const storefront = `${(_nullishCoalesce(rest.baseUrl, () => (
|
|
77
|
+
const storefront = `${(_nullishCoalesce(rest.baseUrl, () => ( _chunkCR7ILYCTcjs.DEFAULT_BASE_URL))).replace(/\/+$/u, "")}/v1/storefront/`;
|
|
78
78
|
const base = rest.fetch;
|
|
79
79
|
const serverFetch = (input, init = {}) => {
|
|
80
80
|
const out = serverInit(
|
|
@@ -86,7 +86,7 @@ function createServerCatalogClient(options) {
|
|
|
86
86
|
);
|
|
87
87
|
return base !== void 0 ? base(input, out) : globalThis.fetch(input, out);
|
|
88
88
|
};
|
|
89
|
-
return
|
|
89
|
+
return _chunkCR7ILYCTcjs.createCatalogClient.call(void 0, {
|
|
90
90
|
...rest,
|
|
91
91
|
fetch: serverFetch
|
|
92
92
|
});
|
|
@@ -106,16 +106,16 @@ async function syncCatalogGeneration(input) {
|
|
|
106
106
|
|
|
107
107
|
// src/server/paging.ts
|
|
108
108
|
function bounds(opts) {
|
|
109
|
-
const pageSize = _nullishCoalesce(opts.pageSize, () => (
|
|
110
|
-
const max = _nullishCoalesce(opts.max, () => (
|
|
111
|
-
if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize >
|
|
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)
|
|
112
112
|
throw invalid("pageSize must be a whole number from 1 to 100.");
|
|
113
113
|
if (!Number.isInteger(max) || max < 0)
|
|
114
114
|
throw invalid("max must be a whole number of 0 or more.");
|
|
115
115
|
return { pageSize, max };
|
|
116
116
|
}
|
|
117
117
|
function invalid(message) {
|
|
118
|
-
return new (0,
|
|
118
|
+
return new (0, _chunkCR7ILYCTcjs.CatalogError)({
|
|
119
119
|
code: "INVALID_REQUEST",
|
|
120
120
|
message,
|
|
121
121
|
statusCode: 0,
|
|
@@ -207,4 +207,4 @@ async function listAllCategoryHandles(client, opts = {}) {
|
|
|
207
207
|
|
|
208
208
|
|
|
209
209
|
|
|
210
|
-
exports.SDK_VERSION =
|
|
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;
|
package/dist/server.js
CHANGED
package/package.json
CHANGED