@webiny/api-headless-cms 5.17.4 → 5.18.0-beta.3

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 (395) hide show
  1. package/content/contextSetup.js +1 -2
  2. package/content/graphQLHandlerFactory.d.ts +1 -2
  3. package/content/graphQLHandlerFactory.js +12 -4
  4. package/content/plugins/CmsGroupPlugin.d.ts +11 -0
  5. package/content/plugins/{ContentModelGroupPlugin.js → CmsGroupPlugin.js} +4 -5
  6. package/content/plugins/CmsModelPlugin.d.ts +11 -0
  7. package/content/plugins/{ContentModelPlugin.js → CmsModelPlugin.js} +4 -5
  8. package/content/plugins/buildSchemaPlugins.js +1 -2
  9. package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
  10. package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
  11. package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
  12. package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
  13. package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +2 -2
  14. package/content/plugins/crud/contentEntry/entryDataValidation.js +1 -2
  15. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +3 -3
  16. package/content/plugins/crud/contentEntry/markLockedFields.js +10 -7
  17. package/content/plugins/crud/contentEntry.crud.d.ts +12 -4
  18. package/content/plugins/crud/contentEntry.crud.js +807 -757
  19. package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
  20. package/content/plugins/crud/contentModel/afterCreate.js +18 -0
  21. package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
  22. package/content/plugins/crud/contentModel/afterDelete.js +18 -0
  23. package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
  24. package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
  25. package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
  26. package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
  27. package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
  28. package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
  29. package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
  30. package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
  31. package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -2
  32. package/content/plugins/crud/contentModel/contentModelManagerFactory.js +2 -3
  33. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -2
  34. package/content/plugins/crud/contentModel/createFieldModels.js +2 -3
  35. package/content/plugins/crud/contentModel/idValidation.js +1 -2
  36. package/content/plugins/crud/contentModel/models.js +1 -2
  37. package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -2
  38. package/content/plugins/crud/contentModel/validateLayout.js +1 -2
  39. package/content/plugins/crud/contentModel.crud.d.ts +12 -4
  40. package/content/plugins/crud/contentModel.crud.js +351 -279
  41. package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
  42. package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
  43. package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
  44. package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
  45. package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
  46. package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
  47. package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -4
  48. package/content/plugins/crud/contentModelGroup.crud.js +259 -219
  49. package/content/plugins/crud/index.d.ts +6 -0
  50. package/content/plugins/crud/index.js +96 -0
  51. package/content/plugins/graphqlFields/boolean.js +1 -2
  52. package/content/plugins/graphqlFields/datetime.js +1 -2
  53. package/content/plugins/graphqlFields/file.js +1 -2
  54. package/content/plugins/graphqlFields/index.js +1 -2
  55. package/content/plugins/graphqlFields/longText.js +1 -2
  56. package/content/plugins/graphqlFields/number.js +1 -2
  57. package/content/plugins/graphqlFields/object.js +1 -2
  58. package/content/plugins/graphqlFields/ref.js +22 -11
  59. package/content/plugins/graphqlFields/richText.js +1 -2
  60. package/content/plugins/graphqlFields/text.js +1 -2
  61. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +2 -3
  62. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +1 -2
  63. package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
  64. package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
  65. package/content/plugins/modelManager/index.d.ts +2 -2
  66. package/content/plugins/modelManager/index.js +3 -4
  67. package/content/plugins/schema/baseSchema.js +1 -2
  68. package/content/plugins/schema/contentEntries.js +9 -10
  69. package/content/plugins/schema/contentModelGroups.js +13 -14
  70. package/content/plugins/schema/contentModels.js +9 -10
  71. package/content/plugins/schema/createFieldResolvers.d.ts +2 -2
  72. package/content/plugins/schema/createFieldResolvers.js +14 -20
  73. package/content/plugins/schema/createManageResolvers.d.ts +3 -3
  74. package/content/plugins/schema/createManageResolvers.js +6 -10
  75. package/content/plugins/schema/createManageSDL.d.ts +2 -2
  76. package/content/plugins/schema/createManageSDL.js +5 -6
  77. package/content/plugins/schema/createPreviewResolvers.d.ts +3 -3
  78. package/content/plugins/schema/createPreviewResolvers.js +5 -6
  79. package/content/plugins/schema/createReadResolvers.d.ts +3 -3
  80. package/content/plugins/schema/createReadResolvers.js +5 -6
  81. package/content/plugins/schema/createReadSDL.d.ts +2 -2
  82. package/content/plugins/schema/createReadSDL.js +3 -4
  83. package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +4 -4
  84. package/content/plugins/schema/resolvers/commonFieldResolvers.js +1 -2
  85. package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +1 -1
  86. package/content/plugins/schema/resolvers/manage/resolveCreate.js +3 -4
  87. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +1 -1
  88. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +3 -4
  89. package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +1 -1
  90. package/content/plugins/schema/resolvers/manage/resolveDelete.js +4 -5
  91. package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +1 -1
  92. package/content/plugins/schema/resolvers/manage/resolveGet.js +3 -4
  93. package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +1 -1
  94. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +3 -4
  95. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +1 -1
  96. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +3 -4
  97. package/content/plugins/schema/resolvers/manage/resolveList.d.ts +1 -1
  98. package/content/plugins/schema/resolvers/manage/resolveList.js +3 -4
  99. package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +1 -1
  100. package/content/plugins/schema/resolvers/manage/resolvePublish.js +3 -4
  101. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +1 -1
  102. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +3 -4
  103. package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +1 -1
  104. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +3 -4
  105. package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +1 -1
  106. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +3 -4
  107. package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +1 -1
  108. package/content/plugins/schema/resolvers/manage/resolveUpdate.js +3 -4
  109. package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +1 -1
  110. package/content/plugins/schema/resolvers/preview/resolveGet.js +3 -4
  111. package/content/plugins/schema/resolvers/preview/resolveList.d.ts +1 -1
  112. package/content/plugins/schema/resolvers/preview/resolveList.js +3 -4
  113. package/content/plugins/schema/resolvers/read/resolveGet.d.ts +1 -1
  114. package/content/plugins/schema/resolvers/read/resolveGet.js +3 -4
  115. package/content/plugins/schema/resolvers/read/resolveList.d.ts +1 -1
  116. package/content/plugins/schema/resolvers/read/resolveList.js +3 -4
  117. package/content/plugins/schema/schemaPlugins.js +4 -3
  118. package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
  119. package/content/plugins/storage/StorageTransformPlugin.js +36 -0
  120. package/content/plugins/storage/default.d.ts +2 -2
  121. package/content/plugins/storage/default.js +12 -12
  122. package/content/plugins/storage/object.d.ts +2 -2
  123. package/content/plugins/storage/object.js +28 -29
  124. package/content/plugins/utils/createTypeName.js +1 -2
  125. package/content/plugins/utils/entryStorage.d.ts +5 -5
  126. package/content/plugins/utils/entryStorage.js +21 -14
  127. package/content/plugins/utils/getEntryTitle.d.ts +2 -2
  128. package/content/plugins/utils/getEntryTitle.js +1 -2
  129. package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +2 -2
  130. package/content/plugins/utils/getSchemaFromFieldPlugins.js +1 -2
  131. package/content/plugins/utils/pluralizedTypeName.js +1 -2
  132. package/content/plugins/utils/renderFields.d.ts +2 -2
  133. package/content/plugins/utils/renderFields.js +1 -2
  134. package/content/plugins/utils/renderGetFilterFields.d.ts +2 -2
  135. package/content/plugins/utils/renderGetFilterFields.js +1 -2
  136. package/content/plugins/utils/renderInputFields.d.ts +2 -2
  137. package/content/plugins/utils/renderInputFields.js +1 -2
  138. package/content/plugins/utils/renderListFilterFields.d.ts +2 -2
  139. package/content/plugins/utils/renderListFilterFields.js +1 -2
  140. package/content/plugins/utils/renderSortEnum.d.ts +2 -2
  141. package/content/plugins/utils/renderSortEnum.js +1 -2
  142. package/content/plugins/validators/dateGte.js +1 -2
  143. package/content/plugins/validators/dateLte.js +1 -2
  144. package/content/plugins/validators/gte.js +1 -2
  145. package/content/plugins/validators/in.js +1 -2
  146. package/content/plugins/validators/index.js +1 -2
  147. package/content/plugins/validators/lte.js +1 -2
  148. package/content/plugins/validators/maxLength.js +1 -2
  149. package/content/plugins/validators/minLength.js +1 -2
  150. package/content/plugins/validators/pattern.js +1 -2
  151. package/content/plugins/validators/patternPlugins/email.js +1 -2
  152. package/content/plugins/validators/patternPlugins/index.js +1 -2
  153. package/content/plugins/validators/patternPlugins/lowerCase.js +1 -2
  154. package/content/plugins/validators/patternPlugins/upperCase.js +1 -2
  155. package/content/plugins/validators/patternPlugins/url.js +1 -2
  156. package/content/plugins/validators/required.js +1 -2
  157. package/content/plugins/validators/timeGte.js +1 -2
  158. package/content/plugins/validators/timeLte.js +1 -2
  159. package/index.d.ts +12 -0
  160. package/index.js +66 -0
  161. package/migrateCMSPermissions.d.ts +2 -2
  162. package/migrateCMSPermissions.js +1 -2
  163. package/package.json +23 -21
  164. package/plugins/context.js +1 -2
  165. package/plugins/crud/index.d.ts +6 -2
  166. package/plugins/crud/index.js +69 -6
  167. package/plugins/crud/settings.crud.d.ts +10 -4
  168. package/plugins/crud/settings.crud.js +64 -77
  169. package/plugins/crud/system.crud.d.ts +10 -4
  170. package/plugins/crud/system.crud.js +139 -126
  171. package/plugins/graphql/system.js +5 -6
  172. package/plugins/graphql.d.ts +1 -2
  173. package/plugins/graphql.js +49 -50
  174. package/plugins/upgrades/index.js +1 -2
  175. package/plugins/upgrades/v5.5.0/helpers.js +1 -2
  176. package/plugins/upgrades/v5.5.0/index.js +3 -4
  177. package/transformers.js +1 -2
  178. package/types.d.ts +742 -1232
  179. package/types.js +104 -254
  180. package/utils.d.ts +4 -11
  181. package/utils.js +2 -49
  182. package/content/contextSetup.js.map +0 -1
  183. package/content/graphQLHandlerFactory.js.map +0 -1
  184. package/content/index.d.ts +0 -5
  185. package/content/index.js +0 -37
  186. package/content/index.js.map +0 -1
  187. package/content/plugins/ContentModelGroupPlugin.d.ts +0 -7
  188. package/content/plugins/ContentModelGroupPlugin.js.map +0 -1
  189. package/content/plugins/ContentModelPlugin.d.ts +0 -7
  190. package/content/plugins/ContentModelPlugin.js.map +0 -1
  191. package/content/plugins/buildSchemaPlugins.js.map +0 -1
  192. package/content/plugins/crud/contentEntry/afterCreate.hook.d.ts +0 -2
  193. package/content/plugins/crud/contentEntry/afterCreate.hook.js +0 -15
  194. package/content/plugins/crud/contentEntry/afterCreate.hook.js.map +0 -1
  195. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.d.ts +0 -2
  196. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.js +0 -15
  197. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.js.map +0 -1
  198. package/content/plugins/crud/contentEntry/afterDelete.hook.d.ts +0 -2
  199. package/content/plugins/crud/contentEntry/afterDelete.hook.js +0 -15
  200. package/content/plugins/crud/contentEntry/afterDelete.hook.js.map +0 -1
  201. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.d.ts +0 -2
  202. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.js +0 -15
  203. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.js.map +0 -1
  204. package/content/plugins/crud/contentEntry/afterPublish.hook.d.ts +0 -2
  205. package/content/plugins/crud/contentEntry/afterPublish.hook.js +0 -15
  206. package/content/plugins/crud/contentEntry/afterPublish.hook.js.map +0 -1
  207. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.d.ts +0 -2
  208. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.js +0 -15
  209. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.js.map +0 -1
  210. package/content/plugins/crud/contentEntry/afterRequestReview.hook.d.ts +0 -2
  211. package/content/plugins/crud/contentEntry/afterRequestReview.hook.js +0 -15
  212. package/content/plugins/crud/contentEntry/afterRequestReview.hook.js.map +0 -1
  213. package/content/plugins/crud/contentEntry/afterUnpublish.hook.d.ts +0 -2
  214. package/content/plugins/crud/contentEntry/afterUnpublish.hook.js +0 -15
  215. package/content/plugins/crud/contentEntry/afterUnpublish.hook.js.map +0 -1
  216. package/content/plugins/crud/contentEntry/afterUpdate.hook.d.ts +0 -2
  217. package/content/plugins/crud/contentEntry/afterUpdate.hook.js +0 -15
  218. package/content/plugins/crud/contentEntry/afterUpdate.hook.js.map +0 -1
  219. package/content/plugins/crud/contentEntry/beforeCreate.hook.d.ts +0 -2
  220. package/content/plugins/crud/contentEntry/beforeCreate.hook.js +0 -18
  221. package/content/plugins/crud/contentEntry/beforeCreate.hook.js.map +0 -1
  222. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.d.ts +0 -2
  223. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.js +0 -15
  224. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.js.map +0 -1
  225. package/content/plugins/crud/contentEntry/beforeDelete.hook.d.ts +0 -2
  226. package/content/plugins/crud/contentEntry/beforeDelete.hook.js +0 -15
  227. package/content/plugins/crud/contentEntry/beforeDelete.hook.js.map +0 -1
  228. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.d.ts +0 -2
  229. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.js +0 -15
  230. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.js.map +0 -1
  231. package/content/plugins/crud/contentEntry/beforePublish.hook.d.ts +0 -2
  232. package/content/plugins/crud/contentEntry/beforePublish.hook.js +0 -15
  233. package/content/plugins/crud/contentEntry/beforePublish.hook.js.map +0 -1
  234. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.d.ts +0 -2
  235. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.js +0 -15
  236. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.js.map +0 -1
  237. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.d.ts +0 -2
  238. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.js +0 -15
  239. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.js.map +0 -1
  240. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.d.ts +0 -2
  241. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.js +0 -15
  242. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.js.map +0 -1
  243. package/content/plugins/crud/contentEntry/beforeUpdate.hook.d.ts +0 -2
  244. package/content/plugins/crud/contentEntry/beforeUpdate.hook.js +0 -18
  245. package/content/plugins/crud/contentEntry/beforeUpdate.hook.js.map +0 -1
  246. package/content/plugins/crud/contentEntry/entryDataValidation.js.map +0 -1
  247. package/content/plugins/crud/contentEntry/hooks.d.ts +0 -18
  248. package/content/plugins/crud/contentEntry/hooks.js +0 -240
  249. package/content/plugins/crud/contentEntry/hooks.js.map +0 -1
  250. package/content/plugins/crud/contentEntry/markLockedFields.js.map +0 -1
  251. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.d.ts +0 -4
  252. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.js +0 -24
  253. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.js.map +0 -1
  254. package/content/plugins/crud/contentEntry.crud.js.map +0 -1
  255. package/content/plugins/crud/contentModel/afterCreate.hook.d.ts +0 -7
  256. package/content/plugins/crud/contentModel/afterCreate.hook.js +0 -24
  257. package/content/plugins/crud/contentModel/afterCreate.hook.js.map +0 -1
  258. package/content/plugins/crud/contentModel/afterDelete.hook.d.ts +0 -7
  259. package/content/plugins/crud/contentModel/afterDelete.hook.js +0 -24
  260. package/content/plugins/crud/contentModel/afterDelete.hook.js.map +0 -1
  261. package/content/plugins/crud/contentModel/afterUpdate.hook.d.ts +0 -7
  262. package/content/plugins/crud/contentModel/afterUpdate.hook.js +0 -24
  263. package/content/plugins/crud/contentModel/afterUpdate.hook.js.map +0 -1
  264. package/content/plugins/crud/contentModel/beforeCreate.hook.d.ts +0 -7
  265. package/content/plugins/crud/contentModel/beforeCreate.hook.js +0 -137
  266. package/content/plugins/crud/contentModel/beforeCreate.hook.js.map +0 -1
  267. package/content/plugins/crud/contentModel/beforeDelete.hook.d.ts +0 -7
  268. package/content/plugins/crud/contentModel/beforeDelete.hook.js +0 -58
  269. package/content/plugins/crud/contentModel/beforeDelete.hook.js.map +0 -1
  270. package/content/plugins/crud/contentModel/beforeUpdate.hook.d.ts +0 -7
  271. package/content/plugins/crud/contentModel/beforeUpdate.hook.js +0 -141
  272. package/content/plugins/crud/contentModel/beforeUpdate.hook.js.map +0 -1
  273. package/content/plugins/crud/contentModel/contentModelManagerFactory.js.map +0 -1
  274. package/content/plugins/crud/contentModel/createFieldModels.js.map +0 -1
  275. package/content/plugins/crud/contentModel/hooks.d.ts +0 -6
  276. package/content/plugins/crud/contentModel/hooks.js +0 -84
  277. package/content/plugins/crud/contentModel/hooks.js.map +0 -1
  278. package/content/plugins/crud/contentModel/idValidation.js.map +0 -1
  279. package/content/plugins/crud/contentModel/models.js.map +0 -1
  280. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.d.ts +0 -2
  281. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.js +0 -24
  282. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.js.map +0 -1
  283. package/content/plugins/crud/contentModel/validateLayout.js.map +0 -1
  284. package/content/plugins/crud/contentModel.crud.js.map +0 -1
  285. package/content/plugins/crud/contentModelGroup/afterCreate.hook.d.ts +0 -7
  286. package/content/plugins/crud/contentModelGroup/afterCreate.hook.js +0 -24
  287. package/content/plugins/crud/contentModelGroup/afterCreate.hook.js.map +0 -1
  288. package/content/plugins/crud/contentModelGroup/afterDelete.hook.d.ts +0 -8
  289. package/content/plugins/crud/contentModelGroup/afterDelete.hook.js +0 -22
  290. package/content/plugins/crud/contentModelGroup/afterDelete.hook.js.map +0 -1
  291. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.d.ts +0 -7
  292. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.js +0 -26
  293. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.js.map +0 -1
  294. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.d.ts +0 -7
  295. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.js +0 -87
  296. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.js.map +0 -1
  297. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.d.ts +0 -7
  298. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.js +0 -46
  299. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.js.map +0 -1
  300. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.d.ts +0 -7
  301. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.js +0 -35
  302. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.js.map +0 -1
  303. package/content/plugins/crud/contentModelGroup.crud.js.map +0 -1
  304. package/content/plugins/graphqlFields/boolean.js.map +0 -1
  305. package/content/plugins/graphqlFields/datetime.js.map +0 -1
  306. package/content/plugins/graphqlFields/file.js.map +0 -1
  307. package/content/plugins/graphqlFields/index.js.map +0 -1
  308. package/content/plugins/graphqlFields/longText.js.map +0 -1
  309. package/content/plugins/graphqlFields/number.js.map +0 -1
  310. package/content/plugins/graphqlFields/object.js.map +0 -1
  311. package/content/plugins/graphqlFields/ref.js.map +0 -1
  312. package/content/plugins/graphqlFields/richText.js.map +0 -1
  313. package/content/plugins/graphqlFields/text.js.map +0 -1
  314. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js.map +0 -1
  315. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js.map +0 -1
  316. package/content/plugins/modelManager/DefaultContentModelManager.d.ts +0 -15
  317. package/content/plugins/modelManager/DefaultContentModelManager.js +0 -63
  318. package/content/plugins/modelManager/DefaultContentModelManager.js.map +0 -1
  319. package/content/plugins/modelManager/index.js.map +0 -1
  320. package/content/plugins/schema/baseSchema.js.map +0 -1
  321. package/content/plugins/schema/contentEntries.js.map +0 -1
  322. package/content/plugins/schema/contentModelGroups.js.map +0 -1
  323. package/content/plugins/schema/contentModels.js.map +0 -1
  324. package/content/plugins/schema/createFieldResolvers.js.map +0 -1
  325. package/content/plugins/schema/createManageResolvers.js.map +0 -1
  326. package/content/plugins/schema/createManageSDL.js.map +0 -1
  327. package/content/plugins/schema/createPreviewResolvers.js.map +0 -1
  328. package/content/plugins/schema/createReadResolvers.js.map +0 -1
  329. package/content/plugins/schema/createReadSDL.js.map +0 -1
  330. package/content/plugins/schema/resolvers/commonFieldResolvers.js.map +0 -1
  331. package/content/plugins/schema/resolvers/manage/resolveCreate.js.map +0 -1
  332. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js.map +0 -1
  333. package/content/plugins/schema/resolvers/manage/resolveDelete.js.map +0 -1
  334. package/content/plugins/schema/resolvers/manage/resolveGet.js.map +0 -1
  335. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js.map +0 -1
  336. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js.map +0 -1
  337. package/content/plugins/schema/resolvers/manage/resolveList.js.map +0 -1
  338. package/content/plugins/schema/resolvers/manage/resolvePublish.js.map +0 -1
  339. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  340. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  341. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js.map +0 -1
  342. package/content/plugins/schema/resolvers/manage/resolveUpdate.js.map +0 -1
  343. package/content/plugins/schema/resolvers/preview/resolveGet.js.map +0 -1
  344. package/content/plugins/schema/resolvers/preview/resolveList.js.map +0 -1
  345. package/content/plugins/schema/resolvers/read/resolveGet.js.map +0 -1
  346. package/content/plugins/schema/resolvers/read/resolveList.js.map +0 -1
  347. package/content/plugins/schema/schemaPlugins.js.map +0 -1
  348. package/content/plugins/storage/default.js.map +0 -1
  349. package/content/plugins/storage/object.js.map +0 -1
  350. package/content/plugins/utils/createTypeName.js.map +0 -1
  351. package/content/plugins/utils/entryStorage.js.map +0 -1
  352. package/content/plugins/utils/getEntryTitle.js.map +0 -1
  353. package/content/plugins/utils/getSchemaFromFieldPlugins.js.map +0 -1
  354. package/content/plugins/utils/pluralizedTypeName.js.map +0 -1
  355. package/content/plugins/utils/renderFields.js.map +0 -1
  356. package/content/plugins/utils/renderGetFilterFields.js.map +0 -1
  357. package/content/plugins/utils/renderInputFields.js.map +0 -1
  358. package/content/plugins/utils/renderListFilterFields.js.map +0 -1
  359. package/content/plugins/utils/renderSortEnum.js.map +0 -1
  360. package/content/plugins/validators/dateGte.js.map +0 -1
  361. package/content/plugins/validators/dateLte.js.map +0 -1
  362. package/content/plugins/validators/gte.js.map +0 -1
  363. package/content/plugins/validators/in.js.map +0 -1
  364. package/content/plugins/validators/index.js.map +0 -1
  365. package/content/plugins/validators/lte.js.map +0 -1
  366. package/content/plugins/validators/maxLength.js.map +0 -1
  367. package/content/plugins/validators/minLength.js.map +0 -1
  368. package/content/plugins/validators/pattern.js.map +0 -1
  369. package/content/plugins/validators/patternPlugins/email.js.map +0 -1
  370. package/content/plugins/validators/patternPlugins/index.js.map +0 -1
  371. package/content/plugins/validators/patternPlugins/lowerCase.js.map +0 -1
  372. package/content/plugins/validators/patternPlugins/upperCase.js.map +0 -1
  373. package/content/plugins/validators/patternPlugins/url.js.map +0 -1
  374. package/content/plugins/validators/required.js.map +0 -1
  375. package/content/plugins/validators/timeGte.js.map +0 -1
  376. package/content/plugins/validators/timeLte.js.map +0 -1
  377. package/migrateCMSPermissions.js.map +0 -1
  378. package/plugins/InstallationPlugin.d.ts +0 -19
  379. package/plugins/InstallationPlugin.js +0 -39
  380. package/plugins/InstallationPlugin.js.map +0 -1
  381. package/plugins/context.js.map +0 -1
  382. package/plugins/crud/index.js.map +0 -1
  383. package/plugins/crud/settings.crud.js.map +0 -1
  384. package/plugins/crud/system.crud.js.map +0 -1
  385. package/plugins/graphql/system.js.map +0 -1
  386. package/plugins/graphql.js.map +0 -1
  387. package/plugins/index.d.ts +0 -2
  388. package/plugins/index.js +0 -25
  389. package/plugins/index.js.map +0 -1
  390. package/plugins/upgrades/index.js.map +0 -1
  391. package/plugins/upgrades/v5.5.0/helpers.js.map +0 -1
  392. package/plugins/upgrades/v5.5.0/index.js.map +0 -1
  393. package/transformers.js.map +0 -1
  394. package/types.js.map +0 -1
  395. package/utils.js.map +0 -1
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.STATUS_UNPUBLISHED = exports.STATUS_REVIEW_REQUESTED = exports.STATUS_PUBLISHED = exports.STATUS_DRAFT = exports.STATUS_CHANGES_REQUESTED = void 0;
8
+ exports.createContentEntryCrud = exports.STATUS_UNPUBLISHED = exports.STATUS_REVIEW_REQUESTED = exports.STATUS_PUBLISHED = exports.STATUS_DRAFT = exports.STATUS_CHANGES_REQUESTED = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -17,10 +17,16 @@ var utils = _interopRequireWildcard(require("../../../utils"));
17
17
 
18
18
  var _entryDataValidation = require("./contentEntry/entryDataValidation");
19
19
 
20
- var _hooks = require("./contentEntry/hooks");
21
-
22
20
  var _error = _interopRequireDefault(require("@webiny/error"));
23
21
 
22
+ var _pubsub = require("@webiny/pubsub");
23
+
24
+ var _beforeCreate = require("./contentEntry/beforeCreate");
25
+
26
+ var _beforeUpdate = require("./contentEntry/beforeUpdate");
27
+
28
+ var _utils2 = require("@webiny/utils");
29
+
24
30
  var _entryStorage = require("../utils/entryStorage");
25
31
 
26
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -65,7 +71,10 @@ const createEntryId = version => {
65
71
  return {
66
72
  entryId,
67
73
  version,
68
- id: `${entryId}#${utils.zeroPad(version)}`
74
+ id: (0, _utils2.createIdentifier)({
75
+ id: entryId,
76
+ version
77
+ })
69
78
  };
70
79
  };
71
80
 
@@ -81,829 +90,870 @@ const increaseEntryIdVersion = id => {
81
90
  return {
82
91
  entryId,
83
92
  version: ver,
84
- id: `${entryId}#${utils.zeroPad(ver)}`
93
+ id: (0, _utils2.createIdentifier)({
94
+ id: entryId,
95
+ version: ver
96
+ })
85
97
  };
86
98
  };
87
99
 
88
- var _default = () => ({
89
- type: "context",
90
- name: "context-content-model-entry",
100
+ const createContentEntryCrud = params => {
101
+ const {
102
+ storageOperations,
103
+ context,
104
+ getTenant,
105
+ getLocale,
106
+ getIdentity
107
+ } = params;
108
+ const onBeforeCreate = (0, _pubsub.createTopic)();
109
+ const onAfterCreate = (0, _pubsub.createTopic)();
110
+ const onBeforeCreateRevision = (0, _pubsub.createTopic)();
111
+ const onAfterCreateRevision = (0, _pubsub.createTopic)();
112
+ const onBeforeUpdate = (0, _pubsub.createTopic)();
113
+ const onAfterUpdate = (0, _pubsub.createTopic)();
114
+ const onBeforePublish = (0, _pubsub.createTopic)();
115
+ const onAfterPublish = (0, _pubsub.createTopic)();
116
+ const onBeforeUnpublish = (0, _pubsub.createTopic)();
117
+ const onAfterUnpublish = (0, _pubsub.createTopic)();
118
+ const onBeforeRequestChanges = (0, _pubsub.createTopic)();
119
+ const onAfterRequestChanges = (0, _pubsub.createTopic)();
120
+ const onBeforeRequestReview = (0, _pubsub.createTopic)();
121
+ const onAfterRequestReview = (0, _pubsub.createTopic)();
122
+ const onBeforeDelete = (0, _pubsub.createTopic)();
123
+ const onAfterDelete = (0, _pubsub.createTopic)();
124
+ const onBeforeDeleteRevision = (0, _pubsub.createTopic)();
125
+ const onAfterDeleteRevision = (0, _pubsub.createTopic)();
126
+ const onBeforeGet = (0, _pubsub.createTopic)();
127
+ const onBeforeList = (0, _pubsub.createTopic)();
128
+ /**
129
+ * We need to assign some default behaviors.
130
+ */
131
+
132
+ (0, _beforeCreate.assignBeforeEntryCreate)({
133
+ context,
134
+ onBeforeCreate
135
+ });
136
+ (0, _beforeUpdate.assignBeforeEntryUpdate)({
137
+ context,
138
+ onBeforeUpdate
139
+ });
140
+
141
+ const checkEntryPermissions = check => {
142
+ return utils.checkPermissions(context, "cms.contentEntry", check);
143
+ };
144
+ /**
145
+ * A helper to delete the entire entry.
146
+ */
147
+
148
+
149
+ const deleteEntry = async params => {
150
+ const {
151
+ model,
152
+ entry,
153
+ storageEntry
154
+ } = params;
155
+
156
+ try {
157
+ await onBeforeDelete.publish({
158
+ entry,
159
+ model
160
+ });
161
+ await storageOperations.entries.delete(model, {
162
+ entry,
163
+ storageEntry
164
+ });
165
+ await onAfterDelete.publish({
166
+ entry,
167
+ model
168
+ });
169
+ } catch (ex) {
170
+ throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
171
+ entry
172
+ });
173
+ }
174
+ };
175
+ /**
176
+ * A helper to get entries by revision IDs
177
+ */
178
+
179
+
180
+ const getEntriesByIds = async (model, ids) => {
181
+ const permission = await checkEntryPermissions({
182
+ rwd: "r"
183
+ });
184
+ await utils.checkModelAccess(context, model);
185
+ const entries = await storageOperations.entries.getByIds(model, {
186
+ tenant: getTenant().id,
187
+ locale: getLocale().code,
188
+ ids
189
+ });
190
+ return entries.filter(entry => utils.validateOwnership(context, permission, entry));
191
+ };
192
+
193
+ return {
194
+ onBeforeEntryCreate: onBeforeCreate,
195
+ onAfterEntryCreate: onAfterCreate,
196
+ onBeforeEntryRevisionCreate: onBeforeCreateRevision,
197
+ onAfterEntryRevisionCreate: onAfterCreateRevision,
198
+ onBeforeEntryUpdate: onBeforeUpdate,
199
+ onAfterEntryUpdate: onAfterUpdate,
200
+ onBeforeEntryDelete: onBeforeDelete,
201
+ onAfterEntryDelete: onAfterDelete,
202
+ onBeforeEntryRevisionDelete: onBeforeDeleteRevision,
203
+ onAfterEntryRevisionDelete: onAfterDeleteRevision,
204
+ onBeforeEntryPublish: onBeforePublish,
205
+ onAfterEntryPublish: onAfterPublish,
206
+ onBeforeEntryUnpublish: onBeforeUnpublish,
207
+ onAfterEntryUnpublish: onAfterUnpublish,
208
+ onBeforeEntryRequestChanges: onBeforeRequestChanges,
209
+ onAfterEntryRequestChanges: onAfterRequestChanges,
210
+ onBeforeEntryRequestReview: onBeforeRequestReview,
211
+ onAfterEntryRequestReview: onAfterRequestReview,
212
+ onBeforeEntryGet: onBeforeGet,
213
+ onBeforeEntryList: onBeforeList,
91
214
 
92
- async apply(context) {
93
215
  /**
94
- * If cms is not defined on the context, do not continue, but log it.
216
+ * Get entries by exact revision IDs from the database.
95
217
  */
96
- if (!context.cms) {
97
- return;
98
- }
218
+ getEntriesByIds: getEntriesByIds,
99
219
 
100
- const pluginType = "cms-content-entry-storage-operations-provider";
101
- const providerPlugins = context.plugins.byType(pluginType);
102
220
  /**
103
- * Storage operations for the content entry.
104
- * Contains logic to save the data into the specific storage.
221
+ * Get a single entry by revision ID from the database.
105
222
  */
223
+ getEntryById: async (model, id) => {
224
+ const where = {
225
+ id
226
+ };
227
+ await onBeforeGet.publish({
228
+ where,
229
+ model
230
+ });
231
+ const [entry] = await getEntriesByIds(model, [where.id]);
106
232
 
107
- const providerPlugin = providerPlugins[providerPlugins.length - 1];
233
+ if (!entry) {
234
+ throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
235
+ }
108
236
 
109
- if (!providerPlugin) {
110
- throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
111
- type: pluginType
112
- });
113
- }
237
+ return entry;
238
+ },
114
239
 
115
- const storageOperations = await providerPlugin.provide({
116
- context
117
- });
240
+ /**
241
+ * Get published revisions by entry IDs.
242
+ */
243
+ getPublishedEntriesByIds: async (model, ids) => {
244
+ const permission = await checkEntryPermissions({
245
+ rwd: "r"
246
+ });
247
+ await utils.checkModelAccess(context, model);
248
+ const entries = await storageOperations.entries.getPublishedByIds(model, {
249
+ tenant: getTenant().id,
250
+ locale: getLocale().code,
251
+ ids
252
+ });
253
+ return entries.filter(entry => utils.validateOwnership(context, permission, entry));
254
+ },
118
255
 
119
- const checkEntryPermissions = check => {
120
- return utils.checkPermissions(context, "cms.contentEntry", check);
121
- };
122
256
  /**
123
- * A helper to delete the entire entry.
257
+ * Get latest revisions by entry IDs.
124
258
  */
259
+ getLatestEntriesByIds: async (model, ids) => {
260
+ const permission = await checkEntryPermissions({
261
+ rwd: "r"
262
+ });
263
+ await utils.checkModelAccess(context, model);
264
+ const entries = await storageOperations.entries.getLatestByIds(model, {
265
+ tenant: getTenant().id,
266
+ locale: getLocale().code,
267
+ ids
268
+ });
269
+ return entries.filter(entry => utils.validateOwnership(context, permission, entry));
270
+ },
271
+ getEntryRevisions: async (model, entryId) => {
272
+ return storageOperations.entries.getRevisions(model, {
273
+ tenant: getTenant().id,
274
+ locale: getLocale().code,
275
+ id: entryId
276
+ });
277
+ },
278
+ getEntry: async (model, params) => {
279
+ await checkEntryPermissions({
280
+ rwd: "r"
281
+ });
282
+ const {
283
+ where,
284
+ sort
285
+ } = params;
286
+ await onBeforeGet.publish({
287
+ where,
288
+ model
289
+ });
290
+ const [items] = await context.cms.listEntries(model, {
291
+ where,
292
+ sort,
293
+ limit: 1
294
+ });
125
295
 
296
+ if (items.length === 0) {
297
+ throw new _handlerGraphql.NotFoundError(`Entry not found!`);
298
+ }
126
299
 
127
- const deleteEntry = async params => {
300
+ return items[0];
301
+ },
302
+ listEntries: async (model, params) => {
303
+ const permission = await checkEntryPermissions({
304
+ rwd: "r"
305
+ });
306
+ await utils.checkModelAccess(context, model);
307
+ const where = params.where || {};
308
+ /**
309
+ * Possibly only get records which are owned by current user.
310
+ * Or if searching for the owner set that value - in the case that user can see other entries than their own.
311
+ */
312
+
313
+ const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
314
+
315
+ const listWhere = _objectSpread(_objectSpread({}, where), {}, {
316
+ tenant: where.tenant || getTenant().id,
317
+ locale: where.locale || getLocale().code
318
+ });
319
+
320
+ if (ownedBy !== undefined) {
321
+ listWhere.ownedBy = ownedBy;
322
+ }
323
+
324
+ await onBeforeList.publish({
325
+ where: listWhere,
326
+ model
327
+ });
128
328
  const {
129
- model,
130
- entry,
131
- storageEntry
132
- } = params;
329
+ hasMoreItems,
330
+ totalCount,
331
+ cursor,
332
+ items
333
+ } = await storageOperations.entries.list(model, _objectSpread(_objectSpread({}, params), {}, {
334
+ where: listWhere
335
+ }));
336
+ const meta = {
337
+ hasMoreItems,
338
+ totalCount,
339
+
340
+ /**
341
+ * Cursor should be null if there are no more items to load.
342
+ * Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
343
+ */
344
+ cursor: hasMoreItems ? cursor : null
345
+ };
346
+ return [items, meta];
347
+ },
348
+ listLatestEntries: async function (model, params) {
349
+ const where = params ? params.where : {};
350
+ return context.cms.listEntries(model, _objectSpread(_objectSpread({
351
+ sort: ["createdOn_DESC"]
352
+ }, params || {}), {}, {
353
+ where: _objectSpread(_objectSpread({}, where), {}, {
354
+ latest: true
355
+ })
356
+ }));
357
+ },
358
+ listPublishedEntries: async function (model, params) {
359
+ const where = params ? params.where : {};
360
+ return context.cms.listEntries(model, _objectSpread(_objectSpread({
361
+ sort: ["createdOn_DESC"]
362
+ }, params || {}), {}, {
363
+ where: _objectSpread(_objectSpread({}, where), {}, {
364
+ published: true
365
+ })
366
+ }));
367
+ },
368
+ createEntry: async (model, inputData) => {
369
+ await checkEntryPermissions({
370
+ rwd: "w"
371
+ });
372
+ await utils.checkModelAccess(context, model);
373
+ /**
374
+ * Make sure we only work with fields that are defined in the model.
375
+ */
376
+
377
+ const input = cleanInputData(model, inputData);
378
+ await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
379
+ const identity = context.security.getIdentity();
380
+ const locale = context.cms.getLocale();
381
+ const owner = {
382
+ id: identity.id,
383
+ displayName: identity.displayName,
384
+ type: identity.type
385
+ };
386
+ const {
387
+ id,
388
+ entryId,
389
+ version
390
+ } = createEntryId(1);
391
+ const entry = {
392
+ webinyVersion: context.WEBINY_VERSION,
393
+ tenant: context.tenancy.getCurrentTenant().id,
394
+ entryId,
395
+ id,
396
+ modelId: model.modelId,
397
+ locale: locale.code,
398
+ createdOn: new Date().toISOString(),
399
+ savedOn: new Date().toISOString(),
400
+ createdBy: owner,
401
+ ownedBy: owner,
402
+ version,
403
+ locked: false,
404
+ status: STATUS_DRAFT,
405
+ values: input
406
+ };
407
+ let storageEntry = null;
133
408
 
134
409
  try {
135
- await (0, _hooks.beforeDeleteHook)({
136
- context,
137
- model,
410
+ await onBeforeCreate.publish({
138
411
  entry,
139
- storageEntry,
140
- storageOperations
412
+ input,
413
+ model
141
414
  });
142
- await storageOperations.delete(model, {
415
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
416
+ const result = await storageOperations.entries.create(model, {
417
+ input,
143
418
  entry,
144
419
  storageEntry
145
420
  });
146
- await (0, _hooks.afterDeleteHook)({
147
- context,
148
- model,
421
+ await onAfterCreate.publish({
149
422
  entry,
150
- storageEntry,
151
- storageOperations
423
+ storageEntry: result,
424
+ model,
425
+ input
152
426
  });
427
+ return result;
153
428
  } catch (ex) {
154
- throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
155
- entry
429
+ throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
430
+ error: ex,
431
+ input,
432
+ entry,
433
+ storageEntry
156
434
  });
157
435
  }
158
- };
159
- /**
160
- * A helper to get entries by revision IDs
161
- */
436
+ },
437
+ createEntryRevisionFrom: async (model, sourceId, inputData = {}) => {
438
+ const permission = await checkEntryPermissions({
439
+ rwd: "w"
440
+ });
441
+ await utils.checkModelAccess(context, model);
442
+ /**
443
+ * Make sure we only work with fields that are defined in the model.
444
+ */
162
445
 
446
+ const input = cleanUpdatedInputData(model, inputData);
447
+ /**
448
+ * Entries are identified by a common parent ID + Revision number.
449
+ */
163
450
 
164
- const getEntriesByIds = async (model, ids) => {
451
+ const [uniqueId] = sourceId.split("#");
452
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
453
+ tenant: getTenant().id,
454
+ locale: getLocale().code,
455
+ id: sourceId
456
+ });
457
+ const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
458
+ tenant: getTenant().id,
459
+ locale: getLocale().code,
460
+ id: uniqueId
461
+ });
462
+
463
+ if (!originalStorageEntry) {
464
+ throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
465
+ }
466
+ /**
467
+ * We need to convert data from DB to its original form before using it further.
468
+ */
469
+
470
+
471
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
472
+
473
+ const values = _objectSpread(_objectSpread({}, originalEntry.values), input);
474
+
475
+ await (0, _entryDataValidation.validateModelEntryData)(context, model, values);
476
+ utils.checkOwnership(context, permission, originalEntry);
477
+ const latestEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, latestStorageEntry);
478
+ const identity = context.security.getIdentity();
479
+ const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
480
+ const {
481
+ id,
482
+ version: nextVersion
483
+ } = increaseEntryIdVersion(latestId);
484
+
485
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
486
+ id,
487
+ version: nextVersion,
488
+ savedOn: new Date().toISOString(),
489
+ createdOn: new Date().toISOString(),
490
+ createdBy: {
491
+ id: identity.id,
492
+ displayName: identity.displayName,
493
+ type: identity.type
494
+ },
495
+ locked: false,
496
+ publishedOn: null,
497
+ status: STATUS_DRAFT,
498
+ values
499
+ });
500
+
501
+ let storageEntry = undefined;
502
+
503
+ try {
504
+ await onBeforeCreateRevision.publish({
505
+ entry,
506
+ model
507
+ });
508
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
509
+ const result = await storageOperations.entries.createRevisionFrom(model, {
510
+ entry,
511
+ storageEntry,
512
+ originalEntry,
513
+ originalStorageEntry,
514
+ latestEntry,
515
+ latestStorageEntry
516
+ });
517
+ await onAfterCreateRevision.publish({
518
+ entry,
519
+ model,
520
+ storageEntry: result
521
+ });
522
+ return result;
523
+ } catch (ex) {
524
+ throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
525
+ error: ex,
526
+ entry,
527
+ storageEntry,
528
+ originalEntry,
529
+ originalStorageEntry
530
+ });
531
+ }
532
+ },
533
+ updateEntry: async (model, id, inputData) => {
165
534
  const permission = await checkEntryPermissions({
166
- rwd: "r"
535
+ rwd: "w"
167
536
  });
168
537
  await utils.checkModelAccess(context, model);
169
- const entries = await storageOperations.getByIds(model, ids);
170
- return entries.filter(entry => utils.validateOwnership(context, permission, entry));
171
- };
172
-
173
- const entries = {
174
- operations: storageOperations,
538
+ /**
539
+ * Make sure we only work with fields that are defined in the model.
540
+ */
175
541
 
542
+ const input = cleanInputData(model, inputData);
176
543
  /**
177
- * Get entries by exact revision IDs from the database.
544
+ * Validate data early. We don't want to query DB if input data is invalid.
178
545
  */
179
- getByIds: getEntriesByIds,
180
546
 
547
+ await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
181
548
  /**
182
- * Get a single entry by revision ID from the database.
549
+ * The entry we are going to update.
183
550
  */
184
- getById: async (model, id) => {
185
- const [entry] = await getEntriesByIds(model, [id]);
186
551
 
187
- if (!entry) {
188
- throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
189
- }
552
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
553
+ tenant: getTenant().id,
554
+ locale: getLocale().code,
555
+ id
556
+ });
557
+
558
+ if (!originalStorageEntry) {
559
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
560
+ }
190
561
 
191
- return entry;
192
- },
562
+ if (originalStorageEntry.locked) {
563
+ throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
564
+ }
193
565
 
566
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
567
+ utils.checkOwnership(context, permission, originalEntry);
194
568
  /**
195
- * Get latest published revisions by entry IDs.
569
+ * We always send the full entry to the hooks and storage operations update.
196
570
  */
197
- getPublishedByIds: async (model, ids) => {
198
- const permission = await checkEntryPermissions({
199
- rwd: "r"
571
+
572
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
573
+ savedOn: new Date().toISOString(),
574
+ values: _objectSpread(_objectSpread({}, originalEntry.values), input)
575
+ });
576
+
577
+ let storageEntry = undefined;
578
+
579
+ try {
580
+ await onBeforeUpdate.publish({
581
+ entry,
582
+ model,
583
+ input,
584
+ original: originalEntry
200
585
  });
201
- await utils.checkModelAccess(context, model);
202
- const entries = await storageOperations.getPublishedByIds(model, ids);
203
- return entries.filter(entry => utils.validateOwnership(context, permission, entry));
204
- },
586
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
587
+ const result = await storageOperations.entries.update(model, {
588
+ originalEntry,
589
+ originalStorageEntry,
590
+ entry,
591
+ storageEntry,
592
+ input
593
+ });
594
+ await onAfterUpdate.publish({
595
+ entry,
596
+ storageEntry: result,
597
+ model,
598
+ input,
599
+ original: originalEntry
600
+ });
601
+ return result;
602
+ } catch (ex) {
603
+ throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
604
+ error: ex,
605
+ entry,
606
+ storageEntry,
607
+ originalEntry,
608
+ input
609
+ });
610
+ }
611
+ },
612
+ deleteEntryRevision: async (model, revisionId) => {
613
+ const permission = await checkEntryPermissions({
614
+ rwd: "d"
615
+ });
616
+ await utils.checkModelAccess(context, model);
617
+ const {
618
+ id: entryId,
619
+ version
620
+ } = (0, _utils2.parseIdentifier)(revisionId);
621
+ const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
622
+ tenant: getTenant().id,
623
+ locale: getLocale().code,
624
+ id: revisionId
625
+ });
626
+ const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
627
+ tenant: getTenant().id,
628
+ locale: getLocale().code,
629
+ id: entryId
630
+ });
631
+ const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
632
+ tenant: getTenant().id,
633
+ locale: getLocale().code,
634
+ entryId,
635
+ version
636
+ });
205
637
 
638
+ if (!storageEntryToDelete) {
639
+ throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
640
+ }
641
+
642
+ utils.checkOwnership(context, permission, storageEntryToDelete);
643
+ const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
644
+ const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
206
645
  /**
207
- * Get latest revisions by entry IDs.
646
+ * If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
647
+ * At this point deleteRevision hooks are not fired.
208
648
  */
209
- getLatestByIds: async (model, ids) => {
210
- const permission = await checkEntryPermissions({
211
- rwd: "r"
212
- });
213
- await utils.checkModelAccess(context, model);
214
- const entries = await storageOperations.getLatestByIds(model, ids);
215
- return entries.filter(entry => utils.validateOwnership(context, permission, entry));
216
- },
217
- getEntryRevisions: async (model, entryId) => {
218
- return storageOperations.getRevisions(model, entryId);
219
- },
220
- get: async (model, args) => {
221
- await checkEntryPermissions({
222
- rwd: "r"
223
- });
224
- const [items] = await context.cms.entries.list(model, _objectSpread(_objectSpread({}, args), {}, {
225
- limit: 1
226
- }));
227
-
228
- if (items.length === 0) {
229
- throw new _handlerGraphql.NotFoundError(`Entry not found!`);
230
- }
231
-
232
- return items[0];
233
- },
234
- list: async (model, args) => {
235
- const permission = await checkEntryPermissions({
236
- rwd: "r"
237
- });
238
- await utils.checkModelAccess(context, model);
239
- const {
240
- where = {}
241
- } = args || {};
242
- /**
243
- * Possibly only get records which are owned by current user.
244
- * Or if searching for the owner set that value - in the case that user can see other entries than their own.
245
- */
246
649
 
247
- const ownedBy = permission.own ? context.security.getIdentity().id : where.ownedBy;
248
-
249
- const listWhere = _objectSpread({}, where);
250
-
251
- if (ownedBy !== undefined) {
252
- listWhere.ownedBy = ownedBy;
253
- }
254
-
255
- const {
256
- hasMoreItems,
257
- totalCount,
258
- cursor,
259
- items
260
- } = await storageOperations.list(model, _objectSpread(_objectSpread({}, args), {}, {
261
- where: listWhere
262
- }));
263
- const meta = {
264
- hasMoreItems,
265
- totalCount,
266
-
267
- /**
268
- * Cursor should be null if there are no more items to load.
269
- * Just make sure of that, disregarding what is returned from the storageOperations.list method.
270
- */
271
- cursor: hasMoreItems ? cursor : null
272
- };
273
- return [items, meta];
274
- },
275
- listLatest: async function (model, args = {}) {
276
- return context.cms.entries.list(model, _objectSpread(_objectSpread({
277
- sort: ["createdOn_DESC"]
278
- }, args), {}, {
279
- where: _objectSpread(_objectSpread({}, args.where || {}), {}, {
280
- latest: true
281
- })
282
- }));
283
- },
284
- listPublished: async function (model, args = {}) {
285
- return context.cms.entries.list(model, _objectSpread(_objectSpread({
286
- sort: ["createdOn_DESC"]
287
- }, args), {}, {
288
- where: _objectSpread(_objectSpread({}, args.where || {}), {}, {
289
- published: true
290
- })
291
- }));
292
- },
293
- create: async (model, inputData) => {
294
- await checkEntryPermissions({
295
- rwd: "w"
296
- });
297
- await utils.checkModelAccess(context, model);
298
- /**
299
- * Make sure we only work with fields that are defined in the model.
300
- */
650
+ if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
651
+ return await deleteEntry({
652
+ model,
653
+ entry: entryToDelete,
654
+ storageEntry: storageEntryToDelete
655
+ });
656
+ }
657
+ /**
658
+ * If targeted record is latest entry revision, set the previous one as the new latest
659
+ */
301
660
 
302
- const input = cleanInputData(model, inputData);
303
- await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
304
- const identity = context.security.getIdentity();
305
- const locale = context.cms.getLocale();
306
- const owner = {
307
- id: identity.id,
308
- displayName: identity.displayName,
309
- type: identity.type
310
- };
311
- const {
312
- id,
313
- entryId,
314
- version
315
- } = createEntryId(1);
316
- const entry = {
317
- webinyVersion: context.WEBINY_VERSION,
318
- tenant: context.tenancy.getCurrentTenant().id,
319
- entryId,
320
- id,
321
- modelId: model.modelId,
322
- locale: locale.code,
323
- createdOn: new Date().toISOString(),
324
- savedOn: new Date().toISOString(),
325
- createdBy: owner,
326
- ownedBy: owner,
327
- version,
328
- locked: false,
329
- status: STATUS_DRAFT,
330
- values: input
331
- };
332
- let storageEntry = null;
333
-
334
- try {
335
- await (0, _hooks.beforeCreateHook)({
336
- model,
337
- input,
338
- entry,
339
- context,
340
- storageOperations
341
- });
342
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
343
- const result = await storageOperations.create(model, {
344
- input,
345
- entry,
346
- storageEntry
347
- });
348
- await (0, _hooks.afterCreateHook)({
349
- model,
350
- input,
351
- entry,
352
-
353
- /**
354
- * Pass the result because storage operations might have changed something (saved date, etc...)
355
- */
356
- storageEntry: result,
357
- context,
358
- storageOperations
359
- });
360
- return result;
361
- } catch (ex) {
362
- throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
363
- error: ex,
364
- input,
365
- entry,
366
- storageEntry
367
- });
368
- }
369
- },
370
- createRevisionFrom: async (model, sourceId, inputData = {}) => {
371
- const permission = await checkEntryPermissions({
372
- rwd: "w"
373
- });
374
- await utils.checkModelAccess(context, model);
375
- /**
376
- * Make sure we only work with fields that are defined in the model.
377
- */
378
661
 
379
- const input = cleanUpdatedInputData(model, inputData);
380
- /**
381
- * Entries are identified by a common parent ID + Revision number.
382
- */
662
+ let entryToSetAsLatest = null;
663
+ let storageEntryToSetAsLatest = null;
383
664
 
384
- const [uniqueId] = sourceId.split("#");
385
- const originalStorageEntry = await storageOperations.getRevisionById(model, sourceId);
386
- const latestStorageEntry = await storageOperations.getLatestRevisionByEntryId(model, uniqueId);
665
+ if (entryToDelete.id === latestEntryRevisionId) {
666
+ entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
667
+ storageEntryToSetAsLatest = previousStorageEntry;
668
+ }
387
669
 
388
- if (!originalStorageEntry) {
389
- throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
390
- }
391
- /**
392
- * We need to convert data from DB to its original form before using it further.
393
- */
670
+ try {
671
+ await onBeforeDeleteRevision.publish({
672
+ entry: entryToDelete,
673
+ model
674
+ });
675
+ await storageOperations.entries.deleteRevision(model, {
676
+ entryToDelete,
677
+ storageEntryToDelete,
678
+ entryToSetAsLatest,
679
+ storageEntryToSetAsLatest
680
+ });
681
+ await onAfterDeleteRevision.publish({
682
+ entry: entryToDelete,
683
+ model
684
+ });
685
+ } catch (ex) {
686
+ throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
687
+ error: ex,
688
+ entryToDelete,
689
+ storageEntryToDelete,
690
+ entryToSetAsLatest,
691
+ storageEntryToSetAsLatest
692
+ });
693
+ }
694
+ },
695
+ deleteEntry: async (model, entryId) => {
696
+ const permission = await checkEntryPermissions({
697
+ rwd: "d"
698
+ });
699
+ await utils.checkModelAccess(context, model);
700
+ const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
701
+ tenant: getTenant().id,
702
+ locale: getLocale().code,
703
+ id: entryId
704
+ });
394
705
 
706
+ if (!storageEntry) {
707
+ throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
708
+ }
395
709
 
396
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
397
-
398
- const values = _objectSpread(_objectSpread({}, originalEntry.values), input);
399
-
400
- await (0, _entryDataValidation.validateModelEntryData)(context, model, values);
401
- utils.checkOwnership(context, permission, originalEntry);
402
- const latestEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, latestStorageEntry);
403
- const identity = context.security.getIdentity();
404
- const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
405
- const {
406
- id,
407
- version: nextVersion
408
- } = increaseEntryIdVersion(latestId);
409
-
410
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
411
- id,
412
- version: nextVersion,
413
- savedOn: new Date().toISOString(),
414
- createdOn: new Date().toISOString(),
415
- createdBy: {
416
- id: identity.id,
417
- displayName: identity.displayName,
418
- type: identity.type
419
- },
420
- locked: false,
421
- publishedOn: null,
422
- status: STATUS_DRAFT,
423
- values
424
- });
425
-
426
- let storageEntry = undefined;
427
-
428
- try {
429
- await (0, _hooks.beforeCreateRevisionFromHook)({
430
- context,
431
- model,
432
- entry,
433
- storageEntry,
434
- originalEntry,
435
- originalStorageEntry,
436
- latestEntry,
437
- latestStorageEntry,
438
- storageOperations
439
- });
440
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
441
- const result = await storageOperations.createRevisionFrom(model, {
442
- entry,
443
- storageEntry,
444
- originalEntry,
445
- originalStorageEntry,
446
- latestEntry,
447
- latestStorageEntry
448
- });
449
- await (0, _hooks.afterCreateRevisionFromHook)({
450
- context,
451
- model,
452
- originalEntry,
453
- originalStorageEntry,
454
- latestEntry,
455
- latestStorageEntry,
456
- entry,
457
-
458
- /**
459
- * Passing result due to storage operations might have changed something on the entry.
460
- */
461
- storageEntry: result,
462
- storageOperations
463
- });
464
- return result;
465
- } catch (ex) {
466
- throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
467
- error: ex,
468
- entry,
469
- storageEntry,
470
- originalEntry,
471
- originalStorageEntry
472
- });
473
- }
474
- },
475
- update: async (model, id, inputData) => {
476
- const permission = await checkEntryPermissions({
477
- rwd: "w"
478
- });
479
- await utils.checkModelAccess(context, model);
480
- /**
481
- * Make sure we only work with fields that are defined in the model.
482
- */
710
+ utils.checkOwnership(context, permission, storageEntry);
711
+ const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
712
+ return await deleteEntry({
713
+ model,
714
+ entry,
715
+ storageEntry
716
+ });
717
+ },
718
+ publishEntry: async (model, id) => {
719
+ const permission = await checkEntryPermissions({
720
+ pw: "p"
721
+ });
722
+ await utils.checkModelAccess(context, model);
723
+ const tenant = getTenant().id;
724
+ const locale = getLocale().code;
725
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
726
+ tenant,
727
+ locale,
728
+ id
729
+ });
483
730
 
484
- const input = cleanInputData(model, inputData);
485
- /**
486
- * Validate data early. We don't want to query DB if input data is invalid.
487
- */
731
+ if (!originalStorageEntry) {
732
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
733
+ }
488
734
 
489
- await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
490
- /**
491
- * The entry we are going to update.
492
- */
735
+ utils.checkOwnership(context, permission, originalStorageEntry);
736
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
737
+ const currentDate = new Date().toISOString();
493
738
 
494
- const originalStorageEntry = await storageOperations.getRevisionById(model, id);
739
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
740
+ status: STATUS_PUBLISHED,
741
+ locked: true,
742
+ savedOn: currentDate,
743
+ publishedOn: currentDate
744
+ });
495
745
 
496
- if (!originalStorageEntry) {
497
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
498
- }
746
+ let storageEntry = undefined;
499
747
 
500
- if (originalStorageEntry.locked) {
501
- throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
502
- }
748
+ try {
749
+ await onBeforePublish.publish({
750
+ entry,
751
+ model
752
+ });
753
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
754
+ const result = await storageOperations.entries.publish(model, {
755
+ entry,
756
+ storageEntry,
757
+ originalEntry,
758
+ originalStorageEntry
759
+ });
760
+ await onAfterPublish.publish({
761
+ entry,
762
+ storageEntry: result,
763
+ model
764
+ });
765
+ return result;
766
+ } catch (ex) {
767
+ throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
768
+ error: ex,
769
+ entry,
770
+ storageEntry,
771
+ originalEntry,
772
+ originalStorageEntry
773
+ });
774
+ }
775
+ },
776
+ requestEntryChanges: async (model, id) => {
777
+ const permission = await checkEntryPermissions({
778
+ pw: "c"
779
+ });
780
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
781
+ tenant: getTenant().id,
782
+ locale: getLocale().code,
783
+ id
784
+ });
503
785
 
504
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
505
- utils.checkOwnership(context, permission, originalEntry);
506
- /**
507
- * We always send the full entry to the hooks and storage operations update.
508
- */
786
+ if (!originalStorageEntry) {
787
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
788
+ }
509
789
 
510
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
511
- savedOn: new Date().toISOString(),
512
- values: _objectSpread(_objectSpread({}, originalEntry.values), input)
513
- });
514
-
515
- let storageEntry = undefined;
516
-
517
- try {
518
- await (0, _hooks.beforeUpdateHook)({
519
- context,
520
- model,
521
- input,
522
- entry,
523
- originalEntry,
524
- originalStorageEntry,
525
- storageOperations
526
- });
527
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
528
- const result = await storageOperations.update(model, {
529
- originalEntry,
530
- originalStorageEntry,
531
- entry,
532
- storageEntry,
533
- input
534
- });
535
- await (0, _hooks.afterUpdateHook)({
536
- context,
537
- model,
538
- input,
539
- entry,
540
- storageEntry: result,
541
- originalEntry,
542
- originalStorageEntry,
543
- storageOperations
544
- });
545
- return result;
546
- } catch (ex) {
547
- throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
548
- error: ex,
549
- entry,
550
- storageEntry,
551
- originalEntry,
552
- input
553
- });
554
- }
555
- },
556
- deleteRevision: async (model, revisionId) => {
557
- const permission = await checkEntryPermissions({
558
- rwd: "d"
559
- });
560
- await utils.checkModelAccess(context, model);
561
- const [entryId, version] = revisionId.split("#");
562
- const storageEntryToDelete = await storageOperations.getRevisionById(model, revisionId);
563
- const latestStorageEntry = await storageOperations.getLatestRevisionByEntryId(model, entryId);
564
- const previousStorageEntry = await storageOperations.getPreviousRevision(model, entryId, parseInt(version));
565
-
566
- if (!storageEntryToDelete) {
567
- throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
568
- }
569
-
570
- utils.checkOwnership(context, permission, storageEntryToDelete);
571
- const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
572
- const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
573
- /**
574
- * If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
575
- * At this point deleteEntry hooks are not fired.
576
- * TODO determine if not running the deleteRevision hooks is ok.
577
- */
790
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
578
791
 
579
- if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
580
- return await deleteEntry({
581
- model,
582
- entry: entryToDelete,
583
- storageEntry: storageEntryToDelete
584
- });
585
- }
586
- /**
587
- * If targeted record is latest entry revision, set the previous one as the new latest
588
- */
792
+ if (originalEntry.status !== STATUS_REVIEW_REQUESTED) {
793
+ throw new _error.default("Cannot request changes on an entry that's not under review.", "ENTRY_NOT_UNDER_REVIEW");
794
+ }
589
795
 
796
+ const identity = context.security.getIdentity();
590
797
 
591
- let entryToSetAsLatest = null;
592
- let storageEntryToSetAsLatest = null;
593
-
594
- if (entryToDelete.id === latestEntryRevisionId) {
595
- entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
596
- storageEntryToSetAsLatest = previousStorageEntry;
597
- }
598
-
599
- try {
600
- await (0, _hooks.beforeDeleteRevisionHook)({
601
- context,
602
- model,
603
- storageOperations,
604
- entryToDelete,
605
- storageEntryToDelete,
606
- entryToSetAsLatest,
607
- storageEntryToSetAsLatest
608
- });
609
- await storageOperations.deleteRevision(model, {
610
- entryToDelete,
611
- storageEntryToDelete,
612
- entryToSetAsLatest,
613
- storageEntryToSetAsLatest
614
- });
615
- await (0, _hooks.afterDeleteRevisionHook)({
616
- context,
617
- model,
618
- storageOperations,
619
- entryToDelete,
620
- storageEntryToDelete,
621
- entryToSetAsLatest,
622
- storageEntryToSetAsLatest
623
- });
624
- } catch (ex) {
625
- throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
626
- error: ex,
627
- entryToDelete,
628
- storageEntryToDelete,
629
- entryToSetAsLatest,
630
- storageEntryToSetAsLatest
631
- });
632
- }
633
- },
634
- deleteEntry: async (model, entryId) => {
635
- const permission = await checkEntryPermissions({
636
- rwd: "d"
637
- });
638
- await utils.checkModelAccess(context, model);
639
- const storageEntry = await storageOperations.getLatestRevisionByEntryId(model, entryId);
640
-
641
- if (!storageEntry) {
642
- throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
643
- }
644
-
645
- utils.checkOwnership(context, permission, storageEntry);
646
- const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
647
- return await deleteEntry({
648
- model,
798
+ if (originalEntry.ownedBy.id === identity.id) {
799
+ throw new _error.default("You cannot request changes on your own entry.", "CANNOT_REQUEST_CHANGES_ON_OWN_ENTRY");
800
+ }
801
+
802
+ utils.checkOwnership(context, permission, originalEntry);
803
+
804
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
805
+ status: STATUS_CHANGES_REQUESTED
806
+ });
807
+
808
+ let storageEntry = undefined;
809
+
810
+ try {
811
+ await onBeforeRequestChanges.publish({
812
+ entry,
813
+ model
814
+ });
815
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
816
+ const result = await storageOperations.entries.requestChanges(model, {
817
+ originalEntry,
818
+ originalStorageEntry,
649
819
  entry,
650
820
  storageEntry
651
821
  });
652
- },
653
- publish: async (model, id) => {
654
- const permission = await checkEntryPermissions({
655
- pw: "p"
656
- });
657
- await utils.checkModelAccess(context, model);
658
- const originalStorageEntry = await storageOperations.getRevisionById(model, id);
659
-
660
- if (!originalStorageEntry) {
661
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
662
- }
663
-
664
- utils.checkOwnership(context, permission, originalStorageEntry);
665
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
666
- const currentDate = new Date().toISOString();
667
-
668
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
669
- status: STATUS_PUBLISHED,
670
- locked: true,
671
- savedOn: currentDate,
672
- publishedOn: currentDate
673
- });
674
-
675
- let storageEntry = undefined;
676
-
677
- try {
678
- await (0, _hooks.beforePublishHook)({
679
- context,
680
- storageOperations,
681
- model,
682
- entry,
683
- originalEntry,
684
- originalStorageEntry
685
- });
686
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
687
- const result = await storageOperations.publish(model, {
688
- entry,
689
- storageEntry,
690
- originalEntry,
691
- originalStorageEntry
692
- });
693
- await (0, _hooks.afterPublishHook)({
694
- context,
695
- storageOperations,
696
- model,
697
- originalEntry,
698
- originalStorageEntry,
699
- entry,
700
- storageEntry: result
701
- });
702
- return result;
703
- } catch (ex) {
704
- throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
705
- entry,
706
- storageEntry,
707
- originalEntry,
708
- originalStorageEntry
709
- });
710
- }
711
- },
712
- requestChanges: async (model, id) => {
713
- const permission = await checkEntryPermissions({
714
- pw: "c"
715
- });
716
- const originalStorageEntry = await storageOperations.getRevisionById(model, id);
717
-
718
- if (!originalStorageEntry) {
719
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
720
- }
721
-
722
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
723
-
724
- if (originalEntry.status !== STATUS_REVIEW_REQUESTED) {
725
- throw new _error.default("Cannot request changes on an entry that's not under review.", "ENTRY_NOT_UNDER_REVIEW");
726
- }
727
-
728
- const identity = context.security.getIdentity();
729
-
730
- if (originalEntry.ownedBy.id === identity.id) {
731
- throw new _error.default("You cannot request changes on your own entry.", "CANNOT_REQUEST_CHANGES_ON_OWN_ENTRY");
732
- }
733
-
734
- utils.checkOwnership(context, permission, originalEntry);
735
-
736
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
737
- status: STATUS_CHANGES_REQUESTED
738
- });
739
-
740
- let storageEntry = undefined;
741
-
742
- try {
743
- await (0, _hooks.beforeRequestChangesHook)({
744
- context,
745
- model,
746
- originalEntry,
747
- originalStorageEntry,
748
- entry,
749
- storageOperations
750
- });
751
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
752
- const result = await storageOperations.requestChanges(model, {
753
- originalEntry,
754
- originalStorageEntry,
755
- entry,
756
- storageEntry
757
- });
758
- await (0, _hooks.afterRequestChangesHook)({
759
- context,
760
- model,
761
- originalEntry,
762
- originalStorageEntry,
763
- entry,
764
- storageEntry: result,
765
- storageOperations
766
- });
767
- return result;
768
- } catch (ex) {
769
- throw new _error.default(ex.message || "Could not request changes for the entry.", ex.code || "REQUEST_CHANGES_ERROR", {
770
- entry,
771
- originalEntry
772
- });
773
- }
774
- },
775
- requestReview: async (model, id) => {
776
- const permission = await checkEntryPermissions({
777
- pw: "r"
778
- });
779
- const [entryId] = id.split("#");
780
- const originalStorageEntry = await storageOperations.getRevisionById(model, id);
781
- const latestEntryRevision = await storageOperations.getLatestRevisionByEntryId(model, entryId);
782
-
783
- if (!originalStorageEntry) {
784
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
785
- } else if (!latestEntryRevision) {
786
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" does not have latest record`);
787
- }
788
-
789
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
790
- const allowedStatuses = [STATUS_DRAFT, STATUS_CHANGES_REQUESTED];
791
-
792
- if (!allowedStatuses.includes(originalEntry.status)) {
793
- throw new _error.default("Cannot request review - entry is not a draft nor was a change request issued.", "REQUEST_REVIEW_ERROR", {
794
- entry: originalEntry
795
- });
796
- }
797
-
798
- utils.checkOwnership(context, permission, originalEntry);
799
-
800
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
801
- status: STATUS_REVIEW_REQUESTED
802
- });
803
-
804
- let storageEntry = undefined;
805
-
806
- try {
807
- await (0, _hooks.beforeRequestReviewHook)({
808
- context,
809
- model,
810
- originalEntry,
811
- originalStorageEntry,
812
- entry,
813
- storageOperations
814
- });
815
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
816
- const result = await storageOperations.requestReview(model, {
817
- originalEntry,
818
- originalStorageEntry,
819
- entry,
820
- storageEntry
821
- });
822
- await (0, _hooks.afterRequestReviewHook)({
823
- context,
824
- model,
825
- originalEntry,
826
- originalStorageEntry,
827
- entry,
828
- storageEntry: result,
829
- storageOperations
830
- });
831
- return result;
832
- } catch (ex) {
833
- throw new _error.default(ex.message || "Could not request review on the entry.", ex.code || "REQUEST_REVIEW_ERROR", {
834
- originalEntry,
835
- entry
836
- });
837
- }
838
- },
839
- unpublish: async (model, id) => {
840
- const permission = await checkEntryPermissions({
841
- pw: "u"
842
- });
843
- const [entryId] = id.split("#");
844
- const originalStorageEntry = await storageOperations.getPublishedRevisionByEntryId(model, entryId);
845
-
846
- if (!originalStorageEntry) {
847
- throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
848
- }
849
-
850
- if (originalStorageEntry.id !== id) {
851
- throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
852
- entry: originalStorageEntry
853
- });
854
- }
855
-
856
- utils.checkOwnership(context, permission, originalStorageEntry);
857
- const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
858
-
859
- const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
860
- status: STATUS_UNPUBLISHED
861
- });
862
-
863
- let storageEntry = undefined;
864
-
865
- try {
866
- await (0, _hooks.beforeUnpublishHook)({
867
- context,
868
- model,
869
- originalEntry,
870
- originalStorageEntry,
871
- entry,
872
- storageOperations
873
- });
874
- storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
875
- const result = await storageOperations.unpublish(model, {
876
- originalEntry,
877
- originalStorageEntry,
878
- entry,
879
- storageEntry
880
- });
881
- await (0, _hooks.afterUnpublishHook)({
882
- context,
883
- model,
884
- originalEntry,
885
- originalStorageEntry,
886
- entry,
887
- storageEntry: result,
888
- storageOperations
889
- });
890
- return result;
891
- } catch (ex) {
892
- throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
893
- originalEntry,
894
- originalStorageEntry,
895
- entry,
896
- storageEntry
897
- });
898
- }
822
+ await onAfterRequestChanges.publish({
823
+ entry,
824
+ storageEntry: result,
825
+ model
826
+ });
827
+ return result;
828
+ } catch (ex) {
829
+ throw new _error.default(ex.message || "Could not request changes for the entry.", ex.code || "REQUEST_CHANGES_ERROR", {
830
+ entry,
831
+ originalEntry
832
+ });
899
833
  }
900
- };
901
- context.cms = _objectSpread(_objectSpread({}, context.cms || {}), {}, {
902
- entries
903
- });
904
- }
834
+ },
835
+ requestEntryReview: async (model, id) => {
836
+ const permission = await checkEntryPermissions({
837
+ pw: "r"
838
+ });
839
+ const [entryId] = id.split("#");
840
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
841
+ tenant: getTenant().id,
842
+ locale: getLocale().code,
843
+ id
844
+ });
845
+ const latestEntryRevision = await storageOperations.entries.getLatestRevisionByEntryId(model, {
846
+ tenant: getTenant().id,
847
+ locale: getLocale().code,
848
+ id: entryId
849
+ });
905
850
 
906
- });
851
+ if (!originalStorageEntry) {
852
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
853
+ } else if (!latestEntryRevision) {
854
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" does not have latest record`);
855
+ }
856
+
857
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
858
+ const allowedStatuses = [STATUS_DRAFT, STATUS_CHANGES_REQUESTED];
859
+
860
+ if (!allowedStatuses.includes(originalEntry.status)) {
861
+ throw new _error.default("Cannot request review - entry is not a draft nor was a change request issued.", "REQUEST_REVIEW_ERROR", {
862
+ entry: originalEntry
863
+ });
864
+ }
865
+
866
+ utils.checkOwnership(context, permission, originalEntry);
867
+
868
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
869
+ status: STATUS_REVIEW_REQUESTED
870
+ });
871
+
872
+ let storageEntry = undefined;
873
+
874
+ try {
875
+ await onBeforeRequestReview.publish({
876
+ entry,
877
+ model
878
+ });
879
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
880
+ const result = await storageOperations.entries.requestReview(model, {
881
+ originalEntry,
882
+ originalStorageEntry,
883
+ entry,
884
+ storageEntry
885
+ });
886
+ await onAfterRequestReview.publish({
887
+ entry,
888
+ storageEntry: result,
889
+ model
890
+ });
891
+ return result;
892
+ } catch (ex) {
893
+ throw new _error.default(ex.message || "Could not request review on the entry.", ex.code || "REQUEST_REVIEW_ERROR", {
894
+ originalEntry,
895
+ entry
896
+ });
897
+ }
898
+ },
899
+ unpublishEntry: async (model, id) => {
900
+ const permission = await checkEntryPermissions({
901
+ pw: "u"
902
+ });
903
+ const [entryId] = id.split("#");
904
+ const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
905
+ tenant: getTenant().id,
906
+ locale: getLocale().code,
907
+ id: entryId
908
+ });
909
+
910
+ if (!originalStorageEntry) {
911
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
912
+ }
913
+
914
+ if (originalStorageEntry.id !== id) {
915
+ throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
916
+ entry: originalStorageEntry
917
+ });
918
+ }
919
+
920
+ utils.checkOwnership(context, permission, originalStorageEntry);
921
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
922
+
923
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
924
+ status: STATUS_UNPUBLISHED
925
+ });
926
+
927
+ let storageEntry = undefined;
928
+
929
+ try {
930
+ await onBeforeUnpublish.publish({
931
+ entry,
932
+ model
933
+ });
934
+ storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
935
+ const result = await storageOperations.entries.unpublish(model, {
936
+ originalEntry,
937
+ originalStorageEntry,
938
+ entry,
939
+ storageEntry
940
+ });
941
+ await onAfterUnpublish.publish({
942
+ entry,
943
+ storageEntry: result,
944
+ model
945
+ });
946
+ return result;
947
+ } catch (ex) {
948
+ throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
949
+ originalEntry,
950
+ originalStorageEntry,
951
+ entry,
952
+ storageEntry
953
+ });
954
+ }
955
+ }
956
+ };
957
+ };
907
958
 
908
- exports.default = _default;
909
- //# sourceMappingURL=contentEntry.crud.js.map
959
+ exports.createContentEntryCrud = createContentEntryCrud;