@blinkk/root-cms 2.2.3 → 2.2.4
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 +2 -2
- package/dist/plugin.js +55 -6
- package/dist/ui/ui.js +96 -96
- package/package.json +3 -3
package/dist/app.js
CHANGED
|
@@ -83,7 +83,7 @@ function convertOneOfTypes(collection) {
|
|
|
83
83
|
// package.json
|
|
84
84
|
var package_default = {
|
|
85
85
|
name: "@blinkk/root-cms",
|
|
86
|
-
version: "2.2.
|
|
86
|
+
version: "2.2.4",
|
|
87
87
|
author: "s@blinkk.com",
|
|
88
88
|
license: "MIT",
|
|
89
89
|
engines: {
|
|
@@ -232,7 +232,7 @@ var package_default = {
|
|
|
232
232
|
yjs: "13.6.27"
|
|
233
233
|
},
|
|
234
234
|
peerDependencies: {
|
|
235
|
-
"@blinkk/root": "2.2.
|
|
235
|
+
"@blinkk/root": "2.2.4",
|
|
236
236
|
"firebase-admin": ">=11",
|
|
237
237
|
"firebase-functions": ">=4",
|
|
238
238
|
preact: ">=10",
|
package/dist/plugin.js
CHANGED
|
@@ -2266,6 +2266,44 @@ function csvToArray(csvString) {
|
|
|
2266
2266
|
function testValidCollectionId(id) {
|
|
2267
2267
|
return /^[A-Za-z0-9_-]+$/.test(id);
|
|
2268
2268
|
}
|
|
2269
|
+
async function buildDocDiffPayload(cmsClient, docId, options) {
|
|
2270
|
+
const [before, after] = await Promise.all([
|
|
2271
|
+
readDocVersionFields(cmsClient, docId, options.beforeVersion),
|
|
2272
|
+
readDocVersionFields(cmsClient, docId, options.afterVersion)
|
|
2273
|
+
]);
|
|
2274
|
+
return { before, after };
|
|
2275
|
+
}
|
|
2276
|
+
async function readDocVersionFields(cmsClient, docId, version) {
|
|
2277
|
+
const { collection, slug } = parseDocId(docId);
|
|
2278
|
+
const doc = await cmsClient.getRawDoc(collection, slug, { mode: version });
|
|
2279
|
+
if (!doc) {
|
|
2280
|
+
return null;
|
|
2281
|
+
}
|
|
2282
|
+
const fields = unmarshalData(doc.fields || {});
|
|
2283
|
+
return removeArrayKeys(fields);
|
|
2284
|
+
}
|
|
2285
|
+
function removeArrayKeys(data) {
|
|
2286
|
+
if (Array.isArray(data)) {
|
|
2287
|
+
return data.map((item) => removeArrayKeys(item));
|
|
2288
|
+
}
|
|
2289
|
+
if (isRecord(data)) {
|
|
2290
|
+
const result = {};
|
|
2291
|
+
for (const [key, value] of Object.entries(data)) {
|
|
2292
|
+
if (key === "_arrayKey") {
|
|
2293
|
+
continue;
|
|
2294
|
+
}
|
|
2295
|
+
result[key] = removeArrayKeys(value);
|
|
2296
|
+
}
|
|
2297
|
+
return result;
|
|
2298
|
+
}
|
|
2299
|
+
return data;
|
|
2300
|
+
}
|
|
2301
|
+
function isRecord(value) {
|
|
2302
|
+
return typeof value === "object" && value !== null;
|
|
2303
|
+
}
|
|
2304
|
+
function isDocVersion(value) {
|
|
2305
|
+
return value === "draft" || value === "published";
|
|
2306
|
+
}
|
|
2269
2307
|
function api(server, options) {
|
|
2270
2308
|
async function getCollectionSchema(req, collectionId) {
|
|
2271
2309
|
if (req.viteServer) {
|
|
@@ -2457,19 +2495,30 @@ function api(server, options) {
|
|
|
2457
2495
|
return;
|
|
2458
2496
|
}
|
|
2459
2497
|
const reqBody = req.body || {};
|
|
2460
|
-
|
|
2498
|
+
const docId = typeof reqBody.docId === "string" ? reqBody.docId.trim() : "";
|
|
2499
|
+
if (!docId) {
|
|
2461
2500
|
res.status(400).json({
|
|
2462
2501
|
success: false,
|
|
2463
2502
|
error: "MISSING_REQUIRED_FIELD",
|
|
2464
|
-
field: "
|
|
2503
|
+
field: "docId"
|
|
2465
2504
|
});
|
|
2466
2505
|
return;
|
|
2467
2506
|
}
|
|
2468
2507
|
try {
|
|
2469
2508
|
const cmsClient = new RootCMSClient(req.rootConfig);
|
|
2509
|
+
const beforeVersion = isDocVersion(reqBody.beforeVersion) ? reqBody.beforeVersion : "published";
|
|
2510
|
+
const afterVersion = isDocVersion(reqBody.afterVersion) ? reqBody.afterVersion : "draft";
|
|
2511
|
+
const diffPayload = await buildDocDiffPayload(cmsClient, docId, {
|
|
2512
|
+
beforeVersion,
|
|
2513
|
+
afterVersion
|
|
2514
|
+
});
|
|
2515
|
+
if (!diffPayload.before && !diffPayload.after) {
|
|
2516
|
+
res.status(200).json({ success: true, summary: "" });
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2470
2519
|
const summary = await summarizeDiff(cmsClient, {
|
|
2471
|
-
before:
|
|
2472
|
-
after:
|
|
2520
|
+
before: diffPayload.before,
|
|
2521
|
+
after: diffPayload.after
|
|
2473
2522
|
});
|
|
2474
2523
|
res.status(200).json({ success: true, summary });
|
|
2475
2524
|
} catch (err) {
|
|
@@ -2503,7 +2552,7 @@ function api(server, options) {
|
|
|
2503
2552
|
// package.json
|
|
2504
2553
|
var package_default = {
|
|
2505
2554
|
name: "@blinkk/root-cms",
|
|
2506
|
-
version: "2.2.
|
|
2555
|
+
version: "2.2.4",
|
|
2507
2556
|
author: "s@blinkk.com",
|
|
2508
2557
|
license: "MIT",
|
|
2509
2558
|
engines: {
|
|
@@ -2652,7 +2701,7 @@ var package_default = {
|
|
|
2652
2701
|
yjs: "13.6.27"
|
|
2653
2702
|
},
|
|
2654
2703
|
peerDependencies: {
|
|
2655
|
-
"@blinkk/root": "2.2.
|
|
2704
|
+
"@blinkk/root": "2.2.4",
|
|
2656
2705
|
"firebase-admin": ">=11",
|
|
2657
2706
|
"firebase-functions": ">=4",
|
|
2658
2707
|
preact: ">=10",
|