@mattisvensson/strapi-plugin-webatlas 0.12.2 → 0.14.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.
- package/README.md +46 -1
- package/dist/admin/{SettingTitle-DXGCUfum.js → ContentBox-CHwpYMiB.js} +1 -5
- package/dist/admin/{SettingTitle-C1_2epDJ.mjs → ContentBox-CYnyB_5a.mjs} +2 -6
- package/dist/admin/{RoutePicker-C6LpgVMi.mjs → RoutePicker-43YnYCpH.mjs} +1 -1
- package/dist/admin/{RoutePicker-DvzQH2CX.js → RoutePicker-D9zf-VdN.js} +1 -1
- package/dist/admin/WarningBox-AyYq0Onj.mjs +18 -0
- package/dist/admin/{WarningBox-BHlYlKQ8.js → WarningBox-FF1yYDXP.js} +0 -24
- package/dist/admin/{de-BWUGdpM0.js → de-DolV3m7M.js} +115 -5
- package/dist/admin/{de-Dnk_hvMW.mjs → de-Dt3jjL3h.mjs} +115 -5
- package/dist/admin/{en-D5EqZSGy.mjs → en-CCRmKJEV.mjs} +114 -4
- package/dist/admin/{en-DOk8P6X5.js → en-jWdO5RMZ.js} +114 -4
- package/dist/admin/index-7iO5UsYI.js +174 -0
- package/dist/admin/{index-DuSnxRbO.mjs → index-B2k8Pikg.mjs} +44 -12
- package/dist/admin/index-CK4JyItR.mjs +5363 -0
- package/dist/admin/{index-CVrufPeL.mjs → index-CMuhLgfi.mjs} +74 -30
- package/dist/admin/{index-D7zg69uM.js → index-Ciem6YTr.js} +50 -18
- package/dist/admin/index-DGYmrx3f.mjs +174 -0
- package/dist/admin/index-Ddnt9W-v.mjs +1025 -0
- package/dist/admin/index-DfG_hSMk.js +5363 -0
- package/dist/admin/{index-DHNPW0YT.js → index-DmOWQK6g.js} +70 -26
- package/dist/admin/index-dB79zyxi.js +1025 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/CMEditViewAside/NewPathInfo.d.ts +5 -0
- package/dist/admin/src/components/CMEditViewAside/OverrideCheckbox.d.ts +7 -0
- package/dist/admin/src/components/CMEditViewAside/Panel.d.ts +5 -0
- package/dist/admin/src/components/CMEditViewAside/PathInput.d.ts +12 -0
- package/dist/admin/src/components/CMEditViewAside/RouteStructure.d.ts +3 -0
- package/dist/admin/src/components/CMEditViewAside/UidPathDisplay.d.ts +4 -0
- package/dist/admin/src/components/CMEditViewAside/index.d.ts +3 -0
- package/dist/admin/src/components/Initializer.d.ts +5 -0
- package/dist/admin/src/components/PathInfo.d.ts +8 -0
- package/dist/admin/src/components/PluginIcon.d.ts +3 -0
- package/dist/admin/src/components/Tooltip.d.ts +3 -0
- package/dist/admin/src/components/UI/Center.d.ts +4 -0
- package/dist/admin/src/components/UI/EmptyBox.d.ts +5 -0
- package/dist/admin/src/components/UI/FullLoader.d.ts +3 -0
- package/dist/admin/src/components/UI/WarningBox.d.ts +4 -0
- package/dist/admin/src/components/UI/index.d.ts +5 -0
- package/dist/admin/src/components/customFields/RoutePicker.d.ts +25 -0
- package/dist/admin/src/components/modals/Delete.d.ts +7 -0
- package/dist/admin/src/components/modals/DiscardChanges.d.ts +3 -0
- package/dist/admin/src/components/modals/NavCreate.d.ts +1 -0
- package/dist/admin/src/components/modals/NavEdit.d.ts +7 -0
- package/dist/admin/src/components/modals/NavModal.d.ts +16 -0
- package/dist/admin/src/components/modals/NavOverview.d.ts +10 -0
- package/dist/admin/src/components/modals/SaveConfirm.d.ts +8 -0
- package/dist/admin/src/components/modals/externalItem/index.d.ts +15 -0
- package/dist/admin/src/components/modals/index.d.ts +14 -0
- package/dist/admin/src/components/modals/internalItem/EntrySelection.d.ts +17 -0
- package/dist/admin/src/components/modals/internalItem/ItemDetails.d.ts +13 -0
- package/dist/admin/src/components/modals/internalItem/MultiItemReview.d.ts +23 -0
- package/dist/admin/src/components/modals/internalItem/internalItemCreate.d.ts +2 -0
- package/dist/admin/src/components/modals/internalItem/internalItemEdit.d.ts +2 -0
- package/dist/admin/src/components/modals/useModalSharedLogic.d.ts +2 -0
- package/dist/admin/src/components/modals/withModalSharedLogic.d.ts +3 -0
- package/dist/admin/src/components/modals/wrapperItem/index.d.ts +15 -0
- package/dist/admin/src/contexts/index.d.ts +17 -0
- package/dist/admin/src/hooks/index.d.ts +7 -0
- package/dist/admin/src/hooks/useAllContentTypes.d.ts +7 -0
- package/dist/admin/src/hooks/useAllEntities.d.ts +7 -0
- package/dist/admin/src/hooks/useApi.d.ts +23 -0
- package/dist/admin/src/hooks/useEntrySearch.d.ts +13 -0
- package/dist/admin/src/hooks/useErrorMessage.d.ts +8 -0
- package/dist/admin/src/hooks/usePluginConfig.d.ts +9 -0
- package/dist/admin/src/pages/Navigation/Page.d.ts +2 -0
- package/dist/admin/src/pages/Navigation/PageWrapper.d.ts +8 -0
- package/dist/admin/src/pages/Navigation/RouteItem.d.ts +2 -0
- package/dist/admin/src/pages/Navigation/RouteItemBadge.d.ts +4 -0
- package/dist/admin/src/pages/Navigation/RouteItemIcon.d.ts +5 -0
- package/dist/admin/src/pages/Navigation/RouteItemMenu.d.ts +12 -0
- package/dist/admin/src/pages/Navigation/RouteItemStatus.d.ts +5 -0
- package/dist/admin/src/pages/Navigation/SortableRouteItem.d.ts +2 -0
- package/dist/admin/src/pages/Navigation/UnsavedChangesBlocker.d.ts +8 -0
- package/dist/admin/src/pages/Navigation/index.d.ts +2 -0
- package/dist/admin/src/pages/Navigation/useCollapsedItems.d.ts +13 -0
- package/dist/admin/src/pages/Paths/HealthSummary.d.ts +8 -0
- package/dist/admin/src/pages/Paths/IssueBadges.d.ts +4 -0
- package/dist/admin/src/pages/Paths/PageWrapper.d.ts +5 -0
- package/dist/admin/src/pages/Paths/PathActionsMenu.d.ts +7 -0
- package/dist/admin/src/pages/Paths/PathFilters.d.ts +14 -0
- package/dist/admin/src/pages/Paths/PathTable.d.ts +18 -0
- package/dist/admin/src/pages/Paths/SearchInput.d.ts +5 -0
- package/dist/admin/src/pages/Paths/TableHeader.d.ts +6 -0
- package/dist/admin/src/pages/Paths/TableRow.d.ts +9 -0
- package/dist/admin/src/pages/Paths/compareBy.d.ts +3 -0
- package/dist/admin/src/pages/Paths/hasPathDeviation.d.ts +2 -0
- package/dist/admin/src/pages/Paths/healthMessages.d.ts +11 -0
- package/dist/admin/src/pages/Paths/index.d.ts +2 -0
- package/dist/admin/src/pages/Settings/ContentBox.d.ts +4 -0
- package/dist/admin/src/pages/Settings/General/ContentTypeAccordion.d.ts +9 -0
- package/dist/admin/src/pages/Settings/General/index.d.ts +2 -0
- package/dist/admin/src/pages/Settings/Navigation/index.d.ts +2 -0
- package/dist/admin/src/pages/Settings/PageWrapper.d.ts +7 -0
- package/dist/admin/src/pages/Settings/SettingTitle.d.ts +3 -0
- package/dist/admin/src/pages/Settings/index.d.ts +4 -0
- package/dist/admin/src/permissions.d.ts +51 -0
- package/dist/admin/src/types/index.d.ts +4 -0
- package/dist/admin/src/types/modal.d.ts +60 -0
- package/dist/admin/src/types/navigation.d.ts +24 -0
- package/dist/admin/src/types/panel.d.ts +50 -0
- package/dist/admin/src/types/route.d.ts +3 -0
- package/dist/admin/src/utils/buildBreadcrumbString.d.ts +16 -0
- package/dist/admin/src/utils/createTempNavItemObject.d.ts +22 -0
- package/dist/admin/src/utils/debounce.d.ts +1 -0
- package/dist/admin/src/utils/dnd.d.ts +13 -0
- package/dist/admin/src/utils/duplicateCheck.d.ts +19 -0
- package/dist/admin/src/utils/findParentNavItem.d.ts +13 -0
- package/dist/admin/src/utils/getRouteSourceFields.d.ts +2 -0
- package/dist/admin/src/utils/getTranslation.d.ts +2 -0
- package/dist/admin/src/utils/index.d.ts +11 -0
- package/dist/admin/src/utils/isAbortError.d.ts +5 -0
- package/dist/admin/src/utils/navTree.d.ts +39 -0
- package/dist/admin/src/utils/syncNavItemPaths.d.ts +12 -0
- package/dist/admin/src/utils/typeChecks.d.ts +3 -0
- package/dist/server/index.js +584 -53
- package/dist/server/index.mjs +585 -54
- package/dist/server/src/bootstrap/documentMiddleware.d.ts +18 -0
- package/dist/server/src/bootstrap/index.d.ts +5 -0
- package/dist/server/src/bootstrap/permissions.d.ts +2 -0
- package/dist/server/src/bootstrap/syncConfig.d.ts +3 -0
- package/dist/server/src/bootstrap/webatlasMiddleware.d.ts +2 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/config/index.d.ts +8 -0
- package/dist/server/src/content-types/index.d.ts +208 -0
- package/dist/server/src/content-types/navigation/index.d.ts +56 -0
- package/dist/server/src/content-types/navigation/schema.d.ts +54 -0
- package/dist/server/src/content-types/navitem/index.d.ts +51 -0
- package/dist/server/src/content-types/navitem/schema.d.ts +49 -0
- package/dist/server/src/content-types/route/index.d.ts +101 -0
- package/dist/server/src/content-types/route/schema.d.ts +99 -0
- package/dist/server/src/controllers/admin.d.ts +19 -0
- package/dist/server/src/controllers/client.d.ts +8 -0
- package/dist/server/src/controllers/index.d.ts +27 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/index.d.ts +31 -8
- package/dist/server/src/middlewares/addWebatlasField.d.ts +10 -0
- package/dist/server/src/middlewares/enrichRoutePicker.d.ts +10 -0
- package/dist/server/src/middlewares/index.d.ts +9 -0
- package/dist/server/src/migrations/001-canonical-path.d.ts +7 -0
- package/dist/server/src/migrations/002-webatlas-json-field.d.ts +7 -0
- package/dist/server/src/migrations/003-route-source-field.d.ts +7 -0
- package/dist/server/src/migrations/004-navigation-max-depth.d.ts +7 -0
- package/dist/server/src/migrations/index.d.ts +3 -0
- package/dist/server/src/policies/has-permissions.d.ts +2 -0
- package/dist/server/src/policies/index.d.ts +4 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/routes/admin.d.ts +17 -0
- package/dist/server/src/routes/client.d.ts +12 -0
- package/dist/server/src/routes/index.d.ts +30 -0
- package/dist/server/src/services/admin.d.ts +33 -0
- package/dist/server/src/services/client.d.ts +48 -0
- package/dist/server/src/services/health.d.ts +5 -0
- package/dist/server/src/services/index.d.ts +83 -0
- package/dist/server/src/utils/addWebatlasBreadcrumb.d.ts +14 -0
- package/dist/server/src/utils/assertDescendantPathsAllowed.d.ts +19 -0
- package/dist/server/src/utils/assertPathAllowed.d.ts +2 -0
- package/dist/server/src/utils/buildCanonicalPath.d.ts +1 -0
- package/dist/server/src/utils/buildNavigationPath.d.ts +5 -0
- package/dist/server/src/utils/buildStructuredNavigation.d.ts +12 -0
- package/dist/server/src/utils/cascadePathUpdates.d.ts +6 -0
- package/dist/server/src/utils/cleanRootKeys.d.ts +1 -0
- package/dist/server/src/utils/duplicateCheck.d.ts +1 -0
- package/dist/server/src/utils/enrichRoutePickerFields.d.ts +7 -0
- package/dist/server/src/utils/enrichWebatlasData.d.ts +6 -0
- package/dist/server/src/utils/extractRouteAndItems.d.ts +32 -0
- package/dist/server/src/utils/getDocumentStatuses.d.ts +12 -0
- package/dist/server/src/utils/getNonInternalRouteIds.d.ts +1 -0
- package/dist/server/src/utils/getPublishedDocumentIds.d.ts +11 -0
- package/dist/server/src/utils/getRouteAncestors.d.ts +1 -0
- package/dist/server/src/utils/getRouteDescendants.d.ts +1 -0
- package/dist/server/src/utils/health/checks.d.ts +48 -0
- package/dist/server/src/utils/index.d.ts +29 -0
- package/dist/server/src/utils/isBlacklistedPath.d.ts +1 -0
- package/dist/server/src/utils/navItemHandler.d.ts +5 -0
- package/dist/server/src/utils/navigationItemStructure.d.ts +27 -0
- package/dist/server/src/utils/normalizeRouteBlacklist.d.ts +5 -0
- package/dist/server/src/utils/pluginHelpers.d.ts +4 -0
- package/dist/server/src/utils/populateDeep.d.ts +4 -0
- package/dist/server/src/utils/reduceDepthOfOrphanedItems.d.ts +2 -0
- package/dist/server/src/utils/removeUnpublishedNavItems.d.ts +7 -0
- package/dist/server/src/utils/removeWaFields.d.ts +1 -0
- package/dist/server/src/utils/routeHandler.d.ts +5 -0
- package/dist/server/src/utils/validateRouteDependencies.d.ts +4 -0
- package/package.json +5 -5
- package/dist/admin/WarningBox-CfIVF0O-.mjs +0 -42
- package/dist/admin/index-DC-2-FsX.mjs +0 -9622
- package/dist/admin/index-Dp_eCRFS.js +0 -249
- package/dist/admin/index-Dx4gvFWK.mjs +0 -147
- package/dist/admin/index-FuvoHpAT.js +0 -147
- package/dist/admin/index-RmZ3LQPu.js +0 -9622
- package/dist/admin/index-Y4uwBSjP.mjs +0 -249
package/dist/server/index.js
CHANGED
|
@@ -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 }]
|
|
@@ -92,6 +93,9 @@ function getAdminService() {
|
|
|
92
93
|
function getClientService() {
|
|
93
94
|
return strapi.plugin(PLUGIN_ID)?.service("client");
|
|
94
95
|
}
|
|
96
|
+
function getHealthService() {
|
|
97
|
+
return strapi.plugin(PLUGIN_ID)?.service("health");
|
|
98
|
+
}
|
|
95
99
|
function reduceDepthOfOrphanedItems(navigationItems, itemId) {
|
|
96
100
|
const navigationItemsCopy = JSON.parse(JSON.stringify(navigationItems));
|
|
97
101
|
const startItemIndex = navigationItemsCopy.findIndex(
|
|
@@ -4440,6 +4444,14 @@ async function buildNavigationPath({
|
|
|
4440
4444
|
const validatedPath = await duplicateCheck(newPath, routeDocumentId);
|
|
4441
4445
|
return validatedPath;
|
|
4442
4446
|
}
|
|
4447
|
+
async function buildItemPath({
|
|
4448
|
+
slug,
|
|
4449
|
+
routeDocumentId,
|
|
4450
|
+
calculatedParent
|
|
4451
|
+
}) {
|
|
4452
|
+
const path = await buildNavigationPath({ slug, routeDocumentId, calculatedParent });
|
|
4453
|
+
return { path, slug: path.split("/").pop() ?? slug };
|
|
4454
|
+
}
|
|
4443
4455
|
async function handleItemDeletion(navigationItems) {
|
|
4444
4456
|
const errors = [];
|
|
4445
4457
|
let items = [...navigationItems];
|
|
@@ -4525,15 +4537,15 @@ async function handleItemUpdate({
|
|
|
4525
4537
|
});
|
|
4526
4538
|
if (!route2)
|
|
4527
4539
|
throw new Error(`Related route not found for new navigation item '${item.route.title}'`);
|
|
4528
|
-
const path = await
|
|
4529
|
-
slug: item.route.slug,
|
|
4540
|
+
const { path, slug } = await buildItemPath({
|
|
4541
|
+
slug: transformToUrl(item.route.slug),
|
|
4530
4542
|
routeDocumentId: route2.documentId,
|
|
4531
4543
|
calculatedParent
|
|
4532
4544
|
});
|
|
4533
4545
|
assertPathAllowed(path, await getRouteBlacklist());
|
|
4534
4546
|
await updateRoute(route2.documentId, {
|
|
4535
4547
|
title: item.route.title,
|
|
4536
|
-
slug
|
|
4548
|
+
slug,
|
|
4537
4549
|
path,
|
|
4538
4550
|
isOverride: path !== route2.canonicalPath
|
|
4539
4551
|
});
|
|
@@ -4561,12 +4573,13 @@ async function handleItemUpdate({
|
|
|
4561
4573
|
});
|
|
4562
4574
|
if (!route2)
|
|
4563
4575
|
throw new Error(`Related route not found for navigation item '${item.route.title}'`);
|
|
4564
|
-
const
|
|
4565
|
-
const
|
|
4566
|
-
|
|
4576
|
+
const changedSlug = item.clientModifications?.slug;
|
|
4577
|
+
const requestedSlug = changedSlug ? isInternal ? transformToUrl(changedSlug) : changedSlug : item.route.slug;
|
|
4578
|
+
const { path, slug } = isInternal ? await buildItemPath({
|
|
4579
|
+
slug: requestedSlug,
|
|
4567
4580
|
routeDocumentId: route2.documentId,
|
|
4568
4581
|
calculatedParent
|
|
4569
|
-
}) : slug;
|
|
4582
|
+
}) : { path: requestedSlug, slug: requestedSlug };
|
|
4570
4583
|
const isOverride = path !== route2.canonicalPath;
|
|
4571
4584
|
if (needsRouteUpdate) {
|
|
4572
4585
|
if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
|
|
@@ -4984,6 +4997,38 @@ async function getPublishedDocumentIds(routes2) {
|
|
|
4984
4997
|
}
|
|
4985
4998
|
return publishedDocumentIds;
|
|
4986
4999
|
}
|
|
5000
|
+
async function getDocumentStatuses(routes2) {
|
|
5001
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
5002
|
+
for (const route2 of routes2) {
|
|
5003
|
+
if (!route2?.relatedContentType || !route2.relatedDocumentId) continue;
|
|
5004
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
5005
|
+
documentIds.push(route2.relatedDocumentId);
|
|
5006
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
5007
|
+
}
|
|
5008
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
5009
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
5010
|
+
const contentType = strapi.contentTypes[uid];
|
|
5011
|
+
if (!contentType || !utils.contentTypes.hasDraftAndPublish(contentType)) continue;
|
|
5012
|
+
const query = {
|
|
5013
|
+
filters: { documentId: { $in: documentIds } },
|
|
5014
|
+
fields: ["documentId", "updatedAt"]
|
|
5015
|
+
};
|
|
5016
|
+
const [drafts, published] = await Promise.all([
|
|
5017
|
+
strapi.documents(uid).findMany({ ...query, status: "draft" }),
|
|
5018
|
+
strapi.documents(uid).findMany({ ...query, status: "published" })
|
|
5019
|
+
]);
|
|
5020
|
+
const publishedUpdatedAt = new Map(
|
|
5021
|
+
published.map((entry) => [entry.documentId, new Date(entry.updatedAt).getTime()])
|
|
5022
|
+
);
|
|
5023
|
+
drafts.forEach((draft) => {
|
|
5024
|
+
const publishedAt = publishedUpdatedAt.get(draft.documentId);
|
|
5025
|
+
if (publishedAt === void 0) return statuses.set(draft.documentId, "draft");
|
|
5026
|
+
const isModified = new Date(draft.updatedAt).getTime() > publishedAt;
|
|
5027
|
+
statuses.set(draft.documentId, isModified ? "modified" : "published");
|
|
5028
|
+
});
|
|
5029
|
+
}
|
|
5030
|
+
return statuses;
|
|
5031
|
+
}
|
|
4987
5032
|
const migration_001_canonical_path = {
|
|
4988
5033
|
version: "001",
|
|
4989
5034
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -5134,10 +5179,25 @@ const migration_003_route_source_field = {
|
|
|
5134
5179
|
);
|
|
5135
5180
|
}
|
|
5136
5181
|
};
|
|
5182
|
+
const migration_004_navigation_max_depth = {
|
|
5183
|
+
version: "004",
|
|
5184
|
+
description: "Move the global navigation max depth of the config to every navigation",
|
|
5185
|
+
async up(strapi2) {
|
|
5186
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5187
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
5188
|
+
const maxDepth = config2?.navigation?.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
5189
|
+
const { count } = await strapi2.db.query(waNavigation).updateMany({
|
|
5190
|
+
where: { maxDepth: { $null: true } },
|
|
5191
|
+
data: { maxDepth }
|
|
5192
|
+
});
|
|
5193
|
+
strapi2.log.info(`[webatlas] Set the max depth ${maxDepth} for ${count} navigation(s)`);
|
|
5194
|
+
}
|
|
5195
|
+
};
|
|
5137
5196
|
const migrations = [
|
|
5138
5197
|
migration_001_canonical_path,
|
|
5139
5198
|
migration_002_webatlas_json_field,
|
|
5140
|
-
migration_003_route_source_field
|
|
5199
|
+
migration_003_route_source_field,
|
|
5200
|
+
migration_004_navigation_max_depth
|
|
5141
5201
|
];
|
|
5142
5202
|
const runMigrations = async (strapi2) => {
|
|
5143
5203
|
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
@@ -5175,9 +5235,37 @@ function registerPermissions(strapi2) {
|
|
|
5175
5235
|
const actions = [
|
|
5176
5236
|
{
|
|
5177
5237
|
section: "plugins",
|
|
5178
|
-
displayName: "
|
|
5179
|
-
uid: "
|
|
5180
|
-
subCategory: "
|
|
5238
|
+
displayName: "Read navigations",
|
|
5239
|
+
uid: "navigation.read",
|
|
5240
|
+
subCategory: "Navigation",
|
|
5241
|
+
pluginName: PLUGIN_ID
|
|
5242
|
+
},
|
|
5243
|
+
{
|
|
5244
|
+
section: "plugins",
|
|
5245
|
+
displayName: "Create navigations",
|
|
5246
|
+
uid: "navigation.create",
|
|
5247
|
+
subCategory: "Navigation",
|
|
5248
|
+
pluginName: PLUGIN_ID
|
|
5249
|
+
},
|
|
5250
|
+
{
|
|
5251
|
+
section: "plugins",
|
|
5252
|
+
displayName: "Edit navigations",
|
|
5253
|
+
uid: "navigation.update",
|
|
5254
|
+
subCategory: "Navigation",
|
|
5255
|
+
pluginName: PLUGIN_ID
|
|
5256
|
+
},
|
|
5257
|
+
{
|
|
5258
|
+
section: "plugins",
|
|
5259
|
+
displayName: "Delete navigations",
|
|
5260
|
+
uid: "navigation.delete",
|
|
5261
|
+
subCategory: "Navigation",
|
|
5262
|
+
pluginName: PLUGIN_ID
|
|
5263
|
+
},
|
|
5264
|
+
{
|
|
5265
|
+
section: "plugins",
|
|
5266
|
+
displayName: "Edit navigation items",
|
|
5267
|
+
uid: "navigation.edit-items",
|
|
5268
|
+
subCategory: "Navigation",
|
|
5181
5269
|
pluginName: PLUGIN_ID
|
|
5182
5270
|
},
|
|
5183
5271
|
{
|
|
@@ -5189,15 +5277,29 @@ function registerPermissions(strapi2) {
|
|
|
5189
5277
|
},
|
|
5190
5278
|
{
|
|
5191
5279
|
section: "plugins",
|
|
5192
|
-
displayName: "
|
|
5193
|
-
uid: "settings.general",
|
|
5280
|
+
displayName: "Read general settings",
|
|
5281
|
+
uid: "settings.general.read",
|
|
5282
|
+
subCategory: "Settings",
|
|
5283
|
+
pluginName: PLUGIN_ID
|
|
5284
|
+
},
|
|
5285
|
+
{
|
|
5286
|
+
section: "plugins",
|
|
5287
|
+
displayName: "Update general settings",
|
|
5288
|
+
uid: "settings.general.update",
|
|
5194
5289
|
subCategory: "Settings",
|
|
5195
5290
|
pluginName: PLUGIN_ID
|
|
5196
5291
|
},
|
|
5197
5292
|
{
|
|
5198
5293
|
section: "plugins",
|
|
5199
|
-
displayName: "
|
|
5200
|
-
uid: "settings.navigation",
|
|
5294
|
+
displayName: "Read navigation settings",
|
|
5295
|
+
uid: "settings.navigation.read",
|
|
5296
|
+
subCategory: "Settings",
|
|
5297
|
+
pluginName: PLUGIN_ID
|
|
5298
|
+
},
|
|
5299
|
+
{
|
|
5300
|
+
section: "plugins",
|
|
5301
|
+
displayName: "Update navigation settings",
|
|
5302
|
+
uid: "settings.navigation.update",
|
|
5201
5303
|
subCategory: "Settings",
|
|
5202
5304
|
pluginName: PLUGIN_ID
|
|
5203
5305
|
},
|
|
@@ -5207,6 +5309,13 @@ function registerPermissions(strapi2) {
|
|
|
5207
5309
|
uid: "cm.aside",
|
|
5208
5310
|
subCategory: "Content Manager",
|
|
5209
5311
|
pluginName: PLUGIN_ID
|
|
5312
|
+
},
|
|
5313
|
+
{
|
|
5314
|
+
section: "plugins",
|
|
5315
|
+
displayName: "Edit path (parent route and override)",
|
|
5316
|
+
uid: "cm.edit-path",
|
|
5317
|
+
subCategory: "Content Manager",
|
|
5318
|
+
pluginName: PLUGIN_ID
|
|
5210
5319
|
}
|
|
5211
5320
|
];
|
|
5212
5321
|
strapi2.admin.services.permission.actionProvider.registerMany(actions);
|
|
@@ -5216,13 +5325,10 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5216
5325
|
const config2 = await pluginStore.get({
|
|
5217
5326
|
key: "config"
|
|
5218
5327
|
});
|
|
5328
|
+
const { navigation: _legacyNavigation, ...currentConfig } = config2 ?? {};
|
|
5219
5329
|
let newConfig = {
|
|
5220
|
-
...
|
|
5330
|
+
...currentConfig,
|
|
5221
5331
|
selectedContentTypes: [],
|
|
5222
|
-
navigation: {
|
|
5223
|
-
maxDepth: config2?.navigation?.maxDepth || 1,
|
|
5224
|
-
...config2?.navigation
|
|
5225
|
-
},
|
|
5226
5332
|
migrationVersion: config2?.migrationVersion || "0"
|
|
5227
5333
|
};
|
|
5228
5334
|
enabledContentTypes.forEach((type) => {
|
|
@@ -5239,6 +5345,21 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5239
5345
|
}
|
|
5240
5346
|
return newConfig;
|
|
5241
5347
|
}
|
|
5348
|
+
async function getDefaultRouteData(strapi2, uid, data) {
|
|
5349
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5350
|
+
const currentConfig = await pluginStore.get({ key: "config" });
|
|
5351
|
+
const ctSettings = currentConfig?.selectedContentTypes.find((ct) => ct.uid === uid);
|
|
5352
|
+
const sourceValue = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5353
|
+
if (typeof sourceValue !== "string" || !sourceValue.trim()) return void 0;
|
|
5354
|
+
const defaultParent = ctSettings.defaultParentRoute ? await strapi2.documents(waRoute).findFirst({
|
|
5355
|
+
filters: { relatedDocumentId: ctSettings.defaultParentRoute }
|
|
5356
|
+
}) : null;
|
|
5357
|
+
return {
|
|
5358
|
+
slug: transformToUrl(sourceValue),
|
|
5359
|
+
parentDocumentId: defaultParent?.documentId ?? null,
|
|
5360
|
+
isOverride: false
|
|
5361
|
+
};
|
|
5362
|
+
}
|
|
5242
5363
|
function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
5243
5364
|
const actions = ["create", "update", "delete"];
|
|
5244
5365
|
strapi2.documents.use(async (context, next) => {
|
|
@@ -5248,12 +5369,15 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5248
5369
|
const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
|
|
5249
5370
|
const requestContext = strapi2.requestContext.get();
|
|
5250
5371
|
const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
|
|
5251
|
-
|
|
5372
|
+
const userAbility = requestContext?.state?.userAbility;
|
|
5373
|
+
const canUseAside = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.aside`);
|
|
5374
|
+
const canEditPath = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.edit-path`);
|
|
5375
|
+
if ((context.action === "create" || context.action === "update") && (!isRouteDataAllowed || !canUseAside)) {
|
|
5252
5376
|
delete context.params.data?.webatlas;
|
|
5253
5377
|
}
|
|
5254
5378
|
if (context.action === "create") {
|
|
5255
5379
|
const data = context.params.data;
|
|
5256
|
-
const
|
|
5380
|
+
const webatlas = data.webatlas && canEditPath ? data.webatlas : await getDefaultRouteData(strapi2, context.uid, data);
|
|
5257
5381
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5258
5382
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5259
5383
|
if (!transformedSlug) return next();
|
|
@@ -5309,17 +5433,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5309
5433
|
if (context.action === "update") {
|
|
5310
5434
|
const data = context.params.data;
|
|
5311
5435
|
const { documentId } = context.params;
|
|
5312
|
-
const
|
|
5436
|
+
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5437
|
+
filters: {
|
|
5438
|
+
relatedDocumentId: documentId
|
|
5439
|
+
},
|
|
5440
|
+
populate: ["parent"]
|
|
5441
|
+
});
|
|
5442
|
+
let webatlas = data.webatlas;
|
|
5443
|
+
if (!relatedRoute && (!webatlas || !canEditPath)) {
|
|
5444
|
+
webatlas = await getDefaultRouteData(strapi2, context.uid, data);
|
|
5445
|
+
} else if (relatedRoute && webatlas && !canEditPath) {
|
|
5446
|
+
const sourceValue2 = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5447
|
+
webatlas = !relatedRoute.isOverride && typeof sourceValue2 === "string" && sourceValue2.trim() ? {
|
|
5448
|
+
slug: transformToUrl(sourceValue2),
|
|
5449
|
+
parentDocumentId: relatedRoute.parent?.documentId ?? null,
|
|
5450
|
+
isOverride: false
|
|
5451
|
+
} : void 0;
|
|
5452
|
+
}
|
|
5313
5453
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5314
5454
|
if (!slug) {
|
|
5315
5455
|
const result3 = await next();
|
|
5316
5456
|
return result3;
|
|
5317
5457
|
}
|
|
5318
|
-
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5319
|
-
filters: {
|
|
5320
|
-
relatedDocumentId: documentId
|
|
5321
|
-
}
|
|
5322
|
-
});
|
|
5323
5458
|
let parent = null;
|
|
5324
5459
|
let isValid = false;
|
|
5325
5460
|
if (parentDocumentId) {
|
|
@@ -5521,9 +5656,6 @@ const register = ({ strapi: strapi2 }) => {
|
|
|
5521
5656
|
const config = {
|
|
5522
5657
|
default: {
|
|
5523
5658
|
selectedContentTypes: [],
|
|
5524
|
-
navigation: {
|
|
5525
|
-
maxDepth: 1
|
|
5526
|
-
},
|
|
5527
5659
|
routeBlacklist: []
|
|
5528
5660
|
},
|
|
5529
5661
|
validator() {
|
|
@@ -5668,6 +5800,13 @@ const schema$1 = {
|
|
|
5668
5800
|
default: false,
|
|
5669
5801
|
configurable: false
|
|
5670
5802
|
},
|
|
5803
|
+
// Depth index of the deepest allowed level, 0 = root only. Only changed in the plugin settings
|
|
5804
|
+
maxDepth: {
|
|
5805
|
+
type: "integer",
|
|
5806
|
+
default: DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
5807
|
+
min: 0,
|
|
5808
|
+
configurable: false
|
|
5809
|
+
},
|
|
5671
5810
|
items: {
|
|
5672
5811
|
type: "relation",
|
|
5673
5812
|
configurable: false,
|
|
@@ -5752,11 +5891,29 @@ const admin$2 = () => ({
|
|
|
5752
5891
|
async getAllRoutes(ctx) {
|
|
5753
5892
|
return await getAdminService().getAllRoutes();
|
|
5754
5893
|
},
|
|
5894
|
+
async getHealthReport(ctx) {
|
|
5895
|
+
return await getHealthService().getHealthReport();
|
|
5896
|
+
},
|
|
5755
5897
|
async getRelatedRoute(ctx) {
|
|
5756
5898
|
const { documentId } = ctx.query;
|
|
5757
5899
|
if (!documentId) throw new utils.errors.ValidationError("Route documentId is required");
|
|
5758
5900
|
return await getAdminService().getRelatedRoute(documentId);
|
|
5759
5901
|
},
|
|
5902
|
+
async getRelatedRoutes(ctx) {
|
|
5903
|
+
const documentIds = String(ctx.query.documentIds || "").split(",").filter(Boolean);
|
|
5904
|
+
if (documentIds.length === 0) throw new utils.errors.ValidationError("documentIds are required");
|
|
5905
|
+
if (documentIds.length > 100)
|
|
5906
|
+
throw new utils.errors.ValidationError("At most 100 documentIds are allowed");
|
|
5907
|
+
return await getAdminService().getRelatedRoutes(documentIds);
|
|
5908
|
+
},
|
|
5909
|
+
async getNavigationDepths(ctx) {
|
|
5910
|
+
return await getAdminService().getNavigationDepths();
|
|
5911
|
+
},
|
|
5912
|
+
async updateNavigationDepths(ctx) {
|
|
5913
|
+
const { data } = ctx.request.body;
|
|
5914
|
+
if (!Array.isArray(data)) throw new utils.errors.ValidationError("Navigation depths are required");
|
|
5915
|
+
return await getAdminService().updateNavigationDepths(data);
|
|
5916
|
+
},
|
|
5760
5917
|
async getProhibitedRouteIds(ctx) {
|
|
5761
5918
|
const { documentId } = ctx.params;
|
|
5762
5919
|
return await getAdminService().getProhibitedRouteIds(documentId);
|
|
@@ -5872,9 +6029,9 @@ const admin$1 = {
|
|
|
5872
6029
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5873
6030
|
config: {
|
|
5874
6031
|
actions: [
|
|
5875
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5876
|
-
`plugin::${PLUGIN_ID}.settings.navigation`,
|
|
5877
|
-
`plugin::${PLUGIN_ID}.
|
|
6032
|
+
`plugin::${PLUGIN_ID}.settings.general.read`,
|
|
6033
|
+
`plugin::${PLUGIN_ID}.settings.navigation.read`,
|
|
6034
|
+
`plugin::${PLUGIN_ID}.navigation.read`,
|
|
5878
6035
|
`plugin::${PLUGIN_ID}.cm.aside`
|
|
5879
6036
|
]
|
|
5880
6037
|
}
|
|
@@ -5892,10 +6049,7 @@ const admin$1 = {
|
|
|
5892
6049
|
{
|
|
5893
6050
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5894
6051
|
config: {
|
|
5895
|
-
actions: [
|
|
5896
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5897
|
-
`plugin::${PLUGIN_ID}.settings.navigation`
|
|
5898
|
-
]
|
|
6052
|
+
actions: [`plugin::${PLUGIN_ID}.settings.general.update`]
|
|
5899
6053
|
}
|
|
5900
6054
|
}
|
|
5901
6055
|
]
|
|
@@ -5918,6 +6072,22 @@ const admin$1 = {
|
|
|
5918
6072
|
]
|
|
5919
6073
|
}
|
|
5920
6074
|
},
|
|
6075
|
+
{
|
|
6076
|
+
method: "GET",
|
|
6077
|
+
path: "/health",
|
|
6078
|
+
handler: "admin.getHealthReport",
|
|
6079
|
+
config: {
|
|
6080
|
+
policies: [
|
|
6081
|
+
"admin::isAuthenticatedAdmin",
|
|
6082
|
+
{
|
|
6083
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6084
|
+
config: {
|
|
6085
|
+
actions: [`plugin::${PLUGIN_ID}.page.routes`]
|
|
6086
|
+
}
|
|
6087
|
+
}
|
|
6088
|
+
]
|
|
6089
|
+
}
|
|
6090
|
+
},
|
|
5921
6091
|
{
|
|
5922
6092
|
method: "GET",
|
|
5923
6093
|
path: "/route/related",
|
|
@@ -5928,7 +6098,56 @@ const admin$1 = {
|
|
|
5928
6098
|
{
|
|
5929
6099
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5930
6100
|
config: {
|
|
5931
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6101
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
]
|
|
6105
|
+
}
|
|
6106
|
+
},
|
|
6107
|
+
// The max depth is a structural setting, so it is only changed in the plugin settings
|
|
6108
|
+
{
|
|
6109
|
+
method: "GET",
|
|
6110
|
+
path: "/settings/navigation-depths",
|
|
6111
|
+
handler: "admin.getNavigationDepths",
|
|
6112
|
+
config: {
|
|
6113
|
+
policies: [
|
|
6114
|
+
"admin::isAuthenticatedAdmin",
|
|
6115
|
+
{
|
|
6116
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6117
|
+
config: {
|
|
6118
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.read`]
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
6121
|
+
]
|
|
6122
|
+
}
|
|
6123
|
+
},
|
|
6124
|
+
{
|
|
6125
|
+
method: "PUT",
|
|
6126
|
+
path: "/settings/navigation-depths",
|
|
6127
|
+
handler: "admin.updateNavigationDepths",
|
|
6128
|
+
config: {
|
|
6129
|
+
policies: [
|
|
6130
|
+
"admin::isAuthenticatedAdmin",
|
|
6131
|
+
{
|
|
6132
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6133
|
+
config: {
|
|
6134
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.update`]
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
]
|
|
6138
|
+
}
|
|
6139
|
+
},
|
|
6140
|
+
{
|
|
6141
|
+
method: "GET",
|
|
6142
|
+
path: "/route/related/batch",
|
|
6143
|
+
handler: "admin.getRelatedRoutes",
|
|
6144
|
+
config: {
|
|
6145
|
+
policies: [
|
|
6146
|
+
"admin::isAuthenticatedAdmin",
|
|
6147
|
+
{
|
|
6148
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6149
|
+
config: {
|
|
6150
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5932
6151
|
}
|
|
5933
6152
|
}
|
|
5934
6153
|
]
|
|
@@ -5960,7 +6179,7 @@ const admin$1 = {
|
|
|
5960
6179
|
{
|
|
5961
6180
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5962
6181
|
config: {
|
|
5963
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6182
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5964
6183
|
}
|
|
5965
6184
|
}
|
|
5966
6185
|
]
|
|
@@ -5977,7 +6196,7 @@ const admin$1 = {
|
|
|
5977
6196
|
{
|
|
5978
6197
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5979
6198
|
config: {
|
|
5980
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6199
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5981
6200
|
}
|
|
5982
6201
|
}
|
|
5983
6202
|
]
|
|
@@ -5993,7 +6212,7 @@ const admin$1 = {
|
|
|
5993
6212
|
{
|
|
5994
6213
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5995
6214
|
config: {
|
|
5996
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6215
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.create`]
|
|
5997
6216
|
}
|
|
5998
6217
|
}
|
|
5999
6218
|
]
|
|
@@ -6009,7 +6228,7 @@ const admin$1 = {
|
|
|
6009
6228
|
{
|
|
6010
6229
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6011
6230
|
config: {
|
|
6012
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6231
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.update`]
|
|
6013
6232
|
}
|
|
6014
6233
|
}
|
|
6015
6234
|
]
|
|
@@ -6025,7 +6244,7 @@ const admin$1 = {
|
|
|
6025
6244
|
{
|
|
6026
6245
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6027
6246
|
config: {
|
|
6028
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6247
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.edit-items`]
|
|
6029
6248
|
}
|
|
6030
6249
|
}
|
|
6031
6250
|
]
|
|
@@ -6041,7 +6260,7 @@ const admin$1 = {
|
|
|
6041
6260
|
{
|
|
6042
6261
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6043
6262
|
config: {
|
|
6044
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6263
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.delete`]
|
|
6045
6264
|
}
|
|
6046
6265
|
}
|
|
6047
6266
|
]
|
|
@@ -6058,7 +6277,7 @@ const admin$1 = {
|
|
|
6058
6277
|
{
|
|
6059
6278
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6060
6279
|
config: {
|
|
6061
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6280
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6062
6281
|
}
|
|
6063
6282
|
}
|
|
6064
6283
|
]
|
|
@@ -6091,6 +6310,36 @@ const routes = {
|
|
|
6091
6310
|
admin: admin$1,
|
|
6092
6311
|
"content-api": client$1
|
|
6093
6312
|
};
|
|
6313
|
+
async function getNavigationDepths() {
|
|
6314
|
+
const navigations = await strapi.documents(waNavigation).findMany({
|
|
6315
|
+
populate: ["items", "items.parent"]
|
|
6316
|
+
});
|
|
6317
|
+
return navigations.map((navigation2) => {
|
|
6318
|
+
const { items } = buildStructuredNavigation(navigation2, "flat");
|
|
6319
|
+
return {
|
|
6320
|
+
documentId: navigation2.documentId,
|
|
6321
|
+
name: navigation2.name,
|
|
6322
|
+
maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
6323
|
+
deepestDepth: Math.max(-1, ...(items ?? []).map((item) => item.depth ?? 0))
|
|
6324
|
+
};
|
|
6325
|
+
});
|
|
6326
|
+
}
|
|
6327
|
+
async function assertItemDepths(navigationId, navigationItems) {
|
|
6328
|
+
const navigation2 = await strapi.documents(waNavigation).findOne({
|
|
6329
|
+
documentId: navigationId,
|
|
6330
|
+
fields: ["maxDepth"]
|
|
6331
|
+
});
|
|
6332
|
+
if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
|
|
6333
|
+
const maxDepth = navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
6334
|
+
const tooDeepItem = navigationItems.find(
|
|
6335
|
+
(item) => item.clientModifications?.type !== "delete" && (item.depth ?? 0) > maxDepth
|
|
6336
|
+
);
|
|
6337
|
+
if (tooDeepItem) {
|
|
6338
|
+
throw new utils.errors.ValidationError(
|
|
6339
|
+
`'${tooDeepItem.clientModifications?.title || tooDeepItem.route?.title}' is deeper than the ${maxDepth + 1} level(s) allowed in this navigation`
|
|
6340
|
+
);
|
|
6341
|
+
}
|
|
6342
|
+
}
|
|
6094
6343
|
const admin = ({ strapi: strapi2 }) => ({
|
|
6095
6344
|
async updateConfig(newConfig) {
|
|
6096
6345
|
if (!newConfig) return;
|
|
@@ -6113,11 +6362,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6113
6362
|
const defaultConfig = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
6114
6363
|
config2 = {
|
|
6115
6364
|
...defaultConfig,
|
|
6116
|
-
...config2
|
|
6117
|
-
navigation: {
|
|
6118
|
-
...defaultConfig.navigation,
|
|
6119
|
-
...config2?.navigation
|
|
6120
|
-
}
|
|
6365
|
+
...config2
|
|
6121
6366
|
};
|
|
6122
6367
|
return config2;
|
|
6123
6368
|
},
|
|
@@ -6127,7 +6372,14 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6127
6372
|
});
|
|
6128
6373
|
},
|
|
6129
6374
|
async getAllRoutes() {
|
|
6130
|
-
return await strapi2.documents(waRoute).findMany(
|
|
6375
|
+
return await strapi2.documents(waRoute).findMany({
|
|
6376
|
+
populate: {
|
|
6377
|
+
navitem: {
|
|
6378
|
+
fields: ["documentId"],
|
|
6379
|
+
populate: { navigation: { fields: ["documentId", "name"] } }
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6382
|
+
});
|
|
6131
6383
|
},
|
|
6132
6384
|
async getRelatedRoute(documentId) {
|
|
6133
6385
|
return await strapi2.db?.query(waRoute).findOne({
|
|
@@ -6137,6 +6389,13 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6137
6389
|
populate: ["parent"]
|
|
6138
6390
|
});
|
|
6139
6391
|
},
|
|
6392
|
+
// Path of the routes linked to the given entries, with one query
|
|
6393
|
+
async getRelatedRoutes(documentIds) {
|
|
6394
|
+
return await strapi2.db?.query(waRoute).findMany({
|
|
6395
|
+
where: { relatedDocumentId: { $in: documentIds } },
|
|
6396
|
+
select: ["relatedDocumentId", "path"]
|
|
6397
|
+
});
|
|
6398
|
+
},
|
|
6140
6399
|
async getProhibitedRouteIds(documentId) {
|
|
6141
6400
|
let route2 = null;
|
|
6142
6401
|
if (documentId) {
|
|
@@ -6181,6 +6440,16 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6181
6440
|
);
|
|
6182
6441
|
}
|
|
6183
6442
|
}
|
|
6443
|
+
const navigations = Array.isArray(navigation2) ? navigation2 : [navigation2];
|
|
6444
|
+
const statuses = await getDocumentStatuses(
|
|
6445
|
+
navigations.flatMap((nav) => (nav.items ?? []).map((item) => item.route))
|
|
6446
|
+
);
|
|
6447
|
+
navigations.forEach(
|
|
6448
|
+
(nav) => nav.items?.forEach((item) => {
|
|
6449
|
+
const status = statuses.get(item.route?.relatedDocumentId);
|
|
6450
|
+
if (status) item.status = status;
|
|
6451
|
+
})
|
|
6452
|
+
);
|
|
6184
6453
|
return navigation2;
|
|
6185
6454
|
},
|
|
6186
6455
|
async createNavigation(name, visible) {
|
|
@@ -6201,6 +6470,28 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6201
6470
|
}
|
|
6202
6471
|
});
|
|
6203
6472
|
},
|
|
6473
|
+
async getNavigationDepths() {
|
|
6474
|
+
return await getNavigationDepths();
|
|
6475
|
+
},
|
|
6476
|
+
async updateNavigationDepths(depths) {
|
|
6477
|
+
const currentDepths = await getNavigationDepths();
|
|
6478
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6479
|
+
const current = currentDepths.find((navigation2) => navigation2.documentId === documentId);
|
|
6480
|
+
if (!current) throw new utils.errors.NotFoundError("Navigation not found");
|
|
6481
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 0) {
|
|
6482
|
+
throw new utils.errors.ValidationError(`Invalid max depth for the navigation '${current.name}'`);
|
|
6483
|
+
}
|
|
6484
|
+
if (maxDepth < current.deepestDepth) {
|
|
6485
|
+
throw new utils.errors.ValidationError(
|
|
6486
|
+
`The navigation '${current.name}' already has items on level ${current.deepestDepth + 1}`
|
|
6487
|
+
);
|
|
6488
|
+
}
|
|
6489
|
+
}
|
|
6490
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6491
|
+
await strapi2.documents(waNavigation).update({ documentId, data: { maxDepth } });
|
|
6492
|
+
}
|
|
6493
|
+
return await getNavigationDepths();
|
|
6494
|
+
},
|
|
6204
6495
|
async deleteNavigation(documentId) {
|
|
6205
6496
|
const navigation2 = await strapi2.documents(waNavigation).findOne({
|
|
6206
6497
|
documentId,
|
|
@@ -6218,6 +6509,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6218
6509
|
},
|
|
6219
6510
|
async updateNavigationItemStructure(navigationId, navigationItems) {
|
|
6220
6511
|
if (!navigationId || !navigationItems) return;
|
|
6512
|
+
await assertItemDepths(navigationId, navigationItems);
|
|
6221
6513
|
const errors2 = [];
|
|
6222
6514
|
let newNavItemsMap = /* @__PURE__ */ new Map();
|
|
6223
6515
|
const deletionResult = await handleItemDeletion(navigationItems);
|
|
@@ -6376,9 +6668,248 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6376
6668
|
return { ...structured, items: entityNavigation };
|
|
6377
6669
|
}
|
|
6378
6670
|
});
|
|
6671
|
+
function checkPathConflicts({ routes: routes2 }) {
|
|
6672
|
+
const routesByValue = /* @__PURE__ */ new Map();
|
|
6673
|
+
for (const route2 of routes2) {
|
|
6674
|
+
if (route2.type === "external") continue;
|
|
6675
|
+
for (const value of [route2.path, route2.canonicalPath, route2.uidPath]) {
|
|
6676
|
+
if (!value) continue;
|
|
6677
|
+
const routesWithValue = routesByValue.get(value) ?? /* @__PURE__ */ new Set();
|
|
6678
|
+
routesWithValue.add(route2);
|
|
6679
|
+
routesByValue.set(value, routesWithValue);
|
|
6680
|
+
}
|
|
6681
|
+
}
|
|
6682
|
+
const issues = [];
|
|
6683
|
+
for (const [value, routesWithValue] of routesByValue) {
|
|
6684
|
+
if (routesWithValue.size < 2) continue;
|
|
6685
|
+
for (const route2 of routesWithValue) {
|
|
6686
|
+
issues.push({
|
|
6687
|
+
check: "pathConflict",
|
|
6688
|
+
severity: "error",
|
|
6689
|
+
routeDocumentId: route2.documentId,
|
|
6690
|
+
details: {
|
|
6691
|
+
value,
|
|
6692
|
+
conflictingRoutes: [...routesWithValue].filter((other) => other !== route2).map((other) => ({ documentId: other.documentId, title: other.title }))
|
|
6693
|
+
}
|
|
6694
|
+
});
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
return issues;
|
|
6698
|
+
}
|
|
6699
|
+
function checkOrphanedRoutes({
|
|
6700
|
+
routes: routes2,
|
|
6701
|
+
existingContentTypes,
|
|
6702
|
+
enabledContentTypes,
|
|
6703
|
+
existingDocumentIds
|
|
6704
|
+
}) {
|
|
6705
|
+
const issues = [];
|
|
6706
|
+
for (const route2 of routes2) {
|
|
6707
|
+
if (route2.type !== "internal") continue;
|
|
6708
|
+
const reason = !existingContentTypes.has(route2.relatedContentType) ? "missingContentType" : !enabledContentTypes.has(route2.relatedContentType) ? "disabledContentType" : !existingDocumentIds.get(route2.relatedContentType)?.has(route2.relatedDocumentId) ? "missingDocument" : null;
|
|
6709
|
+
if (reason) {
|
|
6710
|
+
issues.push({
|
|
6711
|
+
check: "orphanedRoute",
|
|
6712
|
+
severity: "error",
|
|
6713
|
+
routeDocumentId: route2.documentId,
|
|
6714
|
+
details: { reason }
|
|
6715
|
+
});
|
|
6716
|
+
}
|
|
6717
|
+
}
|
|
6718
|
+
return issues;
|
|
6719
|
+
}
|
|
6720
|
+
function checkBlacklistedPaths({ routes: routes2, routeBlacklist }) {
|
|
6721
|
+
if (routeBlacklist.length === 0) return [];
|
|
6722
|
+
const issues = [];
|
|
6723
|
+
for (const route2 of routes2) {
|
|
6724
|
+
if (route2.type === "external") continue;
|
|
6725
|
+
const value = [route2.path, route2.canonicalPath].find(
|
|
6726
|
+
(path) => isBlacklistedPath(path, routeBlacklist)
|
|
6727
|
+
);
|
|
6728
|
+
if (value) {
|
|
6729
|
+
issues.push({
|
|
6730
|
+
check: "blacklistedPath",
|
|
6731
|
+
severity: "error",
|
|
6732
|
+
routeDocumentId: route2.documentId,
|
|
6733
|
+
details: { value }
|
|
6734
|
+
});
|
|
6735
|
+
}
|
|
6736
|
+
}
|
|
6737
|
+
return issues;
|
|
6738
|
+
}
|
|
6739
|
+
const VALID_EXTERNAL_PROTOCOLS = ["http:", "https:", "mailto:", "tel:"];
|
|
6740
|
+
function checkInvalidExternalUrls({ routes: routes2 }) {
|
|
6741
|
+
const issues = [];
|
|
6742
|
+
for (const route2 of routes2) {
|
|
6743
|
+
if (route2.type !== "external") continue;
|
|
6744
|
+
let isValid = false;
|
|
6745
|
+
try {
|
|
6746
|
+
isValid = VALID_EXTERNAL_PROTOCOLS.includes(new URL(route2.path).protocol);
|
|
6747
|
+
} catch {
|
|
6748
|
+
isValid = false;
|
|
6749
|
+
}
|
|
6750
|
+
if (!isValid) {
|
|
6751
|
+
issues.push({
|
|
6752
|
+
check: "invalidExternalUrl",
|
|
6753
|
+
severity: "warning",
|
|
6754
|
+
routeDocumentId: route2.documentId,
|
|
6755
|
+
details: { value: route2.path }
|
|
6756
|
+
});
|
|
6757
|
+
}
|
|
6758
|
+
}
|
|
6759
|
+
return issues;
|
|
6760
|
+
}
|
|
6761
|
+
function checkUnpublishedInNavigation({
|
|
6762
|
+
routes: routes2,
|
|
6763
|
+
navItems,
|
|
6764
|
+
draftOnlyDocumentIds
|
|
6765
|
+
}) {
|
|
6766
|
+
const navigationsByRoute = /* @__PURE__ */ new Map();
|
|
6767
|
+
for (const navItem of navItems) {
|
|
6768
|
+
const names = navigationsByRoute.get(navItem.routeDocumentId) ?? /* @__PURE__ */ new Set();
|
|
6769
|
+
names.add(navItem.navigationName);
|
|
6770
|
+
navigationsByRoute.set(navItem.routeDocumentId, names);
|
|
6771
|
+
}
|
|
6772
|
+
const issues = [];
|
|
6773
|
+
for (const route2 of routes2) {
|
|
6774
|
+
if (route2.type !== "internal" || !draftOnlyDocumentIds.has(route2.relatedDocumentId)) continue;
|
|
6775
|
+
for (const navigationName of navigationsByRoute.get(route2.documentId) ?? []) {
|
|
6776
|
+
issues.push({
|
|
6777
|
+
check: "unpublishedInNavigation",
|
|
6778
|
+
severity: "warning",
|
|
6779
|
+
routeDocumentId: route2.documentId,
|
|
6780
|
+
details: { navigationName }
|
|
6781
|
+
});
|
|
6782
|
+
}
|
|
6783
|
+
}
|
|
6784
|
+
return issues;
|
|
6785
|
+
}
|
|
6786
|
+
function checkTooDeepItems({ navItems }) {
|
|
6787
|
+
return navItems.filter((navItem) => navItem.depth > navItem.maxDepth).map((navItem) => ({
|
|
6788
|
+
check: "tooDeepItem",
|
|
6789
|
+
severity: "warning",
|
|
6790
|
+
routeDocumentId: navItem.routeDocumentId,
|
|
6791
|
+
details: {
|
|
6792
|
+
navigationName: navItem.navigationName,
|
|
6793
|
+
depth: navItem.depth,
|
|
6794
|
+
maxDepth: navItem.maxDepth
|
|
6795
|
+
}
|
|
6796
|
+
}));
|
|
6797
|
+
}
|
|
6798
|
+
function checkNotInNavigation({ routes: routes2, navItems }) {
|
|
6799
|
+
const routesInNavigation = new Set(navItems.map((navItem) => navItem.routeDocumentId));
|
|
6800
|
+
return routes2.filter((route2) => route2.type === "internal" && !routesInNavigation.has(route2.documentId)).map((route2) => ({
|
|
6801
|
+
check: "notInNavigation",
|
|
6802
|
+
severity: "info",
|
|
6803
|
+
routeDocumentId: route2.documentId
|
|
6804
|
+
}));
|
|
6805
|
+
}
|
|
6806
|
+
function checkEmptyWrappers({ routes: routes2, navItems }) {
|
|
6807
|
+
const wrapperRouteIds = new Set(
|
|
6808
|
+
routes2.filter((route2) => route2.type === "wrapper").map((route2) => route2.documentId)
|
|
6809
|
+
);
|
|
6810
|
+
return navItems.filter((navItem) => wrapperRouteIds.has(navItem.routeDocumentId) && !navItem.hasChildren).map((navItem) => ({
|
|
6811
|
+
check: "emptyWrapper",
|
|
6812
|
+
severity: "info",
|
|
6813
|
+
routeDocumentId: navItem.routeDocumentId,
|
|
6814
|
+
details: { navigationName: navItem.navigationName }
|
|
6815
|
+
}));
|
|
6816
|
+
}
|
|
6817
|
+
function runHealthChecks(data) {
|
|
6818
|
+
return [
|
|
6819
|
+
checkPathConflicts,
|
|
6820
|
+
checkOrphanedRoutes,
|
|
6821
|
+
checkBlacklistedPaths,
|
|
6822
|
+
checkInvalidExternalUrls,
|
|
6823
|
+
checkUnpublishedInNavigation,
|
|
6824
|
+
checkTooDeepItems,
|
|
6825
|
+
checkNotInNavigation,
|
|
6826
|
+
checkEmptyWrappers
|
|
6827
|
+
].flatMap((check) => check(data));
|
|
6828
|
+
}
|
|
6829
|
+
async function getHealthNavItems() {
|
|
6830
|
+
const navigations = await strapi.documents(waNavigation).findMany({
|
|
6831
|
+
fields: ["name", "maxDepth"],
|
|
6832
|
+
populate: {
|
|
6833
|
+
items: {
|
|
6834
|
+
fields: ["documentId", "order"],
|
|
6835
|
+
populate: {
|
|
6836
|
+
parent: { fields: ["documentId"] },
|
|
6837
|
+
route: { fields: ["documentId"] }
|
|
6838
|
+
}
|
|
6839
|
+
}
|
|
6840
|
+
}
|
|
6841
|
+
});
|
|
6842
|
+
return navigations.flatMap((navigation2) => {
|
|
6843
|
+
const parentIds = new Set(
|
|
6844
|
+
(navigation2.items ?? []).map((item) => item.parent?.documentId).filter(Boolean)
|
|
6845
|
+
);
|
|
6846
|
+
const { items } = buildStructuredNavigation(navigation2, "flat");
|
|
6847
|
+
return (items ?? []).filter((item) => item.route?.documentId).map((item) => ({
|
|
6848
|
+
routeDocumentId: item.route.documentId,
|
|
6849
|
+
navigationName: navigation2.name,
|
|
6850
|
+
depth: item.depth ?? 0,
|
|
6851
|
+
maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
6852
|
+
hasChildren: parentIds.has(item.documentId)
|
|
6853
|
+
}));
|
|
6854
|
+
});
|
|
6855
|
+
}
|
|
6856
|
+
async function getExistingDocumentIds(routes2, existingContentTypes) {
|
|
6857
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
6858
|
+
for (const route2 of routes2) {
|
|
6859
|
+
if (route2.type !== "internal" || !existingContentTypes.has(route2.relatedContentType)) continue;
|
|
6860
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
6861
|
+
documentIds.push(route2.relatedDocumentId);
|
|
6862
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
6863
|
+
}
|
|
6864
|
+
const existing = /* @__PURE__ */ new Map();
|
|
6865
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
6866
|
+
const entries = await strapi.documents(uid).findMany({
|
|
6867
|
+
filters: { documentId: { $in: documentIds } },
|
|
6868
|
+
fields: ["documentId"]
|
|
6869
|
+
});
|
|
6870
|
+
existing.set(uid, new Set(entries.map((entry) => entry.documentId)));
|
|
6871
|
+
}
|
|
6872
|
+
return existing;
|
|
6873
|
+
}
|
|
6874
|
+
const health = () => ({
|
|
6875
|
+
async getHealthReport() {
|
|
6876
|
+
const routes2 = await strapi.documents(waRoute).findMany({
|
|
6877
|
+
fields: [
|
|
6878
|
+
"title",
|
|
6879
|
+
"path",
|
|
6880
|
+
"canonicalPath",
|
|
6881
|
+
"uidPath",
|
|
6882
|
+
"type",
|
|
6883
|
+
"relatedContentType",
|
|
6884
|
+
"relatedDocumentId"
|
|
6885
|
+
]
|
|
6886
|
+
});
|
|
6887
|
+
const config2 = await getAdminService().getConfig();
|
|
6888
|
+
const existingContentTypes = new Set(Object.keys(strapi.contentTypes));
|
|
6889
|
+
const [navItems, existingDocumentIds, documentStatuses] = await Promise.all([
|
|
6890
|
+
getHealthNavItems(),
|
|
6891
|
+
getExistingDocumentIds(routes2, existingContentTypes),
|
|
6892
|
+
getDocumentStatuses(routes2)
|
|
6893
|
+
]);
|
|
6894
|
+
const draftOnlyDocumentIds = new Set(
|
|
6895
|
+
[...documentStatuses].filter(([, status]) => status === "draft").map(([id]) => id)
|
|
6896
|
+
);
|
|
6897
|
+
const issues = runHealthChecks({
|
|
6898
|
+
routes: routes2,
|
|
6899
|
+
navItems,
|
|
6900
|
+
existingContentTypes,
|
|
6901
|
+
enabledContentTypes: new Set(config2?.selectedContentTypes?.map((type) => type.uid) ?? []),
|
|
6902
|
+
existingDocumentIds,
|
|
6903
|
+
draftOnlyDocumentIds,
|
|
6904
|
+
routeBlacklist: normalizeRouteBlacklist(config2?.routeBlacklist)
|
|
6905
|
+
});
|
|
6906
|
+
return { issues, checkedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
6907
|
+
}
|
|
6908
|
+
});
|
|
6379
6909
|
const services = {
|
|
6380
6910
|
admin,
|
|
6381
|
-
client
|
|
6911
|
+
client,
|
|
6912
|
+
health
|
|
6382
6913
|
};
|
|
6383
6914
|
const index = {
|
|
6384
6915
|
register,
|