@mattisvensson/strapi-plugin-webatlas 0.11.9 → 0.12.1
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 +6 -2
- package/dist/admin/{FullLoader-Btjb2W2p.mjs → FullLoader-BTZzPY8g.mjs} +11 -1
- package/dist/admin/{FullLoader-Da2n70bJ.js → FullLoader-C4hXFaLP.js} +10 -0
- package/dist/admin/{RoutePicker-D9RNp4zS.js → RoutePicker-C3_tzz9U.js} +1 -1
- package/dist/admin/{RoutePicker-p1rh5rcZ.mjs → RoutePicker-IRZiHKFi.mjs} +1 -1
- package/dist/admin/{SettingTitle-BMHyfLrM.mjs → SettingTitle-0mKlA80i.mjs} +1 -1
- package/dist/admin/{SettingTitle-CwB5CsY0.js → SettingTitle-Ib_0AvoZ.js} +1 -1
- package/dist/admin/WarningBox-BZ3BZ5fR.js +41 -0
- package/dist/admin/WarningBox-CXEmXfVx.mjs +42 -0
- package/dist/admin/{de-B5pRvs13.mjs → de-BFjenpyN.mjs} +16 -1
- package/dist/admin/{de-CqU1FU8C.js → de-DhwCZE_m.js} +16 -1
- package/dist/admin/{en-C7I90FwV.js → en-C-rPCNd2.js} +16 -1
- package/dist/admin/{en-BE-zzIv8.mjs → en-CGCh9ld_.mjs} +16 -1
- package/dist/admin/index-88JTX1Mj.js +480 -0
- package/dist/admin/{index-zr90q-6H.js → index-BPUJTNed.js} +178 -85
- package/dist/admin/{index-BE6CLx3P.mjs → index-BY6JLZrD.mjs} +180 -87
- package/dist/admin/index-Bym1mXg1.mjs +480 -0
- package/dist/admin/{index-G7qx6Oy7.mjs → index-ByxM39aL.mjs} +170 -132
- package/dist/admin/{index-zskvsDgF.js → index-CEJBltoJ.js} +21 -13
- package/dist/admin/{index-DpS40t3Q.mjs → index-CNCyng5O.mjs} +21 -13
- package/dist/admin/{index-CFf370lR.js → index-CsKnBzp6.js} +169 -131
- package/dist/admin/{index-LNTPJt5H.js → index-DNBXz42q.js} +13 -8
- package/dist/admin/{index-IxsV1TAn.mjs → index-PD3gcnXA.mjs} +13 -8
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/server/index.js +484 -494
- package/dist/server/index.mjs +497 -507
- package/dist/server/src/index.d.ts +48 -5
- package/package.json +1 -1
- package/dist/admin/index-Df1hDvta.js +0 -243
- package/dist/admin/index-Z6ahaWtf.mjs +0 -243
package/dist/server/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errors } from "@strapi/utils";
|
|
1
2
|
function transformToUrl(input, replaceSlash = true) {
|
|
2
3
|
const specialCharMap = {
|
|
3
4
|
ü: "ue",
|
|
@@ -46,58 +47,42 @@ async function checkPathExists(path, excludeDocumentId) {
|
|
|
46
47
|
return !!entity;
|
|
47
48
|
}
|
|
48
49
|
async function duplicateCheck(initialPath, targetRouteDocumentId) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
counter++;
|
|
57
|
-
}
|
|
58
|
-
return uniquePath;
|
|
59
|
-
} catch (e) {
|
|
60
|
-
strapi.log.error(e);
|
|
50
|
+
let uniquePath = initialPath;
|
|
51
|
+
let counter = 1;
|
|
52
|
+
let exists = await checkPathExists(uniquePath, targetRouteDocumentId);
|
|
53
|
+
while (exists) {
|
|
54
|
+
uniquePath = `${initialPath}-${counter}`;
|
|
55
|
+
exists = await checkPathExists(uniquePath, targetRouteDocumentId);
|
|
56
|
+
counter++;
|
|
61
57
|
}
|
|
58
|
+
return uniquePath;
|
|
62
59
|
}
|
|
63
60
|
async function createNavItem(data) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return entity;
|
|
75
|
-
} catch (e) {
|
|
76
|
-
strapi.log.error(e);
|
|
77
|
-
}
|
|
61
|
+
if (!data.route || !data.navigation) return null;
|
|
62
|
+
const entity = await strapi.documents(waNavItem).create({
|
|
63
|
+
data: {
|
|
64
|
+
navigation: data.navigation,
|
|
65
|
+
route: data.route || null,
|
|
66
|
+
parent: data.parent || null,
|
|
67
|
+
order: data.order || 0
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return entity;
|
|
78
71
|
}
|
|
79
72
|
async function updateNavItem(documentId, data) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
} catch (e) {
|
|
89
|
-
strapi.log.error(e);
|
|
90
|
-
}
|
|
73
|
+
const updateData = {};
|
|
74
|
+
if (data.parent !== void 0) updateData.parent = data.parent;
|
|
75
|
+
if (data.order !== void 0 && typeof data.order === "number") updateData.order = data.order;
|
|
76
|
+
return await strapi.documents(waNavItem).update({
|
|
77
|
+
documentId,
|
|
78
|
+
data: updateData
|
|
79
|
+
});
|
|
91
80
|
}
|
|
92
81
|
async function deleteNavItem(documentId) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return true;
|
|
98
|
-
} catch (e) {
|
|
99
|
-
strapi.log.error(e);
|
|
100
|
-
}
|
|
82
|
+
await strapi.documents(waNavItem).delete({
|
|
83
|
+
documentId
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
101
86
|
}
|
|
102
87
|
function getAdminService() {
|
|
103
88
|
return strapi.plugin(PLUGIN_ID)?.service("admin");
|
|
@@ -126,46 +111,32 @@ function reduceDepthOfOrphanedItems(navigationItems, itemId) {
|
|
|
126
111
|
return navigationItemsCopy;
|
|
127
112
|
}
|
|
128
113
|
async function createExternalRoute(data) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
} catch (e) {
|
|
143
|
-
strapi.log.error(e);
|
|
144
|
-
}
|
|
114
|
+
return await strapi.documents(waRoute).create({
|
|
115
|
+
data: {
|
|
116
|
+
title: data.title,
|
|
117
|
+
slug: data.path,
|
|
118
|
+
path: data.path,
|
|
119
|
+
relatedContentType: "",
|
|
120
|
+
relatedId: 0,
|
|
121
|
+
relatedDocumentId: "",
|
|
122
|
+
uidPath: "",
|
|
123
|
+
type: data.type || "external"
|
|
124
|
+
}
|
|
125
|
+
});
|
|
145
126
|
}
|
|
146
127
|
async function updateRoute(documentId, data) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
data
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
return entity;
|
|
155
|
-
} catch (e) {
|
|
156
|
-
strapi.log.error(e);
|
|
157
|
-
}
|
|
128
|
+
return await strapi.documents(waRoute).update({
|
|
129
|
+
documentId,
|
|
130
|
+
data: {
|
|
131
|
+
...data
|
|
132
|
+
}
|
|
133
|
+
});
|
|
158
134
|
}
|
|
159
135
|
async function deleteRoute(documentId) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return true;
|
|
165
|
-
} catch (e) {
|
|
166
|
-
strapi.log.error(e);
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
136
|
+
await strapi.documents(waRoute).delete({
|
|
137
|
+
documentId
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
169
140
|
}
|
|
170
141
|
function buildStructuredNavigation(navigation2, variant = "nested") {
|
|
171
142
|
const itemsById = /* @__PURE__ */ new Map();
|
|
@@ -4328,17 +4299,11 @@ function removeWaFields(obj) {
|
|
|
4328
4299
|
return obj;
|
|
4329
4300
|
}
|
|
4330
4301
|
async function buildCanonicalPath(slug, parentDocumentId) {
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
const canonicalPath = `${parentCanonicalPath ? parentCanonicalPath + "/" : ""}${slug}`;
|
|
4337
|
-
return canonicalPath;
|
|
4338
|
-
} catch (err) {
|
|
4339
|
-
strapi.log.error("Error building canonical path:", err);
|
|
4340
|
-
return slug;
|
|
4341
|
-
}
|
|
4302
|
+
const parentRoute = await strapi.documents(waRoute).findOne({
|
|
4303
|
+
documentId: parentDocumentId
|
|
4304
|
+
});
|
|
4305
|
+
const parentCanonicalPath = parentRoute?.canonicalPath || "";
|
|
4306
|
+
return `${parentCanonicalPath ? parentCanonicalPath + "/" : ""}${slug}`;
|
|
4342
4307
|
}
|
|
4343
4308
|
async function cascadePathUpdates({
|
|
4344
4309
|
validatedParentPath,
|
|
@@ -4346,26 +4311,28 @@ async function cascadePathUpdates({
|
|
|
4346
4311
|
canonicalPath,
|
|
4347
4312
|
isOverride
|
|
4348
4313
|
}) {
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4314
|
+
const children = await strapi.db.query(waRoute).findMany({
|
|
4315
|
+
where: {
|
|
4316
|
+
parent: {
|
|
4317
|
+
documentId: parentRouteDocumentId
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
});
|
|
4321
|
+
for (const child of children) {
|
|
4322
|
+
const newCanonicalPath = `${canonicalPath}/${child.slug}`;
|
|
4323
|
+
const validatedCanonicalPath = await duplicateCheck(newCanonicalPath, child.documentId);
|
|
4324
|
+
let validatedPath = child.path;
|
|
4325
|
+
if (!child.isOverride) {
|
|
4326
|
+
validatedPath = isOverride ? await duplicateCheck(`${validatedParentPath}/${child.slug}`, child.documentId) : validatedCanonicalPath;
|
|
4327
|
+
}
|
|
4328
|
+
await strapi.db.query(waRoute).updateMany({
|
|
4329
|
+
where: { documentId: child.documentId },
|
|
4330
|
+
data: {
|
|
4331
|
+
canonicalPath: validatedCanonicalPath,
|
|
4332
|
+
path: validatedPath
|
|
4355
4333
|
}
|
|
4356
4334
|
});
|
|
4357
|
-
|
|
4358
|
-
const newCanonicalPath = `${canonicalPath}/${child.slug}`;
|
|
4359
|
-
const newPath = isOverride ? `${validatedParentPath}/${child.slug}` : newCanonicalPath;
|
|
4360
|
-
const validatedCanonicalPath = await duplicateCheck(newCanonicalPath, child.documentId);
|
|
4361
|
-
const validatedPath = isOverride ? await duplicateCheck(newPath, child.documentId) : validatedCanonicalPath;
|
|
4362
|
-
await strapi.db.query(waRoute).updateMany({
|
|
4363
|
-
where: { documentId: child.documentId },
|
|
4364
|
-
data: {
|
|
4365
|
-
canonicalPath: validatedCanonicalPath,
|
|
4366
|
-
path: validatedPath
|
|
4367
|
-
}
|
|
4368
|
-
});
|
|
4335
|
+
if (strapi.contentTypes[child.relatedContentType]?.attributes?.webatlas) {
|
|
4369
4336
|
const existingEntry = await strapi.db.query(child.relatedContentType).findOne({
|
|
4370
4337
|
where: { documentId: child.relatedDocumentId }
|
|
4371
4338
|
});
|
|
@@ -4380,15 +4347,14 @@ async function cascadePathUpdates({
|
|
|
4380
4347
|
}
|
|
4381
4348
|
});
|
|
4382
4349
|
}
|
|
4383
|
-
await cascadePathUpdates({
|
|
4384
|
-
validatedParentPath: validatedPath,
|
|
4385
|
-
parentRouteDocumentId: child.documentId,
|
|
4386
|
-
canonicalPath: validatedCanonicalPath,
|
|
4387
|
-
isOverride
|
|
4388
|
-
});
|
|
4389
4350
|
}
|
|
4390
|
-
|
|
4391
|
-
|
|
4351
|
+
await cascadePathUpdates({
|
|
4352
|
+
validatedParentPath: validatedPath,
|
|
4353
|
+
parentRouteDocumentId: child.documentId,
|
|
4354
|
+
canonicalPath: validatedCanonicalPath,
|
|
4355
|
+
// Once a route diverges from its canonical path, its descendants follow the path chain
|
|
4356
|
+
isOverride: isOverride || Boolean(child.isOverride)
|
|
4357
|
+
});
|
|
4392
4358
|
}
|
|
4393
4359
|
}
|
|
4394
4360
|
async function getRouteDescendants(routeId) {
|
|
@@ -4432,16 +4398,16 @@ async function validateRouteDependencies({
|
|
|
4432
4398
|
documentId: newParentId
|
|
4433
4399
|
});
|
|
4434
4400
|
if (!parentRoute) {
|
|
4435
|
-
throw new
|
|
4401
|
+
throw new errors.ApplicationError(`Parent route not found: ${newParentId}`);
|
|
4436
4402
|
}
|
|
4437
4403
|
if (parentRoute?.type === "external") {
|
|
4438
|
-
throw new
|
|
4404
|
+
throw new errors.ApplicationError("External routes cannot have children");
|
|
4439
4405
|
}
|
|
4440
4406
|
if (!normalizedRouteId) return true;
|
|
4441
4407
|
const descendants = await getRouteDescendants(normalizedRouteId);
|
|
4442
4408
|
const nonInternalRouteIds = await getNonInternalRouteIds();
|
|
4443
4409
|
if (normalizedRouteId === newParentId || descendants.includes(newParentId) || nonInternalRouteIds.includes(newParentId)) {
|
|
4444
|
-
throw new
|
|
4410
|
+
throw new errors.ApplicationError(
|
|
4445
4411
|
`Circular dependency detected: Cannot set route ${newParentId} as parent of ${normalizedRouteId}`
|
|
4446
4412
|
);
|
|
4447
4413
|
}
|
|
@@ -4472,7 +4438,7 @@ async function buildNavigationPath({
|
|
|
4472
4438
|
return validatedPath;
|
|
4473
4439
|
}
|
|
4474
4440
|
async function handleItemDeletion(navigationItems) {
|
|
4475
|
-
const
|
|
4441
|
+
const errors2 = [];
|
|
4476
4442
|
let items = [...navigationItems];
|
|
4477
4443
|
for (let i = 0; i < items.length; i++) {
|
|
4478
4444
|
const item = items[i];
|
|
@@ -4492,7 +4458,7 @@ async function handleItemDeletion(navigationItems) {
|
|
|
4492
4458
|
i--;
|
|
4493
4459
|
} catch (err) {
|
|
4494
4460
|
const errorMsg = `Error deleting navigation item: ${err instanceof Error ? err.message : String(err)}`;
|
|
4495
|
-
|
|
4461
|
+
errors2.push(errorMsg);
|
|
4496
4462
|
strapi.log.error(errorMsg, err);
|
|
4497
4463
|
}
|
|
4498
4464
|
continue;
|
|
@@ -4505,16 +4471,16 @@ async function handleItemDeletion(navigationItems) {
|
|
|
4505
4471
|
i--;
|
|
4506
4472
|
} catch (err) {
|
|
4507
4473
|
const errorMsg = `Error deleting navigation item without route: ${err instanceof Error ? err.message : String(err)}`;
|
|
4508
|
-
|
|
4474
|
+
errors2.push(errorMsg);
|
|
4509
4475
|
strapi.log.error(errorMsg, err);
|
|
4510
4476
|
}
|
|
4511
4477
|
continue;
|
|
4512
4478
|
}
|
|
4513
4479
|
}
|
|
4514
4480
|
return {
|
|
4515
|
-
success:
|
|
4481
|
+
success: errors2.length === 0,
|
|
4516
4482
|
items,
|
|
4517
|
-
errors
|
|
4483
|
+
errors: errors2
|
|
4518
4484
|
};
|
|
4519
4485
|
}
|
|
4520
4486
|
async function handleItemUpdate({
|
|
@@ -4524,7 +4490,7 @@ async function handleItemUpdate({
|
|
|
4524
4490
|
navigationId,
|
|
4525
4491
|
newNavItemsMap
|
|
4526
4492
|
}) {
|
|
4527
|
-
const
|
|
4493
|
+
const errors2 = [];
|
|
4528
4494
|
const isCreate = item.clientModifications?.type === "create";
|
|
4529
4495
|
const isUpdate = item.clientModifications?.type === "update";
|
|
4530
4496
|
const isInternal = item.route.type === "internal";
|
|
@@ -4544,10 +4510,10 @@ async function handleItemUpdate({
|
|
|
4544
4510
|
});
|
|
4545
4511
|
if (newNavItem) newNavItemsMap.set(item.documentId, newNavItem);
|
|
4546
4512
|
} catch (err) {
|
|
4547
|
-
|
|
4513
|
+
errors2.push(err instanceof Error ? err.message : String(err));
|
|
4548
4514
|
strapi.log.error(`Error creating navigation item '${item.route.title}': `, err);
|
|
4549
4515
|
}
|
|
4550
|
-
return { success:
|
|
4516
|
+
return { success: errors2.length === 0, errors: errors2 };
|
|
4551
4517
|
}
|
|
4552
4518
|
if (isCreate && item.clientModifications.route) {
|
|
4553
4519
|
try {
|
|
@@ -4561,6 +4527,7 @@ async function handleItemUpdate({
|
|
|
4561
4527
|
routeDocumentId: route2.documentId,
|
|
4562
4528
|
calculatedParent
|
|
4563
4529
|
});
|
|
4530
|
+
assertPathAllowed(path, await getRouteBlacklist());
|
|
4564
4531
|
await updateRoute(route2.documentId, {
|
|
4565
4532
|
title: item.route.title,
|
|
4566
4533
|
slug: item.route.slug,
|
|
@@ -4575,13 +4542,13 @@ async function handleItemUpdate({
|
|
|
4575
4542
|
});
|
|
4576
4543
|
if (newNavItem) newNavItemsMap.set(item.documentId, newNavItem);
|
|
4577
4544
|
} catch (err) {
|
|
4578
|
-
|
|
4545
|
+
errors2.push(err instanceof Error ? err.message : String(err));
|
|
4579
4546
|
strapi.log.error(
|
|
4580
4547
|
`Error creating navigation item with existing route '${item.route.title}': `,
|
|
4581
4548
|
err
|
|
4582
4549
|
);
|
|
4583
4550
|
}
|
|
4584
|
-
return { success:
|
|
4551
|
+
return { success: errors2.length === 0, errors: errors2 };
|
|
4585
4552
|
}
|
|
4586
4553
|
const needsRouteUpdate = isUpdate || isInternal;
|
|
4587
4554
|
if (needsRouteUpdate || isInternal) {
|
|
@@ -4599,6 +4566,7 @@ async function handleItemUpdate({
|
|
|
4599
4566
|
}) : slug;
|
|
4600
4567
|
const isOverride = path !== route2.canonicalPath;
|
|
4601
4568
|
if (needsRouteUpdate) {
|
|
4569
|
+
if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
|
|
4602
4570
|
await updateRoute(route2.documentId, {
|
|
4603
4571
|
title: item.clientModifications?.title || item.route.title,
|
|
4604
4572
|
slug,
|
|
@@ -4607,17 +4575,18 @@ async function handleItemUpdate({
|
|
|
4607
4575
|
});
|
|
4608
4576
|
}
|
|
4609
4577
|
} catch (err) {
|
|
4610
|
-
|
|
4578
|
+
errors2.push(err instanceof Error ? err.message : String(err));
|
|
4611
4579
|
strapi.log.error(`Error processing route for navigation item '${item.route.title}': `, err);
|
|
4612
4580
|
}
|
|
4613
4581
|
}
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4582
|
+
if (errors2.length === 0)
|
|
4583
|
+
await updateNavItem(item.documentId, {
|
|
4584
|
+
parent: calculatedParent,
|
|
4585
|
+
order: calculatedOrder
|
|
4586
|
+
});
|
|
4618
4587
|
return {
|
|
4619
|
-
success:
|
|
4620
|
-
errors
|
|
4588
|
+
success: errors2.length === 0,
|
|
4589
|
+
errors: errors2
|
|
4621
4590
|
};
|
|
4622
4591
|
}
|
|
4623
4592
|
function calculateParentAndOrder({
|
|
@@ -4868,6 +4837,82 @@ async function enrichRoutePickerFields(data, contentTypeUid) {
|
|
|
4868
4837
|
const enriched = enrichEntity(data, contentTypeUid, routeMap);
|
|
4869
4838
|
return enriched;
|
|
4870
4839
|
}
|
|
4840
|
+
function isBlacklistedPath(url, routeBlacklist) {
|
|
4841
|
+
if (!url) return false;
|
|
4842
|
+
const path = url.toLowerCase();
|
|
4843
|
+
return routeBlacklist.some((segment) => path.startsWith(`${segment}/`) || path === segment);
|
|
4844
|
+
}
|
|
4845
|
+
function normalizeRouteBlacklist(entries) {
|
|
4846
|
+
if (!Array.isArray(entries)) return [];
|
|
4847
|
+
return entries.filter((entry) => typeof entry === "string").map((entry) => entry.trim().toLowerCase().replace(/^\/+/, "").replace(/\/+$/, "")).filter(Boolean);
|
|
4848
|
+
}
|
|
4849
|
+
async function getRouteBlacklist() {
|
|
4850
|
+
const pluginStore = strapi.store({ type: "plugin", name: PLUGIN_ID });
|
|
4851
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
4852
|
+
return normalizeRouteBlacklist(config2?.routeBlacklist);
|
|
4853
|
+
}
|
|
4854
|
+
function assertPathAllowed(path, routeBlacklist) {
|
|
4855
|
+
if (isBlacklistedPath(path, routeBlacklist)) {
|
|
4856
|
+
throw new errors.ApplicationError(
|
|
4857
|
+
`The generated path "${path}" is blocked by the route blacklist.`
|
|
4858
|
+
);
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
async function assertDescendantPathsAllowed({
|
|
4862
|
+
validatedParentPath,
|
|
4863
|
+
parentRouteDocumentId,
|
|
4864
|
+
canonicalPath,
|
|
4865
|
+
isOverride,
|
|
4866
|
+
routeBlacklist
|
|
4867
|
+
}) {
|
|
4868
|
+
const prefixes = [`${validatedParentPath}/`.toLowerCase(), `${canonicalPath}/`.toLowerCase()];
|
|
4869
|
+
if (!routeBlacklist.some((segment) => prefixes.some((prefix) => segment.startsWith(prefix))))
|
|
4870
|
+
return;
|
|
4871
|
+
const children = await strapi.db.query(waRoute).findMany({
|
|
4872
|
+
where: {
|
|
4873
|
+
parent: {
|
|
4874
|
+
documentId: parentRouteDocumentId
|
|
4875
|
+
}
|
|
4876
|
+
}
|
|
4877
|
+
});
|
|
4878
|
+
for (const child of children) {
|
|
4879
|
+
const newCanonicalPath = `${canonicalPath}/${child.slug}`;
|
|
4880
|
+
assertPathAllowed(newCanonicalPath, routeBlacklist);
|
|
4881
|
+
let newPath = child.path;
|
|
4882
|
+
if (!child.isOverride) {
|
|
4883
|
+
newPath = isOverride ? `${validatedParentPath}/${child.slug}` : newCanonicalPath;
|
|
4884
|
+
assertPathAllowed(newPath, routeBlacklist);
|
|
4885
|
+
}
|
|
4886
|
+
await assertDescendantPathsAllowed({
|
|
4887
|
+
validatedParentPath: newPath,
|
|
4888
|
+
parentRouteDocumentId: child.documentId,
|
|
4889
|
+
canonicalPath: newCanonicalPath,
|
|
4890
|
+
isOverride: isOverride || Boolean(child.isOverride),
|
|
4891
|
+
routeBlacklist
|
|
4892
|
+
});
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4895
|
+
function toBreadcrumbEntry(route2) {
|
|
4896
|
+
return {
|
|
4897
|
+
path: route2.path,
|
|
4898
|
+
canonicalPath: route2.canonicalPath,
|
|
4899
|
+
slug: route2.slug,
|
|
4900
|
+
uidPath: route2.uidPath,
|
|
4901
|
+
title: route2.title
|
|
4902
|
+
};
|
|
4903
|
+
}
|
|
4904
|
+
async function addWebatlasBreadcrumb(data, route2) {
|
|
4905
|
+
if (!data?.webatlas || !route2) return data;
|
|
4906
|
+
const segments = route2.canonicalPath?.split("/").filter(Boolean) || [];
|
|
4907
|
+
const ancestorPaths = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join("/"));
|
|
4908
|
+
const ancestors = ancestorPaths.length ? await strapi.db.query(waRoute).findMany({
|
|
4909
|
+
where: { canonicalPath: { $in: ancestorPaths } },
|
|
4910
|
+
select: ["path", "canonicalPath", "slug", "uidPath", "title"]
|
|
4911
|
+
}) : [];
|
|
4912
|
+
const orderedAncestors = ancestorPaths.map((path) => ancestors.find((ancestor) => ancestor.canonicalPath === path)).filter(Boolean);
|
|
4913
|
+
data.webatlas.breadcrumb = [...orderedAncestors, route2].map(toBreadcrumbEntry);
|
|
4914
|
+
return data;
|
|
4915
|
+
}
|
|
4871
4916
|
const migration_001_canonical_path = {
|
|
4872
4917
|
version: "001",
|
|
4873
4918
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -4995,7 +5040,34 @@ const migration_002_webatlas_json_field = {
|
|
|
4995
5040
|
strapi2.log.info("[webatlas] webatlas JSON field migration completed");
|
|
4996
5041
|
}
|
|
4997
5042
|
};
|
|
4998
|
-
const
|
|
5043
|
+
const migration_003_route_source_field = {
|
|
5044
|
+
version: "003",
|
|
5045
|
+
description: 'Rename the "default" / "defaultField" content type keys to "routeSourceField"',
|
|
5046
|
+
async up(strapi2) {
|
|
5047
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5048
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
5049
|
+
if (!config2?.selectedContentTypes?.length) {
|
|
5050
|
+
strapi2.log.info("[webatlas] No content type settings found, skipping");
|
|
5051
|
+
return;
|
|
5052
|
+
}
|
|
5053
|
+
const selectedContentTypes = config2.selectedContentTypes.map((ct) => {
|
|
5054
|
+
const { default: legacyDefault, defaultField, ...rest } = ct;
|
|
5055
|
+
return {
|
|
5056
|
+
...rest,
|
|
5057
|
+
routeSourceField: ct.routeSourceField || defaultField || legacyDefault || null
|
|
5058
|
+
};
|
|
5059
|
+
});
|
|
5060
|
+
await pluginStore.set({ key: "config", value: { ...config2, selectedContentTypes } });
|
|
5061
|
+
strapi2.log.info(
|
|
5062
|
+
`[webatlas] Normalized routeSourceField for ${selectedContentTypes.length} content type(s)`
|
|
5063
|
+
);
|
|
5064
|
+
}
|
|
5065
|
+
};
|
|
5066
|
+
const migrations = [
|
|
5067
|
+
migration_001_canonical_path,
|
|
5068
|
+
migration_002_webatlas_json_field,
|
|
5069
|
+
migration_003_route_source_field
|
|
5070
|
+
];
|
|
4999
5071
|
const runMigrations = async (strapi2) => {
|
|
5000
5072
|
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5001
5073
|
let config2 = await pluginStore.get({ key: "config" });
|
|
@@ -5087,7 +5159,8 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5087
5159
|
newConfig.selectedContentTypes.push({
|
|
5088
5160
|
uid: type.uid,
|
|
5089
5161
|
label: type.info.displayName,
|
|
5090
|
-
|
|
5162
|
+
routeSourceField: existingConfig?.routeSourceField || null,
|
|
5163
|
+
defaultParentRoute: existingConfig?.defaultParentRoute || null
|
|
5091
5164
|
});
|
|
5092
5165
|
});
|
|
5093
5166
|
if (JSON.stringify(newConfig) !== JSON.stringify(config2)) {
|
|
@@ -5107,12 +5180,6 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5107
5180
|
const { webatlas } = data;
|
|
5108
5181
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5109
5182
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5110
|
-
const result2 = await next();
|
|
5111
|
-
if (!transformedSlug) return result2;
|
|
5112
|
-
const existing = await strapi2.db?.query(waRoute).findOne({
|
|
5113
|
-
where: { relatedDocumentId: result2.documentId }
|
|
5114
|
-
});
|
|
5115
|
-
if (existing) return result2;
|
|
5116
5183
|
let parent = null;
|
|
5117
5184
|
let isValid = false;
|
|
5118
5185
|
if (parentDocumentId) {
|
|
@@ -5129,13 +5196,24 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5129
5196
|
if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
|
|
5130
5197
|
const validatedPath = await duplicateCheck(rawPath);
|
|
5131
5198
|
if (!validatedPath)
|
|
5132
|
-
throw new
|
|
5133
|
-
|
|
5134
|
-
|
|
5199
|
+
throw new errors.ApplicationError(
|
|
5200
|
+
`Failed to generate a unique path for slug: ${transformedSlug}`
|
|
5201
|
+
);
|
|
5202
|
+
const title = context.params.data[ctSettings?.routeSourceField]?.trim() || transformedSlug;
|
|
5135
5203
|
const canonicalPath = await buildCanonicalPath(
|
|
5136
5204
|
transformToUrl(title),
|
|
5137
5205
|
isValid ? parent.documentId : null
|
|
5138
5206
|
);
|
|
5207
|
+
const routeBlacklist = await getRouteBlacklist();
|
|
5208
|
+
assertPathAllowed(rawPath, routeBlacklist);
|
|
5209
|
+
assertPathAllowed(canonicalPath, routeBlacklist);
|
|
5210
|
+
const result2 = await next();
|
|
5211
|
+
if (!transformedSlug) return result2;
|
|
5212
|
+
const existing = await strapi2.db?.query(waRoute).findOne({
|
|
5213
|
+
where: { relatedDocumentId: result2.documentId }
|
|
5214
|
+
});
|
|
5215
|
+
if (existing) return result2;
|
|
5216
|
+
const singularName = context.contentType.info.singularName;
|
|
5139
5217
|
await strapi2.documents(waRoute).create({
|
|
5140
5218
|
data: {
|
|
5141
5219
|
relatedContentType: context.uid,
|
|
@@ -5183,9 +5261,21 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5183
5261
|
let rawPath = transformedSlug;
|
|
5184
5262
|
if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
|
|
5185
5263
|
const validatedPath = await duplicateCheck(rawPath, relatedRoute?.documentId ?? null);
|
|
5186
|
-
const
|
|
5187
|
-
const title =
|
|
5264
|
+
const sourceValue = ctSettings?.routeSourceField ? context.params.data[ctSettings.routeSourceField]?.trim() : void 0;
|
|
5265
|
+
const title = sourceValue || relatedRoute?.title || slug;
|
|
5188
5266
|
const canonicalPath = isOverride ? relatedRoute.path : await buildCanonicalPath(transformToUrl(title), parent?.documentId);
|
|
5267
|
+
const routeBlacklist = await getRouteBlacklist();
|
|
5268
|
+
assertPathAllowed(rawPath, routeBlacklist);
|
|
5269
|
+
assertPathAllowed(canonicalPath, routeBlacklist);
|
|
5270
|
+
if (relatedRoute)
|
|
5271
|
+
await assertDescendantPathsAllowed({
|
|
5272
|
+
validatedParentPath: validatedPath,
|
|
5273
|
+
parentRouteDocumentId: relatedRoute.documentId,
|
|
5274
|
+
canonicalPath,
|
|
5275
|
+
isOverride: isOverride || false,
|
|
5276
|
+
routeBlacklist
|
|
5277
|
+
});
|
|
5278
|
+
const result2 = await next();
|
|
5189
5279
|
const routeData = {
|
|
5190
5280
|
title,
|
|
5191
5281
|
path: validatedPath,
|
|
@@ -5223,21 +5313,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5223
5313
|
}
|
|
5224
5314
|
if (context.action === "delete") {
|
|
5225
5315
|
const result2 = await next();
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5316
|
+
const relatedDocumentId = context.params.documentId;
|
|
5317
|
+
const deletedRoute = await strapi2.db.query(waRoute).delete({
|
|
5318
|
+
where: { relatedDocumentId },
|
|
5319
|
+
populate: ["navitem"]
|
|
5320
|
+
});
|
|
5321
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5322
|
+
const currentConfig = await pluginStore.get({ key: "config" });
|
|
5323
|
+
const selectedContentTypes = currentConfig.selectedContentTypes.map(
|
|
5324
|
+
(ct) => ct.defaultParentRoute === relatedDocumentId ? { ...ct, defaultParentRoute: null } : ct
|
|
5325
|
+
);
|
|
5326
|
+
if (selectedContentTypes.some((ct, i) => ct !== currentConfig.selectedContentTypes[i])) {
|
|
5327
|
+
await pluginStore.set({
|
|
5328
|
+
key: "config",
|
|
5329
|
+
value: { ...currentConfig, selectedContentTypes }
|
|
5231
5330
|
});
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
)
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
}
|
|
5239
|
-
} catch (err) {
|
|
5240
|
-
strapi2.log.error(err);
|
|
5331
|
+
}
|
|
5332
|
+
if (!deletedRoute?.documentId) return result2;
|
|
5333
|
+
const navItemDocumentIds = Array.from(
|
|
5334
|
+
deletedRoute.navitem?.map((item) => item.documentId)
|
|
5335
|
+
);
|
|
5336
|
+
for (const navItemDocumentId of navItemDocumentIds) {
|
|
5337
|
+
await strapi2.documents(waNavItem).delete({ documentId: navItemDocumentId });
|
|
5241
5338
|
}
|
|
5242
5339
|
return result2;
|
|
5243
5340
|
}
|
|
@@ -5250,24 +5347,16 @@ function webatlasMiddleware(strapi2) {
|
|
|
5250
5347
|
if (context.uid !== waNavItem) return next();
|
|
5251
5348
|
if (context.action === "delete") {
|
|
5252
5349
|
let externalRouteDocumentId = null;
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
externalRouteDocumentId = navItem.route.documentId;
|
|
5260
|
-
}
|
|
5261
|
-
} catch (err) {
|
|
5262
|
-
strapi2.log.error(err);
|
|
5350
|
+
const navItem = await strapi2.db?.query(waNavItem).findOne({
|
|
5351
|
+
where: { documentId: context.params.documentId },
|
|
5352
|
+
populate: ["route"]
|
|
5353
|
+
});
|
|
5354
|
+
if (navItem?.route?.type === "external") {
|
|
5355
|
+
externalRouteDocumentId = navItem.route.documentId;
|
|
5263
5356
|
}
|
|
5264
5357
|
const result = await next();
|
|
5265
5358
|
if (externalRouteDocumentId) {
|
|
5266
|
-
|
|
5267
|
-
await strapi2.documents(waRoute).delete({ documentId: externalRouteDocumentId });
|
|
5268
|
-
} catch (err) {
|
|
5269
|
-
strapi2.log.error(err);
|
|
5270
|
-
}
|
|
5359
|
+
await strapi2.documents(waRoute).delete({ documentId: externalRouteDocumentId });
|
|
5271
5360
|
}
|
|
5272
5361
|
return result;
|
|
5273
5362
|
}
|
|
@@ -5375,7 +5464,8 @@ const config = {
|
|
|
5375
5464
|
selectedContentTypes: [],
|
|
5376
5465
|
navigation: {
|
|
5377
5466
|
maxDepth: 1
|
|
5378
|
-
}
|
|
5467
|
+
},
|
|
5468
|
+
routeBlacklist: []
|
|
5379
5469
|
},
|
|
5380
5470
|
validator() {
|
|
5381
5471
|
}
|
|
@@ -5589,139 +5679,84 @@ const contentTypes = {
|
|
|
5589
5679
|
};
|
|
5590
5680
|
const admin$2 = () => ({
|
|
5591
5681
|
async updateConfig(ctx) {
|
|
5592
|
-
|
|
5593
|
-
await getAdminService().updateConfig(ctx.request.body);
|
|
5594
|
-
} catch (e) {
|
|
5595
|
-
ctx.throw(500, e);
|
|
5596
|
-
}
|
|
5682
|
+
await getAdminService().updateConfig(ctx.request.body);
|
|
5597
5683
|
return ctx.send({ status: 200 });
|
|
5598
5684
|
},
|
|
5599
5685
|
async getConfig(ctx) {
|
|
5600
|
-
|
|
5601
|
-
return await getAdminService().getConfig();
|
|
5602
|
-
} catch (e) {
|
|
5603
|
-
return ctx.throw(500, e);
|
|
5604
|
-
}
|
|
5686
|
+
return await getAdminService().getConfig();
|
|
5605
5687
|
},
|
|
5606
5688
|
async getRoute(ctx) {
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
return await getAdminService().getRoute(documentId);
|
|
5611
|
-
} catch (e) {
|
|
5612
|
-
return ctx.throw(500, e);
|
|
5613
|
-
}
|
|
5689
|
+
const { documentId } = ctx.params;
|
|
5690
|
+
if (!documentId) throw new errors.ValidationError("Route documentId is required");
|
|
5691
|
+
return await getAdminService().getRoute(documentId);
|
|
5614
5692
|
},
|
|
5615
5693
|
async getAllRoutes(ctx) {
|
|
5616
|
-
|
|
5617
|
-
return await getAdminService().getAllRoutes();
|
|
5618
|
-
} catch (e) {
|
|
5619
|
-
return ctx.throw(500, e);
|
|
5620
|
-
}
|
|
5694
|
+
return await getAdminService().getAllRoutes();
|
|
5621
5695
|
},
|
|
5622
5696
|
async getRelatedRoute(ctx) {
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
return await getAdminService().getRelatedRoute(documentId);
|
|
5627
|
-
} catch (e) {
|
|
5628
|
-
return ctx.throw(500, e);
|
|
5629
|
-
}
|
|
5697
|
+
const { documentId } = ctx.query;
|
|
5698
|
+
if (!documentId) throw new errors.ValidationError("Route documentId is required");
|
|
5699
|
+
return await getAdminService().getRelatedRoute(documentId);
|
|
5630
5700
|
},
|
|
5631
5701
|
async getProhibitedRouteIds(ctx) {
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
return await getAdminService().getProhibitedRouteIds(documentId);
|
|
5635
|
-
} catch (e) {
|
|
5636
|
-
return ctx.throw(500, e);
|
|
5637
|
-
}
|
|
5702
|
+
const { documentId } = ctx.params;
|
|
5703
|
+
return await getAdminService().getProhibitedRouteIds(documentId);
|
|
5638
5704
|
},
|
|
5639
5705
|
async getNavigation(ctx) {
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
return await getAdminService().getNavigation(documentId, variant);
|
|
5643
|
-
} catch (e) {
|
|
5644
|
-
return ctx.throw(500, e);
|
|
5645
|
-
}
|
|
5706
|
+
const { documentId, variant } = ctx.query;
|
|
5707
|
+
return await getAdminService().getNavigation(documentId, variant);
|
|
5646
5708
|
},
|
|
5647
5709
|
async createNavigation(ctx) {
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
return await getAdminService().createNavigation(data.name, data.visible);
|
|
5652
|
-
} catch (e) {
|
|
5653
|
-
return ctx.throw(500, e);
|
|
5654
|
-
}
|
|
5710
|
+
const { data } = ctx.request.body;
|
|
5711
|
+
if (!data || !data.name) throw new errors.ValidationError("Navigation name is required");
|
|
5712
|
+
return await getAdminService().createNavigation(data.name, data.visible);
|
|
5655
5713
|
},
|
|
5656
5714
|
async updateNavigation(ctx) {
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
return await getAdminService().updateNavigation(documentId, data);
|
|
5662
|
-
} catch (e) {
|
|
5663
|
-
return ctx.throw(500, e);
|
|
5664
|
-
}
|
|
5715
|
+
const { documentId } = ctx.query;
|
|
5716
|
+
if (!documentId) throw new errors.ValidationError("Navigation documentId is required");
|
|
5717
|
+
const { data } = ctx.request.body;
|
|
5718
|
+
return await getAdminService().updateNavigation(documentId, data);
|
|
5665
5719
|
},
|
|
5666
5720
|
async updateNavigationItemStructure(ctx) {
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
|
|
5672
|
-
} catch (e) {
|
|
5673
|
-
return ctx.throw(500, e);
|
|
5674
|
-
}
|
|
5721
|
+
const { navigationId, navigationItems } = ctx.request.body;
|
|
5722
|
+
if (!navigationId || !navigationItems)
|
|
5723
|
+
throw new errors.ValidationError("NavigationId and Navigation items are required");
|
|
5724
|
+
return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
|
|
5675
5725
|
},
|
|
5676
5726
|
async deleteNavigation(ctx) {
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
return await getAdminService().deleteNavigation(documentId);
|
|
5681
|
-
} catch (e) {
|
|
5682
|
-
return ctx.throw(500, e);
|
|
5683
|
-
}
|
|
5727
|
+
const { documentId } = ctx.query;
|
|
5728
|
+
if (!documentId) throw new errors.ValidationError("Navigation documentId is required");
|
|
5729
|
+
return await getAdminService().deleteNavigation(documentId);
|
|
5684
5730
|
},
|
|
5685
5731
|
async checkUniquePath(ctx) {
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
return ctx.send({ uniquePath: res });
|
|
5691
|
-
} catch (e) {
|
|
5692
|
-
return ctx.throw(500, e);
|
|
5693
|
-
}
|
|
5732
|
+
const { path, targetRouteDocumentId } = ctx.query;
|
|
5733
|
+
if (!path) throw new errors.ValidationError("Path is required");
|
|
5734
|
+
const res = await getAdminService().checkUniquePath(path, targetRouteDocumentId || null);
|
|
5735
|
+
return ctx.send(res);
|
|
5694
5736
|
}
|
|
5695
5737
|
});
|
|
5696
5738
|
const client$2 = ({ strapi: strapi2 }) => ({
|
|
5697
5739
|
async getEntityByPath(ctx) {
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
} catch (e) {
|
|
5711
|
-
ctx.throw(500, e);
|
|
5712
|
-
}
|
|
5740
|
+
const { slug, populate, populateDeepDepth, fields, status, breadcrumb } = ctx.query;
|
|
5741
|
+
if (!slug) throw new errors.ValidationError("Slug is required");
|
|
5742
|
+
const entity = await getClientService().getEntityByPath(
|
|
5743
|
+
slug,
|
|
5744
|
+
populate,
|
|
5745
|
+
populateDeepDepth,
|
|
5746
|
+
fields,
|
|
5747
|
+
status,
|
|
5748
|
+
breadcrumb !== "false"
|
|
5749
|
+
);
|
|
5750
|
+
if (!entity) throw new errors.NotFoundError("Entity not found");
|
|
5751
|
+
return ctx.send(entity);
|
|
5713
5752
|
},
|
|
5714
5753
|
async getNavigation(ctx) {
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
return ctx.send(navigation2);
|
|
5722
|
-
} catch (e) {
|
|
5723
|
-
return ctx.throw(500, e);
|
|
5724
|
-
}
|
|
5754
|
+
const { id, name, slug, documentId, variant } = ctx.query;
|
|
5755
|
+
if (!id && !name && !slug && !documentId)
|
|
5756
|
+
throw new errors.ValidationError("Navigation id, name, slug or documentId is required");
|
|
5757
|
+
const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
|
|
5758
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
5759
|
+
return ctx.send(navigation2);
|
|
5725
5760
|
}
|
|
5726
5761
|
});
|
|
5727
5762
|
const controllers = {
|
|
@@ -5986,19 +6021,15 @@ const routes = {
|
|
|
5986
6021
|
const admin = ({ strapi: strapi2 }) => ({
|
|
5987
6022
|
async updateConfig(newConfig) {
|
|
5988
6023
|
if (!newConfig) return;
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
newConfigMerged =
|
|
5997
|
-
|
|
5998
|
-
} catch (err) {
|
|
5999
|
-
strapi2.log.error(err);
|
|
6000
|
-
return "Error. Couldn't update config";
|
|
6001
|
-
}
|
|
6024
|
+
const pluginStore = await strapi2.store({
|
|
6025
|
+
type: "plugin",
|
|
6026
|
+
name: PLUGIN_ID
|
|
6027
|
+
});
|
|
6028
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
6029
|
+
const newConfigMerged = { ...config2, ...newConfig };
|
|
6030
|
+
if (newConfig.routeBlacklist !== void 0)
|
|
6031
|
+
newConfigMerged.routeBlacklist = normalizeRouteBlacklist(newConfig.routeBlacklist);
|
|
6032
|
+
await pluginStore.set({ key: "config", value: newConfigMerged });
|
|
6002
6033
|
return newConfigMerged;
|
|
6003
6034
|
},
|
|
6004
6035
|
async getConfig() {
|
|
@@ -6018,140 +6049,107 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6018
6049
|
return config2;
|
|
6019
6050
|
},
|
|
6020
6051
|
async getRoute(documentId) {
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
});
|
|
6025
|
-
} catch (e) {
|
|
6026
|
-
strapi2.log.error(e);
|
|
6027
|
-
}
|
|
6052
|
+
return await strapi2.documents(waRoute).findOne({
|
|
6053
|
+
documentId
|
|
6054
|
+
});
|
|
6028
6055
|
},
|
|
6029
6056
|
async getAllRoutes() {
|
|
6030
|
-
|
|
6031
|
-
const entities = await strapi2.documents(waRoute).findMany();
|
|
6032
|
-
return entities;
|
|
6033
|
-
} catch (e) {
|
|
6034
|
-
strapi2.log.error(e);
|
|
6035
|
-
}
|
|
6057
|
+
return await strapi2.documents(waRoute).findMany();
|
|
6036
6058
|
},
|
|
6037
6059
|
async getRelatedRoute(documentId) {
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
});
|
|
6045
|
-
} catch (e) {
|
|
6046
|
-
strapi2.log.error(e);
|
|
6047
|
-
}
|
|
6060
|
+
return await strapi2.db?.query(waRoute).findOne({
|
|
6061
|
+
where: {
|
|
6062
|
+
relatedDocumentId: documentId
|
|
6063
|
+
},
|
|
6064
|
+
populate: ["parent"]
|
|
6065
|
+
});
|
|
6048
6066
|
},
|
|
6049
6067
|
async getProhibitedRouteIds(documentId) {
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
});
|
|
6056
|
-
}
|
|
6057
|
-
const descendants = route2?.documentId ? await getRouteDescendants(route2.documentId) : [];
|
|
6058
|
-
const nonInternalRouteIds = await getNonInternalRouteIds();
|
|
6059
|
-
const prohibitedRouteIds = [...descendants, ...nonInternalRouteIds];
|
|
6060
|
-
route2?.documentId && prohibitedRouteIds.push(route2.documentId);
|
|
6061
|
-
return prohibitedRouteIds;
|
|
6062
|
-
} catch (e) {
|
|
6063
|
-
strapi2.log.error(e);
|
|
6068
|
+
let route2 = null;
|
|
6069
|
+
if (documentId) {
|
|
6070
|
+
route2 = await strapi2.documents(waRoute).findOne({
|
|
6071
|
+
documentId
|
|
6072
|
+
});
|
|
6064
6073
|
}
|
|
6074
|
+
const descendants = route2?.documentId ? await getRouteDescendants(route2.documentId) : [];
|
|
6075
|
+
const nonInternalRouteIds = await getNonInternalRouteIds();
|
|
6076
|
+
const prohibitedRouteIds = [...descendants, ...nonInternalRouteIds];
|
|
6077
|
+
route2?.documentId && prohibitedRouteIds.push(route2.documentId);
|
|
6078
|
+
return prohibitedRouteIds;
|
|
6065
6079
|
},
|
|
6066
6080
|
async getNavigation(documentId, variant) {
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
if (variant === "namesOnly") {
|
|
6070
|
-
if (documentId) {
|
|
6071
|
-
return await strapi2.documents(waNavigation).findOne({
|
|
6072
|
-
documentId,
|
|
6073
|
-
select: ["documentId", "name", "slug", "visible"]
|
|
6074
|
-
});
|
|
6075
|
-
}
|
|
6076
|
-
return await strapi2.documents(waNavigation).findMany({
|
|
6077
|
-
select: ["documentId", "name", "slug", "visible"]
|
|
6078
|
-
});
|
|
6079
|
-
}
|
|
6081
|
+
let navigation2 = null;
|
|
6082
|
+
if (variant === "namesOnly") {
|
|
6080
6083
|
if (documentId) {
|
|
6081
|
-
|
|
6084
|
+
return await strapi2.documents(waNavigation).findOne({
|
|
6082
6085
|
documentId,
|
|
6083
|
-
|
|
6084
|
-
});
|
|
6085
|
-
if (!navigation2) throw new Error("Navigation not found");
|
|
6086
|
-
if (variant) navigation2 = buildStructuredNavigation(navigation2, variant);
|
|
6087
|
-
} else {
|
|
6088
|
-
navigation2 = await strapi2.documents(waNavigation).findMany({
|
|
6089
|
-
populate: ["items", "items.route", "items.parent"]
|
|
6086
|
+
select: ["documentId", "name", "slug", "visible"]
|
|
6090
6087
|
});
|
|
6091
|
-
if (!navigation2) throw new Error("Navigation not found");
|
|
6092
|
-
if (variant) {
|
|
6093
|
-
navigation2 = navigation2.map(
|
|
6094
|
-
(nav) => buildStructuredNavigation(nav, variant)
|
|
6095
|
-
);
|
|
6096
|
-
}
|
|
6097
6088
|
}
|
|
6098
|
-
return
|
|
6099
|
-
|
|
6100
|
-
strapi2.log.error(e);
|
|
6101
|
-
}
|
|
6102
|
-
},
|
|
6103
|
-
async createNavigation(name, visible) {
|
|
6104
|
-
try {
|
|
6105
|
-
return await strapi2.documents(waNavigation).create({
|
|
6106
|
-
data: {
|
|
6107
|
-
name,
|
|
6108
|
-
slug: transformToUrl(name),
|
|
6109
|
-
visible
|
|
6110
|
-
}
|
|
6089
|
+
return await strapi2.documents(waNavigation).findMany({
|
|
6090
|
+
select: ["documentId", "name", "slug", "visible"]
|
|
6111
6091
|
});
|
|
6112
|
-
} catch (e) {
|
|
6113
|
-
strapi2.log.error(e);
|
|
6114
6092
|
}
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
try {
|
|
6118
|
-
const entity = await strapi2.documents(waNavigation).update({
|
|
6093
|
+
if (documentId) {
|
|
6094
|
+
navigation2 = await strapi2.documents(waNavigation).findOne({
|
|
6119
6095
|
documentId,
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6096
|
+
populate: ["items", "items.route", "items.parent"]
|
|
6097
|
+
});
|
|
6098
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
6099
|
+
if (variant) navigation2 = buildStructuredNavigation(navigation2, variant);
|
|
6100
|
+
} else {
|
|
6101
|
+
navigation2 = await strapi2.documents(waNavigation).findMany({
|
|
6102
|
+
populate: ["items", "items.route", "items.parent"]
|
|
6124
6103
|
});
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6104
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
6105
|
+
if (variant) {
|
|
6106
|
+
navigation2 = navigation2.map(
|
|
6107
|
+
(nav) => buildStructuredNavigation(nav, variant)
|
|
6108
|
+
);
|
|
6109
|
+
}
|
|
6128
6110
|
}
|
|
6111
|
+
return navigation2;
|
|
6129
6112
|
},
|
|
6130
|
-
async
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
if (!navigation2) throw new Error("Navigation not found");
|
|
6137
|
-
for (const item of navigation2.items) {
|
|
6138
|
-
await strapi2.documents(waNavItem).delete({
|
|
6139
|
-
documentId: item.documentId
|
|
6140
|
-
});
|
|
6113
|
+
async createNavigation(name, visible) {
|
|
6114
|
+
return await strapi2.documents(waNavigation).create({
|
|
6115
|
+
data: {
|
|
6116
|
+
name,
|
|
6117
|
+
slug: transformToUrl(name),
|
|
6118
|
+
visible
|
|
6141
6119
|
}
|
|
6142
|
-
|
|
6143
|
-
|
|
6120
|
+
});
|
|
6121
|
+
},
|
|
6122
|
+
async updateNavigation(documentId, data) {
|
|
6123
|
+
return await strapi2.documents(waNavigation).update({
|
|
6124
|
+
documentId,
|
|
6125
|
+
data: {
|
|
6126
|
+
name: data.name,
|
|
6127
|
+
visible: data.visible
|
|
6128
|
+
}
|
|
6129
|
+
});
|
|
6130
|
+
},
|
|
6131
|
+
async deleteNavigation(documentId) {
|
|
6132
|
+
const navigation2 = await strapi2.documents(waNavigation).findOne({
|
|
6133
|
+
documentId,
|
|
6134
|
+
populate: ["items"]
|
|
6135
|
+
});
|
|
6136
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
6137
|
+
for (const item of navigation2.items) {
|
|
6138
|
+
await strapi2.documents(waNavItem).delete({
|
|
6139
|
+
documentId: item.documentId
|
|
6144
6140
|
});
|
|
6145
|
-
} catch (e) {
|
|
6146
|
-
strapi2.log.error(e);
|
|
6147
6141
|
}
|
|
6142
|
+
return await strapi2.documents(waNavigation).delete({
|
|
6143
|
+
documentId
|
|
6144
|
+
});
|
|
6148
6145
|
},
|
|
6149
6146
|
async updateNavigationItemStructure(navigationId, navigationItems) {
|
|
6150
6147
|
if (!navigationId || !navigationItems) return;
|
|
6151
|
-
|
|
6148
|
+
const errors2 = [];
|
|
6152
6149
|
let newNavItemsMap = /* @__PURE__ */ new Map();
|
|
6153
6150
|
const deletionResult = await handleItemDeletion(navigationItems);
|
|
6154
6151
|
if (!deletionResult.success) {
|
|
6152
|
+
errors2.push(...deletionResult.errors);
|
|
6155
6153
|
strapi2.log.error("Deletion errors:", deletionResult.errors);
|
|
6156
6154
|
}
|
|
6157
6155
|
navigationItems = deletionResult.items;
|
|
@@ -6178,126 +6176,118 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6178
6176
|
newNavItemsMap
|
|
6179
6177
|
});
|
|
6180
6178
|
if (!result.success) {
|
|
6179
|
+
errors2.push(...result.errors);
|
|
6181
6180
|
strapi2.log.error("Error updating item: ", item);
|
|
6182
6181
|
}
|
|
6183
|
-
} catch (
|
|
6184
|
-
|
|
6185
|
-
strapi2.log.error("Error updating navigation item ",
|
|
6182
|
+
} catch (err) {
|
|
6183
|
+
errors2.push(err instanceof Error ? err.message : String(err));
|
|
6184
|
+
strapi2.log.error("Error updating navigation item ", err);
|
|
6186
6185
|
}
|
|
6187
6186
|
}
|
|
6188
|
-
return
|
|
6187
|
+
return { success: errors2.length === 0, errors: errors2 };
|
|
6189
6188
|
},
|
|
6190
6189
|
async checkUniquePath(initialPath, targetRouteDocumentId = null) {
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
strapi2.log.error(e);
|
|
6195
|
-
}
|
|
6190
|
+
const routeBlacklist = await getRouteBlacklist();
|
|
6191
|
+
if (isBlacklistedPath(initialPath, routeBlacklist)) return { blacklisted: true };
|
|
6192
|
+
return { uniquePath: await duplicateCheck(initialPath, targetRouteDocumentId) };
|
|
6196
6193
|
}
|
|
6197
6194
|
});
|
|
6198
6195
|
const client = ({ strapi: strapi2 }) => ({
|
|
6199
|
-
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published") {
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
$or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
|
|
6204
|
-
}
|
|
6205
|
-
});
|
|
6206
|
-
if (!route2) return null;
|
|
6207
|
-
let populateObject = populate;
|
|
6208
|
-
if (populate === "deep") {
|
|
6209
|
-
const modelObject = getFullPopulateObject(
|
|
6210
|
-
route2.relatedContentType,
|
|
6211
|
-
Number(populateDeepDepth),
|
|
6212
|
-
[]
|
|
6213
|
-
);
|
|
6214
|
-
if (typeof modelObject === "object" && "populate" in modelObject) {
|
|
6215
|
-
populateObject = modelObject.populate;
|
|
6216
|
-
}
|
|
6196
|
+
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true) {
|
|
6197
|
+
const route2 = await strapi2.documents(waRoute).findFirst({
|
|
6198
|
+
filters: {
|
|
6199
|
+
$or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
|
|
6217
6200
|
}
|
|
6218
|
-
|
|
6219
|
-
|
|
6201
|
+
});
|
|
6202
|
+
if (!route2) return null;
|
|
6203
|
+
let populateObject = populate;
|
|
6204
|
+
if (populate === "deep") {
|
|
6205
|
+
const modelObject = getFullPopulateObject(
|
|
6206
|
+
route2.relatedContentType,
|
|
6207
|
+
Number(populateDeepDepth),
|
|
6208
|
+
[]
|
|
6220
6209
|
);
|
|
6221
|
-
if (
|
|
6222
|
-
|
|
6223
|
-
}
|
|
6224
|
-
const [contentTypeKey, contentType] = contentTypeObject;
|
|
6225
|
-
const entity = await strapi2.documents(route2.relatedContentType).findOne({
|
|
6226
|
-
documentId: route2.relatedDocumentId,
|
|
6227
|
-
populate: populateObject,
|
|
6228
|
-
fields,
|
|
6229
|
-
status
|
|
6230
|
-
});
|
|
6231
|
-
if (!entity) return null;
|
|
6232
|
-
let cleanEntity = cleanRootKeys(entity);
|
|
6233
|
-
cleanEntity = removeWaFields(cleanEntity);
|
|
6234
|
-
cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
|
|
6235
|
-
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
|
|
6236
|
-
return {
|
|
6237
|
-
contentType: contentType.info.singularName,
|
|
6238
|
-
...cleanEntity
|
|
6239
|
-
};
|
|
6240
|
-
} catch (e) {
|
|
6241
|
-
strapi2.log.error(e);
|
|
6242
|
-
return e;
|
|
6210
|
+
if (typeof modelObject === "object" && "populate" in modelObject) {
|
|
6211
|
+
populateObject = modelObject.populate;
|
|
6212
|
+
}
|
|
6243
6213
|
}
|
|
6214
|
+
const contentTypeObject = Object.entries(strapi2.contentTypes).find(
|
|
6215
|
+
([key, value]) => key === route2.relatedContentType
|
|
6216
|
+
);
|
|
6217
|
+
if (!contentTypeObject) {
|
|
6218
|
+
return null;
|
|
6219
|
+
}
|
|
6220
|
+
const [contentTypeKey, contentType] = contentTypeObject;
|
|
6221
|
+
const entity = await strapi2.documents(route2.relatedContentType).findOne({
|
|
6222
|
+
documentId: route2.relatedDocumentId,
|
|
6223
|
+
populate: populateObject,
|
|
6224
|
+
fields,
|
|
6225
|
+
status
|
|
6226
|
+
});
|
|
6227
|
+
if (!entity) return null;
|
|
6228
|
+
let cleanEntity = cleanRootKeys(entity);
|
|
6229
|
+
cleanEntity = removeWaFields(cleanEntity);
|
|
6230
|
+
cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
|
|
6231
|
+
if (breadcrumb) {
|
|
6232
|
+
cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2);
|
|
6233
|
+
}
|
|
6234
|
+
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
|
|
6235
|
+
return {
|
|
6236
|
+
contentType: contentType.info.singularName,
|
|
6237
|
+
...cleanEntity
|
|
6238
|
+
};
|
|
6244
6239
|
},
|
|
6245
6240
|
async getNavigation(id, name, slug, documentId, variant = "nested") {
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
}
|
|
6288
|
-
strapi2.log.error(`Navigation lookup by ${method.name} failed:`, error);
|
|
6289
|
-
}
|
|
6241
|
+
let navigation2 = null;
|
|
6242
|
+
const populateObject = ["items", "items.parent", "items.route"];
|
|
6243
|
+
const lookupMethods = [
|
|
6244
|
+
{
|
|
6245
|
+
condition: documentId,
|
|
6246
|
+
lookup: () => strapi2.documents(waNavigation).findOne({
|
|
6247
|
+
documentId,
|
|
6248
|
+
populate: populateObject
|
|
6249
|
+
}),
|
|
6250
|
+
name: "documentId"
|
|
6251
|
+
},
|
|
6252
|
+
{
|
|
6253
|
+
condition: slug,
|
|
6254
|
+
lookup: () => strapi2.db?.query(waNavigation).findOne({
|
|
6255
|
+
where: { slug },
|
|
6256
|
+
populate: populateObject
|
|
6257
|
+
}),
|
|
6258
|
+
name: "slug"
|
|
6259
|
+
},
|
|
6260
|
+
{
|
|
6261
|
+
condition: name,
|
|
6262
|
+
lookup: () => strapi2.db?.query(waNavigation).findOne({
|
|
6263
|
+
where: { name },
|
|
6264
|
+
populate: populateObject
|
|
6265
|
+
}),
|
|
6266
|
+
name: "name"
|
|
6267
|
+
},
|
|
6268
|
+
{
|
|
6269
|
+
condition: id,
|
|
6270
|
+
lookup: () => strapi2.db?.query(waNavigation).findOne({
|
|
6271
|
+
where: { id },
|
|
6272
|
+
populate: populateObject
|
|
6273
|
+
}),
|
|
6274
|
+
name: "id"
|
|
6275
|
+
}
|
|
6276
|
+
];
|
|
6277
|
+
for (const method of lookupMethods) {
|
|
6278
|
+
if (method.condition && !navigation2) {
|
|
6279
|
+
try {
|
|
6280
|
+
navigation2 = await method.lookup();
|
|
6281
|
+
} catch (error) {
|
|
6282
|
+
strapi2.log.error(`Navigation lookup by ${method.name} failed:`, error);
|
|
6290
6283
|
}
|
|
6291
6284
|
}
|
|
6292
|
-
if (!navigation2) return null;
|
|
6293
|
-
const structured = buildStructuredNavigation(navigation2, variant);
|
|
6294
|
-
if (!structured) return null;
|
|
6295
|
-
const entityNavigation = extractRouteAndItems(structured.items);
|
|
6296
|
-
return { ...structured, items: entityNavigation };
|
|
6297
|
-
} catch (e) {
|
|
6298
|
-
strapi2.log.error(e);
|
|
6299
|
-
return e;
|
|
6300
6285
|
}
|
|
6286
|
+
if (!navigation2) return null;
|
|
6287
|
+
const structured = buildStructuredNavigation(navigation2, variant);
|
|
6288
|
+
if (!structured) return null;
|
|
6289
|
+
const entityNavigation = extractRouteAndItems(structured.items);
|
|
6290
|
+
return { ...structured, items: entityNavigation };
|
|
6301
6291
|
}
|
|
6302
6292
|
});
|
|
6303
6293
|
const services = {
|