@strapi/content-manager 5.44.0 → 5.45.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.
Files changed (66) hide show
  1. package/dist/admin/index.js.map +1 -1
  2. package/dist/admin/index.mjs.map +1 -1
  3. package/dist/admin/pages/EditView/utils/data.js +8 -0
  4. package/dist/admin/pages/EditView/utils/data.js.map +1 -1
  5. package/dist/admin/pages/EditView/utils/data.mjs +8 -0
  6. package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
  7. package/dist/admin/pages/ListView/ListViewPage.js +17 -2
  8. package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
  9. package/dist/admin/pages/ListView/ListViewPage.mjs +17 -2
  10. package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
  11. package/dist/admin/src/index.d.ts +2 -1
  12. package/dist/server/controllers/collection-types.js +78 -1
  13. package/dist/server/controllers/collection-types.js.map +1 -1
  14. package/dist/server/controllers/collection-types.mjs +78 -1
  15. package/dist/server/controllers/collection-types.mjs.map +1 -1
  16. package/dist/server/controllers/validation/dimensions.js +17 -18
  17. package/dist/server/controllers/validation/dimensions.js.map +1 -1
  18. package/dist/server/controllers/validation/dimensions.mjs +18 -19
  19. package/dist/server/controllers/validation/dimensions.mjs.map +1 -1
  20. package/dist/server/controllers/validation/index.js +25 -23
  21. package/dist/server/controllers/validation/index.js.map +1 -1
  22. package/dist/server/controllers/validation/index.mjs +26 -24
  23. package/dist/server/controllers/validation/index.mjs.map +1 -1
  24. package/dist/server/controllers/validation/relations.js +21 -24
  25. package/dist/server/controllers/validation/relations.js.map +1 -1
  26. package/dist/server/controllers/validation/relations.mjs +22 -25
  27. package/dist/server/controllers/validation/relations.mjs.map +1 -1
  28. package/dist/server/history/controllers/validation/history-version.js +4 -24
  29. package/dist/server/history/controllers/validation/history-version.js.map +1 -1
  30. package/dist/server/history/controllers/validation/history-version.mjs +5 -6
  31. package/dist/server/history/controllers/validation/history-version.mjs.map +1 -1
  32. package/dist/server/history/services/lifecycles.js +1 -1
  33. package/dist/server/history/services/lifecycles.js.map +1 -1
  34. package/dist/server/history/services/lifecycles.mjs +1 -1
  35. package/dist/server/history/services/lifecycles.mjs.map +1 -1
  36. package/dist/server/homepage/controllers/homepage.js +6 -26
  37. package/dist/server/homepage/controllers/homepage.js.map +1 -1
  38. package/dist/server/homepage/controllers/homepage.mjs +7 -8
  39. package/dist/server/homepage/controllers/homepage.mjs.map +1 -1
  40. package/dist/server/preview/controllers/validation/preview.js +6 -26
  41. package/dist/server/preview/controllers/validation/preview.js.map +1 -1
  42. package/dist/server/preview/controllers/validation/preview.mjs +7 -8
  43. package/dist/server/preview/controllers/validation/preview.mjs.map +1 -1
  44. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  45. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  46. package/dist/server/src/controllers/validation/index.d.ts +16 -15
  47. package/dist/server/src/controllers/validation/index.d.ts.map +1 -1
  48. package/dist/server/src/controllers/validation/relations.d.ts +17 -2
  49. package/dist/server/src/controllers/validation/relations.d.ts.map +1 -1
  50. package/dist/server/src/history/controllers/validation/history-version.d.ts +3 -1
  51. package/dist/server/src/history/controllers/validation/history-version.d.ts.map +1 -1
  52. package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -1
  53. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -1
  54. package/dist/server/src/validation/policies/hasPermissions.d.ts +4 -1
  55. package/dist/server/src/validation/policies/hasPermissions.d.ts.map +1 -1
  56. package/dist/server/src/validation/zod.d.ts +34 -0
  57. package/dist/server/src/validation/zod.d.ts.map +1 -0
  58. package/dist/server/validation/policies/hasPermissions.js +4 -4
  59. package/dist/server/validation/policies/hasPermissions.js.map +1 -1
  60. package/dist/server/validation/policies/hasPermissions.mjs +5 -5
  61. package/dist/server/validation/policies/hasPermissions.mjs.map +1 -1
  62. package/dist/server/validation/zod.js +60 -0
  63. package/dist/server/validation/zod.js.map +1 -0
  64. package/dist/server/validation/zod.mjs +56 -0
  65. package/dist/server/validation/zod.mjs.map +1 -0
  66. package/package.json +5 -5
@@ -1,22 +1,21 @@
1
- import * as yup from 'yup';
2
- import { errors } from '@strapi/utils';
1
+ import { z, errors } from '@strapi/utils';
3
2
 
4
3
  const createHomepageController = ()=>{
5
4
  const homepageService = strapi.plugin('content-manager').service('homepage');
6
- const recentDocumentParamsSchema = yup.object().shape({
7
- action: yup.mixed().oneOf([
5
+ const recentDocumentParamsSchema = z.object({
6
+ action: z.enum([
8
7
  'update',
9
8
  'publish'
10
- ]).required()
9
+ ])
11
10
  });
12
11
  return {
13
12
  async getRecentDocuments (ctx) {
14
13
  let action;
15
14
  try {
16
- action = (await recentDocumentParamsSchema.validate(ctx.query)).action;
15
+ action = recentDocumentParamsSchema.parse(ctx.query).action;
17
16
  } catch (error) {
18
- if (error instanceof yup.ValidationError) {
19
- throw new errors.ValidationError(error.message);
17
+ if (error instanceof z.ZodError) {
18
+ throw new errors.ValidationError(error.issues[0]?.message ?? 'Validation error');
20
19
  }
21
20
  throw error;
22
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/controllers/homepage.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport * as yup from 'yup';\nimport { errors } from '@strapi/utils';\nimport type { GetRecentDocuments, GetCountDocuments } from '../../../../shared/contracts/homepage';\n\nconst createHomepageController = () => {\n const homepageService = strapi.plugin('content-manager').service('homepage');\n\n const recentDocumentParamsSchema = yup.object().shape({\n action: yup\n .mixed<GetRecentDocuments.Request['query']['action']>()\n .oneOf(['update', 'publish'])\n .required(),\n });\n\n return {\n async getRecentDocuments(ctx): Promise<GetRecentDocuments.Response> {\n let action;\n\n try {\n action = (await recentDocumentParamsSchema.validate(ctx.query)).action;\n } catch (error) {\n if (error instanceof yup.ValidationError) {\n throw new errors.ValidationError(error.message);\n }\n throw error;\n }\n\n if (action === 'publish') {\n return { data: await homepageService.getRecentlyPublishedDocuments() };\n }\n\n return { data: await homepageService.getRecentlyUpdatedDocuments() };\n },\n async getCountDocuments(): Promise<GetCountDocuments.Response> {\n return { data: await homepageService.getCountDocuments() };\n },\n } satisfies Core.Controller;\n};\n\nexport { createHomepageController };\n"],"names":["createHomepageController","homepageService","strapi","plugin","service","recentDocumentParamsSchema","yup","object","shape","action","mixed","oneOf","required","getRecentDocuments","ctx","validate","query","error","ValidationError","errors","message","data","getRecentlyPublishedDocuments","getRecentlyUpdatedDocuments","getCountDocuments"],"mappings":";;;AAKA,MAAMA,wBAAAA,GAA2B,IAAA;AAC/B,IAAA,MAAMC,kBAAkBC,MAAAA,CAAOC,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,UAAA,CAAA;AAEjE,IAAA,MAAMC,0BAAAA,GAA6BC,GAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AACpDC,QAAAA,MAAAA,EAAQH,GAAAA,CACLI,KAAK,EAAA,CACLC,KAAK,CAAC;AAAC,YAAA,QAAA;AAAU,YAAA;AAAU,SAAA,CAAA,CAC3BC,QAAQ;AACb,KAAA,CAAA;IAEA,OAAO;AACL,QAAA,MAAMC,oBAAmBC,GAAG,EAAA;YAC1B,IAAIL,MAAAA;YAEJ,IAAI;gBACFA,MAAAA,GAAU,CAAA,MAAMJ,0BAAAA,CAA2BU,QAAQ,CAACD,GAAAA,CAAIE,KAAK,CAAA,EAAGP,MAAM;AACxE,YAAA,CAAA,CAAE,OAAOQ,KAAAA,EAAO;gBACd,IAAIA,KAAAA,YAAiBX,GAAAA,CAAIY,eAAe,EAAE;AACxC,oBAAA,MAAM,IAAIC,MAAAA,CAAOD,eAAe,CAACD,MAAMG,OAAO,CAAA;AAChD,gBAAA;gBACA,MAAMH,KAAAA;AACR,YAAA;AAEA,YAAA,IAAIR,WAAW,SAAA,EAAW;gBACxB,OAAO;oBAAEY,IAAAA,EAAM,MAAMpB,gBAAgBqB,6BAA6B;AAAG,iBAAA;AACvE,YAAA;YAEA,OAAO;gBAAED,IAAAA,EAAM,MAAMpB,gBAAgBsB,2BAA2B;AAAG,aAAA;AACrE,QAAA,CAAA;QACA,MAAMC,iBAAAA,CAAAA,GAAAA;YACJ,OAAO;gBAAEH,IAAAA,EAAM,MAAMpB,gBAAgBuB,iBAAiB;AAAG,aAAA;AAC3D,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/controllers/homepage.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { z, errors } from '@strapi/utils';\nimport type { GetRecentDocuments, GetCountDocuments } from '../../../../shared/contracts/homepage';\n\nconst createHomepageController = () => {\n const homepageService = strapi.plugin('content-manager').service('homepage');\n\n const recentDocumentParamsSchema = z.object({\n action: z.enum(['update', 'publish']),\n });\n\n return {\n async getRecentDocuments(ctx): Promise<GetRecentDocuments.Response> {\n let action;\n\n try {\n action = recentDocumentParamsSchema.parse(ctx.query).action;\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new errors.ValidationError(error.issues[0]?.message ?? 'Validation error');\n }\n throw error;\n }\n\n if (action === 'publish') {\n return { data: await homepageService.getRecentlyPublishedDocuments() };\n }\n\n return { data: await homepageService.getRecentlyUpdatedDocuments() };\n },\n async getCountDocuments(): Promise<GetCountDocuments.Response> {\n return { data: await homepageService.getCountDocuments() };\n },\n } satisfies Core.Controller;\n};\n\nexport { createHomepageController };\n"],"names":["createHomepageController","homepageService","strapi","plugin","service","recentDocumentParamsSchema","z","object","action","enum","getRecentDocuments","ctx","parse","query","error","ZodError","errors","ValidationError","issues","message","data","getRecentlyPublishedDocuments","getRecentlyUpdatedDocuments","getCountDocuments"],"mappings":";;AAIA,MAAMA,wBAAAA,GAA2B,IAAA;AAC/B,IAAA,MAAMC,kBAAkBC,MAAAA,CAAOC,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,UAAA,CAAA;IAEjE,MAAMC,0BAAAA,GAA6BC,CAAAA,CAAEC,MAAM,CAAC;QAC1CC,MAAAA,EAAQF,CAAAA,CAAEG,IAAI,CAAC;AAAC,YAAA,QAAA;AAAU,YAAA;AAAU,SAAA;AACtC,KAAA,CAAA;IAEA,OAAO;AACL,QAAA,MAAMC,oBAAmBC,GAAG,EAAA;YAC1B,IAAIH,MAAAA;YAEJ,IAAI;AACFA,gBAAAA,MAAAA,GAASH,2BAA2BO,KAAK,CAACD,GAAAA,CAAIE,KAAK,EAAEL,MAAM;AAC7D,YAAA,CAAA,CAAE,OAAOM,KAAAA,EAAO;gBACd,IAAIA,KAAAA,YAAiBR,CAAAA,CAAES,QAAQ,EAAE;oBAC/B,MAAM,IAAIC,OAAOC,eAAe,CAACH,MAAMI,MAAM,CAAC,CAAA,CAAE,EAAEC,OAAAA,IAAW,kBAAA,CAAA;AAC/D,gBAAA;gBACA,MAAML,KAAAA;AACR,YAAA;AAEA,YAAA,IAAIN,WAAW,SAAA,EAAW;gBACxB,OAAO;oBAAEY,IAAAA,EAAM,MAAMnB,gBAAgBoB,6BAA6B;AAAG,iBAAA;AACvE,YAAA;YAEA,OAAO;gBAAED,IAAAA,EAAM,MAAMnB,gBAAgBqB,2BAA2B;AAAG,aAAA;AACrE,QAAA,CAAA;QACA,MAAMC,iBAAAA,CAAAA,GAAAA;YACJ,OAAO;gBAAEH,IAAAA,EAAM,MAAMnB,gBAAgBsB,iBAAiB;AAAG,aAAA;AAC3D,QAAA;AACF,KAAA;AACF;;;;"}
@@ -1,37 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var yup = require('yup');
4
3
  var fp = require('lodash/fp');
5
4
  var strapiUtils = require('@strapi/utils');
6
5
 
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
25
-
26
- const getPreviewUrlSchema = yup__namespace.object().shape({
6
+ const getPreviewUrlSchema = strapiUtils.z.object({
27
7
  // Will be undefined for single types
28
- documentId: yup__namespace.string(),
29
- locale: yup__namespace.string().nullable(),
30
- status: yup__namespace.string()
31
- }).required();
8
+ documentId: strapiUtils.z.string().optional(),
9
+ locale: strapiUtils.z.string().nullable().optional(),
10
+ status: strapiUtils.z.string().optional()
11
+ });
32
12
  const validatePreviewUrl = async (strapi, uid, params)=>{
33
13
  // Validate the request parameters format
34
- await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
14
+ strapiUtils.validateZodSchema(getPreviewUrlSchema)(params);
35
15
  const newParams = fp.pick([
36
16
  'documentId',
37
17
  'locale',
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","sources":["../../../../../server/src/preview/controllers/validation/preview.ts"],"sourcesContent":["import * as yup from 'yup';\nimport { pick } from 'lodash/fp';\n\nimport type { Core, UID } from '@strapi/types';\nimport { validateYupSchema, errors } from '@strapi/utils';\n\nimport { Preview } from '../../../../../shared/contracts';\nimport type { HandlerParams } from '../../services/preview-config';\n\nconst getPreviewUrlSchema = yup\n .object()\n .shape({\n // Will be undefined for single types\n documentId: yup.string(),\n locale: yup.string().nullable(),\n status: yup.string(),\n })\n .required();\n\nexport const validatePreviewUrl = async (\n strapi: Core.Strapi,\n uid: UID.ContentType,\n params: Preview.GetPreviewUrl.Request['query']\n): Promise<HandlerParams> => {\n // Validate the request parameters format\n await validateYupSchema(getPreviewUrlSchema)(params);\n\n const newParams = pick(['documentId', 'locale', 'status'], params) as HandlerParams;\n const model = strapi.getModel(uid);\n\n // If it's not a collection type or single type\n if (!model || model.modelType !== 'contentType') {\n throw new errors.ValidationError('Invalid content type');\n }\n\n // Document id is not required for single types\n const isSingleType = model?.kind === 'singleType';\n if (!isSingleType && !params.documentId) {\n throw new errors.ValidationError('documentId is required for Collection Types');\n }\n\n // Fill the documentId if it's a single type\n if (isSingleType) {\n const doc = await strapi.documents(uid).findFirst();\n\n if (!doc) {\n throw new errors.NotFoundError('Document not found');\n }\n\n newParams.documentId = doc?.documentId;\n }\n\n /**\n * If status is not specified, follow the following rules:\n * - D&P disabled: status is considered published\n * - D&P enabled: status is considered draft\n */\n if (!newParams.status) {\n const isDPEnabled = model?.options?.draftAndPublish;\n newParams.status = isDPEnabled ? 'draft' : 'published';\n }\n\n return newParams;\n};\n"],"names":["getPreviewUrlSchema","yup","object","shape","documentId","string","locale","nullable","status","required","validatePreviewUrl","strapi","uid","params","validateYupSchema","newParams","pick","model","getModel","modelType","errors","ValidationError","isSingleType","kind","doc","documents","findFirst","NotFoundError","isDPEnabled","options","draftAndPublish"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAMA,mBAAAA,GAAsBC,cAAAA,CACzBC,MAAM,EAAA,CACNC,KAAK,CAAC;;AAELC,IAAAA,UAAAA,EAAYH,eAAII,MAAM,EAAA;IACtBC,MAAAA,EAAQL,cAAAA,CAAII,MAAM,EAAA,CAAGE,QAAQ,EAAA;AAC7BC,IAAAA,MAAAA,EAAQP,eAAII,MAAM;AACpB,CAAA,CAAA,CACCI,QAAQ,EAAA;AAEJ,MAAMC,kBAAAA,GAAqB,OAChCC,MAAAA,EACAC,GAAAA,EACAC,MAAAA,GAAAA;;AAGA,IAAA,MAAMC,8BAAkBd,mBAAAA,CAAAA,CAAqBa,MAAAA,CAAAA;AAE7C,IAAA,MAAME,YAAYC,OAAAA,CAAK;AAAC,QAAA,YAAA;AAAc,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAAAA,CAAAA;IAC3D,MAAMI,KAAAA,GAAQN,MAAAA,CAAOO,QAAQ,CAACN,GAAAA,CAAAA;;AAG9B,IAAA,IAAI,CAACK,KAAAA,IAASA,KAAAA,CAAME,SAAS,KAAK,aAAA,EAAe;QAC/C,MAAM,IAAIC,kBAAAA,CAAOC,eAAe,CAAC,sBAAA,CAAA;AACnC,IAAA;;IAGA,MAAMC,YAAAA,GAAeL,OAAOM,IAAAA,KAAS,YAAA;AACrC,IAAA,IAAI,CAACD,YAAAA,IAAgB,CAACT,MAAAA,CAAOT,UAAU,EAAE;QACvC,MAAM,IAAIgB,kBAAAA,CAAOC,eAAe,CAAC,6CAAA,CAAA;AACnC,IAAA;;AAGA,IAAA,IAAIC,YAAAA,EAAc;AAChB,QAAA,MAAME,MAAM,MAAMb,MAAAA,CAAOc,SAAS,CAACb,KAAKc,SAAS,EAAA;AAEjD,QAAA,IAAI,CAACF,GAAAA,EAAK;YACR,MAAM,IAAIJ,kBAAAA,CAAOO,aAAa,CAAC,oBAAA,CAAA;AACjC,QAAA;QAEAZ,SAAAA,CAAUX,UAAU,GAAGoB,GAAAA,EAAKpB,UAAAA;AAC9B,IAAA;AAEA;;;;AAIC,MACD,IAAI,CAACW,SAAAA,CAAUP,MAAM,EAAE;QACrB,MAAMoB,WAAAA,GAAcX,OAAOY,OAAAA,EAASC,eAAAA;QACpCf,SAAAA,CAAUP,MAAM,GAAGoB,WAAAA,GAAc,OAAA,GAAU,WAAA;AAC7C,IAAA;IAEA,OAAOb,SAAAA;AACT;;;;"}
1
+ {"version":3,"file":"preview.js","sources":["../../../../../server/src/preview/controllers/validation/preview.ts"],"sourcesContent":["import { pick } from 'lodash/fp';\n\nimport type { Core, UID } from '@strapi/types';\nimport { z, validateZodSchema, errors } from '@strapi/utils';\n\nimport { Preview } from '../../../../../shared/contracts';\nimport type { HandlerParams } from '../../services/preview-config';\n\nconst getPreviewUrlSchema = z.object({\n // Will be undefined for single types\n documentId: z.string().optional(),\n locale: z.string().nullable().optional(),\n status: z.string().optional(),\n});\n\nexport const validatePreviewUrl = async (\n strapi: Core.Strapi,\n uid: UID.ContentType,\n params: Preview.GetPreviewUrl.Request['query']\n): Promise<HandlerParams> => {\n // Validate the request parameters format\n validateZodSchema(getPreviewUrlSchema)(params);\n\n const newParams = pick(['documentId', 'locale', 'status'], params) as HandlerParams;\n const model = strapi.getModel(uid);\n\n // If it's not a collection type or single type\n if (!model || model.modelType !== 'contentType') {\n throw new errors.ValidationError('Invalid content type');\n }\n\n // Document id is not required for single types\n const isSingleType = model?.kind === 'singleType';\n if (!isSingleType && !params.documentId) {\n throw new errors.ValidationError('documentId is required for Collection Types');\n }\n\n // Fill the documentId if it's a single type\n if (isSingleType) {\n const doc = await strapi.documents(uid).findFirst();\n\n if (!doc) {\n throw new errors.NotFoundError('Document not found');\n }\n\n newParams.documentId = doc?.documentId;\n }\n\n /**\n * If status is not specified, follow the following rules:\n * - D&P disabled: status is considered published\n * - D&P enabled: status is considered draft\n */\n if (!newParams.status) {\n const isDPEnabled = model?.options?.draftAndPublish;\n newParams.status = isDPEnabled ? 'draft' : 'published';\n }\n\n return newParams;\n};\n"],"names":["getPreviewUrlSchema","z","object","documentId","string","optional","locale","nullable","status","validatePreviewUrl","strapi","uid","params","validateZodSchema","newParams","pick","model","getModel","modelType","errors","ValidationError","isSingleType","kind","doc","documents","findFirst","NotFoundError","isDPEnabled","options","draftAndPublish"],"mappings":";;;;;AAQA,MAAMA,mBAAAA,GAAsBC,aAAAA,CAAEC,MAAM,CAAC;;IAEnCC,UAAAA,EAAYF,aAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC/BC,IAAAA,MAAAA,EAAQL,aAAAA,CAAEG,MAAM,EAAA,CAAGG,QAAQ,GAAGF,QAAQ,EAAA;IACtCG,MAAAA,EAAQP,aAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ;AAC7B,CAAA,CAAA;AAEO,MAAMI,kBAAAA,GAAqB,OAChCC,MAAAA,EACAC,GAAAA,EACAC,MAAAA,GAAAA;;AAGAC,IAAAA,6BAAAA,CAAkBb,mBAAAA,CAAAA,CAAqBY,MAAAA,CAAAA;AAEvC,IAAA,MAAME,YAAYC,OAAAA,CAAK;AAAC,QAAA,YAAA;AAAc,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAAAA,CAAAA;IAC3D,MAAMI,KAAAA,GAAQN,MAAAA,CAAOO,QAAQ,CAACN,GAAAA,CAAAA;;AAG9B,IAAA,IAAI,CAACK,KAAAA,IAASA,KAAAA,CAAME,SAAS,KAAK,aAAA,EAAe;QAC/C,MAAM,IAAIC,kBAAAA,CAAOC,eAAe,CAAC,sBAAA,CAAA;AACnC,IAAA;;IAGA,MAAMC,YAAAA,GAAeL,OAAOM,IAAAA,KAAS,YAAA;AACrC,IAAA,IAAI,CAACD,YAAAA,IAAgB,CAACT,MAAAA,CAAOT,UAAU,EAAE;QACvC,MAAM,IAAIgB,kBAAAA,CAAOC,eAAe,CAAC,6CAAA,CAAA;AACnC,IAAA;;AAGA,IAAA,IAAIC,YAAAA,EAAc;AAChB,QAAA,MAAME,MAAM,MAAMb,MAAAA,CAAOc,SAAS,CAACb,KAAKc,SAAS,EAAA;AAEjD,QAAA,IAAI,CAACF,GAAAA,EAAK;YACR,MAAM,IAAIJ,kBAAAA,CAAOO,aAAa,CAAC,oBAAA,CAAA;AACjC,QAAA;QAEAZ,SAAAA,CAAUX,UAAU,GAAGoB,GAAAA,EAAKpB,UAAAA;AAC9B,IAAA;AAEA;;;;AAIC,MACD,IAAI,CAACW,SAAAA,CAAUN,MAAM,EAAE;QACrB,MAAMmB,WAAAA,GAAcX,OAAOY,OAAAA,EAASC,eAAAA;QACpCf,SAAAA,CAAUN,MAAM,GAAGmB,WAAAA,GAAc,OAAA,GAAU,WAAA;AAC7C,IAAA;IAEA,OAAOb,SAAAA;AACT;;;;"}
@@ -1,16 +1,15 @@
1
- import * as yup from 'yup';
2
1
  import { pick } from 'lodash/fp';
3
- import { validateYupSchema, errors } from '@strapi/utils';
2
+ import { z, validateZodSchema, errors } from '@strapi/utils';
4
3
 
5
- const getPreviewUrlSchema = yup.object().shape({
4
+ const getPreviewUrlSchema = z.object({
6
5
  // Will be undefined for single types
7
- documentId: yup.string(),
8
- locale: yup.string().nullable(),
9
- status: yup.string()
10
- }).required();
6
+ documentId: z.string().optional(),
7
+ locale: z.string().nullable().optional(),
8
+ status: z.string().optional()
9
+ });
11
10
  const validatePreviewUrl = async (strapi, uid, params)=>{
12
11
  // Validate the request parameters format
13
- await validateYupSchema(getPreviewUrlSchema)(params);
12
+ validateZodSchema(getPreviewUrlSchema)(params);
14
13
  const newParams = pick([
15
14
  'documentId',
16
15
  'locale',
@@ -1 +1 @@
1
- {"version":3,"file":"preview.mjs","sources":["../../../../../server/src/preview/controllers/validation/preview.ts"],"sourcesContent":["import * as yup from 'yup';\nimport { pick } from 'lodash/fp';\n\nimport type { Core, UID } from '@strapi/types';\nimport { validateYupSchema, errors } from '@strapi/utils';\n\nimport { Preview } from '../../../../../shared/contracts';\nimport type { HandlerParams } from '../../services/preview-config';\n\nconst getPreviewUrlSchema = yup\n .object()\n .shape({\n // Will be undefined for single types\n documentId: yup.string(),\n locale: yup.string().nullable(),\n status: yup.string(),\n })\n .required();\n\nexport const validatePreviewUrl = async (\n strapi: Core.Strapi,\n uid: UID.ContentType,\n params: Preview.GetPreviewUrl.Request['query']\n): Promise<HandlerParams> => {\n // Validate the request parameters format\n await validateYupSchema(getPreviewUrlSchema)(params);\n\n const newParams = pick(['documentId', 'locale', 'status'], params) as HandlerParams;\n const model = strapi.getModel(uid);\n\n // If it's not a collection type or single type\n if (!model || model.modelType !== 'contentType') {\n throw new errors.ValidationError('Invalid content type');\n }\n\n // Document id is not required for single types\n const isSingleType = model?.kind === 'singleType';\n if (!isSingleType && !params.documentId) {\n throw new errors.ValidationError('documentId is required for Collection Types');\n }\n\n // Fill the documentId if it's a single type\n if (isSingleType) {\n const doc = await strapi.documents(uid).findFirst();\n\n if (!doc) {\n throw new errors.NotFoundError('Document not found');\n }\n\n newParams.documentId = doc?.documentId;\n }\n\n /**\n * If status is not specified, follow the following rules:\n * - D&P disabled: status is considered published\n * - D&P enabled: status is considered draft\n */\n if (!newParams.status) {\n const isDPEnabled = model?.options?.draftAndPublish;\n newParams.status = isDPEnabled ? 'draft' : 'published';\n }\n\n return newParams;\n};\n"],"names":["getPreviewUrlSchema","yup","object","shape","documentId","string","locale","nullable","status","required","validatePreviewUrl","strapi","uid","params","validateYupSchema","newParams","pick","model","getModel","modelType","errors","ValidationError","isSingleType","kind","doc","documents","findFirst","NotFoundError","isDPEnabled","options","draftAndPublish"],"mappings":";;;;AASA,MAAMA,mBAAAA,GAAsBC,GAAAA,CACzBC,MAAM,EAAA,CACNC,KAAK,CAAC;;AAELC,IAAAA,UAAAA,EAAYH,IAAII,MAAM,EAAA;IACtBC,MAAAA,EAAQL,GAAAA,CAAII,MAAM,EAAA,CAAGE,QAAQ,EAAA;AAC7BC,IAAAA,MAAAA,EAAQP,IAAII,MAAM;AACpB,CAAA,CAAA,CACCI,QAAQ,EAAA;AAEJ,MAAMC,kBAAAA,GAAqB,OAChCC,MAAAA,EACAC,GAAAA,EACAC,MAAAA,GAAAA;;AAGA,IAAA,MAAMC,kBAAkBd,mBAAAA,CAAAA,CAAqBa,MAAAA,CAAAA;AAE7C,IAAA,MAAME,YAAYC,IAAAA,CAAK;AAAC,QAAA,YAAA;AAAc,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAAAA,CAAAA;IAC3D,MAAMI,KAAAA,GAAQN,MAAAA,CAAOO,QAAQ,CAACN,GAAAA,CAAAA;;AAG9B,IAAA,IAAI,CAACK,KAAAA,IAASA,KAAAA,CAAME,SAAS,KAAK,aAAA,EAAe;QAC/C,MAAM,IAAIC,MAAAA,CAAOC,eAAe,CAAC,sBAAA,CAAA;AACnC,IAAA;;IAGA,MAAMC,YAAAA,GAAeL,OAAOM,IAAAA,KAAS,YAAA;AACrC,IAAA,IAAI,CAACD,YAAAA,IAAgB,CAACT,MAAAA,CAAOT,UAAU,EAAE;QACvC,MAAM,IAAIgB,MAAAA,CAAOC,eAAe,CAAC,6CAAA,CAAA;AACnC,IAAA;;AAGA,IAAA,IAAIC,YAAAA,EAAc;AAChB,QAAA,MAAME,MAAM,MAAMb,MAAAA,CAAOc,SAAS,CAACb,KAAKc,SAAS,EAAA;AAEjD,QAAA,IAAI,CAACF,GAAAA,EAAK;YACR,MAAM,IAAIJ,MAAAA,CAAOO,aAAa,CAAC,oBAAA,CAAA;AACjC,QAAA;QAEAZ,SAAAA,CAAUX,UAAU,GAAGoB,GAAAA,EAAKpB,UAAAA;AAC9B,IAAA;AAEA;;;;AAIC,MACD,IAAI,CAACW,SAAAA,CAAUP,MAAM,EAAE;QACrB,MAAMoB,WAAAA,GAAcX,OAAOY,OAAAA,EAASC,eAAAA;QACpCf,SAAAA,CAAUP,MAAM,GAAGoB,WAAAA,GAAc,OAAA,GAAU,WAAA;AAC7C,IAAA;IAEA,OAAOb,SAAAA;AACT;;;;"}
1
+ {"version":3,"file":"preview.mjs","sources":["../../../../../server/src/preview/controllers/validation/preview.ts"],"sourcesContent":["import { pick } from 'lodash/fp';\n\nimport type { Core, UID } from '@strapi/types';\nimport { z, validateZodSchema, errors } from '@strapi/utils';\n\nimport { Preview } from '../../../../../shared/contracts';\nimport type { HandlerParams } from '../../services/preview-config';\n\nconst getPreviewUrlSchema = z.object({\n // Will be undefined for single types\n documentId: z.string().optional(),\n locale: z.string().nullable().optional(),\n status: z.string().optional(),\n});\n\nexport const validatePreviewUrl = async (\n strapi: Core.Strapi,\n uid: UID.ContentType,\n params: Preview.GetPreviewUrl.Request['query']\n): Promise<HandlerParams> => {\n // Validate the request parameters format\n validateZodSchema(getPreviewUrlSchema)(params);\n\n const newParams = pick(['documentId', 'locale', 'status'], params) as HandlerParams;\n const model = strapi.getModel(uid);\n\n // If it's not a collection type or single type\n if (!model || model.modelType !== 'contentType') {\n throw new errors.ValidationError('Invalid content type');\n }\n\n // Document id is not required for single types\n const isSingleType = model?.kind === 'singleType';\n if (!isSingleType && !params.documentId) {\n throw new errors.ValidationError('documentId is required for Collection Types');\n }\n\n // Fill the documentId if it's a single type\n if (isSingleType) {\n const doc = await strapi.documents(uid).findFirst();\n\n if (!doc) {\n throw new errors.NotFoundError('Document not found');\n }\n\n newParams.documentId = doc?.documentId;\n }\n\n /**\n * If status is not specified, follow the following rules:\n * - D&P disabled: status is considered published\n * - D&P enabled: status is considered draft\n */\n if (!newParams.status) {\n const isDPEnabled = model?.options?.draftAndPublish;\n newParams.status = isDPEnabled ? 'draft' : 'published';\n }\n\n return newParams;\n};\n"],"names":["getPreviewUrlSchema","z","object","documentId","string","optional","locale","nullable","status","validatePreviewUrl","strapi","uid","params","validateZodSchema","newParams","pick","model","getModel","modelType","errors","ValidationError","isSingleType","kind","doc","documents","findFirst","NotFoundError","isDPEnabled","options","draftAndPublish"],"mappings":";;;AAQA,MAAMA,mBAAAA,GAAsBC,CAAAA,CAAEC,MAAM,CAAC;;IAEnCC,UAAAA,EAAYF,CAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ,EAAA;AAC/BC,IAAAA,MAAAA,EAAQL,CAAAA,CAAEG,MAAM,EAAA,CAAGG,QAAQ,GAAGF,QAAQ,EAAA;IACtCG,MAAAA,EAAQP,CAAAA,CAAEG,MAAM,EAAA,CAAGC,QAAQ;AAC7B,CAAA,CAAA;AAEO,MAAMI,kBAAAA,GAAqB,OAChCC,MAAAA,EACAC,GAAAA,EACAC,MAAAA,GAAAA;;AAGAC,IAAAA,iBAAAA,CAAkBb,mBAAAA,CAAAA,CAAqBY,MAAAA,CAAAA;AAEvC,IAAA,MAAME,YAAYC,IAAAA,CAAK;AAAC,QAAA,YAAA;AAAc,QAAA,QAAA;AAAU,QAAA;KAAS,EAAEH,MAAAA,CAAAA;IAC3D,MAAMI,KAAAA,GAAQN,MAAAA,CAAOO,QAAQ,CAACN,GAAAA,CAAAA;;AAG9B,IAAA,IAAI,CAACK,KAAAA,IAASA,KAAAA,CAAME,SAAS,KAAK,aAAA,EAAe;QAC/C,MAAM,IAAIC,MAAAA,CAAOC,eAAe,CAAC,sBAAA,CAAA;AACnC,IAAA;;IAGA,MAAMC,YAAAA,GAAeL,OAAOM,IAAAA,KAAS,YAAA;AACrC,IAAA,IAAI,CAACD,YAAAA,IAAgB,CAACT,MAAAA,CAAOT,UAAU,EAAE;QACvC,MAAM,IAAIgB,MAAAA,CAAOC,eAAe,CAAC,6CAAA,CAAA;AACnC,IAAA;;AAGA,IAAA,IAAIC,YAAAA,EAAc;AAChB,QAAA,MAAME,MAAM,MAAMb,MAAAA,CAAOc,SAAS,CAACb,KAAKc,SAAS,EAAA;AAEjD,QAAA,IAAI,CAACF,GAAAA,EAAK;YACR,MAAM,IAAIJ,MAAAA,CAAOO,aAAa,CAAC,oBAAA,CAAA;AACjC,QAAA;QAEAZ,SAAAA,CAAUX,UAAU,GAAGoB,GAAAA,EAAKpB,UAAAA;AAC9B,IAAA;AAEA;;;;AAIC,MACD,IAAI,CAACW,SAAAA,CAAUN,MAAM,EAAE;QACrB,MAAMmB,WAAAA,GAAcX,OAAOY,OAAAA,EAASC,eAAAA;QACpCf,SAAAA,CAAUN,MAAM,GAAGmB,WAAAA,GAAc,OAAA,GAAU,WAAA;AAC7C,IAAA;IAEA,OAAOb,SAAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"collection-types.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/collection-types.ts"],"names":[],"mappings":";cAiPkB,GAAG;iBA+FA,GAAG;gBA2DJ,GAAG;gBA0BH,GAAG;eAYJ,GAAG;mBA4CC,GAAG;gBAmBN,GAAG;IAoCrB;;;OAGG;iBACgB,GAAG;+BA+FW,GAAG;qBA4Bb,GAAG;uBA8CD,GAAG;mBAyCP,GAAG;iBAyDL,GAAG;oBAwCA,GAAG;6BA6CM,GAAG;wCA2CQ,GAAG;;AAnrB/C,wBA8sBE"}
1
+ {"version":3,"file":"collection-types.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/collection-types.ts"],"names":[],"mappings":";cA6SkB,GAAG;iBA8HA,GAAG;gBA2DJ,GAAG;gBA0BH,GAAG;eAYJ,GAAG;mBA4CC,GAAG;gBAmBN,GAAG;IAoCrB;;;OAGG;iBACgB,GAAG;+BA+FW,GAAG;qBA4Bb,GAAG;uBA8CD,GAAG;mBAyCP,GAAG;iBAyDL,GAAG;oBAwCA,GAAG;6BA6CM,GAAG;wCA2CQ,GAAG;;AAltB/C,wBA6uBE"}
@@ -1 +1 @@
1
- {"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/dimensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,UAAU,OAAO;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAUD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YAC5B,GAAG,SACL,IAAI,MAAM,SACX,OAAO,iBAsBd,CAAC"}
1
+ {"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/dimensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC,UAAU,OAAO;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAQD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YAC5B,GAAG,SACL,IAAI,MAAM,SACX,OAAO,iBAkBd,CAAC"}
@@ -1,25 +1,26 @@
1
1
  import { UID } from '@strapi/types';
2
- import { yup } from '@strapi/utils';
3
2
  import createModelConfigurationSchema from './model-configuration';
4
3
  declare const validateUIDField: (contentTypeUID: any, field: any) => void;
5
4
  declare const validatePagination: ({ page, pageSize }: any) => void;
6
- declare const validateKind: (body: unknown, errorMessage?: string | undefined) => Promise<string | null | undefined>;
7
- declare const validateBulkActionInput: (body: unknown, errorMessage?: string | undefined) => Promise<import("yup/lib/object").AssertsShape<{
8
- documentIds: import("yup/lib/array").RequiredArraySchema<yup.StrapiIDSchema, import("yup/lib/types").AnyObject, any[] | undefined>;
9
- }>>;
10
- declare const validateGenerateUIDInput: (body: unknown, errorMessage?: string | undefined) => Promise<import("yup/lib/object").AssertsShape<{
11
- contentTypeUID: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
12
- field: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
13
- data: import("yup/lib/object").RequiredObjectSchema<import("yup/lib/object").ObjectShape, Record<string, any>, import("yup/lib/object").TypeOfShape<import("yup/lib/object").ObjectShape>>;
14
- }>>;
5
+ declare const validateKind: (data: unknown, errorMessage?: string | undefined) => Promise<"collectionType" | "singleType" | null | undefined>;
6
+ declare const validateBulkActionInput: (data: unknown, errorMessage?: string | undefined) => Promise<{
7
+ documentIds: (string | number)[];
8
+ }>;
9
+ declare const validateGenerateUIDInput: (data: unknown, errorMessage?: string | undefined) => Promise<{
10
+ contentTypeUID: string;
11
+ field: string;
12
+ data: {
13
+ [x: string]: unknown;
14
+ };
15
+ }>;
15
16
  declare const validateCheckUIDAvailabilityInput: (body: {
16
17
  contentTypeUID: UID.ContentType;
17
18
  field: string;
18
19
  value: string;
19
- }) => Promise<import("yup/lib/object").AssertsShape<{
20
- contentTypeUID: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
21
- field: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
22
- value: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
23
- }>>;
20
+ }) => Promise<{
21
+ contentTypeUID: string;
22
+ field: string;
23
+ value: string;
24
+ }>;
24
25
  export { createModelConfigurationSchema, validateUIDField, validatePagination, validateKind, validateBulkActionInput, validateGenerateUIDInput, validateCheckUIDAvailabilityInput, };
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,GAAG,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,GAAG,EAA6B,MAAM,eAAe,CAAC;AAG/D,OAAO,8BAA8B,MAAM,uBAAuB,CAAC;AA0CnE,QAAA,MAAM,gBAAgB,mBAAoB,GAAG,SAAS,GAAG,SAaxD,CAAC;AAEF,QAAA,MAAM,kBAAkB,uBAAwB,GAAG,SAUlD,CAAC;AAEF,QAAA,MAAM,YAAY,0FAAgC,CAAC;AACnD,QAAA,MAAM,uBAAuB;;GAA2C,CAAC;AACzE,QAAA,MAAM,wBAAwB;;;;GAA4C,CAAC;AAC3E,QAAA,MAAM,iCAAiC,SAAU;IAC/C,cAAc,EAAE,IAAI,WAAW,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;;;;GAmBA,CAAC;AAEF,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,iCAAiC,GAClC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,GAAG,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,8BAA8B,MAAM,uBAAuB,CAAC;AA+BnE,QAAA,MAAM,gBAAgB,mBAAoB,GAAG,SAAS,GAAG,SAaxD,CAAC;AAEF,QAAA,MAAM,kBAAkB,uBAAwB,GAAG,SAUlD,CAAC;AAEF,QAAA,MAAM,YAAY,mHAA+B,CAAC;AAClD,QAAA,MAAM,uBAAuB;;EAA0C,CAAC;AACxE,QAAA,MAAM,wBAAwB;;;;;;EAA2C,CAAC;AAC1E,QAAA,MAAM,iCAAiC,SAAU;IAC/C,cAAc,EAAE,IAAI,WAAW,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;;;;EAgBA,CAAC;AAEF,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,iCAAiC,GAClC,CAAC"}
@@ -1,4 +1,19 @@
1
- declare const validateFindAvailable: (body: unknown, errorMessage?: string | undefined) => Promise<any>;
2
- declare const validateFindExisting: (body: unknown, errorMessage?: string | undefined) => Promise<any>;
1
+ declare const validateFindAvailable: (data: unknown, errorMessage?: string | undefined) => Promise<{
2
+ component?: string | undefined;
3
+ id?: string | number | undefined;
4
+ _q?: string | undefined;
5
+ idsToOmit?: (string | number)[] | undefined;
6
+ idsToInclude?: (string | number)[] | undefined;
7
+ page?: number | undefined;
8
+ pageSize?: number | undefined;
9
+ locale?: string | null | undefined;
10
+ status?: "draft" | "published" | null | undefined;
11
+ }>;
12
+ declare const validateFindExisting: (data: unknown, errorMessage?: string | undefined) => Promise<{
13
+ page?: number | undefined;
14
+ pageSize?: number | undefined;
15
+ locale?: string | null | undefined;
16
+ status?: "draft" | "published" | null | undefined;
17
+ }>;
3
18
  export { validateFindAvailable, validateFindExisting };
4
19
  //# sourceMappingURL=relations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/relations.ts"],"names":[],"mappings":"AA2BA,QAAA,MAAM,qBAAqB,oEAAoE,CAAC;AAChG,QAAA,MAAM,oBAAoB,oEAAmE,CAAC;AAE9F,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../../../../server/src/controllers/validation/relations.ts"],"names":[],"mappings":"AAsBA,QAAA,MAAM,qBAAqB;;;;;;;;;;EAAgD,CAAC;AAC5E,QAAA,MAAM,oBAAoB;;;;;EAA+C,CAAC;AAE1E,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,2 +1,4 @@
1
- export declare const validateRestoreVersion: (body: unknown, errorMessage?: string | undefined) => Promise<any>;
1
+ export declare const validateRestoreVersion: (data: unknown, errorMessage?: string | undefined) => {
2
+ contentType: string;
3
+ };
2
4
  //# sourceMappingURL=history-version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"history-version.d.ts","sourceRoot":"","sources":["../../../../../../server/src/history/controllers/validation/history-version.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,sBAAsB,oEAAiD,CAAC"}
1
+ {"version":3,"file":"history-version.d.ts","sourceRoot":"","sources":["../../../../../../server/src/history/controllers/validation/history-version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB;;CAAiD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../../../../../server/src/homepage/controllers/homepage.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAEnG,QAAA,MAAM,wBAAwB;oDAWK,QAAQ,2BAA2B,CAAC;yBAkBxC,QAAQ,0BAA0B,CAAC;CAIjE,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../../../../../server/src/homepage/controllers/homepage.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAEnG,QAAA,MAAM,wBAAwB;oDAQK,QAAQ,2BAA2B,CAAC;yBAkBxC,QAAQ,0BAA0B,CAAC;CAIjE,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../../../server/src/preview/controllers/validation/preview.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAYnE,eAAO,MAAM,kBAAkB,WACrB,KAAK,MAAM,OACd,IAAI,WAAW,UACZ,QAAQ,aAAa,QAAQ,CAAC,OAAO,CAAC,KAC7C,QAAQ,aAAa,CAwCvB,CAAC"}
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../../../server/src/preview/controllers/validation/preview.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AASnE,eAAO,MAAM,kBAAkB,WACrB,KAAK,MAAM,OACd,IAAI,WAAW,UACZ,QAAQ,aAAa,QAAQ,CAAC,OAAO,CAAC,KAC7C,QAAQ,aAAa,CAwCvB,CAAC"}
@@ -1,2 +1,5 @@
1
- export declare const validateHasPermissionsInput: (body: unknown, errorMessage?: string | undefined) => any;
1
+ export declare const validateHasPermissionsInput: (data: unknown, errorMessage?: string | undefined) => {
2
+ actions?: string[] | undefined;
3
+ hasAtLeastOne?: boolean | undefined;
4
+ };
2
5
  //# sourceMappingURL=hasPermissions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasPermissions.d.ts","sourceRoot":"","sources":["../../../../../server/src/validation/policies/hasPermissions.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,2BAA2B,2DAA8C,CAAC"}
1
+ {"version":3,"file":"hasPermissions.d.ts","sourceRoot":"","sources":["../../../../../server/src/validation/policies/hasPermissions.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,2BAA2B;;;CAA0C,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { z } from '@strapi/utils';
2
+ interface FormattedZodError {
3
+ path: string[];
4
+ message: string;
5
+ name: 'ValidationError';
6
+ value: undefined;
7
+ }
8
+ interface FormattedZodErrors {
9
+ errors: FormattedZodError[];
10
+ message: string;
11
+ }
12
+ /**
13
+ * Transforms a ZodError into the same shape as formatYupErrors from @strapi/utils.
14
+ * Only keeps the first error per path to match Yup behavior.
15
+ */
16
+ declare const formatZodErrors: (zodError: z.ZodError) => FormattedZodErrors;
17
+ /**
18
+ * Zod schema for Strapi entity IDs.
19
+ * Matches the StrapiIDSchema from @strapi/utils/yup:
20
+ * accepts strings or non-negative integers.
21
+ */
22
+ declare const strapiID: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
23
+ /**
24
+ * Async Zod validator matching the signature of validateYupSchema from @strapi/utils.
25
+ *
26
+ * Usage:
27
+ * const validate = validateZodAsync(mySchema);
28
+ * const data = await validate(body); // throws ValidationError on failure
29
+ * const data = await validate(body, 'Custom'); // throws with custom message
30
+ */
31
+ declare const validateZodAsync: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => (data: unknown, errorMessage?: string) => Promise<z.infer<T>>;
32
+ export { formatZodErrors, strapiID, validateZodAsync };
33
+ export type { FormattedZodError, FormattedZodErrors };
34
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../../server/src/validation/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAU,MAAM,eAAe,CAAC;AAE1C,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe,aAAc,EAAE,QAAQ,KAAG,kBAqB/C,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,QAAQ,iDAAwD,CAAC;AAEvE;;;;;;;GAOG;AACH,QAAA,MAAM,gBAAgB,8FACS,CAAC,YACjB,OAAO,iBAAiB,MAAM,KAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAY/D,CAAC;AAEJ,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AACvD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -2,11 +2,11 @@
2
2
 
3
3
  var strapiUtils = require('@strapi/utils');
4
4
 
5
- const hasPermissionsSchema = strapiUtils.yup.object({
6
- actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
7
- hasAtLeastOne: strapiUtils.yup.boolean()
5
+ const hasPermissionsSchema = strapiUtils.z.object({
6
+ actions: strapiUtils.z.array(strapiUtils.z.string()).optional(),
7
+ hasAtLeastOne: strapiUtils.z.boolean().optional()
8
8
  });
9
- const validateHasPermissionsInput = strapiUtils.validateYupSchemaSync(hasPermissionsSchema);
9
+ const validateHasPermissionsInput = strapiUtils.validateZodSchema(hasPermissionsSchema);
10
10
 
11
11
  exports.validateHasPermissionsInput = validateHasPermissionsInput;
12
12
  //# sourceMappingURL=hasPermissions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasPermissions.js","sources":["../../../../server/src/validation/policies/hasPermissions.ts"],"sourcesContent":["import { yup, validateYupSchemaSync } from '@strapi/utils';\n\nconst hasPermissionsSchema = yup.object({\n actions: yup.array().of(yup.string()),\n hasAtLeastOne: yup.boolean(),\n});\n\nexport const validateHasPermissionsInput = validateYupSchemaSync(hasPermissionsSchema);\n"],"names":["hasPermissionsSchema","yup","object","actions","array","of","string","hasAtLeastOne","boolean","validateHasPermissionsInput","validateYupSchemaSync"],"mappings":";;;;AAEA,MAAMA,oBAAAA,GAAuBC,eAAAA,CAAIC,MAAM,CAAC;AACtCC,IAAAA,OAAAA,EAASF,gBAAIG,KAAK,EAAA,CAAGC,EAAE,CAACJ,gBAAIK,MAAM,EAAA,CAAA;AAClCC,IAAAA,aAAAA,EAAeN,gBAAIO,OAAO;AAC5B,CAAA,CAAA;AAEO,MAAMC,2BAAAA,GAA8BC,iCAAAA,CAAsBV,oBAAAA;;;;"}
1
+ {"version":3,"file":"hasPermissions.js","sources":["../../../../server/src/validation/policies/hasPermissions.ts"],"sourcesContent":["import { z, validateZodSchema } from '@strapi/utils';\n\nconst hasPermissionsSchema = z.object({\n actions: z.array(z.string()).optional(),\n hasAtLeastOne: z.boolean().optional(),\n});\n\nexport const validateHasPermissionsInput = validateZodSchema(hasPermissionsSchema);\n"],"names":["hasPermissionsSchema","z","object","actions","array","string","optional","hasAtLeastOne","boolean","validateHasPermissionsInput","validateZodSchema"],"mappings":";;;;AAEA,MAAMA,oBAAAA,GAAuBC,aAAAA,CAAEC,MAAM,CAAC;AACpCC,IAAAA,OAAAA,EAASF,cAAEG,KAAK,CAACH,aAAAA,CAAEI,MAAM,IAAIC,QAAQ,EAAA;IACrCC,aAAAA,EAAeN,aAAAA,CAAEO,OAAO,EAAA,CAAGF,QAAQ;AACrC,CAAA,CAAA;AAEO,MAAMG,2BAAAA,GAA8BC,6BAAAA,CAAkBV,oBAAAA;;;;"}
@@ -1,10 +1,10 @@
1
- import { yup, validateYupSchemaSync } from '@strapi/utils';
1
+ import { z, validateZodSchema } from '@strapi/utils';
2
2
 
3
- const hasPermissionsSchema = yup.object({
4
- actions: yup.array().of(yup.string()),
5
- hasAtLeastOne: yup.boolean()
3
+ const hasPermissionsSchema = z.object({
4
+ actions: z.array(z.string()).optional(),
5
+ hasAtLeastOne: z.boolean().optional()
6
6
  });
7
- const validateHasPermissionsInput = validateYupSchemaSync(hasPermissionsSchema);
7
+ const validateHasPermissionsInput = validateZodSchema(hasPermissionsSchema);
8
8
 
9
9
  export { validateHasPermissionsInput };
10
10
  //# sourceMappingURL=hasPermissions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasPermissions.mjs","sources":["../../../../server/src/validation/policies/hasPermissions.ts"],"sourcesContent":["import { yup, validateYupSchemaSync } from '@strapi/utils';\n\nconst hasPermissionsSchema = yup.object({\n actions: yup.array().of(yup.string()),\n hasAtLeastOne: yup.boolean(),\n});\n\nexport const validateHasPermissionsInput = validateYupSchemaSync(hasPermissionsSchema);\n"],"names":["hasPermissionsSchema","yup","object","actions","array","of","string","hasAtLeastOne","boolean","validateHasPermissionsInput","validateYupSchemaSync"],"mappings":";;AAEA,MAAMA,oBAAAA,GAAuBC,GAAAA,CAAIC,MAAM,CAAC;AACtCC,IAAAA,OAAAA,EAASF,IAAIG,KAAK,EAAA,CAAGC,EAAE,CAACJ,IAAIK,MAAM,EAAA,CAAA;AAClCC,IAAAA,aAAAA,EAAeN,IAAIO,OAAO;AAC5B,CAAA,CAAA;AAEO,MAAMC,2BAAAA,GAA8BC,qBAAAA,CAAsBV,oBAAAA;;;;"}
1
+ {"version":3,"file":"hasPermissions.mjs","sources":["../../../../server/src/validation/policies/hasPermissions.ts"],"sourcesContent":["import { z, validateZodSchema } from '@strapi/utils';\n\nconst hasPermissionsSchema = z.object({\n actions: z.array(z.string()).optional(),\n hasAtLeastOne: z.boolean().optional(),\n});\n\nexport const validateHasPermissionsInput = validateZodSchema(hasPermissionsSchema);\n"],"names":["hasPermissionsSchema","z","object","actions","array","string","optional","hasAtLeastOne","boolean","validateHasPermissionsInput","validateZodSchema"],"mappings":";;AAEA,MAAMA,oBAAAA,GAAuBC,CAAAA,CAAEC,MAAM,CAAC;AACpCC,IAAAA,OAAAA,EAASF,EAAEG,KAAK,CAACH,CAAAA,CAAEI,MAAM,IAAIC,QAAQ,EAAA;IACrCC,aAAAA,EAAeN,CAAAA,CAAEO,OAAO,EAAA,CAAGF,QAAQ;AACrC,CAAA,CAAA;AAEO,MAAMG,2BAAAA,GAA8BC,iBAAAA,CAAkBV,oBAAAA;;;;"}
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ var strapiUtils = require('@strapi/utils');
4
+
5
+ /**
6
+ * Transforms a ZodError into the same shape as formatYupErrors from @strapi/utils.
7
+ * Only keeps the first error per path to match Yup behavior.
8
+ */ const formatZodErrors = (zodError)=>{
9
+ const seen = new Set();
10
+ const formattedErrors = [];
11
+ for (const issue of zodError.issues){
12
+ const key = issue.path.join('.');
13
+ if (!seen.has(key)) {
14
+ seen.add(key);
15
+ formattedErrors.push({
16
+ path: issue.path.map(String),
17
+ message: issue.message,
18
+ name: 'ValidationError',
19
+ value: undefined
20
+ });
21
+ }
22
+ }
23
+ return {
24
+ errors: formattedErrors,
25
+ message: zodError.issues[0]?.message ?? 'Validation error'
26
+ };
27
+ };
28
+ /**
29
+ * Zod schema for Strapi entity IDs.
30
+ * Matches the StrapiIDSchema from @strapi/utils/yup:
31
+ * accepts strings or non-negative integers.
32
+ */ const strapiID = strapiUtils.z.union([
33
+ strapiUtils.z.string(),
34
+ strapiUtils.z.number().int().nonnegative()
35
+ ]);
36
+ /**
37
+ * Async Zod validator matching the signature of validateYupSchema from @strapi/utils.
38
+ *
39
+ * Usage:
40
+ * const validate = validateZodAsync(mySchema);
41
+ * const data = await validate(body); // throws ValidationError on failure
42
+ * const data = await validate(body, 'Custom'); // throws with custom message
43
+ */ const validateZodAsync = (schema)=>async (data, errorMessage)=>{
44
+ try {
45
+ return await schema.parseAsync(data);
46
+ } catch (error) {
47
+ if (error instanceof strapiUtils.z.ZodError) {
48
+ const { message, errors: formattedErrors } = formatZodErrors(error);
49
+ throw new strapiUtils.errors.ValidationError(errorMessage || message, {
50
+ errors: formattedErrors
51
+ });
52
+ }
53
+ throw error;
54
+ }
55
+ };
56
+
57
+ exports.formatZodErrors = formatZodErrors;
58
+ exports.strapiID = strapiID;
59
+ exports.validateZodAsync = validateZodAsync;
60
+ //# sourceMappingURL=zod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.js","sources":["../../../server/src/validation/zod.ts"],"sourcesContent":["import { z, errors } from '@strapi/utils';\n\ninterface FormattedZodError {\n path: string[];\n message: string;\n name: 'ValidationError';\n value: undefined;\n}\n\ninterface FormattedZodErrors {\n errors: FormattedZodError[];\n message: string;\n}\n\n/**\n * Transforms a ZodError into the same shape as formatYupErrors from @strapi/utils.\n * Only keeps the first error per path to match Yup behavior.\n */\nconst formatZodErrors = (zodError: z.ZodError): FormattedZodErrors => {\n const seen = new Set<string>();\n const formattedErrors: FormattedZodError[] = [];\n\n for (const issue of zodError.issues) {\n const key = issue.path.join('.');\n if (!seen.has(key)) {\n seen.add(key);\n formattedErrors.push({\n path: issue.path.map(String),\n message: issue.message,\n name: 'ValidationError',\n value: undefined,\n });\n }\n }\n\n return {\n errors: formattedErrors,\n message: zodError.issues[0]?.message ?? 'Validation error',\n };\n};\n\n/**\n * Zod schema for Strapi entity IDs.\n * Matches the StrapiIDSchema from @strapi/utils/yup:\n * accepts strings or non-negative integers.\n */\nconst strapiID = z.union([z.string(), z.number().int().nonnegative()]);\n\n/**\n * Async Zod validator matching the signature of validateYupSchema from @strapi/utils.\n *\n * Usage:\n * const validate = validateZodAsync(mySchema);\n * const data = await validate(body); // throws ValidationError on failure\n * const data = await validate(body, 'Custom'); // throws with custom message\n */\nconst validateZodAsync =\n <T extends z.Schema>(schema: T) =>\n async (data: unknown, errorMessage?: string): Promise<z.infer<T>> => {\n try {\n return await schema.parseAsync(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors: formattedErrors } = formatZodErrors(error);\n throw new errors.ValidationError(errorMessage || message, {\n errors: formattedErrors,\n });\n }\n throw error;\n }\n };\n\nexport { formatZodErrors, strapiID, validateZodAsync };\nexport type { FormattedZodError, FormattedZodErrors };\n"],"names":["formatZodErrors","zodError","seen","Set","formattedErrors","issue","issues","key","path","join","has","add","push","map","String","message","name","value","undefined","errors","strapiID","z","union","string","number","int","nonnegative","validateZodAsync","schema","data","errorMessage","parseAsync","error","ZodError","ValidationError"],"mappings":";;;;AAcA;;;IAIA,MAAMA,kBAAkB,CAACC,QAAAA,GAAAA;AACvB,IAAA,MAAMC,OAAO,IAAIC,GAAAA,EAAAA;AACjB,IAAA,MAAMC,kBAAuC,EAAE;AAE/C,IAAA,KAAK,MAAMC,KAAAA,IAASJ,QAAAA,CAASK,MAAM,CAAE;AACnC,QAAA,MAAMC,GAAAA,GAAMF,KAAAA,CAAMG,IAAI,CAACC,IAAI,CAAC,GAAA,CAAA;AAC5B,QAAA,IAAI,CAACP,IAAAA,CAAKQ,GAAG,CAACH,GAAAA,CAAAA,EAAM;AAClBL,YAAAA,IAAAA,CAAKS,GAAG,CAACJ,GAAAA,CAAAA;AACTH,YAAAA,eAAAA,CAAgBQ,IAAI,CAAC;AACnBJ,gBAAAA,IAAAA,EAAMH,KAAAA,CAAMG,IAAI,CAACK,GAAG,CAACC,MAAAA,CAAAA;AACrBC,gBAAAA,OAAAA,EAASV,MAAMU,OAAO;gBACtBC,IAAAA,EAAM,iBAAA;gBACNC,KAAAA,EAAOC;AACT,aAAA,CAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAO;QACLC,MAAAA,EAAQf,eAAAA;AACRW,QAAAA,OAAAA,EAASd,QAAAA,CAASK,MAAM,CAAC,CAAA,CAAE,EAAES,OAAAA,IAAW;AAC1C,KAAA;AACF;AAEA;;;;AAIC,IACD,MAAMK,QAAAA,GAAWC,aAAAA,CAAEC,KAAK,CAAC;AAACD,IAAAA,aAAAA,CAAEE,MAAM,EAAA;AAAIF,IAAAA,aAAAA,CAAEG,MAAM,EAAA,CAAGC,GAAG,EAAA,CAAGC,WAAW;AAAG,CAAA;AAErE;;;;;;;AAOC,IACD,MAAMC,gBAAAA,GACJ,CAAqBC,MAAAA,GACrB,OAAOC,IAAAA,EAAeC,YAAAA,GAAAA;QACpB,IAAI;YACF,OAAO,MAAMF,MAAAA,CAAOG,UAAU,CAACF,IAAAA,CAAAA;AACjC,QAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;YACd,IAAIA,KAAAA,YAAiBX,aAAAA,CAAEY,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAElB,OAAO,EAAEI,QAAQf,eAAe,EAAE,GAAGJ,eAAAA,CAAgBgC,KAAAA,CAAAA;AAC7D,gBAAA,MAAM,IAAIb,kBAAAA,CAAOe,eAAe,CAACJ,gBAAgBf,OAAAA,EAAS;oBACxDI,MAAAA,EAAQf;AACV,iBAAA,CAAA;AACF,YAAA;YACA,MAAM4B,KAAAA;AACR,QAAA;AACF,IAAA;;;;;;"}
@@ -0,0 +1,56 @@
1
+ import { z, errors } from '@strapi/utils';
2
+
3
+ /**
4
+ * Transforms a ZodError into the same shape as formatYupErrors from @strapi/utils.
5
+ * Only keeps the first error per path to match Yup behavior.
6
+ */ const formatZodErrors = (zodError)=>{
7
+ const seen = new Set();
8
+ const formattedErrors = [];
9
+ for (const issue of zodError.issues){
10
+ const key = issue.path.join('.');
11
+ if (!seen.has(key)) {
12
+ seen.add(key);
13
+ formattedErrors.push({
14
+ path: issue.path.map(String),
15
+ message: issue.message,
16
+ name: 'ValidationError',
17
+ value: undefined
18
+ });
19
+ }
20
+ }
21
+ return {
22
+ errors: formattedErrors,
23
+ message: zodError.issues[0]?.message ?? 'Validation error'
24
+ };
25
+ };
26
+ /**
27
+ * Zod schema for Strapi entity IDs.
28
+ * Matches the StrapiIDSchema from @strapi/utils/yup:
29
+ * accepts strings or non-negative integers.
30
+ */ const strapiID = z.union([
31
+ z.string(),
32
+ z.number().int().nonnegative()
33
+ ]);
34
+ /**
35
+ * Async Zod validator matching the signature of validateYupSchema from @strapi/utils.
36
+ *
37
+ * Usage:
38
+ * const validate = validateZodAsync(mySchema);
39
+ * const data = await validate(body); // throws ValidationError on failure
40
+ * const data = await validate(body, 'Custom'); // throws with custom message
41
+ */ const validateZodAsync = (schema)=>async (data, errorMessage)=>{
42
+ try {
43
+ return await schema.parseAsync(data);
44
+ } catch (error) {
45
+ if (error instanceof z.ZodError) {
46
+ const { message, errors: formattedErrors } = formatZodErrors(error);
47
+ throw new errors.ValidationError(errorMessage || message, {
48
+ errors: formattedErrors
49
+ });
50
+ }
51
+ throw error;
52
+ }
53
+ };
54
+
55
+ export { formatZodErrors, strapiID, validateZodAsync };
56
+ //# sourceMappingURL=zod.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.mjs","sources":["../../../server/src/validation/zod.ts"],"sourcesContent":["import { z, errors } from '@strapi/utils';\n\ninterface FormattedZodError {\n path: string[];\n message: string;\n name: 'ValidationError';\n value: undefined;\n}\n\ninterface FormattedZodErrors {\n errors: FormattedZodError[];\n message: string;\n}\n\n/**\n * Transforms a ZodError into the same shape as formatYupErrors from @strapi/utils.\n * Only keeps the first error per path to match Yup behavior.\n */\nconst formatZodErrors = (zodError: z.ZodError): FormattedZodErrors => {\n const seen = new Set<string>();\n const formattedErrors: FormattedZodError[] = [];\n\n for (const issue of zodError.issues) {\n const key = issue.path.join('.');\n if (!seen.has(key)) {\n seen.add(key);\n formattedErrors.push({\n path: issue.path.map(String),\n message: issue.message,\n name: 'ValidationError',\n value: undefined,\n });\n }\n }\n\n return {\n errors: formattedErrors,\n message: zodError.issues[0]?.message ?? 'Validation error',\n };\n};\n\n/**\n * Zod schema for Strapi entity IDs.\n * Matches the StrapiIDSchema from @strapi/utils/yup:\n * accepts strings or non-negative integers.\n */\nconst strapiID = z.union([z.string(), z.number().int().nonnegative()]);\n\n/**\n * Async Zod validator matching the signature of validateYupSchema from @strapi/utils.\n *\n * Usage:\n * const validate = validateZodAsync(mySchema);\n * const data = await validate(body); // throws ValidationError on failure\n * const data = await validate(body, 'Custom'); // throws with custom message\n */\nconst validateZodAsync =\n <T extends z.Schema>(schema: T) =>\n async (data: unknown, errorMessage?: string): Promise<z.infer<T>> => {\n try {\n return await schema.parseAsync(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors: formattedErrors } = formatZodErrors(error);\n throw new errors.ValidationError(errorMessage || message, {\n errors: formattedErrors,\n });\n }\n throw error;\n }\n };\n\nexport { formatZodErrors, strapiID, validateZodAsync };\nexport type { FormattedZodError, FormattedZodErrors };\n"],"names":["formatZodErrors","zodError","seen","Set","formattedErrors","issue","issues","key","path","join","has","add","push","map","String","message","name","value","undefined","errors","strapiID","z","union","string","number","int","nonnegative","validateZodAsync","schema","data","errorMessage","parseAsync","error","ZodError","ValidationError"],"mappings":";;AAcA;;;IAIA,MAAMA,kBAAkB,CAACC,QAAAA,GAAAA;AACvB,IAAA,MAAMC,OAAO,IAAIC,GAAAA,EAAAA;AACjB,IAAA,MAAMC,kBAAuC,EAAE;AAE/C,IAAA,KAAK,MAAMC,KAAAA,IAASJ,QAAAA,CAASK,MAAM,CAAE;AACnC,QAAA,MAAMC,GAAAA,GAAMF,KAAAA,CAAMG,IAAI,CAACC,IAAI,CAAC,GAAA,CAAA;AAC5B,QAAA,IAAI,CAACP,IAAAA,CAAKQ,GAAG,CAACH,GAAAA,CAAAA,EAAM;AAClBL,YAAAA,IAAAA,CAAKS,GAAG,CAACJ,GAAAA,CAAAA;AACTH,YAAAA,eAAAA,CAAgBQ,IAAI,CAAC;AACnBJ,gBAAAA,IAAAA,EAAMH,KAAAA,CAAMG,IAAI,CAACK,GAAG,CAACC,MAAAA,CAAAA;AACrBC,gBAAAA,OAAAA,EAASV,MAAMU,OAAO;gBACtBC,IAAAA,EAAM,iBAAA;gBACNC,KAAAA,EAAOC;AACT,aAAA,CAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAO;QACLC,MAAAA,EAAQf,eAAAA;AACRW,QAAAA,OAAAA,EAASd,QAAAA,CAASK,MAAM,CAAC,CAAA,CAAE,EAAES,OAAAA,IAAW;AAC1C,KAAA;AACF;AAEA;;;;AAIC,IACD,MAAMK,QAAAA,GAAWC,CAAAA,CAAEC,KAAK,CAAC;AAACD,IAAAA,CAAAA,CAAEE,MAAM,EAAA;AAAIF,IAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGC,GAAG,EAAA,CAAGC,WAAW;AAAG,CAAA;AAErE;;;;;;;AAOC,IACD,MAAMC,gBAAAA,GACJ,CAAqBC,MAAAA,GACrB,OAAOC,IAAAA,EAAeC,YAAAA,GAAAA;QACpB,IAAI;YACF,OAAO,MAAMF,MAAAA,CAAOG,UAAU,CAACF,IAAAA,CAAAA;AACjC,QAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;YACd,IAAIA,KAAAA,YAAiBX,CAAAA,CAAEY,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAElB,OAAO,EAAEI,QAAQf,eAAe,EAAE,GAAGJ,eAAAA,CAAgBgC,KAAAA,CAAAA;AAC7D,gBAAA,MAAM,IAAIb,MAAAA,CAAOe,eAAe,CAACJ,gBAAgBf,OAAAA,EAAS;oBACxDI,MAAAA,EAAQf;AACV,iBAAA,CAAA;AACF,YAAA;YACA,MAAM4B,KAAAA;AACR,QAAA;AACF,IAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/content-manager",
3
- "version": "5.44.0",
3
+ "version": "5.45.0",
4
4
  "description": "A powerful UI to easily manage your data.",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -74,8 +74,8 @@
74
74
  "@sindresorhus/slugify": "1.1.0",
75
75
  "@strapi/design-system": "2.2.0",
76
76
  "@strapi/icons": "2.2.0",
77
- "@strapi/types": "5.44.0",
78
- "@strapi/utils": "5.44.0",
77
+ "@strapi/types": "5.45.0",
78
+ "@strapi/utils": "5.45.0",
79
79
  "codemirror5": "npm:codemirror@^5.65.11",
80
80
  "date-fns": "2.30.0",
81
81
  "fractional-indexing": "3.2.0",
@@ -109,8 +109,8 @@
109
109
  "yup": "0.32.9"
110
110
  },
111
111
  "devDependencies": {
112
- "@strapi/admin": "5.44.0",
113
- "@strapi/database": "5.44.0",
112
+ "@strapi/admin": "5.45.0",
113
+ "@strapi/database": "5.45.0",
114
114
  "@testing-library/react": "16.3.0",
115
115
  "@types/jest": "29.5.2",
116
116
  "@types/lodash": "^4.14.191",