@strapi/content-manager 5.57.0 → 5.58.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/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +27 -7
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +28 -8
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/services/relations.js +3 -0
- package/dist/admin/services/relations.js.map +1 -1
- package/dist/admin/services/relations.mjs +3 -0
- package/dist/admin/services/relations.mjs.map +1 -1
- package/dist/server/history/entitlements.js +26 -0
- package/dist/server/history/entitlements.js.map +1 -0
- package/dist/server/history/entitlements.mjs +24 -0
- package/dist/server/history/entitlements.mjs.map +1 -0
- package/dist/server/history/index.js +3 -0
- package/dist/server/history/index.js.map +1 -1
- package/dist/server/history/index.mjs +3 -0
- package/dist/server/history/index.mjs.map +1 -1
- package/dist/server/history/services/utils.js +19 -8
- package/dist/server/history/services/utils.js.map +1 -1
- package/dist/server/history/services/utils.mjs +18 -9
- package/dist/server/history/services/utils.mjs.map +1 -1
- package/dist/server/src/history/entitlements.d.ts +9 -0
- package/dist/server/src/history/entitlements.d.ts.map +1 -0
- package/dist/server/src/history/index.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +6 -0
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/shared/contracts/relations.d.ts +1 -0
- package/dist/shared/contracts/relations.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations.js","sources":["../../../admin/src/services/relations.ts"],"sourcesContent":["import { generateNKeysBetween } from 'fractional-indexing';\n\nimport {\n RelationResult as RelResult,\n FindAvailable,\n FindExisting,\n} from '../../../shared/contracts/relations';\n\nimport { contentManagerApi } from './api';\n\nimport type { Modules } from '@strapi/types';\nimport type { errors } from '@strapi/utils';\n\ninterface RelationResult extends RelResult {\n __temp_key__: string;\n}\n\ntype GetRelationsResponse =\n | {\n results: Array<RelationResult>;\n pagination: {\n page: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['page']>;\n pageSize: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['pageSize']>;\n pageCount: number;\n total: number;\n } | null;\n error?: never;\n }\n | {\n results?: never;\n pagination?: never;\n error: errors.ApplicationError | errors.YupValidationError;\n };\n\nconst relationsApi = contentManagerApi.injectEndpoints({\n endpoints: (build) => ({\n getRelations: build.query<\n GetRelationsResponse,\n FindExisting.Params & {\n params?: FindExisting.Request['query'];\n }\n >({\n query: ({ model, id, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${id}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n id: queryArgs.id,\n targetField: queryArgs.targetField,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n *\n * Push new items at the beginning as latest items are shown first\n */\n currentCache.results = [\n ...prepareTempKeys(newItems.results, currentCache.results),\n ...currentCache.results,\n ];\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = prepareTempKeys(newItems.results);\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindExisting.Response) => {\n if ('results' in response && response.results) {\n return {\n ...response,\n results: prepareTempKeys(response.results.toReversed()),\n };\n } else {\n return response;\n }\n },\n providesTags: ['Relations'],\n }),\n searchRelations: build.query<\n FindAvailable.Response,\n FindAvailable.Params & {\n params?: FindAvailable.Request['query'];\n }\n >({\n query: ({ model, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n targetField: queryArgs.targetField,\n _q: queryArgs.params?._q,\n idsToOmit: queryArgs.params?.idsToOmit,\n idsToInclude: queryArgs.params?.idsToInclude,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n */\n const existingIds = currentCache.results.map((item) => item.documentId);\n const uniqueNewItems = newItems.results.filter(\n (item) => !existingIds.includes(item.documentId)\n );\n currentCache.results.push(...uniqueNewItems);\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = newItems.results;\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindAvailable.Response) => {\n if (response.results) {\n return {\n ...response,\n results: response.results,\n };\n } else {\n return response;\n }\n },\n }),\n }),\n});\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each relation item. This gives us\n * a stable identifier regardless of it's ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = (relations: RelResult[], existingRelations: RelationResult[] = []) => {\n const [firstItem] = existingRelations.slice(0);\n const keys = generateNKeysBetween(null, firstItem?.__temp_key__ ?? null, relations.length);\n\n return relations.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n};\n\nconst { useGetRelationsQuery, useLazySearchRelationsQuery } = relationsApi;\n\nexport { useGetRelationsQuery, useLazySearchRelationsQuery };\nexport type { RelationResult };\n"],"names":["relationsApi","contentManagerApi","injectEndpoints","endpoints","build","getRelations","query","model","id","targetField","params","url","method","config","serializeQueryArgs","args","endpointName","queryArgs","locale","status","merge","currentCache","newItems","pagination","page","results","prepareTempKeys","forceRefetch","currentArg","previousArg","pageSize","transformResponse","response","toReversed","providesTags","searchRelations","_q","idsToOmit","idsToInclude","existingIds","map","item","documentId","uniqueNewItems","filter","includes","push","relations","existingRelations","firstItem","slice","keys","generateNKeysBetween","__temp_key__","length","datum","index","useGetRelationsQuery","useLazySearchRelationsQuery"],"mappings":";;;;;AAkCA,MAAMA,YAAAA,GAAeC,qBAAAA,CAAkBC,eAAe,CAAC;IACrDC,SAAAA,EAAW,CAACC,SAAW;YACrBC,YAAAA,EAAcD,KAAAA,CAAME,KAAK,CAKvB;gBACAA,KAAAA,EAAO,CAAC,EAAEC,KAAK,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAA;oBACxC,OAAO;wBACLC,GAAAA,EAAK,CAAC,2BAA2B,EAAEJ,KAAAA,CAAM,CAAC,EAAEC,EAAAA,CAAG,CAAC,EAAEC,WAAAA,CAAAA,CAAa;wBAC/DG,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACNH,4BAAAA;AACF;AACF,qBAAA;AACF,gBAAA,CAAA;AACAI,gBAAAA,kBAAAA,EAAoB,CAACC,IAAAA,GAAAA;AACnB,oBAAA,MAAM,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGF,IAAAA;oBACpC,OAAO;AACLC,wBAAAA,YAAAA;AACAT,wBAAAA,KAAAA,EAAOU,UAAUV,KAAK;AACtBC,wBAAAA,EAAAA,EAAIS,UAAUT,EAAE;AAChBC,wBAAAA,WAAAA,EAAaQ,UAAUR,WAAW;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E1D,gBAAA,CAAA;AACAC,gBAAAA,iBAAAA,EAAmB,CAACC,QAAAA,GAAAA;oBAClB,IAAIA,QAAAA,CAASP,OAAO,EAAE;wBACpB,OAAO;AACL,4BAAA,GAAGO,QAAQ;AACXP,4BAAAA,OAAAA,EAASO,SAASP;AACpB,yBAAA;oBACF,CAAA,MAAO;wBACL,OAAOO,QAAAA;AACT,oBAAA;AACF,gBAAA;AACF,aAAA;SACF;AACF,CAAA,CAAA;AAEA;;;;AAIC,IACD,MAAMN,eAAAA,GAAkB,CAACqB,SAAAA,EAAwBC,oBAAsC,EAAE,GAAA;AACvF,IAAA,MAAM,CAACC,SAAAA,CAAU,GAAGD,iBAAAA,CAAkBE,KAAK,CAAC,CAAA,CAAA;AAC5C,IAAA,MAAMC,OAAOC,uCAAAA,CAAqB,IAAA,EAAMH,WAAWI,YAAAA,IAAgB,IAAA,EAAMN,UAAUO,MAAM,CAAA;AAEzF,IAAA,OAAOP,UAAUP,GAAG,CAAC,CAACe,KAAAA,EAAOC,SAAW;AACtC,YAAA,GAAGD,KAAK;YACRF,YAAAA,EAAcF,IAAI,CAACK,KAAAA;SACrB,CAAA,CAAA;AACF,CAAA;AAEA,MAAM,EAAEC,oBAAoB,EAAEC,2BAA2B,EAAE,GAAG1D;;;;;"}
|
|
1
|
+
{"version":3,"file":"relations.js","sources":["../../../admin/src/services/relations.ts"],"sourcesContent":["import { generateNKeysBetween } from 'fractional-indexing';\n\nimport {\n RelationResult as RelResult,\n FindAvailable,\n FindExisting,\n} from '../../../shared/contracts/relations';\n\nimport { contentManagerApi } from './api';\n\nimport type { Modules } from '@strapi/types';\nimport type { errors } from '@strapi/utils';\n\ninterface RelationResult extends RelResult {\n __temp_key__: string;\n}\n\ntype GetRelationsResponse =\n | {\n results: Array<RelationResult>;\n pagination: {\n page: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['page']>;\n pageSize: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['pageSize']>;\n pageCount: number;\n total: number;\n } | null;\n error?: never;\n }\n | {\n results?: never;\n pagination?: never;\n error: errors.ApplicationError | errors.YupValidationError;\n };\n\nconst relationsApi = contentManagerApi.injectEndpoints({\n endpoints: (build) => ({\n getRelations: build.query<\n GetRelationsResponse,\n FindExisting.Params & {\n params?: FindExisting.Request['query'];\n }\n >({\n query: ({ model, id, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${id}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n id: queryArgs.id,\n targetField: queryArgs.targetField,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n *\n * Push new items at the beginning as latest items are shown first\n */\n currentCache.results = [\n ...prepareTempKeys(newItems.results, currentCache.results),\n ...currentCache.results,\n ];\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = prepareTempKeys(newItems.results);\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindExisting.Response) => {\n if ('results' in response && response.results) {\n return {\n ...response,\n results: prepareTempKeys(response.results.toReversed()),\n };\n } else {\n return response;\n }\n },\n providesTags: ['Relations'],\n }),\n searchRelations: build.query<\n FindAvailable.Response,\n FindAvailable.Params & {\n params?: FindAvailable.Request['query'];\n }\n >({\n query: ({ model, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n targetField: queryArgs.targetField,\n id: queryArgs.params?.id,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n _q: queryArgs.params?._q,\n idsToOmit: queryArgs.params?.idsToOmit,\n idsToInclude: queryArgs.params?.idsToInclude,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n */\n const existingIds = currentCache.results.map((item) => item.documentId);\n const uniqueNewItems = newItems.results.filter(\n (item) => !existingIds.includes(item.documentId)\n );\n currentCache.results.push(...uniqueNewItems);\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = newItems.results;\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindAvailable.Response) => {\n if (response.results) {\n return {\n ...response,\n results: response.results,\n };\n } else {\n return response;\n }\n },\n }),\n }),\n});\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each relation item. This gives us\n * a stable identifier regardless of it's ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = (relations: RelResult[], existingRelations: RelationResult[] = []) => {\n const [firstItem] = existingRelations.slice(0);\n const keys = generateNKeysBetween(null, firstItem?.__temp_key__ ?? null, relations.length);\n\n return relations.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n};\n\nconst { useGetRelationsQuery, useLazySearchRelationsQuery } = relationsApi;\n\nexport { useGetRelationsQuery, useLazySearchRelationsQuery };\nexport type { RelationResult };\n"],"names":["relationsApi","contentManagerApi","injectEndpoints","endpoints","build","getRelations","query","model","id","targetField","params","url","method","config","serializeQueryArgs","args","endpointName","queryArgs","locale","status","merge","currentCache","newItems","pagination","page","results","prepareTempKeys","forceRefetch","currentArg","previousArg","pageSize","transformResponse","response","toReversed","providesTags","searchRelations","_q","idsToOmit","idsToInclude","existingIds","map","item","documentId","uniqueNewItems","filter","includes","push","relations","existingRelations","firstItem","slice","keys","generateNKeysBetween","__temp_key__","length","datum","index","useGetRelationsQuery","useLazySearchRelationsQuery"],"mappings":";;;;;AAkCA,MAAMA,YAAAA,GAAeC,qBAAAA,CAAkBC,eAAe,CAAC;IACrDC,SAAAA,EAAW,CAACC,SAAW;YACrBC,YAAAA,EAAcD,KAAAA,CAAME,KAAK,CAKvB;gBACAA,KAAAA,EAAO,CAAC,EAAEC,KAAK,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAA;oBACxC,OAAO;wBACLC,GAAAA,EAAK,CAAC,2BAA2B,EAAEJ,KAAAA,CAAM,CAAC,EAAEC,EAAAA,CAAG,CAAC,EAAEC,WAAAA,CAAAA,CAAa;wBAC/DG,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACNH,4BAAAA;AACF;AACF,qBAAA;AACF,gBAAA,CAAA;AACAI,gBAAAA,kBAAAA,EAAoB,CAACC,IAAAA,GAAAA;AACnB,oBAAA,MAAM,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGF,IAAAA;oBACpC,OAAO;AACLC,wBAAAA,YAAAA;AACAT,wBAAAA,KAAAA,EAAOU,UAAUV,KAAK;AACtBC,wBAAAA,EAAAA,EAAIS,UAAUT,EAAE;AAChBC,wBAAAA,WAAAA,EAAaQ,UAAUR,WAAW;wBAClCS,MAAAA,EAAQD,SAAAA,CAAUP,MAAM,EAAEQ,MAAAA;wBAC1BC,MAAAA,EAAQF,SAAAA,CAAUP,MAAM,EAAES;AAC5B,qBAAA;AACF,gBAAA,CAAA;AACAC,gBAAAA,KAAAA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oB,QAAAA;AAE1D,gBAAA,CAAA;AACAC,gBAAAA,iBAAAA,EAAmB,CAACC,QAAAA,GAAAA;oBAClB,IAAIA,QAAAA,CAASP,OAAO,EAAE;wBACpB,OAAO;AACL,4BAAA,GAAGO,QAAQ;AACXP,4BAAAA,OAAAA,EAASO,SAASP;AACpB,yBAAA;oBACF,CAAA,MAAO;wBACL,OAAOO,QAAAA;AACT,oBAAA;AACF,gBAAA;AACF,aAAA;SACF;AACF,CAAA,CAAA;AAEA;;;;AAIC,IACD,MAAMN,eAAAA,GAAkB,CAACqB,SAAAA,EAAwBC,oBAAsC,EAAE,GAAA;AACvF,IAAA,MAAM,CAACC,SAAAA,CAAU,GAAGD,iBAAAA,CAAkBE,KAAK,CAAC,CAAA,CAAA;AAC5C,IAAA,MAAMC,OAAOC,uCAAAA,CAAqB,IAAA,EAAMH,WAAWI,YAAAA,IAAgB,IAAA,EAAMN,UAAUO,MAAM,CAAA;AAEzF,IAAA,OAAOP,UAAUP,GAAG,CAAC,CAACe,KAAAA,EAAOC,SAAW;AACtC,YAAA,GAAGD,KAAK;YACRF,YAAAA,EAAcF,IAAI,CAACK,KAAAA;SACrB,CAAA,CAAA;AACF,CAAA;AAEA,MAAM,EAAEC,oBAAoB,EAAEC,2BAA2B,EAAE,GAAG1D;;;;;"}
|
|
@@ -81,6 +81,9 @@ const relationsApi = contentManagerApi.injectEndpoints({
|
|
|
81
81
|
endpointName,
|
|
82
82
|
model: queryArgs.model,
|
|
83
83
|
targetField: queryArgs.targetField,
|
|
84
|
+
id: queryArgs.params?.id,
|
|
85
|
+
locale: queryArgs.params?.locale,
|
|
86
|
+
status: queryArgs.params?.status,
|
|
84
87
|
_q: queryArgs.params?._q,
|
|
85
88
|
idsToOmit: queryArgs.params?.idsToOmit,
|
|
86
89
|
idsToInclude: queryArgs.params?.idsToInclude
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations.mjs","sources":["../../../admin/src/services/relations.ts"],"sourcesContent":["import { generateNKeysBetween } from 'fractional-indexing';\n\nimport {\n RelationResult as RelResult,\n FindAvailable,\n FindExisting,\n} from '../../../shared/contracts/relations';\n\nimport { contentManagerApi } from './api';\n\nimport type { Modules } from '@strapi/types';\nimport type { errors } from '@strapi/utils';\n\ninterface RelationResult extends RelResult {\n __temp_key__: string;\n}\n\ntype GetRelationsResponse =\n | {\n results: Array<RelationResult>;\n pagination: {\n page: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['page']>;\n pageSize: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['pageSize']>;\n pageCount: number;\n total: number;\n } | null;\n error?: never;\n }\n | {\n results?: never;\n pagination?: never;\n error: errors.ApplicationError | errors.YupValidationError;\n };\n\nconst relationsApi = contentManagerApi.injectEndpoints({\n endpoints: (build) => ({\n getRelations: build.query<\n GetRelationsResponse,\n FindExisting.Params & {\n params?: FindExisting.Request['query'];\n }\n >({\n query: ({ model, id, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${id}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n id: queryArgs.id,\n targetField: queryArgs.targetField,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n *\n * Push new items at the beginning as latest items are shown first\n */\n currentCache.results = [\n ...prepareTempKeys(newItems.results, currentCache.results),\n ...currentCache.results,\n ];\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = prepareTempKeys(newItems.results);\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindExisting.Response) => {\n if ('results' in response && response.results) {\n return {\n ...response,\n results: prepareTempKeys(response.results.toReversed()),\n };\n } else {\n return response;\n }\n },\n providesTags: ['Relations'],\n }),\n searchRelations: build.query<\n FindAvailable.Response,\n FindAvailable.Params & {\n params?: FindAvailable.Request['query'];\n }\n >({\n query: ({ model, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n targetField: queryArgs.targetField,\n _q: queryArgs.params?._q,\n idsToOmit: queryArgs.params?.idsToOmit,\n idsToInclude: queryArgs.params?.idsToInclude,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n */\n const existingIds = currentCache.results.map((item) => item.documentId);\n const uniqueNewItems = newItems.results.filter(\n (item) => !existingIds.includes(item.documentId)\n );\n currentCache.results.push(...uniqueNewItems);\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = newItems.results;\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindAvailable.Response) => {\n if (response.results) {\n return {\n ...response,\n results: response.results,\n };\n } else {\n return response;\n }\n },\n }),\n }),\n});\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each relation item. This gives us\n * a stable identifier regardless of it's ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = (relations: RelResult[], existingRelations: RelationResult[] = []) => {\n const [firstItem] = existingRelations.slice(0);\n const keys = generateNKeysBetween(null, firstItem?.__temp_key__ ?? null, relations.length);\n\n return relations.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n};\n\nconst { useGetRelationsQuery, useLazySearchRelationsQuery } = relationsApi;\n\nexport { useGetRelationsQuery, useLazySearchRelationsQuery };\nexport type { RelationResult };\n"],"names":["relationsApi","contentManagerApi","injectEndpoints","endpoints","build","getRelations","query","model","id","targetField","params","url","method","config","serializeQueryArgs","args","endpointName","queryArgs","locale","status","merge","currentCache","newItems","pagination","page","results","prepareTempKeys","forceRefetch","currentArg","previousArg","pageSize","transformResponse","response","toReversed","providesTags","searchRelations","_q","idsToOmit","idsToInclude","existingIds","map","item","documentId","uniqueNewItems","filter","includes","push","relations","existingRelations","firstItem","slice","keys","generateNKeysBetween","__temp_key__","length","datum","index","useGetRelationsQuery","useLazySearchRelationsQuery"],"mappings":";;;AAkCA,MAAMA,YAAAA,GAAeC,iBAAAA,CAAkBC,eAAe,CAAC;IACrDC,SAAAA,EAAW,CAACC,SAAW;YACrBC,YAAAA,EAAcD,KAAAA,CAAME,KAAK,CAKvB;gBACAA,KAAAA,EAAO,CAAC,EAAEC,KAAK,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAA;oBACxC,OAAO;wBACLC,GAAAA,EAAK,CAAC,2BAA2B,EAAEJ,KAAAA,CAAM,CAAC,EAAEC,EAAAA,CAAG,CAAC,EAAEC,WAAAA,CAAAA,CAAa;wBAC/DG,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACNH,4BAAAA;AACF;AACF,qBAAA;AACF,gBAAA,CAAA;AACAI,gBAAAA,kBAAAA,EAAoB,CAACC,IAAAA,GAAAA;AACnB,oBAAA,MAAM,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGF,IAAAA;oBACpC,OAAO;AACLC,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AA,EAAQc,IAAAA,KAASK,WAAAA,EAAanB,MAAAA,EAAQc,QAClDI,UAAAA,EAAYlB,MAAAA,EAAQoB,QAAAA,KAAaD,WAAAA,EAAanB,MAAAA,EAAQoB,QAAAA;AAE1D,gBAAA,CAAA;AACAC,gBAAAA,iBAAAA,EAAmB,CAACC,QAAAA,GAAAA;oBAClB,IAAIA,QAAAA,CAASP,OAAO,EAAE;wBACpB,OAAO;AACL,4BAAA,GAAGO,QAAQ;AACXP,4BAAAA,OAAAA,EAASO,SAASP;AACpB,yBAAA;oBACF,CAAA,MAAO;wBACL,OAAOO,QAAAA;AACT,oBAAA;AACF,gBAAA;AACF,aAAA;SACF;AACF,CAAA,CAAA;AAEA;;;;AAIC,IACD,MAAMN,eAAAA,GAAkB,CAACqB,SAAAA,EAAwBC,oBAAsC,EAAE,GAAA;AACvF,IAAA,MAAM,CAACC,SAAAA,CAAU,GAAGD,iBAAAA,CAAkBE,KAAK,CAAC,CAAA,CAAA;AAC5C,IAAA,MAAMC,OAAOC,oBAAAA,CAAqB,IAAA,EAAMH,WAAWI,YAAAA,IAAgB,IAAA,EAAMN,UAAUO,MAAM,CAAA;AAEzF,IAAA,OAAOP,UAAUP,GAAG,CAAC,CAACe,KAAAA,EAAOC,SAAW;AACtC,YAAA,GAAGD,KAAK;YACRF,YAAAA,EAAcF,IAAI,CAACK,KAAAA;SACrB,CAAA,CAAA;AACF,CAAA;AAEA,MAAM,EAAEC,oBAAoB,EAAEC,2BAA2B,EAAE,GAAG1D;;;;"}
|
|
1
|
+
{"version":3,"file":"relations.mjs","sources":["../../../admin/src/services/relations.ts"],"sourcesContent":["import { generateNKeysBetween } from 'fractional-indexing';\n\nimport {\n RelationResult as RelResult,\n FindAvailable,\n FindExisting,\n} from '../../../shared/contracts/relations';\n\nimport { contentManagerApi } from './api';\n\nimport type { Modules } from '@strapi/types';\nimport type { errors } from '@strapi/utils';\n\ninterface RelationResult extends RelResult {\n __temp_key__: string;\n}\n\ntype GetRelationsResponse =\n | {\n results: Array<RelationResult>;\n pagination: {\n page: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['page']>;\n pageSize: NonNullable<Modules.EntityService.Params.Pagination.PageNotation['pageSize']>;\n pageCount: number;\n total: number;\n } | null;\n error?: never;\n }\n | {\n results?: never;\n pagination?: never;\n error: errors.ApplicationError | errors.YupValidationError;\n };\n\nconst relationsApi = contentManagerApi.injectEndpoints({\n endpoints: (build) => ({\n getRelations: build.query<\n GetRelationsResponse,\n FindExisting.Params & {\n params?: FindExisting.Request['query'];\n }\n >({\n query: ({ model, id, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${id}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n id: queryArgs.id,\n targetField: queryArgs.targetField,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n *\n * Push new items at the beginning as latest items are shown first\n */\n currentCache.results = [\n ...prepareTempKeys(newItems.results, currentCache.results),\n ...currentCache.results,\n ];\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = prepareTempKeys(newItems.results);\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindExisting.Response) => {\n if ('results' in response && response.results) {\n return {\n ...response,\n results: prepareTempKeys(response.results.toReversed()),\n };\n } else {\n return response;\n }\n },\n providesTags: ['Relations'],\n }),\n searchRelations: build.query<\n FindAvailable.Response,\n FindAvailable.Params & {\n params?: FindAvailable.Request['query'];\n }\n >({\n query: ({ model, targetField, params }) => {\n return {\n url: `/content-manager/relations/${model}/${targetField}`,\n method: 'GET',\n config: {\n params,\n },\n };\n },\n serializeQueryArgs: (args) => {\n const { endpointName, queryArgs } = args;\n return {\n endpointName,\n model: queryArgs.model,\n targetField: queryArgs.targetField,\n id: queryArgs.params?.id,\n locale: queryArgs.params?.locale,\n status: queryArgs.params?.status,\n _q: queryArgs.params?._q,\n idsToOmit: queryArgs.params?.idsToOmit,\n idsToInclude: queryArgs.params?.idsToInclude,\n };\n },\n merge: (currentCache, newItems) => {\n if (currentCache.pagination && newItems.pagination) {\n if (currentCache.pagination.page < newItems.pagination.page) {\n /**\n * Relations will always have unique IDs, so we can therefore assume\n * that we only need to push the new items to the cache.\n */\n const existingIds = currentCache.results.map((item) => item.documentId);\n const uniqueNewItems = newItems.results.filter(\n (item) => !existingIds.includes(item.documentId)\n );\n currentCache.results.push(...uniqueNewItems);\n currentCache.pagination = newItems.pagination;\n } else if (newItems.pagination.page === 1) {\n /**\n * We're resetting the relations\n */\n currentCache.results = newItems.results;\n currentCache.pagination = newItems.pagination;\n }\n }\n },\n forceRefetch({ currentArg, previousArg }) {\n if (!currentArg?.params && !previousArg?.params) {\n return false;\n }\n\n return (\n currentArg?.params?.page !== previousArg?.params?.page ||\n currentArg?.params?.pageSize !== previousArg?.params?.pageSize\n );\n },\n transformResponse: (response: FindAvailable.Response) => {\n if (response.results) {\n return {\n ...response,\n results: response.results,\n };\n } else {\n return response;\n }\n },\n }),\n }),\n});\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each relation item. This gives us\n * a stable identifier regardless of it's ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = (relations: RelResult[], existingRelations: RelationResult[] = []) => {\n const [firstItem] = existingRelations.slice(0);\n const keys = generateNKeysBetween(null, firstItem?.__temp_key__ ?? null, relations.length);\n\n return relations.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n};\n\nconst { useGetRelationsQuery, useLazySearchRelationsQuery } = relationsApi;\n\nexport { useGetRelationsQuery, useLazySearchRelationsQuery };\nexport type { RelationResult };\n"],"names":["relationsApi","contentManagerApi","injectEndpoints","endpoints","build","getRelations","query","model","id","targetField","params","url","method","config","serializeQueryArgs","args","endpointName","queryArgs","locale","status","merge","currentCache","newItems","pagination","page","results","prepareTempKeys","forceRefetch","currentArg","previousArg","pageSize","transformResponse","response","toReversed","providesTags","searchRelations","_q","idsToOmit","idsToInclude","existingIds","map","item","documentId","uniqueNewItems","filter","includes","push","relations","existingRelations","firstItem","slice","keys","generateNKeysBetween","__temp_key__","length","datum","index","useGetRelationsQuery","useLazySearchRelationsQuery"],"mappings":";;;AAkCA,MAAMA,YAAAA,GAAeC,iBAAAA,CAAkBC,eAAe,CAAC;IACrDC,SAAAA,EAAW,CAACC,SAAW;YACrBC,YAAAA,EAAcD,KAAAA,CAAME,KAAK,CAKvB;gBACAA,KAAAA,EAAO,CAAC,EAAEC,KAAK,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAA;oBACxC,OAAO;wBACLC,GAAAA,EAAK,CAAC,2BAA2B,EAAEJ,KAAAA,CAAM,CAAC,EAAEC,EAAAA,CAAG,CAAC,EAAEC,WAAAA,CAAAA,CAAa;wBAC/DG,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACNH,4BAAAA;AACF;AACF,qBAAA;AACF,gBAAA,CAAA;AACAI,gBAAAA,kBAAAA,EAAoB,CAACC,IAAAA,GAAAA;AACnB,oBAAA,MAAM,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGF,IAAAA;oBACpC,OAAO;AACLC,wBAAAA,YAAAA;AACAT,wBAAAA,KAAAA,EAAOU,UAAUV,KAAK;AACtBC,wBAAAA,EAAAA,EAAIS,UAAUT,EAAE;AAChBC,wBAAAA,WAAAA,EAAaQ,UAAUR,WAAW;wBAClCS,MAAAA,EA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EAAYlB,MAAAA,EAAQc,IAAAA,KAASK,WAAAA,EAAanB,MAAAA,EAAQc,QAClDI,UAAAA,EAAYlB,MAAAA,EAAQoB,QAAAA,KAAaD,WAAAA,EAAanB,MAAAA,EAAQoB,QAAAA;AAE1D,gBAAA,CAAA;AACAC,gBAAAA,iBAAAA,EAAmB,CAACC,QAAAA,GAAAA;oBAClB,IAAIA,QAAAA,CAASP,OAAO,EAAE;wBACpB,OAAO;AACL,4BAAA,GAAGO,QAAQ;AACXP,4BAAAA,OAAAA,EAASO,SAASP;AACpB,yBAAA;oBACF,CAAA,MAAO;wBACL,OAAOO,QAAAA;AACT,oBAAA;AACF,gBAAA;AACF,aAAA;SACF;AACF,CAAA,CAAA;AAEA;;;;AAIC,IACD,MAAMN,eAAAA,GAAkB,CAACqB,SAAAA,EAAwBC,oBAAsC,EAAE,GAAA;AACvF,IAAA,MAAM,CAACC,SAAAA,CAAU,GAAGD,iBAAAA,CAAkBE,KAAK,CAAC,CAAA,CAAA;AAC5C,IAAA,MAAMC,OAAOC,oBAAAA,CAAqB,IAAA,EAAMH,WAAWI,YAAAA,IAAgB,IAAA,EAAMN,UAAUO,MAAM,CAAA;AAEzF,IAAA,OAAOP,UAAUP,GAAG,CAAC,CAACe,KAAAA,EAAOC,SAAW;AACtC,YAAA,GAAGD,KAAK;YACRF,YAAAA,EAAcF,IAAI,CAACK,KAAAA;SACrB,CAAA,CAAA;AACF,CAAA;AAEA,MAAM,EAAEC,oBAAoB,EAAEC,2BAA2B,EAAE,GAAG1D;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./services/utils.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reports the history retention the delete job uses for the Plan card and the debug dump. That
|
|
7
|
+
* caps an unconfigured instance at the default even when the license allows far more, so the
|
|
8
|
+
* card never promises retention the job does not keep. Registered whatever the boot-time license
|
|
9
|
+
* says, so a lapsed or later-renewed license still resolves.
|
|
10
|
+
*/ const registerHistoryEntitlements = (strapi)=>{
|
|
11
|
+
strapi.ee.entitlements.register({
|
|
12
|
+
feature: 'cms-content-history',
|
|
13
|
+
limits: [
|
|
14
|
+
{
|
|
15
|
+
key: 'retentionDays',
|
|
16
|
+
unit: 'days',
|
|
17
|
+
get (feature) {
|
|
18
|
+
return utils.computeRetentionDays(typeof feature === 'object' ? feature.options?.retentionDays : undefined, strapi.config.get('admin.history.retentionDays'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.registerHistoryEntitlements = registerHistoryEntitlements;
|
|
26
|
+
//# sourceMappingURL=entitlements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.js","sources":["../../../server/src/history/entitlements.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport { computeRetentionDays } from './services/utils';\n\n/**\n * Reports the history retention the delete job uses for the Plan card and the debug dump. That\n * caps an unconfigured instance at the default even when the license allows far more, so the\n * card never promises retention the job does not keep. Registered whatever the boot-time license\n * says, so a lapsed or later-renewed license still resolves.\n */\nexport const registerHistoryEntitlements = (strapi: Core.Strapi) => {\n strapi.ee.entitlements.register({\n feature: 'cms-content-history',\n limits: [\n {\n key: 'retentionDays',\n unit: 'days',\n get(feature) {\n return computeRetentionDays(\n typeof feature === 'object' ? feature.options?.retentionDays : undefined,\n strapi.config.get('admin.history.retentionDays')\n );\n },\n },\n ],\n });\n};\n"],"names":["registerHistoryEntitlements","strapi","ee","entitlements","register","feature","limits","key","unit","get","computeRetentionDays","options","retentionDays","undefined","config"],"mappings":";;;;AAIA;;;;;IAMO,MAAMA,2BAAAA,GAA8B,CAACC,MAAAA,GAAAA;AAC1CA,IAAAA,MAAAA,CAAOC,EAAE,CAACC,YAAY,CAACC,QAAQ,CAAC;QAC9BC,OAAAA,EAAS,qBAAA;QACTC,MAAAA,EAAQ;AACN,YAAA;gBACEC,GAAAA,EAAK,eAAA;gBACLC,IAAAA,EAAM,MAAA;AACNC,gBAAAA,GAAAA,CAAAA,CAAIJ,OAAO,EAAA;AACT,oBAAA,OAAOK,0BAAAA,CACL,OAAOL,OAAAA,KAAY,QAAA,GAAWA,OAAAA,CAAQM,OAAO,EAAEC,aAAAA,GAAgBC,SAAAA,EAC/DZ,MAAAA,CAAOa,MAAM,CAACL,GAAG,CAAC,6BAAA,CAAA,CAAA;AAEtB,gBAAA;AACF;AACD;AACH,KAAA,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { computeRetentionDays } from './services/utils.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reports the history retention the delete job uses for the Plan card and the debug dump. That
|
|
5
|
+
* caps an unconfigured instance at the default even when the license allows far more, so the
|
|
6
|
+
* card never promises retention the job does not keep. Registered whatever the boot-time license
|
|
7
|
+
* says, so a lapsed or later-renewed license still resolves.
|
|
8
|
+
*/ const registerHistoryEntitlements = (strapi)=>{
|
|
9
|
+
strapi.ee.entitlements.register({
|
|
10
|
+
feature: 'cms-content-history',
|
|
11
|
+
limits: [
|
|
12
|
+
{
|
|
13
|
+
key: 'retentionDays',
|
|
14
|
+
unit: 'days',
|
|
15
|
+
get (feature) {
|
|
16
|
+
return computeRetentionDays(typeof feature === 'object' ? feature.options?.retentionDays : undefined, strapi.config.get('admin.history.retentionDays'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { registerHistoryEntitlements };
|
|
24
|
+
//# sourceMappingURL=entitlements.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.mjs","sources":["../../../server/src/history/entitlements.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport { computeRetentionDays } from './services/utils';\n\n/**\n * Reports the history retention the delete job uses for the Plan card and the debug dump. That\n * caps an unconfigured instance at the default even when the license allows far more, so the\n * card never promises retention the job does not keep. Registered whatever the boot-time license\n * says, so a lapsed or later-renewed license still resolves.\n */\nexport const registerHistoryEntitlements = (strapi: Core.Strapi) => {\n strapi.ee.entitlements.register({\n feature: 'cms-content-history',\n limits: [\n {\n key: 'retentionDays',\n unit: 'days',\n get(feature) {\n return computeRetentionDays(\n typeof feature === 'object' ? feature.options?.retentionDays : undefined,\n strapi.config.get('admin.history.retentionDays')\n );\n },\n },\n ],\n });\n};\n"],"names":["registerHistoryEntitlements","strapi","ee","entitlements","register","feature","limits","key","unit","get","computeRetentionDays","options","retentionDays","undefined","config"],"mappings":";;AAIA;;;;;IAMO,MAAMA,2BAAAA,GAA8B,CAACC,MAAAA,GAAAA;AAC1CA,IAAAA,MAAAA,CAAOC,EAAE,CAACC,YAAY,CAACC,QAAQ,CAAC;QAC9BC,OAAAA,EAAS,qBAAA;QACTC,MAAAA,EAAQ;AACN,YAAA;gBACEC,GAAAA,EAAK,eAAA;gBACLC,IAAAA,EAAM,MAAA;AACNC,gBAAAA,GAAAA,CAAAA,CAAIJ,OAAO,EAAA;AACT,oBAAA,OAAOK,oBAAAA,CACL,OAAOL,OAAAA,KAAY,QAAA,GAAWA,OAAAA,CAAQM,OAAO,EAAEC,aAAAA,GAAgBC,SAAAA,EAC/DZ,MAAAA,CAAOa,MAAM,CAACL,GAAG,CAAC,6BAAA,CAAA,CAAA;AAEtB,gBAAA;AACF;AACD;AACH,KAAA,CAAA;AACF;;;;"}
|
|
@@ -5,6 +5,7 @@ var index$1 = require('./services/index.js');
|
|
|
5
5
|
var index = require('./routes/index.js');
|
|
6
6
|
var utils = require('./utils.js');
|
|
7
7
|
var historyVersion = require('./models/history-version.js');
|
|
8
|
+
var entitlements = require('./entitlements.js');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Check once if the feature is enabled before loading it,
|
|
@@ -14,6 +15,7 @@ var historyVersion = require('./models/history-version.js');
|
|
|
14
15
|
return {
|
|
15
16
|
register ({ strapi: strapi1 }) {
|
|
16
17
|
strapi1.get('models').add(historyVersion.historyVersion);
|
|
18
|
+
entitlements.registerHistoryEntitlements(strapi1);
|
|
17
19
|
},
|
|
18
20
|
bootstrap ({ strapi: strapi1 }) {
|
|
19
21
|
// Start recording history and saving history versions
|
|
@@ -33,6 +35,7 @@ var historyVersion = require('./models/history-version.js');
|
|
|
33
35
|
*/ return {
|
|
34
36
|
register ({ strapi: strapi1 }) {
|
|
35
37
|
strapi1.get('models').add(historyVersion.historyVersion);
|
|
38
|
+
entitlements.registerHistoryEntitlements(strapi1);
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../server/src/history/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { controllers } from './controllers';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { getService } from './utils';\nimport { historyVersion } from './models/history-version';\n\n/**\n * Check once if the feature is enabled before loading it,\n * so that we can assume it is enabled in the other files.\n */\nconst getFeature = (): Partial<Plugin.LoadedPlugin> => {\n if (strapi.ee.features.isEnabled('cms-content-history')) {\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n },\n bootstrap({ strapi }) {\n // Start recording history and saving history versions\n getService(strapi, 'lifecycles').bootstrap();\n },\n destroy({ strapi }) {\n getService(strapi, 'lifecycles').destroy();\n },\n controllers,\n services,\n routes,\n };\n }\n\n /**\n * Keep registering the model to avoid losing the data if the feature is disabled,\n * or if the license expires.\n */\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n },\n };\n};\n\nexport default getFeature();\n"],"names":["getFeature","strapi","ee","features","isEnabled","register","get","add","historyVersion","bootstrap","getService","destroy","controllers","services","routes"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../server/src/history/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { controllers } from './controllers';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { getService } from './utils';\nimport { historyVersion } from './models/history-version';\nimport { registerHistoryEntitlements } from './entitlements';\n\n/**\n * Check once if the feature is enabled before loading it,\n * so that we can assume it is enabled in the other files.\n */\nconst getFeature = (): Partial<Plugin.LoadedPlugin> => {\n if (strapi.ee.features.isEnabled('cms-content-history')) {\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n registerHistoryEntitlements(strapi);\n },\n bootstrap({ strapi }) {\n // Start recording history and saving history versions\n getService(strapi, 'lifecycles').bootstrap();\n },\n destroy({ strapi }) {\n getService(strapi, 'lifecycles').destroy();\n },\n controllers,\n services,\n routes,\n };\n }\n\n /**\n * Keep registering the model to avoid losing the data if the feature is disabled,\n * or if the license expires.\n */\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n registerHistoryEntitlements(strapi);\n },\n };\n};\n\nexport default getFeature();\n"],"names":["getFeature","strapi","ee","features","isEnabled","register","get","add","historyVersion","registerHistoryEntitlements","bootstrap","getService","destroy","controllers","services","routes"],"mappings":";;;;;;;;;AAQA;;;AAGC,IACD,MAAMA,UAAAA,GAAa,IAAA;AACjB,IAAA,IAAIC,OAAOC,EAAE,CAACC,QAAQ,CAACC,SAAS,CAAC,qBAAA,CAAA,EAAwB;QACvD,OAAO;YACLC,QAAAA,CAAAA,CAAS,EAAEJ,MAAAA,EAAAA,OAAM,EAAE,EAAA;AACjBA,gBAAAA,OAAAA,CAAOK,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,6BAAAA,CAAAA;gBACzBC,wCAAAA,CAA4BR,OAAAA,CAAAA;AAC9B,YAAA,CAAA;YACAS,SAAAA,CAAAA,CAAU,EAAET,MAAAA,EAAAA,OAAM,EAAE,EAAA;;gBAElBU,gBAAAA,CAAWV,OAAAA,EAAQ,cAAcS,SAAS,EAAA;AAC5C,YAAA,CAAA;YACAE,OAAAA,CAAAA,CAAQ,EAAEX,MAAAA,EAAAA,OAAM,EAAE,EAAA;gBAChBU,gBAAAA,CAAWV,OAAAA,EAAQ,cAAcW,OAAO,EAAA;AAC1C,YAAA,CAAA;AACAC,yBAAAA,mBAAAA;AACAC,sBAAAA,gBAAAA;AACAC,oBAAAA;AACF,SAAA;AACF,IAAA;AAEA;;;AAGC,MACD,OAAO;QACLV,QAAAA,CAAAA,CAAS,EAAEJ,MAAAA,EAAAA,OAAM,EAAE,EAAA;AACjBA,YAAAA,OAAAA,CAAOK,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,6BAAAA,CAAAA;YACzBC,wCAAAA,CAA4BR,OAAAA,CAAAA;AAC9B,QAAA;AACF,KAAA;AACF,CAAA;AAEA,cAAeD,UAAAA,EAAAA;;;;"}
|
|
@@ -3,6 +3,7 @@ import { services } from './services/index.mjs';
|
|
|
3
3
|
import { routes } from './routes/index.mjs';
|
|
4
4
|
import { getService } from './utils.mjs';
|
|
5
5
|
import { historyVersion } from './models/history-version.mjs';
|
|
6
|
+
import { registerHistoryEntitlements } from './entitlements.mjs';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Check once if the feature is enabled before loading it,
|
|
@@ -12,6 +13,7 @@ import { historyVersion } from './models/history-version.mjs';
|
|
|
12
13
|
return {
|
|
13
14
|
register ({ strapi: strapi1 }) {
|
|
14
15
|
strapi1.get('models').add(historyVersion);
|
|
16
|
+
registerHistoryEntitlements(strapi1);
|
|
15
17
|
},
|
|
16
18
|
bootstrap ({ strapi: strapi1 }) {
|
|
17
19
|
// Start recording history and saving history versions
|
|
@@ -31,6 +33,7 @@ import { historyVersion } from './models/history-version.mjs';
|
|
|
31
33
|
*/ return {
|
|
32
34
|
register ({ strapi: strapi1 }) {
|
|
33
35
|
strapi1.get('models').add(historyVersion);
|
|
36
|
+
registerHistoryEntitlements(strapi1);
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../server/src/history/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { controllers } from './controllers';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { getService } from './utils';\nimport { historyVersion } from './models/history-version';\n\n/**\n * Check once if the feature is enabled before loading it,\n * so that we can assume it is enabled in the other files.\n */\nconst getFeature = (): Partial<Plugin.LoadedPlugin> => {\n if (strapi.ee.features.isEnabled('cms-content-history')) {\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n },\n bootstrap({ strapi }) {\n // Start recording history and saving history versions\n getService(strapi, 'lifecycles').bootstrap();\n },\n destroy({ strapi }) {\n getService(strapi, 'lifecycles').destroy();\n },\n controllers,\n services,\n routes,\n };\n }\n\n /**\n * Keep registering the model to avoid losing the data if the feature is disabled,\n * or if the license expires.\n */\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n },\n };\n};\n\nexport default getFeature();\n"],"names":["getFeature","strapi","ee","features","isEnabled","register","get","add","historyVersion","bootstrap","getService","destroy","controllers","services","routes"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../server/src/history/index.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport { controllers } from './controllers';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { getService } from './utils';\nimport { historyVersion } from './models/history-version';\nimport { registerHistoryEntitlements } from './entitlements';\n\n/**\n * Check once if the feature is enabled before loading it,\n * so that we can assume it is enabled in the other files.\n */\nconst getFeature = (): Partial<Plugin.LoadedPlugin> => {\n if (strapi.ee.features.isEnabled('cms-content-history')) {\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n registerHistoryEntitlements(strapi);\n },\n bootstrap({ strapi }) {\n // Start recording history and saving history versions\n getService(strapi, 'lifecycles').bootstrap();\n },\n destroy({ strapi }) {\n getService(strapi, 'lifecycles').destroy();\n },\n controllers,\n services,\n routes,\n };\n }\n\n /**\n * Keep registering the model to avoid losing the data if the feature is disabled,\n * or if the license expires.\n */\n return {\n register({ strapi }) {\n strapi.get('models').add(historyVersion);\n registerHistoryEntitlements(strapi);\n },\n };\n};\n\nexport default getFeature();\n"],"names":["getFeature","strapi","ee","features","isEnabled","register","get","add","historyVersion","registerHistoryEntitlements","bootstrap","getService","destroy","controllers","services","routes"],"mappings":";;;;;;;AAQA;;;AAGC,IACD,MAAMA,UAAAA,GAAa,IAAA;AACjB,IAAA,IAAIC,OAAOC,EAAE,CAACC,QAAQ,CAACC,SAAS,CAAC,qBAAA,CAAA,EAAwB;QACvD,OAAO;YACLC,QAAAA,CAAAA,CAAS,EAAEJ,MAAAA,EAAAA,OAAM,EAAE,EAAA;AACjBA,gBAAAA,OAAAA,CAAOK,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,cAAAA,CAAAA;gBACzBC,2BAAAA,CAA4BR,OAAAA,CAAAA;AAC9B,YAAA,CAAA;YACAS,SAAAA,CAAAA,CAAU,EAAET,MAAAA,EAAAA,OAAM,EAAE,EAAA;;gBAElBU,UAAAA,CAAWV,OAAAA,EAAQ,cAAcS,SAAS,EAAA;AAC5C,YAAA,CAAA;YACAE,OAAAA,CAAAA,CAAQ,EAAEX,MAAAA,EAAAA,OAAM,EAAE,EAAA;gBAChBU,UAAAA,CAAWV,OAAAA,EAAQ,cAAcW,OAAO,EAAA;AAC1C,YAAA,CAAA;AACAC,YAAAA,WAAAA;AACAC,YAAAA,QAAAA;AACAC,YAAAA;AACF,SAAA;AACF,IAAA;AAEA;;;AAGC,MACD,OAAO;QACLV,QAAAA,CAAAA,CAAS,EAAEJ,MAAAA,EAAAA,OAAM,EAAE,EAAA;AACjBA,YAAAA,OAAAA,CAAOK,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,cAAAA,CAAAA;YACzBC,2BAAAA,CAA4BR,OAAAA,CAAAA;AAC9B,QAAA;AACF,KAAA;AACF,CAAA;AAEA,cAAeD,UAAAA,EAAAA;;;;"}
|
|
@@ -5,6 +5,22 @@ var strapiUtils = require('@strapi/utils');
|
|
|
5
5
|
var constants = require('../constants.js');
|
|
6
6
|
|
|
7
7
|
const DEFAULT_RETENTION_DAYS = 90;
|
|
8
|
+
/**
|
|
9
|
+
* The retention the history delete job applies, from the license's value and the admin setting.
|
|
10
|
+
* Shared with the Plan card's resolver (../entitlements.ts) so the card shows this same figure.
|
|
11
|
+
*/ const computeRetentionDays = (licenseRetentionDays, userRetentionDays)=>{
|
|
12
|
+
if (licenseRetentionDays == null) {
|
|
13
|
+
return userRetentionDays ?? DEFAULT_RETENTION_DAYS;
|
|
14
|
+
}
|
|
15
|
+
// The registry can ship the value as a numeric string
|
|
16
|
+
const licenseDays = Number(licenseRetentionDays);
|
|
17
|
+
// Allow users to override the license retention days, but not to increase it
|
|
18
|
+
if (userRetentionDays && userRetentionDays < licenseDays) {
|
|
19
|
+
return userRetentionDays;
|
|
20
|
+
}
|
|
21
|
+
// User didn't provide retention days value, use the license or fallback to default
|
|
22
|
+
return Math.min(licenseDays, DEFAULT_RETENTION_DAYS);
|
|
23
|
+
};
|
|
8
24
|
const createServiceUtils = ({ strapi })=>{
|
|
9
25
|
/**
|
|
10
26
|
* @description
|
|
@@ -96,14 +112,7 @@ const createServiceUtils = ({ strapi })=>{
|
|
|
96
112
|
* Gets the number of retention days defined on the license or configured by the user
|
|
97
113
|
*/ const getRetentionDays = ()=>{
|
|
98
114
|
const featureConfig = strapi.ee.features.get('cms-content-history');
|
|
99
|
-
|
|
100
|
-
const userRetentionDays = strapi.config.get('admin.history.retentionDays');
|
|
101
|
-
// Allow users to override the license retention days, but not to increase it
|
|
102
|
-
if (userRetentionDays && userRetentionDays < licenseRetentionDays) {
|
|
103
|
-
return userRetentionDays;
|
|
104
|
-
}
|
|
105
|
-
// User didn't provide retention days value, use the license or fallback to default
|
|
106
|
-
return Math.min(licenseRetentionDays, DEFAULT_RETENTION_DAYS);
|
|
115
|
+
return computeRetentionDays(typeof featureConfig === 'object' ? featureConfig?.options?.retentionDays : undefined, strapi.config.get('admin.history.retentionDays'));
|
|
107
116
|
};
|
|
108
117
|
const getVersionStatus = async (contentTypeUid, document)=>{
|
|
109
118
|
const documentMetadataService = strapi.plugin('content-manager').service('document-metadata');
|
|
@@ -274,5 +283,7 @@ const createServiceUtils = ({ strapi })=>{
|
|
|
274
283
|
};
|
|
275
284
|
};
|
|
276
285
|
|
|
286
|
+
exports.DEFAULT_RETENTION_DAYS = DEFAULT_RETENTION_DAYS;
|
|
287
|
+
exports.computeRetentionDays = computeRetentionDays;
|
|
277
288
|
exports.createServiceUtils = createServiceUtils;
|
|
278
289
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../server/src/history/services/utils.ts"],"sourcesContent":["import { difference, omit } from 'lodash';\n\nimport { contentTypes } from '@strapi/utils';\nimport type { Core, Modules, Schema, Data, Struct, UID } from '@strapi/types';\n\nimport { FIELDS_TO_IGNORE } from '../constants';\nimport type { CreateHistoryVersion } from '../../../../shared/contracts/history-versions';\nimport type { HistoryVersions } from '../../../../shared/contracts';\nimport type { RelationResult } from '../../../../shared/contracts/relations';\n\nconst DEFAULT_RETENTION_DAYS = 90;\n\ntype RelationResponse = {\n results: RelationResult[];\n meta: { missingCount: number };\n};\n\nexport const createServiceUtils = ({ strapi }: { strapi: Core.Strapi }) => {\n /**\n * @description\n * Get the difference between the version schema and the content type schema\n */\n const getSchemaAttributesDiff = (\n versionSchemaAttributes: CreateHistoryVersion['schema'],\n contentTypeSchemaAttributes: Struct.SchemaAttributes\n ) => {\n // Omit the same fields that were omitted when creating a history version\n const sanitizedContentTypeSchemaAttributes = omit(\n contentTypeSchemaAttributes,\n FIELDS_TO_IGNORE\n );\n\n const reduceDifferenceToAttributesObject = (\n diffKeys: string[],\n source: CreateHistoryVersion['schema']\n ) => {\n return diffKeys.reduce<CreateHistoryVersion['schema']>(\n (previousAttributesObject, diffKey) => {\n previousAttributesObject[diffKey] = source[diffKey];\n\n return previousAttributesObject;\n },\n {}\n );\n };\n\n const versionSchemaKeys = Object.keys(versionSchemaAttributes);\n const contentTypeSchemaAttributesKeys = Object.keys(sanitizedContentTypeSchemaAttributes);\n // The attribute is new if it's on the content type schema but not on the version schema\n const uniqueToContentType = difference(contentTypeSchemaAttributesKeys, versionSchemaKeys);\n const added = reduceDifferenceToAttributesObject(\n uniqueToContentType,\n sanitizedContentTypeSchemaAttributes\n );\n // The attribute was removed or renamed if it's on the version schema but not on the content type schema\n const uniqueToVersion = difference(versionSchemaKeys, contentTypeSchemaAttributesKeys);\n const removed = reduceDifferenceToAttributesObject(uniqueToVersion, versionSchemaAttributes);\n\n return { added, removed };\n };\n\n /**\n * @description\n * Gets the value to set for a relation when restoring a document\n * @returns\n * The relation if it exists or null\n */\n const getRelationRestoreValue = async (\n versionRelationData: Modules.Documents.AnyDocument | Modules.Documents.AnyDocument[],\n attribute: Schema.Attribute.RelationWithTarget\n ) => {\n if (Array.isArray(versionRelationData)) {\n if (versionRelationData.length === 0) return versionRelationData;\n\n const existingAndMissingRelations = await Promise.all(\n versionRelationData.map((relation) => {\n return strapi.documents(attribute.target).findOne({\n documentId: relation.documentId,\n locale: relation.locale || undefined,\n });\n })\n );\n\n return existingAndMissingRelations.filter((relation) => relation !== null);\n }\n\n return strapi.documents(attribute.target).findOne({\n documentId: versionRelationData.documentId,\n locale: versionRelationData.locale || undefined,\n });\n };\n\n /**\n * @description\n * Gets the value to set for a media asset when restoring a document\n * @returns\n * The media asset if it exists or null\n */\n const getMediaRestoreValue = async (\n versionRelationData: Modules.Documents.AnyDocument | Modules.Documents.AnyDocument[]\n ) => {\n if (Array.isArray(versionRelationData)) {\n const existingAndMissingMedias = await Promise.all(\n versionRelationData.map((media) => {\n return strapi.db.query('plugin::upload.file').findOne({ where: { id: media.id } });\n })\n );\n\n return existingAndMissingMedias.filter((media) => media != null);\n }\n\n return strapi.db\n .query('plugin::upload.file')\n .findOne({ where: { id: versionRelationData.id } });\n };\n\n const getDefaultLocale = async () => strapi.localization.getDefaultLocale();\n\n const isLocalizedContentType = (model: Schema.ContentType) =>\n strapi.localization.isLocalizedContentType(model);\n\n /**\n *\n * @description\n * Creates a dictionary of all locales available\n */\n const getLocaleDictionary = async (): Promise<{\n [key: string]: { name: string; code: string };\n }> => {\n const locales = await strapi.localization.getLocales();\n\n return locales.reduce<\n Record<string, NonNullable<HistoryVersions.HistoryVersionDataResponse['locale']>>\n >((acc, locale) => {\n acc[locale.code] = { name: locale.name, code: locale.code };\n\n return acc;\n }, {});\n };\n\n /**\n *\n * @description\n * Gets the number of retention days defined on the license or configured by the user\n */\n const getRetentionDays = () => {\n const featureConfig = strapi.ee.features.get('cms-content-history');\n const licenseRetentionDays =\n typeof featureConfig === 'object' && featureConfig?.options.retentionDays;\n const userRetentionDays: number = strapi.config.get('admin.history.retentionDays');\n\n // Allow users to override the license retention days, but not to increase it\n if (userRetentionDays && userRetentionDays < licenseRetentionDays) {\n return userRetentionDays;\n }\n\n // User didn't provide retention days value, use the license or fallback to default\n return Math.min(licenseRetentionDays, DEFAULT_RETENTION_DAYS);\n };\n\n const getVersionStatus = async (\n contentTypeUid: HistoryVersions.CreateHistoryVersion['contentType'],\n document: Modules.Documents.AnyDocument | null\n ) => {\n const documentMetadataService = strapi.plugin('content-manager').service('document-metadata');\n const meta = await documentMetadataService.getMetadata(contentTypeUid, document);\n\n return documentMetadataService.getStatus(document, meta.availableStatus);\n };\n\n /**\n * Lists all the fields of a component, excepts those that will be populated.\n * The goal is to exclude the ID, because when restoring a component,\n * referencing an ID for a component db row that was deleted creates an error.\n * So we never store component IDs to ensure they're re-created while restoring a version.\n */\n const getComponentFields = (componentUID: UID.Component): string[] => {\n return Object.entries(strapi.getModel(componentUID).attributes).reduce<string[]>(\n (fieldsAcc, [key, attribute]) => {\n if (!['relation', 'media', 'component', 'dynamiczone'].includes(attribute.type)) {\n fieldsAcc.push(key);\n }\n\n return fieldsAcc;\n },\n []\n );\n };\n\n /**\n * @description\n * Creates a populate object that looks for all the relations that need\n * to be saved in history, and populates only the fields needed to later retrieve the content.\n *\n * @param uid - The content type UID\n * @param useDatabaseSyntax - Whether to use the database syntax for populate, defaults to false\n */\n const getDeepPopulate = (uid: UID.Schema, useDatabaseSyntax = false) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n const fieldSelector = useDatabaseSyntax ? 'select' : 'fields';\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = { [fieldSelector]: ['documentId', 'locale', 'publishedAt'] };\n }\n break;\n }\n\n case 'media': {\n acc[attributeName] = { [fieldSelector]: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component);\n acc[attributeName] = {\n populate,\n [fieldSelector]: getComponentFields(attribute.component),\n };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = {\n populate: getDeepPopulate(componentUID),\n [fieldSelector]: getComponentFields(componentUID),\n };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n };\n\n /**\n * @description\n * Builds a response object for relations containing the related data and a count of missing relations\n */\n const buildMediaResponse = async (values: { id: Data.ID }[]): Promise<RelationResponse> => {\n return (\n values\n // Until we implement proper pagination, limit relations to an arbitrary amount\n .slice(0, 25)\n .reduce(\n async (currentRelationDataPromise, entry) => {\n const currentRelationData = await currentRelationDataPromise;\n\n // Entry can be null if it's a toOne relation\n if (!entry) {\n return currentRelationData;\n }\n\n const relatedEntry = await strapi.db\n .query('plugin::upload.file')\n .findOne({ where: { id: entry.id } });\n\n if (relatedEntry) {\n currentRelationData.results.push(relatedEntry);\n } else {\n // The related content has been deleted\n currentRelationData.meta.missingCount += 1;\n }\n\n return currentRelationData;\n },\n Promise.resolve<RelationResponse>({\n results: [],\n meta: { missingCount: 0 },\n })\n )\n );\n };\n\n /**\n * @description\n * Builds a response object for media containing the media assets data and a count of missing media assets\n */\n const buildRelationReponse = async (\n values: {\n documentId: string;\n locale: string | null;\n }[],\n attributeSchema: Schema.Attribute.RelationWithTarget\n ): Promise<RelationResponse> => {\n return (\n values\n // Until we implement proper pagination, limit relations to an arbitrary amount\n .slice(0, 25)\n .reduce(\n async (currentRelationDataPromise, entry) => {\n const currentRelationData = await currentRelationDataPromise;\n\n // Entry can be null if it's a toOne relation\n if (!entry) {\n return currentRelationData;\n }\n const relatedEntry = await strapi\n .documents(attributeSchema.target)\n .findOne({ documentId: entry.documentId, locale: entry.locale || undefined });\n\n if (relatedEntry) {\n currentRelationData.results.push({\n ...relatedEntry,\n status: await getVersionStatus(attributeSchema.target, relatedEntry),\n });\n } else {\n // The related content has been deleted\n currentRelationData.meta.missingCount += 1;\n }\n\n return currentRelationData;\n },\n Promise.resolve<RelationResponse>({\n results: [],\n meta: { missingCount: 0 },\n })\n )\n );\n };\n\n return {\n getSchemaAttributesDiff,\n getRelationRestoreValue,\n getMediaRestoreValue,\n getDefaultLocale,\n isLocalizedContentType,\n getLocaleDictionary,\n getRetentionDays,\n getVersionStatus,\n getDeepPopulate,\n buildMediaResponse,\n buildRelationReponse,\n };\n};\n"],"names":["DEFAULT_RETENTION_DAYS","createServiceUtils","strapi","getSchemaAttributesDiff","versionSchemaAttributes","contentTypeSchemaAttributes","sanitizedContentTypeSchemaAttributes","omit","FIELDS_TO_IGNORE","reduceDifferenceToAttributesObject","diffKeys","source","reduce","previousAttributesObject","diffKey","versionSchemaKeys","Object","keys","contentTypeSchemaAttributesKeys","uniqueToContentType","difference","added","uniqueToVersion","removed","getRelationRestoreValue","versionRelationData","attribute","Array","isArray","length","existingAndMissingRelations","Promise","all","map","relation","documents","target","findOne","documentId","locale","undefined","filter","getMediaRestoreValue","existingAndMissingMedias","media","db","query","where","id","getDefaultLocale","localization","isLocalizedContentType","model","getLocaleDictionary","locales","getLocales","acc","code","name","getRetentionDays","featureConfig","ee","features","get","licenseRetentionDays","options","retentionDays","userRetentionDays","config","Math","min","getVersionStatus","contentTypeUid","document","documentMetadataService","plugin","service","meta","getMetadata","getStatus","availableStatus","getComponentFields","componentUID","entries","getModel","attributes","fieldsAcc","key","includes","type","push","getDeepPopulate","uid","useDatabaseSyntax","fieldSelector","attributeName","isMorphRelation","toLowerCase","startsWith","isVisible","contentTypes","isVisibleAttribute","populate","component","populatedComponents","components","on","buildMediaResponse","values","slice","currentRelationDataPromise","entry","currentRelationData","relatedEntry","results","missingCount","resolve","buildRelationReponse","attributeSchema","status"],"mappings":";;;;;;AAUA,MAAMA,sBAAAA,GAAyB,EAAA;AAOxB,MAAMC,kBAAAA,GAAqB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACpE;;;MAIA,MAAMC,uBAAAA,GAA0B,CAC9BC,uBAAAA,EACAC,2BAAAA,GAAAA;;QAGA,MAAMC,oCAAAA,GAAuCC,OAC3CF,2BAAAA,EACAG,0BAAAA,CAAAA;QAGF,MAAMC,kCAAAA,GAAqC,CACzCC,QAAAA,EACAC,MAAAA,GAAAA;AAEA,YAAA,OAAOD,QAAAA,CAASE,MAAM,CACpB,CAACC,wBAAAA,EAA0BC,OAAAA,GAAAA;AACzBD,gBAAAA,wBAAwB,CAACC,OAAAA,CAAQ,GAAGH,MAAM,CAACG,OAAAA,CAAQ;gBAEnD,OAAOD,wBAAAA;AACT,YAAA,CAAA,EACA,EAAC,CAAA;AAEL,QAAA,CAAA;QAEA,MAAME,iBAAAA,GAAoBC,MAAAA,CAAOC,IAAI,CAACb,uBAAAA,CAAAA;QACtC,MAAMc,+BAAAA,GAAkCF,MAAAA,CAAOC,IAAI,CAACX,oCAAAA,CAAAA;;QAEpD,MAAMa,mBAAAA,GAAsBC,aAAWF,+BAAA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oBE,OAAO,CAACxB,IAAI,CAAC;AAC/B,oBAAA,GAAGuB,YAAY;AACfM,oBAAAA,MAAAA,EAAQ,MAAMhD,gBAAAA,CAAiB+C,eAAAA,CAAgBlF,MAAM,EAAE6E,YAAAA;AACzD,iBAAA,CAAA;YACF,CAAA,MAAO;;gBAELD,mBAAAA,CAAoBnC,IAAI,CAACsC,YAAY,IAAI,CAAA;AAC3C,YAAA;YAEA,OAAOH,mBAAAA;QACT,CAAA,EACAjF,OAAAA,CAAQqF,OAAO,CAAmB;AAChCF,YAAAA,OAAAA,EAAS,EAAE;YACXrC,IAAAA,EAAM;gBAAEsC,YAAAA,EAAc;AAAE;AAC1B,SAAA,CAAA,CAAA;AAGR,IAAA,CAAA;IAEA,OAAO;AACLhH,QAAAA,uBAAAA;AACAqB,QAAAA,uBAAAA;AACAkB,QAAAA,oBAAAA;AACAO,QAAAA,gBAAAA;AACAE,QAAAA,sBAAAA;AACAE,QAAAA,mBAAAA;AACAM,QAAAA,gBAAAA;AACAY,QAAAA,gBAAAA;AACAoB,QAAAA,eAAAA;AACAgB,QAAAA,kBAAAA;AACAU,QAAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../server/src/history/services/utils.ts"],"sourcesContent":["import { difference, omit } from 'lodash';\n\nimport { contentTypes } from '@strapi/utils';\nimport type { Core, Modules, Schema, Data, Struct, UID } from '@strapi/types';\n\nimport { FIELDS_TO_IGNORE } from '../constants';\nimport type { CreateHistoryVersion } from '../../../../shared/contracts/history-versions';\nimport type { HistoryVersions } from '../../../../shared/contracts';\nimport type { RelationResult } from '../../../../shared/contracts/relations';\n\nexport const DEFAULT_RETENTION_DAYS = 90;\n\n/**\n * The retention the history delete job applies, from the license's value and the admin setting.\n * Shared with the Plan card's resolver (../entitlements.ts) so the card shows this same figure.\n */\nexport const computeRetentionDays = (\n licenseRetentionDays: unknown,\n userRetentionDays: number | null | undefined\n): number => {\n if (licenseRetentionDays == null) {\n return userRetentionDays ?? DEFAULT_RETENTION_DAYS;\n }\n\n // The registry can ship the value as a numeric string\n const licenseDays = Number(licenseRetentionDays);\n\n // Allow users to override the license retention days, but not to increase it\n if (userRetentionDays && userRetentionDays < licenseDays) {\n return userRetentionDays;\n }\n\n // User didn't provide retention days value, use the license or fallback to default\n return Math.min(licenseDays, DEFAULT_RETENTION_DAYS);\n};\n\ntype RelationResponse = {\n results: RelationResult[];\n meta: { missingCount: number };\n};\n\nexport const createServiceUtils = ({ strapi }: { strapi: Core.Strapi }) => {\n /**\n * @description\n * Get the difference between the version schema and the content type schema\n */\n const getSchemaAttributesDiff = (\n versionSchemaAttributes: CreateHistoryVersion['schema'],\n contentTypeSchemaAttributes: Struct.SchemaAttributes\n ) => {\n // Omit the same fields that were omitted when creating a history version\n const sanitizedContentTypeSchemaAttributes = omit(\n contentTypeSchemaAttributes,\n FIELDS_TO_IGNORE\n );\n\n const reduceDifferenceToAttributesObject = (\n diffKeys: string[],\n source: CreateHistoryVersion['schema']\n ) => {\n return diffKeys.reduce<CreateHistoryVersion['schema']>(\n (previousAttributesObject, diffKey) => {\n previousAttributesObject[diffKey] = source[diffKey];\n\n return previousAttributesObject;\n },\n {}\n );\n };\n\n const versionSchemaKeys = Object.keys(versionSchemaAttributes);\n const contentTypeSchemaAttributesKeys = Object.keys(sanitizedContentTypeSchemaAttributes);\n // The attribute is new if it's on the content type schema but not on the version schema\n const uniqueToContentType = difference(contentTypeSchemaAttributesKeys, versionSchemaKeys);\n const added = reduceDifferenceToAttributesObject(\n uniqueToContentType,\n sanitizedContentTypeSchemaAttributes\n );\n // The attribute was removed or renamed if it's on the version schema but not on the content type schema\n const uniqueToVersion = difference(versionSchemaKeys, contentTypeSchemaAttributesKeys);\n const removed = reduceDifferenceToAttributesObject(uniqueToVersion, versionSchemaAttributes);\n\n return { added, removed };\n };\n\n /**\n * @description\n * Gets the value to set for a relation when restoring a document\n * @returns\n * The relation if it exists or null\n */\n const getRelationRestoreValue = async (\n versionRelationData: Modules.Documents.AnyDocument | Modules.Documents.AnyDocument[],\n attribute: Schema.Attribute.RelationWithTarget\n ) => {\n if (Array.isArray(versionRelationData)) {\n if (versionRelationData.length === 0) return versionRelationData;\n\n const existingAndMissingRelations = await Promise.all(\n versionRelationData.map((relation) => {\n return strapi.documents(attribute.target).findOne({\n documentId: relation.documentId,\n locale: relation.locale || undefined,\n });\n })\n );\n\n return existingAndMissingRelations.filter((relation) => relation !== null);\n }\n\n return strapi.documents(attribute.target).findOne({\n documentId: versionRelationData.documentId,\n locale: versionRelationData.locale || undefined,\n });\n };\n\n /**\n * @description\n * Gets the value to set for a media asset when restoring a document\n * @returns\n * The media asset if it exists or null\n */\n const getMediaRestoreValue = async (\n versionRelationData: Modules.Documents.AnyDocument | Modules.Documents.AnyDocument[]\n ) => {\n if (Array.isArray(versionRelationData)) {\n const existingAndMissingMedias = await Promise.all(\n versionRelationData.map((media) => {\n return strapi.db.query('plugin::upload.file').findOne({ where: { id: media.id } });\n })\n );\n\n return existingAndMissingMedias.filter((media) => media != null);\n }\n\n return strapi.db\n .query('plugin::upload.file')\n .findOne({ where: { id: versionRelationData.id } });\n };\n\n const getDefaultLocale = async () => strapi.localization.getDefaultLocale();\n\n const isLocalizedContentType = (model: Schema.ContentType) =>\n strapi.localization.isLocalizedContentType(model);\n\n /**\n *\n * @description\n * Creates a dictionary of all locales available\n */\n const getLocaleDictionary = async (): Promise<{\n [key: string]: { name: string; code: string };\n }> => {\n const locales = await strapi.localization.getLocales();\n\n return locales.reduce<\n Record<string, NonNullable<HistoryVersions.HistoryVersionDataResponse['locale']>>\n >((acc, locale) => {\n acc[locale.code] = { name: locale.name, code: locale.code };\n\n return acc;\n }, {});\n };\n\n /**\n *\n * @description\n * Gets the number of retention days defined on the license or configured by the user\n */\n const getRetentionDays = () => {\n const featureConfig = strapi.ee.features.get('cms-content-history');\n\n return computeRetentionDays(\n typeof featureConfig === 'object' ? featureConfig?.options?.retentionDays : undefined,\n strapi.config.get('admin.history.retentionDays')\n );\n };\n\n const getVersionStatus = async (\n contentTypeUid: HistoryVersions.CreateHistoryVersion['contentType'],\n document: Modules.Documents.AnyDocument | null\n ) => {\n const documentMetadataService = strapi.plugin('content-manager').service('document-metadata');\n const meta = await documentMetadataService.getMetadata(contentTypeUid, document);\n\n return documentMetadataService.getStatus(document, meta.availableStatus);\n };\n\n /**\n * Lists all the fields of a component, excepts those that will be populated.\n * The goal is to exclude the ID, because when restoring a component,\n * referencing an ID for a component db row that was deleted creates an error.\n * So we never store component IDs to ensure they're re-created while restoring a version.\n */\n const getComponentFields = (componentUID: UID.Component): string[] => {\n return Object.entries(strapi.getModel(componentUID).attributes).reduce<string[]>(\n (fieldsAcc, [key, attribute]) => {\n if (!['relation', 'media', 'component', 'dynamiczone'].includes(attribute.type)) {\n fieldsAcc.push(key);\n }\n\n return fieldsAcc;\n },\n []\n );\n };\n\n /**\n * @description\n * Creates a populate object that looks for all the relations that need\n * to be saved in history, and populates only the fields needed to later retrieve the content.\n *\n * @param uid - The content type UID\n * @param useDatabaseSyntax - Whether to use the database syntax for populate, defaults to false\n */\n const getDeepPopulate = (uid: UID.Schema, useDatabaseSyntax = false) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n const fieldSelector = useDatabaseSyntax ? 'select' : 'fields';\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = { [fieldSelector]: ['documentId', 'locale', 'publishedAt'] };\n }\n break;\n }\n\n case 'media': {\n acc[attributeName] = { [fieldSelector]: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component);\n acc[attributeName] = {\n populate,\n [fieldSelector]: getComponentFields(attribute.component),\n };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = {\n populate: getDeepPopulate(componentUID),\n [fieldSelector]: getComponentFields(componentUID),\n };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n };\n\n /**\n * @description\n * Builds a response object for relations containing the related data and a count of missing relations\n */\n const buildMediaResponse = async (values: { id: Data.ID }[]): Promise<RelationResponse> => {\n return (\n values\n // Until we implement proper pagination, limit relations to an arbitrary amount\n .slice(0, 25)\n .reduce(\n async (currentRelationDataPromise, entry) => {\n const currentRelationData = await currentRelationDataPromise;\n\n // Entry can be null if it's a toOne relation\n if (!entry) {\n return currentRelationData;\n }\n\n const relatedEntry = await strapi.db\n .query('plugin::upload.file')\n .findOne({ where: { id: entry.id } });\n\n if (relatedEntry) {\n currentRelationData.results.push(relatedEntry);\n } else {\n // The related content has been deleted\n currentRelationData.meta.missingCount += 1;\n }\n\n return currentRelationData;\n },\n Promise.resolve<RelationResponse>({\n results: [],\n meta: { missingCount: 0 },\n })\n )\n );\n };\n\n /**\n * @description\n * Builds a response object for media containing the media assets data and a count of missing media assets\n */\n const buildRelationReponse = async (\n values: {\n documentId: string;\n locale: string | null;\n }[],\n attributeSchema: Schema.Attribute.RelationWithTarget\n ): Promise<RelationResponse> => {\n return (\n values\n // Until we implement proper pagination, limit relations to an arbitrary amount\n .slice(0, 25)\n .reduce(\n async (currentRelationDataPromise, entry) => {\n const currentRelationData = await currentRelationDataPromise;\n\n // Entry can be null if it's a toOne relation\n if (!entry) {\n return currentRelationData;\n }\n const relatedEntry = await strapi\n .documents(attributeSchema.target)\n .findOne({ documentId: entry.documentId, locale: entry.locale || undefined });\n\n if (relatedEntry) {\n currentRelationData.results.push({\n ...relatedEntry,\n status: await getVersionStatus(attributeSchema.target, relatedEntry),\n });\n } else {\n // The related content has been deleted\n currentRelationData.meta.missingCount += 1;\n }\n\n return currentRelationData;\n },\n Promise.resolve<RelationResponse>({\n results: [],\n meta: { missingCount: 0 },\n })\n )\n );\n };\n\n return {\n getSchemaAttributesDiff,\n getRelationRestoreValue,\n getMediaRestoreValue,\n getDefaultLocale,\n isLocalizedContentType,\n getLocaleDictionary,\n getRetentionDays,\n getVersionStatus,\n getDeepPopulate,\n buildMediaResponse,\n buildRelationReponse,\n };\n};\n"],"names":["DEFAULT_RETENTION_DAYS","computeRetentionDays","licenseRetentionDays","userRetentionDays","licenseDays","Number","Math","min","createServiceUtils","strapi","getSchemaAttributesDiff","versionSchemaAttributes","contentTypeSchemaAttributes","sanitizedContentTypeSchemaAttributes","omit","FIELDS_TO_IGNORE","reduceDifferenceToAttributesObject","diffKeys","source","reduce","previousAttributesObject","diffKey","versionSchemaKeys","Object","keys","contentTypeSchemaAttributesKeys","uniqueToContentType","difference","added","uniqueToVersion","removed","getRelationRestoreValue","versionRelationData","attribute","Array","isArray","length","existingAndMissingRelations","Promise","all","map","relation","documents","target","findOne","documentId","locale","undefined","filter","getMediaRestoreValue","existingAndMissingMedias","media","db","query","where","id","getDefaultLocale","localization","isLocalizedContentType","model","getLocaleDictionary","locales","getLocales","acc","code","name","getRetentionDays","featureConfig","ee","features","get","options","retentionDays","config","getVersionStatus","contentTypeUid","document","documentMetadataService","plugin","service","meta","getMetadata","getStatus","availableStatus","getComponentFields","componentUID","entries","getModel","attributes","fieldsAcc","key","includes","type","push","getDeepPopulate","uid","useDatabaseSyntax","fieldSelector","attributeName","isMorphRelation","toLowerCase","startsWith","isVisible","contentTypes","isVisibleAttribute","populate","component","populatedComponents","components","on","buildMediaResponse","values","slice","currentRelationDataPromise","entry","currentRelationData","relatedEntry","results","missingCount","resolve","buildRelationReponse","attributeSchema","status"],"mappings":";;;;;;AAUO,MAAMA,yBAAyB;AAEtC;;;AAGC,IACM,MAAMC,oBAAAA,GAAuB,CAClCC,oBAAAA,EACAC,iBAAAA,GAAAA;AAEA,IAAA,IAA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AAAA,EAAc;AAAE;AAC1B,SAAA,CAAA,CAAA;AAGR,IAAA,CAAA;IAEA,OAAO;AACL5G,QAAAA,uBAAAA;AACAqB,QAAAA,uBAAAA;AACAkB,QAAAA,oBAAAA;AACAO,QAAAA,gBAAAA;AACAE,QAAAA,sBAAAA;AACAE,QAAAA,mBAAAA;AACAM,QAAAA,gBAAAA;AACAQ,QAAAA,gBAAAA;AACAoB,QAAAA,eAAAA;AACAgB,QAAAA,kBAAAA;AACAU,QAAAA;AACF,KAAA;AACF;;;;;;"}
|
|
@@ -3,6 +3,22 @@ import { contentTypes } from '@strapi/utils';
|
|
|
3
3
|
import { FIELDS_TO_IGNORE } from '../constants.mjs';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_RETENTION_DAYS = 90;
|
|
6
|
+
/**
|
|
7
|
+
* The retention the history delete job applies, from the license's value and the admin setting.
|
|
8
|
+
* Shared with the Plan card's resolver (../entitlements.ts) so the card shows this same figure.
|
|
9
|
+
*/ const computeRetentionDays = (licenseRetentionDays, userRetentionDays)=>{
|
|
10
|
+
if (licenseRetentionDays == null) {
|
|
11
|
+
return userRetentionDays ?? DEFAULT_RETENTION_DAYS;
|
|
12
|
+
}
|
|
13
|
+
// The registry can ship the value as a numeric string
|
|
14
|
+
const licenseDays = Number(licenseRetentionDays);
|
|
15
|
+
// Allow users to override the license retention days, but not to increase it
|
|
16
|
+
if (userRetentionDays && userRetentionDays < licenseDays) {
|
|
17
|
+
return userRetentionDays;
|
|
18
|
+
}
|
|
19
|
+
// User didn't provide retention days value, use the license or fallback to default
|
|
20
|
+
return Math.min(licenseDays, DEFAULT_RETENTION_DAYS);
|
|
21
|
+
};
|
|
6
22
|
const createServiceUtils = ({ strapi })=>{
|
|
7
23
|
/**
|
|
8
24
|
* @description
|
|
@@ -94,14 +110,7 @@ const createServiceUtils = ({ strapi })=>{
|
|
|
94
110
|
* Gets the number of retention days defined on the license or configured by the user
|
|
95
111
|
*/ const getRetentionDays = ()=>{
|
|
96
112
|
const featureConfig = strapi.ee.features.get('cms-content-history');
|
|
97
|
-
|
|
98
|
-
const userRetentionDays = strapi.config.get('admin.history.retentionDays');
|
|
99
|
-
// Allow users to override the license retention days, but not to increase it
|
|
100
|
-
if (userRetentionDays && userRetentionDays < licenseRetentionDays) {
|
|
101
|
-
return userRetentionDays;
|
|
102
|
-
}
|
|
103
|
-
// User didn't provide retention days value, use the license or fallback to default
|
|
104
|
-
return Math.min(licenseRetentionDays, DEFAULT_RETENTION_DAYS);
|
|
113
|
+
return computeRetentionDays(typeof featureConfig === 'object' ? featureConfig?.options?.retentionDays : undefined, strapi.config.get('admin.history.retentionDays'));
|
|
105
114
|
};
|
|
106
115
|
const getVersionStatus = async (contentTypeUid, document)=>{
|
|
107
116
|
const documentMetadataService = strapi.plugin('content-manager').service('document-metadata');
|
|
@@ -272,5 +281,5 @@ const createServiceUtils = ({ strapi })=>{
|
|
|
272
281
|
};
|
|
273
282
|
};
|
|
274
283
|
|
|
275
|
-
export { createServiceUtils };
|
|
284
|
+
export { DEFAULT_RETENTION_DAYS, computeRetentionDays, createServiceUtils };
|
|
276
285
|
//# sourceMappingURL=utils.mjs.map
|