@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60e968001a
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.
- package/context.d.ts +5 -2
- package/context.js +63 -8
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.d.ts +2 -2
- package/crud/contentEntry/afterDelete.js +2 -2
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.d.ts +2 -2
- package/crud/contentEntry/beforeCreate.js +2 -2
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.d.ts +2 -2
- package/crud/contentEntry/beforeUpdate.js +2 -2
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +3 -7
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +10 -11
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +11 -13
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +83 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +0 -2
- package/crud/contentEntry.crud.js +253 -270
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +3 -3
- package/crud/contentModel/afterCreate.js +5 -5
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.d.ts +3 -3
- package/crud/contentModel/afterCreateFrom.js +5 -5
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.d.ts +3 -3
- package/crud/contentModel/afterDelete.js +5 -5
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.d.ts +3 -3
- package/crud/contentModel/afterUpdate.js +5 -5
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +4 -4
- package/crud/contentModel/beforeCreate.js +10 -10
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +3 -3
- package/crud/contentModel/beforeDelete.js +6 -6
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +3 -3
- package/crud/contentModel/beforeUpdate.js +5 -5
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +5 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/models.js +12 -0
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/validateModel.js +1 -1
- package/crud/contentModel/validateModelFields.js +47 -42
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +109 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +287 -211
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
- package/crud/contentModelGroup/beforeCreate.js +3 -3
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
- package/crud/contentModelGroup/beforeDelete.js +3 -3
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
- package/crud/contentModelGroup/beforeUpdate.js +2 -2
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +43 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +102 -82
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.js +3 -8
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +63 -51
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +17 -19
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +2 -2
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +59 -29
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +49 -38
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +2 -2
- package/graphql/schema/baseContentSchema.js +8 -12
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.d.ts +2 -2
- package/graphql/schema/contentEntries.js +6 -6
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +2 -2
- package/graphql/schema/contentModelGroups.js +3 -3
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +2 -2
- package/graphql/schema/contentModels.js +42 -4
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +26 -16
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +4 -18
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +11 -12
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +8 -7
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +11 -5
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +5 -9
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +3 -7
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +3 -7
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +2 -2
- package/graphql/schema/schemaPlugins.js +11 -8
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +79 -82
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +21 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +3 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +4 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +123 -73
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +38 -56
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -8
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.d.ts +7 -7
- package/modelManager/DefaultCmsModelManager.js +1 -1
- package/package.json +30 -31
- package/parameters/header.js +1 -1
- package/parameters/manual.js +7 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +17 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +38 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +6 -2
- package/plugins/CmsModelPlugin.js +18 -13
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +26 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +7 -8
- package/storage/object.js.map +1 -1
- package/types.d.ts +469 -180
- package/types.js +55 -9
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +5 -9
- package/upgrades/5.33.0/index.js.map +1 -1
- package/utils/converters/Converter.js +1 -1
- package/utils/converters/ConverterCollection.d.ts +7 -0
- package/utils/converters/ConverterCollection.js +36 -8
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +3 -7
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +75 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +4 -2
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +17 -18
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterModelFields.js +5 -9
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/permissions.js +1 -5
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +1 -1
- package/utils/renderFields.js +3 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +8 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +12 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +23 -4
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +24 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +3 -1
- package/validators/index.js.map +1 -1
- package/validators/unique.js +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -89
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createModelGroupsCrud = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _fields = require("@commodo/fields");
|
|
13
|
-
|
|
14
|
-
var _validation = require("@webiny/validation");
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
15
11
|
|
|
16
12
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
17
13
|
|
|
@@ -37,38 +33,14 @@ var _ownership = require("../utils/ownership");
|
|
|
37
33
|
|
|
38
34
|
var _access = require("../utils/access");
|
|
39
35
|
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
45
|
-
|
|
46
|
-
const CreateContentModelGroupModel = (0, _fields.withFields)({
|
|
47
|
-
name: (0, _fields.string)({
|
|
48
|
-
validation: _validation.validation.create("required,maxLength:100")
|
|
49
|
-
}),
|
|
50
|
-
slug: (0, _fields.string)({
|
|
51
|
-
validation: _validation.validation.create("maxLength:100")
|
|
52
|
-
}),
|
|
53
|
-
description: (0, _fields.string)({
|
|
54
|
-
validation: _validation.validation.create("maxLength:255")
|
|
55
|
-
}),
|
|
56
|
-
icon: (0, _fields.string)({
|
|
57
|
-
validation: _validation.validation.create("required,maxLength:255")
|
|
58
|
-
})
|
|
59
|
-
})();
|
|
60
|
-
const UpdateContentModelGroupModel = (0, _fields.withFields)({
|
|
61
|
-
name: (0, _fields.string)({
|
|
62
|
-
validation: _validation.validation.create("maxLength:100")
|
|
63
|
-
}),
|
|
64
|
-
description: (0, _fields.string)({
|
|
65
|
-
validation: _validation.validation.create("maxLength:255")
|
|
66
|
-
}),
|
|
67
|
-
icon: (0, _fields.string)({
|
|
68
|
-
validation: _validation.validation.create("maxLength:255")
|
|
69
|
-
})
|
|
70
|
-
})();
|
|
36
|
+
var _validation = require("./contentModelGroup/validation");
|
|
37
|
+
|
|
38
|
+
var _utils = require("@webiny/utils");
|
|
71
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Package mdbid does not have types.
|
|
42
|
+
*/
|
|
43
|
+
// @ts-ignore
|
|
72
44
|
const createModelGroupsCrud = params => {
|
|
73
45
|
const {
|
|
74
46
|
getTenant,
|
|
@@ -82,7 +54,7 @@ const createModelGroupsCrud = params => {
|
|
|
82
54
|
const tenant = getTenant().id;
|
|
83
55
|
const locale = getLocale().code;
|
|
84
56
|
const pluginsGroups = getGroupsAsPlugins().map(group => {
|
|
85
|
-
return
|
|
57
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
|
|
86
58
|
tenant: group.tenant || tenant,
|
|
87
59
|
locale: group.locale || locale
|
|
88
60
|
});
|
|
@@ -125,7 +97,7 @@ const createModelGroupsCrud = params => {
|
|
|
125
97
|
|
|
126
98
|
return true;
|
|
127
99
|
}).map(plugin => {
|
|
128
|
-
return
|
|
100
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugin.contentModelGroup), {}, {
|
|
129
101
|
tenant,
|
|
130
102
|
locale,
|
|
131
103
|
webinyVersion: context.WEBINY_VERSION
|
|
@@ -158,43 +130,74 @@ const createModelGroupsCrud = params => {
|
|
|
158
130
|
try {
|
|
159
131
|
return await dataLoaders.listGroups.load("listGroups");
|
|
160
132
|
} catch (ex) {
|
|
161
|
-
throw new _error.default(ex.message, ex.code || "LIST_ERROR",
|
|
133
|
+
throw new _error.default(ex.message, ex.code || "LIST_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
162
134
|
where
|
|
163
135
|
}));
|
|
164
136
|
}
|
|
165
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Create
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
const onGroupBeforeCreate = (0, _pubsub.createTopic)("cms.onGroupBeforeCreate");
|
|
144
|
+
const onGroupAfterCreate = (0, _pubsub.createTopic)("cms.onGroupAfterCreate");
|
|
145
|
+
const onGroupCreateError = (0, _pubsub.createTopic)("cms.onGroupCreateError");
|
|
146
|
+
/**
|
|
147
|
+
* Update
|
|
148
|
+
*/
|
|
166
149
|
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
150
|
+
const onGroupBeforeUpdate = (0, _pubsub.createTopic)("cms.onGroupBeforeUpdate");
|
|
151
|
+
const onGroupAfterUpdate = (0, _pubsub.createTopic)("cms.onGroupAfterUpdate");
|
|
152
|
+
const onGroupUpdateError = (0, _pubsub.createTopic)("cms.onGroupUpdateError");
|
|
153
|
+
/**
|
|
154
|
+
* Delete
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
const onGroupBeforeDelete = (0, _pubsub.createTopic)("cms.onGroupBeforeDelete");
|
|
158
|
+
const onGroupAfterDelete = (0, _pubsub.createTopic)("cms.onGroupAfterDelete");
|
|
159
|
+
const onGroupDeleteError = (0, _pubsub.createTopic)("cms.onGroupDeleteError");
|
|
173
160
|
/**
|
|
174
161
|
* We need to assign some default behaviors.
|
|
175
162
|
*/
|
|
176
163
|
|
|
177
164
|
(0, _beforeCreate.assignBeforeGroupCreate)({
|
|
178
|
-
|
|
165
|
+
onGroupBeforeCreate,
|
|
179
166
|
plugins: context.plugins,
|
|
180
167
|
storageOperations
|
|
181
168
|
});
|
|
182
169
|
(0, _beforeUpdate.assignBeforeGroupUpdate)({
|
|
183
|
-
|
|
170
|
+
onGroupBeforeUpdate,
|
|
184
171
|
plugins: context.plugins
|
|
185
172
|
});
|
|
186
173
|
(0, _beforeDelete.assignBeforeGroupDelete)({
|
|
187
|
-
|
|
174
|
+
onGroupBeforeDelete,
|
|
188
175
|
plugins: context.plugins,
|
|
189
176
|
storageOperations
|
|
190
177
|
});
|
|
191
178
|
return {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Deprecated - will be removed in 5.36.0
|
|
181
|
+
*/
|
|
182
|
+
onBeforeGroupCreate: onGroupBeforeCreate,
|
|
183
|
+
onAfterGroupCreate: onGroupAfterCreate,
|
|
184
|
+
onBeforeGroupUpdate: onGroupBeforeUpdate,
|
|
185
|
+
onAfterGroupUpdate: onGroupAfterUpdate,
|
|
186
|
+
onBeforeGroupDelete: onGroupBeforeDelete,
|
|
187
|
+
onAfterGroupDelete: onGroupAfterDelete,
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Released in 5.34.0
|
|
191
|
+
*/
|
|
192
|
+
onGroupBeforeCreate,
|
|
193
|
+
onGroupAfterCreate,
|
|
194
|
+
onGroupCreateError,
|
|
195
|
+
onGroupBeforeUpdate,
|
|
196
|
+
onGroupAfterUpdate,
|
|
197
|
+
onGroupUpdateError,
|
|
198
|
+
onGroupBeforeDelete,
|
|
199
|
+
onGroupAfterDelete,
|
|
200
|
+
onGroupDeleteError,
|
|
198
201
|
clearGroupsCache,
|
|
199
202
|
getGroup: async id => {
|
|
200
203
|
const permission = await checkPermissions("r");
|
|
@@ -212,8 +215,8 @@ const createModelGroupsCrud = params => {
|
|
|
212
215
|
locale
|
|
213
216
|
} = where || {};
|
|
214
217
|
const permission = await checkPermissions("r");
|
|
215
|
-
const response = await groupsList(
|
|
216
|
-
where:
|
|
218
|
+
const response = await groupsList((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params || {}), {}, {
|
|
219
|
+
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, where || {}), {}, {
|
|
217
220
|
tenant: tenant || getTenant().id,
|
|
218
221
|
locale: locale || getLocale().code
|
|
219
222
|
})
|
|
@@ -226,18 +229,18 @@ const createModelGroupsCrud = params => {
|
|
|
226
229
|
return (0, _access.validateGroupAccess)(context, permission, group);
|
|
227
230
|
});
|
|
228
231
|
},
|
|
229
|
-
createGroup: async
|
|
232
|
+
createGroup: async input => {
|
|
230
233
|
await checkPermissions("w");
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
const result = await (0, _validation.createGroupCreateValidation)().safeParseAsync(input);
|
|
235
|
+
|
|
236
|
+
if (!result.success) {
|
|
237
|
+
throw (0, _utils.createZodError)(result.error);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const data = result.data;
|
|
237
241
|
const identity = getIdentity();
|
|
238
242
|
const id = (0, _mdbid.default)();
|
|
239
|
-
|
|
240
|
-
const group = _objectSpread(_objectSpread({}, input), {}, {
|
|
243
|
+
const group = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
241
244
|
id,
|
|
242
245
|
tenant: getTenant().id,
|
|
243
246
|
locale: getLocale().code,
|
|
@@ -252,49 +255,56 @@ const createModelGroupsCrud = params => {
|
|
|
252
255
|
});
|
|
253
256
|
|
|
254
257
|
try {
|
|
255
|
-
await
|
|
258
|
+
await onGroupBeforeCreate.publish({
|
|
256
259
|
group
|
|
257
260
|
});
|
|
258
261
|
const result = await storageOperations.groups.create({
|
|
259
262
|
group
|
|
260
263
|
});
|
|
261
264
|
clearGroupsCache();
|
|
262
|
-
await
|
|
265
|
+
await onGroupAfterCreate.publish({
|
|
263
266
|
group: result
|
|
264
267
|
});
|
|
265
268
|
return group;
|
|
266
269
|
} catch (ex) {
|
|
267
|
-
|
|
270
|
+
await onGroupCreateError.publish({
|
|
271
|
+
input,
|
|
272
|
+
group,
|
|
273
|
+
error: ex
|
|
274
|
+
});
|
|
275
|
+
throw new _error.default(ex.message || "Could not save data model group.", ex.code || "ERROR_ON_CREATE", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
268
276
|
group,
|
|
269
277
|
input
|
|
270
278
|
}));
|
|
271
279
|
}
|
|
272
280
|
},
|
|
273
|
-
updateGroup: async (id,
|
|
281
|
+
updateGroup: async (id, input) => {
|
|
274
282
|
const permission = await checkPermissions("w");
|
|
275
283
|
const original = await groupsGet(id);
|
|
276
284
|
(0, _ownership.checkOwnership)(context, permission, original);
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
285
|
+
const result = await (0, _validation.createGroupUpdateValidation)().safeParseAsync(input);
|
|
286
|
+
|
|
287
|
+
if (!result.success) {
|
|
288
|
+
throw (0, _utils.createZodError)(result.error);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const data = result.data;
|
|
282
292
|
/**
|
|
283
293
|
* No need to continue if no values were changed
|
|
284
294
|
*/
|
|
285
295
|
|
|
286
|
-
if (Object.keys(
|
|
296
|
+
if (Object.keys(data).length === 0) {
|
|
287
297
|
return original;
|
|
288
298
|
}
|
|
289
299
|
|
|
290
|
-
const group =
|
|
300
|
+
const group = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data), {}, {
|
|
291
301
|
locale: getLocale().code,
|
|
292
302
|
tenant: getTenant().id,
|
|
293
303
|
savedOn: new Date().toISOString()
|
|
294
304
|
});
|
|
295
305
|
|
|
296
306
|
try {
|
|
297
|
-
await
|
|
307
|
+
await onGroupBeforeUpdate.publish({
|
|
298
308
|
original,
|
|
299
309
|
group
|
|
300
310
|
});
|
|
@@ -302,12 +312,18 @@ const createModelGroupsCrud = params => {
|
|
|
302
312
|
group
|
|
303
313
|
});
|
|
304
314
|
clearGroupsCache();
|
|
305
|
-
await
|
|
315
|
+
await onGroupAfterUpdate.publish({
|
|
306
316
|
original,
|
|
307
317
|
group: updatedGroup
|
|
308
318
|
});
|
|
309
319
|
return updatedGroup;
|
|
310
320
|
} catch (ex) {
|
|
321
|
+
await onGroupUpdateError.publish({
|
|
322
|
+
input,
|
|
323
|
+
original,
|
|
324
|
+
group,
|
|
325
|
+
error: ex
|
|
326
|
+
});
|
|
311
327
|
throw new _error.default(ex.message, ex.code || "UPDATE_ERROR", {
|
|
312
328
|
error: ex,
|
|
313
329
|
original,
|
|
@@ -322,18 +338,22 @@ const createModelGroupsCrud = params => {
|
|
|
322
338
|
(0, _ownership.checkOwnership)(context, permission, group);
|
|
323
339
|
|
|
324
340
|
try {
|
|
325
|
-
await
|
|
341
|
+
await onGroupBeforeDelete.publish({
|
|
326
342
|
group
|
|
327
343
|
});
|
|
328
344
|
await storageOperations.groups.delete({
|
|
329
345
|
group
|
|
330
346
|
});
|
|
331
347
|
clearGroupsCache();
|
|
332
|
-
await
|
|
348
|
+
await onGroupAfterDelete.publish({
|
|
333
349
|
group
|
|
334
350
|
});
|
|
335
351
|
} catch (ex) {
|
|
336
|
-
|
|
352
|
+
await onGroupDeleteError.publish({
|
|
353
|
+
group,
|
|
354
|
+
error: ex
|
|
355
|
+
});
|
|
356
|
+
throw new _error.default(ex.message, ex.code || "DELETE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
337
357
|
id
|
|
338
358
|
}));
|
|
339
359
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CreateContentModelGroupModel","withFields","name","string","validation","create","slug","description","icon","UpdateContentModelGroupModel","createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","context","dataLoaders","listGroups","DataLoader","tenant","id","locale","code","pluginsGroups","getGroupsAsPlugins","map","group","groups","list","where","concat","clearGroupsCache","loader","Object","values","clearAll","plugins","byType","CmsGroupPlugin","type","filter","plugin","t","l","contentModelGroup","webinyVersion","WEBINY_VERSION","checkPermissions","check","baseCheckPermissions","rwd","groupsGet","load","find","g","NotFoundError","groupsList","ex","WebinyError","message","data","onBeforeCreate","createTopic","onAfterCreate","onBeforeUpdate","onAfterUpdate","onBeforeDelete","onAfterDelete","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","onBeforeGroupCreate","onAfterGroupCreate","onBeforeGroupUpdate","onAfterGroupUpdate","onBeforeGroupDelete","onAfterGroupDelete","getGroup","permission","checkOwnership","validateGroupAccess","response","validateOwnership","createGroup","inputData","createdData","populate","toSlug","validate","input","toJSON","identity","mdbid","createdOn","Date","toISOString","savedOn","createdBy","displayName","publish","result","updateGroup","original","updatedDataJson","onlyDirty","keys","length","updatedGroup","update","error","deleteGroup","delete"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\n/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport {\n CmsGroupContext,\n CmsGroupListParams,\n CmsGroupPermission,\n CmsGroup,\n CmsContext,\n HeadlessCmsStorageOperations,\n CmsGroupCreateInput,\n BeforeGroupCreateTopicParams,\n AfterGroupCreateTopicParams,\n BeforeGroupUpdateTopicParams,\n AfterGroupUpdateTopicParams,\n BeforeGroupDeleteTopicParams,\n AfterGroupDeleteTopicParams\n} from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { assignBeforeGroupUpdate } from \"./contentModelGroup/beforeUpdate\";\nimport { assignBeforeGroupCreate } from \"./contentModelGroup/beforeCreate\";\nimport { assignBeforeGroupDelete } from \"./contentModelGroup/beforeDelete\";\nimport DataLoader from \"dataloader\";\nimport { checkPermissions as baseCheckPermissions } from \"~/utils/permissions\";\nimport { checkOwnership, validateOwnership } from \"~/utils/ownership\";\nimport { validateGroupAccess } from \"~/utils/access\";\nimport { toSlug } from \"~/utils/toSlug\";\n\nconst CreateContentModelGroupModel = withFields({\n name: string({ validation: validation.create(\"required,maxLength:100\") }),\n slug: string({ validation: validation.create(\"maxLength:100\") }),\n description: string({ validation: validation.create(\"maxLength:255\") }),\n icon: string({ validation: validation.create(\"required,maxLength:255\") })\n})();\n\nconst UpdateContentModelGroupModel = withFields({\n name: string({ validation: validation.create(\"maxLength:100\") }),\n description: string({ validation: validation.create(\"maxLength:255\") }),\n icon: string({ validation: validation.create(\"maxLength:255\") })\n})();\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const { getTenant, getIdentity, getLocale, storageOperations, context } = params;\n\n const dataLoaders = {\n listGroups: new DataLoader(async () => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n const pluginsGroups = getGroupsAsPlugins().map(group => {\n return {\n ...group,\n tenant: group.tenant || tenant,\n locale: group.locale || locale\n };\n });\n\n const groups = await storageOperations.groups.list({\n where: {\n tenant: getTenant().id,\n locale: getLocale().code\n }\n });\n\n return [groups.concat(pluginsGroups)];\n })\n };\n\n const clearGroupsCache = (): void => {\n for (const loader of Object.values(dataLoaders)) {\n loader.clearAll();\n }\n };\n\n const getGroupsAsPlugins = (): CmsGroup[] => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n return (\n context.plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n /**\n * We need to filter out groups that are not for this tenant or locale.\n * If it does not have tenant or locale define, it is for every locale and tenant\n */\n .filter(plugin => {\n const { tenant: t, locale: l } = plugin.contentModelGroup;\n if (t && t !== tenant) {\n return false;\n } else if (l && l !== locale) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant,\n locale,\n webinyVersion: context.WEBINY_VERSION\n };\n })\n );\n };\n\n const checkPermissions = (check: string): Promise<CmsGroupPermission> => {\n return baseCheckPermissions(context, \"cms.contentModelGroup\", { rwd: check });\n };\n\n const groupsGet = async (id: string) => {\n const groups = await dataLoaders.listGroups.load(\"listGroups\");\n\n const group = groups.find(g => g.id === id);\n\n if (!group) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n return group;\n };\n\n const groupsList = async (params: CmsGroupListParams) => {\n const { where } = params || {};\n\n try {\n return await dataLoaders.listGroups.load(\"listGroups\");\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code || \"LIST_ERROR\", {\n ...(ex.data || {}),\n where\n });\n }\n };\n\n const onBeforeCreate = createTopic<BeforeGroupCreateTopicParams>();\n const onAfterCreate = createTopic<AfterGroupCreateTopicParams>();\n const onBeforeUpdate = createTopic<BeforeGroupUpdateTopicParams>();\n const onAfterUpdate = createTopic<AfterGroupUpdateTopicParams>();\n const onBeforeDelete = createTopic<BeforeGroupDeleteTopicParams>();\n const onAfterDelete = createTopic<AfterGroupDeleteTopicParams>();\n\n /**\n * We need to assign some default behaviors.\n */\n assignBeforeGroupCreate({\n onBeforeCreate,\n plugins: context.plugins,\n storageOperations\n });\n assignBeforeGroupUpdate({\n onBeforeUpdate,\n plugins: context.plugins\n });\n assignBeforeGroupDelete({\n onBeforeDelete,\n plugins: context.plugins,\n storageOperations\n });\n\n return {\n onBeforeGroupCreate: onBeforeCreate,\n onAfterGroupCreate: onAfterCreate,\n onBeforeGroupUpdate: onBeforeUpdate,\n onAfterGroupUpdate: onAfterUpdate,\n onBeforeGroupDelete: onBeforeDelete,\n onAfterGroupDelete: onAfterDelete,\n clearGroupsCache,\n getGroup: async id => {\n const permission = await checkPermissions(\"r\");\n\n const group = await groupsGet(id);\n checkOwnership(context, permission, group);\n validateGroupAccess(context, permission, group);\n\n return group;\n },\n listGroups: async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n const permission = await checkPermissions(\"r\");\n\n const response = await groupsList({\n ...(params || {}),\n where: {\n ...(where || {}),\n tenant: tenant || getTenant().id,\n locale: locale || getLocale().code\n }\n });\n\n return response.filter(group => {\n if (!validateOwnership(context, permission, group)) {\n return false;\n }\n return validateGroupAccess(context, permission, group);\n });\n },\n createGroup: async inputData => {\n await checkPermissions(\"w\");\n\n const createdData = new CreateContentModelGroupModel().populate({\n ...inputData,\n slug: inputData.slug ? toSlug(inputData.slug) : \"\",\n description: inputData.description || \"\"\n });\n await createdData.validate();\n const input: CmsGroupCreateInput & { slug: string; description: string } =\n await createdData.toJSON();\n\n const identity = getIdentity();\n\n const id = mdbid();\n const group: CmsGroup = {\n ...input,\n id,\n tenant: getTenant().id,\n locale: getLocale().code,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n webinyVersion: context.WEBINY_VERSION\n };\n try {\n await onBeforeCreate.publish({\n group\n });\n\n const result = await storageOperations.groups.create({\n group\n });\n\n clearGroupsCache();\n\n await onAfterCreate.publish({\n group: result\n });\n\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not save data model group.\",\n ex.code || \"ERROR_ON_CREATE\",\n {\n ...(ex.data || {}),\n group,\n input\n }\n );\n }\n },\n updateGroup: async (id, inputData) => {\n const permission = await checkPermissions(\"w\");\n\n const original = await groupsGet(id);\n\n checkOwnership(context, permission, original);\n\n const input = new UpdateContentModelGroupModel().populate(inputData);\n await input.validate();\n\n const updatedDataJson: Partial<CmsGroup> = await input.toJSON({\n onlyDirty: true\n });\n\n /**\n * No need to continue if no values were changed\n */\n if (Object.keys(updatedDataJson).length === 0) {\n return original;\n }\n\n const group: CmsGroup = {\n ...original,\n ...updatedDataJson,\n locale: getLocale().code,\n tenant: getTenant().id,\n savedOn: new Date().toISOString()\n };\n\n try {\n await onBeforeUpdate.publish({\n original,\n group\n });\n\n const updatedGroup = await storageOperations.groups.update({\n group\n });\n clearGroupsCache();\n\n await onAfterUpdate.publish({\n original,\n group: updatedGroup\n });\n\n return updatedGroup;\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code || \"UPDATE_ERROR\", {\n error: ex,\n original,\n group,\n input\n });\n }\n },\n deleteGroup: async id => {\n const permission = await checkPermissions(\"d\");\n\n const group = await groupsGet(id);\n\n checkOwnership(context, permission, group);\n\n try {\n await onBeforeDelete.publish({\n group\n });\n\n await storageOperations.groups.delete({ group });\n clearGroupsCache();\n\n await onAfterDelete.publish({\n group\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code || \"DELETE_ERROR\", {\n ...(ex.data || {}),\n id\n });\n }\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AAKA;;AAgBA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,4BAA4B,GAAG,IAAAC,kBAAA,EAAW;EAC5CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB;EAAd,CAAP,CADsC;EAE5CC,IAAI,EAAE,IAAAH,cAAA,EAAO;IAAEC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,eAAlB;EAAd,CAAP,CAFsC;EAG5CE,WAAW,EAAE,IAAAJ,cAAA,EAAO;IAAEC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,eAAlB;EAAd,CAAP,CAH+B;EAI5CG,IAAI,EAAE,IAAAL,cAAA,EAAO;IAAEC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB;EAAd,CAAP;AAJsC,CAAX,GAArC;AAOA,MAAMI,4BAA4B,GAAG,IAAAR,kBAAA,EAAW;EA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G,QADwB;UAExB5E,KAAK,EAAEiF;QAFiB,CAAtB,CAAN;QAKA,OAAOA,YAAP;MACH,CAjBD,CAiBE,OAAOlD,EAAP,EAAW;QACT,MAAM,IAAIC,cAAJ,CAAgBD,EAAE,CAACE,OAAnB,EAA4BF,EAAE,CAACnC,IAAH,IAAW,cAAvC,EAAuD;UACzDuF,KAAK,EAAEpD,EADkD;UAEzD6C,QAFyD;UAGzD5E,KAHyD;UAIzD+D;QAJyD,CAAvD,CAAN;MAMH;IACJ,CAtJE;IAuJHqB,WAAW,EAAE,MAAM1F,EAAN,IAAY;MACrB,MAAM0D,UAAU,GAAG,MAAM/B,gBAAgB,CAAC,GAAD,CAAzC;MAEA,MAAMrB,KAAK,GAAG,MAAMyB,SAAS,CAAC/B,EAAD,CAA7B;MAEA,IAAA2D,yBAAA,EAAehE,OAAf,EAAwB+D,UAAxB,EAAoCpD,KAApC;;MAEA,IAAI;QACA,MAAMwC,cAAc,CAACiC,OAAf,CAAuB;UACzBzE;QADyB,CAAvB,CAAN;QAIA,MAAMZ,iBAAiB,CAACa,MAAlB,CAAyBoF,MAAzB,CAAgC;UAAErF;QAAF,CAAhC,CAAN;QACAK,gBAAgB;QAEhB,MAAMoC,aAAa,CAACgC,OAAd,CAAsB;UACxBzE;QADwB,CAAtB,CAAN;MAGH,CAXD,CAWE,OAAO+B,EAAP,EAAW;QACT,MAAM,IAAIC,cAAJ,CAAgBD,EAAE,CAACE,OAAnB,EAA4BF,EAAE,CAACnC,IAAH,IAAW,cAAvC,kCACEmC,EAAE,CAACG,IAAH,IAAW,EADb;UAEFxC;QAFE,GAAN;MAIH;;MAED,OAAO,IAAP;IACH;EAjLE,CAAP;AAmLH,CAxSM"}
|
|
1
|
+
{"version":3,"names":["createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","context","dataLoaders","listGroups","DataLoader","tenant","id","locale","code","pluginsGroups","getGroupsAsPlugins","map","group","groups","list","where","concat","clearGroupsCache","loader","Object","values","clearAll","plugins","byType","CmsGroupPlugin","type","filter","plugin","t","l","contentModelGroup","webinyVersion","WEBINY_VERSION","checkPermissions","check","baseCheckPermissions","rwd","groupsGet","load","find","g","NotFoundError","groupsList","ex","WebinyError","message","data","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","onBeforeGroupCreate","onAfterGroupCreate","onBeforeGroupUpdate","onAfterGroupUpdate","onBeforeGroupDelete","onAfterGroupDelete","getGroup","permission","checkOwnership","validateGroupAccess","response","validateOwnership","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","identity","mdbid","createdOn","Date","toISOString","savedOn","createdBy","displayName","publish","create","updateGroup","original","createGroupUpdateValidation","keys","length","updatedGroup","update","deleteGroup","delete"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport {\n CmsGroupContext,\n CmsGroupListParams,\n CmsGroupPermission,\n CmsGroup,\n CmsContext,\n HeadlessCmsStorageOperations,\n OnGroupBeforeCreateTopicParams,\n OnGroupAfterCreateTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupAfterDeleteTopicParams,\n OnGroupCreateErrorTopicParams,\n OnGroupUpdateErrorTopicParams,\n OnGroupDeleteErrorTopicParams\n} from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { assignBeforeGroupUpdate } from \"./contentModelGroup/beforeUpdate\";\nimport { assignBeforeGroupCreate } from \"./contentModelGroup/beforeCreate\";\nimport { assignBeforeGroupDelete } from \"./contentModelGroup/beforeDelete\";\nimport DataLoader from \"dataloader\";\nimport { checkPermissions as baseCheckPermissions } from \"~/utils/permissions\";\nimport { checkOwnership, validateOwnership } from \"~/utils/ownership\";\nimport { validateGroupAccess } from \"~/utils/access\";\nimport {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError } from \"@webiny/utils\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const { getTenant, getIdentity, getLocale, storageOperations, context } = params;\n\n const dataLoaders = {\n listGroups: new DataLoader(async () => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n const pluginsGroups = getGroupsAsPlugins().map(group => {\n return {\n ...group,\n tenant: group.tenant || tenant,\n locale: group.locale || locale\n };\n });\n\n const groups = await storageOperations.groups.list({\n where: {\n tenant: getTenant().id,\n locale: getLocale().code\n }\n });\n\n return [groups.concat(pluginsGroups)];\n })\n };\n\n const clearGroupsCache = (): void => {\n for (const loader of Object.values(dataLoaders)) {\n loader.clearAll();\n }\n };\n\n const getGroupsAsPlugins = (): CmsGroup[] => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n return (\n context.plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n /**\n * We need to filter out groups that are not for this tenant or locale.\n * If it does not have tenant or locale define, it is for every locale and tenant\n */\n .filter(plugin => {\n const { tenant: t, locale: l } = plugin.contentModelGroup;\n if (t && t !== tenant) {\n return false;\n } else if (l && l !== locale) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant,\n locale,\n webinyVersion: context.WEBINY_VERSION\n };\n })\n );\n };\n\n const checkPermissions = (check: string): Promise<CmsGroupPermission> => {\n return baseCheckPermissions(context, \"cms.contentModelGroup\", { rwd: check });\n };\n\n const groupsGet = async (id: string) => {\n const groups = await dataLoaders.listGroups.load(\"listGroups\");\n\n const group = groups.find(g => g.id === id);\n\n if (!group) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n return group;\n };\n\n const groupsList = async (params: CmsGroupListParams) => {\n const { where } = params || {};\n\n try {\n return await dataLoaders.listGroups.load(\"listGroups\");\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code || \"LIST_ERROR\", {\n ...(ex.data || {}),\n where\n });\n }\n };\n\n /**\n * Create\n */\n const onGroupBeforeCreate =\n createTopic<OnGroupBeforeCreateTopicParams>(\"cms.onGroupBeforeCreate\");\n const onGroupAfterCreate = createTopic<OnGroupAfterCreateTopicParams>(\"cms.onGroupAfterCreate\");\n const onGroupCreateError = createTopic<OnGroupCreateErrorTopicParams>(\"cms.onGroupCreateError\");\n /**\n * Update\n */\n const onGroupBeforeUpdate =\n createTopic<OnGroupBeforeUpdateTopicParams>(\"cms.onGroupBeforeUpdate\");\n const onGroupAfterUpdate = createTopic<OnGroupAfterUpdateTopicParams>(\"cms.onGroupAfterUpdate\");\n const onGroupUpdateError = createTopic<OnGroupUpdateErrorTopicParams>(\"cms.onGroupUpdateError\");\n /**\n * Delete\n */\n const onGroupBeforeDelete =\n createTopic<OnGroupBeforeDeleteTopicParams>(\"cms.onGroupBeforeDelete\");\n const onGroupAfterDelete = createTopic<OnGroupAfterDeleteTopicParams>(\"cms.onGroupAfterDelete\");\n const onGroupDeleteError = createTopic<OnGroupDeleteErrorTopicParams>(\"cms.onGroupDeleteError\");\n\n /**\n * We need to assign some default behaviors.\n */\n assignBeforeGroupCreate({\n onGroupBeforeCreate,\n plugins: context.plugins,\n storageOperations\n });\n assignBeforeGroupUpdate({\n onGroupBeforeUpdate,\n plugins: context.plugins\n });\n assignBeforeGroupDelete({\n onGroupBeforeDelete,\n plugins: context.plugins,\n storageOperations\n });\n\n return {\n /**\n * Deprecated - will be removed in 5.36.0\n */\n onBeforeGroupCreate: onGroupBeforeCreate,\n onAfterGroupCreate: onGroupAfterCreate,\n onBeforeGroupUpdate: onGroupBeforeUpdate,\n onAfterGroupUpdate: onGroupAfterUpdate,\n onBeforeGroupDelete: onGroupBeforeDelete,\n onAfterGroupDelete: onGroupAfterDelete,\n /**\n * Released in 5.34.0\n */\n onGroupBeforeCreate,\n onGroupAfterCreate,\n onGroupCreateError,\n onGroupBeforeUpdate,\n onGroupAfterUpdate,\n onGroupUpdateError,\n onGroupBeforeDelete,\n onGroupAfterDelete,\n onGroupDeleteError,\n clearGroupsCache,\n getGroup: async id => {\n const permission = await checkPermissions(\"r\");\n\n const group = await groupsGet(id);\n checkOwnership(context, permission, group);\n validateGroupAccess(context, permission, group);\n\n return group;\n },\n listGroups: async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n const permission = await checkPermissions(\"r\");\n\n const response = await groupsList({\n ...(params || {}),\n where: {\n ...(where || {}),\n tenant: tenant || getTenant().id,\n locale: locale || getLocale().code\n }\n });\n\n return response.filter(group => {\n if (!validateOwnership(context, permission, group)) {\n return false;\n }\n return validateGroupAccess(context, permission, group);\n });\n },\n createGroup: async input => {\n await checkPermissions(\"w\");\n\n const result = await createGroupCreateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n const identity = getIdentity();\n\n const id = mdbid();\n const group: CmsGroup = {\n ...data,\n id,\n tenant: getTenant().id,\n locale: getLocale().code,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n webinyVersion: context.WEBINY_VERSION\n };\n try {\n await onGroupBeforeCreate.publish({\n group\n });\n\n const result = await storageOperations.groups.create({\n group\n });\n\n clearGroupsCache();\n\n await onGroupAfterCreate.publish({\n group: result\n });\n\n return group;\n } catch (ex) {\n await onGroupCreateError.publish({\n input,\n group,\n error: ex\n });\n throw new WebinyError(\n ex.message || \"Could not save data model group.\",\n ex.code || \"ERROR_ON_CREATE\",\n {\n ...(ex.data || {}),\n group,\n input\n }\n );\n }\n },\n updateGroup: async (id, input) => {\n const permission = await checkPermissions(\"w\");\n\n const original = await groupsGet(id);\n\n checkOwnership(context, permission, original);\n\n const result = await createGroupUpdateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n /**\n * No need to continue if no values were changed\n */\n if (Object.keys(data).length === 0) {\n return original;\n }\n\n const group: CmsGroup = {\n ...original,\n ...data,\n locale: getLocale().code,\n tenant: getTenant().id,\n savedOn: new Date().toISOString()\n };\n\n try {\n await onGroupBeforeUpdate.publish({\n original,\n group\n });\n\n const updatedGroup = await storageOperations.groups.update({\n group\n });\n clearGroupsCache();\n\n await onGroupAfterUpdate.publish({\n original,\n group: updatedGroup\n });\n\n return updatedGroup;\n } catch (ex) {\n await onGroupUpdateError.publish({\n input,\n original,\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"UPDATE_ERROR\", {\n error: ex,\n original,\n group,\n input\n });\n }\n },\n deleteGroup: async id => {\n const permission = await checkPermissions(\"d\");\n\n const group = await groupsGet(id);\n\n checkOwnership(context, permission, group);\n\n try {\n await onGroupBeforeDelete.publish({\n group\n });\n\n await storageOperations.groups.delete({ group });\n clearGroupsCache();\n\n await onGroupAfterDelete.publish({\n group\n });\n } catch (ex) {\n await onGroupDeleteError.publish({\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"DELETE_ERROR\", {\n ...(ex.data || {}),\n id\n });\n }\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAIA;;AAkBA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIA;;AAxCA;AACA;A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AGH,CAXD,CAWE,OAAO+B,EAAP,EAAW;QACT,MAAMa,kBAAkB,CAACgC,OAAnB,CAA2B;UAC7B5E,KAD6B;UAE7BmE,KAAK,EAAEpC;QAFsB,CAA3B,CAAN;QAIA,MAAM,IAAIC,cAAJ,CAAgBD,EAAE,CAACE,OAAnB,EAA4BF,EAAE,CAACnC,IAAH,IAAW,cAAvC,8DACEmC,EAAE,CAACG,IAAH,IAAW,EADb;UAEFxC;QAFE,GAAN;MAIH;;MAED,OAAO,IAAP;IACH;EA7ME,CAAP;AA+MH,CAnVM"}
|
package/crud/settings.crud.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSettingsCrud = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _permissions = require("../utils/permissions");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
const createSettingsCrud = params => {
|
|
19
15
|
const {
|
|
20
16
|
storageOperations,
|
|
@@ -40,8 +36,7 @@ const createSettingsCrud = params => {
|
|
|
40
36
|
tenant: getTenant().id,
|
|
41
37
|
locale: getLocale().code
|
|
42
38
|
});
|
|
43
|
-
|
|
44
|
-
const settings = _objectSpread(_objectSpread({}, original || {}), {}, {
|
|
39
|
+
const settings = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original || {}), {}, {
|
|
45
40
|
contentModelLastChange: new Date(),
|
|
46
41
|
tenant: getTenant().id,
|
|
47
42
|
locale: getLocale().code
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSettingsCrud","params","storageOperations","context","getTenant","getLocale","checkPermissions","baseCheckPermissions","getSettings","settings","get","tenant","id","locale","code","updateModelLastChange","original","contentModelLastChange","Date","create","update","getModelLastChange","ex","console","log","error","message","data"],"sources":["settings.crud.ts"],"sourcesContent":["import {\n CmsContext,\n CmsSettingsPermission,\n CmsSettings,\n HeadlessCmsStorageOperations,\n CmsSettingsContext\n} from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { checkPermissions as baseCheckPermissions } from \"~/utils/permissions\";\n\nexport interface CreateSettingsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n}\nexport const createSettingsCrud = (params: CreateSettingsCrudParams): CmsSettingsContext => {\n const { storageOperations, context, getTenant, getLocale } = params;\n\n const checkPermissions = (): Promise<CmsSettingsPermission> => {\n return baseCheckPermissions(context, \"cms.settings\");\n };\n\n return {\n getSettings: async (): Promise<CmsSettings | null> => {\n await checkPermissions();\n return await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n },\n updateModelLastChange: async (): Promise<void> => {\n const original = await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n\n const settings: CmsSettings = {\n ...(original || {}),\n contentModelLastChange: new Date(),\n tenant: getTenant().id,\n locale: getLocale().code\n };\n\n if (!original) {\n await storageOperations.settings.create({ settings });\n return;\n }\n\n await storageOperations.settings.update({\n settings\n });\n },\n getModelLastChange: async (): Promise<Date> => {\n try {\n const settings = await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n if (!settings?.contentModelLastChange) {\n return new Date();\n }\n return settings.contentModelLastChange;\n } catch (ex) {\n console.log({\n error: {\n message: ex.message,\n code: ex.code || \"COULD_NOT_FETCH_CONTENT_MODEL_LAST_CHANGE\",\n data: ex\n }\n });\n }\n return new Date();\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AASA
|
|
1
|
+
{"version":3,"names":["createSettingsCrud","params","storageOperations","context","getTenant","getLocale","checkPermissions","baseCheckPermissions","getSettings","settings","get","tenant","id","locale","code","updateModelLastChange","original","contentModelLastChange","Date","create","update","getModelLastChange","ex","console","log","error","message","data"],"sources":["settings.crud.ts"],"sourcesContent":["import {\n CmsContext,\n CmsSettingsPermission,\n CmsSettings,\n HeadlessCmsStorageOperations,\n CmsSettingsContext\n} from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { checkPermissions as baseCheckPermissions } from \"~/utils/permissions\";\n\nexport interface CreateSettingsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n}\nexport const createSettingsCrud = (params: CreateSettingsCrudParams): CmsSettingsContext => {\n const { storageOperations, context, getTenant, getLocale } = params;\n\n const checkPermissions = (): Promise<CmsSettingsPermission> => {\n return baseCheckPermissions(context, \"cms.settings\");\n };\n\n return {\n getSettings: async (): Promise<CmsSettings | null> => {\n await checkPermissions();\n return await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n },\n updateModelLastChange: async (): Promise<void> => {\n const original = await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n\n const settings: CmsSettings = {\n ...(original || {}),\n contentModelLastChange: new Date(),\n tenant: getTenant().id,\n locale: getLocale().code\n };\n\n if (!original) {\n await storageOperations.settings.create({ settings });\n return;\n }\n\n await storageOperations.settings.update({\n settings\n });\n },\n getModelLastChange: async (): Promise<Date> => {\n try {\n const settings = await storageOperations.settings.get({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n if (!settings?.contentModelLastChange) {\n return new Date();\n }\n return settings.contentModelLastChange;\n } catch (ex) {\n console.log({\n error: {\n message: ex.message,\n code: ex.code || \"COULD_NOT_FETCH_CONTENT_MODEL_LAST_CHANGE\",\n data: ex\n }\n });\n }\n return new Date();\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AASA;;AAQO,MAAMA,kBAAkB,GAAIC,MAAD,IAA0D;EACxF,MAAM;IAAEC,iBAAF;IAAqBC,OAArB;IAA8BC,SAA9B;IAAyCC;EAAzC,IAAuDJ,MAA7D;;EAEA,MAAMK,gBAAgB,GAAG,MAAsC;IAC3D,OAAO,IAAAC,6BAAA,EAAqBJ,OAArB,EAA8B,cAA9B,CAAP;EACH,CAFD;;EAIA,OAAO;IACHK,WAAW,EAAE,YAAyC;MAClD,MAAMF,gBAAgB,EAAtB;MACA,OAAO,MAAMJ,iBAAiB,CAACO,QAAlB,CAA2BC,GAA3B,CAA+B;QACxCC,MAAM,EAAEP,SAAS,GAAGQ,EADoB;QAExCC,MAAM,EAAER,SAAS,GAAGS;MAFoB,CAA/B,CAAb;IAIH,CAPE;IAQHC,qBAAqB,EAAE,YAA2B;MAC9C,MAAMC,QAAQ,GAAG,MAAMd,iBAAiB,CAACO,QAAlB,CAA2BC,GAA3B,CAA+B;QAClDC,MAAM,EAAEP,SAAS,GAAGQ,EAD8B;QAElDC,MAAM,EAAER,SAAS,GAAGS;MAF8B,CAA/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