@reblu/site-client 5.14.0 → 5.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @reblu/site-client
2
2
 
3
+ ## 5.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c7f3a43: Course catalogue filters are tenant config (REB-1234).
8
+ - `@reblu/site-contracts`: new `AcademyConfigPublic` and `AcademyCatalogFiltersPublic` types for `GET /api/site/academy/config`.
9
+ - `@reblu/site-client`: new `client.academy.config()`, returning `{ catalogFilters: { category, instructor, price } }` as switched on in nexus. A filter the tenant never set is `true`.
10
+ - `@reblu/site-blocks`: `CourseCatalogFilters` gains a category filter (`categories` + `hrefs.category`, `active.category`) and an `enabled` prop. Pass `catalogFilters` as `enabled` and only the switched-on filters render; with all off it renders nothing. Without `enabled` and `categories` the output is unchanged.
11
+
3
12
  ## 5.14.0
4
13
 
5
14
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -292,6 +292,13 @@ function makeAcademyNamespace(ctx) {
292
292
  instructors: (cache) => requestList(ctx, "/api/site/academy/instructors", {
293
293
  cachePolicy: cache
294
294
  }),
295
+ /**
296
+ * Tenant academy settings for the SITE (REB-1234). `catalogFilters` says
297
+ * which catalogue filters the tenant switched on in nexus — pass it as
298
+ * `enabled` to `CourseCatalogFilters` (`@reblu/site-blocks`). A filter the
299
+ * tenant never set comes back `true`.
300
+ */
301
+ config: (cache) => requestOne(ctx, "/api/site/academy/config", { cachePolicy: cache }),
295
302
  /** Active course categories backing the catalog filter. Not paginated. */
296
303
  categories: (cache) => requestList(ctx, "/api/site/academy/categories", {
297
304
  cachePolicy: cache
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cache.ts","../src/checkout-redirect.ts","../src/build-url.ts","../src/errors.ts","../src/client.ts","../src/domains/academy.ts","../src/domains/analytics.ts","../src/domains/blog.ts","../src/domains/config.ts","../src/domains/contact-form.ts","../src/domains/ctas.ts","../src/domains/data-requests.ts","../src/domains/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.ts","../src/contact-form-metadata.ts","../src/index.ts"],"names":[],"mappings":";;;AA0BO,IAAM,oBAAN,MAAqD;AAAA,EAC1D,WAAA,CAA6B,oBAAoC,KAAA,EAAO;AAA3C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA4C;AAAA,EAA5C,iBAAA;AAAA,EAE7B,mBAAmB,MAAA,EAAuC;AACxD,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,IAAA,CAAK,iBAAA;AAC7C,IAAA,OAAO,UAAA,KAAe,KAAA,IAAS,UAAA,KAAe,CAAA,GAC1C,EAAE,OAAO,UAAA,EAAW,GACpB,EAAE,KAAA,EAAO,aAAA,EAAc;AAAA,EAC7B;AACF;;;ACnBO,IAAM,+BAAA,GAAqD,CAAC,qBAAqB;AAOjF,SAAS,yBAAA,CACd,GAAA,EACA,YAAA,GAAkC,+BAAA,EACzB;AACT,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,IAAI,GAAG,CAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAO,QAAA,KAAa,QAAA,IAAY,YAAA,CAAa,QAAA,CAAS,OAAO,QAAQ,CAAA;AAC9E;AAOO,IAAM,2BAAA,GAAN,cAA0C,KAAA,CAAM;AAAA,EACrD,WAAA,CACkB,KACA,YAAA,EAChB;AACA,IAAA,KAAA;AAAA,MACE,CAAA,2DAAA,EAA8D,KAAK,SAAA,CAAU,GAAG,CAAC,CAAA,iBAAA,EAC5D,YAAA,CAAa,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KAC9C;AANgB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACA,IAAA,IAAA,CAAA,Y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AAG,CAAA;AAAA,IACzC,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,OAAA,EAAS,qBAAqB,GAAG,CAAA;AAAA,IACjC,WAAA,EAAa,yBAAyB,GAAG,CAAA;AAAA,IACzC,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,YAAA,EAAc,0BAA0B,GAAG;AAAA,GAC7C;AACF","file":"index.cjs","sourcesContent":["/**\n * Cache adapter — the seam that severs the SDK from any framework's caching\n * model (design doc D4 / §3.2). The client owns *when* to cache (a per-call\n * `RebluCachePolicy`); the adapter owns *how* (the framework-specific\n * `RequestInit` fields). `@reblu/site-client` ships the framework-agnostic\n * `PlainCacheAdapter`; `@reblu/site-next` (REB-418) supplies a `NextCacheAdapter`\n * that returns `{ next: { revalidate } }`.\n */\n\nexport interface RebluCachePolicy {\n /**\n * Seconds to revalidate. `undefined` → use the adapter's default; `0`/`false`\n * → never cache (always fetch fresh).\n */\n revalidate?: number | false\n}\n\nexport interface RebluCacheAdapter {\n /** Map a per-call cache policy to framework-specific `fetch` `RequestInit` fields. */\n resolveRequestInit(policy: RebluCachePolicy): RequestInit\n}\n\n/**\n * Default adapter — plain `fetch` cache semantics that work in Node, edge,\n * browser and tests. No `next`, no `server-only`.\n */\nexport class PlainCacheAdapter implements RebluCacheAdapter {\n constructor(private readonly defaultRevalidate: number | false = false) {}\n\n resolveRequestInit(policy: RebluCachePolicy): RequestInit {\n const revalidate = policy.revalidate ?? this.defaultRevalidate\n return revalidate === false || revalidate === 0\n ? { cache: 'no-store' }\n : { cache: 'force-cache' }\n }\n}\n","/**\n * Stripe Checkout redirect-origin guard (REB-836, defence in depth).\n *\n * `shop.checkout()` returns a URL every SITE immediately hands to\n * `window.location.assign(url)`. Nothing upstream of this SDK validated it\n * before REB-836 — a compromised/misconfigured base-api, a tampered\n * response, or a MITM proxy could have sent a buyer's browser anywhere.\n * `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses\n * to refuse an unsafe URL before ever returning it to the caller; a SITE's\n * `@reblu/site-next` Route Handler re-checks the SAME property server-side\n * (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an\n * independent copy — see that file's docblock for why it isn't a shared\n * import). Update both together if Stripe ever changes its Checkout host.\n */\n\n/** The only Checkout redirect host trusted by default. */\nexport const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[] = ['checkout.stripe.com']\n\n/**\n * True only when `url` parses as an absolute URL, uses `https:`, and its\n * hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).\n * Never throws — an unparsable `url` is simply unsafe.\n */\nexport function isSafeCheckoutRedirectUrl(\n url: string,\n allowedHosts: readonly string[] = DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n): boolean {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n return false\n }\n return parsed.protocol === 'https:' && allowedHosts.includes(parsed.hostname)\n}\n\n/**\n * Thrown by `shop.checkout()` when base-api's Checkout URL fails\n * {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back\n * to a caller that would otherwise `window.location.assign` it.\n */\nexport class UnsafeCheckoutRedirectError extends Error {\n constructor(\n public readonly url: string,\n public readonly allowedHosts: readonly string[],\n ) {\n super(\n `Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} ` +\n `(allowed hosts: ${allowedHosts.join(', ')})`,\n )\n this.name = 'UnsafeCheckoutRedirectError'\n }\n}\n","/** A value that can be serialized into a query string. */\nexport type QueryValue = string | number | boolean | undefined | null\n\n/**\n * Append a query string to `base`, dropping `undefined`/`null` values.\n *\n * Single definition for the whole client (design doc §3.1 dedupes the two copies\n * that lived in demo-site's `client.ts` and `index.ts`). Falsy-but-meaningful\n * values (`0`, `false`, `''`) are preserved; only `undefined`/`null` are omitted.\n * Array values (REB-475 faceted `attr[key]`) emit one repeated param per element.\n */\nexport function buildUrl(\n base: string,\n params?: Record<string, QueryValue | QueryValue[]>,\n): string {\n if (!params) return base\n const pairs: [string, string][] = []\n for (const [key, value] of Object.entries(params)) {\n const values = Array.isArray(value) ? value : [value]\n for (const v of values) {\n if (v === undefined || v === null) continue\n pairs.push([key, String(v)])\n }\n }\n if (pairs.length === 0) return base\n const qs = new URLSearchParams(pairs).toString()\n return `${base}?${qs}`\n}\n","/**\n * The `details` shape `/api/site/contact-form` and `/api/site/leads` attach on a\n * 400/422, straight from zod's `.flatten()` (see\n * `details: parsed.error.flatten()` in\n * `apps/base-api/src/lib/server/services/contact-form.service.ts:114` and\n * `apiError('Validation error', 422, parsed.error.flatten())` in\n * `apps/base-api/src/app/api/site/leads/route.ts:40`). `fieldErrors` is what a\n * SITE actually needs — REB-659's `details.fieldErrors.phone` — `formErrors` is\n * kept alongside it because `.flatten()` always emits both and dropping it would\n * silently discard form-level (non-field) messages.\n */\nexport interface ApiErrorDetails {\n fieldErrors?: Record<string, string[]>\n formErrors?: string[]\n /**\n * REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /\n * `PRICE_CHANGED` error — see `ApiErrorBody.code`.\n */\n productIds?: string[]\n /** REB-842: optional request-field identifier for checkout validation errors. */\n field?: string\n}\n\n/**\n * The parsed shape of a non-2xx SITE API response body: `{ error, details? }`\n * (see `apiError()` in `apps/base-api/src/lib/api/response.ts:33` — the general\n * shape both routes above build on).\n */\nexport interface ApiErrorBody {\n error: string\n details?: ApiErrorDetails\n /**\n * REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from\n * `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write\n * endpoints may set — additive and OPTIONAL, so a consumer that only reads\n * `error`/`message` keeps working unchanged. `string` rather than\n * `ShopErrorCode` here because `ApiError` is a generic transport error used\n * by every `/api/site/*` domain, not just shop.\n */\n code?: string\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string')\n}\n\n/**\n * Validates `ApiErrorDetails` deeply — `fieldErrors` must be a record whose\n * values are `string[] | undefined`, `formErrors` (if present) must be\n * `string[]`, and `field` (if present) must be a string. Without this, a body like\n * `{ fieldErrors: { phone: \"abc\" } }` passed the old shallow check, so\n * `body.details?.fieldErrors?.phone?.[0]` silently returned the character\n * `\"a\"` instead of a validation message (REB-764 review finding).\n */\nfunction isApiErrorDetails(value: unknown): value is ApiErrorDetails {\n if (typeof value !== 'object' || value === null) return false\n const details = value as {\n fieldErrors?: unknown\n formErrors?: unknown\n productIds?: unknown\n field?: unknown\n }\n\n if (details.fieldErrors !== undefined) {\n if (\n typeof details.fieldErrors !== 'object' ||\n details.fieldErrors === null ||\n Array.isArray(details.fieldErrors)\n ) {\n return false\n }\n for (const fieldValue of Object.values(details.fieldErrors as Record<string, unknown>)) {\n if (fieldValue !== undefined && !isStringArray(fieldValue)) return false\n }\n }\n\n if (details.formErrors !== undefined && !isStringArray(details.formErrors)) return false\n\n // REB-836: STOCK_CHANGED/PRICE_CHANGED carry the affected product ids here.\n if (details.productIds !== undefined && !isStringArray(details.productIds)) return false\n if ('field' in details && typeof details.field !== 'string') return false\n\n return true\n}\n\n/**\n * `details`, when present, must match `ApiErrorDetails` deeply — an\n * unrecognised `details` shape makes the whole body unrecognised (`body`\n * stays `undefined`), the stricter reading consistent with\n * `parseApiErrorBody`'s existing all-or-nothing semantics: a body is either\n * shaped like `ApiErrorBody` or it isn't. Silently dropping a malformed\n * `details` instead would let a consumer treat a schema-drifted or corrupted\n * response as merely detail-less, hiding the mismatch rather than surfacing\n * it as \"unparseable\" (REB-764 review finding).\n */\nfunction isApiErrorBody(value: unknown): value is ApiErrorBody {\n if (typeof value !== 'object' || value === null) return false\n const body = value as { error?: unknown; details?: unknown; code?: unknown }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) return false\n // REB-836: `code` must be a string when present — same all-or-nothing\n // reading as `details` above (an unrecognised shape makes the whole body\n // unrecognised, never silently dropped).\n if (body.code !== undefined && typeof body.code !== 'string') return false\n return true\n}\n\n/**\n * Parses `rawBody` (the exact text `message` is built from) into a typed\n * `ApiErrorBody`, or `undefined` when it is not JSON, or JSON that does not\n * match the expected shape — an edge proxy 502 returns HTML, and this must\n * never throw while constructing the error it is reporting.\n */\nfunction parseApiErrorBody(rawBody: string): ApiErrorBody | undefined {\n if (!rawBody) return undefined\n try {\n const parsed: unknown = JSON.parse(rawBody)\n return isApiErrorBody(parsed) ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Typed transport error for the Reblu SITE API.\n *\n * Every non-2xx response throws an `ApiError` (never a bare `fetch` rejection),\n * so consumers can `catch (e) { if (e instanceof ApiError) … }` and fall back\n * gracefully (e.g. render an empty section) — the one behavioural contract the\n * SITE relies on. Moved verbatim from demo-site's `client.ts` (design doc §3.4).\n */\nexport class ApiError extends Error {\n /**\n * The parsed response body, when it was JSON shaped like `{ error, details? }`\n * (REB-764). `undefined` when the body was not JSON or didn't match — parsing\n * is defensive and never throws. Read `body.details?.fieldErrors?.phone`\n * instead of regex-stripping this error's `message`.\n */\n public readonly body: ApiErrorBody | undefined\n\n constructor(\n public readonly status: number,\n public readonly path: string,\n message: string,\n ) {\n super(`API ${status} @ ${path}: ${message}`)\n this.name = 'ApiError'\n this.body = parseApiErrorBody(message)\n }\n}\n\n/** One page a slug could mean (REB-867) — `null` = the uncategorised page. */\nexport interface PageSlugCandidate {\n categorySlug: string | null\n}\n\nfunction parseCandidates(rawBody: string): PageSlugCandidate[] {\n try {\n const parsed = JSON.parse(rawBody) as { candidates?: unknown }\n if (!Array.isArray(parsed.candidates)) return []\n return parsed.candidates.flatMap((c: unknown) => {\n const slug = (c as { categorySlug?: unknown } | null)?.categorySlug\n return typeof slug === 'string' || slug === null ? [{ categorySlug: slug }] : []\n })\n } catch {\n return []\n }\n}\n\n/**\n * REB-867 — `GET /api/site/pages/[slug]` answered 409 `ambiguous_slug`: page\n * slugs are unique PER CATEGORY and this one exists in more than one, so the\n * server refused to pick. Retry with `pages.bySlug(slug, { category })` using\n * one of `candidates`. Extends `ApiError`, so an existing\n * `catch (e) { if (e instanceof ApiError) … }` keeps handling it.\n */\nexport class AmbiguousPageSlugError extends ApiError {\n public readonly candidates: PageSlugCandidate[]\n\n constructor(source: ApiError, rawBody: string) {\n super(source.status, source.path, rawBody)\n this.name = 'AmbiguousPageSlugError'\n this.candidates = parseCandidates(rawBody)\n }\n}\n\n/** The raw body an `ApiError` was built from (its message minus the prefix). */\nexport function apiErrorRawBody(error: ApiError): string {\n const prefix = `API ${error.status} @ ${error.path}: `\n return error.message.startsWith(prefix) ? error.message.slice(prefix.length) : error.message\n}\n","import type { PaginationMeta } from '@reblu/site-contracts'\nimport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nimport { ApiError } from './errors'\nimport type { ListResult } from './types'\n\n/**\n * Resolved, immutable client context threaded into every domain namespace. Built\n * once by `createRebluClient` from the consumer's config — the SDK never reads\n * `process.env`, so the consumer owns `baseUrl`/`apiKey` (design doc §3.3).\n */\nexport interface RebluClientContext {\n baseUrl: string\n apiKey: string\n apiVersion: string\n cache: RebluCacheAdapter\n timeoutMs: number\n fetch: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth). Defaults to\n * `DEFAULT_CHECKOUT_REDIRECT_HOSTS` (`['checkout.stripe.com']`) — tests\n * inject a different value via `RebluClientConfig.checkoutRedirectHosts`.\n */\n checkoutRedirectHosts: readonly string[]\n /**\n * REB-1214 — returns the memo store of the CURRENT server request, so\n * identical GET reads within it are fetched once (e.g. `generateMetadata`\n * and the page body). `@reblu/site-next` supplies one backed by React\n * `cache()` (`rebluRequestScope`). Absent, or returning `undefined`,\n * identical GETs still share one fetch while they are in flight.\n */\n requestScope?: RequestScope\n /** In-flight GETs when no request scope is active. Created by `createRebluClient`. */\n inFlight?: Map<string, Promise<unknown>>\n}\n\n/** Memo store of one server request, keyed by read identity (REB-1214). */\nexport type RequestScope = () => Map<string, Promise<unknown>> | undefined\n\n/** Upper bound for a `Retry-After` wait before the single retry (REB-1214). */\nexport const RETRY_AFTER_CAP_MS = 2000\n/** Wait before the single retry when `Retry-After` is absent or unparseable. */\nexport const DEFAULT_RETRY_DELAY_MS = 250\n/** Statuses that mean \"try again shortly\" for a read. */\nconst RETRYABLE_READ_STATUSES = new Set([429, 503])\n\n/** `Retry-After` (seconds or HTTP date) → ms, capped; default when unusable. */\nfunction retryDelayMs(header: string | null): number {\n if (header !== null && header.trim() !== '') {\n const value = header.trim()\n const seconds = /^\\d+$/.test(value) ? Number(value) * 1000 : NaN\n const ms = Number.isFinite(seconds) ? seconds : Date.parse(value) - Date.now()\n if (Number.isFinite(ms)) return Math.min(Math.max(0, ms), RETRY_AFTER_CAP_MS)\n }\n return DEFAULT_RETRY_DELAY_MS\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/** Per-call request options. `cachePolicy` is interpreted by the cache adapter. */\nexport interface RequestOptions {\n method?: string\n body?: string\n headers?: Record<string, string>\n cachePolicy?: RebluCachePolicy\n}\n\n/**\n * Core transport (design doc §3.4). Injects the auth + contract-version headers,\n * merges the adapter's cache `RequestInit`, enforces a hard timeout per attempt,\n * throws a typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n *\n * REB-1214 — GET reads only: identical reads are deduped (see\n * `RebluClientContext.requestScope`) and a 429/503 is retried once after\n * `Retry-After`, capped at {@link RETRY_AFTER_CAP_MS}. If the retry fails too,\n * the second response's `ApiError` is thrown — the same type as before.\n * Writes are never deduped nor retried.\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const method = opts.method ?? 'GET'\n const init: RequestInit = {\n method,\n body: opts.body,\n headers: {\n 'X-Reblu-Api-Key': ctx.apiKey,\n 'X-Reblu-Api-Version': ctx.apiVersion,\n 'Content-Type': 'application/json',\n ...opts.headers,\n },\n ...ctx.cache.resolveRequestInit(opts.cachePolicy ?? {}),\n }\n if (method !== 'GET' || opts.body !== undefined) {\n return attempt<T>(ctx, path, init)\n }\n\n // REB-1214 — a read is identified by everything that shapes its response:\n // URL, headers and the resolved cache init. Kept for the whole request when\n // a scope is active; otherwise only while in flight.\n const key = JSON.stringify([ctx.baseUrl + path, init])\n const scope = ctx.requestScope?.()\n const store = scope ?? ctx.inFlight\n const existing = store?.get(key)\n if (existing) return existing as Promise<T>\n\n const pending = readWithRetry<T>(ctx, path, init)\n if (store) {\n store.set(key, pending)\n // A failure is never memoised; without a scope nothing outlives the fetch.\n pending.then(\n () => {\n if (!scope) store.delete(key)\n },\n () => {\n if (store.get(key) === pending) store.delete(key)\n },\n )\n }\n return pending\n}\n\n/** A GET answered 429/503 is retried once after `Retry-After` (capped). */\nasync function readWithRetry<T>(\n ctx: RebluClientContext,\n path: string,\n init: RequestInit,\n): Promise<T> {\n try {\n return await attempt<T>(ctx, path, init)\n } catch (error) {\n if (!(error instanceof RetryableReadError)) throw error\n await sleep(retryDelayMs(error.retryAfter))\n try {\n return await attempt<T>(ctx, path, init)\n } catch (retryError) {\n throw retryError instanceof RetryableReadError ? retryError.apiError : retryError\n }\n }\n}\n\n/** Internal carrier: a retryable read status plus the `ApiError` to throw if it persists. */\nclass RetryableReadError extends Error {\n constructor(\n readonly apiError: ApiError,\n readonly retryAfter: string | null,\n ) {\n super(apiError.message)\n }\n}\n\n/**\n * One HTTP attempt: enforces the hard timeout via `AbortController`, throws a\n * typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n */\nasync function attempt<T>(ctx: RebluClientContext, path: string, init: RequestInit): Promise<T> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(ctx.baseUrl + path, { ...init, signal: controller.signal })\n\n if (!res.ok) {\n const error = new ApiError(res.status, path, await res.text())\n if (init.method === 'GET' && RETRYABLE_READ_STATUSES.has(res.status)) {\n throw new RetryableReadError(error, res.headers.get('retry-after'))\n }\n throw error\n }\n return (await res.json()) as T\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch a single resource and unwrap the `{ data: T }` envelope. */\nexport async function requestOne<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const body = await request<{ data: T }>(ctx, path, opts)\n return body.data\n}\n\n/** Fetch a list resource, returning the `{ data, meta }` envelope (meta preserved). */\nexport async function requestList<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<ListResult<T>> {\n const body = await request<{ data: T[]; meta?: PaginationMeta }>(ctx, path, opts)\n return { data: body.data, meta: body.meta }\n}\n\n/**\n * Header carrying the visitor IP from a SITE server to base-api (REB-1005).\n * base-api keys its per-visitor limit on public writes on it, and trusts it\n * only behind a valid API key.\n */\nexport const VISITOR_IP_HEADER = 'x-reblu-visitor-ip'\n\n/**\n * Per-call options for a write (REB-1005).\n *\n * - `visitorIp` — the visitor's IP when a SITE calls the SDK server-side, sent\n * as `x-reblu-visitor-ip`. Do NOT rely on forwarding `x-forwarded-for`: on\n * Vercel the SITE→base-api hop gets it overwritten with the SITE function's\n * egress IP. Read it from the INCOMING request with\n * {@link visitorIpFromHeaders}.\n * - `headers` — other extra headers (e.g. `user-agent`). They can never set\n * `x-reblu-visitor-ip` nor replace `X-Reblu-Api-Key`, `X-Reblu-Api-Version`\n * or `Content-Type`.\n */\nexport interface RebluMutationOptions {\n visitorIp?: string\n headers?: Record<string, string>\n}\n\n/** The visitor IP of an incoming request: first `x-forwarded-for` entry, else `x-real-ip`. */\nexport function visitorIpFromHeaders(headers: {\n get(name: string): string | null\n}): string | undefined {\n return (\n headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||\n headers.get('x-real-ip')?.trim() ||\n undefined\n )\n}\n\n/** Headers the SDK owns on every request — an extra header never sets or overrides these. */\nconst RESERVED_HEADERS = new Set([\n 'x-reblu-api-key',\n 'x-reblu-api-version',\n 'content-type',\n VISITOR_IP_HEADER,\n])\n\n/**\n * The extra headers a write sends for `options`: caller headers minus the\n * reserved ones, plus `x-reblu-visitor-ip` from `visitorIp`. Shared by\n * {@link requestMutation} and the writes that cannot use it (academy).\n */\nexport function extraHeaders(\n options: RebluMutationOptions | undefined,\n): Record<string, string> | undefined {\n if (!options?.headers && !options?.visitorIp) return undefined\n const safe: Record<string, string> = {}\n for (const [name, value] of Object.entries(options.headers ?? {})) {\n if (!RESERVED_HEADERS.has(name.toLowerCase())) safe[name] = value\n }\n const visitorIp = options.visitorIp?.trim()\n if (visitorIp) safe[VISITOR_IP_HEADER] = visitorIp\n return safe\n}\n\n/**\n * POST a mutation: serialize `body` to JSON, force a cache bypass (`revalidate:\n * false` → `no-store` regardless of the injected adapter, since a mutation must\n * never be served from cache), then unwrap the `{ data: T }` envelope. Mirrors\n * every `/api/site/*` write route, which answers with `apiOk`/`{ data }`.\n */\nexport async function requestMutation<Req, Res>(\n ctx: RebluClientContext,\n path: string,\n body: Req,\n options?: RebluMutationOptions,\n): Promise<Res> {\n const headers = extraHeaders(options)\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n AcademyInstructorPublic,\n AcademyLessonPreview,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n extraHeaders,\n request,\n requestList,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport type {\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n ListResult,\n} from '../types'\n\n/**\n * Academy domain — the public course catalogue (`GET /api/site/academy/*`,\n * REB-528 / REB-534) plus the anonymous enrollment request (REB-496). The reads\n * are published-filtered server-side, so nothing here needs an entitlement\n * notion; the one write is unauthenticated by design.\n *\n * `enrollmentRequest` drops to the raw `request()` transport rather than\n * `requestMutation` (REB-584). The route answers with a BARE `{ message }`, not\n * the `{ data }` envelope every other write uses, so `requestMutation` would\n * unwrap a missing `.data` and hand the caller `undefined`. Normalizing the\n * route's envelope instead was rejected: its response shape is load-bearing\n * anti-enumeration behaviour, and changing it would ripple into base-api tests\n * for no gain on the SITE side.\n */\nexport function makeAcademyNamespace(ctx: RebluClientContext) {\n return {\n /** Published courses, filtered + paginated. `meta` carries the pagination. */\n courses: (\n params?: AcademyCourseListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<AcademyCourseSummary>> =>\n requestList<AcademyCourseSummary>(\n ctx,\n buildUrl('/api/site/academy/courses', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n /** A single published course by slug, with its modules, lessons and CTA gate. */\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<AcademyCourseDetail> =>\n requestOne<AcademyCourseDetail>(ctx, `/api/site/academy/courses/${slug}`, {\n cachePolicy: cache,\n }),\n\n /**\n * A free-preview lesson, viewable by the public (REB-1135): title, duration,\n * Markdown body and a ready-to-embed video. Any lesson the public may not see\n * is a uniform 404 (`ApiError`). Never cached: the payload carries a\n * short-lived signed playback token. Server-side, prefer `getLessonPreview`\n * from `@reblu/site-next/academy-server`, which maps that 404 to `null`.\n */\n lessonPreview: (courseSlug: string, lessonSlug: string): Promise<AcademyLessonPreview> =>\n requestOne<AcademyLessonPreview>(\n ctx,\n `/api/site/academy/courses/${encodeURIComponent(courseSlug)}/lessons/${encodeURIComponent(lessonSlug)}`,\n { cachePolicy: { revalidate: false } },\n ),\n\n /**\n * Instructors of published courses, sorted by name, backing the catalog\n * instructor filter (REB-547). Pass an `id` as `courses({ instructor })`.\n * Not paginated.\n */\n instructors: (cache?: RebluCachePolicy): Promise<ListResult<AcademyInstructorPublic>> =>\n requestList<AcademyInstructorPublic>(ctx, '/api/site/academy/instructors', {\n cachePolicy: cache,\n }),\n\n /** Active course categories backing the catalog filter. Not paginated. */\n categories: (cache?: RebluCachePolicy): Promise<ListResult<AcademyCategoryPublic>> =>\n requestList<AcademyCategoryPublic>(ctx, '/api/site/academy/categories', {\n cachePolicy: cache,\n }),\n\n /**\n * Submit an anonymous enrollment request for a course.\n *\n * The reply is UNIFORM by design: the caller cannot tell whether the email\n * was new (a request row was created) or already known (a sign-in link was\n * sent and NO request row exists). Never present the returned message as\n * confirmation that a request was recorded — it is not one.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n options?: RebluMutationOptions,\n ): Promise<AcademyEnrollmentRequestResult> => {\n const headers = extraHeaders(options)\n return request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n },\n }\n}\n","import type { Analytics } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/analytics` — the tenant's analytics provider configuration. */\nexport function makeAnalyticsNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Analytics> =>\n requestOne<Analytics>(ctx, '/api/site/analytics', { cachePolicy: cache }),\n }\n}\n","import type {\n BlogCategoryWithCount,\n BlogPostDetail,\n BlogPostListItem,\n BlogPostPreview,\n BlogSlug,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport type { BlogListParams, ListResult } from '../types'\n\n/** Blog domain — `GET /api/site/blog/*`. */\nexport function makeBlogNamespace(ctx: RebluClientContext) {\n return {\n list: (\n params?: BlogListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(\n ctx,\n buildUrl('/api/site/blog', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<BlogPostDetail> =>\n requestOne<BlogPostDetail>(ctx, `/api/site/blog/${slug}`, { cachePolicy: cache }),\n\n related: (slug: string, cache?: RebluCachePolicy): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(ctx, `/api/site/blog/${slug}/related`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<BlogCategoryWithCount>> =>\n requestList<BlogCategoryWithCount>(ctx, '/api/site/blog/categories', { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<BlogSlug>> =>\n requestList<BlogSlug>(ctx, '/api/site/blog/slugs', { cachePolicy: cache }),\n\n /** Draft preview — never cached (unpublished content). */\n preview: (id: string): Promise<BlogPostPreview> =>\n requestOne<BlogPostPreview>(ctx, `/api/site/blog/preview/${id}`, {\n cachePolicy: { revalidate: false },\n }),\n }\n}\n","import type { Config } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/config` — the tenant's public site configuration. */\nexport function makeConfigNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Config> =>\n requestOne<Config>(ctx, '/api/site/config', { cachePolicy: cache }),\n }\n}\n","import type { ContactFormInput, ContactFormSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * Contact form domain — WRITE only (`POST /api/site/contact-form`, REB-438).\n * Posts a body typed by `@reblu/site-contracts` and bypasses the cache; returns\n * the created lead's id + creation timestamp.\n */\nexport function makeContactFormNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a contact form. Returns the created lead acknowledgement.\n * Server-side (a Server Action / Route Handler), pass `options.visitorIp`\n * (from the incoming request, see `visitorIpFromHeaders`) so base-api's\n * per-IP limit (REB-1005) applies to the real visitor.\n */\n submit: (\n body: ContactFormInput,\n options?: RebluMutationOptions,\n ): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(\n ctx,\n '/api/site/contact-form',\n body,\n options,\n ),\n }\n}\n","import type { Cta } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/**\n * `GET /api/site/ctas?slot=…` — editable CTAs for a given slot.\n *\n * `slot` is typed as `string` on purpose: the slot enum lives in base-api's\n * `validations/` (not the response contracts), so `@reblu/site-contracts` does\n * not export it. Keeping it a `string` avoids duplicating (and drifting from)\n * the server-owned enum. The server validates the slot.\n */\nexport function makeCtasNamespace(ctx: RebluClientContext) {\n return {\n list: (slot: string, cache?: RebluCachePolicy): Promise<ListResult<Cta>> =>\n requestList<Cta>(ctx, buildUrl('/api/site/ctas', { slot }), { cachePolicy: cache }),\n }\n}\n","import type { DataRequestInput, DataRequestSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * GDPR data-subject requests domain — WRITE only (`POST /api/site/data-requests`,\n * REB-77 endpoint / REB-980 SDK). Posts the public rights-form body typed by\n * `@reblu/site-contracts`, bypasses the cache, and returns the request id, when\n * it was received and the 72h deadline (`slaDueAt`) it is now held to.\n *\n * base-api requires a reCAPTCHA v3 token (`captcha`) and rate-limits per tenant\n * and per visitor IP (REB-1005); a rejection surfaces as an `ApiError` carrying\n * the upstream `status` (400 validation, 422 captcha, 429 rate limit).\n */\nexport function makeDataRequestsNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a data-subject request. Returns its acknowledgement with the 72h\n * deadline. Server-side, pass `options.visitorIp` (from the incoming\n * request, see `visitorIpFromHeaders`) so base-api's per-IP limit\n * (REB-1005) sees the real visitor.\n */\n submit: (\n body: DataRequestInput,\n options?: RebluMutationOptions,\n ): Promise<DataRequestSubmission> =>\n requestMutation<DataRequestInput, DataRequestSubmission>(\n ctx,\n '/api/site/data-requests',\n body,\n options,\n ),\n }\n}\n","import type { LeadInput, LeadSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext } from '../client'\n\n/**\n * Leads domain — WRITE only (`POST /api/site/leads`, REB-438). The generic\n * lead-ingestion endpoint: posts a body typed by `@reblu/site-contracts`,\n * bypasses the cache, and returns the created lead's id + creation timestamp.\n */\nexport function makeLeadsNamespace(ctx: RebluClientContext) {\n return {\n /** Create a lead. Returns the created lead acknowledgement. */\n create: (body: LeadInput): Promise<LeadSubmission> =>\n requestMutation<LeadInput, LeadSubmission>(ctx, '/api/site/leads', body),\n }\n}\n","import type { Legal } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/legal` — the tenant's legal content (privacy, terms, cookies). */\nexport function makeLegalNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Legal> =>\n requestOne<Legal>(ctx, '/api/site/legal', { cachePolicy: cache }),\n }\n}\n","import type { PageDetail, PageListItem, PageSlug } from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport { AmbiguousPageSlugError, ApiError, apiErrorRawBody } from '../errors'\nimport type { ListResult, PagesListParams } from '../types'\n\n/**\n * REB-867 — options for `pages.bySlug`. Page slugs are unique PER CATEGORY:\n * - `category: '<categorySlug>'` → the page with that slug in that category;\n * - `category: null` → the UNCATEGORISED page with that slug;\n * - omitted → the unique page with that slug; throws\n * `AmbiguousPageSlugError` when it exists in more than one category.\n */\nexport interface PageBySlugOptions {\n category?: string | null\n cache?: RebluCachePolicy\n}\n\n/**\n * The two second-argument shapes share no key: a `RebluCachePolicy` only ever\n * has `revalidate`, `PageBySlugOptions` only `category`/`cache`. So the\n * presence of `category` or `cache` (even `category: undefined`) selects the\n * options form; anything else — including `{}` — is a cache policy, exactly as\n * before REB-867.\n */\n/** REB-869 — options for `pages.featured`. */\nexport interface FeaturedPagesOptions {\n /**\n * How many pages at most: an integer >= 1. Default 3. Values above the\n * server's cap (3) are clamped to 3; anything else invalid (0, negative,\n * fractional, NaN) throws a `RangeError` before any request is made.\n */\n limit?: number\n /**\n * When the category has nothing featured, return its first `limit` pages in\n * normal order instead of `[]`. Default `true`, so a teaser is never empty\n * just because nobody picked pages yet.\n */\n fallback?: boolean\n cache?: RebluCachePolicy\n}\n\n/** The server caps a featured list at 3 (REB-869). */\nconst FEATURED_PAGES_MAX = 3\n\nfunction isBySlugOptions(value: RebluCachePolicy | PageBySlugOptions): value is PageBySlugOptions {\n return 'category' in value || 'cache' in value\n}\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n const namespace = {\n list: (\n params?: PagesListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<PageListItem>> =>\n requestList<PageListItem>(\n ctx,\n // REB-63: `type` can now be a single PageType or an array (repeated\n // `?type=` params) — widen the cast alongside `PagesListParams`.\n buildUrl('/api/site/pages', params as Record<string, QueryValue | QueryValue[]> | undefined),\n { cachePolicy: cache },\n ),\n\n /**\n * A published page by slug. The second argument is either a cache policy\n * (backward-compatible) or {@link PageBySlugOptions} (REB-867).\n */\n bySlug: async (\n slug: string,\n cacheOrOptions?: RebluCachePolicy | PageBySlugOptions,\n ): Promise<PageDetail> => {\n const options: PageBySlugOptions =\n cacheOrOptions && isBySlugOptions(cacheOrOptions)\n ? cacheOrOptions\n : { cache: cacheOrOptions }\n const path =\n options.category === undefined\n ? `/api/site/pages/${slug}`\n : buildUrl(`/api/site/pages/${slug}`, { category: options.category ?? '' })\n try {\n return await requestOne<PageDetail>(ctx, path, { cachePolicy: options.cache })\n } catch (error) {\n if (error instanceof ApiError && error.status === 409 && error.body?.code === 'ambiguous_slug') {\n throw new AmbiguousPageSlugError(error, apiErrorRawBody(error))\n }\n throw error\n }\n },\n\n /**\n * REB-869 — the pages to show in a category teaser: the category's\n * featured pages in the tenant's order; when none are featured (and\n * `fallback` is not `false`), the first `limit` pages of the category in\n * normal order. Returns the items only (no pagination applies).\n */\n featured: async (\n category: string,\n { limit: requested = FEATURED_PAGES_MAX, fallback = true, cache }: FeaturedPagesOptions = {},\n ): Promise<PageListItem[]> => {\n if (!Number.isInteger(requested) || requested < 1) {\n throw new RangeError(`pages.featured: limit must be an integer >= 1 (got ${requested})`)\n }\n const limit = Math.min(requested, FEATURED_PAGES_MAX)\n const featured = await namespace.list({ category, featured: true }, cache)\n if (featured.data.length > 0 || !fallback) return featured.data.slice(0, limit)\n const first = await namespace.list({ category, pageSize: limit }, cache)\n return first.data.slice(0, limit)\n },\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\n return namespace\n}\n","import type {\n ShopApplyDiscountInput,\n ShopCartValidation,\n ShopCategory,\n ShopCheckEmailInput,\n ShopCheckoutInput,\n ShopCheckoutSession,\n ShopConfig,\n ShopDiscountApplication,\n ShopEmailCheck,\n ShopFacets,\n ShopOrder,\n ShopProductDetail,\n ShopProductListItem,\n ShopValidateCartInput,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n requestList,\n requestMutation,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport { isSafeCheckoutRedirectUrl, UnsafeCheckoutRedirectError } from '../checkout-redirect'\nimport type { ListResult, ShopProductsParams } from '../types'\n\n/**\n * Flatten `ShopProductsParams` into a query record: scalars pass through; the\n * `taxonomy`/`attr` maps become repeatable `taxonomy[key]`/`attr[key]` params.\n * Array attr values repeat the same bracket key.\n */\nfunction flattenShopParams(params?: ShopProductsParams): Record<string, QueryValue | QueryValue[]> {\n if (!params) return {}\n const { taxonomy, attr, ...scalars } = params\n const out: Record<string, QueryValue | QueryValue[]> = { ...scalars }\n if (taxonomy) {\n for (const [key, value] of Object.entries(taxonomy)) out[`taxonomy[${key}]`] = value\n }\n if (attr) {\n for (const [key, value] of Object.entries(attr)) out[`attr[${key}]`] = value\n }\n return out\n}\n\n/**\n * Shop domain — READ surface (`GET /api/site/shop/*`) plus the mutation flow\n * (`POST` checkout, validate-cart, apply-discount, and the deprecated\n * check-email) added in REB-438. Every write posts a body typed by `@reblu/site-contracts` and bypasses\n * the cache. Request/response DTOs live in the contracts package (zero Zod).\n */\nexport function makeShopNamespace(ctx: RebluClientContext) {\n return {\n products: (\n params?: ShopProductsParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<ShopProductListItem>> =>\n requestList<ShopProductListItem>(\n ctx,\n buildUrl('/api/site/shop/products', flattenShopParams(params)),\n { cachePolicy: cache },\n ),\n\n /** Available facets (brand/attributes/price/on-sale) for the given filters. */\n facets: (params?: ShopProductsParams, cache?: RebluCachePolicy): Promise<ShopFacets> =>\n requestOne<ShopFacets>(ctx, buildUrl('/api/site/shop/facets', flattenShopParams(params)), {\n cachePolicy: cache,\n }),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<ShopProductDetail> =>\n requestOne<ShopProductDetail>(ctx, `/api/site/shop/products/${slug}`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<ShopCategory>> =>\n requestList<ShopCategory>(ctx, '/api/site/shop/categories', { cachePolicy: cache }),\n\n config: (cache?: RebluCachePolicy): Promise<ShopConfig> =>\n requestOne<ShopConfig>(ctx, '/api/site/shop/config', { cachePolicy: cache }),\n\n // ── Mutations (REB-438) ──────────────────────────────────────────────────\n\n /**\n * Start a hosted checkout session. Returns the Stripe URL + session id.\n *\n * REB-836 (defence in depth): every SITE hands `url` straight to\n * `window.location.assign`, so this validates it is `https:` on an\n * allowed host (`ctx.checkoutRedirectHosts`, default\n * `checkout.stripe.com`) BEFORE returning — throwing\n * {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL\n * that could redirect a buyer's browser off Stripe's domain.\n */\n checkout: async (body: ShopCheckoutInput): Promise<ShopCheckoutSession> => {\n const session = await requestMutation<ShopCheckoutInput, ShopCheckoutSession>(\n ctx,\n '/api/site/shop/checkout',\n body,\n )\n if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {\n throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts)\n }\n return session\n },\n\n /** Validate a cart against live product/stock/price state before checkout. */\n validateCart: (body: ShopValidateCartInput): Promise<ShopCartValidation> =>\n requestMutation<ShopValidateCartInput, ShopCartValidation>(\n ctx,\n '/api/site/shop/validate-cart',\n body,\n ),\n\n /** Validate a discount code against the current cart subtotal. */\n applyDiscount: (body: ShopApplyDiscountInput): Promise<ShopDiscountApplication> =>\n requestMutation<ShopApplyDiscountInput, ShopDiscountApplication>(\n ctx,\n '/api/site/shop/apply-discount',\n body,\n ),\n\n /**\n * @deprecated REB-834 — the endpoint no longer reveals whether an account\n * exists: it always resolves `{ exists: false }`. Do not call it and never\n * branch UI on `exists`; the checkout always offers «Iniciar sesión o\n * continuar como invitado» and the server links the order to an existing\n * account after payment. Removed in the next major.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n checkEmail: (\n body: ShopCheckEmailInput,\n options?: RebluMutationOptions,\n ): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(\n ctx,\n '/api/site/shop/check-email',\n body,\n options,\n ),\n\n /**\n * Look up a confirmed (or still-pending) order by its Stripe Checkout\n * session id — the order-confirmation flow (REB-829). `GET`, so it goes\n * through `requestOne` like every other read, not `requestMutation`.\n */\n order: (sessionId: string, cache?: RebluCachePolicy): Promise<ShopOrder> =>\n requestOne<ShopOrder>(ctx, `/api/site/shop/order/${encodeURIComponent(sessionId)}`, {\n cachePolicy: cache,\n }),\n }\n}\n","import type { TrustBadge, TrustBadgeType } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** Filters for {@link makeTrustBadgesNamespace}'s `list` (REB-996). */\nexport interface TrustBadgeListParams {\n /** Only badges of this type (e.g. `'SUBVENTION'`). Omit for every type. */\n type?: TrustBadgeType\n}\n\nfunction isCachePolicy(value: TrustBadgeListParams | RebluCachePolicy): value is RebluCachePolicy {\n return Object.prototype.hasOwnProperty.call(value, 'revalidate')\n}\n\n/**\n * `GET /api/site/trust-badges` — the tenant's PUBLIC trust badges (no\n * pagination): active in nexus and inside their optional validity window, so\n * expiring or switching one off needs no SITE change.\n */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n function list(cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>>\n function list(\n params: TrustBadgeListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>>\n function list(\n paramsOrCache?: TrustBadgeListParams | RebluCachePolicy,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>> {\n // `list(cache)` is the pre-REB-996 call shape — kept so this stays a minor.\n const legacyCache = paramsOrCache && isCachePolicy(paramsOrCache) ? paramsOrCache : undefined\n const params = legacyCache ? undefined : (paramsOrCache as TrustBadgeListParams | undefined)\n return requestList<TrustBadge>(\n ctx,\n buildUrl('/api/site/trust-badges', { type: params?.type }),\n { cachePolicy: legacyCache ?? cache },\n )\n }\n return { list }\n}\n","import type { ContactFormInput } from '@reblu/site-contracts'\n\n/**\n * REB-1077 — the `metadata` block of a contact-form submission, built from the\n * page the visitor is on so a SITE never hand-codes `fromPage`.\n *\n * Call it in the browser, at submit time (inside the form's submit handler):\n * it reads `globalThis.location` unless a `location` is passed.\n */\n\n/** The part of `window.location` these helpers read. */\nexport interface PageLocation {\n pathname: string\n href?: string\n}\n\nexport type ContactFormMetadata = ContactFormInput['metadata']\n\nexport interface ContactFormMetadataOptions {\n /**\n * Explicit page path, overriding the one read from the location (e.g. a\n * modal form that wants to report the landing it belongs to).\n */\n fromPage?: string\n /** @default { platform: 'organic' } */\n leadSource?: ContactFormMetadata['leadSource']\n /** @default globalThis.location */\n location?: PageLocation | null\n /** Submission time. @default new Date() */\n now?: Date\n}\n\nfunction browserLocation(): PageLocation | null {\n const location = (globalThis as { location?: PageLocation }).location\n return location && typeof location.pathname === 'string' ? location : null\n}\n\n/**\n * Path of the page the visitor is on — `location.pathname`, never with a query\n * string or hash. `'/'` when there is no location (server render).\n */\nexport function currentPagePath(location: PageLocation | null = browserLocation()): string {\n const path = location?.pathname.split(/[?#]/, 1)[0] ?? ''\n return path.startsWith('/') ? path : '/'\n}\n\n/**\n * The `metadata` for `contactForm.submit()` / `POST /api/site/contact-form`:\n * `fromPage` is the current page path, `currentUrl` the full href (base-api\n * reads the UTMs from it), `timestamp` the submission time.\n *\n * ```ts\n * body: JSON.stringify({ ...fields, captcha, metadata: buildContactFormMetadata() })\n * ```\n */\nexport function buildContactFormMetadata(\n options: ContactFormMetadataOptions = {},\n): ContactFormMetadata {\n const location = options.location === undefined ? browserLocation() : options.location\n return {\n fromPage: options.fromPage ?? currentPagePath(location),\n timestamp: (options.now ?? new Date()).toISOString(),\n currentUrl: location?.href ?? '',\n leadSource: options.leadSource ?? { platform: 'organic' },\n }\n}\n","/**\n * `@reblu/site-client` — framework-agnostic HTTP client for the Reblu SITE API\n * (REB-415 / design doc §3).\n *\n * The consumer owns the environment: `baseUrl`/`apiKey` are passed in, never read\n * from `process.env`. Caching is delegated to an injectable `RebluCacheAdapter`\n * (default `PlainCacheAdapter`), which severs any coupling to a specific\n * framework's cache model — `@reblu/site-next` supplies the ISR-aware adapter.\n * Response DTOs are typed by the peer, type-only `@reblu/site-contracts`.\n */\nimport { PlainCacheAdapter, type RebluCacheAdapter } from './cache'\nimport type { RebluClientContext, RequestScope } from './client'\nimport { DEFAULT_CHECKOUT_REDIRECT_HOSTS } from './checkout-redirect'\nimport { makeAcademyNamespace } from './domains/academy'\nimport { makeAnalyticsNamespace } from './domains/analytics'\nimport { makeBlogNamespace } from './domains/blog'\nimport { makeConfigNamespace } from './domains/config'\nimport { makeContactFormNamespace } from './domains/contact-form'\nimport { makeCtasNamespace } from './domains/ctas'\nimport { makeDataRequestsNamespace } from './domains/data-requests'\nimport { makeLeadsNamespace } from './domains/leads'\nimport { makeLegalNamespace } from './domains/legal'\nimport { makePagesNamespace } from './domains/pages'\nimport { makeShopNamespace } from './domains/shop'\nimport { makeTrustBadgesNamespace } from './domains/trust-badges'\n\nconst DEFAULT_API_VERSION = '1'\n/** Parity with demo-site's upstream timeout (client.ts:36). */\nconst DEFAULT_TIMEOUT_MS = 8000\n\nexport interface RebluClientConfig {\n /** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */\n baseUrl: string\n /** Tenant SITE API key (`rbl_…`), sent as `X-Reblu-Api-Key`. */\n apiKey: string\n /** Contract version sent as `X-Reblu-Api-Version`. Defaults to `'1'`. */\n apiVersion?: string\n /** Cache strategy. Defaults to `new PlainCacheAdapter()` (no-store). */\n cache?: RebluCacheAdapter\n /** Per-request hard timeout in ms. Defaults to `8000`. */\n timeoutMs?: number\n /** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */\n fetch?: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth — see `./checkout-redirect`). Defaults to\n * `['checkout.stripe.com']`. Override only to point at a test double (e.g.\n * a Stripe CLI mock host) — never to widen production trust.\n */\n checkoutRedirectHosts?: string[]\n /**\n * REB-1214 — memo store of the current server request, so identical GET\n * reads within it are fetched once. In Next.js pass `rebluRequestScope`\n * from `@reblu/site-next` (React `cache()`); see the README. Without it,\n * identical GETs share one fetch only while in flight.\n */\n requestScope?: RequestScope\n}\n\n/**\n * Build a Reblu SITE API client. Each domain is a small namespace of bound\n * methods assembled from a separate module, so a consumer importing only a\n * couple of domains can tree-shake the rest.\n */\nexport function createRebluClient(config: RebluClientConfig) {\n // Wrap global fetch so calling `ctx.fetch()` never loses its `this` binding\n // (browsers throw \"Illegal invocation\" for an unbound `window.fetch`).\n const boundFetch: typeof fetch = config.fetch ?? ((input, init) => fetch(input, init))\n\n const ctx: RebluClientContext = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,\n cache: config.cache ?? new PlainCacheAdapter(),\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetch: boundFetch,\n checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n requestScope: config.requestScope,\n inFlight: new Map(),\n }\n\n return {\n config: makeConfigNamespace(ctx),\n analytics: makeAnalyticsNamespace(ctx),\n legal: makeLegalNamespace(ctx),\n trustBadges: makeTrustBadgesNamespace(ctx),\n ctas: makeCtasNamespace(ctx),\n blog: makeBlogNamespace(ctx),\n pages: makePagesNamespace(ctx),\n shop: makeShopNamespace(ctx),\n academy: makeAcademyNamespace(ctx),\n contactForm: makeContactFormNamespace(ctx),\n leads: makeLeadsNamespace(ctx),\n dataRequests: makeDataRequestsNamespace(ctx),\n }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError, AmbiguousPageSlugError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails, PageSlugCandidate } from './errors'\nexport type { PageBySlugOptions, FeaturedPagesOptions } from './domains/pages'\nexport type { TrustBadgeListParams } from './domains/trust-badges'\nexport {\n DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n isSafeCheckoutRedirectUrl,\n UnsafeCheckoutRedirectError,\n} from './checkout-redirect'\nexport { PlainCacheAdapter } from './cache'\nexport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nexport type {\n ListResult,\n BlogListParams,\n PagesListParams,\n ShopProductsParams,\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n} from './types'\nexport {\n VISITOR_IP_HEADER,\n visitorIpFromHeaders,\n RETRY_AFTER_CAP_MS,\n type RebluMutationOptions,\n type RequestScope,\n} from './client'\nexport {\n buildContactFormMetadata,\n currentPagePath,\n type ContactFormMetadata,\n type ContactFormMetadataOptions,\n type PageLocation,\n} from './contact-form-metadata'\n"]}
1
+ {"version":3,"sources":["../src/cache.ts","../src/checkout-redirect.ts","../src/build-url.ts","../src/errors.ts","../src/client.ts","../src/domains/academy.ts","../src/domains/analytics.ts","../src/domains/blog.ts","../src/domains/config.ts","../src/domains/contact-form.ts","../src/domains/ctas.ts","../src/domains/data-requests.ts","../src/domains/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.ts","../src/contact-form-metadata.ts","../src/index.ts"],"names":[],"mappings":";;;AA0BO,IAAM,oBAAN,MAAqD;AAAA,EAC1D,WAAA,CAA6B,oBAAoC,KAAA,EAAO;AAA3C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA4C;AAAA,EAA5C,iBAAA;AAAA,EAE7B,mBAAmB,MAAA,EAAuC;AACxD,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,IAAA,CAAK,iBAAA;AAC7C,IAAA,OAAO,UAAA,KAAe,KAAA,IAAS,UAAA,KAAe,CAAA,GAC1C,EAAE,OAAO,UAAA,EAAW,GACpB,EAAE,KAAA,EAAO,aAAA,EAAc;AAAA,EAC7B;AACF;;;ACn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— the seam that severs the SDK from any framework's caching\n * model (design doc D4 / §3.2). The client owns *when* to cache (a per-call\n * `RebluCachePolicy`); the adapter owns *how* (the framework-specific\n * `RequestInit` fields). `@reblu/site-client` ships the framework-agnostic\n * `PlainCacheAdapter`; `@reblu/site-next` (REB-418) supplies a `NextCacheAdapter`\n * that returns `{ next: { revalidate } }`.\n */\n\nexport interface RebluCachePolicy {\n /**\n * Seconds to revalidate. `undefined` → use the adapter's default; `0`/`false`\n * → never cache (always fetch fresh).\n */\n revalidate?: number | false\n}\n\nexport interface RebluCacheAdapter {\n /** Map a per-call cache policy to framework-specific `fetch` `RequestInit` fields. */\n resolveRequestInit(policy: RebluCachePolicy): RequestInit\n}\n\n/**\n * Default adapter — plain `fetch` cache semantics that work in Node, edge,\n * browser and tests. No `next`, no `server-only`.\n */\nexport class PlainCacheAdapter implements RebluCacheAdapter {\n constructor(private readonly defaultRevalidate: number | false = false) {}\n\n resolveRequestInit(policy: RebluCachePolicy): RequestInit {\n const revalidate = policy.revalidate ?? this.defaultRevalidate\n return revalidate === false || revalidate === 0\n ? { cache: 'no-store' }\n : { cache: 'force-cache' }\n }\n}\n","/**\n * Stripe Checkout redirect-origin guard (REB-836, defence in depth).\n *\n * `shop.checkout()` returns a URL every SITE immediately hands to\n * `window.location.assign(url)`. Nothing upstream of this SDK validated it\n * before REB-836 — a compromised/misconfigured base-api, a tampered\n * response, or a MITM proxy could have sent a buyer's browser anywhere.\n * `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses\n * to refuse an unsafe URL before ever returning it to the caller; a SITE's\n * `@reblu/site-next` Route Handler re-checks the SAME property server-side\n * (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an\n * independent copy — see that file's docblock for why it isn't a shared\n * import). Update both together if Stripe ever changes its Checkout host.\n */\n\n/** The only Checkout redirect host trusted by default. */\nexport const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[] = ['checkout.stripe.com']\n\n/**\n * True only when `url` parses as an absolute URL, uses `https:`, and its\n * hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).\n * Never throws — an unparsable `url` is simply unsafe.\n */\nexport function isSafeCheckoutRedirectUrl(\n url: string,\n allowedHosts: readonly string[] = DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n): boolean {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n return false\n }\n return parsed.protocol === 'https:' && allowedHosts.includes(parsed.hostname)\n}\n\n/**\n * Thrown by `shop.checkout()` when base-api's Checkout URL fails\n * {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back\n * to a caller that would otherwise `window.location.assign` it.\n */\nexport class UnsafeCheckoutRedirectError extends Error {\n constructor(\n public readonly url: string,\n public readonly allowedHosts: readonly string[],\n ) {\n super(\n `Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} ` +\n `(allowed hosts: ${allowedHosts.join(', ')})`,\n )\n this.name = 'UnsafeCheckoutRedirectError'\n }\n}\n","/** A value that can be serialized into a query string. */\nexport type QueryValue = string | number | boolean | undefined | null\n\n/**\n * Append a query string to `base`, dropping `undefined`/`null` values.\n *\n * Single definition for the whole client (design doc §3.1 dedupes the two copies\n * that lived in demo-site's `client.ts` and `index.ts`). Falsy-but-meaningful\n * values (`0`, `false`, `''`) are preserved; only `undefined`/`null` are omitted.\n * Array values (REB-475 faceted `attr[key]`) emit one repeated param per element.\n */\nexport function buildUrl(\n base: string,\n params?: Record<string, QueryValue | QueryValue[]>,\n): string {\n if (!params) return base\n const pairs: [string, string][] = []\n for (const [key, value] of Object.entries(params)) {\n const values = Array.isArray(value) ? value : [value]\n for (const v of values) {\n if (v === undefined || v === null) continue\n pairs.push([key, String(v)])\n }\n }\n if (pairs.length === 0) return base\n const qs = new URLSearchParams(pairs).toString()\n return `${base}?${qs}`\n}\n","/**\n * The `details` shape `/api/site/contact-form` and `/api/site/leads` attach on a\n * 400/422, straight from zod's `.flatten()` (see\n * `details: parsed.error.flatten()` in\n * `apps/base-api/src/lib/server/services/contact-form.service.ts:114` and\n * `apiError('Validation error', 422, parsed.error.flatten())` in\n * `apps/base-api/src/app/api/site/leads/route.ts:40`). `fieldErrors` is what a\n * SITE actually needs — REB-659's `details.fieldErrors.phone` — `formErrors` is\n * kept alongside it because `.flatten()` always emits both and dropping it would\n * silently discard form-level (non-field) messages.\n */\nexport interface ApiErrorDetails {\n fieldErrors?: Record<string, string[]>\n formErrors?: string[]\n /**\n * REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /\n * `PRICE_CHANGED` error — see `ApiErrorBody.code`.\n */\n productIds?: string[]\n /** REB-842: optional request-field identifier for checkout validation errors. */\n field?: string\n}\n\n/**\n * The parsed shape of a non-2xx SITE API response body: `{ error, details? }`\n * (see `apiError()` in `apps/base-api/src/lib/api/response.ts:33` — the general\n * shape both routes above build on).\n */\nexport interface ApiErrorBody {\n error: string\n details?: ApiErrorDetails\n /**\n * REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from\n * `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write\n * endpoints may set — additive and OPTIONAL, so a consumer that only reads\n * `error`/`message` keeps working unchanged. `string` rather than\n * `ShopErrorCode` here because `ApiError` is a generic transport error used\n * by every `/api/site/*` domain, not just shop.\n */\n code?: string\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string')\n}\n\n/**\n * Validates `ApiErrorDetails` deeply — `fieldErrors` must be a record whose\n * values are `string[] | undefined`, `formErrors` (if present) must be\n * `string[]`, and `field` (if present) must be a string. Without this, a body like\n * `{ fieldErrors: { phone: \"abc\" } }` passed the old shallow check, so\n * `body.details?.fieldErrors?.phone?.[0]` silently returned the character\n * `\"a\"` instead of a validation message (REB-764 review finding).\n */\nfunction isApiErrorDetails(value: unknown): value is ApiErrorDetails {\n if (typeof value !== 'object' || value === null) return false\n const details = value as {\n fieldErrors?: unknown\n formErrors?: unknown\n productIds?: unknown\n field?: unknown\n }\n\n if (details.fieldErrors !== undefined) {\n if (\n typeof details.fieldErrors !== 'object' ||\n details.fieldErrors === null ||\n Array.isArray(details.fieldErrors)\n ) {\n return false\n }\n for (const fieldValue of Object.values(details.fieldErrors as Record<string, unknown>)) {\n if (fieldValue !== undefined && !isStringArray(fieldValue)) return false\n }\n }\n\n if (details.formErrors !== undefined && !isStringArray(details.formErrors)) return false\n\n // REB-836: STOCK_CHANGED/PRICE_CHANGED carry the affected product ids here.\n if (details.productIds !== undefined && !isStringArray(details.productIds)) return false\n if ('field' in details && typeof details.field !== 'string') return false\n\n return true\n}\n\n/**\n * `details`, when present, must match `ApiErrorDetails` deeply — an\n * unrecognised `details` shape makes the whole body unrecognised (`body`\n * stays `undefined`), the stricter reading consistent with\n * `parseApiErrorBody`'s existing all-or-nothing semantics: a body is either\n * shaped like `ApiErrorBody` or it isn't. Silently dropping a malformed\n * `details` instead would let a consumer treat a schema-drifted or corrupted\n * response as merely detail-less, hiding the mismatch rather than surfacing\n * it as \"unparseable\" (REB-764 review finding).\n */\nfunction isApiErrorBody(value: unknown): value is ApiErrorBody {\n if (typeof value !== 'object' || value === null) return false\n const body = value as { error?: unknown; details?: unknown; code?: unknown }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) return false\n // REB-836: `code` must be a string when present — same all-or-nothing\n // reading as `details` above (an unrecognised shape makes the whole body\n // unrecognised, never silently dropped).\n if (body.code !== undefined && typeof body.code !== 'string') return false\n return true\n}\n\n/**\n * Parses `rawBody` (the exact text `message` is built from) into a typed\n * `ApiErrorBody`, or `undefined` when it is not JSON, or JSON that does not\n * match the expected shape — an edge proxy 502 returns HTML, and this must\n * never throw while constructing the error it is reporting.\n */\nfunction parseApiErrorBody(rawBody: string): ApiErrorBody | undefined {\n if (!rawBody) return undefined\n try {\n const parsed: unknown = JSON.parse(rawBody)\n return isApiErrorBody(parsed) ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Typed transport error for the Reblu SITE API.\n *\n * Every non-2xx response throws an `ApiError` (never a bare `fetch` rejection),\n * so consumers can `catch (e) { if (e instanceof ApiError) … }` and fall back\n * gracefully (e.g. render an empty section) — the one behavioural contract the\n * SITE relies on. Moved verbatim from demo-site's `client.ts` (design doc §3.4).\n */\nexport class ApiError extends Error {\n /**\n * The parsed response body, when it was JSON shaped like `{ error, details? }`\n * (REB-764). `undefined` when the body was not JSON or didn't match — parsing\n * is defensive and never throws. Read `body.details?.fieldErrors?.phone`\n * instead of regex-stripping this error's `message`.\n */\n public readonly body: ApiErrorBody | undefined\n\n constructor(\n public readonly status: number,\n public readonly path: string,\n message: string,\n ) {\n super(`API ${status} @ ${path}: ${message}`)\n this.name = 'ApiError'\n this.body = parseApiErrorBody(message)\n }\n}\n\n/** One page a slug could mean (REB-867) — `null` = the uncategorised page. */\nexport interface PageSlugCandidate {\n categorySlug: string | null\n}\n\nfunction parseCandidates(rawBody: string): PageSlugCandidate[] {\n try {\n const parsed = JSON.parse(rawBody) as { candidates?: unknown }\n if (!Array.isArray(parsed.candidates)) return []\n return parsed.candidates.flatMap((c: unknown) => {\n const slug = (c as { categorySlug?: unknown } | null)?.categorySlug\n return typeof slug === 'string' || slug === null ? [{ categorySlug: slug }] : []\n })\n } catch {\n return []\n }\n}\n\n/**\n * REB-867 — `GET /api/site/pages/[slug]` answered 409 `ambiguous_slug`: page\n * slugs are unique PER CATEGORY and this one exists in more than one, so the\n * server refused to pick. Retry with `pages.bySlug(slug, { category })` using\n * one of `candidates`. Extends `ApiError`, so an existing\n * `catch (e) { if (e instanceof ApiError) … }` keeps handling it.\n */\nexport class AmbiguousPageSlugError extends ApiError {\n public readonly candidates: PageSlugCandidate[]\n\n constructor(source: ApiError, rawBody: string) {\n super(source.status, source.path, rawBody)\n this.name = 'AmbiguousPageSlugError'\n this.candidates = parseCandidates(rawBody)\n }\n}\n\n/** The raw body an `ApiError` was built from (its message minus the prefix). */\nexport function apiErrorRawBody(error: ApiError): string {\n const prefix = `API ${error.status} @ ${error.path}: `\n return error.message.startsWith(prefix) ? error.message.slice(prefix.length) : error.message\n}\n","import type { PaginationMeta } from '@reblu/site-contracts'\nimport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nimport { ApiError } from './errors'\nimport type { ListResult } from './types'\n\n/**\n * Resolved, immutable client context threaded into every domain namespace. Built\n * once by `createRebluClient` from the consumer's config — the SDK never reads\n * `process.env`, so the consumer owns `baseUrl`/`apiKey` (design doc §3.3).\n */\nexport interface RebluClientContext {\n baseUrl: string\n apiKey: string\n apiVersion: string\n cache: RebluCacheAdapter\n timeoutMs: number\n fetch: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth). Defaults to\n * `DEFAULT_CHECKOUT_REDIRECT_HOSTS` (`['checkout.stripe.com']`) — tests\n * inject a different value via `RebluClientConfig.checkoutRedirectHosts`.\n */\n checkoutRedirectHosts: readonly string[]\n /**\n * REB-1214 — returns the memo store of the CURRENT server request, so\n * identical GET reads within it are fetched once (e.g. `generateMetadata`\n * and the page body). `@reblu/site-next` supplies one backed by React\n * `cache()` (`rebluRequestScope`). Absent, or returning `undefined`,\n * identical GETs still share one fetch while they are in flight.\n */\n requestScope?: RequestScope\n /** In-flight GETs when no request scope is active. Created by `createRebluClient`. */\n inFlight?: Map<string, Promise<unknown>>\n}\n\n/** Memo store of one server request, keyed by read identity (REB-1214). */\nexport type RequestScope = () => Map<string, Promise<unknown>> | undefined\n\n/** Upper bound for a `Retry-After` wait before the single retry (REB-1214). */\nexport const RETRY_AFTER_CAP_MS = 2000\n/** Wait before the single retry when `Retry-After` is absent or unparseable. */\nexport const DEFAULT_RETRY_DELAY_MS = 250\n/** Statuses that mean \"try again shortly\" for a read. */\nconst RETRYABLE_READ_STATUSES = new Set([429, 503])\n\n/** `Retry-After` (seconds or HTTP date) → ms, capped; default when unusable. */\nfunction retryDelayMs(header: string | null): number {\n if (header !== null && header.trim() !== '') {\n const value = header.trim()\n const seconds = /^\\d+$/.test(value) ? Number(value) * 1000 : NaN\n const ms = Number.isFinite(seconds) ? seconds : Date.parse(value) - Date.now()\n if (Number.isFinite(ms)) return Math.min(Math.max(0, ms), RETRY_AFTER_CAP_MS)\n }\n return DEFAULT_RETRY_DELAY_MS\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/** Per-call request options. `cachePolicy` is interpreted by the cache adapter. */\nexport interface RequestOptions {\n method?: string\n body?: string\n headers?: Record<string, string>\n cachePolicy?: RebluCachePolicy\n}\n\n/**\n * Core transport (design doc §3.4). Injects the auth + contract-version headers,\n * merges the adapter's cache `RequestInit`, enforces a hard timeout per attempt,\n * throws a typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n *\n * REB-1214 — GET reads only: identical reads are deduped (see\n * `RebluClientContext.requestScope`) and a 429/503 is retried once after\n * `Retry-After`, capped at {@link RETRY_AFTER_CAP_MS}. If the retry fails too,\n * the second response's `ApiError` is thrown — the same type as before.\n * Writes are never deduped nor retried.\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const method = opts.method ?? 'GET'\n const init: RequestInit = {\n method,\n body: opts.body,\n headers: {\n 'X-Reblu-Api-Key': ctx.apiKey,\n 'X-Reblu-Api-Version': ctx.apiVersion,\n 'Content-Type': 'application/json',\n ...opts.headers,\n },\n ...ctx.cache.resolveRequestInit(opts.cachePolicy ?? {}),\n }\n if (method !== 'GET' || opts.body !== undefined) {\n return attempt<T>(ctx, path, init)\n }\n\n // REB-1214 — a read is identified by everything that shapes its response:\n // URL, headers and the resolved cache init. Kept for the whole request when\n // a scope is active; otherwise only while in flight.\n const key = JSON.stringify([ctx.baseUrl + path, init])\n const scope = ctx.requestScope?.()\n const store = scope ?? ctx.inFlight\n const existing = store?.get(key)\n if (existing) return existing as Promise<T>\n\n const pending = readWithRetry<T>(ctx, path, init)\n if (store) {\n store.set(key, pending)\n // A failure is never memoised; without a scope nothing outlives the fetch.\n pending.then(\n () => {\n if (!scope) store.delete(key)\n },\n () => {\n if (store.get(key) === pending) store.delete(key)\n },\n )\n }\n return pending\n}\n\n/** A GET answered 429/503 is retried once after `Retry-After` (capped). */\nasync function readWithRetry<T>(\n ctx: RebluClientContext,\n path: string,\n init: RequestInit,\n): Promise<T> {\n try {\n return await attempt<T>(ctx, path, init)\n } catch (error) {\n if (!(error instanceof RetryableReadError)) throw error\n await sleep(retryDelayMs(error.retryAfter))\n try {\n return await attempt<T>(ctx, path, init)\n } catch (retryError) {\n throw retryError instanceof RetryableReadError ? retryError.apiError : retryError\n }\n }\n}\n\n/** Internal carrier: a retryable read status plus the `ApiError` to throw if it persists. */\nclass RetryableReadError extends Error {\n constructor(\n readonly apiError: ApiError,\n readonly retryAfter: string | null,\n ) {\n super(apiError.message)\n }\n}\n\n/**\n * One HTTP attempt: enforces the hard timeout via `AbortController`, throws a\n * typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n */\nasync function attempt<T>(ctx: RebluClientContext, path: string, init: RequestInit): Promise<T> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(ctx.baseUrl + path, { ...init, signal: controller.signal })\n\n if (!res.ok) {\n const error = new ApiError(res.status, path, await res.text())\n if (init.method === 'GET' && RETRYABLE_READ_STATUSES.has(res.status)) {\n throw new RetryableReadError(error, res.headers.get('retry-after'))\n }\n throw error\n }\n return (await res.json()) as T\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch a single resource and unwrap the `{ data: T }` envelope. */\nexport async function requestOne<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const body = await request<{ data: T }>(ctx, path, opts)\n return body.data\n}\n\n/** Fetch a list resource, returning the `{ data, meta }` envelope (meta preserved). */\nexport async function requestList<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<ListResult<T>> {\n const body = await request<{ data: T[]; meta?: PaginationMeta }>(ctx, path, opts)\n return { data: body.data, meta: body.meta }\n}\n\n/**\n * Header carrying the visitor IP from a SITE server to base-api (REB-1005).\n * base-api keys its per-visitor limit on public writes on it, and trusts it\n * only behind a valid API key.\n */\nexport const VISITOR_IP_HEADER = 'x-reblu-visitor-ip'\n\n/**\n * Per-call options for a write (REB-1005).\n *\n * - `visitorIp` — the visitor's IP when a SITE calls the SDK server-side, sent\n * as `x-reblu-visitor-ip`. Do NOT rely on forwarding `x-forwarded-for`: on\n * Vercel the SITE→base-api hop gets it overwritten with the SITE function's\n * egress IP. Read it from the INCOMING request with\n * {@link visitorIpFromHeaders}.\n * - `headers` — other extra headers (e.g. `user-agent`). They can never set\n * `x-reblu-visitor-ip` nor replace `X-Reblu-Api-Key`, `X-Reblu-Api-Version`\n * or `Content-Type`.\n */\nexport interface RebluMutationOptions {\n visitorIp?: string\n headers?: Record<string, string>\n}\n\n/** The visitor IP of an incoming request: first `x-forwarded-for` entry, else `x-real-ip`. */\nexport function visitorIpFromHeaders(headers: {\n get(name: string): string | null\n}): string | undefined {\n return (\n headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||\n headers.get('x-real-ip')?.trim() ||\n undefined\n )\n}\n\n/** Headers the SDK owns on every request — an extra header never sets or overrides these. */\nconst RESERVED_HEADERS = new Set([\n 'x-reblu-api-key',\n 'x-reblu-api-version',\n 'content-type',\n VISITOR_IP_HEADER,\n])\n\n/**\n * The extra headers a write sends for `options`: caller headers minus the\n * reserved ones, plus `x-reblu-visitor-ip` from `visitorIp`. Shared by\n * {@link requestMutation} and the writes that cannot use it (academy).\n */\nexport function extraHeaders(\n options: RebluMutationOptions | undefined,\n): Record<string, string> | undefined {\n if (!options?.headers && !options?.visitorIp) return undefined\n const safe: Record<string, string> = {}\n for (const [name, value] of Object.entries(options.headers ?? {})) {\n if (!RESERVED_HEADERS.has(name.toLowerCase())) safe[name] = value\n }\n const visitorIp = options.visitorIp?.trim()\n if (visitorIp) safe[VISITOR_IP_HEADER] = visitorIp\n return safe\n}\n\n/**\n * POST a mutation: serialize `body` to JSON, force a cache bypass (`revalidate:\n * false` → `no-store` regardless of the injected adapter, since a mutation must\n * never be served from cache), then unwrap the `{ data: T }` envelope. Mirrors\n * every `/api/site/*` write route, which answers with `apiOk`/`{ data }`.\n */\nexport async function requestMutation<Req, Res>(\n ctx: RebluClientContext,\n path: string,\n body: Req,\n options?: RebluMutationOptions,\n): Promise<Res> {\n const headers = extraHeaders(options)\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyConfigPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n AcademyInstructorPublic,\n AcademyLessonPreview,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n extraHeaders,\n request,\n requestList,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport type {\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n ListResult,\n} from '../types'\n\n/**\n * Academy domain — the public course catalogue (`GET /api/site/academy/*`,\n * REB-528 / REB-534) plus the anonymous enrollment request (REB-496). The reads\n * are published-filtered server-side, so nothing here needs an entitlement\n * notion; the one write is unauthenticated by design.\n *\n * `enrollmentRequest` drops to the raw `request()` transport rather than\n * `requestMutation` (REB-584). The route answers with a BARE `{ message }`, not\n * the `{ data }` envelope every other write uses, so `requestMutation` would\n * unwrap a missing `.data` and hand the caller `undefined`. Normalizing the\n * route's envelope instead was rejected: its response shape is load-bearing\n * anti-enumeration behaviour, and changing it would ripple into base-api tests\n * for no gain on the SITE side.\n */\nexport function makeAcademyNamespace(ctx: RebluClientContext) {\n return {\n /** Published courses, filtered + paginated. `meta` carries the pagination. */\n courses: (\n params?: AcademyCourseListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<AcademyCourseSummary>> =>\n requestList<AcademyCourseSummary>(\n ctx,\n buildUrl('/api/site/academy/courses', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n /** A single published course by slug, with its modules, lessons and CTA gate. */\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<AcademyCourseDetail> =>\n requestOne<AcademyCourseDetail>(ctx, `/api/site/academy/courses/${slug}`, {\n cachePolicy: cache,\n }),\n\n /**\n * A free-preview lesson, viewable by the public (REB-1135): title, duration,\n * Markdown body and a ready-to-embed video. Any lesson the public may not see\n * is a uniform 404 (`ApiError`). Never cached: the payload carries a\n * short-lived signed playback token. Server-side, prefer `getLessonPreview`\n * from `@reblu/site-next/academy-server`, which maps that 404 to `null`.\n */\n lessonPreview: (courseSlug: string, lessonSlug: string): Promise<AcademyLessonPreview> =>\n requestOne<AcademyLessonPreview>(\n ctx,\n `/api/site/academy/courses/${encodeURIComponent(courseSlug)}/lessons/${encodeURIComponent(lessonSlug)}`,\n { cachePolicy: { revalidate: false } },\n ),\n\n /**\n * Instructors of published courses, sorted by name, backing the catalog\n * instructor filter (REB-547). Pass an `id` as `courses({ instructor })`.\n * Not paginated.\n */\n instructors: (cache?: RebluCachePolicy): Promise<ListResult<AcademyInstructorPublic>> =>\n requestList<AcademyInstructorPublic>(ctx, '/api/site/academy/instructors', {\n cachePolicy: cache,\n }),\n\n /**\n * Tenant academy settings for the SITE (REB-1234). `catalogFilters` says\n * which catalogue filters the tenant switched on in nexus — pass it as\n * `enabled` to `CourseCatalogFilters` (`@reblu/site-blocks`). A filter the\n * tenant never set comes back `true`.\n */\n config: (cache?: RebluCachePolicy): Promise<AcademyConfigPublic> =>\n requestOne<AcademyConfigPublic>(ctx, '/api/site/academy/config', { cachePolicy: cache }),\n\n /** Active course categories backing the catalog filter. Not paginated. */\n categories: (cache?: RebluCachePolicy): Promise<ListResult<AcademyCategoryPublic>> =>\n requestList<AcademyCategoryPublic>(ctx, '/api/site/academy/categories', {\n cachePolicy: cache,\n }),\n\n /**\n * Submit an anonymous enrollment request for a course.\n *\n * The reply is UNIFORM by design: the caller cannot tell whether the email\n * was new (a request row was created) or already known (a sign-in link was\n * sent and NO request row exists). Never present the returned message as\n * confirmation that a request was recorded — it is not one.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n options?: RebluMutationOptions,\n ): Promise<AcademyEnrollmentRequestResult> => {\n const headers = extraHeaders(options)\n return request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n },\n }\n}\n","import type { Analytics } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/analytics` — the tenant's analytics provider configuration. */\nexport function makeAnalyticsNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Analytics> =>\n requestOne<Analytics>(ctx, '/api/site/analytics', { cachePolicy: cache }),\n }\n}\n","import type {\n BlogCategoryWithCount,\n BlogPostDetail,\n BlogPostListItem,\n BlogPostPreview,\n BlogSlug,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport type { BlogListParams, ListResult } from '../types'\n\n/** Blog domain — `GET /api/site/blog/*`. */\nexport function makeBlogNamespace(ctx: RebluClientContext) {\n return {\n list: (\n params?: BlogListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(\n ctx,\n buildUrl('/api/site/blog', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<BlogPostDetail> =>\n requestOne<BlogPostDetail>(ctx, `/api/site/blog/${slug}`, { cachePolicy: cache }),\n\n related: (slug: string, cache?: RebluCachePolicy): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(ctx, `/api/site/blog/${slug}/related`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<BlogCategoryWithCount>> =>\n requestList<BlogCategoryWithCount>(ctx, '/api/site/blog/categories', { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<BlogSlug>> =>\n requestList<BlogSlug>(ctx, '/api/site/blog/slugs', { cachePolicy: cache }),\n\n /** Draft preview — never cached (unpublished content). */\n preview: (id: string): Promise<BlogPostPreview> =>\n requestOne<BlogPostPreview>(ctx, `/api/site/blog/preview/${id}`, {\n cachePolicy: { revalidate: false },\n }),\n }\n}\n","import type { Config } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/config` — the tenant's public site configuration. */\nexport function makeConfigNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Config> =>\n requestOne<Config>(ctx, '/api/site/config', { cachePolicy: cache }),\n }\n}\n","import type { ContactFormInput, ContactFormSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * Contact form domain — WRITE only (`POST /api/site/contact-form`, REB-438).\n * Posts a body typed by `@reblu/site-contracts` and bypasses the cache; returns\n * the created lead's id + creation timestamp.\n */\nexport function makeContactFormNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a contact form. Returns the created lead acknowledgement.\n * Server-side (a Server Action / Route Handler), pass `options.visitorIp`\n * (from the incoming request, see `visitorIpFromHeaders`) so base-api's\n * per-IP limit (REB-1005) applies to the real visitor.\n */\n submit: (\n body: ContactFormInput,\n options?: RebluMutationOptions,\n ): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(\n ctx,\n '/api/site/contact-form',\n body,\n options,\n ),\n }\n}\n","import type { Cta } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/**\n * `GET /api/site/ctas?slot=…` — editable CTAs for a given slot.\n *\n * `slot` is typed as `string` on purpose: the slot enum lives in base-api's\n * `validations/` (not the response contracts), so `@reblu/site-contracts` does\n * not export it. Keeping it a `string` avoids duplicating (and drifting from)\n * the server-owned enum. The server validates the slot.\n */\nexport function makeCtasNamespace(ctx: RebluClientContext) {\n return {\n list: (slot: string, cache?: RebluCachePolicy): Promise<ListResult<Cta>> =>\n requestList<Cta>(ctx, buildUrl('/api/site/ctas', { slot }), { cachePolicy: cache }),\n }\n}\n","import type { DataRequestInput, DataRequestSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * GDPR data-subject requests domain — WRITE only (`POST /api/site/data-requests`,\n * REB-77 endpoint / REB-980 SDK). Posts the public rights-form body typed by\n * `@reblu/site-contracts`, bypasses the cache, and returns the request id, when\n * it was received and the 72h deadline (`slaDueAt`) it is now held to.\n *\n * base-api requires a reCAPTCHA v3 token (`captcha`) and rate-limits per tenant\n * and per visitor IP (REB-1005); a rejection surfaces as an `ApiError` carrying\n * the upstream `status` (400 validation, 422 captcha, 429 rate limit).\n */\nexport function makeDataRequestsNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a data-subject request. Returns its acknowledgement with the 72h\n * deadline. Server-side, pass `options.visitorIp` (from the incoming\n * request, see `visitorIpFromHeaders`) so base-api's per-IP limit\n * (REB-1005) sees the real visitor.\n */\n submit: (\n body: DataRequestInput,\n options?: RebluMutationOptions,\n ): Promise<DataRequestSubmission> =>\n requestMutation<DataRequestInput, DataRequestSubmission>(\n ctx,\n '/api/site/data-requests',\n body,\n options,\n ),\n }\n}\n","import type { LeadInput, LeadSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext } from '../client'\n\n/**\n * Leads domain — WRITE only (`POST /api/site/leads`, REB-438). The generic\n * lead-ingestion endpoint: posts a body typed by `@reblu/site-contracts`,\n * bypasses the cache, and returns the created lead's id + creation timestamp.\n */\nexport function makeLeadsNamespace(ctx: RebluClientContext) {\n return {\n /** Create a lead. Returns the created lead acknowledgement. */\n create: (body: LeadInput): Promise<LeadSubmission> =>\n requestMutation<LeadInput, LeadSubmission>(ctx, '/api/site/leads', body),\n }\n}\n","import type { Legal } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/legal` — the tenant's legal content (privacy, terms, cookies). */\nexport function makeLegalNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Legal> =>\n requestOne<Legal>(ctx, '/api/site/legal', { cachePolicy: cache }),\n }\n}\n","import type { PageDetail, PageListItem, PageSlug } from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport { AmbiguousPageSlugError, ApiError, apiErrorRawBody } from '../errors'\nimport type { ListResult, PagesListParams } from '../types'\n\n/**\n * REB-867 — options for `pages.bySlug`. Page slugs are unique PER CATEGORY:\n * - `category: '<categorySlug>'` → the page with that slug in that category;\n * - `category: null` → the UNCATEGORISED page with that slug;\n * - omitted → the unique page with that slug; throws\n * `AmbiguousPageSlugError` when it exists in more than one category.\n */\nexport interface PageBySlugOptions {\n category?: string | null\n cache?: RebluCachePolicy\n}\n\n/**\n * The two second-argument shapes share no key: a `RebluCachePolicy` only ever\n * has `revalidate`, `PageBySlugOptions` only `category`/`cache`. So the\n * presence of `category` or `cache` (even `category: undefined`) selects the\n * options form; anything else — including `{}` — is a cache policy, exactly as\n * before REB-867.\n */\n/** REB-869 — options for `pages.featured`. */\nexport interface FeaturedPagesOptions {\n /**\n * How many pages at most: an integer >= 1. Default 3. Values above the\n * server's cap (3) are clamped to 3; anything else invalid (0, negative,\n * fractional, NaN) throws a `RangeError` before any request is made.\n */\n limit?: number\n /**\n * When the category has nothing featured, return its first `limit` pages in\n * normal order instead of `[]`. Default `true`, so a teaser is never empty\n * just because nobody picked pages yet.\n */\n fallback?: boolean\n cache?: RebluCachePolicy\n}\n\n/** The server caps a featured list at 3 (REB-869). */\nconst FEATURED_PAGES_MAX = 3\n\nfunction isBySlugOptions(value: RebluCachePolicy | PageBySlugOptions): value is PageBySlugOptions {\n return 'category' in value || 'cache' in value\n}\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n const namespace = {\n list: (\n params?: PagesListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<PageListItem>> =>\n requestList<PageListItem>(\n ctx,\n // REB-63: `type` can now be a single PageType or an array (repeated\n // `?type=` params) — widen the cast alongside `PagesListParams`.\n buildUrl('/api/site/pages', params as Record<string, QueryValue | QueryValue[]> | undefined),\n { cachePolicy: cache },\n ),\n\n /**\n * A published page by slug. The second argument is either a cache policy\n * (backward-compatible) or {@link PageBySlugOptions} (REB-867).\n */\n bySlug: async (\n slug: string,\n cacheOrOptions?: RebluCachePolicy | PageBySlugOptions,\n ): Promise<PageDetail> => {\n const options: PageBySlugOptions =\n cacheOrOptions && isBySlugOptions(cacheOrOptions)\n ? cacheOrOptions\n : { cache: cacheOrOptions }\n const path =\n options.category === undefined\n ? `/api/site/pages/${slug}`\n : buildUrl(`/api/site/pages/${slug}`, { category: options.category ?? '' })\n try {\n return await requestOne<PageDetail>(ctx, path, { cachePolicy: options.cache })\n } catch (error) {\n if (error instanceof ApiError && error.status === 409 && error.body?.code === 'ambiguous_slug') {\n throw new AmbiguousPageSlugError(error, apiErrorRawBody(error))\n }\n throw error\n }\n },\n\n /**\n * REB-869 — the pages to show in a category teaser: the category's\n * featured pages in the tenant's order; when none are featured (and\n * `fallback` is not `false`), the first `limit` pages of the category in\n * normal order. Returns the items only (no pagination applies).\n */\n featured: async (\n category: string,\n { limit: requested = FEATURED_PAGES_MAX, fallback = true, cache }: FeaturedPagesOptions = {},\n ): Promise<PageListItem[]> => {\n if (!Number.isInteger(requested) || requested < 1) {\n throw new RangeError(`pages.featured: limit must be an integer >= 1 (got ${requested})`)\n }\n const limit = Math.min(requested, FEATURED_PAGES_MAX)\n const featured = await namespace.list({ category, featured: true }, cache)\n if (featured.data.length > 0 || !fallback) return featured.data.slice(0, limit)\n const first = await namespace.list({ category, pageSize: limit }, cache)\n return first.data.slice(0, limit)\n },\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\n return namespace\n}\n","import type {\n ShopApplyDiscountInput,\n ShopCartValidation,\n ShopCategory,\n ShopCheckEmailInput,\n ShopCheckoutInput,\n ShopCheckoutSession,\n ShopConfig,\n ShopDiscountApplication,\n ShopEmailCheck,\n ShopFacets,\n ShopOrder,\n ShopProductDetail,\n ShopProductListItem,\n ShopValidateCartInput,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n requestList,\n requestMutation,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport { isSafeCheckoutRedirectUrl, UnsafeCheckoutRedirectError } from '../checkout-redirect'\nimport type { ListResult, ShopProductsParams } from '../types'\n\n/**\n * Flatten `ShopProductsParams` into a query record: scalars pass through; the\n * `taxonomy`/`attr` maps become repeatable `taxonomy[key]`/`attr[key]` params.\n * Array attr values repeat the same bracket key.\n */\nfunction flattenShopParams(params?: ShopProductsParams): Record<string, QueryValue | QueryValue[]> {\n if (!params) return {}\n const { taxonomy, attr, ...scalars } = params\n const out: Record<string, QueryValue | QueryValue[]> = { ...scalars }\n if (taxonomy) {\n for (const [key, value] of Object.entries(taxonomy)) out[`taxonomy[${key}]`] = value\n }\n if (attr) {\n for (const [key, value] of Object.entries(attr)) out[`attr[${key}]`] = value\n }\n return out\n}\n\n/**\n * Shop domain — READ surface (`GET /api/site/shop/*`) plus the mutation flow\n * (`POST` checkout, validate-cart, apply-discount, and the deprecated\n * check-email) added in REB-438. Every write posts a body typed by `@reblu/site-contracts` and bypasses\n * the cache. Request/response DTOs live in the contracts package (zero Zod).\n */\nexport function makeShopNamespace(ctx: RebluClientContext) {\n return {\n products: (\n params?: ShopProductsParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<ShopProductListItem>> =>\n requestList<ShopProductListItem>(\n ctx,\n buildUrl('/api/site/shop/products', flattenShopParams(params)),\n { cachePolicy: cache },\n ),\n\n /** Available facets (brand/attributes/price/on-sale) for the given filters. */\n facets: (params?: ShopProductsParams, cache?: RebluCachePolicy): Promise<ShopFacets> =>\n requestOne<ShopFacets>(ctx, buildUrl('/api/site/shop/facets', flattenShopParams(params)), {\n cachePolicy: cache,\n }),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<ShopProductDetail> =>\n requestOne<ShopProductDetail>(ctx, `/api/site/shop/products/${slug}`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<ShopCategory>> =>\n requestList<ShopCategory>(ctx, '/api/site/shop/categories', { cachePolicy: cache }),\n\n config: (cache?: RebluCachePolicy): Promise<ShopConfig> =>\n requestOne<ShopConfig>(ctx, '/api/site/shop/config', { cachePolicy: cache }),\n\n // ── Mutations (REB-438) ──────────────────────────────────────────────────\n\n /**\n * Start a hosted checkout session. Returns the Stripe URL + session id.\n *\n * REB-836 (defence in depth): every SITE hands `url` straight to\n * `window.location.assign`, so this validates it is `https:` on an\n * allowed host (`ctx.checkoutRedirectHosts`, default\n * `checkout.stripe.com`) BEFORE returning — throwing\n * {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL\n * that could redirect a buyer's browser off Stripe's domain.\n */\n checkout: async (body: ShopCheckoutInput): Promise<ShopCheckoutSession> => {\n const session = await requestMutation<ShopCheckoutInput, ShopCheckoutSession>(\n ctx,\n '/api/site/shop/checkout',\n body,\n )\n if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {\n throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts)\n }\n return session\n },\n\n /** Validate a cart against live product/stock/price state before checkout. */\n validateCart: (body: ShopValidateCartInput): Promise<ShopCartValidation> =>\n requestMutation<ShopValidateCartInput, ShopCartValidation>(\n ctx,\n '/api/site/shop/validate-cart',\n body,\n ),\n\n /** Validate a discount code against the current cart subtotal. */\n applyDiscount: (body: ShopApplyDiscountInput): Promise<ShopDiscountApplication> =>\n requestMutation<ShopApplyDiscountInput, ShopDiscountApplication>(\n ctx,\n '/api/site/shop/apply-discount',\n body,\n ),\n\n /**\n * @deprecated REB-834 — the endpoint no longer reveals whether an account\n * exists: it always resolves `{ exists: false }`. Do not call it and never\n * branch UI on `exists`; the checkout always offers «Iniciar sesión o\n * continuar como invitado» and the server links the order to an existing\n * account after payment. Removed in the next major.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n checkEmail: (\n body: ShopCheckEmailInput,\n options?: RebluMutationOptions,\n ): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(\n ctx,\n '/api/site/shop/check-email',\n body,\n options,\n ),\n\n /**\n * Look up a confirmed (or still-pending) order by its Stripe Checkout\n * session id — the order-confirmation flow (REB-829). `GET`, so it goes\n * through `requestOne` like every other read, not `requestMutation`.\n */\n order: (sessionId: string, cache?: RebluCachePolicy): Promise<ShopOrder> =>\n requestOne<ShopOrder>(ctx, `/api/site/shop/order/${encodeURIComponent(sessionId)}`, {\n cachePolicy: cache,\n }),\n }\n}\n","import type { TrustBadge, TrustBadgeType } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** Filters for {@link makeTrustBadgesNamespace}'s `list` (REB-996). */\nexport interface TrustBadgeListParams {\n /** Only badges of this type (e.g. `'SUBVENTION'`). Omit for every type. */\n type?: TrustBadgeType\n}\n\nfunction isCachePolicy(value: TrustBadgeListParams | RebluCachePolicy): value is RebluCachePolicy {\n return Object.prototype.hasOwnProperty.call(value, 'revalidate')\n}\n\n/**\n * `GET /api/site/trust-badges` — the tenant's PUBLIC trust badges (no\n * pagination): active in nexus and inside their optional validity window, so\n * expiring or switching one off needs no SITE change.\n */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n function list(cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>>\n function list(\n params: TrustBadgeListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>>\n function list(\n paramsOrCache?: TrustBadgeListParams | RebluCachePolicy,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>> {\n // `list(cache)` is the pre-REB-996 call shape — kept so this stays a minor.\n const legacyCache = paramsOrCache && isCachePolicy(paramsOrCache) ? paramsOrCache : undefined\n const params = legacyCache ? undefined : (paramsOrCache as TrustBadgeListParams | undefined)\n return requestList<TrustBadge>(\n ctx,\n buildUrl('/api/site/trust-badges', { type: params?.type }),\n { cachePolicy: legacyCache ?? cache },\n )\n }\n return { list }\n}\n","import type { ContactFormInput } from '@reblu/site-contracts'\n\n/**\n * REB-1077 — the `metadata` block of a contact-form submission, built from the\n * page the visitor is on so a SITE never hand-codes `fromPage`.\n *\n * Call it in the browser, at submit time (inside the form's submit handler):\n * it reads `globalThis.location` unless a `location` is passed.\n */\n\n/** The part of `window.location` these helpers read. */\nexport interface PageLocation {\n pathname: string\n href?: string\n}\n\nexport type ContactFormMetadata = ContactFormInput['metadata']\n\nexport interface ContactFormMetadataOptions {\n /**\n * Explicit page path, overriding the one read from the location (e.g. a\n * modal form that wants to report the landing it belongs to).\n */\n fromPage?: string\n /** @default { platform: 'organic' } */\n leadSource?: ContactFormMetadata['leadSource']\n /** @default globalThis.location */\n location?: PageLocation | null\n /** Submission time. @default new Date() */\n now?: Date\n}\n\nfunction browserLocation(): PageLocation | null {\n const location = (globalThis as { location?: PageLocation }).location\n return location && typeof location.pathname === 'string' ? location : null\n}\n\n/**\n * Path of the page the visitor is on — `location.pathname`, never with a query\n * string or hash. `'/'` when there is no location (server render).\n */\nexport function currentPagePath(location: PageLocation | null = browserLocation()): string {\n const path = location?.pathname.split(/[?#]/, 1)[0] ?? ''\n return path.startsWith('/') ? path : '/'\n}\n\n/**\n * The `metadata` for `contactForm.submit()` / `POST /api/site/contact-form`:\n * `fromPage` is the current page path, `currentUrl` the full href (base-api\n * reads the UTMs from it), `timestamp` the submission time.\n *\n * ```ts\n * body: JSON.stringify({ ...fields, captcha, metadata: buildContactFormMetadata() })\n * ```\n */\nexport function buildContactFormMetadata(\n options: ContactFormMetadataOptions = {},\n): ContactFormMetadata {\n const location = options.location === undefined ? browserLocation() : options.location\n return {\n fromPage: options.fromPage ?? currentPagePath(location),\n timestamp: (options.now ?? new Date()).toISOString(),\n currentUrl: location?.href ?? '',\n leadSource: options.leadSource ?? { platform: 'organic' },\n }\n}\n","/**\n * `@reblu/site-client` — framework-agnostic HTTP client for the Reblu SITE API\n * (REB-415 / design doc §3).\n *\n * The consumer owns the environment: `baseUrl`/`apiKey` are passed in, never read\n * from `process.env`. Caching is delegated to an injectable `RebluCacheAdapter`\n * (default `PlainCacheAdapter`), which severs any coupling to a specific\n * framework's cache model — `@reblu/site-next` supplies the ISR-aware adapter.\n * Response DTOs are typed by the peer, type-only `@reblu/site-contracts`.\n */\nimport { PlainCacheAdapter, type RebluCacheAdapter } from './cache'\nimport type { RebluClientContext, RequestScope } from './client'\nimport { DEFAULT_CHECKOUT_REDIRECT_HOSTS } from './checkout-redirect'\nimport { makeAcademyNamespace } from './domains/academy'\nimport { makeAnalyticsNamespace } from './domains/analytics'\nimport { makeBlogNamespace } from './domains/blog'\nimport { makeConfigNamespace } from './domains/config'\nimport { makeContactFormNamespace } from './domains/contact-form'\nimport { makeCtasNamespace } from './domains/ctas'\nimport { makeDataRequestsNamespace } from './domains/data-requests'\nimport { makeLeadsNamespace } from './domains/leads'\nimport { makeLegalNamespace } from './domains/legal'\nimport { makePagesNamespace } from './domains/pages'\nimport { makeShopNamespace } from './domains/shop'\nimport { makeTrustBadgesNamespace } from './domains/trust-badges'\n\nconst DEFAULT_API_VERSION = '1'\n/** Parity with demo-site's upstream timeout (client.ts:36). */\nconst DEFAULT_TIMEOUT_MS = 8000\n\nexport interface RebluClientConfig {\n /** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */\n baseUrl: string\n /** Tenant SITE API key (`rbl_…`), sent as `X-Reblu-Api-Key`. */\n apiKey: string\n /** Contract version sent as `X-Reblu-Api-Version`. Defaults to `'1'`. */\n apiVersion?: string\n /** Cache strategy. Defaults to `new PlainCacheAdapter()` (no-store). */\n cache?: RebluCacheAdapter\n /** Per-request hard timeout in ms. Defaults to `8000`. */\n timeoutMs?: number\n /** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */\n fetch?: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth — see `./checkout-redirect`). Defaults to\n * `['checkout.stripe.com']`. Override only to point at a test double (e.g.\n * a Stripe CLI mock host) — never to widen production trust.\n */\n checkoutRedirectHosts?: string[]\n /**\n * REB-1214 — memo store of the current server request, so identical GET\n * reads within it are fetched once. In Next.js pass `rebluRequestScope`\n * from `@reblu/site-next` (React `cache()`); see the README. Without it,\n * identical GETs share one fetch only while in flight.\n */\n requestScope?: RequestScope\n}\n\n/**\n * Build a Reblu SITE API client. Each domain is a small namespace of bound\n * methods assembled from a separate module, so a consumer importing only a\n * couple of domains can tree-shake the rest.\n */\nexport function createRebluClient(config: RebluClientConfig) {\n // Wrap global fetch so calling `ctx.fetch()` never loses its `this` binding\n // (browsers throw \"Illegal invocation\" for an unbound `window.fetch`).\n const boundFetch: typeof fetch = config.fetch ?? ((input, init) => fetch(input, init))\n\n const ctx: RebluClientContext = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,\n cache: config.cache ?? new PlainCacheAdapter(),\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetch: boundFetch,\n checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n requestScope: config.requestScope,\n inFlight: new Map(),\n }\n\n return {\n config: makeConfigNamespace(ctx),\n analytics: makeAnalyticsNamespace(ctx),\n legal: makeLegalNamespace(ctx),\n trustBadges: makeTrustBadgesNamespace(ctx),\n ctas: makeCtasNamespace(ctx),\n blog: makeBlogNamespace(ctx),\n pages: makePagesNamespace(ctx),\n shop: makeShopNamespace(ctx),\n academy: makeAcademyNamespace(ctx),\n contactForm: makeContactFormNamespace(ctx),\n leads: makeLeadsNamespace(ctx),\n dataRequests: makeDataRequestsNamespace(ctx),\n }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError, AmbiguousPageSlugError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails, PageSlugCandidate } from './errors'\nexport type { PageBySlugOptions, FeaturedPagesOptions } from './domains/pages'\nexport type { TrustBadgeListParams } from './domains/trust-badges'\nexport {\n DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n isSafeCheckoutRedirectUrl,\n UnsafeCheckoutRedirectError,\n} from './checkout-redirect'\nexport { PlainCacheAdapter } from './cache'\nexport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nexport type {\n ListResult,\n BlogListParams,\n PagesListParams,\n ShopProductsParams,\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n} from './types'\nexport {\n VISITOR_IP_HEADER,\n visitorIpFromHeaders,\n RETRY_AFTER_CAP_MS,\n type RebluMutationOptions,\n type RequestScope,\n} from './client'\nexport {\n buildContactFormMetadata,\n currentPagePath,\n type ContactFormMetadata,\n type ContactFormMetadataOptions,\n type PageLocation,\n} from './contact-form-metadata'\n"]}
package/dist/index.d.cts CHANGED
@@ -445,6 +445,7 @@ declare function createRebluClient(config: RebluClientConfig): {
445
445
  bySlug: (slug: string, cache?: RebluCachePolicy) => Promise<_reblu_site_contracts.AcademyCourseDetail>;
446
446
  lessonPreview: (courseSlug: string, lessonSlug: string) => Promise<_reblu_site_contracts.AcademyLessonPreview>;
447
447
  instructors: (cache?: RebluCachePolicy) => Promise<ListResult<_reblu_site_contracts.AcademyInstructorPublic>>;
448
+ config: (cache?: RebluCachePolicy) => Promise<_reblu_site_contracts.AcademyConfigPublic>;
448
449
  categories: (cache?: RebluCachePolicy) => Promise<ListResult<_reblu_site_contracts.AcademyCategoryPublic>>;
449
450
  enrollmentRequest: (body: AcademyEnrollmentRequestInput, options?: RebluMutationOptions) => Promise<AcademyEnrollmentRequestResult>;
450
451
  };
package/dist/index.d.ts CHANGED
@@ -445,6 +445,7 @@ declare function createRebluClient(config: RebluClientConfig): {
445
445
  bySlug: (slug: string, cache?: RebluCachePolicy) => Promise<_reblu_site_contracts.AcademyCourseDetail>;
446
446
  lessonPreview: (courseSlug: string, lessonSlug: string) => Promise<_reblu_site_contracts.AcademyLessonPreview>;
447
447
  instructors: (cache?: RebluCachePolicy) => Promise<ListResult<_reblu_site_contracts.AcademyInstructorPublic>>;
448
+ config: (cache?: RebluCachePolicy) => Promise<_reblu_site_contracts.AcademyConfigPublic>;
448
449
  categories: (cache?: RebluCachePolicy) => Promise<ListResult<_reblu_site_contracts.AcademyCategoryPublic>>;
449
450
  enrollmentRequest: (body: AcademyEnrollmentRequestInput, options?: RebluMutationOptions) => Promise<AcademyEnrollmentRequestResult>;
450
451
  };
package/dist/index.js CHANGED
@@ -290,6 +290,13 @@ function makeAcademyNamespace(ctx) {
290
290
  instructors: (cache) => requestList(ctx, "/api/site/academy/instructors", {
291
291
  cachePolicy: cache
292
292
  }),
293
+ /**
294
+ * Tenant academy settings for the SITE (REB-1234). `catalogFilters` says
295
+ * which catalogue filters the tenant switched on in nexus — pass it as
296
+ * `enabled` to `CourseCatalogFilters` (`@reblu/site-blocks`). A filter the
297
+ * tenant never set comes back `true`.
298
+ */
299
+ config: (cache) => requestOne(ctx, "/api/site/academy/config", { cachePolicy: cache }),
293
300
  /** Active course categories backing the catalog filter. Not paginated. */
294
301
  categories: (cache) => requestList(ctx, "/api/site/academy/categories", {
295
302
  cachePolicy: cache
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cache.ts","../src/checkout-redirect.ts","../src/build-url.ts","../src/errors.ts","../src/client.ts","../src/domains/academy.ts","../src/domains/analytics.ts","../src/domains/blog.ts","../src/domains/config.ts","../src/domains/contact-form.ts","../src/domains/ctas.ts","../src/domains/data-requests.ts","../src/domains/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.ts","../src/contact-form-metadata.ts","../src/index.ts"],"names":[],"mappings":";AA0BO,IAAM,oBAAN,MAAqD;AAAA,EAC1D,WAAA,CAA6B,oBAAoC,KAAA,EAAO;AAA3C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA4C;AAAA,EAA5C,iBAAA;AAAA,EAE7B,mBAAmB,MAAA,EAAuC;AACxD,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,IAAA,CAAK,iBAAA;AAC7C,IAAA,OAAO,UAAA,KAAe,KAAA,IAAS,UAAA,KAAe,CAAA,G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kB,MAAA,EAA2B;AAG3D,EAAA,MAAM,UAAA,GAA2B,OAAO,KAAA,KAAU,CAAC,OAAO,IAAA,KAAS,KAAA,CAAM,OAAO,IAAI,CAAA,CAAA;AAEpF,EAAA,MAAM,GAAA,GAA0B;AAAA,IAC9B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,UAAA,EAAY,OAAO,UAAA,IAAc,mBAAA;AAAA,IACjC,KAAA,EAAO,MAAA,CAAO,KAAA,IAAS,IAAI,iBAAA,EAAkB;AAAA,IAC7C,SAAA,EAAW,OAAO,SAAA,IAAa,kBAAA;AAAA,IAC/B,KAAA,EAAO,UAAA;AAAA,IACP,qBAAA,EAAuB,OAAO,qBAAA,IAAyB,+BAAA;AAAA,IACvD,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,QAAA,sBAAc,GAAA;AAAI,GACpB;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,oBAAoB,GAAG,CAAA;AAAA,IAC/B,SAAA,EAAW,uBAAuB,GAAG,CAAA;AAAA,IACrC,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,WAAA,EAAa,yBAAyB,GAAG,CAAA;AAAA,IACzC,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,OAAA,EAAS,qBAAqB,GAAG,CAAA;AAAA,IACjC,WAAA,EAAa,yBAAyB,GAAG,CAAA;AAAA,IACzC,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,YAAA,EAAc,0BAA0B,GAAG;AAAA,GAC7C;AACF","file":"index.js","sourcesContent":["/**\n * Cache adapter — the seam that severs the SDK from any framework's caching\n * model (design doc D4 / §3.2). The client owns *when* to cache (a per-call\n * `RebluCachePolicy`); the adapter owns *how* (the framework-specific\n * `RequestInit` fields). `@reblu/site-client` ships the framework-agnostic\n * `PlainCacheAdapter`; `@reblu/site-next` (REB-418) supplies a `NextCacheAdapter`\n * that returns `{ next: { revalidate } }`.\n */\n\nexport interface RebluCachePolicy {\n /**\n * Seconds to revalidate. `undefined` → use the adapter's default; `0`/`false`\n * → never cache (always fetch fresh).\n */\n revalidate?: number | false\n}\n\nexport interface RebluCacheAdapter {\n /** Map a per-call cache policy to framework-specific `fetch` `RequestInit` fields. */\n resolveRequestInit(policy: RebluCachePolicy): RequestInit\n}\n\n/**\n * Default adapter — plain `fetch` cache semantics that work in Node, edge,\n * browser and tests. No `next`, no `server-only`.\n */\nexport class PlainCacheAdapter implements RebluCacheAdapter {\n constructor(private readonly defaultRevalidate: number | false = false) {}\n\n resolveRequestInit(policy: RebluCachePolicy): RequestInit {\n const revalidate = policy.revalidate ?? this.defaultRevalidate\n return revalidate === false || revalidate === 0\n ? { cache: 'no-store' }\n : { cache: 'force-cache' }\n }\n}\n","/**\n * Stripe Checkout redirect-origin guard (REB-836, defence in depth).\n *\n * `shop.checkout()` returns a URL every SITE immediately hands to\n * `window.location.assign(url)`. Nothing upstream of this SDK validated it\n * before REB-836 — a compromised/misconfigured base-api, a tampered\n * response, or a MITM proxy could have sent a buyer's browser anywhere.\n * `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses\n * to refuse an unsafe URL before ever returning it to the caller; a SITE's\n * `@reblu/site-next` Route Handler re-checks the SAME property server-side\n * (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an\n * independent copy — see that file's docblock for why it isn't a shared\n * import). Update both together if Stripe ever changes its Checkout host.\n */\n\n/** The only Checkout redirect host trusted by default. */\nexport const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[] = ['checkout.stripe.com']\n\n/**\n * True only when `url` parses as an absolute URL, uses `https:`, and its\n * hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).\n * Never throws — an unparsable `url` is simply unsafe.\n */\nexport function isSafeCheckoutRedirectUrl(\n url: string,\n allowedHosts: readonly string[] = DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n): boolean {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n return false\n }\n return parsed.protocol === 'https:' && allowedHosts.includes(parsed.hostname)\n}\n\n/**\n * Thrown by `shop.checkout()` when base-api's Checkout URL fails\n * {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back\n * to a caller that would otherwise `window.location.assign` it.\n */\nexport class UnsafeCheckoutRedirectError extends Error {\n constructor(\n public readonly url: string,\n public readonly allowedHosts: readonly string[],\n ) {\n super(\n `Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} ` +\n `(allowed hosts: ${allowedHosts.join(', ')})`,\n )\n this.name = 'UnsafeCheckoutRedirectError'\n }\n}\n","/** A value that can be serialized into a query string. */\nexport type QueryValue = string | number | boolean | undefined | null\n\n/**\n * Append a query string to `base`, dropping `undefined`/`null` values.\n *\n * Single definition for the whole client (design doc §3.1 dedupes the two copies\n * that lived in demo-site's `client.ts` and `index.ts`). Falsy-but-meaningful\n * values (`0`, `false`, `''`) are preserved; only `undefined`/`null` are omitted.\n * Array values (REB-475 faceted `attr[key]`) emit one repeated param per element.\n */\nexport function buildUrl(\n base: string,\n params?: Record<string, QueryValue | QueryValue[]>,\n): string {\n if (!params) return base\n const pairs: [string, string][] = []\n for (const [key, value] of Object.entries(params)) {\n const values = Array.isArray(value) ? value : [value]\n for (const v of values) {\n if (v === undefined || v === null) continue\n pairs.push([key, String(v)])\n }\n }\n if (pairs.length === 0) return base\n const qs = new URLSearchParams(pairs).toString()\n return `${base}?${qs}`\n}\n","/**\n * The `details` shape `/api/site/contact-form` and `/api/site/leads` attach on a\n * 400/422, straight from zod's `.flatten()` (see\n * `details: parsed.error.flatten()` in\n * `apps/base-api/src/lib/server/services/contact-form.service.ts:114` and\n * `apiError('Validation error', 422, parsed.error.flatten())` in\n * `apps/base-api/src/app/api/site/leads/route.ts:40`). `fieldErrors` is what a\n * SITE actually needs — REB-659's `details.fieldErrors.phone` — `formErrors` is\n * kept alongside it because `.flatten()` always emits both and dropping it would\n * silently discard form-level (non-field) messages.\n */\nexport interface ApiErrorDetails {\n fieldErrors?: Record<string, string[]>\n formErrors?: string[]\n /**\n * REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /\n * `PRICE_CHANGED` error — see `ApiErrorBody.code`.\n */\n productIds?: string[]\n /** REB-842: optional request-field identifier for checkout validation errors. */\n field?: string\n}\n\n/**\n * The parsed shape of a non-2xx SITE API response body: `{ error, details? }`\n * (see `apiError()` in `apps/base-api/src/lib/api/response.ts:33` — the general\n * shape both routes above build on).\n */\nexport interface ApiErrorBody {\n error: string\n details?: ApiErrorDetails\n /**\n * REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from\n * `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write\n * endpoints may set — additive and OPTIONAL, so a consumer that only reads\n * `error`/`message` keeps working unchanged. `string` rather than\n * `ShopErrorCode` here because `ApiError` is a generic transport error used\n * by every `/api/site/*` domain, not just shop.\n */\n code?: string\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string')\n}\n\n/**\n * Validates `ApiErrorDetails` deeply — `fieldErrors` must be a record whose\n * values are `string[] | undefined`, `formErrors` (if present) must be\n * `string[]`, and `field` (if present) must be a string. Without this, a body like\n * `{ fieldErrors: { phone: \"abc\" } }` passed the old shallow check, so\n * `body.details?.fieldErrors?.phone?.[0]` silently returned the character\n * `\"a\"` instead of a validation message (REB-764 review finding).\n */\nfunction isApiErrorDetails(value: unknown): value is ApiErrorDetails {\n if (typeof value !== 'object' || value === null) return false\n const details = value as {\n fieldErrors?: unknown\n formErrors?: unknown\n productIds?: unknown\n field?: unknown\n }\n\n if (details.fieldErrors !== undefined) {\n if (\n typeof details.fieldErrors !== 'object' ||\n details.fieldErrors === null ||\n Array.isArray(details.fieldErrors)\n ) {\n return false\n }\n for (const fieldValue of Object.values(details.fieldErrors as Record<string, unknown>)) {\n if (fieldValue !== undefined && !isStringArray(fieldValue)) return false\n }\n }\n\n if (details.formErrors !== undefined && !isStringArray(details.formErrors)) return false\n\n // REB-836: STOCK_CHANGED/PRICE_CHANGED carry the affected product ids here.\n if (details.productIds !== undefined && !isStringArray(details.productIds)) return false\n if ('field' in details && typeof details.field !== 'string') return false\n\n return true\n}\n\n/**\n * `details`, when present, must match `ApiErrorDetails` deeply — an\n * unrecognised `details` shape makes the whole body unrecognised (`body`\n * stays `undefined`), the stricter reading consistent with\n * `parseApiErrorBody`'s existing all-or-nothing semantics: a body is either\n * shaped like `ApiErrorBody` or it isn't. Silently dropping a malformed\n * `details` instead would let a consumer treat a schema-drifted or corrupted\n * response as merely detail-less, hiding the mismatch rather than surfacing\n * it as \"unparseable\" (REB-764 review finding).\n */\nfunction isApiErrorBody(value: unknown): value is ApiErrorBody {\n if (typeof value !== 'object' || value === null) return false\n const body = value as { error?: unknown; details?: unknown; code?: unknown }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) return false\n // REB-836: `code` must be a string when present — same all-or-nothing\n // reading as `details` above (an unrecognised shape makes the whole body\n // unrecognised, never silently dropped).\n if (body.code !== undefined && typeof body.code !== 'string') return false\n return true\n}\n\n/**\n * Parses `rawBody` (the exact text `message` is built from) into a typed\n * `ApiErrorBody`, or `undefined` when it is not JSON, or JSON that does not\n * match the expected shape — an edge proxy 502 returns HTML, and this must\n * never throw while constructing the error it is reporting.\n */\nfunction parseApiErrorBody(rawBody: string): ApiErrorBody | undefined {\n if (!rawBody) return undefined\n try {\n const parsed: unknown = JSON.parse(rawBody)\n return isApiErrorBody(parsed) ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Typed transport error for the Reblu SITE API.\n *\n * Every non-2xx response throws an `ApiError` (never a bare `fetch` rejection),\n * so consumers can `catch (e) { if (e instanceof ApiError) … }` and fall back\n * gracefully (e.g. render an empty section) — the one behavioural contract the\n * SITE relies on. Moved verbatim from demo-site's `client.ts` (design doc §3.4).\n */\nexport class ApiError extends Error {\n /**\n * The parsed response body, when it was JSON shaped like `{ error, details? }`\n * (REB-764). `undefined` when the body was not JSON or didn't match — parsing\n * is defensive and never throws. Read `body.details?.fieldErrors?.phone`\n * instead of regex-stripping this error's `message`.\n */\n public readonly body: ApiErrorBody | undefined\n\n constructor(\n public readonly status: number,\n public readonly path: string,\n message: string,\n ) {\n super(`API ${status} @ ${path}: ${message}`)\n this.name = 'ApiError'\n this.body = parseApiErrorBody(message)\n }\n}\n\n/** One page a slug could mean (REB-867) — `null` = the uncategorised page. */\nexport interface PageSlugCandidate {\n categorySlug: string | null\n}\n\nfunction parseCandidates(rawBody: string): PageSlugCandidate[] {\n try {\n const parsed = JSON.parse(rawBody) as { candidates?: unknown }\n if (!Array.isArray(parsed.candidates)) return []\n return parsed.candidates.flatMap((c: unknown) => {\n const slug = (c as { categorySlug?: unknown } | null)?.categorySlug\n return typeof slug === 'string' || slug === null ? [{ categorySlug: slug }] : []\n })\n } catch {\n return []\n }\n}\n\n/**\n * REB-867 — `GET /api/site/pages/[slug]` answered 409 `ambiguous_slug`: page\n * slugs are unique PER CATEGORY and this one exists in more than one, so the\n * server refused to pick. Retry with `pages.bySlug(slug, { category })` using\n * one of `candidates`. Extends `ApiError`, so an existing\n * `catch (e) { if (e instanceof ApiError) … }` keeps handling it.\n */\nexport class AmbiguousPageSlugError extends ApiError {\n public readonly candidates: PageSlugCandidate[]\n\n constructor(source: ApiError, rawBody: string) {\n super(source.status, source.path, rawBody)\n this.name = 'AmbiguousPageSlugError'\n this.candidates = parseCandidates(rawBody)\n }\n}\n\n/** The raw body an `ApiError` was built from (its message minus the prefix). */\nexport function apiErrorRawBody(error: ApiError): string {\n const prefix = `API ${error.status} @ ${error.path}: `\n return error.message.startsWith(prefix) ? error.message.slice(prefix.length) : error.message\n}\n","import type { PaginationMeta } from '@reblu/site-contracts'\nimport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nimport { ApiError } from './errors'\nimport type { ListResult } from './types'\n\n/**\n * Resolved, immutable client context threaded into every domain namespace. Built\n * once by `createRebluClient` from the consumer's config — the SDK never reads\n * `process.env`, so the consumer owns `baseUrl`/`apiKey` (design doc §3.3).\n */\nexport interface RebluClientContext {\n baseUrl: string\n apiKey: string\n apiVersion: string\n cache: RebluCacheAdapter\n timeoutMs: number\n fetch: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth). Defaults to\n * `DEFAULT_CHECKOUT_REDIRECT_HOSTS` (`['checkout.stripe.com']`) — tests\n * inject a different value via `RebluClientConfig.checkoutRedirectHosts`.\n */\n checkoutRedirectHosts: readonly string[]\n /**\n * REB-1214 — returns the memo store of the CURRENT server request, so\n * identical GET reads within it are fetched once (e.g. `generateMetadata`\n * and the page body). `@reblu/site-next` supplies one backed by React\n * `cache()` (`rebluRequestScope`). Absent, or returning `undefined`,\n * identical GETs still share one fetch while they are in flight.\n */\n requestScope?: RequestScope\n /** In-flight GETs when no request scope is active. Created by `createRebluClient`. */\n inFlight?: Map<string, Promise<unknown>>\n}\n\n/** Memo store of one server request, keyed by read identity (REB-1214). */\nexport type RequestScope = () => Map<string, Promise<unknown>> | undefined\n\n/** Upper bound for a `Retry-After` wait before the single retry (REB-1214). */\nexport const RETRY_AFTER_CAP_MS = 2000\n/** Wait before the single retry when `Retry-After` is absent or unparseable. */\nexport const DEFAULT_RETRY_DELAY_MS = 250\n/** Statuses that mean \"try again shortly\" for a read. */\nconst RETRYABLE_READ_STATUSES = new Set([429, 503])\n\n/** `Retry-After` (seconds or HTTP date) → ms, capped; default when unusable. */\nfunction retryDelayMs(header: string | null): number {\n if (header !== null && header.trim() !== '') {\n const value = header.trim()\n const seconds = /^\\d+$/.test(value) ? Number(value) * 1000 : NaN\n const ms = Number.isFinite(seconds) ? seconds : Date.parse(value) - Date.now()\n if (Number.isFinite(ms)) return Math.min(Math.max(0, ms), RETRY_AFTER_CAP_MS)\n }\n return DEFAULT_RETRY_DELAY_MS\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/** Per-call request options. `cachePolicy` is interpreted by the cache adapter. */\nexport interface RequestOptions {\n method?: string\n body?: string\n headers?: Record<string, string>\n cachePolicy?: RebluCachePolicy\n}\n\n/**\n * Core transport (design doc §3.4). Injects the auth + contract-version headers,\n * merges the adapter's cache `RequestInit`, enforces a hard timeout per attempt,\n * throws a typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n *\n * REB-1214 — GET reads only: identical reads are deduped (see\n * `RebluClientContext.requestScope`) and a 429/503 is retried once after\n * `Retry-After`, capped at {@link RETRY_AFTER_CAP_MS}. If the retry fails too,\n * the second response's `ApiError` is thrown — the same type as before.\n * Writes are never deduped nor retried.\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const method = opts.method ?? 'GET'\n const init: RequestInit = {\n method,\n body: opts.body,\n headers: {\n 'X-Reblu-Api-Key': ctx.apiKey,\n 'X-Reblu-Api-Version': ctx.apiVersion,\n 'Content-Type': 'application/json',\n ...opts.headers,\n },\n ...ctx.cache.resolveRequestInit(opts.cachePolicy ?? {}),\n }\n if (method !== 'GET' || opts.body !== undefined) {\n return attempt<T>(ctx, path, init)\n }\n\n // REB-1214 — a read is identified by everything that shapes its response:\n // URL, headers and the resolved cache init. Kept for the whole request when\n // a scope is active; otherwise only while in flight.\n const key = JSON.stringify([ctx.baseUrl + path, init])\n const scope = ctx.requestScope?.()\n const store = scope ?? ctx.inFlight\n const existing = store?.get(key)\n if (existing) return existing as Promise<T>\n\n const pending = readWithRetry<T>(ctx, path, init)\n if (store) {\n store.set(key, pending)\n // A failure is never memoised; without a scope nothing outlives the fetch.\n pending.then(\n () => {\n if (!scope) store.delete(key)\n },\n () => {\n if (store.get(key) === pending) store.delete(key)\n },\n )\n }\n return pending\n}\n\n/** A GET answered 429/503 is retried once after `Retry-After` (capped). */\nasync function readWithRetry<T>(\n ctx: RebluClientContext,\n path: string,\n init: RequestInit,\n): Promise<T> {\n try {\n return await attempt<T>(ctx, path, init)\n } catch (error) {\n if (!(error instanceof RetryableReadError)) throw error\n await sleep(retryDelayMs(error.retryAfter))\n try {\n return await attempt<T>(ctx, path, init)\n } catch (retryError) {\n throw retryError instanceof RetryableReadError ? retryError.apiError : retryError\n }\n }\n}\n\n/** Internal carrier: a retryable read status plus the `ApiError` to throw if it persists. */\nclass RetryableReadError extends Error {\n constructor(\n readonly apiError: ApiError,\n readonly retryAfter: string | null,\n ) {\n super(apiError.message)\n }\n}\n\n/**\n * One HTTP attempt: enforces the hard timeout via `AbortController`, throws a\n * typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n */\nasync function attempt<T>(ctx: RebluClientContext, path: string, init: RequestInit): Promise<T> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(ctx.baseUrl + path, { ...init, signal: controller.signal })\n\n if (!res.ok) {\n const error = new ApiError(res.status, path, await res.text())\n if (init.method === 'GET' && RETRYABLE_READ_STATUSES.has(res.status)) {\n throw new RetryableReadError(error, res.headers.get('retry-after'))\n }\n throw error\n }\n return (await res.json()) as T\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch a single resource and unwrap the `{ data: T }` envelope. */\nexport async function requestOne<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const body = await request<{ data: T }>(ctx, path, opts)\n return body.data\n}\n\n/** Fetch a list resource, returning the `{ data, meta }` envelope (meta preserved). */\nexport async function requestList<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<ListResult<T>> {\n const body = await request<{ data: T[]; meta?: PaginationMeta }>(ctx, path, opts)\n return { data: body.data, meta: body.meta }\n}\n\n/**\n * Header carrying the visitor IP from a SITE server to base-api (REB-1005).\n * base-api keys its per-visitor limit on public writes on it, and trusts it\n * only behind a valid API key.\n */\nexport const VISITOR_IP_HEADER = 'x-reblu-visitor-ip'\n\n/**\n * Per-call options for a write (REB-1005).\n *\n * - `visitorIp` — the visitor's IP when a SITE calls the SDK server-side, sent\n * as `x-reblu-visitor-ip`. Do NOT rely on forwarding `x-forwarded-for`: on\n * Vercel the SITE→base-api hop gets it overwritten with the SITE function's\n * egress IP. Read it from the INCOMING request with\n * {@link visitorIpFromHeaders}.\n * - `headers` — other extra headers (e.g. `user-agent`). They can never set\n * `x-reblu-visitor-ip` nor replace `X-Reblu-Api-Key`, `X-Reblu-Api-Version`\n * or `Content-Type`.\n */\nexport interface RebluMutationOptions {\n visitorIp?: string\n headers?: Record<string, string>\n}\n\n/** The visitor IP of an incoming request: first `x-forwarded-for` entry, else `x-real-ip`. */\nexport function visitorIpFromHeaders(headers: {\n get(name: string): string | null\n}): string | undefined {\n return (\n headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||\n headers.get('x-real-ip')?.trim() ||\n undefined\n )\n}\n\n/** Headers the SDK owns on every request — an extra header never sets or overrides these. */\nconst RESERVED_HEADERS = new Set([\n 'x-reblu-api-key',\n 'x-reblu-api-version',\n 'content-type',\n VISITOR_IP_HEADER,\n])\n\n/**\n * The extra headers a write sends for `options`: caller headers minus the\n * reserved ones, plus `x-reblu-visitor-ip` from `visitorIp`. Shared by\n * {@link requestMutation} and the writes that cannot use it (academy).\n */\nexport function extraHeaders(\n options: RebluMutationOptions | undefined,\n): Record<string, string> | undefined {\n if (!options?.headers && !options?.visitorIp) return undefined\n const safe: Record<string, string> = {}\n for (const [name, value] of Object.entries(options.headers ?? {})) {\n if (!RESERVED_HEADERS.has(name.toLowerCase())) safe[name] = value\n }\n const visitorIp = options.visitorIp?.trim()\n if (visitorIp) safe[VISITOR_IP_HEADER] = visitorIp\n return safe\n}\n\n/**\n * POST a mutation: serialize `body` to JSON, force a cache bypass (`revalidate:\n * false` → `no-store` regardless of the injected adapter, since a mutation must\n * never be served from cache), then unwrap the `{ data: T }` envelope. Mirrors\n * every `/api/site/*` write route, which answers with `apiOk`/`{ data }`.\n */\nexport async function requestMutation<Req, Res>(\n ctx: RebluClientContext,\n path: string,\n body: Req,\n options?: RebluMutationOptions,\n): Promise<Res> {\n const headers = extraHeaders(options)\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n AcademyInstructorPublic,\n AcademyLessonPreview,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n extraHeaders,\n request,\n requestList,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport type {\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n ListResult,\n} from '../types'\n\n/**\n * Academy domain — the public course catalogue (`GET /api/site/academy/*`,\n * REB-528 / REB-534) plus the anonymous enrollment request (REB-496). The reads\n * are published-filtered server-side, so nothing here needs an entitlement\n * notion; the one write is unauthenticated by design.\n *\n * `enrollmentRequest` drops to the raw `request()` transport rather than\n * `requestMutation` (REB-584). The route answers with a BARE `{ message }`, not\n * the `{ data }` envelope every other write uses, so `requestMutation` would\n * unwrap a missing `.data` and hand the caller `undefined`. Normalizing the\n * route's envelope instead was rejected: its response shape is load-bearing\n * anti-enumeration behaviour, and changing it would ripple into base-api tests\n * for no gain on the SITE side.\n */\nexport function makeAcademyNamespace(ctx: RebluClientContext) {\n return {\n /** Published courses, filtered + paginated. `meta` carries the pagination. */\n courses: (\n params?: AcademyCourseListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<AcademyCourseSummary>> =>\n requestList<AcademyCourseSummary>(\n ctx,\n buildUrl('/api/site/academy/courses', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n /** A single published course by slug, with its modules, lessons and CTA gate. */\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<AcademyCourseDetail> =>\n requestOne<AcademyCourseDetail>(ctx, `/api/site/academy/courses/${slug}`, {\n cachePolicy: cache,\n }),\n\n /**\n * A free-preview lesson, viewable by the public (REB-1135): title, duration,\n * Markdown body and a ready-to-embed video. Any lesson the public may not see\n * is a uniform 404 (`ApiError`). Never cached: the payload carries a\n * short-lived signed playback token. Server-side, prefer `getLessonPreview`\n * from `@reblu/site-next/academy-server`, which maps that 404 to `null`.\n */\n lessonPreview: (courseSlug: string, lessonSlug: string): Promise<AcademyLessonPreview> =>\n requestOne<AcademyLessonPreview>(\n ctx,\n `/api/site/academy/courses/${encodeURIComponent(courseSlug)}/lessons/${encodeURIComponent(lessonSlug)}`,\n { cachePolicy: { revalidate: false } },\n ),\n\n /**\n * Instructors of published courses, sorted by name, backing the catalog\n * instructor filter (REB-547). Pass an `id` as `courses({ instructor })`.\n * Not paginated.\n */\n instructors: (cache?: RebluCachePolicy): Promise<ListResult<AcademyInstructorPublic>> =>\n requestList<AcademyInstructorPublic>(ctx, '/api/site/academy/instructors', {\n cachePolicy: cache,\n }),\n\n /** Active course categories backing the catalog filter. Not paginated. */\n categories: (cache?: RebluCachePolicy): Promise<ListResult<AcademyCategoryPublic>> =>\n requestList<AcademyCategoryPublic>(ctx, '/api/site/academy/categories', {\n cachePolicy: cache,\n }),\n\n /**\n * Submit an anonymous enrollment request for a course.\n *\n * The reply is UNIFORM by design: the caller cannot tell whether the email\n * was new (a request row was created) or already known (a sign-in link was\n * sent and NO request row exists). Never present the returned message as\n * confirmation that a request was recorded — it is not one.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n options?: RebluMutationOptions,\n ): Promise<AcademyEnrollmentRequestResult> => {\n const headers = extraHeaders(options)\n return request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n },\n }\n}\n","import type { Analytics } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/analytics` — the tenant's analytics provider configuration. */\nexport function makeAnalyticsNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Analytics> =>\n requestOne<Analytics>(ctx, '/api/site/analytics', { cachePolicy: cache }),\n }\n}\n","import type {\n BlogCategoryWithCount,\n BlogPostDetail,\n BlogPostListItem,\n BlogPostPreview,\n BlogSlug,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport type { BlogListParams, ListResult } from '../types'\n\n/** Blog domain — `GET /api/site/blog/*`. */\nexport function makeBlogNamespace(ctx: RebluClientContext) {\n return {\n list: (\n params?: BlogListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(\n ctx,\n buildUrl('/api/site/blog', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<BlogPostDetail> =>\n requestOne<BlogPostDetail>(ctx, `/api/site/blog/${slug}`, { cachePolicy: cache }),\n\n related: (slug: string, cache?: RebluCachePolicy): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(ctx, `/api/site/blog/${slug}/related`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<BlogCategoryWithCount>> =>\n requestList<BlogCategoryWithCount>(ctx, '/api/site/blog/categories', { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<BlogSlug>> =>\n requestList<BlogSlug>(ctx, '/api/site/blog/slugs', { cachePolicy: cache }),\n\n /** Draft preview — never cached (unpublished content). */\n preview: (id: string): Promise<BlogPostPreview> =>\n requestOne<BlogPostPreview>(ctx, `/api/site/blog/preview/${id}`, {\n cachePolicy: { revalidate: false },\n }),\n }\n}\n","import type { Config } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/config` — the tenant's public site configuration. */\nexport function makeConfigNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Config> =>\n requestOne<Config>(ctx, '/api/site/config', { cachePolicy: cache }),\n }\n}\n","import type { ContactFormInput, ContactFormSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * Contact form domain — WRITE only (`POST /api/site/contact-form`, REB-438).\n * Posts a body typed by `@reblu/site-contracts` and bypasses the cache; returns\n * the created lead's id + creation timestamp.\n */\nexport function makeContactFormNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a contact form. Returns the created lead acknowledgement.\n * Server-side (a Server Action / Route Handler), pass `options.visitorIp`\n * (from the incoming request, see `visitorIpFromHeaders`) so base-api's\n * per-IP limit (REB-1005) applies to the real visitor.\n */\n submit: (\n body: ContactFormInput,\n options?: RebluMutationOptions,\n ): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(\n ctx,\n '/api/site/contact-form',\n body,\n options,\n ),\n }\n}\n","import type { Cta } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/**\n * `GET /api/site/ctas?slot=…` — editable CTAs for a given slot.\n *\n * `slot` is typed as `string` on purpose: the slot enum lives in base-api's\n * `validations/` (not the response contracts), so `@reblu/site-contracts` does\n * not export it. Keeping it a `string` avoids duplicating (and drifting from)\n * the server-owned enum. The server validates the slot.\n */\nexport function makeCtasNamespace(ctx: RebluClientContext) {\n return {\n list: (slot: string, cache?: RebluCachePolicy): Promise<ListResult<Cta>> =>\n requestList<Cta>(ctx, buildUrl('/api/site/ctas', { slot }), { cachePolicy: cache }),\n }\n}\n","import type { DataRequestInput, DataRequestSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * GDPR data-subject requests domain — WRITE only (`POST /api/site/data-requests`,\n * REB-77 endpoint / REB-980 SDK). Posts the public rights-form body typed by\n * `@reblu/site-contracts`, bypasses the cache, and returns the request id, when\n * it was received and the 72h deadline (`slaDueAt`) it is now held to.\n *\n * base-api requires a reCAPTCHA v3 token (`captcha`) and rate-limits per tenant\n * and per visitor IP (REB-1005); a rejection surfaces as an `ApiError` carrying\n * the upstream `status` (400 validation, 422 captcha, 429 rate limit).\n */\nexport function makeDataRequestsNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a data-subject request. Returns its acknowledgement with the 72h\n * deadline. Server-side, pass `options.visitorIp` (from the incoming\n * request, see `visitorIpFromHeaders`) so base-api's per-IP limit\n * (REB-1005) sees the real visitor.\n */\n submit: (\n body: DataRequestInput,\n options?: RebluMutationOptions,\n ): Promise<DataRequestSubmission> =>\n requestMutation<DataRequestInput, DataRequestSubmission>(\n ctx,\n '/api/site/data-requests',\n body,\n options,\n ),\n }\n}\n","import type { LeadInput, LeadSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext } from '../client'\n\n/**\n * Leads domain — WRITE only (`POST /api/site/leads`, REB-438). The generic\n * lead-ingestion endpoint: posts a body typed by `@reblu/site-contracts`,\n * bypasses the cache, and returns the created lead's id + creation timestamp.\n */\nexport function makeLeadsNamespace(ctx: RebluClientContext) {\n return {\n /** Create a lead. Returns the created lead acknowledgement. */\n create: (body: LeadInput): Promise<LeadSubmission> =>\n requestMutation<LeadInput, LeadSubmission>(ctx, '/api/site/leads', body),\n }\n}\n","import type { Legal } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/legal` — the tenant's legal content (privacy, terms, cookies). */\nexport function makeLegalNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Legal> =>\n requestOne<Legal>(ctx, '/api/site/legal', { cachePolicy: cache }),\n }\n}\n","import type { PageDetail, PageListItem, PageSlug } from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport { AmbiguousPageSlugError, ApiError, apiErrorRawBody } from '../errors'\nimport type { ListResult, PagesListParams } from '../types'\n\n/**\n * REB-867 — options for `pages.bySlug`. Page slugs are unique PER CATEGORY:\n * - `category: '<categorySlug>'` → the page with that slug in that category;\n * - `category: null` → the UNCATEGORISED page with that slug;\n * - omitted → the unique page with that slug; throws\n * `AmbiguousPageSlugError` when it exists in more than one category.\n */\nexport interface PageBySlugOptions {\n category?: string | null\n cache?: RebluCachePolicy\n}\n\n/**\n * The two second-argument shapes share no key: a `RebluCachePolicy` only ever\n * has `revalidate`, `PageBySlugOptions` only `category`/`cache`. So the\n * presence of `category` or `cache` (even `category: undefined`) selects the\n * options form; anything else — including `{}` — is a cache policy, exactly as\n * before REB-867.\n */\n/** REB-869 — options for `pages.featured`. */\nexport interface FeaturedPagesOptions {\n /**\n * How many pages at most: an integer >= 1. Default 3. Values above the\n * server's cap (3) are clamped to 3; anything else invalid (0, negative,\n * fractional, NaN) throws a `RangeError` before any request is made.\n */\n limit?: number\n /**\n * When the category has nothing featured, return its first `limit` pages in\n * normal order instead of `[]`. Default `true`, so a teaser is never empty\n * just because nobody picked pages yet.\n */\n fallback?: boolean\n cache?: RebluCachePolicy\n}\n\n/** The server caps a featured list at 3 (REB-869). */\nconst FEATURED_PAGES_MAX = 3\n\nfunction isBySlugOptions(value: RebluCachePolicy | PageBySlugOptions): value is PageBySlugOptions {\n return 'category' in value || 'cache' in value\n}\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n const namespace = {\n list: (\n params?: PagesListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<PageListItem>> =>\n requestList<PageListItem>(\n ctx,\n // REB-63: `type` can now be a single PageType or an array (repeated\n // `?type=` params) — widen the cast alongside `PagesListParams`.\n buildUrl('/api/site/pages', params as Record<string, QueryValue | QueryValue[]> | undefined),\n { cachePolicy: cache },\n ),\n\n /**\n * A published page by slug. The second argument is either a cache policy\n * (backward-compatible) or {@link PageBySlugOptions} (REB-867).\n */\n bySlug: async (\n slug: string,\n cacheOrOptions?: RebluCachePolicy | PageBySlugOptions,\n ): Promise<PageDetail> => {\n const options: PageBySlugOptions =\n cacheOrOptions && isBySlugOptions(cacheOrOptions)\n ? cacheOrOptions\n : { cache: cacheOrOptions }\n const path =\n options.category === undefined\n ? `/api/site/pages/${slug}`\n : buildUrl(`/api/site/pages/${slug}`, { category: options.category ?? '' })\n try {\n return await requestOne<PageDetail>(ctx, path, { cachePolicy: options.cache })\n } catch (error) {\n if (error instanceof ApiError && error.status === 409 && error.body?.code === 'ambiguous_slug') {\n throw new AmbiguousPageSlugError(error, apiErrorRawBody(error))\n }\n throw error\n }\n },\n\n /**\n * REB-869 — the pages to show in a category teaser: the category's\n * featured pages in the tenant's order; when none are featured (and\n * `fallback` is not `false`), the first `limit` pages of the category in\n * normal order. Returns the items only (no pagination applies).\n */\n featured: async (\n category: string,\n { limit: requested = FEATURED_PAGES_MAX, fallback = true, cache }: FeaturedPagesOptions = {},\n ): Promise<PageListItem[]> => {\n if (!Number.isInteger(requested) || requested < 1) {\n throw new RangeError(`pages.featured: limit must be an integer >= 1 (got ${requested})`)\n }\n const limit = Math.min(requested, FEATURED_PAGES_MAX)\n const featured = await namespace.list({ category, featured: true }, cache)\n if (featured.data.length > 0 || !fallback) return featured.data.slice(0, limit)\n const first = await namespace.list({ category, pageSize: limit }, cache)\n return first.data.slice(0, limit)\n },\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\n return namespace\n}\n","import type {\n ShopApplyDiscountInput,\n ShopCartValidation,\n ShopCategory,\n ShopCheckEmailInput,\n ShopCheckoutInput,\n ShopCheckoutSession,\n ShopConfig,\n ShopDiscountApplication,\n ShopEmailCheck,\n ShopFacets,\n ShopOrder,\n ShopProductDetail,\n ShopProductListItem,\n ShopValidateCartInput,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n requestList,\n requestMutation,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport { isSafeCheckoutRedirectUrl, UnsafeCheckoutRedirectError } from '../checkout-redirect'\nimport type { ListResult, ShopProductsParams } from '../types'\n\n/**\n * Flatten `ShopProductsParams` into a query record: scalars pass through; the\n * `taxonomy`/`attr` maps become repeatable `taxonomy[key]`/`attr[key]` params.\n * Array attr values repeat the same bracket key.\n */\nfunction flattenShopParams(params?: ShopProductsParams): Record<string, QueryValue | QueryValue[]> {\n if (!params) return {}\n const { taxonomy, attr, ...scalars } = params\n const out: Record<string, QueryValue | QueryValue[]> = { ...scalars }\n if (taxonomy) {\n for (const [key, value] of Object.entries(taxonomy)) out[`taxonomy[${key}]`] = value\n }\n if (attr) {\n for (const [key, value] of Object.entries(attr)) out[`attr[${key}]`] = value\n }\n return out\n}\n\n/**\n * Shop domain — READ surface (`GET /api/site/shop/*`) plus the mutation flow\n * (`POST` checkout, validate-cart, apply-discount, and the deprecated\n * check-email) added in REB-438. Every write posts a body typed by `@reblu/site-contracts` and bypasses\n * the cache. Request/response DTOs live in the contracts package (zero Zod).\n */\nexport function makeShopNamespace(ctx: RebluClientContext) {\n return {\n products: (\n params?: ShopProductsParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<ShopProductListItem>> =>\n requestList<ShopProductListItem>(\n ctx,\n buildUrl('/api/site/shop/products', flattenShopParams(params)),\n { cachePolicy: cache },\n ),\n\n /** Available facets (brand/attributes/price/on-sale) for the given filters. */\n facets: (params?: ShopProductsParams, cache?: RebluCachePolicy): Promise<ShopFacets> =>\n requestOne<ShopFacets>(ctx, buildUrl('/api/site/shop/facets', flattenShopParams(params)), {\n cachePolicy: cache,\n }),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<ShopProductDetail> =>\n requestOne<ShopProductDetail>(ctx, `/api/site/shop/products/${slug}`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<ShopCategory>> =>\n requestList<ShopCategory>(ctx, '/api/site/shop/categories', { cachePolicy: cache }),\n\n config: (cache?: RebluCachePolicy): Promise<ShopConfig> =>\n requestOne<ShopConfig>(ctx, '/api/site/shop/config', { cachePolicy: cache }),\n\n // ── Mutations (REB-438) ──────────────────────────────────────────────────\n\n /**\n * Start a hosted checkout session. Returns the Stripe URL + session id.\n *\n * REB-836 (defence in depth): every SITE hands `url` straight to\n * `window.location.assign`, so this validates it is `https:` on an\n * allowed host (`ctx.checkoutRedirectHosts`, default\n * `checkout.stripe.com`) BEFORE returning — throwing\n * {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL\n * that could redirect a buyer's browser off Stripe's domain.\n */\n checkout: async (body: ShopCheckoutInput): Promise<ShopCheckoutSession> => {\n const session = await requestMutation<ShopCheckoutInput, ShopCheckoutSession>(\n ctx,\n '/api/site/shop/checkout',\n body,\n )\n if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {\n throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts)\n }\n return session\n },\n\n /** Validate a cart against live product/stock/price state before checkout. */\n validateCart: (body: ShopValidateCartInput): Promise<ShopCartValidation> =>\n requestMutation<ShopValidateCartInput, ShopCartValidation>(\n ctx,\n '/api/site/shop/validate-cart',\n body,\n ),\n\n /** Validate a discount code against the current cart subtotal. */\n applyDiscount: (body: ShopApplyDiscountInput): Promise<ShopDiscountApplication> =>\n requestMutation<ShopApplyDiscountInput, ShopDiscountApplication>(\n ctx,\n '/api/site/shop/apply-discount',\n body,\n ),\n\n /**\n * @deprecated REB-834 — the endpoint no longer reveals whether an account\n * exists: it always resolves `{ exists: false }`. Do not call it and never\n * branch UI on `exists`; the checkout always offers «Iniciar sesión o\n * continuar como invitado» and the server links the order to an existing\n * account after payment. Removed in the next major.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n checkEmail: (\n body: ShopCheckEmailInput,\n options?: RebluMutationOptions,\n ): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(\n ctx,\n '/api/site/shop/check-email',\n body,\n options,\n ),\n\n /**\n * Look up a confirmed (or still-pending) order by its Stripe Checkout\n * session id — the order-confirmation flow (REB-829). `GET`, so it goes\n * through `requestOne` like every other read, not `requestMutation`.\n */\n order: (sessionId: string, cache?: RebluCachePolicy): Promise<ShopOrder> =>\n requestOne<ShopOrder>(ctx, `/api/site/shop/order/${encodeURIComponent(sessionId)}`, {\n cachePolicy: cache,\n }),\n }\n}\n","import type { TrustBadge, TrustBadgeType } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** Filters for {@link makeTrustBadgesNamespace}'s `list` (REB-996). */\nexport interface TrustBadgeListParams {\n /** Only badges of this type (e.g. `'SUBVENTION'`). Omit for every type. */\n type?: TrustBadgeType\n}\n\nfunction isCachePolicy(value: TrustBadgeListParams | RebluCachePolicy): value is RebluCachePolicy {\n return Object.prototype.hasOwnProperty.call(value, 'revalidate')\n}\n\n/**\n * `GET /api/site/trust-badges` — the tenant's PUBLIC trust badges (no\n * pagination): active in nexus and inside their optional validity window, so\n * expiring or switching one off needs no SITE change.\n */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n function list(cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>>\n function list(\n params: TrustBadgeListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>>\n function list(\n paramsOrCache?: TrustBadgeListParams | RebluCachePolicy,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>> {\n // `list(cache)` is the pre-REB-996 call shape — kept so this stays a minor.\n const legacyCache = paramsOrCache && isCachePolicy(paramsOrCache) ? paramsOrCache : undefined\n const params = legacyCache ? undefined : (paramsOrCache as TrustBadgeListParams | undefined)\n return requestList<TrustBadge>(\n ctx,\n buildUrl('/api/site/trust-badges', { type: params?.type }),\n { cachePolicy: legacyCache ?? cache },\n )\n }\n return { list }\n}\n","import type { ContactFormInput } from '@reblu/site-contracts'\n\n/**\n * REB-1077 — the `metadata` block of a contact-form submission, built from the\n * page the visitor is on so a SITE never hand-codes `fromPage`.\n *\n * Call it in the browser, at submit time (inside the form's submit handler):\n * it reads `globalThis.location` unless a `location` is passed.\n */\n\n/** The part of `window.location` these helpers read. */\nexport interface PageLocation {\n pathname: string\n href?: string\n}\n\nexport type ContactFormMetadata = ContactFormInput['metadata']\n\nexport interface ContactFormMetadataOptions {\n /**\n * Explicit page path, overriding the one read from the location (e.g. a\n * modal form that wants to report the landing it belongs to).\n */\n fromPage?: string\n /** @default { platform: 'organic' } */\n leadSource?: ContactFormMetadata['leadSource']\n /** @default globalThis.location */\n location?: PageLocation | null\n /** Submission time. @default new Date() */\n now?: Date\n}\n\nfunction browserLocation(): PageLocation | null {\n const location = (globalThis as { location?: PageLocation }).location\n return location && typeof location.pathname === 'string' ? location : null\n}\n\n/**\n * Path of the page the visitor is on — `location.pathname`, never with a query\n * string or hash. `'/'` when there is no location (server render).\n */\nexport function currentPagePath(location: PageLocation | null = browserLocation()): string {\n const path = location?.pathname.split(/[?#]/, 1)[0] ?? ''\n return path.startsWith('/') ? path : '/'\n}\n\n/**\n * The `metadata` for `contactForm.submit()` / `POST /api/site/contact-form`:\n * `fromPage` is the current page path, `currentUrl` the full href (base-api\n * reads the UTMs from it), `timestamp` the submission time.\n *\n * ```ts\n * body: JSON.stringify({ ...fields, captcha, metadata: buildContactFormMetadata() })\n * ```\n */\nexport function buildContactFormMetadata(\n options: ContactFormMetadataOptions = {},\n): ContactFormMetadata {\n const location = options.location === undefined ? browserLocation() : options.location\n return {\n fromPage: options.fromPage ?? currentPagePath(location),\n timestamp: (options.now ?? new Date()).toISOString(),\n currentUrl: location?.href ?? '',\n leadSource: options.leadSource ?? { platform: 'organic' },\n }\n}\n","/**\n * `@reblu/site-client` — framework-agnostic HTTP client for the Reblu SITE API\n * (REB-415 / design doc §3).\n *\n * The consumer owns the environment: `baseUrl`/`apiKey` are passed in, never read\n * from `process.env`. Caching is delegated to an injectable `RebluCacheAdapter`\n * (default `PlainCacheAdapter`), which severs any coupling to a specific\n * framework's cache model — `@reblu/site-next` supplies the ISR-aware adapter.\n * Response DTOs are typed by the peer, type-only `@reblu/site-contracts`.\n */\nimport { PlainCacheAdapter, type RebluCacheAdapter } from './cache'\nimport type { RebluClientContext, RequestScope } from './client'\nimport { DEFAULT_CHECKOUT_REDIRECT_HOSTS } from './checkout-redirect'\nimport { makeAcademyNamespace } from './domains/academy'\nimport { makeAnalyticsNamespace } from './domains/analytics'\nimport { makeBlogNamespace } from './domains/blog'\nimport { makeConfigNamespace } from './domains/config'\nimport { makeContactFormNamespace } from './domains/contact-form'\nimport { makeCtasNamespace } from './domains/ctas'\nimport { makeDataRequestsNamespace } from './domains/data-requests'\nimport { makeLeadsNamespace } from './domains/leads'\nimport { makeLegalNamespace } from './domains/legal'\nimport { makePagesNamespace } from './domains/pages'\nimport { makeShopNamespace } from './domains/shop'\nimport { makeTrustBadgesNamespace } from './domains/trust-badges'\n\nconst DEFAULT_API_VERSION = '1'\n/** Parity with demo-site's upstream timeout (client.ts:36). */\nconst DEFAULT_TIMEOUT_MS = 8000\n\nexport interface RebluClientConfig {\n /** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */\n baseUrl: string\n /** Tenant SITE API key (`rbl_…`), sent as `X-Reblu-Api-Key`. */\n apiKey: string\n /** Contract version sent as `X-Reblu-Api-Version`. Defaults to `'1'`. */\n apiVersion?: string\n /** Cache strategy. Defaults to `new PlainCacheAdapter()` (no-store). */\n cache?: RebluCacheAdapter\n /** Per-request hard timeout in ms. Defaults to `8000`. */\n timeoutMs?: number\n /** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */\n fetch?: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth — see `./checkout-redirect`). Defaults to\n * `['checkout.stripe.com']`. Override only to point at a test double (e.g.\n * a Stripe CLI mock host) — never to widen production trust.\n */\n checkoutRedirectHosts?: string[]\n /**\n * REB-1214 — memo store of the current server request, so identical GET\n * reads within it are fetched once. In Next.js pass `rebluRequestScope`\n * from `@reblu/site-next` (React `cache()`); see the README. Without it,\n * identical GETs share one fetch only while in flight.\n */\n requestScope?: RequestScope\n}\n\n/**\n * Build a Reblu SITE API client. Each domain is a small namespace of bound\n * methods assembled from a separate module, so a consumer importing only a\n * couple of domains can tree-shake the rest.\n */\nexport function createRebluClient(config: RebluClientConfig) {\n // Wrap global fetch so calling `ctx.fetch()` never loses its `this` binding\n // (browsers throw \"Illegal invocation\" for an unbound `window.fetch`).\n const boundFetch: typeof fetch = config.fetch ?? ((input, init) => fetch(input, init))\n\n const ctx: RebluClientContext = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,\n cache: config.cache ?? new PlainCacheAdapter(),\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetch: boundFetch,\n checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n requestScope: config.requestScope,\n inFlight: new Map(),\n }\n\n return {\n config: makeConfigNamespace(ctx),\n analytics: makeAnalyticsNamespace(ctx),\n legal: makeLegalNamespace(ctx),\n trustBadges: makeTrustBadgesNamespace(ctx),\n ctas: makeCtasNamespace(ctx),\n blog: makeBlogNamespace(ctx),\n pages: makePagesNamespace(ctx),\n shop: makeShopNamespace(ctx),\n academy: makeAcademyNamespace(ctx),\n contactForm: makeContactFormNamespace(ctx),\n leads: makeLeadsNamespace(ctx),\n dataRequests: makeDataRequestsNamespace(ctx),\n }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError, AmbiguousPageSlugError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails, PageSlugCandidate } from './errors'\nexport type { PageBySlugOptions, FeaturedPagesOptions } from './domains/pages'\nexport type { TrustBadgeListParams } from './domains/trust-badges'\nexport {\n DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n isSafeCheckoutRedirectUrl,\n UnsafeCheckoutRedirectError,\n} from './checkout-redirect'\nexport { PlainCacheAdapter } from './cache'\nexport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nexport type {\n ListResult,\n BlogListParams,\n PagesListParams,\n ShopProductsParams,\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n} from './types'\nexport {\n VISITOR_IP_HEADER,\n visitorIpFromHeaders,\n RETRY_AFTER_CAP_MS,\n type RebluMutationOptions,\n type RequestScope,\n} from './client'\nexport {\n buildContactFormMetadata,\n currentPagePath,\n type ContactFormMetadata,\n type ContactFormMetadataOptions,\n type PageLocation,\n} from './contact-form-metadata'\n"]}
1
+ {"version":3,"sources":["../src/cache.ts","../src/checkout-redirect.ts","../src/build-url.ts","../src/errors.ts","../src/client.ts","../src/domains/academy.ts","../src/domains/analytics.ts","../src/domains/blog.ts","../src/domains/config.ts","../src/domains/contact-form.ts","../src/domains/ctas.ts","../src/domains/data-requests.ts","../src/domains/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.ts","../src/contact-form-metadata.ts","../src/index.ts"],"names":[],"mappings":";AA0BO,IAAM,oBAAN,MAAqD;AAAA,EAC1D,WAAA,CAA6B,oBAAoC,KAAA,EAAO;AAA3C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAAA,EAA4C;AAAA,EAA5C,iBAAA;AAAA,EAE7B,mBAAmB,MAAA,EAAuC;AACxD,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,IAAA,CAAK,iBAAA;AAC7C,IAAA,OAAO,UAAA,KAAe,KAAA,IAAS,UAAA,KAAe,CAAA,GAC1C,EAAE,OAAO,UAAA,EAAW,GACpB,EAAE,KAAA,EAAO,aAAA,EAAc;AAAA,EAC7B;AACF;;;ACnBO,IAAM,+BAAA,GAAqD,CAAC,qBAAqB;AAOjF,SAAS,yBAAA,CACd,GAAA,EACA,YAAA,GAAkC,+BAAA,EACzB;AACT,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,IAAI,GAAG,CAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAO,QAAA,KAAa,QAAA,IAAY,YAAA,CAAa,QAAA,CAAS,OAAO,QAAQ,CAAA;AAC9E;AAOO,IAAM,2BAAA,GAAN,cAA0C,KAAA,CAAM;AAAA,EACrD,WAAA,CACkB,KACA,YAAA,EAChB;AACA,IAAA,KAAA;AAAA,MACE,CAAA,2DAAA,EAA8D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AO,UAAA;AAAA,IACP,qBAAA,EAAuB,OAAO,qBAAA,IAAyB,+BAAA;AAAA,IACvD,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,QAAA,sBAAc,GAAA;AAAI,GACpB;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,oBAAoB,GAAG,CAAA;AAAA,IAC/B,SAAA,EAAW,uBAAuB,GAAG,CAAA;AAAA,IACrC,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,WAAA,EAAa,yBAAyB,GAAG,CAAA;AAAA,IACzC,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,IAAA,EAAM,kBAAkB,GAAG,CAAA;AAAA,IAC3B,OAAA,EAAS,qBAAqB,GAAG,CAAA;AAAA,IACjC,WAAA,EAAa,yBAAyB,GAAG,CAAA;AAAA,IACzC,KAAA,EAAO,mBAAmB,GAAG,CAAA;AAAA,IAC7B,YAAA,EAAc,0BAA0B,GAAG;AAAA,GAC7C;AACF","file":"index.js","sourcesContent":["/**\n * Cache adapter — the seam that severs the SDK from any framework's caching\n * model (design doc D4 / §3.2). The client owns *when* to cache (a per-call\n * `RebluCachePolicy`); the adapter owns *how* (the framework-specific\n * `RequestInit` fields). `@reblu/site-client` ships the framework-agnostic\n * `PlainCacheAdapter`; `@reblu/site-next` (REB-418) supplies a `NextCacheAdapter`\n * that returns `{ next: { revalidate } }`.\n */\n\nexport interface RebluCachePolicy {\n /**\n * Seconds to revalidate. `undefined` → use the adapter's default; `0`/`false`\n * → never cache (always fetch fresh).\n */\n revalidate?: number | false\n}\n\nexport interface RebluCacheAdapter {\n /** Map a per-call cache policy to framework-specific `fetch` `RequestInit` fields. */\n resolveRequestInit(policy: RebluCachePolicy): RequestInit\n}\n\n/**\n * Default adapter — plain `fetch` cache semantics that work in Node, edge,\n * browser and tests. No `next`, no `server-only`.\n */\nexport class PlainCacheAdapter implements RebluCacheAdapter {\n constructor(private readonly defaultRevalidate: number | false = false) {}\n\n resolveRequestInit(policy: RebluCachePolicy): RequestInit {\n const revalidate = policy.revalidate ?? this.defaultRevalidate\n return revalidate === false || revalidate === 0\n ? { cache: 'no-store' }\n : { cache: 'force-cache' }\n }\n}\n","/**\n * Stripe Checkout redirect-origin guard (REB-836, defence in depth).\n *\n * `shop.checkout()` returns a URL every SITE immediately hands to\n * `window.location.assign(url)`. Nothing upstream of this SDK validated it\n * before REB-836 — a compromised/misconfigured base-api, a tampered\n * response, or a MITM proxy could have sent a buyer's browser anywhere.\n * `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses\n * to refuse an unsafe URL before ever returning it to the caller; a SITE's\n * `@reblu/site-next` Route Handler re-checks the SAME property server-side\n * (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an\n * independent copy — see that file's docblock for why it isn't a shared\n * import). Update both together if Stripe ever changes its Checkout host.\n */\n\n/** The only Checkout redirect host trusted by default. */\nexport const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[] = ['checkout.stripe.com']\n\n/**\n * True only when `url` parses as an absolute URL, uses `https:`, and its\n * hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).\n * Never throws — an unparsable `url` is simply unsafe.\n */\nexport function isSafeCheckoutRedirectUrl(\n url: string,\n allowedHosts: readonly string[] = DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n): boolean {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n return false\n }\n return parsed.protocol === 'https:' && allowedHosts.includes(parsed.hostname)\n}\n\n/**\n * Thrown by `shop.checkout()` when base-api's Checkout URL fails\n * {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back\n * to a caller that would otherwise `window.location.assign` it.\n */\nexport class UnsafeCheckoutRedirectError extends Error {\n constructor(\n public readonly url: string,\n public readonly allowedHosts: readonly string[],\n ) {\n super(\n `Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} ` +\n `(allowed hosts: ${allowedHosts.join(', ')})`,\n )\n this.name = 'UnsafeCheckoutRedirectError'\n }\n}\n","/** A value that can be serialized into a query string. */\nexport type QueryValue = string | number | boolean | undefined | null\n\n/**\n * Append a query string to `base`, dropping `undefined`/`null` values.\n *\n * Single definition for the whole client (design doc §3.1 dedupes the two copies\n * that lived in demo-site's `client.ts` and `index.ts`). Falsy-but-meaningful\n * values (`0`, `false`, `''`) are preserved; only `undefined`/`null` are omitted.\n * Array values (REB-475 faceted `attr[key]`) emit one repeated param per element.\n */\nexport function buildUrl(\n base: string,\n params?: Record<string, QueryValue | QueryValue[]>,\n): string {\n if (!params) return base\n const pairs: [string, string][] = []\n for (const [key, value] of Object.entries(params)) {\n const values = Array.isArray(value) ? value : [value]\n for (const v of values) {\n if (v === undefined || v === null) continue\n pairs.push([key, String(v)])\n }\n }\n if (pairs.length === 0) return base\n const qs = new URLSearchParams(pairs).toString()\n return `${base}?${qs}`\n}\n","/**\n * The `details` shape `/api/site/contact-form` and `/api/site/leads` attach on a\n * 400/422, straight from zod's `.flatten()` (see\n * `details: parsed.error.flatten()` in\n * `apps/base-api/src/lib/server/services/contact-form.service.ts:114` and\n * `apiError('Validation error', 422, parsed.error.flatten())` in\n * `apps/base-api/src/app/api/site/leads/route.ts:40`). `fieldErrors` is what a\n * SITE actually needs — REB-659's `details.fieldErrors.phone` — `formErrors` is\n * kept alongside it because `.flatten()` always emits both and dropping it would\n * silently discard form-level (non-field) messages.\n */\nexport interface ApiErrorDetails {\n fieldErrors?: Record<string, string[]>\n formErrors?: string[]\n /**\n * REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /\n * `PRICE_CHANGED` error — see `ApiErrorBody.code`.\n */\n productIds?: string[]\n /** REB-842: optional request-field identifier for checkout validation errors. */\n field?: string\n}\n\n/**\n * The parsed shape of a non-2xx SITE API response body: `{ error, details? }`\n * (see `apiError()` in `apps/base-api/src/lib/api/response.ts:33` — the general\n * shape both routes above build on).\n */\nexport interface ApiErrorBody {\n error: string\n details?: ApiErrorDetails\n /**\n * REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from\n * `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write\n * endpoints may set — additive and OPTIONAL, so a consumer that only reads\n * `error`/`message` keeps working unchanged. `string` rather than\n * `ShopErrorCode` here because `ApiError` is a generic transport error used\n * by every `/api/site/*` domain, not just shop.\n */\n code?: string\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string')\n}\n\n/**\n * Validates `ApiErrorDetails` deeply — `fieldErrors` must be a record whose\n * values are `string[] | undefined`, `formErrors` (if present) must be\n * `string[]`, and `field` (if present) must be a string. Without this, a body like\n * `{ fieldErrors: { phone: \"abc\" } }` passed the old shallow check, so\n * `body.details?.fieldErrors?.phone?.[0]` silently returned the character\n * `\"a\"` instead of a validation message (REB-764 review finding).\n */\nfunction isApiErrorDetails(value: unknown): value is ApiErrorDetails {\n if (typeof value !== 'object' || value === null) return false\n const details = value as {\n fieldErrors?: unknown\n formErrors?: unknown\n productIds?: unknown\n field?: unknown\n }\n\n if (details.fieldErrors !== undefined) {\n if (\n typeof details.fieldErrors !== 'object' ||\n details.fieldErrors === null ||\n Array.isArray(details.fieldErrors)\n ) {\n return false\n }\n for (const fieldValue of Object.values(details.fieldErrors as Record<string, unknown>)) {\n if (fieldValue !== undefined && !isStringArray(fieldValue)) return false\n }\n }\n\n if (details.formErrors !== undefined && !isStringArray(details.formErrors)) return false\n\n // REB-836: STOCK_CHANGED/PRICE_CHANGED carry the affected product ids here.\n if (details.productIds !== undefined && !isStringArray(details.productIds)) return false\n if ('field' in details && typeof details.field !== 'string') return false\n\n return true\n}\n\n/**\n * `details`, when present, must match `ApiErrorDetails` deeply — an\n * unrecognised `details` shape makes the whole body unrecognised (`body`\n * stays `undefined`), the stricter reading consistent with\n * `parseApiErrorBody`'s existing all-or-nothing semantics: a body is either\n * shaped like `ApiErrorBody` or it isn't. Silently dropping a malformed\n * `details` instead would let a consumer treat a schema-drifted or corrupted\n * response as merely detail-less, hiding the mismatch rather than surfacing\n * it as \"unparseable\" (REB-764 review finding).\n */\nfunction isApiErrorBody(value: unknown): value is ApiErrorBody {\n if (typeof value !== 'object' || value === null) return false\n const body = value as { error?: unknown; details?: unknown; code?: unknown }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) return false\n // REB-836: `code` must be a string when present — same all-or-nothing\n // reading as `details` above (an unrecognised shape makes the whole body\n // unrecognised, never silently dropped).\n if (body.code !== undefined && typeof body.code !== 'string') return false\n return true\n}\n\n/**\n * Parses `rawBody` (the exact text `message` is built from) into a typed\n * `ApiErrorBody`, or `undefined` when it is not JSON, or JSON that does not\n * match the expected shape — an edge proxy 502 returns HTML, and this must\n * never throw while constructing the error it is reporting.\n */\nfunction parseApiErrorBody(rawBody: string): ApiErrorBody | undefined {\n if (!rawBody) return undefined\n try {\n const parsed: unknown = JSON.parse(rawBody)\n return isApiErrorBody(parsed) ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Typed transport error for the Reblu SITE API.\n *\n * Every non-2xx response throws an `ApiError` (never a bare `fetch` rejection),\n * so consumers can `catch (e) { if (e instanceof ApiError) … }` and fall back\n * gracefully (e.g. render an empty section) — the one behavioural contract the\n * SITE relies on. Moved verbatim from demo-site's `client.ts` (design doc §3.4).\n */\nexport class ApiError extends Error {\n /**\n * The parsed response body, when it was JSON shaped like `{ error, details? }`\n * (REB-764). `undefined` when the body was not JSON or didn't match — parsing\n * is defensive and never throws. Read `body.details?.fieldErrors?.phone`\n * instead of regex-stripping this error's `message`.\n */\n public readonly body: ApiErrorBody | undefined\n\n constructor(\n public readonly status: number,\n public readonly path: string,\n message: string,\n ) {\n super(`API ${status} @ ${path}: ${message}`)\n this.name = 'ApiError'\n this.body = parseApiErrorBody(message)\n }\n}\n\n/** One page a slug could mean (REB-867) — `null` = the uncategorised page. */\nexport interface PageSlugCandidate {\n categorySlug: string | null\n}\n\nfunction parseCandidates(rawBody: string): PageSlugCandidate[] {\n try {\n const parsed = JSON.parse(rawBody) as { candidates?: unknown }\n if (!Array.isArray(parsed.candidates)) return []\n return parsed.candidates.flatMap((c: unknown) => {\n const slug = (c as { categorySlug?: unknown } | null)?.categorySlug\n return typeof slug === 'string' || slug === null ? [{ categorySlug: slug }] : []\n })\n } catch {\n return []\n }\n}\n\n/**\n * REB-867 — `GET /api/site/pages/[slug]` answered 409 `ambiguous_slug`: page\n * slugs are unique PER CATEGORY and this one exists in more than one, so the\n * server refused to pick. Retry with `pages.bySlug(slug, { category })` using\n * one of `candidates`. Extends `ApiError`, so an existing\n * `catch (e) { if (e instanceof ApiError) … }` keeps handling it.\n */\nexport class AmbiguousPageSlugError extends ApiError {\n public readonly candidates: PageSlugCandidate[]\n\n constructor(source: ApiError, rawBody: string) {\n super(source.status, source.path, rawBody)\n this.name = 'AmbiguousPageSlugError'\n this.candidates = parseCandidates(rawBody)\n }\n}\n\n/** The raw body an `ApiError` was built from (its message minus the prefix). */\nexport function apiErrorRawBody(error: ApiError): string {\n const prefix = `API ${error.status} @ ${error.path}: `\n return error.message.startsWith(prefix) ? error.message.slice(prefix.length) : error.message\n}\n","import type { PaginationMeta } from '@reblu/site-contracts'\nimport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nimport { ApiError } from './errors'\nimport type { ListResult } from './types'\n\n/**\n * Resolved, immutable client context threaded into every domain namespace. Built\n * once by `createRebluClient` from the consumer's config — the SDK never reads\n * `process.env`, so the consumer owns `baseUrl`/`apiKey` (design doc §3.3).\n */\nexport interface RebluClientContext {\n baseUrl: string\n apiKey: string\n apiVersion: string\n cache: RebluCacheAdapter\n timeoutMs: number\n fetch: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth). Defaults to\n * `DEFAULT_CHECKOUT_REDIRECT_HOSTS` (`['checkout.stripe.com']`) — tests\n * inject a different value via `RebluClientConfig.checkoutRedirectHosts`.\n */\n checkoutRedirectHosts: readonly string[]\n /**\n * REB-1214 — returns the memo store of the CURRENT server request, so\n * identical GET reads within it are fetched once (e.g. `generateMetadata`\n * and the page body). `@reblu/site-next` supplies one backed by React\n * `cache()` (`rebluRequestScope`). Absent, or returning `undefined`,\n * identical GETs still share one fetch while they are in flight.\n */\n requestScope?: RequestScope\n /** In-flight GETs when no request scope is active. Created by `createRebluClient`. */\n inFlight?: Map<string, Promise<unknown>>\n}\n\n/** Memo store of one server request, keyed by read identity (REB-1214). */\nexport type RequestScope = () => Map<string, Promise<unknown>> | undefined\n\n/** Upper bound for a `Retry-After` wait before the single retry (REB-1214). */\nexport const RETRY_AFTER_CAP_MS = 2000\n/** Wait before the single retry when `Retry-After` is absent or unparseable. */\nexport const DEFAULT_RETRY_DELAY_MS = 250\n/** Statuses that mean \"try again shortly\" for a read. */\nconst RETRYABLE_READ_STATUSES = new Set([429, 503])\n\n/** `Retry-After` (seconds or HTTP date) → ms, capped; default when unusable. */\nfunction retryDelayMs(header: string | null): number {\n if (header !== null && header.trim() !== '') {\n const value = header.trim()\n const seconds = /^\\d+$/.test(value) ? Number(value) * 1000 : NaN\n const ms = Number.isFinite(seconds) ? seconds : Date.parse(value) - Date.now()\n if (Number.isFinite(ms)) return Math.min(Math.max(0, ms), RETRY_AFTER_CAP_MS)\n }\n return DEFAULT_RETRY_DELAY_MS\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/** Per-call request options. `cachePolicy` is interpreted by the cache adapter. */\nexport interface RequestOptions {\n method?: string\n body?: string\n headers?: Record<string, string>\n cachePolicy?: RebluCachePolicy\n}\n\n/**\n * Core transport (design doc §3.4). Injects the auth + contract-version headers,\n * merges the adapter's cache `RequestInit`, enforces a hard timeout per attempt,\n * throws a typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n *\n * REB-1214 — GET reads only: identical reads are deduped (see\n * `RebluClientContext.requestScope`) and a 429/503 is retried once after\n * `Retry-After`, capped at {@link RETRY_AFTER_CAP_MS}. If the retry fails too,\n * the second response's `ApiError` is thrown — the same type as before.\n * Writes are never deduped nor retried.\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const method = opts.method ?? 'GET'\n const init: RequestInit = {\n method,\n body: opts.body,\n headers: {\n 'X-Reblu-Api-Key': ctx.apiKey,\n 'X-Reblu-Api-Version': ctx.apiVersion,\n 'Content-Type': 'application/json',\n ...opts.headers,\n },\n ...ctx.cache.resolveRequestInit(opts.cachePolicy ?? {}),\n }\n if (method !== 'GET' || opts.body !== undefined) {\n return attempt<T>(ctx, path, init)\n }\n\n // REB-1214 — a read is identified by everything that shapes its response:\n // URL, headers and the resolved cache init. Kept for the whole request when\n // a scope is active; otherwise only while in flight.\n const key = JSON.stringify([ctx.baseUrl + path, init])\n const scope = ctx.requestScope?.()\n const store = scope ?? ctx.inFlight\n const existing = store?.get(key)\n if (existing) return existing as Promise<T>\n\n const pending = readWithRetry<T>(ctx, path, init)\n if (store) {\n store.set(key, pending)\n // A failure is never memoised; without a scope nothing outlives the fetch.\n pending.then(\n () => {\n if (!scope) store.delete(key)\n },\n () => {\n if (store.get(key) === pending) store.delete(key)\n },\n )\n }\n return pending\n}\n\n/** A GET answered 429/503 is retried once after `Retry-After` (capped). */\nasync function readWithRetry<T>(\n ctx: RebluClientContext,\n path: string,\n init: RequestInit,\n): Promise<T> {\n try {\n return await attempt<T>(ctx, path, init)\n } catch (error) {\n if (!(error instanceof RetryableReadError)) throw error\n await sleep(retryDelayMs(error.retryAfter))\n try {\n return await attempt<T>(ctx, path, init)\n } catch (retryError) {\n throw retryError instanceof RetryableReadError ? retryError.apiError : retryError\n }\n }\n}\n\n/** Internal carrier: a retryable read status plus the `ApiError` to throw if it persists. */\nclass RetryableReadError extends Error {\n constructor(\n readonly apiError: ApiError,\n readonly retryAfter: string | null,\n ) {\n super(apiError.message)\n }\n}\n\n/**\n * One HTTP attempt: enforces the hard timeout via `AbortController`, throws a\n * typed `ApiError` on non-2xx, and returns the parsed JSON body verbatim\n * (envelope unwrapping is the caller's concern).\n */\nasync function attempt<T>(ctx: RebluClientContext, path: string, init: RequestInit): Promise<T> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(ctx.baseUrl + path, { ...init, signal: controller.signal })\n\n if (!res.ok) {\n const error = new ApiError(res.status, path, await res.text())\n if (init.method === 'GET' && RETRYABLE_READ_STATUSES.has(res.status)) {\n throw new RetryableReadError(error, res.headers.get('retry-after'))\n }\n throw error\n }\n return (await res.json()) as T\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch a single resource and unwrap the `{ data: T }` envelope. */\nexport async function requestOne<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const body = await request<{ data: T }>(ctx, path, opts)\n return body.data\n}\n\n/** Fetch a list resource, returning the `{ data, meta }` envelope (meta preserved). */\nexport async function requestList<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<ListResult<T>> {\n const body = await request<{ data: T[]; meta?: PaginationMeta }>(ctx, path, opts)\n return { data: body.data, meta: body.meta }\n}\n\n/**\n * Header carrying the visitor IP from a SITE server to base-api (REB-1005).\n * base-api keys its per-visitor limit on public writes on it, and trusts it\n * only behind a valid API key.\n */\nexport const VISITOR_IP_HEADER = 'x-reblu-visitor-ip'\n\n/**\n * Per-call options for a write (REB-1005).\n *\n * - `visitorIp` — the visitor's IP when a SITE calls the SDK server-side, sent\n * as `x-reblu-visitor-ip`. Do NOT rely on forwarding `x-forwarded-for`: on\n * Vercel the SITE→base-api hop gets it overwritten with the SITE function's\n * egress IP. Read it from the INCOMING request with\n * {@link visitorIpFromHeaders}.\n * - `headers` — other extra headers (e.g. `user-agent`). They can never set\n * `x-reblu-visitor-ip` nor replace `X-Reblu-Api-Key`, `X-Reblu-Api-Version`\n * or `Content-Type`.\n */\nexport interface RebluMutationOptions {\n visitorIp?: string\n headers?: Record<string, string>\n}\n\n/** The visitor IP of an incoming request: first `x-forwarded-for` entry, else `x-real-ip`. */\nexport function visitorIpFromHeaders(headers: {\n get(name: string): string | null\n}): string | undefined {\n return (\n headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||\n headers.get('x-real-ip')?.trim() ||\n undefined\n )\n}\n\n/** Headers the SDK owns on every request — an extra header never sets or overrides these. */\nconst RESERVED_HEADERS = new Set([\n 'x-reblu-api-key',\n 'x-reblu-api-version',\n 'content-type',\n VISITOR_IP_HEADER,\n])\n\n/**\n * The extra headers a write sends for `options`: caller headers minus the\n * reserved ones, plus `x-reblu-visitor-ip` from `visitorIp`. Shared by\n * {@link requestMutation} and the writes that cannot use it (academy).\n */\nexport function extraHeaders(\n options: RebluMutationOptions | undefined,\n): Record<string, string> | undefined {\n if (!options?.headers && !options?.visitorIp) return undefined\n const safe: Record<string, string> = {}\n for (const [name, value] of Object.entries(options.headers ?? {})) {\n if (!RESERVED_HEADERS.has(name.toLowerCase())) safe[name] = value\n }\n const visitorIp = options.visitorIp?.trim()\n if (visitorIp) safe[VISITOR_IP_HEADER] = visitorIp\n return safe\n}\n\n/**\n * POST a mutation: serialize `body` to JSON, force a cache bypass (`revalidate:\n * false` → `no-store` regardless of the injected adapter, since a mutation must\n * never be served from cache), then unwrap the `{ data: T }` envelope. Mirrors\n * every `/api/site/*` write route, which answers with `apiOk`/`{ data }`.\n */\nexport async function requestMutation<Req, Res>(\n ctx: RebluClientContext,\n path: string,\n body: Req,\n options?: RebluMutationOptions,\n): Promise<Res> {\n const headers = extraHeaders(options)\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyConfigPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n AcademyInstructorPublic,\n AcademyLessonPreview,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n extraHeaders,\n request,\n requestList,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport type {\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n ListResult,\n} from '../types'\n\n/**\n * Academy domain — the public course catalogue (`GET /api/site/academy/*`,\n * REB-528 / REB-534) plus the anonymous enrollment request (REB-496). The reads\n * are published-filtered server-side, so nothing here needs an entitlement\n * notion; the one write is unauthenticated by design.\n *\n * `enrollmentRequest` drops to the raw `request()` transport rather than\n * `requestMutation` (REB-584). The route answers with a BARE `{ message }`, not\n * the `{ data }` envelope every other write uses, so `requestMutation` would\n * unwrap a missing `.data` and hand the caller `undefined`. Normalizing the\n * route's envelope instead was rejected: its response shape is load-bearing\n * anti-enumeration behaviour, and changing it would ripple into base-api tests\n * for no gain on the SITE side.\n */\nexport function makeAcademyNamespace(ctx: RebluClientContext) {\n return {\n /** Published courses, filtered + paginated. `meta` carries the pagination. */\n courses: (\n params?: AcademyCourseListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<AcademyCourseSummary>> =>\n requestList<AcademyCourseSummary>(\n ctx,\n buildUrl('/api/site/academy/courses', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n /** A single published course by slug, with its modules, lessons and CTA gate. */\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<AcademyCourseDetail> =>\n requestOne<AcademyCourseDetail>(ctx, `/api/site/academy/courses/${slug}`, {\n cachePolicy: cache,\n }),\n\n /**\n * A free-preview lesson, viewable by the public (REB-1135): title, duration,\n * Markdown body and a ready-to-embed video. Any lesson the public may not see\n * is a uniform 404 (`ApiError`). Never cached: the payload carries a\n * short-lived signed playback token. Server-side, prefer `getLessonPreview`\n * from `@reblu/site-next/academy-server`, which maps that 404 to `null`.\n */\n lessonPreview: (courseSlug: string, lessonSlug: string): Promise<AcademyLessonPreview> =>\n requestOne<AcademyLessonPreview>(\n ctx,\n `/api/site/academy/courses/${encodeURIComponent(courseSlug)}/lessons/${encodeURIComponent(lessonSlug)}`,\n { cachePolicy: { revalidate: false } },\n ),\n\n /**\n * Instructors of published courses, sorted by name, backing the catalog\n * instructor filter (REB-547). Pass an `id` as `courses({ instructor })`.\n * Not paginated.\n */\n instructors: (cache?: RebluCachePolicy): Promise<ListResult<AcademyInstructorPublic>> =>\n requestList<AcademyInstructorPublic>(ctx, '/api/site/academy/instructors', {\n cachePolicy: cache,\n }),\n\n /**\n * Tenant academy settings for the SITE (REB-1234). `catalogFilters` says\n * which catalogue filters the tenant switched on in nexus — pass it as\n * `enabled` to `CourseCatalogFilters` (`@reblu/site-blocks`). A filter the\n * tenant never set comes back `true`.\n */\n config: (cache?: RebluCachePolicy): Promise<AcademyConfigPublic> =>\n requestOne<AcademyConfigPublic>(ctx, '/api/site/academy/config', { cachePolicy: cache }),\n\n /** Active course categories backing the catalog filter. Not paginated. */\n categories: (cache?: RebluCachePolicy): Promise<ListResult<AcademyCategoryPublic>> =>\n requestList<AcademyCategoryPublic>(ctx, '/api/site/academy/categories', {\n cachePolicy: cache,\n }),\n\n /**\n * Submit an anonymous enrollment request for a course.\n *\n * The reply is UNIFORM by design: the caller cannot tell whether the email\n * was new (a request row was created) or already known (a sign-in link was\n * sent and NO request row exists). Never present the returned message as\n * confirmation that a request was recorded — it is not one.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n options?: RebluMutationOptions,\n ): Promise<AcademyEnrollmentRequestResult> => {\n const headers = extraHeaders(options)\n return request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n ...(headers ? { headers } : {}),\n })\n },\n }\n}\n","import type { Analytics } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/analytics` — the tenant's analytics provider configuration. */\nexport function makeAnalyticsNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Analytics> =>\n requestOne<Analytics>(ctx, '/api/site/analytics', { cachePolicy: cache }),\n }\n}\n","import type {\n BlogCategoryWithCount,\n BlogPostDetail,\n BlogPostListItem,\n BlogPostPreview,\n BlogSlug,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport type { BlogListParams, ListResult } from '../types'\n\n/** Blog domain — `GET /api/site/blog/*`. */\nexport function makeBlogNamespace(ctx: RebluClientContext) {\n return {\n list: (\n params?: BlogListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(\n ctx,\n buildUrl('/api/site/blog', params as Record<string, QueryValue> | undefined),\n { cachePolicy: cache },\n ),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<BlogPostDetail> =>\n requestOne<BlogPostDetail>(ctx, `/api/site/blog/${slug}`, { cachePolicy: cache }),\n\n related: (slug: string, cache?: RebluCachePolicy): Promise<ListResult<BlogPostListItem>> =>\n requestList<BlogPostListItem>(ctx, `/api/site/blog/${slug}/related`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<BlogCategoryWithCount>> =>\n requestList<BlogCategoryWithCount>(ctx, '/api/site/blog/categories', { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<BlogSlug>> =>\n requestList<BlogSlug>(ctx, '/api/site/blog/slugs', { cachePolicy: cache }),\n\n /** Draft preview — never cached (unpublished content). */\n preview: (id: string): Promise<BlogPostPreview> =>\n requestOne<BlogPostPreview>(ctx, `/api/site/blog/preview/${id}`, {\n cachePolicy: { revalidate: false },\n }),\n }\n}\n","import type { Config } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/config` — the tenant's public site configuration. */\nexport function makeConfigNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Config> =>\n requestOne<Config>(ctx, '/api/site/config', { cachePolicy: cache }),\n }\n}\n","import type { ContactFormInput, ContactFormSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * Contact form domain — WRITE only (`POST /api/site/contact-form`, REB-438).\n * Posts a body typed by `@reblu/site-contracts` and bypasses the cache; returns\n * the created lead's id + creation timestamp.\n */\nexport function makeContactFormNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a contact form. Returns the created lead acknowledgement.\n * Server-side (a Server Action / Route Handler), pass `options.visitorIp`\n * (from the incoming request, see `visitorIpFromHeaders`) so base-api's\n * per-IP limit (REB-1005) applies to the real visitor.\n */\n submit: (\n body: ContactFormInput,\n options?: RebluMutationOptions,\n ): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(\n ctx,\n '/api/site/contact-form',\n body,\n options,\n ),\n }\n}\n","import type { Cta } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/**\n * `GET /api/site/ctas?slot=…` — editable CTAs for a given slot.\n *\n * `slot` is typed as `string` on purpose: the slot enum lives in base-api's\n * `validations/` (not the response contracts), so `@reblu/site-contracts` does\n * not export it. Keeping it a `string` avoids duplicating (and drifting from)\n * the server-owned enum. The server validates the slot.\n */\nexport function makeCtasNamespace(ctx: RebluClientContext) {\n return {\n list: (slot: string, cache?: RebluCachePolicy): Promise<ListResult<Cta>> =>\n requestList<Cta>(ctx, buildUrl('/api/site/ctas', { slot }), { cachePolicy: cache }),\n }\n}\n","import type { DataRequestInput, DataRequestSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext, type RebluMutationOptions } from '../client'\n\n/**\n * GDPR data-subject requests domain — WRITE only (`POST /api/site/data-requests`,\n * REB-77 endpoint / REB-980 SDK). Posts the public rights-form body typed by\n * `@reblu/site-contracts`, bypasses the cache, and returns the request id, when\n * it was received and the 72h deadline (`slaDueAt`) it is now held to.\n *\n * base-api requires a reCAPTCHA v3 token (`captcha`) and rate-limits per tenant\n * and per visitor IP (REB-1005); a rejection surfaces as an `ApiError` carrying\n * the upstream `status` (400 validation, 422 captcha, 429 rate limit).\n */\nexport function makeDataRequestsNamespace(ctx: RebluClientContext) {\n return {\n /**\n * Submit a data-subject request. Returns its acknowledgement with the 72h\n * deadline. Server-side, pass `options.visitorIp` (from the incoming\n * request, see `visitorIpFromHeaders`) so base-api's per-IP limit\n * (REB-1005) sees the real visitor.\n */\n submit: (\n body: DataRequestInput,\n options?: RebluMutationOptions,\n ): Promise<DataRequestSubmission> =>\n requestMutation<DataRequestInput, DataRequestSubmission>(\n ctx,\n '/api/site/data-requests',\n body,\n options,\n ),\n }\n}\n","import type { LeadInput, LeadSubmission } from '@reblu/site-contracts'\nimport { requestMutation, type RebluClientContext } from '../client'\n\n/**\n * Leads domain — WRITE only (`POST /api/site/leads`, REB-438). The generic\n * lead-ingestion endpoint: posts a body typed by `@reblu/site-contracts`,\n * bypasses the cache, and returns the created lead's id + creation timestamp.\n */\nexport function makeLeadsNamespace(ctx: RebluClientContext) {\n return {\n /** Create a lead. Returns the created lead acknowledgement. */\n create: (body: LeadInput): Promise<LeadSubmission> =>\n requestMutation<LeadInput, LeadSubmission>(ctx, '/api/site/leads', body),\n }\n}\n","import type { Legal } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestOne, type RebluClientContext } from '../client'\n\n/** `GET /api/site/legal` — the tenant's legal content (privacy, terms, cookies). */\nexport function makeLegalNamespace(ctx: RebluClientContext) {\n return {\n get: (cache?: RebluCachePolicy): Promise<Legal> =>\n requestOne<Legal>(ctx, '/api/site/legal', { cachePolicy: cache }),\n }\n}\n","import type { PageDetail, PageListItem, PageSlug } from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, requestOne, type RebluClientContext } from '../client'\nimport { AmbiguousPageSlugError, ApiError, apiErrorRawBody } from '../errors'\nimport type { ListResult, PagesListParams } from '../types'\n\n/**\n * REB-867 — options for `pages.bySlug`. Page slugs are unique PER CATEGORY:\n * - `category: '<categorySlug>'` → the page with that slug in that category;\n * - `category: null` → the UNCATEGORISED page with that slug;\n * - omitted → the unique page with that slug; throws\n * `AmbiguousPageSlugError` when it exists in more than one category.\n */\nexport interface PageBySlugOptions {\n category?: string | null\n cache?: RebluCachePolicy\n}\n\n/**\n * The two second-argument shapes share no key: a `RebluCachePolicy` only ever\n * has `revalidate`, `PageBySlugOptions` only `category`/`cache`. So the\n * presence of `category` or `cache` (even `category: undefined`) selects the\n * options form; anything else — including `{}` — is a cache policy, exactly as\n * before REB-867.\n */\n/** REB-869 — options for `pages.featured`. */\nexport interface FeaturedPagesOptions {\n /**\n * How many pages at most: an integer >= 1. Default 3. Values above the\n * server's cap (3) are clamped to 3; anything else invalid (0, negative,\n * fractional, NaN) throws a `RangeError` before any request is made.\n */\n limit?: number\n /**\n * When the category has nothing featured, return its first `limit` pages in\n * normal order instead of `[]`. Default `true`, so a teaser is never empty\n * just because nobody picked pages yet.\n */\n fallback?: boolean\n cache?: RebluCachePolicy\n}\n\n/** The server caps a featured list at 3 (REB-869). */\nconst FEATURED_PAGES_MAX = 3\n\nfunction isBySlugOptions(value: RebluCachePolicy | PageBySlugOptions): value is PageBySlugOptions {\n return 'category' in value || 'cache' in value\n}\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n const namespace = {\n list: (\n params?: PagesListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<PageListItem>> =>\n requestList<PageListItem>(\n ctx,\n // REB-63: `type` can now be a single PageType or an array (repeated\n // `?type=` params) — widen the cast alongside `PagesListParams`.\n buildUrl('/api/site/pages', params as Record<string, QueryValue | QueryValue[]> | undefined),\n { cachePolicy: cache },\n ),\n\n /**\n * A published page by slug. The second argument is either a cache policy\n * (backward-compatible) or {@link PageBySlugOptions} (REB-867).\n */\n bySlug: async (\n slug: string,\n cacheOrOptions?: RebluCachePolicy | PageBySlugOptions,\n ): Promise<PageDetail> => {\n const options: PageBySlugOptions =\n cacheOrOptions && isBySlugOptions(cacheOrOptions)\n ? cacheOrOptions\n : { cache: cacheOrOptions }\n const path =\n options.category === undefined\n ? `/api/site/pages/${slug}`\n : buildUrl(`/api/site/pages/${slug}`, { category: options.category ?? '' })\n try {\n return await requestOne<PageDetail>(ctx, path, { cachePolicy: options.cache })\n } catch (error) {\n if (error instanceof ApiError && error.status === 409 && error.body?.code === 'ambiguous_slug') {\n throw new AmbiguousPageSlugError(error, apiErrorRawBody(error))\n }\n throw error\n }\n },\n\n /**\n * REB-869 — the pages to show in a category teaser: the category's\n * featured pages in the tenant's order; when none are featured (and\n * `fallback` is not `false`), the first `limit` pages of the category in\n * normal order. Returns the items only (no pagination applies).\n */\n featured: async (\n category: string,\n { limit: requested = FEATURED_PAGES_MAX, fallback = true, cache }: FeaturedPagesOptions = {},\n ): Promise<PageListItem[]> => {\n if (!Number.isInteger(requested) || requested < 1) {\n throw new RangeError(`pages.featured: limit must be an integer >= 1 (got ${requested})`)\n }\n const limit = Math.min(requested, FEATURED_PAGES_MAX)\n const featured = await namespace.list({ category, featured: true }, cache)\n if (featured.data.length > 0 || !fallback) return featured.data.slice(0, limit)\n const first = await namespace.list({ category, pageSize: limit }, cache)\n return first.data.slice(0, limit)\n },\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\n return namespace\n}\n","import type {\n ShopApplyDiscountInput,\n ShopCartValidation,\n ShopCategory,\n ShopCheckEmailInput,\n ShopCheckoutInput,\n ShopCheckoutSession,\n ShopConfig,\n ShopDiscountApplication,\n ShopEmailCheck,\n ShopFacets,\n ShopOrder,\n ShopProductDetail,\n ShopProductListItem,\n ShopValidateCartInput,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport {\n requestList,\n requestMutation,\n requestOne,\n type RebluClientContext,\n type RebluMutationOptions,\n} from '../client'\nimport { isSafeCheckoutRedirectUrl, UnsafeCheckoutRedirectError } from '../checkout-redirect'\nimport type { ListResult, ShopProductsParams } from '../types'\n\n/**\n * Flatten `ShopProductsParams` into a query record: scalars pass through; the\n * `taxonomy`/`attr` maps become repeatable `taxonomy[key]`/`attr[key]` params.\n * Array attr values repeat the same bracket key.\n */\nfunction flattenShopParams(params?: ShopProductsParams): Record<string, QueryValue | QueryValue[]> {\n if (!params) return {}\n const { taxonomy, attr, ...scalars } = params\n const out: Record<string, QueryValue | QueryValue[]> = { ...scalars }\n if (taxonomy) {\n for (const [key, value] of Object.entries(taxonomy)) out[`taxonomy[${key}]`] = value\n }\n if (attr) {\n for (const [key, value] of Object.entries(attr)) out[`attr[${key}]`] = value\n }\n return out\n}\n\n/**\n * Shop domain — READ surface (`GET /api/site/shop/*`) plus the mutation flow\n * (`POST` checkout, validate-cart, apply-discount, and the deprecated\n * check-email) added in REB-438. Every write posts a body typed by `@reblu/site-contracts` and bypasses\n * the cache. Request/response DTOs live in the contracts package (zero Zod).\n */\nexport function makeShopNamespace(ctx: RebluClientContext) {\n return {\n products: (\n params?: ShopProductsParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<ShopProductListItem>> =>\n requestList<ShopProductListItem>(\n ctx,\n buildUrl('/api/site/shop/products', flattenShopParams(params)),\n { cachePolicy: cache },\n ),\n\n /** Available facets (brand/attributes/price/on-sale) for the given filters. */\n facets: (params?: ShopProductsParams, cache?: RebluCachePolicy): Promise<ShopFacets> =>\n requestOne<ShopFacets>(ctx, buildUrl('/api/site/shop/facets', flattenShopParams(params)), {\n cachePolicy: cache,\n }),\n\n bySlug: (slug: string, cache?: RebluCachePolicy): Promise<ShopProductDetail> =>\n requestOne<ShopProductDetail>(ctx, `/api/site/shop/products/${slug}`, { cachePolicy: cache }),\n\n categories: (cache?: RebluCachePolicy): Promise<ListResult<ShopCategory>> =>\n requestList<ShopCategory>(ctx, '/api/site/shop/categories', { cachePolicy: cache }),\n\n config: (cache?: RebluCachePolicy): Promise<ShopConfig> =>\n requestOne<ShopConfig>(ctx, '/api/site/shop/config', { cachePolicy: cache }),\n\n // ── Mutations (REB-438) ──────────────────────────────────────────────────\n\n /**\n * Start a hosted checkout session. Returns the Stripe URL + session id.\n *\n * REB-836 (defence in depth): every SITE hands `url` straight to\n * `window.location.assign`, so this validates it is `https:` on an\n * allowed host (`ctx.checkoutRedirectHosts`, default\n * `checkout.stripe.com`) BEFORE returning — throwing\n * {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL\n * that could redirect a buyer's browser off Stripe's domain.\n */\n checkout: async (body: ShopCheckoutInput): Promise<ShopCheckoutSession> => {\n const session = await requestMutation<ShopCheckoutInput, ShopCheckoutSession>(\n ctx,\n '/api/site/shop/checkout',\n body,\n )\n if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {\n throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts)\n }\n return session\n },\n\n /** Validate a cart against live product/stock/price state before checkout. */\n validateCart: (body: ShopValidateCartInput): Promise<ShopCartValidation> =>\n requestMutation<ShopValidateCartInput, ShopCartValidation>(\n ctx,\n '/api/site/shop/validate-cart',\n body,\n ),\n\n /** Validate a discount code against the current cart subtotal. */\n applyDiscount: (body: ShopApplyDiscountInput): Promise<ShopDiscountApplication> =>\n requestMutation<ShopApplyDiscountInput, ShopDiscountApplication>(\n ctx,\n '/api/site/shop/apply-discount',\n body,\n ),\n\n /**\n * @deprecated REB-834 — the endpoint no longer reveals whether an account\n * exists: it always resolves `{ exists: false }`. Do not call it and never\n * branch UI on `exists`; the checkout always offers «Iniciar sesión o\n * continuar como invitado» and the server links the order to an existing\n * account after payment. Removed in the next major.\n *\n * Server-side, pass `options.visitorIp` (from the incoming request, see\n * `visitorIpFromHeaders`): base-api keys this route's per-IP limit on it\n * and, without it, throttles every visitor of the SITE in one shared\n * tenant-level bucket (REB-1006).\n */\n checkEmail: (\n body: ShopCheckEmailInput,\n options?: RebluMutationOptions,\n ): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(\n ctx,\n '/api/site/shop/check-email',\n body,\n options,\n ),\n\n /**\n * Look up a confirmed (or still-pending) order by its Stripe Checkout\n * session id — the order-confirmation flow (REB-829). `GET`, so it goes\n * through `requestOne` like every other read, not `requestMutation`.\n */\n order: (sessionId: string, cache?: RebluCachePolicy): Promise<ShopOrder> =>\n requestOne<ShopOrder>(ctx, `/api/site/shop/order/${encodeURIComponent(sessionId)}`, {\n cachePolicy: cache,\n }),\n }\n}\n","import type { TrustBadge, TrustBadgeType } from '@reblu/site-contracts'\nimport { buildUrl } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** Filters for {@link makeTrustBadgesNamespace}'s `list` (REB-996). */\nexport interface TrustBadgeListParams {\n /** Only badges of this type (e.g. `'SUBVENTION'`). Omit for every type. */\n type?: TrustBadgeType\n}\n\nfunction isCachePolicy(value: TrustBadgeListParams | RebluCachePolicy): value is RebluCachePolicy {\n return Object.prototype.hasOwnProperty.call(value, 'revalidate')\n}\n\n/**\n * `GET /api/site/trust-badges` — the tenant's PUBLIC trust badges (no\n * pagination): active in nexus and inside their optional validity window, so\n * expiring or switching one off needs no SITE change.\n */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n function list(cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>>\n function list(\n params: TrustBadgeListParams,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>>\n function list(\n paramsOrCache?: TrustBadgeListParams | RebluCachePolicy,\n cache?: RebluCachePolicy,\n ): Promise<ListResult<TrustBadge>> {\n // `list(cache)` is the pre-REB-996 call shape — kept so this stays a minor.\n const legacyCache = paramsOrCache && isCachePolicy(paramsOrCache) ? paramsOrCache : undefined\n const params = legacyCache ? undefined : (paramsOrCache as TrustBadgeListParams | undefined)\n return requestList<TrustBadge>(\n ctx,\n buildUrl('/api/site/trust-badges', { type: params?.type }),\n { cachePolicy: legacyCache ?? cache },\n )\n }\n return { list }\n}\n","import type { ContactFormInput } from '@reblu/site-contracts'\n\n/**\n * REB-1077 — the `metadata` block of a contact-form submission, built from the\n * page the visitor is on so a SITE never hand-codes `fromPage`.\n *\n * Call it in the browser, at submit time (inside the form's submit handler):\n * it reads `globalThis.location` unless a `location` is passed.\n */\n\n/** The part of `window.location` these helpers read. */\nexport interface PageLocation {\n pathname: string\n href?: string\n}\n\nexport type ContactFormMetadata = ContactFormInput['metadata']\n\nexport interface ContactFormMetadataOptions {\n /**\n * Explicit page path, overriding the one read from the location (e.g. a\n * modal form that wants to report the landing it belongs to).\n */\n fromPage?: string\n /** @default { platform: 'organic' } */\n leadSource?: ContactFormMetadata['leadSource']\n /** @default globalThis.location */\n location?: PageLocation | null\n /** Submission time. @default new Date() */\n now?: Date\n}\n\nfunction browserLocation(): PageLocation | null {\n const location = (globalThis as { location?: PageLocation }).location\n return location && typeof location.pathname === 'string' ? location : null\n}\n\n/**\n * Path of the page the visitor is on — `location.pathname`, never with a query\n * string or hash. `'/'` when there is no location (server render).\n */\nexport function currentPagePath(location: PageLocation | null = browserLocation()): string {\n const path = location?.pathname.split(/[?#]/, 1)[0] ?? ''\n return path.startsWith('/') ? path : '/'\n}\n\n/**\n * The `metadata` for `contactForm.submit()` / `POST /api/site/contact-form`:\n * `fromPage` is the current page path, `currentUrl` the full href (base-api\n * reads the UTMs from it), `timestamp` the submission time.\n *\n * ```ts\n * body: JSON.stringify({ ...fields, captcha, metadata: buildContactFormMetadata() })\n * ```\n */\nexport function buildContactFormMetadata(\n options: ContactFormMetadataOptions = {},\n): ContactFormMetadata {\n const location = options.location === undefined ? browserLocation() : options.location\n return {\n fromPage: options.fromPage ?? currentPagePath(location),\n timestamp: (options.now ?? new Date()).toISOString(),\n currentUrl: location?.href ?? '',\n leadSource: options.leadSource ?? { platform: 'organic' },\n }\n}\n","/**\n * `@reblu/site-client` — framework-agnostic HTTP client for the Reblu SITE API\n * (REB-415 / design doc §3).\n *\n * The consumer owns the environment: `baseUrl`/`apiKey` are passed in, never read\n * from `process.env`. Caching is delegated to an injectable `RebluCacheAdapter`\n * (default `PlainCacheAdapter`), which severs any coupling to a specific\n * framework's cache model — `@reblu/site-next` supplies the ISR-aware adapter.\n * Response DTOs are typed by the peer, type-only `@reblu/site-contracts`.\n */\nimport { PlainCacheAdapter, type RebluCacheAdapter } from './cache'\nimport type { RebluClientContext, RequestScope } from './client'\nimport { DEFAULT_CHECKOUT_REDIRECT_HOSTS } from './checkout-redirect'\nimport { makeAcademyNamespace } from './domains/academy'\nimport { makeAnalyticsNamespace } from './domains/analytics'\nimport { makeBlogNamespace } from './domains/blog'\nimport { makeConfigNamespace } from './domains/config'\nimport { makeContactFormNamespace } from './domains/contact-form'\nimport { makeCtasNamespace } from './domains/ctas'\nimport { makeDataRequestsNamespace } from './domains/data-requests'\nimport { makeLeadsNamespace } from './domains/leads'\nimport { makeLegalNamespace } from './domains/legal'\nimport { makePagesNamespace } from './domains/pages'\nimport { makeShopNamespace } from './domains/shop'\nimport { makeTrustBadgesNamespace } from './domains/trust-badges'\n\nconst DEFAULT_API_VERSION = '1'\n/** Parity with demo-site's upstream timeout (client.ts:36). */\nconst DEFAULT_TIMEOUT_MS = 8000\n\nexport interface RebluClientConfig {\n /** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */\n baseUrl: string\n /** Tenant SITE API key (`rbl_…`), sent as `X-Reblu-Api-Key`. */\n apiKey: string\n /** Contract version sent as `X-Reblu-Api-Version`. Defaults to `'1'`. */\n apiVersion?: string\n /** Cache strategy. Defaults to `new PlainCacheAdapter()` (no-store). */\n cache?: RebluCacheAdapter\n /** Per-request hard timeout in ms. Defaults to `8000`. */\n timeoutMs?: number\n /** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */\n fetch?: typeof fetch\n /**\n * Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns\n * (REB-836, defence in depth — see `./checkout-redirect`). Defaults to\n * `['checkout.stripe.com']`. Override only to point at a test double (e.g.\n * a Stripe CLI mock host) — never to widen production trust.\n */\n checkoutRedirectHosts?: string[]\n /**\n * REB-1214 — memo store of the current server request, so identical GET\n * reads within it are fetched once. In Next.js pass `rebluRequestScope`\n * from `@reblu/site-next` (React `cache()`); see the README. Without it,\n * identical GETs share one fetch only while in flight.\n */\n requestScope?: RequestScope\n}\n\n/**\n * Build a Reblu SITE API client. Each domain is a small namespace of bound\n * methods assembled from a separate module, so a consumer importing only a\n * couple of domains can tree-shake the rest.\n */\nexport function createRebluClient(config: RebluClientConfig) {\n // Wrap global fetch so calling `ctx.fetch()` never loses its `this` binding\n // (browsers throw \"Illegal invocation\" for an unbound `window.fetch`).\n const boundFetch: typeof fetch = config.fetch ?? ((input, init) => fetch(input, init))\n\n const ctx: RebluClientContext = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,\n cache: config.cache ?? new PlainCacheAdapter(),\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetch: boundFetch,\n checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n requestScope: config.requestScope,\n inFlight: new Map(),\n }\n\n return {\n config: makeConfigNamespace(ctx),\n analytics: makeAnalyticsNamespace(ctx),\n legal: makeLegalNamespace(ctx),\n trustBadges: makeTrustBadgesNamespace(ctx),\n ctas: makeCtasNamespace(ctx),\n blog: makeBlogNamespace(ctx),\n pages: makePagesNamespace(ctx),\n shop: makeShopNamespace(ctx),\n academy: makeAcademyNamespace(ctx),\n contactForm: makeContactFormNamespace(ctx),\n leads: makeLeadsNamespace(ctx),\n dataRequests: makeDataRequestsNamespace(ctx),\n }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError, AmbiguousPageSlugError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails, PageSlugCandidate } from './errors'\nexport type { PageBySlugOptions, FeaturedPagesOptions } from './domains/pages'\nexport type { TrustBadgeListParams } from './domains/trust-badges'\nexport {\n DEFAULT_CHECKOUT_REDIRECT_HOSTS,\n isSafeCheckoutRedirectUrl,\n UnsafeCheckoutRedirectError,\n} from './checkout-redirect'\nexport { PlainCacheAdapter } from './cache'\nexport type { RebluCacheAdapter, RebluCachePolicy } from './cache'\nexport type {\n ListResult,\n BlogListParams,\n PagesListParams,\n ShopProductsParams,\n AcademyCourseListParams,\n AcademyEnrollmentRequestInput,\n AcademyEnrollmentRequestResult,\n} from './types'\nexport {\n VISITOR_IP_HEADER,\n visitorIpFromHeaders,\n RETRY_AFTER_CAP_MS,\n type RebluMutationOptions,\n type RequestScope,\n} from './client'\nexport {\n buildContactFormMetadata,\n currentPagePath,\n type ContactFormMetadata,\n type ContactFormMetadataOptions,\n type PageLocation,\n} from './contact-form-metadata'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reblu/site-client",
3
- "version": "5.14.0",
3
+ "version": "5.15.0",
4
4
  "description": "Framework-agnostic HTTP client for the Reblu SITE API — dependency-free, injectable cache adapter, typed by @reblu/site-contracts.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Reblu — Adolfo Unturbe",
@@ -47,7 +47,7 @@
47
47
  "access": "public"
48
48
  },
49
49
  "peerDependencies": {
50
- "@reblu/site-contracts": "^1.23.0"
50
+ "@reblu/site-contracts": "^1.24.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@size-limit/preset-small-lib": "^11.1.6",
@@ -57,8 +57,8 @@
57
57
  "tsup": "^8.5.0",
58
58
  "typescript": "^5.8.3",
59
59
  "vitest": "^4.0.15",
60
- "@reblu/config": "0.0.1",
61
- "@reblu/site-contracts": "^1.23.0"
60
+ "@reblu/site-contracts": "^1.24.0",
61
+ "@reblu/config": "0.0.1"
62
62
  },
63
63
  "size-limit": [
64
64
  {