@reblu/site-client 5.2.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +51 -20
- package/dist/index.cjs +53 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +51 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @reblu/site-client
|
|
2
2
|
|
|
3
|
+
## 5.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c40434a: Add a distributable controlled phone input and E.164 normalization. Preserve and validate the additive checkout `details.field` in typed API errors so CheckoutForm can mark the rejected phone while retaining generic error fallback.
|
|
8
|
+
|
|
9
|
+
## 5.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 21feec3: REB-836 — checkout hardening: Stripe redirect-origin check + stable checkout error codes.
|
|
14
|
+
- `@reblu/site-contracts`: re-exports the new `ShopErrorCode` type (type-only, `z.infer` from base-api's `shopErrorCodeSchema`, no Zod reaches the published `.d.ts`) — nine values: `STOCK_CHANGED`, `PRICE_CHANGED`, `PRODUCT_UNAVAILABLE`, `DISCOUNT_INVALID`, `SHIPPING_UNAVAILABLE`, `INVALID_INPUT`, `STORE_DISABLED`, `PAYMENT_PROVIDER_ERROR`, and `INTERNAL_ERROR` (added in a native-review follow-up to distinguish an unexpected, non-Stripe failure — reported as HTTP 500 — from a Stripe failure, reported as 400 or, for a transient/5xx Stripe error, 503). This is the shop write endpoints' (`checkout`/`validateCart`/`applyDiscount`) new optional error-body `code` field.
|
|
15
|
+
- `@reblu/site-client`: (1) `shop.checkout()` now validates the returned Stripe Checkout URL is `https:` on an allowed host (default `checkout.stripe.com`, injectable via the new `RebluClientConfig.checkoutRedirectHosts`) before ever returning it, throwing the new `UnsafeCheckoutRedirectError` otherwise — exported alongside `isSafeCheckoutRedirectUrl` and `DEFAULT_CHECKOUT_REDIRECT_HOSTS`. (2) `ApiError.body` (`ApiErrorBody`/`ApiErrorDetails`) gains the optional `code` and `details.productIds` fields.
|
|
16
|
+
- `@reblu/site-next`: (1) `createShopCheckoutRoute` re-checks the Checkout URL server-side before responding to the browser (502 `unsafe_redirect` when it fails the check) — new `ShopCheckoutRouteOptions.allowedRedirectHosts`/`unsafeRedirectMessage`. (2) Native-review follow-up: that same route now strips `content-encoding`/`content-length`/`transfer-encoding` from its re-serialized response instead of forwarding them from the upstream proxy response, fixing a "browser tries to gunzip already-decoded JSON" failure mode.
|
|
17
|
+
- `@reblu/site-blocks`: adds `DEFAULT_SHOP_ERROR_MESSAGES` (a default Spanish message per `ShopErrorCode`, including `INTERNAL_ERROR`'s "Ha ocurrido un error inesperado. Inténtalo de nuevo en unos minutos.") and `getShopErrorMessage(code, overrides?, fallback?)`, which a SITE can override per code without restating the others.
|
|
18
|
+
|
|
19
|
+
All new fields/exports are additive and optional (REB-788) — a SITE that ignores `code`/`checkoutRedirectHosts` keeps working unchanged. The base-api side of this change (the `ShopErrorCode` schema itself, `checkout.service.ts`'s Stripe-vs-internal error classification, and `apiError()`'s options-object signature) is unpublished — it ships with the next base-api deploy, not through these changesets.
|
|
20
|
+
|
|
3
21
|
## 5.2.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -67,7 +67,10 @@ interface ApiErrorBody {
|
|
|
67
67
|
details?: {
|
|
68
68
|
fieldErrors?: Record<string, string[]> // per-field messages, e.g. details.fieldErrors.phone
|
|
69
69
|
formErrors?: string[] // form-level messages not tied to one field
|
|
70
|
+
productIds?: string[] // affected products for shop errors
|
|
71
|
+
field?: string // rejected request field, e.g. customerPhone
|
|
70
72
|
}
|
|
73
|
+
code?: string // optional machine-readable shop error code
|
|
71
74
|
}
|
|
72
75
|
```
|
|
73
76
|
|
|
@@ -75,11 +78,43 @@ This matches what `/api/site/contact-form` and `/api/site/leads` actually send o
|
|
|
75
78
|
a 400/422 (zod's `.flatten()` under the hood). `body` is `undefined` whenever the
|
|
76
79
|
response was not JSON shaped like this — e.g. an edge proxy's HTML error page on
|
|
77
80
|
a 502 — parsing is defensive and never throws while constructing the error.
|
|
81
|
+
An optional `details.field` must be a string; an invalid type makes the whole
|
|
82
|
+
`body` unrecognised, just as malformed `fieldErrors`, `formErrors` or
|
|
83
|
+
`productIds` do. Unknown field names are preserved as strings; the UI decides
|
|
84
|
+
whether it owns that field.
|
|
85
|
+
|
|
86
|
+
For checkout, pass **`ApiError.body`**, not `ApiError.message` (which includes
|
|
87
|
+
the transport prefix), to the presentational `@reblu/site-blocks` form:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { useState } from 'react'
|
|
91
|
+
import { ApiError, type ApiErrorBody } from '@reblu/site-client'
|
|
92
|
+
import { CheckoutForm } from '@reblu/site-blocks'
|
|
93
|
+
|
|
94
|
+
// Inside the SITE's checkout component (client, payload and checkoutProps in scope):
|
|
95
|
+
const [checkoutError, setCheckoutError] = useState<ApiErrorBody | null>(null)
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await client.shop.checkout(payload)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof ApiError) {
|
|
101
|
+
// An unparseable body still gets the form's generic fallback message.
|
|
102
|
+
setCheckoutError(error.body ?? { error: 'Checkout failed' })
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
;<CheckoutForm {...checkoutProps} checkoutError={checkoutError} />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Only `INVALID_INPUT` with `details.field === 'customerPhone'` marks the phone;
|
|
110
|
+
other or missing details keep the generic error path. Reset the error on edit or
|
|
111
|
+
retry in the consuming SITE. The SITE must adopt this code separately; the SDK
|
|
112
|
+
does not alter an existing checkout page by itself.
|
|
78
113
|
|
|
79
114
|
### Caching — the injectable adapter
|
|
80
115
|
|
|
81
|
-
The client owns
|
|
82
|
-
|
|
116
|
+
The client owns _when_ to cache (a per-call policy); a `RebluCacheAdapter` owns
|
|
117
|
+
_how_ (framework-specific `fetch` options). The default `PlainCacheAdapter` uses
|
|
83
118
|
plain `fetch` cache semantics and works in Node, edge, browser and tests:
|
|
84
119
|
|
|
85
120
|
```ts
|
|
@@ -98,29 +133,25 @@ injected.
|
|
|
98
133
|
Read endpoints for all nine SITE domains. Single-resource methods return the bare
|
|
99
134
|
resource; list methods return `{ data, meta? }` (pagination metadata preserved).
|
|
100
135
|
|
|
101
|
-
| Namespace
|
|
102
|
-
|
|
|
103
|
-
| `config`
|
|
104
|
-
| `analytics`
|
|
105
|
-
| `legal`
|
|
106
|
-
| `trustBadges` | `list()`
|
|
107
|
-
| `ctas`
|
|
108
|
-
| `blog`
|
|
109
|
-
| `pages`
|
|
110
|
-
| `shop`
|
|
136
|
+
| Namespace | Methods |
|
|
137
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
138
|
+
| `config` | `get()` |
|
|
139
|
+
| `analytics` | `get()` |
|
|
140
|
+
| `legal` | `get()` |
|
|
141
|
+
| `trustBadges` | `list()` |
|
|
142
|
+
| `ctas` | `list(slot)` |
|
|
143
|
+
| `blog` | `list(params?)`, `bySlug(slug)`, `related(slug)`, `categories()`, `slugs()`, `preview(id)` |
|
|
144
|
+
| `pages` | `list(params?)`, `bySlug(slug)`, `slugs()` |
|
|
145
|
+
| `shop` | `products(params?)`, `facets(params?)`, `bySlug(slug)`, `categories()`, `config()`, `checkout(body)`, `validateCart(body)`, `applyDiscount(body)`, `checkEmail(body)`, `order(sessionId)` |
|
|
111
146
|
|
|
112
147
|
Every method accepts an optional trailing `RebluCachePolicy` (`{ revalidate }`) to
|
|
113
148
|
override caching per call. `blog.preview` is always uncached (draft content).
|
|
114
149
|
|
|
115
|
-
### Write endpoints
|
|
150
|
+
### Write endpoints
|
|
116
151
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
adding them to the SDK requires a contracts extension first, so they are tracked
|
|
121
|
-
as a follow-up. See
|
|
122
|
-
[`docs/architecture/site-sdk-distribution-design.md`](../../docs/architecture/site-sdk-distribution-design.md)
|
|
123
|
-
(§3, D4).
|
|
152
|
+
`shop.checkout`, `shop.validateCart`, `shop.applyDiscount` and
|
|
153
|
+
`shop.checkEmail` send typed `@reblu/site-contracts` request bodies without
|
|
154
|
+
caching. Checkout error handling uses `ApiError.body` as shown above.
|
|
124
155
|
|
|
125
156
|
## Versioning
|
|
126
157
|
|
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,30 @@ var PlainCacheAdapter = class {
|
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// src/checkout-redirect.ts
|
|
16
|
+
var DEFAULT_CHECKOUT_REDIRECT_HOSTS = ["checkout.stripe.com"];
|
|
17
|
+
function isSafeCheckoutRedirectUrl(url, allowedHosts = DEFAULT_CHECKOUT_REDIRECT_HOSTS) {
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = new URL(url);
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return parsed.protocol === "https:" && allowedHosts.includes(parsed.hostname);
|
|
25
|
+
}
|
|
26
|
+
var UnsafeCheckoutRedirectError = class extends Error {
|
|
27
|
+
constructor(url, allowedHosts) {
|
|
28
|
+
super(
|
|
29
|
+
`Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} (allowed hosts: ${allowedHosts.join(", ")})`
|
|
30
|
+
);
|
|
31
|
+
this.url = url;
|
|
32
|
+
this.allowedHosts = allowedHosts;
|
|
33
|
+
this.name = "UnsafeCheckoutRedirectError";
|
|
34
|
+
}
|
|
35
|
+
url;
|
|
36
|
+
allowedHosts;
|
|
37
|
+
};
|
|
38
|
+
|
|
15
39
|
// src/build-url.ts
|
|
16
40
|
function buildUrl(base, params) {
|
|
17
41
|
if (!params) return base;
|
|
@@ -44,6 +68,8 @@ function isApiErrorDetails(value) {
|
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
70
|
if (details.formErrors !== void 0 && !isStringArray(details.formErrors)) return false;
|
|
71
|
+
if (details.productIds !== void 0 && !isStringArray(details.productIds)) return false;
|
|
72
|
+
if ("field" in details && typeof details.field !== "string") return false;
|
|
47
73
|
return true;
|
|
48
74
|
}
|
|
49
75
|
function isApiErrorBody(value) {
|
|
@@ -51,6 +77,7 @@ function isApiErrorBody(value) {
|
|
|
51
77
|
const body = value;
|
|
52
78
|
if (typeof body.error !== "string") return false;
|
|
53
79
|
if (body.details !== void 0 && !isApiErrorDetails(body.details)) return false;
|
|
80
|
+
if (body.code !== void 0 && typeof body.code !== "string") return false;
|
|
54
81
|
return true;
|
|
55
82
|
}
|
|
56
83
|
function parseApiErrorBody(rawBody) {
|
|
@@ -263,8 +290,27 @@ function makeShopNamespace(ctx) {
|
|
|
263
290
|
categories: (cache) => requestList(ctx, "/api/site/shop/categories", { cachePolicy: cache }),
|
|
264
291
|
config: (cache) => requestOne(ctx, "/api/site/shop/config", { cachePolicy: cache }),
|
|
265
292
|
// ── Mutations (REB-438) ──────────────────────────────────────────────────
|
|
266
|
-
/**
|
|
267
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Start a hosted checkout session. Returns the Stripe URL + session id.
|
|
295
|
+
*
|
|
296
|
+
* REB-836 (defence in depth): every SITE hands `url` straight to
|
|
297
|
+
* `window.location.assign`, so this validates it is `https:` on an
|
|
298
|
+
* allowed host (`ctx.checkoutRedirectHosts`, default
|
|
299
|
+
* `checkout.stripe.com`) BEFORE returning — throwing
|
|
300
|
+
* {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL
|
|
301
|
+
* that could redirect a buyer's browser off Stripe's domain.
|
|
302
|
+
*/
|
|
303
|
+
checkout: async (body) => {
|
|
304
|
+
const session = await requestMutation(
|
|
305
|
+
ctx,
|
|
306
|
+
"/api/site/shop/checkout",
|
|
307
|
+
body
|
|
308
|
+
);
|
|
309
|
+
if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {
|
|
310
|
+
throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts);
|
|
311
|
+
}
|
|
312
|
+
return session;
|
|
313
|
+
},
|
|
268
314
|
/** Validate a cart against live product/stock/price state before checkout. */
|
|
269
315
|
validateCart: (body) => requestMutation(
|
|
270
316
|
ctx,
|
|
@@ -308,7 +354,8 @@ function createRebluClient(config) {
|
|
|
308
354
|
apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,
|
|
309
355
|
cache: config.cache ?? new PlainCacheAdapter(),
|
|
310
356
|
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
311
|
-
fetch: boundFetch
|
|
357
|
+
fetch: boundFetch,
|
|
358
|
+
checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS
|
|
312
359
|
};
|
|
313
360
|
return {
|
|
314
361
|
config: makeConfigNamespace(ctx),
|
|
@@ -326,7 +373,10 @@ function createRebluClient(config) {
|
|
|
326
373
|
}
|
|
327
374
|
|
|
328
375
|
exports.ApiError = ApiError;
|
|
376
|
+
exports.DEFAULT_CHECKOUT_REDIRECT_HOSTS = DEFAULT_CHECKOUT_REDIRECT_HOSTS;
|
|
329
377
|
exports.PlainCacheAdapter = PlainCacheAdapter;
|
|
378
|
+
exports.UnsafeCheckoutRedirectError = UnsafeCheckoutRedirectError;
|
|
330
379
|
exports.createRebluClient = createRebluClient;
|
|
380
|
+
exports.isSafeCheckoutRedirectUrl = isSafeCheckoutRedirectUrl;
|
|
331
381
|
//# sourceMappingURL=index.cjs.map
|
|
332
382
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cache.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/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.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;;;ACxBO,SAAS,QAAA,CACd,MACA,MAAA,EACQ;AACR,EAAA,IAAI,CAAC,QAAQ,OAAO,IAAA;AACpB,EAAA,MAAM,QAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACjD,IAAA,MAAM,SAAS,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,KAAA,GAAQ,CAAC,KAAK,CAAA;AACpD,IAAA,KAAA,MAAW,KAAK,MAAA,EAAQ;AACtB,MAAA,IAAI,CAAA,KAAM,MAAA,IAAa,CAAA,KAAM,IAAA,EAAM;AACnC,MAAA,KAAA,CAAM,KAAK,CAAC,GAAA,EAAK,MAAA,CAAO,CAAC,CAAC,CAAC,CAAA;AAAA,IAC7B;AAAA,EACF;AACA,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAC/B,EAAA,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;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;AAAA,GACT;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;AAAA,GAC/B;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","/** 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\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\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[]`. 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 { fieldErrors?: unknown; formErrors?: unknown }\n\n if (details.fieldErrors !== undefined) {\n if (typeof details.fieldErrors !== 'object' || details.fieldErrors === null || Array.isArray(details.fieldErrors)) {\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 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 }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) 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","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\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 via\n * `AbortController`, throws a typed `ApiError` on non-2xx, and returns the parsed\n * JSON body verbatim (envelope unwrapping is the caller's concern).\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const url = ctx.baseUrl + path\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(url, {\n method: opts.method ?? 'GET',\n body: opts.body,\n signal: controller.signal,\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\n if (!res.ok) {\n throw new ApiError(res.status, path, await res.text())\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 * 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): Promise<Res> {\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { request, requestList, requestOne, type RebluClientContext } 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 /** 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 enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n ): Promise<AcademyEnrollmentRequestResult> =>\n request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\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 } 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 /** Submit a contact form. Returns the created lead acknowledgement. */\n submit: (body: ContactFormInput): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(ctx, '/api/site/contact-form', body),\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 { 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 type { ListResult, PagesListParams } from '../types'\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n return {\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 bySlug: (slug: string, cache?: RebluCachePolicy): Promise<PageDetail> =>\n requestOne<PageDetail>(ctx, `/api/site/pages/${slug}`, { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\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 { requestList, requestMutation, requestOne, type RebluClientContext } from '../client'\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, check-email) added in\n * 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 /** Start a hosted checkout session. Returns the Stripe URL + session id. */\n checkout: (body: ShopCheckoutInput): Promise<ShopCheckoutSession> =>\n requestMutation<ShopCheckoutInput, ShopCheckoutSession>(ctx, '/api/site/shop/checkout', body),\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 /** Check whether a customer with the given email already exists. */\n checkEmail: (body: ShopCheckEmailInput): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(ctx, '/api/site/shop/check-email', body),\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 } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** `GET /api/site/trust-badges` — the tenant's trust badges (no pagination). */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n return {\n list: (cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>> =>\n requestList<TrustBadge>(ctx, '/api/site/trust-badges', { cachePolicy: cache }),\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 } from './client'\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 { 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\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 }\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 }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails } from './errors'\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'\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/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.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,KAA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AE5B,IAAM,kBAAA,GAAqB,GAAA;AA6BpB,SAAS,kBAAkB,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;AAAA,GACzD;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;AAAA,GAC/B;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","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\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 via\n * `AbortController`, throws a typed `ApiError` on non-2xx, and returns the parsed\n * JSON body verbatim (envelope unwrapping is the caller's concern).\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const url = ctx.baseUrl + path\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(url, {\n method: opts.method ?? 'GET',\n body: opts.body,\n signal: controller.signal,\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\n if (!res.ok) {\n throw new ApiError(res.status, path, await res.text())\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 * 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): Promise<Res> {\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { request, requestList, requestOne, type RebluClientContext } 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 /** 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 enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n ): Promise<AcademyEnrollmentRequestResult> =>\n request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\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 } 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 /** Submit a contact form. Returns the created lead acknowledgement. */\n submit: (body: ContactFormInput): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(ctx, '/api/site/contact-form', body),\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 { 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 type { ListResult, PagesListParams } from '../types'\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n return {\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 bySlug: (slug: string, cache?: RebluCachePolicy): Promise<PageDetail> =>\n requestOne<PageDetail>(ctx, `/api/site/pages/${slug}`, { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\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 { requestList, requestMutation, requestOne, type RebluClientContext } 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, check-email) added in\n * 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 /** Check whether a customer with the given email already exists. */\n checkEmail: (body: ShopCheckEmailInput): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(ctx, '/api/site/shop/check-email', body),\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 } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** `GET /api/site/trust-badges` — the tenant's trust badges (no pagination). */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n return {\n list: (cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>> =>\n requestList<TrustBadge>(ctx, '/api/site/trust-badges', { cachePolicy: cache }),\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 } 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 { 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\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 }\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 }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails } from './errors'\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'\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -153,6 +153,13 @@ declare class PlainCacheAdapter implements RebluCacheAdapter {
|
|
|
153
153
|
interface ApiErrorDetails {
|
|
154
154
|
fieldErrors?: Record<string, string[]>;
|
|
155
155
|
formErrors?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /
|
|
158
|
+
* `PRICE_CHANGED` error — see `ApiErrorBody.code`.
|
|
159
|
+
*/
|
|
160
|
+
productIds?: string[];
|
|
161
|
+
/** REB-842: optional request-field identifier for checkout validation errors. */
|
|
162
|
+
field?: string;
|
|
156
163
|
}
|
|
157
164
|
/**
|
|
158
165
|
* The parsed shape of a non-2xx SITE API response body: `{ error, details? }`
|
|
@@ -162,6 +169,15 @@ interface ApiErrorDetails {
|
|
|
162
169
|
interface ApiErrorBody {
|
|
163
170
|
error: string;
|
|
164
171
|
details?: ApiErrorDetails;
|
|
172
|
+
/**
|
|
173
|
+
* REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from
|
|
174
|
+
* `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write
|
|
175
|
+
* endpoints may set — additive and OPTIONAL, so a consumer that only reads
|
|
176
|
+
* `error`/`message` keeps working unchanged. `string` rather than
|
|
177
|
+
* `ShopErrorCode` here because `ApiError` is a generic transport error used
|
|
178
|
+
* by every `/api/site/*` domain, not just shop.
|
|
179
|
+
*/
|
|
180
|
+
code?: string;
|
|
165
181
|
}
|
|
166
182
|
/**
|
|
167
183
|
* Typed transport error for the Reblu SITE API.
|
|
@@ -184,6 +200,39 @@ declare class ApiError extends Error {
|
|
|
184
200
|
constructor(status: number, path: string, message: string);
|
|
185
201
|
}
|
|
186
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Stripe Checkout redirect-origin guard (REB-836, defence in depth).
|
|
205
|
+
*
|
|
206
|
+
* `shop.checkout()` returns a URL every SITE immediately hands to
|
|
207
|
+
* `window.location.assign(url)`. Nothing upstream of this SDK validated it
|
|
208
|
+
* before REB-836 — a compromised/misconfigured base-api, a tampered
|
|
209
|
+
* response, or a MITM proxy could have sent a buyer's browser anywhere.
|
|
210
|
+
* `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses
|
|
211
|
+
* to refuse an unsafe URL before ever returning it to the caller; a SITE's
|
|
212
|
+
* `@reblu/site-next` Route Handler re-checks the SAME property server-side
|
|
213
|
+
* (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an
|
|
214
|
+
* independent copy — see that file's docblock for why it isn't a shared
|
|
215
|
+
* import). Update both together if Stripe ever changes its Checkout host.
|
|
216
|
+
*/
|
|
217
|
+
/** The only Checkout redirect host trusted by default. */
|
|
218
|
+
declare const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[];
|
|
219
|
+
/**
|
|
220
|
+
* True only when `url` parses as an absolute URL, uses `https:`, and its
|
|
221
|
+
* hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).
|
|
222
|
+
* Never throws — an unparsable `url` is simply unsafe.
|
|
223
|
+
*/
|
|
224
|
+
declare function isSafeCheckoutRedirectUrl(url: string, allowedHosts?: readonly string[]): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Thrown by `shop.checkout()` when base-api's Checkout URL fails
|
|
227
|
+
* {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back
|
|
228
|
+
* to a caller that would otherwise `window.location.assign` it.
|
|
229
|
+
*/
|
|
230
|
+
declare class UnsafeCheckoutRedirectError extends Error {
|
|
231
|
+
readonly url: string;
|
|
232
|
+
readonly allowedHosts: readonly string[];
|
|
233
|
+
constructor(url: string, allowedHosts: readonly string[]);
|
|
234
|
+
}
|
|
235
|
+
|
|
187
236
|
interface RebluClientConfig {
|
|
188
237
|
/** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */
|
|
189
238
|
baseUrl: string;
|
|
@@ -197,6 +246,13 @@ interface RebluClientConfig {
|
|
|
197
246
|
timeoutMs?: number;
|
|
198
247
|
/** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */
|
|
199
248
|
fetch?: typeof fetch;
|
|
249
|
+
/**
|
|
250
|
+
* Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns
|
|
251
|
+
* (REB-836, defence in depth — see `./checkout-redirect`). Defaults to
|
|
252
|
+
* `['checkout.stripe.com']`. Override only to point at a test double (e.g.
|
|
253
|
+
* a Stripe CLI mock host) — never to widen production trust.
|
|
254
|
+
*/
|
|
255
|
+
checkoutRedirectHosts?: string[];
|
|
200
256
|
}
|
|
201
257
|
/**
|
|
202
258
|
* Build a Reblu SITE API client. Each domain is a small namespace of bound
|
|
@@ -260,4 +316,4 @@ declare function createRebluClient(config: RebluClientConfig): {
|
|
|
260
316
|
/** The assembled client returned by {@link createRebluClient}. */
|
|
261
317
|
type RebluClient = ReturnType<typeof createRebluClient>;
|
|
262
318
|
|
|
263
|
-
export { type AcademyCourseListParams, type AcademyEnrollmentRequestInput, type AcademyEnrollmentRequestResult, ApiError, type ApiErrorBody, type ApiErrorDetails, type BlogListParams, type ListResult, type PagesListParams, PlainCacheAdapter, type RebluCacheAdapter, type RebluCachePolicy, type RebluClient, type RebluClientConfig, type ShopProductsParams, createRebluClient };
|
|
319
|
+
export { type AcademyCourseListParams, type AcademyEnrollmentRequestInput, type AcademyEnrollmentRequestResult, ApiError, type ApiErrorBody, type ApiErrorDetails, type BlogListParams, DEFAULT_CHECKOUT_REDIRECT_HOSTS, type ListResult, type PagesListParams, PlainCacheAdapter, type RebluCacheAdapter, type RebluCachePolicy, type RebluClient, type RebluClientConfig, type ShopProductsParams, UnsafeCheckoutRedirectError, createRebluClient, isSafeCheckoutRedirectUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -153,6 +153,13 @@ declare class PlainCacheAdapter implements RebluCacheAdapter {
|
|
|
153
153
|
interface ApiErrorDetails {
|
|
154
154
|
fieldErrors?: Record<string, string[]>;
|
|
155
155
|
formErrors?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* REB-836: the affected product ids on a shop checkout `STOCK_CHANGED` /
|
|
158
|
+
* `PRICE_CHANGED` error — see `ApiErrorBody.code`.
|
|
159
|
+
*/
|
|
160
|
+
productIds?: string[];
|
|
161
|
+
/** REB-842: optional request-field identifier for checkout validation errors. */
|
|
162
|
+
field?: string;
|
|
156
163
|
}
|
|
157
164
|
/**
|
|
158
165
|
* The parsed shape of a non-2xx SITE API response body: `{ error, details? }`
|
|
@@ -162,6 +169,15 @@ interface ApiErrorDetails {
|
|
|
162
169
|
interface ApiErrorBody {
|
|
163
170
|
error: string;
|
|
164
171
|
details?: ApiErrorDetails;
|
|
172
|
+
/**
|
|
173
|
+
* REB-836: stable, machine-readable error code (e.g. `ShopErrorCode` from
|
|
174
|
+
* `@reblu/site-contracts`) the checkout/validate-cart/apply-discount write
|
|
175
|
+
* endpoints may set — additive and OPTIONAL, so a consumer that only reads
|
|
176
|
+
* `error`/`message` keeps working unchanged. `string` rather than
|
|
177
|
+
* `ShopErrorCode` here because `ApiError` is a generic transport error used
|
|
178
|
+
* by every `/api/site/*` domain, not just shop.
|
|
179
|
+
*/
|
|
180
|
+
code?: string;
|
|
165
181
|
}
|
|
166
182
|
/**
|
|
167
183
|
* Typed transport error for the Reblu SITE API.
|
|
@@ -184,6 +200,39 @@ declare class ApiError extends Error {
|
|
|
184
200
|
constructor(status: number, path: string, message: string);
|
|
185
201
|
}
|
|
186
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Stripe Checkout redirect-origin guard (REB-836, defence in depth).
|
|
205
|
+
*
|
|
206
|
+
* `shop.checkout()` returns a URL every SITE immediately hands to
|
|
207
|
+
* `window.location.assign(url)`. Nothing upstream of this SDK validated it
|
|
208
|
+
* before REB-836 — a compromised/misconfigured base-api, a tampered
|
|
209
|
+
* response, or a MITM proxy could have sent a buyer's browser anywhere.
|
|
210
|
+
* `isSafeCheckoutRedirectUrl` is the shared predicate `domains/shop.ts` uses
|
|
211
|
+
* to refuse an unsafe URL before ever returning it to the caller; a SITE's
|
|
212
|
+
* `@reblu/site-next` Route Handler re-checks the SAME property server-side
|
|
213
|
+
* (`packages/site-next/src/shop/checkout-redirect.ts`, kept as an
|
|
214
|
+
* independent copy — see that file's docblock for why it isn't a shared
|
|
215
|
+
* import). Update both together if Stripe ever changes its Checkout host.
|
|
216
|
+
*/
|
|
217
|
+
/** The only Checkout redirect host trusted by default. */
|
|
218
|
+
declare const DEFAULT_CHECKOUT_REDIRECT_HOSTS: readonly string[];
|
|
219
|
+
/**
|
|
220
|
+
* True only when `url` parses as an absolute URL, uses `https:`, and its
|
|
221
|
+
* hostname is in `allowedHosts` (default: {@link DEFAULT_CHECKOUT_REDIRECT_HOSTS}).
|
|
222
|
+
* Never throws — an unparsable `url` is simply unsafe.
|
|
223
|
+
*/
|
|
224
|
+
declare function isSafeCheckoutRedirectUrl(url: string, allowedHosts?: readonly string[]): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Thrown by `shop.checkout()` when base-api's Checkout URL fails
|
|
227
|
+
* {@link isSafeCheckoutRedirectUrl} — the SDK never hands an unsafe URL back
|
|
228
|
+
* to a caller that would otherwise `window.location.assign` it.
|
|
229
|
+
*/
|
|
230
|
+
declare class UnsafeCheckoutRedirectError extends Error {
|
|
231
|
+
readonly url: string;
|
|
232
|
+
readonly allowedHosts: readonly string[];
|
|
233
|
+
constructor(url: string, allowedHosts: readonly string[]);
|
|
234
|
+
}
|
|
235
|
+
|
|
187
236
|
interface RebluClientConfig {
|
|
188
237
|
/** Absolute origin of the Reblu SITE API, e.g. `https://api.reblu.app`. */
|
|
189
238
|
baseUrl: string;
|
|
@@ -197,6 +246,13 @@ interface RebluClientConfig {
|
|
|
197
246
|
timeoutMs?: number;
|
|
198
247
|
/** Injectable `fetch` — for tests, custom runtimes, or instrumentation. */
|
|
199
248
|
fetch?: typeof fetch;
|
|
249
|
+
/**
|
|
250
|
+
* Allowed hosts for the Stripe Checkout URL `shop.checkout()` returns
|
|
251
|
+
* (REB-836, defence in depth — see `./checkout-redirect`). Defaults to
|
|
252
|
+
* `['checkout.stripe.com']`. Override only to point at a test double (e.g.
|
|
253
|
+
* a Stripe CLI mock host) — never to widen production trust.
|
|
254
|
+
*/
|
|
255
|
+
checkoutRedirectHosts?: string[];
|
|
200
256
|
}
|
|
201
257
|
/**
|
|
202
258
|
* Build a Reblu SITE API client. Each domain is a small namespace of bound
|
|
@@ -260,4 +316,4 @@ declare function createRebluClient(config: RebluClientConfig): {
|
|
|
260
316
|
/** The assembled client returned by {@link createRebluClient}. */
|
|
261
317
|
type RebluClient = ReturnType<typeof createRebluClient>;
|
|
262
318
|
|
|
263
|
-
export { type AcademyCourseListParams, type AcademyEnrollmentRequestInput, type AcademyEnrollmentRequestResult, ApiError, type ApiErrorBody, type ApiErrorDetails, type BlogListParams, type ListResult, type PagesListParams, PlainCacheAdapter, type RebluCacheAdapter, type RebluCachePolicy, type RebluClient, type RebluClientConfig, type ShopProductsParams, createRebluClient };
|
|
319
|
+
export { type AcademyCourseListParams, type AcademyEnrollmentRequestInput, type AcademyEnrollmentRequestResult, ApiError, type ApiErrorBody, type ApiErrorDetails, type BlogListParams, DEFAULT_CHECKOUT_REDIRECT_HOSTS, type ListResult, type PagesListParams, PlainCacheAdapter, type RebluCacheAdapter, type RebluCachePolicy, type RebluClient, type RebluClientConfig, type ShopProductsParams, UnsafeCheckoutRedirectError, createRebluClient, isSafeCheckoutRedirectUrl };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,30 @@ var PlainCacheAdapter = class {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// src/checkout-redirect.ts
|
|
14
|
+
var DEFAULT_CHECKOUT_REDIRECT_HOSTS = ["checkout.stripe.com"];
|
|
15
|
+
function isSafeCheckoutRedirectUrl(url, allowedHosts = DEFAULT_CHECKOUT_REDIRECT_HOSTS) {
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = new URL(url);
|
|
19
|
+
} catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return parsed.protocol === "https:" && allowedHosts.includes(parsed.hostname);
|
|
23
|
+
}
|
|
24
|
+
var UnsafeCheckoutRedirectError = class extends Error {
|
|
25
|
+
constructor(url, allowedHosts) {
|
|
26
|
+
super(
|
|
27
|
+
`Refusing to return an unsafe Stripe Checkout redirect URL: ${JSON.stringify(url)} (allowed hosts: ${allowedHosts.join(", ")})`
|
|
28
|
+
);
|
|
29
|
+
this.url = url;
|
|
30
|
+
this.allowedHosts = allowedHosts;
|
|
31
|
+
this.name = "UnsafeCheckoutRedirectError";
|
|
32
|
+
}
|
|
33
|
+
url;
|
|
34
|
+
allowedHosts;
|
|
35
|
+
};
|
|
36
|
+
|
|
13
37
|
// src/build-url.ts
|
|
14
38
|
function buildUrl(base, params) {
|
|
15
39
|
if (!params) return base;
|
|
@@ -42,6 +66,8 @@ function isApiErrorDetails(value) {
|
|
|
42
66
|
}
|
|
43
67
|
}
|
|
44
68
|
if (details.formErrors !== void 0 && !isStringArray(details.formErrors)) return false;
|
|
69
|
+
if (details.productIds !== void 0 && !isStringArray(details.productIds)) return false;
|
|
70
|
+
if ("field" in details && typeof details.field !== "string") return false;
|
|
45
71
|
return true;
|
|
46
72
|
}
|
|
47
73
|
function isApiErrorBody(value) {
|
|
@@ -49,6 +75,7 @@ function isApiErrorBody(value) {
|
|
|
49
75
|
const body = value;
|
|
50
76
|
if (typeof body.error !== "string") return false;
|
|
51
77
|
if (body.details !== void 0 && !isApiErrorDetails(body.details)) return false;
|
|
78
|
+
if (body.code !== void 0 && typeof body.code !== "string") return false;
|
|
52
79
|
return true;
|
|
53
80
|
}
|
|
54
81
|
function parseApiErrorBody(rawBody) {
|
|
@@ -261,8 +288,27 @@ function makeShopNamespace(ctx) {
|
|
|
261
288
|
categories: (cache) => requestList(ctx, "/api/site/shop/categories", { cachePolicy: cache }),
|
|
262
289
|
config: (cache) => requestOne(ctx, "/api/site/shop/config", { cachePolicy: cache }),
|
|
263
290
|
// ── Mutations (REB-438) ──────────────────────────────────────────────────
|
|
264
|
-
/**
|
|
265
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Start a hosted checkout session. Returns the Stripe URL + session id.
|
|
293
|
+
*
|
|
294
|
+
* REB-836 (defence in depth): every SITE hands `url` straight to
|
|
295
|
+
* `window.location.assign`, so this validates it is `https:` on an
|
|
296
|
+
* allowed host (`ctx.checkoutRedirectHosts`, default
|
|
297
|
+
* `checkout.stripe.com`) BEFORE returning — throwing
|
|
298
|
+
* {@link UnsafeCheckoutRedirectError} instead of ever handing back a URL
|
|
299
|
+
* that could redirect a buyer's browser off Stripe's domain.
|
|
300
|
+
*/
|
|
301
|
+
checkout: async (body) => {
|
|
302
|
+
const session = await requestMutation(
|
|
303
|
+
ctx,
|
|
304
|
+
"/api/site/shop/checkout",
|
|
305
|
+
body
|
|
306
|
+
);
|
|
307
|
+
if (!isSafeCheckoutRedirectUrl(session.url, ctx.checkoutRedirectHosts)) {
|
|
308
|
+
throw new UnsafeCheckoutRedirectError(session.url, ctx.checkoutRedirectHosts);
|
|
309
|
+
}
|
|
310
|
+
return session;
|
|
311
|
+
},
|
|
266
312
|
/** Validate a cart against live product/stock/price state before checkout. */
|
|
267
313
|
validateCart: (body) => requestMutation(
|
|
268
314
|
ctx,
|
|
@@ -306,7 +352,8 @@ function createRebluClient(config) {
|
|
|
306
352
|
apiVersion: config.apiVersion ?? DEFAULT_API_VERSION,
|
|
307
353
|
cache: config.cache ?? new PlainCacheAdapter(),
|
|
308
354
|
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
309
|
-
fetch: boundFetch
|
|
355
|
+
fetch: boundFetch,
|
|
356
|
+
checkoutRedirectHosts: config.checkoutRedirectHosts ?? DEFAULT_CHECKOUT_REDIRECT_HOSTS
|
|
310
357
|
};
|
|
311
358
|
return {
|
|
312
359
|
config: makeConfigNamespace(ctx),
|
|
@@ -323,6 +370,6 @@ function createRebluClient(config) {
|
|
|
323
370
|
};
|
|
324
371
|
}
|
|
325
372
|
|
|
326
|
-
export { ApiError, PlainCacheAdapter, createRebluClient };
|
|
373
|
+
export { ApiError, DEFAULT_CHECKOUT_REDIRECT_HOSTS, PlainCacheAdapter, UnsafeCheckoutRedirectError, createRebluClient, isSafeCheckoutRedirectUrl };
|
|
327
374
|
//# sourceMappingURL=index.js.map
|
|
328
375
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cache.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/leads.ts","../src/domains/legal.ts","../src/domains/p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AA,IAAa,kBAAA;AAAA,IAC/B,KAAA,EAAO;AAAA,GACT;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;AAAA,GAC/B;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","/** 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\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\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[]`. 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 { fieldErrors?: unknown; formErrors?: unknown }\n\n if (details.fieldErrors !== undefined) {\n if (typeof details.fieldErrors !== 'object' || details.fieldErrors === null || Array.isArray(details.fieldErrors)) {\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 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 }\n if (typeof body.error !== 'string') return false\n if (body.details !== undefined && !isApiErrorDetails(body.details)) 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","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\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 via\n * `AbortController`, throws a typed `ApiError` on non-2xx, and returns the parsed\n * JSON body verbatim (envelope unwrapping is the caller's concern).\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const url = ctx.baseUrl + path\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(url, {\n method: opts.method ?? 'GET',\n body: opts.body,\n signal: controller.signal,\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\n if (!res.ok) {\n throw new ApiError(res.status, path, await res.text())\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 * 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): Promise<Res> {\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { request, requestList, requestOne, type RebluClientContext } 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 /** 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 enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n ): Promise<AcademyEnrollmentRequestResult> =>\n request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\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 } 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 /** Submit a contact form. Returns the created lead acknowledgement. */\n submit: (body: ContactFormInput): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(ctx, '/api/site/contact-form', body),\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 { 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 type { ListResult, PagesListParams } from '../types'\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n return {\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 bySlug: (slug: string, cache?: RebluCachePolicy): Promise<PageDetail> =>\n requestOne<PageDetail>(ctx, `/api/site/pages/${slug}`, { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\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 { requestList, requestMutation, requestOne, type RebluClientContext } from '../client'\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, check-email) added in\n * 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 /** Start a hosted checkout session. Returns the Stripe URL + session id. */\n checkout: (body: ShopCheckoutInput): Promise<ShopCheckoutSession> =>\n requestMutation<ShopCheckoutInput, ShopCheckoutSession>(ctx, '/api/site/shop/checkout', body),\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 /** Check whether a customer with the given email already exists. */\n checkEmail: (body: ShopCheckEmailInput): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(ctx, '/api/site/shop/check-email', body),\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 } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** `GET /api/site/trust-badges` — the tenant's trust badges (no pagination). */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n return {\n list: (cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>> =>\n requestList<TrustBadge>(ctx, '/api/site/trust-badges', { cachePolicy: cache }),\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 } from './client'\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 { 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\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 }\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 }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails } from './errors'\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'\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/leads.ts","../src/domains/legal.ts","../src/domains/pages.ts","../src/domains/shop.ts","../src/domains/trust-badges.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,I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AAO,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;AAAA,GACzD;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;AAAA,GAC/B;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","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\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 via\n * `AbortController`, throws a typed `ApiError` on non-2xx, and returns the parsed\n * JSON body verbatim (envelope unwrapping is the caller's concern).\n */\nexport async function request<T>(\n ctx: RebluClientContext,\n path: string,\n opts: RequestOptions,\n): Promise<T> {\n const url = ctx.baseUrl + path\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), ctx.timeoutMs)\n\n try {\n const res = await ctx.fetch(url, {\n method: opts.method ?? 'GET',\n body: opts.body,\n signal: controller.signal,\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\n if (!res.ok) {\n throw new ApiError(res.status, path, await res.text())\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 * 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): Promise<Res> {\n const envelope = await request<{ data: Res }>(ctx, path, {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\n })\n return envelope.data\n}\n","import type {\n AcademyCategoryPublic,\n AcademyCourseDetail,\n AcademyCourseSummary,\n} from '@reblu/site-contracts'\nimport { buildUrl, type QueryValue } from '../build-url'\nimport type { RebluCachePolicy } from '../cache'\nimport { request, requestList, requestOne, type RebluClientContext } 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 /** 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 enrollmentRequest: (\n body: AcademyEnrollmentRequestInput,\n ): Promise<AcademyEnrollmentRequestResult> =>\n request<AcademyEnrollmentRequestResult>(ctx, '/api/site/academy/enrollment-requests', {\n method: 'POST',\n body: JSON.stringify(body),\n cachePolicy: { revalidate: false },\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 } 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 /** Submit a contact form. Returns the created lead acknowledgement. */\n submit: (body: ContactFormInput): Promise<ContactFormSubmission> =>\n requestMutation<ContactFormInput, ContactFormSubmission>(ctx, '/api/site/contact-form', body),\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 { 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 type { ListResult, PagesListParams } from '../types'\n\n/** Dynamic pages domain — `GET /api/site/pages/*`. */\nexport function makePagesNamespace(ctx: RebluClientContext) {\n return {\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 bySlug: (slug: string, cache?: RebluCachePolicy): Promise<PageDetail> =>\n requestOne<PageDetail>(ctx, `/api/site/pages/${slug}`, { cachePolicy: cache }),\n\n slugs: (cache?: RebluCachePolicy): Promise<ListResult<PageSlug>> =>\n requestList<PageSlug>(ctx, '/api/site/pages/slugs', { cachePolicy: cache }),\n }\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 { requestList, requestMutation, requestOne, type RebluClientContext } 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, check-email) added in\n * 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 /** Check whether a customer with the given email already exists. */\n checkEmail: (body: ShopCheckEmailInput): Promise<ShopEmailCheck> =>\n requestMutation<ShopCheckEmailInput, ShopEmailCheck>(ctx, '/api/site/shop/check-email', body),\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 } from '@reblu/site-contracts'\nimport type { RebluCachePolicy } from '../cache'\nimport { requestList, type RebluClientContext } from '../client'\nimport type { ListResult } from '../types'\n\n/** `GET /api/site/trust-badges` — the tenant's trust badges (no pagination). */\nexport function makeTrustBadgesNamespace(ctx: RebluClientContext) {\n return {\n list: (cache?: RebluCachePolicy): Promise<ListResult<TrustBadge>> =>\n requestList<TrustBadge>(ctx, '/api/site/trust-badges', { cachePolicy: cache }),\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 } 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 { 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\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 }\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 }\n}\n\n/** The assembled client returned by {@link createRebluClient}. */\nexport type RebluClient = ReturnType<typeof createRebluClient>\n\nexport { ApiError } from './errors'\nexport type { ApiErrorBody, ApiErrorDetails } from './errors'\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'\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reblu/site-client",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
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.
|
|
50
|
+
"@reblu/site-contracts": "^1.6.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@size-limit/preset-small-lib": "^11.1.6",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"typescript": "^5.8.3",
|
|
59
59
|
"vitest": "^4.0.15",
|
|
60
60
|
"@reblu/config": "0.0.1",
|
|
61
|
-
"@reblu/site-contracts": "^1.
|
|
61
|
+
"@reblu/site-contracts": "^1.6.0"
|
|
62
62
|
},
|
|
63
63
|
"size-limit": [
|
|
64
64
|
{
|