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