@webiny/api-headless-cms 5.34.8 → 5.35.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/context.js +47 -68
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.js +0 -5
  4. package/crud/contentEntry/afterDelete.js.map +1 -1
  5. package/crud/contentEntry/beforeCreate.js +0 -3
  6. package/crud/contentEntry/beforeCreate.js.map +1 -1
  7. package/crud/contentEntry/beforeUpdate.js +0 -3
  8. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  9. package/crud/contentEntry/entryDataValidation.js +1 -40
  10. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  11. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  12. package/crud/contentEntry/markLockedFields.js +5 -26
  13. package/crud/contentEntry/markLockedFields.js.map +1 -1
  14. package/crud/contentEntry/referenceFieldsMapping.js +39 -66
  15. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  16. package/crud/contentEntry/searchableFields.js +1 -12
  17. package/crud/contentEntry/searchableFields.js.map +1 -1
  18. package/crud/contentEntry.crud.d.ts +5 -2
  19. package/crud/contentEntry.crud.js +859 -941
  20. package/crud/contentEntry.crud.js.map +1 -1
  21. package/crud/contentModel/afterCreate.js +0 -2
  22. package/crud/contentModel/afterCreate.js.map +1 -1
  23. package/crud/contentModel/afterCreateFrom.js +0 -2
  24. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  25. package/crud/contentModel/afterDelete.js +0 -2
  26. package/crud/contentModel/afterDelete.js.map +1 -1
  27. package/crud/contentModel/afterUpdate.js +0 -2
  28. package/crud/contentModel/afterUpdate.js.map +1 -1
  29. package/crud/contentModel/beforeCreate.js +39 -105
  30. package/crud/contentModel/beforeCreate.js.map +1 -1
  31. package/crud/contentModel/beforeDelete.d.ts +1 -1
  32. package/crud/contentModel/beforeDelete.js +1 -15
  33. package/crud/contentModel/beforeDelete.js.map +1 -1
  34. package/crud/contentModel/beforeUpdate.js +31 -8
  35. package/crud/contentModel/beforeUpdate.js.map +1 -1
  36. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  37. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  38. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  39. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  40. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  41. package/crud/contentModel/createFieldStorageId.js +0 -3
  42. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  43. package/crud/contentModel/defaultFields.d.ts +5 -0
  44. package/crud/contentModel/defaultFields.js +58 -0
  45. package/crud/contentModel/defaultFields.js.map +1 -0
  46. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  47. package/crud/contentModel/fields/descriptionField.js +42 -0
  48. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  49. package/crud/contentModel/fields/imageField.d.ts +2 -0
  50. package/crud/contentModel/fields/imageField.js +46 -0
  51. package/crud/contentModel/fields/imageField.js.map +1 -0
  52. package/crud/contentModel/fields/titleField.d.ts +2 -0
  53. package/crud/contentModel/fields/titleField.js +58 -0
  54. package/crud/contentModel/fields/titleField.js.map +1 -0
  55. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  56. package/crud/contentModel/validate/endingAllowed.js +26 -0
  57. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  58. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  59. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  60. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  61. package/crud/contentModel/validate/modelId.d.ts +11 -0
  62. package/crud/contentModel/validate/modelId.js +36 -0
  63. package/crud/contentModel/validate/modelId.js.map +1 -0
  64. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  65. package/crud/contentModel/validate/pluralApiName.js +24 -0
  66. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  67. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  68. package/crud/contentModel/validate/singularApiName.js +24 -0
  69. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  70. package/crud/contentModel/validateLayout.js +0 -8
  71. package/crud/contentModel/validateLayout.js.map +1 -1
  72. package/crud/contentModel/validateModel.d.ts +1 -0
  73. package/crud/contentModel/validateModel.js +0 -8
  74. package/crud/contentModel/validateModel.js.map +1 -1
  75. package/crud/contentModel/validateModelFields.d.ts +2 -1
  76. package/crud/contentModel/validateModelFields.js +25 -133
  77. package/crud/contentModel/validateModelFields.js.map +1 -1
  78. package/crud/contentModel/validation.d.ts +551 -0
  79. package/crud/contentModel/validation.js +145 -0
  80. package/crud/contentModel/validation.js.map +1 -0
  81. package/crud/contentModel.crud.js +354 -373
  82. package/crud/contentModel.crud.js.map +1 -1
  83. package/crud/contentModelGroup/beforeCreate.js +0 -12
  84. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  85. package/crud/contentModelGroup/beforeDelete.js +0 -8
  86. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  87. package/crud/contentModelGroup/beforeUpdate.js +0 -5
  88. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  89. package/crud/contentModelGroup/validation.d.ts +30 -0
  90. package/crud/contentModelGroup/validation.js +34 -0
  91. package/crud/contentModelGroup/validation.js.map +1 -0
  92. package/crud/contentModelGroup.crud.js +177 -221
  93. package/crud/contentModelGroup.crud.js.map +1 -1
  94. package/crud/settings.crud.d.ts +1 -1
  95. package/crud/settings.crud.js +5 -22
  96. package/crud/settings.crud.js.map +1 -1
  97. package/crud/system.crud.js +1 -96
  98. package/crud/system.crud.js.map +1 -1
  99. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
  100. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  101. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +0 -36
  102. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  103. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
  104. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  105. package/fieldConverters/index.js +0 -5
  106. package/fieldConverters/index.js.map +1 -1
  107. package/graphql/buildSchemaPlugins.d.ts +2 -2
  108. package/graphql/buildSchemaPlugins.js +4 -9
  109. package/graphql/buildSchemaPlugins.js.map +1 -1
  110. package/graphql/checkEndpointAccess.d.ts +2 -0
  111. package/graphql/checkEndpointAccess.js +18 -0
  112. package/graphql/checkEndpointAccess.js.map +1 -0
  113. package/graphql/createExecutableSchema.d.ts +2 -3
  114. package/graphql/createExecutableSchema.js +2 -6
  115. package/graphql/createExecutableSchema.js.map +1 -1
  116. package/graphql/createRequestBody.d.ts +2 -0
  117. package/graphql/createRequestBody.js +14 -0
  118. package/graphql/createRequestBody.js.map +1 -0
  119. package/graphql/formatErrorPayload.d.ts +1 -0
  120. package/graphql/formatErrorPayload.js +25 -0
  121. package/graphql/formatErrorPayload.js.map +1 -0
  122. package/graphql/generateSchema.js +2 -9
  123. package/graphql/generateSchema.js.map +1 -1
  124. package/graphql/getSchema.d.ts +17 -0
  125. package/graphql/getSchema.js +102 -0
  126. package/graphql/getSchema.js.map +1 -0
  127. package/graphql/graphQLHandlerFactory.js +6 -173
  128. package/graphql/graphQLHandlerFactory.js.map +1 -1
  129. package/graphql/handleRequest.d.ts +11 -0
  130. package/graphql/handleRequest.js +81 -0
  131. package/graphql/handleRequest.js.map +1 -0
  132. package/graphql/index.d.ts +1 -1
  133. package/graphql/index.js +0 -5
  134. package/graphql/index.js.map +1 -1
  135. package/graphql/schema/baseContentSchema.d.ts +2 -2
  136. package/graphql/schema/baseContentSchema.js +5 -19
  137. package/graphql/schema/baseContentSchema.js.map +1 -1
  138. package/graphql/schema/baseSchema.d.ts +1 -1
  139. package/graphql/schema/baseSchema.js +5 -10
  140. package/graphql/schema/baseSchema.js.map +1 -1
  141. package/graphql/schema/contentEntries.d.ts +2 -2
  142. package/graphql/schema/contentEntries.js +98 -100
  143. package/graphql/schema/contentEntries.js.map +1 -1
  144. package/graphql/schema/contentModelGroups.d.ts +2 -2
  145. package/graphql/schema/contentModelGroups.js +12 -29
  146. package/graphql/schema/contentModelGroups.js.map +1 -1
  147. package/graphql/schema/contentModels.d.ts +2 -2
  148. package/graphql/schema/contentModels.js +28 -31
  149. package/graphql/schema/contentModels.js.map +1 -1
  150. package/graphql/schema/createFieldResolvers.js +7 -29
  151. package/graphql/schema/createFieldResolvers.js.map +1 -1
  152. package/graphql/schema/createManageResolvers.d.ts +1 -1
  153. package/graphql/schema/createManageResolvers.js +33 -43
  154. package/graphql/schema/createManageResolvers.js.map +1 -1
  155. package/graphql/schema/createManageSDL.d.ts +1 -0
  156. package/graphql/schema/createManageSDL.js +56 -63
  157. package/graphql/schema/createManageSDL.js.map +1 -1
  158. package/graphql/schema/createPreviewResolvers.js +3 -17
  159. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  160. package/graphql/schema/createReadResolvers.js +4 -18
  161. package/graphql/schema/createReadResolvers.js.map +1 -1
  162. package/graphql/schema/createReadSDL.d.ts +1 -0
  163. package/graphql/schema/createReadSDL.js +24 -32
  164. package/graphql/schema/createReadSDL.js.map +1 -1
  165. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  166. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
  167. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  168. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  169. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  170. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  171. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  172. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  173. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  174. package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
  175. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  176. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  177. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  178. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  179. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  180. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  181. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  182. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  183. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  184. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  185. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  186. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  187. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  188. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  189. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  190. package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
  191. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  192. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  193. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  194. package/graphql/schema/resolvers/read/resolveGet.js +0 -8
  195. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  196. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  197. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  198. package/graphql/schema/schemaPlugins.d.ts +2 -2
  199. package/graphql/schema/schemaPlugins.js +21 -30
  200. package/graphql/schema/schemaPlugins.js.map +1 -1
  201. package/graphql/system.js +55 -87
  202. package/graphql/system.js.map +1 -1
  203. package/graphqlFields/boolean.js +0 -12
  204. package/graphqlFields/boolean.js.map +1 -1
  205. package/graphqlFields/datetime.js +0 -17
  206. package/graphqlFields/datetime.js.map +1 -1
  207. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
  208. package/graphqlFields/dynamicZone/dynamicZoneField.js +57 -48
  209. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  210. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +2 -18
  211. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
  212. package/graphqlFields/dynamicZone/index.js +0 -2
  213. package/graphqlFields/dynamicZone/index.js.map +1 -1
  214. package/graphqlFields/file.js +0 -8
  215. package/graphqlFields/file.js.map +1 -1
  216. package/graphqlFields/helpers.js +0 -10
  217. package/graphqlFields/helpers.js.map +1 -1
  218. package/graphqlFields/index.js +0 -12
  219. package/graphqlFields/index.js.map +1 -1
  220. package/graphqlFields/longText.js +0 -10
  221. package/graphqlFields/longText.js.map +1 -1
  222. package/graphqlFields/number.js +0 -12
  223. package/graphqlFields/number.js.map +1 -1
  224. package/graphqlFields/object.js +21 -38
  225. package/graphqlFields/object.js.map +1 -1
  226. package/graphqlFields/ref.js +59 -65
  227. package/graphqlFields/ref.js.map +1 -1
  228. package/graphqlFields/richText.js +0 -9
  229. package/graphqlFields/richText.js.map +1 -1
  230. package/graphqlFields/text.js +0 -11
  231. package/graphqlFields/text.js.map +1 -1
  232. package/index.d.ts +4 -2
  233. package/index.js +26 -22
  234. package/index.js.map +1 -1
  235. package/modelManager/DefaultCmsModelManager.js +0 -16
  236. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  237. package/modelManager/index.js +0 -4
  238. package/modelManager/index.js.map +1 -1
  239. package/package.json +26 -28
  240. package/parameters/context.js +0 -4
  241. package/parameters/context.js.map +1 -1
  242. package/parameters/header.js +0 -11
  243. package/parameters/header.js.map +1 -1
  244. package/parameters/index.js +0 -8
  245. package/parameters/index.js.map +1 -1
  246. package/parameters/manual.js +1 -8
  247. package/parameters/manual.js.map +1 -1
  248. package/parameters/path.js +0 -11
  249. package/parameters/path.js.map +1 -1
  250. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  251. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  252. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  253. package/plugins/CmsGraphQLSchemaSorterPlugin.js +0 -10
  254. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
  255. package/plugins/CmsGroupPlugin.js +0 -8
  256. package/plugins/CmsGroupPlugin.js.map +1 -1
  257. package/plugins/CmsModelFieldConverterPlugin.js +0 -5
  258. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  259. package/plugins/CmsModelPlugin.d.ts +21 -3
  260. package/plugins/CmsModelPlugin.js +30 -40
  261. package/plugins/CmsModelPlugin.js.map +1 -1
  262. package/plugins/CmsParametersPlugin.js +0 -7
  263. package/plugins/CmsParametersPlugin.js.map +1 -1
  264. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  265. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  266. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  267. package/plugins/StorageTransformPlugin.js +0 -9
  268. package/plugins/StorageTransformPlugin.js.map +1 -1
  269. package/plugins/index.d.ts +2 -0
  270. package/plugins/index.js +22 -12
  271. package/plugins/index.js.map +1 -1
  272. package/storage/default.js +0 -3
  273. package/storage/default.js.map +1 -1
  274. package/storage/object.js +0 -19
  275. package/storage/object.js.map +1 -1
  276. package/types.d.ts +173 -79
  277. package/types.js +23 -73
  278. package/types.js.map +1 -1
  279. package/utils/access.js +11 -25
  280. package/utils/access.js.map +1 -1
  281. package/utils/converters/Converter.js +0 -13
  282. package/utils/converters/Converter.js.map +1 -1
  283. package/utils/converters/ConverterCollection.js +9 -33
  284. package/utils/converters/ConverterCollection.js.map +1 -1
  285. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  286. package/utils/converters/valueKeyStorageConverter.js +21 -44
  287. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  288. package/utils/createTypeFromFields.d.ts +1 -0
  289. package/utils/createTypeFromFields.js +11 -20
  290. package/utils/createTypeFromFields.js.map +1 -1
  291. package/utils/createTypeName.d.ts +0 -2
  292. package/utils/createTypeName.js +2 -19
  293. package/utils/createTypeName.js.map +1 -1
  294. package/utils/entryStorage.js +10 -26
  295. package/utils/entryStorage.js.map +1 -1
  296. package/utils/filterAsync.js +0 -5
  297. package/utils/filterAsync.js.map +1 -1
  298. package/utils/getBaseFieldType.js +0 -2
  299. package/utils/getBaseFieldType.js.map +1 -1
  300. package/utils/getEntryDescription.d.ts +2 -0
  301. package/utils/getEntryDescription.js +17 -0
  302. package/utils/getEntryDescription.js.map +1 -0
  303. package/utils/getEntryImage.d.ts +2 -0
  304. package/utils/getEntryImage.js +17 -0
  305. package/utils/getEntryImage.js.map +1 -0
  306. package/utils/getEntryTitle.js +0 -9
  307. package/utils/getEntryTitle.js.map +1 -1
  308. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  309. package/utils/getSchemaFromFieldPlugins.js +23 -19
  310. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  311. package/utils/incrementEntryIdVersion.d.ts +5 -0
  312. package/utils/incrementEntryIdVersion.js +29 -0
  313. package/utils/incrementEntryIdVersion.js.map +1 -0
  314. package/utils/ownership.d.ts +3 -3
  315. package/utils/ownership.js +0 -8
  316. package/utils/ownership.js.map +1 -1
  317. package/utils/permissions.js +8 -23
  318. package/utils/permissions.js.map +1 -1
  319. package/utils/renderFields.d.ts +2 -1
  320. package/utils/renderFields.js +8 -10
  321. package/utils/renderFields.js.map +1 -1
  322. package/utils/renderGetFilterFields.js +0 -13
  323. package/utils/renderGetFilterFields.js.map +1 -1
  324. package/utils/renderInputFields.d.ts +2 -1
  325. package/utils/renderInputFields.js +4 -9
  326. package/utils/renderInputFields.js.map +1 -1
  327. package/utils/renderListFilterFields.js +1 -10
  328. package/utils/renderListFilterFields.js.map +1 -1
  329. package/utils/renderSortEnum.js +0 -9
  330. package/utils/renderSortEnum.js.map +1 -1
  331. package/utils/toSlug.js +0 -4
  332. package/utils/toSlug.js.map +1 -1
  333. package/validators/dateGte.js +0 -7
  334. package/validators/dateGte.js.map +1 -1
  335. package/validators/dateLte.js +0 -7
  336. package/validators/dateLte.js.map +1 -1
  337. package/validators/dynamicZone.js +0 -4
  338. package/validators/dynamicZone.js.map +1 -1
  339. package/validators/gte.js +0 -8
  340. package/validators/gte.js.map +1 -1
  341. package/validators/in.js +0 -8
  342. package/validators/in.js.map +1 -1
  343. package/validators/index.js +0 -16
  344. package/validators/index.js.map +1 -1
  345. package/validators/lte.js +0 -8
  346. package/validators/lte.js.map +1 -1
  347. package/validators/maxLength.js +0 -8
  348. package/validators/maxLength.js.map +1 -1
  349. package/validators/minLength.js +0 -8
  350. package/validators/minLength.js.map +1 -1
  351. package/validators/pattern.js +0 -9
  352. package/validators/pattern.js.map +1 -1
  353. package/validators/patternPlugins/email.js +0 -2
  354. package/validators/patternPlugins/email.js.map +1 -1
  355. package/validators/patternPlugins/index.js +0 -8
  356. package/validators/patternPlugins/index.js.map +1 -1
  357. package/validators/patternPlugins/lowerCase.js +0 -2
  358. package/validators/patternPlugins/lowerCase.js.map +1 -1
  359. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  360. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  361. package/validators/patternPlugins/upperCase.js +0 -2
  362. package/validators/patternPlugins/upperCase.js.map +1 -1
  363. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  364. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  365. package/validators/patternPlugins/url.js +0 -2
  366. package/validators/patternPlugins/url.js.map +1 -1
  367. package/validators/required.js +0 -5
  368. package/validators/required.js.map +1 -1
  369. package/validators/timeGte.js +0 -8
  370. package/validators/timeGte.js.map +1 -1
  371. package/validators/timeLte.js +0 -8
  372. package/validators/timeLte.js.map +1 -1
  373. package/validators/unique.js +0 -7
  374. package/validators/unique.js.map +1 -1
@@ -1,23 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
15
-
16
11
  var _getBaseFieldType = require("./getBaseFieldType");
17
-
18
12
  const getStoragePluginFactory = context => {
19
13
  let defaultStoragePlugin;
20
- const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type) // we reverse plugins because we want to get latest added only
14
+ const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type)
15
+ // we reverse plugins because we want to get latest added only
21
16
  .reverse().reduce((collection, plugin) => {
22
17
  /**
23
18
  * Check if it's a default plugin and set it - always override the previous one.
@@ -26,12 +21,11 @@ const getStoragePluginFactory = context => {
26
21
  defaultStoragePlugin = plugin;
27
22
  return collection;
28
23
  }
24
+
29
25
  /**
30
26
  * We will just set the plugin for given type.
31
27
  * The last one will override existing one - so users can override our default ones.
32
28
  */
33
-
34
-
35
29
  collection[plugin.fieldType] = plugin;
36
30
  return collection;
37
31
  }, {});
@@ -39,23 +33,20 @@ const getStoragePluginFactory = context => {
39
33
  return plugins[fieldType] || defaultStoragePlugin;
40
34
  };
41
35
  };
36
+
42
37
  /**
43
38
  * This should be used when transforming the whole entry.
44
39
  */
45
-
46
-
47
40
  const entryStorageTransform = async (context, model, operation, entry) => {
48
41
  const getStoragePlugin = getStoragePluginFactory(context);
49
42
  const transformedValues = {};
50
-
51
43
  for (const field of model.fields) {
52
44
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
53
- const plugin = getStoragePlugin(baseType); // TODO: remove this once plugins are converted into classes
54
-
45
+ const plugin = getStoragePlugin(baseType);
46
+ // TODO: remove this once plugins are converted into classes
55
47
  if (typeof plugin[operation] !== "function") {
56
48
  throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
57
49
  }
58
-
59
50
  transformedValues[field.fieldId] = await plugin[operation]({
60
51
  plugins: context.plugins,
61
52
  model,
@@ -64,32 +55,26 @@ const entryStorageTransform = async (context, model, operation, entry) => {
64
55
  getStoragePlugin
65
56
  });
66
57
  }
67
-
68
58
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
69
59
  values: transformedValues
70
60
  });
71
61
  };
62
+
72
63
  /**
73
64
  * A function that is used in crud to transform entry into the storage type.
74
65
  */
75
-
76
-
77
66
  const entryToStorageTransform = async (context, model, entry) => {
78
67
  return entryStorageTransform(context, model, "toStorage", entry);
79
68
  };
69
+
80
70
  /**
81
71
  * A function that is used to transform the whole entry from storage into its native form.
82
72
  */
83
-
84
-
85
73
  exports.entryToStorageTransform = entryToStorageTransform;
86
-
87
74
  const entryFromStorageTransform = async (context, model, entry) => {
88
75
  return entryStorageTransform(context, model, "fromStorage", entry);
89
76
  };
90
-
91
77
  exports.entryFromStorageTransform = entryFromStorageTransform;
92
-
93
78
  /*
94
79
  * A function that is used to transform a single field from storage
95
80
  */
@@ -102,12 +87,12 @@ const entryFieldFromStorageTransform = async params => {
102
87
  } = params;
103
88
  const getStoragePlugin = getStoragePluginFactory(context);
104
89
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
105
- const plugin = getStoragePlugin(baseType); // TODO: remove this once plugins are converted into classes
90
+ const plugin = getStoragePlugin(baseType);
106
91
 
92
+ // TODO: remove this once plugins are converted into classes
107
93
  if (typeof plugin.fromStorage !== "function") {
108
94
  throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
109
95
  }
110
-
111
96
  return plugin.fromStorage({
112
97
  plugins: context.plugins,
113
98
  model,
@@ -116,5 +101,4 @@ const entryFieldFromStorageTransform = async params => {
116
101
  getStoragePlugin
117
102
  });
118
103
  };
119
-
120
104
  exports.entryFieldFromStorageTransform = entryFieldFromStorageTransform;
@@ -1 +1 @@
1
- {"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: CmsContext;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":"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"}
1
+ {"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: CmsContext;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":"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"}
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.filterAsync = void 0;
7
-
8
7
  const filterAsync = async (items, predicate) => {
9
8
  const filteredItems = [];
10
-
11
9
  for (let i = 0; i < items.length; i++) {
12
10
  const item = items[i];
13
11
  const valid = await predicate(item);
14
-
15
12
  if (valid) {
16
13
  filteredItems.push(item);
17
14
  }
18
15
  }
19
-
20
16
  return filteredItems;
21
17
  };
22
-
23
18
  exports.filterAsync = filterAsync;
@@ -1 +1 @@
1
- {"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":";;;;;;;AAAO,MAAMA,WAAW,GAAG,OACvBC,KADuB,EAEvBC,SAFuB,KAGR;EACf,MAAMC,aAAa,GAAG,EAAtB;;EAEA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,KAAK,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;IACnC,MAAME,IAAI,GAAGL,KAAK,CAACG,CAAD,CAAlB;IACA,MAAMG,KAAK,GAAG,MAAML,SAAS,CAACI,IAAD,CAA7B;;IACA,IAAIC,KAAJ,EAAW;MACPJ,aAAa,CAACK,IAAd,CAAmBF,IAAnB;IACH;EACJ;;EAED,OAAOH,aAAP;AACH,CAfM"}
1
+ {"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":";;;;;;AAAO,MAAMA,WAAW,GAAG,OACvBC,KAAU,EACVC,SAAyC,KAC1B;EACf,MAAMC,aAAa,GAAG,EAAE;EAExB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAME,IAAI,GAAGL,KAAK,CAACG,CAAC,CAAC;IACrB,MAAMG,KAAK,GAAG,MAAML,SAAS,CAACI,IAAI,CAAC;IACnC,IAAIC,KAAK,EAAE;MACPJ,aAAa,CAACK,IAAI,CAACF,IAAI,CAAC;IAC5B;EACJ;EAEA,OAAOH,aAAa;AACxB,CAAC;AAAC"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getBaseFieldType = void 0;
7
-
8
7
  const getBaseFieldType = field => {
9
8
  return field.type.split(":")[0];
10
9
  };
11
-
12
10
  exports.getBaseFieldType = getBaseFieldType;
@@ -1 +1 @@
1
- {"version":3,"names":["getBaseFieldType","field","type","split"],"sources":["getBaseFieldType.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const getBaseFieldType = (field: { type: CmsModelField[\"type\"] }) => {\n return field.type.split(\":\")[0];\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,gBAAgB,GAAIC,KAAD,IAA4C;EACxE,OAAOA,KAAK,CAACC,IAAN,CAAWC,KAAX,CAAiB,GAAjB,EAAsB,CAAtB,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["getBaseFieldType","field","type","split"],"sources":["getBaseFieldType.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const getBaseFieldType = (field: { type: CmsModelField[\"type\"] }) => {\n return field.type.split(\":\")[0];\n};\n"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAIC,KAAsC,IAAK;EACxE,OAAOA,KAAK,CAACC,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntry, CmsModel } from "../types";
2
+ export declare function getEntryDescription(model: CmsModel, entry: CmsEntry): string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getEntryDescription = getEntryDescription;
7
+ function getEntryDescription(model, entry) {
8
+ if (!model.descriptionFieldId) {
9
+ return "";
10
+ }
11
+ const field = model.fields.find(f => f.fieldId === model.descriptionFieldId);
12
+ if (!field) {
13
+ return "";
14
+ }
15
+ const descriptionFieldId = field.fieldId;
16
+ return entry.values[descriptionFieldId] || "";
17
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getEntryDescription","model","entry","descriptionFieldId","field","fields","find","f","fieldId","values"],"sources":["getEntryDescription.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryDescription(model: CmsModel, entry: CmsEntry): string {\n if (!model.descriptionFieldId) {\n return \"\";\n }\n const field = model.fields.find(f => f.fieldId === model.descriptionFieldId);\n if (!field) {\n return \"\";\n }\n const descriptionFieldId = field.fieldId;\n return entry.values[descriptionFieldId] || \"\";\n}\n"],"mappings":";;;;;;AAEO,SAASA,mBAAmB,CAACC,KAAe,EAAEC,KAAe,EAAU;EAC1E,IAAI,CAACD,KAAK,CAACE,kBAAkB,EAAE;IAC3B,OAAO,EAAE;EACb;EACA,MAAMC,KAAK,GAAGH,KAAK,CAACI,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKP,KAAK,CAACE,kBAAkB,CAAC;EAC5E,IAAI,CAACC,KAAK,EAAE;IACR,OAAO,EAAE;EACb;EACA,MAAMD,kBAAkB,GAAGC,KAAK,CAACI,OAAO;EACxC,OAAON,KAAK,CAACO,MAAM,CAACN,kBAAkB,CAAC,IAAI,EAAE;AACjD"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntry, CmsModel } from "../types";
2
+ export declare function getEntryImage(model: CmsModel, entry: CmsEntry): string | null;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getEntryImage = getEntryImage;
7
+ function getEntryImage(model, entry) {
8
+ if (!model.imageFieldId) {
9
+ return null;
10
+ }
11
+ const field = model.fields.find(f => f.fieldId === model.imageFieldId);
12
+ if (!field) {
13
+ return null;
14
+ }
15
+ const imageFieldId = field.fieldId;
16
+ return entry.values[imageFieldId] || null;
17
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getEntryImage","model","entry","imageFieldId","field","fields","find","f","fieldId","values"],"sources":["getEntryImage.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryImage(model: CmsModel, entry: CmsEntry): string | null {\n if (!model.imageFieldId) {\n return null;\n }\n const field = model.fields.find(f => f.fieldId === model.imageFieldId);\n if (!field) {\n return null;\n }\n const imageFieldId = field.fieldId;\n return entry.values[imageFieldId] || null;\n}\n"],"mappings":";;;;;;AAEO,SAASA,aAAa,CAACC,KAAe,EAAEC,KAAe,EAAiB;EAC3E,IAAI,CAACD,KAAK,CAACE,YAAY,EAAE;IACrB,OAAO,IAAI;EACf;EACA,MAAMC,KAAK,GAAGH,KAAK,CAACI,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKP,KAAK,CAACE,YAAY,CAAC;EACtE,IAAI,CAACC,KAAK,EAAE;IACR,OAAO,IAAI;EACf;EACA,MAAMD,YAAY,GAAGC,KAAK,CAACI,OAAO;EAClC,OAAON,KAAK,CAACO,MAAM,CAACN,YAAY,CAAC,IAAI,IAAI;AAC7C"}
@@ -4,40 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getEntryTitle = getEntryTitle;
7
-
8
7
  function getEntryTitle(model, entry) {
9
8
  if (!model.titleFieldId) {
10
9
  return entry.id;
11
10
  }
12
-
13
11
  const field = model.fields.find(f => f.fieldId === model.titleFieldId);
14
-
15
12
  if (!field) {
16
13
  return entry.id;
17
14
  }
18
-
19
15
  const titleFieldId = field.fieldId;
20
16
  const titleValue = entry.values[titleFieldId];
21
-
22
17
  if (!titleValue) {
23
18
  return entry.id;
24
19
  }
25
-
26
20
  const {
27
21
  enabled = false,
28
22
  values
29
23
  } = field.predefinedValues || {};
30
-
31
24
  if (!enabled || !values || Array.isArray(values) === false) {
32
25
  return titleValue;
33
26
  }
34
-
35
27
  for (const value of values) {
36
28
  // needs to be loose because titleValue can be a number and value can be a string - but it must match
37
29
  if (value.value == titleValue) {
38
30
  return value.label;
39
31
  }
40
32
  }
41
-
42
33
  return titleValue;
43
34
  }
@@ -1 +1 @@
1
- {"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,aAAT,CAAuBC,KAAvB,EAAwCC,KAAxC,EAAiE;EACpE,IAAI,CAACD,KAAK,CAACE,YAAX,EAAyB;IACrB,OAAOD,KAAK,CAACE,EAAb;EACH;;EACD,MAAMC,KAAK,GAAGJ,KAAK,CAACK,MAAN,CAAaC,IAAb,CAAkBC,CAAC,IAAIA,CAAC,CAACC,OAAF,KAAcR,KAAK,CAACE,YAA3C,CAAd;;EACA,IAAI,CAACE,KAAL,EAAY;IACR,OAAOH,KAAK,CAACE,EAAb;EACH;;EACD,MAAMD,YAAY,GAAGE,KAAK,CAACI,OAA3B;EACA,MAAMC,UAAU,GAAGR,KAAK,CAACS,MAAN,CAAaR,YAAb,CAAnB;;EACA,IAAI,CAACO,UAAL,EAAiB;IACb,OAAOR,KAAK,CAACE,EAAb;EACH;;EAED,MAAM;IAAEQ,OAAO,GAAG,KAAZ;IAAmBD;EAAnB,IAA8BN,KAAK,CAACQ,gBAAN,IAA0B,EAA9D;;EACA,IAAI,CAACD,OAAD,IAAY,CAACD,MAAb,IAAuBG,KAAK,CAACC,OAAN,CAAcJ,MAAd,MAA0B,KAArD,EAA4D;IACxD,OAAOD,UAAP;EACH;;EACD,KAAK,MAAMM,KAAX,IAAoBL,MAApB,EAA4B;IACxB;IACA,IAAIK,KAAK,CAACA,KAAN,IAAeN,UAAnB,EAA+B;MAC3B,OAAOM,KAAK,CAACC,KAAb;IACH;EACJ;;EACD,OAAOP,UAAP;AACH"}
1
+ {"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":";;;;;;AAEO,SAASA,aAAa,CAACC,KAAe,EAAEC,KAAe,EAAU;EACpE,IAAI,CAACD,KAAK,CAACE,YAAY,EAAE;IACrB,OAAOD,KAAK,CAACE,EAAE;EACnB;EACA,MAAMC,KAAK,GAAGJ,KAAK,CAACK,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKR,KAAK,CAACE,YAAY,CAAC;EACtE,IAAI,CAACE,KAAK,EAAE;IACR,OAAOH,KAAK,CAACE,EAAE;EACnB;EACA,MAAMD,YAAY,GAAGE,KAAK,CAACI,OAAO;EAClC,MAAMC,UAAU,GAAGR,KAAK,CAACS,MAAM,CAACR,YAAY,CAAC;EAC7C,IAAI,CAACO,UAAU,EAAE;IACb,OAAOR,KAAK,CAACE,EAAE;EACnB;EAEA,MAAM;IAAEQ,OAAO,GAAG,KAAK;IAAED;EAAO,CAAC,GAAGN,KAAK,CAACQ,gBAAgB,IAAI,CAAC,CAAC;EAChE,IAAI,CAACD,OAAO,IAAI,CAACD,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,KAAK,KAAK,EAAE;IACxD,OAAOD,UAAU;EACrB;EACA,KAAK,MAAMM,KAAK,IAAIL,MAAM,EAAE;IACxB;IACA,IAAIK,KAAK,CAACA,KAAK,IAAIN,UAAU,EAAE;MAC3B,OAAOM,KAAK,CAACC,KAAK;IACtB;EACJ;EACA,OAAOP,UAAU;AACrB"}
@@ -1,12 +1,9 @@
1
- import { CmsModel, CmsContext, CmsFieldTypePlugins, ApiEndpoint } from "../types";
2
- import { GraphQLSchemaDefinition } from "@webiny/handler-graphql/types";
3
- interface RenderTypesFromFieldPluginsParams {
1
+ import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from "../types";
2
+ import { CmsGraphQLSchemaPlugin } from "../plugins";
3
+ interface Params {
4
4
  models: CmsModel[];
5
5
  fieldTypePlugins: CmsFieldTypePlugins;
6
6
  type: ApiEndpoint;
7
7
  }
8
- interface RenderTypesFromFieldPlugins {
9
- (params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];
10
- }
11
- export declare const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins;
8
+ export declare const createGraphQLSchemaPluginFromFieldPlugins: (params: Params) => CmsGraphQLSchemaPlugin<import("../types").CmsContext>[];
12
9
  export {};
@@ -3,33 +3,37 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSchemaFromFieldPlugins = void 0;
6
+ exports.createGraphQLSchemaPluginFromFieldPlugins = void 0;
7
+ var _plugins = require("../plugins");
7
8
  const TYPE_MAP = {
8
9
  preview: "read",
9
10
  read: "read",
10
11
  manage: "manage"
11
12
  };
12
-
13
- const getSchemaFromFieldPlugins = ({
14
- models,
15
- fieldTypePlugins,
16
- type
17
- }) => {
18
- return Object.values(fieldTypePlugins).map(plugin => {
19
- if (!TYPE_MAP[type] || !plugin[TYPE_MAP[type]]) {
20
- return null;
13
+ const createGraphQLSchemaPluginFromFieldPlugins = params => {
14
+ const {
15
+ models,
16
+ fieldTypePlugins,
17
+ type
18
+ } = params;
19
+ const plugins = [];
20
+ for (const key in fieldTypePlugins) {
21
+ const fieldTypePlugin = fieldTypePlugins[key];
22
+ if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {
23
+ continue;
21
24
  }
22
-
23
- const createSchema = plugin[TYPE_MAP[type]].createSchema; // Render gql types generated by field type plugins
24
-
25
+ const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;
26
+ // Render gql types generated by field type plugins
25
27
  if (!createSchema) {
26
- return null;
28
+ continue;
27
29
  }
28
-
29
- return createSchema({
30
+ const schema = createSchema({
30
31
  models
31
32
  });
32
- }).filter(Boolean);
33
+ const plugin = new _plugins.CmsGraphQLSchemaPlugin(schema);
34
+ plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;
35
+ plugins.push(plugin);
36
+ }
37
+ return plugins;
33
38
  };
34
-
35
- exports.getSchemaFromFieldPlugins = getSchemaFromFieldPlugins;
39
+ exports.createGraphQLSchemaPluginFromFieldPlugins = createGraphQLSchemaPluginFromFieldPlugins;
@@ -1 +1 @@
1
- {"version":3,"names":["TYPE_MAP","preview","read","manage","getSchemaFromFieldPlugins","models","fieldTypePlugins","type","Object","values","map","plugin","createSchema","filter","Boolean"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsContext, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types\";\n\ninterface RenderTypesFromFieldPluginsParams {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\ninterface RenderTypesFromFieldPlugins {\n (params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];\n}\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\nexport const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins = ({\n models,\n fieldTypePlugins,\n type\n}) => {\n return Object.values(fieldTypePlugins)\n .map(plugin => {\n if (!TYPE_MAP[type] || !plugin[TYPE_MAP[type]]) {\n return null;\n }\n const createSchema = plugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n return null;\n }\n return createSchema({ models });\n })\n .filter(Boolean) as GraphQLSchemaDefinition<CmsContext>[];\n};\n"],"mappings":";;;;;;AAYA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,MADuC;EAEhDC,IAAI,EAAE,MAF0C;EAGhDC,MAAM,EAAE;AAHwC,CAApD;;AAMO,MAAMC,yBAAsD,GAAG,CAAC;EACnEC,MADmE;EAEnEC,gBAFmE;EAGnEC;AAHmE,CAAD,KAIhE;EACF,OAAOC,MAAM,CAACC,MAAP,CAAcH,gBAAd,EACFI,GADE,CACEC,MAAM,IAAI;IACX,IAAI,CAACX,QAAQ,CAACO,IAAD,CAAT,IAAmB,CAACI,MAAM,CAACX,QAAQ,CAACO,IAAD,CAAT,CAA9B,EAAgD;MAC5C,OAAO,IAAP;IACH;;IACD,MAAMK,YAAY,GAAGD,MAAM,CAACX,QAAQ,CAACO,IAAD,CAAT,CAAN,CAAuBK,YAA5C,CAJW,CAKX;;IACA,IAAI,CAACA,YAAL,EAAmB;MACf,OAAO,IAAP;IACH;;IACD,OAAOA,YAAY,CAAC;MAAEP;IAAF,CAAD,CAAnB;EACH,CAXE,EAYFQ,MAZE,CAYKC,OAZL,CAAP;AAaH,CAlBM"}
1
+ {"version":3,"names":["TYPE_MAP","preview","read","manage","createGraphQLSchemaPluginFromFieldPlugins","params","models","fieldTypePlugins","type","plugins","key","fieldTypePlugin","createSchema","schema","plugin","CmsGraphQLSchemaPlugin","name","fieldType","push"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\ninterface Params {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\nexport const createGraphQLSchemaPluginFromFieldPlugins = (params: Params) => {\n const { models, fieldTypePlugins, type } = params;\n\n const plugins: CmsGraphQLSchemaPlugin[] = [];\n for (const key in fieldTypePlugins) {\n const fieldTypePlugin = fieldTypePlugins[key];\n if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {\n continue;\n }\n const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n continue;\n }\n const schema = createSchema({ models });\n\n const plugin = new CmsGraphQLSchemaPlugin(schema);\n plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;\n plugins.push(plugin);\n }\n return plugins;\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,MAAM;EACfC,IAAI,EAAE,MAAM;EACZC,MAAM,EAAE;AACZ,CAAC;AAOM,MAAMC,yCAAyC,GAAIC,MAAc,IAAK;EACzE,MAAM;IAAEC,MAAM;IAAEC,gBAAgB;IAAEC;EAAK,CAAC,GAAGH,MAAM;EAEjD,MAAMI,OAAiC,GAAG,EAAE;EAC5C,KAAK,MAAMC,GAAG,IAAIH,gBAAgB,EAAE;IAChC,MAAMI,eAAe,GAAGJ,gBAAgB,CAACG,GAAG,CAAC;IAC7C,IAAI,CAACV,QAAQ,CAACQ,IAAI,CAAC,IAAI,CAACG,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,EAAE;MACrD;IACJ;IACA,MAAMI,YAAY,GAAGD,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,CAACI,YAAY;IACjE;IACA,IAAI,CAACA,YAAY,EAAE;MACf;IACJ;IACA,MAAMC,MAAM,GAAGD,YAAY,CAAC;MAAEN;IAAO,CAAC,CAAC;IAEvC,MAAMQ,MAAM,GAAG,IAAIC,+BAAsB,CAACF,MAAM,CAAC;IACjDC,MAAM,CAACE,IAAI,GAAI,+BAA8BR,IAAK,UAASG,eAAe,CAACM,SAAU,EAAC;IACtFR,OAAO,CAACS,IAAI,CAACJ,MAAM,CAAC;EACxB;EACA,OAAOL,OAAO;AAClB,CAAC;AAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const incrementEntryIdVersion: (id: string) => {
2
+ entryId: string;
3
+ version: number;
4
+ id: string;
5
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.incrementEntryIdVersion = void 0;
8
+ var _utils = require("@webiny/utils");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const incrementEntryIdVersion = id => {
11
+ const {
12
+ id: entryId,
13
+ version
14
+ } = (0, _utils.parseIdentifier)(id);
15
+ if (!version) {
16
+ throw new _error.default("Cannot increase version on the ID without the version part.", "WRONG_ID", {
17
+ id
18
+ });
19
+ }
20
+ return {
21
+ entryId,
22
+ version: version + 1,
23
+ id: (0, _utils.createIdentifier)({
24
+ id: entryId,
25
+ version: version + 1
26
+ })
27
+ };
28
+ };
29
+ exports.incrementEntryIdVersion = incrementEntryIdVersion;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["incrementEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier"],"sources":["incrementEntryIdVersion.ts"],"sourcesContent":["import { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\n\nexport const incrementEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,uBAAuB,GAAIC,EAAU,IAAK;EACnD,MAAM;IAAEA,EAAE,EAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACH,EAAE,CAAC;EACpD,IAAI,CAACE,OAAO,EAAE;IACV,MAAM,IAAIE,cAAW,CACjB,6DAA6D,EAC7D,UAAU,EACV;MACIJ;IACJ,CAAC,CACJ;EACL;EACA,OAAO;IACHC,OAAO;IACPC,OAAO,EAAEA,OAAO,GAAG,CAAC;IACpBF,EAAE,EAAE,IAAAK,uBAAgB,EAAC;MACjBL,EAAE,EAAEC,OAAO;MACXC,OAAO,EAAEA,OAAO,GAAG;IACvB,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
@@ -1,7 +1,7 @@
1
- import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from "../types";
1
+ import { BaseCmsSecurityPermission, CmsContext, CmsIdentity } from "../types";
2
2
  interface OwnableRecord {
3
- createdBy?: CreatedBy;
4
- ownedBy?: CreatedBy;
3
+ createdBy?: CmsIdentity;
4
+ ownedBy?: CmsIdentity;
5
5
  }
6
6
  export declare const checkOwnership: (context: CmsContext, permission: BaseCmsSecurityPermission, record: OwnableRecord) => void;
7
7
  export declare const validateOwnership: (context: CmsContext, permission: BaseCmsSecurityPermission, record: OwnableRecord) => boolean;
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateOwnership = exports.checkOwnership = void 0;
7
-
8
7
  var _apiSecurity = require("@webiny/api-security");
9
-
10
8
  const checkOwnership = (context, permission, record) => {
11
9
  var _record$ownedBy, _record$createdBy;
12
-
13
10
  if (!permission.own) {
14
11
  return;
15
12
  }
16
-
17
13
  const identity = context.security.getIdentity();
18
14
  const owner = identity && ((_record$ownedBy = record.ownedBy) === null || _record$ownedBy === void 0 ? void 0 : _record$ownedBy.id) === identity.id;
19
15
  const creator = identity && ((_record$createdBy = record.createdBy) === null || _record$createdBy === void 0 ? void 0 : _record$createdBy.id) === identity.id;
20
-
21
16
  if (!owner && !creator) {
22
17
  throw new _apiSecurity.NotAuthorizedError({
23
18
  data: {
@@ -26,9 +21,7 @@ const checkOwnership = (context, permission, record) => {
26
21
  });
27
22
  }
28
23
  };
29
-
30
24
  exports.checkOwnership = checkOwnership;
31
-
32
25
  const validateOwnership = (context, permission, record) => {
33
26
  try {
34
27
  checkOwnership(context, permission, record);
@@ -37,5 +30,4 @@ const validateOwnership = (context, permission, record) => {
37
30
  return false;
38
31
  }
39
32
  };
40
-
41
33
  exports.validateOwnership = validateOwnership;
@@ -1 +1 @@
1
- {"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CreatedBy;\n ownedBy?: CreatedBy;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;;AACA;;AAOO,MAAMA,cAAc,GAAG,CAC1BC,OAD0B,EAE1BC,UAF0B,EAG1BC,MAH0B,KAInB;EAAA;;EACP,IAAI,CAACD,UAAU,CAACE,GAAhB,EAAqB;IACjB;EACH;;EAED,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,QAAR,CAAiBC,WAAjB,EAAjB;EACA,MAAMC,KAAK,GAAGH,QAAQ,IAAI,oBAAAF,MAAM,CAACM,OAAP,oEAAgBC,EAAhB,MAAuBL,QAAQ,CAACK,EAA1D;EACA,MAAMC,OAAO,GAAGN,QAAQ,IAAI,sBAAAF,MAAM,CAACS,SAAP,wEAAkBF,EAAlB,MAAyBL,QAAQ,CAACK,EAA9D;;EAEA,IAAI,CAACF,KAAD,IAAU,CAACG,OAAf,EAAwB;IACpB,MAAM,IAAIE,+BAAJ,CAAuB;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG;MADP;IADmB,CAAvB,CAAN;EAKH;AACJ,CApBM;;;;AAsBA,MAAMC,iBAAiB,GAAG,CAC7Bf,OAD6B,EAE7BC,UAF6B,EAG7BC,MAH6B,KAInB;EACV,IAAI;IACAH,cAAc,CAACC,OAAD,EAAUC,UAAV,EAAsBC,MAAtB,CAAd;IACA,OAAO,IAAP;EACH,CAHD,CAGE,MAAM;IACJ,OAAO,KAAP;EACH;AACJ,CAXM"}
1
+ {"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CmsIdentity } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CmsIdentity;\n ownedBy?: CmsIdentity;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;AACA;AAOO,MAAMA,cAAc,GAAG,CAC1BC,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACd;EAAA;EACP,IAAI,CAACD,UAAU,CAACE,GAAG,EAAE;IACjB;EACJ;EAEA,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,QAAQ,CAACC,WAAW,EAAE;EAC/C,MAAMC,KAAK,GAAGH,QAAQ,IAAI,oBAAAF,MAAM,CAACM,OAAO,oDAAd,gBAAgBC,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAC5D,MAAMC,OAAO,GAAGN,QAAQ,IAAI,sBAAAF,MAAM,CAACS,SAAS,sDAAhB,kBAAkBF,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAEhE,IAAI,CAACF,KAAK,IAAI,CAACG,OAAO,EAAE;IACpB,MAAM,IAAIE,+BAAkB,CAAC;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG;MACb;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC;AAEK,MAAMC,iBAAiB,GAAG,CAC7Bf,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACX;EACV,IAAI;IACAH,cAAc,CAACC,OAAO,EAAEC,UAAU,EAAEC,MAAM,CAAC;IAC3C,OAAO,IAAI;EACf,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAAC"}
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hasRwd = exports.hasPw = exports.checkPermissions = void 0;
7
-
8
7
  var _apiSecurity = require("@webiny/api-security");
9
-
10
8
  const hasRwd = (permission, rwd) => {
11
9
  if (typeof permission.rwd !== "string") {
12
10
  return true;
13
11
  }
14
-
15
12
  return permission.rwd.includes(rwd);
16
13
  };
17
-
18
14
  exports.hasRwd = hasRwd;
19
-
20
15
  const hasPw = (permission, pw) => {
21
16
  const isCustom = Object.keys(permission).length > 1; // "name" key is always present
22
17
 
@@ -24,14 +19,11 @@ const hasPw = (permission, pw) => {
24
19
  // Means it's a "full-access" permission.
25
20
  return true;
26
21
  }
27
-
28
22
  if (typeof permission.pw !== "string") {
29
23
  return false;
30
24
  }
31
-
32
25
  return permission.pw.includes(pw);
33
26
  };
34
-
35
27
  exports.hasPw = hasPw;
36
28
  const PW = {
37
29
  p: "publish",
@@ -42,24 +34,23 @@ const RWD = {
42
34
  w: "write",
43
35
  d: "delete"
44
36
  };
45
-
46
37
  const checkPermissions = async (context, name, check) => {
47
38
  // Check if user is allowed to edit content in current language
48
39
  const contentPermission = await context.security.getPermission("content.i18n");
49
-
50
40
  if (!contentPermission) {
51
41
  throw new _apiSecurity.NotAuthorizedError({
52
42
  data: {
53
43
  reason: "Missing access to content in any locale."
54
44
  }
55
45
  });
56
- } // We need to check this manually as CMS locale comes from the URL and not the default i18n app.
57
-
46
+ }
58
47
 
48
+ // We need to check this manually as CMS locale comes from the URL and not the default i18n app.
59
49
  const code = context.cms.getLocale().code;
60
- const locales = contentPermission.locales; // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.
61
- // However, if the the `locales` IS SET - check that it contains the required locale.
50
+ const locales = contentPermission.locales;
62
51
 
52
+ // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.
53
+ // However, if the the `locales` IS SET - check that it contains the required locale.
63
54
  if (Array.isArray(locales) && !locales.includes(code)) {
64
55
  throw new _apiSecurity.NotAuthorizedError({
65
56
  data: {
@@ -67,9 +58,7 @@ const checkPermissions = async (context, name, check) => {
67
58
  }
68
59
  });
69
60
  }
70
-
71
61
  const permission = await context.security.getPermission(name);
72
-
73
62
  if (!permission) {
74
63
  throw new _apiSecurity.NotAuthorizedError({
75
64
  data: {
@@ -77,21 +66,19 @@ const checkPermissions = async (context, name, check) => {
77
66
  }
78
67
  });
79
68
  }
80
-
81
69
  if (!check) {
82
70
  return permission;
83
71
  }
84
-
85
72
  if (check.rwd && !hasRwd(permission, check.rwd)) {
86
73
  throw new _apiSecurity.NotAuthorizedError({
87
74
  data: {
88
75
  reason: `Not allowed to perform "${RWD[check.rwd]}" on "${name}".`
89
76
  }
90
77
  });
91
- } // p = publish
92
- // u = unpublish
93
-
78
+ }
94
79
 
80
+ // p = publish
81
+ // u = unpublish
95
82
  if (check.pw && !hasPw(permission, check.pw)) {
96
83
  throw new _apiSecurity.NotAuthorizedError({
97
84
  data: {
@@ -99,8 +86,6 @@ const checkPermissions = async (context, name, check) => {
99
86
  }
100
87
  });
101
88
  }
102
-
103
89
  return permission;
104
90
  };
105
-
106
91
  exports.checkPermissions = checkPermissions;