@webiny/api-headless-cms 5.37.8 → 5.38.0-beta.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.
- package/constants.js +3 -1
- package/context.js +10 -17
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +3 -1
- package/crud/contentEntry/beforeCreate.js +3 -1
- package/crud/contentEntry/beforeUpdate.js +3 -1
- package/crud/contentEntry/entryDataValidation.d.ts +4 -2
- package/crud/contentEntry/entryDataValidation.js +220 -47
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +3 -1
- package/crud/contentEntry/referenceFieldsMapping.d.ts +6 -0
- package/crud/contentEntry/referenceFieldsMapping.js +118 -97
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +5 -3
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.js +68 -64
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +1 -1
- package/crud/contentModel/beforeCreate.js +11 -9
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +3 -1
- package/crud/contentModel/beforeUpdate.d.ts +1 -1
- package/crud/contentModel/beforeUpdate.js +3 -6
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.js +3 -1
- package/crud/contentModel/contentModelManagerFactory.js +3 -1
- package/crud/contentModel/createFieldStorageId.js +3 -1
- package/crud/contentModel/defaultFields.js +3 -1
- package/crud/contentModel/ensureTypeTag.d.ts +5 -0
- package/crud/contentModel/ensureTypeTag.js +21 -0
- package/crud/contentModel/ensureTypeTag.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.js +3 -1
- package/crud/contentModel/fields/imageField.js +3 -1
- package/crud/contentModel/fields/titleField.js +3 -1
- package/crud/contentModel/listModelsFromDatabase.d.ts +10 -0
- package/crud/contentModel/listModelsFromDatabase.js +39 -0
- package/crud/contentModel/listModelsFromDatabase.js.map +1 -0
- package/crud/contentModel/validate/endingAllowed.js +3 -1
- package/crud/contentModel/validate/isModelEndingAllowed.js +4 -2
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -1
- package/crud/contentModel/validate/modelId.js +3 -1
- package/crud/contentModel/validate/pluralApiName.js +3 -1
- package/crud/contentModel/validate/singularApiName.js +3 -1
- package/crud/contentModel/validateModel.js +3 -1
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +3 -1
- package/crud/contentModel/validation.d.ts +339 -58
- package/crud/contentModel/validation.js +71 -11
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +80 -156
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +1 -1
- package/crud/contentModelGroup/beforeCreate.js +15 -1
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +3 -1
- package/crud/contentModelGroup/beforeUpdate.js +3 -1
- package/crud/contentModelGroup/listGroupsFromDatabase.d.ts +8 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js +22 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js.map +1 -0
- package/crud/contentModelGroup/validation.d.ts +9 -6
- package/crud/contentModelGroup/validation.js +5 -2
- package/crud/contentModelGroup/validation.js.map +1 -1
- package/crud/contentModelGroup.crud.js +89 -110
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/system.crud.js +4 -7
- package/crud/system.crud.js.map +1 -1
- package/export/crud/exporting.d.ts +3 -0
- package/export/crud/exporting.js +50 -0
- package/export/crud/exporting.js.map +1 -0
- package/export/crud/importing.d.ts +3 -0
- package/export/crud/importing.js +79 -0
- package/export/crud/importing.js.map +1 -0
- package/export/crud/imports/importData.d.ts +14 -0
- package/export/crud/imports/importData.js +25 -0
- package/export/crud/imports/importData.js.map +1 -0
- package/export/crud/imports/importGroups.d.ts +8 -0
- package/export/crud/imports/importGroups.js +99 -0
- package/export/crud/imports/importGroups.js.map +1 -0
- package/export/crud/imports/importModels.d.ts +8 -0
- package/export/crud/imports/importModels.js +134 -0
- package/export/crud/imports/importModels.js.map +1 -0
- package/export/crud/imports/validateGroups.d.ts +8 -0
- package/export/crud/imports/validateGroups.js +106 -0
- package/export/crud/imports/validateGroups.js.map +1 -0
- package/export/crud/imports/validateInput.d.ts +19 -0
- package/export/crud/imports/validateInput.js +49 -0
- package/export/crud/imports/validateInput.js.map +1 -0
- package/export/crud/imports/validateModels.d.ts +9 -0
- package/export/crud/imports/validateModels.js +204 -0
- package/export/crud/imports/validateModels.js.map +1 -0
- package/export/crud/index.d.ts +4 -0
- package/export/crud/index.js +15 -0
- package/export/crud/index.js.map +1 -0
- package/export/crud/sanitize.d.ts +4 -0
- package/export/crud/sanitize.js +35 -0
- package/export/crud/sanitize.js.map +1 -0
- package/export/graphql/index.d.ts +3 -0
- package/export/graphql/index.js +188 -0
- package/export/graphql/index.js.map +1 -0
- package/export/index.d.ts +2 -0
- package/export/index.js +29 -0
- package/export/index.js.map +1 -0
- package/export/types.d.ts +111 -0
- package/export/types.js +22 -0
- package/export/types.js.map +1 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +3 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +3 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +3 -1
- package/fieldConverters/index.js +3 -1
- package/graphql/buildSchemaPlugins.js +3 -1
- package/graphql/checkEndpointAccess.js +3 -1
- package/graphql/createExecutableSchema.js +3 -1
- package/graphql/createRequestBody.js +3 -1
- package/graphql/formatErrorPayload.js +3 -1
- package/graphql/generateSchema.js +3 -1
- package/graphql/getSchema.d.ts +0 -1
- package/graphql/getSchema.js +23 -13
- package/graphql/getSchema.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +3 -1
- package/graphql/handleRequest.js +3 -5
- package/graphql/handleRequest.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +4 -2
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +3 -1
- package/graphql/schema/baseSchema.d.ts +2 -3
- package/graphql/schema/baseSchema.js +58 -2
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +4 -2
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +4 -1
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +5 -5
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +3 -1
- package/graphql/schema/createFieldTypePluginRecords.js +3 -1
- package/graphql/schema/createManageResolvers.js +7 -1
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +8 -4
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -1
- package/graphql/schema/createReadResolvers.js +3 -1
- package/graphql/schema/createReadSDL.js +3 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +3 -1
- package/graphql/schema/resolvers/manage/resolveCreate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +3 -1
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +3 -1
- package/graphql/schema/resolvers/manage/resolveList.js +3 -1
- package/graphql/schema/resolvers/manage/resolveMove.js +3 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveValidate.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js +20 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveGet.js +3 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -1
- package/graphql/schema/resolvers/read/resolveGet.js +3 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -1
- package/graphql/schema/schemaPlugins.js +3 -1
- package/graphql/system.js +3 -1
- package/graphqlFields/boolean.js +3 -1
- package/graphqlFields/datetime.js +4 -3
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +29 -6
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +3 -1
- package/graphqlFields/dynamicZone/index.js +3 -1
- package/graphqlFields/file.js +3 -1
- package/graphqlFields/helpers.d.ts +0 -1
- package/graphqlFields/helpers.js +6 -18
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +3 -1
- package/graphqlFields/longText.js +14 -3
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +3 -1
- package/graphqlFields/object.js +5 -17
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +4 -2
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +3 -1
- package/graphqlFields/text.js +3 -1
- package/index.d.ts +1 -1
- package/index.js +5 -2
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +3 -1
- package/modelManager/index.js +3 -1
- package/package.json +18 -19
- package/parameters/context.js +3 -1
- package/parameters/header.js +3 -1
- package/parameters/index.js +3 -1
- package/parameters/manual.js +3 -1
- package/parameters/path.js +3 -1
- package/plugins/CmsGraphQLSchemaPlugin.js +3 -1
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +3 -1
- package/plugins/CmsGroupPlugin.d.ts +6 -3
- package/plugins/CmsGroupPlugin.js +7 -2
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +3 -1
- package/plugins/CmsModelPlugin.d.ts +2 -2
- package/plugins/CmsModelPlugin.js +6 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +3 -1
- package/plugins/StorageOperationsCmsModelPlugin.js +3 -1
- package/plugins/StorageTransformPlugin.js +3 -1
- package/plugins/index.js +3 -1
- package/storage/default.js +3 -1
- package/storage/object.js +3 -1
- package/types.d.ts +62 -230
- package/types.js +3 -17
- package/types.js.map +1 -1
- package/utils/access.js +3 -1
- package/utils/caching/Cache.d.ts +2 -0
- package/utils/caching/Cache.js +53 -0
- package/utils/caching/Cache.js.map +1 -0
- package/utils/caching/CacheKey.d.ts +3 -0
- package/utils/caching/CacheKey.js +41 -0
- package/utils/caching/CacheKey.js.map +1 -0
- package/utils/caching/index.d.ts +2 -0
- package/utils/caching/index.js +29 -0
- package/utils/caching/index.js.map +1 -0
- package/utils/caching/types.d.ts +9 -0
- package/utils/caching/types.js +7 -0
- package/utils/caching/types.js.map +1 -0
- package/utils/converters/Converter.js +3 -1
- package/utils/converters/ConverterCollection.js +3 -1
- package/utils/converters/valueKeyStorageConverter.js +3 -1
- package/utils/createTypeFromFields.js +6 -1
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.js +3 -1
- package/utils/entryStorage.js +3 -1
- package/utils/filterAsync.js +3 -1
- package/utils/getBaseFieldType.js +3 -1
- package/utils/getEntryDescription.js +3 -1
- package/utils/getEntryImage.js +3 -1
- package/utils/getEntryTitle.js +3 -1
- package/utils/getSchemaFromFieldPlugins.js +3 -1
- package/utils/incrementEntryIdVersion.js +3 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/permissions/EntriesPermissions.js +3 -1
- package/utils/permissions/ModelGroupsPermissions.js +3 -1
- package/utils/permissions/ModelsPermissions.js +3 -1
- package/utils/renderFields.js +3 -1
- package/utils/renderGetFilterFields.js +3 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderListFilterFields.js +3 -1
- package/utils/renderSortEnum.js +3 -1
- package/utils/toSlug.js +3 -1
- package/validators/dateGte.js +3 -1
- package/validators/dateLte.js +3 -1
- package/validators/gte.js +3 -1
- package/validators/in.js +3 -1
- package/validators/index.js +4 -3
- package/validators/index.js.map +1 -1
- package/validators/lte.js +3 -1
- package/validators/maxLength.js +3 -1
- package/validators/minLength.js +3 -1
- package/validators/pattern.js +3 -1
- package/validators/patternPlugins/email.js +3 -1
- package/validators/patternPlugins/index.js +3 -1
- package/validators/patternPlugins/lowerCase.js +3 -1
- package/validators/patternPlugins/lowerCaseSpace.js +3 -1
- package/validators/patternPlugins/upperCase.js +3 -1
- package/validators/patternPlugins/upperCaseSpace.js +3 -1
- package/validators/patternPlugins/url.js +3 -1
- package/validators/required.js +3 -1
- package/validators/timeGte.js +3 -1
- package/validators/timeLte.js +3 -1
- package/validators/unique.js +4 -2
- package/validators/unique.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +0 -8
- package/crud/contentModel/afterCreate.js +0 -16
- package/crud/contentModel/afterCreate.js.map +0 -1
- package/crud/contentModel/afterCreateFrom.d.ts +0 -8
- package/crud/contentModel/afterCreateFrom.js +0 -16
- package/crud/contentModel/afterCreateFrom.js.map +0 -1
- package/crud/contentModel/afterDelete.d.ts +0 -8
- package/crud/contentModel/afterDelete.js +0 -16
- package/crud/contentModel/afterDelete.js.map +0 -1
- package/crud/contentModel/afterUpdate.d.ts +0 -8
- package/crud/contentModel/afterUpdate.js +0 -16
- package/crud/contentModel/afterUpdate.js.map +0 -1
- package/crud/contentModel/validateLayout.d.ts +0 -2
- package/crud/contentModel/validateLayout.js +0 -28
- package/crud/contentModel/validateLayout.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -12
- package/crud/settings.crud.js +0 -62
- package/crud/settings.crud.js.map +0 -1
- package/utils/permissions/SettingsPermissions.d.ts +0 -4
- package/utils/permissions/SettingsPermissions.js +0 -9
- package/utils/permissions/SettingsPermissions.js.map +0 -1
- package/validators/dynamicZone.d.ts +0 -2
- package/validators/dynamicZone.js +0 -20
- package/validators/dynamicZone.js.map +0 -1
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createModelGroupsCrud = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
10
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
12
10
|
var _CmsGroupPlugin = require("../plugins/CmsGroupPlugin");
|
|
13
11
|
var _pubsub = require("@webiny/pubsub");
|
|
14
12
|
var _beforeUpdate = require("./contentModelGroup/beforeUpdate");
|
|
@@ -17,6 +15,9 @@ var _beforeDelete = require("./contentModelGroup/beforeDelete");
|
|
|
17
15
|
var _validation = require("./contentModelGroup/validation");
|
|
18
16
|
var _utils = require("@webiny/utils");
|
|
19
17
|
var _filterAsync = require("../utils/filterAsync");
|
|
18
|
+
var _utils2 = require("../utils");
|
|
19
|
+
var _listGroupsFromDatabase = require("./contentModelGroup/listGroupsFromDatabase");
|
|
20
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
20
21
|
const createModelGroupsCrud = params => {
|
|
21
22
|
const {
|
|
22
23
|
getTenant,
|
|
@@ -26,72 +27,86 @@ const createModelGroupsCrud = params => {
|
|
|
26
27
|
modelGroupsPermissions,
|
|
27
28
|
context
|
|
28
29
|
} = params;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const listAllGroupsCache = (0, _utils2.createMemoryCache)();
|
|
31
|
+
const listPluginGroupsCache = (0, _utils2.createMemoryCache)();
|
|
32
|
+
const clearGroupsCache = () => {
|
|
33
|
+
listPluginGroupsCache.clear();
|
|
34
|
+
listAllGroupsCache.clear();
|
|
35
|
+
};
|
|
36
|
+
const fetchPluginGroups = (tenant, locale) => {
|
|
37
|
+
const pluginGroups = context.plugins.byType(_CmsGroupPlugin.CmsGroupPlugin.type);
|
|
38
|
+
const cacheKey = (0, _utils2.createCacheKey)({
|
|
39
|
+
tenant,
|
|
40
|
+
locale,
|
|
41
|
+
groups: pluginGroups.map(({
|
|
42
|
+
contentModelGroup: group
|
|
43
|
+
}) => {
|
|
44
|
+
return `${group.id}#${group.slug}#${group.savedOn || "unknown"}`;
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
return listPluginGroupsCache.getOrSet(cacheKey, () => {
|
|
48
|
+
return pluginGroups
|
|
49
|
+
/**
|
|
50
|
+
* We need to filter out groups that are not for this tenant or locale.
|
|
51
|
+
* If it does not have tenant or locale define, it is for every locale and tenant
|
|
52
|
+
*/.filter(plugin => {
|
|
53
|
+
const {
|
|
54
|
+
tenant: t,
|
|
55
|
+
locale: l
|
|
56
|
+
} = plugin.contentModelGroup;
|
|
57
|
+
if (t && t !== tenant) {
|
|
58
|
+
return false;
|
|
59
|
+
} else if (l && l !== locale) {
|
|
60
|
+
return false;
|
|
43
61
|
}
|
|
62
|
+
return true;
|
|
63
|
+
}).map(plugin => {
|
|
64
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugin.contentModelGroup), {}, {
|
|
65
|
+
tenant,
|
|
66
|
+
locale,
|
|
67
|
+
webinyVersion: context.WEBINY_VERSION
|
|
68
|
+
});
|
|
44
69
|
});
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
};
|
|
48
|
-
const listGroupsCache = new Map();
|
|
49
|
-
const clearGroupsCache = () => {
|
|
50
|
-
for (const loader of Object.values(dataLoaders)) {
|
|
51
|
-
loader.clearAll();
|
|
52
|
-
}
|
|
70
|
+
});
|
|
53
71
|
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
return context.plugins.byType(_CmsGroupPlugin.CmsGroupPlugin.type)
|
|
72
|
+
const fetchGroups = async (tenant, locale) => {
|
|
73
|
+
var _getIdentity;
|
|
74
|
+
const pluginGroups = fetchPluginGroups(tenant, locale);
|
|
58
75
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
* Maybe we can cache based on permissions, not the identity id?
|
|
77
|
+
*
|
|
78
|
+
* TODO: @adrian please check if possible.
|
|
79
|
+
*/
|
|
80
|
+
const cacheKey = (0, _utils2.createCacheKey)({
|
|
81
|
+
tenant,
|
|
82
|
+
locale,
|
|
83
|
+
identity: context.security.isAuthorizationEnabled() ? (_getIdentity = getIdentity()) === null || _getIdentity === void 0 ? void 0 : _getIdentity.id : undefined,
|
|
84
|
+
groups: pluginGroups.map(group => {
|
|
85
|
+
return `${group.id}#${group.slug}#${group.savedOn || "unknown"}`;
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
return listAllGroupsCache.getOrSet(cacheKey, async () => {
|
|
89
|
+
const databaseGroups = await (0, _listGroupsFromDatabase.listGroupsFromDatabase)({
|
|
90
|
+
storageOperations,
|
|
74
91
|
tenant,
|
|
75
|
-
locale
|
|
76
|
-
|
|
92
|
+
locale
|
|
93
|
+
});
|
|
94
|
+
const groups = databaseGroups.concat(pluginGroups);
|
|
95
|
+
return (0, _filterAsync.filterAsync)(groups, async group => {
|
|
96
|
+
const ownsGroup = await modelGroupsPermissions.ensure({
|
|
97
|
+
owns: group.createdBy
|
|
98
|
+
}, {
|
|
99
|
+
throw: false
|
|
100
|
+
});
|
|
101
|
+
if (!ownsGroup) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return await modelGroupsPermissions.canAccessGroup({
|
|
105
|
+
group
|
|
106
|
+
});
|
|
77
107
|
});
|
|
78
108
|
});
|
|
79
109
|
};
|
|
80
|
-
const getGroupViaDataLoader = async id => {
|
|
81
|
-
const groups = await dataLoaders.listGroups.load("listGroups");
|
|
82
|
-
const group = groups.find(g => g.id === id);
|
|
83
|
-
if (!group) {
|
|
84
|
-
throw new _handlerGraphql.NotFoundError(`Cms Group "${id}" was not found!`);
|
|
85
|
-
}
|
|
86
|
-
return group;
|
|
87
|
-
};
|
|
88
|
-
const listGroupsViaDataLoader = async () => {
|
|
89
|
-
try {
|
|
90
|
-
return await dataLoaders.listGroups.load("listGroups");
|
|
91
|
-
} catch (ex) {
|
|
92
|
-
throw new _error.default(ex.message, ex.code || "LIST_ERROR", (0, _objectSpread2.default)({}, ex.data || {}));
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
110
|
|
|
96
111
|
/**
|
|
97
112
|
* Create
|
|
@@ -136,7 +151,13 @@ const createModelGroupsCrud = params => {
|
|
|
136
151
|
await modelGroupsPermissions.ensure({
|
|
137
152
|
rwd: "r"
|
|
138
153
|
});
|
|
139
|
-
const
|
|
154
|
+
const groups = await context.security.withoutAuthorization(async () => {
|
|
155
|
+
return fetchGroups(getTenant().id, getLocale().code);
|
|
156
|
+
});
|
|
157
|
+
const group = groups.find(group => group.id === id);
|
|
158
|
+
if (!group) {
|
|
159
|
+
throw new _handlerGraphql.NotFoundError(`Cms Group "${id}" was not found!`);
|
|
160
|
+
}
|
|
140
161
|
await modelGroupsPermissions.ensure({
|
|
141
162
|
owns: group.createdBy
|
|
142
163
|
});
|
|
@@ -146,7 +167,6 @@ const createModelGroupsCrud = params => {
|
|
|
146
167
|
return group;
|
|
147
168
|
};
|
|
148
169
|
const listGroups = async params => {
|
|
149
|
-
var _getIdentity;
|
|
150
170
|
const {
|
|
151
171
|
where
|
|
152
172
|
} = params || {};
|
|
@@ -157,38 +177,7 @@ const createModelGroupsCrud = params => {
|
|
|
157
177
|
await modelGroupsPermissions.ensure({
|
|
158
178
|
rwd: "r"
|
|
159
179
|
});
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Maybe we can cache based on permissions, not the identity id?
|
|
163
|
-
*
|
|
164
|
-
* TODO: @adrian please check if possible.
|
|
165
|
-
*/
|
|
166
|
-
const key = JSON.stringify({
|
|
167
|
-
tenant: tenant || getTenant().id,
|
|
168
|
-
locale: locale || getLocale().code,
|
|
169
|
-
identity: context.security.isAuthorizationEnabled() ? (_getIdentity = getIdentity()) === null || _getIdentity === void 0 ? void 0 : _getIdentity.id : undefined
|
|
170
|
-
});
|
|
171
|
-
if (listGroupsCache.has(key)) {
|
|
172
|
-
return listGroupsCache.get(key);
|
|
173
|
-
}
|
|
174
|
-
const cached = async () => {
|
|
175
|
-
const response = await listGroupsViaDataLoader();
|
|
176
|
-
return (0, _filterAsync.filterAsync)(response, async group => {
|
|
177
|
-
const ownsGroup = await modelGroupsPermissions.ensure({
|
|
178
|
-
owns: group.createdBy
|
|
179
|
-
}, {
|
|
180
|
-
throw: false
|
|
181
|
-
});
|
|
182
|
-
if (!ownsGroup) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
return await modelGroupsPermissions.canAccessGroup({
|
|
186
|
-
group
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
listGroupsCache.set(key, cached());
|
|
191
|
-
return listGroupsCache.get(key);
|
|
180
|
+
return fetchGroups(tenant || getTenant().id, locale || getLocale().code);
|
|
192
181
|
};
|
|
193
182
|
const createGroup = async input => {
|
|
194
183
|
await modelGroupsPermissions.ensure({
|
|
@@ -200,7 +189,7 @@ const createModelGroupsCrud = params => {
|
|
|
200
189
|
}
|
|
201
190
|
const data = result.data;
|
|
202
191
|
const identity = getIdentity();
|
|
203
|
-
const id = (0, _utils.mdbid)();
|
|
192
|
+
const id = data.id || (0, _utils.mdbid)();
|
|
204
193
|
const group = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
205
194
|
id,
|
|
206
195
|
tenant: getTenant().id,
|
|
@@ -242,7 +231,7 @@ const createModelGroupsCrud = params => {
|
|
|
242
231
|
await modelGroupsPermissions.ensure({
|
|
243
232
|
rwd: "w"
|
|
244
233
|
});
|
|
245
|
-
const original = await
|
|
234
|
+
const original = await getGroup(id);
|
|
246
235
|
await modelGroupsPermissions.ensure({
|
|
247
236
|
owns: original.createdBy
|
|
248
237
|
});
|
|
@@ -296,7 +285,7 @@ const createModelGroupsCrud = params => {
|
|
|
296
285
|
await modelGroupsPermissions.ensure({
|
|
297
286
|
rwd: "d"
|
|
298
287
|
});
|
|
299
|
-
const group = await
|
|
288
|
+
const group = await getGroup(id);
|
|
300
289
|
await modelGroupsPermissions.ensure({
|
|
301
290
|
owns: group.createdBy
|
|
302
291
|
});
|
|
@@ -323,18 +312,6 @@ const createModelGroupsCrud = params => {
|
|
|
323
312
|
return true;
|
|
324
313
|
};
|
|
325
314
|
return {
|
|
326
|
-
/**
|
|
327
|
-
* Deprecated - will be removed in 5.36.0
|
|
328
|
-
*/
|
|
329
|
-
onBeforeGroupCreate: onGroupBeforeCreate,
|
|
330
|
-
onAfterGroupCreate: onGroupAfterCreate,
|
|
331
|
-
onBeforeGroupUpdate: onGroupBeforeUpdate,
|
|
332
|
-
onAfterGroupUpdate: onGroupAfterUpdate,
|
|
333
|
-
onBeforeGroupDelete: onGroupBeforeDelete,
|
|
334
|
-
onAfterGroupDelete: onGroupAfterDelete,
|
|
335
|
-
/**
|
|
336
|
-
* Released in 5.34.0
|
|
337
|
-
*/
|
|
338
315
|
onGroupBeforeCreate,
|
|
339
316
|
onGroupAfterCreate,
|
|
340
317
|
onGroupCreateError,
|
|
@@ -372,4 +349,6 @@ const createModelGroupsCrud = params => {
|
|
|
372
349
|
}
|
|
373
350
|
};
|
|
374
351
|
};
|
|
375
|
-
exports.createModelGroupsCrud = createModelGroupsCrud;
|
|
352
|
+
exports.createModelGroupsCrud = createModelGroupsCrud;
|
|
353
|
+
|
|
354
|
+
//# sourceMappingURL=contentModelGroup.crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dataloader","_interopRequireDefault","require","_error","_handlerGraphql","_CmsGroupPlugin","_pubsub","_beforeUpdate","_beforeCreate","_beforeDelete","_validation","_utils","_filterAsync","createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","modelGroupsPermissions","context","dataLoaders","listGroups","DataLoader","tenant","id","locale","code","pluginsGroups","getGroupsAsPlugins","map","group","_objectSpread2","default","groups","list","where","concat","listGroupsCache","Map","clearGroupsCache","loader","Object","values","clearAll","plugins","byType","CmsGroupPlugin","type","filter","plugin","t","l","contentModelGroup","webinyVersion","WEBINY_VERSION","getGroupViaDataLoader","load","find","g","NotFoundError","listGroupsViaDataLoader","ex","WebinyError","message","data","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","getGroup","ensure","rwd","owns","createdBy","ensureCanAccessGroup","_getIdentity","key","JSON","stringify","identity","security","isAuthorizationEnabled","undefined","has","get","cached","response","filterAsync","ownsGroup","throw","canAccessGroup","set","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","mdbid","createdOn","Date","toISOString","savedOn","displayName","publish","create","updateGroup","original","createGroupUpdateValidation","keys","length","updatedGroup","update","deleteGroup","delete","onBeforeGroupCreate","onAfterGroupCreate","onBeforeGroupUpdate","onAfterGroupUpdate","onBeforeGroupDelete","onAfterGroupDelete","benchmark","measure","exports"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsContext,\n CmsGroup,\n CmsGroupContext,\n HeadlessCmsStorageOperations,\n OnGroupAfterCreateTopicParams,\n OnGroupAfterDeleteTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeCreateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupCreateErrorTopicParams,\n OnGroupDeleteErrorTopicParams,\n OnGroupUpdateErrorTopicParams\n} from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\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 {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError, mdbid } from \"@webiny/utils\";\nimport { ModelGroupsPermissions } from \"~/utils/permissions/ModelGroupsPermissions\";\nimport { filterAsync } from \"~/utils/filterAsync\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n modelGroupsPermissions: ModelGroupsPermissions;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\n\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const {\n getTenant,\n getIdentity,\n getLocale,\n storageOperations,\n modelGroupsPermissions,\n context\n } = 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 listGroupsCache = new Map<string, Promise<CmsGroup[]>>();\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 getGroupViaDataLoader = 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 listGroupsViaDataLoader = async () => {\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 });\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 * CRUD Methods\n */\n const getGroup: CmsGroupContext[\"getGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n const group = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n await modelGroupsPermissions.ensureCanAccessGroup({\n group\n });\n\n return group;\n };\n\n const listGroups: CmsGroupContext[\"listGroups\"] = async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n /**\n * Maybe we can cache based on permissions, not the identity id?\n *\n * TODO: @adrian please check if possible.\n */\n const key = JSON.stringify({\n tenant: tenant || getTenant().id,\n locale: locale || getLocale().code,\n identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined\n });\n if (listGroupsCache.has(key)) {\n return listGroupsCache.get(key) as Promise<CmsGroup[]>;\n }\n\n const cached = async () => {\n const response = await listGroupsViaDataLoader();\n\n return filterAsync(response, async group => {\n const ownsGroup = await modelGroupsPermissions.ensure(\n { owns: group.createdBy },\n { throw: false }\n );\n\n if (!ownsGroup) {\n return false;\n }\n\n return await modelGroupsPermissions.canAccessGroup({\n group\n });\n });\n };\n\n listGroupsCache.set(key, cached());\n\n return listGroupsCache.get(key) as Promise<CmsGroup[]>;\n };\n\n const createGroup: CmsGroupContext[\"createGroup\"] = async input => {\n await modelGroupsPermissions.ensure({ rwd: \"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 const updateGroup: CmsGroupContext[\"updateGroup\"] = async (id, input) => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const original = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: original.createdBy });\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 const deleteGroup: CmsGroupContext[\"deleteGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"d\" });\n\n const group = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\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 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 return context.benchmark.measure(\"headlessCms.crud.groups.getGroup\", async () => {\n return getGroup(id);\n });\n },\n listGroups: async params => {\n return context.benchmark.measure(\"headlessCms.crud.groups.listGroups\", async () => {\n return listGroups(params);\n });\n },\n createGroup: async input => {\n return context.benchmark.measure(\"headlessCms.crud.groups.createGroup\", async () => {\n return createGroup(input);\n });\n },\n updateGroup: async (id, input) => {\n return context.benchmark.measure(\"headlessCms.crud.groups.updateGroup\", async () => {\n return updateGroup(id, input);\n });\n },\n deleteGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.deleteGroup\", async () => {\n return deleteGroup(id);\n });\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAgBA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAIA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAIA,IAAAS,MAAA,GAAAT,OAAA;AAEA,IAAAU,YAAA,GAAAV,OAAA;AAWO,MAAMW,qBAAqB,GAAIC,MAAmC,IAAsB;EAC3F,MAAM;IACFC,SAAS;IACTC,WAAW;IACXC,SAAS;IACTC,iBAAiB;IACjBC,sBAAsB;IACtBC;EACJ,CAAC,GAAGN,MAAM;EAEV,MAAMO,WAAW,GAAG;IAChBC,UAAU,EAAE,IAAIC,mBAAU,CAAC,YAAY;MACnC,MAAMC,MAAM,GAAGT,SAAS,CAAC,CAAC,CAACU,EAAE;MAC7B,MAAMC,MAAM,GAAGT,SAAS,CAAC,CAAC,CAACU,IAAI;MAE/B,MAAMC,aAAa,GAAGC,kBAAkB,CAAC,CAAC,CAACC,GAAG,CAACC,KAAK,IAAI;QACpD,W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7E,OAAOvD,QAAQ,CAACtD,EAAE,CAAC;MACvB,CAAC,CAAC;IACN,CAAC;IACDH,UAAU,EAAE,MAAMR,MAAM,IAAI;MACxB,OAAOM,OAAO,CAACiH,SAAS,CAACC,OAAO,CAAC,oCAAoC,EAAE,YAAY;QAC/E,OAAOhH,UAAU,CAACR,MAAM,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACDwF,WAAW,EAAE,MAAMC,KAAK,IAAI;MACxB,OAAOnF,OAAO,CAACiH,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOhC,WAAW,CAACC,KAAK,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACDe,WAAW,EAAE,MAAAA,CAAO7F,EAAE,EAAE8E,KAAK,KAAK;MAC9B,OAAOnF,OAAO,CAACiH,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOhB,WAAW,CAAC7F,EAAE,EAAE8E,KAAK,CAAC;MACjC,CAAC,CAAC;IACN,CAAC;IACDsB,WAAW,EAAE,MAAMpG,EAAE,IAAI;MACrB,OAAOL,OAAO,CAACiH,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOT,WAAW,CAACpG,EAAE,CAAC;MAC1B,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC;AAAC8G,OAAA,CAAA1H,qBAAA,GAAAA,qBAAA"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_CmsGroupPlugin","_pubsub","_beforeUpdate","_beforeCreate","_beforeDelete","_validation","_utils","_filterAsync","_utils2","_listGroupsFromDatabase","_handlerGraphql","createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","modelGroupsPermissions","context","listAllGroupsCache","createMemoryCache","listPluginGroupsCache","clearGroupsCache","clear","fetchPluginGroups","tenant","locale","pluginGroups","plugins","byType","CmsGroupPlugin","type","cacheKey","createCacheKey","groups","map","contentModelGroup","group","id","slug","savedOn","getOrSet","filter","plugin","t","l","_objectSpread2","default","webinyVersion","WEBINY_VERSION","fetchGroups","_getIdentity","identity","security","isAuthorizationEnabled","undefined","databaseGroups","listGroupsFromDatabase","concat","filterAsync","ownsGroup","ensure","owns","createdBy","throw","canAccessGroup","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","getGroup","rwd","withoutAuthorization","code","find","NotFoundError","ensureCanAccessGroup","listGroups","where","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","data","mdbid","createdOn","Date","toISOString","displayName","publish","create","ex","WebinyError","message","updateGroup","original","createGroupUpdateValidation","Object","keys","length","updatedGroup","update","deleteGroup","delete","benchmark","measure","exports"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n CmsContext,\n CmsGroup,\n CmsGroupContext,\n HeadlessCmsStorageOperations,\n OnGroupAfterCreateTopicParams,\n OnGroupAfterDeleteTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeCreateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupCreateErrorTopicParams,\n OnGroupDeleteErrorTopicParams,\n OnGroupUpdateErrorTopicParams\n} from \"~/types\";\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 {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError, mdbid } from \"@webiny/utils\";\nimport { ModelGroupsPermissions } from \"~/utils/permissions/ModelGroupsPermissions\";\nimport { filterAsync } from \"~/utils/filterAsync\";\nimport { createCacheKey, createMemoryCache } from \"~/utils\";\nimport { listGroupsFromDatabase } from \"~/crud/contentModelGroup/listGroupsFromDatabase\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n modelGroupsPermissions: ModelGroupsPermissions;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\n\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const {\n getTenant,\n getIdentity,\n getLocale,\n storageOperations,\n modelGroupsPermissions,\n context\n } = params;\n\n const listAllGroupsCache = createMemoryCache<Promise<CmsGroup[]>>();\n const listPluginGroupsCache = createMemoryCache<CmsGroup[]>();\n const clearGroupsCache = (): void => {\n listPluginGroupsCache.clear();\n listAllGroupsCache.clear();\n };\n\n const fetchPluginGroups = (tenant: string, locale: string): CmsGroup[] => {\n const pluginGroups = context.plugins.byType<CmsGroupPlugin>(CmsGroupPlugin.type);\n\n const cacheKey = createCacheKey({\n tenant,\n locale,\n groups: pluginGroups.map(({ contentModelGroup: group }) => {\n return `${group.id}#${group.slug}#${group.savedOn || \"unknown\"}`;\n })\n });\n\n return listPluginGroupsCache.getOrSet(cacheKey, () => {\n return (\n pluginGroups\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\n const fetchGroups = async (tenant: string, locale: string) => {\n const pluginGroups = fetchPluginGroups(tenant, locale);\n /**\n * Maybe we can cache based on permissions, not the identity id?\n *\n * TODO: @adrian please check if possible.\n */\n const cacheKey = createCacheKey({\n tenant,\n locale,\n identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined,\n groups: pluginGroups.map(group => {\n return `${group.id}#${group.slug}#${group.savedOn || \"unknown\"}`;\n })\n });\n\n return listAllGroupsCache.getOrSet(cacheKey, async () => {\n const databaseGroups = await listGroupsFromDatabase({\n storageOperations,\n tenant,\n locale\n });\n const groups = databaseGroups.concat(pluginGroups);\n\n return filterAsync(groups, async group => {\n const ownsGroup = await modelGroupsPermissions.ensure(\n { owns: group.createdBy },\n { throw: false }\n );\n\n if (!ownsGroup) {\n return false;\n }\n\n return await modelGroupsPermissions.canAccessGroup({\n group\n });\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 * CRUD Methods\n */\n const getGroup: CmsGroupContext[\"getGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n const groups = await context.security.withoutAuthorization(async () => {\n return fetchGroups(getTenant().id, getLocale().code);\n });\n const group = groups.find(group => group.id === id);\n if (!group) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n await modelGroupsPermissions.ensureCanAccessGroup({\n group\n });\n\n return group;\n };\n\n const listGroups: CmsGroupContext[\"listGroups\"] = async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n return fetchGroups(tenant || getTenant().id, locale || getLocale().code);\n };\n\n const createGroup: CmsGroupContext[\"createGroup\"] = async input => {\n await modelGroupsPermissions.ensure({ rwd: \"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 = data.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 const updateGroup: CmsGroupContext[\"updateGroup\"] = async (id, input) => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const original = await getGroup(id);\n\n await modelGroupsPermissions.ensure({ owns: original.createdBy });\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 const deleteGroup: CmsGroupContext[\"deleteGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"d\" });\n\n const group = await getGroup(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\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 return {\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 return context.benchmark.measure(\"headlessCms.crud.groups.getGroup\", async () => {\n return getGroup(id);\n });\n },\n listGroups: async params => {\n return context.benchmark.measure(\"headlessCms.crud.groups.listGroups\", async () => {\n return listGroups(params);\n });\n },\n createGroup: async input => {\n return context.benchmark.measure(\"headlessCms.crud.groups.createGroup\", async () => {\n return createGroup(input);\n });\n },\n updateGroup: async (id, input) => {\n return context.benchmark.measure(\"headlessCms.crud.groups.updateGroup\", async () => {\n return updateGroup(id, input);\n });\n },\n deleteGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.deleteGroup\", async () => {\n return deleteGroup(id);\n });\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAgBA,IAAAC,eAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAIA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AACA,IAAAU,uBAAA,GAAAV,OAAA;AACA,IAAAW,eAAA,GAAAX,OAAA;AAWO,MAAMY,qBAAqB,GAAIC,MAAmC,IAAsB;EAC3F,MAAM;IACFC,SAAS;IACTC,WAAW;IACXC,SAAS;IACTC,iBAAiB;IACjBC,sBAAsB;IACtBC;EACJ,CAAC,GAAGN,MAAM;EAEV,MAAMO,kBAAkB,GAAG,IAAAC,yBAAiB,EAAsB,CAAC;EACnE,MAAMC,qBAAqB,GAAG,IAAAD,yBAAiB,EAAa,CAAC;EAC7D,MAAME,gBAAgB,GAAGA,CAAA,KAAY;IACjCD,qBAAqB,CAACE,KAAK,CAAC,CAAC;IAC7BJ,kBAAkB,CAACI,KAAK,C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E,IAAI;MACrB,OAAOpB,OAAO,CAACmG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOH,WAAW,CAAC7E,EAAE,CAAC;MAC1B,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC;AAACiF,OAAA,CAAA5G,qBAAA,GAAAA,qBAAA"}
|
package/crud/system.crud.js
CHANGED
|
@@ -55,12 +55,7 @@ const createSystemCrud = params => {
|
|
|
55
55
|
};
|
|
56
56
|
return {
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
onBeforeSystemInstall: onSystemBeforeInstall,
|
|
61
|
-
onAfterSystemInstall: onSystemAfterInstall,
|
|
62
|
-
/**
|
|
63
|
-
* Released in 5.34.0
|
|
58
|
+
* Lifecycle Events.
|
|
64
59
|
*/
|
|
65
60
|
onSystemBeforeInstall,
|
|
66
61
|
onSystemAfterInstall,
|
|
@@ -123,4 +118,6 @@ const createSystemCrud = params => {
|
|
|
123
118
|
}
|
|
124
119
|
};
|
|
125
120
|
};
|
|
126
|
-
exports.createSystemCrud = createSystemCrud;
|
|
121
|
+
exports.createSystemCrud = createSystemCrud;
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=system.crud.js.map
|
package/crud/system.crud.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiSecurity","require","_error","_interopRequireDefault","_pubsub","initialContentModelGroup","name","slug","description","icon","createSystemCrud","params","getTenant","getLocale","storageOperations","context","getIdentity","onSystemBeforeInstall","createTopic","onSystemAfterInstall","onSystemInstallError","getVersion","system","get","tenant","id","version","setVersion","original","_objectSpread2","default","create","update","
|
|
1
|
+
{"version":3,"names":["_apiSecurity","require","_error","_interopRequireDefault","_pubsub","initialContentModelGroup","name","slug","description","icon","createSystemCrud","params","getTenant","getLocale","storageOperations","context","getIdentity","onSystemBeforeInstall","createTopic","onSystemAfterInstall","onSystemInstallError","getVersion","system","get","tenant","id","version","setVersion","original","_objectSpread2","default","create","update","getSystemVersion","setSystemVersion","installSystem","identity","NotAuthorizedError","publish","locale","code","cms","createGroup","ex","WebinyError","message","group","WEBINY_VERSION","error","data","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport WebinyError from \"@webiny/error\";\nimport {\n OnSystemAfterInstallTopicParams,\n OnSystemBeforeInstallTopicParams,\n CmsContext,\n CmsSystem,\n CmsSystemContext,\n HeadlessCmsStorageOperations,\n OnSystemInstallErrorTopicParams\n} from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst initialContentModelGroup = {\n name: \"Ungrouped\",\n slug: \"ungrouped\",\n description: \"A generic content model group\",\n icon: \"fas/star\"\n};\n\ninterface CreateSystemCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\nexport const createSystemCrud = (params: CreateSystemCrudParams): CmsSystemContext => {\n const { getTenant, getLocale, storageOperations, context, getIdentity } = params;\n\n const onSystemBeforeInstall = createTopic<OnSystemBeforeInstallTopicParams>(\n \"cms.onSystemBeforeInstall\"\n );\n const onSystemAfterInstall = createTopic<OnSystemAfterInstallTopicParams>(\n \"cms.onSystemAfterInstall\"\n );\n\n const onSystemInstallError = createTopic<OnSystemInstallErrorTopicParams>(\n \"cms.onSystemInstallError\"\n );\n\n const getVersion = async () => {\n if (!getTenant()) {\n return null;\n }\n\n const system = await storageOperations.system.get({\n tenant: getTenant().id\n });\n\n return system?.version || null;\n };\n\n const setVersion = async (version: string) => {\n const original = await storageOperations.system.get({\n tenant: getTenant().id\n });\n const system: CmsSystem = {\n ...(original || {}),\n version,\n tenant: getTenant().id\n };\n if (!original) {\n await storageOperations.system.create({\n system\n });\n return;\n }\n await storageOperations.system.update({\n system\n });\n };\n\n return {\n /**\n * Lifecycle Events.\n */\n onSystemBeforeInstall,\n onSystemAfterInstall,\n onSystemInstallError,\n getSystemVersion: getVersion,\n setSystemVersion: setVersion,\n installSystem: async (): Promise<void> => {\n const identity = getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await getVersion();\n if (version) {\n return;\n }\n try {\n /**\n * First trigger before install event.\n */\n await onSystemBeforeInstall.publish({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n\n /**\n * Add default content model group.\n */\n try {\n await context.cms.createGroup(initialContentModelGroup);\n } catch (ex) {\n throw new WebinyError(\n ex.message,\n \"CMS_INSTALLATION_CONTENT_MODEL_GROUP_ERROR\",\n {\n group: initialContentModelGroup\n }\n );\n }\n\n const system: CmsSystem = {\n version: context.WEBINY_VERSION,\n tenant: getTenant().id\n };\n /**\n * We need to create the system data.\n */\n await storageOperations.system.create({\n system\n });\n /**\n * And trigger after install event.\n */\n await onSystemAfterInstall.publish({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n } catch (ex) {\n await onSystemInstallError.publish({\n error: ex,\n tenant: getTenant().id,\n locale: getLocale().code\n });\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAYA,IAAAG,OAAA,GAAAH,OAAA;AAGA,MAAMI,wBAAwB,GAAG;EAC7BC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,WAAW;EACjBC,WAAW,EAAE,+BAA+B;EAC5CC,IAAI,EAAE;AACV,CAAC;AASM,MAAMC,gBAAgB,GAAIC,MAA8B,IAAuB;EAClF,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,iBAAiB;IAAEC,OAAO;IAAEC;EAAY,CAAC,GAAGL,MAAM;EAEhF,MAAMM,qBAAqB,GAAG,IAAAC,m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,CAAC,CAAC;QACF,MAAM,IAAII,cAAW,CAACD,EAAE,CAACE,OAAO,EAAEF,EAAE,CAACH,IAAI,EAAEG,EAAE,CAACM,IAAI,CAAC;MACvD;IACJ;EACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAxC,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createExportStructureContext = void 0;
|
|
7
|
+
var _sanitize = require("./sanitize");
|
|
8
|
+
const createExportStructureContext = context => {
|
|
9
|
+
return async params => {
|
|
10
|
+
const {
|
|
11
|
+
models: modelIdList
|
|
12
|
+
} = params;
|
|
13
|
+
const groups = (await context.cms.listGroups()).map(_sanitize.sanitizeGroup);
|
|
14
|
+
/**
|
|
15
|
+
* We need all the models which:
|
|
16
|
+
* * are accessible by current user
|
|
17
|
+
* * are not private
|
|
18
|
+
* * are included (if targets are provided)
|
|
19
|
+
* * are part of one of the groups we already fetched
|
|
20
|
+
*/
|
|
21
|
+
const models = (await context.cms.listModels()).filter(model => {
|
|
22
|
+
var _model$fields;
|
|
23
|
+
if (model.isPrivate) {
|
|
24
|
+
return false;
|
|
25
|
+
} else if (!((_model$fields = model.fields) !== null && _model$fields !== void 0 && _model$fields.length)) {
|
|
26
|
+
return false;
|
|
27
|
+
} else if (!(modelIdList !== null && modelIdList !== void 0 && modelIdList.length)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return modelIdList.includes(model.modelId);
|
|
31
|
+
}).map(model => {
|
|
32
|
+
const group = groups.find(group => group.id === model.group.id);
|
|
33
|
+
if (!group) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return (0, _sanitize.sanitizeModel)(group, model);
|
|
37
|
+
}).filter(model => {
|
|
38
|
+
return !!model;
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
groups: groups.filter(group => {
|
|
42
|
+
return models.some(model => model.group === group.id);
|
|
43
|
+
}),
|
|
44
|
+
models
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.createExportStructureContext = createExportStructureContext;
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=exporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_sanitize","require","createExportStructureContext","context","params","models","modelIdList","groups","cms","listGroups","map","sanitizeGroup","listModels","filter","model","_model$fields","isPrivate","fields","length","includes","modelId","group","find","id","sanitizeModel","some","exports"],"sources":["exporting.ts"],"sourcesContent":["import { HeadlessCmsExportStructure, SanitizedCmsModel } from \"~/export/types\";\nimport { CmsContext } from \"~/types\";\nimport { sanitizeGroup, sanitizeModel } from \"./sanitize\";\n\nexport const createExportStructureContext = (context: CmsContext): HeadlessCmsExportStructure => {\n return async params => {\n const { models: modelIdList } = params;\n const groups = (await context.cms.listGroups()).map(sanitizeGroup);\n /**\n * We need all the models which:\n * * are accessible by current user\n * * are not private\n * * are included (if targets are provided)\n * * are part of one of the groups we already fetched\n */\n const models = (await context.cms.listModels())\n .filter(model => {\n if (model.isPrivate) {\n return false;\n } else if (!model.fields?.length) {\n return false;\n } else if (!modelIdList?.length) {\n return true;\n }\n return modelIdList.includes(model.modelId);\n })\n .map(model => {\n const group = groups.find(group => group.id === model.group.id);\n if (!group) {\n return null;\n }\n return sanitizeModel(group, model);\n })\n .filter((model): model is SanitizedCmsModel => {\n return !!model;\n });\n\n return {\n groups: groups.filter(group => {\n return models.some(model => model.group === group.id);\n }),\n models\n };\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAiC;EAC7F,OAAO,MAAMC,MAAM,IAAI;IACnB,MAAM;MAAEC,MAAM,EAAEC;IAAY,CAAC,GAAGF,MAAM;IACtC,MAAMG,MAAM,GAAG,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AAAxB,4BAAA,GAAAA,4BAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createImportCrud = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
+
var _importData = require("./imports/importData");
|
|
11
|
+
var _validateInput = require("./imports/validateInput");
|
|
12
|
+
const fetchGroupsAndModels = async context => {
|
|
13
|
+
return await context.security.withoutAuthorization(async () => {
|
|
14
|
+
return {
|
|
15
|
+
groups: await context.cms.listGroups(),
|
|
16
|
+
models: await context.cms.listModels()
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const createImportCrud = context => {
|
|
21
|
+
return {
|
|
22
|
+
validate: async params => {
|
|
23
|
+
const {
|
|
24
|
+
data
|
|
25
|
+
} = params;
|
|
26
|
+
const {
|
|
27
|
+
groups,
|
|
28
|
+
models
|
|
29
|
+
} = await fetchGroupsAndModels(context);
|
|
30
|
+
const validated = await (0, _validateInput.validateInput)({
|
|
31
|
+
groups,
|
|
32
|
+
models,
|
|
33
|
+
data
|
|
34
|
+
});
|
|
35
|
+
if (validated.error) {
|
|
36
|
+
return {
|
|
37
|
+
groups: validated.groups,
|
|
38
|
+
models: validated.models,
|
|
39
|
+
message: validated.error
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
groups: validated.groups,
|
|
44
|
+
models: validated.models,
|
|
45
|
+
message: "Validation done."
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
structure: async params => {
|
|
49
|
+
const {
|
|
50
|
+
data
|
|
51
|
+
} = params;
|
|
52
|
+
const {
|
|
53
|
+
groups,
|
|
54
|
+
models
|
|
55
|
+
} = await fetchGroupsAndModels(context);
|
|
56
|
+
const validated = await (0, _validateInput.validateInput)({
|
|
57
|
+
groups,
|
|
58
|
+
models,
|
|
59
|
+
data
|
|
60
|
+
});
|
|
61
|
+
if (validated.error) {
|
|
62
|
+
throw new _error.default(validated.error, "VALIDATION_ERROR");
|
|
63
|
+
}
|
|
64
|
+
const imported = await (0, _importData.importData)({
|
|
65
|
+
context,
|
|
66
|
+
groups: validated.groups,
|
|
67
|
+
models: validated.models
|
|
68
|
+
});
|
|
69
|
+
const modelError = imported.models.find(model => !!model.error);
|
|
70
|
+
const error = imported.error || modelError;
|
|
71
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, imported), {}, {
|
|
72
|
+
message: error ? null : "Import done."
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.createImportCrud = createImportCrud;
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=importing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_importData","_validateInput","fetchGroupsAndModels","context","security","withoutAuthorization","groups","cms","listGroups","models","listModels","createImportCrud","validate","params","data","validated","validateInput","error","message","structure","WebinyError","imported","importData","modelError","find","model","_objectSpread2","default","exports"],"sources":["importing.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { HeadlessCmsImport, ValidCmsGroupResult, ValidCmsModelResult } from \"~/export/types\";\nimport { CmsContext } from \"~/types\";\nimport { importData } from \"./imports/importData\";\nimport { validateInput } from \"./imports/validateInput\";\n\nconst fetchGroupsAndModels = async (context: CmsContext) => {\n return await context.security.withoutAuthorization(async () => {\n return {\n groups: await context.cms.listGroups(),\n models: await context.cms.listModels()\n };\n });\n};\n\nexport const createImportCrud = (context: CmsContext): HeadlessCmsImport => {\n return {\n validate: async params => {\n const { data } = params;\n\n const { groups, models } = await fetchGroupsAndModels(context);\n\n const validated = await validateInput({\n groups,\n models,\n data\n });\n if (validated.error) {\n return {\n groups: validated.groups,\n models: validated.models,\n message: validated.error\n };\n }\n\n return {\n groups: validated.groups,\n models: validated.models,\n message: \"Validation done.\"\n };\n },\n structure: async params => {\n const { data } = params;\n\n const { groups, models } = await fetchGroupsAndModels(context);\n\n const validated = await validateInput({\n groups,\n models,\n data\n });\n if (validated.error) {\n throw new WebinyError(validated.error, \"VALIDATION_ERROR\");\n }\n\n const imported = await importData({\n context,\n groups: validated.groups as ValidCmsGroupResult[],\n models: validated.models as ValidCmsModelResult[]\n });\n\n const modelError = imported.models.find(model => !!model.error);\n const error = imported.error || modelError;\n\n return {\n ...imported,\n message: error ? null : \"Import done.\"\n };\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEA,MAAMG,oBAAoB,GAAG,MAAOC,OAAmB,IAAK;EACxD,OAAO,MAAMA,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAAC,YAAY;IAC3D,OAAO;MACHC,MAAM,EAAE,MAAMH,OAAO,CAACI,GAAG,CAACC,UAAU,CAAC,CAAC;MACtCC,MAAM,EAAE,MAAMN,OAAO,CAACI,GAAG,CAACG,UAAU,CAAC;IACzC,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAEM,MAAMC,gBAAgB,GAAIR,OAAmB,IAAwB;EACxE,OAAO;IACHS,QAAQ,EAAE,MAAMC,MAAM,IAAI;MACtB,MAAM;QAAEC;MAAK,CAAC,GAAGD,MAAM;MAEvB,MAAM;QAAEP,MAAM;QAAEG;MAAO,CAAC,GAAG,MAAMP,oBAAoB,CAACC,OAAO,CAAC;MAE9D,MAAMY,SAAS,GAAG,MAAM,IAAAC,4BAAa,EAAC;QAClCV,MAAM;QACNG,MAAM;QACNK;MACJ,CAAC,CAAC;MACF,IAAIC,SAAS,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