@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
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.validateModelEntryData = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ const validateValue = async (args, fieldValidators, value) => {
13
+ if (!fieldValidators) {
14
+ return null;
15
+ }
16
+
17
+ const {
18
+ validatorList,
19
+ context,
20
+ field,
21
+ contentModel
22
+ } = args;
23
+
24
+ try {
25
+ for (const fieldValidator of fieldValidators) {
26
+ const name = fieldValidator.name;
27
+ const validations = validatorList[name];
28
+
29
+ if (!validations || validations.length === 0) {
30
+ return `There are no "${name}" validators defined.`;
31
+ }
32
+
33
+ for (const validate of validations) {
34
+ const result = await validate({
35
+ value,
36
+ context,
37
+ validator: fieldValidator,
38
+ field,
39
+ contentModel
40
+ });
41
+
42
+ if (!result) {
43
+ return fieldValidator.message;
44
+ }
45
+ }
46
+ }
47
+ } catch (ex) {
48
+ return ex.message;
49
+ }
50
+
51
+ return null;
52
+ };
53
+
54
+ const validatePredefinedValue = (field, value) => {
55
+ const {
56
+ enabled = false,
57
+ values: predefinedValues = []
58
+ } = field.predefinedValues || {};
59
+
60
+ if (!enabled) {
61
+ return null;
62
+ } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {
63
+ return "Missing predefined values to validate against.";
64
+ }
65
+
66
+ for (const predefinedValue of predefinedValues) {
67
+ // console.log(field.fieldId, predefinedValue.value, value, predefinedValue.value == value);
68
+ if (predefinedValue.value == value) {
69
+ return null;
70
+ }
71
+ }
72
+
73
+ return "Value sent does not match any of the available predefined values.";
74
+ };
75
+ /**
76
+ * When multiple values is selected we must run validations on the array containing the values
77
+ * And then on each value in the array
78
+ */
79
+
80
+
81
+ const runFieldMultipleValuesValidations = async args => {
82
+ const {
83
+ field,
84
+ data
85
+ } = args;
86
+ const values = data[field.fieldId];
87
+
88
+ if (Array.isArray(values) === false) {
89
+ return `Value of the field "${field.fieldId}" is not an array.`;
90
+ }
91
+
92
+ const valuesError = await validateValue(args, field.listValidation || [], values);
93
+
94
+ if (valuesError) {
95
+ return valuesError;
96
+ }
97
+
98
+ for (const value of values) {
99
+ const valueError = await validateValue(args, field.validation || [], value);
100
+
101
+ if (valueError) {
102
+ return valueError;
103
+ }
104
+
105
+ const predefinedValueError = validatePredefinedValue(field, value);
106
+
107
+ if (predefinedValueError) {
108
+ return predefinedValueError;
109
+ }
110
+ }
111
+
112
+ return null;
113
+ };
114
+ /**
115
+ * Runs validation on given value.
116
+ */
117
+
118
+
119
+ const runFieldValueValidations = async args => {
120
+ const {
121
+ data,
122
+ field
123
+ } = args;
124
+ const value = data[field.fieldId];
125
+ const error = await validateValue(args, field.validation, value);
126
+
127
+ if (error) {
128
+ return error;
129
+ }
130
+
131
+ return validatePredefinedValue(field, value);
132
+ };
133
+
134
+ const execValidation = async args => {
135
+ if (args.field.multipleValues) {
136
+ return await runFieldMultipleValuesValidations(args);
137
+ }
138
+
139
+ return await runFieldValueValidations(args);
140
+ };
141
+
142
+ const validateModelEntryData = async (context, contentModel, data) => {
143
+ /**
144
+ * To later simplify searching for the validations we map them to a name.
145
+ * @see CmsModelFieldValidatorPlugin.validator.validate
146
+ */
147
+ const validatorList = context.plugins.byType("cms-model-field-validator").reduce((acc, plugin) => {
148
+ const name = plugin.validator.name;
149
+
150
+ if (!acc[name]) {
151
+ acc[name] = [];
152
+ }
153
+
154
+ acc[name].push(plugin.validator.validate);
155
+ return acc;
156
+ }, {});
157
+ /**
158
+ * Loop through model fields and validate the corresponding data.
159
+ * Run validation only if the field has validation configured.
160
+ */
161
+
162
+ const invalidFields = [];
163
+
164
+ for (const field of contentModel.fields) {
165
+ const error = await execValidation({
166
+ contentModel,
167
+ validatorList,
168
+ field,
169
+ data,
170
+ context
171
+ });
172
+
173
+ if (!error) {
174
+ continue;
175
+ }
176
+
177
+ invalidFields.push({
178
+ fieldId: field.fieldId,
179
+ error
180
+ });
181
+ }
182
+
183
+ if (invalidFields.length > 0) {
184
+ throw new _error.default("Validation failed.", "VALIDATION_FAILED", invalidFields);
185
+ }
186
+ };
187
+
188
+ exports.validateModelEntryData = validateModelEntryData;
@@ -0,0 +1,12 @@
1
+ import { CmsEntry, CmsModel, CmsContext } from "../../../../types";
2
+ export interface MarkLockedFieldsParams {
3
+ model: CmsModel;
4
+ entry: CmsEntry;
5
+ context: CmsContext;
6
+ }
7
+ export declare const markLockedFields: (params: MarkLockedFieldsParams) => Promise<void>;
8
+ export interface MarkFieldsUnlockedParams {
9
+ context: CmsContext;
10
+ model: CmsModel;
11
+ }
12
+ export declare const markUnlockedFields: (params: MarkFieldsUnlockedParams) => Promise<void>;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.markUnlockedFields = exports.markLockedFields = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _CmsModelPlugin = require("../../CmsModelPlugin");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ const markLockedFields = async params => {
21
+ const {
22
+ model,
23
+ context
24
+ } = params;
25
+ /**
26
+ * If the model is registered via a plugin, we don't need do process anything.
27
+ */
28
+
29
+ const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
30
+
31
+ if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
32
+ return;
33
+ }
34
+
35
+ const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
36
+ const existingLockedFields = model.lockedFields || [];
37
+ const lockedFields = [];
38
+
39
+ for (const field of model.fields) {
40
+ const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.fieldId);
41
+
42
+ if (alreadyLocked) {
43
+ continue;
44
+ }
45
+
46
+ let lockedFieldData = {};
47
+ const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);
48
+
49
+ for (const plugin of lockedFieldPlugins) {
50
+ if (typeof plugin.getLockedFieldData !== "function") {
51
+ continue;
52
+ }
53
+
54
+ const data = plugin.getLockedFieldData({
55
+ field
56
+ });
57
+ lockedFieldData = _objectSpread(_objectSpread({}, lockedFieldData), data);
58
+ }
59
+
60
+ lockedFields.push(_objectSpread({
61
+ fieldId: field.fieldId,
62
+ multipleValues: field.multipleValues,
63
+ type: field.type
64
+ }, lockedFieldData));
65
+ } // no need to update anything if no locked fields were added
66
+
67
+
68
+ if (lockedFields.length === 0) {
69
+ return;
70
+ }
71
+
72
+ const newLockedFields = existingLockedFields.concat(lockedFields);
73
+
74
+ try {
75
+ await context.cms.updateModelDirect({
76
+ original: model,
77
+ model: _objectSpread(_objectSpread({}, model), {}, {
78
+ lockedFields: newLockedFields
79
+ })
80
+ });
81
+ model.lockedFields = newLockedFields;
82
+ } catch (ex) {
83
+ throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", ex);
84
+ }
85
+ };
86
+
87
+ exports.markLockedFields = markLockedFields;
88
+
89
+ const markUnlockedFields = async params => {
90
+ const {
91
+ context,
92
+ model
93
+ } = params;
94
+ /**
95
+ * If the model is registered via a plugin, we don't need do process anything.
96
+ */
97
+
98
+ const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
99
+
100
+ if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
101
+ return;
102
+ }
103
+
104
+ try {
105
+ await context.cms.updateModelDirect({
106
+ original: model,
107
+ model: _objectSpread(_objectSpread({}, model), {}, {
108
+ lockedFields: []
109
+ })
110
+ });
111
+ model.lockedFields = [];
112
+ } catch (ex) {
113
+ throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", ex);
114
+ }
115
+ };
116
+
117
+ exports.markUnlockedFields = markUnlockedFields;
@@ -0,0 +1,17 @@
1
+ import { CmsEntryContext, CmsContext, HeadlessCmsStorageOperations } from "../../../types";
2
+ import { I18NLocale } from "@webiny/api-i18n/types";
3
+ import { Tenant } from "@webiny/api-tenancy/types";
4
+ import { SecurityIdentity } from "@webiny/api-security/types";
5
+ export declare const STATUS_DRAFT = "draft";
6
+ export declare const STATUS_PUBLISHED = "published";
7
+ export declare const STATUS_UNPUBLISHED = "unpublished";
8
+ export declare const STATUS_CHANGES_REQUESTED = "changesRequested";
9
+ export declare const STATUS_REVIEW_REQUESTED = "reviewRequested";
10
+ export interface Params {
11
+ storageOperations: HeadlessCmsStorageOperations;
12
+ context: CmsContext;
13
+ getTenant: () => Tenant;
14
+ getLocale: () => I18NLocale;
15
+ getIdentity: () => SecurityIdentity;
16
+ }
17
+ export declare const createContentEntryCrud: (params: Params) => CmsEntryContext;