@mattisvensson/strapi-plugin-webatlas 0.11.9 → 0.12.0

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.
Files changed (31) hide show
  1. package/README.md +6 -2
  2. package/dist/admin/{FullLoader-Btjb2W2p.mjs → FullLoader-BTZzPY8g.mjs} +11 -1
  3. package/dist/admin/{FullLoader-Da2n70bJ.js → FullLoader-C4hXFaLP.js} +10 -0
  4. package/dist/admin/{RoutePicker-p1rh5rcZ.mjs → RoutePicker-h2yWGB6S.mjs} +1 -1
  5. package/dist/admin/{RoutePicker-D9RNp4zS.js → RoutePicker-mEHRtXQ9.js} +1 -1
  6. package/dist/admin/{SettingTitle-CwB5CsY0.js → SettingTitle-CBcBCh1h.js} +1 -1
  7. package/dist/admin/{SettingTitle-BMHyfLrM.mjs → SettingTitle-DTXdYICP.mjs} +1 -1
  8. package/dist/admin/WarningBox-CMQuE_Ov.mjs +42 -0
  9. package/dist/admin/WarningBox-DsBtzhs3.js +41 -0
  10. package/dist/admin/{de-B5pRvs13.mjs → de-BFjenpyN.mjs} +16 -1
  11. package/dist/admin/{de-CqU1FU8C.js → de-DhwCZE_m.js} +16 -1
  12. package/dist/admin/{en-C7I90FwV.js → en-C-rPCNd2.js} +16 -1
  13. package/dist/admin/{en-BE-zzIv8.mjs → en-CGCh9ld_.mjs} +16 -1
  14. package/dist/admin/{index-CFf370lR.js → index-BYytQZfK.js} +169 -131
  15. package/dist/admin/{index-LNTPJt5H.js → index-BZBUZWp1.js} +13 -8
  16. package/dist/admin/{index-zr90q-6H.js → index-Bn_SWdWd.js} +178 -85
  17. package/dist/admin/{index-zskvsDgF.js → index-CaFjiS4j.js} +21 -13
  18. package/dist/admin/{index-G7qx6Oy7.mjs → index-Ckaev6xU.mjs} +170 -132
  19. package/dist/admin/{index-BE6CLx3P.mjs → index-Do9dOMP-.mjs} +180 -87
  20. package/dist/admin/{index-DpS40t3Q.mjs → index-DuwTQMlZ.mjs} +21 -13
  21. package/dist/admin/index-GZ_b2eve.js +480 -0
  22. package/dist/admin/index-aSdHc104.mjs +480 -0
  23. package/dist/admin/{index-IxsV1TAn.mjs → index-l4-tTCw9.mjs} +13 -8
  24. package/dist/admin/index.js +1 -1
  25. package/dist/admin/index.mjs +2 -2
  26. package/dist/server/index.js +483 -494
  27. package/dist/server/index.mjs +496 -507
  28. package/dist/server/src/index.d.ts +48 -5
  29. package/package.json +1 -1
  30. package/dist/admin/index-Df1hDvta.js +0 -243
  31. package/dist/admin/index-Z6ahaWtf.mjs +0 -243
@@ -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
- try {
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++;
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
- try {
67
- if (!data.route || !data.navigation) return null;
68
- const entity = await strapi.documents(waNavItem).create({
69
- data: {
70
- navigation: data.navigation,
71
- route: data.route || null,
72
- parent: data.parent || null,
73
- order: data.order || 0
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
- try {
83
- const updateData = {};
84
- if (data.parent !== void 0) updateData.parent = data.parent;
85
- if (data.order !== void 0 && typeof data.order === "number") updateData.order = data.order;
86
- return await strapi.documents(waNavItem).update({
87
- documentId,
88
- data: updateData
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
- try {
96
- await strapi.documents(waNavItem).delete({
97
- documentId
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
- try {
132
- return await strapi.documents(waRoute).create({
133
- data: {
134
- title: data.title,
135
- slug: data.path,
136
- path: data.path,
137
- relatedContentType: "",
138
- relatedId: 0,
139
- relatedDocumentId: "",
140
- uidPath: "",
141
- type: data.type || "external"
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
- try {
150
- const entity = await strapi.documents(waRoute).update({
151
- documentId,
152
- data: {
153
- ...data
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
- try {
163
- await strapi.documents(waRoute).delete({
164
- documentId
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
- try {
4334
- const parentRoute = await strapi.documents(waRoute).findOne({
4335
- documentId: parentDocumentId
4336
- });
4337
- const parentCanonicalPath = parentRoute?.canonicalPath || "";
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
- try {
4352
- const children = await strapi.db.query(waRoute).findMany({
4353
- where: {
4354
- parent: {
4355
- documentId: parentRouteDocumentId
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
- for (const child of children) {
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
- } catch (err) {
4393
- strapi.log.error(err);
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 Error(`Parent route not found: ${newParentId}`);
4403
+ throw new utils.errors.ApplicationError(`Parent route not found: ${newParentId}`);
4438
4404
  }
4439
4405
  if (parentRoute?.type === "external") {
4440
- throw new Error("External routes cannot have children");
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 Error(
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
- await updateNavItem(item.documentId, {
4617
- parent: calculatedParent,
4618
- order: calculatedOrder
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 migrations = [migration_001_canonical_path, migration_002_webatlas_json_field];
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
- default: existingConfig?.default || null
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 Error(`Failed to generate a unique path for slug: ${transformedSlug}`);
5135
- const singularName = context.contentType.info.singularName;
5136
- const title = context.params.data[ctSettings?.default]?.trim() || transformedSlug;
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,20 @@ 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 result2 = await next();
5189
- const title = context.params.data[ctSettings?.default]?.trim() || slug;
5266
+ const title = context.params.data[ctSettings?.routeSourceField]?.trim() || slug;
5190
5267
  const canonicalPath = isOverride ? relatedRoute.path : await buildCanonicalPath(transformToUrl(title), parent?.documentId);
5268
+ const routeBlacklist = await getRouteBlacklist();
5269
+ assertPathAllowed(rawPath, routeBlacklist);
5270
+ assertPathAllowed(canonicalPath, routeBlacklist);
5271
+ if (relatedRoute)
5272
+ await assertDescendantPathsAllowed({
5273
+ validatedParentPath: validatedPath,
5274
+ parentRouteDocumentId: relatedRoute.documentId,
5275
+ canonicalPath,
5276
+ isOverride: isOverride || false,
5277
+ routeBlacklist
5278
+ });
5279
+ const result2 = await next();
5191
5280
  const routeData = {
5192
5281
  title,
5193
5282
  path: validatedPath,
@@ -5225,21 +5314,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5225
5314
  }
5226
5315
  if (context.action === "delete") {
5227
5316
  const result2 = await next();
5228
- try {
5229
- const relatedDocumentId = context.params.documentId;
5230
- const deletedRoute = await strapi2.db.query(waRoute).delete({
5231
- where: { relatedDocumentId },
5232
- populate: ["navitem"]
5317
+ const relatedDocumentId = context.params.documentId;
5318
+ const deletedRoute = await strapi2.db.query(waRoute).delete({
5319
+ where: { relatedDocumentId },
5320
+ populate: ["navitem"]
5321
+ });
5322
+ const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
5323
+ const currentConfig = await pluginStore.get({ key: "config" });
5324
+ const selectedContentTypes = currentConfig.selectedContentTypes.map(
5325
+ (ct) => ct.defaultParentRoute === relatedDocumentId ? { ...ct, defaultParentRoute: null } : ct
5326
+ );
5327
+ if (selectedContentTypes.some((ct, i) => ct !== currentConfig.selectedContentTypes[i])) {
5328
+ await pluginStore.set({
5329
+ key: "config",
5330
+ value: { ...currentConfig, selectedContentTypes }
5233
5331
  });
5234
- if (!deletedRoute?.documentId) return result2;
5235
- const navItemDocumentIds = Array.from(
5236
- deletedRoute.navitem?.map((item) => item.documentId)
5237
- );
5238
- for (const navItemDocumentId of navItemDocumentIds) {
5239
- await strapi2.documents(waNavItem).delete({ documentId: navItemDocumentId });
5240
- }
5241
- } catch (err) {
5242
- strapi2.log.error(err);
5332
+ }
5333
+ if (!deletedRoute?.documentId) return result2;
5334
+ const navItemDocumentIds = Array.from(
5335
+ deletedRoute.navitem?.map((item) => item.documentId)
5336
+ );
5337
+ for (const navItemDocumentId of navItemDocumentIds) {
5338
+ await strapi2.documents(waNavItem).delete({ documentId: navItemDocumentId });
5243
5339
  }
5244
5340
  return result2;
5245
5341
  }
@@ -5252,24 +5348,16 @@ function webatlasMiddleware(strapi2) {
5252
5348
  if (context.uid !== waNavItem) return next();
5253
5349
  if (context.action === "delete") {
5254
5350
  let externalRouteDocumentId = null;
5255
- try {
5256
- const navItem = await strapi2.db?.query(waNavItem).findOne({
5257
- where: { documentId: context.params.documentId },
5258
- populate: ["route"]
5259
- });
5260
- if (navItem?.route?.type === "external") {
5261
- externalRouteDocumentId = navItem.route.documentId;
5262
- }
5263
- } catch (err) {
5264
- strapi2.log.error(err);
5351
+ const navItem = await strapi2.db?.query(waNavItem).findOne({
5352
+ where: { documentId: context.params.documentId },
5353
+ populate: ["route"]
5354
+ });
5355
+ if (navItem?.route?.type === "external") {
5356
+ externalRouteDocumentId = navItem.route.documentId;
5265
5357
  }
5266
5358
  const result = await next();
5267
5359
  if (externalRouteDocumentId) {
5268
- try {
5269
- await strapi2.documents(waRoute).delete({ documentId: externalRouteDocumentId });
5270
- } catch (err) {
5271
- strapi2.log.error(err);
5272
- }
5360
+ await strapi2.documents(waRoute).delete({ documentId: externalRouteDocumentId });
5273
5361
  }
5274
5362
  return result;
5275
5363
  }
@@ -5377,7 +5465,8 @@ const config = {
5377
5465
  selectedContentTypes: [],
5378
5466
  navigation: {
5379
5467
  maxDepth: 1
5380
- }
5468
+ },
5469
+ routeBlacklist: []
5381
5470
  },
5382
5471
  validator() {
5383
5472
  }
@@ -5591,139 +5680,84 @@ const contentTypes = {
5591
5680
  };
5592
5681
  const admin$2 = () => ({
5593
5682
  async updateConfig(ctx) {
5594
- try {
5595
- await getAdminService().updateConfig(ctx.request.body);
5596
- } catch (e) {
5597
- ctx.throw(500, e);
5598
- }
5683
+ await getAdminService().updateConfig(ctx.request.body);
5599
5684
  return ctx.send({ status: 200 });
5600
5685
  },
5601
5686
  async getConfig(ctx) {
5602
- try {
5603
- return await getAdminService().getConfig();
5604
- } catch (e) {
5605
- return ctx.throw(500, e);
5606
- }
5687
+ return await getAdminService().getConfig();
5607
5688
  },
5608
5689
  async getRoute(ctx) {
5609
- try {
5610
- const { documentId } = ctx.params;
5611
- if (!documentId) return ctx.throw(400, "Route documentId is required");
5612
- return await getAdminService().getRoute(documentId);
5613
- } catch (e) {
5614
- return ctx.throw(500, e);
5615
- }
5690
+ const { documentId } = ctx.params;
5691
+ if (!documentId) throw new utils.errors.ValidationError("Route documentId is required");
5692
+ return await getAdminService().getRoute(documentId);
5616
5693
  },
5617
5694
  async getAllRoutes(ctx) {
5618
- try {
5619
- return await getAdminService().getAllRoutes();
5620
- } catch (e) {
5621
- return ctx.throw(500, e);
5622
- }
5695
+ return await getAdminService().getAllRoutes();
5623
5696
  },
5624
5697
  async getRelatedRoute(ctx) {
5625
- try {
5626
- const { documentId } = ctx.query;
5627
- if (!documentId) return ctx.throw(400, "Route documentId is required");
5628
- return await getAdminService().getRelatedRoute(documentId);
5629
- } catch (e) {
5630
- return ctx.throw(500, e);
5631
- }
5698
+ const { documentId } = ctx.query;
5699
+ if (!documentId) throw new utils.errors.ValidationError("Route documentId is required");
5700
+ return await getAdminService().getRelatedRoute(documentId);
5632
5701
  },
5633
5702
  async getProhibitedRouteIds(ctx) {
5634
- try {
5635
- const { documentId } = ctx.params;
5636
- return await getAdminService().getProhibitedRouteIds(documentId);
5637
- } catch (e) {
5638
- return ctx.throw(500, e);
5639
- }
5703
+ const { documentId } = ctx.params;
5704
+ return await getAdminService().getProhibitedRouteIds(documentId);
5640
5705
  },
5641
5706
  async getNavigation(ctx) {
5642
- try {
5643
- const { documentId, variant } = ctx.query;
5644
- return await getAdminService().getNavigation(documentId, variant);
5645
- } catch (e) {
5646
- return ctx.throw(500, e);
5647
- }
5707
+ const { documentId, variant } = ctx.query;
5708
+ return await getAdminService().getNavigation(documentId, variant);
5648
5709
  },
5649
5710
  async createNavigation(ctx) {
5650
- try {
5651
- const { data } = ctx.request.body;
5652
- if (!data || !data.name) return ctx.throw(400, "Navigation name is required");
5653
- return await getAdminService().createNavigation(data.name, data.visible);
5654
- } catch (e) {
5655
- return ctx.throw(500, e);
5656
- }
5711
+ const { data } = ctx.request.body;
5712
+ if (!data || !data.name) throw new utils.errors.ValidationError("Navigation name is required");
5713
+ return await getAdminService().createNavigation(data.name, data.visible);
5657
5714
  },
5658
5715
  async updateNavigation(ctx) {
5659
- try {
5660
- const { documentId } = ctx.query;
5661
- if (!documentId) return ctx.throw(400, "Navigation documentId is required");
5662
- const { data } = ctx.request.body;
5663
- return await getAdminService().updateNavigation(documentId, data);
5664
- } catch (e) {
5665
- return ctx.throw(500, e);
5666
- }
5716
+ const { documentId } = ctx.query;
5717
+ if (!documentId) throw new utils.errors.ValidationError("Navigation documentId is required");
5718
+ const { data } = ctx.request.body;
5719
+ return await getAdminService().updateNavigation(documentId, data);
5667
5720
  },
5668
5721
  async updateNavigationItemStructure(ctx) {
5669
- try {
5670
- const { navigationId, navigationItems } = ctx.request.body;
5671
- if (!navigationId || !navigationItems)
5672
- return ctx.throw(400, "NavigationId and Navigation items are required");
5673
- return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
5674
- } catch (e) {
5675
- return ctx.throw(500, e);
5676
- }
5722
+ const { navigationId, navigationItems } = ctx.request.body;
5723
+ if (!navigationId || !navigationItems)
5724
+ throw new utils.errors.ValidationError("NavigationId and Navigation items are required");
5725
+ return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
5677
5726
  },
5678
5727
  async deleteNavigation(ctx) {
5679
- try {
5680
- const { documentId } = ctx.query;
5681
- if (!documentId) return ctx.throw(400, "Navigation documentId is required");
5682
- return await getAdminService().deleteNavigation(documentId);
5683
- } catch (e) {
5684
- return ctx.throw(500, e);
5685
- }
5728
+ const { documentId } = ctx.query;
5729
+ if (!documentId) throw new utils.errors.ValidationError("Navigation documentId is required");
5730
+ return await getAdminService().deleteNavigation(documentId);
5686
5731
  },
5687
5732
  async checkUniquePath(ctx) {
5688
- try {
5689
- const { path, targetRouteDocumentId } = ctx.query;
5690
- if (!path) return ctx.throw(400, "Path is required");
5691
- const res = await getAdminService().checkUniquePath(path, targetRouteDocumentId || null);
5692
- return ctx.send({ uniquePath: res });
5693
- } catch (e) {
5694
- return ctx.throw(500, e);
5695
- }
5733
+ const { path, targetRouteDocumentId } = ctx.query;
5734
+ if (!path) throw new utils.errors.ValidationError("Path is required");
5735
+ const res = await getAdminService().checkUniquePath(path, targetRouteDocumentId || null);
5736
+ return ctx.send(res);
5696
5737
  }
5697
5738
  });
5698
5739
  const client$2 = ({ strapi: strapi2 }) => ({
5699
5740
  async getEntityByPath(ctx) {
5700
- try {
5701
- const { slug, populate, populateDeepDepth, fields, status } = ctx.query;
5702
- if (!slug) return ctx.throw(400, "Slug is required");
5703
- const entity = await getClientService().getEntityByPath(
5704
- slug,
5705
- populate,
5706
- populateDeepDepth,
5707
- fields,
5708
- status
5709
- );
5710
- if (!entity) return ctx.throw(404, "Entity not found");
5711
- return ctx.send(entity);
5712
- } catch (e) {
5713
- ctx.throw(500, e);
5714
- }
5741
+ const { slug, populate, populateDeepDepth, fields, status, breadcrumb } = ctx.query;
5742
+ if (!slug) throw new utils.errors.ValidationError("Slug is required");
5743
+ const entity = await getClientService().getEntityByPath(
5744
+ slug,
5745
+ populate,
5746
+ populateDeepDepth,
5747
+ fields,
5748
+ status,
5749
+ breadcrumb !== "false"
5750
+ );
5751
+ if (!entity) throw new utils.errors.NotFoundError("Entity not found");
5752
+ return ctx.send(entity);
5715
5753
  },
5716
5754
  async getNavigation(ctx) {
5717
- try {
5718
- const { id, name, slug, documentId, variant } = ctx.query;
5719
- if (!id && !name && !slug && !documentId)
5720
- return ctx.throw(400, "Navigation id, name, slug or documentId is required");
5721
- const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
5722
- if (!navigation2) return ctx.throw(404, "Navigation not found");
5723
- return ctx.send(navigation2);
5724
- } catch (e) {
5725
- return ctx.throw(500, e);
5726
- }
5755
+ const { id, name, slug, documentId, variant } = ctx.query;
5756
+ if (!id && !name && !slug && !documentId)
5757
+ throw new utils.errors.ValidationError("Navigation id, name, slug or documentId is required");
5758
+ const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
5759
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
5760
+ return ctx.send(navigation2);
5727
5761
  }
5728
5762
  });
5729
5763
  const controllers = {
@@ -5988,19 +6022,15 @@ const routes = {
5988
6022
  const admin = ({ strapi: strapi2 }) => ({
5989
6023
  async updateConfig(newConfig) {
5990
6024
  if (!newConfig) return;
5991
- let newConfigMerged;
5992
- try {
5993
- const pluginStore = await strapi2.store({
5994
- type: "plugin",
5995
- name: PLUGIN_ID
5996
- });
5997
- const config2 = await pluginStore.get({ key: "config" });
5998
- newConfigMerged = { ...config2, ...newConfig };
5999
- await pluginStore.set({ key: "config", value: newConfigMerged });
6000
- } catch (err) {
6001
- strapi2.log.error(err);
6002
- return "Error. Couldn't update config";
6003
- }
6025
+ const pluginStore = await strapi2.store({
6026
+ type: "plugin",
6027
+ name: PLUGIN_ID
6028
+ });
6029
+ const config2 = await pluginStore.get({ key: "config" });
6030
+ const newConfigMerged = { ...config2, ...newConfig };
6031
+ if (newConfig.routeBlacklist !== void 0)
6032
+ newConfigMerged.routeBlacklist = normalizeRouteBlacklist(newConfig.routeBlacklist);
6033
+ await pluginStore.set({ key: "config", value: newConfigMerged });
6004
6034
  return newConfigMerged;
6005
6035
  },
6006
6036
  async getConfig() {
@@ -6020,140 +6050,107 @@ const admin = ({ strapi: strapi2 }) => ({
6020
6050
  return config2;
6021
6051
  },
6022
6052
  async getRoute(documentId) {
6023
- try {
6024
- return await strapi2.documents(waRoute).findOne({
6025
- documentId
6026
- });
6027
- } catch (e) {
6028
- strapi2.log.error(e);
6029
- }
6053
+ return await strapi2.documents(waRoute).findOne({
6054
+ documentId
6055
+ });
6030
6056
  },
6031
6057
  async getAllRoutes() {
6032
- try {
6033
- const entities = await strapi2.documents(waRoute).findMany();
6034
- return entities;
6035
- } catch (e) {
6036
- strapi2.log.error(e);
6037
- }
6058
+ return await strapi2.documents(waRoute).findMany();
6038
6059
  },
6039
6060
  async getRelatedRoute(documentId) {
6040
- try {
6041
- return await strapi2.db?.query(waRoute).findOne({
6042
- where: {
6043
- relatedDocumentId: documentId
6044
- },
6045
- populate: ["parent"]
6046
- });
6047
- } catch (e) {
6048
- strapi2.log.error(e);
6049
- }
6061
+ return await strapi2.db?.query(waRoute).findOne({
6062
+ where: {
6063
+ relatedDocumentId: documentId
6064
+ },
6065
+ populate: ["parent"]
6066
+ });
6050
6067
  },
6051
6068
  async getProhibitedRouteIds(documentId) {
6052
- try {
6053
- let route2 = null;
6054
- if (documentId) {
6055
- route2 = await strapi2.documents(waRoute).findOne({
6056
- documentId
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);
6069
+ let route2 = null;
6070
+ if (documentId) {
6071
+ route2 = await strapi2.documents(waRoute).findOne({
6072
+ documentId
6073
+ });
6066
6074
  }
6075
+ const descendants = route2?.documentId ? await getRouteDescendants(route2.documentId) : [];
6076
+ const nonInternalRouteIds = await getNonInternalRouteIds();
6077
+ const prohibitedRouteIds = [...descendants, ...nonInternalRouteIds];
6078
+ route2?.documentId && prohibitedRouteIds.push(route2.documentId);
6079
+ return prohibitedRouteIds;
6067
6080
  },
6068
6081
  async getNavigation(documentId, variant) {
6069
- try {
6070
- let navigation2 = null;
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
- }
6082
+ let navigation2 = null;
6083
+ if (variant === "namesOnly") {
6082
6084
  if (documentId) {
6083
- navigation2 = await strapi2.documents(waNavigation).findOne({
6085
+ return await strapi2.documents(waNavigation).findOne({
6084
6086
  documentId,
6085
- populate: ["items", "items.route", "items.parent"]
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"]
6087
+ select: ["documentId", "name", "slug", "visible"]
6092
6088
  });
6093
- if (!navigation2) throw new Error("Navigation not found");
6094
- if (variant) {
6095
- navigation2 = navigation2.map(
6096
- (nav) => buildStructuredNavigation(nav, variant)
6097
- );
6098
- }
6099
6089
  }
6100
- return navigation2;
6101
- } catch (e) {
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
- }
6090
+ return await strapi2.documents(waNavigation).findMany({
6091
+ select: ["documentId", "name", "slug", "visible"]
6113
6092
  });
6114
- } catch (e) {
6115
- strapi2.log.error(e);
6116
6093
  }
6117
- },
6118
- async updateNavigation(documentId, data) {
6119
- try {
6120
- const entity = await strapi2.documents(waNavigation).update({
6094
+ if (documentId) {
6095
+ navigation2 = await strapi2.documents(waNavigation).findOne({
6121
6096
  documentId,
6122
- data: {
6123
- name: data.name,
6124
- visible: data.visible
6125
- }
6097
+ populate: ["items", "items.route", "items.parent"]
6098
+ });
6099
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
6100
+ if (variant) navigation2 = buildStructuredNavigation(navigation2, variant);
6101
+ } else {
6102
+ navigation2 = await strapi2.documents(waNavigation).findMany({
6103
+ populate: ["items", "items.route", "items.parent"]
6126
6104
  });
6127
- return entity;
6128
- } catch (e) {
6129
- strapi2.log.error(e);
6105
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
6106
+ if (variant) {
6107
+ navigation2 = navigation2.map(
6108
+ (nav) => buildStructuredNavigation(nav, variant)
6109
+ );
6110
+ }
6130
6111
  }
6112
+ return navigation2;
6131
6113
  },
6132
- async deleteNavigation(documentId) {
6133
- try {
6134
- const navigation2 = await strapi2.documents(waNavigation).findOne({
6135
- documentId,
6136
- populate: ["items"]
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
- });
6114
+ async createNavigation(name, visible) {
6115
+ return await strapi2.documents(waNavigation).create({
6116
+ data: {
6117
+ name,
6118
+ slug: transformToUrl(name),
6119
+ visible
6143
6120
  }
6144
- return await strapi2.documents(waNavigation).delete({
6145
- documentId
6121
+ });
6122
+ },
6123
+ async updateNavigation(documentId, data) {
6124
+ return await strapi2.documents(waNavigation).update({
6125
+ documentId,
6126
+ data: {
6127
+ name: data.name,
6128
+ visible: data.visible
6129
+ }
6130
+ });
6131
+ },
6132
+ async deleteNavigation(documentId) {
6133
+ const navigation2 = await strapi2.documents(waNavigation).findOne({
6134
+ documentId,
6135
+ populate: ["items"]
6136
+ });
6137
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
6138
+ for (const item of navigation2.items) {
6139
+ await strapi2.documents(waNavItem).delete({
6140
+ documentId: item.documentId
6146
6141
  });
6147
- } catch (e) {
6148
- strapi2.log.error(e);
6149
6142
  }
6143
+ return await strapi2.documents(waNavigation).delete({
6144
+ documentId
6145
+ });
6150
6146
  },
6151
6147
  async updateNavigationItemStructure(navigationId, navigationItems) {
6152
6148
  if (!navigationId || !navigationItems) return;
6153
- let error = false;
6149
+ const errors2 = [];
6154
6150
  let newNavItemsMap = /* @__PURE__ */ new Map();
6155
6151
  const deletionResult = await handleItemDeletion(navigationItems);
6156
6152
  if (!deletionResult.success) {
6153
+ errors2.push(...deletionResult.errors);
6157
6154
  strapi2.log.error("Deletion errors:", deletionResult.errors);
6158
6155
  }
6159
6156
  navigationItems = deletionResult.items;
@@ -6180,126 +6177,118 @@ const admin = ({ strapi: strapi2 }) => ({
6180
6177
  newNavItemsMap
6181
6178
  });
6182
6179
  if (!result.success) {
6180
+ errors2.push(...result.errors);
6183
6181
  strapi2.log.error("Error updating item: ", item);
6184
6182
  }
6185
- } catch (errorMsg) {
6186
- error = true;
6187
- strapi2.log.error("Error updating navigation item ", errorMsg);
6183
+ } catch (err) {
6184
+ errors2.push(err instanceof Error ? err.message : String(err));
6185
+ strapi2.log.error("Error updating navigation item ", err);
6188
6186
  }
6189
6187
  }
6190
- return !error;
6188
+ return { success: errors2.length === 0, errors: errors2 };
6191
6189
  },
6192
6190
  async checkUniquePath(initialPath, targetRouteDocumentId = null) {
6193
- try {
6194
- return await duplicateCheck(initialPath, targetRouteDocumentId);
6195
- } catch (e) {
6196
- strapi2.log.error(e);
6197
- }
6191
+ const routeBlacklist = await getRouteBlacklist();
6192
+ if (isBlacklistedPath(initialPath, routeBlacklist)) return { blacklisted: true };
6193
+ return { uniquePath: await duplicateCheck(initialPath, targetRouteDocumentId) };
6198
6194
  }
6199
6195
  });
6200
6196
  const client = ({ strapi: strapi2 }) => ({
6201
- async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published") {
6202
- try {
6203
- const route2 = await strapi2.documents(waRoute).findFirst({
6204
- filters: {
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
- }
6197
+ async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true) {
6198
+ const route2 = await strapi2.documents(waRoute).findFirst({
6199
+ filters: {
6200
+ $or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
6219
6201
  }
6220
- const contentTypeObject = Object.entries(strapi2.contentTypes).find(
6221
- ([key, value]) => key === route2.relatedContentType
6202
+ });
6203
+ if (!route2) return null;
6204
+ let populateObject = populate;
6205
+ if (populate === "deep") {
6206
+ const modelObject = getFullPopulateObject(
6207
+ route2.relatedContentType,
6208
+ Number(populateDeepDepth),
6209
+ []
6222
6210
  );
6223
- if (!contentTypeObject) {
6224
- return null;
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;
6211
+ if (typeof modelObject === "object" && "populate" in modelObject) {
6212
+ populateObject = modelObject.populate;
6213
+ }
6245
6214
  }
6215
+ const contentTypeObject = Object.entries(strapi2.contentTypes).find(
6216
+ ([key, value]) => key === route2.relatedContentType
6217
+ );
6218
+ if (!contentTypeObject) {
6219
+ return null;
6220
+ }
6221
+ const [contentTypeKey, contentType] = contentTypeObject;
6222
+ const entity = await strapi2.documents(route2.relatedContentType).findOne({
6223
+ documentId: route2.relatedDocumentId,
6224
+ populate: populateObject,
6225
+ fields,
6226
+ status
6227
+ });
6228
+ if (!entity) return null;
6229
+ let cleanEntity = cleanRootKeys(entity);
6230
+ cleanEntity = removeWaFields(cleanEntity);
6231
+ cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
6232
+ if (breadcrumb) {
6233
+ cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2);
6234
+ }
6235
+ cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
6236
+ return {
6237
+ contentType: contentType.info.singularName,
6238
+ ...cleanEntity
6239
+ };
6246
6240
  },
6247
6241
  async getNavigation(id, name, slug, documentId, variant = "nested") {
6248
- try {
6249
- let navigation2 = null;
6250
- const populateObject = ["items", "items.parent", "items.route"];
6251
- const lookupMethods = [
6252
- {
6253
- condition: documentId,
6254
- lookup: () => strapi2.documents(waNavigation).findOne({
6255
- documentId,
6256
- populate: populateObject
6257
- }),
6258
- name: "documentId"
6259
- },
6260
- {
6261
- condition: slug,
6262
- lookup: () => strapi2.db?.query(waNavigation).findOne({
6263
- where: { slug },
6264
- populate: populateObject
6265
- }),
6266
- name: "slug"
6267
- },
6268
- {
6269
- condition: name,
6270
- lookup: () => strapi2.db?.query(waNavigation).findOne({
6271
- where: { name },
6272
- populate: populateObject
6273
- }),
6274
- name: "name"
6275
- },
6276
- {
6277
- condition: id,
6278
- lookup: () => strapi2.db?.query(waNavigation).findOne({
6279
- where: { id },
6280
- populate: populateObject
6281
- }),
6282
- name: "id"
6283
- }
6284
- ];
6285
- for (const method of lookupMethods) {
6286
- if (method.condition && !navigation2) {
6287
- try {
6288
- navigation2 = await method.lookup();
6289
- } catch (error) {
6290
- strapi2.log.error(`Navigation lookup by ${method.name} failed:`, error);
6291
- }
6242
+ let navigation2 = null;
6243
+ const populateObject = ["items", "items.parent", "items.route"];
6244
+ const lookupMethods = [
6245
+ {
6246
+ condition: documentId,
6247
+ lookup: () => strapi2.documents(waNavigation).findOne({
6248
+ documentId,
6249
+ populate: populateObject
6250
+ }),
6251
+ name: "documentId"
6252
+ },
6253
+ {
6254
+ condition: slug,
6255
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6256
+ where: { slug },
6257
+ populate: populateObject
6258
+ }),
6259
+ name: "slug"
6260
+ },
6261
+ {
6262
+ condition: name,
6263
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6264
+ where: { name },
6265
+ populate: populateObject
6266
+ }),
6267
+ name: "name"
6268
+ },
6269
+ {
6270
+ condition: id,
6271
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6272
+ where: { id },
6273
+ populate: populateObject
6274
+ }),
6275
+ name: "id"
6276
+ }
6277
+ ];
6278
+ for (const method of lookupMethods) {
6279
+ if (method.condition && !navigation2) {
6280
+ try {
6281
+ navigation2 = await method.lookup();
6282
+ } catch (error) {
6283
+ strapi2.log.error(`Navigation lookup by ${method.name} failed:`, error);
6292
6284
  }
6293
6285
  }
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
6286
  }
6287
+ if (!navigation2) return null;
6288
+ const structured = buildStructuredNavigation(navigation2, variant);
6289
+ if (!structured) return null;
6290
+ const entityNavigation = extractRouteAndItems(structured.items);
6291
+ return { ...structured, items: entityNavigation };
6303
6292
  }
6304
6293
  });
6305
6294
  const services = {