@riverbankcms/sdk 0.1.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/README.md +1892 -0
- package/dist/cli/index.js +327 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/analytics.d.mts +103 -0
- package/dist/client/analytics.d.ts +103 -0
- package/dist/client/analytics.js +197 -0
- package/dist/client/analytics.js.map +1 -0
- package/dist/client/analytics.mjs +169 -0
- package/dist/client/analytics.mjs.map +1 -0
- package/dist/client/bookings.d.mts +89 -0
- package/dist/client/bookings.d.ts +89 -0
- package/dist/client/bookings.js +34 -0
- package/dist/client/bookings.js.map +1 -0
- package/dist/client/bookings.mjs +11 -0
- package/dist/client/bookings.mjs.map +1 -0
- package/dist/client/client.d.mts +195 -0
- package/dist/client/client.d.ts +195 -0
- package/dist/client/client.js +606 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/client.mjs +572 -0
- package/dist/client/client.mjs.map +1 -0
- package/dist/client/hooks.d.mts +71 -0
- package/dist/client/hooks.d.ts +71 -0
- package/dist/client/hooks.js +264 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/hooks.mjs +235 -0
- package/dist/client/hooks.mjs.map +1 -0
- package/dist/client/rendering/client.d.mts +1 -0
- package/dist/client/rendering/client.d.ts +1 -0
- package/dist/client/rendering/client.js +33 -0
- package/dist/client/rendering/client.js.map +1 -0
- package/dist/client/rendering/client.mjs +8 -0
- package/dist/client/rendering/client.mjs.map +1 -0
- package/dist/client/usePage-BvKAa3Zw.d.mts +366 -0
- package/dist/client/usePage-BvKAa3Zw.d.ts +366 -0
- package/dist/server/chunk-2RW5HAQQ.mjs +86 -0
- package/dist/server/chunk-2RW5HAQQ.mjs.map +1 -0
- package/dist/server/chunk-3KKZVGH4.mjs +179 -0
- package/dist/server/chunk-3KKZVGH4.mjs.map +1 -0
- package/dist/server/chunk-4Z3GPTCS.js +179 -0
- package/dist/server/chunk-4Z3GPTCS.js.map +1 -0
- package/dist/server/chunk-4Z5FBFRL.mjs +211 -0
- package/dist/server/chunk-4Z5FBFRL.mjs.map +1 -0
- package/dist/server/chunk-ADREPXFU.js +86 -0
- package/dist/server/chunk-ADREPXFU.js.map +1 -0
- package/dist/server/chunk-F472SMKX.js +140 -0
- package/dist/server/chunk-F472SMKX.js.map +1 -0
- package/dist/server/chunk-GWBMJPLH.mjs +57 -0
- package/dist/server/chunk-GWBMJPLH.mjs.map +1 -0
- package/dist/server/chunk-JB4LIEFS.js +85 -0
- package/dist/server/chunk-JB4LIEFS.js.map +1 -0
- package/dist/server/chunk-PEAXKTDU.mjs +140 -0
- package/dist/server/chunk-PEAXKTDU.mjs.map +1 -0
- package/dist/server/chunk-QQ6U4QX6.js +120 -0
- package/dist/server/chunk-QQ6U4QX6.js.map +1 -0
- package/dist/server/chunk-R5YGLRUG.mjs +122 -0
- package/dist/server/chunk-R5YGLRUG.mjs.map +1 -0
- package/dist/server/chunk-SW7LE4M3.js +211 -0
- package/dist/server/chunk-SW7LE4M3.js.map +1 -0
- package/dist/server/chunk-W3K7LVPS.mjs +120 -0
- package/dist/server/chunk-W3K7LVPS.mjs.map +1 -0
- package/dist/server/chunk-WKG57P2H.mjs +85 -0
- package/dist/server/chunk-WKG57P2H.mjs.map +1 -0
- package/dist/server/chunk-YHEZMVTS.js +122 -0
- package/dist/server/chunk-YHEZMVTS.js.map +1 -0
- package/dist/server/chunk-YXDDFG3N.js +57 -0
- package/dist/server/chunk-YXDDFG3N.js.map +1 -0
- package/dist/server/components.d.mts +49 -0
- package/dist/server/components.d.ts +49 -0
- package/dist/server/components.js +22 -0
- package/dist/server/components.js.map +1 -0
- package/dist/server/components.mjs +22 -0
- package/dist/server/components.mjs.map +1 -0
- package/dist/server/config-validation.d.mts +300 -0
- package/dist/server/config-validation.d.ts +300 -0
- package/dist/server/config-validation.js +50 -0
- package/dist/server/config-validation.js.map +1 -0
- package/dist/server/config-validation.mjs +50 -0
- package/dist/server/config-validation.mjs.map +1 -0
- package/dist/server/config.d.mts +38 -0
- package/dist/server/config.d.ts +38 -0
- package/dist/server/config.js +44 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/config.mjs +44 -0
- package/dist/server/config.mjs.map +1 -0
- package/dist/server/data.d.mts +108 -0
- package/dist/server/data.d.ts +108 -0
- package/dist/server/data.js +15 -0
- package/dist/server/data.js.map +1 -0
- package/dist/server/data.mjs +15 -0
- package/dist/server/data.mjs.map +1 -0
- package/dist/server/index-B0yI_V6Z.d.mts +18 -0
- package/dist/server/index-C6M0Wfjq.d.ts +18 -0
- package/dist/server/index.d.mts +5 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +12 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/loadContent-CJcbYF3J.d.ts +152 -0
- package/dist/server/loadContent-zhlL4YSE.d.mts +152 -0
- package/dist/server/loadPage-BYmVMk0V.d.ts +216 -0
- package/dist/server/loadPage-CCf15nt8.d.mts +216 -0
- package/dist/server/loadPage-DVH3DW6E.js +9 -0
- package/dist/server/loadPage-DVH3DW6E.js.map +1 -0
- package/dist/server/loadPage-PHQZ6XQZ.mjs +9 -0
- package/dist/server/loadPage-PHQZ6XQZ.mjs.map +1 -0
- package/dist/server/metadata.d.mts +135 -0
- package/dist/server/metadata.d.ts +135 -0
- package/dist/server/metadata.js +68 -0
- package/dist/server/metadata.js.map +1 -0
- package/dist/server/metadata.mjs +68 -0
- package/dist/server/metadata.mjs.map +1 -0
- package/dist/server/rendering/server.d.mts +83 -0
- package/dist/server/rendering/server.d.ts +83 -0
- package/dist/server/rendering/server.js +14 -0
- package/dist/server/rendering/server.js.map +1 -0
- package/dist/server/rendering/server.mjs +14 -0
- package/dist/server/rendering/server.mjs.map +1 -0
- package/dist/server/rendering.d.mts +12 -0
- package/dist/server/rendering.d.ts +12 -0
- package/dist/server/rendering.js +40 -0
- package/dist/server/rendering.js.map +1 -0
- package/dist/server/rendering.mjs +40 -0
- package/dist/server/rendering.mjs.map +1 -0
- package/dist/server/routing.d.mts +115 -0
- package/dist/server/routing.d.ts +115 -0
- package/dist/server/routing.js +57 -0
- package/dist/server/routing.js.map +1 -0
- package/dist/server/routing.mjs +57 -0
- package/dist/server/routing.mjs.map +1 -0
- package/dist/server/server.d.mts +9 -0
- package/dist/server/server.d.ts +9 -0
- package/dist/server/server.js +21 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/server.mjs +21 -0
- package/dist/server/server.mjs.map +1 -0
- package/dist/server/theme-bridge.d.mts +232 -0
- package/dist/server/theme-bridge.d.ts +232 -0
- package/dist/server/theme-bridge.js +231 -0
- package/dist/server/theme-bridge.js.map +1 -0
- package/dist/server/theme-bridge.mjs +231 -0
- package/dist/server/theme-bridge.mjs.map +1 -0
- package/dist/server/theme.d.mts +40 -0
- package/dist/server/theme.d.ts +40 -0
- package/dist/server/theme.js +17 -0
- package/dist/server/theme.js.map +1 -0
- package/dist/server/theme.mjs +17 -0
- package/dist/server/theme.mjs.map +1 -0
- package/dist/server/types-BCeqWtI2.d.mts +333 -0
- package/dist/server/types-BCeqWtI2.d.ts +333 -0
- package/dist/server/types-Bbo01M7P.d.mts +76 -0
- package/dist/server/types-Bbo01M7P.d.ts +76 -0
- package/dist/server/types-C6gmRHLe.d.mts +150 -0
- package/dist/server/types-C6gmRHLe.d.ts +150 -0
- package/package.json +147 -0
- package/src/styles/index.css +10 -0
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/client.ts
|
|
22
|
+
var client_exports = {};
|
|
23
|
+
__export(client_exports, {
|
|
24
|
+
Page: () => Page,
|
|
25
|
+
createRiverbankClient: () => createRiverbankClient,
|
|
26
|
+
isContentError: () => isContentError,
|
|
27
|
+
isContentLoading: () => isContentLoading,
|
|
28
|
+
isEntryContentResult: () => isEntryContentResult,
|
|
29
|
+
isPageContentResult: () => isPageContentResult,
|
|
30
|
+
useContent: () => useContent,
|
|
31
|
+
usePage: () => usePage
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(client_exports);
|
|
34
|
+
|
|
35
|
+
// src/rendering/hooks/usePage.ts
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
|
|
38
|
+
// src/data/prefetchBlockData.ts
|
|
39
|
+
var import_data = require("@riverbankcms/blocks/system/data");
|
|
40
|
+
var SUPPORTED_LOADER_ENDPOINTS = [
|
|
41
|
+
"listPublishedEntries",
|
|
42
|
+
"getPublishedEntryPreview",
|
|
43
|
+
"listPublicEvents",
|
|
44
|
+
"getPublicFormById",
|
|
45
|
+
"getPublicBookingServices"
|
|
46
|
+
];
|
|
47
|
+
async function prefetchBlockData(page, context, client, options) {
|
|
48
|
+
const { customBlocks } = options ?? {};
|
|
49
|
+
const customBlockMap = new Map(
|
|
50
|
+
(customBlocks ?? []).map((block) => [block.id, block])
|
|
51
|
+
);
|
|
52
|
+
return (0, import_data.prefetchBlockData)(page, context, {
|
|
53
|
+
apiClient: async ({ endpoint, params }) => {
|
|
54
|
+
if (!isSupportedEndpoint(endpoint)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Unsupported loader endpoint: ${endpoint}. SDK only supports: ${SUPPORTED_LOADER_ENDPOINTS.join(", ")}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
switch (endpoint) {
|
|
60
|
+
case "listPublishedEntries": {
|
|
61
|
+
const { siteId, type, orderBy, limit, stage, mode, entryIds } = params ?? {};
|
|
62
|
+
if (!siteId || !type) {
|
|
63
|
+
throw new Error("listPublishedEntries requires siteId and type params");
|
|
64
|
+
}
|
|
65
|
+
const parsedLimit = typeof limit === "string" ? Number.parseInt(limit, 10) : typeof limit === "number" ? limit : void 0;
|
|
66
|
+
const order = orderBy === "newest" || orderBy === "oldest" || orderBy === "title" || orderBy === "order" ? orderBy : void 0;
|
|
67
|
+
let parsedEntryIds;
|
|
68
|
+
if (mode === "manual" && Array.isArray(entryIds)) {
|
|
69
|
+
parsedEntryIds = entryIds.map((item) => {
|
|
70
|
+
if (typeof item === "object" && item !== null && "entryId" in item) {
|
|
71
|
+
return item.entryId;
|
|
72
|
+
}
|
|
73
|
+
if (typeof item === "string") {
|
|
74
|
+
return item;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}).filter((id) => id !== null);
|
|
78
|
+
}
|
|
79
|
+
return await client.getEntries({
|
|
80
|
+
siteId,
|
|
81
|
+
contentType: type,
|
|
82
|
+
limit: parsedLimit,
|
|
83
|
+
order,
|
|
84
|
+
preview: stage === "preview",
|
|
85
|
+
// Manual mode - pass entry IDs for hydration
|
|
86
|
+
mode: mode === "manual" ? "manual" : void 0,
|
|
87
|
+
entryIds: parsedEntryIds
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
case "getPublishedEntryPreview": {
|
|
91
|
+
const { siteId, type, slug } = params ?? {};
|
|
92
|
+
if (!siteId || !type || !slug) {
|
|
93
|
+
throw new Error("getPublishedEntryPreview requires siteId, type, and slug params");
|
|
94
|
+
}
|
|
95
|
+
return await client.getEntry({ siteId, contentType: type, slug });
|
|
96
|
+
}
|
|
97
|
+
case "listPublicEvents": {
|
|
98
|
+
const { siteId, limit, from, to, stage } = params ?? {};
|
|
99
|
+
if (!siteId) {
|
|
100
|
+
throw new Error("listPublicEvents requires siteId param");
|
|
101
|
+
}
|
|
102
|
+
const parsedLimit = typeof limit === "string" ? Number.parseInt(limit, 10) : typeof limit === "number" ? limit : void 0;
|
|
103
|
+
return await client.listPublicEvents({ siteId, limit: parsedLimit, from, to, stage });
|
|
104
|
+
}
|
|
105
|
+
case "getPublicFormById": {
|
|
106
|
+
const { formId } = params ?? {};
|
|
107
|
+
if (!formId) {
|
|
108
|
+
throw new Error("getPublicFormById requires formId param");
|
|
109
|
+
}
|
|
110
|
+
return await client.getPublicFormById({ formId });
|
|
111
|
+
}
|
|
112
|
+
case "getPublicBookingServices": {
|
|
113
|
+
const { siteId, ids } = params ?? {};
|
|
114
|
+
if (!siteId) {
|
|
115
|
+
throw new Error("getPublicBookingServices requires siteId param");
|
|
116
|
+
}
|
|
117
|
+
return await client.getPublicBookingServices({ siteId, ids });
|
|
118
|
+
}
|
|
119
|
+
default: {
|
|
120
|
+
const _exhaustive = endpoint;
|
|
121
|
+
throw new Error(`Unhandled endpoint: ${_exhaustive}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
isValidEndpoint: isSupportedEndpoint,
|
|
126
|
+
onError: (error, { block, loader }) => {
|
|
127
|
+
console.warn("[prefetchBlockData] failed to prefetch block data", {
|
|
128
|
+
block,
|
|
129
|
+
loader,
|
|
130
|
+
error
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
// Provide custom block loader lookup for SDK custom blocks
|
|
134
|
+
getCustomBlockLoaders: (blockKind) => {
|
|
135
|
+
const customBlock = customBlockMap.get(blockKind);
|
|
136
|
+
if (!customBlock?.dataLoaders) return void 0;
|
|
137
|
+
const loaders = {};
|
|
138
|
+
for (const [key, loader] of Object.entries(customBlock.dataLoaders)) {
|
|
139
|
+
loaders[key] = {
|
|
140
|
+
endpoint: loader.endpoint,
|
|
141
|
+
params: loader.params,
|
|
142
|
+
mode: loader.mode
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return loaders;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function isSupportedEndpoint(endpoint) {
|
|
150
|
+
return SUPPORTED_LOADER_ENDPOINTS.includes(endpoint);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/rendering/hooks/usePage.ts
|
|
154
|
+
function usePage(params) {
|
|
155
|
+
const { client, siteId, path, pageId, preview = false } = params;
|
|
156
|
+
const [result, setResult] = (0, import_react.useState)({
|
|
157
|
+
loading: true,
|
|
158
|
+
error: null,
|
|
159
|
+
page: null,
|
|
160
|
+
theme: null,
|
|
161
|
+
siteId,
|
|
162
|
+
resolvedData: null,
|
|
163
|
+
sdkConfig: null
|
|
164
|
+
});
|
|
165
|
+
(0, import_react.useEffect)(() => {
|
|
166
|
+
let cancelled = false;
|
|
167
|
+
async function fetchPage() {
|
|
168
|
+
try {
|
|
169
|
+
const [site, pageResponse] = await Promise.all([
|
|
170
|
+
client.getSite({ id: siteId }),
|
|
171
|
+
client.getPage({ siteId, path, preview })
|
|
172
|
+
]);
|
|
173
|
+
if (cancelled) return;
|
|
174
|
+
if ("entry" in pageResponse) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
"This path resolves to a content entry, not a page. Use useContent() instead, which handles both pages and entries. For entries, useContent() returns the raw entry data for custom rendering."
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
const { page: pageData } = pageResponse;
|
|
180
|
+
const blocks = pageData.blocks.map((block) => {
|
|
181
|
+
if (!block || typeof block !== "object") {
|
|
182
|
+
throw new Error("Invalid block format in API response");
|
|
183
|
+
}
|
|
184
|
+
if (typeof block.id !== "string" && block.id !== null) {
|
|
185
|
+
throw new Error(`Invalid block id: expected string or null, got ${typeof block.id}`);
|
|
186
|
+
}
|
|
187
|
+
if (typeof block.kind !== "string") {
|
|
188
|
+
throw new Error(`Invalid block kind: expected string, got ${typeof block.kind}`);
|
|
189
|
+
}
|
|
190
|
+
if (typeof block.purpose !== "string") {
|
|
191
|
+
throw new Error(`Invalid block purpose: expected string, got ${typeof block.purpose}`);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
id: block.id,
|
|
195
|
+
kind: block.kind,
|
|
196
|
+
purpose: block.purpose
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
const pageOutline = {
|
|
200
|
+
name: pageData.name,
|
|
201
|
+
path: pageData.path,
|
|
202
|
+
purpose: pageData.purpose,
|
|
203
|
+
blocks
|
|
204
|
+
};
|
|
205
|
+
const resolvedData = await prefetchBlockData(
|
|
206
|
+
pageOutline,
|
|
207
|
+
{
|
|
208
|
+
siteId,
|
|
209
|
+
pageId: pageId ?? pageData.id,
|
|
210
|
+
previewStage: preview ? "preview" : "published"
|
|
211
|
+
},
|
|
212
|
+
client
|
|
213
|
+
);
|
|
214
|
+
if (cancelled) return;
|
|
215
|
+
setResult({
|
|
216
|
+
loading: false,
|
|
217
|
+
error: null,
|
|
218
|
+
page: pageOutline,
|
|
219
|
+
theme: site.theme,
|
|
220
|
+
siteId,
|
|
221
|
+
resolvedData,
|
|
222
|
+
sdkConfig: site.sdkConfig ?? null
|
|
223
|
+
});
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (cancelled) return;
|
|
226
|
+
setResult({
|
|
227
|
+
loading: false,
|
|
228
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
229
|
+
page: null,
|
|
230
|
+
theme: null,
|
|
231
|
+
siteId,
|
|
232
|
+
resolvedData: null,
|
|
233
|
+
sdkConfig: null
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
fetchPage();
|
|
238
|
+
return () => {
|
|
239
|
+
cancelled = true;
|
|
240
|
+
};
|
|
241
|
+
}, [client, siteId, path, pageId, preview]);
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/rendering/hooks/useContent.ts
|
|
246
|
+
var import_react2 = require("react");
|
|
247
|
+
function isContentLoading(result) {
|
|
248
|
+
return result.loading === true;
|
|
249
|
+
}
|
|
250
|
+
function isContentError(result) {
|
|
251
|
+
return result.loading === false && result.error !== null;
|
|
252
|
+
}
|
|
253
|
+
function isPageContentResult(result) {
|
|
254
|
+
return result.loading === false && result.error === null && result.type === "page";
|
|
255
|
+
}
|
|
256
|
+
function isEntryContentResult(result) {
|
|
257
|
+
return result.loading === false && result.error === null && result.type === "entry";
|
|
258
|
+
}
|
|
259
|
+
function useContent(params) {
|
|
260
|
+
const { client, siteId, path, preview = false } = params;
|
|
261
|
+
const [result, setResult] = (0, import_react2.useState)({
|
|
262
|
+
loading: true,
|
|
263
|
+
error: null,
|
|
264
|
+
type: null,
|
|
265
|
+
page: null,
|
|
266
|
+
entry: null,
|
|
267
|
+
theme: null,
|
|
268
|
+
siteId,
|
|
269
|
+
resolvedData: null
|
|
270
|
+
});
|
|
271
|
+
(0, import_react2.useEffect)(() => {
|
|
272
|
+
let cancelled = false;
|
|
273
|
+
async function fetchContent() {
|
|
274
|
+
try {
|
|
275
|
+
const [site, contentResponse] = await Promise.all([
|
|
276
|
+
client.getSite({ id: siteId }),
|
|
277
|
+
client.getPage({ siteId, path, preview })
|
|
278
|
+
]);
|
|
279
|
+
if (cancelled) return;
|
|
280
|
+
if (isEntryResponse(contentResponse)) {
|
|
281
|
+
const entryData = contentResponse.entry;
|
|
282
|
+
const entry = {
|
|
283
|
+
id: entryData.id,
|
|
284
|
+
type: entryData.type,
|
|
285
|
+
title: entryData.title,
|
|
286
|
+
slug: entryData.slug,
|
|
287
|
+
path: entryData.path,
|
|
288
|
+
status: entryData.status,
|
|
289
|
+
publishAt: entryData.publishAt,
|
|
290
|
+
content: preview ? entryData.draftContent ?? entryData.content : entryData.content,
|
|
291
|
+
metaTitle: preview ? entryData.draftMetaTitle ?? entryData.metaTitle : entryData.metaTitle,
|
|
292
|
+
metaDescription: preview ? entryData.draftMetaDescription ?? entryData.metaDescription : entryData.metaDescription,
|
|
293
|
+
createdAt: entryData.createdAt,
|
|
294
|
+
updatedAt: entryData.updatedAt
|
|
295
|
+
};
|
|
296
|
+
setResult({
|
|
297
|
+
loading: false,
|
|
298
|
+
error: null,
|
|
299
|
+
type: "entry",
|
|
300
|
+
page: null,
|
|
301
|
+
entry,
|
|
302
|
+
theme: site.theme,
|
|
303
|
+
siteId,
|
|
304
|
+
resolvedData: null
|
|
305
|
+
});
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const { page: pageData } = contentResponse;
|
|
309
|
+
const blocks = pageData.blocks.map((block) => {
|
|
310
|
+
if (!block || typeof block !== "object") {
|
|
311
|
+
throw new Error("Invalid block format in API response");
|
|
312
|
+
}
|
|
313
|
+
if (typeof block.id !== "string" && block.id !== null) {
|
|
314
|
+
throw new Error(`Invalid block id: expected string or null, got ${typeof block.id}`);
|
|
315
|
+
}
|
|
316
|
+
if (typeof block.kind !== "string") {
|
|
317
|
+
throw new Error(`Invalid block kind: expected string, got ${typeof block.kind}`);
|
|
318
|
+
}
|
|
319
|
+
if (typeof block.purpose !== "string") {
|
|
320
|
+
throw new Error(`Invalid block purpose: expected string, got ${typeof block.purpose}`);
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
id: block.id,
|
|
324
|
+
kind: block.kind,
|
|
325
|
+
purpose: block.purpose
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
const pageOutline = {
|
|
329
|
+
name: pageData.name,
|
|
330
|
+
path: pageData.path,
|
|
331
|
+
purpose: pageData.purpose,
|
|
332
|
+
blocks
|
|
333
|
+
};
|
|
334
|
+
const resolvedData = await prefetchBlockData(
|
|
335
|
+
pageOutline,
|
|
336
|
+
{
|
|
337
|
+
siteId,
|
|
338
|
+
pageId: pageData.id,
|
|
339
|
+
previewStage: preview ? "preview" : "published"
|
|
340
|
+
},
|
|
341
|
+
client
|
|
342
|
+
);
|
|
343
|
+
if (cancelled) return;
|
|
344
|
+
setResult({
|
|
345
|
+
loading: false,
|
|
346
|
+
error: null,
|
|
347
|
+
type: "page",
|
|
348
|
+
page: pageOutline,
|
|
349
|
+
entry: null,
|
|
350
|
+
theme: site.theme,
|
|
351
|
+
siteId,
|
|
352
|
+
resolvedData
|
|
353
|
+
});
|
|
354
|
+
} catch (error) {
|
|
355
|
+
if (cancelled) return;
|
|
356
|
+
setResult({
|
|
357
|
+
loading: false,
|
|
358
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
359
|
+
type: null,
|
|
360
|
+
page: null,
|
|
361
|
+
entry: null,
|
|
362
|
+
theme: null,
|
|
363
|
+
siteId,
|
|
364
|
+
resolvedData: null
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
fetchContent();
|
|
369
|
+
return () => {
|
|
370
|
+
cancelled = true;
|
|
371
|
+
};
|
|
372
|
+
}, [client, siteId, path, preview]);
|
|
373
|
+
return result;
|
|
374
|
+
}
|
|
375
|
+
function isEntryResponse(response) {
|
|
376
|
+
return "type" in response && response.type === "entry";
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/rendering/components/Page.tsx
|
|
380
|
+
var import_blocks = require("@riverbankcms/blocks");
|
|
381
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
382
|
+
function Page({
|
|
383
|
+
page,
|
|
384
|
+
theme,
|
|
385
|
+
themeTokens: providedTokens,
|
|
386
|
+
siteId,
|
|
387
|
+
resolvedData,
|
|
388
|
+
routeMap,
|
|
389
|
+
wrapBlock,
|
|
390
|
+
registry,
|
|
391
|
+
usePlaceholders = false,
|
|
392
|
+
blockOverrides,
|
|
393
|
+
sdkConfig,
|
|
394
|
+
dataContext
|
|
395
|
+
}) {
|
|
396
|
+
const baseTokens = providedTokens ?? (0, import_blocks.buildThemeRuntime)(theme).tokens;
|
|
397
|
+
const themeTokens = sdkConfig?.theme?.palette ? { ...baseTokens, palette: { ...baseTokens.palette, ...sdkConfig.theme.palette } } : baseTokens;
|
|
398
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
399
|
+
import_blocks.PageRenderer,
|
|
400
|
+
{
|
|
401
|
+
theme,
|
|
402
|
+
page,
|
|
403
|
+
themeTokens,
|
|
404
|
+
usePlaceholders,
|
|
405
|
+
dataContext: {
|
|
406
|
+
siteId,
|
|
407
|
+
resolvedData,
|
|
408
|
+
routes: routeMap,
|
|
409
|
+
occurrenceContext: dataContext?.occurrenceContext ?? null,
|
|
410
|
+
contentEntry: dataContext?.contentEntry ?? null
|
|
411
|
+
},
|
|
412
|
+
routeMap,
|
|
413
|
+
wrapBlock,
|
|
414
|
+
registry,
|
|
415
|
+
blockOverrides,
|
|
416
|
+
sdkConfig
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/client/index.ts
|
|
422
|
+
var import_api = require("@riverbankcms/api");
|
|
423
|
+
|
|
424
|
+
// src/client/cache.ts
|
|
425
|
+
var SimpleCache = class {
|
|
426
|
+
constructor(options = {}) {
|
|
427
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
428
|
+
this.maxSize = options.maxSize ?? 100;
|
|
429
|
+
this.ttl = options.ttl ?? 3e5;
|
|
430
|
+
}
|
|
431
|
+
get(key) {
|
|
432
|
+
const entry = this.cache.get(key);
|
|
433
|
+
if (!entry) return void 0;
|
|
434
|
+
if (Date.now() > entry.expires) {
|
|
435
|
+
this.cache.delete(key);
|
|
436
|
+
return void 0;
|
|
437
|
+
}
|
|
438
|
+
return entry.value;
|
|
439
|
+
}
|
|
440
|
+
set(key, value) {
|
|
441
|
+
if (this.cache.size >= this.maxSize) {
|
|
442
|
+
const firstKey = this.cache.keys().next().value;
|
|
443
|
+
if (firstKey) {
|
|
444
|
+
this.cache.delete(firstKey);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
this.cache.set(key, {
|
|
448
|
+
value,
|
|
449
|
+
expires: Date.now() + this.ttl
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
clear() {
|
|
453
|
+
this.cache.clear();
|
|
454
|
+
}
|
|
455
|
+
has(key) {
|
|
456
|
+
return this.get(key) !== void 0;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// src/client/index.ts
|
|
461
|
+
function createRiverbankClient(config) {
|
|
462
|
+
if (!config.baseUrl) {
|
|
463
|
+
throw new Error(
|
|
464
|
+
"baseUrl is required when creating a Builder client. Expected format: https://dashboard.example.com/api (must include /api path)"
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
if (!config.baseUrl.endsWith("/api")) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`baseUrl must end with '/api'. Received: ${config.baseUrl}. Expected format: https://dashboard.example.com/api`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
const cacheEnabled = config.cache?.enabled ?? true;
|
|
473
|
+
const cacheTTL = (config.cache?.ttl ?? 300) * 1e3;
|
|
474
|
+
const cacheMaxSize = config.cache?.maxSize ?? 100;
|
|
475
|
+
const apiClient = (0, import_api.createBearerAPIClient)(config.apiKey, config.baseUrl);
|
|
476
|
+
const cache = new SimpleCache({
|
|
477
|
+
maxSize: cacheMaxSize,
|
|
478
|
+
ttl: cacheTTL
|
|
479
|
+
});
|
|
480
|
+
async function cachedFetch(cacheKey, fetcher, options) {
|
|
481
|
+
if (cacheEnabled && !options?.force) {
|
|
482
|
+
const cached = cache.get(cacheKey);
|
|
483
|
+
if (cached !== void 0) {
|
|
484
|
+
return cached;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const data = await fetcher();
|
|
488
|
+
if (cacheEnabled) {
|
|
489
|
+
cache.set(cacheKey, data);
|
|
490
|
+
}
|
|
491
|
+
return data;
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
async getSite(params) {
|
|
495
|
+
const { slug, domain, id } = params;
|
|
496
|
+
if (!slug && !domain && !id) {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`getSite() requires at least one identifier: slug, domain, or id. Received: ${JSON.stringify(params)}`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
const cacheKey = `site:${slug || domain || id}`;
|
|
502
|
+
return cachedFetch(cacheKey, async () => {
|
|
503
|
+
const apiParams = {};
|
|
504
|
+
if (params.slug) apiParams.slug = params.slug;
|
|
505
|
+
if (params.domain) apiParams.domain = params.domain;
|
|
506
|
+
if (params.id) apiParams.id = params.id;
|
|
507
|
+
return await apiClient({ endpoint: "getSite", params: apiParams });
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
async getPage(params) {
|
|
511
|
+
const { siteId, path, preview = false } = params;
|
|
512
|
+
const cacheKey = `page:${siteId}:${path}:${preview}`;
|
|
513
|
+
return cachedFetch(cacheKey, async () => {
|
|
514
|
+
return await apiClient({ endpoint: "getContentByPath", params: { siteId }, body: { path, preview } });
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
async getEntries(params) {
|
|
518
|
+
const { siteId, contentType, limit, order, preview = false, mode, entryIds } = params;
|
|
519
|
+
const entryIdsCacheKey = mode === "manual" && entryIds?.length ? entryIds.join(",") : "";
|
|
520
|
+
const cacheKey = `entries:${siteId}:${contentType}:${limit ?? ""}:${order ?? ""}:${preview}:${mode ?? ""}:${entryIdsCacheKey}`;
|
|
521
|
+
return cachedFetch(cacheKey, async () => {
|
|
522
|
+
const apiParams = {
|
|
523
|
+
siteId,
|
|
524
|
+
type: contentType
|
|
525
|
+
};
|
|
526
|
+
if (typeof limit === "number") {
|
|
527
|
+
apiParams.limit = String(limit);
|
|
528
|
+
}
|
|
529
|
+
if (order === "newest") {
|
|
530
|
+
apiParams.order = "published_at.desc";
|
|
531
|
+
} else if (order === "oldest") {
|
|
532
|
+
apiParams.order = "published_at.asc";
|
|
533
|
+
} else if (order === "title") {
|
|
534
|
+
apiParams.order = "title.asc";
|
|
535
|
+
}
|
|
536
|
+
if (preview) {
|
|
537
|
+
apiParams.stage = "preview";
|
|
538
|
+
}
|
|
539
|
+
if (mode === "manual" && entryIds?.length) {
|
|
540
|
+
apiParams.mode = "manual";
|
|
541
|
+
apiParams.entryIds = JSON.stringify(entryIds);
|
|
542
|
+
}
|
|
543
|
+
return await apiClient({ endpoint: "listPublishedEntries", params: apiParams });
|
|
544
|
+
});
|
|
545
|
+
},
|
|
546
|
+
async getEntry(params) {
|
|
547
|
+
const { siteId, contentType, slug } = params;
|
|
548
|
+
const cacheKey = `entry:${siteId}:${contentType}:${slug}`;
|
|
549
|
+
return cachedFetch(cacheKey, async () => {
|
|
550
|
+
return await apiClient({ endpoint: "getPublishedEntryPreview", params: { siteId, type: contentType, slug } });
|
|
551
|
+
});
|
|
552
|
+
},
|
|
553
|
+
async getPublicFormById(params) {
|
|
554
|
+
const { formId } = params;
|
|
555
|
+
if (!formId) {
|
|
556
|
+
throw new Error("getPublicFormById() requires formId");
|
|
557
|
+
}
|
|
558
|
+
const cacheKey = `public-form:${formId}`;
|
|
559
|
+
return cachedFetch(cacheKey, async () => {
|
|
560
|
+
return await apiClient({ endpoint: "getPublicFormById", params: { formId } });
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
async getPublicBookingServices(params) {
|
|
564
|
+
const { siteId, ids } = params;
|
|
565
|
+
if (!siteId) {
|
|
566
|
+
throw new Error("getPublicBookingServices() requires siteId");
|
|
567
|
+
}
|
|
568
|
+
const cacheKey = `public-booking-services:${siteId}:${ids ?? ""}`;
|
|
569
|
+
return cachedFetch(cacheKey, async () => {
|
|
570
|
+
const apiParams = { siteId };
|
|
571
|
+
if (ids) apiParams.ids = ids;
|
|
572
|
+
return await apiClient({ endpoint: "getPublicBookingServices", params: apiParams });
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
async listPublicEvents(params) {
|
|
576
|
+
const { siteId, limit, from, to, stage } = params;
|
|
577
|
+
if (!siteId) {
|
|
578
|
+
throw new Error("listPublicEvents() requires siteId");
|
|
579
|
+
}
|
|
580
|
+
const cacheKey = `public-events:${siteId}:${limit ?? ""}:${from ?? ""}:${to ?? ""}:${stage ?? ""}`;
|
|
581
|
+
return cachedFetch(cacheKey, async () => {
|
|
582
|
+
const apiParams = { siteId };
|
|
583
|
+
if (typeof limit === "number") apiParams.limit = String(limit);
|
|
584
|
+
if (from) apiParams.from = from;
|
|
585
|
+
if (to) apiParams.to = to;
|
|
586
|
+
if (stage) apiParams.stage = stage;
|
|
587
|
+
return await apiClient({ endpoint: "listPublicEvents", params: apiParams });
|
|
588
|
+
});
|
|
589
|
+
},
|
|
590
|
+
clearCache() {
|
|
591
|
+
cache.clear();
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
596
|
+
0 && (module.exports = {
|
|
597
|
+
Page,
|
|
598
|
+
createRiverbankClient,
|
|
599
|
+
isContentError,
|
|
600
|
+
isContentLoading,
|
|
601
|
+
isEntryContentResult,
|
|
602
|
+
isPageContentResult,
|
|
603
|
+
useContent,
|
|
604
|
+
usePage
|
|
605
|
+
});
|
|
606
|
+
//# sourceMappingURL=client.js.map
|