@strapi/content-type-builder 0.0.0-experimental.0e316dc69ac15cab63af4c7f91191d12fc2bbc27

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 (319) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +1 -0
  3. package/dist/_chunks/ListView-BBUIU-Ay.js +964 -0
  4. package/dist/_chunks/ListView-BBUIU-Ay.js.map +1 -0
  5. package/dist/_chunks/ListView-Dvefai4e.mjs +959 -0
  6. package/dist/_chunks/ListView-Dvefai4e.mjs.map +1 -0
  7. package/dist/_chunks/ar-BYDB75EB.mjs +51 -0
  8. package/dist/_chunks/ar-BYDB75EB.mjs.map +1 -0
  9. package/dist/_chunks/ar-OCxhAFUy.js +51 -0
  10. package/dist/_chunks/ar-OCxhAFUy.js.map +1 -0
  11. package/dist/_chunks/cs-ChL4LaFY.mjs +139 -0
  12. package/dist/_chunks/cs-ChL4LaFY.mjs.map +1 -0
  13. package/dist/_chunks/cs-Ci3js5EC.js +139 -0
  14. package/dist/_chunks/cs-Ci3js5EC.js.map +1 -0
  15. package/dist/_chunks/de-DnlblIOh.js +193 -0
  16. package/dist/_chunks/de-DnlblIOh.js.map +1 -0
  17. package/dist/_chunks/de-DsHQNzp2.mjs +193 -0
  18. package/dist/_chunks/de-DsHQNzp2.mjs.map +1 -0
  19. package/dist/_chunks/dk-BC7NAQR2.mjs +183 -0
  20. package/dist/_chunks/dk-BC7NAQR2.mjs.map +1 -0
  21. package/dist/_chunks/dk-D3XnOjYz.js +183 -0
  22. package/dist/_chunks/dk-D3XnOjYz.js.map +1 -0
  23. package/dist/_chunks/en-CXG5y_vo.js +216 -0
  24. package/dist/_chunks/en-CXG5y_vo.js.map +1 -0
  25. package/dist/_chunks/en-jBwb53yg.mjs +216 -0
  26. package/dist/_chunks/en-jBwb53yg.mjs.map +1 -0
  27. package/dist/_chunks/es-BE_zx2_w.mjs +183 -0
  28. package/dist/_chunks/es-BE_zx2_w.mjs.map +1 -0
  29. package/dist/_chunks/es-DL8lez9W.js +183 -0
  30. package/dist/_chunks/es-DL8lez9W.js.map +1 -0
  31. package/dist/_chunks/fr-DnTxugIo.js +75 -0
  32. package/dist/_chunks/fr-DnTxugIo.js.map +1 -0
  33. package/dist/_chunks/fr-lU_OMJma.mjs +75 -0
  34. package/dist/_chunks/fr-lU_OMJma.mjs.map +1 -0
  35. package/dist/_chunks/id-DYuTgqcc.js +166 -0
  36. package/dist/_chunks/id-DYuTgqcc.js.map +1 -0
  37. package/dist/_chunks/id-W1sKBFEw.mjs +166 -0
  38. package/dist/_chunks/id-W1sKBFEw.mjs.map +1 -0
  39. package/dist/_chunks/index-CW3_BcbS.js +6742 -0
  40. package/dist/_chunks/index-CW3_BcbS.js.map +1 -0
  41. package/dist/_chunks/index-DWK63j70.mjs +6705 -0
  42. package/dist/_chunks/index-DWK63j70.mjs.map +1 -0
  43. package/dist/_chunks/index-DdDQ4Urn.mjs +1322 -0
  44. package/dist/_chunks/index-DdDQ4Urn.mjs.map +1 -0
  45. package/dist/_chunks/index-Dn4kcqyl.js +1349 -0
  46. package/dist/_chunks/index-Dn4kcqyl.js.map +1 -0
  47. package/dist/_chunks/it-D04lb2Wc.mjs +167 -0
  48. package/dist/_chunks/it-D04lb2Wc.mjs.map +1 -0
  49. package/dist/_chunks/it-DS4sM3km.js +167 -0
  50. package/dist/_chunks/it-DS4sM3km.js.map +1 -0
  51. package/dist/_chunks/ja-BHLK_2_g.mjs +50 -0
  52. package/dist/_chunks/ja-BHLK_2_g.mjs.map +1 -0
  53. package/dist/_chunks/ja-BjouJgZf.js +50 -0
  54. package/dist/_chunks/ja-BjouJgZf.js.map +1 -0
  55. package/dist/_chunks/ko-D_71Pdfn.js +183 -0
  56. package/dist/_chunks/ko-D_71Pdfn.js.map +1 -0
  57. package/dist/_chunks/ko-DoNsXHXA.mjs +183 -0
  58. package/dist/_chunks/ko-DoNsXHXA.mjs.map +1 -0
  59. package/dist/_chunks/ms-BtGFDB9t.mjs +163 -0
  60. package/dist/_chunks/ms-BtGFDB9t.mjs.map +1 -0
  61. package/dist/_chunks/ms-Re1pSHmx.js +163 -0
  62. package/dist/_chunks/ms-Re1pSHmx.js.map +1 -0
  63. package/dist/_chunks/nl-BaTAuelQ.mjs +156 -0
  64. package/dist/_chunks/nl-BaTAuelQ.mjs.map +1 -0
  65. package/dist/_chunks/nl-DQjrDEw0.js +156 -0
  66. package/dist/_chunks/nl-DQjrDEw0.js.map +1 -0
  67. package/dist/_chunks/pl-BGwXgwH7.js +193 -0
  68. package/dist/_chunks/pl-BGwXgwH7.js.map +1 -0
  69. package/dist/_chunks/pl-CP2Zgp01.mjs +193 -0
  70. package/dist/_chunks/pl-CP2Zgp01.mjs.map +1 -0
  71. package/dist/_chunks/pt-BR-CCQGwXs0.mjs +193 -0
  72. package/dist/_chunks/pt-BR-CCQGwXs0.mjs.map +1 -0
  73. package/dist/_chunks/pt-BR-DPd5nRnl.js +193 -0
  74. package/dist/_chunks/pt-BR-DPd5nRnl.js.map +1 -0
  75. package/dist/_chunks/pt-CJoUDTHQ.js +51 -0
  76. package/dist/_chunks/pt-CJoUDTHQ.js.map +1 -0
  77. package/dist/_chunks/pt-DMeTMW2x.mjs +51 -0
  78. package/dist/_chunks/pt-DMeTMW2x.mjs.map +1 -0
  79. package/dist/_chunks/ru-C8A_4j0w.js +168 -0
  80. package/dist/_chunks/ru-C8A_4j0w.js.map +1 -0
  81. package/dist/_chunks/ru-DGSjru5m.mjs +168 -0
  82. package/dist/_chunks/ru-DGSjru5m.mjs.map +1 -0
  83. package/dist/_chunks/sk-DVK4HfSC.mjs +167 -0
  84. package/dist/_chunks/sk-DVK4HfSC.mjs.map +1 -0
  85. package/dist/_chunks/sk-raWRcmPT.js +167 -0
  86. package/dist/_chunks/sk-raWRcmPT.js.map +1 -0
  87. package/dist/_chunks/sv-BGb12eW3.mjs +202 -0
  88. package/dist/_chunks/sv-BGb12eW3.mjs.map +1 -0
  89. package/dist/_chunks/sv-BNN71SFE.js +202 -0
  90. package/dist/_chunks/sv-BNN71SFE.js.map +1 -0
  91. package/dist/_chunks/th--u3VqsON.mjs +164 -0
  92. package/dist/_chunks/th--u3VqsON.mjs.map +1 -0
  93. package/dist/_chunks/th-C83Bb_kR.js +164 -0
  94. package/dist/_chunks/th-C83Bb_kR.js.map +1 -0
  95. package/dist/_chunks/tr-BW20CfcO.js +179 -0
  96. package/dist/_chunks/tr-BW20CfcO.js.map +1 -0
  97. package/dist/_chunks/tr-DsUerr-c.mjs +179 -0
  98. package/dist/_chunks/tr-DsUerr-c.mjs.map +1 -0
  99. package/dist/_chunks/uk-Bx5IlOKX.mjs +164 -0
  100. package/dist/_chunks/uk-Bx5IlOKX.mjs.map +1 -0
  101. package/dist/_chunks/uk-VwB0oiuV.js +164 -0
  102. package/dist/_chunks/uk-VwB0oiuV.js.map +1 -0
  103. package/dist/_chunks/zh-BiOCwPJu.js +202 -0
  104. package/dist/_chunks/zh-BiOCwPJu.js.map +1 -0
  105. package/dist/_chunks/zh-CsUDN13W.mjs +202 -0
  106. package/dist/_chunks/zh-CsUDN13W.mjs.map +1 -0
  107. package/dist/_chunks/zh-Hans-CLTLm_nt.js +147 -0
  108. package/dist/_chunks/zh-Hans-CLTLm_nt.js.map +1 -0
  109. package/dist/_chunks/zh-Hans-Cc0M5PXr.mjs +147 -0
  110. package/dist/_chunks/zh-Hans-Cc0M5PXr.mjs.map +1 -0
  111. package/dist/admin/index.js +8 -0
  112. package/dist/admin/index.js.map +1 -0
  113. package/dist/admin/index.mjs +8 -0
  114. package/dist/admin/index.mjs.map +1 -0
  115. package/dist/admin/src/components/AllowedTypesSelect.d.ts +9 -0
  116. package/dist/admin/src/components/AttributeIcon.d.ts +9 -0
  117. package/dist/admin/src/components/AttributeOptions/AttributeList.d.ts +6 -0
  118. package/dist/admin/src/components/AttributeOptions/AttributeOption.d.ts +11 -0
  119. package/dist/admin/src/components/AttributeOptions/AttributeOptions.d.ts +13 -0
  120. package/dist/admin/src/components/AttributeOptions/CustomFieldOption.d.ts +22 -0
  121. package/dist/admin/src/components/AttributeOptions/CustomFieldsList.d.ts +1 -0
  122. package/dist/admin/src/components/AttributeOptions/EmptyAttributes.d.ts +2 -0
  123. package/dist/admin/src/components/AttributeOptions/OptionBoxWrapper.d.ts +8 -0
  124. package/dist/admin/src/components/AutoReloadOverlayBlocker.d.ts +25 -0
  125. package/dist/admin/src/components/BooleanDefaultValueSelect.d.ts +20 -0
  126. package/dist/admin/src/components/BooleanRadioGroup.d.ts +8 -0
  127. package/dist/admin/src/components/BoxWrapper.d.ts +8 -0
  128. package/dist/admin/src/components/CheckboxWithNumberField.d.ts +11 -0
  129. package/dist/admin/src/components/ComponentCard/ComponentCard.d.ts +10 -0
  130. package/dist/admin/src/components/ComponentCard/ComponentIcon/ComponentIcon.d.ts +7 -0
  131. package/dist/admin/src/components/ComponentCard/ComponentIcon/index.d.ts +1 -0
  132. package/dist/admin/src/components/ComponentCard/index.d.ts +1 -0
  133. package/dist/admin/src/components/ComponentList.d.ts +10 -0
  134. package/dist/admin/src/components/ContentTypeBuilderNav/ContentTypeBuilderNav.d.ts +1 -0
  135. package/dist/admin/src/components/ContentTypeBuilderNav/useContentTypeBuilderMenu.d.ts +19 -0
  136. package/dist/admin/src/components/ContentTypeRadioGroup.d.ts +15 -0
  137. package/dist/admin/src/components/CustomRadioGroup/CustomRadioGroup.d.ts +15 -0
  138. package/dist/admin/src/components/CustomRadioGroup/Styles.d.ts +5 -0
  139. package/dist/admin/src/components/CustomRadioGroup/index.d.ts +1 -0
  140. package/dist/admin/src/components/DataManagerProvider/DataManagerProvider.d.ts +6 -0
  141. package/dist/admin/src/components/DataManagerProvider/constants.d.ts +17 -0
  142. package/dist/admin/src/components/DataManagerProvider/reducer.d.ts +12 -0
  143. package/dist/admin/src/components/DataManagerProvider/selectors.d.ts +17 -0
  144. package/dist/admin/src/components/DataManagerProvider/utils/cleanData.d.ts +23 -0
  145. package/dist/admin/src/components/DataManagerProvider/utils/createDataObject.d.ts +2 -0
  146. package/dist/admin/src/components/DataManagerProvider/utils/createModifiedDataSchema.d.ts +6 -0
  147. package/dist/admin/src/components/DataManagerProvider/utils/formatSchemas.d.ts +6 -0
  148. package/dist/admin/src/components/DataManagerProvider/utils/retrieveComponentsFromSchema.d.ts +4 -0
  149. package/dist/admin/src/components/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.d.ts +12 -0
  150. package/dist/admin/src/components/DataManagerProvider/utils/retrieveNestedComponents.d.ts +8 -0
  151. package/dist/admin/src/components/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.d.ts +1 -0
  152. package/dist/admin/src/components/DataManagerProvider/utils/serverRestartWatcher.d.ts +6 -0
  153. package/dist/admin/src/components/DataManagerProvider/utils/validateSchema.d.ts +1 -0
  154. package/dist/admin/src/components/DisplayedType.d.ts +7 -0
  155. package/dist/admin/src/components/DraftAndPublishToggle.d.ts +27 -0
  156. package/dist/admin/src/components/DynamicZoneList.d.ts +10 -0
  157. package/dist/admin/src/components/FormModal/FormModal.d.ts +1 -0
  158. package/dist/admin/src/components/FormModal/attributes/advancedForm.d.ts +416 -0
  159. package/dist/admin/src/components/FormModal/attributes/attributeOptions.d.ts +90 -0
  160. package/dist/admin/src/components/FormModal/attributes/baseForm.d.ts +376 -0
  161. package/dist/admin/src/components/FormModal/attributes/commonBaseForm.d.ts +17 -0
  162. package/dist/admin/src/components/FormModal/attributes/form.d.ts +792 -0
  163. package/dist/admin/src/components/FormModal/attributes/nameField.d.ts +12 -0
  164. package/dist/admin/src/components/FormModal/attributes/types.d.ts +325 -0
  165. package/dist/admin/src/components/FormModal/attributes/validation/common.d.ts +29 -0
  166. package/dist/admin/src/components/FormModal/category/createCategorySchema.d.ts +5 -0
  167. package/dist/admin/src/components/FormModal/category/form.d.ts +20 -0
  168. package/dist/admin/src/components/FormModal/category/regex.d.ts +1 -0
  169. package/dist/admin/src/components/FormModal/component/componentField.d.ts +20 -0
  170. package/dist/admin/src/components/FormModal/component/componentForm.d.ts +25 -0
  171. package/dist/admin/src/components/FormModal/component/createComponentSchema.d.ts +10 -0
  172. package/dist/admin/src/components/FormModal/constants.d.ts +12 -0
  173. package/dist/admin/src/components/FormModal/contentType/contentTypeForm.d.ts +116 -0
  174. package/dist/admin/src/components/FormModal/contentType/createContentTypeSchema.d.ts +24 -0
  175. package/dist/admin/src/components/FormModal/dynamiczoneForm.d.ts +68 -0
  176. package/dist/admin/src/components/FormModal/forms/forms.d.ts +207 -0
  177. package/dist/admin/src/components/FormModal/forms/utils/addItemsToFormSection.d.ts +38 -0
  178. package/dist/admin/src/components/FormModal/forms/utils/createCollectionName.d.ts +2 -0
  179. package/dist/admin/src/components/FormModal/forms/utils/getUsedAttributeNames.d.ts +11 -0
  180. package/dist/admin/src/components/FormModal/reducer.d.ts +4 -0
  181. package/dist/admin/src/components/FormModal/selectors.d.ts +16 -0
  182. package/dist/admin/src/components/FormModal/utils/canEditContentType.d.ts +18 -0
  183. package/dist/admin/src/components/FormModal/utils/createUid.d.ts +4 -0
  184. package/dist/admin/src/components/FormModal/utils/customFieldDefaultOptionsReducer.d.ts +1 -0
  185. package/dist/admin/src/components/FormModal/utils/getAttributesToDisplay.d.ts +4 -0
  186. package/dist/admin/src/components/FormModal/utils/getFormInputNames.d.ts +1 -0
  187. package/dist/admin/src/components/FormModal/utils/relations.d.ts +4 -0
  188. package/dist/admin/src/components/FormModalEndActions.d.ts +42 -0
  189. package/dist/admin/src/components/FormModalHeader.d.ts +18 -0
  190. package/dist/admin/src/components/FormModalNavigationProvider/FormModalNavigationProvider.d.ts +22 -0
  191. package/dist/admin/src/components/FormModalNavigationProvider/constants.d.ts +17 -0
  192. package/dist/admin/src/components/FormModalSubHeader.d.ts +22 -0
  193. package/dist/admin/src/components/GenericInputs.d.ts +57 -0
  194. package/dist/admin/src/components/IconPicker/IconPicker.d.ts +13 -0
  195. package/dist/admin/src/components/IconPicker/constants.d.ts +5 -0
  196. package/dist/admin/src/components/IconPicker/index.d.ts +1 -0
  197. package/dist/admin/src/components/List.d.ts +18 -0
  198. package/dist/admin/src/components/ListRow.d.ts +26 -0
  199. package/dist/admin/src/components/NestedFooter.d.ts +9 -0
  200. package/dist/admin/src/components/PluralName.d.ts +22 -0
  201. package/dist/admin/src/components/Relation/Relation.d.ts +9 -0
  202. package/dist/admin/src/components/Relation/RelationField/RelationField.d.ts +13 -0
  203. package/dist/admin/src/components/Relation/RelationField/RelationTargetPicker/RelationTargetPicker.d.ts +6 -0
  204. package/dist/admin/src/components/Relation/RelationNaturePicker/Components.d.ts +22 -0
  205. package/dist/admin/src/components/Relation/RelationNaturePicker/RelationNaturePicker.d.ts +8 -0
  206. package/dist/admin/src/components/SelectCategory.d.ts +21 -0
  207. package/dist/admin/src/components/SelectComponent.d.ts +20 -0
  208. package/dist/admin/src/components/SelectComponents.d.ts +19 -0
  209. package/dist/admin/src/components/SelectDateType.d.ts +38 -0
  210. package/dist/admin/src/components/SelectNumber.d.ts +42 -0
  211. package/dist/admin/src/components/SingularName.d.ts +17 -0
  212. package/dist/admin/src/components/TabForm.d.ts +9 -0
  213. package/dist/admin/src/components/TextareaEnum.d.ts +20 -0
  214. package/dist/admin/src/components/Tr.d.ts +5 -0
  215. package/dist/admin/src/components/UpperFirst.d.ts +3 -0
  216. package/dist/admin/src/constants.d.ts +7 -0
  217. package/dist/admin/src/contexts/DataManagerContext.d.ts +41 -0
  218. package/dist/admin/src/contexts/FormModalNavigationContext.d.ts +40 -0
  219. package/dist/admin/src/exports.d.ts +15 -0
  220. package/dist/admin/src/hooks/useDataManager.d.ts +1 -0
  221. package/dist/admin/src/hooks/useFormModalNavigation.d.ts +1 -0
  222. package/dist/admin/src/icons/Curve.d.ts +5 -0
  223. package/dist/admin/src/index.d.ts +17 -0
  224. package/dist/admin/src/pages/App/index.d.ts +2 -0
  225. package/dist/admin/src/pages/ListView/LinkToCMSettingsView.d.ts +10 -0
  226. package/dist/admin/src/pages/ListView/ListView.d.ts +2 -0
  227. package/dist/admin/src/pages/RecursivePath/RecursivePath.d.ts +1 -0
  228. package/dist/admin/src/pluginId.d.ts +1 -0
  229. package/dist/admin/src/reducers.d.ts +3 -0
  230. package/dist/admin/src/types.d.ts +57 -0
  231. package/dist/admin/src/utils/findAttribute.d.ts +2 -0
  232. package/dist/admin/src/utils/formAPI.d.ts +1 -0
  233. package/dist/admin/src/utils/getAttributeDisplayedType.d.ts +1 -0
  234. package/dist/admin/src/utils/getMaxDepth.d.ts +23 -0
  235. package/dist/admin/src/utils/getRelationType.d.ts +6 -0
  236. package/dist/admin/src/utils/getTrad.d.ts +1 -0
  237. package/dist/admin/src/utils/getYupInnerErrors.d.ts +7 -0
  238. package/dist/admin/src/utils/index.d.ts +2 -0
  239. package/dist/admin/src/utils/isAllowedContentTypesForRelations.d.ts +2 -0
  240. package/dist/admin/src/utils/makeUnique.d.ts +2 -0
  241. package/dist/admin/src/utils/nameToSlug.d.ts +1 -0
  242. package/dist/admin/src/utils/parseDateValue.d.ts +1 -0
  243. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  244. package/dist/admin/src/utils/startsWithANumber.d.ts +1 -0
  245. package/dist/admin/src/utils/timeFormat.d.ts +16 -0
  246. package/dist/admin/src/utils/toRegressedEnumValue.d.ts +1 -0
  247. package/dist/server/index.js +2330 -0
  248. package/dist/server/index.js.map +1 -0
  249. package/dist/server/index.mjs +2309 -0
  250. package/dist/server/index.mjs.map +1 -0
  251. package/dist/server/src/bootstrap.d.ts +6 -0
  252. package/dist/server/src/bootstrap.d.ts.map +1 -0
  253. package/dist/server/src/config.d.ts +6 -0
  254. package/dist/server/src/config.d.ts.map +1 -0
  255. package/dist/server/src/controllers/builder.d.ts +6 -0
  256. package/dist/server/src/controllers/builder.d.ts.map +1 -0
  257. package/dist/server/src/controllers/component-categories.d.ts +7 -0
  258. package/dist/server/src/controllers/component-categories.d.ts.map +1 -0
  259. package/dist/server/src/controllers/components.d.ts +38 -0
  260. package/dist/server/src/controllers/components.d.ts.map +1 -0
  261. package/dist/server/src/controllers/content-types.d.ts +10 -0
  262. package/dist/server/src/controllers/content-types.d.ts.map +1 -0
  263. package/dist/server/src/controllers/index.d.ts +25 -0
  264. package/dist/server/src/controllers/index.d.ts.map +1 -0
  265. package/dist/server/src/controllers/validation/common.d.ts +25 -0
  266. package/dist/server/src/controllers/validation/common.d.ts.map +1 -0
  267. package/dist/server/src/controllers/validation/component-category.d.ts +5 -0
  268. package/dist/server/src/controllers/validation/component-category.d.ts.map +1 -0
  269. package/dist/server/src/controllers/validation/component.d.ts +25 -0
  270. package/dist/server/src/controllers/validation/component.d.ts.map +1 -0
  271. package/dist/server/src/controllers/validation/content-type.d.ts +36 -0
  272. package/dist/server/src/controllers/validation/content-type.d.ts.map +1 -0
  273. package/dist/server/src/controllers/validation/data-transform.d.ts +4 -0
  274. package/dist/server/src/controllers/validation/data-transform.d.ts.map +1 -0
  275. package/dist/server/src/controllers/validation/model-schema.d.ts +12 -0
  276. package/dist/server/src/controllers/validation/model-schema.d.ts.map +1 -0
  277. package/dist/server/src/controllers/validation/relations.d.ts +16 -0
  278. package/dist/server/src/controllers/validation/relations.d.ts.map +1 -0
  279. package/dist/server/src/controllers/validation/types.d.ts +9 -0
  280. package/dist/server/src/controllers/validation/types.d.ts.map +1 -0
  281. package/dist/server/src/index.d.ts +68 -0
  282. package/dist/server/src/index.d.ts.map +1 -0
  283. package/dist/server/src/routes/admin.d.ts +18 -0
  284. package/dist/server/src/routes/admin.d.ts.map +1 -0
  285. package/dist/server/src/routes/content-api.d.ts +10 -0
  286. package/dist/server/src/routes/content-api.d.ts.map +1 -0
  287. package/dist/server/src/routes/index.d.ts +28 -0
  288. package/dist/server/src/routes/index.d.ts.map +1 -0
  289. package/dist/server/src/services/api-handler.d.ts +15 -0
  290. package/dist/server/src/services/api-handler.d.ts.map +1 -0
  291. package/dist/server/src/services/builder.d.ts +9 -0
  292. package/dist/server/src/services/builder.d.ts.map +1 -0
  293. package/dist/server/src/services/component-categories.d.ts +13 -0
  294. package/dist/server/src/services/component-categories.d.ts.map +1 -0
  295. package/dist/server/src/services/components.d.ts +54 -0
  296. package/dist/server/src/services/components.d.ts.map +1 -0
  297. package/dist/server/src/services/constants.d.ts +18 -0
  298. package/dist/server/src/services/constants.d.ts.map +1 -0
  299. package/dist/server/src/services/content-types.d.ts +60 -0
  300. package/dist/server/src/services/content-types.d.ts.map +1 -0
  301. package/dist/server/src/services/index.d.ts +14 -0
  302. package/dist/server/src/services/index.d.ts.map +1 -0
  303. package/dist/server/src/services/schema-builder/component-builder.d.ts +39 -0
  304. package/dist/server/src/services/schema-builder/component-builder.d.ts.map +1 -0
  305. package/dist/server/src/services/schema-builder/content-type-builder.d.ts +38 -0
  306. package/dist/server/src/services/schema-builder/content-type-builder.d.ts.map +1 -0
  307. package/dist/server/src/services/schema-builder/index.d.ts +78 -0
  308. package/dist/server/src/services/schema-builder/index.d.ts.map +1 -0
  309. package/dist/server/src/services/schema-builder/schema-handler.d.ts +36 -0
  310. package/dist/server/src/services/schema-builder/schema-handler.d.ts.map +1 -0
  311. package/dist/server/src/utils/attributes.d.ts +191 -0
  312. package/dist/server/src/utils/attributes.d.ts.map +1 -0
  313. package/dist/server/src/utils/helpers.d.ts +3 -0
  314. package/dist/server/src/utils/helpers.d.ts.map +1 -0
  315. package/dist/server/src/utils/index.d.ts +15 -0
  316. package/dist/server/src/utils/index.d.ts.map +1 -0
  317. package/dist/server/src/utils/typeguards.d.ts +3 -0
  318. package/dist/server/src/utils/typeguards.d.ts.map +1 -0
  319. package/package.json +111 -0
@@ -0,0 +1,2330 @@
1
+ "use strict";
2
+ const _ = require("lodash");
3
+ const fp = require("lodash/fp");
4
+ const utils = require("@strapi/utils");
5
+ const path = require("path");
6
+ const fse = require("fs-extra");
7
+ const pluralize = require("pluralize");
8
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule)
11
+ return e;
12
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
13
+ if (e) {
14
+ for (const k in e) {
15
+ if (k !== "default") {
16
+ const d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: () => e[k]
20
+ });
21
+ }
22
+ }
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+ const ___default = /* @__PURE__ */ _interopDefault(_);
28
+ const utils__default = /* @__PURE__ */ _interopDefault(utils);
29
+ const path__namespace = /* @__PURE__ */ _interopNamespace(path);
30
+ const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
31
+ const pluralize__default = /* @__PURE__ */ _interopDefault(pluralize);
32
+ const config = {
33
+ default: {},
34
+ validator() {
35
+ }
36
+ };
37
+ const bootstrap = async ({ strapi: strapi2 }) => {
38
+ const actions = [
39
+ {
40
+ section: "plugins",
41
+ displayName: "Read",
42
+ uid: "read",
43
+ pluginName: "content-type-builder"
44
+ }
45
+ ];
46
+ await strapi2.service("admin::permission").actionProvider.registerMany(actions);
47
+ };
48
+ const { ApplicationError: ApplicationError$3 } = utils.errors;
49
+ const isConfigurable = (attribute) => ___default.default.get(attribute, "configurable", true);
50
+ const isRelation = (attribute) => attribute.type === "relation";
51
+ const formatAttributes = (model) => {
52
+ const { getVisibleAttributes } = utils__default.default.contentTypes;
53
+ return getVisibleAttributes(model).reduce((acc, key) => {
54
+ acc[key] = formatAttribute(model.attributes[key]);
55
+ return acc;
56
+ }, {});
57
+ };
58
+ const formatAttribute = (attribute) => {
59
+ const { configurable, required, autoPopulate, pluginOptions } = attribute;
60
+ if (attribute.type === "media") {
61
+ return {
62
+ type: "media",
63
+ multiple: !!attribute.multiple,
64
+ required: !!required,
65
+ configurable: configurable === false ? false : void 0,
66
+ private: !!attribute.private,
67
+ allowedTypes: attribute.allowedTypes,
68
+ pluginOptions
69
+ };
70
+ }
71
+ if (attribute.type === "relation") {
72
+ return {
73
+ ...attribute,
74
+ type: "relation",
75
+ target: attribute.target,
76
+ targetAttribute: attribute.inversedBy || attribute.mappedBy || null,
77
+ configurable: configurable === false ? false : void 0,
78
+ private: !!attribute.private,
79
+ pluginOptions,
80
+ // TODO: remove
81
+ autoPopulate
82
+ };
83
+ }
84
+ return attribute;
85
+ };
86
+ const replaceTemporaryUIDs = (uidMap) => (schema) => {
87
+ return {
88
+ ...schema,
89
+ attributes: Object.keys(schema.attributes).reduce((acc, key) => {
90
+ const attr = schema.attributes[key];
91
+ if (attr.type === "component") {
92
+ if (___default.default.has(uidMap, attr.component)) {
93
+ acc[key] = {
94
+ ...attr,
95
+ component: uidMap[attr.component]
96
+ };
97
+ return acc;
98
+ }
99
+ if (!___default.default.has(strapi.components, attr.component)) {
100
+ throw new ApplicationError$3("component.notFound");
101
+ }
102
+ }
103
+ if (attr.type === "dynamiczone" && ___default.default.intersection(attr.components, Object.keys(uidMap)).length > 0) {
104
+ acc[key] = {
105
+ ...attr,
106
+ components: attr.components.map((value) => {
107
+ if (___default.default.has(uidMap, value))
108
+ return uidMap[value];
109
+ if (!___default.default.has(strapi.components, value)) {
110
+ throw new ApplicationError$3("component.notFound");
111
+ }
112
+ return value;
113
+ })
114
+ };
115
+ return acc;
116
+ }
117
+ acc[key] = attr;
118
+ return acc;
119
+ }, {})
120
+ };
121
+ };
122
+ function createSchemaHandler(infos) {
123
+ const { category, modelName, plugin, uid, dir, filename, schema } = infos;
124
+ const initialState = {
125
+ modelName,
126
+ plugin,
127
+ category,
128
+ uid,
129
+ dir,
130
+ filename,
131
+ schema: schema || {
132
+ info: {},
133
+ options: {},
134
+ attributes: {}
135
+ }
136
+ };
137
+ const state = ___default.default.cloneDeep(initialState);
138
+ Object.freeze(initialState.schema);
139
+ let modified = false;
140
+ let deleted = false;
141
+ return {
142
+ get modelName() {
143
+ return initialState.modelName;
144
+ },
145
+ get plugin() {
146
+ return initialState.plugin;
147
+ },
148
+ get category() {
149
+ return initialState.category;
150
+ },
151
+ get kind() {
152
+ return ___default.default.get(state.schema, "kind", "collectionType");
153
+ },
154
+ get uid() {
155
+ return state.uid;
156
+ },
157
+ get writable() {
158
+ return ___default.default.get(state, "plugin") !== "admin";
159
+ },
160
+ setUID(val) {
161
+ modified = true;
162
+ state.uid = val;
163
+ return this;
164
+ },
165
+ setDir(val) {
166
+ modified = true;
167
+ state.dir = val;
168
+ return this;
169
+ },
170
+ get schema() {
171
+ return ___default.default.cloneDeep(state.schema);
172
+ },
173
+ setSchema(val) {
174
+ modified = true;
175
+ state.schema = ___default.default.cloneDeep(val);
176
+ return this;
177
+ },
178
+ // get a particular path inside the schema
179
+ get(path2) {
180
+ return ___default.default.get(state.schema, path2);
181
+ },
182
+ // set a particular path inside the schema
183
+ set(path2, val) {
184
+ if (!state.schema)
185
+ return this;
186
+ modified = true;
187
+ const value = ___default.default.defaultTo(val, ___default.default.get(state.schema, path2));
188
+ ___default.default.set(state.schema, path2, value);
189
+ return this;
190
+ },
191
+ // delete a particular path inside the schema
192
+ unset(path2) {
193
+ modified = true;
194
+ ___default.default.unset(state.schema, path2);
195
+ return this;
196
+ },
197
+ delete() {
198
+ deleted = true;
199
+ return this;
200
+ },
201
+ getAttribute(key) {
202
+ return this.get(["attributes", key]);
203
+ },
204
+ setAttribute(key, attribute) {
205
+ return this.set(["attributes", key], attribute);
206
+ },
207
+ deleteAttribute(key) {
208
+ return this.unset(["attributes", key]);
209
+ },
210
+ setAttributes(newAttributes) {
211
+ if (!this.schema)
212
+ return this;
213
+ for (const key in this.schema.attributes) {
214
+ if (isConfigurable(this.schema.attributes[key])) {
215
+ this.deleteAttribute(key);
216
+ }
217
+ }
218
+ for (const key of Object.keys(newAttributes)) {
219
+ this.setAttribute(key, newAttributes[key]);
220
+ }
221
+ return this;
222
+ },
223
+ removeContentType(uid2) {
224
+ if (!state.schema)
225
+ return this;
226
+ const attributes = state.schema.attributes;
227
+ Object.keys(attributes).forEach((key) => {
228
+ const attribute = attributes[key];
229
+ if (attribute.target === uid2) {
230
+ this.deleteAttribute(key);
231
+ }
232
+ });
233
+ return this;
234
+ },
235
+ // utils
236
+ removeComponent(uid2) {
237
+ if (!state.schema)
238
+ return this;
239
+ const attributes = state.schema.attributes;
240
+ Object.keys(attributes).forEach((key) => {
241
+ const attr = attributes[key];
242
+ if (attr.type === "component" && attr.component === uid2) {
243
+ this.deleteAttribute(key);
244
+ }
245
+ if (attr.type === "dynamiczone" && Array.isArray(attr.components) && attr.components.includes(uid2)) {
246
+ const updatedComponentList = attributes[key].components.filter(
247
+ (val) => val !== uid2
248
+ );
249
+ this.set(["attributes", key, "components"], updatedComponentList);
250
+ }
251
+ });
252
+ return this;
253
+ },
254
+ updateComponent(uid2, newUID) {
255
+ if (!state.schema)
256
+ return this;
257
+ const attributes = state.schema.attributes;
258
+ Object.keys(attributes).forEach((key) => {
259
+ const attr = attributes[key];
260
+ if (attr.type === "component" && attr.component === uid2) {
261
+ this.set(["attributes", key, "component"], newUID);
262
+ }
263
+ if (attr.type === "dynamiczone" && Array.isArray(attr.components) && attr.components.includes(uid2)) {
264
+ const updatedComponentList = attr.components.map(
265
+ (val) => val === uid2 ? newUID : val
266
+ );
267
+ this.set(["attributes", key, "components"], updatedComponentList);
268
+ }
269
+ });
270
+ return this;
271
+ },
272
+ // save the schema to disk
273
+ async flush() {
274
+ if (!this.writable) {
275
+ return;
276
+ }
277
+ const initialPath = path__namespace.default.join(initialState.dir, initialState.filename);
278
+ const filePath = path__namespace.default.join(state.dir, state.filename);
279
+ if (deleted) {
280
+ await fse__namespace.default.remove(initialPath);
281
+ const list = await fse__namespace.default.readdir(initialState.dir);
282
+ if (list.length === 0) {
283
+ await fse__namespace.default.remove(initialState.dir);
284
+ }
285
+ return;
286
+ }
287
+ if (modified) {
288
+ if (!state.schema)
289
+ return Promise.resolve();
290
+ await fse__namespace.default.ensureFile(filePath);
291
+ await fse__namespace.default.writeJSON(
292
+ filePath,
293
+ {
294
+ kind: state.schema.kind,
295
+ collectionName: state.schema.collectionName,
296
+ info: state.schema.info,
297
+ options: state.schema.options,
298
+ pluginOptions: state.schema.pluginOptions,
299
+ attributes: state.schema.attributes,
300
+ config: state.schema.config
301
+ },
302
+ { spaces: 2 }
303
+ );
304
+ if (initialPath !== filePath) {
305
+ await fse__namespace.default.remove(initialPath);
306
+ const list = await fse__namespace.default.readdir(initialState.dir);
307
+ if (list.length === 0) {
308
+ await fse__namespace.default.remove(initialState.dir);
309
+ }
310
+ }
311
+ return;
312
+ }
313
+ return Promise.resolve();
314
+ },
315
+ // reset the schema to its initial value
316
+ async rollback() {
317
+ if (!this.writable) {
318
+ return;
319
+ }
320
+ const initialPath = path__namespace.default.join(initialState.dir, initialState.filename);
321
+ const filePath = path__namespace.default.join(state.dir, state.filename);
322
+ if (!initialState.uid) {
323
+ await fse__namespace.default.remove(filePath);
324
+ const list = await fse__namespace.default.readdir(state.dir);
325
+ if (list.length === 0) {
326
+ await fse__namespace.default.remove(state.dir);
327
+ }
328
+ return;
329
+ }
330
+ if (modified || deleted) {
331
+ await fse__namespace.default.ensureFile(initialPath);
332
+ await fse__namespace.default.writeJSON(initialPath, initialState.schema, { spaces: 2 });
333
+ if (initialPath !== filePath) {
334
+ await fse__namespace.default.remove(filePath);
335
+ const list = await fse__namespace.default.readdir(state.dir);
336
+ if (list.length === 0) {
337
+ await fse__namespace.default.remove(state.dir);
338
+ }
339
+ }
340
+ }
341
+ return Promise.resolve();
342
+ }
343
+ };
344
+ }
345
+ const { ApplicationError: ApplicationError$2 } = utils.errors;
346
+ function createComponentBuilder$1() {
347
+ return {
348
+ createComponentUID({ category, displayName }) {
349
+ return `${utils.strings.nameToSlug(category)}.${utils.strings.nameToSlug(displayName)}`;
350
+ },
351
+ createNewComponentUIDMap(components2) {
352
+ return components2.reduce((uidMap, component) => {
353
+ uidMap[component.tmpUID] = this.createComponentUID(component);
354
+ return uidMap;
355
+ }, {});
356
+ },
357
+ /**
358
+ * create a component in the tmpComponent map
359
+ */
360
+ createComponent(infos) {
361
+ const uid = this.createComponentUID(infos);
362
+ if (this.components.has(uid)) {
363
+ throw new ApplicationError$2("component.alreadyExists");
364
+ }
365
+ const handler = createSchemaHandler({
366
+ dir: path__namespace.default.join(strapi.dirs.app.components, utils.strings.nameToSlug(infos.category)),
367
+ filename: `${utils.strings.nameToSlug(infos.displayName)}.json`
368
+ });
369
+ const collectionName = `components_${utils.strings.nameToCollectionName(
370
+ infos.category
371
+ )}_${utils.strings.nameToCollectionName(pluralize__default.default(infos.displayName))}`;
372
+ this.components.forEach((compo) => {
373
+ if (compo.schema.collectionName === collectionName) {
374
+ throw new ApplicationError$2("component.alreadyExists");
375
+ }
376
+ });
377
+ handler.setUID(uid).set("collectionName", collectionName).set(["info", "displayName"], infos.displayName).set(["info", "icon"], infos.icon).set(["info", "description"], infos.description).set("pluginOptions", infos.pluginOptions).set("config", infos.config).setAttributes(this.convertAttributes(infos.attributes));
378
+ if (this.components.size === 0) {
379
+ strapi.telemetry.send("didCreateFirstComponent");
380
+ } else {
381
+ strapi.telemetry.send("didCreateComponent");
382
+ }
383
+ this.components.set(uid, handler);
384
+ return handler;
385
+ },
386
+ /**
387
+ * create a component in the tmpComponent map
388
+ */
389
+ editComponent(infos) {
390
+ const { uid } = infos;
391
+ if (!this.components.has(uid)) {
392
+ throw new utils.errors.ApplicationError("component.notFound");
393
+ }
394
+ const component = this.components.get(uid);
395
+ const [, nameUID] = uid.split(".");
396
+ const newCategory = utils.strings.nameToSlug(infos.category);
397
+ const newUID = `${newCategory}.${nameUID}`;
398
+ if (newUID !== uid && this.components.has(newUID)) {
399
+ throw new utils.errors.ApplicationError("component.edit.alreadyExists");
400
+ }
401
+ const newDir = path__namespace.default.join(strapi.dirs.app.components, newCategory);
402
+ const oldAttributes = component.schema.attributes;
403
+ const newAttributes = ___default.default.omitBy(infos.attributes, (attr, key) => {
404
+ return ___default.default.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);
405
+ });
406
+ component.setUID(newUID).setDir(newDir).set(["info", "displayName"], infos.displayName).set(["info", "icon"], infos.icon).set(["info", "description"], infos.description).set("pluginOptions", infos.pluginOptions).setAttributes(this.convertAttributes(newAttributes));
407
+ if (newUID !== uid) {
408
+ this.components.forEach((compo) => {
409
+ compo.updateComponent(uid, newUID);
410
+ });
411
+ this.contentTypes.forEach((ct) => {
412
+ ct.updateComponent(uid, newUID);
413
+ });
414
+ }
415
+ return component;
416
+ },
417
+ deleteComponent(uid) {
418
+ if (!this.components.has(uid)) {
419
+ throw new utils.errors.ApplicationError("component.notFound");
420
+ }
421
+ this.components.forEach((compo) => {
422
+ compo.removeComponent(uid);
423
+ });
424
+ this.contentTypes.forEach((ct) => {
425
+ ct.removeComponent(uid);
426
+ });
427
+ return this.components.get(uid).delete();
428
+ }
429
+ };
430
+ }
431
+ const modelTypes = {
432
+ CONTENT_TYPE: "CONTENT_TYPE",
433
+ COMPONENT: "COMPONENT"
434
+ };
435
+ const typeKinds = {
436
+ SINGLE_TYPE: "singleType",
437
+ COLLECTION_TYPE: "collectionType"
438
+ };
439
+ const DEFAULT_TYPES = [
440
+ // advanced types
441
+ "media",
442
+ // scalar types
443
+ "string",
444
+ "text",
445
+ "richtext",
446
+ "blocks",
447
+ "json",
448
+ "enumeration",
449
+ "password",
450
+ "email",
451
+ "integer",
452
+ "biginteger",
453
+ "float",
454
+ "decimal",
455
+ "date",
456
+ "time",
457
+ "datetime",
458
+ "timestamp",
459
+ "boolean",
460
+ "relation"
461
+ ];
462
+ const VALID_UID_TARGETS = ["string", "text"];
463
+ const coreUids = {
464
+ STRAPI_USER: "admin::user",
465
+ PREFIX: "strapi::"
466
+ };
467
+ const pluginsUids = {
468
+ UPLOAD_FILE: "plugin::upload.file"
469
+ };
470
+ const { ApplicationError: ApplicationError$1 } = utils.errors;
471
+ const reuseUnsetPreviousProperties = (newAttribute, oldAttribute) => {
472
+ ___default.default.defaults(
473
+ newAttribute,
474
+ ___default.default.omit(oldAttribute, [
475
+ "configurable",
476
+ "required",
477
+ "private",
478
+ "unique",
479
+ "pluginOptions",
480
+ "inversedBy",
481
+ "mappedBy"
482
+ ])
483
+ );
484
+ };
485
+ function createComponentBuilder() {
486
+ return {
487
+ setRelation({ key, uid, attribute }) {
488
+ if (!___default.default.has(attribute, "target")) {
489
+ return;
490
+ }
491
+ const targetCT = this.contentTypes.get(attribute.target);
492
+ const targetAttribute = targetCT.getAttribute(attribute.targetAttribute);
493
+ if (!attribute.targetAttribute) {
494
+ return;
495
+ }
496
+ targetCT.setAttribute(
497
+ attribute.targetAttribute,
498
+ generateRelation({ key, attribute, uid, targetAttribute })
499
+ );
500
+ },
501
+ unsetRelation(attribute) {
502
+ if (!___default.default.has(attribute, "target")) {
503
+ return;
504
+ }
505
+ const targetCT = this.contentTypes.get(attribute.target);
506
+ const targetAttributeName = attribute.inversedBy || attribute.mappedBy;
507
+ const targetAttribute = targetCT.getAttribute(targetAttributeName);
508
+ if (!targetAttribute)
509
+ return;
510
+ return targetCT.deleteAttribute(targetAttributeName);
511
+ },
512
+ /**
513
+ * Creates a content type in memory to be written to files later on
514
+ */
515
+ createContentType(infos) {
516
+ const uid = createContentTypeUID(infos);
517
+ if (this.contentTypes.has(uid)) {
518
+ throw new ApplicationError$1("contentType.alreadyExists");
519
+ }
520
+ const contentType = createSchemaHandler({
521
+ modelName: infos.singularName,
522
+ dir: path__namespace.default.join(
523
+ strapi.dirs.app.api,
524
+ infos.singularName,
525
+ "content-types",
526
+ infos.singularName
527
+ ),
528
+ filename: `schema.json`
529
+ });
530
+ this.contentTypes.set(uid, contentType);
531
+ Object.keys(infos.attributes).forEach((key) => {
532
+ const { target } = infos.attributes[key];
533
+ if (target === "__self__") {
534
+ infos.attributes[key].target = uid;
535
+ }
536
+ });
537
+ contentType.setUID(uid).set("kind", infos.kind || typeKinds.COLLECTION_TYPE).set(
538
+ "collectionName",
539
+ infos.collectionName || utils.strings.nameToCollectionName(infos.pluralName)
540
+ ).set("info", {
541
+ singularName: infos.singularName,
542
+ pluralName: infos.pluralName,
543
+ displayName: infos.displayName,
544
+ description: infos.description
545
+ }).set("options", {
546
+ ...infos.options ?? {},
547
+ draftAndPublish: infos.draftAndPublish
548
+ }).set("pluginOptions", infos.pluginOptions).set("config", infos.config).setAttributes(this.convertAttributes(infos.attributes));
549
+ Object.keys(infos.attributes).forEach((key) => {
550
+ const attribute = infos.attributes[key];
551
+ if (isRelation(attribute)) {
552
+ if (["manyToMany", "oneToOne"].includes(attribute.relation)) {
553
+ if (attribute.target === uid && attribute.targetAttribute !== void 0) {
554
+ const targetAttribute = infos.attributes[attribute.targetAttribute];
555
+ if (targetAttribute.dominant === void 0) {
556
+ attribute.dominant = true;
557
+ } else {
558
+ attribute.dominant = false;
559
+ }
560
+ } else {
561
+ attribute.dominant = true;
562
+ }
563
+ }
564
+ this.setRelation({
565
+ key,
566
+ uid,
567
+ attribute
568
+ });
569
+ }
570
+ });
571
+ return contentType;
572
+ },
573
+ editContentType(infos) {
574
+ const { uid } = infos;
575
+ if (!this.contentTypes.has(uid)) {
576
+ throw new ApplicationError$1("contentType.notFound");
577
+ }
578
+ const contentType = this.contentTypes.get(uid);
579
+ const oldAttributes = contentType.schema.attributes;
580
+ const newAttributes = ___default.default.omitBy(infos.attributes, (attr, key) => {
581
+ return ___default.default.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);
582
+ });
583
+ const newKeys = ___default.default.difference(Object.keys(newAttributes), Object.keys(oldAttributes));
584
+ const deletedKeys = ___default.default.difference(Object.keys(oldAttributes), Object.keys(newAttributes));
585
+ const remainingKeys = ___default.default.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));
586
+ deletedKeys.forEach((key) => {
587
+ const attribute = oldAttributes[key];
588
+ const targetAttributeName = attribute.inversedBy || attribute.mappedBy;
589
+ if (isConfigurable(attribute) && isRelation(attribute) && !___default.default.isNil(targetAttributeName)) {
590
+ this.unsetRelation(attribute);
591
+ }
592
+ });
593
+ remainingKeys.forEach((key) => {
594
+ const oldAttribute = oldAttributes[key];
595
+ const newAttribute = newAttributes[key];
596
+ if (!isRelation(oldAttribute) && isRelation(newAttribute)) {
597
+ return this.setRelation({
598
+ key,
599
+ uid,
600
+ attribute: newAttributes[key]
601
+ });
602
+ }
603
+ if (isRelation(oldAttribute) && !isRelation(newAttribute)) {
604
+ return this.unsetRelation(oldAttribute);
605
+ }
606
+ if (isRelation(oldAttribute) && isRelation(newAttribute)) {
607
+ const oldTargetAttributeName = oldAttribute.inversedBy || oldAttribute.mappedBy;
608
+ const sameRelation = oldAttribute.relation === newAttribute.relation;
609
+ const targetAttributeHasChanged = oldTargetAttributeName !== newAttribute.targetAttribute;
610
+ if (!sameRelation || targetAttributeHasChanged) {
611
+ this.unsetRelation(oldAttribute);
612
+ }
613
+ reuseUnsetPreviousProperties(newAttribute, oldAttribute);
614
+ if (oldAttribute.inversedBy) {
615
+ newAttribute.dominant = true;
616
+ } else if (oldAttribute.mappedBy) {
617
+ newAttribute.dominant = false;
618
+ }
619
+ return this.setRelation({
620
+ key,
621
+ uid,
622
+ attribute: newAttribute
623
+ });
624
+ }
625
+ });
626
+ newKeys.forEach((key) => {
627
+ const attribute = newAttributes[key];
628
+ if (isRelation(attribute)) {
629
+ if (["manyToMany", "oneToOne"].includes(attribute.relation)) {
630
+ if (attribute.target === uid && attribute.targetAttribute !== void 0) {
631
+ const targetAttribute = newAttributes[attribute.targetAttribute];
632
+ if (targetAttribute.dominant === void 0) {
633
+ attribute.dominant = true;
634
+ } else {
635
+ attribute.dominant = false;
636
+ }
637
+ } else {
638
+ attribute.dominant = true;
639
+ }
640
+ }
641
+ this.setRelation({
642
+ key,
643
+ uid,
644
+ attribute
645
+ });
646
+ }
647
+ });
648
+ contentType.set("kind", infos.kind || contentType.schema.kind).set(["info", "displayName"], infos.displayName).set(["info", "description"], infos.description).set("options", {
649
+ ...infos.options ?? {},
650
+ draftAndPublish: infos.draftAndPublish
651
+ }).set("pluginOptions", infos.pluginOptions).setAttributes(this.convertAttributes(newAttributes));
652
+ return contentType;
653
+ },
654
+ deleteContentType(uid) {
655
+ if (!this.contentTypes.has(uid)) {
656
+ throw new ApplicationError$1("contentType.notFound");
657
+ }
658
+ this.components.forEach((compo) => {
659
+ compo.removeContentType(uid);
660
+ });
661
+ this.contentTypes.forEach((ct) => {
662
+ ct.removeContentType(uid);
663
+ });
664
+ return this.contentTypes.get(uid).delete();
665
+ }
666
+ };
667
+ }
668
+ const createContentTypeUID = ({
669
+ singularName
670
+ }) => `api::${singularName}.${singularName}`;
671
+ const generateRelation = ({ key, attribute, uid, targetAttribute = {} }) => {
672
+ const opts = {
673
+ type: "relation",
674
+ target: uid,
675
+ autoPopulate: targetAttribute.autoPopulate,
676
+ private: targetAttribute.private || void 0,
677
+ pluginOptions: targetAttribute.pluginOptions || void 0
678
+ };
679
+ switch (attribute.relation) {
680
+ case "oneToOne": {
681
+ opts.relation = "oneToOne";
682
+ if (attribute.dominant) {
683
+ opts.mappedBy = key;
684
+ } else {
685
+ opts.inversedBy = key;
686
+ }
687
+ break;
688
+ }
689
+ case "oneToMany": {
690
+ opts.relation = "manyToOne";
691
+ opts.inversedBy = key;
692
+ break;
693
+ }
694
+ case "manyToOne": {
695
+ opts.relation = "oneToMany";
696
+ opts.mappedBy = key;
697
+ break;
698
+ }
699
+ case "manyToMany": {
700
+ opts.relation = "manyToMany";
701
+ if (attribute.dominant) {
702
+ opts.mappedBy = key;
703
+ } else {
704
+ opts.inversedBy = key;
705
+ }
706
+ break;
707
+ }
708
+ }
709
+ const { type, relation, target, ...restOptions } = opts;
710
+ return {
711
+ type,
712
+ relation,
713
+ target,
714
+ ...restOptions
715
+ };
716
+ };
717
+ function createBuilder() {
718
+ const components2 = Object.values(strapi.components).map((componentInput) => ({
719
+ category: componentInput.category,
720
+ modelName: componentInput.modelName,
721
+ plugin: componentInput.modelName,
722
+ uid: componentInput.uid,
723
+ filename: componentInput.__filename__,
724
+ dir: path.join(strapi.dirs.app.components, componentInput.category),
725
+ schema: componentInput.__schema__,
726
+ config: componentInput.config
727
+ }));
728
+ const contentTypes2 = Object.values(strapi.contentTypes).map((contentTypeInput) => {
729
+ const dir = contentTypeInput.plugin ? path.join(
730
+ strapi.dirs.app.extensions,
731
+ contentTypeInput.plugin,
732
+ "content-types",
733
+ contentTypeInput.info.singularName
734
+ ) : path.join(
735
+ strapi.dirs.app.api,
736
+ contentTypeInput.apiName,
737
+ "content-types",
738
+ contentTypeInput.info.singularName
739
+ );
740
+ return {
741
+ modelName: contentTypeInput.modelName,
742
+ plugin: contentTypeInput.plugin,
743
+ uid: contentTypeInput.uid,
744
+ filename: "schema.json",
745
+ dir,
746
+ schema: contentTypeInput.__schema__,
747
+ config: contentTypeInput.config
748
+ };
749
+ });
750
+ return createSchemaBuilder({
751
+ components: components2,
752
+ contentTypes: contentTypes2
753
+ });
754
+ }
755
+ function createSchemaBuilder({ components: components2, contentTypes: contentTypes2 }) {
756
+ const tmpComponents = /* @__PURE__ */ new Map();
757
+ const tmpContentTypes = /* @__PURE__ */ new Map();
758
+ Object.keys(contentTypes2).forEach((key) => {
759
+ tmpContentTypes.set(contentTypes2[key].uid, createSchemaHandler(contentTypes2[key]));
760
+ });
761
+ Object.keys(components2).forEach((key) => {
762
+ tmpComponents.set(components2[key].uid, createSchemaHandler(components2[key]));
763
+ });
764
+ return {
765
+ get components() {
766
+ return tmpComponents;
767
+ },
768
+ get contentTypes() {
769
+ return tmpContentTypes;
770
+ },
771
+ /**
772
+ * Convert Attributes received from the API to the right syntax
773
+ */
774
+ convertAttributes(attributes) {
775
+ return Object.keys(attributes).reduce(
776
+ (acc, key) => {
777
+ const attribute = attributes[key];
778
+ const { configurable, private: isPrivate } = attribute;
779
+ const baseProperties = {
780
+ private: isPrivate === true ? true : void 0,
781
+ configurable: configurable === false ? false : void 0
782
+ };
783
+ if (attribute.type === "relation") {
784
+ const { target, relation, targetAttribute, dominant, ...restOfProperties } = attribute;
785
+ const attr = {
786
+ type: "relation",
787
+ relation,
788
+ target,
789
+ ...restOfProperties,
790
+ ...baseProperties
791
+ };
792
+ acc[key] = attr;
793
+ if (target && !this.contentTypes.has(target)) {
794
+ throw new utils.errors.ApplicationError(`target: ${target} does not exist`);
795
+ }
796
+ if (___default.default.isNil(targetAttribute)) {
797
+ return acc;
798
+ }
799
+ if (["oneToOne", "manyToMany"].includes(relation) && dominant === true) {
800
+ attr.inversedBy = targetAttribute;
801
+ } else if (["oneToOne", "manyToMany"].includes(relation) && dominant === false) {
802
+ attr.mappedBy = targetAttribute;
803
+ } else if (["oneToOne", "manyToOne", "manyToMany"].includes(relation)) {
804
+ attr.inversedBy = targetAttribute;
805
+ } else if (["oneToMany"].includes(relation)) {
806
+ attr.mappedBy = targetAttribute;
807
+ }
808
+ return acc;
809
+ }
810
+ acc[key] = {
811
+ ...attribute,
812
+ ...baseProperties
813
+ };
814
+ return acc;
815
+ },
816
+ {}
817
+ );
818
+ },
819
+ ...createComponentBuilder$1(),
820
+ ...createComponentBuilder(),
821
+ /**
822
+ * Write all type to files
823
+ */
824
+ writeFiles() {
825
+ const schemas = [
826
+ ...Array.from(tmpComponents.values()),
827
+ ...Array.from(tmpContentTypes.values())
828
+ ];
829
+ return Promise.all(schemas.map((schema) => schema.flush())).catch((error) => {
830
+ strapi.log.error("Error writing schema files");
831
+ strapi.log.error(error);
832
+ return this.rollback();
833
+ }).catch((error) => {
834
+ strapi.log.error(
835
+ "Error rolling back schema files. You might need to fix your files manually"
836
+ );
837
+ strapi.log.error(error);
838
+ throw new utils.errors.ApplicationError("Invalid schema edition");
839
+ });
840
+ },
841
+ /**
842
+ * rollback all files
843
+ */
844
+ rollback() {
845
+ return Promise.all(
846
+ [...Array.from(tmpComponents.values()), ...Array.from(tmpContentTypes.values())].map(
847
+ (schema) => schema.rollback()
848
+ )
849
+ );
850
+ }
851
+ };
852
+ }
853
+ const { ApplicationError } = utils.errors;
854
+ const isContentTypeVisible = (model) => fp.getOr(true, "pluginOptions.content-type-builder.visible", model) === true;
855
+ const getRestrictRelationsTo = (contentType) => {
856
+ const { uid } = contentType;
857
+ if (uid === coreUids.STRAPI_USER) {
858
+ return ["oneWay", "manyWay"];
859
+ }
860
+ if (uid.startsWith(coreUids.PREFIX) || uid === pluginsUids.UPLOAD_FILE || !isContentTypeVisible(contentType)) {
861
+ return [];
862
+ }
863
+ return null;
864
+ };
865
+ const formatContentType = (contentType) => {
866
+ const { uid, kind, modelName, plugin, collectionName, info } = contentType;
867
+ return {
868
+ uid,
869
+ plugin,
870
+ apiID: modelName,
871
+ schema: {
872
+ ...utils.contentTypes.getOptions(contentType),
873
+ displayName: info.displayName,
874
+ singularName: info.singularName,
875
+ pluralName: info.pluralName,
876
+ description: ___default.default.get(info, "description", ""),
877
+ pluginOptions: contentType.pluginOptions,
878
+ kind: kind || "collectionType",
879
+ collectionName,
880
+ attributes: formatAttributes(contentType),
881
+ visible: isContentTypeVisible(contentType),
882
+ restrictRelationsTo: getRestrictRelationsTo(contentType)
883
+ }
884
+ };
885
+ };
886
+ const createContentTypes = async (contentTypes2) => {
887
+ const builder2 = createBuilder();
888
+ const createdContentTypes = [];
889
+ for (const contentType of contentTypes2) {
890
+ createdContentTypes.push(await createContentType(contentType, { defaultBuilder: builder2 }));
891
+ }
892
+ await builder2.writeFiles();
893
+ return createdContentTypes;
894
+ };
895
+ const createContentType = async ({ contentType, components: components2 }, options = {}) => {
896
+ const builder2 = options.defaultBuilder || createBuilder();
897
+ const uidMap = builder2.createNewComponentUIDMap(components2 || []);
898
+ const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
899
+ const newContentType = builder2.createContentType(replaceTmpUIDs(contentType));
900
+ const targetContentType = (infos) => {
901
+ Object.keys(infos.attributes).forEach((key) => {
902
+ const { target } = infos.attributes[key];
903
+ if (target === "__contentType__") {
904
+ infos.attributes[key].target = newContentType.uid;
905
+ }
906
+ });
907
+ return infos;
908
+ };
909
+ components2?.forEach((component) => {
910
+ const options2 = replaceTmpUIDs(targetContentType(component));
911
+ if (!___default.default.has(component, "uid")) {
912
+ return builder2.createComponent(options2);
913
+ }
914
+ return builder2.editComponent(options2);
915
+ });
916
+ await generateAPI({
917
+ displayName: contentType.displayName || contentType.info.displayName,
918
+ singularName: contentType.singularName,
919
+ pluralName: contentType.pluralName,
920
+ kind: contentType.kind
921
+ });
922
+ if (!options.defaultBuilder) {
923
+ await builder2.writeFiles();
924
+ }
925
+ strapi.eventHub.emit("content-type.create", { contentType: newContentType });
926
+ return newContentType;
927
+ };
928
+ const generateAPI = ({
929
+ singularName,
930
+ kind = "collectionType",
931
+ pluralName,
932
+ displayName
933
+ }) => {
934
+ const strapiGenerators = require("@strapi/generators");
935
+ return strapiGenerators.generate(
936
+ "content-type",
937
+ {
938
+ kind,
939
+ singularName,
940
+ id: singularName,
941
+ pluralName,
942
+ displayName,
943
+ destination: "new",
944
+ bootstrapApi: true,
945
+ attributes: []
946
+ },
947
+ { dir: strapi.dirs.app.root }
948
+ );
949
+ };
950
+ const editContentType = async (uid, { contentType, components: components2 = [] }) => {
951
+ const builder2 = createBuilder();
952
+ const previousSchema = builder2.contentTypes.get(uid).schema;
953
+ const previousKind = previousSchema.kind;
954
+ const newKind = contentType.kind || previousKind;
955
+ const previousAttributes = previousSchema.attributes;
956
+ const prevNonVisibleAttributes = utils.contentTypes.getNonVisibleAttributes(previousSchema).reduce((acc, key) => {
957
+ if (key in previousAttributes) {
958
+ acc[key] = previousAttributes[key];
959
+ }
960
+ return acc;
961
+ }, {});
962
+ contentType.attributes = ___default.default.merge(prevNonVisibleAttributes, contentType.attributes);
963
+ if (newKind !== previousKind && newKind === "singleType") {
964
+ const entryCount = await strapi.db.query(uid).count();
965
+ if (entryCount > 1) {
966
+ throw new ApplicationError(
967
+ "You cannot convert a collectionType to a singleType when having multiple entries in DB"
968
+ );
969
+ }
970
+ }
971
+ const uidMap = builder2.createNewComponentUIDMap(components2);
972
+ const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
973
+ const updatedContentType = builder2.editContentType({
974
+ uid,
975
+ ...replaceTmpUIDs(contentType)
976
+ });
977
+ components2.forEach((component) => {
978
+ if (!___default.default.has(component, "uid")) {
979
+ return builder2.createComponent(replaceTmpUIDs(component));
980
+ }
981
+ return builder2.editComponent(replaceTmpUIDs(component));
982
+ });
983
+ if (newKind !== previousKind) {
984
+ const apiHandler2 = strapi.plugin("content-type-builder").service("api-handler");
985
+ await apiHandler2.backup(uid);
986
+ try {
987
+ await apiHandler2.clear(uid);
988
+ await generateAPI({
989
+ displayName: updatedContentType.schema.info.displayName,
990
+ singularName: updatedContentType.schema.info.singularName,
991
+ pluralName: updatedContentType.schema.info.pluralName,
992
+ kind: updatedContentType.schema.kind
993
+ });
994
+ await builder2.writeFiles();
995
+ } catch (error) {
996
+ strapi.log.error(error);
997
+ await apiHandler2.rollback(uid);
998
+ }
999
+ return updatedContentType;
1000
+ }
1001
+ await builder2.writeFiles();
1002
+ strapi.eventHub.emit("content-type.update", { contentType: updatedContentType });
1003
+ return updatedContentType;
1004
+ };
1005
+ const deleteContentTypes = async (uids) => {
1006
+ const builder2 = createBuilder();
1007
+ const apiHandler2 = strapi.plugin("content-type-builder").service("api-handler");
1008
+ for (const uid of uids) {
1009
+ await deleteContentType(uid, builder2);
1010
+ }
1011
+ await builder2.writeFiles();
1012
+ for (const uid of uids) {
1013
+ try {
1014
+ await apiHandler2.clear(uid);
1015
+ } catch (error) {
1016
+ strapi.log.error(error);
1017
+ await apiHandler2.rollback(uid);
1018
+ }
1019
+ }
1020
+ };
1021
+ const deleteContentType = async (uid, defaultBuilder = void 0) => {
1022
+ const builder2 = defaultBuilder || createBuilder();
1023
+ const apiHandler2 = strapi.plugin("content-type-builder").service("api-handler");
1024
+ await apiHandler2.backup(uid);
1025
+ const contentType = builder2.deleteContentType(uid);
1026
+ if (!defaultBuilder) {
1027
+ try {
1028
+ await builder2.writeFiles();
1029
+ await apiHandler2.clear(uid);
1030
+ } catch (error) {
1031
+ await apiHandler2.rollback(uid);
1032
+ }
1033
+ }
1034
+ strapi.eventHub.emit("content-type.delete", { contentType });
1035
+ return contentType;
1036
+ };
1037
+ const contentTypes$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1038
+ __proto__: null,
1039
+ createContentType,
1040
+ createContentTypes,
1041
+ deleteContentType,
1042
+ deleteContentTypes,
1043
+ editContentType,
1044
+ formatContentType,
1045
+ generateAPI,
1046
+ getRestrictRelationsTo,
1047
+ isContentTypeVisible
1048
+ }, Symbol.toStringTag, { value: "Module" }));
1049
+ const formatComponent = (component) => {
1050
+ const { uid, modelName, connection, collectionName, info, category } = component;
1051
+ return {
1052
+ uid,
1053
+ category,
1054
+ apiId: modelName,
1055
+ schema: {
1056
+ displayName: _.get(info, "displayName"),
1057
+ description: _.get(info, "description", ""),
1058
+ icon: _.get(info, "icon"),
1059
+ connection,
1060
+ collectionName,
1061
+ pluginOptions: component.pluginOptions,
1062
+ attributes: formatAttributes(component)
1063
+ }
1064
+ };
1065
+ };
1066
+ const createComponent = async ({ component, components: components2 = [] }) => {
1067
+ const builder2 = createBuilder();
1068
+ const uidMap = builder2.createNewComponentUIDMap(components2);
1069
+ const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
1070
+ const newComponent = builder2.createComponent(replaceTmpUIDs(component));
1071
+ components2.forEach((component2) => {
1072
+ if (!_.has(component2, "uid")) {
1073
+ return builder2.createComponent(replaceTmpUIDs(component2));
1074
+ }
1075
+ return builder2.editComponent(replaceTmpUIDs(component2));
1076
+ });
1077
+ await builder2.writeFiles();
1078
+ strapi.eventHub.emit("component.create", { component: newComponent });
1079
+ return newComponent;
1080
+ };
1081
+ const editComponent = async (uid, { component, components: components2 = [] }) => {
1082
+ const builder2 = createBuilder();
1083
+ const uidMap = builder2.createNewComponentUIDMap(components2);
1084
+ const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
1085
+ const updatedComponent = builder2.editComponent({
1086
+ uid,
1087
+ ...replaceTmpUIDs(component)
1088
+ });
1089
+ components2.forEach((component2) => {
1090
+ if (!_.has(component2, "uid")) {
1091
+ return builder2.createComponent(replaceTmpUIDs(component2));
1092
+ }
1093
+ return builder2.editComponent(replaceTmpUIDs(component2));
1094
+ });
1095
+ await builder2.writeFiles();
1096
+ strapi.eventHub.emit("component.update", { component: updatedComponent });
1097
+ return updatedComponent;
1098
+ };
1099
+ const deleteComponent = async (uid) => {
1100
+ const builder2 = createBuilder();
1101
+ const deletedComponent = builder2.deleteComponent(uid);
1102
+ await builder2.writeFiles();
1103
+ strapi.eventHub.emit("component.delete", { component: deletedComponent });
1104
+ return deletedComponent;
1105
+ };
1106
+ const components$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1107
+ __proto__: null,
1108
+ createComponent,
1109
+ deleteComponent,
1110
+ editComponent,
1111
+ formatComponent
1112
+ }, Symbol.toStringTag, { value: "Module" }));
1113
+ const editCategory = async (name, infos) => {
1114
+ const newName = utils.strings.nameToSlug(infos.name);
1115
+ if (name === newName)
1116
+ return;
1117
+ if (!categoryExists(name)) {
1118
+ throw new utils.errors.ApplicationError("category not found");
1119
+ }
1120
+ if (categoryExists(newName)) {
1121
+ throw new utils.errors.ApplicationError("Name already taken");
1122
+ }
1123
+ const builder2 = createBuilder();
1124
+ builder2.components.forEach((component) => {
1125
+ const oldUID = component.uid;
1126
+ const newUID = `${newName}.${component.modelName}`;
1127
+ if (component.category !== name)
1128
+ return;
1129
+ component.setUID(newUID).setDir(path.join(strapi.dirs.app.components, newName));
1130
+ builder2.components.forEach((compo) => {
1131
+ compo.updateComponent(oldUID, newUID);
1132
+ });
1133
+ builder2.contentTypes.forEach((ct) => {
1134
+ ct.updateComponent(oldUID, newUID);
1135
+ });
1136
+ });
1137
+ await builder2.writeFiles();
1138
+ return newName;
1139
+ };
1140
+ const deleteCategory = async (name) => {
1141
+ if (!categoryExists(name)) {
1142
+ throw new utils.errors.ApplicationError("category not found");
1143
+ }
1144
+ const builder2 = createBuilder();
1145
+ builder2.components.forEach((component) => {
1146
+ if (component.category === name) {
1147
+ builder2.deleteComponent(component.uid);
1148
+ }
1149
+ });
1150
+ await builder2.writeFiles();
1151
+ };
1152
+ const categoryExists = (name) => {
1153
+ const matchingIndex = Object.values(strapi.components).findIndex(
1154
+ (component) => component.category === name
1155
+ );
1156
+ return matchingIndex > -1;
1157
+ };
1158
+ const componentCategories$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1159
+ __proto__: null,
1160
+ deleteCategory,
1161
+ editCategory
1162
+ }, Symbol.toStringTag, { value: "Module" }));
1163
+ const reservedAttributes = [
1164
+ // TODO: these need to come from a centralized place so we don't break things accidentally in the future and can share them outside the CTB, for example on Strapi bootstrap prior to schema db sync
1165
+ // ID fields
1166
+ "id",
1167
+ "document_id",
1168
+ // Creator fields
1169
+ "created_at",
1170
+ "updated_at",
1171
+ "published_at",
1172
+ "created_by_id",
1173
+ "updated_by_id",
1174
+ // does not actually conflict because the fields are called *_by_id but we'll leave it to avoid confusion
1175
+ "created_by",
1176
+ "updated_by",
1177
+ // Used for Strapi functionality
1178
+ "entry_id",
1179
+ "status",
1180
+ "localizations",
1181
+ "meta",
1182
+ "locale",
1183
+ "__component",
1184
+ "__contentType",
1185
+ // We support ending with * to denote prefixes
1186
+ "strapi*",
1187
+ "_strapi*",
1188
+ "__strapi*"
1189
+ ];
1190
+ const reservedModels = [
1191
+ "boolean",
1192
+ "date",
1193
+ "date_time",
1194
+ "time",
1195
+ "upload",
1196
+ "document",
1197
+ "then",
1198
+ // no longer an issue but still restricting for being a javascript keyword
1199
+ // We support ending with * to denote prefixes
1200
+ "strapi*",
1201
+ "_strapi*",
1202
+ "__strapi*"
1203
+ ];
1204
+ const getReservedNames = () => {
1205
+ return {
1206
+ models: reservedModels,
1207
+ attributes: reservedAttributes
1208
+ };
1209
+ };
1210
+ const isReservedModelName = (name) => {
1211
+ const snakeCaseName = fp.snakeCase(name);
1212
+ if (reservedModels.includes(snakeCaseName)) {
1213
+ return true;
1214
+ }
1215
+ if (reservedModels.filter((key) => key.endsWith("*")).map((key) => key.slice(0, -1)).some((prefix) => snakeCaseName.startsWith(prefix))) {
1216
+ return true;
1217
+ }
1218
+ return false;
1219
+ };
1220
+ const isReservedAttributeName = (name) => {
1221
+ const snakeCaseName = fp.snakeCase(name);
1222
+ if (reservedAttributes.includes(snakeCaseName)) {
1223
+ return true;
1224
+ }
1225
+ if (reservedAttributes.filter((key) => key.endsWith("*")).map((key) => key.slice(0, -1)).some((prefix) => snakeCaseName.startsWith(prefix))) {
1226
+ return true;
1227
+ }
1228
+ return false;
1229
+ };
1230
+ const builder$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1231
+ __proto__: null,
1232
+ getReservedNames,
1233
+ isReservedAttributeName,
1234
+ isReservedModelName,
1235
+ reservedAttributes,
1236
+ reservedModels
1237
+ }, Symbol.toStringTag, { value: "Module" }));
1238
+ async function clear(uid) {
1239
+ const { apiName, modelName } = strapi.contentTypes[uid];
1240
+ const apiFolder = path__namespace.join(strapi.dirs.app.api, apiName);
1241
+ await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));
1242
+ await deleteBackup(uid);
1243
+ }
1244
+ async function backup(uid) {
1245
+ const { apiName } = strapi.contentTypes[uid];
1246
+ const apiFolder = path__namespace.join(strapi.dirs.app.api, apiName);
1247
+ const backupFolder = path__namespace.join(strapi.dirs.app.api, ".backup", apiName);
1248
+ await fse__namespace.copy(apiFolder, backupFolder);
1249
+ }
1250
+ async function deleteBackup(uid) {
1251
+ const { apiName } = strapi.contentTypes[uid];
1252
+ const backupFolder = path__namespace.join(strapi.dirs.app.api, ".backup");
1253
+ const apiBackupFolder = path__namespace.join(strapi.dirs.app.api, ".backup", apiName);
1254
+ await fse__namespace.remove(apiBackupFolder);
1255
+ const list = await fse__namespace.readdir(backupFolder);
1256
+ if (list.length === 0) {
1257
+ await fse__namespace.remove(backupFolder);
1258
+ }
1259
+ }
1260
+ async function rollback(uid) {
1261
+ const { apiName } = strapi.contentTypes[uid];
1262
+ const apiFolder = path__namespace.join(strapi.dirs.app.api, apiName);
1263
+ const backupFolder = path__namespace.join(strapi.dirs.app.api, ".backup", apiName);
1264
+ try {
1265
+ await fse__namespace.access(backupFolder);
1266
+ } catch {
1267
+ throw new Error("Cannot rollback api that was not backed up");
1268
+ }
1269
+ await fse__namespace.remove(apiFolder);
1270
+ await fse__namespace.copy(backupFolder, apiFolder);
1271
+ await deleteBackup(uid);
1272
+ }
1273
+ const createDeleteApiFunction = (baseName) => {
1274
+ return async (filePath) => {
1275
+ const fileName = path__namespace.basename(filePath, path__namespace.extname(filePath));
1276
+ const isSchemaFile = filePath.endsWith(`${baseName}/schema.json`);
1277
+ if (fileName === baseName || isSchemaFile) {
1278
+ return fse__namespace.remove(filePath);
1279
+ }
1280
+ };
1281
+ };
1282
+ const recursiveRemoveFiles = async (folder, deleteFn) => {
1283
+ const filesName = await fse__namespace.readdir(folder);
1284
+ for (const fileName of filesName) {
1285
+ const filePath = path__namespace.join(folder, fileName);
1286
+ const stat = await fse__namespace.stat(filePath);
1287
+ if (stat.isDirectory()) {
1288
+ await recursiveRemoveFiles(filePath, deleteFn);
1289
+ } else {
1290
+ await deleteFn(filePath);
1291
+ }
1292
+ }
1293
+ const files = await fse__namespace.readdir(folder);
1294
+ if (files.length === 0) {
1295
+ await fse__namespace.remove(folder);
1296
+ }
1297
+ };
1298
+ const apiHandler = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1299
+ __proto__: null,
1300
+ backup,
1301
+ clear,
1302
+ rollback
1303
+ }, Symbol.toStringTag, { value: "Module" }));
1304
+ const services = {
1305
+ "content-types": contentTypes$1,
1306
+ components: components$1,
1307
+ "component-categories": componentCategories$1,
1308
+ builder: builder$1,
1309
+ "api-handler": apiHandler
1310
+ };
1311
+ function getService(name) {
1312
+ return strapi.plugin("content-type-builder").service(name);
1313
+ }
1314
+ const builder = {
1315
+ getReservedNames(ctx) {
1316
+ ctx.body = getService("builder").getReservedNames();
1317
+ }
1318
+ };
1319
+ const validators = {
1320
+ required: utils.yup.boolean(),
1321
+ unique: utils.yup.boolean(),
1322
+ minLength: utils.yup.number().integer().positive(),
1323
+ maxLength: utils.yup.number().integer().positive()
1324
+ };
1325
+ const NAME_REGEX = /^[A-Za-z][_0-9A-Za-z]*$/;
1326
+ const COLLECTION_NAME_REGEX = /^[A-Za-z][-_0-9A-Za-z]*$/;
1327
+ const CATEGORY_NAME_REGEX = /^[A-Za-z][-_0-9A-Za-z]*$/;
1328
+ const ICON_REGEX = /^[A-Za-z0-9][-A-Za-z0-9]*$/;
1329
+ const UID_REGEX = /^[A-Za-z0-9-_.~]*$/;
1330
+ const isValidName = {
1331
+ name: "isValidName",
1332
+ message: `\${path} must match the following regex: ${NAME_REGEX}`,
1333
+ test: (val) => val === "" || NAME_REGEX.test(val)
1334
+ };
1335
+ const isValidIcon = {
1336
+ name: "isValidIcon",
1337
+ message: `\${path} is not a valid icon name. Make sure your icon name starts with an alphanumeric character and only includes alphanumeric characters or dashes.`,
1338
+ test: (val) => val === "" || ICON_REGEX.test(val)
1339
+ };
1340
+ const isValidUID = {
1341
+ name: "isValidUID",
1342
+ message: `\${path} must match the following regex: ${UID_REGEX}`,
1343
+ test: (val) => val === "" || UID_REGEX.test(val)
1344
+ };
1345
+ const isValidCategoryName = {
1346
+ name: "isValidCategoryName",
1347
+ message: `\${path} must match the following regex: ${CATEGORY_NAME_REGEX}`,
1348
+ test: (val) => val === "" || CATEGORY_NAME_REGEX.test(val)
1349
+ };
1350
+ const isValidCollectionName = {
1351
+ name: "isValidCollectionName",
1352
+ message: `\${path} must match the following regex: ${COLLECTION_NAME_REGEX}`,
1353
+ test: (val) => val === "" || COLLECTION_NAME_REGEX.test(val)
1354
+ };
1355
+ const isValidKey = (key) => ({
1356
+ name: "isValidKey",
1357
+ message: `Attribute name '${key}' must match the following regex: ${NAME_REGEX}`,
1358
+ test: () => NAME_REGEX.test(key)
1359
+ });
1360
+ const isValidEnum = {
1361
+ name: "isValidEnum",
1362
+ message: "${path} should not start with number",
1363
+ test: (val) => val === "" || !utils.strings.startsWithANumber(val)
1364
+ };
1365
+ const areEnumValuesUnique = {
1366
+ name: "areEnumValuesUnique",
1367
+ message: "${path} cannot contain duplicate values",
1368
+ test(values) {
1369
+ const filtered = [...new Set(values)];
1370
+ return filtered.length === values.length;
1371
+ }
1372
+ };
1373
+ const isValidRegExpPattern = {
1374
+ name: "isValidRegExpPattern",
1375
+ message: "${path} must be a valid RexExp pattern string",
1376
+ test: (val) => val === "" || !!new RegExp(val)
1377
+ };
1378
+ const isValidDefaultJSON = {
1379
+ name: "isValidDefaultJSON",
1380
+ message: "${path} is not a valid JSON",
1381
+ test(val) {
1382
+ if (val === void 0) {
1383
+ return true;
1384
+ }
1385
+ if (___default.default.isNumber(val) || ___default.default.isNull(val) || ___default.default.isObject(val) || ___default.default.isArray(val)) {
1386
+ return true;
1387
+ }
1388
+ try {
1389
+ JSON.parse(val);
1390
+ return true;
1391
+ } catch (err) {
1392
+ return false;
1393
+ }
1394
+ }
1395
+ };
1396
+ const componentCategorySchema = utils.yup.object({
1397
+ name: utils.yup.string().min(3).test(isValidCategoryName).required("name.required")
1398
+ }).noUnknown();
1399
+ const validateComponentCategory = utils.validateYupSchema(componentCategorySchema);
1400
+ const componentCategories = {
1401
+ async editCategory(ctx) {
1402
+ const body = ctx.request.body;
1403
+ try {
1404
+ await validateComponentCategory(body);
1405
+ } catch (error) {
1406
+ return ctx.send({ error }, 400);
1407
+ }
1408
+ const { name } = ctx.params;
1409
+ strapi.reload.isWatching = false;
1410
+ const componentCategoryService = getService("component-categories");
1411
+ const newName = await componentCategoryService.editCategory(name, body);
1412
+ setImmediate(() => strapi.reload());
1413
+ ctx.send({ name: newName });
1414
+ },
1415
+ async deleteCategory(ctx) {
1416
+ const { name } = ctx.params;
1417
+ strapi.reload.isWatching = false;
1418
+ const componentCategoryService = getService("component-categories");
1419
+ await componentCategoryService.deleteCategory(name);
1420
+ setImmediate(() => strapi.reload());
1421
+ ctx.send({ name });
1422
+ }
1423
+ };
1424
+ const maxLengthIsGreaterThanOrEqualToMinLength = {
1425
+ name: "isGreaterThanMin",
1426
+ message: "maxLength must be greater or equal to minLength",
1427
+ test(value) {
1428
+ const { minLength } = this.parent;
1429
+ return !(!___default.default.isUndefined(minLength) && !___default.default.isUndefined(value) && value < minLength);
1430
+ }
1431
+ };
1432
+ const getTypeValidator = (attribute, { types, modelType, attributes }) => {
1433
+ return utils.yup.object({
1434
+ type: utils.yup.string().oneOf([...types]).required(),
1435
+ configurable: utils.yup.boolean().nullable(),
1436
+ private: utils.yup.boolean().nullable(),
1437
+ pluginOptions: utils.yup.object(),
1438
+ ...getTypeShape(attribute, { modelType, attributes })
1439
+ });
1440
+ };
1441
+ const getTypeShape = (attribute, { attributes } = {}) => {
1442
+ switch (attribute.type) {
1443
+ case "media": {
1444
+ return {
1445
+ multiple: utils.yup.boolean(),
1446
+ required: validators.required,
1447
+ allowedTypes: utils.yup.array().of(utils.yup.string().oneOf(["images", "videos", "files", "audios"])).min(1)
1448
+ };
1449
+ }
1450
+ case "uid": {
1451
+ return {
1452
+ required: validators.required,
1453
+ targetField: utils.yup.string().oneOf(
1454
+ Object.keys(attributes).filter(
1455
+ (key) => VALID_UID_TARGETS.includes(___default.default.get(attributes[key], "type"))
1456
+ )
1457
+ ).nullable(),
1458
+ default: utils.yup.string().test(
1459
+ "isValidDefaultUID",
1460
+ "cannot define a default UID if the targetField is set",
1461
+ function(value) {
1462
+ const { targetField } = this.parent;
1463
+ return !!(___default.default.isNil(targetField) || ___default.default.isNil(value));
1464
+ }
1465
+ ).test(isValidUID),
1466
+ minLength: validators.minLength,
1467
+ maxLength: validators.maxLength.max(256).test(maxLengthIsGreaterThanOrEqualToMinLength),
1468
+ options: utils.yup.object().shape({
1469
+ separator: utils.yup.string(),
1470
+ lowercase: utils.yup.boolean(),
1471
+ decamelize: utils.yup.boolean(),
1472
+ customReplacements: utils.yup.array().of(utils.yup.array().of(utils.yup.string()).min(2).max(2)),
1473
+ preserveLeadingUnderscore: utils.yup.boolean()
1474
+ })
1475
+ };
1476
+ }
1477
+ case "string":
1478
+ case "text": {
1479
+ return {
1480
+ default: utils.yup.string(),
1481
+ required: validators.required,
1482
+ unique: validators.unique,
1483
+ minLength: validators.minLength,
1484
+ maxLength: validators.maxLength,
1485
+ regex: utils.yup.string().test(isValidRegExpPattern)
1486
+ };
1487
+ }
1488
+ case "richtext": {
1489
+ return {
1490
+ default: utils.yup.string(),
1491
+ required: validators.required,
1492
+ minLength: validators.minLength,
1493
+ maxLength: validators.maxLength
1494
+ };
1495
+ }
1496
+ case "blocks": {
1497
+ return {
1498
+ required: validators.required
1499
+ };
1500
+ }
1501
+ case "json": {
1502
+ return {
1503
+ default: utils.yup.mixed().test(isValidDefaultJSON),
1504
+ required: validators.required
1505
+ };
1506
+ }
1507
+ case "enumeration": {
1508
+ return {
1509
+ enum: utils.yup.array().of(utils.yup.string().test(isValidEnum).required()).min(1).test(areEnumValuesUnique).required(),
1510
+ default: utils.yup.string().when("enum", (enumVal) => utils.yup.string().oneOf(enumVal)),
1511
+ enumName: utils.yup.string().test(isValidName),
1512
+ required: validators.required
1513
+ };
1514
+ }
1515
+ case "password": {
1516
+ return {
1517
+ required: validators.required,
1518
+ minLength: validators.minLength,
1519
+ maxLength: validators.maxLength
1520
+ };
1521
+ }
1522
+ case "email": {
1523
+ return {
1524
+ default: utils.yup.string().email(),
1525
+ required: validators.required,
1526
+ unique: validators.unique,
1527
+ minLength: validators.minLength,
1528
+ maxLength: validators.maxLength
1529
+ };
1530
+ }
1531
+ case "integer": {
1532
+ return {
1533
+ default: utils.yup.number().integer(),
1534
+ required: validators.required,
1535
+ unique: validators.unique,
1536
+ min: utils.yup.number().integer(),
1537
+ max: utils.yup.number().integer()
1538
+ };
1539
+ }
1540
+ case "biginteger": {
1541
+ return {
1542
+ default: utils.yup.string().nullable().matches(/^\d*$/),
1543
+ required: validators.required,
1544
+ unique: validators.unique,
1545
+ min: utils.yup.string().nullable().matches(/^\d*$/),
1546
+ max: utils.yup.string().nullable().matches(/^\d*$/)
1547
+ };
1548
+ }
1549
+ case "float": {
1550
+ return {
1551
+ default: utils.yup.number(),
1552
+ required: validators.required,
1553
+ unique: validators.unique,
1554
+ min: utils.yup.number(),
1555
+ max: utils.yup.number()
1556
+ };
1557
+ }
1558
+ case "decimal": {
1559
+ return {
1560
+ default: utils.yup.number(),
1561
+ required: validators.required,
1562
+ unique: validators.unique,
1563
+ min: utils.yup.number(),
1564
+ max: utils.yup.number()
1565
+ };
1566
+ }
1567
+ case "time":
1568
+ case "datetime":
1569
+ case "date": {
1570
+ return {
1571
+ default: utils.yup.string(),
1572
+ required: validators.required,
1573
+ unique: validators.unique
1574
+ };
1575
+ }
1576
+ case "boolean": {
1577
+ return {
1578
+ default: utils.yup.boolean(),
1579
+ required: validators.required
1580
+ };
1581
+ }
1582
+ case "component": {
1583
+ return {
1584
+ required: validators.required,
1585
+ repeatable: utils.yup.boolean(),
1586
+ // TODO: Add correct server validation for nested components
1587
+ component: utils.yup.string().required(),
1588
+ min: utils.yup.number(),
1589
+ max: utils.yup.number()
1590
+ };
1591
+ }
1592
+ case "dynamiczone": {
1593
+ return {
1594
+ required: validators.required,
1595
+ components: utils.yup.array().of(utils.yup.string().required()).test("isArray", "${path} must be an array", (value) => Array.isArray(value)).min(1),
1596
+ min: utils.yup.number(),
1597
+ max: utils.yup.number()
1598
+ };
1599
+ }
1600
+ default: {
1601
+ return {};
1602
+ }
1603
+ }
1604
+ };
1605
+ const STRAPI_USER_RELATIONS = ["oneToOne", "oneToMany"];
1606
+ const isValidRelation = (validNatures) => function(value) {
1607
+ if (value === void 0) {
1608
+ return true;
1609
+ }
1610
+ if (this.parent.target === coreUids.STRAPI_USER) {
1611
+ if (!validNatures.includes(value) || !fp.isUndefined(this.parent.targetAttribute)) {
1612
+ return this.createError({
1613
+ path: this.path,
1614
+ message: `must be one of the following values: ${STRAPI_USER_RELATIONS.join(", ")}`
1615
+ });
1616
+ }
1617
+ }
1618
+ return validNatures.includes(value) ? true : this.createError({
1619
+ path: this.path,
1620
+ message: `must be one of the following values: ${validNatures.join(", ")}`
1621
+ });
1622
+ };
1623
+ const getRelationValidator = (attribute, allowedRelations) => {
1624
+ const contentTypesUIDs = Object.keys(strapi.contentTypes).filter((key) => strapi.contentTypes[key].kind === typeKinds.COLLECTION_TYPE).filter((key) => !key.startsWith(coreUids.PREFIX) || key === coreUids.STRAPI_USER).concat(["__self__", "__contentType__"]);
1625
+ const base = {
1626
+ type: utils.yup.string().oneOf(["relation"]).required(),
1627
+ relation: utils.yup.string().test("isValidRelation", isValidRelation(allowedRelations)).required(),
1628
+ configurable: utils.yup.boolean().nullable(),
1629
+ private: utils.yup.boolean().nullable(),
1630
+ pluginOptions: utils.yup.object()
1631
+ };
1632
+ switch (attribute.relation) {
1633
+ case "oneToOne":
1634
+ case "oneToMany":
1635
+ case "manyToOne":
1636
+ case "manyToMany":
1637
+ case "morphOne":
1638
+ case "morphMany": {
1639
+ return utils.yup.object({
1640
+ ...base,
1641
+ target: utils.yup.string().oneOf(contentTypesUIDs).required(),
1642
+ targetAttribute: utils.yup.string().test(isValidName).nullable()
1643
+ });
1644
+ }
1645
+ case "morphToOne":
1646
+ case "morphToMany":
1647
+ default: {
1648
+ return utils.yup.object({ ...base });
1649
+ }
1650
+ }
1651
+ };
1652
+ const createSchema = (types, relations, { modelType } = {}) => {
1653
+ const shape = {
1654
+ description: utils.yup.string(),
1655
+ options: utils.yup.object(),
1656
+ pluginOptions: utils.yup.object(),
1657
+ collectionName: utils.yup.string().nullable().test(isValidCollectionName),
1658
+ attributes: createAttributesValidator({ types, relations, modelType }),
1659
+ reviewWorkflows: utils.yup.boolean(),
1660
+ draftAndPublish: utils.yup.boolean()
1661
+ };
1662
+ if (modelType === modelTypes.CONTENT_TYPE) {
1663
+ shape.kind = utils.yup.string().oneOf([typeKinds.SINGLE_TYPE, typeKinds.COLLECTION_TYPE]).nullable();
1664
+ }
1665
+ return utils.yup.object(shape).noUnknown();
1666
+ };
1667
+ const createAttributesValidator = ({ types, modelType, relations }) => {
1668
+ return utils.yup.lazy((attributes) => {
1669
+ return utils.yup.object().shape(
1670
+ ___default.default.mapValues(attributes, (attribute, key) => {
1671
+ if (isForbiddenKey(key)) {
1672
+ return forbiddenValidator();
1673
+ }
1674
+ if (isConflictingKey(key, attributes)) {
1675
+ return conflictingKeysValidator(key);
1676
+ }
1677
+ if (attribute.type === "relation") {
1678
+ return getRelationValidator(attribute, relations).test(isValidKey(key));
1679
+ }
1680
+ if (___default.default.has(attribute, "type")) {
1681
+ return getTypeValidator(attribute, { types, modelType, attributes }).test(
1682
+ isValidKey(key)
1683
+ );
1684
+ }
1685
+ return typeOrRelationValidator;
1686
+ })
1687
+ ).required("attributes.required");
1688
+ });
1689
+ };
1690
+ const isConflictingKey = (key, attributes) => {
1691
+ const snakeCaseKey = fp.snakeCase(key);
1692
+ return Object.keys(attributes).some((existingKey) => {
1693
+ if (existingKey === key)
1694
+ return false;
1695
+ return fp.snakeCase(existingKey) === snakeCaseKey;
1696
+ });
1697
+ };
1698
+ const isForbiddenKey = (key) => {
1699
+ return getService("builder").isReservedAttributeName(key);
1700
+ };
1701
+ const forbiddenValidator = () => {
1702
+ const reservedNames = [...getService("builder").getReservedNames().attributes];
1703
+ return utils.yup.mixed().test({
1704
+ name: "forbiddenKeys",
1705
+ message: `Attribute keys cannot be one of ${reservedNames.join(", ")}`,
1706
+ test: () => false
1707
+ });
1708
+ };
1709
+ const conflictingKeysValidator = (key) => {
1710
+ return utils.yup.mixed().test({
1711
+ name: "conflictingKeys",
1712
+ message: `Attribute ${key} conflicts with an existing key`,
1713
+ test: () => false
1714
+ });
1715
+ };
1716
+ const typeOrRelationValidator = utils.yup.object().test({
1717
+ name: "mustHaveTypeOrTarget",
1718
+ message: "Attribute must have either a type or a target",
1719
+ test: () => false
1720
+ });
1721
+ const hasDefaultAttribute = (attribute) => {
1722
+ return "default" in attribute;
1723
+ };
1724
+ const removeEmptyDefaults = (data) => {
1725
+ const { attributes } = data || {};
1726
+ Object.keys(attributes).forEach((attributeName) => {
1727
+ const attribute = attributes[attributeName];
1728
+ if (hasDefaultAttribute(attribute) && attribute.default === "") {
1729
+ attribute.default = void 0;
1730
+ }
1731
+ });
1732
+ };
1733
+ const removeDeletedUIDTargetFields = (data) => {
1734
+ if (___default.default.has(data, "attributes")) {
1735
+ Object.values(data.attributes).forEach((attribute) => {
1736
+ if (attribute.type === "uid" && !___default.default.isUndefined(attribute.targetField) && !___default.default.has(data.attributes, attribute.targetField)) {
1737
+ attribute.targetField = void 0;
1738
+ }
1739
+ });
1740
+ }
1741
+ };
1742
+ const VALID_RELATIONS$1 = ["oneToOne", "oneToMany"];
1743
+ const VALID_TYPES$1 = [...DEFAULT_TYPES, "component", "customField"];
1744
+ const componentSchema = createSchema(VALID_TYPES$1, VALID_RELATIONS$1, {
1745
+ modelType: modelTypes.COMPONENT
1746
+ }).shape({
1747
+ displayName: utils.yup.string().min(1).required("displayName.required"),
1748
+ icon: utils.yup.string().nullable().test(isValidIcon),
1749
+ category: utils.yup.string().nullable().test(isValidCategoryName).required("category.required")
1750
+ }).required().noUnknown();
1751
+ const nestedComponentSchema = utils.yup.array().of(
1752
+ componentSchema.shape({
1753
+ uid: utils.yup.string(),
1754
+ tmpUID: utils.yup.string()
1755
+ }).test({
1756
+ name: "mustHaveUIDOrTmpUID",
1757
+ message: "Component must have a uid or a tmpUID",
1758
+ test(attr) {
1759
+ if (___default.default.has(attr, "uid") && ___default.default.has(attr, "tmpUID"))
1760
+ return false;
1761
+ if (!___default.default.has(attr, "uid") && !___default.default.has(attr, "tmpUID"))
1762
+ return false;
1763
+ return true;
1764
+ }
1765
+ }).required().noUnknown()
1766
+ );
1767
+ const componentInputSchema = utils.yup.object({
1768
+ component: componentSchema,
1769
+ components: nestedComponentSchema
1770
+ }).noUnknown();
1771
+ const validateComponentInput = utils.validateYupSchema(componentInputSchema);
1772
+ const updateComponentInputSchema = utils.yup.object({
1773
+ component: componentSchema,
1774
+ components: nestedComponentSchema
1775
+ }).noUnknown();
1776
+ const validateUpdateComponentInput = (data) => {
1777
+ if (___default.default.has(data, "component") && data.component) {
1778
+ removeEmptyDefaults(data.component);
1779
+ }
1780
+ if (___default.default.has(data, "components") && Array.isArray(data.components)) {
1781
+ data.components.forEach((data2) => {
1782
+ if (___default.default.has(data2, "uid")) {
1783
+ removeEmptyDefaults(data2);
1784
+ }
1785
+ });
1786
+ }
1787
+ return utils.validateYupSchema(updateComponentInputSchema)(data);
1788
+ };
1789
+ const components = {
1790
+ /**
1791
+ * GET /components handler
1792
+ * Returns a list of available components
1793
+ * @param {Object} ctx - koa context
1794
+ */
1795
+ async getComponents(ctx) {
1796
+ const componentService = getService("components");
1797
+ const componentUIDs = Object.keys(strapi.components);
1798
+ const data = componentUIDs.map((uid) => {
1799
+ return componentService.formatComponent(strapi.components[uid]);
1800
+ });
1801
+ ctx.send({ data });
1802
+ },
1803
+ /**
1804
+ * GET /components/:uid
1805
+ * Returns a specific component
1806
+ * @param {Object} ctx - koa context
1807
+ */
1808
+ async getComponent(ctx) {
1809
+ const { uid } = ctx.params;
1810
+ const component = strapi.components[uid];
1811
+ if (!component) {
1812
+ return ctx.send({ error: "component.notFound" }, 404);
1813
+ }
1814
+ const componentService = getService("components");
1815
+ ctx.send({ data: componentService.formatComponent(component) });
1816
+ },
1817
+ /**
1818
+ * POST /components
1819
+ * Creates a component and returns its infos
1820
+ * @param {Object} ctx - koa context
1821
+ */
1822
+ async createComponent(ctx) {
1823
+ const body = ctx.request.body;
1824
+ try {
1825
+ await validateComponentInput(body);
1826
+ } catch (error) {
1827
+ return ctx.send({ error }, 400);
1828
+ }
1829
+ try {
1830
+ strapi.reload.isWatching = false;
1831
+ const componentService = getService("components");
1832
+ const component = await componentService.createComponent({
1833
+ component: body.component,
1834
+ components: body.components
1835
+ });
1836
+ setImmediate(() => strapi.reload());
1837
+ ctx.send({ data: { uid: component.uid } }, 201);
1838
+ } catch (error) {
1839
+ strapi.log.error(error);
1840
+ ctx.send({ error: error?.message || "Unknown error" }, 400);
1841
+ }
1842
+ },
1843
+ /**
1844
+ * PUT /components/:uid
1845
+ * Updates a component and return its infos
1846
+ * @param {Object} ctx - koa context - enhanced koa context
1847
+ */
1848
+ async updateComponent(ctx) {
1849
+ const { uid } = ctx.params;
1850
+ const body = ctx.request.body;
1851
+ if (!___default.default.has(strapi.components, uid)) {
1852
+ return ctx.send({ error: "component.notFound" }, 404);
1853
+ }
1854
+ try {
1855
+ await validateUpdateComponentInput(body);
1856
+ } catch (error) {
1857
+ return ctx.send({ error }, 400);
1858
+ }
1859
+ try {
1860
+ strapi.reload.isWatching = false;
1861
+ const componentService = getService("components");
1862
+ const component = await componentService.editComponent(uid, {
1863
+ component: body.component,
1864
+ components: body.components
1865
+ });
1866
+ setImmediate(() => strapi.reload());
1867
+ ctx.send({ data: { uid: component.uid } });
1868
+ } catch (error) {
1869
+ strapi.log.error(error);
1870
+ ctx.send({ error: error?.message || "Unknown error" }, 400);
1871
+ }
1872
+ },
1873
+ /**
1874
+ * DELETE /components/:uid
1875
+ * Deletes a components and returns its old infos
1876
+ * @param {Object} ctx - koa context
1877
+ */
1878
+ async deleteComponent(ctx) {
1879
+ const { uid } = ctx.params;
1880
+ if (!___default.default.has(strapi.components, uid)) {
1881
+ return ctx.send({ error: "component.notFound" }, 404);
1882
+ }
1883
+ try {
1884
+ strapi.reload.isWatching = false;
1885
+ const componentService = getService("components");
1886
+ const component = await componentService.deleteComponent(uid);
1887
+ setImmediate(() => strapi.reload());
1888
+ ctx.send({ data: { uid: component.uid } });
1889
+ } catch (error) {
1890
+ strapi.log.error(error);
1891
+ ctx.send({ error: error?.message || "Unknown error" }, 400);
1892
+ }
1893
+ }
1894
+ };
1895
+ const VALID_RELATIONS = {
1896
+ [typeKinds.SINGLE_TYPE]: [
1897
+ "oneToOne",
1898
+ "oneToMany",
1899
+ "morphOne",
1900
+ "morphMany",
1901
+ "morphToOne",
1902
+ "morphToMany"
1903
+ ],
1904
+ [typeKinds.COLLECTION_TYPE]: [
1905
+ "oneToOne",
1906
+ "oneToMany",
1907
+ "manyToOne",
1908
+ "manyToMany",
1909
+ "morphOne",
1910
+ "morphMany",
1911
+ "morphToOne",
1912
+ "morphToMany"
1913
+ ]
1914
+ };
1915
+ const VALID_TYPES = [...DEFAULT_TYPES, "uid", "component", "dynamiczone", "customField"];
1916
+ const createContentTypeSchema = (data, { isEdition = false } = {}) => {
1917
+ const kind = fp.getOr(
1918
+ typeKinds.COLLECTION_TYPE,
1919
+ "contentType.kind",
1920
+ data
1921
+ );
1922
+ const contentTypeSchema = createSchema(VALID_TYPES, VALID_RELATIONS[kind] || [], {
1923
+ modelType: modelTypes.CONTENT_TYPE
1924
+ }).shape({
1925
+ displayName: utils.yup.string().min(1).required(),
1926
+ singularName: utils.yup.string().min(1).test(nameIsAvailable(isEdition)).test(forbiddenContentTypeNameValidator()).isKebabCase().required(),
1927
+ pluralName: utils.yup.string().min(1).test(nameIsAvailable(isEdition)).test(nameIsNotExistingCollectionName(isEdition)).test(forbiddenContentTypeNameValidator()).isKebabCase().required()
1928
+ }).test(
1929
+ "singularName-not-equal-pluralName",
1930
+ "${path}: singularName and pluralName should be different",
1931
+ (value) => value.singularName !== value.pluralName
1932
+ );
1933
+ return utils.yup.object({
1934
+ // FIXME .noUnknown(false) will strip off the unwanted properties without throwing an error
1935
+ // Why not having .noUnknown() ? Because we want to be able to add options relatable to EE features
1936
+ // without having any reference to them in CE.
1937
+ // Why not handle an "options" object in the content-type ? The admin panel needs lots of rework
1938
+ // to be able to send this options object instead of top-level attributes.
1939
+ // @nathan-pichon 20/02/2023
1940
+ contentType: contentTypeSchema.required().noUnknown(false),
1941
+ components: nestedComponentSchema
1942
+ }).noUnknown();
1943
+ };
1944
+ const validateContentTypeInput = (data) => {
1945
+ return utils.validateYupSchema(createContentTypeSchema(data))(data);
1946
+ };
1947
+ const validateUpdateContentTypeInput = (data) => {
1948
+ if (fp.has("contentType", data)) {
1949
+ removeEmptyDefaults(data.contentType);
1950
+ removeDeletedUIDTargetFields(data.contentType);
1951
+ }
1952
+ if (fp.has("components", data) && Array.isArray(data.components)) {
1953
+ data.components.forEach((comp) => {
1954
+ if (fp.has("uid", comp)) {
1955
+ removeEmptyDefaults(comp);
1956
+ }
1957
+ });
1958
+ }
1959
+ return utils.validateYupSchema(createContentTypeSchema(data, { isEdition: true }))(data);
1960
+ };
1961
+ const forbiddenContentTypeNameValidator = () => {
1962
+ const reservedNames = getService("builder").getReservedNames().models;
1963
+ return {
1964
+ name: "forbiddenContentTypeName",
1965
+ message: `Content Type name cannot be one of ${reservedNames.join(", ")}`,
1966
+ test(value) {
1967
+ if (typeof value !== "string") {
1968
+ return true;
1969
+ }
1970
+ return !getService("builder").isReservedModelName(value);
1971
+ }
1972
+ };
1973
+ };
1974
+ const nameIsAvailable = (isEdition) => {
1975
+ const usedNames = fp.flatMap((ct) => {
1976
+ return [ct.info?.singularName, ct.info?.pluralName];
1977
+ })(strapi.contentTypes);
1978
+ return {
1979
+ name: "nameAlreadyUsed",
1980
+ message: "contentType: name `${value}` is already being used by another content type.",
1981
+ test(value) {
1982
+ if (isEdition)
1983
+ return true;
1984
+ if (typeof value !== "string") {
1985
+ return true;
1986
+ }
1987
+ return usedNames.every((usedName) => fp.snakeCase(usedName) !== fp.snakeCase(value));
1988
+ }
1989
+ };
1990
+ };
1991
+ const nameIsNotExistingCollectionName = (isEdition) => {
1992
+ const usedNames = Object.keys(strapi.contentTypes).map(
1993
+ (key) => strapi.contentTypes[key].collectionName
1994
+ );
1995
+ return {
1996
+ name: "nameAlreadyUsed",
1997
+ message: "contentType: name `${value}` is already being used by another content type.",
1998
+ test(value) {
1999
+ if (isEdition)
2000
+ return true;
2001
+ if (typeof value !== "string") {
2002
+ return true;
2003
+ }
2004
+ return usedNames.every((usedName) => fp.snakeCase(usedName) !== fp.snakeCase(value));
2005
+ }
2006
+ };
2007
+ };
2008
+ const kindSchema = utils.yup.string().oneOf([typeKinds.SINGLE_TYPE, typeKinds.COLLECTION_TYPE]);
2009
+ const validateKind = utils.validateYupSchema(kindSchema);
2010
+ const contentTypes = {
2011
+ async getContentTypes(ctx) {
2012
+ const { kind } = ctx.query;
2013
+ try {
2014
+ await validateKind(kind);
2015
+ } catch (error) {
2016
+ return ctx.send({ error }, 400);
2017
+ }
2018
+ const contentTypeService = getService("content-types");
2019
+ const contentTypes2 = Object.keys(strapi.contentTypes).filter(
2020
+ (uid) => !kind || ___default.default.get(strapi.contentTypes[uid], "kind", "collectionType") === kind
2021
+ ).map(
2022
+ (uid) => contentTypeService.formatContentType(strapi.contentTypes[uid])
2023
+ );
2024
+ ctx.send({
2025
+ data: contentTypes2
2026
+ });
2027
+ },
2028
+ getContentType(ctx) {
2029
+ const { uid } = ctx.params;
2030
+ const contentType = strapi.contentTypes[uid];
2031
+ if (!contentType) {
2032
+ return ctx.send({ error: "contentType.notFound" }, 404);
2033
+ }
2034
+ const contentTypeService = getService("content-types");
2035
+ ctx.send({ data: contentTypeService.formatContentType(contentType) });
2036
+ },
2037
+ async createContentType(ctx) {
2038
+ const body = ctx.request.body;
2039
+ try {
2040
+ await validateContentTypeInput(body);
2041
+ } catch (error) {
2042
+ return ctx.send({ error }, 400);
2043
+ }
2044
+ try {
2045
+ strapi.reload.isWatching = false;
2046
+ const contentTypeService = getService("content-types");
2047
+ const contentType = await contentTypeService.createContentType({
2048
+ contentType: body.contentType,
2049
+ components: body.components
2050
+ });
2051
+ const metricsPayload = {
2052
+ eventProperties: {
2053
+ kind: contentType.kind
2054
+ }
2055
+ };
2056
+ if (___default.default.isEmpty(strapi.apis)) {
2057
+ await strapi.telemetry.send("didCreateFirstContentType", metricsPayload);
2058
+ } else {
2059
+ await strapi.telemetry.send("didCreateContentType", metricsPayload);
2060
+ }
2061
+ setImmediate(() => strapi.reload());
2062
+ ctx.send({ data: { uid: contentType.uid } }, 201);
2063
+ } catch (err) {
2064
+ strapi.log.error(err);
2065
+ await strapi.telemetry.send("didNotCreateContentType", {
2066
+ eventProperties: { error: err.message || err }
2067
+ });
2068
+ ctx.send({ error: err.message || "Unknown error" }, 400);
2069
+ }
2070
+ },
2071
+ async updateContentType(ctx) {
2072
+ const { uid } = ctx.params;
2073
+ const body = ctx.request.body;
2074
+ if (!___default.default.has(strapi.contentTypes, uid)) {
2075
+ return ctx.send({ error: "contentType.notFound" }, 404);
2076
+ }
2077
+ try {
2078
+ await validateUpdateContentTypeInput(body);
2079
+ } catch (error) {
2080
+ return ctx.send({ error }, 400);
2081
+ }
2082
+ try {
2083
+ strapi.reload.isWatching = false;
2084
+ const contentTypeService = getService("content-types");
2085
+ const component = await contentTypeService.editContentType(uid, {
2086
+ contentType: body.contentType,
2087
+ components: body.components
2088
+ });
2089
+ setImmediate(() => strapi.reload());
2090
+ ctx.send({ data: { uid: component.uid } }, 201);
2091
+ } catch (error) {
2092
+ strapi.log.error(error);
2093
+ ctx.send({ error: error?.message || "Unknown error" }, 400);
2094
+ }
2095
+ },
2096
+ async deleteContentType(ctx) {
2097
+ const { uid } = ctx.params;
2098
+ if (!___default.default.has(strapi.contentTypes, uid)) {
2099
+ return ctx.send({ error: "contentType.notFound" }, 404);
2100
+ }
2101
+ try {
2102
+ strapi.reload.isWatching = false;
2103
+ const contentTypeService = getService("content-types");
2104
+ const component = await contentTypeService.deleteContentType(uid);
2105
+ setImmediate(() => strapi.reload());
2106
+ ctx.send({ data: { uid: component.uid } });
2107
+ } catch (error) {
2108
+ strapi.log.error(error);
2109
+ ctx.send({ error: error?.message || "Unknown error" }, 400);
2110
+ }
2111
+ }
2112
+ };
2113
+ const exportObject = {
2114
+ builder,
2115
+ "component-categories": componentCategories,
2116
+ components,
2117
+ "content-types": contentTypes
2118
+ };
2119
+ const admin = {
2120
+ type: "admin",
2121
+ routes: [
2122
+ {
2123
+ method: "GET",
2124
+ path: "/reserved-names",
2125
+ handler: "builder.getReservedNames",
2126
+ config: {
2127
+ policies: [
2128
+ {
2129
+ name: "admin::hasPermissions",
2130
+ config: { actions: ["plugin::content-type-builder.read"] }
2131
+ }
2132
+ ]
2133
+ }
2134
+ },
2135
+ {
2136
+ method: "GET",
2137
+ path: "/content-types",
2138
+ handler: "content-types.getContentTypes",
2139
+ config: {
2140
+ policies: [
2141
+ {
2142
+ name: "admin::hasPermissions",
2143
+ config: { actions: ["plugin::content-type-builder.read"] }
2144
+ }
2145
+ ]
2146
+ }
2147
+ },
2148
+ {
2149
+ method: "GET",
2150
+ path: "/content-types/:uid",
2151
+ handler: "content-types.getContentType",
2152
+ config: {
2153
+ policies: [
2154
+ {
2155
+ name: "admin::hasPermissions",
2156
+ config: { actions: ["plugin::content-type-builder.read"] }
2157
+ }
2158
+ ]
2159
+ }
2160
+ },
2161
+ {
2162
+ method: "POST",
2163
+ path: "/content-types",
2164
+ handler: "content-types.createContentType",
2165
+ config: {
2166
+ policies: [
2167
+ {
2168
+ name: "admin::hasPermissions",
2169
+ config: { actions: ["plugin::content-type-builder.read"] }
2170
+ }
2171
+ ]
2172
+ }
2173
+ },
2174
+ {
2175
+ method: "PUT",
2176
+ path: "/content-types/:uid",
2177
+ handler: "content-types.updateContentType",
2178
+ config: {
2179
+ policies: [
2180
+ {
2181
+ name: "admin::hasPermissions",
2182
+ config: { actions: ["plugin::content-type-builder.read"] }
2183
+ }
2184
+ ]
2185
+ }
2186
+ },
2187
+ {
2188
+ method: "DELETE",
2189
+ path: "/content-types/:uid",
2190
+ handler: "content-types.deleteContentType",
2191
+ config: {
2192
+ policies: [
2193
+ {
2194
+ name: "admin::hasPermissions",
2195
+ config: { actions: ["plugin::content-type-builder.read"] }
2196
+ }
2197
+ ]
2198
+ }
2199
+ },
2200
+ {
2201
+ method: "GET",
2202
+ path: "/components",
2203
+ handler: "components.getComponents",
2204
+ config: {
2205
+ policies: [
2206
+ {
2207
+ name: "admin::hasPermissions",
2208
+ config: { actions: ["plugin::content-type-builder.read"] }
2209
+ }
2210
+ ]
2211
+ }
2212
+ },
2213
+ {
2214
+ method: "GET",
2215
+ path: "/components/:uid",
2216
+ handler: "components.getComponent",
2217
+ config: {
2218
+ policies: [
2219
+ {
2220
+ name: "admin::hasPermissions",
2221
+ config: { actions: ["plugin::content-type-builder.read"] }
2222
+ }
2223
+ ]
2224
+ }
2225
+ },
2226
+ {
2227
+ method: "POST",
2228
+ path: "/components",
2229
+ handler: "components.createComponent",
2230
+ config: {
2231
+ policies: [
2232
+ {
2233
+ name: "admin::hasPermissions",
2234
+ config: { actions: ["plugin::content-type-builder.read"] }
2235
+ }
2236
+ ]
2237
+ }
2238
+ },
2239
+ {
2240
+ method: "PUT",
2241
+ path: "/components/:uid",
2242
+ handler: "components.updateComponent",
2243
+ config: {
2244
+ policies: [
2245
+ {
2246
+ name: "admin::hasPermissions",
2247
+ config: { actions: ["plugin::content-type-builder.read"] }
2248
+ }
2249
+ ]
2250
+ }
2251
+ },
2252
+ {
2253
+ method: "DELETE",
2254
+ path: "/components/:uid",
2255
+ handler: "components.deleteComponent",
2256
+ config: {
2257
+ policies: [
2258
+ {
2259
+ name: "admin::hasPermissions",
2260
+ config: { actions: ["plugin::content-type-builder.read"] }
2261
+ }
2262
+ ]
2263
+ }
2264
+ },
2265
+ {
2266
+ method: "PUT",
2267
+ path: "/component-categories/:name",
2268
+ handler: "component-categories.editCategory",
2269
+ config: {
2270
+ policies: [
2271
+ {
2272
+ name: "admin::hasPermissions",
2273
+ config: { actions: ["plugin::content-type-builder.read"] }
2274
+ }
2275
+ ]
2276
+ }
2277
+ },
2278
+ {
2279
+ method: "DELETE",
2280
+ path: "/component-categories/:name",
2281
+ handler: "component-categories.deleteCategory",
2282
+ config: {
2283
+ policies: [
2284
+ {
2285
+ name: "admin::hasPermissions",
2286
+ config: { actions: ["plugin::content-type-builder.read"] }
2287
+ }
2288
+ ]
2289
+ }
2290
+ }
2291
+ ]
2292
+ };
2293
+ const contentApi = {
2294
+ type: "content-api",
2295
+ routes: [
2296
+ {
2297
+ method: "GET",
2298
+ path: "/content-types",
2299
+ handler: "content-types.getContentTypes"
2300
+ },
2301
+ {
2302
+ method: "GET",
2303
+ path: "/content-types/:uid",
2304
+ handler: "content-types.getContentType"
2305
+ },
2306
+ {
2307
+ method: "GET",
2308
+ path: "/components",
2309
+ handler: "components.getComponents"
2310
+ },
2311
+ {
2312
+ method: "GET",
2313
+ path: "/components/:uid",
2314
+ handler: "components.getComponent"
2315
+ }
2316
+ ]
2317
+ };
2318
+ const routes = {
2319
+ admin,
2320
+ "content-api": contentApi
2321
+ };
2322
+ const index = () => ({
2323
+ config,
2324
+ bootstrap,
2325
+ services,
2326
+ controllers: exportObject,
2327
+ routes
2328
+ });
2329
+ module.exports = index;
2330
+ //# sourceMappingURL=index.js.map