@mattisvensson/strapi-plugin-webatlas 0.12.1 → 0.13.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 (32) hide show
  1. package/README.md +59 -2
  2. package/dist/admin/{SettingTitle-Ib_0AvoZ.js → ContentBox-D4PGQ8eh.js} +1 -5
  3. package/dist/admin/{SettingTitle-0mKlA80i.mjs → ContentBox-KyQN2KGV.mjs} +2 -6
  4. package/dist/admin/{RoutePicker-IRZiHKFi.mjs → RoutePicker-CgndSXoF.mjs} +1 -1
  5. package/dist/admin/{RoutePicker-C3_tzz9U.js → RoutePicker-CwoMMhf_.js} +1 -1
  6. package/dist/admin/WarningBox-AyYq0Onj.mjs +18 -0
  7. package/dist/admin/{WarningBox-BZ3BZ5fR.js → WarningBox-FF1yYDXP.js} +0 -24
  8. package/dist/admin/{de-DhwCZE_m.js → de-Cl0vM1wA.js} +52 -4
  9. package/dist/admin/{de-BFjenpyN.mjs → de-DWs5ckOd.mjs} +52 -4
  10. package/dist/admin/{en-CGCh9ld_.mjs → en-CyhISGZi.mjs} +52 -4
  11. package/dist/admin/{en-C-rPCNd2.js → en-DSmtmPYk.js} +52 -4
  12. package/dist/admin/{index-ByxM39aL.mjs → index-BKhrfzjO.mjs} +105 -33
  13. package/dist/admin/{index-Bym1mXg1.mjs → index-Bv5Ri-ri.mjs} +44 -12
  14. package/dist/admin/{index-88JTX1Mj.js → index-BxGPKxr_.js} +50 -18
  15. package/dist/admin/index-Ctm4TBT5.mjs +5308 -0
  16. package/dist/admin/{index-PD3gcnXA.mjs → index-D2O7sLKs.mjs} +1 -1
  17. package/dist/admin/{index-CsKnBzp6.js → index-DTrsl_uN.js} +105 -33
  18. package/dist/admin/index-FvaXwOH0.mjs +174 -0
  19. package/dist/admin/index-JBUU7dE6.js +5308 -0
  20. package/dist/admin/{index-DNBXz42q.js → index-jOCO4_-k.js} +1 -1
  21. package/dist/admin/index-uOC1Clyv.js +174 -0
  22. package/dist/admin/index.js +1 -1
  23. package/dist/admin/index.mjs +1 -1
  24. package/dist/server/index.js +443 -96
  25. package/dist/server/index.mjs +444 -97
  26. package/dist/server/src/index.d.ts +17 -4
  27. package/package.json +3 -3
  28. package/dist/admin/WarningBox-CXEmXfVx.mjs +0 -42
  29. package/dist/admin/index-BPUJTNed.js +0 -9622
  30. package/dist/admin/index-BY6JLZrD.mjs +0 -9622
  31. package/dist/admin/index-CEJBltoJ.js +0 -147
  32. package/dist/admin/index-CNCyng5O.mjs +0 -147
@@ -38,6 +38,7 @@ const PLUGIN_ID = pluginPkg.strapi.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plug
38
38
  const waNavigation = `plugin::${PLUGIN_ID}.navigation`;
39
39
  const waNavItem = `plugin::${PLUGIN_ID}.navitem`;
40
40
  const waRoute = `plugin::${PLUGIN_ID}.route`;
41
+ const DEFAULT_NAVIGATION_MAX_DEPTH = 1;
41
42
  async function checkPathExists(path, excludeDocumentId) {
42
43
  const filters = {
43
44
  $or: [{ path }, { uidPath: path }, { canonicalPath: path }]
@@ -184,6 +185,7 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
184
185
  itemsById.set(item.documentId, newItem);
185
186
  itemsProcessed.add(item.documentId);
186
187
  });
188
+ if (remainingItems.length === itemsToProcess.length) break;
187
189
  itemsToProcess = remainingItems;
188
190
  }
189
191
  const sortedItems = sortItems(rootItems);
@@ -4439,6 +4441,14 @@ async function buildNavigationPath({
4439
4441
  const validatedPath = await duplicateCheck(newPath, routeDocumentId);
4440
4442
  return validatedPath;
4441
4443
  }
4444
+ async function buildItemPath({
4445
+ slug,
4446
+ routeDocumentId,
4447
+ calculatedParent
4448
+ }) {
4449
+ const path = await buildNavigationPath({ slug, routeDocumentId, calculatedParent });
4450
+ return { path, slug: path.split("/").pop() ?? slug };
4451
+ }
4442
4452
  async function handleItemDeletion(navigationItems) {
4443
4453
  const errors = [];
4444
4454
  let items = [...navigationItems];
@@ -4524,15 +4534,15 @@ async function handleItemUpdate({
4524
4534
  });
4525
4535
  if (!route2)
4526
4536
  throw new Error(`Related route not found for new navigation item '${item.route.title}'`);
4527
- const path = await buildNavigationPath({
4528
- slug: item.route.slug,
4537
+ const { path, slug } = await buildItemPath({
4538
+ slug: transformToUrl(item.route.slug),
4529
4539
  routeDocumentId: route2.documentId,
4530
4540
  calculatedParent
4531
4541
  });
4532
4542
  assertPathAllowed(path, await getRouteBlacklist());
4533
4543
  await updateRoute(route2.documentId, {
4534
4544
  title: item.route.title,
4535
- slug: item.route.slug,
4545
+ slug,
4536
4546
  path,
4537
4547
  isOverride: path !== route2.canonicalPath
4538
4548
  });
@@ -4560,12 +4570,13 @@ async function handleItemUpdate({
4560
4570
  });
4561
4571
  if (!route2)
4562
4572
  throw new Error(`Related route not found for navigation item '${item.route.title}'`);
4563
- const slug = item.clientModifications?.slug || item.route.slug;
4564
- const path = isInternal ? await buildNavigationPath({
4565
- slug,
4573
+ const changedSlug = item.clientModifications?.slug;
4574
+ const requestedSlug = changedSlug ? isInternal ? transformToUrl(changedSlug) : changedSlug : item.route.slug;
4575
+ const { path, slug } = isInternal ? await buildItemPath({
4576
+ slug: requestedSlug,
4566
4577
  routeDocumentId: route2.documentId,
4567
4578
  calculatedParent
4568
- }) : slug;
4579
+ }) : { path: requestedSlug, slug: requestedSlug };
4569
4580
  const isOverride = path !== route2.canonicalPath;
4570
4581
  if (needsRouteUpdate) {
4571
4582
  if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
@@ -4671,7 +4682,8 @@ async function enrichWebatlasData(data, contentTypeUid) {
4671
4682
  }
4672
4683
  return ids;
4673
4684
  };
4674
- const documentIds = collectDocumentIds(data, contentTypeUid);
4685
+ const items = Array.isArray(data) ? data : [data];
4686
+ const documentIds = items.flatMap((item) => collectDocumentIds(item, contentTypeUid));
4675
4687
  if (documentIds.length === 0) return data;
4676
4688
  const uniqueDocumentIds = [...new Set(documentIds)];
4677
4689
  const routes2 = await strapi.db?.query(waRoute).findMany({
@@ -4727,7 +4739,7 @@ async function enrichWebatlasData(data, contentTypeUid) {
4727
4739
  }
4728
4740
  return entity;
4729
4741
  };
4730
- return enrichEntity2(data, contentTypeUid);
4742
+ return Array.isArray(data) ? data.map((item) => enrichEntity2(item, contentTypeUid)) : enrichEntity2(data, contentTypeUid);
4731
4743
  }
4732
4744
  function isExternalUrl(value) {
4733
4745
  return !/^[a-z0-9]+$/.test(value);
@@ -4789,6 +4801,8 @@ function enrichEntity(entity, uid, routeMap) {
4789
4801
  `Wrapper route detected in route-picker field '${key}'. Wrapper routes cannot be used as page links. Setting to null.`
4790
4802
  );
4791
4803
  entity[key] = null;
4804
+ } else if (route2.isUnpublished) {
4805
+ entity[key] = null;
4792
4806
  } else {
4793
4807
  entity[key] = route2.canonicalPath || route2.path || value;
4794
4808
  }
@@ -4824,20 +4838,36 @@ function enrichEntity(entity, uid, routeMap) {
4824
4838
  }
4825
4839
  return entity;
4826
4840
  }
4827
- async function enrichRoutePickerFields(data, contentTypeUid) {
4841
+ async function enrichRoutePickerFields(data, contentTypeUid, status = "published") {
4828
4842
  if (!data || typeof data !== "object") return data;
4829
- const documentIds = collectRoutePickerIds(data, contentTypeUid);
4843
+ const items = Array.isArray(data) ? data : [data];
4844
+ const documentIds = items.flatMap((item) => collectRoutePickerIds(item, contentTypeUid));
4830
4845
  if (documentIds.length === 0) return data;
4831
4846
  const uniqueDocumentIds = [...new Set(documentIds)];
4832
4847
  const routes2 = await strapi.db?.query(waRoute).findMany({
4833
4848
  where: {
4834
4849
  documentId: { $in: uniqueDocumentIds }
4835
4850
  },
4836
- select: ["documentId", "path", "canonicalPath", "type"]
4851
+ select: [
4852
+ "documentId",
4853
+ "path",
4854
+ "canonicalPath",
4855
+ "type",
4856
+ "relatedContentType",
4857
+ "relatedDocumentId"
4858
+ ]
4837
4859
  });
4838
- const routeMap = new Map(routes2?.map((route2) => [route2.documentId, route2]) || []);
4839
- const enriched = enrichEntity(data, contentTypeUid, routeMap);
4840
- return enriched;
4860
+ const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(routes2 || []) : null;
4861
+ const routeMap = new Map(
4862
+ routes2?.map((route2) => [
4863
+ route2.documentId,
4864
+ {
4865
+ ...route2,
4866
+ isUnpublished: publishedDocumentIds && route2.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
4867
+ }
4868
+ ]) || []
4869
+ );
4870
+ return Array.isArray(data) ? data.map((item) => enrichEntity(item, contentTypeUid, routeMap)) : enrichEntity(data, contentTypeUid, routeMap);
4841
4871
  }
4842
4872
  function isBlacklistedPath(url, routeBlacklist) {
4843
4873
  if (!url) return false;
@@ -4903,18 +4933,99 @@ function toBreadcrumbEntry(route2) {
4903
4933
  title: route2.title
4904
4934
  };
4905
4935
  }
4906
- async function addWebatlasBreadcrumb(data, route2) {
4936
+ async function addWebatlasBreadcrumb(data, route2, status = "published") {
4907
4937
  if (!data?.webatlas || !route2) return data;
4908
4938
  const segments = route2.canonicalPath?.split("/").filter(Boolean) || [];
4909
4939
  const ancestorPaths = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join("/"));
4910
4940
  const ancestors = ancestorPaths.length ? await strapi.db.query(waRoute).findMany({
4911
4941
  where: { canonicalPath: { $in: ancestorPaths } },
4912
- select: ["path", "canonicalPath", "slug", "uidPath", "title"]
4942
+ select: [
4943
+ "path",
4944
+ "canonicalPath",
4945
+ "slug",
4946
+ "uidPath",
4947
+ "title",
4948
+ "relatedContentType",
4949
+ "relatedDocumentId"
4950
+ ]
4913
4951
  }) : [];
4914
- const orderedAncestors = ancestorPaths.map((path) => ancestors.find((ancestor) => ancestor.canonicalPath === path)).filter(Boolean);
4952
+ const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(ancestors) : null;
4953
+ const isVisible = (ancestor) => !publishedDocumentIds || !ancestor.relatedContentType || publishedDocumentIds.has(ancestor.relatedDocumentId);
4954
+ const orderedAncestors = ancestorPaths.map((path) => ancestors.find((ancestor) => ancestor.canonicalPath === path)).filter((ancestor) => ancestor && isVisible(ancestor));
4915
4955
  data.webatlas.breadcrumb = [...orderedAncestors, route2].map(toBreadcrumbEntry);
4916
4956
  return data;
4917
4957
  }
4958
+ async function removeUnpublishedNavItems(items) {
4959
+ const publishedDocumentIds = await getPublishedDocumentIds(items.map((item) => item.route));
4960
+ const removedItemIds = new Set(
4961
+ items.filter(
4962
+ ({ route: route2 }) => route2?.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
4963
+ ).map((item) => item.documentId)
4964
+ );
4965
+ let foundDescendant = removedItemIds.size > 0;
4966
+ while (foundDescendant) {
4967
+ foundDescendant = false;
4968
+ for (const item of items) {
4969
+ if (item.parent && removedItemIds.has(item.parent.documentId) && !removedItemIds.has(item.documentId)) {
4970
+ removedItemIds.add(item.documentId);
4971
+ foundDescendant = true;
4972
+ }
4973
+ }
4974
+ }
4975
+ return items.filter((item) => !removedItemIds.has(item.documentId));
4976
+ }
4977
+ async function getPublishedDocumentIds(routes2) {
4978
+ const documentIdsByUid = /* @__PURE__ */ new Map();
4979
+ for (const route2 of routes2) {
4980
+ if (!route2?.relatedContentType) continue;
4981
+ const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
4982
+ documentIds.push(route2.relatedDocumentId);
4983
+ documentIdsByUid.set(route2.relatedContentType, documentIds);
4984
+ }
4985
+ const publishedDocumentIds = /* @__PURE__ */ new Set();
4986
+ for (const [uid, documentIds] of documentIdsByUid) {
4987
+ if (!strapi.contentTypes[uid]) continue;
4988
+ const entries = await strapi.documents(uid).findMany({
4989
+ filters: { documentId: { $in: documentIds } },
4990
+ fields: ["documentId"],
4991
+ status: "published"
4992
+ });
4993
+ entries.forEach((entry) => publishedDocumentIds.add(entry.documentId));
4994
+ }
4995
+ return publishedDocumentIds;
4996
+ }
4997
+ async function getDocumentStatuses(routes2) {
4998
+ const documentIdsByUid = /* @__PURE__ */ new Map();
4999
+ for (const route2 of routes2) {
5000
+ if (!route2?.relatedContentType || !route2.relatedDocumentId) continue;
5001
+ const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
5002
+ documentIds.push(route2.relatedDocumentId);
5003
+ documentIdsByUid.set(route2.relatedContentType, documentIds);
5004
+ }
5005
+ const statuses = /* @__PURE__ */ new Map();
5006
+ for (const [uid, documentIds] of documentIdsByUid) {
5007
+ const contentType = strapi.contentTypes[uid];
5008
+ if (!contentType || !utils.contentTypes.hasDraftAndPublish(contentType)) continue;
5009
+ const query = {
5010
+ filters: { documentId: { $in: documentIds } },
5011
+ fields: ["documentId", "updatedAt"]
5012
+ };
5013
+ const [drafts, published] = await Promise.all([
5014
+ strapi.documents(uid).findMany({ ...query, status: "draft" }),
5015
+ strapi.documents(uid).findMany({ ...query, status: "published" })
5016
+ ]);
5017
+ const publishedUpdatedAt = new Map(
5018
+ published.map((entry) => [entry.documentId, new Date(entry.updatedAt).getTime()])
5019
+ );
5020
+ drafts.forEach((draft) => {
5021
+ const publishedAt = publishedUpdatedAt.get(draft.documentId);
5022
+ if (publishedAt === void 0) return statuses.set(draft.documentId, "draft");
5023
+ const isModified = new Date(draft.updatedAt).getTime() > publishedAt;
5024
+ statuses.set(draft.documentId, isModified ? "modified" : "published");
5025
+ });
5026
+ }
5027
+ return statuses;
5028
+ }
4918
5029
  const migration_001_canonical_path = {
4919
5030
  version: "001",
4920
5031
  description: "Migrate title field to canonicalPath using transformToUrl",
@@ -5065,10 +5176,25 @@ const migration_003_route_source_field = {
5065
5176
  );
5066
5177
  }
5067
5178
  };
5179
+ const migration_004_navigation_max_depth = {
5180
+ version: "004",
5181
+ description: "Move the global navigation max depth of the config to every navigation",
5182
+ async up(strapi2) {
5183
+ const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
5184
+ const config2 = await pluginStore.get({ key: "config" });
5185
+ const maxDepth = config2?.navigation?.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
5186
+ const { count } = await strapi2.db.query(waNavigation).updateMany({
5187
+ where: { maxDepth: { $null: true } },
5188
+ data: { maxDepth }
5189
+ });
5190
+ strapi2.log.info(`[webatlas] Set the max depth ${maxDepth} for ${count} navigation(s)`);
5191
+ }
5192
+ };
5068
5193
  const migrations = [
5069
5194
  migration_001_canonical_path,
5070
5195
  migration_002_webatlas_json_field,
5071
- migration_003_route_source_field
5196
+ migration_003_route_source_field,
5197
+ migration_004_navigation_max_depth
5072
5198
  ];
5073
5199
  const runMigrations = async (strapi2) => {
5074
5200
  const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
@@ -5106,9 +5232,37 @@ function registerPermissions(strapi2) {
5106
5232
  const actions = [
5107
5233
  {
5108
5234
  section: "plugins",
5109
- displayName: "Navigation page",
5110
- uid: "page.navigation",
5111
- subCategory: "Pages",
5235
+ displayName: "Read navigations",
5236
+ uid: "navigation.read",
5237
+ subCategory: "Navigation",
5238
+ pluginName: PLUGIN_ID
5239
+ },
5240
+ {
5241
+ section: "plugins",
5242
+ displayName: "Create navigations",
5243
+ uid: "navigation.create",
5244
+ subCategory: "Navigation",
5245
+ pluginName: PLUGIN_ID
5246
+ },
5247
+ {
5248
+ section: "plugins",
5249
+ displayName: "Edit navigations",
5250
+ uid: "navigation.update",
5251
+ subCategory: "Navigation",
5252
+ pluginName: PLUGIN_ID
5253
+ },
5254
+ {
5255
+ section: "plugins",
5256
+ displayName: "Delete navigations",
5257
+ uid: "navigation.delete",
5258
+ subCategory: "Navigation",
5259
+ pluginName: PLUGIN_ID
5260
+ },
5261
+ {
5262
+ section: "plugins",
5263
+ displayName: "Edit navigation items",
5264
+ uid: "navigation.edit-items",
5265
+ subCategory: "Navigation",
5112
5266
  pluginName: PLUGIN_ID
5113
5267
  },
5114
5268
  {
@@ -5120,15 +5274,29 @@ function registerPermissions(strapi2) {
5120
5274
  },
5121
5275
  {
5122
5276
  section: "plugins",
5123
- displayName: "General page",
5124
- uid: "settings.general",
5277
+ displayName: "Read general settings",
5278
+ uid: "settings.general.read",
5125
5279
  subCategory: "Settings",
5126
5280
  pluginName: PLUGIN_ID
5127
5281
  },
5128
5282
  {
5129
5283
  section: "plugins",
5130
- displayName: "Navigation page",
5131
- uid: "settings.navigation",
5284
+ displayName: "Update general settings",
5285
+ uid: "settings.general.update",
5286
+ subCategory: "Settings",
5287
+ pluginName: PLUGIN_ID
5288
+ },
5289
+ {
5290
+ section: "plugins",
5291
+ displayName: "Read navigation settings",
5292
+ uid: "settings.navigation.read",
5293
+ subCategory: "Settings",
5294
+ pluginName: PLUGIN_ID
5295
+ },
5296
+ {
5297
+ section: "plugins",
5298
+ displayName: "Update navigation settings",
5299
+ uid: "settings.navigation.update",
5132
5300
  subCategory: "Settings",
5133
5301
  pluginName: PLUGIN_ID
5134
5302
  },
@@ -5138,6 +5306,13 @@ function registerPermissions(strapi2) {
5138
5306
  uid: "cm.aside",
5139
5307
  subCategory: "Content Manager",
5140
5308
  pluginName: PLUGIN_ID
5309
+ },
5310
+ {
5311
+ section: "plugins",
5312
+ displayName: "Edit path (parent route and override)",
5313
+ uid: "cm.edit-path",
5314
+ subCategory: "Content Manager",
5315
+ pluginName: PLUGIN_ID
5141
5316
  }
5142
5317
  ];
5143
5318
  strapi2.admin.services.permission.actionProvider.registerMany(actions);
@@ -5147,13 +5322,10 @@ async function syncConfig(strapi2, enabledContentTypes) {
5147
5322
  const config2 = await pluginStore.get({
5148
5323
  key: "config"
5149
5324
  });
5325
+ const { navigation: _legacyNavigation, ...currentConfig } = config2 ?? {};
5150
5326
  let newConfig = {
5151
- ...config2,
5327
+ ...currentConfig,
5152
5328
  selectedContentTypes: [],
5153
- navigation: {
5154
- maxDepth: config2?.navigation?.maxDepth || 1,
5155
- ...config2?.navigation
5156
- },
5157
5329
  migrationVersion: config2?.migrationVersion || "0"
5158
5330
  };
5159
5331
  enabledContentTypes.forEach((type) => {
@@ -5170,6 +5342,21 @@ async function syncConfig(strapi2, enabledContentTypes) {
5170
5342
  }
5171
5343
  return newConfig;
5172
5344
  }
5345
+ async function getDefaultRouteData(strapi2, uid, data) {
5346
+ const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
5347
+ const currentConfig = await pluginStore.get({ key: "config" });
5348
+ const ctSettings = currentConfig?.selectedContentTypes.find((ct) => ct.uid === uid);
5349
+ const sourceValue = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
5350
+ if (typeof sourceValue !== "string" || !sourceValue.trim()) return void 0;
5351
+ const defaultParent = ctSettings.defaultParentRoute ? await strapi2.documents(waRoute).findFirst({
5352
+ filters: { relatedDocumentId: ctSettings.defaultParentRoute }
5353
+ }) : null;
5354
+ return {
5355
+ slug: transformToUrl(sourceValue),
5356
+ parentDocumentId: defaultParent?.documentId ?? null,
5357
+ isOverride: false
5358
+ };
5359
+ }
5173
5360
  function documentMiddleware(strapi2, enabledContentTypes, config2) {
5174
5361
  const actions = ["create", "update", "delete"];
5175
5362
  strapi2.documents.use(async (context, next) => {
@@ -5177,11 +5364,20 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5177
5364
  return next();
5178
5365
  }
5179
5366
  const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
5367
+ const requestContext = strapi2.requestContext.get();
5368
+ const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
5369
+ const userAbility = requestContext?.state?.userAbility;
5370
+ const canUseAside = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.aside`);
5371
+ const canEditPath = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.edit-path`);
5372
+ if ((context.action === "create" || context.action === "update") && (!isRouteDataAllowed || !canUseAside)) {
5373
+ delete context.params.data?.webatlas;
5374
+ }
5180
5375
  if (context.action === "create") {
5181
5376
  const data = context.params.data;
5182
- const { webatlas } = data;
5377
+ const webatlas = data.webatlas && canEditPath ? data.webatlas : await getDefaultRouteData(strapi2, context.uid, data);
5183
5378
  const { slug, parentDocumentId, isOverride } = webatlas || {};
5184
5379
  const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
5380
+ if (!transformedSlug) return next();
5185
5381
  let parent = null;
5186
5382
  let isValid = false;
5187
5383
  if (parentDocumentId) {
@@ -5210,7 +5406,6 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5210
5406
  assertPathAllowed(rawPath, routeBlacklist);
5211
5407
  assertPathAllowed(canonicalPath, routeBlacklist);
5212
5408
  const result2 = await next();
5213
- if (!transformedSlug) return result2;
5214
5409
  const existing = await strapi2.db?.query(waRoute).findOne({
5215
5410
  where: { relatedDocumentId: result2.documentId }
5216
5411
  });
@@ -5235,17 +5430,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5235
5430
  if (context.action === "update") {
5236
5431
  const data = context.params.data;
5237
5432
  const { documentId } = context.params;
5238
- const { webatlas } = data;
5433
+ const relatedRoute = await strapi2.documents(waRoute).findFirst({
5434
+ filters: {
5435
+ relatedDocumentId: documentId
5436
+ },
5437
+ populate: ["parent"]
5438
+ });
5439
+ let webatlas = data.webatlas;
5440
+ if (!relatedRoute && (!webatlas || !canEditPath)) {
5441
+ webatlas = await getDefaultRouteData(strapi2, context.uid, data);
5442
+ } else if (relatedRoute && webatlas && !canEditPath) {
5443
+ const sourceValue2 = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
5444
+ webatlas = !relatedRoute.isOverride && typeof sourceValue2 === "string" && sourceValue2.trim() ? {
5445
+ slug: transformToUrl(sourceValue2),
5446
+ parentDocumentId: relatedRoute.parent?.documentId ?? null,
5447
+ isOverride: false
5448
+ } : void 0;
5449
+ }
5239
5450
  const { slug, parentDocumentId, isOverride } = webatlas || {};
5240
5451
  if (!slug) {
5241
5452
  const result3 = await next();
5242
5453
  return result3;
5243
5454
  }
5244
- const relatedRoute = await strapi2.documents(waRoute).findFirst({
5245
- filters: {
5246
- relatedDocumentId: documentId
5247
- }
5248
- });
5249
5455
  let parent = null;
5250
5456
  let isValid = false;
5251
5457
  if (parentDocumentId) {
@@ -5383,15 +5589,7 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
5383
5589
  if (!contentTypeEntry) return;
5384
5590
  const [contentTypeUid] = contentTypeEntry;
5385
5591
  if (ctx.body.data) {
5386
- if (Array.isArray(ctx.body.data)) {
5387
- ctx.body.data = await Promise.all(
5388
- ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
5389
- );
5390
- } else {
5391
- ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
5392
- }
5393
- } else if (Array.isArray(ctx.body)) {
5394
- ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
5592
+ ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
5395
5593
  } else if (typeof ctx.body === "object") {
5396
5594
  ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
5397
5595
  }
@@ -5414,20 +5612,11 @@ const enrichRoutePicker = ({ strapi: strapi2 }) => {
5414
5612
  );
5415
5613
  if (!contentTypeEntry) return;
5416
5614
  const [contentTypeUid] = contentTypeEntry;
5615
+ const status = ctx.query?.status === "draft" ? "draft" : "published";
5417
5616
  if (ctx.body.data) {
5418
- if (Array.isArray(ctx.body.data)) {
5419
- ctx.body.data = await Promise.all(
5420
- ctx.body.data.map((item) => enrichRoutePickerFields(item, contentTypeUid))
5421
- );
5422
- } else {
5423
- ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid);
5424
- }
5425
- } else if (Array.isArray(ctx.body)) {
5426
- ctx.body = await Promise.all(
5427
- ctx.body.map((item) => enrichRoutePickerFields(item, contentTypeUid))
5428
- );
5617
+ ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid, status);
5429
5618
  } else if (typeof ctx.body === "object") {
5430
- ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid);
5619
+ ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid, status);
5431
5620
  }
5432
5621
  };
5433
5622
  };
@@ -5464,9 +5653,6 @@ const register = ({ strapi: strapi2 }) => {
5464
5653
  const config = {
5465
5654
  default: {
5466
5655
  selectedContentTypes: [],
5467
- navigation: {
5468
- maxDepth: 1
5469
- },
5470
5656
  routeBlacklist: []
5471
5657
  },
5472
5658
  validator() {
@@ -5611,6 +5797,13 @@ const schema$1 = {
5611
5797
  default: false,
5612
5798
  configurable: false
5613
5799
  },
5800
+ // Depth index of the deepest allowed level, 0 = root only. Only changed in the plugin settings
5801
+ maxDepth: {
5802
+ type: "integer",
5803
+ default: DEFAULT_NAVIGATION_MAX_DEPTH,
5804
+ min: 0,
5805
+ configurable: false
5806
+ },
5614
5807
  items: {
5615
5808
  type: "relation",
5616
5809
  configurable: false,
@@ -5700,6 +5893,21 @@ const admin$2 = () => ({
5700
5893
  if (!documentId) throw new utils.errors.ValidationError("Route documentId is required");
5701
5894
  return await getAdminService().getRelatedRoute(documentId);
5702
5895
  },
5896
+ async getRelatedRoutes(ctx) {
5897
+ const documentIds = String(ctx.query.documentIds || "").split(",").filter(Boolean);
5898
+ if (documentIds.length === 0) throw new utils.errors.ValidationError("documentIds are required");
5899
+ if (documentIds.length > 100)
5900
+ throw new utils.errors.ValidationError("At most 100 documentIds are allowed");
5901
+ return await getAdminService().getRelatedRoutes(documentIds);
5902
+ },
5903
+ async getNavigationDepths(ctx) {
5904
+ return await getAdminService().getNavigationDepths();
5905
+ },
5906
+ async updateNavigationDepths(ctx) {
5907
+ const { data } = ctx.request.body;
5908
+ if (!Array.isArray(data)) throw new utils.errors.ValidationError("Navigation depths are required");
5909
+ return await getAdminService().updateNavigationDepths(data);
5910
+ },
5703
5911
  async getProhibitedRouteIds(ctx) {
5704
5912
  const { documentId } = ctx.params;
5705
5913
  return await getAdminService().getProhibitedRouteIds(documentId);
@@ -5740,14 +5948,20 @@ const admin$2 = () => ({
5740
5948
  const client$2 = ({ strapi: strapi2 }) => ({
5741
5949
  async getEntityByPath(ctx) {
5742
5950
  const { slug, populate, populateDeepDepth, fields, status, breadcrumb } = ctx.query;
5743
- if (!slug) throw new utils.errors.ValidationError("Slug is required");
5951
+ if (typeof slug !== "string" || !slug) throw new utils.errors.ValidationError("Slug is required");
5952
+ if (status !== void 0 && status !== "draft" && status !== "published")
5953
+ throw new utils.errors.ValidationError('Status must be "draft" or "published"');
5954
+ const depth = populateDeepDepth === void 0 ? 5 : Number(populateDeepDepth);
5955
+ if (!Number.isInteger(depth) || depth < 1 || depth > 10)
5956
+ throw new utils.errors.ValidationError("populateDeepDepth must be a number between 1 and 10");
5744
5957
  const entity = await getClientService().getEntityByPath(
5745
5958
  slug,
5746
5959
  populate,
5747
- populateDeepDepth,
5960
+ depth,
5748
5961
  fields,
5749
5962
  status,
5750
- breadcrumb !== "false"
5963
+ breadcrumb !== "false",
5964
+ ctx.state.auth
5751
5965
  );
5752
5966
  if (!entity) throw new utils.errors.NotFoundError("Entity not found");
5753
5967
  return ctx.send(entity);
@@ -5756,6 +5970,14 @@ const client$2 = ({ strapi: strapi2 }) => ({
5756
5970
  const { id, name, slug, documentId, variant } = ctx.query;
5757
5971
  if (!id && !name && !slug && !documentId)
5758
5972
  throw new utils.errors.ValidationError("Navigation id, name, slug or documentId is required");
5973
+ for (const [key, value] of Object.entries({ id, name, slug, documentId })) {
5974
+ if (value !== void 0 && typeof value !== "string")
5975
+ throw new utils.errors.ValidationError(`Navigation ${key} must be a string`);
5976
+ }
5977
+ if (id !== void 0 && !/^\d+$/.test(id))
5978
+ throw new utils.errors.ValidationError("Navigation id must be a number");
5979
+ if (variant !== void 0 && variant !== "nested" && variant !== "flat")
5980
+ throw new utils.errors.ValidationError('Variant must be "nested" or "flat"');
5759
5981
  const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
5760
5982
  if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
5761
5983
  return ctx.send(navigation2);
@@ -5801,9 +6023,9 @@ const admin$1 = {
5801
6023
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5802
6024
  config: {
5803
6025
  actions: [
5804
- `plugin::${PLUGIN_ID}.settings.general`,
5805
- `plugin::${PLUGIN_ID}.settings.navigation`,
5806
- `plugin::${PLUGIN_ID}.page.navigation`,
6026
+ `plugin::${PLUGIN_ID}.settings.general.read`,
6027
+ `plugin::${PLUGIN_ID}.settings.navigation.read`,
6028
+ `plugin::${PLUGIN_ID}.navigation.read`,
5807
6029
  `plugin::${PLUGIN_ID}.cm.aside`
5808
6030
  ]
5809
6031
  }
@@ -5821,10 +6043,7 @@ const admin$1 = {
5821
6043
  {
5822
6044
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5823
6045
  config: {
5824
- actions: [
5825
- `plugin::${PLUGIN_ID}.settings.general`,
5826
- `plugin::${PLUGIN_ID}.settings.navigation`
5827
- ]
6046
+ actions: [`plugin::${PLUGIN_ID}.settings.general.update`]
5828
6047
  }
5829
6048
  }
5830
6049
  ]
@@ -5857,7 +6076,56 @@ const admin$1 = {
5857
6076
  {
5858
6077
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5859
6078
  config: {
5860
- actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.page.navigation`]
6079
+ actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
6080
+ }
6081
+ }
6082
+ ]
6083
+ }
6084
+ },
6085
+ // The max depth is a structural setting, so it is only changed in the plugin settings
6086
+ {
6087
+ method: "GET",
6088
+ path: "/settings/navigation-depths",
6089
+ handler: "admin.getNavigationDepths",
6090
+ config: {
6091
+ policies: [
6092
+ "admin::isAuthenticatedAdmin",
6093
+ {
6094
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6095
+ config: {
6096
+ actions: [`plugin::${PLUGIN_ID}.settings.navigation.read`]
6097
+ }
6098
+ }
6099
+ ]
6100
+ }
6101
+ },
6102
+ {
6103
+ method: "PUT",
6104
+ path: "/settings/navigation-depths",
6105
+ handler: "admin.updateNavigationDepths",
6106
+ config: {
6107
+ policies: [
6108
+ "admin::isAuthenticatedAdmin",
6109
+ {
6110
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6111
+ config: {
6112
+ actions: [`plugin::${PLUGIN_ID}.settings.navigation.update`]
6113
+ }
6114
+ }
6115
+ ]
6116
+ }
6117
+ },
6118
+ {
6119
+ method: "GET",
6120
+ path: "/route/related/batch",
6121
+ handler: "admin.getRelatedRoutes",
6122
+ config: {
6123
+ policies: [
6124
+ "admin::isAuthenticatedAdmin",
6125
+ {
6126
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6127
+ config: {
6128
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5861
6129
  }
5862
6130
  }
5863
6131
  ]
@@ -5889,7 +6157,7 @@ const admin$1 = {
5889
6157
  {
5890
6158
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5891
6159
  config: {
5892
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6160
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5893
6161
  }
5894
6162
  }
5895
6163
  ]
@@ -5906,7 +6174,7 @@ const admin$1 = {
5906
6174
  {
5907
6175
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5908
6176
  config: {
5909
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6177
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5910
6178
  }
5911
6179
  }
5912
6180
  ]
@@ -5922,7 +6190,7 @@ const admin$1 = {
5922
6190
  {
5923
6191
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5924
6192
  config: {
5925
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6193
+ actions: [`plugin::${PLUGIN_ID}.navigation.create`]
5926
6194
  }
5927
6195
  }
5928
6196
  ]
@@ -5938,7 +6206,7 @@ const admin$1 = {
5938
6206
  {
5939
6207
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5940
6208
  config: {
5941
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6209
+ actions: [`plugin::${PLUGIN_ID}.navigation.update`]
5942
6210
  }
5943
6211
  }
5944
6212
  ]
@@ -5954,7 +6222,7 @@ const admin$1 = {
5954
6222
  {
5955
6223
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5956
6224
  config: {
5957
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6225
+ actions: [`plugin::${PLUGIN_ID}.navigation.edit-items`]
5958
6226
  }
5959
6227
  }
5960
6228
  ]
@@ -5970,7 +6238,7 @@ const admin$1 = {
5970
6238
  {
5971
6239
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5972
6240
  config: {
5973
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6241
+ actions: [`plugin::${PLUGIN_ID}.navigation.delete`]
5974
6242
  }
5975
6243
  }
5976
6244
  ]
@@ -5987,7 +6255,7 @@ const admin$1 = {
5987
6255
  {
5988
6256
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5989
6257
  config: {
5990
- actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.page.navigation`]
6258
+ actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
5991
6259
  }
5992
6260
  }
5993
6261
  ]
@@ -6020,6 +6288,36 @@ const routes = {
6020
6288
  admin: admin$1,
6021
6289
  "content-api": client$1
6022
6290
  };
6291
+ async function getNavigationDepths() {
6292
+ const navigations = await strapi.documents(waNavigation).findMany({
6293
+ populate: ["items", "items.parent"]
6294
+ });
6295
+ return navigations.map((navigation2) => {
6296
+ const { items } = buildStructuredNavigation(navigation2, "flat");
6297
+ return {
6298
+ documentId: navigation2.documentId,
6299
+ name: navigation2.name,
6300
+ maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
6301
+ deepestDepth: Math.max(-1, ...(items ?? []).map((item) => item.depth ?? 0))
6302
+ };
6303
+ });
6304
+ }
6305
+ async function assertItemDepths(navigationId, navigationItems) {
6306
+ const navigation2 = await strapi.documents(waNavigation).findOne({
6307
+ documentId: navigationId,
6308
+ fields: ["maxDepth"]
6309
+ });
6310
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
6311
+ const maxDepth = navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
6312
+ const tooDeepItem = navigationItems.find(
6313
+ (item) => item.clientModifications?.type !== "delete" && (item.depth ?? 0) > maxDepth
6314
+ );
6315
+ if (tooDeepItem) {
6316
+ throw new utils.errors.ValidationError(
6317
+ `'${tooDeepItem.clientModifications?.title || tooDeepItem.route?.title}' is deeper than the ${maxDepth + 1} level(s) allowed in this navigation`
6318
+ );
6319
+ }
6320
+ }
6023
6321
  const admin = ({ strapi: strapi2 }) => ({
6024
6322
  async updateConfig(newConfig) {
6025
6323
  if (!newConfig) return;
@@ -6042,11 +6340,7 @@ const admin = ({ strapi: strapi2 }) => ({
6042
6340
  const defaultConfig = strapi2.config.get(`plugin::${PLUGIN_ID}`);
6043
6341
  config2 = {
6044
6342
  ...defaultConfig,
6045
- ...config2,
6046
- navigation: {
6047
- ...defaultConfig.navigation,
6048
- ...config2?.navigation
6049
- }
6343
+ ...config2
6050
6344
  };
6051
6345
  return config2;
6052
6346
  },
@@ -6066,6 +6360,13 @@ const admin = ({ strapi: strapi2 }) => ({
6066
6360
  populate: ["parent"]
6067
6361
  });
6068
6362
  },
6363
+ // Path of the routes linked to the given entries, with one query
6364
+ async getRelatedRoutes(documentIds) {
6365
+ return await strapi2.db?.query(waRoute).findMany({
6366
+ where: { relatedDocumentId: { $in: documentIds } },
6367
+ select: ["relatedDocumentId", "path"]
6368
+ });
6369
+ },
6069
6370
  async getProhibitedRouteIds(documentId) {
6070
6371
  let route2 = null;
6071
6372
  if (documentId) {
@@ -6110,6 +6411,16 @@ const admin = ({ strapi: strapi2 }) => ({
6110
6411
  );
6111
6412
  }
6112
6413
  }
6414
+ const navigations = Array.isArray(navigation2) ? navigation2 : [navigation2];
6415
+ const statuses = await getDocumentStatuses(
6416
+ navigations.flatMap((nav) => (nav.items ?? []).map((item) => item.route))
6417
+ );
6418
+ navigations.forEach(
6419
+ (nav) => nav.items?.forEach((item) => {
6420
+ const status = statuses.get(item.route?.relatedDocumentId);
6421
+ if (status) item.status = status;
6422
+ })
6423
+ );
6113
6424
  return navigation2;
6114
6425
  },
6115
6426
  async createNavigation(name, visible) {
@@ -6130,6 +6441,28 @@ const admin = ({ strapi: strapi2 }) => ({
6130
6441
  }
6131
6442
  });
6132
6443
  },
6444
+ async getNavigationDepths() {
6445
+ return await getNavigationDepths();
6446
+ },
6447
+ async updateNavigationDepths(depths) {
6448
+ const currentDepths = await getNavigationDepths();
6449
+ for (const { documentId, maxDepth } of depths) {
6450
+ const current = currentDepths.find((navigation2) => navigation2.documentId === documentId);
6451
+ if (!current) throw new utils.errors.NotFoundError("Navigation not found");
6452
+ if (!Number.isInteger(maxDepth) || maxDepth < 0) {
6453
+ throw new utils.errors.ValidationError(`Invalid max depth for the navigation '${current.name}'`);
6454
+ }
6455
+ if (maxDepth < current.deepestDepth) {
6456
+ throw new utils.errors.ValidationError(
6457
+ `The navigation '${current.name}' already has items on level ${current.deepestDepth + 1}`
6458
+ );
6459
+ }
6460
+ }
6461
+ for (const { documentId, maxDepth } of depths) {
6462
+ await strapi2.documents(waNavigation).update({ documentId, data: { maxDepth } });
6463
+ }
6464
+ return await getNavigationDepths();
6465
+ },
6133
6466
  async deleteNavigation(documentId) {
6134
6467
  const navigation2 = await strapi2.documents(waNavigation).findOne({
6135
6468
  documentId,
@@ -6147,6 +6480,7 @@ const admin = ({ strapi: strapi2 }) => ({
6147
6480
  },
6148
6481
  async updateNavigationItemStructure(navigationId, navigationItems) {
6149
6482
  if (!navigationId || !navigationItems) return;
6483
+ await assertItemDepths(navigationId, navigationItems);
6150
6484
  const errors2 = [];
6151
6485
  let newNavItemsMap = /* @__PURE__ */ new Map();
6152
6486
  const deletionResult = await handleItemDeletion(navigationItems);
@@ -6195,7 +6529,7 @@ const admin = ({ strapi: strapi2 }) => ({
6195
6529
  }
6196
6530
  });
6197
6531
  const client = ({ strapi: strapi2 }) => ({
6198
- async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true) {
6532
+ async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true, auth) {
6199
6533
  const route2 = await strapi2.documents(waRoute).findFirst({
6200
6534
  filters: {
6201
6535
  $or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
@@ -6206,12 +6540,10 @@ const client = ({ strapi: strapi2 }) => ({
6206
6540
  if (populate === "deep") {
6207
6541
  const modelObject = getFullPopulateObject(
6208
6542
  route2.relatedContentType,
6209
- Number(populateDeepDepth),
6543
+ populateDeepDepth,
6210
6544
  []
6211
6545
  );
6212
- if (typeof modelObject === "object" && "populate" in modelObject) {
6213
- populateObject = modelObject.populate;
6214
- }
6546
+ populateObject = typeof modelObject === "object" && "populate" in modelObject ? modelObject.populate : void 0;
6215
6547
  }
6216
6548
  const contentTypeObject = Object.entries(strapi2.contentTypes).find(
6217
6549
  ([key, value]) => key === route2.relatedContentType
@@ -6220,20 +6552,34 @@ const client = ({ strapi: strapi2 }) => ({
6220
6552
  return null;
6221
6553
  }
6222
6554
  const [contentTypeKey, contentType] = contentTypeObject;
6555
+ const action = contentType.kind === "singleType" ? "find" : "findOne";
6556
+ try {
6557
+ await strapi2.auth.verify(auth, { scope: [`${contentTypeKey}.${action}`] });
6558
+ } catch {
6559
+ return null;
6560
+ }
6561
+ await strapi2.contentAPI.validate.query(
6562
+ { populate: populate === "deep" ? void 0 : populate, fields },
6563
+ contentType,
6564
+ { auth }
6565
+ );
6566
+ const sanitizedQuery = await strapi2.contentAPI.sanitize.query({ fields }, contentType, { auth });
6567
+ const sanitizedPopulate = populateObject ? await strapi2.contentAPI.sanitize.populate(populateObject, contentType, { auth }) : void 0;
6223
6568
  const entity = await strapi2.documents(route2.relatedContentType).findOne({
6224
6569
  documentId: route2.relatedDocumentId,
6225
- populate: populateObject,
6226
- fields,
6570
+ populate: sanitizedPopulate,
6571
+ fields: sanitizedQuery.fields,
6227
6572
  status
6228
6573
  });
6229
6574
  if (!entity) return null;
6230
- let cleanEntity = cleanRootKeys(entity);
6575
+ const sanitizedEntity = await strapi2.contentAPI.sanitize.output(entity, contentType, { auth });
6576
+ let cleanEntity = cleanRootKeys(sanitizedEntity);
6231
6577
  cleanEntity = removeWaFields(cleanEntity);
6232
6578
  cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
6233
6579
  if (breadcrumb) {
6234
- cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2);
6580
+ cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2, status);
6235
6581
  }
6236
- cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
6582
+ cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey, status);
6237
6583
  return {
6238
6584
  contentType: contentType.info.singularName,
6239
6585
  ...cleanEntity
@@ -6286,6 +6632,7 @@ const client = ({ strapi: strapi2 }) => ({
6286
6632
  }
6287
6633
  }
6288
6634
  if (!navigation2) return null;
6635
+ if (navigation2.items) navigation2.items = await removeUnpublishedNavItems(navigation2.items);
6289
6636
  const structured = buildStructuredNavigation(navigation2, variant);
6290
6637
  if (!structured) return null;
6291
6638
  const entityNavigation = extractRouteAndItems(structured.items);