@webiny/api-headless-cms 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.78f581c1d2
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.js +15 -0
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +5 -0
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +3 -0
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +3 -0
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +40 -1
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +25 -2
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +59 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry.crud.js +145 -27
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +2 -0
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +2 -0
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +2 -0
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +2 -0
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +32 -4
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +10 -0
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +5 -0
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +7 -0
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldModels.js +6 -0
- package/crud/contentModel/createFieldModels.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +2 -0
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/fieldIdValidation.js +5 -0
- package/crud/contentModel/fieldIdValidation.js.map +1 -1
- package/crud/contentModel/idValidation.js +5 -0
- package/crud/contentModel/idValidation.js.map +1 -1
- package/crud/contentModel/models.js +8 -1
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validateLayout.js +8 -0
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.js +8 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +60 -8
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel.crud.js +96 -11
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +12 -0
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +8 -0
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +5 -0
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup.crud.js +47 -10
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/index.js +16 -0
- package/crud/index.js.map +1 -1
- package/crud/settings.crud.js +12 -0
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +37 -2
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +13 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +53 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +4 -0
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +9 -5
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +28 -3
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.js +8 -1
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +9 -1
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +42 -2
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +19 -2
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +18 -2
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +21 -3
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +26 -0
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +14 -1
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +10 -0
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +10 -0
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.js +10 -0
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -0
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +6 -0
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +16 -0
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +3 -0
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +8 -0
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -0
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +8 -0
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -0
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +19 -5
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +14 -1
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +12 -0
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +17 -0
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/file.js +8 -0
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +10 -0
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +11 -0
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +10 -0
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +12 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +36 -6
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +51 -17
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +9 -0
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +11 -0
- package/graphqlFields/text.js.map +1 -1
- package/index.js +19 -0
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +16 -0
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +4 -0
- package/modelManager/index.js.map +1 -1
- package/package.json +24 -24
- package/parameters/context.js +4 -0
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +11 -0
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +8 -0
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +8 -1
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +11 -0
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGroupPlugin.js +8 -0
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +5 -0
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.js +38 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +7 -0
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.js +9 -0
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.js +10 -0
- package/plugins/index.js.map +1 -1
- package/storage/default.js +3 -0
- package/storage/default.js.map +1 -1
- package/storage/object.js +18 -0
- package/storage/object.js.map +1 -1
- package/types.js +62 -0
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +26 -3
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +3 -0
- package/upgrades/index.js.map +1 -1
- package/utils/access.js +25 -11
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +13 -0
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +32 -9
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +26 -0
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeName.js +8 -0
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +26 -10
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +5 -0
- package/utils/filterAsync.js.map +1 -1
- package/utils/filterModelFields.js +9 -3
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getEntryTitle.js +9 -0
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.js +6 -2
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.js +8 -0
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +23 -8
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.js +8 -0
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +11 -0
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +8 -0
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +9 -1
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +7 -0
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +4 -0
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +7 -0
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +7 -0
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +8 -0
- package/validators/gte.js.map +1 -1
- package/validators/in.js +8 -0
- package/validators/in.js.map +1 -1
- package/validators/index.js +15 -0
- package/validators/index.js.map +1 -1
- package/validators/lte.js +8 -0
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +8 -0
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +8 -0
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +9 -0
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +2 -0
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +8 -0
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +2 -0
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +2 -0
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +2 -0
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +2 -0
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +2 -0
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +5 -0
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +8 -0
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +8 -0
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +7 -0
- package/validators/unique.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assignBeforeGroupCreate","params","onGroupBeforeCreate","plugins","storageOperations","subscribe","group","slug","trim","groups","list","where","tenant","locale","length","WebinyError","toSlug","name","generateAlphaNumericId","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","Error"],"sources":["beforeCreate.ts"],"sourcesContent":["import { OnGroupBeforeCreateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { toSlug } from \"~/utils/toSlug\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\ninterface AssignBeforeGroupCreateParams {\n onGroupBeforeCreate: Topic<OnGroupBeforeCreateTopicParams>;\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nexport const assignBeforeGroupCreate = (params: AssignBeforeGroupCreateParams) => {\n const { onGroupBeforeCreate, plugins, storageOperations } = params;\n\n onGroupBeforeCreate.subscribe(async params => {\n const { group } = params;\n\n if (group.slug && group.slug.trim()) {\n const groups = await storageOperations.groups.list({\n where: {\n tenant: group.tenant,\n locale: group.locale,\n slug: group.slug\n }\n });\n if (groups.length > 0) {\n throw new WebinyError(\n `Cms Group with the slug \"${group.slug}\" already exists.`,\n \"SLUG_ALREADY_EXISTS\"\n );\n }\n } else {\n const slug = toSlug(group.name);\n const groups = await storageOperations.groups.list({\n where: {\n tenant: group.tenant,\n locale: group.locale,\n slug\n }\n });\n\n if (groups.length === 0) {\n group.slug = slug;\n } else {\n group.slug = `${slug}-${generateAlphaNumericId(8)}`;\n }\n }\n\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n\n if (groupPlugin) {\n throw new Error(\n `Cannot create \"${group.slug}\" content model group because one is already registered via a plugin.`\n );\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["assignBeforeGroupCreate","params","onGroupBeforeCreate","plugins","storageOperations","subscribe","group","slug","trim","groups","list","where","tenant","locale","length","WebinyError","toSlug","name","generateAlphaNumericId","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","Error"],"sources":["beforeCreate.ts"],"sourcesContent":["import { OnGroupBeforeCreateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { toSlug } from \"~/utils/toSlug\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\ninterface AssignBeforeGroupCreateParams {\n onGroupBeforeCreate: Topic<OnGroupBeforeCreateTopicParams>;\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nexport const assignBeforeGroupCreate = (params: AssignBeforeGroupCreateParams) => {\n const { onGroupBeforeCreate, plugins, storageOperations } = params;\n\n onGroupBeforeCreate.subscribe(async params => {\n const { group } = params;\n\n if (group.slug && group.slug.trim()) {\n const groups = await storageOperations.groups.list({\n where: {\n tenant: group.tenant,\n locale: group.locale,\n slug: group.slug\n }\n });\n if (groups.length > 0) {\n throw new WebinyError(\n `Cms Group with the slug \"${group.slug}\" already exists.`,\n \"SLUG_ALREADY_EXISTS\"\n );\n }\n } else {\n const slug = toSlug(group.name);\n const groups = await storageOperations.groups.list({\n where: {\n tenant: group.tenant,\n locale: group.locale,\n slug\n }\n });\n\n if (groups.length === 0) {\n group.slug = slug;\n } else {\n group.slug = `${slug}-${generateAlphaNumericId(8)}`;\n }\n }\n\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n\n if (groupPlugin) {\n throw new Error(\n `Cannot create \"${group.slug}\" content model group because one is already registered via a plugin.`\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAOO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC,OAAvB;IAAgCC;EAAhC,IAAsDH,MAA5D;EAEAC,mBAAmB,CAACG,SAApB,CAA8B,MAAMJ,MAAN,IAAgB;IAC1C,MAAM;MAAEK;IAAF,IAAYL,MAAlB;;IAEA,IAAIK,KAAK,CAACC,IAAN,IAAcD,KAAK,CAACC,IAAN,CAAWC,IAAX,EAAlB,EAAqC;MACjC,MAAMC,MAAM,GAAG,MAAML,iBAAiB,CAACK,MAAlB,CAAyBC,IAAzB,CAA8B;QAC/CC,KAAK,EAAE;UACHC,MAAM,EAAEN,KAAK,CAACM,MADX;UAEHC,MAAM,EAAEP,KAAK,CAACO,MAFX;UAGHN,IAAI,EAAED,KAAK,CAACC;QAHT;MADwC,CAA9B,CAArB;;MAOA,IAAIE,MAAM,CAACK,MAAP,GAAgB,CAApB,EAAuB;QACnB,MAAM,IAAIC,cAAJ,CACD,4BAA2BT,KAAK,CAACC,IAAK,mBADrC,EAEF,qBAFE,CAAN;MAIH;IACJ,CAdD,MAcO;MACH,MAAMA,IAAI,GAAG,IAAAS,cAAA,EAAOV,KAAK,CAACW,IAAb,CAAb;MACA,MAAMR,MAAM,GAAG,MAAML,iBAAiB,CAACK,MAAlB,CAAyBC,IAAzB,CAA8B;QAC/CC,KAAK,EAAE;UACHC,MAAM,EAAEN,KAAK,CAACM,MADX;UAEHC,MAAM,EAAEP,KAAK,CAACO,MAFX;UAGHN;QAHG;MADwC,CAA9B,CAArB;;MAQA,IAAIE,MAAM,CAACK,MAAP,KAAkB,CAAtB,EAAyB;QACrBR,KAAK,CAACC,IAAN,GAAaA,IAAb;MACH,CAFD,MAEO;QACHD,KAAK,CAACC,IAAN,GAAc,GAAEA,IAAK,IAAG,IAAAW,6BAAA,EAAuB,CAAvB,CAA0B,EAAlD;MACH;IACJ;;IAED,MAAMC,WAAW,GAAGhB,OAAO,CACtBiB,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,iBAAL,CAAuBlB,IAAvB,KAAgCD,KAAK,CAACC,IAFpC,CAApB;;IAIA,IAAIY,WAAJ,EAAiB;MACb,MAAM,IAAIO,KAAJ,CACD,kBAAiBpB,KAAK,CAACC,IAAK,uEAD3B,CAAN;IAGH;EACJ,CA3CD;AA4CH,CA/CM"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.assignBeforeGroupDelete = void 0;
|
|
9
|
+
|
|
8
10
|
var _CmsGroupPlugin = require("../../plugins/CmsGroupPlugin");
|
|
11
|
+
|
|
9
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
10
14
|
const assignBeforeGroupDelete = params => {
|
|
11
15
|
const {
|
|
12
16
|
onGroupBeforeDelete,
|
|
@@ -18,9 +22,11 @@ const assignBeforeGroupDelete = params => {
|
|
|
18
22
|
group
|
|
19
23
|
} = params;
|
|
20
24
|
const groupPlugin = plugins.byType(_CmsGroupPlugin.CmsGroupPlugin.type).find(item => item.contentModelGroup.slug === group.slug);
|
|
25
|
+
|
|
21
26
|
if (groupPlugin) {
|
|
22
27
|
throw new Error(`Cms Groups defined via plugins cannot be deleted.`);
|
|
23
28
|
}
|
|
29
|
+
|
|
24
30
|
const models = await storageOperations.models.list({
|
|
25
31
|
where: {
|
|
26
32
|
tenant: group.tenant,
|
|
@@ -30,6 +36,7 @@ const assignBeforeGroupDelete = params => {
|
|
|
30
36
|
const items = models.filter(model => {
|
|
31
37
|
return model.group.id === group.id;
|
|
32
38
|
});
|
|
39
|
+
|
|
33
40
|
if (items.length > 0) {
|
|
34
41
|
throw new _error.default("Cannot delete this group because there are models that belong to it.", "BEFORE_DELETE_ERROR", {
|
|
35
42
|
group
|
|
@@ -37,4 +44,5 @@ const assignBeforeGroupDelete = params => {
|
|
|
37
44
|
}
|
|
38
45
|
});
|
|
39
46
|
};
|
|
47
|
+
|
|
40
48
|
exports.assignBeforeGroupDelete = assignBeforeGroupDelete;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assignBeforeGroupDelete","params","onGroupBeforeDelete","plugins","storageOperations","subscribe","group","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","slug","Error","models","list","where","tenant","locale","items","filter","model","id","length","WebinyError"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnGroupBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ninterface AssignBeforeGroupDeleteParams {\n onGroupBeforeDelete: Topic<OnGroupBeforeDeleteTopicParams>;\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nexport const assignBeforeGroupDelete = (params: AssignBeforeGroupDeleteParams) => {\n const { onGroupBeforeDelete, plugins, storageOperations } = params;\n\n onGroupBeforeDelete.subscribe(async params => {\n const { group } = params;\n\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n\n if (groupPlugin) {\n throw new Error(`Cms Groups defined via plugins cannot be deleted.`);\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: group.tenant,\n locale: group.locale\n }\n });\n const items = models.filter(model => {\n return model.group.id === group.id;\n });\n if (items.length > 0) {\n throw new WebinyError(\n \"Cannot delete this group because there are models that belong to it.\",\n \"BEFORE_DELETE_ERROR\",\n {\n group\n }\n );\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["assignBeforeGroupDelete","params","onGroupBeforeDelete","plugins","storageOperations","subscribe","group","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","slug","Error","models","list","where","tenant","locale","items","filter","model","id","length","WebinyError"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnGroupBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ninterface AssignBeforeGroupDeleteParams {\n onGroupBeforeDelete: Topic<OnGroupBeforeDeleteTopicParams>;\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nexport const assignBeforeGroupDelete = (params: AssignBeforeGroupDeleteParams) => {\n const { onGroupBeforeDelete, plugins, storageOperations } = params;\n\n onGroupBeforeDelete.subscribe(async params => {\n const { group } = params;\n\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n\n if (groupPlugin) {\n throw new Error(`Cms Groups defined via plugins cannot be deleted.`);\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: group.tenant,\n locale: group.locale\n }\n });\n const items = models.filter(model => {\n return model.group.id === group.id;\n });\n if (items.length > 0) {\n throw new WebinyError(\n \"Cannot delete this group because there are models that belong to it.\",\n \"BEFORE_DELETE_ERROR\",\n {\n group\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AAOO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC,OAAvB;IAAgCC;EAAhC,IAAsDH,MAA5D;EAEAC,mBAAmB,CAACG,SAApB,CAA8B,MAAMJ,MAAN,IAAgB;IAC1C,MAAM;MAAEK;IAAF,IAAYL,MAAlB;IAEA,MAAMM,WAAW,GAAGJ,OAAO,CACtBK,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,iBAAL,CAAuBC,IAAvB,KAAgCR,KAAK,CAACQ,IAFpC,CAApB;;IAIA,IAAIP,WAAJ,EAAiB;MACb,MAAM,IAAIQ,KAAJ,CAAW,mDAAX,CAAN;IACH;;IAED,MAAMC,MAAM,GAAG,MAAMZ,iBAAiB,CAACY,MAAlB,CAAyBC,IAAzB,CAA8B;MAC/CC,KAAK,EAAE;QACHC,MAAM,EAAEb,KAAK,CAACa,MADX;QAEHC,MAAM,EAAEd,KAAK,CAACc;MAFX;IADwC,CAA9B,CAArB;IAMA,MAAMC,KAAK,GAAGL,MAAM,CAACM,MAAP,CAAcC,KAAK,IAAI;MACjC,OAAOA,KAAK,CAACjB,KAAN,CAAYkB,EAAZ,KAAmBlB,KAAK,CAACkB,EAAhC;IACH,CAFa,CAAd;;IAGA,IAAIH,KAAK,CAACI,MAAN,GAAe,CAAnB,EAAsB;MAClB,MAAM,IAAIC,cAAJ,CACF,sEADE,EAEF,qBAFE,EAGF;QACIpB;MADJ,CAHE,CAAN;IAOH;EACJ,CA7BD;AA8BH,CAjCM"}
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.assignBeforeGroupUpdate = void 0;
|
|
7
|
+
|
|
7
8
|
var _CmsGroupPlugin = require("../../plugins/CmsGroupPlugin");
|
|
9
|
+
|
|
8
10
|
const assignBeforeGroupUpdate = params => {
|
|
9
11
|
const {
|
|
10
12
|
onGroupBeforeUpdate,
|
|
@@ -14,10 +16,13 @@ const assignBeforeGroupUpdate = params => {
|
|
|
14
16
|
group
|
|
15
17
|
}) => {
|
|
16
18
|
const groupPlugin = plugins.byType(_CmsGroupPlugin.CmsGroupPlugin.type).find(item => item.contentModelGroup.slug === group.slug);
|
|
19
|
+
|
|
17
20
|
if (!groupPlugin) {
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
23
|
+
|
|
20
24
|
throw new Error(`Cms Groups defined via plugins cannot be updated.`);
|
|
21
25
|
});
|
|
22
26
|
};
|
|
27
|
+
|
|
23
28
|
exports.assignBeforeGroupUpdate = assignBeforeGroupUpdate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assignBeforeGroupUpdate","params","onGroupBeforeUpdate","plugins","subscribe","group","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","slug","Error"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnGroupBeforeUpdateTopicParams } from \"~/types\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface AssignBeforeGroupUpdateParams {\n onGroupBeforeUpdate: Topic<OnGroupBeforeUpdateTopicParams>;\n plugins: PluginsContainer;\n}\nexport const assignBeforeGroupUpdate = (params: AssignBeforeGroupUpdateParams) => {\n const { onGroupBeforeUpdate, plugins } = params;\n\n onGroupBeforeUpdate.subscribe(({ group }) => {\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n if (!groupPlugin) {\n return;\n }\n throw new Error(`Cms Groups defined via plugins cannot be updated.`);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["assignBeforeGroupUpdate","params","onGroupBeforeUpdate","plugins","subscribe","group","groupPlugin","byType","CmsGroupPlugin","type","find","item","contentModelGroup","slug","Error"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnGroupBeforeUpdateTopicParams } from \"~/types\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface AssignBeforeGroupUpdateParams {\n onGroupBeforeUpdate: Topic<OnGroupBeforeUpdateTopicParams>;\n plugins: PluginsContainer;\n}\nexport const assignBeforeGroupUpdate = (params: AssignBeforeGroupUpdateParams) => {\n const { onGroupBeforeUpdate, plugins } = params;\n\n onGroupBeforeUpdate.subscribe(({ group }) => {\n const groupPlugin = plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .find(item => item.contentModelGroup.slug === group.slug);\n if (!groupPlugin) {\n return;\n }\n throw new Error(`Cms Groups defined via plugins cannot be updated.`);\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAOO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,CAAC;IAAEC;EAAF,CAAD,KAAe;IACzC,MAAMC,WAAW,GAAGH,OAAO,CACtBI,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,iBAAL,CAAuBC,IAAvB,KAAgCR,KAAK,CAACQ,IAFpC,CAApB;;IAGA,IAAI,CAACP,WAAL,EAAkB;MACd;IACH;;IACD,MAAM,IAAIQ,KAAJ,CAAW,mDAAX,CAAN;EACH,CARD;AASH,CAZM"}
|
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.createModelGroupsCrud = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
var _fields = require("@commodo/fields");
|
|
13
|
+
|
|
10
14
|
var _validation = require("@webiny/validation");
|
|
15
|
+
|
|
11
16
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
17
|
+
|
|
12
18
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
19
|
+
|
|
13
20
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
21
|
+
|
|
14
22
|
var _CmsGroupPlugin = require("../plugins/CmsGroupPlugin");
|
|
23
|
+
|
|
15
24
|
var _pubsub = require("@webiny/pubsub");
|
|
25
|
+
|
|
16
26
|
var _beforeUpdate = require("./contentModelGroup/beforeUpdate");
|
|
27
|
+
|
|
17
28
|
var _beforeCreate = require("./contentModelGroup/beforeCreate");
|
|
29
|
+
|
|
18
30
|
var _beforeDelete = require("./contentModelGroup/beforeDelete");
|
|
31
|
+
|
|
19
32
|
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
33
|
+
|
|
20
34
|
var _permissions = require("../utils/permissions");
|
|
35
|
+
|
|
21
36
|
var _ownership = require("../utils/ownership");
|
|
37
|
+
|
|
22
38
|
var _access = require("../utils/access");
|
|
39
|
+
|
|
23
40
|
var _toSlug = require("../utils/toSlug");
|
|
41
|
+
|
|
24
42
|
/**
|
|
25
43
|
* Package @commodo/fields does not have types.
|
|
26
44
|
*/
|
|
@@ -30,7 +48,6 @@ var _toSlug = require("../utils/toSlug");
|
|
|
30
48
|
* Package mdbid does not have types.
|
|
31
49
|
*/
|
|
32
50
|
// @ts-ignore
|
|
33
|
-
|
|
34
51
|
const CreateContentModelGroupModel = (0, _fields.withFields)({
|
|
35
52
|
name: (0, _fields.string)({
|
|
36
53
|
validation: _validation.validation.create("required,maxLength:100")
|
|
@@ -56,6 +73,7 @@ const UpdateContentModelGroupModel = (0, _fields.withFields)({
|
|
|
56
73
|
validation: _validation.validation.create("maxLength:255")
|
|
57
74
|
})
|
|
58
75
|
})();
|
|
76
|
+
|
|
59
77
|
const createModelGroupsCrud = params => {
|
|
60
78
|
const {
|
|
61
79
|
getTenant,
|
|
@@ -83,11 +101,13 @@ const createModelGroupsCrud = params => {
|
|
|
83
101
|
return [groups.concat(pluginsGroups)];
|
|
84
102
|
})
|
|
85
103
|
};
|
|
104
|
+
|
|
86
105
|
const clearGroupsCache = () => {
|
|
87
106
|
for (const loader of Object.values(dataLoaders)) {
|
|
88
107
|
loader.clearAll();
|
|
89
108
|
}
|
|
90
109
|
};
|
|
110
|
+
|
|
91
111
|
const getGroupsAsPlugins = () => {
|
|
92
112
|
const tenant = getTenant().id;
|
|
93
113
|
const locale = getLocale().code;
|
|
@@ -95,16 +115,19 @@ const createModelGroupsCrud = params => {
|
|
|
95
115
|
/**
|
|
96
116
|
* We need to filter out groups that are not for this tenant or locale.
|
|
97
117
|
* If it does not have tenant or locale define, it is for every locale and tenant
|
|
98
|
-
|
|
118
|
+
*/
|
|
119
|
+
.filter(plugin => {
|
|
99
120
|
const {
|
|
100
121
|
tenant: t,
|
|
101
122
|
locale: l
|
|
102
123
|
} = plugin.contentModelGroup;
|
|
124
|
+
|
|
103
125
|
if (t && t !== tenant) {
|
|
104
126
|
return false;
|
|
105
127
|
} else if (l && l !== locale) {
|
|
106
128
|
return false;
|
|
107
129
|
}
|
|
130
|
+
|
|
108
131
|
return true;
|
|
109
132
|
}).map(plugin => {
|
|
110
133
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugin.contentModelGroup), {}, {
|
|
@@ -114,23 +137,29 @@ const createModelGroupsCrud = params => {
|
|
|
114
137
|
});
|
|
115
138
|
});
|
|
116
139
|
};
|
|
140
|
+
|
|
117
141
|
const checkPermissions = check => {
|
|
118
142
|
return (0, _permissions.checkPermissions)(context, "cms.contentModelGroup", {
|
|
119
143
|
rwd: check
|
|
120
144
|
});
|
|
121
145
|
};
|
|
146
|
+
|
|
122
147
|
const groupsGet = async id => {
|
|
123
148
|
const groups = await dataLoaders.listGroups.load("listGroups");
|
|
124
149
|
const group = groups.find(g => g.id === id);
|
|
150
|
+
|
|
125
151
|
if (!group) {
|
|
126
152
|
throw new _handlerGraphql.NotFoundError(`Cms Group "${id}" was not found!`);
|
|
127
153
|
}
|
|
154
|
+
|
|
128
155
|
return group;
|
|
129
156
|
};
|
|
157
|
+
|
|
130
158
|
const groupsList = async params => {
|
|
131
159
|
const {
|
|
132
160
|
where
|
|
133
161
|
} = params || {};
|
|
162
|
+
|
|
134
163
|
try {
|
|
135
164
|
return await dataLoaders.listGroups.load("listGroups");
|
|
136
165
|
} catch (ex) {
|
|
@@ -138,21 +167,21 @@ const createModelGroupsCrud = params => {
|
|
|
138
167
|
where
|
|
139
168
|
}));
|
|
140
169
|
}
|
|
141
|
-
};
|
|
170
|
+
}; // create
|
|
171
|
+
|
|
142
172
|
|
|
143
|
-
// create
|
|
144
173
|
const onGroupBeforeCreate = (0, _pubsub.createTopic)("cms.onGroupBeforeCreate");
|
|
145
|
-
const onGroupAfterCreate = (0, _pubsub.createTopic)("cms.onGroupAfterCreate");
|
|
146
|
-
|
|
174
|
+
const onGroupAfterCreate = (0, _pubsub.createTopic)("cms.onGroupAfterCreate"); // update
|
|
175
|
+
|
|
147
176
|
const onGroupBeforeUpdate = (0, _pubsub.createTopic)("cms.onGroupBeforeUpdate");
|
|
148
|
-
const onGroupAfterUpdate = (0, _pubsub.createTopic)("cms.onGroupAfterUpdate");
|
|
149
|
-
|
|
177
|
+
const onGroupAfterUpdate = (0, _pubsub.createTopic)("cms.onGroupAfterUpdate"); // delete
|
|
178
|
+
|
|
150
179
|
const onGroupBeforeDelete = (0, _pubsub.createTopic)("cms.onGroupBeforeDelete");
|
|
151
180
|
const onGroupAfterDelete = (0, _pubsub.createTopic)("cms.onGroupAfterDelete");
|
|
152
|
-
|
|
153
181
|
/**
|
|
154
182
|
* We need to assign some default behaviors.
|
|
155
183
|
*/
|
|
184
|
+
|
|
156
185
|
(0, _beforeCreate.assignBeforeGroupCreate)({
|
|
157
186
|
onGroupBeforeCreate,
|
|
158
187
|
plugins: context.plugins,
|
|
@@ -177,6 +206,7 @@ const createModelGroupsCrud = params => {
|
|
|
177
206
|
onAfterGroupUpdate: onGroupAfterUpdate,
|
|
178
207
|
onBeforeGroupDelete: onGroupBeforeDelete,
|
|
179
208
|
onAfterGroupDelete: onGroupAfterDelete,
|
|
209
|
+
|
|
180
210
|
/**
|
|
181
211
|
* Released in 5.34.0
|
|
182
212
|
*/
|
|
@@ -213,6 +243,7 @@ const createModelGroupsCrud = params => {
|
|
|
213
243
|
if (!(0, _ownership.validateOwnership)(context, permission, group)) {
|
|
214
244
|
return false;
|
|
215
245
|
}
|
|
246
|
+
|
|
216
247
|
return (0, _access.validateGroupAccess)(context, permission, group);
|
|
217
248
|
});
|
|
218
249
|
},
|
|
@@ -239,6 +270,7 @@ const createModelGroupsCrud = params => {
|
|
|
239
270
|
},
|
|
240
271
|
webinyVersion: context.WEBINY_VERSION
|
|
241
272
|
});
|
|
273
|
+
|
|
242
274
|
try {
|
|
243
275
|
await onGroupBeforeCreate.publish({
|
|
244
276
|
group
|
|
@@ -267,18 +299,20 @@ const createModelGroupsCrud = params => {
|
|
|
267
299
|
const updatedDataJson = await input.toJSON({
|
|
268
300
|
onlyDirty: true
|
|
269
301
|
});
|
|
270
|
-
|
|
271
302
|
/**
|
|
272
303
|
* No need to continue if no values were changed
|
|
273
304
|
*/
|
|
305
|
+
|
|
274
306
|
if (Object.keys(updatedDataJson).length === 0) {
|
|
275
307
|
return original;
|
|
276
308
|
}
|
|
309
|
+
|
|
277
310
|
const group = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), updatedDataJson), {}, {
|
|
278
311
|
locale: getLocale().code,
|
|
279
312
|
tenant: getTenant().id,
|
|
280
313
|
savedOn: new Date().toISOString()
|
|
281
314
|
});
|
|
315
|
+
|
|
282
316
|
try {
|
|
283
317
|
await onGroupBeforeUpdate.publish({
|
|
284
318
|
original,
|
|
@@ -306,6 +340,7 @@ const createModelGroupsCrud = params => {
|
|
|
306
340
|
const permission = await checkPermissions("d");
|
|
307
341
|
const group = await groupsGet(id);
|
|
308
342
|
(0, _ownership.checkOwnership)(context, permission, group);
|
|
343
|
+
|
|
309
344
|
try {
|
|
310
345
|
await onGroupBeforeDelete.publish({
|
|
311
346
|
group
|
|
@@ -322,8 +357,10 @@ const createModelGroupsCrud = params => {
|
|
|
322
357
|
id
|
|
323
358
|
}));
|
|
324
359
|
}
|
|
360
|
+
|
|
325
361
|
return true;
|
|
326
362
|
}
|
|
327
363
|
};
|
|
328
364
|
};
|
|
365
|
+
|
|
329
366
|
exports.createModelGroupsCrud = createModelGroupsCrud;
|
|
@@ -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","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupBeforeDelete","onGroupAfterDelete","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 OnGroupBeforeCreateTopicParams,\n OnGroupAfterCreateTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupAfterDeleteTopicParams\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 // create\n const onGroupBeforeCreate =\n createTopic<OnGroupBeforeCreateTopicParams>(\"cms.onGroupBeforeCreate\");\n const onGroupAfterCreate = createTopic<OnGroupAfterCreateTopicParams>(\"cms.onGroupAfterCreate\");\n // update\n const onGroupBeforeUpdate =\n createTopic<OnGroupBeforeUpdateTopicParams>(\"cms.onGroupBeforeUpdate\");\n const onGroupAfterUpdate = createTopic<OnGroupAfterUpdateTopicParams>(\"cms.onGroupAfterUpdate\");\n // delete\n const onGroupBeforeDelete =\n createTopic<OnGroupBeforeDeleteTopicParams>(\"cms.onGroupBeforeDelete\");\n const onGroupAfterDelete = createTopic<OnGroupAfterDeleteTopicParams>(\"cms.onGroupAfterDelete\");\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 onGroupBeforeUpdate,\n onGroupAfterUpdate,\n onGroupBeforeDelete,\n onGroupAfterDelete,\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 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 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 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 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 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;AAxCA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AAiCA,MAAMA,4BAA4B,GAAG,IAAAC,kBAAU,EAAC;EAC5CC,IAAI,EAAE,IAAAC,cAAM,EAAC;IAAEC,UAAU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MAEjC,IAAA2D,yBAAc,EAAChE,OAAO,EAAE+D,UAAU,EAAEpD,KAAK,CAAC;MAE1C,IAAI;QACA,MAAMwC,mBAAmB,CAACiC,OAAO,CAAC;UAC9BzE;QACJ,CAAC,CAAC;QAEF,MAAMZ,iBAAiB,CAACa,MAAM,CAACoF,MAAM,CAAC;UAAErF;QAAM,CAAC,CAAC;QAChDK,gBAAgB,EAAE;QAElB,MAAMoC,kBAAkB,CAACgC,OAAO,CAAC;UAC7BzE;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAO+B,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CAACD,EAAE,CAACE,OAAO,EAAEF,EAAE,CAACnC,IAAI,IAAI,cAAc,8DACnDmC,EAAE,CAACG,IAAI,IAAI,CAAC,CAAC;UACjBxC;QAAE,GACJ;MACN;MAEA,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
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","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupBeforeDelete","onGroupAfterDelete","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 OnGroupBeforeCreateTopicParams,\n OnGroupAfterCreateTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupAfterDeleteTopicParams\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 // create\n const onGroupBeforeCreate =\n createTopic<OnGroupBeforeCreateTopicParams>(\"cms.onGroupBeforeCreate\");\n const onGroupAfterCreate = createTopic<OnGroupAfterCreateTopicParams>(\"cms.onGroupAfterCreate\");\n // update\n const onGroupBeforeUpdate =\n createTopic<OnGroupBeforeUpdateTopicParams>(\"cms.onGroupBeforeUpdate\");\n const onGroupAfterUpdate = createTopic<OnGroupAfterUpdateTopicParams>(\"cms.onGroupAfterUpdate\");\n // delete\n const onGroupBeforeDelete =\n createTopic<OnGroupBeforeDeleteTopicParams>(\"cms.onGroupBeforeDelete\");\n const onGroupAfterDelete = createTopic<OnGroupAfterDeleteTopicParams>(\"cms.onGroupAfterDelete\");\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 onGroupBeforeUpdate,\n onGroupAfterUpdate,\n onGroupBeforeDelete,\n onGroupAfterDelete,\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 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 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 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 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 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;;AAxCA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AAiCA,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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MoC,kBAAkB,CAACgC,OAAnB,CAA2B;UAC7BzE;QAD6B,CAA3B,CAAN;MAGH,CAXD,CAWE,OAAO+B,EAAP,EAAW;QACT,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;EA7LE,CAAP;AA+LH,CA1TM"}
|
package/crud/index.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.createCrud = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
var _api = require("@webiny/api");
|
|
13
|
+
|
|
10
14
|
var _contentModelGroup = require("./contentModelGroup.crud");
|
|
15
|
+
|
|
11
16
|
var _contentModel = require("./contentModel.crud");
|
|
17
|
+
|
|
12
18
|
var _contentEntry = require("./contentEntry.crud");
|
|
19
|
+
|
|
13
20
|
var _system = require("./system.crud");
|
|
21
|
+
|
|
14
22
|
var _settings = require("./settings.crud");
|
|
23
|
+
|
|
15
24
|
const createCrud = params => {
|
|
16
25
|
const {
|
|
17
26
|
storageOperations
|
|
@@ -20,15 +29,19 @@ const createCrud = params => {
|
|
|
20
29
|
const getLocale = () => {
|
|
21
30
|
return context.cms.getLocale();
|
|
22
31
|
};
|
|
32
|
+
|
|
23
33
|
const getIdentity = () => {
|
|
24
34
|
return context.security.getIdentity();
|
|
25
35
|
};
|
|
36
|
+
|
|
26
37
|
const getTenant = () => {
|
|
27
38
|
return context.tenancy.getCurrentTenant();
|
|
28
39
|
};
|
|
40
|
+
|
|
29
41
|
if (storageOperations.beforeInit) {
|
|
30
42
|
await storageOperations.beforeInit(context);
|
|
31
43
|
}
|
|
44
|
+
|
|
32
45
|
context.cms = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, context.cms), {}, {
|
|
33
46
|
storageOperations
|
|
34
47
|
}, (0, _system.createSystemCrud)({
|
|
@@ -60,10 +73,13 @@ const createCrud = params => {
|
|
|
60
73
|
getTenant,
|
|
61
74
|
storageOperations
|
|
62
75
|
}));
|
|
76
|
+
|
|
63
77
|
if (!storageOperations.init) {
|
|
64
78
|
return;
|
|
65
79
|
}
|
|
80
|
+
|
|
66
81
|
await storageOperations.init(context);
|
|
67
82
|
});
|
|
68
83
|
};
|
|
84
|
+
|
|
69
85
|
exports.createCrud = createCrud;
|
package/crud/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createCrud","params","storageOperations","ContextPlugin","context","getLocale","cms","getIdentity","security","getTenant","tenancy","getCurrentTenant","beforeInit","createSystemCrud","createSettingsCrud","createModelGroupsCrud","createModelsCrud","createContentEntryCrud","init"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CmsContext, HeadlessCmsStorageOperations } from \"~/types\";\nimport { createModelGroupsCrud } from \"./contentModelGroup.crud\";\nimport { createModelsCrud } from \"./contentModel.crud\";\nimport { createContentEntryCrud } from \"./contentEntry.crud\";\nimport { createSystemCrud } from \"./system.crud\";\nimport { createSettingsCrud } from \"./settings.crud\";\n\nexport interface CrudParams {\n storageOperations: HeadlessCmsStorageOperations;\n}\n\nexport const createCrud = (params: CrudParams) => {\n const { storageOperations } = params;\n return new ContextPlugin<CmsContext>(async context => {\n const getLocale = () => {\n return context.cms.getLocale();\n };\n\n const getIdentity = () => {\n return context.security.getIdentity();\n };\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n if (storageOperations.beforeInit) {\n await storageOperations.beforeInit(context);\n }\n\n context.cms = {\n ...context.cms,\n storageOperations,\n ...createSystemCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createSettingsCrud({\n context,\n getTenant,\n getLocale,\n storageOperations\n }),\n ...createModelGroupsCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createModelsCrud({\n context,\n getLocale,\n getTenant,\n getIdentity,\n storageOperations\n }),\n ...createContentEntryCrud({\n context,\n getIdentity,\n getTenant,\n storageOperations\n })\n };\n\n if (!storageOperations.init) {\n return;\n }\n await storageOperations.init(context);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createCrud","params","storageOperations","ContextPlugin","context","getLocale","cms","getIdentity","security","getTenant","tenancy","getCurrentTenant","beforeInit","createSystemCrud","createSettingsCrud","createModelGroupsCrud","createModelsCrud","createContentEntryCrud","init"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CmsContext, HeadlessCmsStorageOperations } from \"~/types\";\nimport { createModelGroupsCrud } from \"./contentModelGroup.crud\";\nimport { createModelsCrud } from \"./contentModel.crud\";\nimport { createContentEntryCrud } from \"./contentEntry.crud\";\nimport { createSystemCrud } from \"./system.crud\";\nimport { createSettingsCrud } from \"./settings.crud\";\n\nexport interface CrudParams {\n storageOperations: HeadlessCmsStorageOperations;\n}\n\nexport const createCrud = (params: CrudParams) => {\n const { storageOperations } = params;\n return new ContextPlugin<CmsContext>(async context => {\n const getLocale = () => {\n return context.cms.getLocale();\n };\n\n const getIdentity = () => {\n return context.security.getIdentity();\n };\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n if (storageOperations.beforeInit) {\n await storageOperations.beforeInit(context);\n }\n\n context.cms = {\n ...context.cms,\n storageOperations,\n ...createSystemCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createSettingsCrud({\n context,\n getTenant,\n getLocale,\n storageOperations\n }),\n ...createModelGroupsCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createModelsCrud({\n context,\n getLocale,\n getTenant,\n getIdentity,\n storageOperations\n }),\n ...createContentEntryCrud({\n context,\n getIdentity,\n getTenant,\n storageOperations\n })\n };\n\n if (!storageOperations.init) {\n return;\n }\n await storageOperations.init(context);\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAMO,MAAMA,UAAU,GAAIC,MAAD,IAAwB;EAC9C,MAAM;IAAEC;EAAF,IAAwBD,MAA9B;EACA,OAAO,IAAIE,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;IAClD,MAAMC,SAAS,GAAG,MAAM;MACpB,OAAOD,OAAO,CAACE,GAAR,CAAYD,SAAZ,EAAP;IACH,CAFD;;IAIA,MAAME,WAAW,GAAG,MAAM;MACtB,OAAOH,OAAO,CAACI,QAAR,CAAiBD,WAAjB,EAAP;IACH,CAFD;;IAIA,MAAME,SAAS,GAAG,MAAM;MACpB,OAAOL,OAAO,CAACM,OAAR,CAAgBC,gBAAhB,EAAP;IACH,CAFD;;IAIA,IAAIT,iBAAiB,CAACU,UAAtB,EAAkC;MAC9B,MAAMV,iBAAiB,CAACU,UAAlB,CAA6BR,OAA7B,CAAN;IACH;;IAEDA,OAAO,CAACE,GAAR,+KACOF,OAAO,CAACE,GADf;MAEIJ;IAFJ,GAGO,IAAAW,wBAAA,EAAiB;MAChBT,OADgB;MAEhBK,SAFgB;MAGhBJ,SAHgB;MAIhBE,WAJgB;MAKhBL;IALgB,CAAjB,CAHP,GAUO,IAAAY,4BAAA,EAAmB;MAClBV,OADkB;MAElBK,SAFkB;MAGlBJ,SAHkB;MAIlBH;IAJkB,CAAnB,CAVP,GAgBO,IAAAa,wCAAA,EAAsB;MACrBX,OADqB;MAErBK,SAFqB;MAGrBJ,SAHqB;MAIrBE,WAJqB;MAKrBL;IALqB,CAAtB,CAhBP,GAuBO,IAAAc,8BAAA,EAAiB;MAChBZ,OADgB;MAEhBC,SAFgB;MAGhBI,SAHgB;MAIhBF,WAJgB;MAKhBL;IALgB,CAAjB,CAvBP,GA8BO,IAAAe,oCAAA,EAAuB;MACtBb,OADsB;MAEtBG,WAFsB;MAGtBE,SAHsB;MAItBP;IAJsB,CAAvB,CA9BP;;IAsCA,IAAI,CAACA,iBAAiB,CAACgB,IAAvB,EAA6B;MACzB;IACH;;IACD,MAAMhB,iBAAiB,CAACgB,IAAlB,CAAuBd,OAAvB,CAAN;EACH,CA3DM,CAAP;AA4DH,CA9DM"}
|
package/crud/settings.crud.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.createSettingsCrud = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
var _permissions = require("../utils/permissions");
|
|
13
|
+
|
|
10
14
|
const createSettingsCrud = params => {
|
|
11
15
|
const {
|
|
12
16
|
storageOperations,
|
|
@@ -14,9 +18,11 @@ const createSettingsCrud = params => {
|
|
|
14
18
|
getTenant,
|
|
15
19
|
getLocale
|
|
16
20
|
} = params;
|
|
21
|
+
|
|
17
22
|
const checkPermissions = () => {
|
|
18
23
|
return (0, _permissions.checkPermissions)(context, "cms.settings");
|
|
19
24
|
};
|
|
25
|
+
|
|
20
26
|
return {
|
|
21
27
|
getSettings: async () => {
|
|
22
28
|
await checkPermissions();
|
|
@@ -35,12 +41,14 @@ const createSettingsCrud = params => {
|
|
|
35
41
|
tenant: getTenant().id,
|
|
36
42
|
locale: getLocale().code
|
|
37
43
|
});
|
|
44
|
+
|
|
38
45
|
if (!original) {
|
|
39
46
|
await storageOperations.settings.create({
|
|
40
47
|
settings
|
|
41
48
|
});
|
|
42
49
|
return;
|
|
43
50
|
}
|
|
51
|
+
|
|
44
52
|
await storageOperations.settings.update({
|
|
45
53
|
settings
|
|
46
54
|
});
|
|
@@ -51,9 +59,11 @@ const createSettingsCrud = params => {
|
|
|
51
59
|
tenant: getTenant().id,
|
|
52
60
|
locale: getLocale().code
|
|
53
61
|
});
|
|
62
|
+
|
|
54
63
|
if (!(settings !== null && settings !== void 0 && settings.contentModelLastChange)) {
|
|
55
64
|
return new Date();
|
|
56
65
|
}
|
|
66
|
+
|
|
57
67
|
return settings.contentModelLastChange;
|
|
58
68
|
} catch (ex) {
|
|
59
69
|
console.log({
|
|
@@ -64,8 +74,10 @@ const createSettingsCrud = params => {
|
|
|
64
74
|
}
|
|
65
75
|
});
|
|
66
76
|
}
|
|
77
|
+
|
|
67
78
|
return new Date();
|
|
68
79
|
}
|
|
69
80
|
};
|
|
70
81
|
};
|
|
82
|
+
|
|
71
83
|
exports.createSettingsCrud = createSettingsCrud;
|
|
@@ -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":"
|
|
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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