@strapi/content-releases 5.63.0 → 5.64.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.
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { ALLOWED_WEBHOOK_EVENTS, OVERDUE_SWEEP_CRON_RULE } from './constants';\nimport { registerAuditEvents } from './audit-logs';\nimport { getService, runAfterCommit } from './utils';\nimport {\n createDeleteActionsOnDelete,\n createRevalidateActionsOnDraftChange,\n} from './middlewares/documents';\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n if (strapi.ee.features.isEnabled('cms-content-releases')) {\n const contentTypesWithDraftAndPublish = Object.keys(strapi.contentTypes).filter(\n (uid: any) => strapi.contentTypes[uid]?.options?.draftAndPublish\n );\n\n strapi.db.lifecycles.subscribe({\n models: contentTypesWithDraftAndPublish,\n\n /**\n * deleteMany is still used outside documents service, for example when deleting a locale\n */\n afterDeleteMany(event) {\n const model = strapi.getModel(event.model.uid as UID.Schema);\n // @ts-expect-error TODO: lifecycles types looks like are not 100% finished\n if (model.kind !== 'collectionType' || !model.options?.draftAndPublish) {\n return;\n }\n\n const { where } = event.params;\n\n // Not awaited: the delete entry flow doesn't wait for its releases, and isn't blocked by\n // their failure, which is logged\n runAfterCommit(\n () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType: model.uid,\n locale: where?.locale ?? null,\n ...(where?.documentId && { entryDocumentId: where.documentId }),\n }),\n 'Error while deleting release actions after entry deleteMany',\n { strapi }\n );\n },\n });\n\n // We register middleware to handle ReleaseActions when changes on documents are made\n strapi.documents.use(createDeleteActionsOnDelete({ strapi }));\n strapi.documents.use(createRevalidateActionsOnDraftChange({ strapi }));\n\n const schedulingService = getService('scheduling', { strapi });\n const freezeOverdueReleases = (now = new Date()) =>\n schedulingService.freezeOverdueReleases({ now }).catch((error: unknown) => {\n strapi.log.error('Error while freezing overdue releases in the content-releases plugin', {\n error,\n });\n });\n\n // Overdue releases are frozen before the jobs are armed: a release that failed before the\n // upgrade must not be armed for a date it won't run on. Both use the same instant, so a release\n // still within the grace period for the sweep is run right away by the sync, not left to the\n // next sweep to freeze.\n const startedAt = new Date();\n freezeOverdueReleases(startedAt)\n .then(() => schedulingService.syncFromDatabase({ now: startedAt }))\n .catch((error: unknown) => {\n strapi.log.error(\n 'Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling.',\n { error }\n );\n });\n\n // Then every minute: a release whose scheduled run didn't happen leaves Pending\n strapi.cron.add({\n 'content-releases::freezeOverdueReleases': {\n task: () => freezeOverdueReleases(),\n options: OVERDUE_SWEEP_CRON_RULE,\n },\n });\n\n Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {\n strapi.get('webhookStore').addAllowedEvent(key, value);\n });\n\n // Absent in CE, without the audit-logs license, or when disabled by config;\n // get() throws for services that were never added, so probe first.\n if (strapi.has('audit-logs-lifecycle')) {\n registerAuditEvents(strapi.get('audit-logs-lifecycle'));\n }\n }\n};\n"],"names":["bootstrap","strapi","ee","features","isEnabled","contentTypesWithDraftAndPublish","Object","keys","contentTypes","filter","uid","options","draftAndPublish","db","lifecycles","subscribe","models","afterDeleteMany","event","model","getModel","kind","where","params","runAfterCommit","getService","deletePlannedActions","contentType","locale","documentId","entryDocumentId","documents","use","createDeleteActionsOnDelete","createRevalidateActionsOnDraftChange","schedulingService","freezeOverdueReleases","now","Date","catch","error","log","startedAt","then","syncFromDatabase","cron","add","task","OVERDUE_SWEEP_CRON_RULE","entries","ALLOWED_WEBHOOK_EVENTS","forEach","key","value","get","addAllowedEvent","has","registerAuditEvents"],"mappings":";;;;;;;;AAUO,MAAMA,SAAAA,GAAY,OAAO,EAAEC,MAAM,EAA2B,GAAA;AACjE,IAAA,IAAIA,OAAOC,EAAE,CAACC,QAAQ,CAACC,SAAS,CAAC,sBAAA,CAAA,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AAA,CAAOqD,GAAG,CAAC,sBAAA,CAAA,CAAA;AACjC,QAAA;AACF,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { ALLOWED_WEBHOOK_EVENTS, OVERDUE_SWEEP_CRON_RULE } from './constants';\nimport { registerAuditEvents } from './audit-logs';\nimport { getService, runAfterCommit } from './utils';\nimport {\n createDeleteActionsOnDelete,\n createRevalidateActionsOnDraftChange,\n} from './middlewares/documents';\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n if (strapi.ee.features.isEnabled('cms-content-releases')) {\n const contentTypesWithDraftAndPublish = Object.keys(strapi.contentTypes).filter(\n (uid: any) => strapi.contentTypes[uid]?.options?.draftAndPublish\n );\n\n strapi.db.lifecycles.subscribe({\n models: contentTypesWithDraftAndPublish,\n\n /**\n * deleteMany is still used outside documents service, for example when deleting a locale\n */\n afterDeleteMany(event) {\n const model = strapi.getModel(event.model.uid as UID.Schema);\n // @ts-expect-error TODO: lifecycles types looks like are not 100% finished\n if (model.kind !== 'collectionType' || !model.options?.draftAndPublish) {\n return;\n }\n\n const { where } = event.params;\n\n // Not awaited: the delete entry flow doesn't wait for its releases, and isn't blocked by\n // their failure, which is logged\n runAfterCommit(\n () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType: model.uid,\n locale: where?.locale ?? null,\n ...(where?.documentId ? { entryDocumentId: where.documentId } : {}),\n }),\n 'Error while deleting release actions after entry deleteMany',\n { strapi }\n );\n },\n });\n\n // We register middleware to handle ReleaseActions when changes on documents are made\n strapi.documents.use(createDeleteActionsOnDelete({ strapi }));\n strapi.documents.use(createRevalidateActionsOnDraftChange({ strapi }));\n\n const schedulingService = getService('scheduling', { strapi });\n const freezeOverdueReleases = (now = new Date()) =>\n schedulingService.freezeOverdueReleases({ now }).catch((error: unknown) => {\n strapi.log.error('Error while freezing overdue releases in the content-releases plugin', {\n error,\n });\n });\n\n // Overdue releases are frozen before the jobs are armed: a release that failed before the\n // upgrade must not be armed for a date it won't run on. Both use the same instant, so a release\n // still within the grace period for the sweep is run right away by the sync, not left to the\n // next sweep to freeze.\n const startedAt = new Date();\n freezeOverdueReleases(startedAt)\n .then(() => schedulingService.syncFromDatabase({ now: startedAt }))\n .catch((error: unknown) => {\n strapi.log.error(\n 'Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling.',\n { error }\n );\n });\n\n // Then every minute: a release whose scheduled run didn't happen leaves Pending\n strapi.cron.add({\n 'content-releases::freezeOverdueReleases': {\n task: () => freezeOverdueReleases(),\n options: OVERDUE_SWEEP_CRON_RULE,\n },\n });\n\n Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {\n strapi.get('webhookStore').addAllowedEvent(key, value);\n });\n\n // Absent in CE, without the audit-logs license, or when disabled by config;\n // get() throws for services that were never added, so probe first.\n if (strapi.has('audit-logs-lifecycle')) {\n registerAuditEvents(strapi.get('audit-logs-lifecycle'));\n }\n }\n};\n"],"names":["bootstrap","strapi","ee","features","isEnabled","contentTypesWithDraftAndPublish","Object","keys","contentTypes","filter","uid","options","draftAndPublish","db","lifecycles","subscribe","models","afterDeleteMany","event","model","getModel","kind","where","params","runAfterCommit","getService","deletePlannedActions","contentType","locale","documentId","entryDocumentId","documents","use","createDeleteActionsOnDelete","createRevalidateActionsOnDraftChange","schedulingService","freezeOverdueReleases","now","Date","catch","error","log","startedAt","then","syncFromDatabase","cron","add","task","OVERDUE_SWEEP_CRON_RULE","entries","ALLOWED_WEBHOOK_EVENTS","forEach","key","value","get","addAllowedEvent","has","registerAuditEvents"],"mappings":";;;;;;;;AAUO,MAAMA,SAAAA,GAAY,OAAO,EAAEC,MAAM,EAA2B,GAAA;AACjE,IAAA,IAAIA,OAAOC,EAAE,CAACC,QAAQ,CAACC,SAAS,CAAC,sBAAA,CAAA,EAAyB;AACxD,QAAA,MAAMC,kCAAkCC,MAAA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C,sBAAA,CAAA,CAAA;AACjC,QAAA;AACF,IAAA;AACF;;;;"}
@@ -25,9 +25,9 @@ const bootstrap = async ({ strapi })=>{
25
25
  }).deletePlannedActions({
26
26
  contentType: model.uid,
27
27
  locale: where?.locale ?? null,
28
- ...where?.documentId && {
28
+ ...where?.documentId ? {
29
29
  entryDocumentId: where.documentId
30
- }
30
+ } : {}
31
31
  }), 'Error while deleting release actions after entry deleteMany', {
32
32
  strapi
33
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { ALLOWED_WEBHOOK_EVENTS, OVERDUE_SWEEP_CRON_RULE } from './constants';\nimport { registerAuditEvents } from './audit-logs';\nimport { getService, runAfterCommit } from './utils';\nimport {\n createDeleteActionsOnDelete,\n createRevalidateActionsOnDraftChange,\n} from './middlewares/documents';\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n if (strapi.ee.features.isEnabled('cms-content-releases')) {\n const contentTypesWithDraftAndPublish = Object.keys(strapi.contentTypes).filter(\n (uid: any) => strapi.contentTypes[uid]?.options?.draftAndPublish\n );\n\n strapi.db.lifecycles.subscribe({\n models: contentTypesWithDraftAndPublish,\n\n /**\n * deleteMany is still used outside documents service, for example when deleting a locale\n */\n afterDeleteMany(event) {\n const model = strapi.getModel(event.model.uid as UID.Schema);\n // @ts-expect-error TODO: lifecycles types looks like are not 100% finished\n if (model.kind !== 'collectionType' || !model.options?.draftAndPublish) {\n return;\n }\n\n const { where } = event.params;\n\n // Not awaited: the delete entry flow doesn't wait for its releases, and isn't blocked by\n // their failure, which is logged\n runAfterCommit(\n () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType: model.uid,\n locale: where?.locale ?? null,\n ...(where?.documentId && { entryDocumentId: where.documentId }),\n }),\n 'Error while deleting release actions after entry deleteMany',\n { strapi }\n );\n },\n });\n\n // We register middleware to handle ReleaseActions when changes on documents are made\n strapi.documents.use(createDeleteActionsOnDelete({ strapi }));\n strapi.documents.use(createRevalidateActionsOnDraftChange({ strapi }));\n\n const schedulingService = getService('scheduling', { strapi });\n const freezeOverdueReleases = (now = new Date()) =>\n schedulingService.freezeOverdueReleases({ now }).catch((error: unknown) => {\n strapi.log.error('Error while freezing overdue releases in the content-releases plugin', {\n error,\n });\n });\n\n // Overdue releases are frozen before the jobs are armed: a release that failed before the\n // upgrade must not be armed for a date it won't run on. Both use the same instant, so a release\n // still within the grace period for the sweep is run right away by the sync, not left to the\n // next sweep to freeze.\n const startedAt = new Date();\n freezeOverdueReleases(startedAt)\n .then(() => schedulingService.syncFromDatabase({ now: startedAt }))\n .catch((error: unknown) => {\n strapi.log.error(\n 'Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling.',\n { error }\n );\n });\n\n // Then every minute: a release whose scheduled run didn't happen leaves Pending\n strapi.cron.add({\n 'content-releases::freezeOverdueReleases': {\n task: () => freezeOverdueReleases(),\n options: OVERDUE_SWEEP_CRON_RULE,\n },\n });\n\n Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {\n strapi.get('webhookStore').addAllowedEvent(key, value);\n });\n\n // Absent in CE, without the audit-logs license, or when disabled by config;\n // get() throws for services that were never added, so probe first.\n if (strapi.has('audit-logs-lifecycle')) {\n registerAuditEvents(strapi.get('audit-logs-lifecycle'));\n }\n }\n};\n"],"names":["bootstrap","strapi","ee","features","isEnabled","contentTypesWithDraftAndPublish","Object","keys","contentTypes","filter","uid","options","draftAndPublish","db","lifecycles","subscribe","models","afterDeleteMany","event","model","getModel","kind","where","params","runAfterCommit","getService","deletePlannedActions","contentType","locale","documentId","entryDocumentId","documents","use","createDeleteActionsOnDelete","createRevalidateActionsOnDraftChange","schedulingService","freezeOverdueReleases","now","Date","catch","error","log","startedAt","then","syncFromDatabase","cron","add","task","OVERDUE_SWEEP_CRON_RULE","entries","ALLOWED_WEBHOOK_EVENTS","forEach","key","value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A,CAAA,CAAgBC,eAAe,CAACH,GAAAA,EAAKC,KAAAA,CAAAA;AAClD,QAAA,CAAA,CAAA;;;QAIA,IAAIpD,MAAAA,CAAOuD,GAAG,CAAC,sBAAA,CAAA,EAAyB;YACtCC,mBAAAA,CAAoBxD,MAAAA,CAAOqD,GAAG,CAAC,sBAAA,CAAA,CAAA;AACjC,QAAA;AACF,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"bootstrap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import type { Core, UID } from '@strapi/types';\n\nimport { ALLOWED_WEBHOOK_EVENTS, OVERDUE_SWEEP_CRON_RULE } from './constants';\nimport { registerAuditEvents } from './audit-logs';\nimport { getService, runAfterCommit } from './utils';\nimport {\n createDeleteActionsOnDelete,\n createRevalidateActionsOnDraftChange,\n} from './middlewares/documents';\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n if (strapi.ee.features.isEnabled('cms-content-releases')) {\n const contentTypesWithDraftAndPublish = Object.keys(strapi.contentTypes).filter(\n (uid: any) => strapi.contentTypes[uid]?.options?.draftAndPublish\n );\n\n strapi.db.lifecycles.subscribe({\n models: contentTypesWithDraftAndPublish,\n\n /**\n * deleteMany is still used outside documents service, for example when deleting a locale\n */\n afterDeleteMany(event) {\n const model = strapi.getModel(event.model.uid as UID.Schema);\n // @ts-expect-error TODO: lifecycles types looks like are not 100% finished\n if (model.kind !== 'collectionType' || !model.options?.draftAndPublish) {\n return;\n }\n\n const { where } = event.params;\n\n // Not awaited: the delete entry flow doesn't wait for its releases, and isn't blocked by\n // their failure, which is logged\n runAfterCommit(\n () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType: model.uid,\n locale: where?.locale ?? null,\n ...(where?.documentId ? { entryDocumentId: where.documentId } : {}),\n }),\n 'Error while deleting release actions after entry deleteMany',\n { strapi }\n );\n },\n });\n\n // We register middleware to handle ReleaseActions when changes on documents are made\n strapi.documents.use(createDeleteActionsOnDelete({ strapi }));\n strapi.documents.use(createRevalidateActionsOnDraftChange({ strapi }));\n\n const schedulingService = getService('scheduling', { strapi });\n const freezeOverdueReleases = (now = new Date()) =>\n schedulingService.freezeOverdueReleases({ now }).catch((error: unknown) => {\n strapi.log.error('Error while freezing overdue releases in the content-releases plugin', {\n error,\n });\n });\n\n // Overdue releases are frozen before the jobs are armed: a release that failed before the\n // upgrade must not be armed for a date it won't run on. Both use the same instant, so a release\n // still within the grace period for the sweep is run right away by the sync, not left to the\n // next sweep to freeze.\n const startedAt = new Date();\n freezeOverdueReleases(startedAt)\n .then(() => schedulingService.syncFromDatabase({ now: startedAt }))\n .catch((error: unknown) => {\n strapi.log.error(\n 'Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling.',\n { error }\n );\n });\n\n // Then every minute: a release whose scheduled run didn't happen leaves Pending\n strapi.cron.add({\n 'content-releases::freezeOverdueReleases': {\n task: () => freezeOverdueReleases(),\n options: OVERDUE_SWEEP_CRON_RULE,\n },\n });\n\n Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {\n strapi.get('webhookStore').addAllowedEvent(key, value);\n });\n\n // Absent in CE, without the audit-logs license, or when disabled by config;\n // get() throws for services that were never added, so probe first.\n if (strapi.has('audit-logs-lifecycle')) {\n registerAuditEvents(strapi.get('audit-logs-lifecycle'));\n }\n }\n};\n"],"names":["bootstrap","strapi","ee","features","isEnabled","contentTypesWithDraftAndPublish","Object","keys","contentTypes","filter","uid","options","draftAndPublish","db","lifecycles","subscribe","models","afterDeleteMany","event","model","getModel","kind","where","params","runAfterCommit","getService","deletePlannedActions","contentType","locale","documentId","entryDocumentId","documents","use","createDeleteActionsOnDelete","createRevalidateActionsOnDraftChange","schedulingService","freezeOverdueReleases","now","Date","catch","error","log","startedAt","then","syncFromDatabase","cron","add","task","OVERDUE_SWEEP_CRON_RULE","entries","ALLOWED_WEBHOOK_EVENTS","forEach","key","value","get","addAllowedEvent","has","registerAuditEvents"],"mappings":";;;;;;AA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H,GAAAA,EAAKC,KAAAA,CAAAA;AAClD,QAAA,CAAA,CAAA;;;QAIA,IAAIpD,MAAAA,CAAOuD,GAAG,CAAC,sBAAA,CAAA,EAAyB;YACtCC,mBAAAA,CAAoBxD,MAAAA,CAAOqD,GAAG,CAAC,sBAAA,CAAA,CAAA;AACjC,QAAA;AACF,IAAA;AACF;;;;"}
@@ -72,7 +72,7 @@ const createRevalidateActionsOnDraftChange = ({ strapi })=>async (ctx, next)=>{
72
72
  }
73
73
  // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`
74
74
  // `{ entries }`, the new draft of each locale it discarded
75
- const drafts = action === 'discardDraft' && 'entries' in result ? result.entries : [
75
+ const drafts = action === 'discardDraft' && 'entries' in result && Array.isArray(result.entries) ? result.entries : [
76
76
  result
77
77
  ];
78
78
  transactions.runAfterCommit(async ()=>{
@@ -1 +1 @@
1
- {"version":3,"file":"documents.js","sources":["../../../server/src/middlewares/documents.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\nimport { getService, runAfterCommit } from '../utils';\n\ntype Middleware = Modules.Documents.Middleware.Middleware;\n\ntype LocaleFilter = { locale?: string | null | { $in: string[] } };\n\n/**\n * The locales a document delete removed, as a filter on release actions. Resolved the way the\n * document service resolves the `locale` param of a delete.\n */\nconst getDeletedLocalesFilter = async (\n contentType: Schema.ContentType,\n locale: unknown,\n { strapi }: { strapi: Core.Strapi }\n): Promise<LocaleFilter> => {\n if (!strapi.localization.isLocalizedContentType(contentType) || locale === '*') {\n return {};\n }\n\n if (Array.isArray(locale)) {\n return { locale: { $in: locale } };\n }\n\n if (typeof locale === 'string' && locale !== '') {\n return { locale };\n }\n\n return { locale: await strapi.localization.getDefaultLocale() };\n};\n\nconst createDeleteActionsOnDelete =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'delete') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const { contentType: model } = ctx;\n const contentType = model.uid;\n const { documentId, locale } = ctx.params;\n\n const result = await next();\n\n if (!result) {\n return result;\n }\n\n runAfterCommit(\n async () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType,\n entryDocumentId: documentId,\n ...(await getDeletedLocalesFilter(model, locale, { strapi })),\n }),\n 'Error while deleting release actions after delete',\n { strapi }\n );\n\n return result;\n };\n\n// An update or a discarded draft changes the draft a planned release would publish\nconst createRevalidateActionsOnDraftChange =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'update' && ctx.action !== 'discardDraft') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const contentType = ctx.contentType.uid;\n const isLocalized = strapi.localization.isLocalizedContentType(ctx.contentType);\n const { action } = ctx;\n\n const result = await next();\n\n // Neither action returns a count or a list; nothing to revalidate without a result\n if (!result || typeof result !== 'object' || Array.isArray(result)) {\n return result;\n }\n\n // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`\n // `{ entries }`, the new draft of each locale it discarded\n const drafts = action === 'discardDraft' && 'entries' in result ? result.entries : [result];\n\n runAfterCommit(\n async () => {\n for (const draft of drafts) {\n await getService('release-action', { strapi }).revalidatePlannedActions({\n contentType,\n entryDocumentId: draft.documentId,\n ...(isLocalized && { locale: draft.locale }),\n });\n }\n },\n `Error while updating release actions after ${action}`,\n { strapi }\n );\n\n return result;\n };\n\nexport { createDeleteActionsOnDelete, createRevalidateActionsOnDraftChange };\n"],"names":["getDeletedLocalesFilter","contentType","locale","strapi","localization","isLocalizedContentType","Array","isArray","$in","getDefaultLocale","createDeleteActionsOnDelete","ctx","next","action","contentTypes","hasDraftAndPublish","model","uid","documentId","params","result","runAfterCommit","getService","deletePlannedActions","entryDocumentId","createRevalidateActionsOnDraftChange","isLocalized","drafts","entries","draft","revalidatePlannedActions"],"mappings":";;;;;;AAQA;;;AAGC,IAC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A,CAAQ;AAC1B,gBAAA,MAAML,iBAAW,gBAAA,EAAkB;AAAEnB,oBAAAA;AAAO,iBAAA,CAAA,CAAG2B,wBAAwB,CAAC;AACtE7B,oBAAAA,WAAAA;AACAuB,oBAAAA,eAAAA,EAAiBK,MAAMX,UAAU;AACjC,oBAAA,GAAIQ,WAAAA,IAAe;AAAExB,wBAAAA,MAAAA,EAAQ2B,MAAM3B;;AACrC,iBAAA,CAAA;AACF,YAAA;AACF,QAAA,CAAA,EACA,CAAC,2CAA2C,EAAEW,MAAAA,CAAAA,CAAQ,EACtD;AAAEV,YAAAA;AAAO,SAAA,CAAA;QAGX,OAAOiB,MAAAA;AACT,IAAA;;;;;"}
1
+ {"version":3,"file":"documents.js","sources":["../../../server/src/middlewares/documents.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\nimport { getService, runAfterCommit } from '../utils';\n\ntype Middleware = Modules.Documents.Middleware.Middleware;\n\ntype LocaleFilter = { locale?: string | null | { $in: string[] } };\n\n/**\n * The locales a document delete removed, as a filter on release actions. Resolved the way the\n * document service resolves the `locale` param of a delete.\n */\nconst getDeletedLocalesFilter = async (\n contentType: Schema.ContentType,\n locale: unknown,\n { strapi }: { strapi: Core.Strapi }\n): Promise<LocaleFilter> => {\n if (!strapi.localization.isLocalizedContentType(contentType) || locale === '*') {\n return {};\n }\n\n if (Array.isArray(locale)) {\n return { locale: { $in: locale } };\n }\n\n if (typeof locale === 'string' && locale !== '') {\n return { locale };\n }\n\n return { locale: await strapi.localization.getDefaultLocale() };\n};\n\nconst createDeleteActionsOnDelete =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'delete') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const { contentType: model } = ctx;\n const contentType = model.uid;\n const { documentId, locale } = ctx.params;\n\n const result = await next();\n\n if (!result) {\n return result;\n }\n\n runAfterCommit(\n async () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType,\n entryDocumentId: documentId,\n ...(await getDeletedLocalesFilter(model, locale, { strapi })),\n }),\n 'Error while deleting release actions after delete',\n { strapi }\n );\n\n return result;\n };\n\n// An update or a discarded draft changes the draft a planned release would publish\nconst createRevalidateActionsOnDraftChange =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'update' && ctx.action !== 'discardDraft') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const contentType = ctx.contentType.uid;\n const isLocalized = strapi.localization.isLocalizedContentType(ctx.contentType);\n const { action } = ctx;\n\n const result = await next();\n\n // Neither action returns a count or a list; nothing to revalidate without a result\n if (!result || typeof result !== 'object' || Array.isArray(result)) {\n return result;\n }\n\n // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`\n // `{ entries }`, the new draft of each locale it discarded\n const drafts: Modules.Documents.AnyDocument[] =\n action === 'discardDraft' && 'entries' in result && Array.isArray(result.entries)\n ? result.entries\n : [result];\n\n runAfterCommit(\n async () => {\n for (const draft of drafts) {\n await getService('release-action', { strapi }).revalidatePlannedActions({\n contentType,\n entryDocumentId: draft.documentId,\n ...(isLocalized && { locale: draft.locale }),\n });\n }\n },\n `Error while updating release actions after ${action}`,\n { strapi }\n );\n\n return result;\n };\n\nexport { createDeleteActionsOnDelete, createRevalidateActionsOnDraftChange };\n"],"names":["getDeletedLocalesFilter","contentType","locale","strapi","localization","isLocalizedContentType","Array","isArray","$in","getDefaultLocale","createDeleteActionsOnDelete","ctx","next","action","contentTypes","hasDraftAndPublish","model","uid","documentId","params","result","runAfterCommit","getService","deletePlannedActions","entryDocumentId","createRevalidateActionsOnDraftChange","isLocalized","drafts","entries","draft","revalidatePlannedActions"],"mappings":";;;;;;AAQA;;;AAGC,IACD,MAAMA,uBAAAA,GAA0B,OAC9BC,aACAC,MAAAA,EACA,EAAEC,MAAM,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AASF,MAAAA,CAAQ;AAC1B,gBAAA,MAAML,iBAAW,gBAAA,EAAkB;AAAEnB,oBAAAA;AAAO,iBAAA,CAAA,CAAG2B,wBAAwB,CAAC;AACtE7B,oBAAAA,WAAAA;AACAuB,oBAAAA,eAAAA,EAAiBK,MAAMX,UAAU;AACjC,oBAAA,GAAIQ,WAAAA,IAAe;AAAExB,wBAAAA,MAAAA,EAAQ2B,MAAM3B;;AACrC,iBAAA,CAAA;AACF,YAAA;AACF,QAAA,CAAA,EACA,CAAC,2CAA2C,EAAEW,MAAAA,CAAAA,CAAQ,EACtD;AAAEV,YAAAA;AAAO,SAAA,CAAA;QAGX,OAAOiB,MAAAA;AACT,IAAA;;;;;"}
@@ -70,7 +70,7 @@ const createRevalidateActionsOnDraftChange = ({ strapi })=>async (ctx, next)=>{
70
70
  }
71
71
  // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`
72
72
  // `{ entries }`, the new draft of each locale it discarded
73
- const drafts = action === 'discardDraft' && 'entries' in result ? result.entries : [
73
+ const drafts = action === 'discardDraft' && 'entries' in result && Array.isArray(result.entries) ? result.entries : [
74
74
  result
75
75
  ];
76
76
  runAfterCommit(async ()=>{
@@ -1 +1 @@
1
- {"version":3,"file":"documents.mjs","sources":["../../../server/src/middlewares/documents.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\nimport { getService, runAfterCommit } from '../utils';\n\ntype Middleware = Modules.Documents.Middleware.Middleware;\n\ntype LocaleFilter = { locale?: string | null | { $in: string[] } };\n\n/**\n * The locales a document delete removed, as a filter on release actions. Resolved the way the\n * document service resolves the `locale` param of a delete.\n */\nconst getDeletedLocalesFilter = async (\n contentType: Schema.ContentType,\n locale: unknown,\n { strapi }: { strapi: Core.Strapi }\n): Promise<LocaleFilter> => {\n if (!strapi.localization.isLocalizedContentType(contentType) || locale === '*') {\n return {};\n }\n\n if (Array.isArray(locale)) {\n return { locale: { $in: locale } };\n }\n\n if (typeof locale === 'string' && locale !== '') {\n return { locale };\n }\n\n return { locale: await strapi.localization.getDefaultLocale() };\n};\n\nconst createDeleteActionsOnDelete =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'delete') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const { contentType: model } = ctx;\n const contentType = model.uid;\n const { documentId, locale } = ctx.params;\n\n const result = await next();\n\n if (!result) {\n return result;\n }\n\n runAfterCommit(\n async () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType,\n entryDocumentId: documentId,\n ...(await getDeletedLocalesFilter(model, locale, { strapi })),\n }),\n 'Error while deleting release actions after delete',\n { strapi }\n );\n\n return result;\n };\n\n// An update or a discarded draft changes the draft a planned release would publish\nconst createRevalidateActionsOnDraftChange =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'update' && ctx.action !== 'discardDraft') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const contentType = ctx.contentType.uid;\n const isLocalized = strapi.localization.isLocalizedContentType(ctx.contentType);\n const { action } = ctx;\n\n const result = await next();\n\n // Neither action returns a count or a list; nothing to revalidate without a result\n if (!result || typeof result !== 'object' || Array.isArray(result)) {\n return result;\n }\n\n // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`\n // `{ entries }`, the new draft of each locale it discarded\n const drafts = action === 'discardDraft' && 'entries' in result ? result.entries : [result];\n\n runAfterCommit(\n async () => {\n for (const draft of drafts) {\n await getService('release-action', { strapi }).revalidatePlannedActions({\n contentType,\n entryDocumentId: draft.documentId,\n ...(isLocalized && { locale: draft.locale }),\n });\n }\n },\n `Error while updating release actions after ${action}`,\n { strapi }\n );\n\n return result;\n };\n\nexport { createDeleteActionsOnDelete, createRevalidateActionsOnDraftChange };\n"],"names":["getDeletedLocalesFilter","contentType","locale","strapi","localization","isLocalizedContentType","Array","isArray","$in","getDefaultLocale","createDeleteActionsOnDelete","ctx","next","action","contentTypes","hasDraftAndPublish","model","uid","documentId","params","result","runAfterCommit","getService","deletePlannedActions","entryDocumentId","createRevalidateActionsOnDraftChange","isLocalized","drafts","entries","draft","revalidatePlannedActions"],"mappings":";;;;AAQA;;;AAGC,IACD,MAAMA,uBAAAA,GAA0B,OAC9BC,aACAC,MAAAA,EACA,EAAEC,MAAM,EAA2B,GAAA;IAEnC,IAAI,CAACA,OAAOC,YAAY,CAACC,sBAAsB,CAACJ,WAAAA,CAAAA,IAAgBC,WAAW,GAAA,EAAK;AAC9E,QAAA,OAAO,EAAC;AACV,IAAA;IAEA,IAAII,KAAAA,CAAMC,OAAO,CAACL,MAAAA,CAAAA,EAAS;QACzB,OAAO;YAAEA,MAAAA,EAAQ;gBAAEM,GAAAA,EAAKN;AAAO;AAAE,SAAA;AACnC,IAAA;AAEA,IAAA,IAAI,OAAOA,MAAAA,KAAW,QAAA,IAAYA,MAAAA,KAAW,EAAA,EAAI;QAC/C,OAAO;AAAEA,YAAAA;AAAO,SAAA;AAClB,IAAA;IAEA,OAAO;AAAEA,QAAAA,MAAAA,EAAQ,MAAMC,MAAAA,CAAOC,YAAY,CAACK,gBAAgB;AAAG,KAAA;AAChE,CAAA;AAEA,MAAMC,8BACJ,CAAC,EAAEP,MAAM,EAA2B,GACpC,OAAOQ,GAAAA,EAAKC,IAAAA,GAAAA;QACV,IAAID,GAAAA,CAAIE,MAAM,KAAK,QAAA,EAAU;YAC3B,OAAOD,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,IAAI,CAACE,YAAAA,CAAaC,kBAAkB,CAACJ,GAAAA,CAAIV,WAAW,CAAA,EAAG;YACrD,OAAOW,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,MAAM,EAAEX,WAAAA,EAAae,KAAK,EAAE,GAAGL,GAAAA;QAC/B,MAAMV,WAAAA,GAAce,MAAMC,GAAG;AAC7B,QAAA,MAAM,EAA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MAAAA;AACT,QAAA;;;AAIA,QAAA,MAAMO,SAASd,MAAAA,KAAW,cAAA,IAAkB,aAAaO,MAAAA,GAASA,MAAAA,CAAOQ,OAAO,GAAG;AAACR,YAAAA;AAAO,SAAA;QAE3FC,cAAAA,CACE,UAAA;YACE,KAAK,MAAMQ,SAASF,MAAAA,CAAQ;AAC1B,gBAAA,MAAML,WAAW,gBAAA,EAAkB;AAAEnB,oBAAAA;AAAO,iBAAA,CAAA,CAAG2B,wBAAwB,CAAC;AACtE7B,oBAAAA,WAAAA;AACAuB,oBAAAA,eAAAA,EAAiBK,MAAMX,UAAU;AACjC,oBAAA,GAAIQ,WAAAA,IAAe;AAAExB,wBAAAA,MAAAA,EAAQ2B,MAAM3B;;AACrC,iBAAA,CAAA;AACF,YAAA;AACF,QAAA,CAAA,EACA,CAAC,2CAA2C,EAAEW,MAAAA,CAAAA,CAAQ,EACtD;AAAEV,YAAAA;AAAO,SAAA,CAAA;QAGX,OAAOiB,MAAAA;AACT,IAAA;;;;"}
1
+ {"version":3,"file":"documents.mjs","sources":["../../../server/src/middlewares/documents.ts"],"sourcesContent":["import type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\nimport { getService, runAfterCommit } from '../utils';\n\ntype Middleware = Modules.Documents.Middleware.Middleware;\n\ntype LocaleFilter = { locale?: string | null | { $in: string[] } };\n\n/**\n * The locales a document delete removed, as a filter on release actions. Resolved the way the\n * document service resolves the `locale` param of a delete.\n */\nconst getDeletedLocalesFilter = async (\n contentType: Schema.ContentType,\n locale: unknown,\n { strapi }: { strapi: Core.Strapi }\n): Promise<LocaleFilter> => {\n if (!strapi.localization.isLocalizedContentType(contentType) || locale === '*') {\n return {};\n }\n\n if (Array.isArray(locale)) {\n return { locale: { $in: locale } };\n }\n\n if (typeof locale === 'string' && locale !== '') {\n return { locale };\n }\n\n return { locale: await strapi.localization.getDefaultLocale() };\n};\n\nconst createDeleteActionsOnDelete =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'delete') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const { contentType: model } = ctx;\n const contentType = model.uid;\n const { documentId, locale } = ctx.params;\n\n const result = await next();\n\n if (!result) {\n return result;\n }\n\n runAfterCommit(\n async () =>\n getService('release-action', { strapi }).deletePlannedActions({\n contentType,\n entryDocumentId: documentId,\n ...(await getDeletedLocalesFilter(model, locale, { strapi })),\n }),\n 'Error while deleting release actions after delete',\n { strapi }\n );\n\n return result;\n };\n\n// An update or a discarded draft changes the draft a planned release would publish\nconst createRevalidateActionsOnDraftChange =\n ({ strapi }: { strapi: Core.Strapi }): Middleware =>\n async (ctx, next) => {\n if (ctx.action !== 'update' && ctx.action !== 'discardDraft') {\n return next();\n }\n\n if (!contentTypes.hasDraftAndPublish(ctx.contentType)) {\n return next();\n }\n\n const contentType = ctx.contentType.uid;\n const isLocalized = strapi.localization.isLocalizedContentType(ctx.contentType);\n const { action } = ctx;\n\n const result = await next();\n\n // Neither action returns a count or a list; nothing to revalidate without a result\n if (!result || typeof result !== 'object' || Array.isArray(result)) {\n return result;\n }\n\n // `update` returns the updated draft (which may have its own `entries` field); `discardDraft`\n // `{ entries }`, the new draft of each locale it discarded\n const drafts: Modules.Documents.AnyDocument[] =\n action === 'discardDraft' && 'entries' in result && Array.isArray(result.entries)\n ? result.entries\n : [result];\n\n runAfterCommit(\n async () => {\n for (const draft of drafts) {\n await getService('release-action', { strapi }).revalidatePlannedActions({\n contentType,\n entryDocumentId: draft.documentId,\n ...(isLocalized && { locale: draft.locale }),\n });\n }\n },\n `Error while updating release actions after ${action}`,\n { strapi }\n );\n\n return result;\n };\n\nexport { createDeleteActionsOnDelete, createRevalidateActionsOnDraftChange };\n"],"names":["getDeletedLocalesFilter","contentType","locale","strapi","localization","isLocalizedContentType","Array","isArray","$in","getDefaultLocale","createDeleteActionsOnDelete","ctx","next","action","contentTypes","hasDraftAndPublish","model","uid","documentId","params","result","runAfterCommit","getService","deletePlannedActions","entryDocumentId","createRevalidateActionsOnDraftChange","isLocalized","drafts","entries","draft","revalidatePlannedActions"],"mappings":";;;;AAQA;;;AAGC,IACD,MAAMA,uBAAAA,GAA0B,OAC9BC,aACAC,MAAAA,EACA,EAAEC,MAAM,EAA2B,GAAA;IAEnC,IAAI,CAACA,OAAOC,YAAY,CAACC,sBAAsB,CAACJ,WAAAA,CAAAA,IAAgBC,WAAW,GAAA,EAAK;AAC9E,QAAA,OAAO,EAAC;AACV,IAAA;IAEA,IAAII,KAAAA,CAAMC,OAAO,CAACL,MAAAA,CAAAA,EAAS;QACzB,OAAO;YAAEA,MAAAA,EAAQ;gBAAEM,GAAAA,EAAKN;AAAO;AAAE,SAAA;AACnC,IAAA;AAEA,IAAA,IAAI,OAAOA,MAAAA,KAAW,QAAA,IAAYA,MAAAA,KAAW,EAAA,EAAI;QAC/C,OAAO;AAAEA,YAAAA;AAAO,SAAA;AAClB,IAAA;IAEA,OAAO;AAAEA,QAAAA,MAAAA,EAAQ,MAAMC,MAAAA,CAAOC,YAAY,CAACK,gBAAgB;AAAG,KAAA;AAChE,CAAA;AAEA,MAAMC,8BACJ,CAAC,EAAEP,MAAM,EAA2B,GACpC,OAAOQ,GAAAA,EAAKC,IAAAA,GAAAA;QACV,IAAID,GAAAA,CAAIE,MAAM,KAAK,QAAA,EAAU;YAC3B,OAAOD,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,IAAI,CAACE,YAAAA,CAAaC,kBAAkB,CAACJ,GAAAA,CAAIV,WAAW,CAAA,EAAG;YACrD,OAAOW,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,MAAM,EAAEX,WAAAA,EAAae,KAAK,EAAE,GAAGL,GAAAA;QAC/B,MAAMV,WAAAA,GAAce,MAAMC,GAAG;AAC7B,QAAA,MAAM,EAAEC,UAAU,EAAEhB,MAAM,EAAE,GAAGS,IAAIQ,MAAM;AAEzC,QAAA,MAAMC,S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AAkB,SAAA,IAAaO,MAAAA,IAAUd,KAAAA,CAAMC,OAAO,CAACa,MAAAA,CAAOQ,OAAO,CAAA,GAC5ER,MAAAA,CAAOQ,OAAO,GACd;AAACR,YAAAA;AAAO,SAAA;QAEdC,cAAAA,CACE,UAAA;YACE,KAAK,MAAMQ,SAASF,MAAAA,CAAQ;AAC1B,gBAAA,MAAML,WAAW,gBAAA,EAAkB;AAAEnB,oBAAAA;AAAO,iBAAA,CAAA,CAAG2B,wBAAwB,CAAC;AACtE7B,oBAAAA,WAAAA;AACAuB,oBAAAA,eAAAA,EAAiBK,MAAMX,UAAU;AACjC,oBAAA,GAAIQ,WAAAA,IAAe;AAAExB,wBAAAA,MAAAA,EAAQ2B,MAAM3B;;AACrC,iBAAA,CAAA;AACF,YAAA;AACF,QAAA,CAAA,EACA,CAAC,2CAA2C,EAAEW,MAAAA,CAAAA,CAAQ,EACtD;AAAEV,YAAAA;AAAO,SAAA,CAAA;QAGX,OAAOiB,MAAAA;AACT,IAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../../../server/src/middlewares/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AAI3D,KAAK,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC;AA4B1D,QAAA,MAAM,2BAA2B,GAC9B,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,KAAG,UAgCtC,CAAC;AAGJ,QAAA,MAAM,oCAAoC,GACvC,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,KAAG,UAwCtC,CAAC;AAEJ,OAAO,EAAE,2BAA2B,EAAE,oCAAoC,EAAE,CAAC"}
1
+ {"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../../../server/src/middlewares/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AAI3D,KAAK,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC;AA4B1D,QAAA,MAAM,2BAA2B,GAC9B,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,KAAG,UAgCtC,CAAC;AAGJ,QAAA,MAAM,oCAAoC,GACvC,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,KAAG,UA2CtC,CAAC;AAEJ,OAAO,EAAE,2BAA2B,EAAE,oCAAoC,EAAE,CAAC"}
@@ -151,7 +151,7 @@ const computeEntryPublishability = async (contentTypeUid, entry, { workflow, str
151
151
  // leaves that version out of unique checks
152
152
  const publishedVersion = await strapi.documents(contentTypeUid).findOne({
153
153
  documentId: entry.documentId,
154
- locale: entry.locale,
154
+ locale: entry.locale ?? undefined,
155
155
  status: 'published',
156
156
  fields: [
157
157
  'documentId'
@@ -1 +1 @@
1
- {"version":3,"file":"publishability.js","sources":["../../../server/src/utils/publishability.ts"],"sourcesContent":["import { contentTypes, errors } from '@strapi/utils';\n\nimport type { UID, Core, Modules, Schema } from '@strapi/types';\nimport type {\n ReleaseAction,\n ReleaseActionOutcome,\n ReleaseActionReason,\n StageRef,\n} from '../../../shared/contracts/release-actions';\nimport { getEntry } from './entries';\nimport type { EntryPopulate } from './entries';\n\nexport interface EntryValidity {\n isEntryValid: boolean;\n reason: ReleaseActionReason | null;\n}\n\nexport const UNPUBLISH_VALIDITY: EntryValidity = { isEntryValid: true, reason: null };\n\ntype WorkflowWithRequiredStage = { stageRequiredToPublish?: StageRef | null } | null | undefined;\n\ntype DraftEntry = Modules.Documents.AnyDocument & { strapi_stage?: StageRef | null };\n\nexport type PublishabilityOutcome = Extract<\n ReleaseActionOutcome,\n 'skipped_invalid' | 'skipped_not_approved'\n>;\n\nexport type EntryPublishability =\n | { publishable: true; outcome: null; reason: null; error: null }\n | {\n publishable: false;\n outcome: PublishabilityOutcome;\n reason: ReleaseActionReason;\n /** What publishing the entry would throw; a rejected release reports its message */\n error: Error;\n };\n\n// The draft a publish action points at\nexport type DraftRef = Pick<ReleaseAction, 'contentType'> & {\n entryDocumentId?: ReleaseAction['entryDocumentId'];\n locale?: ReleaseAction['locale'];\n};\n\ntype PublishActionRef = DraftRef & Pick<ReleaseAction, 'id' | 'type'>;\n\n// Identifies an entry in one locale (or the only one, for a content type that isn't localized)\nexport const getEntryKey = (\n contentType: string,\n documentId: string | undefined,\n locale?: string | null\n) => JSON.stringify([contentType, documentId, locale ?? null]);\n\n// Thrown by review-workflows when an entry that isn't at the required stage is published\nconst STAGE_ERROR_MESSAGE = 'Entry is not at the required stage to publish';\n\n// A publish review-workflows refused because the entry isn't at the required stage\nexport const isStageError = (error: unknown) =>\n error instanceof errors.ValidationError && error.message === STAGE_ERROR_MESSAGE;\n\nconst toStageReason = (\n entryStage: StageRef | null,\n requiredStage: StageRef\n): NonNullable<ReleaseActionReason['stage']> => ({\n entryStage: entryStage && { id: entryStage.id, name: entryStage.name },\n requiredStage: { id: requiredStage.id, name: requiredStage.name },\n});\n\n// Strapi's type-mismatch message ends with the submitted value (`notType` in `@strapi/utils`'s\n// yup.ts): cut off, the rest still names the field and the expected type\nconst SUBMITTED_VALUE_SUFFIX = /, but the final value was: [\\s\\S]*$/;\n\n// Only the field paths and messages: the details also carry the submitted values\nconst getValidationErrors = (error: Error) => {\n const details: unknown = error instanceof errors.ValidationError ? error.details : null;\n const detailErrors: unknown[] =\n typeof details === 'object' &&\n details !== null &&\n 'errors' in details &&\n Array.isArray(details.errors)\n ? details.errors\n : [];\n\n return detailErrors.map((detail) => {\n const isObject = typeof detail === 'object' && detail !== null;\n const path = isObject && 'path' in detail ? detail.path : undefined;\n const message = isObject && 'message' in detail ? detail.message : undefined;\n\n return {\n path: Array.isArray(path) ? path.map(String) : [],\n message: typeof message === 'string' ? message.replace(SUBMITTED_VALUE_SUFFIX, '') : '',\n };\n });\n};\n\n// Something thrown that isn't an Error, kept as its cause\nexport const toError = (caught: unknown) =>\n caught instanceof Error ? caught : new Error('Non-Error thrown', { cause: caught });\n\n// Only the error's name: its message can carry row contents\nexport const getErrorName = (error: unknown) => (error instanceof Error ? error.name : 'Error');\n\n// A database driver's error code (e.g. node-postgres `23505`, mysql2 `ER_DUP_ENTRY`): it names the\n// failure without any row contents\nconst getErrorCode = (error: unknown) =>\n typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string'\n ? error.code\n : undefined;\n\n// A transient conflict with another transaction: a MySQL deadlock or lock wait timeout, a Postgres\n// deadlock or serialization failure. InnoDB rolls back the whole transaction on a deadlock (on a\n// lock wait timeout, only with `innodb_rollback_on_timeout`; else just the statement).\nconst CONFLICT_CODES = new Set(['ER_LOCK_DEADLOCK', 'ER_LOCK_WAIT_TIMEOUT', '40P01', '40001']);\n\n/**\n * Whether an error in a transaction isn't the entry's own failure but the transaction's: a\n * conflict with another transaction, or a savepoint the database couldn't release or roll back to\n * (`SavepointError` from `@strapi/database`, matched by name: the transaction is lost or broken).\n * Nothing done in the transaction can then be recorded as the entry's outcome, so the caller's\n * transaction must fail with it, leaving the release planned for another run.\n */\nexport const isRunConflict = (error: unknown) =>\n (error instanceof Error && error.name === 'SavepointError') ||\n CONFLICT_CODES.has(getErrorCode(error) ?? '');\n\n// The reason shapes an entry that wasn't released stores\nexport const toValidationReason = (error: Error) => ({\n validation: { errors: getValidationErrors(error) },\n});\n\n// Only the error's name, and its driver code: its message can carry row contents. An application\n// error's message is meant for the client (a manual publish sends it as is), so it's kept, without\n// the submitted value a type-mismatch message ends with.\nexport const toErrorReason = (error: unknown): ReleaseActionReason => {\n const code = getErrorCode(error);\n\n return {\n error: {\n name: getErrorName(error),\n ...(error instanceof errors.ApplicationError && {\n message: error.message.replace(SUBMITTED_VALUE_SUFFIX, ''),\n }),\n ...(code && { code }),\n },\n };\n};\n\n// The validity stored for a checked entry. One whose check threw (e.g. its draft can't be read)\n// isn't publishable, with only the error's name (and an application error's message).\nexport const toEntryValidity = (check: EntryPublishability | Error): EntryValidity => {\n if (check instanceof Error) {\n return { isEntryValid: false, reason: toErrorReason(check) };\n }\n\n return check.publishable\n ? { isEntryValid: true, reason: null }\n : { isEntryValid: false, reason: check.reason };\n};\n\n// A check's result, or the error that stopped it. In a transaction, each check reads in its own\n// savepoint: without one, on Postgres a failed read would abort the transaction, and every other\n// check with it.\nconst readCheck = async <TResult>(\n read: () => Promise<TResult>,\n { strapi }: { strapi: Core.Strapi }\n): Promise<TResult | Error> => {\n const inTransaction = strapi.db.inTransaction();\n\n try {\n return await (inTransaction ? strapi.db.savepoint(read) : read());\n } catch (error) {\n // In a transaction, the transaction fails with a conflict: no other check, nor what the caller\n // records, can be kept. Outside one, it only undid this read, so it's a failed check.\n if (inTransaction && isRunConflict(error)) {\n throw error;\n }\n return toError(error);\n }\n};\n\nconst getAssignedWorkflow = async (\n contentTypeUid: UID.ContentType,\n { strapi }: { strapi: Core.Strapi }\n): Promise<WorkflowWithRequiredStage> => {\n // Workflows service may not be available depending on the license\n const workflowsService = strapi.plugin('review-workflows')?.service('workflows');\n\n return workflowsService?.getAssignedWorkflow(contentTypeUid, {\n populate: 'stageRequiredToPublish',\n });\n};\n\n// Whether an entry can be published now: its draft passes publish validation and, if its\n// workflow requires a stage to publish, it is at that stage\nconst computeEntryPublishability = async (\n contentTypeUid: UID.ContentType,\n entry: DraftEntry | null,\n { workflow, strictRelations }: { workflow: WorkflowWithRequiredStage; strictRelations: boolean },\n { strapi }: { strapi: Core.Strapi }\n): Promise<EntryPublishability> => {\n if (!entry) {\n return {\n publishable: false,\n outcome: 'skipped_invalid',\n reason: { validation: { errors: [] } },\n error: new errors.ValidationError('Entry not found'),\n };\n }\n\n // Publishing deletes the published version before validating the draft, so the validator\n // leaves that version out of unique checks\n const publishedVersion = await strapi.documents(contentTypeUid).findOne({\n documentId: entry.documentId,\n locale: entry.locale,\n status: 'published',\n fields: ['documentId'],\n });\n\n let validationError: Error | null = null;\n try {\n // @TODO: When documents service has validateEntityCreation method, use it instead\n await strapi.entityValidator.validateEntityCreation(\n strapi.getModel(contentTypeUid),\n entry,\n { isDraft: false, locale: entry.locale, strictRelations },\n // @ts-expect-error - the validator takes the entry to leave out of unique checks, but its type doesn't declare it for creation\n publishedVersion\n );\n } catch (error) {\n // Anything else isn't the entry's fault: the caller decides what an unchecked entry means\n if (!(error instanceof errors.ValidationError)) {\n throw error;\n }\n validationError = error;\n }\n\n // Checked even when validation failed, so the reason can carry both\n const requiredStage = workflow?.stageRequiredToPublish ?? null;\n const entryStage = entry.strapi_stage ?? null;\n const isAtRequiredStage = requiredStage === null || entryStage?.id === requiredStage.id;\n\n if (isAtRequiredStage) {\n return validationError === null\n ? { publishable: true, outcome: null, reason: null, error: null }\n : {\n publishable: false,\n outcome: 'skipped_invalid',\n reason: toValidationReason(validationError),\n error: validationError,\n };\n }\n\n return {\n publishable: false,\n outcome: validationError ? 'skipped_invalid' : 'skipped_not_approved',\n reason: {\n ...(validationError && toValidationReason(validationError)),\n stage: toStageReason(entryStage, requiredStage),\n },\n // Same precedence as a publish: review-workflows rejects the stage before validation\n error: new errors.ValidationError(STAGE_ERROR_MESSAGE),\n };\n};\n\n// What the run's earlier actions leave each entry with, by entry key: published (a publish) or not\n// (an unpublish)\ntype ReleasedInRun = ReadonlyMap<string, boolean>;\n\ntype RelationTarget = { documentId?: string; locale?: string | null };\n\ninterface TargetFilter {\n isTargetPublished: (\n targetUid: UID.ContentType,\n target: RelationTarget\n ) => boolean | Promise<boolean>;\n strapi: Core.Strapi;\n}\n\n// The target of a required relation publish can drop: one with draft and publish (any other\n// target is always published), on a relation the validation reads\nconst getDroppableTarget = (\n attribute: Schema.Attribute.AnyAttribute,\n { strapi }: Pick<TargetFilter, 'strapi'>\n): UID.ContentType | undefined =>\n attribute.type === 'relation' &&\n attribute.required &&\n 'target' in attribute &&\n contentTypes.hasDraftAndPublish(strapi.getModel(attribute.target))\n ? attribute.target\n : undefined;\n\n// The targets of a relation publish connects: a to-one relation without one is empty\nconst keepPublishedTargets = async (\n targetUid: UID.ContentType,\n value: unknown,\n { isTargetPublished }: TargetFilter\n) => {\n if (!Array.isArray(value)) {\n return (await isTargetPublished(targetUid, value as RelationTarget)) ? value : null;\n }\n\n const kept = [];\n for (const target of value) {\n if (await isTargetPublished(targetUid, target)) {\n kept.push(target);\n }\n }\n return kept;\n};\n\nconst keepInComponent = (componentUid: UID.Component, value: unknown, filter: TargetFilter) =>\n typeof value === 'object' && value !== null\n ? keepPublishedRequiredTargets(componentUid, value as Record<string, unknown>, filter)\n : value;\n\n// An attribute's value as publish validates it: its droppable targets filtered, its components\n// and dynamic zone items walked\nconst keepInAttribute = async (\n attribute: Schema.Attribute.AnyAttribute,\n value: unknown,\n filter: TargetFilter\n): Promise<unknown> => {\n const targetUid = getDroppableTarget(attribute, filter);\n if (targetUid) {\n return keepPublishedTargets(targetUid, value, filter);\n }\n\n if (attribute.type === 'component') {\n return Array.isArray(value)\n ? Promise.all(\n value.map((component) => keepInComponent(attribute.component, component, filter))\n )\n : keepInComponent(attribute.component, value, filter);\n }\n\n if (attribute.type === 'dynamiczone' && Array.isArray(value)) {\n return Promise.all(\n value.map((component: { __component?: UID.Component }) =>\n component.__component\n ? keepInComponent(component.__component, component, filter)\n : component\n )\n );\n }\n\n return value;\n};\n\n/**\n * The draft as the document service's publish validates it under `api.documents.strictRelations`:\n * publish connects each relation to its target's published version and drops the targets without\n * one (`allowMissingId` in its data transform), then enforces required relations. Only required\n * relations to draft and publish targets are filtered: the others are never dropped, or never\n * validated. Components and dynamic zones are walked, as publish does.\n */\nconst keepPublishedRequiredTargets = async (\n modelUid: UID.Schema,\n data: Record<string, unknown>,\n filter: TargetFilter\n): Promise<Record<string, unknown>> => {\n const attributes: Record<string, Schema.Attribute.AnyAttribute> =\n filter.strapi.getModel(modelUid)?.attributes ?? {};\n const result = { ...data };\n\n for (const [name, attribute] of Object.entries(attributes)) {\n const value = data[name];\n if (value !== null && value !== undefined) {\n result[name] = await keepInAttribute(attribute, value, filter);\n }\n }\n\n return result;\n};\n\n// Whether an entry has a published version, read once per entry. A target without a document id\n// can't be connected.\nconst createPublishedVersionLookup = ({ strapi }: { strapi: Core.Strapi }) => {\n const hasPublishedVersionByEntry = new Map<string, Promise<boolean>>();\n\n return (targetUid: UID.ContentType, { documentId, locale }: RelationTarget) => {\n const key = getEntryKey(targetUid, documentId, locale);\n let hasPublished = hasPublishedVersionByEntry.get(key);\n if (!hasPublished) {\n hasPublished = documentId\n ? strapi\n .documents(targetUid)\n .findOne({\n documentId,\n locale: locale ?? undefined,\n status: 'published',\n fields: ['documentId'],\n })\n .then((published) => published !== null)\n : Promise.resolve(false);\n hasPublishedVersionByEntry.set(key, hasPublished);\n }\n\n return hasPublished;\n };\n};\n\n// Checks drafts, looking up the populate and the workflow once per content type and reading\n// each draft once (an entry in several planned releases has one action in each)\nconst createDraftPublishabilityCheck = ({ strapi }: { strapi: Core.Strapi }) => {\n const populateBuilderService = strapi.plugin('content-manager').service('populate-builder');\n // Same strict relations rule as the document service's publish\n const strictRelations = strapi.config.get('api.documents.strictRelations', undefined) === true;\n const lookupsByContentType = new Map<\n UID.ContentType,\n { populate: EntryPopulate; workflow: WorkflowWithRequiredStage }\n >();\n const publishabilityByDraft = new Map<string, Promise<EntryPublishability>>();\n const hasPublishedVersion = createPublishedVersionLookup({ strapi });\n\n const readDraft = async (\n draft: DraftRef,\n releasedInRun: ReleasedInRun | undefined\n ): Promise<EntryPublishability> => {\n let lookups = lookupsByContentType.get(draft.contentType);\n if (!lookups) {\n lookups = {\n // @ts-expect-error - populateBuilderService should be a function but is returning service\n populate: await populateBuilderService(draft.contentType).populateDeep(Infinity).build(),\n workflow: await getAssignedWorkflow(draft.contentType, { strapi }),\n };\n lookupsByContentType.set(draft.contentType, lookups);\n }\n\n const entry = await getEntry(\n {\n contentType: draft.contentType,\n documentId: draft.entryDocumentId,\n locale: draft.locale,\n populate: lookups.populate,\n },\n { strapi }\n );\n\n // A planned release's validity checks the draft as is: which targets the run releases first\n // is only known in the run\n const checkedEntry =\n entry && strictRelations && releasedInRun\n ? ((await keepPublishedRequiredTargets(draft.contentType, entry, {\n isTargetPublished: (targetUid, target) =>\n releasedInRun.get(getEntryKey(targetUid, target.documentId, target.locale)) ??\n hasPublishedVersion(targetUid, target),\n strapi,\n })) as DraftEntry)\n : entry;\n\n return computeEntryPublishability(\n draft.contentType,\n checkedEntry,\n { workflow: lookups.workflow, strictRelations },\n { strapi }\n );\n };\n\n return (draft: DraftRef, releasedInRun?: ReleasedInRun): Promise<EntryPublishability> => {\n const key = getEntryKey(draft.contentType, draft.entryDocumentId, draft.locale);\n let publishability = publishabilityByDraft.get(key);\n if (!publishability) {\n publishability = readDraft(draft, releasedInRun);\n publishabilityByDraft.set(key, publishability);\n }\n\n return publishability;\n };\n};\n\n// With `inRunOrder`, the actions are a run's, in the order it releases them: each check sees what\n// the actions before it release\nconst checkPublishActions = async <TAction extends PublishActionRef, TResult>(\n actions: readonly TAction[],\n toResult: (readPublishability: () => Promise<EntryPublishability>) => Promise<TResult>,\n { strapi, inRunOrder = false }: { strapi: Core.Strapi; inRunOrder?: boolean }\n): Promise<Map<TAction['id'], TResult>> => {\n const check = createDraftPublishabilityCheck({ strapi });\n const results = new Map<TAction['id'], TResult>();\n const releasedInRun = new Map<string, boolean>();\n\n for (const action of actions) {\n if (action.type === 'publish') {\n results.set(\n action.id,\n await toResult(() => check(action, inRunOrder ? releasedInRun : undefined))\n );\n }\n if (inRunOrder) {\n releasedInRun.set(\n getEntryKey(action.contentType, action.entryDocumentId, action.locale),\n action.type === 'publish'\n );\n }\n }\n\n return results;\n};\n\n/**\n * Why review-workflows refused to publish an entry: its stage and the one its workflow requires,\n * read as the check reads them. Null if they can't be read, or no stage is required anymore; in a\n * transaction, a run conflict is rethrown.\n */\nexport const getStageReason = async (\n draft: DraftRef,\n { strapi }: { strapi: Core.Strapi }\n): Promise<ReleaseActionReason | null> => {\n const reason = await readCheck(\n async () => {\n const workflow = await getAssignedWorkflow(draft.contentType, { strapi });\n const requiredStage = workflow?.stageRequiredToPublish ?? null;\n if (!requiredStage) {\n return null;\n }\n\n const entry: DraftEntry | null = await getEntry(\n {\n contentType: draft.contentType,\n documentId: draft.entryDocumentId,\n locale: draft.locale,\n populate: ['strapi_stage'],\n },\n { strapi }\n );\n\n return { stage: toStageReason(entry?.strapi_stage ?? null, requiredStage) };\n },\n { strapi }\n );\n\n return reason instanceof Error ? null : reason;\n};\n\n/**\n * Publishability of each of a run's publish actions from its current draft, by action id, or the\n * error that stopped the check (a draft that can't be read): the run decides what that entry\n * means. The actions come in run order: under `api.documents.strictRelations`, a required\n * relation's target counts as published if it has a published version or an earlier action of the\n * run publishes it (and not if an earlier action unpublishes it).\n */\nexport const getPublishabilityForActions = <TAction extends PublishActionRef>(\n actions: readonly TAction[],\n { strapi }: { strapi: Core.Strapi }\n) =>\n checkPublishActions(actions, (read) => readCheck(read, { strapi }), {\n strapi,\n inRunOrder: true,\n });\n\n/**\n * The validity to store on each publish action, by action id. A draft that can't be read is\n * stored as not publishable and doesn't stop the others, except in a transaction a run conflict\n * (see `isRunConflict`), which is rethrown.\n */\nexport const getValidityForActions = <TAction extends PublishActionRef>(\n actions: readonly TAction[],\n { strapi }: { strapi: Core.Strapi }\n) =>\n checkPublishActions(\n actions,\n async (readPublishability) => toEntryValidity(await readCheck(readPublishability, { strapi })),\n { strapi }\n );\n\n// What an action stores when it's added or changes type\nexport const getActionValidity = async (\n action: DraftRef & Pick<ReleaseAction, 'type'>,\n { strapi }: { strapi: Core.Strapi }\n): Promise<EntryValidity> =>\n action.type === 'publish'\n ? toEntryValidity(\n await readCheck(() => createDraftPublishabilityCheck({ strapi })(action), { strapi })\n )\n : UNPUBLISH_VALIDITY;\n"],"names":["UNPUBLISH_VALIDITY","isEntryValid","reason","getEntryKey","contentType","documentId","locale","JSON","stringify","STAGE_ERROR_MESSAGE","isStageError","error","errors","ValidationError","message","toStageReason","entryStage","requiredStage","id","name","SUBMITTED_VALUE_SUFFIX","getValidationErrors","details","detailErrors","Array","isArray","map","detail","isObject","path","undefined","String","replace","toError","caught","Error","cause","getErrorName","getErrorCode","code","CONFLICT_CODES","Set","isRunConflict","has","toValidationReason","validation","toErrorReason","ApplicationError","toEntryValidity","check","publishable","readCheck","read","strapi","inTransaction","db","savepoint","getAssignedWorkflow","contentTypeUid","workflowsService","plugin","service","populate","computeEntryPublishability","entry","workflow","strictRelations","outcome","publishedVersion","documents","findOne","status","fields","validationError","entityValidator","validateEntityCreation","getModel","isDraft","stageRequiredToPublish","strapi_stage","isAtRequiredStage","stage","getDroppableTarget","attribute","type","required","contentTypes","hasDraftAndPublish","target","keepPublishedTargets","targetUid","value","isTargetPublished","kept","push","keepInComponent","componentUid","filter","keepPublishedRequiredTargets","keepInAttribute","Promise","all","component","__component","modelUid","data","attributes","result","Object","entries","createPublishedVersionLookup","hasPublishedVersionByEntry","Map","key","hasPublished","get","then","published","resolve","set","createDraftPublishabilityCheck","populateBuilderService","config","lookupsByContentType","publishabilityByDraft","hasPublishedVersion","readDraft","draft","releasedInRun","lookups","populateDeep","Infinity","build","getEntry","entryDocumentId","checkedEntry","publishability","checkPublishActions","actions","toResult","inRunOrder","results","action","getStageReason","getPublishabilityForActions","getValidityForActions","readPublishability","getActionValidity"],"mappings":";;;;;MAiBaA,kBAAAA,GAAoC;IAAEC,YAAAA,EAAc,IAAA;IAAMC,MAAAA,EAAQ;AAAK;AA6BpF;AACO,MAAMC,cAAc,CACzBC,WAAAA,EACAC,YACAC,MAAAA,GACGC,IAAAA,CAAKC,SAAS,CAAC;AAACJ,QAAAA,WAAAA;AAAaC,QAAAA,UAAAA;QAAYC,MAAAA,IAAU;KAAK;AAE7D;AACA,MAAMG,mBAAAA,GAAsB,+CAAA;AAE5B;AACO,MAAMC,YAAAA,GAAe,CAACC,KAAAA,GAC3BA,KAAAA,YAAiBC,YAAAA,CAAOC,eAAe,IAAIF,KAAAA,CAAMG,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CAAciD,KAAAA,EAAOe,YAAAA,IAAgB,IAAA,EAAM9D,aAAAA;AAAe,SAAA;IAC5E,CAAA,EACA;AAAEoC,QAAAA;AAAO,KAAA,CAAA;IAGX,OAAOnD,MAAAA,YAAkBiC,QAAQ,IAAA,GAAOjC,MAAAA;AAC1C;AAEA;;;;;;AAMC,IACM,MAAM8I,2BAAAA,GAA8B,CACzCN,SACA,EAAErF,MAAM,EAA2B,GAEnCoF,mBAAAA,CAAoBC,OAAAA,EAAS,CAACtF,IAAAA,GAASD,UAAUC,IAAAA,EAAM;AAAEC,YAAAA;SAAO,CAAA,EAAI;AAClEA,QAAAA,MAAAA;QACAuF,UAAAA,EAAY;KACd;AAEF;;;;AAIC,IACM,MAAMK,qBAAAA,GAAwB,CACnCP,OAAAA,EACA,EAAErF,MAAM,EAA2B,GAEnCoF,mBAAAA,CACEC,SACA,OAAOQ,kBAAAA,GAAuBlG,eAAAA,CAAgB,MAAMG,UAAU+F,kBAAAA,EAAoB;AAAE7F,YAAAA;SAAO,CAAA,CAAA,EAC3F;AAAEA,QAAAA;KAAO;AAGb;MACa8F,iBAAAA,GAAoB,OAC/BL,MAAAA,EACA,EAAEzF,MAAM,EAA2B,GAEnCyF,MAAAA,CAAO1D,IAAI,KAAK,SAAA,GACZpC,eAAAA,CACE,MAAMG,SAAAA,CAAU,IAAMqE,8BAAAA,CAA+B;AAAEnE,YAAAA;AAAO,SAAA,CAAA,CAAGyF,MAAAA,CAAAA,EAAS;AAAEzF,QAAAA;AAAO,KAAA,CAAA,CAAA,GAErFrD;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"publishability.js","sources":["../../../server/src/utils/publishability.ts"],"sourcesContent":["import { contentTypes, errors } from '@strapi/utils';\n\nimport type { UID, Core, Modules, Schema } from '@strapi/types';\nimport type {\n ReleaseAction,\n ReleaseActionOutcome,\n ReleaseActionReason,\n StageRef,\n} from '../../../shared/contracts/release-actions';\nimport { getEntry } from './entries';\nimport type { EntryPopulate } from './entries';\n\nexport interface EntryValidity {\n isEntryValid: boolean;\n reason: ReleaseActionReason | null;\n}\n\nexport const UNPUBLISH_VALIDITY: EntryValidity = { isEntryValid: true, reason: null };\n\ntype WorkflowWithRequiredStage = { stageRequiredToPublish?: StageRef | null } | null | undefined;\n\ntype DraftEntry = Modules.Documents.AnyDocument & { strapi_stage?: StageRef | null };\n\nexport type PublishabilityOutcome = Extract<\n ReleaseActionOutcome,\n 'skipped_invalid' | 'skipped_not_approved'\n>;\n\nexport type EntryPublishability =\n | { publishable: true; outcome: null; reason: null; error: null }\n | {\n publishable: false;\n outcome: PublishabilityOutcome;\n reason: ReleaseActionReason;\n /** What publishing the entry would throw; a rejected release reports its message */\n error: Error;\n };\n\n// The draft a publish action points at\nexport type DraftRef = Pick<ReleaseAction, 'contentType'> & {\n entryDocumentId?: ReleaseAction['entryDocumentId'];\n locale?: ReleaseAction['locale'];\n};\n\ntype PublishActionRef = DraftRef & Pick<ReleaseAction, 'id' | 'type'>;\n\n// Identifies an entry in one locale (or the only one, for a content type that isn't localized)\nexport const getEntryKey = (\n contentType: string,\n documentId: string | undefined,\n locale?: string | null\n) => JSON.stringify([contentType, documentId, locale ?? null]);\n\n// Thrown by review-workflows when an entry that isn't at the required stage is published\nconst STAGE_ERROR_MESSAGE = 'Entry is not at the required stage to publish';\n\n// A publish review-workflows refused because the entry isn't at the required stage\nexport const isStageError = (error: unknown) =>\n error instanceof errors.ValidationError && error.message === STAGE_ERROR_MESSAGE;\n\nconst toStageReason = (\n entryStage: StageRef | null,\n requiredStage: StageRef\n): NonNullable<ReleaseActionReason['stage']> => ({\n entryStage: entryStage && { id: entryStage.id, name: entryStage.name },\n requiredStage: { id: requiredStage.id, name: requiredStage.name },\n});\n\n// Strapi's type-mismatch message ends with the submitted value (`notType` in `@strapi/utils`'s\n// yup.ts): cut off, the rest still names the field and the expected type\nconst SUBMITTED_VALUE_SUFFIX = /, but the final value was: [\\s\\S]*$/;\n\n// Only the field paths and messages: the details also carry the submitted values\nconst getValidationErrors = (error: Error) => {\n const details: unknown = error instanceof errors.ValidationError ? error.details : null;\n const detailErrors: unknown[] =\n typeof details === 'object' &&\n details !== null &&\n 'errors' in details &&\n Array.isArray(details.errors)\n ? details.errors\n : [];\n\n return detailErrors.map((detail) => {\n const isObject = typeof detail === 'object' && detail !== null;\n const path = isObject && 'path' in detail ? detail.path : undefined;\n const message = isObject && 'message' in detail ? detail.message : undefined;\n\n return {\n path: Array.isArray(path) ? path.map(String) : [],\n message: typeof message === 'string' ? message.replace(SUBMITTED_VALUE_SUFFIX, '') : '',\n };\n });\n};\n\n// Something thrown that isn't an Error, kept as its cause\nexport const toError = (caught: unknown) =>\n caught instanceof Error ? caught : new Error('Non-Error thrown', { cause: caught });\n\n// Only the error's name: its message can carry row contents\nexport const getErrorName = (error: unknown) => (error instanceof Error ? error.name : 'Error');\n\n// A database driver's error code (e.g. node-postgres `23505`, mysql2 `ER_DUP_ENTRY`): it names the\n// failure without any row contents\nconst getErrorCode = (error: unknown) =>\n typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string'\n ? error.code\n : undefined;\n\n// A transient conflict with another transaction: a MySQL deadlock or lock wait timeout, a Postgres\n// deadlock or serialization failure. InnoDB rolls back the whole transaction on a deadlock (on a\n// lock wait timeout, only with `innodb_rollback_on_timeout`; else just the statement).\nconst CONFLICT_CODES = new Set(['ER_LOCK_DEADLOCK', 'ER_LOCK_WAIT_TIMEOUT', '40P01', '40001']);\n\n/**\n * Whether an error in a transaction isn't the entry's own failure but the transaction's: a\n * conflict with another transaction, or a savepoint the database couldn't release or roll back to\n * (`SavepointError` from `@strapi/database`, matched by name: the transaction is lost or broken).\n * Nothing done in the transaction can then be recorded as the entry's outcome, so the caller's\n * transaction must fail with it, leaving the release planned for another run.\n */\nexport const isRunConflict = (error: unknown) =>\n (error instanceof Error && error.name === 'SavepointError') ||\n CONFLICT_CODES.has(getErrorCode(error) ?? '');\n\n// The reason shapes an entry that wasn't released stores\nexport const toValidationReason = (error: Error) => ({\n validation: { errors: getValidationErrors(error) },\n});\n\n// Only the error's name, and its driver code: its message can carry row contents. An application\n// error's message is meant for the client (a manual publish sends it as is), so it's kept, without\n// the submitted value a type-mismatch message ends with.\nexport const toErrorReason = (error: unknown): ReleaseActionReason => {\n const code = getErrorCode(error);\n\n return {\n error: {\n name: getErrorName(error),\n ...(error instanceof errors.ApplicationError && {\n message: error.message.replace(SUBMITTED_VALUE_SUFFIX, ''),\n }),\n ...(code && { code }),\n },\n };\n};\n\n// The validity stored for a checked entry. One whose check threw (e.g. its draft can't be read)\n// isn't publishable, with only the error's name (and an application error's message).\nexport const toEntryValidity = (check: EntryPublishability | Error): EntryValidity => {\n if (check instanceof Error) {\n return { isEntryValid: false, reason: toErrorReason(check) };\n }\n\n return check.publishable\n ? { isEntryValid: true, reason: null }\n : { isEntryValid: false, reason: check.reason };\n};\n\n// A check's result, or the error that stopped it. In a transaction, each check reads in its own\n// savepoint: without one, on Postgres a failed read would abort the transaction, and every other\n// check with it.\nconst readCheck = async <TResult>(\n read: () => Promise<TResult>,\n { strapi }: { strapi: Core.Strapi }\n): Promise<TResult | Error> => {\n const inTransaction = strapi.db.inTransaction();\n\n try {\n return await (inTransaction ? strapi.db.savepoint(read) : read());\n } catch (error) {\n // In a transaction, the transaction fails with a conflict: no other check, nor what the caller\n // records, can be kept. Outside one, it only undid this read, so it's a failed check.\n if (inTransaction && isRunConflict(error)) {\n throw error;\n }\n return toError(error);\n }\n};\n\nconst getAssignedWorkflow = async (\n contentTypeUid: UID.ContentType,\n { strapi }: { strapi: Core.Strapi }\n): Promise<WorkflowWithRequiredStage> => {\n // Workflows service may not be available depending on the license\n const workflowsService = strapi.plugin('review-workflows')?.service('workflows');\n\n return workflowsService?.getAssignedWorkflow(contentTypeUid, {\n populate: 'stageRequiredToPublish',\n });\n};\n\n// Whether an entry can be published now: its draft passes publish validation and, if its\n// workflow requires a stage to publish, it is at that stage\nconst computeEntryPublishability = async (\n contentTypeUid: UID.ContentType,\n entry: (DraftEntry & { locale?: string | null }) | null,\n { workflow, strictRelations }: { workflow: WorkflowWithRequiredStage; strictRelations: boolean },\n { strapi }: { strapi: Core.Strapi }\n): Promise<EntryPublishability> => {\n if (!entry) {\n return {\n publishable: false,\n outcome: 'skipped_invalid',\n reason: { validation: { errors: [] } },\n error: new errors.ValidationError('Entry not found'),\n };\n }\n\n // Publishing deletes the published version before validating the draft, so the validator\n // leaves that version out of unique checks\n const publishedVersion = await strapi.documents(contentTypeUid).findOne({\n documentId: entry.documentId,\n locale: entry.locale ?? undefined,\n status: 'published',\n fields: ['documentId'],\n });\n\n let validationError: Error | null = null;\n try {\n // @TODO: When documents service has validateEntityCreation method, use it instead\n await strapi.entityValidator.validateEntityCreation(\n strapi.getModel(contentTypeUid),\n entry,\n { isDraft: false, locale: entry.locale, strictRelations },\n // @ts-expect-error - the validator takes the entry to leave out of unique checks, but its type doesn't declare it for creation\n publishedVersion\n );\n } catch (error) {\n // Anything else isn't the entry's fault: the caller decides what an unchecked entry means\n if (!(error instanceof errors.ValidationError)) {\n throw error;\n }\n validationError = error;\n }\n\n // Checked even when validation failed, so the reason can carry both\n const requiredStage = workflow?.stageRequiredToPublish ?? null;\n const entryStage = entry.strapi_stage ?? null;\n const isAtRequiredStage = requiredStage === null || entryStage?.id === requiredStage.id;\n\n if (isAtRequiredStage) {\n return validationError === null\n ? { publishable: true, outcome: null, reason: null, error: null }\n : {\n publishable: false,\n outcome: 'skipped_invalid',\n reason: toValidationReason(validationError),\n error: validationError,\n };\n }\n\n return {\n publishable: false,\n outcome: validationError ? 'skipped_invalid' : 'skipped_not_approved',\n reason: {\n ...(validationError && toValidationReason(validationError)),\n stage: toStageReason(entryStage, requiredStage),\n },\n // Same precedence as a publish: review-workflows rejects the stage before validation\n error: new errors.ValidationError(STAGE_ERROR_MESSAGE),\n };\n};\n\n// What the run's earlier actions leave each entry with, by entry key: published (a publish) or not\n// (an unpublish)\ntype ReleasedInRun = ReadonlyMap<string, boolean>;\n\ntype RelationTarget = { documentId?: string; locale?: string | null };\n\ninterface TargetFilter {\n isTargetPublished: (\n targetUid: UID.ContentType,\n target: RelationTarget\n ) => boolean | Promise<boolean>;\n strapi: Core.Strapi;\n}\n\n// The target of a required relation publish can drop: one with draft and publish (any other\n// target is always published), on a relation the validation reads\nconst getDroppableTarget = (\n attribute: Schema.Attribute.AnyAttribute,\n { strapi }: Pick<TargetFilter, 'strapi'>\n): UID.ContentType | undefined =>\n attribute.type === 'relation' &&\n attribute.required &&\n 'target' in attribute &&\n contentTypes.hasDraftAndPublish(strapi.getModel(attribute.target))\n ? attribute.target\n : undefined;\n\n// The targets of a relation publish connects: a to-one relation without one is empty\nconst keepPublishedTargets = async (\n targetUid: UID.ContentType,\n value: unknown,\n { isTargetPublished }: TargetFilter\n) => {\n if (!Array.isArray(value)) {\n return (await isTargetPublished(targetUid, value as RelationTarget)) ? value : null;\n }\n\n const kept = [];\n for (const target of value) {\n if (await isTargetPublished(targetUid, target)) {\n kept.push(target);\n }\n }\n return kept;\n};\n\nconst keepInComponent = (componentUid: UID.Component, value: unknown, filter: TargetFilter) =>\n typeof value === 'object' && value !== null\n ? keepPublishedRequiredTargets(componentUid, value as Record<string, unknown>, filter)\n : value;\n\n// An attribute's value as publish validates it: its droppable targets filtered, its components\n// and dynamic zone items walked\nconst keepInAttribute = async (\n attribute: Schema.Attribute.AnyAttribute,\n value: unknown,\n filter: TargetFilter\n): Promise<unknown> => {\n const targetUid = getDroppableTarget(attribute, filter);\n if (targetUid) {\n return keepPublishedTargets(targetUid, value, filter);\n }\n\n if (attribute.type === 'component') {\n return Array.isArray(value)\n ? Promise.all(\n value.map((component) => keepInComponent(attribute.component, component, filter))\n )\n : keepInComponent(attribute.component, value, filter);\n }\n\n if (attribute.type === 'dynamiczone' && Array.isArray(value)) {\n return Promise.all(\n value.map((component: { __component?: UID.Component }) =>\n component.__component\n ? keepInComponent(component.__component, component, filter)\n : component\n )\n );\n }\n\n return value;\n};\n\n/**\n * The draft as the document service's publish validates it under `api.documents.strictRelations`:\n * publish connects each relation to its target's published version and drops the targets without\n * one (`allowMissingId` in its data transform), then enforces required relations. Only required\n * relations to draft and publish targets are filtered: the others are never dropped, or never\n * validated. Components and dynamic zones are walked, as publish does.\n */\nconst keepPublishedRequiredTargets = async (\n modelUid: UID.Schema,\n data: Record<string, unknown>,\n filter: TargetFilter\n): Promise<Record<string, unknown>> => {\n const attributes: Record<string, Schema.Attribute.AnyAttribute> =\n filter.strapi.getModel(modelUid)?.attributes ?? {};\n const result = { ...data };\n\n for (const [name, attribute] of Object.entries(attributes)) {\n const value = data[name];\n if (value !== null && value !== undefined) {\n result[name] = await keepInAttribute(attribute, value, filter);\n }\n }\n\n return result;\n};\n\n// Whether an entry has a published version, read once per entry. A target without a document id\n// can't be connected.\nconst createPublishedVersionLookup = ({ strapi }: { strapi: Core.Strapi }) => {\n const hasPublishedVersionByEntry = new Map<string, Promise<boolean>>();\n\n return (targetUid: UID.ContentType, { documentId, locale }: RelationTarget) => {\n const key = getEntryKey(targetUid, documentId, locale);\n let hasPublished = hasPublishedVersionByEntry.get(key);\n if (!hasPublished) {\n hasPublished = documentId\n ? strapi\n .documents(targetUid)\n .findOne({\n documentId,\n locale: locale ?? undefined,\n status: 'published',\n fields: ['documentId'],\n })\n .then((published) => published !== null)\n : Promise.resolve(false);\n hasPublishedVersionByEntry.set(key, hasPublished);\n }\n\n return hasPublished;\n };\n};\n\n// Checks drafts, looking up the populate and the workflow once per content type and reading\n// each draft once (an entry in several planned releases has one action in each)\nconst createDraftPublishabilityCheck = ({ strapi }: { strapi: Core.Strapi }) => {\n const populateBuilderService = strapi.plugin('content-manager').service('populate-builder');\n // Same strict relations rule as the document service's publish\n const strictRelations = strapi.config.get('api.documents.strictRelations', undefined) === true;\n const lookupsByContentType = new Map<\n UID.ContentType,\n { populate: EntryPopulate; workflow: WorkflowWithRequiredStage }\n >();\n const publishabilityByDraft = new Map<string, Promise<EntryPublishability>>();\n const hasPublishedVersion = createPublishedVersionLookup({ strapi });\n\n const readDraft = async (\n draft: DraftRef,\n releasedInRun: ReleasedInRun | undefined\n ): Promise<EntryPublishability> => {\n let lookups = lookupsByContentType.get(draft.contentType);\n if (!lookups) {\n lookups = {\n // @ts-expect-error - populateBuilderService should be a function but is returning service\n populate: await populateBuilderService(draft.contentType).populateDeep(Infinity).build(),\n workflow: await getAssignedWorkflow(draft.contentType, { strapi }),\n };\n lookupsByContentType.set(draft.contentType, lookups);\n }\n\n const entry = await getEntry(\n {\n contentType: draft.contentType,\n documentId: draft.entryDocumentId,\n locale: draft.locale,\n populate: lookups.populate,\n },\n { strapi }\n );\n\n // A planned release's validity checks the draft as is: which targets the run releases first\n // is only known in the run\n const checkedEntry =\n entry && strictRelations && releasedInRun\n ? ((await keepPublishedRequiredTargets(draft.contentType, entry, {\n isTargetPublished: (targetUid, target) =>\n releasedInRun.get(getEntryKey(targetUid, target.documentId, target.locale)) ??\n hasPublishedVersion(targetUid, target),\n strapi,\n })) as DraftEntry)\n : entry;\n\n return computeEntryPublishability(\n draft.contentType,\n checkedEntry,\n { workflow: lookups.workflow, strictRelations },\n { strapi }\n );\n };\n\n return (draft: DraftRef, releasedInRun?: ReleasedInRun): Promise<EntryPublishability> => {\n const key = getEntryKey(draft.contentType, draft.entryDocumentId, draft.locale);\n let publishability = publishabilityByDraft.get(key);\n if (!publishability) {\n publishability = readDraft(draft, releasedInRun);\n publishabilityByDraft.set(key, publishability);\n }\n\n return publishability;\n };\n};\n\n// With `inRunOrder`, the actions are a run's, in the order it releases them: each check sees what\n// the actions before it release\nconst checkPublishActions = async <TAction extends PublishActionRef, TResult>(\n actions: readonly TAction[],\n toResult: (readPublishability: () => Promise<EntryPublishability>) => Promise<TResult>,\n { strapi, inRunOrder = false }: { strapi: Core.Strapi; inRunOrder?: boolean }\n): Promise<Map<TAction['id'], TResult>> => {\n const check = createDraftPublishabilityCheck({ strapi });\n const results = new Map<TAction['id'], TResult>();\n const releasedInRun = new Map<string, boolean>();\n\n for (const action of actions) {\n if (action.type === 'publish') {\n results.set(\n action.id,\n await toResult(() => check(action, inRunOrder ? releasedInRun : undefined))\n );\n }\n if (inRunOrder) {\n releasedInRun.set(\n getEntryKey(action.contentType, action.entryDocumentId, action.locale),\n action.type === 'publish'\n );\n }\n }\n\n return results;\n};\n\n/**\n * Why review-workflows refused to publish an entry: its stage and the one its workflow requires,\n * read as the check reads them. Null if they can't be read, or no stage is required anymore; in a\n * transaction, a run conflict is rethrown.\n */\nexport const getStageReason = async (\n draft: DraftRef,\n { strapi }: { strapi: Core.Strapi }\n): Promise<ReleaseActionReason | null> => {\n const reason = await readCheck(\n async () => {\n const workflow = await getAssignedWorkflow(draft.contentType, { strapi });\n const requiredStage = workflow?.stageRequiredToPublish ?? null;\n if (!requiredStage) {\n return null;\n }\n\n const entry: DraftEntry | null = await getEntry(\n {\n contentType: draft.contentType,\n documentId: draft.entryDocumentId,\n locale: draft.locale,\n populate: ['strapi_stage'],\n },\n { strapi }\n );\n\n return { stage: toStageReason(entry?.strapi_stage ?? null, requiredStage) };\n },\n { strapi }\n );\n\n return reason instanceof Error ? null : reason;\n};\n\n/**\n * Publishability of each of a run's publish actions from its current draft, by action id, or the\n * error that stopped the check (a draft that can't be read): the run decides what that entry\n * means. The actions come in run order: under `api.documents.strictRelations`, a required\n * relation's target counts as published if it has a published version or an earlier action of the\n * run publishes it (and not if an earlier action unpublishes it).\n */\nexport const getPublishabilityForActions = <TAction extends PublishActionRef>(\n actions: readonly TAction[],\n { strapi }: { strapi: Core.Strapi }\n) =>\n checkPublishActions(actions, (read) => readCheck(read, { strapi }), {\n strapi,\n inRunOrder: true,\n });\n\n/**\n * The validity to store on each publish action, by action id. A draft that can't be read is\n * stored as not publishable and doesn't stop the others, except in a transaction a run conflict\n * (see `isRunConflict`), which is rethrown.\n */\nexport const getValidityForActions = <TAction extends PublishActionRef>(\n actions: readonly TAction[],\n { strapi }: { strapi: Core.Strapi }\n) =>\n checkPublishActions(\n actions,\n async (readPublishability) => toEntryValidity(await readCheck(readPublishability, { strapi })),\n { strapi }\n );\n\n// What an action stores when it's added or changes type\nexport const getActionValidity = async (\n action: DraftRef & Pick<ReleaseAction, 'type'>,\n { strapi }: { strapi: Core.Strapi }\n): Promise<EntryValidity> =>\n action.type === 'publish'\n ? toEntryValidity(\n await readCheck(() => createDraftPublishabilityCheck({ strapi })(action), { strapi })\n )\n : UNPUBLISH_VALIDITY;\n"],"names":["UNPUBLISH_VALIDITY","isEntryValid","reason","getEntryKey","contentType","documentId","locale","JSON","stringify","STAGE_ERROR_MESSAGE","isStageError","error","errors","ValidationError","message","toStageReason","entryStage","requiredStage","id","name","SUBMITTED_VALUE_SUFFIX","getValidationErrors","details","detailErrors","Array","isArray","map","detail","isObject","path","undefined","String","replace","toError","caught","Error","cause","getErrorName","getErrorCode","code","CONFLICT_CODES","Set","isRunConflict","has","toValidationReason","validation","toErrorReason","ApplicationError","toEntryValidity","check","publishable","readCheck","read","strapi","inTransaction","db","savepoint","getAssignedWorkflow","contentTypeUid","workflowsService","plugin","service","populate","computeEntryPublishability","entry","workflow","strictRelations","outcome","publishedVersion","documents","findOne","status","fields","validationError","entityValidator","validateEntityCreation","getModel","isDraft","stageRequiredToPublish","strapi_stage","isAtRequiredStage","stage","getDroppableTarget","attribute","type","required","contentTypes","hasDraftAndPublish","target","keepPublishedTargets","targetUid","value","isTargetPublished","kept","push","keepInComponent","componentUid","filter","keepPublishedRequiredTargets","keepInAttribute","Promise","all","component","__component","modelUid","data","attributes","result","Object","entries","createPublishedVersionLookup","hasPublishedVersionByEntry","Map","key","hasPublished","get","then","published","resolve","set","createDraftPublishabilityCheck","populateBuilderService","config","lookupsByContentType","publishabilityByDraft","hasPublishedVersion","readDraft","draft","releasedInRun","lookups","populateDeep","Infinity","build","getEntry","entryDocumentId","checkedEntry","publishability","checkPublishActions","actions","toResult","inRunOrder","results","action","getStageReason","getPublishabilityForActions","getValidityForActions","readPublishability","getActionValidity"],"mappings":";;;;;MAiBaA,kBAAAA,GAAoC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AA+B;AAAEnE,YAAAA;AAAO,SAAA,CAAA,CAAGyF,MAAAA,CAAAA,EAAS;AAAEzF,QAAAA;AAAO,KAAA,CAAA,CAAA,GAErFrD;;;;;;;;;;;;;;;;"}
@@ -149,7 +149,7 @@ const computeEntryPublishability = async (contentTypeUid, entry, { workflow, str
149
149
  // leaves that version out of unique checks
150
150
  const publishedVersion = await strapi.documents(contentTypeUid).findOne({
151
151
  documentId: entry.documentId,
152
- locale: entry.locale,
152
+ locale: entry.locale ?? undefined,
153
153
  status: 'published',
154
154
  fields: [
155
155
  'documentId'