@strapi/core 0.0.0-experimental.a9a5a36dd73072c19eadeff5f387e8286b2a4d22 → 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f

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 (98) hide show
  1. package/LICENSE +18 -3
  2. package/dist/core-api/service/collection-type.d.ts +2 -2
  3. package/dist/factories.js.map +1 -1
  4. package/dist/factories.mjs.map +1 -1
  5. package/dist/index.d.ts +14 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  10. package/dist/loaders/plugins/get-enabled-plugins.js +31 -3
  11. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  12. package/dist/loaders/plugins/get-enabled-plugins.mjs +9 -3
  13. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  14. package/dist/loaders/plugins/index.d.ts.map +1 -1
  15. package/dist/loaders/plugins/index.js +28 -1
  16. package/dist/loaders/plugins/index.js.map +1 -1
  17. package/dist/loaders/plugins/index.mjs +9 -1
  18. package/dist/loaders/plugins/index.mjs.map +1 -1
  19. package/dist/middlewares/cors.d.ts.map +1 -1
  20. package/dist/middlewares/cors.js +4 -0
  21. package/dist/middlewares/cors.js.map +1 -1
  22. package/dist/middlewares/cors.mjs +4 -0
  23. package/dist/middlewares/cors.mjs.map +1 -1
  24. package/dist/middlewares/query.d.ts.map +1 -1
  25. package/dist/middlewares/query.js.map +1 -1
  26. package/dist/middlewares/query.mjs.map +1 -1
  27. package/dist/middlewares/security.d.ts.map +1 -1
  28. package/dist/middlewares/security.js +1 -1
  29. package/dist/middlewares/security.js.map +1 -1
  30. package/dist/middlewares/security.mjs +1 -1
  31. package/dist/middlewares/security.mjs.map +1 -1
  32. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
  33. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  34. package/dist/migrations/database/5.0.0-discard-drafts.js +50 -11
  35. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  36. package/dist/migrations/database/5.0.0-discard-drafts.mjs +51 -12
  37. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  38. package/dist/providers/admin.d.ts.map +1 -1
  39. package/dist/providers/admin.js.map +1 -1
  40. package/dist/providers/admin.mjs.map +1 -1
  41. package/dist/registries/policies.d.ts +1 -1
  42. package/dist/registries/policies.d.ts.map +1 -1
  43. package/dist/registries/policies.js +1 -1
  44. package/dist/registries/policies.js.map +1 -1
  45. package/dist/registries/policies.mjs +1 -1
  46. package/dist/registries/policies.mjs.map +1 -1
  47. package/dist/services/content-api/index.d.ts +10 -12
  48. package/dist/services/content-api/index.d.ts.map +1 -1
  49. package/dist/services/content-api/permissions/index.d.ts +10 -12
  50. package/dist/services/content-api/permissions/index.d.ts.map +1 -1
  51. package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
  52. package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
  53. package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
  54. package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
  55. package/dist/services/cron.d.ts +3 -3
  56. package/dist/services/cron.d.ts.map +1 -1
  57. package/dist/services/cron.js.map +1 -1
  58. package/dist/services/cron.mjs.map +1 -1
  59. package/dist/services/document-service/repository.d.ts.map +1 -1
  60. package/dist/services/document-service/repository.js +42 -6
  61. package/dist/services/document-service/repository.js.map +1 -1
  62. package/dist/services/document-service/repository.mjs +43 -7
  63. package/dist/services/document-service/repository.mjs.map +1 -1
  64. package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
  65. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
  66. package/dist/services/document-service/utils/unidirectional-relations.js +58 -0
  67. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
  68. package/dist/services/document-service/utils/unidirectional-relations.mjs +58 -0
  69. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
  70. package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
  71. package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
  72. package/dist/services/entity-validator/blocks-validator.js +4 -3
  73. package/dist/services/entity-validator/blocks-validator.js.map +1 -1
  74. package/dist/services/entity-validator/blocks-validator.mjs +3 -3
  75. package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
  76. package/dist/services/entity-validator/index.d.ts +2 -1
  77. package/dist/services/entity-validator/index.d.ts.map +1 -1
  78. package/dist/services/entity-validator/index.js +10 -15
  79. package/dist/services/entity-validator/index.js.map +1 -1
  80. package/dist/services/entity-validator/index.mjs +14 -19
  81. package/dist/services/entity-validator/index.mjs.map +1 -1
  82. package/dist/services/entity-validator/validators.d.ts +32 -23
  83. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  84. package/dist/services/entity-validator/validators.js +137 -63
  85. package/dist/services/entity-validator/validators.js.map +1 -1
  86. package/dist/services/entity-validator/validators.mjs +136 -63
  87. package/dist/services/entity-validator/validators.mjs.map +1 -1
  88. package/dist/utils/filepath-to-prop-path.js +2 -2
  89. package/dist/utils/filepath-to-prop-path.js.map +1 -1
  90. package/dist/utils/filepath-to-prop-path.mjs +2 -2
  91. package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
  92. package/dist/utils/transform-content-types-to-models.d.ts +2 -2
  93. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  94. package/dist/utils/transform-content-types-to-models.js +2 -1
  95. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  96. package/dist/utils/transform-content-types-to-models.mjs +2 -1
  97. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  98. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs, { IParseOptions } from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = IParseOptions;\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n });\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config });\n};\n"],"names":[],"mappings":";AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AACb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAc,GAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACD;AAEM,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAQ;AAC3D;"}
1
+ {"version":3,"file":"query.mjs","sources":["../../src/middlewares/query.ts"],"sourcesContent":["import qs from 'qs';\nimport type Koa from 'koa';\nimport type { Core } from '@strapi/types';\n\ntype Config = Parameters<typeof qs.parse>[1];\n\nconst defaults: Config = {\n strictNullHandling: true,\n arrayLimit: 100,\n depth: 20,\n};\n\n/**\n * Body parser hook\n */\nconst addQsParser = (app: Koa, settings: Config) => {\n Object.defineProperty(app.request, 'query', {\n configurable: false,\n enumerable: true,\n /*\n * Get parsed query-string.\n */\n get() {\n const qstr = this.querystring;\n\n this._querycache = this._querycache || {};\n const cache = this._querycache;\n\n if (!cache[qstr]) {\n cache[qstr] = qs.parse(qstr, settings);\n }\n\n return cache[qstr];\n },\n\n /*\n * Set query-string as an object.\n */\n set(obj) {\n this.querystring = qs.stringify(obj);\n },\n } satisfies PropertyDescriptor & ThisType<Koa.BaseRequest>);\n\n return app;\n};\n\nexport const query: Core.MiddlewareFactory = (\n config: Partial<Config>,\n { strapi }: { strapi: Core.Strapi }\n) => {\n addQsParser(strapi.server.app, { ...defaults, ...config } as Config);\n};\n"],"names":[],"mappings":";AAMA,MAAM,WAAmB;AAAA,EACvB,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT;AAKA,MAAM,cAAc,CAAC,KAAU,aAAqB;AAC3C,SAAA,eAAe,IAAI,SAAS,SAAS;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA;AAAA;AAAA;AAAA,IAIZ,MAAM;AACJ,YAAM,OAAO,KAAK;AAEb,WAAA,cAAc,KAAK,eAAe,CAAA;AACvC,YAAM,QAAQ,KAAK;AAEf,UAAA,CAAC,MAAM,IAAI,GAAG;AAChB,cAAM,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ;AAAA,MACvC;AAEA,aAAO,MAAM,IAAI;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAK;AACF,WAAA,cAAc,GAAG,UAAU,GAAG;AAAA,IACrC;AAAA,EAAA,CACwD;AAEnD,SAAA;AACT;AAEO,MAAM,QAAgC,CAC3C,QACA,EAAE,aACC;AACS,cAAA,OAAO,OAAO,KAAK,EAAE,GAAG,UAAU,GAAG,QAAkB;AACrE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAkC3D,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAkEjD,CAAC"}
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/middlewares/security.ts"],"names":[],"mappings":"AACA,OAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAkC3D,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAmEjD,CAAC"}
@@ -62,7 +62,7 @@ const security = (config, { strapi }) => (ctx, next) => {
62
62
  }
63
63
  });
64
64
  }
65
- if (["development", "test"].includes(process.env.NODE_ENV ?? "") && ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
65
+ if (["development", "test"].includes(process.env.NODE_ENV ?? "") && ctx.method === "GET" && ctx.path.startsWith(strapi.config.get("admin.path"))) {
66
66
  helmetConfig = mergeConfig(helmetConfig, {
67
67
  contentSecurityPolicy: {
68
68
  directives: {
@@ -1 +1 @@
1
- {"version":3,"file":"security.js","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ['/admin'].some((str) => ctx.path.startsWith(str))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":["mergeWith","defaultsDeep","helmet"],"mappings":";;;;;;AAOA,MAAM,WAAmB;AAAA,EACvB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,IACrB,aAAa;AAAA,IACb,YAAY;AAAA,MACV,eAAe,CAAC,UAAU,QAAQ;AAAA,MAClC,WAAW,CAAC,UAAU,SAAS,SAAS,iCAAiC;AAAA,MACzE,aAAa,CAAC,UAAU,SAAS,OAAO;AAAA,MACxC,yBAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,mBAAmB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,EACV;AACF;AAEA,MAAM,cAAc,CAAC,gBAAwB,cAAsB;AAC1D,SAAAA,GAAA;AAAA,IACL,CAAC,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D;AACA,mBAAe,YAAY,cAAc;AAAA,MACvC,uBAAuB;AAAA,QACrB,YAAY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,SAAS,UAAU,KAAK;AAAA,QACpD;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAOC,gBAAO,QAAA,YAAY,EAAE,KAAK,IAAI;AACvC;;"}
1
+ {"version":3,"file":"security.js","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ctx.path.startsWith(strapi.config.get('admin.path'))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":["mergeWith","defaultsDeep","helmet"],"mappings":";;;;;;AAOA,MAAM,WAAmB;AAAA,EACvB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,IACrB,aAAa;AAAA,IACb,YAAY;AAAA,MACV,eAAe,CAAC,UAAU,QAAQ;AAAA,MAClC,WAAW,CAAC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,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAChF,mBAAe,YAAY,cAAc;AAAA,MACvC,2BAA2B;AAAA;AAAA,MAC3B,uBAAuB;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAYE,MAAA,CAAC,eAAe,MAAM,EAAE,SAAS,QAAQ,IAAI,YAAY,EAAE,KAC3D,IAAI,WAAW,SACf,IAAI,KAAK,WAAW,OAAO,OAAO,IAAI,YAAY,CAAC,GACnD;AACA,mBAAe,YAAY,cAAc;AAAA,MACvC,uBAAuB;AAAA,QACrB,YAAY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,SAAS,UAAU,KAAK;AAAA,QACpD;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAOC,gBAAO,QAAA,YAAY,EAAE,KAAK,IAAI;AACvC;;"}
@@ -58,7 +58,7 @@ const security = (config, { strapi }) => (ctx, next) => {
58
58
  }
59
59
  });
60
60
  }
61
- if (["development", "test"].includes(process.env.NODE_ENV ?? "") && ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
61
+ if (["development", "test"].includes(process.env.NODE_ENV ?? "") && ctx.method === "GET" && ctx.path.startsWith(strapi.config.get("admin.path"))) {
62
62
  helmetConfig = mergeConfig(helmetConfig, {
63
63
  contentSecurityPolicy: {
64
64
  directives: {
@@ -1 +1 @@
1
- {"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ['/admin'].some((str) => ctx.path.startsWith(str))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":[],"mappings":";;AAOA,MAAM,WAAmB;AAAA,EACvB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,IACrB,aAAa;AAAA,IACb,YAAY;AAAA,MACV,eAAe,CAAC,UAAU,QAAQ;AAAA,MAClC,WAAW,CAAC,UAAU,SAAS,SAAS,iCAAiC;AAAA,MACzE,aAAa,CAAC,UAAU,SAAS,OAAO;AAAA,MACxC,yBAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,mBAAmB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,EACV;AACF;AAEA,MAAM,cAAc,CAAC,gBAAwB,cAAsB;AAC1D,SAAA;AAAA,IACL,CAAC,KAAK,QAAS,MAAM,QAAQ,GAAG,KAAK,MAAM,QAAQ,GAAG,IAAI,IAAI,OAAO,GAAG,IAAI;AAAA,IAC5E;AAAA,IACA;AAAA,EAAA;AAEJ;AAEa,MAAA,WACX,CAAC,QAAQ,EAAE,aACX,CAAC,KAAK,SAAS;AACT,MAAA,eAAuB,aAAa,UAAU,MAAM;AAElD,QAAA,eAAe,CAAC,gBAAgB;AAEtC,QAAM,aAKF;AAAA,IACF,cAAc,CAAC,UAAU,mBA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sDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ctx.path.startsWith(strapi.config.get('admin.path'))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":[],"mappings":";;AAOA,MAAM,WAAmB;AAAA,EACvB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,IACrB,aAAa;AAAA,IACb,YAAY;AAAA,MACV,eAAe,CAAC,UAAU,QAAQ;AAAA,MAClC,WAAW,CAAC,UAAU,SAAS,SAAS,iCAAiC;AAAA,MACzE,aAAa,CAAC,UAAU,SAAS,OAAO;AAAA,MACxC,yBAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,mBAAmB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,EACV;AACF;AAEA,MAAM,cAAc,CAAC,gBAAwB,cAAsB;AAC1D,SAAA;AAAA,IACL,CAAC,KAAK,QAAS,MAAM,QAAQ,GAAG,K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AY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,SAAS,UAAU,KAAK;AAAA,QACpD;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAO,OAAO,YAAY,EAAE,KAAK,IAAI;AACvC;"}
@@ -1,3 +1,15 @@
1
+ /**
2
+ * This migration is responsible for creating the draft counterpart for all the entries that were in a published state.
3
+ *
4
+ * In v4, entries could either be in a draft or published state, but not both at the same time.
5
+ * In v5, we introduced the concept of document, and an entry can be in a draft or published state.
6
+ *
7
+ * This means the migration needs to create the draft counterpart if an entry was published.
8
+ *
9
+ * This migration performs the following steps:
10
+ * 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.
11
+ * 2. Using the document service, discard those same drafts to copy its relations.
12
+ */
1
13
  import type { Database, Migration } from '@strapi/database';
2
14
  type DocumentVersion = {
3
15
  documentId: string;
@@ -16,15 +28,6 @@ export declare function getBatchToDiscard({ db, trx, uid, batchSize, }: {
16
28
  uid: string;
17
29
  batchSize?: number;
18
30
  }): AsyncGenerator<DocumentVersion[], void, unknown>;
19
- /**
20
- * On V4 there was no concept of document, and an entry could be in a draft or published state.
21
- * But not both at the same time.
22
- *
23
- * On V5 we introduced the concept of document, and an entry can be in a draft or published state,
24
- * with the requirement that a document must always have a draft.
25
- *
26
- * This migration creates the document draft counterpart for all the entries that were in a published state.
27
- */
28
31
  export declare const discardDocumentDrafts: Migration;
29
32
  export {};
30
33
  //# sourceMappingURL=5.0.0-discard-drafts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAiCD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,SASnC,CAAC"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAgF3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAwCD,eAAO,MAAM,qBAAqB,EAAE,SAQnC,CAAC"}
@@ -1,6 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const strapiUtils = require("@strapi/utils");
4
+ const hasDraftAndPublish = async (trx, meta) => {
5
+ const hasTable = await trx.schema.hasTable(meta.tableName);
6
+ if (!hasTable) {
7
+ return false;
8
+ }
9
+ const uid = meta.uid;
10
+ const model = strapi.getModel(uid);
11
+ const hasDP = strapiUtils.contentTypes.hasDraftAndPublish(model);
12
+ if (!hasDP) {
13
+ return false;
14
+ }
15
+ return true;
16
+ };
17
+ async function copyPublishedEntriesToDraft({
18
+ db,
19
+ trx,
20
+ uid
21
+ }) {
22
+ const meta = db.metadata.get(uid);
23
+ const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute) => {
24
+ if (["id"].includes(attribute.columnName)) {
25
+ return acc;
26
+ }
27
+ if (strapiUtils.contentTypes.isScalarAttribute(attribute)) {
28
+ acc.push(attribute.columnName);
29
+ }
30
+ return acc;
31
+ }, []);
32
+ await trx.into(trx.raw(`${meta.tableName} (${scalarAttributes.join(", ")})`)).insert((subQb) => {
33
+ subQb.select(
34
+ ...scalarAttributes.map((att) => {
35
+ if (att === "published_at") {
36
+ return trx.raw("NULL as published_at");
37
+ }
38
+ return att;
39
+ })
40
+ ).from(meta.tableName).whereNotNull("published_at");
41
+ });
42
+ }
4
43
  async function* getBatchToDiscard({
5
44
  db,
6
45
  trx,
@@ -19,19 +58,19 @@ async function* getBatchToDiscard({
19
58
  }
20
59
  }
21
60
  const migrateUp = async (trx, db) => {
61
+ const dpModels = [];
22
62
  for (const meta of db.metadata.values()) {
23
- const hasTable = await trx.schema.hasTable(meta.tableName);
24
- if (!hasTable) {
25
- continue;
63
+ const hasDP = await hasDraftAndPublish(trx, meta);
64
+ if (hasDP) {
65
+ dpModels.push(meta);
26
66
  }
27
- const uid = meta.uid;
28
- const model = strapi.getModel(uid);
29
- const hasDP = strapiUtils.contentTypes.hasDraftAndPublish(model);
30
- if (!hasDP) {
31
- continue;
32
- }
33
- const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
34
- for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
67
+ }
68
+ for (const model of dpModels) {
69
+ await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });
70
+ }
71
+ for (const model of dpModels) {
72
+ const discardDraft = async (entry) => strapi.documents(model.uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
73
+ for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {
35
74
  await strapiUtils.async.map(batch, discardDraft, { concurrency: 10 });
36
75
  }
37
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.js","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["contentTypes","async"],"mappings":";;;AAcA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAKG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAEd,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,CAAC,MAAM,cAAc,QAAQ,CAAC,EACrC,MAAM,EAAE,aAAa,EAAE,KAAK,KAAO,EAAA,CAAC,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,UAAA,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AACnD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAG,EAEb,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG;AACvE,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;;;"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.js","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/**\n * This migration is responsible for creating the draft counterpart for all the entries that were in a published state.\n *\n * In v4, entries could either be in a draft or published state, but not both at the same time.\n * In v5, we introduced the concept of document, and an entry can be in a draft or published state.\n *\n * This means the migration needs to create the draft counterpart if an entry was published.\n *\n * This migration performs the following steps:\n * 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.\n * 2. Using the document service, discard those same drafts to copy its relations.\n */\n\n/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Check if the model has draft and publish enabled.\n */\nconst hasDraftAndPublish = async (trx: Knex, meta: any) => {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n return false;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Copy all the published entries to draft entries, without it's components, dynamic zones or relations.\n * This ensures all necessary draft's exist before copying it's relations.\n */\nasync function copyPublishedEntriesToDraft({\n db,\n trx,\n uid,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n}) {\n // Extract all scalar attributes to use in the insert query\n const meta = db.metadata.get(uid);\n\n // Get scalar attributes that will be copied over the new draft\n const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypes.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * Query to copy the published entries into draft entries.\n *\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n await trx\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(trx.raw(`${meta.tableName} (${scalarAttributes.join(', ')})`))\n .insert((subQb: typeof trx) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...scalarAttributes.map((att: string) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return trx.raw('NULL as published_at');\n }\n\n return att;\n })\n )\n .from(meta.tableName)\n // Only select entries that were published\n .whereNotNull('published_at');\n });\n}\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\n/**\n * 2 pass migration to create the draft entries for all the published entries.\n * And then discard the drafts to copy the relations.\n */\nconst migrateUp = async (trx: Knex, db: Database) => {\n const dpModels = [];\n for (const meta of db.metadata.values()) {\n const hasDP = await hasDraftAndPublish(trx, meta);\n if (hasDP) {\n dpModels.push(meta);\n }\n }\n\n /**\n * Create plain draft entries for all the entries that were published.\n */\n for (const model of dpModels) {\n await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });\n }\n\n /**\n * Discard the drafts will copy the relations from the published entries to the newly created drafts.\n *\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["contentTypes","async"],"mappings":";;;AAwBA,MAAM,qBAAqB,OAAO,KAAW,SAAc;AACzD,QAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,MAAI,CAAC,UAAU;AACN,WAAA;AAAA,EACT;AAEA,QAAM,MAAM,KAAK;AACX,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,QAAA,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAMA,eAAe,4BAA4B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,OAAO,GAAG,SAAS,IAAI,GAAG;AAG1B,QAAA,mBAAmB,OAAO,OAAO,KAAK,UA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T,eAAS,KAAK,IAAI;AAAA,IACpB;AAAA,EACF;AAKA,aAAW,SAAS,UAAU;AAC5B,UAAM,4BAA4B,EAAE,IAAI,KAAK,KAAK,MAAM,KAAK;AAAA,EAC/D;AAQA,aAAW,SAAS,UAAU;AAC5B,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,MAAM,GAAsB,EACtC,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAEvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG;AACxE,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAEO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AACV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;;;"}
@@ -1,4 +1,43 @@
1
- import { contentTypes, async } from "@strapi/utils";
1
+ import { async, contentTypes } from "@strapi/utils";
2
+ const hasDraftAndPublish = async (trx, meta) => {
3
+ const hasTable = await trx.schema.hasTable(meta.tableName);
4
+ if (!hasTable) {
5
+ return false;
6
+ }
7
+ const uid = meta.uid;
8
+ const model = strapi.getModel(uid);
9
+ const hasDP = contentTypes.hasDraftAndPublish(model);
10
+ if (!hasDP) {
11
+ return false;
12
+ }
13
+ return true;
14
+ };
15
+ async function copyPublishedEntriesToDraft({
16
+ db,
17
+ trx,
18
+ uid
19
+ }) {
20
+ const meta = db.metadata.get(uid);
21
+ const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute) => {
22
+ if (["id"].includes(attribute.columnName)) {
23
+ return acc;
24
+ }
25
+ if (contentTypes.isScalarAttribute(attribute)) {
26
+ acc.push(attribute.columnName);
27
+ }
28
+ return acc;
29
+ }, []);
30
+ await trx.into(trx.raw(`${meta.tableName} (${scalarAttributes.join(", ")})`)).insert((subQb) => {
31
+ subQb.select(
32
+ ...scalarAttributes.map((att) => {
33
+ if (att === "published_at") {
34
+ return trx.raw("NULL as published_at");
35
+ }
36
+ return att;
37
+ })
38
+ ).from(meta.tableName).whereNotNull("published_at");
39
+ });
40
+ }
2
41
  async function* getBatchToDiscard({
3
42
  db,
4
43
  trx,
@@ -17,19 +56,19 @@ async function* getBatchToDiscard({
17
56
  }
18
57
  }
19
58
  const migrateUp = async (trx, db) => {
59
+ const dpModels = [];
20
60
  for (const meta of db.metadata.values()) {
21
- const hasTable = await trx.schema.hasTable(meta.tableName);
22
- if (!hasTable) {
23
- continue;
61
+ const hasDP = await hasDraftAndPublish(trx, meta);
62
+ if (hasDP) {
63
+ dpModels.push(meta);
24
64
  }
25
- const uid = meta.uid;
26
- const model = strapi.getModel(uid);
27
- const hasDP = contentTypes.hasDraftAndPublish(model);
28
- if (!hasDP) {
29
- continue;
30
- }
31
- const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
32
- for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
65
+ }
66
+ for (const model of dpModels) {
67
+ await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });
68
+ }
69
+ for (const model of dpModels) {
70
+ const discardDraft = async (entry) => strapi.documents(model.uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
71
+ for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {
33
72
  await async.map(batch, discardDraft, { concurrency: 10 });
34
73
  }
35
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";AAcA,gBAA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"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/**\n * This migration is responsible for creating the draft counterpart for all the entries that were in a published state.\n *\n * In v4, entries could either be in a draft or published state, but not both at the same time.\n * In v5, we introduced the concept of document, and an entry can be in a draft or published state.\n *\n * This means the migration needs to create the draft counterpart if an entry was published.\n *\n * This migration performs the following steps:\n * 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.\n * 2. Using the document service, discard those same drafts to copy its relations.\n */\n\n/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Check if the model has draft and publish enabled.\n */\nconst hasDraftAndPublish = async (trx: Knex, meta: any) => {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n return false;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Copy all the published entries to draft entries, without it's components, dynamic zones or relations.\n * This ensures all necessary draft's exist before copying it's relations.\n */\nasync function copyPublishedEntriesToDraft({\n db,\n trx,\n uid,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n}) {\n // Extract all scalar attributes to use in the insert query\n const meta = db.metadata.get(uid);\n\n // Get scalar attributes that will be copied over the new draft\n const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypes.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * Query to copy the published entries into draft entries.\n *\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n await trx\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(trx.raw(`${meta.tableName} (${scalarAttributes.join(', ')})`))\n .insert((subQb: typeof trx) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...scalarAttributes.map((att: string) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return trx.raw('NULL as published_at');\n }\n\n return att;\n })\n )\n .from(meta.tableName)\n // Only select entries that were published\n .whereNotNull('published_at');\n });\n}\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\n/**\n * 2 pass migration to create the draft entries for all the published entries.\n * And then discard the drafts to copy the relations.\n */\nconst migrateUp = async (trx: Knex, db: Database) => {\n const dpModels = [];\n for (const meta of db.metadata.values()) {\n const hasDP = await hasDraftAndPublish(trx, meta);\n if (hasDP) {\n dpModels.push(meta);\n }\n }\n\n /**\n * Create plain draft entries for all the entries that were published.\n */\n for (const model of dpModels) {\n await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });\n }\n\n /**\n * Discard the drafts will copy the relations from the published entries to the newly created drafts.\n *\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";AAwBA,MAAM,qBAAqB,OAAO,KAAW,SAAc;AACzD,QAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,MAAI,CAAC,UAAU;AACN,WAAA;AAAA,EACT;AAEA,QAAM,MAAM,KAAK;AACX,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,QAAA,QAAQ,aAAa,mBAAmB,KAAK;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAMA,eAAe,4BAA4B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,OAAO,GAAG,SAAS,IAAI,GAAG;AAG1B,QAAA,mBAAmB,OAAO,OAAO,KAAK,UAAU,EAAE,OAAO,CAAC,KAAK,cAAmB;AACtF,QAAI,CAAC,IAAI,EAAE,SAAS,UAAU,UAAU,GAAG;AAClC,aAAA;AAAA,IACT;AAEI,QAAA,aAAa,kBAAkB,SAAS,GAAG;AACzC,UAAA,KAAK,UAAU,UAAU;AAAA,IAC/B;AAEO,WAAA;AAAA,EACT,GAAG,CAAc,CAAA;AASjB,QAAM,IAEH,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,KAAK,iBAAiB,KAAK,IAAI,CAAC,GAAG,CAAC,EAClE,OAAO,CAAC,UAAsB;AAG1B,UAAA;AAAA,MACC,GAAG,iBAAiB,IAAI,CAAC,QAAgB;AAEvC,YAAI,QAAQ,gBAAgB;AACnB,iBAAA,IAAI,IAAI,sBAAsB;AAAA,QACvC;AAEO,eAAA;AAAA,MAAA,CACR;AAAA,IAAA,EAEF,KAAK,KAAK,SA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A,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/providers/admin.ts"],"names":[],"mappings":";AAGA,wBAkBG"}
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/providers/admin.ts"],"names":[],"mappings":";AAGA,wBAmBG"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.js","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":["defineProvider","loadAdmin"],"mappings":";;;AAGA,MAAA,QAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AACX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAMC,QAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;;"}
1
+ {"version":3,"file":"admin.js","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n // eslint-disable-next-line node/no-missing-require\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":["defineProvider","loadAdmin"],"mappings":";;;AAGA,MAAA,QAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AAEX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAMC,QAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AACX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAM,UAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;"}
1
+ {"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n // eslint-disable-next-line node/no-missing-require\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AAEX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAM,UAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;"}
@@ -13,7 +13,7 @@ declare const policiesRegistry: () => {
13
13
  /**
14
14
  * Returns this list of registered policies uids
15
15
  */
16
- keys(): IterableIterator<string>;
16
+ keys(): string[];
17
17
  /**
18
18
  * Returns the instance of a policy. Instantiate the policy if not already done
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;IAKH;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAG/C;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAK/C;;OAEG;sBACe,MAAM;IAIxB;;OAEG;aACM,MAAM,UAAU,KAAK,MAAM;IAKpC;;OAEG;mBACY,MAAM,eAAe,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;IAa/D;;OAEG;oBACa,YAAY,GAAG,YAAY,EAAE,kBAAkB,aAAa;;;;CAW/E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;IAMH;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAG/C;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAK/C;;OAEG;sBACe,MAAM;IAIxB;;OAEG;aACM,MAAM,UAAU,KAAK,MAAM;IAKpC;;OAEG;mBACY,MAAM,eAAe,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;IAa/D;;OAEG;oBACa,YAAY,GAAG,YAAY,EAAE,kBAAkB,aAAa;;;;CAW/E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -49,7 +49,7 @@ const policiesRegistry = () => {
49
49
  * Returns this list of registered policies uids
50
50
  */
51
51
  keys() {
52
- return policies.keys();
52
+ return Array.from(policies.keys());
53
53
  },
54
54
  /**
55
55
  * Returns the instance of a policy. Instantiate the policy if not already done
@@ -1 +1 @@
1
- {"version":3,"file":"policies.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","hasNamespace","addNamespace","has","castArray"],"mappings":";;;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AAEA,QAAI,OAAO,WAAW;AACpB,aAAO,UAAU,MAAM;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAChB;AA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.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","hasNamespace","addNamespace","has","castArray"],"mappings":";;;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,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YAAY,QAAQ,CAAC;AAAA,IACtF;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,QAAqB;AAC3B,eAAA,IAAI,KAAK,MAAM;AACjB,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,aAA0C;AAC/D,iBAAW,cAAc,OAAO,KAAK,WAAW,GAAG;AAC3C,cAAA,SAAS,YAAY,UAAU;AAC/B,cAAA,MAAMG,UAAAA,aAAa,YAAYH,WAAS;AAE1C,YAAAI,GAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAOC,GAAU,UAAA,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -48,7 +48,7 @@ const policiesRegistry = () => {
48
48
  * Returns this list of registered policies uids
49
49
  */
50
50
  keys() {
51
- return policies.keys();
51
+ return Array.from(policies.keys());
52
52
  },
53
53
  /**
54
54
  * Returns the instance of a policy. Instantiate the policy if not already done
@@ -1 +1 @@
1
- {"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;A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;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAO,UAAU,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AAEA,QAAI,OAAO,WAAW;AACpB,aAAO,UAAU,MAAM;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAChB;AAEO,SAAA;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i: Core.Strapi) => {
8
8
  engine: import("@strapi/permissions/dist/engine").Engine;
9
9
  providers: {
10
10
  action: {
11
- register(action: string, payload: Record<string, unknown>): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
11
+ register(action: string, payload: Record<string, unknown>): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
12
12
  hooks: import("@strapi/utils/dist/provider-factory").ProviderHooksMap;
13
- delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
13
+ delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
14
14
  get(key: string): {
15
15
  [x: string]: unknown;
16
16
  } | undefined;
17
- getWhere(filters?: Record<string, unknown> | undefined): {
18
- [x: string]: unknown;
19
- }[];
20
17
  values(): {
21
18
  [x: string]: unknown;
22
19
  }[];
23
20
  keys(): string[];
24
21
  has(key: string): boolean;
25
22
  size(): number;
26
- clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
23
+ clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider<{
24
+ [x: string]: unknown;
25
+ }>>;
27
26
  };
28
27
  condition: {
29
- register(condition: import("./permissions/providers/condition").Condition): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
28
+ register(condition: import("./permissions/providers/condition").Condition): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
30
29
  hooks: import("@strapi/utils/dist/provider-factory").ProviderHooksMap;
31
- delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
30
+ delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
32
31
  get(key: string): {
33
32
  [x: string]: unknown;
34
33
  } | undefined;
35
- getWhere(filters?: Record<string, unknown> | undefined): {
36
- [x: string]: unknown;
37
- }[];
38
34
  values(): {
39
35
  [x: string]: unknown;
40
36
  }[];
41
37
  keys(): string[];
42
38
  has(key: string): boolean;
43
39
  size(): number;
44
- clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
40
+ clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider<{
41
+ [x: string]: unknown;
42
+ }>>;
45
43
  };
46
44
  };
47
45
  registerActions: () => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAO,MAAM,eAAe,CAAC;AAgB/C;;GAEG;AACH,QAAA,MAAM,gBAAgB,WAAY,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgF5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAO,MAAM,eAAe,CAAC;AAgB/C;;GAEG;AACH,QAAA,MAAM,gBAAgB,WAAY,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgF5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -7,40 +7,38 @@ declare const _default: (strapi: Core.Strapi) => {
7
7
  engine: import("@strapi/permissions/dist/engine").Engine;
8
8
  providers: {
9
9
  action: {
10
- register(action: string, payload: Record<string, unknown>): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
10
+ register(action: string, payload: Record<string, unknown>): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
11
11
  hooks: import("@strapi/utils/dist/provider-factory").ProviderHooksMap;
12
- delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
12
+ delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
13
13
  get(key: string): {
14
14
  [x: string]: unknown;
15
15
  } | undefined;
16
- getWhere(filters?: Record<string, unknown> | undefined): {
17
- [x: string]: unknown;
18
- }[];
19
16
  values(): {
20
17
  [x: string]: unknown;
21
18
  }[];
22
19
  keys(): string[];
23
20
  has(key: string): boolean;
24
21
  size(): number;
25
- clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
22
+ clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider<{
23
+ [x: string]: unknown;
24
+ }>>;
26
25
  };
27
26
  condition: {
28
- register(condition: import("./providers/condition").Condition): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
27
+ register(condition: import("./providers/condition").Condition): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
29
28
  hooks: import("@strapi/utils/dist/provider-factory").ProviderHooksMap;
30
- delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
29
+ delete(key: string): Promise<import("@strapi/utils/dist/provider-factory").Provider<unknown>>;
31
30
  get(key: string): {
32
31
  [x: string]: unknown;
33
32
  } | undefined;
34
- getWhere(filters?: Record<string, unknown> | undefined): {
35
- [x: string]: unknown;
36
- }[];
37
33
  values(): {
38
34
  [x: string]: unknown;
39
35
  }[];
40
36
  keys(): string[];
41
37
  has(key: string): boolean;
42
38
  size(): number;
43
- clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider>;
39
+ clear(): Promise<import("@strapi/utils/dist/provider-factory").Provider<{
40
+ [x: string]: unknown;
41
+ }>>;
44
42
  };
45
43
  };
46
44
  registerActions: () => Promise<void>;