@webiny/api-headless-cms 6.5.2-beta.1 → 6.5.2-beta.2
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 +26 -19
- package/context.js.map +1 -1
- package/crud/AccessControl/AccessControl.d.ts +5 -0
- package/crud/AccessControl/AccessControl.js +4 -0
- package/crud/AccessControl/AccessControl.js.map +1 -1
- package/crud/contentModel/validation.js +4 -4
- package/crud/contentModel/validation.js.map +1 -1
- package/domain/contentEntry/errors.d.ts +4 -0
- package/domain/contentEntry/errors.js +8 -1
- package/domain/contentEntry/errors.js.map +1 -1
- package/domain/contentModel/schemas.js +3 -3
- package/domain/contentModel/schemas.js.map +1 -1
- package/domain/contentModelGroup/validation.js +2 -2
- package/domain/contentModelGroup/validation.js.map +1 -1
- package/export/crud/importing.js +12 -0
- package/export/crud/importing.js.map +1 -1
- package/export/graphql/index.js +1 -0
- package/export/graphql/index.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.d.ts +12 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +18 -4
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntry/abstractions.d.ts +2 -1
- package/features/contentEntry/CreateEntry/abstractions.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +6 -0
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js +4 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntry/decorators/ForceDeleteDecorator.d.ts +9 -2
- package/features/contentEntry/DeleteEntry/decorators/ForceDeleteDecorator.js +26 -4
- package/features/contentEntry/DeleteEntry/decorators/ForceDeleteDecorator.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js +2 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js.map +1 -1
- package/features/contentEntry/DuplicateEntry/abstractions.d.ts +2 -1
- package/features/contentEntry/DuplicateEntry/abstractions.js.map +1 -1
- package/features/contentEntry/GetSingletonEntry/abstractions.d.ts +2 -1
- package/features/contentEntry/GetSingletonEntry/abstractions.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +8 -0
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateSingletonEntry/abstractions.d.ts +2 -1
- package/features/contentEntry/UpdateSingletonEntry/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +34 -28
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +3 -2
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +39 -31
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/canOverrideMetaFields.d.ts +16 -0
- package/features/contentEntry/entryDataFactories/canOverrideMetaFields.js +11 -0
- package/features/contentEntry/entryDataFactories/canOverrideMetaFields.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.d.ts +3 -3
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js +6 -5
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelUseCase.d.ts +3 -1
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js +20 -3
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
- package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js +2 -1
- package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
- package/graphql/generateSchema.js +4 -0
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/schema/cms/getModelResolver.js +14 -0
- package/graphql/schema/cms/getModelResolver.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +11 -12
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/package.json +23 -23
- package/types/types.d.ts +5 -0
- package/types/types.js.map +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RefModelsGenerator } from "./abstractions.js";
|
|
2
2
|
import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
|
|
3
3
|
import { ValuesSelectionGenerator } from "../ValuesSelectionGenerator/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { GetModelUseCase } from "../GetModel/abstractions.js";
|
|
5
5
|
class RefModelsGeneratorImpl {
|
|
6
|
-
constructor(modelToAst,
|
|
6
|
+
constructor(modelToAst, getModelUseCase, valuesSelectionGenerator){
|
|
7
7
|
this.modelToAst = modelToAst;
|
|
8
|
-
this.
|
|
8
|
+
this.getModelUseCase = getModelUseCase;
|
|
9
9
|
this.valuesSelectionGenerator = valuesSelectionGenerator;
|
|
10
10
|
}
|
|
11
11
|
async generate(model) {
|
|
@@ -14,9 +14,10 @@ class RefModelsGeneratorImpl {
|
|
|
14
14
|
for (const node of ast.children)this.collectRefModelIds(node, refModelIds);
|
|
15
15
|
const result = {};
|
|
16
16
|
for (const modelId of refModelIds){
|
|
17
|
-
const fetchResult = await this.
|
|
17
|
+
const fetchResult = await this.getModelUseCase.execute(modelId);
|
|
18
18
|
if (fetchResult.isFail()) continue;
|
|
19
19
|
const refModel = fetchResult.value;
|
|
20
|
+
if (refModel.isPrivate) continue;
|
|
20
21
|
const valuesSelection = this.valuesSelectionGenerator.generate(refModel);
|
|
21
22
|
result[modelId] = {
|
|
22
23
|
valuesSelection
|
|
@@ -47,7 +48,7 @@ const RefModelsGenerator_RefModelsGenerator = RefModelsGenerator.createImplement
|
|
|
47
48
|
implementation: RefModelsGeneratorImpl,
|
|
48
49
|
dependencies: [
|
|
49
50
|
ModelToAstConverter,
|
|
50
|
-
|
|
51
|
+
GetModelUseCase,
|
|
51
52
|
ValuesSelectionGenerator
|
|
52
53
|
]
|
|
53
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModel/RefModelsGenerator/RefModelsGenerator.js","sources":["../../../../src/features/contentModel/RefModelsGenerator/RefModelsGenerator.ts"],"sourcesContent":["import {\n RefModelsGenerator as Abstraction,\n type IRefModelsGenerator,\n type RefModelMetadata\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport { ValuesSelectionGenerator } from \"../ValuesSelectionGenerator/abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/contentModel/RefModelsGenerator/RefModelsGenerator.js","sources":["../../../../src/features/contentModel/RefModelsGenerator/RefModelsGenerator.ts"],"sourcesContent":["import {\n RefModelsGenerator as Abstraction,\n type IRefModelsGenerator,\n type RefModelMetadata\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport { ValuesSelectionGenerator } from \"../ValuesSelectionGenerator/abstractions.js\";\nimport { GetModelUseCase } from \"../GetModel/abstractions.js\";\nimport type {\n CmsModel,\n CmsModelFieldAstNode,\n CmsModelFieldAstNodeField,\n CmsModelFieldAstNodeCollection\n} from \"~/types/index.js\";\n\nclass RefModelsGeneratorImpl implements IRefModelsGenerator {\n constructor(\n private readonly modelToAst: ModelToAstConverter.Interface,\n private readonly getModelUseCase: GetModelUseCase.Interface,\n private readonly valuesSelectionGenerator: ValuesSelectionGenerator.Interface\n ) {}\n\n async generate(model: CmsModel): Promise<Record<string, RefModelMetadata>> {\n const ast = this.modelToAst.toAst(model);\n const refModelIds = new Set<string>();\n\n for (const node of ast.children) {\n this.collectRefModelIds(node, refModelIds);\n }\n\n const result: Record<string, RefModelMetadata> = {};\n\n for (const modelId of refModelIds) {\n // Security: only expose models the current identity can read. Private models are\n // internal and never exposed.\n const fetchResult = await this.getModelUseCase.execute(modelId);\n if (fetchResult.isFail()) {\n continue;\n }\n\n const refModel = fetchResult.value;\n if (refModel.isPrivate) {\n continue;\n }\n const valuesSelection = this.valuesSelectionGenerator.generate(refModel);\n\n result[modelId] = { valuesSelection };\n }\n\n return result;\n }\n\n private collectRefModelIds(node: CmsModelFieldAstNode, modelIds: Set<string>): void {\n if (node.type === \"field\") {\n this.collectFromFieldNode(node, modelIds);\n } else if (node.type === \"collection\") {\n this.collectFromCollectionNode(node, modelIds);\n }\n }\n\n private collectFromFieldNode(node: CmsModelFieldAstNodeField, modelIds: Set<string>): void {\n const { field, children } = node;\n\n if (field.type === \"ref\") {\n const models = field.settings?.models;\n if (Array.isArray(models)) {\n for (const refModel of models) {\n if (refModel.modelId) {\n modelIds.add(refModel.modelId);\n }\n }\n }\n return;\n }\n\n for (const child of children) {\n this.collectRefModelIds(child, modelIds);\n }\n }\n\n private collectFromCollectionNode(\n node: CmsModelFieldAstNodeCollection,\n modelIds: Set<string>\n ): void {\n for (const child of node.children) {\n this.collectRefModelIds(child, modelIds);\n }\n }\n}\n\nexport const RefModelsGenerator = Abstraction.createImplementation({\n implementation: RefModelsGeneratorImpl,\n dependencies: [ModelToAstConverter, GetModelUseCase, ValuesSelectionGenerator]\n});\n"],"names":["RefModelsGeneratorImpl","modelToAst","getModelUseCase","valuesSelectionGenerator","model","ast","refModelIds","Set","node","result","modelId","fetchResult","refModel","valuesSelection","modelIds","field","children","models","Array","child","RefModelsGenerator","Abstraction","ModelToAstConverter","GetModelUseCase","ValuesSelectionGenerator"],"mappings":";;;;AAeA,MAAMA;IACF,YACqBC,UAAyC,EACzCC,eAA0C,EAC1CC,wBAA4D,CAC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;IAEQ,0BACJN,IAAoC,EACpCM,QAAqB,EACjB;QACJ,KAAK,MAAMK,SAASX,KAAK,QAAQ,CAC7B,IAAI,CAAC,kBAAkB,CAACW,OAAOL;IAEvC;AACJ;AAEO,MAAMM,wCAAqBC,mBAAAA,oBAAgC,CAAC;IAC/D,gBAAgBrB;IAChB,cAAc;QAACsB;QAAqBC;QAAiBC;KAAyB;AAClF"}
|
|
@@ -7,6 +7,7 @@ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/i
|
|
|
7
7
|
import type { CmsModel } from "../../../types/index.js";
|
|
8
8
|
import type { CmsModelUpdateInput } from "../../../types/index.js";
|
|
9
9
|
import { GetModelUseCase } from "../../../features/contentModel/GetModel/index.js";
|
|
10
|
+
import { GetGroupUseCase } from "../../../features/contentModelGroup/GetGroup/abstractions.js";
|
|
10
11
|
/**
|
|
11
12
|
* UpdateModelUseCase - Core model update orchestration.
|
|
12
13
|
*
|
|
@@ -29,7 +30,8 @@ declare class UpdateModelUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
|
29
30
|
private repository;
|
|
30
31
|
private accessControl;
|
|
31
32
|
private tenantContext;
|
|
32
|
-
|
|
33
|
+
private getGroupUseCase;
|
|
34
|
+
constructor(getModelUseCase: GetModelUseCase.Interface, eventPublisher: EventPublisher.Interface, repository: UpdateModelRepository.Interface, accessControl: AccessControl.Interface, tenantContext: TenantContext.Interface, getGroupUseCase: GetGroupUseCase.Interface);
|
|
33
35
|
execute(modelId: string, input: CmsModelUpdateInput): Promise<Result<CmsModel, UseCaseAbstraction.Error>>;
|
|
34
36
|
}
|
|
35
37
|
export declare const UpdateModelUseCase: typeof UpdateModelUseCaseImpl & {
|
|
@@ -4,18 +4,21 @@ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.j
|
|
|
4
4
|
import { ModelAfterUpdateEvent, ModelBeforeUpdateEvent, ModelUpdateErrorEvent } from "./events.js";
|
|
5
5
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
-
import { ModelNotAuthorizedError, ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
7
|
+
import { ModelNotAuthorizedError, ModelPersistenceError, ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
8
8
|
import { createZodError, removeUndefinedValues } from "@webiny/utils";
|
|
9
9
|
import { createModelUpdateValidation } from "../../../domain/contentModel/schemas.js";
|
|
10
10
|
import { ensureTypeTag } from "../../../domain/contentModel/ensureTypeTag.js";
|
|
11
11
|
import { GetModelUseCase } from "../GetModel/index.js";
|
|
12
|
+
import { GetGroupUseCase } from "../../contentModelGroup/GetGroup/abstractions.js";
|
|
13
|
+
import { GroupNotAuthorizedError, GroupNotFoundError } from "../../../domain/contentModelGroup/errors.js";
|
|
12
14
|
class UpdateModelUseCaseImpl {
|
|
13
|
-
constructor(getModelUseCase, eventPublisher, repository, accessControl, tenantContext){
|
|
15
|
+
constructor(getModelUseCase, eventPublisher, repository, accessControl, tenantContext, getGroupUseCase){
|
|
14
16
|
this.getModelUseCase = getModelUseCase;
|
|
15
17
|
this.eventPublisher = eventPublisher;
|
|
16
18
|
this.repository = repository;
|
|
17
19
|
this.accessControl = accessControl;
|
|
18
20
|
this.tenantContext = tenantContext;
|
|
21
|
+
this.getGroupUseCase = getGroupUseCase;
|
|
19
22
|
}
|
|
20
23
|
async execute(modelId, input) {
|
|
21
24
|
const canAccess = await this.accessControl.canAccessModel({
|
|
@@ -25,6 +28,11 @@ class UpdateModelUseCaseImpl {
|
|
|
25
28
|
const getResult = await this.getModelUseCase.execute(modelId);
|
|
26
29
|
if (getResult.isFail()) return getResult;
|
|
27
30
|
const original = structuredClone(getResult.value);
|
|
31
|
+
const canWriteOriginal = await this.accessControl.canAccessModel({
|
|
32
|
+
model: original,
|
|
33
|
+
rwd: "w"
|
|
34
|
+
});
|
|
35
|
+
if (!canWriteOriginal) return Result.fail(ModelNotAuthorizedError.fromModel(original));
|
|
28
36
|
const validationResult = await createModelUpdateValidation().safeParseAsync(input);
|
|
29
37
|
if (!validationResult.success) {
|
|
30
38
|
const zodError = createZodError(validationResult.error);
|
|
@@ -35,6 +43,14 @@ class UpdateModelUseCaseImpl {
|
|
|
35
43
|
}
|
|
36
44
|
const data = removeUndefinedValues(validationResult.data);
|
|
37
45
|
if (0 === Object.keys(data).length) return Result.ok(original);
|
|
46
|
+
if (data.group && data.group !== original.group) {
|
|
47
|
+
const groupResult = await this.getGroupUseCase.execute(data.group);
|
|
48
|
+
if (groupResult.isFail()) {
|
|
49
|
+
const error = groupResult.error;
|
|
50
|
+
if (error instanceof GroupNotFoundError || error instanceof GroupNotAuthorizedError) return Result.fail(error);
|
|
51
|
+
return Result.fail(new ModelPersistenceError(error));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
38
54
|
const tenant = this.tenantContext.getTenant();
|
|
39
55
|
const model = {
|
|
40
56
|
...original,
|
|
@@ -82,7 +98,8 @@ const UpdateModelUseCase_UpdateModelUseCase = UpdateModelUseCase.createImplement
|
|
|
82
98
|
EventPublisher,
|
|
83
99
|
UpdateModelRepository,
|
|
84
100
|
AccessControl,
|
|
85
|
-
TenantContext
|
|
101
|
+
TenantContext,
|
|
102
|
+
GetGroupUseCase
|
|
86
103
|
]
|
|
87
104
|
});
|
|
88
105
|
export { UpdateModelUseCase_UpdateModelUseCase as UpdateModelUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModel/UpdateModel/UpdateModelUseCase.js","sources":["../../../../src/features/contentModel/UpdateModel/UpdateModelUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateModelUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateModelRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { ModelBeforeUpdateEvent } from \"./events.js\";\nimport { ModelAfterUpdateEvent } from \"./events.js\";\nimport { ModelUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { ModelNotAuthorizedError, ModelValidationError } from \"~/domain/contentModel/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { removeUndefinedValues } from \"@webiny/utils\";\nimport { createModelUpdateValidation } from \"~/domain/contentModel/schemas.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport type { CmsModelUpdateInput } from \"~/types/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\n\n/**\n * UpdateModelUseCase - Core model update orchestration.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Fetch original model\n * - Create updated domain model object\n * - Handle group changes\n * - Handle field ID changes (title, description, image)\n * - Access control checks\n * - Publish before event\n * - Delegate to repository for validation and persistence\n * - Publish after event or error event\n *\n * Note: Repository handles domain validations (API name uniqueness, field validation, etc.)\n */\nclass UpdateModelUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateModelRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n modelId: string,\n input: CmsModelUpdateInput\n ): Promise<Result<CmsModel, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessModel({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new ModelNotAuthorizedError());\n }\n\n // Get the original model (with access control check)\n const getResult = await this.getModelUseCase.execute(modelId);\n if (getResult.isFail()) {\n return getResult;\n }\n\n const original = structuredClone(getResult.value);\n\n // Validate input\n const validationResult = await createModelUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new ModelValidationError({\n message: zodError.message,\n data: zodError.data\n })\n );\n }\n\n const data = removeUndefinedValues(validationResult.data);\n\n // If no changes, return original\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Create updated model\n const tenant = this.tenantContext.getTenant();\n\n const model: CmsModel = {\n ...original,\n ...data,\n icon: data.icon ?? original.icon,\n // Handle optional field IDs explicitly\n titleFieldId:\n data.titleFieldId === undefined\n ? original.titleFieldId\n : (data.titleFieldId as string),\n descriptionFieldId:\n data.descriptionFieldId === undefined\n ? original.descriptionFieldId\n : data.descriptionFieldId,\n imageFieldId:\n data.imageFieldId === undefined ? original.imageFieldId : data.imageFieldId,\n description: data.description || original.description,\n tenant: original.tenant || tenant.id,\n savedOn: new Date().toISOString()\n };\n\n // Access control check on the updated model\n const canAccessModel = await this.accessControl.canAccessModel({ model, rwd: \"w\" });\n if (!canAccessModel) {\n return Result.fail(ModelNotAuthorizedError.fromModel(model));\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n // Publish before event\n await this.eventPublisher.publish(\n new ModelBeforeUpdateEvent({ model, original, input: data })\n );\n\n // Persist via repository (repository will validate)\n const result = await this.repository.execute(model, original);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new ModelUpdateErrorEvent({\n input: data,\n model,\n original,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new ModelAfterUpdateEvent({\n model: result.value,\n original\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const UpdateModelUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateModelUseCaseImpl,\n dependencies: [\n GetModelUseCase,\n EventPublisher,\n UpdateModelRepository,\n AccessControl,\n TenantContext\n ]\n});\n"],"names":["UpdateModelUseCaseImpl","getModelUseCase","eventPublisher","repository","accessControl","tenantContext","modelId","input","canAccess","Result","ModelNotAuthorizedError","getResult","original","structuredClone","validationResult","createModelUpdateValidation","zodError","createZodError","ModelValidationError","data","removeUndefinedValues","Object","tenant","model","undefined","Date","canAccessModel","ensureTypeTag","ModelBeforeUpdateEvent","result","ModelUpdateErrorEvent","ModelAfterUpdateEvent","UpdateModelUseCase","UseCaseAbstraction","GetModelUseCase","EventPublisher","UpdateModelRepository","AccessControl","TenantContext"],"mappings":";;;;;;;;;;;AAkCA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA2C,EAC3CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA0B,EACyB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QACrD,IAAIK,UAAU,MAAM,IAChB,OAAOA;QAGX,MAAMC,WAAWC,gBAAgBF,UAAU,KAAK;QAGhD,MAAMG,mBAAmB,MAAMC,8BAA8B,cAAc,CAACR;QAC5E,IAAI,CAACO,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOL,OAAO,IAAI,CACd,IAAIS,qBAAqB;gBACrB,SAASF,SAAS,OAAO;gBACzB,MAAMA,SAAS,IAAI;YACvB;QAER;QAEA,MAAMG,OAAOC,sBAAsBN,iBAAiB,IAAI;QAGxD,IAAIO,AAA6B,MAA7BA,OAAO,IAAI,CAACF,MAAM,MAAM,EACxB,OAAOV,OAAO,EAAE,CAACG;QAIrB,MAAMU,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAE3C,MAAMC,QAAkB;YACpB,GAAGX,QAAQ;YACX,GAAGO,IAAI;YACP,MAAMA,KAAK,IAAI,IAAIP,SAAS,IAAI;YAEhC,c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
1
|
+
{"version":3,"file":"features/contentModel/UpdateModel/UpdateModelUseCase.js","sources":["../../../../src/features/contentModel/UpdateModel/UpdateModelUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateModelUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateModelRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { ModelBeforeUpdateEvent } from \"./events.js\";\nimport { ModelAfterUpdateEvent } from \"./events.js\";\nimport { ModelUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n ModelNotAuthorizedError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { removeUndefinedValues } from \"@webiny/utils\";\nimport { createModelUpdateValidation } from \"~/domain/contentModel/schemas.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport type { CmsModelUpdateInput } from \"~/types/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { GroupNotAuthorizedError, GroupNotFoundError } from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * UpdateModelUseCase - Core model update orchestration.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Fetch original model\n * - Create updated domain model object\n * - Handle group changes\n * - Handle field ID changes (title, description, image)\n * - Access control checks\n * - Publish before event\n * - Delegate to repository for validation and persistence\n * - Publish after event or error event\n *\n * Note: Repository handles domain validations (API name uniqueness, field validation, etc.)\n */\nclass UpdateModelUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateModelRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface\n ) {}\n\n async execute(\n modelId: string,\n input: CmsModelUpdateInput\n ): Promise<Result<CmsModel, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessModel({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new ModelNotAuthorizedError());\n }\n\n // Get the original model (with access control check)\n const getResult = await this.getModelUseCase.execute(modelId);\n if (getResult.isFail()) {\n return getResult;\n }\n\n const original = structuredClone(getResult.value);\n\n // Security: write access must be checked on the model as it is now. Checking only the\n // updated model would let a user move a model out of a group they can only read.\n const canWriteOriginal = await this.accessControl.canAccessModel({\n model: original,\n rwd: \"w\"\n });\n if (!canWriteOriginal) {\n return Result.fail(ModelNotAuthorizedError.fromModel(original));\n }\n\n // Validate input\n const validationResult = await createModelUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new ModelValidationError({\n message: zodError.message,\n data: zodError.data\n })\n );\n }\n\n const data = removeUndefinedValues(validationResult.data);\n\n // If no changes, return original\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Security: when moving the model to another group, that group must exist and be\n // accessible to the current identity.\n if (data.group && data.group !== original.group) {\n const groupResult = await this.getGroupUseCase.execute(data.group);\n if (groupResult.isFail()) {\n const error = groupResult.error;\n if (\n error instanceof GroupNotFoundError ||\n error instanceof GroupNotAuthorizedError\n ) {\n return Result.fail(error);\n }\n return Result.fail(new ModelPersistenceError(error));\n }\n }\n\n // Create updated model\n const tenant = this.tenantContext.getTenant();\n\n const model: CmsModel = {\n ...original,\n ...data,\n icon: data.icon ?? original.icon,\n // Handle optional field IDs explicitly\n titleFieldId:\n data.titleFieldId === undefined\n ? original.titleFieldId\n : (data.titleFieldId as string),\n descriptionFieldId:\n data.descriptionFieldId === undefined\n ? original.descriptionFieldId\n : data.descriptionFieldId,\n imageFieldId:\n data.imageFieldId === undefined ? original.imageFieldId : data.imageFieldId,\n description: data.description || original.description,\n tenant: original.tenant || tenant.id,\n savedOn: new Date().toISOString()\n };\n\n // Access control check on the updated model\n const canAccessModel = await this.accessControl.canAccessModel({ model, rwd: \"w\" });\n if (!canAccessModel) {\n return Result.fail(ModelNotAuthorizedError.fromModel(model));\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n // Publish before event\n await this.eventPublisher.publish(\n new ModelBeforeUpdateEvent({ model, original, input: data })\n );\n\n // Persist via repository (repository will validate)\n const result = await this.repository.execute(model, original);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new ModelUpdateErrorEvent({\n input: data,\n model,\n original,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new ModelAfterUpdateEvent({\n model: result.value,\n original\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const UpdateModelUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateModelUseCaseImpl,\n dependencies: [\n GetModelUseCase,\n EventPublisher,\n UpdateModelRepository,\n AccessControl,\n TenantContext,\n GetGroupUseCase\n ]\n});\n"],"names":["UpdateModelUseCaseImpl","getModelUseCase","eventPublisher","repository","accessControl","tenantContext","getGroupUseCase","modelId","input","canAccess","Result","ModelNotAuthorizedError","getResult","original","structuredClone","canWriteOriginal","validationResult","createModelUpdateValidation","zodError","createZodError","ModelValidationError","data","removeUndefinedValues","Object","groupResult","error","GroupNotFoundError","GroupNotAuthorizedError","ModelPersistenceError","tenant","model","undefined","Date","canAccessModel","ensureTypeTag","ModelBeforeUpdateEvent","result","ModelUpdateErrorEvent","ModelAfterUpdateEvent","UpdateModelUseCase","UseCaseAbstraction","GetModelUseCase","EventPublisher","UpdateModelRepository","AccessControl","TenantContext","GetGroupUseCase"],"mappings":";;;;;;;;;;;;;AAwCA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,E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;YACvB;YAEJ,OAAO1B,OAAO,IAAI,CAAC0B,OAAO,KAAK;QACnC;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;YACtB,OAAOF,OAAO,KAAK;YACnBvB;QACJ;QAGJ,OAAOH,OAAO,EAAE,CAAC0B,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMG,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBxC;IAChB,cAAc;QACVyC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -21,7 +21,8 @@ class DeleteGroupUseCaseImpl {
|
|
|
21
21
|
if (getResult.isFail()) return Result.fail(getResult.error);
|
|
22
22
|
const group = getResult.value;
|
|
23
23
|
const canAccessGroup = await this.accessControl.canAccessGroup({
|
|
24
|
-
group
|
|
24
|
+
group,
|
|
25
|
+
rwd: "d"
|
|
25
26
|
});
|
|
26
27
|
if (!canAccessGroup) return Result.fail(new GroupNotAuthorizedError());
|
|
27
28
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { DeleteGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeDeleteEvent } from \"./events.js\";\nimport { GroupAfterDeleteEvent } from \"./events.js\";\nimport { GroupDeleteErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GroupNotAuthorizedError } from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * DeleteGroupUseCase - Orchestrates group deletion.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass DeleteGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: DeleteGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"d\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const group = getResult.value;\n\n // Access control check on group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeDeleteEvent({\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterDeleteEvent({\n group\n })\n );\n\n return Result.ok();\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const DeleteGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteGroupUseCaseImpl,\n dependencies: [EventPublisher, DeleteGroupRepository, GetGroupUseCase, AccessControl]\n});\n"],"names":["DeleteGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","groupId","canAccess","Result","GroupNotAuthorizedError","getResult","group","canAccessGroup","GroupBeforeDeleteEvent","result","GroupDeleteErrorEvent","GroupAfterDeleteEvent","error","DeleteGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","DeleteGroupRepository","GetGroupUseCase","AccessControl"],"mappings":";;;;;;;AAsBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,CAChD;aAJUH,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,OAAe,EAAmD;QAE5E,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ;QACrD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,QAAQD,UAAU,KAAK;QAG7B,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { DeleteGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeDeleteEvent } from \"./events.js\";\nimport { GroupAfterDeleteEvent } from \"./events.js\";\nimport { GroupDeleteErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GroupNotAuthorizedError } from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * DeleteGroupUseCase - Orchestrates group deletion.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass DeleteGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: DeleteGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"d\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const group = getResult.value;\n\n // Access control check on group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group, rwd: \"d\" });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeDeleteEvent({\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterDeleteEvent({\n group\n })\n );\n\n return Result.ok();\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const DeleteGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteGroupUseCaseImpl,\n dependencies: [EventPublisher, DeleteGroupRepository, GetGroupUseCase, AccessControl]\n});\n"],"names":["DeleteGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","groupId","canAccess","Result","GroupNotAuthorizedError","getResult","group","canAccessGroup","GroupBeforeDeleteEvent","result","GroupDeleteErrorEvent","GroupAfterDeleteEvent","error","DeleteGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","DeleteGroupRepository","GetGroupUseCase","AccessControl"],"mappings":";;;;;;;AAsBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,CAChD;aAJUH,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,OAAe,EAAmD;QAE5E,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ;QACrD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,QAAQD,UAAU,KAAK;QAG7B,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;YAAO,KAAK;QAAI;QACjF,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,uBAAuB;gBACvBF;YACJ;YAIJ,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YAC7C,IAAIG,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBJ;oBACA,OAAOG,OAAO,KAAK;gBACvB;gBAEJ,OAAON,OAAO,IAAI,CAACM,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBL;YACJ;YAGJ,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOS,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBJ;gBACA,OAAOM;YACX;YAEJ,OAAOT,OAAO,IAAI,CAACS;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAgBC;QAAuBC;QAAiBC;KAAc;AACzF"}
|
|
@@ -25,7 +25,8 @@ class UpdateGroupUseCaseImpl {
|
|
|
25
25
|
if (getResult.isFail()) return Result.fail(getResult.error);
|
|
26
26
|
const original = getResult.value;
|
|
27
27
|
const canAccessGroup = await this.accessControl.canAccessGroup({
|
|
28
|
-
group: original
|
|
28
|
+
group: original,
|
|
29
|
+
rwd: "w"
|
|
29
30
|
});
|
|
30
31
|
if (!canAccessGroup) return Result.fail(new GroupNotAuthorizedError());
|
|
31
32
|
const validationResult = await createGroupUpdateValidation().safeParseAsync(input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({\n group: original,\n rwd: \"w\"\n });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Skip if no changes\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Merge changes\n const tenant = this.tenantContext.getTenant();\n const group: CmsGroup = {\n ...original,\n ...data,\n tenant: tenant.id,\n savedOn: new Date().toISOString()\n };\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeUpdateEvent({\n original,\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterUpdateEvent({\n original,\n group: result.value\n })\n );\n\n return Result.ok(result.value);\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const UpdateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n UpdateGroupRepository,\n GetGroupUseCase,\n AccessControl,\n TenantContext\n ]\n});\n"],"names":["UpdateGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","tenantContext","groupId","input","canAccess","Result","GroupNotAuthorizedError","getResult","original","canAccessGroup","validationResult","createGroupUpdateValidation","zodError","createZodError","GroupValidationError","data","Object","tenant","group","Date","GroupBeforeUpdateEvent","result","GroupUpdateErrorEvent","GroupAfterUpdateEvent","error","UpdateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateGroupRepository","GetGroupUseCase","AccessControl","TenantContext"],"mappings":";;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3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IAAIC,uBAAuB;gBACvBZ;gBACAU;YACJ;YAIJ,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YAC7C,IAAIG,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBnB;oBACAK;oBACAU;oBACA,OAAOG,OAAO,KAAK;gBACvB;gBAEJ,OAAOhB,OAAO,IAAI,CAACgB,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBf;gBACA,OAAOa,OAAO,KAAK;YACvB;YAGJ,OAAOhB,OAAO,EAAE,CAACgB,OAAO,KAAK;QACjC,EAAE,OAAOG,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBnB;gBACAK;gBACAU;gBACA,OAAOM;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildSchemaPlugins } from "./buildSchemaPlugins.js";
|
|
2
2
|
import { createExecutableSchema } from "./createExecutableSchema.js";
|
|
3
3
|
import { CmsGraphQLSchemaPlugin } from "../plugins/index.js";
|
|
4
|
+
const generatedPlugins = new WeakSet();
|
|
4
5
|
const generateSchema = async (params)=>{
|
|
5
6
|
const { context, models } = params;
|
|
6
7
|
let generatedSchemaPlugins = [];
|
|
@@ -13,8 +14,11 @@ const generateSchema = async (params)=>{
|
|
|
13
14
|
console.log("Error while building schema plugins.");
|
|
14
15
|
throw ex;
|
|
15
16
|
}
|
|
17
|
+
for (const plugin of generatedSchemaPlugins)generatedPlugins.add(plugin);
|
|
16
18
|
context.plugins.register(generatedSchemaPlugins);
|
|
19
|
+
const currentlyGenerated = new Set(generatedSchemaPlugins);
|
|
17
20
|
const schemaPlugins = context.plugins.byType(CmsGraphQLSchemaPlugin.type).filter((pl)=>{
|
|
21
|
+
if (generatedPlugins.has(pl) && !currentlyGenerated.has(pl)) return false;
|
|
18
22
|
if ("function" == typeof pl.isApplicable) return pl.isApplicable(context);
|
|
19
23
|
return true;
|
|
20
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/generateSchema.js","sources":["../../src/graphql/generateSchema.ts"],"sourcesContent":["import type { CmsContext, CmsModel } from \"~/types/index.js\";\nimport { buildSchemaPlugins } from \"./buildSchemaPlugins.js\";\nimport { createExecutableSchema } from \"./createExecutableSchema.js\";\nimport type { GraphQLSchema } from \"graphql/type/index.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\n\ninterface GenerateSchemaParams {\n context: CmsContext;\n models: CmsModel[];\n}\nexport const generateSchema = async (params: GenerateSchemaParams): Promise<GraphQLSchema> => {\n const { context, models } = params;\n\n let generatedSchemaPlugins: ICmsGraphQLSchemaPlugin[] = [];\n try {\n generatedSchemaPlugins = await buildSchemaPlugins({ context, models });\n } catch (ex) {\n console.log(`Error while building schema plugins.`);\n throw ex;\n }\n\n context.plugins.register(generatedSchemaPlugins);\n\n const schemaPlugins = context.plugins\n .byType<ICmsGraphQLSchemaPlugin>(CmsGraphQLSchemaPlugin.type)\n .filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n\n return createExecutableSchema({\n plugins: schemaPlugins\n });\n};\n"],"names":["generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","schemaPlugins","CmsGraphQLSchemaPlugin","pl","createExecutableSchema"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"graphql/generateSchema.js","sources":["../../src/graphql/generateSchema.ts"],"sourcesContent":["import type { CmsContext, CmsModel } from \"~/types/index.js\";\nimport { buildSchemaPlugins } from \"./buildSchemaPlugins.js\";\nimport { createExecutableSchema } from \"./createExecutableSchema.js\";\nimport type { GraphQLSchema } from \"graphql/type/index.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\n\n/**\n * Plugins generated for a specific endpoint (their SDL depends on `context.cms.READ/PREVIEW/MANAGE`\n * at generation time). They are registered into `context.plugins`, so we must remember them to\n * exclude them when a schema for another endpoint is generated within the same request.\n */\nconst generatedPlugins = new WeakSet<ICmsGraphQLSchemaPlugin>();\n\ninterface GenerateSchemaParams {\n context: CmsContext;\n models: CmsModel[];\n}\nexport const generateSchema = async (params: GenerateSchemaParams): Promise<GraphQLSchema> => {\n const { context, models } = params;\n\n let generatedSchemaPlugins: ICmsGraphQLSchemaPlugin[] = [];\n try {\n generatedSchemaPlugins = await buildSchemaPlugins({ context, models });\n } catch (ex) {\n console.log(`Error while building schema plugins.`);\n throw ex;\n }\n\n for (const plugin of generatedSchemaPlugins) {\n generatedPlugins.add(plugin);\n }\n context.plugins.register(generatedSchemaPlugins);\n\n const currentlyGenerated = new Set(generatedSchemaPlugins);\n\n const schemaPlugins = context.plugins\n .byType<ICmsGraphQLSchemaPlugin>(CmsGraphQLSchemaPlugin.type)\n .filter(pl => {\n // Security: skip plugins generated earlier in this request for another endpoint\n // (e.g. manage-only mutations when generating the read schema).\n if (generatedPlugins.has(pl) && !currentlyGenerated.has(pl)) {\n return false;\n }\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n\n return createExecutableSchema({\n plugins: schemaPlugins\n });\n};\n"],"names":["generatedPlugins","WeakSet","generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","plugin","currentlyGenerated","Set","schemaPlugins","CmsGraphQLSchemaPlugin","pl","createExecutableSchema"],"mappings":";;;AAYA,MAAMA,mBAAmB,IAAIC;AAMtB,MAAMC,iBAAiB,OAAOC;IACjC,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGF;IAE5B,IAAIG,yBAAoD,EAAE;IAC1D,IAAI;QACAA,yBAAyB,MAAMC,mBAAmB;YAAEH;YAASC;QAAO;IACxE,EAAE,OAAOG,IAAI;QACTC,QAAQ,GAAG,CAAC;QACZ,MAAMD;IACV;IAEA,KAAK,MAAME,UAAUJ,uBACjBN,iBAAiB,GAAG,CAACU;IAEzBN,QAAQ,OAAO,CAAC,QAAQ,CAACE;IAEzB,MAAMK,qBAAqB,IAAIC,IAAIN;IAEnC,MAAMO,gBAAgBT,QAAQ,OAAO,CAChC,MAAM,CAA0BU,uBAAuB,IAAI,EAC3D,MAAM,CAACC,CAAAA;QAGJ,IAAIf,iBAAiB,GAAG,CAACe,OAAO,CAACJ,mBAAmB,GAAG,CAACI,KACpD,OAAO;QAEX,IAAI,AAA2B,cAA3B,OAAOA,GAAG,YAAY,EACtB,OAAOA,GAAG,YAAY,CAACX;QAE3B,OAAO;IACX;IAEJ,OAAOY,uBAAuB;QAC1B,SAASH;IACb;AACJ"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import { NotAuthorizedError } from "../../../utils/errors.js";
|
|
1
2
|
import { getErrorMessage, getModel } from "./helpers.js";
|
|
2
3
|
import { ComponentMapGenerator } from "../../../features/contentModel/ComponentMapGenerator/abstractions.js";
|
|
3
4
|
import { ValuesSelectionGenerator } from "../../../features/contentModel/ValuesSelectionGenerator/abstractions.js";
|
|
4
5
|
import { RefModelsGenerator } from "../../../features/contentModel/RefModelsGenerator/abstractions.js";
|
|
6
|
+
const ENDPOINTS = [
|
|
7
|
+
"read",
|
|
8
|
+
"preview",
|
|
9
|
+
"manage"
|
|
10
|
+
];
|
|
11
|
+
const ensureCanAccessAnyEndpoint = async (context)=>{
|
|
12
|
+
for (const endpoint of ENDPOINTS){
|
|
13
|
+
const permission = await context.security.getPermission(`cms.endpoint.${endpoint}`);
|
|
14
|
+
if (permission) return;
|
|
15
|
+
}
|
|
16
|
+
throw new NotAuthorizedError("Not allowed to access CMS endpoints.");
|
|
17
|
+
};
|
|
5
18
|
const createGetModelResolver = ()=>async ({ args, context })=>{
|
|
6
19
|
const { modelId } = args;
|
|
7
20
|
try {
|
|
21
|
+
await ensureCanAccessAnyEndpoint(context);
|
|
8
22
|
const model = await getModel(context, modelId);
|
|
9
23
|
const componentMapGenerator = context.container.resolve(ComponentMapGenerator);
|
|
10
24
|
const valuesSelectionGenerator = context.container.resolve(ValuesSelectionGenerator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/schema/cms/getModelResolver.js","sources":["../../../../src/graphql/schema/cms/getModelResolver.ts"],"sourcesContent":["import type { CmsContext } from \"~/types/index.js\";\nimport { getModel, getErrorMessage } from \"./helpers.js\";\nimport { ComponentMapGenerator } from \"~/features/contentModel/ComponentMapGenerator/abstractions.js\";\nimport { ValuesSelectionGenerator } from \"~/features/contentModel/ValuesSelectionGenerator/abstractions.js\";\nimport { RefModelsGenerator } from \"~/features/contentModel/RefModelsGenerator/abstractions.js\";\n\nexport interface GetModelArgs {\n modelId: string;\n}\n\nexport const createGetModelResolver = () => {\n return async ({ args, context }: { args: GetModelArgs; context: CmsContext }) => {\n const { modelId } = args;\n\n try {\n const model = await getModel(context, modelId);\n const componentMapGenerator = context.container.resolve(ComponentMapGenerator);\n const valuesSelectionGenerator = context.container.resolve(ValuesSelectionGenerator);\n const refModelsGenerator = context.container.resolve(RefModelsGenerator);\n\n const componentMap = componentMapGenerator.generate(model);\n const valuesSelection = valuesSelectionGenerator.generate(model);\n const refModels = await refModelsGenerator.generate(model);\n\n return {\n data: {\n name: model.name,\n modelId: model.modelId,\n singularApiName: model.singularApiName,\n pluralApiName: model.pluralApiName,\n description: model.description,\n titleFieldId: model.titleFieldId,\n descriptionFieldId: model.descriptionFieldId,\n imageFieldId: model.imageFieldId,\n fields: model.fields,\n layout: model.layout,\n tags: model.tags,\n settings: model.settings,\n metadata: {\n valuesSelection,\n componentMap,\n refModels\n }\n },\n error: null\n };\n } catch (error) {\n return {\n data: null,\n error: {\n message: getErrorMessage(error, \"Failed to get model\"),\n code: \"GET_MODEL_ERROR\"\n }\n };\n }\n };\n};\n"],"names":["
|
|
1
|
+
{"version":3,"file":"graphql/schema/cms/getModelResolver.js","sources":["../../../../src/graphql/schema/cms/getModelResolver.ts"],"sourcesContent":["import type { ApiEndpoint, CmsContext } from \"~/types/index.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getModel, getErrorMessage } from \"./helpers.js\";\nimport { ComponentMapGenerator } from \"~/features/contentModel/ComponentMapGenerator/abstractions.js\";\nimport { ValuesSelectionGenerator } from \"~/features/contentModel/ValuesSelectionGenerator/abstractions.js\";\nimport { RefModelsGenerator } from \"~/features/contentModel/RefModelsGenerator/abstractions.js\";\n\nexport interface GetModelArgs {\n modelId: string;\n}\n\nconst ENDPOINTS: ApiEndpoint[] = [\"read\", \"preview\", \"manage\"];\n\n/**\n * Security: the proxy must respect the endpoint permissions, like the entry resolvers do via\n * `getExecutableSchema`. Model metadata is useful on any endpoint, so any of them is enough.\n */\nconst ensureCanAccessAnyEndpoint = async (context: CmsContext) => {\n for (const endpoint of ENDPOINTS) {\n const permission = await context.security.getPermission(`cms.endpoint.${endpoint}`);\n if (permission) {\n return;\n }\n }\n throw new NotAuthorizedError(`Not allowed to access CMS endpoints.`);\n};\n\nexport const createGetModelResolver = () => {\n return async ({ args, context }: { args: GetModelArgs; context: CmsContext }) => {\n const { modelId } = args;\n\n try {\n await ensureCanAccessAnyEndpoint(context);\n const model = await getModel(context, modelId);\n const componentMapGenerator = context.container.resolve(ComponentMapGenerator);\n const valuesSelectionGenerator = context.container.resolve(ValuesSelectionGenerator);\n const refModelsGenerator = context.container.resolve(RefModelsGenerator);\n\n const componentMap = componentMapGenerator.generate(model);\n const valuesSelection = valuesSelectionGenerator.generate(model);\n const refModels = await refModelsGenerator.generate(model);\n\n return {\n data: {\n name: model.name,\n modelId: model.modelId,\n singularApiName: model.singularApiName,\n pluralApiName: model.pluralApiName,\n description: model.description,\n titleFieldId: model.titleFieldId,\n descriptionFieldId: model.descriptionFieldId,\n imageFieldId: model.imageFieldId,\n fields: model.fields,\n layout: model.layout,\n tags: model.tags,\n settings: model.settings,\n metadata: {\n valuesSelection,\n componentMap,\n refModels\n }\n },\n error: null\n };\n } catch (error) {\n return {\n data: null,\n error: {\n message: getErrorMessage(error, \"Failed to get model\"),\n code: \"GET_MODEL_ERROR\"\n }\n };\n }\n };\n};\n"],"names":["ENDPOINTS","ensureCanAccessAnyEndpoint","context","endpoint","permission","NotAuthorizedError","createGetModelResolver","args","modelId","model","getModel","componentMapGenerator","ComponentMapGenerator","valuesSelectionGenerator","ValuesSelectionGenerator","refModelsGenerator","RefModelsGenerator","componentMap","valuesSelection","refModels","error","getErrorMessage"],"mappings":";;;;;AAWA,MAAMA,YAA2B;IAAC;IAAQ;IAAW;CAAS;AAM9D,MAAMC,6BAA6B,OAAOC;IACtC,KAAK,MAAMC,YAAYH,UAAW;QAC9B,MAAMI,aAAa,MAAMF,QAAQ,QAAQ,CAAC,aAAa,CAAC,CAAC,aAAa,EAAEC,UAAU;QAClF,IAAIC,YACA;IAER;IACA,MAAM,IAAIC,mBAAmB;AACjC;AAEO,MAAMC,yBAAyB,IAC3B,OAAO,EAAEC,IAAI,EAAEL,OAAO,EAA+C;QACxE,MAAM,EAAEM,OAAO,EAAE,GAAGD;QAEpB,IAAI;YACA,MAAMN,2BAA2BC;YACjC,MAAMO,QAAQ,MAAMC,SAASR,SAASM;YACtC,MAAMG,wBAAwBT,QAAQ,SAAS,CAAC,OAAO,CAACU;YACxD,MAAMC,2BAA2BX,QAAQ,SAAS,CAAC,OAAO,CAACY;YAC3D,MAAMC,qBAAqBb,QAAQ,SAAS,CAAC,OAAO,CAACc;YAErD,MAAMC,eAAeN,sBAAsB,QAAQ,CAACF;YACpD,MAAMS,kBAAkBL,yBAAyB,QAAQ,CAACJ;YAC1D,MAAMU,YAAY,MAAMJ,mBAAmB,QAAQ,CAACN;YAEpD,OAAO;gBACH,MAAM;oBACF,MAAMA,MAAM,IAAI;oBAChB,SAASA,MAAM,OAAO;oBACtB,iBAAiBA,MAAM,eAAe;oBACtC,eAAeA,MAAM,aAAa;oBAClC,aAAaA,MAAM,WAAW;oBAC9B,cAAcA,MAAM,YAAY;oBAChC,oBAAoBA,MAAM,kBAAkB;oBAC5C,cAAcA,MAAM,YAAY;oBAChC,QAAQA,MAAM,MAAM;oBACpB,QAAQA,MAAM,MAAM;oBACpB,MAAMA,MAAM,IAAI;oBAChB,UAAUA,MAAM,QAAQ;oBACxB,UAAU;wBACNS;wBACAD;wBACAE;oBACJ;gBACJ;gBACA,OAAO;YACX;QACJ,EAAE,OAAOC,OAAO;YACZ,OAAO;gBACH,MAAM;gBACN,OAAO;oBACH,SAASC,gBAAgBD,OAAO;oBAChC,MAAM;gBACV;YACJ;QACJ;IACJ"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ErrorResponse, NotFoundError, Response } from "@webiny/handler-graphql";
|
|
2
2
|
import { CmsGroupPlugin } from "../../plugins/CmsGroupPlugin.js";
|
|
3
3
|
import { createCmsGraphQLSchemaPlugin } from "../../plugins/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "../../features/contentModel/ListModels/index.js";
|
|
5
|
+
const listGroupModels = async (context, groupSlug)=>{
|
|
6
|
+
const result = await context.container.resolve(ListModelsUseCase).execute({
|
|
7
|
+
includePrivate: false
|
|
8
|
+
});
|
|
9
|
+
if (result.isFail()) return [];
|
|
10
|
+
return result.value.filter((model)=>model.group === groupSlug);
|
|
11
|
+
};
|
|
4
12
|
const createGroupsSchema = ({ context })=>{
|
|
5
13
|
let manageSchema = "";
|
|
6
14
|
if (context.cms.MANAGE) manageSchema = `
|
|
@@ -44,19 +52,10 @@ const createGroupsSchema = ({ context })=>{
|
|
|
44
52
|
let resolvers = {};
|
|
45
53
|
if (context.cms.MANAGE) resolvers = {
|
|
46
54
|
CmsContentModelGroup: {
|
|
47
|
-
contentModels: async (group, _, context)=>
|
|
48
|
-
const models = await context.security.withoutAuthorization(async ()=>context.cms.listModels());
|
|
49
|
-
return models.filter((model)=>{
|
|
50
|
-
if (true === model.isPrivate) return false;
|
|
51
|
-
return model.group === group.slug;
|
|
52
|
-
});
|
|
53
|
-
},
|
|
55
|
+
contentModels: async (group, _, context)=>listGroupModels(context, group.slug),
|
|
54
56
|
totalContentModels: async (group, _, context)=>{
|
|
55
|
-
const models = await context
|
|
56
|
-
return models.
|
|
57
|
-
if (true === model.isPrivate) return false;
|
|
58
|
-
return model.group === group.slug;
|
|
59
|
-
}).length;
|
|
57
|
+
const models = await listGroupModels(context, group.slug);
|
|
58
|
+
return models.length;
|
|
60
59
|
},
|
|
61
60
|
plugin: async (group, _, context)=>context.plugins.byType(CmsGroupPlugin.type).some((item)=>item.contentModelGroup.id === group.id)
|
|
62
61
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/schema/contentModelGroups.js","sources":["../../../src/graphql/schema/contentModelGroups.ts"],"sourcesContent":["import { ErrorResponse, NotFoundError, Response } from \"@webiny/handler-graphql\";\nimport type { CmsContext } from \"~/types/index.js\";\nimport type { Resolvers } from \"@webiny/handler-graphql/types.js\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { createCmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\n\ninterface Params {\n context: CmsContext;\n}\nexport const createGroupsSchema = ({ context }: Params): ICmsGraphQLSchemaPlugin => {\n let manageSchema = \"\";\n if (context.cms.MANAGE) {\n manageSchema = /* GraphQL */ `\n input CmsContentModelGroupInput {\n id: ID\n name: String!\n slug: String\n description: String\n icon: Icon!\n }\n\n type CmsContentModelGroupResponse {\n data: CmsContentModelGroup\n error: CmsError\n }\n\n type CmsContentModelGroupListResponse {\n data: [CmsContentModelGroup]\n meta: CmsListMeta\n error: CmsError\n }\n\n extend type Query {\n getContentModelGroup(id: ID): CmsContentModelGroupResponse\n listContentModelGroups: CmsContentModelGroupListResponse\n }\n\n extend type Mutation {\n createContentModelGroup(\n data: CmsContentModelGroupInput!\n ): CmsContentModelGroupResponse\n\n updateContentModelGroup(\n id: ID!\n data: CmsContentModelGroupInput!\n ): CmsContentModelGroupResponse\n\n deleteContentModelGroup(id: ID!): CmsDeleteResponse\n }\n `;\n }\n\n let resolvers: Resolvers<CmsContext> = {};\n\n if (context.cms.MANAGE) {\n resolvers = {\n CmsContentModelGroup: {\n contentModels: async (group, _, context) => {\n
|
|
1
|
+
{"version":3,"file":"graphql/schema/contentModelGroups.js","sources":["../../../src/graphql/schema/contentModelGroups.ts"],"sourcesContent":["import { ErrorResponse, NotFoundError, Response } from \"@webiny/handler-graphql\";\nimport type { CmsContext } from \"~/types/index.js\";\nimport type { Resolvers } from \"@webiny/handler-graphql/types.js\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { createCmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\n\n/**\n * Models of a group that the current identity can read. No error when it can't read any model.\n */\nconst listGroupModels = async (context: CmsContext, groupSlug: string) => {\n const result = await context.container\n .resolve(ListModelsUseCase)\n .execute({ includePrivate: false });\n if (result.isFail()) {\n return [];\n }\n // `model.group` holds the group slug.\n return result.value.filter(model => model.group === groupSlug);\n};\n\ninterface Params {\n context: CmsContext;\n}\n\nexport const createGroupsSchema = ({ context }: Params): ICmsGraphQLSchemaPlugin => {\n let manageSchema = \"\";\n if (context.cms.MANAGE) {\n manageSchema = /* GraphQL */ `\n input CmsContentModelGroupInput {\n id: ID\n name: String!\n slug: String\n description: String\n icon: Icon!\n }\n\n type CmsContentModelGroupResponse {\n data: CmsContentModelGroup\n error: CmsError\n }\n\n type CmsContentModelGroupListResponse {\n data: [CmsContentModelGroup]\n meta: CmsListMeta\n error: CmsError\n }\n\n extend type Query {\n getContentModelGroup(id: ID): CmsContentModelGroupResponse\n listContentModelGroups: CmsContentModelGroupListResponse\n }\n\n extend type Mutation {\n createContentModelGroup(\n data: CmsContentModelGroupInput!\n ): CmsContentModelGroupResponse\n\n updateContentModelGroup(\n id: ID!\n data: CmsContentModelGroupInput!\n ): CmsContentModelGroupResponse\n\n deleteContentModelGroup(id: ID!): CmsDeleteResponse\n }\n `;\n }\n\n let resolvers: Resolvers<CmsContext> = {};\n\n if (context.cms.MANAGE) {\n resolvers = {\n CmsContentModelGroup: {\n contentModels: async (group, _, context) => {\n return listGroupModels(context, group.slug);\n },\n totalContentModels: async (group, _, context) => {\n const models = await listGroupModels(context, group.slug);\n return models.length;\n },\n plugin: async (group, _, context: CmsContext): Promise<boolean> => {\n return context.plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n .some(item => item.contentModelGroup.id === group.id);\n }\n },\n Query: {\n getContentModelGroup: async (_, args: any, context) => {\n try {\n const { id } = args;\n const group = await context.cms.getGroup(id);\n if (group?.isPrivate) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n return new Response(group);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n listContentModelGroups: async (_, __, context) => {\n try {\n const groups = await context.cms.listGroups();\n return new Response(groups.filter(group => group.isPrivate !== true));\n } catch (e) {\n return new ErrorResponse(e);\n }\n }\n },\n Mutation: {\n createContentModelGroup: async (_, args: any, context) => {\n try {\n const model = await context.cms.createGroup(args.data);\n return new Response(model);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n updateContentModelGroup: async (_, args: any, context) => {\n try {\n const group = await context.cms.updateGroup(args.id, args.data);\n return new Response(group);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n deleteContentModelGroup: async (_, args: any, context) => {\n try {\n await context.cms.deleteGroup(args.id);\n return new Response(true);\n } catch (e) {\n return new ErrorResponse(e);\n }\n }\n }\n };\n }\n\n const plugin = createCmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type CmsContentModelGroup {\n id: ID!\n createdOn: DateTime\n savedOn: DateTime\n name: String!\n contentModels: [CmsContentModel!]\n totalContentModels: Int!\n slug: String!\n description: String\n icon: Icon\n createdBy: CmsIdentity\n\n # Returns true if the content model group is registered via a plugin.\n plugin: Boolean!\n }\n ${manageSchema}\n `,\n resolvers\n });\n\n plugin.name = `headless-cms.graphql.schema.${context.cms.type}.content-model-groups`;\n\n return plugin;\n};\n"],"names":["listGroupModels","context","groupSlug","result","ListModelsUseCase","model","createGroupsSchema","manageSchema","resolvers","group","_","models","CmsGroupPlugin","item","args","id","NotFoundError","Response","e","ErrorResponse","__","groups","plugin","createCmsGraphQLSchemaPlugin"],"mappings":";;;;AAWA,MAAMA,kBAAkB,OAAOC,SAAqBC;IAChD,MAAMC,SAAS,MAAMF,QAAQ,SAAS,CACjC,OAAO,CAACG,mBACR,OAAO,CAAC;QAAE,gBAAgB;IAAM;IACrC,IAAID,OAAO,MAAM,IACb,OAAO,EAAE;IAGb,OAAOA,OAAO,KAAK,CAAC,MAAM,CAACE,CAAAA,QAASA,MAAM,KAAK,KAAKH;AACxD;AAMO,MAAMI,qBAAqB,CAAC,EAAEL,OAAO,EAAU;IAClD,IAAIM,eAAe;IACnB,IAAIN,QAAQ,GAAG,CAAC,MAAM,EAClBM,eAA6B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAqC9B,CAAC;IAGL,IAAIC,YAAmC,CAAC;IAExC,IAAIP,QAAQ,GAAG,CAAC,MAAM,EAClBO,YAAY;QACR,sBAAsB;YAClB,eAAe,OAAOC,OAAOC,GAAGT,UACrBD,gBAAgBC,SAASQ,MAAM,IAAI;YAE9C,oBAAoB,OAAOA,OAAOC,GAAGT;gBACjC,MAAMU,SAAS,MA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R;gBACxB,EAAE,OAAOS,GAAG;oBACR,OAAO,IAAIC,cAAcD;gBAC7B;YACJ;YACA,yBAAyB,OAAOR,GAAGI,MAAWb;gBAC1C,IAAI;oBACA,MAAMA,QAAQ,GAAG,CAAC,WAAW,CAACa,KAAK,EAAE;oBACrC,OAAO,IAAIG,SAAS;gBACxB,EAAE,OAAOC,GAAG;oBACR,OAAO,IAAIC,cAAcD;gBAC7B;YACJ;QACJ;IACJ;IAGJ,MAAMI,SAASC,6BAA6B;QACxC,UAAwB,CAAC;;;;;;;;;;;;;;;;YAgBrB,EAAEhB,aAAa;QACnB,CAAC;QACDC;IACJ;IAEAc,OAAO,IAAI,GAAG,CAAC,4BAA4B,EAAErB,QAAQ,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC;IAEpF,OAAOqB;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
"@babel/code-frame": "8.0.6",
|
|
26
26
|
"@graphql-tools/merge": "10.0.8",
|
|
27
27
|
"@graphql-tools/schema": "11.0.8",
|
|
28
|
-
"@webiny/api": "6.5.2-beta.
|
|
29
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
28
|
+
"@webiny/api": "6.5.2-beta.2",
|
|
29
|
+
"@webiny/api-core": "6.5.2-beta.2",
|
|
30
30
|
"@webiny/di": "1.1.0",
|
|
31
|
-
"@webiny/error": "6.5.2-beta.
|
|
32
|
-
"@webiny/feature": "6.5.2-beta.
|
|
33
|
-
"@webiny/handler": "6.5.2-beta.
|
|
34
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
35
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
36
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
37
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
38
|
-
"@webiny/project": "6.5.2-beta.
|
|
39
|
-
"@webiny/utils": "6.5.2-beta.
|
|
40
|
-
"@webiny/validation": "6.5.2-beta.
|
|
31
|
+
"@webiny/error": "6.5.2-beta.2",
|
|
32
|
+
"@webiny/feature": "6.5.2-beta.2",
|
|
33
|
+
"@webiny/handler": "6.5.2-beta.2",
|
|
34
|
+
"@webiny/handler-aws": "6.5.2-beta.2",
|
|
35
|
+
"@webiny/handler-db": "6.5.2-beta.2",
|
|
36
|
+
"@webiny/handler-graphql": "6.5.2-beta.2",
|
|
37
|
+
"@webiny/plugins": "6.5.2-beta.2",
|
|
38
|
+
"@webiny/project": "6.5.2-beta.2",
|
|
39
|
+
"@webiny/utils": "6.5.2-beta.2",
|
|
40
|
+
"@webiny/validation": "6.5.2-beta.2",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
|
-
"graphql": "16.
|
|
42
|
+
"graphql": "16.15.0",
|
|
43
43
|
"graphql-tag": "2.12.7",
|
|
44
44
|
"lodash": "4.18.1",
|
|
45
45
|
"p-map": "7.1.1",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/pluralize": "0.0.33",
|
|
53
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
54
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
55
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
56
|
-
"@webiny/sdk": "6.5.2-beta.
|
|
57
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
53
|
+
"@webiny/build-tools": "6.5.2-beta.2",
|
|
54
|
+
"@webiny/handler-db": "6.5.2-beta.2",
|
|
55
|
+
"@webiny/project-utils": "6.5.2-beta.2",
|
|
56
|
+
"@webiny/sdk": "6.5.2-beta.2",
|
|
57
|
+
"@webiny/wcp": "6.5.2-beta.2",
|
|
58
58
|
"apollo-graphql": "0.9.7",
|
|
59
|
-
"graphql": "16.
|
|
60
|
-
"oxfmt": "0.
|
|
61
|
-
"rimraf": "6.1.
|
|
59
|
+
"graphql": "16.15.0",
|
|
60
|
+
"oxfmt": "0.78.0",
|
|
61
|
+
"rimraf": "6.1.4",
|
|
62
62
|
"typescript": "7.0.2",
|
|
63
|
-
"vitest": "5.0
|
|
63
|
+
"vitest": "5.1.0",
|
|
64
64
|
"write-json-file": "7.0.0"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|
package/types/types.d.ts
CHANGED
|
@@ -648,6 +648,11 @@ export interface CreateCmsEntryInput<TValues extends CmsEntryValues = CmsEntryVa
|
|
|
648
648
|
}
|
|
649
649
|
export interface CreateCmsEntryOptionsInput {
|
|
650
650
|
skipValidation?: boolean;
|
|
651
|
+
/**
|
|
652
|
+
* Refuse to create the entry when an entry with the given `id` already exists, even on a
|
|
653
|
+
* private model. Applied only while authorization is enabled. Public models always refuse.
|
|
654
|
+
*/
|
|
655
|
+
failIfExists?: boolean;
|
|
651
656
|
}
|
|
652
657
|
/**
|
|
653
658
|
* @category Context
|