@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errors } from "@strapi/utils";
|
|
1
|
+
import { errors, contentTypes as contentTypes$1 } from "@strapi/utils";
|
|
2
2
|
function transformToUrl(input, replaceSlash = true) {
|
|
3
3
|
const specialCharMap = {
|
|
4
4
|
ü: "ue",
|
|
@@ -36,6 +36,7 @@ const PLUGIN_ID = pluginPkg.strapi.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plug
|
|
|
36
36
|
const waNavigation = `plugin::${PLUGIN_ID}.navigation`;
|
|
37
37
|
const waNavItem = `plugin::${PLUGIN_ID}.navitem`;
|
|
38
38
|
const waRoute = `plugin::${PLUGIN_ID}.route`;
|
|
39
|
+
const DEFAULT_NAVIGATION_MAX_DEPTH = 1;
|
|
39
40
|
async function checkPathExists(path, excludeDocumentId) {
|
|
40
41
|
const filters = {
|
|
41
42
|
$or: [{ path }, { uidPath: path }, { canonicalPath: path }]
|
|
@@ -90,6 +91,9 @@ function getAdminService() {
|
|
|
90
91
|
function getClientService() {
|
|
91
92
|
return strapi.plugin(PLUGIN_ID)?.service("client");
|
|
92
93
|
}
|
|
94
|
+
function getHealthService() {
|
|
95
|
+
return strapi.plugin(PLUGIN_ID)?.service("health");
|
|
96
|
+
}
|
|
93
97
|
function reduceDepthOfOrphanedItems(navigationItems, itemId) {
|
|
94
98
|
const navigationItemsCopy = JSON.parse(JSON.stringify(navigationItems));
|
|
95
99
|
const startItemIndex = navigationItemsCopy.findIndex(
|
|
@@ -4438,6 +4442,14 @@ async function buildNavigationPath({
|
|
|
4438
4442
|
const validatedPath = await duplicateCheck(newPath, routeDocumentId);
|
|
4439
4443
|
return validatedPath;
|
|
4440
4444
|
}
|
|
4445
|
+
async function buildItemPath({
|
|
4446
|
+
slug,
|
|
4447
|
+
routeDocumentId,
|
|
4448
|
+
calculatedParent
|
|
4449
|
+
}) {
|
|
4450
|
+
const path = await buildNavigationPath({ slug, routeDocumentId, calculatedParent });
|
|
4451
|
+
return { path, slug: path.split("/").pop() ?? slug };
|
|
4452
|
+
}
|
|
4441
4453
|
async function handleItemDeletion(navigationItems) {
|
|
4442
4454
|
const errors2 = [];
|
|
4443
4455
|
let items = [...navigationItems];
|
|
@@ -4523,15 +4535,15 @@ async function handleItemUpdate({
|
|
|
4523
4535
|
});
|
|
4524
4536
|
if (!route2)
|
|
4525
4537
|
throw new Error(`Related route not found for new navigation item '${item.route.title}'`);
|
|
4526
|
-
const path = await
|
|
4527
|
-
slug: item.route.slug,
|
|
4538
|
+
const { path, slug } = await buildItemPath({
|
|
4539
|
+
slug: transformToUrl(item.route.slug),
|
|
4528
4540
|
routeDocumentId: route2.documentId,
|
|
4529
4541
|
calculatedParent
|
|
4530
4542
|
});
|
|
4531
4543
|
assertPathAllowed(path, await getRouteBlacklist());
|
|
4532
4544
|
await updateRoute(route2.documentId, {
|
|
4533
4545
|
title: item.route.title,
|
|
4534
|
-
slug
|
|
4546
|
+
slug,
|
|
4535
4547
|
path,
|
|
4536
4548
|
isOverride: path !== route2.canonicalPath
|
|
4537
4549
|
});
|
|
@@ -4559,12 +4571,13 @@ async function handleItemUpdate({
|
|
|
4559
4571
|
});
|
|
4560
4572
|
if (!route2)
|
|
4561
4573
|
throw new Error(`Related route not found for navigation item '${item.route.title}'`);
|
|
4562
|
-
const
|
|
4563
|
-
const
|
|
4564
|
-
|
|
4574
|
+
const changedSlug = item.clientModifications?.slug;
|
|
4575
|
+
const requestedSlug = changedSlug ? isInternal ? transformToUrl(changedSlug) : changedSlug : item.route.slug;
|
|
4576
|
+
const { path, slug } = isInternal ? await buildItemPath({
|
|
4577
|
+
slug: requestedSlug,
|
|
4565
4578
|
routeDocumentId: route2.documentId,
|
|
4566
4579
|
calculatedParent
|
|
4567
|
-
}) : slug;
|
|
4580
|
+
}) : { path: requestedSlug, slug: requestedSlug };
|
|
4568
4581
|
const isOverride = path !== route2.canonicalPath;
|
|
4569
4582
|
if (needsRouteUpdate) {
|
|
4570
4583
|
if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
|
|
@@ -4982,6 +4995,38 @@ async function getPublishedDocumentIds(routes2) {
|
|
|
4982
4995
|
}
|
|
4983
4996
|
return publishedDocumentIds;
|
|
4984
4997
|
}
|
|
4998
|
+
async function getDocumentStatuses(routes2) {
|
|
4999
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
5000
|
+
for (const route2 of routes2) {
|
|
5001
|
+
if (!route2?.relatedContentType || !route2.relatedDocumentId) continue;
|
|
5002
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
5003
|
+
documentIds.push(route2.relatedDocumentId);
|
|
5004
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
5005
|
+
}
|
|
5006
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
5007
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
5008
|
+
const contentType = strapi.contentTypes[uid];
|
|
5009
|
+
if (!contentType || !contentTypes$1.hasDraftAndPublish(contentType)) continue;
|
|
5010
|
+
const query = {
|
|
5011
|
+
filters: { documentId: { $in: documentIds } },
|
|
5012
|
+
fields: ["documentId", "updatedAt"]
|
|
5013
|
+
};
|
|
5014
|
+
const [drafts, published] = await Promise.all([
|
|
5015
|
+
strapi.documents(uid).findMany({ ...query, status: "draft" }),
|
|
5016
|
+
strapi.documents(uid).findMany({ ...query, status: "published" })
|
|
5017
|
+
]);
|
|
5018
|
+
const publishedUpdatedAt = new Map(
|
|
5019
|
+
published.map((entry) => [entry.documentId, new Date(entry.updatedAt).getTime()])
|
|
5020
|
+
);
|
|
5021
|
+
drafts.forEach((draft) => {
|
|
5022
|
+
const publishedAt = publishedUpdatedAt.get(draft.documentId);
|
|
5023
|
+
if (publishedAt === void 0) return statuses.set(draft.documentId, "draft");
|
|
5024
|
+
const isModified = new Date(draft.updatedAt).getTime() > publishedAt;
|
|
5025
|
+
statuses.set(draft.documentId, isModified ? "modified" : "published");
|
|
5026
|
+
});
|
|
5027
|
+
}
|
|
5028
|
+
return statuses;
|
|
5029
|
+
}
|
|
4985
5030
|
const migration_001_canonical_path = {
|
|
4986
5031
|
version: "001",
|
|
4987
5032
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -5132,10 +5177,25 @@ const migration_003_route_source_field = {
|
|
|
5132
5177
|
);
|
|
5133
5178
|
}
|
|
5134
5179
|
};
|
|
5180
|
+
const migration_004_navigation_max_depth = {
|
|
5181
|
+
version: "004",
|
|
5182
|
+
description: "Move the global navigation max depth of the config to every navigation",
|
|
5183
|
+
async up(strapi2) {
|
|
5184
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5185
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
5186
|
+
const maxDepth = config2?.navigation?.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
5187
|
+
const { count } = await strapi2.db.query(waNavigation).updateMany({
|
|
5188
|
+
where: { maxDepth: { $null: true } },
|
|
5189
|
+
data: { maxDepth }
|
|
5190
|
+
});
|
|
5191
|
+
strapi2.log.info(`[webatlas] Set the max depth ${maxDepth} for ${count} navigation(s)`);
|
|
5192
|
+
}
|
|
5193
|
+
};
|
|
5135
5194
|
const migrations = [
|
|
5136
5195
|
migration_001_canonical_path,
|
|
5137
5196
|
migration_002_webatlas_json_field,
|
|
5138
|
-
migration_003_route_source_field
|
|
5197
|
+
migration_003_route_source_field,
|
|
5198
|
+
migration_004_navigation_max_depth
|
|
5139
5199
|
];
|
|
5140
5200
|
const runMigrations = async (strapi2) => {
|
|
5141
5201
|
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
@@ -5173,9 +5233,37 @@ function registerPermissions(strapi2) {
|
|
|
5173
5233
|
const actions = [
|
|
5174
5234
|
{
|
|
5175
5235
|
section: "plugins",
|
|
5176
|
-
displayName: "
|
|
5177
|
-
uid: "
|
|
5178
|
-
subCategory: "
|
|
5236
|
+
displayName: "Read navigations",
|
|
5237
|
+
uid: "navigation.read",
|
|
5238
|
+
subCategory: "Navigation",
|
|
5239
|
+
pluginName: PLUGIN_ID
|
|
5240
|
+
},
|
|
5241
|
+
{
|
|
5242
|
+
section: "plugins",
|
|
5243
|
+
displayName: "Create navigations",
|
|
5244
|
+
uid: "navigation.create",
|
|
5245
|
+
subCategory: "Navigation",
|
|
5246
|
+
pluginName: PLUGIN_ID
|
|
5247
|
+
},
|
|
5248
|
+
{
|
|
5249
|
+
section: "plugins",
|
|
5250
|
+
displayName: "Edit navigations",
|
|
5251
|
+
uid: "navigation.update",
|
|
5252
|
+
subCategory: "Navigation",
|
|
5253
|
+
pluginName: PLUGIN_ID
|
|
5254
|
+
},
|
|
5255
|
+
{
|
|
5256
|
+
section: "plugins",
|
|
5257
|
+
displayName: "Delete navigations",
|
|
5258
|
+
uid: "navigation.delete",
|
|
5259
|
+
subCategory: "Navigation",
|
|
5260
|
+
pluginName: PLUGIN_ID
|
|
5261
|
+
},
|
|
5262
|
+
{
|
|
5263
|
+
section: "plugins",
|
|
5264
|
+
displayName: "Edit navigation items",
|
|
5265
|
+
uid: "navigation.edit-items",
|
|
5266
|
+
subCategory: "Navigation",
|
|
5179
5267
|
pluginName: PLUGIN_ID
|
|
5180
5268
|
},
|
|
5181
5269
|
{
|
|
@@ -5187,15 +5275,29 @@ function registerPermissions(strapi2) {
|
|
|
5187
5275
|
},
|
|
5188
5276
|
{
|
|
5189
5277
|
section: "plugins",
|
|
5190
|
-
displayName: "
|
|
5191
|
-
uid: "settings.general",
|
|
5278
|
+
displayName: "Read general settings",
|
|
5279
|
+
uid: "settings.general.read",
|
|
5280
|
+
subCategory: "Settings",
|
|
5281
|
+
pluginName: PLUGIN_ID
|
|
5282
|
+
},
|
|
5283
|
+
{
|
|
5284
|
+
section: "plugins",
|
|
5285
|
+
displayName: "Update general settings",
|
|
5286
|
+
uid: "settings.general.update",
|
|
5192
5287
|
subCategory: "Settings",
|
|
5193
5288
|
pluginName: PLUGIN_ID
|
|
5194
5289
|
},
|
|
5195
5290
|
{
|
|
5196
5291
|
section: "plugins",
|
|
5197
|
-
displayName: "
|
|
5198
|
-
uid: "settings.navigation",
|
|
5292
|
+
displayName: "Read navigation settings",
|
|
5293
|
+
uid: "settings.navigation.read",
|
|
5294
|
+
subCategory: "Settings",
|
|
5295
|
+
pluginName: PLUGIN_ID
|
|
5296
|
+
},
|
|
5297
|
+
{
|
|
5298
|
+
section: "plugins",
|
|
5299
|
+
displayName: "Update navigation settings",
|
|
5300
|
+
uid: "settings.navigation.update",
|
|
5199
5301
|
subCategory: "Settings",
|
|
5200
5302
|
pluginName: PLUGIN_ID
|
|
5201
5303
|
},
|
|
@@ -5205,6 +5307,13 @@ function registerPermissions(strapi2) {
|
|
|
5205
5307
|
uid: "cm.aside",
|
|
5206
5308
|
subCategory: "Content Manager",
|
|
5207
5309
|
pluginName: PLUGIN_ID
|
|
5310
|
+
},
|
|
5311
|
+
{
|
|
5312
|
+
section: "plugins",
|
|
5313
|
+
displayName: "Edit path (parent route and override)",
|
|
5314
|
+
uid: "cm.edit-path",
|
|
5315
|
+
subCategory: "Content Manager",
|
|
5316
|
+
pluginName: PLUGIN_ID
|
|
5208
5317
|
}
|
|
5209
5318
|
];
|
|
5210
5319
|
strapi2.admin.services.permission.actionProvider.registerMany(actions);
|
|
@@ -5214,13 +5323,10 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5214
5323
|
const config2 = await pluginStore.get({
|
|
5215
5324
|
key: "config"
|
|
5216
5325
|
});
|
|
5326
|
+
const { navigation: _legacyNavigation, ...currentConfig } = config2 ?? {};
|
|
5217
5327
|
let newConfig = {
|
|
5218
|
-
...
|
|
5328
|
+
...currentConfig,
|
|
5219
5329
|
selectedContentTypes: [],
|
|
5220
|
-
navigation: {
|
|
5221
|
-
maxDepth: config2?.navigation?.maxDepth || 1,
|
|
5222
|
-
...config2?.navigation
|
|
5223
|
-
},
|
|
5224
5330
|
migrationVersion: config2?.migrationVersion || "0"
|
|
5225
5331
|
};
|
|
5226
5332
|
enabledContentTypes.forEach((type) => {
|
|
@@ -5237,6 +5343,21 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5237
5343
|
}
|
|
5238
5344
|
return newConfig;
|
|
5239
5345
|
}
|
|
5346
|
+
async function getDefaultRouteData(strapi2, uid, data) {
|
|
5347
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5348
|
+
const currentConfig = await pluginStore.get({ key: "config" });
|
|
5349
|
+
const ctSettings = currentConfig?.selectedContentTypes.find((ct) => ct.uid === uid);
|
|
5350
|
+
const sourceValue = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5351
|
+
if (typeof sourceValue !== "string" || !sourceValue.trim()) return void 0;
|
|
5352
|
+
const defaultParent = ctSettings.defaultParentRoute ? await strapi2.documents(waRoute).findFirst({
|
|
5353
|
+
filters: { relatedDocumentId: ctSettings.defaultParentRoute }
|
|
5354
|
+
}) : null;
|
|
5355
|
+
return {
|
|
5356
|
+
slug: transformToUrl(sourceValue),
|
|
5357
|
+
parentDocumentId: defaultParent?.documentId ?? null,
|
|
5358
|
+
isOverride: false
|
|
5359
|
+
};
|
|
5360
|
+
}
|
|
5240
5361
|
function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
5241
5362
|
const actions = ["create", "update", "delete"];
|
|
5242
5363
|
strapi2.documents.use(async (context, next) => {
|
|
@@ -5246,12 +5367,15 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5246
5367
|
const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
|
|
5247
5368
|
const requestContext = strapi2.requestContext.get();
|
|
5248
5369
|
const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
|
|
5249
|
-
|
|
5370
|
+
const userAbility = requestContext?.state?.userAbility;
|
|
5371
|
+
const canUseAside = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.aside`);
|
|
5372
|
+
const canEditPath = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.edit-path`);
|
|
5373
|
+
if ((context.action === "create" || context.action === "update") && (!isRouteDataAllowed || !canUseAside)) {
|
|
5250
5374
|
delete context.params.data?.webatlas;
|
|
5251
5375
|
}
|
|
5252
5376
|
if (context.action === "create") {
|
|
5253
5377
|
const data = context.params.data;
|
|
5254
|
-
const
|
|
5378
|
+
const webatlas = data.webatlas && canEditPath ? data.webatlas : await getDefaultRouteData(strapi2, context.uid, data);
|
|
5255
5379
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5256
5380
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5257
5381
|
if (!transformedSlug) return next();
|
|
@@ -5307,17 +5431,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5307
5431
|
if (context.action === "update") {
|
|
5308
5432
|
const data = context.params.data;
|
|
5309
5433
|
const { documentId } = context.params;
|
|
5310
|
-
const
|
|
5434
|
+
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5435
|
+
filters: {
|
|
5436
|
+
relatedDocumentId: documentId
|
|
5437
|
+
},
|
|
5438
|
+
populate: ["parent"]
|
|
5439
|
+
});
|
|
5440
|
+
let webatlas = data.webatlas;
|
|
5441
|
+
if (!relatedRoute && (!webatlas || !canEditPath)) {
|
|
5442
|
+
webatlas = await getDefaultRouteData(strapi2, context.uid, data);
|
|
5443
|
+
} else if (relatedRoute && webatlas && !canEditPath) {
|
|
5444
|
+
const sourceValue2 = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5445
|
+
webatlas = !relatedRoute.isOverride && typeof sourceValue2 === "string" && sourceValue2.trim() ? {
|
|
5446
|
+
slug: transformToUrl(sourceValue2),
|
|
5447
|
+
parentDocumentId: relatedRoute.parent?.documentId ?? null,
|
|
5448
|
+
isOverride: false
|
|
5449
|
+
} : void 0;
|
|
5450
|
+
}
|
|
5311
5451
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5312
5452
|
if (!slug) {
|
|
5313
5453
|
const result3 = await next();
|
|
5314
5454
|
return result3;
|
|
5315
5455
|
}
|
|
5316
|
-
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5317
|
-
filters: {
|
|
5318
|
-
relatedDocumentId: documentId
|
|
5319
|
-
}
|
|
5320
|
-
});
|
|
5321
5456
|
let parent = null;
|
|
5322
5457
|
let isValid = false;
|
|
5323
5458
|
if (parentDocumentId) {
|
|
@@ -5519,9 +5654,6 @@ const register = ({ strapi: strapi2 }) => {
|
|
|
5519
5654
|
const config = {
|
|
5520
5655
|
default: {
|
|
5521
5656
|
selectedContentTypes: [],
|
|
5522
|
-
navigation: {
|
|
5523
|
-
maxDepth: 1
|
|
5524
|
-
},
|
|
5525
5657
|
routeBlacklist: []
|
|
5526
5658
|
},
|
|
5527
5659
|
validator() {
|
|
@@ -5666,6 +5798,13 @@ const schema$1 = {
|
|
|
5666
5798
|
default: false,
|
|
5667
5799
|
configurable: false
|
|
5668
5800
|
},
|
|
5801
|
+
// Depth index of the deepest allowed level, 0 = root only. Only changed in the plugin settings
|
|
5802
|
+
maxDepth: {
|
|
5803
|
+
type: "integer",
|
|
5804
|
+
default: DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
5805
|
+
min: 0,
|
|
5806
|
+
configurable: false
|
|
5807
|
+
},
|
|
5669
5808
|
items: {
|
|
5670
5809
|
type: "relation",
|
|
5671
5810
|
configurable: false,
|
|
@@ -5750,11 +5889,29 @@ const admin$2 = () => ({
|
|
|
5750
5889
|
async getAllRoutes(ctx) {
|
|
5751
5890
|
return await getAdminService().getAllRoutes();
|
|
5752
5891
|
},
|
|
5892
|
+
async getHealthReport(ctx) {
|
|
5893
|
+
return await getHealthService().getHealthReport();
|
|
5894
|
+
},
|
|
5753
5895
|
async getRelatedRoute(ctx) {
|
|
5754
5896
|
const { documentId } = ctx.query;
|
|
5755
5897
|
if (!documentId) throw new errors.ValidationError("Route documentId is required");
|
|
5756
5898
|
return await getAdminService().getRelatedRoute(documentId);
|
|
5757
5899
|
},
|
|
5900
|
+
async getRelatedRoutes(ctx) {
|
|
5901
|
+
const documentIds = String(ctx.query.documentIds || "").split(",").filter(Boolean);
|
|
5902
|
+
if (documentIds.length === 0) throw new errors.ValidationError("documentIds are required");
|
|
5903
|
+
if (documentIds.length > 100)
|
|
5904
|
+
throw new errors.ValidationError("At most 100 documentIds are allowed");
|
|
5905
|
+
return await getAdminService().getRelatedRoutes(documentIds);
|
|
5906
|
+
},
|
|
5907
|
+
async getNavigationDepths(ctx) {
|
|
5908
|
+
return await getAdminService().getNavigationDepths();
|
|
5909
|
+
},
|
|
5910
|
+
async updateNavigationDepths(ctx) {
|
|
5911
|
+
const { data } = ctx.request.body;
|
|
5912
|
+
if (!Array.isArray(data)) throw new errors.ValidationError("Navigation depths are required");
|
|
5913
|
+
return await getAdminService().updateNavigationDepths(data);
|
|
5914
|
+
},
|
|
5758
5915
|
async getProhibitedRouteIds(ctx) {
|
|
5759
5916
|
const { documentId } = ctx.params;
|
|
5760
5917
|
return await getAdminService().getProhibitedRouteIds(documentId);
|
|
@@ -5870,9 +6027,9 @@ const admin$1 = {
|
|
|
5870
6027
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5871
6028
|
config: {
|
|
5872
6029
|
actions: [
|
|
5873
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5874
|
-
`plugin::${PLUGIN_ID}.settings.navigation`,
|
|
5875
|
-
`plugin::${PLUGIN_ID}.
|
|
6030
|
+
`plugin::${PLUGIN_ID}.settings.general.read`,
|
|
6031
|
+
`plugin::${PLUGIN_ID}.settings.navigation.read`,
|
|
6032
|
+
`plugin::${PLUGIN_ID}.navigation.read`,
|
|
5876
6033
|
`plugin::${PLUGIN_ID}.cm.aside`
|
|
5877
6034
|
]
|
|
5878
6035
|
}
|
|
@@ -5890,10 +6047,7 @@ const admin$1 = {
|
|
|
5890
6047
|
{
|
|
5891
6048
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5892
6049
|
config: {
|
|
5893
|
-
actions: [
|
|
5894
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5895
|
-
`plugin::${PLUGIN_ID}.settings.navigation`
|
|
5896
|
-
]
|
|
6050
|
+
actions: [`plugin::${PLUGIN_ID}.settings.general.update`]
|
|
5897
6051
|
}
|
|
5898
6052
|
}
|
|
5899
6053
|
]
|
|
@@ -5916,6 +6070,22 @@ const admin$1 = {
|
|
|
5916
6070
|
]
|
|
5917
6071
|
}
|
|
5918
6072
|
},
|
|
6073
|
+
{
|
|
6074
|
+
method: "GET",
|
|
6075
|
+
path: "/health",
|
|
6076
|
+
handler: "admin.getHealthReport",
|
|
6077
|
+
config: {
|
|
6078
|
+
policies: [
|
|
6079
|
+
"admin::isAuthenticatedAdmin",
|
|
6080
|
+
{
|
|
6081
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6082
|
+
config: {
|
|
6083
|
+
actions: [`plugin::${PLUGIN_ID}.page.routes`]
|
|
6084
|
+
}
|
|
6085
|
+
}
|
|
6086
|
+
]
|
|
6087
|
+
}
|
|
6088
|
+
},
|
|
5919
6089
|
{
|
|
5920
6090
|
method: "GET",
|
|
5921
6091
|
path: "/route/related",
|
|
@@ -5926,7 +6096,56 @@ const admin$1 = {
|
|
|
5926
6096
|
{
|
|
5927
6097
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5928
6098
|
config: {
|
|
5929
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6099
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6100
|
+
}
|
|
6101
|
+
}
|
|
6102
|
+
]
|
|
6103
|
+
}
|
|
6104
|
+
},
|
|
6105
|
+
// The max depth is a structural setting, so it is only changed in the plugin settings
|
|
6106
|
+
{
|
|
6107
|
+
method: "GET",
|
|
6108
|
+
path: "/settings/navigation-depths",
|
|
6109
|
+
handler: "admin.getNavigationDepths",
|
|
6110
|
+
config: {
|
|
6111
|
+
policies: [
|
|
6112
|
+
"admin::isAuthenticatedAdmin",
|
|
6113
|
+
{
|
|
6114
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6115
|
+
config: {
|
|
6116
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.read`]
|
|
6117
|
+
}
|
|
6118
|
+
}
|
|
6119
|
+
]
|
|
6120
|
+
}
|
|
6121
|
+
},
|
|
6122
|
+
{
|
|
6123
|
+
method: "PUT",
|
|
6124
|
+
path: "/settings/navigation-depths",
|
|
6125
|
+
handler: "admin.updateNavigationDepths",
|
|
6126
|
+
config: {
|
|
6127
|
+
policies: [
|
|
6128
|
+
"admin::isAuthenticatedAdmin",
|
|
6129
|
+
{
|
|
6130
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6131
|
+
config: {
|
|
6132
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.update`]
|
|
6133
|
+
}
|
|
6134
|
+
}
|
|
6135
|
+
]
|
|
6136
|
+
}
|
|
6137
|
+
},
|
|
6138
|
+
{
|
|
6139
|
+
method: "GET",
|
|
6140
|
+
path: "/route/related/batch",
|
|
6141
|
+
handler: "admin.getRelatedRoutes",
|
|
6142
|
+
config: {
|
|
6143
|
+
policies: [
|
|
6144
|
+
"admin::isAuthenticatedAdmin",
|
|
6145
|
+
{
|
|
6146
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6147
|
+
config: {
|
|
6148
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5930
6149
|
}
|
|
5931
6150
|
}
|
|
5932
6151
|
]
|
|
@@ -5958,7 +6177,7 @@ const admin$1 = {
|
|
|
5958
6177
|
{
|
|
5959
6178
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5960
6179
|
config: {
|
|
5961
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6180
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5962
6181
|
}
|
|
5963
6182
|
}
|
|
5964
6183
|
]
|
|
@@ -5975,7 +6194,7 @@ const admin$1 = {
|
|
|
5975
6194
|
{
|
|
5976
6195
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5977
6196
|
config: {
|
|
5978
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6197
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5979
6198
|
}
|
|
5980
6199
|
}
|
|
5981
6200
|
]
|
|
@@ -5991,7 +6210,7 @@ const admin$1 = {
|
|
|
5991
6210
|
{
|
|
5992
6211
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5993
6212
|
config: {
|
|
5994
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6213
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.create`]
|
|
5995
6214
|
}
|
|
5996
6215
|
}
|
|
5997
6216
|
]
|
|
@@ -6007,7 +6226,7 @@ const admin$1 = {
|
|
|
6007
6226
|
{
|
|
6008
6227
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6009
6228
|
config: {
|
|
6010
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6229
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.update`]
|
|
6011
6230
|
}
|
|
6012
6231
|
}
|
|
6013
6232
|
]
|
|
@@ -6023,7 +6242,7 @@ const admin$1 = {
|
|
|
6023
6242
|
{
|
|
6024
6243
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6025
6244
|
config: {
|
|
6026
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6245
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.edit-items`]
|
|
6027
6246
|
}
|
|
6028
6247
|
}
|
|
6029
6248
|
]
|
|
@@ -6039,7 +6258,7 @@ const admin$1 = {
|
|
|
6039
6258
|
{
|
|
6040
6259
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6041
6260
|
config: {
|
|
6042
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6261
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.delete`]
|
|
6043
6262
|
}
|
|
6044
6263
|
}
|
|
6045
6264
|
]
|
|
@@ -6056,7 +6275,7 @@ const admin$1 = {
|
|
|
6056
6275
|
{
|
|
6057
6276
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6058
6277
|
config: {
|
|
6059
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6278
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6060
6279
|
}
|
|
6061
6280
|
}
|
|
6062
6281
|
]
|
|
@@ -6089,6 +6308,36 @@ const routes = {
|
|
|
6089
6308
|
admin: admin$1,
|
|
6090
6309
|
"content-api": client$1
|
|
6091
6310
|
};
|
|
6311
|
+
async function getNavigationDepths() {
|
|
6312
|
+
const navigations = await strapi.documents(waNavigation).findMany({
|
|
6313
|
+
populate: ["items", "items.parent"]
|
|
6314
|
+
});
|
|
6315
|
+
return navigations.map((navigation2) => {
|
|
6316
|
+
const { items } = buildStructuredNavigation(navigation2, "flat");
|
|
6317
|
+
return {
|
|
6318
|
+
documentId: navigation2.documentId,
|
|
6319
|
+
name: navigation2.name,
|
|
6320
|
+
maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
6321
|
+
deepestDepth: Math.max(-1, ...(items ?? []).map((item) => item.depth ?? 0))
|
|
6322
|
+
};
|
|
6323
|
+
});
|
|
6324
|
+
}
|
|
6325
|
+
async function assertItemDepths(navigationId, navigationItems) {
|
|
6326
|
+
const navigation2 = await strapi.documents(waNavigation).findOne({
|
|
6327
|
+
documentId: navigationId,
|
|
6328
|
+
fields: ["maxDepth"]
|
|
6329
|
+
});
|
|
6330
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
6331
|
+
const maxDepth = navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
6332
|
+
const tooDeepItem = navigationItems.find(
|
|
6333
|
+
(item) => item.clientModifications?.type !== "delete" && (item.depth ?? 0) > maxDepth
|
|
6334
|
+
);
|
|
6335
|
+
if (tooDeepItem) {
|
|
6336
|
+
throw new errors.ValidationError(
|
|
6337
|
+
`'${tooDeepItem.clientModifications?.title || tooDeepItem.route?.title}' is deeper than the ${maxDepth + 1} level(s) allowed in this navigation`
|
|
6338
|
+
);
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6092
6341
|
const admin = ({ strapi: strapi2 }) => ({
|
|
6093
6342
|
async updateConfig(newConfig) {
|
|
6094
6343
|
if (!newConfig) return;
|
|
@@ -6111,11 +6360,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6111
6360
|
const defaultConfig = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
6112
6361
|
config2 = {
|
|
6113
6362
|
...defaultConfig,
|
|
6114
|
-
...config2
|
|
6115
|
-
navigation: {
|
|
6116
|
-
...defaultConfig.navigation,
|
|
6117
|
-
...config2?.navigation
|
|
6118
|
-
}
|
|
6363
|
+
...config2
|
|
6119
6364
|
};
|
|
6120
6365
|
return config2;
|
|
6121
6366
|
},
|
|
@@ -6125,7 +6370,14 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6125
6370
|
});
|
|
6126
6371
|
},
|
|
6127
6372
|
async getAllRoutes() {
|
|
6128
|
-
return await strapi2.documents(waRoute).findMany(
|
|
6373
|
+
return await strapi2.documents(waRoute).findMany({
|
|
6374
|
+
populate: {
|
|
6375
|
+
navitem: {
|
|
6376
|
+
fields: ["documentId"],
|
|
6377
|
+
populate: { navigation: { fields: ["documentId", "name"] } }
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
});
|
|
6129
6381
|
},
|
|
6130
6382
|
async getRelatedRoute(documentId) {
|
|
6131
6383
|
return await strapi2.db?.query(waRoute).findOne({
|
|
@@ -6135,6 +6387,13 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6135
6387
|
populate: ["parent"]
|
|
6136
6388
|
});
|
|
6137
6389
|
},
|
|
6390
|
+
// Path of the routes linked to the given entries, with one query
|
|
6391
|
+
async getRelatedRoutes(documentIds) {
|
|
6392
|
+
return await strapi2.db?.query(waRoute).findMany({
|
|
6393
|
+
where: { relatedDocumentId: { $in: documentIds } },
|
|
6394
|
+
select: ["relatedDocumentId", "path"]
|
|
6395
|
+
});
|
|
6396
|
+
},
|
|
6138
6397
|
async getProhibitedRouteIds(documentId) {
|
|
6139
6398
|
let route2 = null;
|
|
6140
6399
|
if (documentId) {
|
|
@@ -6179,6 +6438,16 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6179
6438
|
);
|
|
6180
6439
|
}
|
|
6181
6440
|
}
|
|
6441
|
+
const navigations = Array.isArray(navigation2) ? navigation2 : [navigation2];
|
|
6442
|
+
const statuses = await getDocumentStatuses(
|
|
6443
|
+
navigations.flatMap((nav) => (nav.items ?? []).map((item) => item.route))
|
|
6444
|
+
);
|
|
6445
|
+
navigations.forEach(
|
|
6446
|
+
(nav) => nav.items?.forEach((item) => {
|
|
6447
|
+
const status = statuses.get(item.route?.relatedDocumentId);
|
|
6448
|
+
if (status) item.status = status;
|
|
6449
|
+
})
|
|
6450
|
+
);
|
|
6182
6451
|
return navigation2;
|
|
6183
6452
|
},
|
|
6184
6453
|
async createNavigation(name, visible) {
|
|
@@ -6199,6 +6468,28 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6199
6468
|
}
|
|
6200
6469
|
});
|
|
6201
6470
|
},
|
|
6471
|
+
async getNavigationDepths() {
|
|
6472
|
+
return await getNavigationDepths();
|
|
6473
|
+
},
|
|
6474
|
+
async updateNavigationDepths(depths) {
|
|
6475
|
+
const currentDepths = await getNavigationDepths();
|
|
6476
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6477
|
+
const current = currentDepths.find((navigation2) => navigation2.documentId === documentId);
|
|
6478
|
+
if (!current) throw new errors.NotFoundError("Navigation not found");
|
|
6479
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 0) {
|
|
6480
|
+
throw new errors.ValidationError(`Invalid max depth for the navigation '${current.name}'`);
|
|
6481
|
+
}
|
|
6482
|
+
if (maxDepth < current.deepestDepth) {
|
|
6483
|
+
throw new errors.ValidationError(
|
|
6484
|
+
`The navigation '${current.name}' already has items on level ${current.deepestDepth + 1}`
|
|
6485
|
+
);
|
|
6486
|
+
}
|
|
6487
|
+
}
|
|
6488
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6489
|
+
await strapi2.documents(waNavigation).update({ documentId, data: { maxDepth } });
|
|
6490
|
+
}
|
|
6491
|
+
return await getNavigationDepths();
|
|
6492
|
+
},
|
|
6202
6493
|
async deleteNavigation(documentId) {
|
|
6203
6494
|
const navigation2 = await strapi2.documents(waNavigation).findOne({
|
|
6204
6495
|
documentId,
|
|
@@ -6216,6 +6507,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6216
6507
|
},
|
|
6217
6508
|
async updateNavigationItemStructure(navigationId, navigationItems) {
|
|
6218
6509
|
if (!navigationId || !navigationItems) return;
|
|
6510
|
+
await assertItemDepths(navigationId, navigationItems);
|
|
6219
6511
|
const errors2 = [];
|
|
6220
6512
|
let newNavItemsMap = /* @__PURE__ */ new Map();
|
|
6221
6513
|
const deletionResult = await handleItemDeletion(navigationItems);
|
|
@@ -6374,9 +6666,248 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6374
6666
|
return { ...structured, items: entityNavigation };
|
|
6375
6667
|
}
|
|
6376
6668
|
});
|
|
6669
|
+
function checkPathConflicts({ routes: routes2 }) {
|
|
6670
|
+
const routesByValue = /* @__PURE__ */ new Map();
|
|
6671
|
+
for (const route2 of routes2) {
|
|
6672
|
+
if (route2.type === "external") continue;
|
|
6673
|
+
for (const value of [route2.path, route2.canonicalPath, route2.uidPath]) {
|
|
6674
|
+
if (!value) continue;
|
|
6675
|
+
const routesWithValue = routesByValue.get(value) ?? /* @__PURE__ */ new Set();
|
|
6676
|
+
routesWithValue.add(route2);
|
|
6677
|
+
routesByValue.set(value, routesWithValue);
|
|
6678
|
+
}
|
|
6679
|
+
}
|
|
6680
|
+
const issues = [];
|
|
6681
|
+
for (const [value, routesWithValue] of routesByValue) {
|
|
6682
|
+
if (routesWithValue.size < 2) continue;
|
|
6683
|
+
for (const route2 of routesWithValue) {
|
|
6684
|
+
issues.push({
|
|
6685
|
+
check: "pathConflict",
|
|
6686
|
+
severity: "error",
|
|
6687
|
+
routeDocumentId: route2.documentId,
|
|
6688
|
+
details: {
|
|
6689
|
+
value,
|
|
6690
|
+
conflictingRoutes: [...routesWithValue].filter((other) => other !== route2).map((other) => ({ documentId: other.documentId, title: other.title }))
|
|
6691
|
+
}
|
|
6692
|
+
});
|
|
6693
|
+
}
|
|
6694
|
+
}
|
|
6695
|
+
return issues;
|
|
6696
|
+
}
|
|
6697
|
+
function checkOrphanedRoutes({
|
|
6698
|
+
routes: routes2,
|
|
6699
|
+
existingContentTypes,
|
|
6700
|
+
enabledContentTypes,
|
|
6701
|
+
existingDocumentIds
|
|
6702
|
+
}) {
|
|
6703
|
+
const issues = [];
|
|
6704
|
+
for (const route2 of routes2) {
|
|
6705
|
+
if (route2.type !== "internal") continue;
|
|
6706
|
+
const reason = !existingContentTypes.has(route2.relatedContentType) ? "missingContentType" : !enabledContentTypes.has(route2.relatedContentType) ? "disabledContentType" : !existingDocumentIds.get(route2.relatedContentType)?.has(route2.relatedDocumentId) ? "missingDocument" : null;
|
|
6707
|
+
if (reason) {
|
|
6708
|
+
issues.push({
|
|
6709
|
+
check: "orphanedRoute",
|
|
6710
|
+
severity: "error",
|
|
6711
|
+
routeDocumentId: route2.documentId,
|
|
6712
|
+
details: { reason }
|
|
6713
|
+
});
|
|
6714
|
+
}
|
|
6715
|
+
}
|
|
6716
|
+
return issues;
|
|
6717
|
+
}
|
|
6718
|
+
function checkBlacklistedPaths({ routes: routes2, routeBlacklist }) {
|
|
6719
|
+
if (routeBlacklist.length === 0) return [];
|
|
6720
|
+
const issues = [];
|
|
6721
|
+
for (const route2 of routes2) {
|
|
6722
|
+
if (route2.type === "external") continue;
|
|
6723
|
+
const value = [route2.path, route2.canonicalPath].find(
|
|
6724
|
+
(path) => isBlacklistedPath(path, routeBlacklist)
|
|
6725
|
+
);
|
|
6726
|
+
if (value) {
|
|
6727
|
+
issues.push({
|
|
6728
|
+
check: "blacklistedPath",
|
|
6729
|
+
severity: "error",
|
|
6730
|
+
routeDocumentId: route2.documentId,
|
|
6731
|
+
details: { value }
|
|
6732
|
+
});
|
|
6733
|
+
}
|
|
6734
|
+
}
|
|
6735
|
+
return issues;
|
|
6736
|
+
}
|
|
6737
|
+
const VALID_EXTERNAL_PROTOCOLS = ["http:", "https:", "mailto:", "tel:"];
|
|
6738
|
+
function checkInvalidExternalUrls({ routes: routes2 }) {
|
|
6739
|
+
const issues = [];
|
|
6740
|
+
for (const route2 of routes2) {
|
|
6741
|
+
if (route2.type !== "external") continue;
|
|
6742
|
+
let isValid = false;
|
|
6743
|
+
try {
|
|
6744
|
+
isValid = VALID_EXTERNAL_PROTOCOLS.includes(new URL(route2.path).protocol);
|
|
6745
|
+
} catch {
|
|
6746
|
+
isValid = false;
|
|
6747
|
+
}
|
|
6748
|
+
if (!isValid) {
|
|
6749
|
+
issues.push({
|
|
6750
|
+
check: "invalidExternalUrl",
|
|
6751
|
+
severity: "warning",
|
|
6752
|
+
routeDocumentId: route2.documentId,
|
|
6753
|
+
details: { value: route2.path }
|
|
6754
|
+
});
|
|
6755
|
+
}
|
|
6756
|
+
}
|
|
6757
|
+
return issues;
|
|
6758
|
+
}
|
|
6759
|
+
function checkUnpublishedInNavigation({
|
|
6760
|
+
routes: routes2,
|
|
6761
|
+
navItems,
|
|
6762
|
+
draftOnlyDocumentIds
|
|
6763
|
+
}) {
|
|
6764
|
+
const navigationsByRoute = /* @__PURE__ */ new Map();
|
|
6765
|
+
for (const navItem of navItems) {
|
|
6766
|
+
const names = navigationsByRoute.get(navItem.routeDocumentId) ?? /* @__PURE__ */ new Set();
|
|
6767
|
+
names.add(navItem.navigationName);
|
|
6768
|
+
navigationsByRoute.set(navItem.routeDocumentId, names);
|
|
6769
|
+
}
|
|
6770
|
+
const issues = [];
|
|
6771
|
+
for (const route2 of routes2) {
|
|
6772
|
+
if (route2.type !== "internal" || !draftOnlyDocumentIds.has(route2.relatedDocumentId)) continue;
|
|
6773
|
+
for (const navigationName of navigationsByRoute.get(route2.documentId) ?? []) {
|
|
6774
|
+
issues.push({
|
|
6775
|
+
check: "unpublishedInNavigation",
|
|
6776
|
+
severity: "warning",
|
|
6777
|
+
routeDocumentId: route2.documentId,
|
|
6778
|
+
details: { navigationName }
|
|
6779
|
+
});
|
|
6780
|
+
}
|
|
6781
|
+
}
|
|
6782
|
+
return issues;
|
|
6783
|
+
}
|
|
6784
|
+
function checkTooDeepItems({ navItems }) {
|
|
6785
|
+
return navItems.filter((navItem) => navItem.depth > navItem.maxDepth).map((navItem) => ({
|
|
6786
|
+
check: "tooDeepItem",
|
|
6787
|
+
severity: "warning",
|
|
6788
|
+
routeDocumentId: navItem.routeDocumentId,
|
|
6789
|
+
details: {
|
|
6790
|
+
navigationName: navItem.navigationName,
|
|
6791
|
+
depth: navItem.depth,
|
|
6792
|
+
maxDepth: navItem.maxDepth
|
|
6793
|
+
}
|
|
6794
|
+
}));
|
|
6795
|
+
}
|
|
6796
|
+
function checkNotInNavigation({ routes: routes2, navItems }) {
|
|
6797
|
+
const routesInNavigation = new Set(navItems.map((navItem) => navItem.routeDocumentId));
|
|
6798
|
+
return routes2.filter((route2) => route2.type === "internal" && !routesInNavigation.has(route2.documentId)).map((route2) => ({
|
|
6799
|
+
check: "notInNavigation",
|
|
6800
|
+
severity: "info",
|
|
6801
|
+
routeDocumentId: route2.documentId
|
|
6802
|
+
}));
|
|
6803
|
+
}
|
|
6804
|
+
function checkEmptyWrappers({ routes: routes2, navItems }) {
|
|
6805
|
+
const wrapperRouteIds = new Set(
|
|
6806
|
+
routes2.filter((route2) => route2.type === "wrapper").map((route2) => route2.documentId)
|
|
6807
|
+
);
|
|
6808
|
+
return navItems.filter((navItem) => wrapperRouteIds.has(navItem.routeDocumentId) && !navItem.hasChildren).map((navItem) => ({
|
|
6809
|
+
check: "emptyWrapper",
|
|
6810
|
+
severity: "info",
|
|
6811
|
+
routeDocumentId: navItem.routeDocumentId,
|
|
6812
|
+
details: { navigationName: navItem.navigationName }
|
|
6813
|
+
}));
|
|
6814
|
+
}
|
|
6815
|
+
function runHealthChecks(data) {
|
|
6816
|
+
return [
|
|
6817
|
+
checkPathConflicts,
|
|
6818
|
+
checkOrphanedRoutes,
|
|
6819
|
+
checkBlacklistedPaths,
|
|
6820
|
+
checkInvalidExternalUrls,
|
|
6821
|
+
checkUnpublishedInNavigation,
|
|
6822
|
+
checkTooDeepItems,
|
|
6823
|
+
checkNotInNavigation,
|
|
6824
|
+
checkEmptyWrappers
|
|
6825
|
+
].flatMap((check) => check(data));
|
|
6826
|
+
}
|
|
6827
|
+
async function getHealthNavItems() {
|
|
6828
|
+
const navigations = await strapi.documents(waNavigation).findMany({
|
|
6829
|
+
fields: ["name", "maxDepth"],
|
|
6830
|
+
populate: {
|
|
6831
|
+
items: {
|
|
6832
|
+
fields: ["documentId", "order"],
|
|
6833
|
+
populate: {
|
|
6834
|
+
parent: { fields: ["documentId"] },
|
|
6835
|
+
route: { fields: ["documentId"] }
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
}
|
|
6839
|
+
});
|
|
6840
|
+
return navigations.flatMap((navigation2) => {
|
|
6841
|
+
const parentIds = new Set(
|
|
6842
|
+
(navigation2.items ?? []).map((item) => item.parent?.documentId).filter(Boolean)
|
|
6843
|
+
);
|
|
6844
|
+
const { items } = buildStructuredNavigation(navigation2, "flat");
|
|
6845
|
+
return (items ?? []).filter((item) => item.route?.documentId).map((item) => ({
|
|
6846
|
+
routeDocumentId: item.route.documentId,
|
|
6847
|
+
navigationName: navigation2.name,
|
|
6848
|
+
depth: item.depth ?? 0,
|
|
6849
|
+
maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
6850
|
+
hasChildren: parentIds.has(item.documentId)
|
|
6851
|
+
}));
|
|
6852
|
+
});
|
|
6853
|
+
}
|
|
6854
|
+
async function getExistingDocumentIds(routes2, existingContentTypes) {
|
|
6855
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
6856
|
+
for (const route2 of routes2) {
|
|
6857
|
+
if (route2.type !== "internal" || !existingContentTypes.has(route2.relatedContentType)) continue;
|
|
6858
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
6859
|
+
documentIds.push(route2.relatedDocumentId);
|
|
6860
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
6861
|
+
}
|
|
6862
|
+
const existing = /* @__PURE__ */ new Map();
|
|
6863
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
6864
|
+
const entries = await strapi.documents(uid).findMany({
|
|
6865
|
+
filters: { documentId: { $in: documentIds } },
|
|
6866
|
+
fields: ["documentId"]
|
|
6867
|
+
});
|
|
6868
|
+
existing.set(uid, new Set(entries.map((entry) => entry.documentId)));
|
|
6869
|
+
}
|
|
6870
|
+
return existing;
|
|
6871
|
+
}
|
|
6872
|
+
const health = () => ({
|
|
6873
|
+
async getHealthReport() {
|
|
6874
|
+
const routes2 = await strapi.documents(waRoute).findMany({
|
|
6875
|
+
fields: [
|
|
6876
|
+
"title",
|
|
6877
|
+
"path",
|
|
6878
|
+
"canonicalPath",
|
|
6879
|
+
"uidPath",
|
|
6880
|
+
"type",
|
|
6881
|
+
"relatedContentType",
|
|
6882
|
+
"relatedDocumentId"
|
|
6883
|
+
]
|
|
6884
|
+
});
|
|
6885
|
+
const config2 = await getAdminService().getConfig();
|
|
6886
|
+
const existingContentTypes = new Set(Object.keys(strapi.contentTypes));
|
|
6887
|
+
const [navItems, existingDocumentIds, documentStatuses] = await Promise.all([
|
|
6888
|
+
getHealthNavItems(),
|
|
6889
|
+
getExistingDocumentIds(routes2, existingContentTypes),
|
|
6890
|
+
getDocumentStatuses(routes2)
|
|
6891
|
+
]);
|
|
6892
|
+
const draftOnlyDocumentIds = new Set(
|
|
6893
|
+
[...documentStatuses].filter(([, status]) => status === "draft").map(([id]) => id)
|
|
6894
|
+
);
|
|
6895
|
+
const issues = runHealthChecks({
|
|
6896
|
+
routes: routes2,
|
|
6897
|
+
navItems,
|
|
6898
|
+
existingContentTypes,
|
|
6899
|
+
enabledContentTypes: new Set(config2?.selectedContentTypes?.map((type) => type.uid) ?? []),
|
|
6900
|
+
existingDocumentIds,
|
|
6901
|
+
draftOnlyDocumentIds,
|
|
6902
|
+
routeBlacklist: normalizeRouteBlacklist(config2?.routeBlacklist)
|
|
6903
|
+
});
|
|
6904
|
+
return { issues, checkedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
6905
|
+
}
|
|
6906
|
+
});
|
|
6377
6907
|
const services = {
|
|
6378
6908
|
admin,
|
|
6379
|
-
client
|
|
6909
|
+
client,
|
|
6910
|
+
health
|
|
6380
6911
|
};
|
|
6381
6912
|
const index = {
|
|
6382
6913
|
register,
|