@webiny/api-headless-cms 0.0.0-mt-1

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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/content/contextSetup.d.ts +4 -0
  4. package/content/contextSetup.js +65 -0
  5. package/content/graphQLHandlerFactory.d.ts +5 -0
  6. package/content/graphQLHandlerFactory.js +173 -0
  7. package/content/plugins/CmsGroupPlugin.d.ts +11 -0
  8. package/content/plugins/CmsGroupPlugin.js +24 -0
  9. package/content/plugins/CmsModelPlugin.d.ts +11 -0
  10. package/content/plugins/CmsModelPlugin.js +24 -0
  11. package/content/plugins/buildSchemaPlugins.d.ts +7 -0
  12. package/content/plugins/buildSchemaPlugins.js +29 -0
  13. package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
  14. package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
  15. package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
  16. package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
  17. package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
  18. package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
  19. package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +4 -0
  20. package/content/plugins/crud/contentEntry/entryDataValidation.js +188 -0
  21. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +12 -0
  22. package/content/plugins/crud/contentEntry/markLockedFields.js +117 -0
  23. package/content/plugins/crud/contentEntry.crud.d.ts +17 -0
  24. package/content/plugins/crud/contentEntry.crud.js +931 -0
  25. package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
  26. package/content/plugins/crud/contentModel/afterCreate.js +18 -0
  27. package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
  28. package/content/plugins/crud/contentModel/afterDelete.js +18 -0
  29. package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
  30. package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
  31. package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
  32. package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
  33. package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
  34. package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
  35. package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
  36. package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
  37. package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
  38. package/content/plugins/crud/contentModel/contentModelManagerFactory.js +29 -0
  39. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -0
  40. package/content/plugins/crud/contentModel/createFieldModels.js +22 -0
  41. package/content/plugins/crud/contentModel/idValidation.d.ts +2 -0
  42. package/content/plugins/crud/contentModel/idValidation.js +22 -0
  43. package/content/plugins/crud/contentModel/models.d.ts +3 -0
  44. package/content/plugins/crud/contentModel/models.js +141 -0
  45. package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -0
  46. package/content/plugins/crud/contentModel/validateLayout.js +38 -0
  47. package/content/plugins/crud/contentModel.crud.d.ts +12 -0
  48. package/content/plugins/crud/contentModel.crud.js +425 -0
  49. package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
  50. package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
  51. package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
  52. package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
  53. package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
  54. package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
  55. package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -0
  56. package/content/plugins/crud/contentModelGroup.crud.js +351 -0
  57. package/content/plugins/crud/index.d.ts +6 -0
  58. package/content/plugins/crud/index.js +100 -0
  59. package/content/plugins/graphqlFields/boolean.d.ts +3 -0
  60. package/content/plugins/graphqlFields/boolean.js +69 -0
  61. package/content/plugins/graphqlFields/datetime.d.ts +3 -0
  62. package/content/plugins/graphqlFields/datetime.js +83 -0
  63. package/content/plugins/graphqlFields/file.d.ts +3 -0
  64. package/content/plugins/graphqlFields/file.js +49 -0
  65. package/content/plugins/graphqlFields/index.d.ts +2 -0
  66. package/content/plugins/graphqlFields/index.js +30 -0
  67. package/content/plugins/graphqlFields/longText.d.ts +3 -0
  68. package/content/plugins/graphqlFields/longText.js +62 -0
  69. package/content/plugins/graphqlFields/number.d.ts +3 -0
  70. package/content/plugins/graphqlFields/number.js +75 -0
  71. package/content/plugins/graphqlFields/object.d.ts +3 -0
  72. package/content/plugins/graphqlFields/object.js +180 -0
  73. package/content/plugins/graphqlFields/ref.d.ts +3 -0
  74. package/content/plugins/graphqlFields/ref.js +205 -0
  75. package/content/plugins/graphqlFields/richText.d.ts +3 -0
  76. package/content/plugins/graphqlFields/richText.js +55 -0
  77. package/content/plugins/graphqlFields/text.d.ts +3 -0
  78. package/content/plugins/graphqlFields/text.js +72 -0
  79. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.d.ts +8 -0
  80. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +54 -0
  81. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.d.ts +7 -0
  82. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +35 -0
  83. package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
  84. package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
  85. package/content/plugins/modelManager/index.d.ts +3 -0
  86. package/content/plugins/modelManager/index.js +20 -0
  87. package/content/plugins/schema/baseSchema.d.ts +4 -0
  88. package/content/plugins/schema/baseSchema.js +98 -0
  89. package/content/plugins/schema/contentEntries.d.ts +4 -0
  90. package/content/plugins/schema/contentEntries.js +166 -0
  91. package/content/plugins/schema/contentModelGroups.d.ts +4 -0
  92. package/content/plugins/schema/contentModelGroups.js +153 -0
  93. package/content/plugins/schema/contentModels.d.ts +4 -0
  94. package/content/plugins/schema/contentModels.js +225 -0
  95. package/content/plugins/schema/createFieldResolvers.d.ts +19 -0
  96. package/content/plugins/schema/createFieldResolvers.js +92 -0
  97. package/content/plugins/schema/createManageResolvers.d.ts +11 -0
  98. package/content/plugins/schema/createManageResolvers.js +135 -0
  99. package/content/plugins/schema/createManageSDL.d.ts +9 -0
  100. package/content/plugins/schema/createManageSDL.js +153 -0
  101. package/content/plugins/schema/createPreviewResolvers.d.ts +10 -0
  102. package/content/plugins/schema/createPreviewResolvers.js +55 -0
  103. package/content/plugins/schema/createReadResolvers.d.ts +10 -0
  104. package/content/plugins/schema/createReadResolvers.js +55 -0
  105. package/content/plugins/schema/createReadSDL.d.ts +9 -0
  106. package/content/plugins/schema/createReadSDL.js +96 -0
  107. package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +6 -0
  108. package/content/plugins/schema/resolvers/commonFieldResolvers.js +14 -0
  109. package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +6 -0
  110. package/content/plugins/schema/resolvers/manage/resolveCreate.js +23 -0
  111. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +7 -0
  112. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +23 -0
  113. package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +2 -0
  114. package/content/plugins/schema/resolvers/manage/resolveDelete.js +30 -0
  115. package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +2 -0
  116. package/content/plugins/schema/resolvers/manage/resolveGet.js +21 -0
  117. package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +2 -0
  118. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +23 -0
  119. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +2 -0
  120. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +23 -0
  121. package/content/plugins/schema/resolvers/manage/resolveList.d.ts +2 -0
  122. package/content/plugins/schema/resolvers/manage/resolveList.js +23 -0
  123. package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +2 -0
  124. package/content/plugins/schema/resolvers/manage/resolvePublish.js +21 -0
  125. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +6 -0
  126. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +23 -0
  127. package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +6 -0
  128. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +23 -0
  129. package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +2 -0
  130. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +21 -0
  131. package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +7 -0
  132. package/content/plugins/schema/resolvers/manage/resolveUpdate.js +23 -0
  133. package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +2 -0
  134. package/content/plugins/schema/resolvers/preview/resolveGet.js +38 -0
  135. package/content/plugins/schema/resolvers/preview/resolveList.d.ts +2 -0
  136. package/content/plugins/schema/resolvers/preview/resolveList.js +23 -0
  137. package/content/plugins/schema/resolvers/read/resolveGet.d.ts +2 -0
  138. package/content/plugins/schema/resolvers/read/resolveGet.js +38 -0
  139. package/content/plugins/schema/resolvers/read/resolveList.d.ts +2 -0
  140. package/content/plugins/schema/resolvers/read/resolveList.js +23 -0
  141. package/content/plugins/schema/schemaPlugins.d.ts +3 -0
  142. package/content/plugins/schema/schemaPlugins.js +92 -0
  143. package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
  144. package/content/plugins/storage/StorageTransformPlugin.js +36 -0
  145. package/content/plugins/storage/default.d.ts +3 -0
  146. package/content/plugins/storage/default.js +28 -0
  147. package/content/plugins/storage/object.d.ts +3 -0
  148. package/content/plugins/storage/object.js +119 -0
  149. package/content/plugins/utils/createTypeName.d.ts +3 -0
  150. package/content/plugins/utils/createTypeName.js +28 -0
  151. package/content/plugins/utils/entryStorage.d.ts +17 -0
  152. package/content/plugins/utils/entryStorage.js +125 -0
  153. package/content/plugins/utils/getEntryTitle.d.ts +2 -0
  154. package/content/plugins/utils/getEntryTitle.js +42 -0
  155. package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +11 -0
  156. package/content/plugins/utils/getSchemaFromFieldPlugins.js +30 -0
  157. package/content/plugins/utils/pluralizedTypeName.d.ts +1 -0
  158. package/content/plugins/utils/pluralizedTypeName.js +26 -0
  159. package/content/plugins/utils/renderFields.d.ts +16 -0
  160. package/content/plugins/utils/renderFields.js +51 -0
  161. package/content/plugins/utils/renderGetFilterFields.d.ts +9 -0
  162. package/content/plugins/utils/renderGetFilterFields.js +41 -0
  163. package/content/plugins/utils/renderInputFields.d.ts +14 -0
  164. package/content/plugins/utils/renderInputFields.js +53 -0
  165. package/content/plugins/utils/renderListFilterFields.d.ts +10 -0
  166. package/content/plugins/utils/renderListFilterFields.js +39 -0
  167. package/content/plugins/utils/renderSortEnum.d.ts +9 -0
  168. package/content/plugins/utils/renderSortEnum.js +32 -0
  169. package/content/plugins/validators/dateGte.d.ts +3 -0
  170. package/content/plugins/validators/dateGte.js +37 -0
  171. package/content/plugins/validators/dateLte.d.ts +3 -0
  172. package/content/plugins/validators/dateLte.js +37 -0
  173. package/content/plugins/validators/gte.d.ts +3 -0
  174. package/content/plugins/validators/gte.js +32 -0
  175. package/content/plugins/validators/in.d.ts +3 -0
  176. package/content/plugins/validators/in.js +32 -0
  177. package/content/plugins/validators/index.d.ts +2 -0
  178. package/content/plugins/validators/index.js +36 -0
  179. package/content/plugins/validators/lte.d.ts +3 -0
  180. package/content/plugins/validators/lte.js +32 -0
  181. package/content/plugins/validators/maxLength.d.ts +3 -0
  182. package/content/plugins/validators/maxLength.js +32 -0
  183. package/content/plugins/validators/minLength.d.ts +3 -0
  184. package/content/plugins/validators/minLength.js +32 -0
  185. package/content/plugins/validators/pattern.d.ts +3 -0
  186. package/content/plugins/validators/pattern.js +47 -0
  187. package/content/plugins/validators/patternPlugins/email.d.ts +3 -0
  188. package/content/plugins/validators/patternPlugins/email.js +17 -0
  189. package/content/plugins/validators/patternPlugins/index.d.ts +2 -0
  190. package/content/plugins/validators/patternPlugins/index.js +19 -0
  191. package/content/plugins/validators/patternPlugins/lowerCase.d.ts +3 -0
  192. package/content/plugins/validators/patternPlugins/lowerCase.js +17 -0
  193. package/content/plugins/validators/patternPlugins/upperCase.d.ts +3 -0
  194. package/content/plugins/validators/patternPlugins/upperCase.js +17 -0
  195. package/content/plugins/validators/patternPlugins/url.d.ts +3 -0
  196. package/content/plugins/validators/patternPlugins/url.js +17 -0
  197. package/content/plugins/validators/required.d.ts +3 -0
  198. package/content/plugins/validators/required.js +25 -0
  199. package/content/plugins/validators/timeGte.d.ts +3 -0
  200. package/content/plugins/validators/timeGte.js +32 -0
  201. package/content/plugins/validators/timeLte.d.ts +3 -0
  202. package/content/plugins/validators/timeLte.js +32 -0
  203. package/index.d.ts +12 -0
  204. package/index.js +66 -0
  205. package/migrateCMSPermissions.d.ts +17 -0
  206. package/migrateCMSPermissions.js +193 -0
  207. package/package.json +80 -0
  208. package/plugins/context.d.ts +4 -0
  209. package/plugins/context.js +34 -0
  210. package/plugins/crud/index.d.ts +6 -0
  211. package/plugins/crud/index.js +100 -0
  212. package/plugins/crud/settings.crud.d.ts +10 -0
  213. package/plugins/crud/settings.crud.js +93 -0
  214. package/plugins/crud/system.crud.d.ts +10 -0
  215. package/plugins/crud/system.crud.js +182 -0
  216. package/plugins/graphql/system.d.ts +17 -0
  217. package/plugins/graphql/system.js +72 -0
  218. package/plugins/graphql.d.ts +2 -0
  219. package/plugins/graphql.js +79 -0
  220. package/plugins/upgrades/index.d.ts +2 -0
  221. package/plugins/upgrades/index.js +14 -0
  222. package/plugins/upgrades/v5.5.0/helpers.d.ts +6 -0
  223. package/plugins/upgrades/v5.5.0/helpers.js +10 -0
  224. package/plugins/upgrades/v5.5.0/index.d.ts +4 -0
  225. package/plugins/upgrades/v5.5.0/index.js +129 -0
  226. package/transformers.d.ts +2 -0
  227. package/transformers.js +25 -0
  228. package/types.d.ts +2149 -0
  229. package/types.js +366 -0
  230. package/utils.d.ts +25 -0
  231. package/utils.js +251 -0
package/types.js ADDED
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CONTENT_ENTRY_STATUS = void 0;
7
+
8
+ /**
9
+ * @description This combines all contexts used in the CMS into a single one.
10
+ *
11
+ * @category Context
12
+ */
13
+
14
+ /**
15
+ * Object containing content model field predefined options and values.
16
+ *
17
+ * @category CmsModelField
18
+ */
19
+
20
+ /**
21
+ * Object containing content model field renderer options.
22
+ *
23
+ * @category CmsModelField
24
+ */
25
+
26
+ /**
27
+ * A definition for content model field. This type exists on the app side as well.
28
+ *
29
+ * @category ModelField
30
+ * @category Database model
31
+ */
32
+
33
+ /**
34
+ * A definition for dateTime field to show possible type of the field in settings.
35
+ */
36
+
37
+ /**
38
+ * Arguments for the field validator validate method.
39
+ *
40
+ * @category ModelField
41
+ * @category FieldValidation
42
+ */
43
+
44
+ /**
45
+ * Definition for the field validator.
46
+ *
47
+ * @category Plugin
48
+ * @category ModelField
49
+ * @category FieldValidation
50
+ */
51
+
52
+ /**
53
+ * A pattern validator for the content entry field value.
54
+ *
55
+ * @category Plugin
56
+ * @category ModelField
57
+ * @category FieldValidation
58
+ */
59
+
60
+ /**
61
+ * Locked field in the content model
62
+ *
63
+ * @see CmsModel.lockedFields
64
+ *
65
+ * @category ModelField
66
+ */
67
+
68
+ /**
69
+ * Cms Model defining an entry.
70
+ *
71
+ * @category Database model
72
+ * @category CmsModel
73
+ */
74
+
75
+ /**
76
+ * @category ModelField
77
+ */
78
+
79
+ /**
80
+ * @category Plugin
81
+ * @category ModelField
82
+ * @category GraphQL
83
+ */
84
+
85
+ /**
86
+ * Check for content model locked field.
87
+ * A custom plugin definable by the user.
88
+ *
89
+ * @category CmsModel
90
+ * @category Plugin
91
+ */
92
+
93
+ /**
94
+ * @category ModelField
95
+ */
96
+
97
+ /**
98
+ * A interface describing the reference to a user that created some data in the database.
99
+ *
100
+ * @category General
101
+ */
102
+
103
+ /**
104
+ * Representation of settings database model.
105
+ *
106
+ * @category Database model
107
+ */
108
+
109
+ /**
110
+ * Settings CRUD in context.
111
+ *
112
+ * @category Context
113
+ */
114
+
115
+ /**
116
+ * A GraphQL params.data parameter received when creating content model group.
117
+ *
118
+ * @category CmsGroup
119
+ * @category GraphQL params
120
+ */
121
+
122
+ /**
123
+ * A GraphQL params.data parameter received when updating content model group.
124
+ *
125
+ * @category CmsGroup
126
+ * @category GraphQL params
127
+ */
128
+
129
+ /**
130
+ * A representation of content model group in the database.
131
+ *
132
+ * @category CmsGroup
133
+ * @category Database model
134
+ */
135
+
136
+ /**
137
+ * A data.where parameter received when listing content model groups.
138
+ *
139
+ * @category CmsGroup
140
+ * @category GraphQL params
141
+ */
142
+
143
+ /**
144
+ * @category CmsGroup
145
+ * @category Topic
146
+ */
147
+
148
+ /**
149
+ * @category CmsGroup
150
+ * @category Topic
151
+ */
152
+
153
+ /**
154
+ * @category CmsGroup
155
+ * @category Topic
156
+ */
157
+
158
+ /**
159
+ * @category CmsGroup
160
+ * @category Topic
161
+ */
162
+
163
+ /**
164
+ * @category CmsGroup
165
+ * @category Topic
166
+ */
167
+
168
+ /**
169
+ * @category CmsGroup
170
+ * @category Topic
171
+ */
172
+
173
+ /**
174
+ * Cms Group in context.
175
+ *
176
+ * @category Context
177
+ * @category CmsGroup
178
+ */
179
+
180
+ /**
181
+ * Definition for content model field validator.
182
+ *
183
+ * @category ModelField
184
+ * @category FieldValidation
185
+ */
186
+
187
+ /**
188
+ * A GraphQL params.data parameter received when creating content model.
189
+ *
190
+ * @category GraphQL params
191
+ * @category CmsModel
192
+ */
193
+
194
+ /**
195
+ * A definition for content model field received from the user.
196
+ *
197
+ * Input type for `CmsModelField`.
198
+ * @see CmsModelField
199
+ *
200
+ * @category GraphQL params
201
+ * @category ModelField
202
+ */
203
+
204
+ /**
205
+ * A GraphQL params.data parameter received when updating content model.
206
+ *
207
+ * @category GraphQL params
208
+ * @category CmsModel
209
+ */
210
+
211
+ /**
212
+ * A plugin to load a CmsModelManager.
213
+ *
214
+ * @see CmsModelManager
215
+ *
216
+ * @category Plugin
217
+ * @category CmsModel
218
+ * @category CmsEntry
219
+ */
220
+
221
+ /**
222
+ * A content entry definition for and from the database.
223
+ *
224
+ * @category Database model
225
+ * @category CmsEntry
226
+ */
227
+
228
+ /**
229
+ * A definition for content model manager to be used in the code.
230
+ * The default one uses `CmsEntryContext` methods internally, but devs can change to what every they want.
231
+ *
232
+ * @see CmsEntryContext
233
+ *
234
+ * @category Context
235
+ * @category CmsEntry
236
+ * @category CmsModel
237
+ */
238
+
239
+ /**
240
+ * Cms Model in the context.
241
+ *
242
+ * @category Context
243
+ * @category CmsModel
244
+ */
245
+
246
+ /**
247
+ * Available statuses for content entry.
248
+ *
249
+ * @category CmsEntry
250
+ */
251
+
252
+ /**
253
+ * Entry listing where params.
254
+ *
255
+ * @category CmsEntry
256
+ * @category GraphQL params
257
+ */
258
+
259
+ /**
260
+ * Entry listing sort.
261
+ *
262
+ * @category CmsEntry
263
+ * @category GraphQL params
264
+ */
265
+
266
+ /**
267
+ * Get entry GraphQL resolver params.
268
+ *
269
+ * @category CmsEntry
270
+ * @category GraphQL params
271
+ */
272
+
273
+ /**
274
+ * List entries GraphQL resolver params.
275
+ *
276
+ * @category CmsEntry
277
+ * @category GraphQL params
278
+ */
279
+
280
+ /**
281
+ * Meta information for GraphQL output.
282
+ *
283
+ * @category CmsEntry
284
+ * @category GraphQL output
285
+ */
286
+
287
+ /**
288
+ * Cms Entry CRUD methods in the context.
289
+ *
290
+ * @category Context
291
+ * @category CmsEntry
292
+ */
293
+
294
+ /**
295
+ * Parameters for CmsEntryResolverFactory.
296
+ *
297
+ * @category GraphQL resolver
298
+ * @category CmsEntry
299
+ */
300
+
301
+ /**
302
+ * A type for EntryResolvers. Used when creating get, list, update, publish, ...etc.
303
+ *
304
+ * @category GraphQL resolver
305
+ * @category CmsEntry
306
+ */
307
+
308
+ /**
309
+ * Settings security permission.
310
+ *
311
+ * @category SecurityPermission
312
+ */
313
+ // eslint-disable-line
314
+
315
+ /**
316
+ * A security permission for content model.
317
+ *
318
+ * @category SecurityPermission
319
+ * @category CmsModel
320
+ */
321
+
322
+ /**
323
+ * The security permission for content model groups.
324
+ *
325
+ * @category SecurityPermission
326
+ * @category CmsGroup
327
+ */
328
+
329
+ /**
330
+ * The security permission for content entry.
331
+ *
332
+ * @category SecurityPermission
333
+ * @category CmsEntry
334
+ */
335
+
336
+ /**
337
+ * Description of the CmsGroup CRUD operations.
338
+ * If user wants to add another database to the application, this is how it is done.
339
+ * This is just plain read, update, write, delete and list - no authentication or permission checks.
340
+ */
341
+
342
+ /**
343
+ * Description of the CmsModel storage operations.
344
+ * If user wants to add another database to the application, this is how it is done.
345
+ * This is just plain read, update, write, delete and list - no authentication or permission checks.
346
+ */
347
+
348
+ /**
349
+ * Description of the CmsModel storage operations.
350
+ * If user wants to add another database to the application, this is how it is done.
351
+ * This is just plain read, update, write, delete and list - no authentication or permission checks.
352
+ *
353
+ *
354
+ * @category StorageOperations
355
+ * @category CmsEntry
356
+ */
357
+ let CONTENT_ENTRY_STATUS;
358
+ exports.CONTENT_ENTRY_STATUS = CONTENT_ENTRY_STATUS;
359
+
360
+ (function (CONTENT_ENTRY_STATUS) {
361
+ CONTENT_ENTRY_STATUS["DRAFT"] = "draft";
362
+ CONTENT_ENTRY_STATUS["PUBLISHED"] = "published";
363
+ CONTENT_ENTRY_STATUS["UNPUBLISHED"] = "unpublished";
364
+ CONTENT_ENTRY_STATUS["CHANGES_REQUESTED"] = "changesRequested";
365
+ CONTENT_ENTRY_STATUS["REVIEW_REQUESTED"] = "reviewRequested";
366
+ })(CONTENT_ENTRY_STATUS || (exports.CONTENT_ENTRY_STATUS = CONTENT_ENTRY_STATUS = {}));
package/utils.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { SecurityPermission } from "@webiny/api-security/types";
2
+ import { CmsModel, CmsContext, CreatedBy, CmsGroupPermission, CmsGroup } from "./types";
3
+ export declare const hasRwd: (permission: any, rwd: any) => any;
4
+ export declare const hasPw: (permission: any, pw: any) => any;
5
+ export declare const checkPermissions: <TPermission extends SecurityPermission = SecurityPermission>(context: CmsContext, name: string, check?: {
6
+ rwd?: string;
7
+ pw?: string;
8
+ }) => Promise<TPermission>;
9
+ export declare const checkOwnership: (context: CmsContext, permission: SecurityPermission, record: {
10
+ createdBy?: CreatedBy;
11
+ ownedBy?: CreatedBy;
12
+ }) => void;
13
+ export declare const validateOwnership: (context: CmsContext, permission: SecurityPermission, record: {
14
+ createdBy?: CreatedBy;
15
+ ownedBy?: CreatedBy;
16
+ }) => boolean;
17
+ /**
18
+ * model access is checking for both specific model or group access
19
+ * if permission has specific models set as access pattern then groups will not matter (although both can be set)
20
+ */
21
+ export declare const checkModelAccess: (context: CmsContext, model: CmsModel) => Promise<void>;
22
+ export declare const validateModelAccess: (context: CmsContext, model: CmsModel) => Promise<boolean>;
23
+ export declare const validateGroupAccess: (context: CmsContext, permission: CmsGroupPermission, group: CmsGroup) => boolean;
24
+ export declare const toSlug: (text: any) => string;
25
+ export declare const filterAsync: <T = Record<string, any>>(items: T[], predicate: (T: any) => Promise<boolean>) => Promise<T[]>;
package/utils.js ADDED
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.validateOwnership = exports.validateModelAccess = exports.validateGroupAccess = exports.toSlug = exports.hasRwd = exports.hasPw = exports.filterAsync = exports.checkPermissions = exports.checkOwnership = exports.checkModelAccess = void 0;
9
+
10
+ var _slugify = _interopRequireDefault(require("slugify"));
11
+
12
+ var _apiSecurity = require("@webiny/api-security");
13
+
14
+ const hasRwd = (permission, rwd) => {
15
+ if (typeof permission.rwd !== "string") {
16
+ return true;
17
+ }
18
+
19
+ return permission.rwd.includes(rwd);
20
+ };
21
+
22
+ exports.hasRwd = hasRwd;
23
+
24
+ const hasPw = (permission, pw) => {
25
+ const isCustom = Object.keys(permission).length > 1; // "name" key is always present
26
+
27
+ if (!isCustom) {
28
+ // Means it's a "full-access" permission.
29
+ return true;
30
+ }
31
+
32
+ if (typeof permission.pw !== "string") {
33
+ return false;
34
+ }
35
+
36
+ return permission.pw.includes(pw);
37
+ };
38
+
39
+ exports.hasPw = hasPw;
40
+ const PW = {
41
+ r: "request review",
42
+ c: "request change",
43
+ p: "publish",
44
+ u: "unpublish"
45
+ };
46
+ const RWD = {
47
+ r: "read",
48
+ w: "write",
49
+ d: "delete"
50
+ };
51
+
52
+ const checkPermissions = async (context, name, check) => {
53
+ // Check if user is allowed to edit content in current language
54
+ const contentPermission = await context.security.getPermission("content.i18n");
55
+
56
+ if (!contentPermission) {
57
+ throw new _apiSecurity.NotAuthorizedError({
58
+ data: {
59
+ reason: "Missing access to content in any locale."
60
+ }
61
+ });
62
+ } // We need to check this manually as CMS locale comes from the URL and not the default i18n app.
63
+
64
+
65
+ const code = context.cms.getLocale().code; // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.
66
+ // However, if the the `locales` IS SET - check that it contains the required locale.
67
+
68
+ if (Array.isArray(contentPermission.locales) && !contentPermission.locales.includes(code)) {
69
+ throw new _apiSecurity.NotAuthorizedError({
70
+ data: {
71
+ reason: `Not allowed to access content in "${code}."`
72
+ }
73
+ });
74
+ }
75
+
76
+ const permission = await context.security.getPermission(name);
77
+
78
+ if (!permission) {
79
+ throw new _apiSecurity.NotAuthorizedError({
80
+ data: {
81
+ reason: `Missing permission "${name}".`
82
+ }
83
+ });
84
+ }
85
+
86
+ if (!check) {
87
+ return permission;
88
+ }
89
+
90
+ if (check.rwd && !hasRwd(permission, check.rwd)) {
91
+ throw new _apiSecurity.NotAuthorizedError({
92
+ data: {
93
+ reason: `Not allowed to perform "${RWD[check.rwd]}" on "${name}".`
94
+ }
95
+ });
96
+ } // r = request review
97
+ // c = request change
98
+ // p = publish
99
+ // u = unpublish
100
+
101
+
102
+ if (check.pw && !hasPw(permission, check.pw)) {
103
+ throw new _apiSecurity.NotAuthorizedError({
104
+ data: {
105
+ reason: `Not allowed to perform "${PW[check.pw]}" on "${name}".`
106
+ }
107
+ });
108
+ }
109
+
110
+ return permission;
111
+ };
112
+
113
+ exports.checkPermissions = checkPermissions;
114
+
115
+ const checkOwnership = (context, permission, record) => {
116
+ if (!permission.own) {
117
+ return;
118
+ }
119
+
120
+ const identity = context.security.getIdentity();
121
+ const owner = identity && record["ownedBy"] && record["ownedBy"].id === identity.id;
122
+ const creator = identity && record["createdBy"] && record["createdBy"].id === identity.id;
123
+
124
+ if (!owner && !creator) {
125
+ throw new _apiSecurity.NotAuthorizedError({
126
+ data: {
127
+ reason: `You are not the owner of the record.`
128
+ }
129
+ });
130
+ }
131
+ };
132
+
133
+ exports.checkOwnership = checkOwnership;
134
+
135
+ const validateOwnership = (context, permission, record) => {
136
+ try {
137
+ checkOwnership(context, permission, record);
138
+ return true;
139
+ } catch {
140
+ return false;
141
+ }
142
+ };
143
+ /**
144
+ * model access is checking for both specific model or group access
145
+ * if permission has specific models set as access pattern then groups will not matter (although both can be set)
146
+ */
147
+
148
+
149
+ exports.validateOwnership = validateOwnership;
150
+
151
+ const checkModelAccess = async (context, model) => {
152
+ if (await validateModelAccess(context, model)) {
153
+ return;
154
+ }
155
+
156
+ throw new _apiSecurity.NotAuthorizedError({
157
+ data: {
158
+ reason: `Not allowed to access model "${model.modelId}".`
159
+ }
160
+ });
161
+ };
162
+
163
+ exports.checkModelAccess = checkModelAccess;
164
+
165
+ const validateModelAccess = async (context, model) => {
166
+ const modelGroupPermission = await checkPermissions(context, "cms.contentModelGroup", {
167
+ rwd: "r"
168
+ });
169
+ const {
170
+ groups
171
+ } = modelGroupPermission;
172
+ const modelPermission = await checkPermissions(context, "cms.contentModel", {
173
+ rwd: "r"
174
+ });
175
+ const {
176
+ models
177
+ } = modelPermission; // when no models or groups defined on permission
178
+ // it means user has access to everything
179
+
180
+ if (!models && !groups) {
181
+ return true;
182
+ }
183
+
184
+ const locale = context.cms.getLocale().code; // Check whether the model is question belongs to "content model groups" for which user has permission.
185
+
186
+ if (groups) {
187
+ if (Array.isArray(groups[locale]) === false || groups[locale].includes(model.group.id) === false) {
188
+ return false;
189
+ }
190
+ } // Check whether the model is question belongs to "content models" for which user has permission.
191
+
192
+
193
+ if (models) {
194
+ if (Array.isArray(models[locale]) === false || models[locale].includes(model.modelId) === false) {
195
+ return false;
196
+ }
197
+ }
198
+
199
+ return true;
200
+ };
201
+
202
+ exports.validateModelAccess = validateModelAccess;
203
+
204
+ const validateGroupAccess = (context, permission, group) => {
205
+ const {
206
+ groups
207
+ } = permission; // when no groups defined on permission
208
+ // it means user has access to everything
209
+
210
+ if (!groups) {
211
+ return true;
212
+ }
213
+
214
+ const locale = context.cms.getLocale().code; // when there is no locale in groups, it means that no access was given
215
+ // this happens when access control was set but no models or groups were added
216
+
217
+ if (Array.isArray(groups[locale]) === false || groups[locale].includes(group.id) === false) {
218
+ return false;
219
+ }
220
+
221
+ return true;
222
+ };
223
+
224
+ exports.validateGroupAccess = validateGroupAccess;
225
+
226
+ const toSlug = text => {
227
+ return (0, _slugify.default)(text, {
228
+ replacement: "-",
229
+ lower: true,
230
+ remove: /[*#\?<>_\{\}\[\]+~.()'"!:;@]/g
231
+ });
232
+ };
233
+
234
+ exports.toSlug = toSlug;
235
+
236
+ const filterAsync = async (items, predicate) => {
237
+ const filteredItems = [];
238
+
239
+ for (let i = 0; i < items.length; i++) {
240
+ const item = items[i];
241
+ const valid = await predicate(item);
242
+
243
+ if (valid) {
244
+ filteredItems.push(item);
245
+ }
246
+ }
247
+
248
+ return filteredItems;
249
+ };
250
+
251
+ exports.filterAsync = filterAsync;