@dyrected/core 2.5.39 → 2.5.40
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/server.cjs +42 -22
- package/dist/server.js +42 -22
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1363,7 +1363,7 @@ var GlobalController = class {
|
|
|
1363
1363
|
query = beforeReadResult;
|
|
1364
1364
|
}
|
|
1365
1365
|
let data = await db.getGlobal({ slug: this.global.slug });
|
|
1366
|
-
const isEmpty = !data ||
|
|
1366
|
+
const isEmpty = !data || isFunctionallyEmpty(data);
|
|
1367
1367
|
if (isEmpty && this.global.initialData) {
|
|
1368
1368
|
console.log(`[dyrected/core] Auto-seeding global "${this.global.slug}" from config.initialData`);
|
|
1369
1369
|
await db.updateGlobal({ slug: this.global.slug, data: this.global.initialData });
|
|
@@ -1434,7 +1434,7 @@ var GlobalController = class {
|
|
|
1434
1434
|
return c.json({ message: "Invalid initial data" }, 400);
|
|
1435
1435
|
}
|
|
1436
1436
|
const existing = await db.getGlobal({ slug: this.global.slug });
|
|
1437
|
-
if (existing &&
|
|
1437
|
+
if (existing && !isFunctionallyEmpty(existing)) {
|
|
1438
1438
|
return c.json({ message: "Global is not empty, skipping seed" });
|
|
1439
1439
|
}
|
|
1440
1440
|
console.log(`[dyrected/core] Auto-seeding global: ${this.global.slug}`);
|
|
@@ -1442,6 +1442,19 @@ var GlobalController = class {
|
|
|
1442
1442
|
return c.json({ message: "Seed successful", data: initialData }, 201);
|
|
1443
1443
|
}
|
|
1444
1444
|
};
|
|
1445
|
+
function isFunctionallyEmpty(obj) {
|
|
1446
|
+
if (obj === null || obj === void 0 || obj === "") return true;
|
|
1447
|
+
if (Array.isArray(obj)) {
|
|
1448
|
+
if (obj.length === 0) return true;
|
|
1449
|
+
return obj.every(isFunctionallyEmpty);
|
|
1450
|
+
}
|
|
1451
|
+
if (typeof obj === "object") {
|
|
1452
|
+
const keys = Object.keys(obj);
|
|
1453
|
+
if (keys.length === 0) return true;
|
|
1454
|
+
return keys.every((key) => isFunctionallyEmpty(obj[key]));
|
|
1455
|
+
}
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1445
1458
|
|
|
1446
1459
|
// src/controllers/media.controller.ts
|
|
1447
1460
|
var MediaController = class {
|
|
@@ -3421,9 +3434,8 @@ function registerRoutes(app, config) {
|
|
|
3421
3434
|
const previewController = new PreviewController();
|
|
3422
3435
|
app.post("/api/preview-token", requireAuth(), (c) => previewController.createToken(c));
|
|
3423
3436
|
app.get("/api/preview-data", (c) => previewController.getData(c));
|
|
3424
|
-
app.
|
|
3437
|
+
app.post("/api/collections/:slug/:id/transitions/:transition", requireAuth(), async (c) => {
|
|
3425
3438
|
const slug = c.req.param("slug");
|
|
3426
|
-
const id = c.req.param("id");
|
|
3427
3439
|
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
3428
3440
|
const config2 = c.get("config");
|
|
3429
3441
|
if (config2.collections.some((col) => col.slug === slug)) {
|
|
@@ -3438,23 +3450,25 @@ function registerRoutes(app, config) {
|
|
|
3438
3450
|
return c.json({ message: `Collection "${slug}" not found or has no workflow` }, 404);
|
|
3439
3451
|
}
|
|
3440
3452
|
const controller = new CollectionController(collection);
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
};
|
|
3452
|
-
return controller.transition(c);
|
|
3453
|
+
return controller.transition(c);
|
|
3454
|
+
});
|
|
3455
|
+
app.get("/api/collections/:slug/:id/workflow-history", requireAuth(), async (c) => {
|
|
3456
|
+
const slug = c.req.param("slug");
|
|
3457
|
+
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
3458
|
+
const config2 = c.get("config");
|
|
3459
|
+
if (config2.collections.some((col) => col.slug === slug)) {
|
|
3460
|
+
return c.json({ message: "Not Found" }, 404);
|
|
3461
|
+
}
|
|
3462
|
+
if (!config2.onSchemaFetch || !siteId) {
|
|
3463
|
+
return c.json({ message: `Collection "${slug}" not found` }, 404);
|
|
3453
3464
|
}
|
|
3454
|
-
|
|
3455
|
-
|
|
3465
|
+
const dynamic = await config2.onSchemaFetch(siteId);
|
|
3466
|
+
const collection = dynamic.collections?.find((col) => col.slug === slug);
|
|
3467
|
+
if (!collection?.workflow) {
|
|
3468
|
+
return c.json({ message: `Collection "${slug}" not found or has no workflow` }, 404);
|
|
3456
3469
|
}
|
|
3457
|
-
|
|
3470
|
+
const controller = new CollectionController(collection);
|
|
3471
|
+
return controller.workflowHistory(c);
|
|
3458
3472
|
});
|
|
3459
3473
|
app.all("/api/collections/:slug/:id?", async (c) => {
|
|
3460
3474
|
const slug = c.req.param("slug");
|
|
@@ -3503,8 +3517,9 @@ function registerRoutes(app, config) {
|
|
|
3503
3517
|
}
|
|
3504
3518
|
return c.json({ message: `Collection "${slug}" not found` }, 404);
|
|
3505
3519
|
});
|
|
3506
|
-
app.all("/api/globals/:slug", async (c) => {
|
|
3520
|
+
app.all("/api/globals/:slug/:id?", async (c) => {
|
|
3507
3521
|
const slug = c.req.param("slug");
|
|
3522
|
+
const id = c.req.param("id");
|
|
3508
3523
|
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
3509
3524
|
const config2 = c.get("config");
|
|
3510
3525
|
if (config2.globals.some((glb) => glb.slug === slug)) {
|
|
@@ -3515,8 +3530,13 @@ function registerRoutes(app, config) {
|
|
|
3515
3530
|
const global = dynamic.globals?.find((glb) => glb.slug === slug);
|
|
3516
3531
|
if (global) {
|
|
3517
3532
|
const controller = new GlobalController(global);
|
|
3518
|
-
|
|
3519
|
-
if (
|
|
3533
|
+
const method = c.req.method;
|
|
3534
|
+
if (id) {
|
|
3535
|
+
if (method === "POST" && id === "seed") return controller.seed(c);
|
|
3536
|
+
} else {
|
|
3537
|
+
if (method === "GET") return controller.get(c);
|
|
3538
|
+
if (method === "PATCH") return controller.update(c);
|
|
3539
|
+
}
|
|
3520
3540
|
}
|
|
3521
3541
|
}
|
|
3522
3542
|
return c.json({ message: `Global "${slug}" not found` }, 404);
|
package/dist/server.js
CHANGED
|
@@ -889,7 +889,7 @@ var GlobalController = class {
|
|
|
889
889
|
query = beforeReadResult;
|
|
890
890
|
}
|
|
891
891
|
let data = await db.getGlobal({ slug: this.global.slug });
|
|
892
|
-
const isEmpty = !data ||
|
|
892
|
+
const isEmpty = !data || isFunctionallyEmpty(data);
|
|
893
893
|
if (isEmpty && this.global.initialData) {
|
|
894
894
|
console.log(`[dyrected/core] Auto-seeding global "${this.global.slug}" from config.initialData`);
|
|
895
895
|
await db.updateGlobal({ slug: this.global.slug, data: this.global.initialData });
|
|
@@ -960,7 +960,7 @@ var GlobalController = class {
|
|
|
960
960
|
return c.json({ message: "Invalid initial data" }, 400);
|
|
961
961
|
}
|
|
962
962
|
const existing = await db.getGlobal({ slug: this.global.slug });
|
|
963
|
-
if (existing &&
|
|
963
|
+
if (existing && !isFunctionallyEmpty(existing)) {
|
|
964
964
|
return c.json({ message: "Global is not empty, skipping seed" });
|
|
965
965
|
}
|
|
966
966
|
console.log(`[dyrected/core] Auto-seeding global: ${this.global.slug}`);
|
|
@@ -968,6 +968,19 @@ var GlobalController = class {
|
|
|
968
968
|
return c.json({ message: "Seed successful", data: initialData }, 201);
|
|
969
969
|
}
|
|
970
970
|
};
|
|
971
|
+
function isFunctionallyEmpty(obj) {
|
|
972
|
+
if (obj === null || obj === void 0 || obj === "") return true;
|
|
973
|
+
if (Array.isArray(obj)) {
|
|
974
|
+
if (obj.length === 0) return true;
|
|
975
|
+
return obj.every(isFunctionallyEmpty);
|
|
976
|
+
}
|
|
977
|
+
if (typeof obj === "object") {
|
|
978
|
+
const keys = Object.keys(obj);
|
|
979
|
+
if (keys.length === 0) return true;
|
|
980
|
+
return keys.every((key) => isFunctionallyEmpty(obj[key]));
|
|
981
|
+
}
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
971
984
|
|
|
972
985
|
// src/controllers/media.controller.ts
|
|
973
986
|
var MediaController = class {
|
|
@@ -2122,9 +2135,8 @@ function registerRoutes(app, config) {
|
|
|
2122
2135
|
const previewController = new PreviewController();
|
|
2123
2136
|
app.post("/api/preview-token", requireAuth(), (c) => previewController.createToken(c));
|
|
2124
2137
|
app.get("/api/preview-data", (c) => previewController.getData(c));
|
|
2125
|
-
app.
|
|
2138
|
+
app.post("/api/collections/:slug/:id/transitions/:transition", requireAuth(), async (c) => {
|
|
2126
2139
|
const slug = c.req.param("slug");
|
|
2127
|
-
const id = c.req.param("id");
|
|
2128
2140
|
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
2129
2141
|
const config2 = c.get("config");
|
|
2130
2142
|
if (config2.collections.some((col) => col.slug === slug)) {
|
|
@@ -2139,23 +2151,25 @@ function registerRoutes(app, config) {
|
|
|
2139
2151
|
return c.json({ message: `Collection "${slug}" not found or has no workflow` }, 404);
|
|
2140
2152
|
}
|
|
2141
2153
|
const controller = new CollectionController(collection);
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
};
|
|
2153
|
-
return controller.transition(c);
|
|
2154
|
+
return controller.transition(c);
|
|
2155
|
+
});
|
|
2156
|
+
app.get("/api/collections/:slug/:id/workflow-history", requireAuth(), async (c) => {
|
|
2157
|
+
const slug = c.req.param("slug");
|
|
2158
|
+
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
2159
|
+
const config2 = c.get("config");
|
|
2160
|
+
if (config2.collections.some((col) => col.slug === slug)) {
|
|
2161
|
+
return c.json({ message: "Not Found" }, 404);
|
|
2162
|
+
}
|
|
2163
|
+
if (!config2.onSchemaFetch || !siteId) {
|
|
2164
|
+
return c.json({ message: `Collection "${slug}" not found` }, 404);
|
|
2154
2165
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2166
|
+
const dynamic = await config2.onSchemaFetch(siteId);
|
|
2167
|
+
const collection = dynamic.collections?.find((col) => col.slug === slug);
|
|
2168
|
+
if (!collection?.workflow) {
|
|
2169
|
+
return c.json({ message: `Collection "${slug}" not found or has no workflow` }, 404);
|
|
2157
2170
|
}
|
|
2158
|
-
|
|
2171
|
+
const controller = new CollectionController(collection);
|
|
2172
|
+
return controller.workflowHistory(c);
|
|
2159
2173
|
});
|
|
2160
2174
|
app.all("/api/collections/:slug/:id?", async (c) => {
|
|
2161
2175
|
const slug = c.req.param("slug");
|
|
@@ -2204,8 +2218,9 @@ function registerRoutes(app, config) {
|
|
|
2204
2218
|
}
|
|
2205
2219
|
return c.json({ message: `Collection "${slug}" not found` }, 404);
|
|
2206
2220
|
});
|
|
2207
|
-
app.all("/api/globals/:slug", async (c) => {
|
|
2221
|
+
app.all("/api/globals/:slug/:id?", async (c) => {
|
|
2208
2222
|
const slug = c.req.param("slug");
|
|
2223
|
+
const id = c.req.param("id");
|
|
2209
2224
|
const siteId = c.req.header("X-Site-Id") || c.get("siteId");
|
|
2210
2225
|
const config2 = c.get("config");
|
|
2211
2226
|
if (config2.globals.some((glb) => glb.slug === slug)) {
|
|
@@ -2216,8 +2231,13 @@ function registerRoutes(app, config) {
|
|
|
2216
2231
|
const global = dynamic.globals?.find((glb) => glb.slug === slug);
|
|
2217
2232
|
if (global) {
|
|
2218
2233
|
const controller = new GlobalController(global);
|
|
2219
|
-
|
|
2220
|
-
if (
|
|
2234
|
+
const method = c.req.method;
|
|
2235
|
+
if (id) {
|
|
2236
|
+
if (method === "POST" && id === "seed") return controller.seed(c);
|
|
2237
|
+
} else {
|
|
2238
|
+
if (method === "GET") return controller.get(c);
|
|
2239
|
+
if (method === "PATCH") return controller.update(c);
|
|
2240
|
+
}
|
|
2221
2241
|
}
|
|
2222
2242
|
}
|
|
2223
2243
|
return c.json({ message: `Global "${slug}" not found` }, 404);
|