@reblu/site-next 1.14.0 → 1.15.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/dist/shop.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { S as ShopFilterHrefs } from './collection-BE5dhf-r.cjs';
2
- export { a as ShopCollection, b as buildShopFilterHrefs, g as getShopCollection, p as parseShopSearchParams, s as serializeShopParams, t as toURLSearchParams } from './collection-BE5dhf-r.cjs';
1
+ import { a as ShopFilterHrefs } from './collection-gAD_g03I.cjs';
2
+ export { S as ShopCollection, b as buildShopFilterHrefs, g as getShopCollection, p as parseShopSearchParams, s as serializeShopParams, t as toURLSearchParams } from './collection-gAD_g03I.cjs';
3
+ import { ShopOrder } from '@reblu/site-contracts';
3
4
  import '@reblu/site-client';
4
- import '@reblu/site-contracts';
5
5
 
6
6
  /**
7
7
  * Client-reactive version of `buildShopFilterHrefs` (REB-809), bound to the
@@ -17,4 +17,72 @@ import '@reblu/site-contracts';
17
17
  */
18
18
  declare function useShopFilterLinks(): ShopFilterHrefs;
19
19
 
20
- export { ShopFilterHrefs, useShopFilterLinks };
20
+ type ShopOrderStatusState = 'loading' | 'paid' | 'pending_timeout' | 'failed' | 'refunded' | 'partially_refunded' | 'not_found' | 'error';
21
+ interface UseShopOrderStatusOptions {
22
+ /**
23
+ * Builds the SITE's own order Route Handler path from the session id.
24
+ * @default (id) => `/api/shop/order/${encodeURIComponent(id)}`
25
+ */
26
+ buildUrl?: (sessionId: string) => string;
27
+ /**
28
+ * Total polling window before giving up as `pending_timeout`, ms.
29
+ * @default 30000
30
+ *
31
+ * Enforced by its OWN independent timer (REB-837 review fix), not by
32
+ * checking elapsed time inside `poll()` — a hung request that never
33
+ * settles used to block `poll()` from ever reaching that check at all,
34
+ * leaving `status` stuck on `'loading'` forever.
35
+ */
36
+ timeoutMs?: number;
37
+ /** Initial delay between polls, ms, before backoff. @default 2000 */
38
+ intervalMs?: number;
39
+ /** Multiplier applied to the interval after each PENDING poll. @default 1.5 */
40
+ backoffFactor?: number;
41
+ /** Ceiling on the backed-off interval, ms. @default 5000 */
42
+ maxIntervalMs?: number;
43
+ /**
44
+ * Hard timeout for a SINGLE request, ms (REB-837 review fix) — aborts and
45
+ * retries with backoff rather than leaving a hung `fetch` blocking
46
+ * indefinitely. Distinct from `timeoutMs` (the WHOLE polling window):
47
+ * one slow request past `requestTimeoutMs` is transient and retried; the
48
+ * window elapsing is terminal (`pending_timeout`).
49
+ * @default 8000
50
+ */
51
+ requestTimeoutMs?: number;
52
+ }
53
+ interface UseShopOrderStatusResult {
54
+ status: ShopOrderStatusState;
55
+ order: ShopOrder | null;
56
+ /** Re-runs the poll loop from scratch — e.g. the "Volver a comprobar" button. */
57
+ recheck: () => void;
58
+ }
59
+ /**
60
+ * `useShopOrderStatus` (REB-837) — the client-side half of the order-
61
+ * confirmation flow: polls the SITE's OWN order Route Handler (built from
62
+ * `createShopOrderRoute`, never base-api directly — same rule as every other
63
+ * client-side shop call in this package) for up to `timeoutMs` with backoff,
64
+ * and clears the cart ONLY once the order resolves to `PAID` — never on
65
+ * `pending_timeout`, `failed`, or any other state, so an interrupted/failed
66
+ * payment leaves the visitor's cart exactly as they left it.
67
+ *
68
+ * Checkout is card-only today, so `PENDING` past the window is only ever
69
+ * transient (the confirming webhook landing late) — see REB-836 for the
70
+ * redirect-origin hardening this flow sits behind.
71
+ */
72
+ declare function useShopOrderStatus(sessionId: string | null | undefined, opts?: UseShopOrderStatusOptions): UseShopOrderStatusResult;
73
+
74
+ /**
75
+ * `useCheckoutReturn` (REB-837) — parses the standard return query
76
+ * `createShopCheckoutRoute`'s default `successPath`/`cancelPath` land the
77
+ * visitor on: `?pago=ok&session_id=...` or `?pago=cancelado`. A SITE using a
78
+ * custom `successPath`/`cancelPath` that keeps the SAME `pago`/`session_id`
79
+ * query keys still works with this hook unchanged.
80
+ */
81
+ type CheckoutReturnStatus = 'ok' | 'cancelled' | null;
82
+ interface UseCheckoutReturnResult {
83
+ status: CheckoutReturnStatus;
84
+ sessionId: string | null;
85
+ }
86
+ declare function useCheckoutReturn(): UseCheckoutReturnResult;
87
+
88
+ export { type CheckoutReturnStatus, ShopFilterHrefs, type ShopOrderStatusState, type UseCheckoutReturnResult, type UseShopOrderStatusOptions, type UseShopOrderStatusResult, useCheckoutReturn, useShopFilterLinks, useShopOrderStatus };
package/dist/shop.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { S as ShopFilterHrefs } from './collection-BE5dhf-r.js';
2
- export { a as ShopCollection, b as buildShopFilterHrefs, g as getShopCollection, p as parseShopSearchParams, s as serializeShopParams, t as toURLSearchParams } from './collection-BE5dhf-r.js';
1
+ import { a as ShopFilterHrefs } from './collection-gAD_g03I.js';
2
+ export { S as ShopCollection, b as buildShopFilterHrefs, g as getShopCollection, p as parseShopSearchParams, s as serializeShopParams, t as toURLSearchParams } from './collection-gAD_g03I.js';
3
+ import { ShopOrder } from '@reblu/site-contracts';
3
4
  import '@reblu/site-client';
4
- import '@reblu/site-contracts';
5
5
 
6
6
  /**
7
7
  * Client-reactive version of `buildShopFilterHrefs` (REB-809), bound to the
@@ -17,4 +17,72 @@ import '@reblu/site-contracts';
17
17
  */
18
18
  declare function useShopFilterLinks(): ShopFilterHrefs;
19
19
 
20
- export { ShopFilterHrefs, useShopFilterLinks };
20
+ type ShopOrderStatusState = 'loading' | 'paid' | 'pending_timeout' | 'failed' | 'refunded' | 'partially_refunded' | 'not_found' | 'error';
21
+ interface UseShopOrderStatusOptions {
22
+ /**
23
+ * Builds the SITE's own order Route Handler path from the session id.
24
+ * @default (id) => `/api/shop/order/${encodeURIComponent(id)}`
25
+ */
26
+ buildUrl?: (sessionId: string) => string;
27
+ /**
28
+ * Total polling window before giving up as `pending_timeout`, ms.
29
+ * @default 30000
30
+ *
31
+ * Enforced by its OWN independent timer (REB-837 review fix), not by
32
+ * checking elapsed time inside `poll()` — a hung request that never
33
+ * settles used to block `poll()` from ever reaching that check at all,
34
+ * leaving `status` stuck on `'loading'` forever.
35
+ */
36
+ timeoutMs?: number;
37
+ /** Initial delay between polls, ms, before backoff. @default 2000 */
38
+ intervalMs?: number;
39
+ /** Multiplier applied to the interval after each PENDING poll. @default 1.5 */
40
+ backoffFactor?: number;
41
+ /** Ceiling on the backed-off interval, ms. @default 5000 */
42
+ maxIntervalMs?: number;
43
+ /**
44
+ * Hard timeout for a SINGLE request, ms (REB-837 review fix) — aborts and
45
+ * retries with backoff rather than leaving a hung `fetch` blocking
46
+ * indefinitely. Distinct from `timeoutMs` (the WHOLE polling window):
47
+ * one slow request past `requestTimeoutMs` is transient and retried; the
48
+ * window elapsing is terminal (`pending_timeout`).
49
+ * @default 8000
50
+ */
51
+ requestTimeoutMs?: number;
52
+ }
53
+ interface UseShopOrderStatusResult {
54
+ status: ShopOrderStatusState;
55
+ order: ShopOrder | null;
56
+ /** Re-runs the poll loop from scratch — e.g. the "Volver a comprobar" button. */
57
+ recheck: () => void;
58
+ }
59
+ /**
60
+ * `useShopOrderStatus` (REB-837) — the client-side half of the order-
61
+ * confirmation flow: polls the SITE's OWN order Route Handler (built from
62
+ * `createShopOrderRoute`, never base-api directly — same rule as every other
63
+ * client-side shop call in this package) for up to `timeoutMs` with backoff,
64
+ * and clears the cart ONLY once the order resolves to `PAID` — never on
65
+ * `pending_timeout`, `failed`, or any other state, so an interrupted/failed
66
+ * payment leaves the visitor's cart exactly as they left it.
67
+ *
68
+ * Checkout is card-only today, so `PENDING` past the window is only ever
69
+ * transient (the confirming webhook landing late) — see REB-836 for the
70
+ * redirect-origin hardening this flow sits behind.
71
+ */
72
+ declare function useShopOrderStatus(sessionId: string | null | undefined, opts?: UseShopOrderStatusOptions): UseShopOrderStatusResult;
73
+
74
+ /**
75
+ * `useCheckoutReturn` (REB-837) — parses the standard return query
76
+ * `createShopCheckoutRoute`'s default `successPath`/`cancelPath` land the
77
+ * visitor on: `?pago=ok&session_id=...` or `?pago=cancelado`. A SITE using a
78
+ * custom `successPath`/`cancelPath` that keeps the SAME `pago`/`session_id`
79
+ * query keys still works with this hook unchanged.
80
+ */
81
+ type CheckoutReturnStatus = 'ok' | 'cancelled' | null;
82
+ interface UseCheckoutReturnResult {
83
+ status: CheckoutReturnStatus;
84
+ sessionId: string | null;
85
+ }
86
+ declare function useCheckoutReturn(): UseCheckoutReturnResult;
87
+
88
+ export { type CheckoutReturnStatus, ShopFilterHrefs, type ShopOrderStatusState, type UseCheckoutReturnResult, type UseShopOrderStatusOptions, type UseShopOrderStatusResult, useCheckoutReturn, useShopFilterLinks, useShopOrderStatus };
package/dist/shop.js CHANGED
@@ -171,12 +171,231 @@ async function getShopCollection(client, params) {
171
171
  }
172
172
  return { products: productsResult.value, facets: facetsResult.value, facetsStatus: "ok" };
173
173
  }
174
+
175
+ // src/shop/use-shop-order-status.ts
176
+ import { useCallback, useEffect, useRef, useState } from "react";
177
+
178
+ // src/cart/store.ts
179
+ import { create } from "zustand";
180
+ import { persist } from "zustand/middleware";
181
+ var CART_STORAGE_KEY = "shop-cart";
182
+ var CART_STORE_PERSIST_VERSION = 0;
183
+ function isSameItem(a, productId, variantId) {
184
+ return a.productId === productId && (a.variantId ?? null) === (variantId ?? null);
185
+ }
186
+ function normalizeQuantity(quantity, maxStock) {
187
+ if (!Number.isFinite(quantity)) return 0;
188
+ const truncated = Math.trunc(quantity);
189
+ if (truncated < 1) return 0;
190
+ if (maxStock === null) return truncated;
191
+ const maxTruncated = Math.trunc(maxStock);
192
+ if (maxTruncated < 1) return 0;
193
+ return Math.min(truncated, maxTruncated);
194
+ }
195
+ function createCartStore() {
196
+ return create()(
197
+ persist(
198
+ (set, get) => ({
199
+ items: [],
200
+ addItem: (item) => {
201
+ let outcome = { status: "refused", quantity: 0 };
202
+ set((state) => {
203
+ const existing = state.items.find((i) => isSameItem(i, item.productId, item.variantId));
204
+ if (existing) {
205
+ if (item.maxStock !== null && Math.trunc(item.maxStock) < 1) {
206
+ outcome = { status: "refused", quantity: 0 };
207
+ return {
208
+ items: state.items.filter((i) => !isSameItem(i, item.productId, item.variantId))
209
+ };
210
+ }
211
+ const requestedQty = existing.quantity + item.quantity;
212
+ const newQty = normalizeQuantity(requestedQty, item.maxStock);
213
+ if (newQty < 1) {
214
+ outcome = { status: "refused", quantity: existing.quantity };
215
+ return {};
216
+ }
217
+ outcome = {
218
+ status: newQty <= existing.quantity ? "refused" : newQty < requestedQty ? "clamped" : "added",
219
+ quantity: newQty
220
+ };
221
+ return {
222
+ items: state.items.map(
223
+ (i) => isSameItem(i, item.productId, item.variantId) ? { ...i, quantity: newQty, maxStock: item.maxStock } : i
224
+ )
225
+ };
226
+ }
227
+ const qty = normalizeQuantity(item.quantity, item.maxStock);
228
+ if (qty < 1) {
229
+ outcome = { status: "refused", quantity: 0 };
230
+ return {};
231
+ }
232
+ outcome = { status: qty < item.quantity ? "clamped" : "added", quantity: qty };
233
+ return { items: [...state.items, { ...item, quantity: qty }] };
234
+ });
235
+ return outcome;
236
+ },
237
+ removeItem: (productId, variantId) => {
238
+ set((state) => ({
239
+ items: state.items.filter((i) => !isSameItem(i, productId, variantId))
240
+ }));
241
+ },
242
+ updateQuantity: (productId, variantId, quantity) => {
243
+ const existing = get().items.find((i) => isSameItem(i, productId, variantId));
244
+ if (!existing) return;
245
+ const newQty = normalizeQuantity(quantity, existing.maxStock);
246
+ if (newQty < 1) {
247
+ get().removeItem(productId, variantId);
248
+ return;
249
+ }
250
+ set((state) => ({
251
+ items: state.items.map(
252
+ (i) => isSameItem(i, productId, variantId) ? { ...i, quantity: newQty } : i
253
+ )
254
+ }));
255
+ },
256
+ clearCart: () => set({ items: [] }),
257
+ getTotal: () => get().items.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0),
258
+ getItemCount: () => get().items.reduce((sum, item) => sum + item.quantity, 0)
259
+ }),
260
+ {
261
+ name: CART_STORAGE_KEY,
262
+ version: CART_STORE_PERSIST_VERSION,
263
+ skipHydration: true
264
+ }
265
+ )
266
+ );
267
+ }
268
+ var CART_STORE_GLOBAL_KEY = /* @__PURE__ */ Symbol.for(
269
+ `@reblu/site-next/cart-store@v${CART_STORE_PERSIST_VERSION}`
270
+ );
271
+ var globalForCartStore = globalThis;
272
+ var useCartStore = globalForCartStore[CART_STORE_GLOBAL_KEY] ?? (globalForCartStore[CART_STORE_GLOBAL_KEY] = createCartStore());
273
+
274
+ // src/shop/use-shop-order-status.ts
275
+ function defaultBuildUrl(sessionId) {
276
+ return `/api/shop/order/${encodeURIComponent(sessionId)}`;
277
+ }
278
+ function useShopOrderStatus(sessionId, opts = {}) {
279
+ const {
280
+ buildUrl = defaultBuildUrl,
281
+ timeoutMs = 3e4,
282
+ intervalMs = 2e3,
283
+ backoffFactor = 1.5,
284
+ maxIntervalMs = 5e3,
285
+ requestTimeoutMs = 8e3
286
+ } = opts;
287
+ const [status, setStatus] = useState(sessionId ? "loading" : "not_found");
288
+ const [order, setOrder] = useState(null);
289
+ const [recheckToken, setRecheckToken] = useState(0);
290
+ const recheck = useCallback(() => setRecheckToken((n) => n + 1), []);
291
+ const buildUrlRef = useRef(buildUrl);
292
+ buildUrlRef.current = buildUrl;
293
+ useEffect(() => {
294
+ if (!sessionId) {
295
+ setStatus("not_found");
296
+ setOrder(null);
297
+ return;
298
+ }
299
+ setStatus("loading");
300
+ setOrder(null);
301
+ let cancelled = false;
302
+ let pollTimer = null;
303
+ let requestController = null;
304
+ let attempt = 0;
305
+ const finish = (nextStatus) => {
306
+ if (cancelled) return;
307
+ cancelled = true;
308
+ clearTimeout(windowTimer);
309
+ if (pollTimer) clearTimeout(pollTimer);
310
+ requestController?.abort();
311
+ setStatus(nextStatus);
312
+ };
313
+ const windowTimer = setTimeout(() => finish("pending_timeout"), timeoutMs);
314
+ const poll = async () => {
315
+ if (cancelled) return;
316
+ requestController = new AbortController();
317
+ const requestTimer = setTimeout(() => requestController?.abort(), requestTimeoutMs);
318
+ try {
319
+ const res = await fetch(buildUrlRef.current(sessionId), {
320
+ signal: requestController.signal,
321
+ cache: "no-store"
322
+ });
323
+ clearTimeout(requestTimer);
324
+ if (cancelled) return;
325
+ if (res.status === 404) {
326
+ finish("not_found");
327
+ return;
328
+ }
329
+ if (!res.ok) {
330
+ finish("error");
331
+ return;
332
+ }
333
+ const body = await res.json();
334
+ if (cancelled) return;
335
+ const data = body && typeof body === "object" && "data" in body && body.data ? body.data : body;
336
+ setOrder(data);
337
+ switch (data.paymentStatus) {
338
+ case "PAID":
339
+ useCartStore.getState().clearCart();
340
+ finish("paid");
341
+ return;
342
+ case "FAILED":
343
+ finish("failed");
344
+ return;
345
+ case "REFUNDED":
346
+ finish("refunded");
347
+ return;
348
+ case "PARTIALLY_REFUNDED":
349
+ finish("partially_refunded");
350
+ return;
351
+ case "PENDING":
352
+ default: {
353
+ if (cancelled) return;
354
+ const nextDelay = Math.min(intervalMs * backoffFactor ** attempt, maxIntervalMs);
355
+ attempt += 1;
356
+ pollTimer = setTimeout(poll, nextDelay);
357
+ }
358
+ }
359
+ } catch (err) {
360
+ clearTimeout(requestTimer);
361
+ if (cancelled) return;
362
+ if (err instanceof Error && err.name === "AbortError") {
363
+ const nextDelay = Math.min(intervalMs * backoffFactor ** attempt, maxIntervalMs);
364
+ attempt += 1;
365
+ pollTimer = setTimeout(poll, nextDelay);
366
+ return;
367
+ }
368
+ finish("error");
369
+ }
370
+ };
371
+ void poll();
372
+ return () => {
373
+ cancelled = true;
374
+ clearTimeout(windowTimer);
375
+ if (pollTimer) clearTimeout(pollTimer);
376
+ requestController?.abort();
377
+ };
378
+ }, [sessionId, recheckToken, timeoutMs, intervalMs, backoffFactor, maxIntervalMs, requestTimeoutMs]);
379
+ return { status, order, recheck };
380
+ }
381
+
382
+ // src/shop/use-checkout-return.ts
383
+ import { useSearchParams as useSearchParams2 } from "next/navigation";
384
+ function useCheckoutReturn() {
385
+ const searchParams = useSearchParams2();
386
+ const pago = searchParams.get("pago");
387
+ const sessionId = searchParams.get("session_id");
388
+ const status = pago === "ok" ? "ok" : pago === "cancelado" ? "cancelled" : null;
389
+ return { status, sessionId };
390
+ }
174
391
  export {
175
392
  buildShopFilterHrefs,
176
393
  getShopCollection,
177
394
  parseShopSearchParams,
178
395
  serializeShopParams,
179
396
  toURLSearchParams,
180
- useShopFilterLinks
397
+ useCheckoutReturn,
398
+ useShopFilterLinks,
399
+ useShopOrderStatus
181
400
  };
182
401
  //# sourceMappingURL=shop.js.map
package/dist/shop.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/shop/use-shop-filter-links.ts","../src/shop/params.ts","../src/shop/collection.ts"],"sourcesContent":["'use client'\n\nimport { usePathname, useSearchParams } from 'next/navigation'\n\nimport { buildShopFilterHrefs, parseShopSearchParams, type ShopFilterHrefs } from './params'\n\n/**\n * Client-reactive version of `buildShopFilterHrefs` (REB-809), bound to the\n * CURRENT URL via `next/navigation`. Use it when a shop collection's filter\n * bar is its own Client Component (e.g. a sticky sidebar) and you want the\n * hrefs to update instantly as the URL changes client-side, without every\n * caller re-deriving `pathname`/`searchParams` by hand.\n *\n * A Server Component does NOT need this hook — it already has `searchParams`\n * as a prop and a static route pathname, so it calls\n * `buildShopFilterHrefs` (from `./params` or the `./shop-server` subpath)\n * directly. Reach for this hook only from inside a `'use client'` boundary.\n */\nexport function useShopFilterLinks(): ShopFilterHrefs {\n const pathname = usePathname()\n const searchParams = useSearchParams()\n const current = parseShopSearchParams(searchParams)\n return buildShopFilterHrefs(current, pathname)\n}\n","import type { ShopProductsParams } from '@reblu/site-client'\n\n/**\n * REB-809 — URL ↔ `ShopProductsParams` glue for a SITE's shop/collection page.\n *\n * Mirrors base-api's own `parseListParams`\n * (`apps/base-api/src/lib/shop/catalogue-query.ts`) deliberately: the SAME\n * bracket shape (`taxonomy[<key>]=<slug>`, `attr[<key>]=<value>`, repeatable\n * for `attr`), the SAME MVP collapse for `taxonomy` (one term slug per axis —\n * a repeat keeps only the first), and the SAME defensive caps on bracket\n * key/value counts. Keeping this a mirror rather than a re-implementation\n * means a URL this module builds is EXACTLY the URL the server will parse\n * back to the same params — there is no second, drifting parser.\n */\n\nconst MAX_Q_LEN = 200\nconst MAX_FILTER_KEYS = 30\nconst MAX_VALUE_LEN = 120\nconst MAX_VALUES_PER_KEY = 30\n/**\n * Mirrors `shopProductListParamsSchema`'s `limit: z.number().int().min(1).max(50)`\n * in `apps/base-api/src/lib/contracts/shop.contract.ts` — keep the two in sync;\n * a caller-side limit above this is server-rejected/clamped anyway, but parsing\n * it through here means a URL this module builds never claims a limit the\n * server will refuse.\n */\nconst MAX_LIMIT = 50\n\nconst SHOP_SORTS = ['price_asc', 'price_desc', 'newest', 'on_sale'] as const\n\nfunction isShopSort(value: string): value is (typeof SHOP_SORTS)[number] {\n return (SHOP_SORTS as readonly string[]).includes(value)\n}\n\n/**\n * Parse a non-negative integer, STRICT digits only — `/^\\d+$/`, so '12abc'\n * and '1.5' are rejected outright rather than `Number.parseInt` silently\n * taking the leading '12'/'1' and discarding the rest as if it were valid\n * input. Named for exactly what it accepts: >= 0, not \"positive\" (which\n * excludes 0) — callers that need >= 1 (page, limit) enforce that bound\n * themselves on top of this.\n */\nfunction nonNegativeInt(raw: string | null): number | undefined {\n if (raw === null || !/^\\d+$/.test(raw)) return undefined\n const n = Number.parseInt(raw, 10)\n return Number.isNaN(n) ? undefined : n\n}\n\n/**\n * Copy a (possibly null-prototype) object's own enumerable properties into a\n * fresh PLAIN object — `Object.prototype` in its chain, nothing else.\n *\n * R3-001: this module's internal accumulators use `Object.create(null)` for\n * prototype-pollution safety (see `parseBracketParams`' own doc below), but\n * that safety property must NEVER leak into `ShopProductsParams.taxonomy`/\n * `.attr`, the values a SITE actually receives. React Flight — the\n * serialization React Server Components use to send props across the\n * Server→Client boundary — refuses a non-plain object (`Object.\n * getPrototypeOf(x) !== Object.prototype`) with a hard runtime error. This\n * package's own README tells a Client Component caller to pass\n * `active={params}` to `ShopFilters`' `onChange` mode, so a null-prototype\n * `taxonomy`/`attr` reaching that boundary would crash every SITE that\n * followed the documented pattern. Object spread (`{ ...source }`) always\n * produces a plain object regardless of the source's own prototype, which is\n * exactly the property this needs and `Object.assign({}, source)` also has —\n * spread is used here for clarity.\n */\nfunction toPlainObject<T>(source: Record<string, T>): Record<string, T> {\n return { ...source }\n}\n\n/**\n * Parse `bracket[key]` params into a map, collapsing repeats into arrays.\n *\n * Built on `Object.create(null)` rather than a plain `{}` — a query string is\n * attacker-controlled input, and `taxonomy[constructor]=x` or\n * `taxonomy[toString]=x` against a plain object reads/writes through the\n * INHERITED `Object.prototype` property of that name before this function's\n * own `key in out` / `out[key]` logic ever sees an actual own property,\n * corrupting the key-count bookkeeping and the parsed value for that key. A\n * null-prototype object has no inherited properties at all, so `in` and\n * indexed access only ever see what this loop itself has written — the same\n * defense `JSON.parse` reviewers reach for against prototype-pollution-style\n * bracket keys, applied here to a hand-rolled key/value accumulator.\n *\n * The RETURNED object is converted back to a plain one via\n * {@link toPlainObject} — the null prototype is this function's OWN internal\n * bookkeeping safety, never part of its public output (see that helper's doc\n * for why: React Flight/RSC serialization).\n */\nfunction parseBracketParams(\n searchParams: URLSearchParams,\n prefix: string,\n): Record<string, string | string[]> | undefined {\n const out: Record<string, string | string[]> = Object.create(null)\n const re = new RegExp(`^${prefix}\\\\[(.+)\\\\]$`)\n for (const [rawKey, rawValue] of searchParams.entries()) {\n const match = rawKey.match(re)\n if (!match) continue\n const key = match[1]\n const value = rawValue.trim().slice(0, MAX_VALUE_LEN)\n // REB-827: an empty/whitespace-only value (e.g. a cleared `taxonomy[marca]=`,\n // or a stale/hand-built link) is never a real filter — trim and drop it\n // here, mirroring how `q` is trimmed and dropped when empty, so a key left\n // with no surviving value never enters `out` and never reaches the caller\n // as `{ key: '' }`/`{ key: [] }`.\n if (!value) continue\n if (!(key in out) && Object.keys(out).length >= MAX_FILTER_KEYS) continue\n const existing = out[key]\n if (existing === undefined) out[key] = value\n else if (Array.isArray(existing)) {\n if (existing.length < MAX_VALUES_PER_KEY) existing.push(value)\n } else out[key] = [existing, value]\n }\n return Object.keys(out).length > 0 ? toPlainObject(out) : undefined\n}\n\n/**\n * Parse a `URLSearchParams` (or anything with that shape — `ReadonlyURLSearchParams`\n * from `next/navigation`, or a plain `new URLSearchParams(record)`) into\n * `ShopProductsParams`. Hostile/unknown params are dropped: only the known\n * scalar keys and the two bracket groups are ever read.\n */\nexport function parseShopSearchParams(searchParams: URLSearchParams): ShopProductsParams {\n const params: ShopProductsParams = {}\n\n const page = nonNegativeInt(searchParams.get('page'))\n if (page !== undefined && page >= 1) params.page = page\n\n const limit = nonNegativeInt(searchParams.get('limit'))\n if (limit !== undefined && limit >= 1 && limit <= MAX_LIMIT) params.limit = limit\n\n const q = searchParams.get('q')?.trim().slice(0, MAX_Q_LEN)\n if (q) params.q = q\n\n const sort = searchParams.get('sort')\n if (sort !== null && isShopSort(sort)) params.sort = sort\n\n const category = searchParams.get('category')?.trim()\n if (category) params.category = category\n\n let priceMin = nonNegativeInt(searchParams.get('priceMin'))\n let priceMax = nonNegativeInt(searchParams.get('priceMax'))\n // An inverted range (priceMin > priceMax) would otherwise always match zero\n // products server-side — swap rather than pass through a query that can\n // never return a result, or silently drop half of it.\n if (priceMin !== undefined && priceMax !== undefined && priceMin > priceMax) {\n ;[priceMin, priceMax] = [priceMax, priceMin]\n }\n // Only assign when actually present — an explicit `priceMin: undefined` key\n // is never written, so `toStrictEqual`/`toEqual` against a literal object\n // without that key both hold, and a downstream `'priceMin' in params` check\n // reflects reality.\n if (priceMin !== undefined) params.priceMin = priceMin\n if (priceMax !== undefined) params.priceMax = priceMax\n\n const onSale = searchParams.get('onSale')\n if (onSale === 'true' || onSale === '1') params.onSale = true\n\n const taxonomyRaw = parseBracketParams(searchParams, 'taxonomy')\n if (taxonomyRaw) {\n // A taxonomy axis takes a single term slug in MVP — collapse any repeats,\n // exactly like the server does (see module doc). Object.create(null) for\n // the SAME reason as parseBracketParams' own accumulator: `key` is\n // attacker-controlled (it is the bracket-key from the query string), and\n // a plain `{}` here reintroduces the exact bug parseBracketParams just\n // fixed one step downstream — `taxonomy['__proto__'] = value` on a plain\n // object hits the inherited `__proto__` ACCESSOR, which silently no-ops\n // for a non-object value instead of creating an own property, so that\n // key would vanish from the result entirely (not merely mis-set).\n const taxonomy: Record<string, string> = Object.create(null)\n for (const [key, value] of Object.entries(taxonomyRaw)) {\n taxonomy[key] = Array.isArray(value) ? value[0] : value\n }\n // Plain object out, same reason as parseBracketParams' own return value —\n // see toPlainObject's doc (R3-001, React Flight/RSC serialization).\n params.taxonomy = toPlainObject(taxonomy)\n }\n\n const attr = parseBracketParams(searchParams, 'attr')\n if (attr) params.attr = attr\n\n return params\n}\n\n/**\n * Serialize `ShopProductsParams` into a `URLSearchParams` — the inverse of\n * {@link parseShopSearchParams}. Falsy/empty/undefined fields are omitted, so\n * `parseShopSearchParams(serializeShopParams(params))` round-trips to `params`\n * for any already-canonical (non-empty-string, in-range) input — that is the\n * property the round-trip tests pin.\n */\nexport function serializeShopParams(params: ShopProductsParams): URLSearchParams {\n const sp = new URLSearchParams()\n\n if (params.page !== undefined) sp.set('page', String(params.page))\n if (params.limit !== undefined) sp.set('limit', String(params.limit))\n if (params.q) sp.set('q', params.q)\n if (params.sort) sp.set('sort', params.sort)\n if (params.category) sp.set('category', params.category)\n if (params.priceMin !== undefined) sp.set('priceMin', String(params.priceMin))\n if (params.priceMax !== undefined) sp.set('priceMax', String(params.priceMax))\n if (params.onSale) sp.set('onSale', 'true')\n\n // REB-827: an empty/whitespace-only value is never a real filter — never\n // emit it, matching what parseShopSearchParams would now drop on the way\n // back in anyway (a caller handing this an already-empty `active` value,\n // e.g. a stale object a SITE built itself, must not see it reach the URL).\n //\n // R3-serialize-trim-nullish-throw (review follow-up): `ShopProductsParams`\n // types these values as plain strings, but a JS caller building this object\n // dynamically very commonly ends up with an actual `undefined`/`null` value\n // at runtime regardless of the type (e.g. `taxonomy: { marca: someOptional }`).\n // `typeof value === 'string'` guards `.trim()` itself — a nullish entry is\n // treated exactly like an empty one (never emitted), not a thrown TypeError.\n if (params.taxonomy) {\n for (const [key, value] of Object.entries(params.taxonomy)) {\n if (typeof value === 'string' && value.trim()) sp.set(`taxonomy[${key}]`, value)\n }\n }\n\n if (params.attr) {\n for (const [key, value] of Object.entries(params.attr)) {\n if (Array.isArray(value)) {\n for (const v of value) if (typeof v === 'string' && v.trim()) sp.append(`attr[${key}]`, v)\n } else if (typeof value === 'string' && value.trim()) {\n sp.set(`attr[${key}]`, value)\n }\n }\n }\n\n return sp\n}\n\n/**\n * Convert Next's `searchParams` route prop —\n * `Record<string, string | string[] | undefined>`, already URL-decoded, with\n * a repeated query key grouped into an array — into a `URLSearchParams` for\n * {@link parseShopSearchParams}.\n *\n * NOT the same as `new URLSearchParams(searchParams)`: the native\n * `URLSearchParams` constructor only accepts `Record<string, string>` —\n * handed an array value (`{ 'attr[color]': ['red', 'blue'] }`), it calls\n * `String()` on it, producing ONE entry `attr[color]=red,blue` instead of two\n * repeated `attr[color]=red` / `attr[color]=blue` entries. That silently\n * breaks `parseShopSearchParams`'s repeat-count-based array/scalar\n * distinction (see its own module doc) for every multi-value `attr[<key>]`\n * filter — this helper is what actually preserves the repeat.\n */\nexport function toURLSearchParams(\n searchParams: Record<string, string | string[] | undefined>,\n): URLSearchParams {\n const usp = new URLSearchParams()\n for (const [key, value] of Object.entries(searchParams)) {\n if (value === undefined) continue\n if (Array.isArray(value)) {\n for (const v of value) usp.append(key, v)\n } else {\n usp.append(key, value)\n }\n }\n return usp\n}\n\n/**\n * The navigation seam `@reblu/site-blocks`'s `ShopFilters` calls `hrefs` — kept\n * structurally identical to its `ShopFiltersHrefs` type WITHOUT a package\n * dependency on `@reblu/site-blocks` (this package has none today, and this\n * one shape does not warrant adding one). Any object matching this shape is\n * assignable to `ShopFiltersHrefs` by structural typing.\n */\nexport interface ShopFilterHrefs {\n taxonomy: (axisKey: string, value: string | undefined) => string\n attr: (fieldKey: string, value: string) => string\n price: (min: number | undefined, max: number | undefined) => string\n onSale: (nextActive: boolean) => string\n clearAll: () => string\n}\n\n/**\n * Build `ShopFilters`' href set from the CURRENT params and pathname. Every\n * href preserves every OTHER current param (category, q, sort, every other\n * taxonomy/attr filter) and resets pagination (`page`) — a filter change is\n * never silently stuck on page 4 of a now-smaller result set.\n *\n * Pure and framework-agnostic (no `next/navigation`): a Server Component calls\n * it directly with its own `searchParams` prop and route pathname — no\n * `'use client'` boundary required. See `./use-shop-filter-links` for the\n * client-side hook that wraps this with `usePathname`/`useSearchParams`.\n */\nexport function buildShopFilterHrefs(\n current: ShopProductsParams,\n pathname: string,\n): ShopFilterHrefs {\n function hrefFor(patch: Partial<ShopProductsParams>): string {\n // Any filter change resets pagination — the previous page number almost\n // never still makes sense against the new (usually smaller) result set.\n const next: ShopProductsParams = { ...current, ...patch, page: undefined }\n const qs = serializeShopParams(next).toString()\n return qs ? `${pathname}?${qs}` : pathname\n }\n\n return {\n taxonomy: (axisKey, value) => {\n const taxonomy = { ...current.taxonomy }\n if (value === undefined) delete taxonomy[axisKey]\n else taxonomy[axisKey] = value\n return hrefFor({ taxonomy })\n },\n attr: (fieldKey, value) => {\n const existing = current.attr?.[fieldKey]\n const values = existing === undefined ? [] : Array.isArray(existing) ? existing : [existing]\n const next = values.includes(value) ? values.filter((v) => v !== value) : [...values, value]\n const attr = { ...current.attr }\n if (next.length === 0) delete attr[fieldKey]\n else attr[fieldKey] = next\n return hrefFor({ attr })\n },\n price: (min, max) => hrefFor({ priceMin: min, priceMax: max }),\n onSale: (nextActive) => hrefFor({ onSale: nextActive || undefined }),\n // Clears every FACET dimension only — q/category/sort (the non-facet part\n // of the query) are deliberately preserved, mirroring ShopFilters' own\n // onChange clear-all patch.\n clearAll: () =>\n hrefFor({ taxonomy: undefined, attr: undefined, priceMin: undefined, priceMax: undefined, onSale: undefined }),\n }\n}\n","import type { RebluClient, ListResult } from '@reblu/site-client'\nimport type { ShopFacets, ShopProductListItem } from '@reblu/site-contracts'\nimport type { ShopProductsParams } from '@reblu/site-client'\n\n/**\n * `getShopCollection` (REB-809) — fetches the product list AND its facets with\n * the EXACT SAME params in one call. This is the seam that keeps a shop\n * collection page correct: facet counts must reflect the same filter context\n * the product list is showing, and a hand-rolled page that calls\n * `client.shop.products(params)` and `client.shop.facets(someOtherParams)`\n * separately is exactly how they drift apart.\n *\n * Server-safe (no `'use client'`, no React) — call it directly from an async\n * Server Component (route `page.tsx`) with the params parsed via\n * {@link parseShopSearchParams} from that page's `searchParams` prop.\n */\nexport interface ShopCollection {\n products: ListResult<ShopProductListItem>\n facets: ShopFacets\n /**\n * R3-002: `'ok'` when `client.shop.facets(...)` actually succeeded;\n * `'unavailable'` when it failed and `facets` above is the degraded\n * {@link EMPTY_FACETS} fallback. NOT silent — check this before treating an\n * empty `facets` as \"this tenant configured no filterable axes\" when it may\n * really mean \"the facets endpoint is down right now\". A logged\n * `console.warn` (see below) covers the case nobody checks this field.\n */\n facetsStatus: 'ok' | 'unavailable'\n}\n\n/**\n * Returned when `client.shop.facets(...)` fails — a `ShopFilters` that\n * receives this simply renders nothing (`shouldRenderShopFilters` is false\n * for it with no active selection), which is the correct degraded state: no\n * filter UI, rather than no page at all. Paired with `facetsStatus:\n * 'unavailable'` on the returned {@link ShopCollection}, so a caller that\n * DOES care can tell \"no axes configured\" apart from \"facets endpoint down\".\n */\nconst EMPTY_FACETS: ShopFacets = {\n taxonomies: [],\n attributes: [],\n price: { min: 0, max: 0 },\n onSale: { count: 0 },\n}\n\n/**\n * R4-facets-failure-takes-down-listing: `products` and `facets` are NOT\n * equally critical. A product listing with no products is not a listing —\n * that failure must propagate so the caller's own error handling (or a\n * thrown-away `try/catch` degrading the whole page) sees it. A product\n * listing with no FACETS is still a perfectly good listing, just without\n * filter UI — degrading `facets` to {@link EMPTY_FACETS} on failure, instead\n * of letting one upstream endpoint's outage take the other down too, is what\n * `Promise.allSettled` (rather than `Promise.all`) buys here.\n *\n * R3-002: that degradation must not be SILENT. `console.warn`, bracket-tagged\n * `[getShopCollection]` — the same convention `@reblu/site-next` already uses\n * elsewhere (`route-handlers.ts`'s `[createProxyRoute]`,\n * `set-password.tsx`'s `[SetPassword]`) — fires once per failed call, and the\n * returned `facetsStatus: 'unavailable'` lets a caller that wants to act on\n * it (retry, surface a banner, alert) do so without parsing a log line.\n */\nexport async function getShopCollection(\n client: RebluClient,\n params?: ShopProductsParams,\n): Promise<ShopCollection> {\n const [productsResult, facetsResult] = await Promise.allSettled([\n client.shop.products(params),\n client.shop.facets(params),\n ])\n\n if (productsResult.status === 'rejected') {\n throw productsResult.reason\n }\n\n if (facetsResult.status === 'rejected') {\n console.warn('[getShopCollection] facets fetch failed, degrading to empty ShopFacets:', facetsResult.reason)\n return { products: productsResult.value, facets: EMPTY_FACETS, facetsStatus: 'unavailable' }\n }\n\n return { products: productsResult.value, facets: facetsResult.value, facetsStatus: 'ok' }\n}\n"],"mappings":";;;AAEA,SAAS,aAAa,uBAAuB;;;ACa7C,IAAM,YAAY;AAClB,IAAM,kBAAkB;AACxB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAQ3B,IAAM,YAAY;AAElB,IAAM,aAAa,CAAC,aAAa,cAAc,UAAU,SAAS;AAElE,SAAS,WAAW,OAAqD;AACvE,SAAQ,WAAiC,SAAS,KAAK;AACzD;AAUA,SAAS,eAAe,KAAwC;AAC9D,MAAI,QAAQ,QAAQ,CAAC,QAAQ,KAAK,GAAG,EAAG,QAAO;AAC/C,QAAM,IAAI,OAAO,SAAS,KAAK,EAAE;AACjC,SAAO,OAAO,MAAM,CAAC,IAAI,SAAY;AACvC;AAqBA,SAAS,cAAiB,QAA8C;AACtE,SAAO,EAAE,GAAG,OAAO;AACrB;AAqBA,SAAS,mBACP,cACA,QAC+C;AAC/C,QAAM,MAAyC,uBAAO,OAAO,IAAI;AACjE,QAAM,KAAK,IAAI,OAAO,IAAI,MAAM,aAAa;AAC7C,aAAW,CAAC,QAAQ,QAAQ,KAAK,aAAa,QAAQ,GAAG;AACvD,UAAM,QAAQ,OAAO,MAAM,EAAE;AAC7B,QAAI,CAAC,MAAO;AACZ,UAAM,MAAM,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,UAAM,eAAe;AAAA,EACvB;AAEA,MAAI,aAAa,WAAW,YAAY;AACtC,YAAQ,KAAK,2EAA2E,aAAa,MAAM;AAC3G,WAAO,EAAE,UAAU,eAAe,OAAO,QAAQ,cAAc,cAAc,cAAc;AAAA,EAC7F;AAEA,SAAO,EAAE,UAAU,eAAe,OAAO,QAAQ,aAAa,OAAO,cAAc,KAAK;AAC1F;","names":[]}
1
+ {"version":3,"sources":["../src/shop/use-shop-filter-links.ts","../src/shop/params.ts","../src/shop/collection.ts","../src/shop/use-shop-order-status.ts","../src/cart/store.ts","../src/shop/use-checkout-return.ts"],"sourcesContent":["'use client'\n\nimport { usePathname, useSearchParams } from 'next/navigation'\n\nimport { buildShopFilterHrefs, parseShopSearchParams, type ShopFilterHrefs } from './params'\n\n/**\n * Client-reactive version of `buildShopFilterHrefs` (REB-809), bound to the\n * CURRENT URL via `next/navigation`. Use it when a shop collection's filter\n * bar is its own Client Component (e.g. a sticky sidebar) and you want the\n * hrefs to update instantly as the URL changes client-side, without every\n * caller re-deriving `pathname`/`searchParams` by hand.\n *\n * A Server Component does NOT need this hook — it already has `searchParams`\n * as a prop and a static route pathname, so it calls\n * `buildShopFilterHrefs` (from `./params` or the `./shop-server` subpath)\n * directly. Reach for this hook only from inside a `'use client'` boundary.\n */\nexport function useShopFilterLinks(): ShopFilterHrefs {\n const pathname = usePathname()\n const searchParams = useSearchParams()\n const current = parseShopSearchParams(searchParams)\n return buildShopFilterHrefs(current, pathname)\n}\n","import type { ShopProductsParams } from '@reblu/site-client'\n\n/**\n * REB-809 — URL ↔ `ShopProductsParams` glue for a SITE's shop/collection page.\n *\n * Mirrors base-api's own `parseListParams`\n * (`apps/base-api/src/lib/shop/catalogue-query.ts`) deliberately: the SAME\n * bracket shape (`taxonomy[<key>]=<slug>`, `attr[<key>]=<value>`, repeatable\n * for `attr`), the SAME MVP collapse for `taxonomy` (one term slug per axis —\n * a repeat keeps only the first), and the SAME defensive caps on bracket\n * key/value counts. Keeping this a mirror rather than a re-implementation\n * means a URL this module builds is EXACTLY the URL the server will parse\n * back to the same params — there is no second, drifting parser.\n */\n\nconst MAX_Q_LEN = 200\nconst MAX_FILTER_KEYS = 30\nconst MAX_VALUE_LEN = 120\nconst MAX_VALUES_PER_KEY = 30\n/**\n * Mirrors `shopProductListParamsSchema`'s `limit: z.number().int().min(1).max(50)`\n * in `apps/base-api/src/lib/contracts/shop.contract.ts` — keep the two in sync;\n * a caller-side limit above this is server-rejected/clamped anyway, but parsing\n * it through here means a URL this module builds never claims a limit the\n * server will refuse.\n */\nconst MAX_LIMIT = 50\n\nconst SHOP_SORTS = ['price_asc', 'price_desc', 'newest', 'on_sale'] as const\n\nfunction isShopSort(value: string): value is (typeof SHOP_SORTS)[number] {\n return (SHOP_SORTS as readonly string[]).includes(value)\n}\n\n/**\n * Parse a non-negative integer, STRICT digits only — `/^\\d+$/`, so '12abc'\n * and '1.5' are rejected outright rather than `Number.parseInt` silently\n * taking the leading '12'/'1' and discarding the rest as if it were valid\n * input. Named for exactly what it accepts: >= 0, not \"positive\" (which\n * excludes 0) — callers that need >= 1 (page, limit) enforce that bound\n * themselves on top of this.\n */\nfunction nonNegativeInt(raw: string | null): number | undefined {\n if (raw === null || !/^\\d+$/.test(raw)) return undefined\n const n = Number.parseInt(raw, 10)\n return Number.isNaN(n) ? undefined : n\n}\n\n/**\n * Copy a (possibly null-prototype) object's own enumerable properties into a\n * fresh PLAIN object — `Object.prototype` in its chain, nothing else.\n *\n * R3-001: this module's internal accumulators use `Object.create(null)` for\n * prototype-pollution safety (see `parseBracketParams`' own doc below), but\n * that safety property must NEVER leak into `ShopProductsParams.taxonomy`/\n * `.attr`, the values a SITE actually receives. React Flight — the\n * serialization React Server Components use to send props across the\n * Server→Client boundary — refuses a non-plain object (`Object.\n * getPrototypeOf(x) !== Object.prototype`) with a hard runtime error. This\n * package's own README tells a Client Component caller to pass\n * `active={params}` to `ShopFilters`' `onChange` mode, so a null-prototype\n * `taxonomy`/`attr` reaching that boundary would crash every SITE that\n * followed the documented pattern. Object spread (`{ ...source }`) always\n * produces a plain object regardless of the source's own prototype, which is\n * exactly the property this needs and `Object.assign({}, source)` also has —\n * spread is used here for clarity.\n */\nfunction toPlainObject<T>(source: Record<string, T>): Record<string, T> {\n return { ...source }\n}\n\n/**\n * Parse `bracket[key]` params into a map, collapsing repeats into arrays.\n *\n * Built on `Object.create(null)` rather than a plain `{}` — a query string is\n * attacker-controlled input, and `taxonomy[constructor]=x` or\n * `taxonomy[toString]=x` against a plain object reads/writes through the\n * INHERITED `Object.prototype` property of that name before this function's\n * own `key in out` / `out[key]` logic ever sees an actual own property,\n * corrupting the key-count bookkeeping and the parsed value for that key. A\n * null-prototype object has no inherited properties at all, so `in` and\n * indexed access only ever see what this loop itself has written — the same\n * defense `JSON.parse` reviewers reach for against prototype-pollution-style\n * bracket keys, applied here to a hand-rolled key/value accumulator.\n *\n * The RETURNED object is converted back to a plain one via\n * {@link toPlainObject} — the null prototype is this function's OWN internal\n * bookkeeping safety, never part of its public output (see that helper's doc\n * for why: React Flight/RSC serialization).\n */\nfunction parseBracketParams(\n searchParams: URLSearchParams,\n prefix: string,\n): Record<string, string | string[]> | undefined {\n const out: Record<string, string | string[]> = Object.create(null)\n const re = new RegExp(`^${prefix}\\\\[(.+)\\\\]$`)\n for (const [rawKey, rawValue] of searchParams.entries()) {\n const match = rawKey.match(re)\n if (!match) continue\n const key = match[1]\n const value = rawValue.trim().slice(0, MAX_VALUE_LEN)\n // REB-827: an empty/whitespace-only value (e.g. a cleared `taxonomy[marca]=`,\n // or a stale/hand-built link) is never a real filter — trim and drop it\n // here, mirroring how `q` is trimmed and dropped when empty, so a key left\n // with no surviving value never enters `out` and never reaches the caller\n // as `{ key: '' }`/`{ key: [] }`.\n if (!value) continue\n if (!(key in out) && Object.keys(out).length >= MAX_FILTER_KEYS) continue\n const existing = out[key]\n if (existing === undefined) out[key] = value\n else if (Array.isArray(existing)) {\n if (existing.length < MAX_VALUES_PER_KEY) existing.push(value)\n } else out[key] = [existing, value]\n }\n return Object.keys(out).length > 0 ? toPlainObject(out) : undefined\n}\n\n/**\n * Parse a `URLSearchParams` (or anything with that shape — `ReadonlyURLSearchParams`\n * from `next/navigation`, or a plain `new URLSearchParams(record)`) into\n * `ShopProductsParams`. Hostile/unknown params are dropped: only the known\n * scalar keys and the two bracket groups are ever read.\n */\nexport function parseShopSearchParams(searchParams: URLSearchParams): ShopProductsParams {\n const params: ShopProductsParams = {}\n\n const page = nonNegativeInt(searchParams.get('page'))\n if (page !== undefined && page >= 1) params.page = page\n\n const limit = nonNegativeInt(searchParams.get('limit'))\n if (limit !== undefined && limit >= 1 && limit <= MAX_LIMIT) params.limit = limit\n\n const q = searchParams.get('q')?.trim().slice(0, MAX_Q_LEN)\n if (q) params.q = q\n\n const sort = searchParams.get('sort')\n if (sort !== null && isShopSort(sort)) params.sort = sort\n\n const category = searchParams.get('category')?.trim()\n if (category) params.category = category\n\n let priceMin = nonNegativeInt(searchParams.get('priceMin'))\n let priceMax = nonNegativeInt(searchParams.get('priceMax'))\n // An inverted range (priceMin > priceMax) would otherwise always match zero\n // products server-side — swap rather than pass through a query that can\n // never return a result, or silently drop half of it.\n if (priceMin !== undefined && priceMax !== undefined && priceMin > priceMax) {\n ;[priceMin, priceMax] = [priceMax, priceMin]\n }\n // Only assign when actually present — an explicit `priceMin: undefined` key\n // is never written, so `toStrictEqual`/`toEqual` against a literal object\n // without that key both hold, and a downstream `'priceMin' in params` check\n // reflects reality.\n if (priceMin !== undefined) params.priceMin = priceMin\n if (priceMax !== undefined) params.priceMax = priceMax\n\n const onSale = searchParams.get('onSale')\n if (onSale === 'true' || onSale === '1') params.onSale = true\n\n const taxonomyRaw = parseBracketParams(searchParams, 'taxonomy')\n if (taxonomyRaw) {\n // A taxonomy axis takes a single term slug in MVP — collapse any repeats,\n // exactly like the server does (see module doc). Object.create(null) for\n // the SAME reason as parseBracketParams' own accumulator: `key` is\n // attacker-controlled (it is the bracket-key from the query string), and\n // a plain `{}` here reintroduces the exact bug parseBracketParams just\n // fixed one step downstream — `taxonomy['__proto__'] = value` on a plain\n // object hits the inherited `__proto__` ACCESSOR, which silently no-ops\n // for a non-object value instead of creating an own property, so that\n // key would vanish from the result entirely (not merely mis-set).\n const taxonomy: Record<string, string> = Object.create(null)\n for (const [key, value] of Object.entries(taxonomyRaw)) {\n taxonomy[key] = Array.isArray(value) ? value[0] : value\n }\n // Plain object out, same reason as parseBracketParams' own return value —\n // see toPlainObject's doc (R3-001, React Flight/RSC serialization).\n params.taxonomy = toPlainObject(taxonomy)\n }\n\n const attr = parseBracketParams(searchParams, 'attr')\n if (attr) params.attr = attr\n\n return params\n}\n\n/**\n * Serialize `ShopProductsParams` into a `URLSearchParams` — the inverse of\n * {@link parseShopSearchParams}. Falsy/empty/undefined fields are omitted, so\n * `parseShopSearchParams(serializeShopParams(params))` round-trips to `params`\n * for any already-canonical (non-empty-string, in-range) input — that is the\n * property the round-trip tests pin.\n */\nexport function serializeShopParams(params: ShopProductsParams): URLSearchParams {\n const sp = new URLSearchParams()\n\n if (params.page !== undefined) sp.set('page', String(params.page))\n if (params.limit !== undefined) sp.set('limit', String(params.limit))\n if (params.q) sp.set('q', params.q)\n if (params.sort) sp.set('sort', params.sort)\n if (params.category) sp.set('category', params.category)\n if (params.priceMin !== undefined) sp.set('priceMin', String(params.priceMin))\n if (params.priceMax !== undefined) sp.set('priceMax', String(params.priceMax))\n if (params.onSale) sp.set('onSale', 'true')\n\n // REB-827: an empty/whitespace-only value is never a real filter — never\n // emit it, matching what parseShopSearchParams would now drop on the way\n // back in anyway (a caller handing this an already-empty `active` value,\n // e.g. a stale object a SITE built itself, must not see it reach the URL).\n //\n // R3-serialize-trim-nullish-throw (review follow-up): `ShopProductsParams`\n // types these values as plain strings, but a JS caller building this object\n // dynamically very commonly ends up with an actual `undefined`/`null` value\n // at runtime regardless of the type (e.g. `taxonomy: { marca: someOptional }`).\n // `typeof value === 'string'` guards `.trim()` itself — a nullish entry is\n // treated exactly like an empty one (never emitted), not a thrown TypeError.\n if (params.taxonomy) {\n for (const [key, value] of Object.entries(params.taxonomy)) {\n if (typeof value === 'string' && value.trim()) sp.set(`taxonomy[${key}]`, value)\n }\n }\n\n if (params.attr) {\n for (const [key, value] of Object.entries(params.attr)) {\n if (Array.isArray(value)) {\n for (const v of value) if (typeof v === 'string' && v.trim()) sp.append(`attr[${key}]`, v)\n } else if (typeof value === 'string' && value.trim()) {\n sp.set(`attr[${key}]`, value)\n }\n }\n }\n\n return sp\n}\n\n/**\n * Convert Next's `searchParams` route prop —\n * `Record<string, string | string[] | undefined>`, already URL-decoded, with\n * a repeated query key grouped into an array — into a `URLSearchParams` for\n * {@link parseShopSearchParams}.\n *\n * NOT the same as `new URLSearchParams(searchParams)`: the native\n * `URLSearchParams` constructor only accepts `Record<string, string>` —\n * handed an array value (`{ 'attr[color]': ['red', 'blue'] }`), it calls\n * `String()` on it, producing ONE entry `attr[color]=red,blue` instead of two\n * repeated `attr[color]=red` / `attr[color]=blue` entries. That silently\n * breaks `parseShopSearchParams`'s repeat-count-based array/scalar\n * distinction (see its own module doc) for every multi-value `attr[<key>]`\n * filter — this helper is what actually preserves the repeat.\n */\nexport function toURLSearchParams(\n searchParams: Record<string, string | string[] | undefined>,\n): URLSearchParams {\n const usp = new URLSearchParams()\n for (const [key, value] of Object.entries(searchParams)) {\n if (value === undefined) continue\n if (Array.isArray(value)) {\n for (const v of value) usp.append(key, v)\n } else {\n usp.append(key, value)\n }\n }\n return usp\n}\n\n/**\n * The navigation seam `@reblu/site-blocks`'s `ShopFilters` calls `hrefs` — kept\n * structurally identical to its `ShopFiltersHrefs` type WITHOUT a package\n * dependency on `@reblu/site-blocks` (this package has none today, and this\n * one shape does not warrant adding one). Any object matching this shape is\n * assignable to `ShopFiltersHrefs` by structural typing.\n */\nexport interface ShopFilterHrefs {\n taxonomy: (axisKey: string, value: string | undefined) => string\n attr: (fieldKey: string, value: string) => string\n price: (min: number | undefined, max: number | undefined) => string\n onSale: (nextActive: boolean) => string\n clearAll: () => string\n}\n\n/**\n * Build `ShopFilters`' href set from the CURRENT params and pathname. Every\n * href preserves every OTHER current param (category, q, sort, every other\n * taxonomy/attr filter) and resets pagination (`page`) — a filter change is\n * never silently stuck on page 4 of a now-smaller result set.\n *\n * Pure and framework-agnostic (no `next/navigation`): a Server Component calls\n * it directly with its own `searchParams` prop and route pathname — no\n * `'use client'` boundary required. See `./use-shop-filter-links` for the\n * client-side hook that wraps this with `usePathname`/`useSearchParams`.\n */\nexport function buildShopFilterHrefs(\n current: ShopProductsParams,\n pathname: string,\n): ShopFilterHrefs {\n function hrefFor(patch: Partial<ShopProductsParams>): string {\n // Any filter change resets pagination — the previous page number almost\n // never still makes sense against the new (usually smaller) result set.\n const next: ShopProductsParams = { ...current, ...patch, page: undefined }\n const qs = serializeShopParams(next).toString()\n return qs ? `${pathname}?${qs}` : pathname\n }\n\n return {\n taxonomy: (axisKey, value) => {\n const taxonomy = { ...current.taxonomy }\n if (value === undefined) delete taxonomy[axisKey]\n else taxonomy[axisKey] = value\n return hrefFor({ taxonomy })\n },\n attr: (fieldKey, value) => {\n const existing = current.attr?.[fieldKey]\n const values = existing === undefined ? [] : Array.isArray(existing) ? existing : [existing]\n const next = values.includes(value) ? values.filter((v) => v !== value) : [...values, value]\n const attr = { ...current.attr }\n if (next.length === 0) delete attr[fieldKey]\n else attr[fieldKey] = next\n return hrefFor({ attr })\n },\n price: (min, max) => hrefFor({ priceMin: min, priceMax: max }),\n onSale: (nextActive) => hrefFor({ onSale: nextActive || undefined }),\n // Clears every FACET dimension only — q/category/sort (the non-facet part\n // of the query) are deliberately preserved, mirroring ShopFilters' own\n // onChange clear-all patch.\n clearAll: () =>\n hrefFor({ taxonomy: undefined, attr: undefined, priceMin: undefined, priceMax: undefined, onSale: undefined }),\n }\n}\n","import type { RebluClient, ListResult } from '@reblu/site-client'\nimport type { ShopFacets, ShopProductListItem } from '@reblu/site-contracts'\nimport type { ShopProductsParams } from '@reblu/site-client'\n\n/**\n * `getShopCollection` (REB-809) — fetches the product list AND its facets with\n * the EXACT SAME params in one call. This is the seam that keeps a shop\n * collection page correct: facet counts must reflect the same filter context\n * the product list is showing, and a hand-rolled page that calls\n * `client.shop.products(params)` and `client.shop.facets(someOtherParams)`\n * separately is exactly how they drift apart.\n *\n * Server-safe (no `'use client'`, no React) — call it directly from an async\n * Server Component (route `page.tsx`) with the params parsed via\n * {@link parseShopSearchParams} from that page's `searchParams` prop.\n */\nexport interface ShopCollection {\n products: ListResult<ShopProductListItem>\n facets: ShopFacets\n /**\n * R3-002: `'ok'` when `client.shop.facets(...)` actually succeeded;\n * `'unavailable'` when it failed and `facets` above is the degraded\n * {@link EMPTY_FACETS} fallback. NOT silent — check this before treating an\n * empty `facets` as \"this tenant configured no filterable axes\" when it may\n * really mean \"the facets endpoint is down right now\". A logged\n * `console.warn` (see below) covers the case nobody checks this field.\n */\n facetsStatus: 'ok' | 'unavailable'\n}\n\n/**\n * Returned when `client.shop.facets(...)` fails — a `ShopFilters` that\n * receives this simply renders nothing (`shouldRenderShopFilters` is false\n * for it with no active selection), which is the correct degraded state: no\n * filter UI, rather than no page at all. Paired with `facetsStatus:\n * 'unavailable'` on the returned {@link ShopCollection}, so a caller that\n * DOES care can tell \"no axes configured\" apart from \"facets endpoint down\".\n */\nconst EMPTY_FACETS: ShopFacets = {\n taxonomies: [],\n attributes: [],\n price: { min: 0, max: 0 },\n onSale: { count: 0 },\n}\n\n/**\n * R4-facets-failure-takes-down-listing: `products` and `facets` are NOT\n * equally critical. A product listing with no products is not a listing —\n * that failure must propagate so the caller's own error handling (or a\n * thrown-away `try/catch` degrading the whole page) sees it. A product\n * listing with no FACETS is still a perfectly good listing, just without\n * filter UI — degrading `facets` to {@link EMPTY_FACETS} on failure, instead\n * of letting one upstream endpoint's outage take the other down too, is what\n * `Promise.allSettled` (rather than `Promise.all`) buys here.\n *\n * R3-002: that degradation must not be SILENT. `console.warn`, bracket-tagged\n * `[getShopCollection]` — the same convention `@reblu/site-next` already uses\n * elsewhere (`route-handlers.ts`'s `[createProxyRoute]`,\n * `set-password.tsx`'s `[SetPassword]`) — fires once per failed call, and the\n * returned `facetsStatus: 'unavailable'` lets a caller that wants to act on\n * it (retry, surface a banner, alert) do so without parsing a log line.\n */\nexport async function getShopCollection(\n client: RebluClient,\n params?: ShopProductsParams,\n): Promise<ShopCollection> {\n const [productsResult, facetsResult] = await Promise.allSettled([\n client.shop.products(params),\n client.shop.facets(params),\n ])\n\n if (productsResult.status === 'rejected') {\n throw productsResult.reason\n }\n\n if (facetsResult.status === 'rejected') {\n console.warn('[getShopCollection] facets fetch failed, degrading to empty ShopFacets:', facetsResult.reason)\n return { products: productsResult.value, facets: EMPTY_FACETS, facetsStatus: 'unavailable' }\n }\n\n return { products: productsResult.value, facets: facetsResult.value, facetsStatus: 'ok' }\n}\n","'use client'\n\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport type { ShopOrder } from '@reblu/site-contracts'\n\nimport { useCartStore } from '../cart/store'\n\nexport type ShopOrderStatusState =\n | 'loading'\n | 'paid'\n | 'pending_timeout'\n | 'failed'\n | 'refunded'\n | 'partially_refunded'\n | 'not_found'\n | 'error'\n\nexport interface UseShopOrderStatusOptions {\n /**\n * Builds the SITE's own order Route Handler path from the session id.\n * @default (id) => `/api/shop/order/${encodeURIComponent(id)}`\n */\n buildUrl?: (sessionId: string) => string\n /**\n * Total polling window before giving up as `pending_timeout`, ms.\n * @default 30000\n *\n * Enforced by its OWN independent timer (REB-837 review fix), not by\n * checking elapsed time inside `poll()` — a hung request that never\n * settles used to block `poll()` from ever reaching that check at all,\n * leaving `status` stuck on `'loading'` forever.\n */\n timeoutMs?: number\n /** Initial delay between polls, ms, before backoff. @default 2000 */\n intervalMs?: number\n /** Multiplier applied to the interval after each PENDING poll. @default 1.5 */\n backoffFactor?: number\n /** Ceiling on the backed-off interval, ms. @default 5000 */\n maxIntervalMs?: number\n /**\n * Hard timeout for a SINGLE request, ms (REB-837 review fix) — aborts and\n * retries with backoff rather than leaving a hung `fetch` blocking\n * indefinitely. Distinct from `timeoutMs` (the WHOLE polling window):\n * one slow request past `requestTimeoutMs` is transient and retried; the\n * window elapsing is terminal (`pending_timeout`).\n * @default 8000\n */\n requestTimeoutMs?: number\n}\n\nexport interface UseShopOrderStatusResult {\n status: ShopOrderStatusState\n order: ShopOrder | null\n /** Re-runs the poll loop from scratch — e.g. the \"Volver a comprobar\" button. */\n recheck: () => void\n}\n\nfunction defaultBuildUrl(sessionId: string): string {\n return `/api/shop/order/${encodeURIComponent(sessionId)}`\n}\n\n/**\n * `useShopOrderStatus` (REB-837) — the client-side half of the order-\n * confirmation flow: polls the SITE's OWN order Route Handler (built from\n * `createShopOrderRoute`, never base-api directly — same rule as every other\n * client-side shop call in this package) for up to `timeoutMs` with backoff,\n * and clears the cart ONLY once the order resolves to `PAID` — never on\n * `pending_timeout`, `failed`, or any other state, so an interrupted/failed\n * payment leaves the visitor's cart exactly as they left it.\n *\n * Checkout is card-only today, so `PENDING` past the window is only ever\n * transient (the confirming webhook landing late) — see REB-836 for the\n * redirect-origin hardening this flow sits behind.\n */\nexport function useShopOrderStatus(\n sessionId: string | null | undefined,\n opts: UseShopOrderStatusOptions = {},\n): UseShopOrderStatusResult {\n const {\n buildUrl = defaultBuildUrl,\n timeoutMs = 30000,\n intervalMs = 2000,\n backoffFactor = 1.5,\n maxIntervalMs = 5000,\n requestTimeoutMs = 8000,\n } = opts\n\n const [status, setStatus] = useState<ShopOrderStatusState>(sessionId ? 'loading' : 'not_found')\n const [order, setOrder] = useState<ShopOrder | null>(null)\n const [recheckToken, setRecheckToken] = useState(0)\n\n const recheck = useCallback(() => setRecheckToken((n) => n + 1), [])\n\n /**\n * \"Latest ref\" for `buildUrl` (REB-837 mutation find): a caller passing an\n * inline `{ buildUrl: (id) => ... }` literal — the natural way to call\n * this hook — gets a NEW function identity every render. Putting that\n * function directly in the polling effect's dependency array caused an\n * infinite loop: `setOrder(freshlyParsedJson)` always produces a new\n * object reference regardless of content, so it forces a re-render even\n * when the status is already settled; the re-render recreates the inline\n * `buildUrl`; the changed dependency re-fires the effect; which fetches\n * and calls `setOrder` again — forever, reproduced as an OOM crash under\n * test. `buildUrl` is read through this ref inside `poll()` instead, so\n * the effect only restarts on `sessionId`/`recheckToken`/the numeric\n * options, never on a same-render-identity-churning function prop.\n */\n const buildUrlRef = useRef(buildUrl)\n buildUrlRef.current = buildUrl\n\n useEffect(() => {\n if (!sessionId) {\n setStatus('not_found')\n setOrder(null)\n return\n }\n\n setStatus('loading')\n setOrder(null)\n\n let cancelled = false\n let pollTimer: ReturnType<typeof setTimeout> | null = null\n let requestController: AbortController | null = null\n let attempt = 0\n\n /**\n * Terminal transition — idempotent (guarded by `cancelled`) so the\n * independent window timer and an in-flight poll can both race to call\n * it without double-firing side effects like `clearCart()`.\n */\n const finish = (nextStatus: ShopOrderStatusState) => {\n if (cancelled) return\n cancelled = true\n clearTimeout(windowTimer)\n if (pollTimer) clearTimeout(pollTimer)\n requestController?.abort()\n setStatus(nextStatus)\n }\n\n // REB-837 review fix: enforces the WHOLE polling window independently\n // of any request's own outcome — a `fetch` that never settles (hangs\n // forever) must not leave `status` stuck on `'loading'` indefinitely.\n const windowTimer = setTimeout(() => finish('pending_timeout'), timeoutMs)\n\n const poll = async () => {\n if (cancelled) return\n\n requestController = new AbortController()\n const requestTimer = setTimeout(() => requestController?.abort(), requestTimeoutMs)\n\n try {\n const res = await fetch(buildUrlRef.current(sessionId), {\n signal: requestController.signal,\n cache: 'no-store',\n })\n clearTimeout(requestTimer)\n if (cancelled) return\n\n if (res.status === 404) {\n finish('not_found')\n return\n }\n\n if (!res.ok) {\n finish('error')\n return\n }\n\n // REB-839: `createShopOrderRoute` forwards base-api's body verbatim,\n // and base-api wraps every payload as `{ data: <order> }` (`apiOk`).\n // Unwrap it; a bare order (a custom route that already unwrapped) is\n // still accepted as-is.\n const body = (await res.json()) as { data?: ShopOrder } | ShopOrder\n if (cancelled) return\n const data = (\n body && typeof body === 'object' && 'data' in body && body.data ? body.data : body\n ) as ShopOrder\n\n setOrder(data)\n\n switch (data.paymentStatus) {\n case 'PAID':\n // REB-837: the ONE place this hook mutates anything else — a\n // cart cleared on any other status would discard it on a\n // payment that never actually completed.\n useCartStore.getState().clearCart()\n finish('paid')\n return\n case 'FAILED':\n finish('failed')\n return\n case 'REFUNDED':\n finish('refunded')\n return\n case 'PARTIALLY_REFUNDED':\n finish('partially_refunded')\n return\n case 'PENDING':\n default: {\n if (cancelled) return\n const nextDelay = Math.min(intervalMs * backoffFactor ** attempt, maxIntervalMs)\n attempt += 1\n pollTimer = setTimeout(poll, nextDelay)\n }\n }\n } catch (err) {\n clearTimeout(requestTimer)\n if (cancelled) return\n if (err instanceof Error && err.name === 'AbortError') {\n // A single slow/hung request past `requestTimeoutMs` (or an\n // unmount/recheck abort, harmless since `cancelled` is already\n // true in that case and we returned above) — transient, retry\n // with backoff rather than treating ONE slow request as fatal.\n // The independent `windowTimer` is what ultimately bounds this.\n const nextDelay = Math.min(intervalMs * backoffFactor ** attempt, maxIntervalMs)\n attempt += 1\n pollTimer = setTimeout(poll, nextDelay)\n return\n }\n finish('error')\n }\n }\n\n void poll()\n\n return () => {\n cancelled = true\n clearTimeout(windowTimer)\n if (pollTimer) clearTimeout(pollTimer)\n requestController?.abort()\n }\n // `buildUrl` intentionally excluded — see the `buildUrlRef` docblock above.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [sessionId, recheckToken, timeoutMs, intervalMs, backoffFactor, maxIntervalMs, requestTimeoutMs])\n\n return { status, order, recheck }\n}\n","import { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\n\n/**\n * `useCartStore` — the SDK's cart state (REB-829). Ported verbatim (same\n * shape, same quantity-clamping rules) from demo-site's local\n * `lib/store/cart-store.ts`, which every SITE was otherwise expected to\n * hand-copy. `CART_STORAGE_KEY` stays exactly `'shop-cart'` on purpose: a\n * SITE migrating from the local copy keeps its visitors' existing carts.\n *\n * `skipHydration: true` (zustand persist) is load-bearing for SSR: without\n * it, zustand's persist middleware reads `localStorage` synchronously during\n * module evaluation, which throws (or silently desyncs) on the server. The\n * `CartProvider` (`./provider`) calls `useCartStore.persist.rehydrate()`\n * inside a `useEffect`, so hydration only ever happens client-side, after\n * mount — the same explicit-hydration contract the SITE README documents.\n */\nexport const CART_STORAGE_KEY = 'shop-cart'\n\n/**\n * The zustand `persist` schema version for the cart's PERSISTED shape (the\n * `CartItem[]` written to `localStorage` under `CART_STORAGE_KEY`) — bump\n * this (with a `migrate` option) if that shape ever changes incompatibly.\n * Also folded into {@link CART_STORE_GLOBAL_KEY} (REB-837 review fix): a\n * future incompatible shape change should mint a NEW global singleton\n * rather than let a stale, already-evaluated old-shape instance (e.g. kept\n * alive across an HMR reload in dev) silently satisfy the new one.\n */\nexport const CART_STORE_PERSIST_VERSION = 0\n\nexport interface CartItem {\n productId: string\n variantId?: string | null\n name: string\n variantName?: string\n /** Integer cents — every Reblu shop price travels as cents, never a float. */\n unitPrice: number\n quantity: number\n imageUrl?: string\n /** `null` means untracked/unlimited stock — never clamp against it. */\n maxStock: number | null\n /** Basis points, e.g. `2100` = 21%. `null`/`undefined` = unknown or exempt. */\n taxRateBps?: number | null\n taxRateName?: string | null\n}\n\n/**\n * Outcome of `addItem` (REB-837): a SITE's add-to-cart feedback (toast,\n * `AddToCartButton`'s built-in confirmed/error state) needs to know what\n * actually happened, not just fire-and-forget — `'clamped'` only differs\n * from `'added'` in the RESULTING quantity reaching less than what was\n * requested (capped by `maxStock`) while the line still grew; `'refused'`\n * means nothing was added (invalid quantity, out of stock, or the line was\n * already at `maxStock` — REB-839).\n */\nexport type AddItemStatus = 'added' | 'clamped' | 'refused'\n\nexport interface AddItemOutcome {\n status: AddItemStatus\n /** The resulting line quantity after the call (`0` when refused and no line exists). */\n quantity: number\n}\n\nexport interface CartStore {\n items: CartItem[]\n addItem: (item: CartItem) => AddItemOutcome\n removeItem: (productId: string, variantId?: string | null) => void\n updateQuantity: (\n productId: string,\n variantId: string | null | undefined,\n quantity: number,\n ) => void\n clearCart: () => void\n getTotal: () => number\n getItemCount: () => number\n}\n\nfunction isSameItem(a: CartItem, productId: string, variantId?: string | null): boolean {\n return a.productId === productId && (a.variantId ?? null) === (variantId ?? null)\n}\n\n/**\n * REB-829 review finding: neither `addItem` nor `updateQuantity` validated\n * `quantity` — `0`, a negative number, `NaN` (e.g. a stray `parseInt('')`\n * upstream), a non-integer, or `maxStock` itself being `0` (out of stock)\n * all used to leave an invalid line sitting in the cart, silently reaching\n * checkout.\n *\n * Normalizes to a safe POSITIVE INTEGER clamped to `maxStock`. Returns `0`\n * to signal \"not a valid positive quantity\" — callers decide what that\n * means for them: `addItem` ignores the call (never creates/corrupts a\n * line), `updateQuantity` removes the line (same as its pre-existing\n * `quantity <= 0` → remove contract, just now reached by more inputs).\n *\n * `Math.trunc` rounds toward zero (not `Math.floor`, which would round a\n * negative input further negative before the `< 1` check below ever saw it\n * — not a behavioural difference here since any negative result is\n * rejected either way, but `trunc` is the operation that actually means\n * \"drop the fractional part\").\n */\nfunction normalizeQuantity(quantity: number, maxStock: number | null): number {\n if (!Number.isFinite(quantity)) return 0\n const truncated = Math.trunc(quantity)\n if (truncated < 1) return 0\n if (maxStock === null) return truncated\n const maxTruncated = Math.trunc(maxStock)\n if (maxTruncated < 1) return 0\n return Math.min(truncated, maxTruncated)\n}\n\n/**\n * REB-837 cross-entry singleton guard — the mutation that caught it: a\n * single test rendering `useShopOrderStatus` (the `./shop` tsup entry) and\n * asserting on `useCartStore` (the `./cart` entry) saw the order resolve to\n * `paid` but the cart stay non-empty. Root cause: `splitting: false` (R4,\n * `tsup.config.ts`) bundles each entry standalone, so a plain relative\n * import of this file from `./shop` INLINES a SEPARATE copy of this\n * `create(...)` call — a second, disconnected store instance with its own\n * state, not the one `@reblu/site-next/cart` consumers read. `clearCart()`\n * from inside the hook silently cleared the WRONG store.\n *\n * `globalThis` keyed by a `Symbol.for(...)` (same registry entry regardless\n * of which bundle's copy of this module evaluates it first) makes every\n * entry that imports this file — however many times esbuild inlines it —\n * resolve to the SAME store. Verified by mutation: removing this guard\n * (reverting to a bare `export const useCartStore = create(...)`) turns\n * `use-shop-order-status.test.ts`'s cart-clearing assertions red again once\n * the hook is exercised through its OWN entry rather than imported directly\n * within `cart`'s own test file (which never saw the bug, since it only\n * ever touches ONE copy of this module).\n */\nfunction createCartStore() {\n return create<CartStore>()(\n persist(\n (set, get) => ({\n items: [],\n\n addItem: (item) => {\n // REB-837: `set`'s updater can't return a value to the caller, so the\n // outcome is captured in this closure variable and returned after.\n let outcome: AddItemOutcome = { status: 'refused', quantity: 0 }\n\n set((state) => {\n const existing = state.items.find((i) => isSameItem(i, item.productId, item.variantId))\n\n if (existing) {\n // REB-829 review follow-up (a): incoming maxStock is the\n // FRESHEST stock signal available — if it says 0, the product is\n // confirmed out of stock right now, so the existing line is\n // removed outright (same contract as updateQuantity's own\n // \"quantity resolves to <1 → remove\"), not merely left alone.\n if (item.maxStock !== null && Math.trunc(item.maxStock) < 1) {\n outcome = { status: 'refused', quantity: 0 }\n return {\n items: state.items.filter((i) => !isSameItem(i, item.productId, item.variantId)),\n }\n }\n\n const requestedQty = existing.quantity + item.quantity\n const newQty = normalizeQuantity(requestedQty, item.maxStock)\n if (newQty < 1) {\n // Invalid delta (NaN/non-positive quantity) — leave the\n // existing, previously-valid line untouched rather than\n // destroying good data because of one bad call.\n outcome = { status: 'refused', quantity: existing.quantity }\n return {}\n }\n\n // REB-839: nothing was gained when stock caps the line at (or,\n // with fresher stock, below) what it already held — report that\n // as 'refused', never as a partial-success 'clamped'. The line is\n // still reconciled below to the fresher maxStock.\n outcome = {\n status:\n newQty <= existing.quantity\n ? 'refused'\n : newQty < requestedQty\n ? 'clamped'\n : 'added',\n quantity: newQty,\n }\n\n // Refresh maxStock with the incoming value on every successful\n // merge — the stale-maxStock finding: a stored line used to keep\n // its ORIGINAL maxStock forever, so a later updateQuantity call\n // clamped against stock data that could be long out of date.\n return {\n items: state.items.map((i) =>\n isSameItem(i, item.productId, item.variantId)\n ? { ...i, quantity: newQty, maxStock: item.maxStock }\n : i,\n ),\n }\n }\n\n const qty = normalizeQuantity(item.quantity, item.maxStock)\n if (qty < 1) {\n // Invalid quantity, or maxStock 0 (out of stock) — never create\n // a line nobody could actually buy.\n outcome = { status: 'refused', quantity: 0 }\n return {}\n }\n\n outcome = { status: qty < item.quantity ? 'clamped' : 'added', quantity: qty }\n return { items: [...state.items, { ...item, quantity: qty }] }\n })\n\n return outcome\n },\n\n removeItem: (productId, variantId) => {\n set((state) => ({\n items: state.items.filter((i) => !isSameItem(i, productId, variantId)),\n }))\n },\n\n updateQuantity: (productId, variantId, quantity) => {\n const existing = get().items.find((i) => isSameItem(i, productId, variantId))\n if (!existing) return\n\n const newQty = normalizeQuantity(quantity, existing.maxStock)\n if (newQty < 1) {\n get().removeItem(productId, variantId)\n return\n }\n\n set((state) => ({\n items: state.items.map((i) =>\n isSameItem(i, productId, variantId) ? { ...i, quantity: newQty } : i,\n ),\n }))\n },\n\n clearCart: () => set({ items: [] }),\n\n getTotal: () => get().items.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0),\n\n getItemCount: () => get().items.reduce((sum, item) => sum + item.quantity, 0),\n }),\n {\n name: CART_STORAGE_KEY,\n version: CART_STORE_PERSIST_VERSION,\n skipHydration: true,\n },\n ),\n )\n}\n\ntype CartStoreApi = ReturnType<typeof createCartStore>\n\n/**\n * Versioned (REB-837 review fix) with {@link CART_STORE_PERSIST_VERSION} —\n * an incompatible shape change bumps that version, which mints a NEW\n * `Symbol.for(...)` registry key, so a stale old-shape singleton (e.g. kept\n * alive across an HMR reload in dev before a code change takes effect)\n * never satisfies the new one.\n */\nconst CART_STORE_GLOBAL_KEY = Symbol.for(\n `@reblu/site-next/cart-store@v${CART_STORE_PERSIST_VERSION}`,\n)\n\ninterface GlobalWithCartStore {\n [CART_STORE_GLOBAL_KEY]?: CartStoreApi\n}\n\nconst globalForCartStore = globalThis as typeof globalThis & GlobalWithCartStore\n\nexport const useCartStore: CartStoreApi =\n globalForCartStore[CART_STORE_GLOBAL_KEY] ??\n (globalForCartStore[CART_STORE_GLOBAL_KEY] = createCartStore())\n\n/**\n * TEST-ONLY (REB-837 review fix). Clears the `globalThis`-keyed slot so the\n * NEXT access to `useCartStore` — in THIS module instance — creates a fresh\n * store. The singleton is intentionally shared process-wide; most tests\n * should keep resetting STATE via `useCartStore.setState(...)` in\n * `beforeEach`, not the instance itself. Reach for this only to prove\n * something about the singleton mechanism (e.g. the cross-entry test in\n * `tests/cart-store-cross-entry-singleton.test.ts`) — it does not and\n * cannot affect an ALREADY-evaluated copy of this module inlined into a\n * different tsup entry's bundle (each such copy owns its own `const\n * globalForCartStore`/`CART_STORE_GLOBAL_KEY` closed over at that copy's\n * own module-evaluation time, same as any other ES module binding).\n */\nexport function __resetCartStoreForTests(): void {\n delete globalForCartStore[CART_STORE_GLOBAL_KEY]\n}\n","'use client'\n\nimport { useSearchParams } from 'next/navigation'\n\n/**\n * `useCheckoutReturn` (REB-837) — parses the standard return query\n * `createShopCheckoutRoute`'s default `successPath`/`cancelPath` land the\n * visitor on: `?pago=ok&session_id=...` or `?pago=cancelado`. A SITE using a\n * custom `successPath`/`cancelPath` that keeps the SAME `pago`/`session_id`\n * query keys still works with this hook unchanged.\n */\nexport type CheckoutReturnStatus = 'ok' | 'cancelled' | null\n\nexport interface UseCheckoutReturnResult {\n status: CheckoutReturnStatus\n sessionId: string | null\n}\n\nexport function useCheckoutReturn(): UseCheckoutReturnResult {\n const searchParams = useSearchParams()\n const pago = searchParams.get('pago')\n const sessionId = searchParams.get('session_id')\n\n const status: CheckoutReturnStatus =\n pago === 'ok' ? 'ok' : pago === 'cancelado' ? 'cancelled' : null\n\n return { status, sessionId }\n}\n"],"mappings":";;;AAEA,SAAS,aAAa,uBAAuB;;;ACa7C,IAAM,YAAY;AAClB,IAAM,kBAAkB;AACxB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAQ3B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AACtC;AAAA,QACF;AACA,eAAO,OAAO;AAAA,MAChB;AAAA,IACF;AAEA,SAAK,KAAK;AAEV,WAAO,MAAM;AACX,kBAAY;AACZ,mBAAa,WAAW;AACxB,UAAI,UAAW,cAAa,SAAS;AACrC,yBAAmB,MAAM;AAAA,IAC3B;AAAA,EAGF,GAAG,CAAC,WAAW,cAAc,WAAW,YAAY,eAAe,eAAe,gBAAgB,CAAC;AAEnG,SAAO,EAAE,QAAQ,OAAO,QAAQ;AAClC;;;AE3OA,SAAS,mBAAAA,wBAAuB;AAgBzB,SAAS,oBAA6C;AAC3D,QAAM,eAAeA,iBAAgB;AACrC,QAAM,OAAO,aAAa,IAAI,MAAM;AACpC,QAAM,YAAY,aAAa,IAAI,YAAY;AAE/C,QAAM,SACJ,SAAS,OAAO,OAAO,SAAS,cAAc,cAAc;AAE9D,SAAO,EAAE,QAAQ,UAAU;AAC7B;","names":["useSearchParams"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reblu/site-next",
3
- "version": "1.14.0",
3
+ "version": "1.15.1",
4
4
  "description": "Next.js RSC glue for Reblu SITEs — cache + CTA + auth server/client components.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Reblu — Adolfo Unturbe",
@@ -240,9 +240,9 @@
240
240
  "dependencies": {
241
241
  "@radix-ui/react-dialog": "^1.1.15",
242
242
  "zustand": "^5.0.9",
243
- "@reblu/site-client": "^5.2.0",
244
- "@reblu/site-ui": "^0.5.1",
245
- "@reblu/site-contracts": "^1.5.0"
243
+ "@reblu/site-client": "^5.3.0",
244
+ "@reblu/site-contracts": "^1.6.0",
245
+ "@reblu/site-ui": "^0.6.0"
246
246
  },
247
247
  "devDependencies": {
248
248
  "@testing-library/jest-dom": "^6.9.1",