@webiny/api-headless-cms 0.0.0-unstable.aad28a72ae → 0.0.0-unstable.bca7b3e350
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.d.ts +5 -2
- package/context.js +53 -19
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +0 -5
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +0 -3
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +0 -3
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +1 -40
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +12 -28
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +5 -61
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +1 -12
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.js +72 -155
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +0 -2
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +0 -2
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +0 -2
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +0 -2
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +7 -36
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +0 -10
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +2 -7
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +0 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +0 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validateLayout.js +0 -8
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +3 -4
- package/crud/contentModel/validateModel.js +6 -11
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +3 -4
- package/crud/contentModel/validateModelFields.js +84 -75
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +97 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +63 -158
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +0 -12
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +0 -8
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +0 -5
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +21 -93
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.js +0 -12
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +2 -37
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +0 -36
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +0 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +6 -14
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/createExecutableSchema.d.ts +7 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +31 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +70 -92
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -46
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +9 -13
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +53 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +39 -65
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +9 -22
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +21 -23
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +13 -24
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +0 -26
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +6 -16
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +0 -10
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +5 -10
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +6 -12
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +0 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +0 -3
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +0 -3
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +0 -8
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +0 -3
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +63 -65
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +69 -85
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +0 -12
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +0 -17
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +3 -29
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +2 -18
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
- package/graphqlFields/dynamicZone/index.js +0 -2
- package/graphqlFields/dynamicZone/index.js.map +1 -1
- package/graphqlFields/file.js +0 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +0 -10
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +0 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +0 -10
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +0 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +1 -37
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +23 -53
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +0 -9
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +0 -11
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +2 -27
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +0 -16
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +0 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +27 -28
- package/parameters/context.js +0 -4
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +0 -11
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +0 -8
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +1 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +0 -11
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.js +0 -8
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +0 -5
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.js +2 -38
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +0 -7
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.js +0 -9
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -10
- package/plugins/index.js.map +1 -1
- package/storage/default.js +0 -3
- package/storage/default.js.map +1 -1
- package/storage/object.js +0 -19
- package/storage/object.js.map +1 -1
- package/types.d.ts +56 -15
- package/types.js +22 -72
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +3 -26
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +0 -3
- package/upgrades/index.js.map +1 -1
- package/utils/access.js +11 -25
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +0 -13
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +9 -33
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +0 -26
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.js +4 -15
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.js +0 -9
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +10 -26
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +0 -5
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.js +0 -2
- package/utils/getBaseFieldType.js.map +1 -1
- package/utils/getEntryTitle.js +0 -9
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +23 -19
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.js +0 -8
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +8 -23
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +0 -6
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.js +0 -9
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +0 -13
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +0 -9
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +1 -10
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +19 -11
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +0 -4
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +0 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +0 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/dynamicZone.js +0 -4
- package/validators/dynamicZone.js.map +1 -1
- package/validators/gte.js +0 -8
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -8
- package/validators/in.js.map +1 -1
- package/validators/index.js +0 -16
- package/validators/index.js.map +1 -1
- package/validators/lte.js +0 -8
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -8
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -8
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +0 -9
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +0 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +0 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +0 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +0 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +0 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +0 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +0 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +0 -8
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +0 -8
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +0 -7
- package/validators/unique.js.map +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -85
- package/crud/index.js.map +0 -1
- package/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -77
- package/utils/filterModelFields.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTypeFromFields","params","typeOfType","model","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","createTypeName","modelId","typeFields","nestedTypes","replace","RegExp","f","result","renderField","field","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { createTypeName } from \"~/utils/createTypeName\";\nimport { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n model: CmsModel;\n type: ApiEndpoint;\n typeNamePrefix: string;\n fields: CmsModelField[];\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface TypeFromFieldResponse {\n fieldType: string;\n typeDefs: string;\n}\n\nexport const createTypeFromFields = (params: TypeFromFieldParams): TypeFromFieldResponse | null => {\n const { typeOfType, model, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = createTypeName(model.modelId);\n\n const typeFields = [];\n const nestedTypes = [];\n\n // Once the loop below starts, we'll be executing a recursive \"object\" type generation.\n // The main trick here is that nested objects don't know who the parent is, and will generate\n // type names using the \"model\", as if they're at the top level:\n // Every time the types are returned, we need to replace the model name in the generated type name\n // with the actual prefix which includes parent field name type.\n const replace = new RegExp(`${mTypeName}_`, \"g\");\n\n for (const f of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field: f, type, model, fieldTypePlugins })\n : renderInputField({ field: f, model, fieldTypePlugins });\n\n if (!result) {\n continue;\n }\n\n const { fields, typeDefs } = result;\n\n typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));\n if (typeDefs) {\n nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));\n }\n }\n\n return {\n fieldType: `${typeNamePrefix}${typeSuffix}`,\n typeDefs: /* GraphQL */ `\n ${nestedTypes.join(\"\\n\")}\n\n ${typeOfType} ${typeNamePrefix}${typeSuffix} {\n ${typeFields.join(\"\\n\")}\n }\n `\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createTypeFromFields","params","typeOfType","model","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","createTypeName","modelId","typeFields","nestedTypes","replace","RegExp","f","result","renderField","field","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { createTypeName } from \"~/utils/createTypeName\";\nimport { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n model: CmsModel;\n type: ApiEndpoint;\n typeNamePrefix: string;\n fields: CmsModelField[];\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface TypeFromFieldResponse {\n fieldType: string;\n typeDefs: string;\n}\n\nexport const createTypeFromFields = (params: TypeFromFieldParams): TypeFromFieldResponse | null => {\n const { typeOfType, model, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = createTypeName(model.modelId);\n\n const typeFields = [];\n const nestedTypes = [];\n\n // Once the loop below starts, we'll be executing a recursive \"object\" type generation.\n // The main trick here is that nested objects don't know who the parent is, and will generate\n // type names using the \"model\", as if they're at the top level:\n // Every time the types are returned, we need to replace the model name in the generated type name\n // with the actual prefix which includes parent field name type.\n const replace = new RegExp(`${mTypeName}_`, \"g\");\n\n for (const f of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field: f, type, model, fieldTypePlugins })\n : renderInputField({ field: f, model, fieldTypePlugins });\n\n if (!result) {\n continue;\n }\n\n const { fields, typeDefs } = result;\n\n typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));\n if (typeDefs) {\n nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));\n }\n }\n\n return {\n fieldType: `${typeNamePrefix}${typeSuffix}`,\n typeDefs: /* GraphQL */ `\n ${nestedTypes.join(\"\\n\")}\n\n ${typeOfType} ${typeNamePrefix}${typeSuffix} {\n ${typeFields.join(\"\\n\")}\n }\n `\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAiBO,MAAMA,oBAAo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ActB,UAAW,IAAGG,cAAe,GAAEG,UAAW;AACxD,kBAAkBI,UAAU,CAACY,IAAI,CAAC,IAAI,CAAE;AACxC;AACA;EACI,CAAC;AACL,CAAC;AAAC"}
|
package/utils/createTypeName.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createTypeName = exports.createReadTypeName = exports.createManageTypeName = void 0;
|
|
9
|
-
|
|
10
8
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
11
|
-
|
|
12
9
|
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
13
|
-
|
|
14
10
|
const createTypeName = modelId => {
|
|
15
11
|
return (0, _upperFirst.default)((0, _camelCase.default)(modelId));
|
|
16
12
|
};
|
|
17
|
-
|
|
18
13
|
exports.createTypeName = createTypeName;
|
|
19
|
-
|
|
20
14
|
const createReadTypeName = baseTypeName => {
|
|
21
15
|
return createTypeName(baseTypeName);
|
|
22
16
|
};
|
|
23
|
-
|
|
24
17
|
exports.createReadTypeName = createReadTypeName;
|
|
25
|
-
|
|
26
18
|
const createManageTypeName = baseTypeName => {
|
|
27
19
|
return createTypeName(baseTypeName);
|
|
28
20
|
};
|
|
29
|
-
|
|
30
21
|
exports.createManageTypeName = createManageTypeName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTypeName","modelId","upperFirst","camelCase","createReadTypeName","baseTypeName","createManageTypeName"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(camelCase(modelId));\n};\n\nexport const createReadTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n\nexport const createManageTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createTypeName","modelId","upperFirst","camelCase","createReadTypeName","baseTypeName","createManageTypeName"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(camelCase(modelId));\n};\n\nexport const createReadTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n\nexport const createManageTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,cAAc,GAAIC,OAAe,IAAa;EACvD,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,OAAO,CAAC,CAAC;AACzC,CAAC;AAAC;AAEK,MAAMG,kBAAkB,GAAIC,YAAoB,IAAa;EAChE,OAAOL,cAAc,CAACK,YAAY,CAAC;AACvC,CAAC;AAAC;AAEK,MAAMC,oBAAoB,GAAID,YAAoB,IAAa;EAClE,OAAOL,cAAc,CAACK,YAAY,CAAC;AACvC,CAAC;AAAC"}
|
package/utils/entryStorage.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
|
|
15
|
-
|
|
16
11
|
var _getBaseFieldType = require("./getBaseFieldType");
|
|
17
|
-
|
|
18
12
|
const getStoragePluginFactory = context => {
|
|
19
13
|
let defaultStoragePlugin;
|
|
20
|
-
const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type)
|
|
14
|
+
const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type)
|
|
15
|
+
// we reverse plugins because we want to get latest added only
|
|
21
16
|
.reverse().reduce((collection, plugin) => {
|
|
22
17
|
/**
|
|
23
18
|
* Check if it's a default plugin and set it - always override the previous one.
|
|
@@ -26,12 +21,11 @@ const getStoragePluginFactory = context => {
|
|
|
26
21
|
defaultStoragePlugin = plugin;
|
|
27
22
|
return collection;
|
|
28
23
|
}
|
|
24
|
+
|
|
29
25
|
/**
|
|
30
26
|
* We will just set the plugin for given type.
|
|
31
27
|
* The last one will override existing one - so users can override our default ones.
|
|
32
28
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
29
|
collection[plugin.fieldType] = plugin;
|
|
36
30
|
return collection;
|
|
37
31
|
}, {});
|
|
@@ -39,23 +33,20 @@ const getStoragePluginFactory = context => {
|
|
|
39
33
|
return plugins[fieldType] || defaultStoragePlugin;
|
|
40
34
|
};
|
|
41
35
|
};
|
|
36
|
+
|
|
42
37
|
/**
|
|
43
38
|
* This should be used when transforming the whole entry.
|
|
44
39
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
40
|
const entryStorageTransform = async (context, model, operation, entry) => {
|
|
48
41
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
49
42
|
const transformedValues = {};
|
|
50
|
-
|
|
51
43
|
for (const field of model.fields) {
|
|
52
44
|
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
53
|
-
const plugin = getStoragePlugin(baseType);
|
|
54
|
-
|
|
45
|
+
const plugin = getStoragePlugin(baseType);
|
|
46
|
+
// TODO: remove this once plugins are converted into classes
|
|
55
47
|
if (typeof plugin[operation] !== "function") {
|
|
56
48
|
throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
transformedValues[field.fieldId] = await plugin[operation]({
|
|
60
51
|
plugins: context.plugins,
|
|
61
52
|
model,
|
|
@@ -64,32 +55,26 @@ const entryStorageTransform = async (context, model, operation, entry) => {
|
|
|
64
55
|
getStoragePlugin
|
|
65
56
|
});
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
69
59
|
values: transformedValues
|
|
70
60
|
});
|
|
71
61
|
};
|
|
62
|
+
|
|
72
63
|
/**
|
|
73
64
|
* A function that is used in crud to transform entry into the storage type.
|
|
74
65
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
66
|
const entryToStorageTransform = async (context, model, entry) => {
|
|
78
67
|
return entryStorageTransform(context, model, "toStorage", entry);
|
|
79
68
|
};
|
|
69
|
+
|
|
80
70
|
/**
|
|
81
71
|
* A function that is used to transform the whole entry from storage into its native form.
|
|
82
72
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
73
|
exports.entryToStorageTransform = entryToStorageTransform;
|
|
86
|
-
|
|
87
74
|
const entryFromStorageTransform = async (context, model, entry) => {
|
|
88
75
|
return entryStorageTransform(context, model, "fromStorage", entry);
|
|
89
76
|
};
|
|
90
|
-
|
|
91
77
|
exports.entryFromStorageTransform = entryFromStorageTransform;
|
|
92
|
-
|
|
93
78
|
/*
|
|
94
79
|
* A function that is used to transform a single field from storage
|
|
95
80
|
*/
|
|
@@ -102,12 +87,12 @@ const entryFieldFromStorageTransform = async params => {
|
|
|
102
87
|
} = params;
|
|
103
88
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
104
89
|
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
105
|
-
const plugin = getStoragePlugin(baseType);
|
|
90
|
+
const plugin = getStoragePlugin(baseType);
|
|
106
91
|
|
|
92
|
+
// TODO: remove this once plugins are converted into classes
|
|
107
93
|
if (typeof plugin.fromStorage !== "function") {
|
|
108
94
|
throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
|
|
109
95
|
}
|
|
110
|
-
|
|
111
96
|
return plugin.fromStorage({
|
|
112
97
|
plugins: context.plugins,
|
|
113
98
|
model,
|
|
@@ -116,5 +101,4 @@ const entryFieldFromStorageTransform = async params => {
|
|
|
116
101
|
getStoragePlugin
|
|
117
102
|
});
|
|
118
103
|
};
|
|
119
|
-
|
|
120
104
|
exports.entryFieldFromStorageTransform = entryFieldFromStorageTransform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: CmsContext;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: CmsContext;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAEA;AAMA,MAAMA,uBAAgD,GAAGC,OAAO,IAAI;EAChE,IAAIC,oBAA4C;EAEhD,MAAMC,OA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
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.filterAsync = void 0;
|
|
7
|
-
|
|
8
7
|
const filterAsync = async (items, predicate) => {
|
|
9
8
|
const filteredItems = [];
|
|
10
|
-
|
|
11
9
|
for (let i = 0; i < items.length; i++) {
|
|
12
10
|
const item = items[i];
|
|
13
11
|
const valid = await predicate(item);
|
|
14
|
-
|
|
15
12
|
if (valid) {
|
|
16
13
|
filteredItems.push(item);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
return filteredItems;
|
|
21
17
|
};
|
|
22
|
-
|
|
23
18
|
exports.filterAsync = filterAsync;
|
package/utils/filterAsync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":";;;;;;AAAO,MAAMA,WAAW,GAAG,OACvBC,KAAU,EACVC,SAAyC,KAC1B;EACf,MAAMC,aAAa,GAAG,EAAE;EAExB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAME,IAAI,GAAGL,KAAK,CAACG,CAAC,CAAC;IACrB,MAAMG,KAAK,GAAG,MAAML,SAAS,CAACI,IAAI,CAAC;IACnC,IAAIC,KAAK,EAAE;MACPJ,aAAa,CAACK,IAAI,CAACF,IAAI,CAAC;IAC5B;EACJ;EAEA,OAAOH,aAAa;AACxB,CAAC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getBaseFieldType","field","type","split"],"sources":["getBaseFieldType.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const getBaseFieldType = (field: { type: CmsModelField[\"type\"] }) => {\n return field.type.split(\":\")[0];\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getBaseFieldType","field","type","split"],"sources":["getBaseFieldType.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const getBaseFieldType = (field: { type: CmsModelField[\"type\"] }) => {\n return field.type.split(\":\")[0];\n};\n"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAIC,KAAsC,IAAK;EACxE,OAAOA,KAAK,CAACC,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAAC"}
|
package/utils/getEntryTitle.js
CHANGED
|
@@ -4,40 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getEntryTitle = getEntryTitle;
|
|
7
|
-
|
|
8
7
|
function getEntryTitle(model, entry) {
|
|
9
8
|
if (!model.titleFieldId) {
|
|
10
9
|
return entry.id;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const field = model.fields.find(f => f.fieldId === model.titleFieldId);
|
|
14
|
-
|
|
15
12
|
if (!field) {
|
|
16
13
|
return entry.id;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
const titleFieldId = field.fieldId;
|
|
20
16
|
const titleValue = entry.values[titleFieldId];
|
|
21
|
-
|
|
22
17
|
if (!titleValue) {
|
|
23
18
|
return entry.id;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
const {
|
|
27
21
|
enabled = false,
|
|
28
22
|
values
|
|
29
23
|
} = field.predefinedValues || {};
|
|
30
|
-
|
|
31
24
|
if (!enabled || !values || Array.isArray(values) === false) {
|
|
32
25
|
return titleValue;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
for (const value of values) {
|
|
36
28
|
// needs to be loose because titleValue can be a number and value can be a string - but it must match
|
|
37
29
|
if (value.value == titleValue) {
|
|
38
30
|
return value.label;
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
return titleValue;
|
|
43
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":";;;;;;AAEO,SAASA,aAAa,CAACC,KAAe,EAAEC,KAAe,EAAU;EACpE,IAAI,CAACD,KAAK,CAACE,YAAY,EAAE;IACrB,OAAOD,KAAK,CAACE,EAAE;EACnB;EACA,MAAMC,KAAK,GAAGJ,KAAK,CAACK,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKR,KAAK,CAACE,YAAY,CAAC;EACtE,IAAI,CAACE,KAAK,EAAE;IACR,OAAOH,KAAK,CAACE,EAAE;EACnB;EACA,MAAMD,YAAY,GAAGE,KAAK,CAACI,OAAO;EAClC,MAAMC,UAAU,GAAGR,KAAK,CAACS,MAAM,CAACR,YAAY,CAAC;EAC7C,IAAI,CAACO,UAAU,EAAE;IACb,OAAOR,KAAK,CAACE,EAAE;EACnB;EAEA,MAAM;IAAEQ,OAAO,GAAG,KAAK;IAAED;EAAO,CAAC,GAAGN,KAAK,CAACQ,gBAAgB,IAAI,CAAC,CAAC;EAChE,IAAI,CAACD,OAAO,IAAI,CAACD,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,KAAK,KAAK,EAAE;IACxD,OAAOD,UAAU;EACrB;EACA,KAAK,MAAMM,KAAK,IAAIL,MAAM,EAAE;IACxB;IACA,IAAIK,KAAK,CAACA,KAAK,IAAIN,UAAU,EAAE;MAC3B,OAAOM,KAAK,CAACC,KAAK;IACtB;EACJ;EACA,OAAOP,UAAU;AACrB"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { CmsModel,
|
|
2
|
-
import {
|
|
3
|
-
interface
|
|
1
|
+
import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from "../types";
|
|
2
|
+
import { CmsGraphQLSchemaPlugin } from "../plugins";
|
|
3
|
+
interface Params {
|
|
4
4
|
models: CmsModel[];
|
|
5
5
|
fieldTypePlugins: CmsFieldTypePlugins;
|
|
6
6
|
type: ApiEndpoint;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
(params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];
|
|
10
|
-
}
|
|
11
|
-
export declare const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins;
|
|
8
|
+
export declare const createGraphQLSchemaPluginFromFieldPlugins: (params: Params) => CmsGraphQLSchemaPlugin<import("../types").CmsContext>[];
|
|
12
9
|
export {};
|
|
@@ -3,33 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createGraphQLSchemaPluginFromFieldPlugins = void 0;
|
|
7
|
+
var _plugins = require("../plugins");
|
|
7
8
|
const TYPE_MAP = {
|
|
8
9
|
preview: "read",
|
|
9
10
|
read: "read",
|
|
10
11
|
manage: "manage"
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const createGraphQLSchemaPluginFromFieldPlugins = params => {
|
|
14
|
+
const {
|
|
15
|
+
models,
|
|
16
|
+
fieldTypePlugins,
|
|
17
|
+
type
|
|
18
|
+
} = params;
|
|
19
|
+
const plugins = [];
|
|
20
|
+
for (const key in fieldTypePlugins) {
|
|
21
|
+
const fieldTypePlugin = fieldTypePlugins[key];
|
|
22
|
+
if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {
|
|
23
|
+
continue;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;
|
|
26
|
+
// Render gql types generated by field type plugins
|
|
25
27
|
if (!createSchema) {
|
|
26
|
-
|
|
28
|
+
continue;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
return createSchema({
|
|
30
|
+
const schema = createSchema({
|
|
30
31
|
models
|
|
31
32
|
});
|
|
32
|
-
|
|
33
|
+
const plugin = new _plugins.CmsGraphQLSchemaPlugin(schema);
|
|
34
|
+
plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;
|
|
35
|
+
plugins.push(plugin);
|
|
36
|
+
}
|
|
37
|
+
return plugins;
|
|
33
38
|
};
|
|
34
|
-
|
|
35
|
-
exports.getSchemaFromFieldPlugins = getSchemaFromFieldPlugins;
|
|
39
|
+
exports.createGraphQLSchemaPluginFromFieldPlugins = createGraphQLSchemaPluginFromFieldPlugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TYPE_MAP","preview","read","manage","
|
|
1
|
+
{"version":3,"names":["TYPE_MAP","preview","read","manage","createGraphQLSchemaPluginFromFieldPlugins","params","models","fieldTypePlugins","type","plugins","key","fieldTypePlugin","createSchema","schema","plugin","CmsGraphQLSchemaPlugin","name","fieldType","push"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\ninterface Params {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\nexport const createGraphQLSchemaPluginFromFieldPlugins = (params: Params) => {\n const { models, fieldTypePlugins, type } = params;\n\n const plugins: CmsGraphQLSchemaPlugin[] = [];\n for (const key in fieldTypePlugins) {\n const fieldTypePlugin = fieldTypePlugins[key];\n if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {\n continue;\n }\n const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n continue;\n }\n const schema = createSchema({ models });\n\n const plugin = new CmsGraphQLSchemaPlugin(schema);\n plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;\n plugins.push(plugin);\n }\n return plugins;\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,MAAM;EACfC,IAAI,EAAE,MAAM;EACZC,MAAM,EAAE;AACZ,CAAC;AAOM,MAAMC,yCAAyC,GAAIC,MAAc,IAAK;EACzE,MAAM;IAAEC,MAAM;IAAEC,gBAAgB;IAAEC;EAAK,CAAC,GAAGH,MAAM;EAEjD,MAAMI,OAAiC,GAAG,EAAE;EAC5C,KAAK,MAAMC,GAAG,IAAIH,gBAAgB,EAAE;IAChC,MAAMI,eAAe,GAAGJ,gBAAgB,CAACG,GAAG,CAAC;IAC7C,IAAI,CAACV,QAAQ,CAACQ,IAAI,CAAC,IAAI,CAACG,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,EAAE;MACrD;IACJ;IACA,MAAMI,YAAY,GAAGD,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,CAACI,YAAY;IACjE;IACA,IAAI,CAACA,YAAY,EAAE;MACf;IACJ;IACA,MAAMC,MAAM,GAAGD,YAAY,CAAC;MAAEN;IAAO,CAAC,CAAC;IAEvC,MAAMQ,MAAM,GAAG,IAAIC,+BAAsB,CAACF,MAAM,CAAC;IACjDC,MAAM,CAACE,IAAI,GAAI,+BAA8BR,IAAK,UAASG,eAAe,CAACM,SAAU,EAAC;IACtFR,OAAO,CAACS,IAAI,CAACJ,MAAM,CAAC;EACxB;EACA,OAAOL,OAAO;AAClB,CAAC;AAAC"}
|
package/utils/ownership.js
CHANGED
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateOwnership = exports.checkOwnership = void 0;
|
|
7
|
-
|
|
8
7
|
var _apiSecurity = require("@webiny/api-security");
|
|
9
|
-
|
|
10
8
|
const checkOwnership = (context, permission, record) => {
|
|
11
9
|
var _record$ownedBy, _record$createdBy;
|
|
12
|
-
|
|
13
10
|
if (!permission.own) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
const identity = context.security.getIdentity();
|
|
18
14
|
const owner = identity && ((_record$ownedBy = record.ownedBy) === null || _record$ownedBy === void 0 ? void 0 : _record$ownedBy.id) === identity.id;
|
|
19
15
|
const creator = identity && ((_record$createdBy = record.createdBy) === null || _record$createdBy === void 0 ? void 0 : _record$createdBy.id) === identity.id;
|
|
20
|
-
|
|
21
16
|
if (!owner && !creator) {
|
|
22
17
|
throw new _apiSecurity.NotAuthorizedError({
|
|
23
18
|
data: {
|
|
@@ -26,9 +21,7 @@ const checkOwnership = (context, permission, record) => {
|
|
|
26
21
|
});
|
|
27
22
|
}
|
|
28
23
|
};
|
|
29
|
-
|
|
30
24
|
exports.checkOwnership = checkOwnership;
|
|
31
|
-
|
|
32
25
|
const validateOwnership = (context, permission, record) => {
|
|
33
26
|
try {
|
|
34
27
|
checkOwnership(context, permission, record);
|
|
@@ -37,5 +30,4 @@ const validateOwnership = (context, permission, record) => {
|
|
|
37
30
|
return false;
|
|
38
31
|
}
|
|
39
32
|
};
|
|
40
|
-
|
|
41
33
|
exports.validateOwnership = validateOwnership;
|
package/utils/ownership.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CreatedBy;\n ownedBy?: CreatedBy;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CreatedBy;\n ownedBy?: CreatedBy;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;AACA;AAOO,MAAMA,cAAc,GAAG,CAC1BC,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACd;EAAA;EACP,IAAI,CAACD,UAAU,CAACE,GAAG,EAAE;IACjB;EACJ;EAEA,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,QAAQ,CAACC,WAAW,EAAE;EAC/C,MAAMC,KAAK,GAAGH,QAAQ,IAAI,oBAAAF,MAAM,CAACM,OAAO,oDAAd,gBAAgBC,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAC5D,MAAMC,OAAO,GAAGN,QAAQ,IAAI,sBAAAF,MAAM,CAACS,SAAS,sDAAhB,kBAAkBF,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAEhE,IAAI,CAACF,KAAK,IAAI,CAACG,OAAO,EAAE;IACpB,MAAM,IAAIE,+BAAkB,CAAC;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG;MACb;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC;AAEK,MAAMC,iBAAiB,GAAG,CAC7Bf,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACX;EACV,IAAI;IACAH,cAAc,CAACC,OAAO,EAAEC,UAAU,EAAEC,MAAM,CAAC;IAC3C,OAAO,IAAI;EACf,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAAC"}
|
package/utils/permissions.js
CHANGED
|
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hasRwd = exports.hasPw = exports.checkPermissions = void 0;
|
|
7
|
-
|
|
8
7
|
var _apiSecurity = require("@webiny/api-security");
|
|
9
|
-
|
|
10
8
|
const hasRwd = (permission, rwd) => {
|
|
11
9
|
if (typeof permission.rwd !== "string") {
|
|
12
10
|
return true;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
return permission.rwd.includes(rwd);
|
|
16
13
|
};
|
|
17
|
-
|
|
18
14
|
exports.hasRwd = hasRwd;
|
|
19
|
-
|
|
20
15
|
const hasPw = (permission, pw) => {
|
|
21
16
|
const isCustom = Object.keys(permission).length > 1; // "name" key is always present
|
|
22
17
|
|
|
@@ -24,14 +19,11 @@ const hasPw = (permission, pw) => {
|
|
|
24
19
|
// Means it's a "full-access" permission.
|
|
25
20
|
return true;
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
if (typeof permission.pw !== "string") {
|
|
29
23
|
return false;
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
return permission.pw.includes(pw);
|
|
33
26
|
};
|
|
34
|
-
|
|
35
27
|
exports.hasPw = hasPw;
|
|
36
28
|
const PW = {
|
|
37
29
|
p: "publish",
|
|
@@ -42,24 +34,23 @@ const RWD = {
|
|
|
42
34
|
w: "write",
|
|
43
35
|
d: "delete"
|
|
44
36
|
};
|
|
45
|
-
|
|
46
37
|
const checkPermissions = async (context, name, check) => {
|
|
47
38
|
// Check if user is allowed to edit content in current language
|
|
48
39
|
const contentPermission = await context.security.getPermission("content.i18n");
|
|
49
|
-
|
|
50
40
|
if (!contentPermission) {
|
|
51
41
|
throw new _apiSecurity.NotAuthorizedError({
|
|
52
42
|
data: {
|
|
53
43
|
reason: "Missing access to content in any locale."
|
|
54
44
|
}
|
|
55
45
|
});
|
|
56
|
-
}
|
|
57
|
-
|
|
46
|
+
}
|
|
58
47
|
|
|
48
|
+
// We need to check this manually as CMS locale comes from the URL and not the default i18n app.
|
|
59
49
|
const code = context.cms.getLocale().code;
|
|
60
|
-
const locales = contentPermission.locales;
|
|
61
|
-
// However, if the the `locales` IS SET - check that it contains the required locale.
|
|
50
|
+
const locales = contentPermission.locales;
|
|
62
51
|
|
|
52
|
+
// IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.
|
|
53
|
+
// However, if the the `locales` IS SET - check that it contains the required locale.
|
|
63
54
|
if (Array.isArray(locales) && !locales.includes(code)) {
|
|
64
55
|
throw new _apiSecurity.NotAuthorizedError({
|
|
65
56
|
data: {
|
|
@@ -67,9 +58,7 @@ const checkPermissions = async (context, name, check) => {
|
|
|
67
58
|
}
|
|
68
59
|
});
|
|
69
60
|
}
|
|
70
|
-
|
|
71
61
|
const permission = await context.security.getPermission(name);
|
|
72
|
-
|
|
73
62
|
if (!permission) {
|
|
74
63
|
throw new _apiSecurity.NotAuthorizedError({
|
|
75
64
|
data: {
|
|
@@ -77,21 +66,19 @@ const checkPermissions = async (context, name, check) => {
|
|
|
77
66
|
}
|
|
78
67
|
});
|
|
79
68
|
}
|
|
80
|
-
|
|
81
69
|
if (!check) {
|
|
82
70
|
return permission;
|
|
83
71
|
}
|
|
84
|
-
|
|
85
72
|
if (check.rwd && !hasRwd(permission, check.rwd)) {
|
|
86
73
|
throw new _apiSecurity.NotAuthorizedError({
|
|
87
74
|
data: {
|
|
88
75
|
reason: `Not allowed to perform "${RWD[check.rwd]}" on "${name}".`
|
|
89
76
|
}
|
|
90
77
|
});
|
|
91
|
-
}
|
|
92
|
-
// u = unpublish
|
|
93
|
-
|
|
78
|
+
}
|
|
94
79
|
|
|
80
|
+
// p = publish
|
|
81
|
+
// u = unpublish
|
|
95
82
|
if (check.pw && !hasPw(permission, check.pw)) {
|
|
96
83
|
throw new _apiSecurity.NotAuthorizedError({
|
|
97
84
|
data: {
|
|
@@ -99,8 +86,6 @@ const checkPermissions = async (context, name, check) => {
|
|
|
99
86
|
}
|
|
100
87
|
});
|
|
101
88
|
}
|
|
102
|
-
|
|
103
89
|
return permission;
|
|
104
90
|
};
|
|
105
|
-
|
|
106
91
|
exports.checkPermissions = checkPermissions;
|
package/utils/permissions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasRwd","permission","rwd","includes","hasPw","pw","isCustom","Object","keys","length","PW","p","u","RWD","r","w","d","checkPermissions","context","name","check","contentPermission","security","getPermission","NotAuthorizedError","data","reason","code","cms","getLocale","locales","Array","isArray"],"sources":["permissions.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CmsEntryPermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const hasRwd = (permission: BaseCmsSecurityPermission, rwd: string): boolean => {\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n\n return permission.rwd.includes(rwd);\n};\n\nexport const hasPw = (permission: CmsEntryPermission, pw: string): boolean => {\n const isCustom = Object.keys(permission).length > 1; // \"name\" key is always present\n\n if (!isCustom) {\n // Means it's a \"full-access\" permission.\n return true;\n }\n\n if (typeof permission.pw !== \"string\") {\n return false;\n }\n\n return permission.pw.includes(pw);\n};\n\nconst PW: Record<string, string> = {\n p: \"publish\",\n u: \"unpublish\"\n};\n\nconst RWD: Record<string, string> = {\n r: \"read\",\n w: \"write\",\n d: \"delete\"\n};\n\nexport const checkPermissions = async <\n TPermission extends BaseCmsSecurityPermission = BaseCmsSecurityPermission\n>(\n context: CmsContext,\n name: string,\n check?: { rwd?: string; pw?: string }\n): Promise<TPermission> => {\n // Check if user is allowed to edit content in current language\n const contentPermission = await context.security.getPermission(\"content.i18n\");\n\n if (!contentPermission) {\n throw new NotAuthorizedError({\n data: {\n reason: \"Missing access to content in any locale.\"\n }\n });\n }\n\n // We need to check this manually as CMS locale comes from the URL and not the default i18n app.\n const code = context.cms.getLocale().code;\n\n const locales: string[] = contentPermission.locales;\n\n // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.\n // However, if the the `locales` IS SET - check that it contains the required locale.\n if (Array.isArray(locales) && !locales.includes(code)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access content in \"${code}.\"`\n }\n });\n }\n\n const permission = await context.security.getPermission<TPermission>(name);\n\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Missing permission \"${name}\".`\n }\n });\n }\n\n if (!check) {\n return permission;\n }\n\n if (check.rwd && !hasRwd(permission, check.rwd)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${RWD[check.rwd]}\" on \"${name}\".`\n }\n });\n }\n\n // p = publish\n // u = unpublish\n if (check.pw && !hasPw(permission, check.pw)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${PW[check.pw]}\" on \"${name}\".`\n }\n });\n }\n\n return permission;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["hasRwd","permission","rwd","includes","hasPw","pw","isCustom","Object","keys","length","PW","p","u","RWD","r","w","d","checkPermissions","context","name","check","contentPermission","security","getPermission","NotAuthorizedError","data","reason","code","cms","getLocale","locales","Array","isArray"],"sources":["permissions.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CmsEntryPermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const hasRwd = (permission: BaseCmsSecurityPermission, rwd: string): boolean => {\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n\n return permission.rwd.includes(rwd);\n};\n\nexport const hasPw = (permission: CmsEntryPermission, pw: string): boolean => {\n const isCustom = Object.keys(permission).length > 1; // \"name\" key is always present\n\n if (!isCustom) {\n // Means it's a \"full-access\" permission.\n return true;\n }\n\n if (typeof permission.pw !== \"string\") {\n return false;\n }\n\n return permission.pw.includes(pw);\n};\n\nconst PW: Record<string, string> = {\n p: \"publish\",\n u: \"unpublish\"\n};\n\nconst RWD: Record<string, string> = {\n r: \"read\",\n w: \"write\",\n d: \"delete\"\n};\n\nexport const checkPermissions = async <\n TPermission extends BaseCmsSecurityPermission = BaseCmsSecurityPermission\n>(\n context: CmsContext,\n name: string,\n check?: { rwd?: string; pw?: string }\n): Promise<TPermission> => {\n // Check if user is allowed to edit content in current language\n const contentPermission = await context.security.getPermission(\"content.i18n\");\n\n if (!contentPermission) {\n throw new NotAuthorizedError({\n data: {\n reason: \"Missing access to content in any locale.\"\n }\n });\n }\n\n // We need to check this manually as CMS locale comes from the URL and not the default i18n app.\n const code = context.cms.getLocale().code;\n\n const locales: string[] = contentPermission.locales;\n\n // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.\n // However, if the the `locales` IS SET - check that it contains the required locale.\n if (Array.isArray(locales) && !locales.includes(code)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access content in \"${code}.\"`\n }\n });\n }\n\n const permission = await context.security.getPermission<TPermission>(name);\n\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Missing permission \"${name}\".`\n }\n });\n }\n\n if (!check) {\n return permission;\n }\n\n if (check.rwd && !hasRwd(permission, check.rwd)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${RWD[check.rwd]}\" on \"${name}\".`\n }\n });\n }\n\n // p = publish\n // u = unpublish\n if (check.pw && !hasPw(permission, check.pw)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${PW[check.pw]}\" on \"${name}\".`\n }\n });\n }\n\n return permission;\n};\n"],"mappings":";;;;;;AACA;AAEO,MAAMA,MAAM,GAAG,CAACC,UAAqC,EAAEC,GAAW,KAAc;EACnF,IAAI,OAAOD,UAAU,CAACC,GAAG,KAAK,QAAQ,EAAE;IACpC,OAAO,IAAI;EACf;EAEA,OAAOD,UAAU,CAACC,GAAG,CAACC,QAAQ,CAACD,GAAG,CAAC;AACvC,CAAC;AAAC;AAEK,MAAME,KAAK,GAAG,CAACH,UAA8B,EAAEI,EAAU,KAAc;EAC1E,MAAMC,QAAQ,GAAGC,MAAM,CAACC,IAAI,CAACP,UAAU,CAAC,CAACQ,MAAM,GAAG,CAAC,CAAC,CAAC;;EAErD,IAAI,CAACH,QAAQ,EAAE;IACX;IACA,OAAO,IAAI;EACf;EAEA,IAAI,OAAOL,UAAU,CAACI,EAAE,KAAK,QAAQ,EAAE;IACnC,OAAO,KAAK;EAChB;EAEA,OAAOJ,UAAU,CAACI,EAAE,CAACF,QAAQ,CAACE,EAAE,CAAC;AACrC,CAAC;AAAC;AAEF,MAAMK,EAA0B,GAAG;EAC/BC,CAAC,EAAE,SAAS;EACZC,CAAC,EAAE;AACP,CAAC;AAED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