@mattisvensson/strapi-plugin-webatlas 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/admin/FullLoader-Btjb2W2p.mjs +0 -1
  2. package/dist/admin/FullLoader-Da2n70bJ.js +0 -1
  3. package/dist/admin/SettingTitle-B0quw3f8.js +0 -1
  4. package/dist/admin/SettingTitle-HMfQOJnK.mjs +0 -1
  5. package/dist/admin/de-B5pRvs13.mjs +0 -1
  6. package/dist/admin/de-CqU1FU8C.js +0 -1
  7. package/dist/admin/en-BE-zzIv8.mjs +0 -1
  8. package/dist/admin/en-C7I90FwV.js +0 -1
  9. package/dist/admin/index-9_HhKDUC.mjs +0 -1
  10. package/dist/admin/index-B79ELMEC.mjs +0 -1
  11. package/dist/admin/index-BEVoxEAm.js +0 -1
  12. package/dist/admin/index-Bmg-ERct.mjs +0 -1
  13. package/dist/admin/index-C8YjuuOx.js +0 -1
  14. package/dist/admin/index-Cx_mktdk.js +0 -1
  15. package/dist/admin/index-Cz_k_jjp.mjs +0 -1
  16. package/dist/admin/index-D2hB1vTw.js +0 -1
  17. package/dist/admin/index-YdWxpvOH.js +0 -1
  18. package/dist/admin/index-oEJT_mvw.mjs +0 -1
  19. package/dist/admin/index.js +0 -1
  20. package/dist/admin/index.mjs +0 -1
  21. package/dist/admin/src/index.d.ts +12 -0
  22. package/dist/server/index.js +87 -117
  23. package/dist/server/index.mjs +87 -117
  24. package/dist/server/src/index.d.ts +305 -0
  25. package/package.json +1 -1
  26. package/dist/admin/FullLoader-Btjb2W2p.mjs.map +0 -1
  27. package/dist/admin/FullLoader-Da2n70bJ.js.map +0 -1
  28. package/dist/admin/SettingTitle-B0quw3f8.js.map +0 -1
  29. package/dist/admin/SettingTitle-HMfQOJnK.mjs.map +0 -1
  30. package/dist/admin/de-B5pRvs13.mjs.map +0 -1
  31. package/dist/admin/de-CqU1FU8C.js.map +0 -1
  32. package/dist/admin/en-BE-zzIv8.mjs.map +0 -1
  33. package/dist/admin/en-C7I90FwV.js.map +0 -1
  34. package/dist/admin/index-9_HhKDUC.mjs.map +0 -1
  35. package/dist/admin/index-B79ELMEC.mjs.map +0 -1
  36. package/dist/admin/index-BEVoxEAm.js.map +0 -1
  37. package/dist/admin/index-Bmg-ERct.mjs.map +0 -1
  38. package/dist/admin/index-C8YjuuOx.js.map +0 -1
  39. package/dist/admin/index-Cx_mktdk.js.map +0 -1
  40. package/dist/admin/index-Cz_k_jjp.mjs.map +0 -1
  41. package/dist/admin/index-D2hB1vTw.js.map +0 -1
  42. package/dist/admin/index-YdWxpvOH.js.map +0 -1
  43. package/dist/admin/index-oEJT_mvw.mjs.map +0 -1
  44. package/dist/admin/index.js.map +0 -1
  45. package/dist/admin/index.mjs.map +0 -1
  46. package/dist/server/index.js.map +0 -1
  47. package/dist/server/index.mjs.map +0 -1
@@ -102,16 +102,16 @@ async function deleteNavItem(documentId) {
102
102
  }
103
103
  }
104
104
  function getAdminService() {
105
- var _a;
106
- return (_a = strapi.plugin(PLUGIN_ID)) === null || _a === void 0 ? void 0 : _a.service("admin");
105
+ return strapi.plugin(PLUGIN_ID)?.service("admin");
107
106
  }
108
107
  function getClientService() {
109
- var _a;
110
- return (_a = strapi.plugin(PLUGIN_ID)) === null || _a === void 0 ? void 0 : _a.service("client");
108
+ return strapi.plugin(PLUGIN_ID)?.service("client");
111
109
  }
112
110
  function reduceDepthOfOrphanedItems(navigationItems, itemId) {
113
111
  const navigationItemsCopy = JSON.parse(JSON.stringify(navigationItems));
114
- const startItemIndex = navigationItemsCopy.findIndex((item) => item.documentId === itemId);
112
+ const startItemIndex = navigationItemsCopy.findIndex(
113
+ (item) => item.documentId === itemId
114
+ );
115
115
  if (startItemIndex === -1) return;
116
116
  const startItem = navigationItemsCopy[startItemIndex];
117
117
  for (let i = startItemIndex + 1; i < navigationItemsCopy.length; i++) {
@@ -170,11 +170,9 @@ async function deleteRoute(documentId) {
170
170
  }
171
171
  }
172
172
  function buildStructuredNavigation(navigation2, variant = "nested") {
173
- var _a;
174
173
  const itemsById = /* @__PURE__ */ new Map();
175
174
  const rootItems = [];
176
- if (!navigation2.items || ((_a = navigation2.items) === null || _a === void 0 ? void 0 : _a.length) === 0)
177
- return navigation2;
175
+ if (!navigation2.items || navigation2.items?.length === 0) return navigation2;
178
176
  navigation2.items.forEach((item) => {
179
177
  itemsById.set(item.documentId, { ...item, items: [] });
180
178
  });
@@ -248,7 +246,6 @@ const sortItems = (items) => {
248
246
  };
249
247
  function extractRouteAndItems(items) {
250
248
  return items.map((item) => {
251
- var _a;
252
249
  const route2 = { ...item.route };
253
250
  if (!route2) return null;
254
251
  let depth = null;
@@ -256,7 +253,7 @@ function extractRouteAndItems(items) {
256
253
  depth = item.depth;
257
254
  }
258
255
  let children = null;
259
- if (((_a = item.items) === null || _a === void 0 ? void 0 : _a.length) > 0) {
256
+ if (item.items?.length > 0) {
260
257
  const items2 = extractRouteAndItems(item.items);
261
258
  if (items2.length > 0) children = items2;
262
259
  }
@@ -4260,7 +4257,6 @@ const getModelPopulationAttributes = (model) => {
4260
4257
  return model.attributes;
4261
4258
  };
4262
4259
  function getFullPopulateObject(modelUid, maxDepth = 5, ignore = []) {
4263
- var _a;
4264
4260
  if (maxDepth <= 1) {
4265
4261
  return true;
4266
4262
  }
@@ -4273,12 +4269,12 @@ function getFullPopulateObject(modelUid, maxDepth = 5, ignore = []) {
4273
4269
  const populate = {};
4274
4270
  const model = strapi.getModel(modelUid);
4275
4271
  const newIgnore = [...ignore, modelUid];
4276
- if ((_a = model.options) === null || _a === void 0 ? void 0 : _a.populateCreatorFields) {
4272
+ if (model.options?.populateCreatorFields) {
4277
4273
  populate.createdBy = true;
4278
4274
  populate.updatedBy = true;
4279
4275
  }
4280
4276
  for (const [key, value] of Object.entries(getModelPopulationAttributes(model))) {
4281
- if (ignore === null || ignore === void 0 ? void 0 : ignore.includes(key)) continue;
4277
+ if (ignore?.includes(key)) continue;
4282
4278
  if (value) {
4283
4279
  if (value.type === "component") {
4284
4280
  const componentPopulate = getFullPopulateObject(value.component, maxDepth - 1, newIgnore);
@@ -4332,7 +4328,7 @@ async function buildCanonicalPath(slug, parentDocumentId) {
4332
4328
  const parentRoute = await strapi.documents(waRoute).findOne({
4333
4329
  documentId: parentDocumentId
4334
4330
  });
4335
- const parentCanonicalPath = (parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.canonicalPath) || "";
4331
+ const parentCanonicalPath = parentRoute?.canonicalPath || "";
4336
4332
  const canonicalPath = `${parentCanonicalPath ? parentCanonicalPath + "/" : ""}${slug}`;
4337
4333
  return canonicalPath;
4338
4334
  } catch (err) {
@@ -4422,16 +4418,19 @@ async function getNonInternalRouteIds() {
4422
4418
  const routeIds = routes2.map((route2) => route2.documentId);
4423
4419
  return routeIds;
4424
4420
  }
4425
- async function validateRouteDependencies({ routeId, newParentId }) {
4421
+ async function validateRouteDependencies({
4422
+ routeId,
4423
+ newParentId
4424
+ }) {
4426
4425
  if (!newParentId) return true;
4427
- const normalizedRouteId = routeId !== null && routeId !== void 0 ? routeId : void 0;
4426
+ const normalizedRouteId = routeId ?? void 0;
4428
4427
  const parentRoute = await strapi.documents(waRoute).findOne({
4429
4428
  documentId: newParentId
4430
4429
  });
4431
4430
  if (!parentRoute) {
4432
4431
  throw new Error(`Parent route not found: ${newParentId}`);
4433
4432
  }
4434
- if ((parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.type) === "external") {
4433
+ if (parentRoute?.type === "external") {
4435
4434
  throw new Error("External routes cannot have children");
4436
4435
  }
4437
4436
  if (!normalizedRouteId) return true;
@@ -4444,8 +4443,11 @@ async function validateRouteDependencies({ routeId, newParentId }) {
4444
4443
  }
4445
4444
  return true;
4446
4445
  }
4447
- async function buildNavigationPath({ slug, routeDocumentId, calculatedParent }) {
4448
- var _a, _b, _c;
4446
+ async function buildNavigationPath({
4447
+ slug,
4448
+ routeDocumentId,
4449
+ calculatedParent
4450
+ }) {
4449
4451
  let parentDocumentId = calculatedParent;
4450
4452
  let parent = null;
4451
4453
  if (parentDocumentId) {
@@ -4455,25 +4457,22 @@ async function buildNavigationPath({ slug, routeDocumentId, calculatedParent })
4455
4457
  populate: ["route", "parent"]
4456
4458
  });
4457
4459
  parent = navItem;
4458
- parentDocumentId = ((_a = navItem === null || navItem === void 0 ? void 0 : navItem.parent) === null || _a === void 0 ? void 0 : _a.documentId) || null;
4459
- if (((_b = parent === null || parent === void 0 ? void 0 : parent.route) === null || _b === void 0 ? void 0 : _b.type) === "internal")
4460
- break;
4460
+ parentDocumentId = navItem?.parent?.documentId || null;
4461
+ if (parent?.route?.type === "internal") break;
4461
4462
  } while (parentDocumentId);
4462
4463
  }
4463
- if (((_c = parent === null || parent === void 0 ? void 0 : parent.route) === null || _c === void 0 ? void 0 : _c.type) !== "internal")
4464
- parent = null;
4464
+ if (parent?.route?.type !== "internal") parent = null;
4465
4465
  if (slug.startsWith("/")) slug = slug.substring(1);
4466
- const newPath = (parent === null || parent === void 0 ? void 0 : parent.route) ? `${parent.route.path}/${slug}` : `${slug}`;
4466
+ const newPath = parent?.route ? `${parent.route.path}/${slug}` : `${slug}`;
4467
4467
  const validatedPath = await duplicateCheck(newPath, routeDocumentId);
4468
4468
  return validatedPath;
4469
4469
  }
4470
4470
  async function handleItemDeletion(navigationItems) {
4471
- var _a;
4472
4471
  const errors = [];
4473
4472
  let items = [...navigationItems];
4474
4473
  for (let i = 0; i < items.length; i++) {
4475
4474
  const item = items[i];
4476
- if (((_a = item.clientModifications) === null || _a === void 0 ? void 0 : _a.type) === "delete") {
4475
+ if (item.clientModifications?.type === "delete") {
4477
4476
  try {
4478
4477
  if (item.documentId) {
4479
4478
  await deleteNavItem(item.documentId);
@@ -4521,10 +4520,9 @@ async function handleItemUpdate({
4521
4520
  navigationId,
4522
4521
  newNavItemsMap
4523
4522
  }) {
4524
- var _a, _b, _c, _d;
4525
4523
  const errors = [];
4526
- const isCreate = ((_a = item.clientModifications) === null || _a === void 0 ? void 0 : _a.type) === "create";
4527
- const isUpdate = ((_b = item.clientModifications) === null || _b === void 0 ? void 0 : _b.type) === "update";
4524
+ const isCreate = item.clientModifications?.type === "create";
4525
+ const isUpdate = item.clientModifications?.type === "update";
4528
4526
  const isInternal = item.route.type === "internal";
4529
4527
  if (isCreate && !item.clientModifications.route) {
4530
4528
  try {
@@ -4589,7 +4587,7 @@ async function handleItemUpdate({
4589
4587
  });
4590
4588
  if (!route2)
4591
4589
  throw new Error(`Related route not found for navigation item '${item.route.title}'`);
4592
- const slug = ((_c = item.clientModifications) === null || _c === void 0 ? void 0 : _c.slug) || item.route.slug;
4590
+ const slug = item.clientModifications?.slug || item.route.slug;
4593
4591
  const path = isInternal ? await buildNavigationPath({
4594
4592
  slug,
4595
4593
  routeDocumentId: route2.documentId,
@@ -4598,7 +4596,7 @@ async function handleItemUpdate({
4598
4596
  const isOverride = path !== route2.canonicalPath;
4599
4597
  if (needsRouteUpdate) {
4600
4598
  await updateRoute(route2.documentId, {
4601
- title: ((_d = item.clientModifications) === null || _d === void 0 ? void 0 : _d.title) || item.route.title,
4599
+ title: item.clientModifications?.title || item.route.title,
4602
4600
  slug,
4603
4601
  path,
4604
4602
  isOverride
@@ -4638,7 +4636,6 @@ function calculateParentAndOrder({
4638
4636
  groupIndices,
4639
4637
  newNavItemsMap
4640
4638
  }) {
4641
- var _a;
4642
4639
  if (item.depth === 0) {
4643
4640
  if (groupIndices[0] !== void 0) {
4644
4641
  groupIndices[0] = groupIndices[0] + 1;
@@ -4651,7 +4648,7 @@ function calculateParentAndOrder({
4651
4648
  if (previousItem && typeof previousItem.depth === "number") {
4652
4649
  if (item.depth === previousItem.depth + 1) {
4653
4650
  parentIds.push(
4654
- previousItem.documentId.startsWith("temp-") ? ((_a = newNavItemsMap.get(previousItem.documentId)) === null || _a === void 0 ? void 0 : _a.documentId) || previousItem.documentId : previousItem.documentId
4651
+ previousItem.documentId.startsWith("temp-") ? newNavItemsMap.get(previousItem.documentId)?.documentId || previousItem.documentId : previousItem.documentId
4655
4652
  );
4656
4653
  groupIndices[item.depth] = 0;
4657
4654
  } else if (item.depth <= previousItem.depth) {
@@ -4677,10 +4674,9 @@ const migration_001_canonical_path = {
4677
4674
  version: "001",
4678
4675
  description: "Migrate title field to canonicalPath using transformToUrl",
4679
4676
  async up(strapi2) {
4680
- var _a;
4681
4677
  strapi2.log.info("[webatlas] Starting canonical path migration...");
4682
4678
  try {
4683
- const routes2 = await ((_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waRoute).findMany({
4679
+ const routes2 = await strapi2.db?.query(waRoute).findMany({
4684
4680
  where: {
4685
4681
  title: {
4686
4682
  $notNull: true,
@@ -4689,7 +4685,7 @@ const migration_001_canonical_path = {
4689
4685
  $or: [{ canonicalPath: { $null: true } }, { canonicalPath: "" }]
4690
4686
  },
4691
4687
  populate: ["parent"]
4692
- }));
4688
+ });
4693
4689
  if (!routes2 || routes2.length === 0) {
4694
4690
  strapi2.log.info("[webatlas] No routes found that need canonical path migration");
4695
4691
  return;
@@ -4702,15 +4698,14 @@ const migration_001_canonical_path = {
4702
4698
  const chunk = routes2.slice(i, i + chunkSize);
4703
4699
  await Promise.all(
4704
4700
  chunk.map(async (route2) => {
4705
- var _a2, _b;
4706
4701
  try {
4707
4702
  const transformedTitle = transformToUrl(route2.title);
4708
- const parentId = ((_a2 = route2.parent) === null || _a2 === void 0 ? void 0 : _a2.id) || null;
4703
+ const parentId = route2.parent?.id || null;
4709
4704
  const canonicalPath = await buildCanonicalPath(transformedTitle, parentId);
4710
- await ((_b = strapi2.db) === null || _b === void 0 ? void 0 : _b.query(waRoute).update({
4705
+ await strapi2.db?.query(waRoute).update({
4711
4706
  where: { id: route2.id },
4712
4707
  data: { canonicalPath }
4713
- }));
4708
+ });
4714
4709
  migratedCount++;
4715
4710
  if (migratedCount % 25 === 0) {
4716
4711
  strapi2.log.info(`[webatlas] Migrated ${migratedCount}/${routes2.length} routes`);
@@ -4740,14 +4735,12 @@ const migration_002_webatlas_json_field = {
4740
4735
  version: "002",
4741
4736
  description: "Migrate webatlas_path, webatlas_parent and webatlas_override text fields into the webatlas JSON field",
4742
4737
  async up(strapi2) {
4743
- var _a, _b;
4744
4738
  const knex = strapi2.db.connection;
4745
- const enabledContentTypes = Object.values(strapi2.contentTypes).filter((ct) => {
4746
- var _a2, _b2;
4747
- return ((_b2 = (_a2 = ct.pluginOptions) === null || _a2 === void 0 ? void 0 : _a2.webatlas) === null || _b2 === void 0 ? void 0 : _b2.enabled) === true;
4748
- });
4739
+ const enabledContentTypes = Object.values(strapi2.contentTypes).filter(
4740
+ (ct) => ct.pluginOptions?.webatlas?.enabled === true
4741
+ );
4749
4742
  for (const contentType of enabledContentTypes) {
4750
- const tableName = (_b = (_a = strapi2.db.metadata.get(contentType.uid)) === null || _a === void 0 ? void 0 : _a.tableName) !== null && _b !== void 0 ? _b : contentType.collectionName;
4743
+ const tableName = strapi2.db.metadata.get(contentType.uid)?.tableName ?? contentType.collectionName;
4751
4744
  strapi2.log.info(`[webatlas] Processing table: ${tableName} (${contentType.uid})`);
4752
4745
  const [hasPathCol, hasOverrideCol, hasParentCol, hasWebatlasCol] = await Promise.all([
4753
4746
  knex.schema.hasColumn(tableName, "webatlas_path"),
@@ -4878,7 +4871,6 @@ function registerPermissions(strapi2) {
4878
4871
  strapi2.admin.services.permission.actionProvider.registerMany(actions);
4879
4872
  }
4880
4873
  async function syncConfig(strapi2, enabledContentTypes) {
4881
- var _a;
4882
4874
  const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
4883
4875
  const config2 = await pluginStore.get({
4884
4876
  key: "config"
@@ -4887,18 +4879,17 @@ async function syncConfig(strapi2, enabledContentTypes) {
4887
4879
  ...config2,
4888
4880
  selectedContentTypes: [],
4889
4881
  navigation: {
4890
- maxDepth: ((_a = config2 === null || config2 === void 0 ? void 0 : config2.navigation) === null || _a === void 0 ? void 0 : _a.maxDepth) || 1,
4891
- ...config2 === null || config2 === void 0 ? void 0 : config2.navigation
4882
+ maxDepth: config2?.navigation?.maxDepth || 1,
4883
+ ...config2?.navigation
4892
4884
  },
4893
- migrationVersion: (config2 === null || config2 === void 0 ? void 0 : config2.migrationVersion) || "0"
4885
+ migrationVersion: config2?.migrationVersion || "0"
4894
4886
  };
4895
4887
  enabledContentTypes.forEach((type) => {
4896
- var _a2;
4897
- const existingConfig = (_a2 = config2 === null || config2 === void 0 ? void 0 : config2.selectedContentTypes) === null || _a2 === void 0 ? void 0 : _a2.find((ct) => ct.uid === type.uid);
4888
+ const existingConfig = config2?.selectedContentTypes?.find((ct) => ct.uid === type.uid);
4898
4889
  newConfig.selectedContentTypes.push({
4899
4890
  uid: type.uid,
4900
4891
  label: type.info.displayName,
4901
- default: (existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.default) || null
4892
+ default: existingConfig?.default || null
4902
4893
  });
4903
4894
  });
4904
4895
  if (JSON.stringify(newConfig) !== JSON.stringify(config2)) {
@@ -4909,7 +4900,6 @@ async function syncConfig(strapi2, enabledContentTypes) {
4909
4900
  function documentMiddleware(strapi2, enabledContentTypes, config2) {
4910
4901
  const actions = ["create", "update", "delete"];
4911
4902
  strapi2.documents.use(async (context, next) => {
4912
- var _a, _b, _c, _d, _e, _f;
4913
4903
  if (!enabledContentTypes.map((type) => type.uid).includes(context.uid) || !actions.includes(context.action)) {
4914
4904
  return next();
4915
4905
  }
@@ -4924,9 +4914,9 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4924
4914
  }
4925
4915
  const result2 = await next();
4926
4916
  if (!transformedSlug) return result2;
4927
- const existing = await ((_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waRoute).findOne({
4917
+ const existing = await strapi2.db?.query(waRoute).findOne({
4928
4918
  where: { relatedDocumentId: result2.documentId }
4929
- }));
4919
+ });
4930
4920
  if (existing) return result2;
4931
4921
  let parent = null;
4932
4922
  let isValid = false;
@@ -4946,7 +4936,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4946
4936
  if (!validatedPath)
4947
4937
  throw new Error(`Failed to generate a unique path for slug: ${transformedSlug}`);
4948
4938
  const singularName = context.contentType.info.singularName;
4949
- const title = ((_b = context.params.data[ctSettings === null || ctSettings === void 0 ? void 0 : ctSettings.default]) === null || _b === void 0 ? void 0 : _b.trim()) || transformedSlug;
4939
+ const title = context.params.data[ctSettings?.default]?.trim() || transformedSlug;
4950
4940
  const canonicalPath = await buildCanonicalPath(
4951
4941
  transformToUrl(title),
4952
4942
  isValid ? parent.documentId : null
@@ -4961,22 +4951,22 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4961
4951
  uidPath: `${singularName}/${result2.id}`,
4962
4952
  isOverride: isOverride || false,
4963
4953
  title,
4964
- parent: isValid ? parent === null || parent === void 0 ? void 0 : parent.documentId : null,
4954
+ parent: isValid ? parent?.documentId : null,
4965
4955
  canonicalPath
4966
4956
  }
4967
4957
  });
4968
- await ((_c = strapi2.db) === null || _c === void 0 ? void 0 : _c.query(context.uid).updateMany({
4958
+ await strapi2.db?.query(context.uid).updateMany({
4969
4959
  where: { documentId: result2.documentId },
4970
4960
  data: {
4971
4961
  webatlas: {
4972
4962
  ...webatlas,
4973
4963
  slug: transformedSlug,
4974
4964
  path: validatedPath,
4975
- parentDocumentId: isValid ? parent === null || parent === void 0 ? void 0 : parent.documentId : "null",
4965
+ parentDocumentId: isValid ? parent?.documentId : null,
4976
4966
  isOverride: isOverride || false
4977
4967
  }
4978
4968
  }
4979
- }));
4969
+ });
4980
4970
  return result2;
4981
4971
  }
4982
4972
  if (context.action === "update") {
@@ -5006,29 +4996,23 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5006
4996
  const transformedSlug = transformToUrl(slug);
5007
4997
  let rawPath = transformedSlug;
5008
4998
  if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
5009
- const validatedPath = await duplicateCheck(
5010
- rawPath,
5011
- (_d = relatedRoute === null || relatedRoute === void 0 ? void 0 : relatedRoute.documentId) !== null && _d !== void 0 ? _d : null
5012
- );
4999
+ const validatedPath = await duplicateCheck(rawPath, relatedRoute?.documentId ?? null);
5013
5000
  data.webatlas.path = validatedPath;
5014
5001
  data.webatlas.slug = transformedSlug;
5015
5002
  if (relatedRoute) data.relatedRoute = relatedRoute;
5016
5003
  if (!isValid && parentDocumentId) data.webatlas.parent = null;
5017
5004
  const result2 = await next();
5018
- const title = ((_e = context.params.data[ctSettings === null || ctSettings === void 0 ? void 0 : ctSettings.default]) === null || _e === void 0 ? void 0 : _e.trim()) || slug;
5019
- const canonicalPath = isOverride ? relatedRoute.path : await buildCanonicalPath(
5020
- transformToUrl(title),
5021
- parent === null || parent === void 0 ? void 0 : parent.documentId
5022
- );
5005
+ const title = context.params.data[ctSettings?.default]?.trim() || slug;
5006
+ const canonicalPath = isOverride ? relatedRoute.path : await buildCanonicalPath(transformToUrl(title), parent?.documentId);
5023
5007
  const routeData = {
5024
5008
  title,
5025
5009
  path: validatedPath,
5026
5010
  slug,
5027
5011
  isOverride: isOverride || false,
5028
- parent: (parent === null || parent === void 0 ? void 0 : parent.documentId) || null,
5012
+ parent: parent?.documentId || null,
5029
5013
  canonicalPath
5030
5014
  };
5031
- let routeDocumentId = relatedRoute === null || relatedRoute === void 0 ? void 0 : relatedRoute.documentId;
5015
+ let routeDocumentId = relatedRoute?.documentId;
5032
5016
  if (!relatedRoute) {
5033
5017
  const createdRoute = await strapi2.documents(waRoute).create({
5034
5018
  data: {
@@ -5039,7 +5023,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5039
5023
  ...routeData
5040
5024
  }
5041
5025
  });
5042
- routeDocumentId = createdRoute === null || createdRoute === void 0 ? void 0 : createdRoute.documentId;
5026
+ routeDocumentId = createdRoute?.documentId;
5043
5027
  } else {
5044
5028
  await strapi2.documents(waRoute).update({
5045
5029
  documentId: relatedRoute.documentId,
@@ -5063,10 +5047,9 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5063
5047
  where: { relatedDocumentId },
5064
5048
  populate: ["navitem"]
5065
5049
  });
5066
- if (!(deletedRoute === null || deletedRoute === void 0 ? void 0 : deletedRoute.documentId))
5067
- return result2;
5050
+ if (!deletedRoute?.documentId) return result2;
5068
5051
  const navItemDocumentIds = Array.from(
5069
- (_f = deletedRoute.navitem) === null || _f === void 0 ? void 0 : _f.map((item) => item.documentId)
5052
+ deletedRoute.navitem?.map((item) => item.documentId)
5070
5053
  );
5071
5054
  for (const navItemDocumentId of navItemDocumentIds) {
5072
5055
  await strapi2.documents(waNavItem).delete({ documentId: navItemDocumentId });
@@ -5082,16 +5065,15 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5082
5065
  }
5083
5066
  function webatlasMiddleware(strapi2) {
5084
5067
  strapi2.documents.use(async (context, next) => {
5085
- var _a, _b;
5086
5068
  if (context.uid !== waNavItem) return next();
5087
5069
  if (context.action === "delete") {
5088
5070
  let externalRouteDocumentId = null;
5089
5071
  try {
5090
- const navItem = await ((_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waNavItem).findOne({
5072
+ const navItem = await strapi2.db?.query(waNavItem).findOne({
5091
5073
  where: { documentId: context.params.documentId },
5092
5074
  populate: ["route"]
5093
- }));
5094
- if (((_b = navItem === null || navItem === void 0 ? void 0 : navItem.route) === null || _b === void 0 ? void 0 : _b.type) === "external") {
5075
+ });
5076
+ if (navItem?.route?.type === "external") {
5095
5077
  externalRouteDocumentId = navItem.route.documentId;
5096
5078
  }
5097
5079
  } catch (err) {
@@ -5149,10 +5131,9 @@ const bootstrap = async ({ strapi: strapi2 }) => {
5149
5131
  try {
5150
5132
  await runMigrations(strapi2);
5151
5133
  registerPermissions(strapi2);
5152
- const enabledContentTypes = Object.values(strapi2.contentTypes).filter((type) => {
5153
- var _a, _b;
5154
- return ((_b = (_a = type.pluginOptions) === null || _a === void 0 ? void 0 : _a.webatlas) === null || _b === void 0 ? void 0 : _b.enabled) === true;
5155
- });
5134
+ const enabledContentTypes = Object.values(strapi2.contentTypes).filter(
5135
+ (type) => type.pluginOptions?.webatlas?.enabled === true
5136
+ );
5156
5137
  const config2 = await syncConfig(strapi2, enabledContentTypes);
5157
5138
  if (!enabledContentTypes.length) return;
5158
5139
  documentMiddleware(strapi2, enabledContentTypes, config2);
@@ -6068,9 +6049,7 @@ var setExports = requireSet();
6068
6049
  const set = /* @__PURE__ */ getDefaultExportFromCjs(setExports);
6069
6050
  const register = ({ strapi: strapi2 }) => {
6070
6051
  Object.values(strapi2.contentTypes).forEach((contentType) => {
6071
- var _a, _b;
6072
- if (!((_b = (_a = contentType.pluginOptions) === null || _a === void 0 ? void 0 : _a.webatlas) === null || _b === void 0 ? void 0 : _b.enabled))
6073
- return;
6052
+ if (!contentType.pluginOptions?.webatlas?.enabled) return;
6074
6053
  const { attributes } = contentType;
6075
6054
  const fieldSettings = {
6076
6055
  writable: true,
@@ -6728,7 +6707,7 @@ const admin = ({ strapi: strapi2 }) => ({
6728
6707
  ...config2,
6729
6708
  navigation: {
6730
6709
  ...defaultConfig.navigation,
6731
- ...config2 === null || config2 === void 0 ? void 0 : config2.navigation
6710
+ ...config2?.navigation
6732
6711
  }
6733
6712
  };
6734
6713
  return config2;
@@ -6751,14 +6730,13 @@ const admin = ({ strapi: strapi2 }) => ({
6751
6730
  }
6752
6731
  },
6753
6732
  async getRelatedRoute(documentId) {
6754
- var _a;
6755
6733
  try {
6756
- return await ((_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waRoute).findOne({
6734
+ return await strapi2.db?.query(waRoute).findOne({
6757
6735
  where: {
6758
6736
  relatedDocumentId: documentId
6759
6737
  },
6760
6738
  populate: ["parent"]
6761
- }));
6739
+ });
6762
6740
  } catch (e) {
6763
6741
  strapi2.log.error(e);
6764
6742
  }
@@ -6771,10 +6749,10 @@ const admin = ({ strapi: strapi2 }) => ({
6771
6749
  documentId
6772
6750
  });
6773
6751
  }
6774
- const descendants = (route2 === null || route2 === void 0 ? void 0 : route2.documentId) ? await getRouteDescendants(route2.documentId) : [];
6752
+ const descendants = route2?.documentId ? await getRouteDescendants(route2.documentId) : [];
6775
6753
  const nonInternalRouteIds = await getNonInternalRouteIds();
6776
6754
  const prohibitedRouteIds = [...descendants, ...nonInternalRouteIds];
6777
- (route2 === null || route2 === void 0 ? void 0 : route2.documentId) && prohibitedRouteIds.push(route2.documentId);
6755
+ route2?.documentId && prohibitedRouteIds.push(route2.documentId);
6778
6756
  return prohibitedRouteIds;
6779
6757
  } catch (e) {
6780
6758
  strapi2.log.error(e);
@@ -6807,7 +6785,9 @@ const admin = ({ strapi: strapi2 }) => ({
6807
6785
  });
6808
6786
  if (!navigation2) throw new Error("Navigation not found");
6809
6787
  if (variant) {
6810
- navigation2 = navigation2.map((nav) => buildStructuredNavigation(nav, variant));
6788
+ navigation2 = navigation2.map(
6789
+ (nav) => buildStructuredNavigation(nav, variant)
6790
+ );
6811
6791
  }
6812
6792
  }
6813
6793
  return navigation2;
@@ -6979,35 +6959,26 @@ const client = ({ strapi: strapi2 }) => ({
6979
6959
  },
6980
6960
  {
6981
6961
  condition: slug,
6982
- lookup: () => {
6983
- var _a;
6984
- return (_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waNavigation).findOne({
6985
- where: { slug },
6986
- populate: populateObject
6987
- });
6988
- },
6962
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6963
+ where: { slug },
6964
+ populate: populateObject
6965
+ }),
6989
6966
  name: "slug"
6990
6967
  },
6991
6968
  {
6992
6969
  condition: name,
6993
- lookup: () => {
6994
- var _a;
6995
- return (_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waNavigation).findOne({
6996
- where: { name },
6997
- populate: populateObject
6998
- });
6999
- },
6970
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6971
+ where: { name },
6972
+ populate: populateObject
6973
+ }),
7000
6974
  name: "name"
7001
6975
  },
7002
6976
  {
7003
6977
  condition: id,
7004
- lookup: () => {
7005
- var _a;
7006
- return (_a = strapi2.db) === null || _a === void 0 ? void 0 : _a.query(waNavigation).findOne({
7007
- where: { id },
7008
- populate: populateObject
7009
- });
7010
- },
6978
+ lookup: () => strapi2.db?.query(waNavigation).findOne({
6979
+ where: { id },
6980
+ populate: populateObject
6981
+ }),
7011
6982
  name: "id"
7012
6983
  }
7013
6984
  ];
@@ -7048,4 +7019,3 @@ const index = {
7048
7019
  middlewares
7049
7020
  };
7050
7021
  exports.default = index;
7051
- //# sourceMappingURL=index.js.map