@riverbankcms/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +4840 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/client/bookings.d.mts +82 -2
- package/dist/client/bookings.d.ts +82 -2
- package/dist/client/bookings.js +1623 -3
- package/dist/client/bookings.js.map +1 -1
- package/dist/client/bookings.mjs +1610 -5
- package/dist/client/bookings.mjs.map +1 -1
- package/dist/client/client.d.mts +8 -5
- package/dist/client/client.d.ts +8 -5
- package/dist/client/client.js +16873 -322
- package/dist/client/client.js.map +1 -1
- package/dist/client/client.mjs +16855 -307
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/hooks.d.mts +10 -7
- package/dist/client/hooks.d.ts +10 -7
- package/dist/client/hooks.js +5074 -4
- package/dist/client/hooks.js.map +1 -1
- package/dist/client/hooks.mjs +5074 -4
- package/dist/client/hooks.mjs.map +1 -1
- package/dist/client/rendering/client.d.mts +7 -1
- package/dist/client/rendering/client.d.ts +7 -1
- package/dist/client/rendering/client.js +17388 -2
- package/dist/client/rendering/client.js.map +1 -1
- package/dist/client/rendering/client.mjs +17382 -2
- package/dist/client/rendering/client.mjs.map +1 -1
- package/dist/client/resolver-BhueZVxZ.d.mts +61 -0
- package/dist/client/resolver-BhueZVxZ.d.ts +61 -0
- package/dist/client/usePage-BBcFCxOU.d.ts +6297 -0
- package/dist/client/usePage-BydHcMYB.d.mts +6297 -0
- package/dist/client/usePage-CrKw1H6Y.d.ts +6338 -0
- package/dist/client/usePage-DMI8ImsU.d.mts +6338 -0
- package/dist/server/Layout-BM_KmCxO.d.ts +44 -0
- package/dist/server/Layout-CsAQ-0Fv.d.mts +44 -0
- package/dist/server/{chunk-JB4LIEFS.js → chunk-5R4NMVXA.js} +15 -8
- package/dist/server/chunk-5R4NMVXA.js.map +1 -0
- package/dist/server/{chunk-ADREPXFU.js → chunk-62ZJI564.js} +3 -3
- package/dist/server/{chunk-ADREPXFU.js.map → chunk-62ZJI564.js.map} +1 -1
- package/dist/server/chunk-7DS4Q3GA.mjs +333 -0
- package/dist/server/chunk-7DS4Q3GA.mjs.map +1 -0
- package/dist/server/chunk-BJTO5JO5.mjs +11 -0
- package/dist/server/{chunk-4Z5FBFRL.mjs → chunk-BPKYRPCQ.mjs} +7 -3
- package/dist/server/{chunk-4Z5FBFRL.mjs.map → chunk-BPKYRPCQ.mjs.map} +1 -1
- package/dist/server/chunk-DGUM43GV.js +11 -0
- package/dist/server/chunk-DGUM43GV.js.map +1 -0
- package/dist/server/chunk-EGTDJ4PL.js +5461 -0
- package/dist/server/chunk-EGTDJ4PL.js.map +1 -0
- package/dist/server/chunk-FK64TZBT.mjs +831 -0
- package/dist/server/chunk-FK64TZBT.mjs.map +1 -0
- package/dist/server/chunk-HOY77YBF.js +333 -0
- package/dist/server/chunk-HOY77YBF.js.map +1 -0
- package/dist/server/chunk-INWKF3IC.js +831 -0
- package/dist/server/chunk-INWKF3IC.js.map +1 -0
- package/dist/server/{chunk-2RW5HAQQ.mjs → chunk-JTAERCX2.mjs} +2 -2
- package/dist/server/chunk-O5DC7MYW.mjs +9606 -0
- package/dist/server/chunk-O5DC7MYW.mjs.map +1 -0
- package/dist/server/{chunk-PEAXKTDU.mjs → chunk-OP2GHK27.mjs} +2 -2
- package/dist/server/{chunk-WKG57P2H.mjs → chunk-PN3CHDVX.mjs} +10 -3
- package/dist/server/{chunk-WKG57P2H.mjs.map → chunk-PN3CHDVX.mjs.map} +1 -1
- package/dist/server/chunk-QFFQTOY3.mjs +2128 -0
- package/dist/server/chunk-QFFQTOY3.mjs.map +1 -0
- package/dist/server/chunk-SF63XAX7.js +9606 -0
- package/dist/server/chunk-SF63XAX7.js.map +1 -0
- package/dist/server/{chunk-F472SMKX.js → chunk-TO7FD6TQ.js} +4 -4
- package/dist/server/{chunk-F472SMKX.js.map → chunk-TO7FD6TQ.js.map} +1 -1
- package/dist/server/chunk-UFVCBGBY.js +2128 -0
- package/dist/server/chunk-UFVCBGBY.js.map +1 -0
- package/dist/server/chunk-USQF2XTU.mjs +5461 -0
- package/dist/server/chunk-USQF2XTU.mjs.map +1 -0
- package/dist/server/{chunk-SW7LE4M3.js → chunk-XLVL5WPH.js} +12 -8
- package/dist/server/chunk-XLVL5WPH.js.map +1 -0
- package/dist/server/components-CI3JiOYA.d.mts +305 -0
- package/dist/server/components-DJBLu_yc.d.ts +305 -0
- package/dist/server/components.d.mts +14 -49
- package/dist/server/components.d.ts +14 -49
- package/dist/server/components.js +7 -4
- package/dist/server/components.js.map +1 -1
- package/dist/server/components.mjs +9 -6
- package/dist/server/components.mjs.map +1 -1
- package/dist/server/config-validation.d.mts +2 -2
- package/dist/server/config-validation.d.ts +2 -2
- package/dist/server/config-validation.js +6 -3
- package/dist/server/config-validation.js.map +1 -1
- package/dist/server/config-validation.mjs +5 -2
- package/dist/server/config.d.mts +3 -3
- package/dist/server/config.d.ts +3 -3
- package/dist/server/config.js +6 -3
- package/dist/server/config.js.map +1 -1
- package/dist/server/config.mjs +5 -2
- package/dist/server/config.mjs.map +1 -1
- package/dist/server/data.d.mts +10 -8
- package/dist/server/data.d.ts +10 -8
- package/dist/server/data.js +4 -2
- package/dist/server/data.js.map +1 -1
- package/dist/server/data.mjs +3 -1
- package/dist/server/{index-B0yI_V6Z.d.mts → index-DoX3ELQn.d.mts} +1 -1
- package/dist/server/{index-C6M0Wfjq.d.ts → index-Dus2gkY6.d.ts} +1 -1
- package/dist/server/index.d.mts +1568 -5
- package/dist/server/index.d.ts +1568 -5
- package/dist/server/index.js +4 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +4 -4
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/{loadContent-CJcbYF3J.d.ts → loadContent-CdXDGsJM.d.ts} +5 -4
- package/dist/server/{loadContent-zhlL4YSE.d.mts → loadContent-v2n6pOlO.d.mts} +5 -4
- package/dist/server/loadPage-3ECPF426.js +11 -0
- package/dist/server/loadPage-3ECPF426.js.map +1 -0
- package/dist/server/loadPage-LW273NYO.mjs +11 -0
- package/dist/server/loadPage-LW273NYO.mjs.map +1 -0
- package/dist/server/{loadPage-CCf15nt8.d.mts → loadPage-bejlajm9.d.ts} +147 -5
- package/dist/server/{loadPage-BYmVMk0V.d.ts → loadPage-en10WQrt.d.mts} +147 -5
- package/dist/server/metadata.d.mts +10 -6
- package/dist/server/metadata.d.ts +10 -6
- package/dist/server/metadata.js +3 -1
- package/dist/server/metadata.js.map +1 -1
- package/dist/server/metadata.mjs +2 -0
- package/dist/server/metadata.mjs.map +1 -1
- package/dist/server/navigation.d.mts +100 -0
- package/dist/server/navigation.d.ts +100 -0
- package/dist/server/navigation.js +44 -0
- package/dist/server/navigation.js.map +1 -0
- package/dist/server/navigation.mjs +44 -0
- package/dist/server/navigation.mjs.map +1 -0
- package/dist/server/rendering/server.d.mts +10 -7
- package/dist/server/rendering/server.d.ts +10 -7
- package/dist/server/rendering/server.js +7 -4
- package/dist/server/rendering/server.js.map +1 -1
- package/dist/server/rendering/server.mjs +6 -3
- package/dist/server/rendering.d.mts +173 -9
- package/dist/server/rendering.d.ts +173 -9
- package/dist/server/rendering.js +12 -9
- package/dist/server/rendering.js.map +1 -1
- package/dist/server/rendering.mjs +14 -11
- package/dist/server/rendering.mjs.map +1 -1
- package/dist/server/routing.d.mts +10 -6
- package/dist/server/routing.d.ts +10 -6
- package/dist/server/routing.js +4 -2
- package/dist/server/routing.js.map +1 -1
- package/dist/server/routing.mjs +3 -1
- package/dist/server/routing.mjs.map +1 -1
- package/dist/server/schema-Bpy9N5ZI.d.mts +1870 -0
- package/dist/server/schema-Bpy9N5ZI.d.ts +1870 -0
- package/dist/server/server.d.mts +12 -8
- package/dist/server/server.d.ts +12 -8
- package/dist/server/server.js +7 -5
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +6 -4
- package/dist/server/theme-bridge.js +13 -10
- package/dist/server/theme-bridge.js.map +1 -1
- package/dist/server/theme-bridge.mjs +10 -7
- package/dist/server/theme-bridge.mjs.map +1 -1
- package/dist/server/theme.js +3 -1
- package/dist/server/theme.js.map +1 -1
- package/dist/server/theme.mjs +2 -0
- package/dist/server/theme.mjs.map +1 -1
- package/dist/server/{types-BCeqWtI2.d.mts → types-Bq3520hK.d.mts} +3 -3
- package/dist/server/{types-C6gmRHLe.d.mts → types-CLusapsM.d.mts} +1 -1
- package/dist/server/types-Cc7lyPkN.d.ts +4043 -0
- package/dist/server/{types-BCeqWtI2.d.ts → types-D-rqOU5I.d.ts} +3 -3
- package/dist/server/{types-C6gmRHLe.d.ts → types-Ls6BkLKg.d.ts} +1 -1
- package/dist/server/{types-Bbo01M7P.d.mts → types-_nDnPHpv.d.mts} +27 -1
- package/dist/server/{types-Bbo01M7P.d.ts → types-_nDnPHpv.d.ts} +27 -1
- package/dist/server/types-nVerjjdv.d.mts +4043 -0
- package/package.json +22 -17
- package/dist/server/chunk-3KKZVGH4.mjs +0 -179
- package/dist/server/chunk-3KKZVGH4.mjs.map +0 -1
- package/dist/server/chunk-4Z3GPTCS.js +0 -179
- package/dist/server/chunk-4Z3GPTCS.js.map +0 -1
- package/dist/server/chunk-JB4LIEFS.js.map +0 -1
- package/dist/server/chunk-QQ6U4QX6.js +0 -120
- package/dist/server/chunk-QQ6U4QX6.js.map +0 -1
- package/dist/server/chunk-R5YGLRUG.mjs +0 -122
- package/dist/server/chunk-R5YGLRUG.mjs.map +0 -1
- package/dist/server/chunk-SW7LE4M3.js.map +0 -1
- package/dist/server/chunk-W3K7LVPS.mjs +0 -120
- package/dist/server/chunk-W3K7LVPS.mjs.map +0 -1
- package/dist/server/chunk-YHEZMVTS.js +0 -122
- package/dist/server/chunk-YHEZMVTS.js.map +0 -1
- package/dist/server/loadPage-DVH3DW6E.js +0 -9
- package/dist/server/loadPage-DVH3DW6E.js.map +0 -1
- package/dist/server/loadPage-PHQZ6XQZ.mjs +0 -9
- /package/dist/server/{loadPage-PHQZ6XQZ.mjs.map → chunk-BJTO5JO5.mjs.map} +0 -0
- /package/dist/server/{chunk-2RW5HAQQ.mjs.map → chunk-JTAERCX2.mjs.map} +0 -0
- /package/dist/server/{chunk-PEAXKTDU.mjs.map → chunk-OP2GHK27.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riverbankcms/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Riverbank CMS SDK for headless content consumption",
|
|
5
5
|
"main": "./dist/server/index.js",
|
|
6
6
|
"module": "./dist/server/index.mjs",
|
|
@@ -69,6 +69,11 @@
|
|
|
69
69
|
"import": "./dist/server/routing.mjs",
|
|
70
70
|
"require": "./dist/server/routing.js"
|
|
71
71
|
},
|
|
72
|
+
"./navigation": {
|
|
73
|
+
"types": "./dist/server/navigation.d.ts",
|
|
74
|
+
"import": "./dist/server/navigation.mjs",
|
|
75
|
+
"require": "./dist/server/navigation.js"
|
|
76
|
+
},
|
|
72
77
|
"./analytics": {
|
|
73
78
|
"types": "./dist/client/analytics.d.ts",
|
|
74
79
|
"import": "./dist/client/analytics.mjs",
|
|
@@ -101,19 +106,27 @@
|
|
|
101
106
|
"src/styles",
|
|
102
107
|
"README.md"
|
|
103
108
|
],
|
|
109
|
+
"scripts": {
|
|
110
|
+
"build": "tsup",
|
|
111
|
+
"dev": "tsup --watch",
|
|
112
|
+
"typecheck": "tsc --noEmit",
|
|
113
|
+
"lint": "eslint src",
|
|
114
|
+
"test": "vitest run",
|
|
115
|
+
"verify": "./verify.sh"
|
|
116
|
+
},
|
|
104
117
|
"dependencies": {
|
|
105
118
|
"commander": "^12.1.0",
|
|
106
119
|
"jiti": "^2.6.1",
|
|
107
|
-
"zod": "^4.1.1"
|
|
108
|
-
"@riverbankcms/api": "0.1.0",
|
|
109
|
-
"@riverbankcms/blocks": "0.1.0",
|
|
110
|
-
"@riverbankcms/site-renderer": "0.1.0"
|
|
120
|
+
"zod": "^4.1.1"
|
|
111
121
|
},
|
|
112
122
|
"peerDependencies": {
|
|
113
|
-
"react": "19.1
|
|
114
|
-
"react-dom": "19.1
|
|
123
|
+
"react": "^19.2.1",
|
|
124
|
+
"react-dom": "^19.2.1"
|
|
115
125
|
},
|
|
116
126
|
"devDependencies": {
|
|
127
|
+
"@riverbankcms/api": "workspace:*",
|
|
128
|
+
"@riverbankcms/blocks": "workspace:*",
|
|
129
|
+
"@riverbankcms/site-renderer": "workspace:*",
|
|
117
130
|
"@types/node": "^22.0.0",
|
|
118
131
|
"@types/react": "^19.1.0",
|
|
119
132
|
"@types/react-dom": "^19.1.0",
|
|
@@ -135,13 +148,5 @@
|
|
|
135
148
|
"sdk"
|
|
136
149
|
],
|
|
137
150
|
"license": "MIT",
|
|
138
|
-
"private": false
|
|
139
|
-
|
|
140
|
-
"build": "tsup",
|
|
141
|
-
"dev": "tsup --watch",
|
|
142
|
-
"typecheck": "tsc --noEmit",
|
|
143
|
-
"lint": "eslint src",
|
|
144
|
-
"test": "vitest run",
|
|
145
|
-
"verify": "pnpm test"
|
|
146
|
-
}
|
|
147
|
-
}
|
|
151
|
+
"private": false
|
|
152
|
+
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
// src/client/index.ts
|
|
2
|
-
import { createBearerAPIClient } from "@riverbankcms/api";
|
|
3
|
-
|
|
4
|
-
// src/client/cache.ts
|
|
5
|
-
var SimpleCache = class {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
8
|
-
this.maxSize = options.maxSize ?? 100;
|
|
9
|
-
this.ttl = options.ttl ?? 3e5;
|
|
10
|
-
}
|
|
11
|
-
get(key) {
|
|
12
|
-
const entry = this.cache.get(key);
|
|
13
|
-
if (!entry) return void 0;
|
|
14
|
-
if (Date.now() > entry.expires) {
|
|
15
|
-
this.cache.delete(key);
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
return entry.value;
|
|
19
|
-
}
|
|
20
|
-
set(key, value) {
|
|
21
|
-
if (this.cache.size >= this.maxSize) {
|
|
22
|
-
const firstKey = this.cache.keys().next().value;
|
|
23
|
-
if (firstKey) {
|
|
24
|
-
this.cache.delete(firstKey);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
this.cache.set(key, {
|
|
28
|
-
value,
|
|
29
|
-
expires: Date.now() + this.ttl
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
clear() {
|
|
33
|
-
this.cache.clear();
|
|
34
|
-
}
|
|
35
|
-
has(key) {
|
|
36
|
-
return this.get(key) !== void 0;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/client/index.ts
|
|
41
|
-
function createRiverbankClient(config) {
|
|
42
|
-
if (!config.baseUrl) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
"baseUrl is required when creating a Builder client. Expected format: https://dashboard.example.com/api (must include /api path)"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
if (!config.baseUrl.endsWith("/api")) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`baseUrl must end with '/api'. Received: ${config.baseUrl}. Expected format: https://dashboard.example.com/api`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
const cacheEnabled = config.cache?.enabled ?? true;
|
|
53
|
-
const cacheTTL = (config.cache?.ttl ?? 300) * 1e3;
|
|
54
|
-
const cacheMaxSize = config.cache?.maxSize ?? 100;
|
|
55
|
-
const apiClient = createBearerAPIClient(config.apiKey, config.baseUrl);
|
|
56
|
-
const cache = new SimpleCache({
|
|
57
|
-
maxSize: cacheMaxSize,
|
|
58
|
-
ttl: cacheTTL
|
|
59
|
-
});
|
|
60
|
-
async function cachedFetch(cacheKey, fetcher, options) {
|
|
61
|
-
if (cacheEnabled && !options?.force) {
|
|
62
|
-
const cached = cache.get(cacheKey);
|
|
63
|
-
if (cached !== void 0) {
|
|
64
|
-
return cached;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const data = await fetcher();
|
|
68
|
-
if (cacheEnabled) {
|
|
69
|
-
cache.set(cacheKey, data);
|
|
70
|
-
}
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
async getSite(params) {
|
|
75
|
-
const { slug, domain, id } = params;
|
|
76
|
-
if (!slug && !domain && !id) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`getSite() requires at least one identifier: slug, domain, or id. Received: ${JSON.stringify(params)}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const cacheKey = `site:${slug || domain || id}`;
|
|
82
|
-
return cachedFetch(cacheKey, async () => {
|
|
83
|
-
const apiParams = {};
|
|
84
|
-
if (params.slug) apiParams.slug = params.slug;
|
|
85
|
-
if (params.domain) apiParams.domain = params.domain;
|
|
86
|
-
if (params.id) apiParams.id = params.id;
|
|
87
|
-
return await apiClient({ endpoint: "getSite", params: apiParams });
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
async getPage(params) {
|
|
91
|
-
const { siteId, path, preview = false } = params;
|
|
92
|
-
const cacheKey = `page:${siteId}:${path}:${preview}`;
|
|
93
|
-
return cachedFetch(cacheKey, async () => {
|
|
94
|
-
return await apiClient({ endpoint: "getContentByPath", params: { siteId }, body: { path, preview } });
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
async getEntries(params) {
|
|
98
|
-
const { siteId, contentType, limit, order, preview = false, mode, entryIds } = params;
|
|
99
|
-
const entryIdsCacheKey = mode === "manual" && entryIds?.length ? entryIds.join(",") : "";
|
|
100
|
-
const cacheKey = `entries:${siteId}:${contentType}:${limit ?? ""}:${order ?? ""}:${preview}:${mode ?? ""}:${entryIdsCacheKey}`;
|
|
101
|
-
return cachedFetch(cacheKey, async () => {
|
|
102
|
-
const apiParams = {
|
|
103
|
-
siteId,
|
|
104
|
-
type: contentType
|
|
105
|
-
};
|
|
106
|
-
if (typeof limit === "number") {
|
|
107
|
-
apiParams.limit = String(limit);
|
|
108
|
-
}
|
|
109
|
-
if (order === "newest") {
|
|
110
|
-
apiParams.order = "published_at.desc";
|
|
111
|
-
} else if (order === "oldest") {
|
|
112
|
-
apiParams.order = "published_at.asc";
|
|
113
|
-
} else if (order === "title") {
|
|
114
|
-
apiParams.order = "title.asc";
|
|
115
|
-
}
|
|
116
|
-
if (preview) {
|
|
117
|
-
apiParams.stage = "preview";
|
|
118
|
-
}
|
|
119
|
-
if (mode === "manual" && entryIds?.length) {
|
|
120
|
-
apiParams.mode = "manual";
|
|
121
|
-
apiParams.entryIds = JSON.stringify(entryIds);
|
|
122
|
-
}
|
|
123
|
-
return await apiClient({ endpoint: "listPublishedEntries", params: apiParams });
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
async getEntry(params) {
|
|
127
|
-
const { siteId, contentType, slug } = params;
|
|
128
|
-
const cacheKey = `entry:${siteId}:${contentType}:${slug}`;
|
|
129
|
-
return cachedFetch(cacheKey, async () => {
|
|
130
|
-
return await apiClient({ endpoint: "getPublishedEntryPreview", params: { siteId, type: contentType, slug } });
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
async getPublicFormById(params) {
|
|
134
|
-
const { formId } = params;
|
|
135
|
-
if (!formId) {
|
|
136
|
-
throw new Error("getPublicFormById() requires formId");
|
|
137
|
-
}
|
|
138
|
-
const cacheKey = `public-form:${formId}`;
|
|
139
|
-
return cachedFetch(cacheKey, async () => {
|
|
140
|
-
return await apiClient({ endpoint: "getPublicFormById", params: { formId } });
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
async getPublicBookingServices(params) {
|
|
144
|
-
const { siteId, ids } = params;
|
|
145
|
-
if (!siteId) {
|
|
146
|
-
throw new Error("getPublicBookingServices() requires siteId");
|
|
147
|
-
}
|
|
148
|
-
const cacheKey = `public-booking-services:${siteId}:${ids ?? ""}`;
|
|
149
|
-
return cachedFetch(cacheKey, async () => {
|
|
150
|
-
const apiParams = { siteId };
|
|
151
|
-
if (ids) apiParams.ids = ids;
|
|
152
|
-
return await apiClient({ endpoint: "getPublicBookingServices", params: apiParams });
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
async listPublicEvents(params) {
|
|
156
|
-
const { siteId, limit, from, to, stage } = params;
|
|
157
|
-
if (!siteId) {
|
|
158
|
-
throw new Error("listPublicEvents() requires siteId");
|
|
159
|
-
}
|
|
160
|
-
const cacheKey = `public-events:${siteId}:${limit ?? ""}:${from ?? ""}:${to ?? ""}:${stage ?? ""}`;
|
|
161
|
-
return cachedFetch(cacheKey, async () => {
|
|
162
|
-
const apiParams = { siteId };
|
|
163
|
-
if (typeof limit === "number") apiParams.limit = String(limit);
|
|
164
|
-
if (from) apiParams.from = from;
|
|
165
|
-
if (to) apiParams.to = to;
|
|
166
|
-
if (stage) apiParams.stage = stage;
|
|
167
|
-
return await apiClient({ endpoint: "listPublicEvents", params: apiParams });
|
|
168
|
-
});
|
|
169
|
-
},
|
|
170
|
-
clearCache() {
|
|
171
|
-
cache.clear();
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export {
|
|
177
|
-
createRiverbankClient
|
|
178
|
-
};
|
|
179
|
-
//# sourceMappingURL=chunk-3KKZVGH4.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/index.ts","../../src/client/cache.ts"],"sourcesContent":["import { createBearerAPIClient } from '@riverbankcms/api';\nimport type {\n RiverbankClient,\n RiverbankClientConfig,\n PublicBookingServicesResponse,\n PublicEventsResponse,\n PublicFormResponse,\n} from './types';\nimport { SimpleCache } from './cache';\n\n/**\n * Create a Riverbank CMS client for fetching content\n *\n * @example\n * ```ts\n * const client = createRiverbankClient({\n * apiKey: 'bld_live_sk_...',\n * baseUrl: 'https://dashboard.example.com/api',\n * });\n *\n * const site = await client.getSite({ slug: 'my-site' });\n * ```\n */\nexport function createRiverbankClient(config: RiverbankClientConfig): RiverbankClient {\n if (!config.baseUrl) {\n throw new Error(\n 'baseUrl is required when creating a Builder client. ' +\n 'Expected format: https://dashboard.example.com/api (must include /api path)'\n );\n }\n\n // Validate baseUrl format\n if (!config.baseUrl.endsWith('/api')) {\n throw new Error(\n `baseUrl must end with '/api'. Received: ${config.baseUrl}. ` +\n 'Expected format: https://dashboard.example.com/api'\n );\n }\n\n const cacheEnabled = config.cache?.enabled ?? true;\n const cacheTTL = (config.cache?.ttl ?? 300) * 1000; // Convert seconds to milliseconds\n const cacheMaxSize = config.cache?.maxSize ?? 100;\n\n // Create internal API client with Bearer token auth\n const apiClient = createBearerAPIClient(config.apiKey, config.baseUrl);\n\n // Create cache instance\n const cache = new SimpleCache<unknown>({\n maxSize: cacheMaxSize,\n ttl: cacheTTL,\n });\n\n /**\n * Helper to cache API calls\n */\n async function cachedFetch<T>(\n cacheKey: string,\n fetcher: () => Promise<T>,\n options?: { force?: boolean }\n ): Promise<T> {\n // Check cache unless force is true\n if (cacheEnabled && !options?.force) {\n const cached = cache.get(cacheKey) as T | undefined;\n if (cached !== undefined) {\n return cached;\n }\n }\n\n // Fetch fresh data\n const data = await fetcher();\n\n // Store in cache\n if (cacheEnabled) {\n cache.set(cacheKey, data);\n }\n\n return data;\n }\n\n return {\n async getSite(params) {\n const { slug, domain, id } = params;\n\n if (!slug && !domain && !id) {\n throw new Error(\n 'getSite() requires at least one identifier: slug, domain, or id. ' +\n `Received: ${JSON.stringify(params)}`\n );\n }\n\n const cacheKey = `site:${slug || domain || id}`;\n\n return cachedFetch(cacheKey, async () => {\n // Convert params to string record for API client\n const apiParams: Record<string, string> = {};\n if (params.slug) apiParams.slug = params.slug;\n if (params.domain) apiParams.domain = params.domain;\n if (params.id) apiParams.id = params.id;\n return await apiClient({ endpoint: 'getSite', params: apiParams });\n });\n },\n\n async getPage(params) {\n const { siteId, path, preview = false } = params;\n const cacheKey = `page:${siteId}:${path}:${preview}`;\n\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getContentByPath', params: { siteId }, body: { path, preview } });\n });\n },\n\n async getEntries(params) {\n const { siteId, contentType, limit, order, preview = false, mode, entryIds } = params;\n\n // Include all params in cache key to ensure different queries are cached separately\n const entryIdsCacheKey = mode === 'manual' && entryIds?.length ? entryIds.join(',') : '';\n const cacheKey = `entries:${siteId}:${contentType}:${limit ?? ''}:${order ?? ''}:${preview}:${mode ?? ''}:${entryIdsCacheKey}`;\n\n return cachedFetch(cacheKey, async () => {\n // Build API params\n const apiParams: Record<string, string> = {\n siteId,\n type: contentType,\n };\n\n // Add optional pagination\n if (typeof limit === 'number') {\n apiParams.limit = String(limit);\n }\n\n // Convert user-friendly order to API format\n // 'order' means custom ordering - we don't pass an order param (API default)\n if (order === 'newest') {\n apiParams.order = 'published_at.desc';\n } else if (order === 'oldest') {\n apiParams.order = 'published_at.asc';\n } else if (order === 'title') {\n apiParams.order = 'title.asc';\n }\n // 'order' or undefined: don't set order param, use API default\n\n // Add preview stage if enabled\n if (preview) {\n apiParams.stage = 'preview';\n }\n\n // Manual mode - pass entry IDs for hydration\n if (mode === 'manual' && entryIds?.length) {\n apiParams.mode = 'manual';\n apiParams.entryIds = JSON.stringify(entryIds);\n }\n\n return await apiClient({ endpoint: 'listPublishedEntries', params: apiParams });\n });\n },\n\n async getEntry(params) {\n const { siteId, contentType, slug } = params;\n const cacheKey = `entry:${siteId}:${contentType}:${slug}`;\n\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getPublishedEntryPreview', params: { siteId, type: contentType, slug } });\n });\n },\n\n async getPublicFormById(params) {\n const { formId } = params;\n if (!formId) {\n throw new Error('getPublicFormById() requires formId');\n }\n const cacheKey = `public-form:${formId}`;\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getPublicFormById', params: { formId } }) as PublicFormResponse;\n });\n },\n\n async getPublicBookingServices(params) {\n const { siteId, ids } = params;\n if (!siteId) {\n throw new Error('getPublicBookingServices() requires siteId');\n }\n const cacheKey = `public-booking-services:${siteId}:${ids ?? ''}`;\n return cachedFetch(cacheKey, async () => {\n const apiParams: Record<string, string> = { siteId };\n if (ids) apiParams.ids = ids;\n return await apiClient({ endpoint: 'getPublicBookingServices', params: apiParams }) as PublicBookingServicesResponse;\n });\n },\n\n async listPublicEvents(params) {\n const { siteId, limit, from, to, stage } = params;\n if (!siteId) {\n throw new Error('listPublicEvents() requires siteId');\n }\n const cacheKey = `public-events:${siteId}:${limit ?? ''}:${from ?? ''}:${to ?? ''}:${stage ?? ''}`;\n return cachedFetch(cacheKey, async () => {\n const apiParams: Record<string, string> = { siteId };\n if (typeof limit === 'number') apiParams.limit = String(limit);\n if (from) apiParams.from = from;\n if (to) apiParams.to = to;\n if (stage) apiParams.stage = stage;\n return await apiClient({ endpoint: 'listPublicEvents', params: apiParams }) as PublicEventsResponse;\n });\n },\n\n clearCache() {\n cache.clear();\n },\n };\n}\n\n// Re-export types\nexport type { RiverbankClient, RiverbankClientConfig } from './types';\n","/**\n * Simple in-memory cache with TTL support\n */\nexport class SimpleCache<T> {\n private cache = new Map<string, { value: T; expires: number }>();\n private maxSize: number;\n private ttl: number;\n\n constructor(options: { maxSize?: number; ttl?: number } = {}) {\n this.maxSize = options.maxSize ?? 100;\n this.ttl = options.ttl ?? 300000; // 5 minutes in milliseconds\n }\n\n get(key: string): T | undefined {\n const entry = this.cache.get(key);\n if (!entry) return undefined;\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return undefined;\n }\n\n return entry.value;\n }\n\n set(key: string, value: T): void {\n // Enforce max size with simple FIFO eviction\n if (this.cache.size >= this.maxSize) {\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n }\n }\n\n this.cache.set(key, {\n value,\n expires: Date.now() + this.ttl,\n });\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n return this.get(key) !== undefined;\n }\n}\n"],"mappings":";AAAA,SAAS,6BAA6B;;;ACG/B,IAAM,cAAN,MAAqB;AAAA,EAK1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179 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/client/index.ts
|
|
2
|
-
var _api = require('@riverbankcms/api');
|
|
3
|
-
|
|
4
|
-
// src/client/cache.ts
|
|
5
|
-
var SimpleCache = class {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
8
|
-
this.maxSize = _nullishCoalesce(options.maxSize, () => ( 100));
|
|
9
|
-
this.ttl = _nullishCoalesce(options.ttl, () => ( 3e5));
|
|
10
|
-
}
|
|
11
|
-
get(key) {
|
|
12
|
-
const entry = this.cache.get(key);
|
|
13
|
-
if (!entry) return void 0;
|
|
14
|
-
if (Date.now() > entry.expires) {
|
|
15
|
-
this.cache.delete(key);
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
return entry.value;
|
|
19
|
-
}
|
|
20
|
-
set(key, value) {
|
|
21
|
-
if (this.cache.size >= this.maxSize) {
|
|
22
|
-
const firstKey = this.cache.keys().next().value;
|
|
23
|
-
if (firstKey) {
|
|
24
|
-
this.cache.delete(firstKey);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
this.cache.set(key, {
|
|
28
|
-
value,
|
|
29
|
-
expires: Date.now() + this.ttl
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
clear() {
|
|
33
|
-
this.cache.clear();
|
|
34
|
-
}
|
|
35
|
-
has(key) {
|
|
36
|
-
return this.get(key) !== void 0;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/client/index.ts
|
|
41
|
-
function createRiverbankClient(config) {
|
|
42
|
-
if (!config.baseUrl) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
"baseUrl is required when creating a Builder client. Expected format: https://dashboard.example.com/api (must include /api path)"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
if (!config.baseUrl.endsWith("/api")) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`baseUrl must end with '/api'. Received: ${config.baseUrl}. Expected format: https://dashboard.example.com/api`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
const cacheEnabled = _nullishCoalesce(_optionalChain([config, 'access', _ => _.cache, 'optionalAccess', _2 => _2.enabled]), () => ( true));
|
|
53
|
-
const cacheTTL = (_nullishCoalesce(_optionalChain([config, 'access', _3 => _3.cache, 'optionalAccess', _4 => _4.ttl]), () => ( 300))) * 1e3;
|
|
54
|
-
const cacheMaxSize = _nullishCoalesce(_optionalChain([config, 'access', _5 => _5.cache, 'optionalAccess', _6 => _6.maxSize]), () => ( 100));
|
|
55
|
-
const apiClient = _api.createBearerAPIClient.call(void 0, config.apiKey, config.baseUrl);
|
|
56
|
-
const cache = new SimpleCache({
|
|
57
|
-
maxSize: cacheMaxSize,
|
|
58
|
-
ttl: cacheTTL
|
|
59
|
-
});
|
|
60
|
-
async function cachedFetch(cacheKey, fetcher, options) {
|
|
61
|
-
if (cacheEnabled && !_optionalChain([options, 'optionalAccess', _7 => _7.force])) {
|
|
62
|
-
const cached = cache.get(cacheKey);
|
|
63
|
-
if (cached !== void 0) {
|
|
64
|
-
return cached;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const data = await fetcher();
|
|
68
|
-
if (cacheEnabled) {
|
|
69
|
-
cache.set(cacheKey, data);
|
|
70
|
-
}
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
async getSite(params) {
|
|
75
|
-
const { slug, domain, id } = params;
|
|
76
|
-
if (!slug && !domain && !id) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`getSite() requires at least one identifier: slug, domain, or id. Received: ${JSON.stringify(params)}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const cacheKey = `site:${slug || domain || id}`;
|
|
82
|
-
return cachedFetch(cacheKey, async () => {
|
|
83
|
-
const apiParams = {};
|
|
84
|
-
if (params.slug) apiParams.slug = params.slug;
|
|
85
|
-
if (params.domain) apiParams.domain = params.domain;
|
|
86
|
-
if (params.id) apiParams.id = params.id;
|
|
87
|
-
return await apiClient({ endpoint: "getSite", params: apiParams });
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
async getPage(params) {
|
|
91
|
-
const { siteId, path, preview = false } = params;
|
|
92
|
-
const cacheKey = `page:${siteId}:${path}:${preview}`;
|
|
93
|
-
return cachedFetch(cacheKey, async () => {
|
|
94
|
-
return await apiClient({ endpoint: "getContentByPath", params: { siteId }, body: { path, preview } });
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
async getEntries(params) {
|
|
98
|
-
const { siteId, contentType, limit, order, preview = false, mode, entryIds } = params;
|
|
99
|
-
const entryIdsCacheKey = mode === "manual" && _optionalChain([entryIds, 'optionalAccess', _8 => _8.length]) ? entryIds.join(",") : "";
|
|
100
|
-
const cacheKey = `entries:${siteId}:${contentType}:${_nullishCoalesce(limit, () => ( ""))}:${_nullishCoalesce(order, () => ( ""))}:${preview}:${_nullishCoalesce(mode, () => ( ""))}:${entryIdsCacheKey}`;
|
|
101
|
-
return cachedFetch(cacheKey, async () => {
|
|
102
|
-
const apiParams = {
|
|
103
|
-
siteId,
|
|
104
|
-
type: contentType
|
|
105
|
-
};
|
|
106
|
-
if (typeof limit === "number") {
|
|
107
|
-
apiParams.limit = String(limit);
|
|
108
|
-
}
|
|
109
|
-
if (order === "newest") {
|
|
110
|
-
apiParams.order = "published_at.desc";
|
|
111
|
-
} else if (order === "oldest") {
|
|
112
|
-
apiParams.order = "published_at.asc";
|
|
113
|
-
} else if (order === "title") {
|
|
114
|
-
apiParams.order = "title.asc";
|
|
115
|
-
}
|
|
116
|
-
if (preview) {
|
|
117
|
-
apiParams.stage = "preview";
|
|
118
|
-
}
|
|
119
|
-
if (mode === "manual" && _optionalChain([entryIds, 'optionalAccess', _9 => _9.length])) {
|
|
120
|
-
apiParams.mode = "manual";
|
|
121
|
-
apiParams.entryIds = JSON.stringify(entryIds);
|
|
122
|
-
}
|
|
123
|
-
return await apiClient({ endpoint: "listPublishedEntries", params: apiParams });
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
async getEntry(params) {
|
|
127
|
-
const { siteId, contentType, slug } = params;
|
|
128
|
-
const cacheKey = `entry:${siteId}:${contentType}:${slug}`;
|
|
129
|
-
return cachedFetch(cacheKey, async () => {
|
|
130
|
-
return await apiClient({ endpoint: "getPublishedEntryPreview", params: { siteId, type: contentType, slug } });
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
async getPublicFormById(params) {
|
|
134
|
-
const { formId } = params;
|
|
135
|
-
if (!formId) {
|
|
136
|
-
throw new Error("getPublicFormById() requires formId");
|
|
137
|
-
}
|
|
138
|
-
const cacheKey = `public-form:${formId}`;
|
|
139
|
-
return cachedFetch(cacheKey, async () => {
|
|
140
|
-
return await apiClient({ endpoint: "getPublicFormById", params: { formId } });
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
async getPublicBookingServices(params) {
|
|
144
|
-
const { siteId, ids } = params;
|
|
145
|
-
if (!siteId) {
|
|
146
|
-
throw new Error("getPublicBookingServices() requires siteId");
|
|
147
|
-
}
|
|
148
|
-
const cacheKey = `public-booking-services:${siteId}:${_nullishCoalesce(ids, () => ( ""))}`;
|
|
149
|
-
return cachedFetch(cacheKey, async () => {
|
|
150
|
-
const apiParams = { siteId };
|
|
151
|
-
if (ids) apiParams.ids = ids;
|
|
152
|
-
return await apiClient({ endpoint: "getPublicBookingServices", params: apiParams });
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
async listPublicEvents(params) {
|
|
156
|
-
const { siteId, limit, from, to, stage } = params;
|
|
157
|
-
if (!siteId) {
|
|
158
|
-
throw new Error("listPublicEvents() requires siteId");
|
|
159
|
-
}
|
|
160
|
-
const cacheKey = `public-events:${siteId}:${_nullishCoalesce(limit, () => ( ""))}:${_nullishCoalesce(from, () => ( ""))}:${_nullishCoalesce(to, () => ( ""))}:${_nullishCoalesce(stage, () => ( ""))}`;
|
|
161
|
-
return cachedFetch(cacheKey, async () => {
|
|
162
|
-
const apiParams = { siteId };
|
|
163
|
-
if (typeof limit === "number") apiParams.limit = String(limit);
|
|
164
|
-
if (from) apiParams.from = from;
|
|
165
|
-
if (to) apiParams.to = to;
|
|
166
|
-
if (stage) apiParams.stage = stage;
|
|
167
|
-
return await apiClient({ endpoint: "listPublicEvents", params: apiParams });
|
|
168
|
-
});
|
|
169
|
-
},
|
|
170
|
-
clearCache() {
|
|
171
|
-
cache.clear();
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
exports.createRiverbankClient = createRiverbankClient;
|
|
179
|
-
//# sourceMappingURL=chunk-4Z3GPTCS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-4Z3GPTCS.js","../../src/client/index.ts","../../src/client/cache.ts"],"names":[],"mappings":"AAAA;ACAA,wCAAsC;ADEtC;AACA;AEAO,IAAM,YAAA,EAAN,MAAqB;AAAA,EAK1B,WAAA,CAAY,QAAA,EAA8C,CAAC,CAAA,EAAG;AAJ9D,IAAA,IAAA,CAAQ,MAAA,kBAAQ,IAAI,GAAA,CAA2C,CAAA;AAK7D,IAAA,IAAA,CAAK,QAAA,mBAAU,OAAA,CAAQ,OAAA,UAAW,KAAA;AAClC,IAAA,IAAA,C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IAAA;AACH,IAAA;AAGE,MAAA;AACA,MAAA;AACE,QAAA;AAA4D,MAAA;AAE9D,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AAAkF,MAAA;AACnF,IAAA;AACH,IAAA;AAGE,MAAA;AACA,MAAA;AACE,QAAA;AAAoD,MAAA;AAEtD,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AAA0E,MAAA;AAC3E,IAAA;AACH,IAAA;AAGE,MAAA;AAAY,IAAA;AACd,EAAA;AAEJ;ADnCA;AACA;AACA;AACA","file":"/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-4Z3GPTCS.js","sourcesContent":[null,"import { createBearerAPIClient } from '@riverbankcms/api';\nimport type {\n RiverbankClient,\n RiverbankClientConfig,\n PublicBookingServicesResponse,\n PublicEventsResponse,\n PublicFormResponse,\n} from './types';\nimport { SimpleCache } from './cache';\n\n/**\n * Create a Riverbank CMS client for fetching content\n *\n * @example\n * ```ts\n * const client = createRiverbankClient({\n * apiKey: 'bld_live_sk_...',\n * baseUrl: 'https://dashboard.example.com/api',\n * });\n *\n * const site = await client.getSite({ slug: 'my-site' });\n * ```\n */\nexport function createRiverbankClient(config: RiverbankClientConfig): RiverbankClient {\n if (!config.baseUrl) {\n throw new Error(\n 'baseUrl is required when creating a Builder client. ' +\n 'Expected format: https://dashboard.example.com/api (must include /api path)'\n );\n }\n\n // Validate baseUrl format\n if (!config.baseUrl.endsWith('/api')) {\n throw new Error(\n `baseUrl must end with '/api'. Received: ${config.baseUrl}. ` +\n 'Expected format: https://dashboard.example.com/api'\n );\n }\n\n const cacheEnabled = config.cache?.enabled ?? true;\n const cacheTTL = (config.cache?.ttl ?? 300) * 1000; // Convert seconds to milliseconds\n const cacheMaxSize = config.cache?.maxSize ?? 100;\n\n // Create internal API client with Bearer token auth\n const apiClient = createBearerAPIClient(config.apiKey, config.baseUrl);\n\n // Create cache instance\n const cache = new SimpleCache<unknown>({\n maxSize: cacheMaxSize,\n ttl: cacheTTL,\n });\n\n /**\n * Helper to cache API calls\n */\n async function cachedFetch<T>(\n cacheKey: string,\n fetcher: () => Promise<T>,\n options?: { force?: boolean }\n ): Promise<T> {\n // Check cache unless force is true\n if (cacheEnabled && !options?.force) {\n const cached = cache.get(cacheKey) as T | undefined;\n if (cached !== undefined) {\n return cached;\n }\n }\n\n // Fetch fresh data\n const data = await fetcher();\n\n // Store in cache\n if (cacheEnabled) {\n cache.set(cacheKey, data);\n }\n\n return data;\n }\n\n return {\n async getSite(params) {\n const { slug, domain, id } = params;\n\n if (!slug && !domain && !id) {\n throw new Error(\n 'getSite() requires at least one identifier: slug, domain, or id. ' +\n `Received: ${JSON.stringify(params)}`\n );\n }\n\n const cacheKey = `site:${slug || domain || id}`;\n\n return cachedFetch(cacheKey, async () => {\n // Convert params to string record for API client\n const apiParams: Record<string, string> = {};\n if (params.slug) apiParams.slug = params.slug;\n if (params.domain) apiParams.domain = params.domain;\n if (params.id) apiParams.id = params.id;\n return await apiClient({ endpoint: 'getSite', params: apiParams });\n });\n },\n\n async getPage(params) {\n const { siteId, path, preview = false } = params;\n const cacheKey = `page:${siteId}:${path}:${preview}`;\n\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getContentByPath', params: { siteId }, body: { path, preview } });\n });\n },\n\n async getEntries(params) {\n const { siteId, contentType, limit, order, preview = false, mode, entryIds } = params;\n\n // Include all params in cache key to ensure different queries are cached separately\n const entryIdsCacheKey = mode === 'manual' && entryIds?.length ? entryIds.join(',') : '';\n const cacheKey = `entries:${siteId}:${contentType}:${limit ?? ''}:${order ?? ''}:${preview}:${mode ?? ''}:${entryIdsCacheKey}`;\n\n return cachedFetch(cacheKey, async () => {\n // Build API params\n const apiParams: Record<string, string> = {\n siteId,\n type: contentType,\n };\n\n // Add optional pagination\n if (typeof limit === 'number') {\n apiParams.limit = String(limit);\n }\n\n // Convert user-friendly order to API format\n // 'order' means custom ordering - we don't pass an order param (API default)\n if (order === 'newest') {\n apiParams.order = 'published_at.desc';\n } else if (order === 'oldest') {\n apiParams.order = 'published_at.asc';\n } else if (order === 'title') {\n apiParams.order = 'title.asc';\n }\n // 'order' or undefined: don't set order param, use API default\n\n // Add preview stage if enabled\n if (preview) {\n apiParams.stage = 'preview';\n }\n\n // Manual mode - pass entry IDs for hydration\n if (mode === 'manual' && entryIds?.length) {\n apiParams.mode = 'manual';\n apiParams.entryIds = JSON.stringify(entryIds);\n }\n\n return await apiClient({ endpoint: 'listPublishedEntries', params: apiParams });\n });\n },\n\n async getEntry(params) {\n const { siteId, contentType, slug } = params;\n const cacheKey = `entry:${siteId}:${contentType}:${slug}`;\n\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getPublishedEntryPreview', params: { siteId, type: contentType, slug } });\n });\n },\n\n async getPublicFormById(params) {\n const { formId } = params;\n if (!formId) {\n throw new Error('getPublicFormById() requires formId');\n }\n const cacheKey = `public-form:${formId}`;\n return cachedFetch(cacheKey, async () => {\n return await apiClient({ endpoint: 'getPublicFormById', params: { formId } }) as PublicFormResponse;\n });\n },\n\n async getPublicBookingServices(params) {\n const { siteId, ids } = params;\n if (!siteId) {\n throw new Error('getPublicBookingServices() requires siteId');\n }\n const cacheKey = `public-booking-services:${siteId}:${ids ?? ''}`;\n return cachedFetch(cacheKey, async () => {\n const apiParams: Record<string, string> = { siteId };\n if (ids) apiParams.ids = ids;\n return await apiClient({ endpoint: 'getPublicBookingServices', params: apiParams }) as PublicBookingServicesResponse;\n });\n },\n\n async listPublicEvents(params) {\n const { siteId, limit, from, to, stage } = params;\n if (!siteId) {\n throw new Error('listPublicEvents() requires siteId');\n }\n const cacheKey = `public-events:${siteId}:${limit ?? ''}:${from ?? ''}:${to ?? ''}:${stage ?? ''}`;\n return cachedFetch(cacheKey, async () => {\n const apiParams: Record<string, string> = { siteId };\n if (typeof limit === 'number') apiParams.limit = String(limit);\n if (from) apiParams.from = from;\n if (to) apiParams.to = to;\n if (stage) apiParams.stage = stage;\n return await apiClient({ endpoint: 'listPublicEvents', params: apiParams }) as PublicEventsResponse;\n });\n },\n\n clearCache() {\n cache.clear();\n },\n };\n}\n\n// Re-export types\nexport type { RiverbankClient, RiverbankClientConfig } from './types';\n","/**\n * Simple in-memory cache with TTL support\n */\nexport class SimpleCache<T> {\n private cache = new Map<string, { value: T; expires: number }>();\n private maxSize: number;\n private ttl: number;\n\n constructor(options: { maxSize?: number; ttl?: number } = {}) {\n this.maxSize = options.maxSize ?? 100;\n this.ttl = options.ttl ?? 300000; // 5 minutes in milliseconds\n }\n\n get(key: string): T | undefined {\n const entry = this.cache.get(key);\n if (!entry) return undefined;\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return undefined;\n }\n\n return entry.value;\n }\n\n set(key: string, value: T): void {\n // Enforce max size with simple FIFO eviction\n if (this.cache.size >= this.maxSize) {\n const firstKey = this.cache.keys().next().value;\n if (firstKey) {\n this.cache.delete(firstKey);\n }\n }\n\n this.cache.set(key, {\n value,\n expires: Date.now() + this.ttl,\n });\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n return this.get(key) !== undefined;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-JB4LIEFS.js","../../src/rendering/components/Block.tsx"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACGA,8CAA8G;AAsGxG,+CAAA;AAhBN,MAAA,SAAsB,KAAA,CAAM;AAAA,EAC1B,SAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA,EAAiB,iBAAA,EAAmB,KAAA;AAAA,EACpC,QAAA,EAAU;AACZ,CAAA,EAAe;AAEb,E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AA,IACF,CAAA;AAAA,EAEJ;AAGA,EAAA,GAAA,CAAI,CAAC,UAAA,EAAY;AACf,IAAA,uBACE,6BAAA,KAAC,EAAA,EAAI,SAAA,EAAU,6CAAA,EACb,QAAA,kBAAA,8BAAA,GAAC,EAAA,EAAE,SAAA,EAAU,4BAAA,EAA6B,QAAA,EAAA;AAAA,MAAA,sBAAA;AAAA,MAAqB;AAAA,IAAA,EAAA,CAAU,EAAA,CAC3E,CAAA;AAAA,EAEJ;AAGA,EAAA,MAAM,eAAA,EAAiB,+CAAA,EAA4B,QAAA,EAAU,UAAA,CAAW,SAAS,CAAC,CAAA;AAGlF,EAAA,MAAM,SAAA,EAAW,iDAAA,CAA4B;AAE7C,EAAA,uBACE,6BAAA;AAAA,IAAC,cAAA;AAAA,IAAA;AAAA,MACC,OAAA,mBAAS,OAAA,UAAW,KAAA,GAAA;AAAA,MACpB,SAAA;AAAA,MACA,KAAA,EAAO,YAAA,CAAa,MAAA;AAAA,MACpB,WAAA,EAAa,KAAA;AAAA,MACb,OAAA;AAAA,MACA,IAAA,EAAM,YAAA;AAAA,MACN;AAAA,IAAA;AAAA,EACF,CAAA;AAEJ;ADrGA;AACA;AACE;AACF,sBAAC","file":"/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-JB4LIEFS.js","sourcesContent":[null,"/**\n * Block component for rendering individual CMS blocks\n *\n * Renders a single block with its content and data.\n */\n\nimport * as React from 'react';\nimport { getBlockDefinition, makeDefaultBlockComponent, buildThemeRuntime, getDefaultComponentRegistry } from '@riverbankcms/blocks';\nimport type { Theme } from '@riverbankcms/blocks';\nimport type { RiverbankClient } from '../../client/types';\nimport { prefetchBlockData } from '../../data/prefetchBlockData';\n\n/**\n * Override component for custom block rendering.\n * Receives the same props as default block components.\n */\nexport type BlockOverrideComponent = React.ComponentType<{\n content: Record<string, unknown>;\n theme?: Record<string, unknown>;\n themeConfig?: Theme;\n data?: Record<string, unknown>;\n blockId?: string | null;\n blockKind?: string;\n}>;\n\nexport type BlockProps = {\n // Block identification\n blockKind: string;\n blockId?: string | null;\n\n // Block content\n content: Record<string, unknown>;\n\n // Required styling\n theme: Theme;\n siteId: string;\n\n // Optional data context for loaders\n pageId?: string;\n previewStage?: 'published' | 'preview';\n client?: RiverbankClient;\n\n // Optional customization\n usePlaceholders?: boolean;\n\n /**\n * Custom component to override default block rendering.\n * When provided, renders this component instead of the manifest-based default.\n * This is SSR-safe - no context or hooks required.\n *\n * @example\n * ```tsx\n * <Block\n * blockKind=\"block.hero\"\n * content={heroContent}\n * theme={theme}\n * siteId={siteId}\n * override={MyCustomHero}\n * />\n * ```\n */\n override?: BlockOverrideComponent;\n};\n\n/**\n * Renders a single CMS block with optional data loading.\n *\n * Use this component when you want to render individual blocks outside of a full page context,\n * or when mixing CMS blocks with custom JSX.\n *\n * @example Basic usage\n * ```tsx\n * <Block\n * blockKind=\"block.hero\"\n * content={{ headline: 'Welcome', subheadline: 'To our site' }}\n * theme={theme}\n * siteId=\"site-123\"\n * />\n * ```\n *\n * @example With data loading\n * ```tsx\n * <Block\n * blockKind=\"block.blog-listing\"\n * blockId=\"block-456\"\n * content={blockContent}\n * theme={theme}\n * siteId=\"site-123\"\n * pageId=\"page-789\"\n * client={client}\n * />\n * ```\n */\nexport async function Block({\n blockKind,\n blockId,\n content,\n theme,\n siteId,\n pageId,\n previewStage,\n client,\n usePlaceholders: _usePlaceholders = false,\n override: OverrideComponent,\n}: BlockProps) {\n // Get block definition (needed for data loaders even if using override)\n const definition = getBlockDefinition(blockKind);\n if (!definition && !OverrideComponent) {\n return (\n <div className=\"p-4 border border-red-300 bg-red-50 rounded\">\n <p className=\"text-red-800 font-semibold\">Unknown block type: {blockKind}</p>\n </div>\n );\n }\n\n // Build theme tokens\n const themeRuntime = buildThemeRuntime(theme);\n\n // Prefetch block data if client is provided and block has an ID\n let resolvedData: Record<string, unknown> | undefined;\n if (client && blockId && definition) {\n const pageOutline = {\n name: 'Single Block',\n path: '/block',\n purpose: 'Block preview',\n blocks: [{\n id: blockId,\n kind: blockKind,\n purpose: 'preview',\n }],\n };\n\n const allResolvedData = await prefetchBlockData(\n pageOutline,\n { siteId, pageId, previewStage },\n client\n );\n\n resolvedData = allResolvedData[blockId];\n }\n\n // If override component provided, use it instead of manifest-based rendering\n if (OverrideComponent) {\n return (\n <OverrideComponent\n content={content}\n theme={themeRuntime.tokens}\n themeConfig={theme}\n data={resolvedData}\n blockId={blockId ?? null}\n blockKind={blockKind}\n />\n );\n }\n\n // Fallback to manifest-based rendering\n if (!definition) {\n return (\n <div className=\"p-4 border border-red-300 bg-red-50 rounded\">\n <p className=\"text-red-800 font-semibold\">Unknown block type: {blockKind}</p>\n </div>\n );\n }\n\n // Create block component from manifest\n const BlockComponent = makeDefaultBlockComponent({ manifest: definition.manifest });\n\n // Get default component registry\n const registry = getDefaultComponentRegistry();\n\n return (\n <BlockComponent\n blockId={blockId ?? undefined}\n blockKind={blockKind}\n theme={themeRuntime.tokens}\n themeConfig={theme}\n content={content}\n data={resolvedData}\n registry={registry}\n />\n );\n}\n"]}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/data/prefetchBlockData.ts
|
|
2
|
-
var _data = require('@riverbankcms/blocks/system/data');
|
|
3
|
-
var SUPPORTED_LOADER_ENDPOINTS = [
|
|
4
|
-
"listPublishedEntries",
|
|
5
|
-
"getPublishedEntryPreview",
|
|
6
|
-
"listPublicEvents",
|
|
7
|
-
"getPublicFormById",
|
|
8
|
-
"getPublicBookingServices"
|
|
9
|
-
];
|
|
10
|
-
async function prefetchBlockData(page, context, client, options) {
|
|
11
|
-
const { customBlocks } = _nullishCoalesce(options, () => ( {}));
|
|
12
|
-
const customBlockMap = new Map(
|
|
13
|
-
(_nullishCoalesce(customBlocks, () => ( []))).map((block) => [block.id, block])
|
|
14
|
-
);
|
|
15
|
-
return _data.prefetchBlockData.call(void 0, page, context, {
|
|
16
|
-
apiClient: async ({ endpoint, params }) => {
|
|
17
|
-
if (!isSupportedEndpoint(endpoint)) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`Unsupported loader endpoint: ${endpoint}. SDK only supports: ${SUPPORTED_LOADER_ENDPOINTS.join(", ")}`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
switch (endpoint) {
|
|
23
|
-
case "listPublishedEntries": {
|
|
24
|
-
const { siteId, type, orderBy, limit, stage, mode, entryIds } = _nullishCoalesce(params, () => ( {}));
|
|
25
|
-
if (!siteId || !type) {
|
|
26
|
-
throw new Error("listPublishedEntries requires siteId and type params");
|
|
27
|
-
}
|
|
28
|
-
const parsedLimit = typeof limit === "string" ? Number.parseInt(limit, 10) : typeof limit === "number" ? limit : void 0;
|
|
29
|
-
const order = orderBy === "newest" || orderBy === "oldest" || orderBy === "title" || orderBy === "order" ? orderBy : void 0;
|
|
30
|
-
let parsedEntryIds;
|
|
31
|
-
if (mode === "manual" && Array.isArray(entryIds)) {
|
|
32
|
-
parsedEntryIds = entryIds.map((item) => {
|
|
33
|
-
if (typeof item === "object" && item !== null && "entryId" in item) {
|
|
34
|
-
return item.entryId;
|
|
35
|
-
}
|
|
36
|
-
if (typeof item === "string") {
|
|
37
|
-
return item;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}).filter((id) => id !== null);
|
|
41
|
-
}
|
|
42
|
-
return await client.getEntries({
|
|
43
|
-
siteId,
|
|
44
|
-
contentType: type,
|
|
45
|
-
limit: parsedLimit,
|
|
46
|
-
order,
|
|
47
|
-
preview: stage === "preview",
|
|
48
|
-
// Manual mode - pass entry IDs for hydration
|
|
49
|
-
mode: mode === "manual" ? "manual" : void 0,
|
|
50
|
-
entryIds: parsedEntryIds
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
case "getPublishedEntryPreview": {
|
|
54
|
-
const { siteId, type, slug } = _nullishCoalesce(params, () => ( {}));
|
|
55
|
-
if (!siteId || !type || !slug) {
|
|
56
|
-
throw new Error("getPublishedEntryPreview requires siteId, type, and slug params");
|
|
57
|
-
}
|
|
58
|
-
return await client.getEntry({ siteId, contentType: type, slug });
|
|
59
|
-
}
|
|
60
|
-
case "listPublicEvents": {
|
|
61
|
-
const { siteId, limit, from, to, stage } = _nullishCoalesce(params, () => ( {}));
|
|
62
|
-
if (!siteId) {
|
|
63
|
-
throw new Error("listPublicEvents requires siteId param");
|
|
64
|
-
}
|
|
65
|
-
const parsedLimit = typeof limit === "string" ? Number.parseInt(limit, 10) : typeof limit === "number" ? limit : void 0;
|
|
66
|
-
return await client.listPublicEvents({ siteId, limit: parsedLimit, from, to, stage });
|
|
67
|
-
}
|
|
68
|
-
case "getPublicFormById": {
|
|
69
|
-
const { formId } = _nullishCoalesce(params, () => ( {}));
|
|
70
|
-
if (!formId) {
|
|
71
|
-
throw new Error("getPublicFormById requires formId param");
|
|
72
|
-
}
|
|
73
|
-
return await client.getPublicFormById({ formId });
|
|
74
|
-
}
|
|
75
|
-
case "getPublicBookingServices": {
|
|
76
|
-
const { siteId, ids } = _nullishCoalesce(params, () => ( {}));
|
|
77
|
-
if (!siteId) {
|
|
78
|
-
throw new Error("getPublicBookingServices requires siteId param");
|
|
79
|
-
}
|
|
80
|
-
return await client.getPublicBookingServices({ siteId, ids });
|
|
81
|
-
}
|
|
82
|
-
default: {
|
|
83
|
-
const _exhaustive = endpoint;
|
|
84
|
-
throw new Error(`Unhandled endpoint: ${_exhaustive}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
isValidEndpoint: isSupportedEndpoint,
|
|
89
|
-
onError: (error, { block, loader }) => {
|
|
90
|
-
console.warn("[prefetchBlockData] failed to prefetch block data", {
|
|
91
|
-
block,
|
|
92
|
-
loader,
|
|
93
|
-
error
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
// Provide custom block loader lookup for SDK custom blocks
|
|
97
|
-
getCustomBlockLoaders: (blockKind) => {
|
|
98
|
-
const customBlock = customBlockMap.get(blockKind);
|
|
99
|
-
if (!_optionalChain([customBlock, 'optionalAccess', _ => _.dataLoaders])) return void 0;
|
|
100
|
-
const loaders = {};
|
|
101
|
-
for (const [key, loader] of Object.entries(customBlock.dataLoaders)) {
|
|
102
|
-
loaders[key] = {
|
|
103
|
-
endpoint: loader.endpoint,
|
|
104
|
-
params: loader.params,
|
|
105
|
-
mode: loader.mode
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return loaders;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function isSupportedEndpoint(endpoint) {
|
|
113
|
-
return SUPPORTED_LOADER_ENDPOINTS.includes(endpoint);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
exports.SUPPORTED_LOADER_ENDPOINTS = SUPPORTED_LOADER_ENDPOINTS; exports.prefetchBlockData = prefetchBlockData;
|
|
120
|
-
//# sourceMappingURL=chunk-QQ6U4QX6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-QQ6U4QX6.js","../../src/data/prefetchBlockData.ts"],"names":[],"mappings":"AAAA;ACMA,wDAA2D;AAepD,IAAM,2BAAA,EAA6B;AAAA,EACxC,sBAAA;AAAA,EACA,0BAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA;AA6CA,MAA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QAAA;AACtF,QAAA;AAEE,UAAA;AACA,UAAA;AACE,YAAA;AAAyD,UAAA;AAE3D,UAAA;AAAgD,QAAA;AAClD,QAAA;AAEE,UAAA;AACA,UAAA;AACE,YAAA;AAAgE,UAAA;AAElE,UAAA;AAA4D,QAAA;AAC9D,QAAA;AAIE,UAAA;AACA,UAAA;AAAoD,QAAA;AACtD,MAAA;AACF,IAAA;AACF,IAAA;AACiB,IAAA;AAEf,MAAA;AAAkE,QAAA;AAChE,QAAA;AACA,QAAA;AACA,MAAA;AACD,IAAA;AACH;AAAA,IAAA;AAGE,MAAA;AACA,MAAA;AAMA,MAAA;AACA,MAAA;AACE,QAAA;AAAe,UAAA;AACI,UAAA;AACF,UAAA;AACF,QAAA;AACf,MAAA;AAEF,MAAA;AAAO,IAAA;AACT,EAAA;AAEJ;AAKA;AACE,EAAA;AACF;AD7GA;AACA;AACA;AACA;AACA","file":"/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/chunk-QQ6U4QX6.js","sourcesContent":[null,"/**\n * SDK wrapper for block data prefetching.\n * Uses the shared core implementation from @riverbankcms/blocks with the SDK client.\n */\n\nimport type { BlockDataLoader, PageOutline, SdkCustomBlock } from '@riverbankcms/blocks';\nimport { prefetchBlockData as prefetchBlockDataCore } from '@riverbankcms/blocks/system/data';\nimport type { PrefetchContext, ResolvedBlockData } from '@riverbankcms/blocks/system/data';\nimport type { RiverbankClient } from '../client/types';\n\nexport type { PrefetchContext, ResolvedBlockData };\n\n/**\n * Supported loader endpoints for SDK data fetching.\n * Only these endpoints can be used in block data loaders when using the SDK.\n *\n * This is the SINGLE SOURCE OF TRUTH for whitelisted endpoints.\n * - Zod validation schema derives from this array\n * - TypeScript types derive from this array\n * - Runtime validation uses this array\n */\nexport const SUPPORTED_LOADER_ENDPOINTS = [\n 'listPublishedEntries',\n 'getPublishedEntryPreview',\n 'listPublicEvents',\n 'getPublicFormById',\n 'getPublicBookingServices',\n] as const;\n\n/**\n * Union type of all supported loader endpoints.\n * Derived from SUPPORTED_LOADER_ENDPOINTS array.\n */\nexport type SupportedLoaderEndpoint = typeof SUPPORTED_LOADER_ENDPOINTS[number];\n\n/**\n * Options for SDK block data prefetching.\n */\nexport type SdkPrefetchOptions = {\n /**\n * SDK custom blocks from site config.\n * Used to look up data loaders for custom.* blocks.\n */\n customBlocks?: SdkCustomBlock[];\n};\n\n/**\n * Prefetch block data for SDK-based applications.\n * Maps loader endpoints to corresponding SDK client methods.\n *\n * Supports both system blocks and SDK custom blocks with data loaders.\n *\n * @example\n * ```typescript\n * import { createRiverbankClient } from '@riverbankcms/sdk';\n * import { prefetchBlockData } from '@riverbankcms/sdk/data';\n *\n * const client = createRiverbankClient({ apiKey, baseUrl });\n * const page = await client.getPage({ siteId, path: '/' });\n *\n * // Basic usage (system blocks only)\n * const blockData = await prefetchBlockData(page.outline, {\n * siteId: page.siteId,\n * pageId: page.id,\n * }, client);\n *\n * // With custom blocks from SDK config\n * const blockData = await prefetchBlockData(page.outline, context, client, {\n * customBlocks: site.sdkConfig?.customBlocks,\n * });\n * ```\n */\nexport async function prefetchBlockData(\n page: PageOutline,\n context: PrefetchContext,\n client: RiverbankClient,\n options?: SdkPrefetchOptions,\n): Promise<ResolvedBlockData> {\n const { customBlocks } = options ?? {};\n\n // Build lookup map for custom block loaders\n // Key is string (blockKind from page) matching block.id (custom.xxx)\n const customBlockMap = new Map<string, SdkCustomBlock>(\n (customBlocks ?? []).map((block) => [block.id as string, block])\n );\n\n return prefetchBlockDataCore(page, context, {\n apiClient: async ({ endpoint, params }) => {\n // Only support whitelisted loader endpoints\n if (!isSupportedEndpoint(endpoint)) {\n throw new Error(\n `Unsupported loader endpoint: ${endpoint}. ` +\n `SDK only supports: ${SUPPORTED_LOADER_ENDPOINTS.join(', ')}`\n );\n }\n\n // Map endpoint to SDK client method\n switch (endpoint) {\n case 'listPublishedEntries': {\n const { siteId, type, orderBy, limit, stage, mode, entryIds } = params ?? {};\n if (!siteId || !type) {\n throw new Error('listPublishedEntries requires siteId and type params');\n }\n\n // Parse limit if provided (can come as string from bindings)\n const parsedLimit = typeof limit === 'string'\n ? Number.parseInt(limit, 10)\n : typeof limit === 'number'\n ? limit\n : undefined;\n\n // Map orderBy to order param (matching embed block field values)\n const order = (orderBy === 'newest' || orderBy === 'oldest' || orderBy === 'title' || orderBy === 'order')\n ? orderBy as 'newest' | 'oldest' | 'title' | 'order'\n : undefined;\n\n // Extract entry IDs for manual mode\n // entryIds comes from binding to entries field which contains { entryId: \"uuid\" } objects\n let parsedEntryIds: string[] | undefined;\n if (mode === 'manual' && Array.isArray(entryIds)) {\n parsedEntryIds = entryIds\n .map((item: unknown) => {\n if (typeof item === 'object' && item !== null && 'entryId' in item) {\n return (item as { entryId: string }).entryId;\n }\n // Also support direct string IDs\n if (typeof item === 'string') {\n return item;\n }\n return null;\n })\n .filter((id): id is string => id !== null);\n }\n\n return await client.getEntries({\n siteId,\n contentType: type,\n limit: parsedLimit,\n order,\n preview: stage === 'preview',\n // Manual mode - pass entry IDs for hydration\n mode: mode === 'manual' ? 'manual' : undefined,\n entryIds: parsedEntryIds,\n });\n }\n\n case 'getPublishedEntryPreview': {\n const { siteId, type, slug } = params ?? {};\n if (!siteId || !type || !slug) {\n throw new Error('getPublishedEntryPreview requires siteId, type, and slug params');\n }\n return await client.getEntry({ siteId, contentType: type, slug });\n }\n case 'listPublicEvents': {\n const { siteId, limit, from, to, stage } = params ?? {};\n if (!siteId) {\n throw new Error('listPublicEvents requires siteId param');\n }\n const parsedLimit =\n typeof limit === 'string'\n ? Number.parseInt(limit, 10)\n : typeof limit === 'number'\n ? limit\n : undefined;\n return await client.listPublicEvents({ siteId, limit: parsedLimit, from, to, stage });\n }\n case 'getPublicFormById': {\n const { formId } = params ?? {};\n if (!formId) {\n throw new Error('getPublicFormById requires formId param');\n }\n return await client.getPublicFormById({ formId });\n }\n case 'getPublicBookingServices': {\n const { siteId, ids } = params ?? {};\n if (!siteId) {\n throw new Error('getPublicBookingServices requires siteId param');\n }\n return await client.getPublicBookingServices({ siteId, ids });\n }\n\n default: {\n // TypeScript should never reach here due to isSupportedEndpoint check\n const _exhaustive: never = endpoint;\n throw new Error(`Unhandled endpoint: ${_exhaustive}`);\n }\n }\n },\n isValidEndpoint: isSupportedEndpoint,\n onError: (error, { block, loader }) => {\n console.warn('[prefetchBlockData] failed to prefetch block data', {\n block,\n loader,\n error,\n });\n },\n // Provide custom block loader lookup for SDK custom blocks\n getCustomBlockLoaders: (blockKind): Record<string, BlockDataLoader> | undefined => {\n const customBlock = customBlockMap.get(blockKind);\n if (!customBlock?.dataLoaders) return undefined;\n\n // Convert SdkConfigLoader to BlockDataLoader\n // SdkConfigLoader.endpoint is SdkLoaderEndpoint (string union) -> string\n // SdkConfigLoader.params is Record<string, LoaderParamValue> -> Record<string, unknown>\n // Both are structurally compatible via covariance\n const loaders: Record<string, BlockDataLoader> = {};\n for (const [key, loader] of Object.entries(customBlock.dataLoaders)) {\n loaders[key] = {\n endpoint: loader.endpoint,\n params: loader.params,\n mode: loader.mode,\n };\n }\n return loaders;\n },\n });\n}\n\n/**\n * Type guard for supported loader endpoints\n */\nfunction isSupportedEndpoint(endpoint: string): endpoint is SupportedLoaderEndpoint {\n return SUPPORTED_LOADER_ENDPOINTS.includes(endpoint as SupportedLoaderEndpoint);\n}\n"]}
|