@blinkk/root-cms 3.0.1-alpha.1 → 3.0.1-beta.3
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/app.js +12 -6
- package/dist/chunk-CRK7N6RR.js +298 -0
- package/dist/{chunk-SNZ4S4IC.js → chunk-F4SODS5S.js} +87 -297
- package/dist/{chunk-R4LKO3EZ.js → chunk-MAZA5B27.js} +16 -18
- package/dist/chunk-NXEXOHBD.js +982 -0
- package/dist/{chunk-UTSL2E2P.js → chunk-TRM4MQHU.js} +270 -11
- package/dist/{chunk-KDXHFMIH.js → chunk-XLX37FRL.js} +3 -0
- package/dist/cli.js +3 -2
- package/dist/{client-DdB4xpM6.d.ts → client-1puwLgNx.d.ts} +194 -10
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -1
- package/dist/core.d.ts +3 -3
- package/dist/core.js +2 -1
- package/dist/functions.js +3 -2
- package/dist/{generate-types-MHWSSOWV.js → generate-types-SPV7I3A5.js} +1 -1
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +287 -78
- package/dist/project.d.ts +15 -2
- package/dist/project.js +3 -1
- package/dist/richtext.d.ts +25 -18
- package/dist/richtext.js +98 -43
- package/dist/{schema-rjBOZk-j.d.ts → schema-Db_xODoi.d.ts} +5 -0
- package/dist/ui/signin.css +1 -1
- package/dist/ui/signin.js +3 -3
- package/dist/ui/ui.css +1 -1
- package/dist/ui/ui.js +287 -177
- package/dist/ui/ui.js.LEGAL.txt +2 -1
- package/package.json +10 -7
- package/dist/ai-OZY3JXDH.js +0 -19
- package/dist/altText-RDKJNVGH.js +0 -7
- package/dist/chunk-BBOESYH7.js +0 -192
- package/dist/chunk-T5UK2H24.js +0 -419
package/dist/app.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getServerVersion
|
|
3
|
-
|
|
2
|
+
getServerVersion,
|
|
3
|
+
serializeAiConfig
|
|
4
|
+
} from "./chunk-NXEXOHBD.js";
|
|
5
|
+
import "./chunk-CRK7N6RR.js";
|
|
4
6
|
import {
|
|
5
7
|
getCollectionSchema,
|
|
6
8
|
getProjectSchemas
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MAZA5B27.js";
|
|
8
10
|
import "./chunk-MLKGABMK.js";
|
|
9
11
|
|
|
10
12
|
// core/app.tsx
|
|
@@ -100,7 +102,7 @@ async function renderApp(req, res, options) {
|
|
|
100
102
|
const cmsConfig = options.cmsConfig || {};
|
|
101
103
|
let gci = cmsConfig.gci;
|
|
102
104
|
if (gci === true) {
|
|
103
|
-
gci = "https://
|
|
105
|
+
gci = "https://services.rootjs.dev";
|
|
104
106
|
}
|
|
105
107
|
const ctx = {
|
|
106
108
|
rootConfig: {
|
|
@@ -120,6 +122,7 @@ async function renderApp(req, res, options) {
|
|
|
120
122
|
collections,
|
|
121
123
|
sidebar: cmsConfig.sidebar,
|
|
122
124
|
experiments: cmsConfig.experiments,
|
|
125
|
+
ai: cmsConfig.ai ? serializeAiConfig(cmsConfig.ai) : null,
|
|
123
126
|
preview: {
|
|
124
127
|
channel: cmsConfig.preview?.channel ?? false
|
|
125
128
|
},
|
|
@@ -135,7 +138,8 @@ async function renderApp(req, res, options) {
|
|
|
135
138
|
icon: t.icon,
|
|
136
139
|
hasImport: isFunction(t.onImport),
|
|
137
140
|
hasExport: isFunction(t.onExport)
|
|
138
|
-
}))
|
|
141
|
+
})),
|
|
142
|
+
defaultOneOfVariant: cmsConfig.defaultOneOfVariant || "dropdown"
|
|
139
143
|
};
|
|
140
144
|
const projectName = cmsConfig.name || cmsConfig.id || "";
|
|
141
145
|
const title = getCmsTitle(projectName, cmsConfig.minimalBranding);
|
|
@@ -234,8 +238,10 @@ async function renderSignIn(req, res, options) {
|
|
|
234
238
|
ctx.warning = "Dev warning: Server may be misconfigured. See logs for more information.";
|
|
235
239
|
}
|
|
236
240
|
}
|
|
241
|
+
const siteName = ctx.name;
|
|
242
|
+
const title = siteName ? `Sign in \u2013 ${siteName}` : "Sign in";
|
|
237
243
|
const mainHtml = renderJsxToString(
|
|
238
|
-
/* @__PURE__ */ jsx(SignIn, { title
|
|
244
|
+
/* @__PURE__ */ jsx(SignIn, { title, ctx, favicon: options.cmsConfig.favicon })
|
|
239
245
|
);
|
|
240
246
|
const nonce = generateNonce();
|
|
241
247
|
const html = `<!doctype html>
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// core/validation.ts
|
|
2
|
+
function validateFields(fieldsData, schema) {
|
|
3
|
+
if (fieldsData === null || fieldsData === void 0) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
if (typeof fieldsData !== "object" || Array.isArray(fieldsData)) {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
path: "",
|
|
10
|
+
message: "Expected object for fields data",
|
|
11
|
+
expected: "object",
|
|
12
|
+
received: getType(fieldsData)
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
const errors = [];
|
|
17
|
+
for (const field of schema.fields) {
|
|
18
|
+
if (!field.id) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (!(field.id in fieldsData)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const value = fieldsData[field.id];
|
|
25
|
+
errors.push(...validateValue(value, field, field.id));
|
|
26
|
+
}
|
|
27
|
+
return errors;
|
|
28
|
+
}
|
|
29
|
+
function validateValue(value, field, path) {
|
|
30
|
+
if (value === void 0) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
switch (field.type) {
|
|
34
|
+
case "string":
|
|
35
|
+
case "select":
|
|
36
|
+
if (typeof value !== "string") {
|
|
37
|
+
return [createError(path, "string", value)];
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
case "number":
|
|
41
|
+
if (typeof value !== "number") {
|
|
42
|
+
return [createError(path, "number", value)];
|
|
43
|
+
}
|
|
44
|
+
if (isNaN(value)) {
|
|
45
|
+
return [createError(path, "number", value)];
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
case "boolean":
|
|
49
|
+
if (typeof value !== "boolean") {
|
|
50
|
+
return [createError(path, "boolean", value)];
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
case "date":
|
|
54
|
+
case "datetime": {
|
|
55
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
56
|
+
return [createError(path, "object", value)];
|
|
57
|
+
}
|
|
58
|
+
const errors = [];
|
|
59
|
+
const seconds = value.seconds;
|
|
60
|
+
const nanoseconds = value.nanoseconds;
|
|
61
|
+
if (seconds === void 0) {
|
|
62
|
+
errors.push({
|
|
63
|
+
path: `${path}.seconds`,
|
|
64
|
+
message: "Required",
|
|
65
|
+
expected: "number",
|
|
66
|
+
received: "undefined"
|
|
67
|
+
});
|
|
68
|
+
} else if (typeof seconds !== "number") {
|
|
69
|
+
errors.push(createError(`${path}.seconds`, "number", seconds));
|
|
70
|
+
}
|
|
71
|
+
if (nanoseconds === void 0) {
|
|
72
|
+
errors.push({
|
|
73
|
+
path: `${path}.nanoseconds`,
|
|
74
|
+
message: "Required",
|
|
75
|
+
expected: "number",
|
|
76
|
+
received: "undefined"
|
|
77
|
+
});
|
|
78
|
+
} else if (typeof nanoseconds !== "number") {
|
|
79
|
+
errors.push(createError(`${path}.nanoseconds`, "number", nanoseconds));
|
|
80
|
+
}
|
|
81
|
+
return errors;
|
|
82
|
+
}
|
|
83
|
+
case "multiselect":
|
|
84
|
+
if (!Array.isArray(value)) {
|
|
85
|
+
return [createError(path, "array", value)];
|
|
86
|
+
}
|
|
87
|
+
return value.flatMap((item, index) => {
|
|
88
|
+
if (typeof item !== "string") {
|
|
89
|
+
return [createError(`${path}.${index}`, "string", item)];
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
92
|
+
});
|
|
93
|
+
case "image":
|
|
94
|
+
case "file": {
|
|
95
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
96
|
+
return [createError(path, "object", value)];
|
|
97
|
+
}
|
|
98
|
+
const errors = [];
|
|
99
|
+
if (value.src === void 0) {
|
|
100
|
+
errors.push({
|
|
101
|
+
path: `${path}.src`,
|
|
102
|
+
message: "Required",
|
|
103
|
+
expected: "string",
|
|
104
|
+
received: "undefined"
|
|
105
|
+
});
|
|
106
|
+
} else if (typeof value.src !== "string") {
|
|
107
|
+
errors.push(createError(`${path}.src`, "string", value.src));
|
|
108
|
+
}
|
|
109
|
+
if (value.alt !== void 0 && typeof value.alt !== "string") {
|
|
110
|
+
errors.push(createError(`${path}.alt`, "string", value.alt));
|
|
111
|
+
}
|
|
112
|
+
return errors;
|
|
113
|
+
}
|
|
114
|
+
case "object": {
|
|
115
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
116
|
+
return [createError(path, "object", value)];
|
|
117
|
+
}
|
|
118
|
+
const objectField = field;
|
|
119
|
+
const errors = [];
|
|
120
|
+
for (const nestedField of objectField.fields) {
|
|
121
|
+
if (!nestedField.id || !(nestedField.id in value)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
errors.push(
|
|
125
|
+
...validateValue(
|
|
126
|
+
value[nestedField.id],
|
|
127
|
+
nestedField,
|
|
128
|
+
`${path}.${nestedField.id}`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return errors;
|
|
133
|
+
}
|
|
134
|
+
case "array": {
|
|
135
|
+
if (!Array.isArray(value)) {
|
|
136
|
+
return [createError(path, "array", value)];
|
|
137
|
+
}
|
|
138
|
+
const arrayField = field;
|
|
139
|
+
const itemField = arrayField.of;
|
|
140
|
+
return value.flatMap((item, index) => {
|
|
141
|
+
return validateValue(item, itemField, `${path}.${index}`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
case "oneof": {
|
|
145
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
146
|
+
return [createError(path, "object", value)];
|
|
147
|
+
}
|
|
148
|
+
const oneOfField = field;
|
|
149
|
+
const typeName = value._type;
|
|
150
|
+
const typeMap = /* @__PURE__ */ new Map();
|
|
151
|
+
const typeNames = [];
|
|
152
|
+
for (const type of oneOfField.types) {
|
|
153
|
+
if (typeof type === "string") {
|
|
154
|
+
typeNames.push(type);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
typeMap.set(type.name, type);
|
|
158
|
+
typeNames.push(type.name);
|
|
159
|
+
}
|
|
160
|
+
if (!typeNames.includes(typeName)) {
|
|
161
|
+
const expectedStr = typeNames.map((t) => `'${t}'`).join(" | ");
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
path: `${path}._type`,
|
|
165
|
+
message: `Invalid discriminator value. Expected ${expectedStr}`,
|
|
166
|
+
expected: "valid discriminator value",
|
|
167
|
+
received: typeName
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
const matchedSchema = typeMap.get(typeName);
|
|
172
|
+
if (!matchedSchema) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
const errors = [];
|
|
176
|
+
for (const nestedField of matchedSchema.fields) {
|
|
177
|
+
if (!nestedField.id || !(nestedField.id in value)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
errors.push(
|
|
181
|
+
...validateValue(
|
|
182
|
+
value[nestedField.id],
|
|
183
|
+
nestedField,
|
|
184
|
+
`${path}.${nestedField.id}`
|
|
185
|
+
)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return errors;
|
|
189
|
+
}
|
|
190
|
+
case "richtext": {
|
|
191
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
192
|
+
return [createError(path, "object", value)];
|
|
193
|
+
}
|
|
194
|
+
const errors = [];
|
|
195
|
+
if (value.blocks === void 0) {
|
|
196
|
+
errors.push({
|
|
197
|
+
path: `${path}.blocks`,
|
|
198
|
+
message: "Required",
|
|
199
|
+
expected: "array",
|
|
200
|
+
received: "undefined"
|
|
201
|
+
});
|
|
202
|
+
} else if (!Array.isArray(value.blocks)) {
|
|
203
|
+
errors.push(createError(`${path}.blocks`, "array", value.blocks));
|
|
204
|
+
} else {
|
|
205
|
+
value.blocks.forEach((block, index) => {
|
|
206
|
+
if (typeof block !== "object" || block === null) {
|
|
207
|
+
errors.push(
|
|
208
|
+
createError(`${path}.blocks.${index}`, "object", block)
|
|
209
|
+
);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (block.type === void 0) {
|
|
213
|
+
errors.push({
|
|
214
|
+
path: `${path}.blocks.${index}.type`,
|
|
215
|
+
message: "Required",
|
|
216
|
+
expected: "string",
|
|
217
|
+
received: "undefined"
|
|
218
|
+
});
|
|
219
|
+
} else if (typeof block.type !== "string") {
|
|
220
|
+
errors.push(
|
|
221
|
+
createError(`${path}.blocks.${index}.type`, "string", block.type)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return errors;
|
|
227
|
+
}
|
|
228
|
+
case "reference": {
|
|
229
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
230
|
+
return [createError(path, "object", value)];
|
|
231
|
+
}
|
|
232
|
+
const errors = [];
|
|
233
|
+
const requiredFields = ["id", "collection", "slug"];
|
|
234
|
+
for (const req of requiredFields) {
|
|
235
|
+
if (value[req] === void 0) {
|
|
236
|
+
errors.push({
|
|
237
|
+
path: `${path}.${req}`,
|
|
238
|
+
message: "Required",
|
|
239
|
+
expected: "string",
|
|
240
|
+
received: "undefined"
|
|
241
|
+
});
|
|
242
|
+
} else if (typeof value[req] !== "string") {
|
|
243
|
+
errors.push(createError(`${path}.${req}`, "string", value[req]));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return errors;
|
|
247
|
+
}
|
|
248
|
+
case "references": {
|
|
249
|
+
if (!Array.isArray(value)) {
|
|
250
|
+
return [createError(path, "array", value)];
|
|
251
|
+
}
|
|
252
|
+
return value.flatMap((item, index) => {
|
|
253
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
254
|
+
return [createError(`${path}.${index}`, "object", item)];
|
|
255
|
+
}
|
|
256
|
+
const errors = [];
|
|
257
|
+
const requiredFields = ["id", "collection", "slug"];
|
|
258
|
+
for (const req of requiredFields) {
|
|
259
|
+
if (item[req] === void 0) {
|
|
260
|
+
errors.push({
|
|
261
|
+
path: `${path}.${index}.${req}`,
|
|
262
|
+
message: "Required",
|
|
263
|
+
expected: "string",
|
|
264
|
+
received: "undefined"
|
|
265
|
+
});
|
|
266
|
+
} else if (typeof item[req] !== "string") {
|
|
267
|
+
errors.push(
|
|
268
|
+
createError(`${path}.${index}.${req}`, "string", item[req])
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return errors;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
default:
|
|
276
|
+
console.warn(`Unknown field type: ${field.type}`);
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function getType(value) {
|
|
281
|
+
if (value === null) return "null";
|
|
282
|
+
if (Array.isArray(value)) return "array";
|
|
283
|
+
if (typeof value === "number" && Number.isNaN(value)) return "nan";
|
|
284
|
+
return typeof value;
|
|
285
|
+
}
|
|
286
|
+
function createError(path, expected, receivedValue) {
|
|
287
|
+
const received = getType(receivedValue);
|
|
288
|
+
return {
|
|
289
|
+
path,
|
|
290
|
+
message: `Expected ${expected}, received ${received}`,
|
|
291
|
+
expected,
|
|
292
|
+
received
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export {
|
|
297
|
+
validateFields
|
|
298
|
+
};
|