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