@strapi/core 0.0.0-experimental.90ca9123352ed07e0a9cedaf4bcad1475e74137f → 0.0.0-experimental.e3e48deb89bd0a1b6cc69b698696566fa7854a95

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 (254) hide show
  1. package/dist/Strapi.d.ts +5 -3
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +19 -7
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +19 -7
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/configuration/index.d.ts.map +1 -1
  8. package/dist/configuration/index.js +4 -4
  9. package/dist/configuration/index.js.map +1 -1
  10. package/dist/configuration/index.mjs +1 -1
  11. package/dist/configuration/index.mjs.map +1 -1
  12. package/dist/configuration/urls.d.ts +8 -0
  13. package/dist/configuration/urls.d.ts.map +1 -0
  14. package/dist/configuration/urls.js +68 -0
  15. package/dist/configuration/urls.js.map +1 -0
  16. package/dist/configuration/urls.mjs +66 -0
  17. package/dist/configuration/urls.mjs.map +1 -0
  18. package/dist/core-api/controller/collection-type.js.map +1 -1
  19. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  20. package/dist/core-api/controller/index.d.ts.map +1 -1
  21. package/dist/core-api/controller/index.js +6 -1
  22. package/dist/core-api/controller/index.js.map +1 -1
  23. package/dist/core-api/controller/index.mjs +6 -1
  24. package/dist/core-api/controller/index.mjs.map +1 -1
  25. package/dist/core-api/controller/single-type.js.map +1 -1
  26. package/dist/core-api/controller/single-type.mjs.map +1 -1
  27. package/dist/core-api/controller/transform.d.ts +8 -7
  28. package/dist/core-api/controller/transform.d.ts.map +1 -1
  29. package/dist/core-api/controller/transform.js +16 -7
  30. package/dist/core-api/controller/transform.js.map +1 -1
  31. package/dist/core-api/controller/transform.mjs +16 -7
  32. package/dist/core-api/controller/transform.mjs.map +1 -1
  33. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  34. package/dist/core-api/service/collection-type.js.map +1 -1
  35. package/dist/core-api/service/collection-type.mjs.map +1 -1
  36. package/dist/core-api/service/single-type.d.ts +3 -2
  37. package/dist/core-api/service/single-type.d.ts.map +1 -1
  38. package/dist/core-api/service/single-type.js +14 -3
  39. package/dist/core-api/service/single-type.js.map +1 -1
  40. package/dist/core-api/service/single-type.mjs +14 -3
  41. package/dist/core-api/service/single-type.mjs.map +1 -1
  42. package/dist/domain/content-type/index.d.ts.map +1 -1
  43. package/dist/domain/content-type/index.js +3 -0
  44. package/dist/domain/content-type/index.js.map +1 -1
  45. package/dist/domain/content-type/index.mjs +3 -0
  46. package/dist/domain/content-type/index.mjs.map +1 -1
  47. package/dist/domain/content-type/validator.d.ts.map +1 -1
  48. package/dist/domain/content-type/validator.js +1 -1
  49. package/dist/domain/content-type/validator.js.map +1 -1
  50. package/dist/domain/content-type/validator.mjs +2 -2
  51. package/dist/domain/content-type/validator.mjs.map +1 -1
  52. package/dist/domain/module/index.d.ts.map +1 -1
  53. package/dist/domain/module/index.js +2 -3
  54. package/dist/domain/module/index.js.map +1 -1
  55. package/dist/domain/module/index.mjs +2 -3
  56. package/dist/domain/module/index.mjs.map +1 -1
  57. package/dist/ee/index.js.map +1 -1
  58. package/dist/ee/index.mjs.map +1 -1
  59. package/dist/loaders/apis.js +1 -1
  60. package/dist/loaders/apis.js.map +1 -1
  61. package/dist/loaders/apis.mjs +2 -2
  62. package/dist/loaders/apis.mjs.map +1 -1
  63. package/dist/loaders/plugins/get-enabled-plugins.js +1 -1
  64. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  65. package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
  66. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  67. package/dist/middlewares/security.d.ts.map +1 -1
  68. package/dist/middlewares/security.js +2 -2
  69. package/dist/middlewares/security.js.map +1 -1
  70. package/dist/middlewares/security.mjs +2 -2
  71. package/dist/middlewares/security.mjs.map +1 -1
  72. package/dist/migrations/draft-publish.d.ts +17 -0
  73. package/dist/migrations/draft-publish.d.ts.map +1 -0
  74. package/dist/migrations/draft-publish.js +59 -0
  75. package/dist/migrations/draft-publish.js.map +1 -0
  76. package/dist/migrations/draft-publish.mjs +59 -0
  77. package/dist/migrations/draft-publish.mjs.map +1 -0
  78. package/dist/registries/config.d.ts +2 -2
  79. package/dist/registries/config.d.ts.map +1 -1
  80. package/dist/registries/config.js +14 -6
  81. package/dist/registries/config.js.map +1 -1
  82. package/dist/registries/config.mjs +15 -5
  83. package/dist/registries/config.mjs.map +1 -1
  84. package/dist/services/document-service/common.d.ts +2 -2
  85. package/dist/services/document-service/common.d.ts.map +1 -1
  86. package/dist/services/document-service/common.js.map +1 -1
  87. package/dist/services/document-service/common.mjs.map +1 -1
  88. package/dist/services/document-service/draft-and-publish.d.ts +9 -23
  89. package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
  90. package/dist/services/document-service/draft-and-publish.js +37 -9
  91. package/dist/services/document-service/draft-and-publish.js.map +1 -1
  92. package/dist/services/document-service/draft-and-publish.mjs +38 -10
  93. package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
  94. package/dist/services/document-service/index.d.ts.map +1 -1
  95. package/dist/services/document-service/index.js +4 -4
  96. package/dist/services/document-service/index.js.map +1 -1
  97. package/dist/services/document-service/index.mjs +2 -2
  98. package/dist/services/document-service/index.mjs.map +1 -1
  99. package/dist/services/document-service/internationalization.d.ts +2 -1
  100. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  101. package/dist/services/document-service/internationalization.js +14 -0
  102. package/dist/services/document-service/internationalization.js.map +1 -1
  103. package/dist/services/document-service/internationalization.mjs +15 -1
  104. package/dist/services/document-service/internationalization.mjs.map +1 -1
  105. package/dist/services/document-service/repository.d.ts +3 -0
  106. package/dist/services/document-service/repository.d.ts.map +1 -0
  107. package/dist/services/document-service/repository.js +295 -0
  108. package/dist/services/document-service/repository.js.map +1 -0
  109. package/dist/services/document-service/repository.mjs +295 -0
  110. package/dist/services/document-service/repository.mjs.map +1 -0
  111. package/dist/services/document-service/transform/fields.d.ts.map +1 -1
  112. package/dist/services/document-service/transform/fields.js +11 -10
  113. package/dist/services/document-service/transform/fields.js.map +1 -1
  114. package/dist/services/document-service/transform/fields.mjs +11 -10
  115. package/dist/services/document-service/transform/fields.mjs.map +1 -1
  116. package/dist/services/document-service/transform/id-map.d.ts +1 -1
  117. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  118. package/dist/services/document-service/transform/id-map.js +15 -9
  119. package/dist/services/document-service/transform/id-map.js.map +1 -1
  120. package/dist/services/document-service/transform/id-map.mjs +16 -10
  121. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  122. package/dist/services/document-service/transform/id-transform.d.ts +4 -25
  123. package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
  124. package/dist/services/document-service/transform/id-transform.js +19 -43
  125. package/dist/services/document-service/transform/id-transform.js.map +1 -1
  126. package/dist/services/document-service/transform/id-transform.mjs +20 -44
  127. package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
  128. package/dist/services/document-service/transform/populate.d.ts +5 -2
  129. package/dist/services/document-service/transform/populate.d.ts.map +1 -1
  130. package/dist/services/document-service/transform/populate.js +0 -10
  131. package/dist/services/document-service/transform/populate.js.map +1 -1
  132. package/dist/services/document-service/transform/populate.mjs +0 -10
  133. package/dist/services/document-service/transform/populate.mjs.map +1 -1
  134. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +1 -1
  135. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  136. package/dist/services/document-service/transform/relations/extract/data-ids.js +28 -14
  137. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  138. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +28 -14
  139. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  140. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +1 -1
  141. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  142. package/dist/services/document-service/transform/relations/transform/data-ids.js +65 -39
  143. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  144. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +66 -40
  145. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  146. package/dist/services/document-service/transform/relations/utils/data.d.ts +2 -4
  147. package/dist/services/document-service/transform/relations/utils/data.d.ts.map +1 -1
  148. package/dist/services/document-service/transform/relations/utils/data.js +1 -1
  149. package/dist/services/document-service/transform/relations/utils/data.js.map +1 -1
  150. package/dist/services/document-service/transform/relations/utils/data.mjs +1 -1
  151. package/dist/services/document-service/transform/relations/utils/data.mjs.map +1 -1
  152. package/dist/services/document-service/transform/relations/utils/dp.d.ts +10 -0
  153. package/dist/services/document-service/transform/relations/utils/dp.d.ts.map +1 -0
  154. package/dist/services/document-service/transform/relations/utils/dp.js +25 -0
  155. package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -0
  156. package/dist/services/document-service/transform/relations/utils/dp.mjs +25 -0
  157. package/dist/services/document-service/transform/relations/utils/dp.mjs.map +1 -0
  158. package/dist/services/document-service/transform/relations/utils/i18n.d.ts +2 -2
  159. package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
  160. package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
  161. package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
  162. package/dist/services/document-service/transform/relations/utils/types.d.ts +9 -2
  163. package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
  164. package/dist/services/document-service/transform/types.d.ts +1 -1
  165. package/dist/services/document-service/transform/types.d.ts.map +1 -1
  166. package/dist/services/document-service/utils/populate.d.ts +8 -1
  167. package/dist/services/document-service/utils/populate.d.ts.map +1 -1
  168. package/dist/services/document-service/utils/populate.js +5 -5
  169. package/dist/services/document-service/utils/populate.js.map +1 -1
  170. package/dist/services/document-service/utils/populate.mjs +5 -5
  171. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  172. package/dist/services/entity-service/components.d.ts +1 -4
  173. package/dist/services/entity-service/components.d.ts.map +1 -1
  174. package/dist/services/entity-service/components.js +13 -99
  175. package/dist/services/entity-service/components.js.map +1 -1
  176. package/dist/services/entity-service/components.mjs +14 -100
  177. package/dist/services/entity-service/components.mjs.map +1 -1
  178. package/dist/services/entity-service/index.d.ts +1 -3
  179. package/dist/services/entity-service/index.d.ts.map +1 -1
  180. package/dist/services/entity-service/index.js +34 -199
  181. package/dist/services/entity-service/index.js.map +1 -1
  182. package/dist/services/entity-service/index.mjs +27 -192
  183. package/dist/services/entity-service/index.mjs.map +1 -1
  184. package/dist/services/entity-service/params.d.ts +4 -4
  185. package/dist/services/entity-service/params.d.ts.map +1 -1
  186. package/dist/services/entity-service/params.js +1 -1
  187. package/dist/services/entity-service/params.js.map +1 -1
  188. package/dist/services/entity-service/params.mjs +1 -1
  189. package/dist/services/entity-service/params.mjs.map +1 -1
  190. package/dist/services/entity-validator/index.js +1 -1
  191. package/dist/services/entity-validator/index.js.map +1 -1
  192. package/dist/services/entity-validator/index.mjs +1 -1
  193. package/dist/services/entity-validator/index.mjs.map +1 -1
  194. package/dist/utils/is-initialized.js +1 -1
  195. package/dist/utils/is-initialized.js.map +1 -1
  196. package/dist/utils/is-initialized.mjs +1 -1
  197. package/dist/utils/is-initialized.mjs.map +1 -1
  198. package/dist/utils/load-config-file.js +1 -1
  199. package/dist/utils/load-config-file.js.map +1 -1
  200. package/dist/utils/load-config-file.mjs +2 -2
  201. package/dist/utils/load-config-file.mjs.map +1 -1
  202. package/dist/utils/transform-content-types-to-models.d.ts +174 -3
  203. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  204. package/dist/utils/transform-content-types-to-models.js +80 -41
  205. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  206. package/dist/utils/transform-content-types-to-models.mjs +79 -41
  207. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  208. package/package.json +14 -14
  209. package/dist/services/document-service/collection-type.d.ts +0 -4
  210. package/dist/services/document-service/collection-type.d.ts.map +0 -1
  211. package/dist/services/document-service/collection-type.js +0 -145
  212. package/dist/services/document-service/collection-type.js.map +0 -1
  213. package/dist/services/document-service/collection-type.mjs +0 -145
  214. package/dist/services/document-service/collection-type.mjs.map +0 -1
  215. package/dist/services/document-service/document-engine.d.ts +0 -8
  216. package/dist/services/document-service/document-engine.d.ts.map +0 -1
  217. package/dist/services/document-service/document-engine.js +0 -249
  218. package/dist/services/document-service/document-engine.js.map +0 -1
  219. package/dist/services/document-service/document-engine.mjs +0 -250
  220. package/dist/services/document-service/document-engine.mjs.map +0 -1
  221. package/dist/services/document-service/repository-factory.d.ts +0 -3
  222. package/dist/services/document-service/repository-factory.d.ts.map +0 -1
  223. package/dist/services/document-service/repository-factory.js +0 -12
  224. package/dist/services/document-service/repository-factory.js.map +0 -1
  225. package/dist/services/document-service/repository-factory.mjs +0 -12
  226. package/dist/services/document-service/repository-factory.mjs.map +0 -1
  227. package/dist/services/document-service/single-type.d.ts +0 -4
  228. package/dist/services/document-service/single-type.d.ts.map +0 -1
  229. package/dist/services/document-service/single-type.js +0 -92
  230. package/dist/services/document-service/single-type.js.map +0 -1
  231. package/dist/services/document-service/single-type.mjs +0 -92
  232. package/dist/services/document-service/single-type.mjs.map +0 -1
  233. package/dist/services/document-service/transform/filters.js +0 -49
  234. package/dist/services/document-service/transform/filters.js.map +0 -1
  235. package/dist/services/document-service/transform/filters.mjs +0 -49
  236. package/dist/services/document-service/transform/filters.mjs.map +0 -1
  237. package/dist/services/document-service/transform/relations/transform/output-ids.js +0 -26
  238. package/dist/services/document-service/transform/relations/transform/output-ids.js.map +0 -1
  239. package/dist/services/document-service/transform/relations/transform/output-ids.mjs +0 -26
  240. package/dist/services/document-service/transform/relations/transform/output-ids.mjs.map +0 -1
  241. package/dist/services/document-service/transform/sort.js +0 -44
  242. package/dist/services/document-service/transform/sort.js.map +0 -1
  243. package/dist/services/document-service/transform/sort.mjs +0 -44
  244. package/dist/services/document-service/transform/sort.mjs.map +0 -1
  245. package/dist/services/document-service/transform/utils.js +0 -23
  246. package/dist/services/document-service/transform/utils.js.map +0 -1
  247. package/dist/services/document-service/transform/utils.mjs +0 -23
  248. package/dist/services/document-service/transform/utils.mjs.map +0 -1
  249. package/dist/services/utils/upload-files.d.ts +0 -8
  250. package/dist/services/utils/upload-files.d.ts.map +0 -1
  251. package/dist/services/utils/upload-files.js +0 -64
  252. package/dist/services/utils/upload-files.js.map +0 -1
  253. package/dist/services/utils/upload-files.mjs +0 -63
  254. package/dist/services/utils/upload-files.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"apis.js","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["isKebabCase","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkBA,YAAAA,YAAY,IAAI,IAAI,OAAOC,WAAE,QAAA,UAAU,IAAI;AAEpF,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAACC,IAAW,WA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AACI,aAAAP,aAAA,QAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
1
+ {"version":3,"file":"apis.js","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["strings","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkBA,YAAQ,QAAA,YAAY,IAAI,IAAI,OAAOC,WAAE,QAAA,UAAU,IAAI;AAE5F,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAACC,IAAW,WAAA,OAAO,KAAK,KAAK,GAAG,GAAG;AACrC;AAAA,EACF;AAEM,QAAA,UAAU,OAAO,MAAMC,aAAA,QAAI,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE,eAAe,KAAM,CAAA,GACnF,OAAO,WAAW,EAClB,OAAOF,mBAAE,OAAO,SAAS,CAAC;AAE7B,QAAM,OAAa,CAAA;AAGnB,aAAW,SAAS,SAAS;AACrB,UAAA,UAAU,cAAc,MAAM,IAAI;AAClC,UAAA,MAAM,MA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AAAA,MACH,GAAG;AAAA,IAAA;AAGE,WAAA,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,MACA,gBAAgB,YAAY,OAAO,kBAAkB,YAAY,OAAO,KAAK;AAAA,MAC7E,UAAUC,MAAAA,YAAY,YAAY,MAAM;AAAA,IAAA,CACzC;AAEY,iBAAA,cAAc,eAAe,CAAC,IAAI;AAAA,EACjD;AAEO,SAAA;AACT;AAEA,MAAM,UAAU,OAAO,QAAgB;AACrC,MAAI,CAAE,MAAMJ,aAAAA,QAAI,WAAW,GAAG,GAAI;AAChC;AAAA,EACF;AAEM,QAAA,MAAM,MAAMA,aAAAA,QAAI,QAAQ,KAAK,EAAE,eAAe,MAAM;AAE1D,QAAM,OAAgC,CAAA;AACtC,aAAW,MAAM,KAAK;AAChB,QAAA,CAAC,GAAG,OAAO,KAAKK,aAAQ,GAAG,IAAI,MAAM,QAAQ;AAC/C;AAAA,IACF;AAEA,UAAM,MAAMC,KAAS,SAAA,GAAG,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAASJ,KAAK,KAAA,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAMI,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAOE,YAAAA,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAAP,aAAA,QAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
@@ -1,7 +1,7 @@
1
1
  import { join, extname, basename } from "path";
2
2
  import fse, { existsSync } from "fs-extra";
3
3
  import _ from "lodash";
4
- import { isKebabCase, importDefault } from "@strapi/utils";
4
+ import { strings, importDefault } from "@strapi/utils";
5
5
  import { isEmpty } from "lodash/fp";
6
6
  import { getGlobalId } from "../domain/content-type/index.mjs";
7
7
  const DEFAULT_CONTENT_TYPE = {
@@ -9,7 +9,7 @@ const DEFAULT_CONTENT_TYPE = {
9
9
  actions: {},
10
10
  lifecycles: {}
11
11
  };
12
- const normalizeName = (name) => isKebabCase(name) ? name : _.kebabCase(name);
12
+ const normalizeName = (name) => strings.isKebabCase(name) ? name : _.kebabCase(name);
13
13
  const isDirectory = (fd) => fd.isDirectory();
14
14
  const isDotFile = (fd) => fd.name.startsWith(".");
15
15
  async function loadAPIs(strapi) {
@@ -1 +1 @@
1
- {"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkB,YAAY,IAAI,IAAI,OAAO,EAAE,UAAU,IAAI;AAEpF,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAAC,WAAW,OAAO,KAAK,KAAK,GAAG,GAAG;AACrC;AAAA,EACF;AAEM,QAAA,UAAU,OAAO,MAAM,IAAI,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE,eAAe,KAAM,CAAA,GACnF,OAAO,WAAW,EAClB,OA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MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAGE,WAAA,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,MACA,gBAAgB,YAAY,OAAO,kBAAkB,YAAY,OAAO,KAAK;AAAA,MAC7E,UAAU,YAAY,YAAY,MAAM;AAAA,IAAA,CACzC;AAEY,iBAAA,cAAc,eAAe,CAAC,IAAI;AAAA,EACjD;AAEO,SAAA;AACT;AAEA,MAAM,UAAU,OAAO,QAAgB;AACrC,MAAI,CAAE,MAAM,IAAI,WAAW,GAAG,GAAI;AAChC;AAAA,EACF;AAEM,QAAA,MAAM,MAAM,IAAI,QAAQ,KAAK,EAAE,eAAe,MAAM;AAE1D,QAAM,OAAgC,CAAA;AACtC,aAAW,MAAM,KAAK;AAChB,QAAA,CAAC,GAAG,OAAO,KAAK,QAAQ,GAAG,IAAI,MAAM,QAAQ;AAC/C;AAAA,IACF;AAEA,UAAM,MAAM,SAAS,GAAG,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAAS,KAAK,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAM,QAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAA,IAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
1
+ {"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkB,QAAQ,YAAY,IAAI,IAAI,OAAO,EAAE,UAAU,IAAI;AAE5F,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAAC,WAAW,OAAO,KAAK,KAAK,GAAG,GAAG;AACrC;AAAA,EACF;AAEM,QAAA,UAAU,OAAO,MAAM,IAAI,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE,eAAe,KAAM,CAAA,GACnF,OAAO,WAAW,EAClB,OAAO,EAAE,OAAO,SAAS,CAAC;AAE7B,QAAM,OAAa,CAAA;AAGnB,aAAW,SAAS,SAAS;AACrB,UAAA,UAAU,cAAc,MAAM,IAAI;AAClC,UAAA,MAAM,MAAM,QAAQ,SAAS,KAAK,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI,CAAC;AAEzE,SAAK,OAAO,IAAI;AAAA,EAClB;AAEA,8BAA4B,IAAI;AAEhC,aAAW,WAAW,OAAO,KAAK,IAAI,GAAG;AACvC,WAAO,IAAI,MAAM,EAAE,IAAI,SAAS,KAAK,OAAO,CAAC;AAAA,EAC/C;AACF;AAEA,MAAM,8BAA8B,CAAC,SAAe;AAClD,QAAM,iBAAiB,OAAO,OAAO,IAAI,EAAE,QAAQ,CAAC,QAAQ,OAAO,OAAO,IAAI,YAAY,CAAC;AAE3F,QAAM,QAAkB,CAAA;AACxB,iBAAe,QAAQ,CAAC,EAAE,aAAa;AACjC,QAAA,OA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G,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAAS,KAAK,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAM,QAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAA,IAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
@@ -17,7 +17,7 @@ const INTERNAL_PLUGINS = [
17
17
  ];
18
18
  const isStrapiPlugin = (info) => _$1.get("strapi.kind", info) === "plugin";
19
19
  const validatePluginName = (pluginName) => {
20
- if (!strapiUtils.isKebabCase(pluginName)) {
20
+ if (!strapiUtils.strings.isKebabCase(pluginName)) {
21
21
  throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
22
22
  }
23
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","isKebabCase","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,IAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AAC7C,MAAA,CAACC,YAAAA,YAAY,UAAU,GAAG;AAC5B,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;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,IAAI;AACzB,uBAAA,YAAY,OAAO,IAAI,IAAI;AAAA,QAC1C,GAAG,sBAAsB,EAAE,SAAS,MAAM,SAAS,aAAa,UAAU,QAAQ;AAAA,QAClF,MAAM;AAAA,UACJ,GAAG,YAAY;AAAA,UACf,aAAa,YAAY;AAAA,QAC3B;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AAEA,QAAM,kBAA+B,CAAA;AAC/B,QAAA,oBAAoB,MAAMM,qBAAAA;AAEhCC,aAAAA,QAAE,QAAQ,mBAAmB,CAAC,aAAa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAcP,KAAAA,KAAK,cAAc,cAAc;AAC/C,YAAA,cAAc,QAAQ,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AAAA,MAC3D;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0BQ,IAAAA,IAAIC,IAAAA,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiCC,IAAA;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiBC,IAAA;AAAA,IACrBC,IAAAA,aAAa,eAAe;AAAA,IAC5BA,IAAAA,aAAa,8BAA8B;AAAA,IAC3CF,IAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
1
+ {"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","strings","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop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KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiCC,IAAA;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiBC,IAAA;AAAA,IACrBC,IAAAA,aAAa,eAAe;AAAA,IAC5BA,IAAAA,aAAa,8BAA8B;AAAA,IAC3CF,IAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
@@ -2,7 +2,7 @@ import { join, dirname, resolve } from "path";
2
2
  import { existsSync, statSync } from "fs";
3
3
  import _ from "lodash";
4
4
  import { map, prop, pickBy, pipe, defaultsDeep, get } from "lodash/fp";
5
- import { isKebabCase } from "@strapi/utils";
5
+ import { strings } from "@strapi/utils";
6
6
  import { getUserPluginsConfig } from "./get-user-plugins-config.mjs";
7
7
  const INTERNAL_PLUGINS = [
8
8
  "@strapi/plugin-content-manager",
@@ -13,7 +13,7 @@ const INTERNAL_PLUGINS = [
13
13
  ];
14
14
  const isStrapiPlugin = (info) => get("strapi.kind", info) === "plugin";
15
15
  const validatePluginName = (pluginName) => {
16
- if (!isKebabCase(pluginName)) {
16
+ if (!strings.isKebabCase(pluginName)) {
17
17
  throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
18
18
  }
19
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["strapi"],"mappings":";;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqB,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AAC7C,MAAA,CAAC,YAAY,UAAU,GAAG;AAC5B,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AA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AA,IAAA,QAC3B;AACN;AAAA,IACF;AAEI,QAAA,eAAe,WAAW,GAAG;AACZ,yBAAA,YAAY,OAAO,IAAI;AACzB,uBAAA,YAAY,OAAO,IAAI,IAAI;AAAA,QAC1C,GAAG,sBAAsB,EAAE,SAAS,MAAM,SAAS,aAAa,UAAU,QAAQ;AAAA,QAClF,MAAM;AAAA,UACJ,GAAG,YAAY;AAAA,UACf,aAAa,YAAY;AAAA,QAC3B;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AAEA,QAAM,kBAA+B,CAAA;AAC/B,QAAA,oBAAoB,MAAM;AAEhC,IAAE,QAAQ,mBAAmB,CAAC,aAAa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAc,KAAK,cAAc,cAAc;AAC/C,YAAA,cAAc,QAAQ,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AAAA,MAC3D;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0B,IAAI,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiC;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiB;AAAA,IACrB,aAAa,eAAe;AAAA,IAC5B,aAAa,8BAA8B;AAAA,IAC3C,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;"}
1
+ {"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["strapi"],"mappings":";;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACv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5B,aAAa,8BAA8B;AAAA,IAC3C,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;"}
@@ -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,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AA0B3D,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAsDnD,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,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AA0B3D,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAkEnD,CAAC"}
@@ -55,12 +55,12 @@ const security = (config, { strapi }) => (ctx, next) => {
55
55
  }
56
56
  });
57
57
  }
58
- if (ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
58
+ if (process.env.NODE_ENV === "development" && ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
59
59
  helmetConfig = _.merge(helmetConfig, {
60
60
  contentSecurityPolicy: {
61
61
  directives: {
62
62
  "script-src": ["'self'", "'unsafe-inline'"],
63
- "connect-src": ["'self'", "https:", "ws:"]
63
+ "connect-src": ["'self'", "http:", "https:", "ws:"]
64
64
  }
65
65
  }
66
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"security.js","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, merge } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Common } 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\nexport const security: Common.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 = merge(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n if (ctx.method === 'GET' && ['/admin'].some((str) => ctx.path.startsWith(str))) {\n helmetConfig = merge(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":["defaultsDeep","merge","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,MAAA,WACX,CAAC,QAAQ,EAAE,aACX,CAAC,KAAK,SAAS;AACT,MAAA,eAAuBA,EAAAA,aAAa,UAAU,MAAM;AAElD,QAAA,eAAe,CAAC,gBAAgB;AAEtC,QAAM,aAKF;AAAA,IACF,cAAc,CAAC,UAAU,mBAAmB,kBAAkB;AAAA,IAC9D,WAAW,CAAC,UAAU,SAAS,oBAAoB,WAAW;AAAA,IAC9D,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,EAAA;AAIZ,MAAA,OAAO,OAAO,SAAS,GAAG,QAAQ,OAAO,EAAE,WAAW,aAAa;AACrE,UAAM,EAAE,QAAQ,UAAA,IAAc,OAAO,OAAO,SAAS;AACxC,iBAAA,KAAK,UAAU,UAAU,CAAC;AAE5B,eAAA,YAAY,EAAE,KAAK,wBAAwB;AAC3C,eAAA,SAAS,EAAE,KAAK,oDAAoD;AACpE,eAAA,cAAc,EAAE,KAAK,QAAQ;AAC7B,eAAA,cAAc,EAAE,KAAK,kDAAkD;AACvE,eAAA,WAAW,EAAE,KAAK,QAAQ;AAC1B,eAAA,WAAW,EAAE,KAAK,iCAAiC;AAAA,EAChE;AAGA,MAAI,IAAI,WAAW,SAAS,aAAa,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAChF,mBAAeC,QAAM,cAAc;AAAA,MACjC,2BAA2B;AAAA;AAAA,MAC3B,uBAAuB;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,MAAI,IAAI,WAAW,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAC9E,mBAAeA,QAAM,cAAc;AAAA,MACjC,uBAAuB;AAAA,QACrB,YAAY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,UAAU,KAAK;AAAA,QAC3C;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, merge } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Common } 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\nexport const security: Common.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 = merge(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 process.env.NODE_ENV === 'development' &&\n ctx.method === 'GET' &&\n ['/admin'].some((str) => ctx.path.startsWith(str))\n ) {\n helmetConfig = merge(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":["defaultsDeep","merge","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,MAAA,WACX,CAAC,QAAQ,EAAE,aACX,CAAC,KAAK,SAAS;AACT,MAAA,eAAuBA,EAAAA,aAAa,UAAU,MAAM;AAElD,QAAA,eAAe,CAAC,gBAAgB;AAEtC,QAAM,aAKF;AAAA,IACF,cAAc,CAAC,UAAU,mBAAmB,kBAAkB;AAAA,IAC9D,WAAW,CAAC,UAAU,SAAS,oBAAoB,WAAW;AAAA,IAC9D,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,EAAA;AAIZ,MAAA,OAAO,OAAO,SAAS,GAAG,QAAQ,OAAO,EAAE,WAAW,aAAa;AACrE,UAAM,EAAE,QAAQ,UAAA,IAAc,OAAO,OAAO,SAAS;AACxC,iBAAA,KAAK,UAAU,UAAU,CAAC;AAE5B,eAAA,YAAY,EAAE,KAAK,wBAAwB;AAC3C,eAAA,SAAS,EAAE,KAAK,oDAAoD;AACpE,eAAA,cAAc,EAAE,KAAK,QAAQ;AAC7B,eAAA,cAAc,EAAE,KAAK,kDAAkD;AACvE,eAAA,WAAW,EAAE,KAAK,QAAQ;AAC1B,eAAA,WAAW,EAAE,KAAK,iCAAiC;AAAA,EAChE;AAGA,MAAI,IAAI,WAAW,SAAS,aAAa,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAChF,mBAAeC,QAAM,cAAc;AAAA,MACjC,2BAA2B;AAAA;AAAA,MAC3B,uBAAuB;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAUA,MACE,QAAQ,IAAI,aAAa,iBACzB,IAAI,WAAW,SACf,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GACjD;AACA,mBAAeA,QAAM,cAAc;AAAA,MACjC,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;;"}
@@ -51,12 +51,12 @@ const security = (config, { strapi }) => (ctx, next) => {
51
51
  }
52
52
  });
53
53
  }
54
- if (ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
54
+ if (process.env.NODE_ENV === "development" && ctx.method === "GET" && ["/admin"].some((str) => ctx.path.startsWith(str))) {
55
55
  helmetConfig = merge(helmetConfig, {
56
56
  contentSecurityPolicy: {
57
57
  directives: {
58
58
  "script-src": ["'self'", "'unsafe-inline'"],
59
- "connect-src": ["'self'", "https:", "ws:"]
59
+ "connect-src": ["'self'", "http:", "https:", "ws:"]
60
60
  }
61
61
  }
62
62
  });
@@ -1 +1 @@
1
- {"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, merge } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Common } 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\nexport const security: Common.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 = merge(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n if (ctx.method === 'GET' && ['/admin'].some((str) => ctx.path.startsWith(str))) {\n helmetConfig = merge(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", '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,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,mBAAmB,kBAAkB;AAAA,IAC9D,WAAW,CAAC,UAAU,SAAS,oBAAoB,WAAW;AAAA,IAC9D,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,EAAA;AAIZ,MAAA,OAAO,OAAO,SAAS,GAAG,QAAQ,OAAO,EAAE,WAAW,aAAa;AACrE,UAAM,EAAE,QAAQ,UAAA,IAAc,OAAO,OAAO,SAAS;AACxC,iBAAA,KAAK,UAAU,UAAU,CAAC;AAE5B,eAAA,YAAY,EAAE,KAAK,wBAAwB;AAC3C,eAAA,SAAS,EAAE,KAAK,oDAAoD;AACpE,eAAA,cAAc,EAAE,KAAK,QAAQ;AAC7B,eAAA,cAAc,EAAE,KAAK,kDAAkD;AACvE,eAAA,WAAW,EAAE,KAAK,QAAQ;AAC1B,eAAA,WAAW,EAAE,KAAK,iCAAiC;AAAA,EAChE;AAGA,MAAI,IAAI,WAAW,SAAS,aAAa,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAChF,mBAAe,MAAM,cAAc;AAAA,MACjC,2BAA2B;AAAA;AAAA,MAC3B,uBAAuB;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,MAAI,IAAI,WAAW,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAC9E,mBAAe,MAAM,cAAc;AAAA,MACjC,uBAAuB;AAAA,QACrB,YAAY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,UAAU,KAAK;AAAA,QAC3C;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAO,OAAO,YAAY,EAAE,KAAK,IAAI;AACvC;"}
1
+ {"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, merge } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Common } 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\nexport const security: Common.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 = merge(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 process.env.NODE_ENV === 'development' &&\n ctx.method === 'GET' &&\n ['/admin'].some((str) => ctx.path.startsWith(str))\n ) {\n helmetConfig = merge(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,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,mBAAmB,kBAAkB;AAAA,IAC9D,WAAW,CAAC,UAAU,SAAS,oBAAoB,WAAW;AAAA,IAC9D,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,EAAA;AAIZ,MAAA,OAAO,OAAO,SAAS,GAAG,QAAQ,OAAO,EAAE,WAAW,aAAa;AACrE,UAAM,EAAE,QAAQ,UAAA,IAAc,OAAO,OAAO,SAAS;AACxC,iBAAA,KAAK,UAAU,UAAU,CAAC;AAE5B,eAAA,YAAY,EAAE,KAAK,wBAAwB;AAC3C,eAAA,SAAS,EAAE,KAAK,oDAAoD;AACpE,eAAA,cAAc,EAAE,KAAK,QAAQ;AAC7B,eAAA,cAAc,EAAE,KAAK,kDAAkD;AACvE,eAAA,WAAW,EAAE,KAAK,QAAQ;AAC1B,eAAA,WAAW,EAAE,KAAK,iCAAiC;AAAA,EAChE;AAGA,MAAI,IAAI,WAAW,SAAS,aAAa,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GAAG;AAChF,mBAAe,MAAM,cAAc;AAAA,MACjC,2BAA2B;AAAA;AAAA,MAC3B,uBAAuB;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAUA,MACE,QAAQ,IAAI,aAAa,iBACzB,IAAI,WAAW,SACf,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,WAAW,GAAG,CAAC,GACjD;AACA,mBAAe,MAAM,cAAc;AAAA,MACjC,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,SAAO,OAAO,YAAY,EAAE,KAAK,IAAI;AACvC;"}
@@ -0,0 +1,17 @@
1
+ import { Schema } from '@strapi/types';
2
+ interface Input {
3
+ oldContentTypes: Record<string, Schema.ContentType>;
4
+ contentTypes: Record<string, Schema.ContentType>;
5
+ }
6
+ /**
7
+ * Enable draft and publish for content types.
8
+ *
9
+ * Draft and publish disabled content types will have their entries published,
10
+ * this migration clones those entries as drafts.
11
+ *
12
+ * TODO: Clone components, dynamic zones and relations
13
+ */
14
+ declare const enableDraftAndPublish: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
15
+ declare const disableDraftAndPublish: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
16
+ export { enableDraftAndPublish as enable, disableDraftAndPublish as disable };
17
+ //# sourceMappingURL=draft-publish.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,UAAU,KAAK;IACb,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAkE5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const strapiUtils = require("@strapi/utils");
4
+ const enableDraftAndPublish = async ({ oldContentTypes, contentTypes }) => {
5
+ if (!oldContentTypes) {
6
+ return;
7
+ }
8
+ for (const uid in contentTypes) {
9
+ if (!oldContentTypes[uid]) {
10
+ continue;
11
+ }
12
+ const oldContentType = oldContentTypes[uid];
13
+ const contentType = contentTypes[uid];
14
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(oldContentType) && strapiUtils.contentTypes.hasDraftAndPublish(contentType)) {
15
+ const metadata = strapi.db.metadata.get(uid);
16
+ const attributes = Object.values(metadata.attributes).reduce((acc, attribute) => {
17
+ if (["id"].includes(attribute.columnName)) {
18
+ return acc;
19
+ }
20
+ if (strapiUtils.contentTypes.isScalarAttribute(attribute)) {
21
+ acc.push(attribute.columnName);
22
+ }
23
+ return acc;
24
+ }, []);
25
+ const qb = strapi.db?.getConnection();
26
+ await qb.into(qb.raw(`${metadata.tableName} (${attributes.join(", ")})`)).insert((subQb) => {
27
+ subQb.select(
28
+ ...attributes.map((att) => {
29
+ if (att === "published_at") {
30
+ return qb.raw("NULL as published_at");
31
+ }
32
+ if (att === "updated_at") {
33
+ return qb.raw(`? as updated_at`, [/* @__PURE__ */ new Date()]);
34
+ }
35
+ return att;
36
+ })
37
+ ).from(metadata.tableName).whereNotNull("published_at");
38
+ });
39
+ }
40
+ }
41
+ };
42
+ const disableDraftAndPublish = async ({ oldContentTypes, contentTypes }) => {
43
+ if (!oldContentTypes) {
44
+ return;
45
+ }
46
+ for (const uid in contentTypes) {
47
+ if (!oldContentTypes[uid]) {
48
+ continue;
49
+ }
50
+ const oldContentType = oldContentTypes[uid];
51
+ const contentType = contentTypes[uid];
52
+ if (strapiUtils.contentTypes.hasDraftAndPublish(oldContentType) && !strapiUtils.contentTypes.hasDraftAndPublish(contentType)) {
53
+ await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();
54
+ }
55
+ }
56
+ };
57
+ exports.disable = disableDraftAndPublish;
58
+ exports.enable = enableDraftAndPublish;
59
+ //# sourceMappingURL=draft-publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const metadata = strapi.db.metadata.get(uid);\n\n // Extract all scalar attributes to use in the insert query\n const attributes = Object.values(metadata.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypesUtils.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n const qb = strapi.db?.getConnection();\n await qb\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(qb.raw(`${metadata.tableName} (${attributes.join(', ')})`))\n .insert((subQb: typeof qb) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...attributes.map((att) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return qb.raw('NULL as published_at');\n }\n\n if (att === 'updated_at') {\n return qb.raw(`? as updated_at`, [new Date()]);\n }\n\n return att;\n })\n )\n .from(metadata.tableName)\n .whereNotNull('published_at');\n });\n }\n }\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils"],"mappings":";;;AAgBA,MAAM,wBAAwB,OAAO,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A,EACF;AAEA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAAA,YAAAA,aAAkB,mBAAmB,cAAc,KACnD,CAACA,yBAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;;;"}
@@ -0,0 +1,59 @@
1
+ import { contentTypes } from "@strapi/utils";
2
+ const enableDraftAndPublish = async ({ oldContentTypes, contentTypes: contentTypes$1 }) => {
3
+ if (!oldContentTypes) {
4
+ return;
5
+ }
6
+ for (const uid in contentTypes$1) {
7
+ if (!oldContentTypes[uid]) {
8
+ continue;
9
+ }
10
+ const oldContentType = oldContentTypes[uid];
11
+ const contentType = contentTypes$1[uid];
12
+ if (!contentTypes.hasDraftAndPublish(oldContentType) && contentTypes.hasDraftAndPublish(contentType)) {
13
+ const metadata = strapi.db.metadata.get(uid);
14
+ const attributes = Object.values(metadata.attributes).reduce((acc, attribute) => {
15
+ if (["id"].includes(attribute.columnName)) {
16
+ return acc;
17
+ }
18
+ if (contentTypes.isScalarAttribute(attribute)) {
19
+ acc.push(attribute.columnName);
20
+ }
21
+ return acc;
22
+ }, []);
23
+ const qb = strapi.db?.getConnection();
24
+ await qb.into(qb.raw(`${metadata.tableName} (${attributes.join(", ")})`)).insert((subQb) => {
25
+ subQb.select(
26
+ ...attributes.map((att) => {
27
+ if (att === "published_at") {
28
+ return qb.raw("NULL as published_at");
29
+ }
30
+ if (att === "updated_at") {
31
+ return qb.raw(`? as updated_at`, [/* @__PURE__ */ new Date()]);
32
+ }
33
+ return att;
34
+ })
35
+ ).from(metadata.tableName).whereNotNull("published_at");
36
+ });
37
+ }
38
+ }
39
+ };
40
+ const disableDraftAndPublish = async ({ oldContentTypes, contentTypes: contentTypes$1 }) => {
41
+ if (!oldContentTypes) {
42
+ return;
43
+ }
44
+ for (const uid in contentTypes$1) {
45
+ if (!oldContentTypes[uid]) {
46
+ continue;
47
+ }
48
+ const oldContentType = oldContentTypes[uid];
49
+ const contentType = contentTypes$1[uid];
50
+ if (contentTypes.hasDraftAndPublish(oldContentType) && !contentTypes.hasDraftAndPublish(contentType)) {
51
+ await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();
52
+ }
53
+ }
54
+ };
55
+ export {
56
+ disableDraftAndPublish as disable,
57
+ enableDraftAndPublish as enable
58
+ };
59
+ //# sourceMappingURL=draft-publish.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-publish.mjs","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const metadata = strapi.db.metadata.get(uid);\n\n // Extract all scalar attributes to use in the insert query\n const attributes = Object.values(metadata.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypesUtils.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n const qb = strapi.db?.getConnection();\n await qb\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(qb.raw(`${metadata.tableName} (${attributes.join(', ')})`))\n .insert((subQb: typeof qb) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...attributes.map((att) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return qb.raw('NULL as published_at');\n }\n\n if (att === 'updated_at') {\n return qb.raw(`? as updated_at`, [new Date()]);\n }\n\n return att;\n })\n )\n .from(metadata.tableName)\n .whereNotNull('published_at');\n });\n }\n }\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypes","contentTypesUtils"],"mappings":";AAgBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiBA,cAAAA,qBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAIA,aAAW,OAAOA,gBAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAcA,eAAa,GAAG;AAIlC,QAAA,CAACC,aAAkB,mBAAmB,cAAc,KACpDA,aAAkB,mBAAmB,WAAW,GAChD;AACA,YAAM,WAAW,OA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M,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;"}
@@ -1,4 +1,4 @@
1
- import type { ConfigProvider } from '@strapi/types';
2
- declare const _default: (initialConfig?: {}) => ConfigProvider;
1
+ import type { ConfigProvider, LoadedStrapi, Strapi } from '@strapi/types';
2
+ declare const _default: (initialConfig?: {}, strapi?: Strapi | LoadedStrapi) => ConfigProvider;
3
3
  export default _default;
4
4
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/registries/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;gDAKf,cAAc;AAAnD,wBAgBE"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/registries/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;sDAK7B,MAAM,GAAG,YAAY,KAAG,cAAc;AAAnF,wBAgCE"}
@@ -1,21 +1,29 @@
1
1
  "use strict";
2
2
  const _ = require("lodash");
3
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
- const ___default = /* @__PURE__ */ _interopDefault(_);
5
- const config = (initialConfig = {}) => {
3
+ const config = (initialConfig = {}, strapi) => {
6
4
  const _config = { ...initialConfig };
5
+ const transformDeprecatedPaths = (path) => {
6
+ if (_.isString(path) && path.startsWith("plugin.")) {
7
+ const newPath = path.replace("plugin.", "plugin::");
8
+ (strapi?.log?.warn ?? console.warn)(
9
+ `Using dot notation for model config namespaces is deprecated, for example "plugin::myplugin" should be used instead of "plugin.myplugin". Modifying requested path ${path} to ${newPath}`
10
+ );
11
+ return newPath;
12
+ }
13
+ return path;
14
+ };
7
15
  return {
8
16
  ..._config,
9
17
  // TODO: to remove
10
18
  get(path, defaultValue) {
11
- return ___default.default.get(_config, path, defaultValue);
19
+ return _.get(_config, transformDeprecatedPaths(path), defaultValue);
12
20
  },
13
21
  set(path, val) {
14
- ___default.default.set(_config, path, val);
22
+ _.set(_config, transformDeprecatedPaths(path), val);
15
23
  return this;
16
24
  },
17
25
  has(path) {
18
- return ___default.default.has(_config, path);
26
+ return _.has(_config, path);
19
27
  }
20
28
  };
21
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../src/registries/config.ts"],"sourcesContent":["import type { ConfigProvider } from '@strapi/types';\nimport _, { PropertyName } from 'lodash';\n\ntype Config = Record<string, unknown>;\n\nexport default (initialConfig = {}): ConfigProvider => {\n const _config: Config = { ...initialConfig }; // not deep clone because it would break some config\n\n return {\n ..._config, // TODO: to remove\n get(path: PropertyName, defaultValue?: unknown) {\n return _.get(_config, path, defaultValue);\n },\n set(path: PropertyName, val: unknown) {\n _.set(_config, path, val);\n return this;\n },\n has(path: PropertyName) {\n return _.has(_config, path);\n },\n };\n};\n"],"names":["_"],"mappings":";;;;AAKA,MAAA,SAAe,CAAC,gBAAgB,CAAA,MAAuB;AAC/C,QAAA,UAAkB,EAAE,GAAG;AAEtB,SAAA;AAAA,IACL,GAAG;AAAA;AAAA,IACH,IAAI,MAAoB,cAAwB;AAC9C,aAAOA,WAAE,QAAA,IAAI,SAAS,MAAM,YAAY;AAAA,IAC1C;AAAA,IACA,IAAI,MAAoB,KAAc;AAClCA,iBAAAA,QAAA,IAAI,SAAS,MAAM,GAAG;AACjB,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAoB;AACf,aAAAA,mBAAE,IAAI,SAAS,IAAI;AAAA,IAC5B;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"config.js","sources":["../../src/registries/config.ts"],"sourcesContent":["import type { ConfigProvider, LoadedStrapi, Strapi } from '@strapi/types';\nimport { get, set, has, isString, type PropertyName } from 'lodash';\n\ntype Config = Record<string, unknown>;\n\nexport default (initialConfig = {}, strapi?: Strapi | LoadedStrapi): ConfigProvider => {\n const _config: Config = { ...initialConfig }; // not deep clone because it would break some config\n\n // Accessing model configs with dot (.) was deprecated between v4->v5, but to avoid a major breaking change\n // we will still support certain namespaces, currently only 'plugin.'\n const transformDeprecatedPaths = (path: PropertyName) => {\n if (isString(path) && path.startsWith('plugin.')) {\n const newPath = path.replace('plugin.', 'plugin::');\n\n // strapi logger may not be loaded yet, so fall back to console\n (strapi?.log?.warn ?? console.warn)(\n `Using dot notation for model config namespaces is deprecated, for example \"plugin::myplugin\" should be used instead of \"plugin.myplugin\". Modifying requested path ${path} to ${newPath}`\n );\n return newPath;\n }\n\n return path;\n };\n\n return {\n ..._config, // TODO: to remove\n get(path: PropertyName, defaultValue?: unknown) {\n return get(_config, transformDeprecatedPaths(path), defaultValue);\n },\n set(path: PropertyName, val: unknown) {\n set(_config, transformDeprecatedPaths(path), val);\n return this;\n },\n has(path: PropertyName) {\n return has(_config, path);\n },\n };\n};\n"],"names":["isString","get","set","has"],"mappings":";;AAKA,MAAA,SAAe,CAAC,gBAAgB,CAAC,GAAG,WAAmD;AAC/E,QAAA,UAAkB,EAAE,GAAG;AAIvB,QAAA,2BAA2B,CAAC,SAAuB;AACvD,QAAIA,EAAAA,SAAS,IAAI,KAAK,KAAK,WAAW,SAAS,GAAG;AAChD,YAAM,UAAU,KAAK,QAAQ,WAAW,UAAU;AAGjD,OAAA,QAAQ,KAAK,QAAQ,QAAQ;AAAA,QAC5B,sKAAsK,IAAI,OAAO,OAAO;AAAA,MAAA;AAEnL,aAAA;AAAA,IACT;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA;AAAA,IACL,GAAG;AAAA;AAAA,IACH,IAAI,MAAoB,cAAwB;AAC9C,aAAOC,EAAAA,IAAI,SAAS,yBAAyB,IAAI,GAAG,YAAY;AAAA,IAClE;AAAA,IACA,IAAI,MAAoB,KAAc;AACpCC,QAAAA,IAAI,SAAS,yBAAyB,IAAI,GAAG,GAAG;AACzC,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAoB;AACf,aAAAC,EAAA,IAAI,SAAS,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEJ;;"}
@@ -1,18 +1,28 @@
1
- import _ from "lodash";
2
- const config = (initialConfig = {}) => {
1
+ import { get, set, has, isString } from "lodash";
2
+ const config = (initialConfig = {}, strapi) => {
3
3
  const _config = { ...initialConfig };
4
+ const transformDeprecatedPaths = (path) => {
5
+ if (isString(path) && path.startsWith("plugin.")) {
6
+ const newPath = path.replace("plugin.", "plugin::");
7
+ (strapi?.log?.warn ?? console.warn)(
8
+ `Using dot notation for model config namespaces is deprecated, for example "plugin::myplugin" should be used instead of "plugin.myplugin". Modifying requested path ${path} to ${newPath}`
9
+ );
10
+ return newPath;
11
+ }
12
+ return path;
13
+ };
4
14
  return {
5
15
  ..._config,
6
16
  // TODO: to remove
7
17
  get(path, defaultValue) {
8
- return _.get(_config, path, defaultValue);
18
+ return get(_config, transformDeprecatedPaths(path), defaultValue);
9
19
  },
10
20
  set(path, val) {
11
- _.set(_config, path, val);
21
+ set(_config, transformDeprecatedPaths(path), val);
12
22
  return this;
13
23
  },
14
24
  has(path) {
15
- return _.has(_config, path);
25
+ return has(_config, path);
16
26
  }
17
27
  };
18
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","sources":["../../src/registries/config.ts"],"sourcesContent":["import type { ConfigProvider } from '@strapi/types';\nimport _, { PropertyName } from 'lodash';\n\ntype Config = Record<string, unknown>;\n\nexport default (initialConfig = {}): ConfigProvider => {\n const _config: Config = { ...initialConfig }; // not deep clone because it would break some config\n\n return {\n ..._config, // TODO: to remove\n get(path: PropertyName, defaultValue?: unknown) {\n return _.get(_config, path, defaultValue);\n },\n set(path: PropertyName, val: unknown) {\n _.set(_config, path, val);\n return this;\n },\n has(path: PropertyName) {\n return _.has(_config, path);\n },\n };\n};\n"],"names":[],"mappings":";AAKA,MAAA,SAAe,CAAC,gBAAgB,CAAA,MAAuB;AAC/C,QAAA,UAAkB,EAAE,GAAG;AAEtB,SAAA;AAAA,IACL,GAAG;AAAA;AAAA,IACH,IAAI,MAAoB,cAAwB;AAC9C,aAAO,EAAE,IAAI,SAAS,MAAM,YAAY;AAAA,IAC1C;AAAA,IACA,IAAI,MAAoB,KAAc;AAClC,QAAA,IAAI,SAAS,MAAM,GAAG;AACjB,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAoB;AACf,aAAA,EAAE,IAAI,SAAS,IAAI;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"config.mjs","sources":["../../src/registries/config.ts"],"sourcesContent":["import type { ConfigProvider, LoadedStrapi, Strapi } from '@strapi/types';\nimport { get, set, has, isString, type PropertyName } from 'lodash';\n\ntype Config = Record<string, unknown>;\n\nexport default (initialConfig = {}, strapi?: Strapi | LoadedStrapi): ConfigProvider => {\n const _config: Config = { ...initialConfig }; // not deep clone because it would break some config\n\n // Accessing model configs with dot (.) was deprecated between v4->v5, but to avoid a major breaking change\n // we will still support certain namespaces, currently only 'plugin.'\n const transformDeprecatedPaths = (path: PropertyName) => {\n if (isString(path) && path.startsWith('plugin.')) {\n const newPath = path.replace('plugin.', 'plugin::');\n\n // strapi logger may not be loaded yet, so fall back to console\n (strapi?.log?.warn ?? console.warn)(\n `Using dot notation for model config namespaces is deprecated, for example \"plugin::myplugin\" should be used instead of \"plugin.myplugin\". Modifying requested path ${path} to ${newPath}`\n );\n return newPath;\n }\n\n return path;\n };\n\n return {\n ..._config, // TODO: to remove\n get(path: PropertyName, defaultValue?: unknown) {\n return get(_config, transformDeprecatedPaths(path), defaultValue);\n },\n set(path: PropertyName, val: unknown) {\n set(_config, transformDeprecatedPaths(path), val);\n return this;\n },\n has(path: PropertyName) {\n return has(_config, path);\n },\n };\n};\n"],"names":[],"mappings":";AAKA,MAAA,SAAe,CAAC,gBAAgB,CAAC,GAAG,WAAmD;AAC/E,QAAA,UAAkB,EAAE,GAAG;AAIvB,QAAA,2BAA2B,CAAC,SAAuB;AACvD,QAAI,SAAS,IAAI,KAAK,KAAK,WAAW,SAAS,GAAG;AAChD,YAAM,UAAU,KAAK,QAAQ,WAAW,UAAU;AAGjD,OAAA,QAAQ,KAAK,QAAQ,QAAQ;AAAA,QAC5B,sKAAsK,IAAI,OAAO,OAAO;AAAA,MAAA;AAEnL,aAAA;AAAA,IACT;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA;AAAA,IACL,GAAG;AAAA;AAAA,IACH,IAAI,MAAoB,cAAwB;AAC9C,aAAO,IAAI,SAAS,yBAAyB,IAAI,GAAG,YAAY;AAAA,IAClE;AAAA,IACA,IAAI,MAAoB,KAAc;AACpC,UAAI,SAAS,yBAAyB,IAAI,GAAG,GAAG;AACzC,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAoB;AACf,aAAA,IAAI,SAAS,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEJ;"}
@@ -1,4 +1,4 @@
1
- import type { Schema } from '@strapi/types';
2
- export type RepositoryFactoryMethod<TContentType extends Schema.SingleType | Schema.CollectionType> = (contentType: TContentType) => any;
1
+ import type { Common, Documents } from '@strapi/types';
2
+ export type RepositoryFactoryMethod = (uid: Common.UID.CollectionType) => Documents.ServiceInstance;
3
3
  export declare const wrapInTransaction: (fn: (...args: any) => any) => (...args: any[]) => Promise<any>;
4
4
  //# sourceMappingURL=common.d.ts.map