@mattisvensson/strapi-plugin-webatlas 0.11.3 → 0.11.5

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 (48) hide show
  1. package/README.md +2 -1
  2. package/dist/admin/FullLoader-Btjb2W2p.mjs +0 -1
  3. package/dist/admin/FullLoader-Da2n70bJ.js +0 -1
  4. package/dist/admin/{SettingTitle-BdiDHFXF.js → SettingTitle-DGSkTF7e.js} +1 -2
  5. package/dist/admin/{SettingTitle-CcNfx_4T.mjs → SettingTitle-UPbQCuTC.mjs} +1 -2
  6. package/dist/admin/de-B5pRvs13.mjs +0 -1
  7. package/dist/admin/de-CqU1FU8C.js +0 -1
  8. package/dist/admin/en-BE-zzIv8.mjs +0 -1
  9. package/dist/admin/en-C7I90FwV.js +0 -1
  10. package/dist/admin/{index-uW7YJoRU.js → index-BiXgA5Ru.js} +5 -6
  11. package/dist/admin/{index-BkPtrXJO.js → index-Bm8lkiNL.js} +25 -16
  12. package/dist/admin/{index-DBG6vBGU.js → index-BztvKcfc.js} +1 -2
  13. package/dist/admin/{index-BMTlUOrK.mjs → index-CrgTYzgl.mjs} +2 -3
  14. package/dist/admin/{index-Sj2FxwAu.js → index-CyzPvvul.js} +2 -3
  15. package/dist/admin/{index-DkEReTkt.mjs → index-D4B4s4XO.mjs} +2 -3
  16. package/dist/admin/{index-DkfE_arE.mjs → index-DLoZpHxU.mjs} +5 -6
  17. package/dist/admin/{index-CEBh9c4X.js → index-DcUmtUyp.js} +2 -3
  18. package/dist/admin/{index-BX3hiURm.mjs → index-Dx-EVn-t.mjs} +25 -16
  19. package/dist/admin/{index-BdyLsiR4.mjs → index-b3yS9Dm7.mjs} +1 -2
  20. package/dist/admin/index.js +1 -2
  21. package/dist/admin/index.mjs +1 -2
  22. package/dist/admin/src/index.d.ts +12 -0
  23. package/dist/server/index.js +113 -125
  24. package/dist/server/index.mjs +113 -125
  25. package/dist/server/src/index.d.ts +305 -0
  26. package/package.json +18 -7
  27. package/dist/admin/FullLoader-Btjb2W2p.mjs.map +0 -1
  28. package/dist/admin/FullLoader-Da2n70bJ.js.map +0 -1
  29. package/dist/admin/SettingTitle-BdiDHFXF.js.map +0 -1
  30. package/dist/admin/SettingTitle-CcNfx_4T.mjs.map +0 -1
  31. package/dist/admin/de-B5pRvs13.mjs.map +0 -1
  32. package/dist/admin/de-CqU1FU8C.js.map +0 -1
  33. package/dist/admin/en-BE-zzIv8.mjs.map +0 -1
  34. package/dist/admin/en-C7I90FwV.js.map +0 -1
  35. package/dist/admin/index-BMTlUOrK.mjs.map +0 -1
  36. package/dist/admin/index-BX3hiURm.mjs.map +0 -1
  37. package/dist/admin/index-BdyLsiR4.mjs.map +0 -1
  38. package/dist/admin/index-BkPtrXJO.js.map +0 -1
  39. package/dist/admin/index-CEBh9c4X.js.map +0 -1
  40. package/dist/admin/index-DBG6vBGU.js.map +0 -1
  41. package/dist/admin/index-DkEReTkt.mjs.map +0 -1
  42. package/dist/admin/index-DkfE_arE.mjs.map +0 -1
  43. package/dist/admin/index-Sj2FxwAu.js.map +0 -1
  44. package/dist/admin/index-uW7YJoRU.js.map +0 -1
  45. package/dist/admin/index.js.map +0 -1
  46. package/dist/admin/index.mjs.map +0 -1
  47. package/dist/server/index.js.map +0 -1
  48. package/dist/server/index.mjs.map +0 -1
@@ -4664,6 +4664,106 @@ function calculateParentAndOrder({
4664
4664
  calculatedOrder
4665
4665
  };
4666
4666
  }
4667
+ async function enrichWebatlasData(data, contentTypeUid) {
4668
+ console.log("Enriching data with webatlas fields...", { contentTypeUid });
4669
+ console.log("Original data:", JSON.stringify(data, null, 2));
4670
+ if (!data || typeof data !== "object") return data;
4671
+ const collectDocumentIds = (obj, uid) => {
4672
+ if (!obj || typeof obj !== "object") return [];
4673
+ const ids = [];
4674
+ if (obj.documentId) ids.push(obj.documentId);
4675
+ if (!uid) return ids;
4676
+ const ct = strapi.contentTypes[uid];
4677
+ if (!ct?.attributes) return ids;
4678
+ for (const [key, attr] of Object.entries(ct.attributes)) {
4679
+ const attribute = attr;
4680
+ if (attribute.type === "relation" && obj[key]) {
4681
+ const targetUid = attribute.target;
4682
+ if (Array.isArray(obj[key])) {
4683
+ ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, targetUid)));
4684
+ } else {
4685
+ ids.push(...collectDocumentIds(obj[key], targetUid));
4686
+ }
4687
+ }
4688
+ if (attribute.type === "component" && obj[key]) {
4689
+ const componentUid = attribute.component;
4690
+ if (Array.isArray(obj[key])) {
4691
+ ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, componentUid)));
4692
+ } else {
4693
+ ids.push(...collectDocumentIds(obj[key], componentUid));
4694
+ }
4695
+ }
4696
+ if (attribute.type === "dynamiczone" && Array.isArray(obj[key])) {
4697
+ ids.push(
4698
+ ...obj[key].flatMap((item) => {
4699
+ if (!item || !item.__component) return [];
4700
+ return collectDocumentIds(item, item.__component);
4701
+ })
4702
+ );
4703
+ }
4704
+ }
4705
+ return ids;
4706
+ };
4707
+ const documentIds = collectDocumentIds(data, contentTypeUid);
4708
+ if (documentIds.length === 0) return data;
4709
+ const uniqueDocumentIds = [...new Set(documentIds)];
4710
+ const routes2 = await strapi.db?.query(waRoute).findMany({
4711
+ where: {
4712
+ relatedDocumentId: { $in: uniqueDocumentIds }
4713
+ },
4714
+ select: ["relatedDocumentId", "relatedContentType", "path", "canonicalPath", "slug", "uidPath"]
4715
+ });
4716
+ const routeMap = new Map(routes2?.map((route2) => [route2.relatedDocumentId, route2]) || []);
4717
+ const enrichEntity = (entity, uid) => {
4718
+ if (!entity || typeof entity !== "object") return entity;
4719
+ const ct = uid ? strapi.contentTypes[uid] : null;
4720
+ const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
4721
+ if (isWebatlasEnabled && entity.documentId && routeMap.has(entity.documentId)) {
4722
+ const route2 = routeMap.get(entity.documentId);
4723
+ entity.webatlas = {
4724
+ path: route2.path || "",
4725
+ canonicalPath: route2.canonicalPath || "",
4726
+ slug: route2.slug || "",
4727
+ uidPath: route2.uidPath || ""
4728
+ };
4729
+ }
4730
+ if (ct?.attributes) {
4731
+ for (const [key, attr] of Object.entries(ct.attributes)) {
4732
+ const attribute = attr;
4733
+ if (attribute.type === "relation" && entity[key]) {
4734
+ const targetUid = attribute.target;
4735
+ strapi.log.debug("relation found");
4736
+ if (Array.isArray(entity[key])) {
4737
+ entity[key] = entity[key].map(
4738
+ (item) => item ? enrichEntity(item, targetUid) : item
4739
+ );
4740
+ } else {
4741
+ entity[key] = enrichEntity(entity[key], targetUid);
4742
+ }
4743
+ }
4744
+ if (attribute.type === "component" && entity[key]) {
4745
+ const componentUid = attribute.component;
4746
+ if (Array.isArray(entity[key])) {
4747
+ entity[key] = entity[key].map(
4748
+ (item) => item ? enrichEntity(item, componentUid) : item
4749
+ );
4750
+ } else {
4751
+ entity[key] = enrichEntity(entity[key], componentUid);
4752
+ }
4753
+ }
4754
+ if (attribute.type === "dynamiczone" && Array.isArray(entity[key])) {
4755
+ entity[key] = entity[key].map((item) => {
4756
+ if (!item || !item.__component) return item;
4757
+ return enrichEntity(item, item.__component);
4758
+ });
4759
+ }
4760
+ }
4761
+ }
4762
+ strapi.log.debug("finished - returning");
4763
+ return entity;
4764
+ };
4765
+ return enrichEntity(data, contentTypeUid);
4766
+ }
4667
4767
  const migration_001_canonical_path = {
4668
4768
  version: "001",
4669
4769
  description: "Migrate title field to canonicalPath using transformToUrl",
@@ -4902,7 +5002,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4902
5002
  const data = context.params.data;
4903
5003
  const { webatlas } = data;
4904
5004
  const { slug, parentDocumentId, isOverride } = webatlas || {};
4905
- const transformedSlug = slug ? transformToUrl(slug) : null;
5005
+ const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
4906
5006
  const result2 = await next();
4907
5007
  if (!transformedSlug) return result2;
4908
5008
  const existing = await strapi2.db?.query(waRoute).findOne({
@@ -4953,7 +5053,10 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4953
5053
  const { documentId } = context.params;
4954
5054
  const { webatlas } = data;
4955
5055
  const { slug, parentDocumentId, isOverride } = webatlas || {};
4956
- if (!slug) return;
5056
+ if (!slug) {
5057
+ const result3 = await next();
5058
+ return result3;
5059
+ }
4957
5060
  const relatedRoute = await strapi2.documents(waRoute).findFirst({
4958
5061
  filters: {
4959
5062
  relatedDocumentId: documentId
@@ -4972,7 +5075,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4972
5075
  });
4973
5076
  }
4974
5077
  }
4975
- const transformedSlug = transformToUrl(slug);
5078
+ const transformedSlug = transformToUrl(slug, !isOverride);
4976
5079
  let rawPath = transformedSlug;
4977
5080
  if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
4978
5081
  const validatedPath = await duplicateCheck(rawPath, relatedRoute?.documentId ?? null);
@@ -5084,124 +5187,18 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
5084
5187
  );
5085
5188
  if (!contentTypeEntry) return;
5086
5189
  const [contentTypeUid, contentType] = contentTypeEntry;
5087
- const collectDocumentIds = (data, uid = contentTypeUid) => {
5088
- if (!data || typeof data !== "object") return [];
5089
- const ids = [];
5090
- if (data.documentId) {
5091
- ids.push(data.documentId);
5092
- }
5093
- const ct = strapi2.contentTypes[uid];
5094
- if (ct?.attributes) {
5095
- for (const [key, attr] of Object.entries(ct.attributes)) {
5096
- const attribute = attr;
5097
- if (attribute.type === "relation" && data[key]) {
5098
- const targetUid = attribute.target;
5099
- if (Array.isArray(data[key])) {
5100
- ids.push(...data[key].flatMap((item) => collectDocumentIds(item, targetUid)));
5101
- } else {
5102
- ids.push(...collectDocumentIds(data[key], targetUid));
5103
- }
5104
- }
5105
- if (attribute.type === "component" && data[key]) {
5106
- const componentUid = attribute.component;
5107
- if (Array.isArray(data[key])) {
5108
- ids.push(...data[key].flatMap((item) => collectDocumentIds(item, componentUid)));
5109
- } else {
5110
- ids.push(...collectDocumentIds(data[key], componentUid));
5111
- }
5112
- }
5113
- if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
5114
- ids.push(
5115
- ...data[key].flatMap((item) => {
5116
- const componentUid = item.__component;
5117
- return collectDocumentIds(item, componentUid);
5118
- })
5119
- );
5120
- }
5121
- }
5122
- }
5123
- return ids;
5124
- };
5125
- let documentIds = [];
5126
5190
  if (ctx.body.data) {
5127
5191
  if (Array.isArray(ctx.body.data)) {
5128
- documentIds = ctx.body.data.flatMap((item) => collectDocumentIds(item, contentTypeUid));
5129
- } else {
5130
- documentIds = collectDocumentIds(ctx.body.data, contentTypeUid);
5131
- }
5132
- } else if (Array.isArray(ctx.body)) {
5133
- documentIds = ctx.body.flatMap((item) => collectDocumentIds(item, contentTypeUid));
5134
- } else if (typeof ctx.body === "object") {
5135
- documentIds = collectDocumentIds(ctx.body, contentTypeUid);
5136
- }
5137
- if (documentIds.length === 0) return;
5138
- const uniqueDocumentIds = [...new Set(documentIds)];
5139
- const routes2 = await strapi2.db?.query(waRoute).findMany({
5140
- where: {
5141
- relatedDocumentId: { $in: uniqueDocumentIds }
5142
- },
5143
- select: [
5144
- "relatedDocumentId",
5145
- "relatedContentType",
5146
- "path",
5147
- "canonicalPath",
5148
- "slug",
5149
- "uidPath"
5150
- ]
5151
- });
5152
- const routeMap = new Map(routes2?.map((route2) => [route2.relatedDocumentId, route2]) || []);
5153
- const enrichWebatlasField = (data, uid = contentTypeUid) => {
5154
- if (!data || typeof data !== "object") return data;
5155
- const ct = strapi2.contentTypes[uid];
5156
- const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
5157
- if (isWebatlasEnabled && data.documentId && routeMap.has(data.documentId)) {
5158
- const route2 = routeMap.get(data.documentId);
5159
- data.webatlas = {
5160
- path: route2.path || "",
5161
- canonicalPath: route2.canonicalPath || "",
5162
- slug: route2.slug || "",
5163
- uidPath: route2.uidPath || ""
5164
- };
5165
- }
5166
- if (ct?.attributes) {
5167
- for (const [key, attr] of Object.entries(ct.attributes)) {
5168
- const attribute = attr;
5169
- if (attribute.type === "relation" && data[key]) {
5170
- const targetUid = attribute.target;
5171
- if (Array.isArray(data[key])) {
5172
- data[key] = data[key].map((item) => enrichWebatlasField(item, targetUid));
5173
- } else {
5174
- data[key] = enrichWebatlasField(data[key], targetUid);
5175
- }
5176
- }
5177
- if (attribute.type === "component" && data[key]) {
5178
- const componentUid = attribute.component;
5179
- if (Array.isArray(data[key])) {
5180
- data[key] = data[key].map((item) => enrichWebatlasField(item, componentUid));
5181
- } else {
5182
- data[key] = enrichWebatlasField(data[key], componentUid);
5183
- }
5184
- }
5185
- if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
5186
- data[key] = data[key].map((item) => {
5187
- const componentUid = item.__component;
5188
- return enrichWebatlasField(item, componentUid);
5189
- });
5190
- }
5191
- }
5192
- }
5193
- return data;
5194
- };
5195
- if (ctx.body.data) {
5196
- if (Array.isArray(ctx.body.data)) {
5197
- ctx.body.data = ctx.body.data.map((item) => enrichWebatlasField(item, contentTypeUid));
5192
+ ctx.body.data = await Promise.all(
5193
+ ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
5194
+ );
5198
5195
  } else {
5199
- ctx.body.data = enrichWebatlasField(ctx.body.data, contentTypeUid);
5196
+ ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
5200
5197
  }
5201
5198
  } else if (Array.isArray(ctx.body)) {
5202
- ctx.body = ctx.body.map((item) => enrichWebatlasField(item, contentTypeUid));
5199
+ ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
5203
5200
  } else if (typeof ctx.body === "object") {
5204
- ctx.body = enrichWebatlasField(ctx.body, contentTypeUid);
5201
+ ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
5205
5202
  }
5206
5203
  };
5207
5204
  };
@@ -6089,17 +6086,9 @@ const client = ({ strapi: strapi2 }) => ({
6089
6086
  if (!entity) return null;
6090
6087
  let cleanEntity = cleanRootKeys(entity);
6091
6088
  cleanEntity = removeWaFields(cleanEntity);
6092
- const webatlasFields = {
6093
- path: route2.path,
6094
- canonicalPath: route2.canonicalPath,
6095
- slug: route2.slug,
6096
- uidPath: route2.uidPath
6097
- };
6089
+ cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
6098
6090
  return {
6099
6091
  contentType: contentType.info.singularName,
6100
- webatlas: {
6101
- ...webatlasFields
6102
- },
6103
6092
  ...cleanEntity
6104
6093
  };
6105
6094
  } catch (e) {
@@ -6182,4 +6171,3 @@ const index = {
6182
6171
  middlewares
6183
6172
  };
6184
6173
  exports.default = index;
6185
- //# sourceMappingURL=index.js.map
@@ -4662,6 +4662,106 @@ function calculateParentAndOrder({
4662
4662
  calculatedOrder
4663
4663
  };
4664
4664
  }
4665
+ async function enrichWebatlasData(data, contentTypeUid) {
4666
+ console.log("Enriching data with webatlas fields...", { contentTypeUid });
4667
+ console.log("Original data:", JSON.stringify(data, null, 2));
4668
+ if (!data || typeof data !== "object") return data;
4669
+ const collectDocumentIds = (obj, uid) => {
4670
+ if (!obj || typeof obj !== "object") return [];
4671
+ const ids = [];
4672
+ if (obj.documentId) ids.push(obj.documentId);
4673
+ if (!uid) return ids;
4674
+ const ct = strapi.contentTypes[uid];
4675
+ if (!ct?.attributes) return ids;
4676
+ for (const [key, attr] of Object.entries(ct.attributes)) {
4677
+ const attribute = attr;
4678
+ if (attribute.type === "relation" && obj[key]) {
4679
+ const targetUid = attribute.target;
4680
+ if (Array.isArray(obj[key])) {
4681
+ ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, targetUid)));
4682
+ } else {
4683
+ ids.push(...collectDocumentIds(obj[key], targetUid));
4684
+ }
4685
+ }
4686
+ if (attribute.type === "component" && obj[key]) {
4687
+ const componentUid = attribute.component;
4688
+ if (Array.isArray(obj[key])) {
4689
+ ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, componentUid)));
4690
+ } else {
4691
+ ids.push(...collectDocumentIds(obj[key], componentUid));
4692
+ }
4693
+ }
4694
+ if (attribute.type === "dynamiczone" && Array.isArray(obj[key])) {
4695
+ ids.push(
4696
+ ...obj[key].flatMap((item) => {
4697
+ if (!item || !item.__component) return [];
4698
+ return collectDocumentIds(item, item.__component);
4699
+ })
4700
+ );
4701
+ }
4702
+ }
4703
+ return ids;
4704
+ };
4705
+ const documentIds = collectDocumentIds(data, contentTypeUid);
4706
+ if (documentIds.length === 0) return data;
4707
+ const uniqueDocumentIds = [...new Set(documentIds)];
4708
+ const routes2 = await strapi.db?.query(waRoute).findMany({
4709
+ where: {
4710
+ relatedDocumentId: { $in: uniqueDocumentIds }
4711
+ },
4712
+ select: ["relatedDocumentId", "relatedContentType", "path", "canonicalPath", "slug", "uidPath"]
4713
+ });
4714
+ const routeMap = new Map(routes2?.map((route2) => [route2.relatedDocumentId, route2]) || []);
4715
+ const enrichEntity = (entity, uid) => {
4716
+ if (!entity || typeof entity !== "object") return entity;
4717
+ const ct = uid ? strapi.contentTypes[uid] : null;
4718
+ const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
4719
+ if (isWebatlasEnabled && entity.documentId && routeMap.has(entity.documentId)) {
4720
+ const route2 = routeMap.get(entity.documentId);
4721
+ entity.webatlas = {
4722
+ path: route2.path || "",
4723
+ canonicalPath: route2.canonicalPath || "",
4724
+ slug: route2.slug || "",
4725
+ uidPath: route2.uidPath || ""
4726
+ };
4727
+ }
4728
+ if (ct?.attributes) {
4729
+ for (const [key, attr] of Object.entries(ct.attributes)) {
4730
+ const attribute = attr;
4731
+ if (attribute.type === "relation" && entity[key]) {
4732
+ const targetUid = attribute.target;
4733
+ strapi.log.debug("relation found");
4734
+ if (Array.isArray(entity[key])) {
4735
+ entity[key] = entity[key].map(
4736
+ (item) => item ? enrichEntity(item, targetUid) : item
4737
+ );
4738
+ } else {
4739
+ entity[key] = enrichEntity(entity[key], targetUid);
4740
+ }
4741
+ }
4742
+ if (attribute.type === "component" && entity[key]) {
4743
+ const componentUid = attribute.component;
4744
+ if (Array.isArray(entity[key])) {
4745
+ entity[key] = entity[key].map(
4746
+ (item) => item ? enrichEntity(item, componentUid) : item
4747
+ );
4748
+ } else {
4749
+ entity[key] = enrichEntity(entity[key], componentUid);
4750
+ }
4751
+ }
4752
+ if (attribute.type === "dynamiczone" && Array.isArray(entity[key])) {
4753
+ entity[key] = entity[key].map((item) => {
4754
+ if (!item || !item.__component) return item;
4755
+ return enrichEntity(item, item.__component);
4756
+ });
4757
+ }
4758
+ }
4759
+ }
4760
+ strapi.log.debug("finished - returning");
4761
+ return entity;
4762
+ };
4763
+ return enrichEntity(data, contentTypeUid);
4764
+ }
4665
4765
  const migration_001_canonical_path = {
4666
4766
  version: "001",
4667
4767
  description: "Migrate title field to canonicalPath using transformToUrl",
@@ -4900,7 +5000,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4900
5000
  const data = context.params.data;
4901
5001
  const { webatlas } = data;
4902
5002
  const { slug, parentDocumentId, isOverride } = webatlas || {};
4903
- const transformedSlug = slug ? transformToUrl(slug) : null;
5003
+ const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
4904
5004
  const result2 = await next();
4905
5005
  if (!transformedSlug) return result2;
4906
5006
  const existing = await strapi2.db?.query(waRoute).findOne({
@@ -4951,7 +5051,10 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4951
5051
  const { documentId } = context.params;
4952
5052
  const { webatlas } = data;
4953
5053
  const { slug, parentDocumentId, isOverride } = webatlas || {};
4954
- if (!slug) return;
5054
+ if (!slug) {
5055
+ const result3 = await next();
5056
+ return result3;
5057
+ }
4955
5058
  const relatedRoute = await strapi2.documents(waRoute).findFirst({
4956
5059
  filters: {
4957
5060
  relatedDocumentId: documentId
@@ -4970,7 +5073,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
4970
5073
  });
4971
5074
  }
4972
5075
  }
4973
- const transformedSlug = transformToUrl(slug);
5076
+ const transformedSlug = transformToUrl(slug, !isOverride);
4974
5077
  let rawPath = transformedSlug;
4975
5078
  if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
4976
5079
  const validatedPath = await duplicateCheck(rawPath, relatedRoute?.documentId ?? null);
@@ -5082,124 +5185,18 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
5082
5185
  );
5083
5186
  if (!contentTypeEntry) return;
5084
5187
  const [contentTypeUid, contentType] = contentTypeEntry;
5085
- const collectDocumentIds = (data, uid = contentTypeUid) => {
5086
- if (!data || typeof data !== "object") return [];
5087
- const ids = [];
5088
- if (data.documentId) {
5089
- ids.push(data.documentId);
5090
- }
5091
- const ct = strapi2.contentTypes[uid];
5092
- if (ct?.attributes) {
5093
- for (const [key, attr] of Object.entries(ct.attributes)) {
5094
- const attribute = attr;
5095
- if (attribute.type === "relation" && data[key]) {
5096
- const targetUid = attribute.target;
5097
- if (Array.isArray(data[key])) {
5098
- ids.push(...data[key].flatMap((item) => collectDocumentIds(item, targetUid)));
5099
- } else {
5100
- ids.push(...collectDocumentIds(data[key], targetUid));
5101
- }
5102
- }
5103
- if (attribute.type === "component" && data[key]) {
5104
- const componentUid = attribute.component;
5105
- if (Array.isArray(data[key])) {
5106
- ids.push(...data[key].flatMap((item) => collectDocumentIds(item, componentUid)));
5107
- } else {
5108
- ids.push(...collectDocumentIds(data[key], componentUid));
5109
- }
5110
- }
5111
- if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
5112
- ids.push(
5113
- ...data[key].flatMap((item) => {
5114
- const componentUid = item.__component;
5115
- return collectDocumentIds(item, componentUid);
5116
- })
5117
- );
5118
- }
5119
- }
5120
- }
5121
- return ids;
5122
- };
5123
- let documentIds = [];
5124
5188
  if (ctx.body.data) {
5125
5189
  if (Array.isArray(ctx.body.data)) {
5126
- documentIds = ctx.body.data.flatMap((item) => collectDocumentIds(item, contentTypeUid));
5127
- } else {
5128
- documentIds = collectDocumentIds(ctx.body.data, contentTypeUid);
5129
- }
5130
- } else if (Array.isArray(ctx.body)) {
5131
- documentIds = ctx.body.flatMap((item) => collectDocumentIds(item, contentTypeUid));
5132
- } else if (typeof ctx.body === "object") {
5133
- documentIds = collectDocumentIds(ctx.body, contentTypeUid);
5134
- }
5135
- if (documentIds.length === 0) return;
5136
- const uniqueDocumentIds = [...new Set(documentIds)];
5137
- const routes2 = await strapi2.db?.query(waRoute).findMany({
5138
- where: {
5139
- relatedDocumentId: { $in: uniqueDocumentIds }
5140
- },
5141
- select: [
5142
- "relatedDocumentId",
5143
- "relatedContentType",
5144
- "path",
5145
- "canonicalPath",
5146
- "slug",
5147
- "uidPath"
5148
- ]
5149
- });
5150
- const routeMap = new Map(routes2?.map((route2) => [route2.relatedDocumentId, route2]) || []);
5151
- const enrichWebatlasField = (data, uid = contentTypeUid) => {
5152
- if (!data || typeof data !== "object") return data;
5153
- const ct = strapi2.contentTypes[uid];
5154
- const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
5155
- if (isWebatlasEnabled && data.documentId && routeMap.has(data.documentId)) {
5156
- const route2 = routeMap.get(data.documentId);
5157
- data.webatlas = {
5158
- path: route2.path || "",
5159
- canonicalPath: route2.canonicalPath || "",
5160
- slug: route2.slug || "",
5161
- uidPath: route2.uidPath || ""
5162
- };
5163
- }
5164
- if (ct?.attributes) {
5165
- for (const [key, attr] of Object.entries(ct.attributes)) {
5166
- const attribute = attr;
5167
- if (attribute.type === "relation" && data[key]) {
5168
- const targetUid = attribute.target;
5169
- if (Array.isArray(data[key])) {
5170
- data[key] = data[key].map((item) => enrichWebatlasField(item, targetUid));
5171
- } else {
5172
- data[key] = enrichWebatlasField(data[key], targetUid);
5173
- }
5174
- }
5175
- if (attribute.type === "component" && data[key]) {
5176
- const componentUid = attribute.component;
5177
- if (Array.isArray(data[key])) {
5178
- data[key] = data[key].map((item) => enrichWebatlasField(item, componentUid));
5179
- } else {
5180
- data[key] = enrichWebatlasField(data[key], componentUid);
5181
- }
5182
- }
5183
- if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
5184
- data[key] = data[key].map((item) => {
5185
- const componentUid = item.__component;
5186
- return enrichWebatlasField(item, componentUid);
5187
- });
5188
- }
5189
- }
5190
- }
5191
- return data;
5192
- };
5193
- if (ctx.body.data) {
5194
- if (Array.isArray(ctx.body.data)) {
5195
- ctx.body.data = ctx.body.data.map((item) => enrichWebatlasField(item, contentTypeUid));
5190
+ ctx.body.data = await Promise.all(
5191
+ ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
5192
+ );
5196
5193
  } else {
5197
- ctx.body.data = enrichWebatlasField(ctx.body.data, contentTypeUid);
5194
+ ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
5198
5195
  }
5199
5196
  } else if (Array.isArray(ctx.body)) {
5200
- ctx.body = ctx.body.map((item) => enrichWebatlasField(item, contentTypeUid));
5197
+ ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
5201
5198
  } else if (typeof ctx.body === "object") {
5202
- ctx.body = enrichWebatlasField(ctx.body, contentTypeUid);
5199
+ ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
5203
5200
  }
5204
5201
  };
5205
5202
  };
@@ -6087,17 +6084,9 @@ const client = ({ strapi: strapi2 }) => ({
6087
6084
  if (!entity) return null;
6088
6085
  let cleanEntity = cleanRootKeys(entity);
6089
6086
  cleanEntity = removeWaFields(cleanEntity);
6090
- const webatlasFields = {
6091
- path: route2.path,
6092
- canonicalPath: route2.canonicalPath,
6093
- slug: route2.slug,
6094
- uidPath: route2.uidPath
6095
- };
6087
+ cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
6096
6088
  return {
6097
6089
  contentType: contentType.info.singularName,
6098
- webatlas: {
6099
- ...webatlasFields
6100
- },
6101
6090
  ...cleanEntity
6102
6091
  };
6103
6092
  } catch (e) {
@@ -6182,4 +6171,3 @@ const index = {
6182
6171
  export {
6183
6172
  index as default
6184
6173
  };
6185
- //# sourceMappingURL=index.mjs.map