@webiny/api-headless-cms 6.4.8-beta.0 → 6.4.9-beta.0
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/features/contentEntry/ContentEntriesFeature.js +2 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntry/CreateEntryRepository.js +8 -3
- package/features/contentEntry/CreateEntry/CreateEntryRepository.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js +8 -3
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.d.ts +4 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js +8 -3
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js +8 -3
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +8 -3
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.d.ts +4 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js +7 -3
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js.map +1 -1
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.d.ts +4 -4
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js +8 -11
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.d.ts +4 -2
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js +7 -3
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js.map +1 -1
- package/features/contentEntry/ListEntries/ListEntriesRepository.d.ts +4 -2
- package/features/contentEntry/ListEntries/ListEntriesRepository.js +7 -3
- package/features/contentEntry/ListEntries/ListEntriesRepository.js.map +1 -1
- package/features/contentEntry/MoveEntry/MoveEntryRepository.d.ts +4 -2
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js +7 -3
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js +8 -3
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js +8 -3
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js.map +1 -1
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.d.ts +4 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js +8 -3
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js +8 -3
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.d.ts +4 -2
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js +8 -3
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.d.ts +4 -2
- package/features/contentModel/CreateModel/CreateModelRepository.js +8 -4
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelUseCase.js +2 -2
- package/features/contentModel/CreateModel/CreateModelUseCase.js.map +1 -1
- package/features/contentModel/CreateModel/abstractions.d.ts +1 -1
- package/features/contentModel/CreateModel/abstractions.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.d.ts +4 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +8 -4
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
- package/features/contentModel/CreateModelFrom/abstractions.d.ts +1 -1
- package/features/contentModel/CreateModelFrom/abstractions.js.map +1 -1
- package/features/contentModel/DeleteModel/DeleteModelRepository.d.ts +4 -2
- package/features/contentModel/DeleteModel/DeleteModelRepository.js +7 -3
- package/features/contentModel/DeleteModel/DeleteModelRepository.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelRepository.d.ts +4 -2
- package/features/contentModel/UpdateModel/UpdateModelRepository.js +8 -4
- package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js +2 -2
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
- package/features/contentModel/UpdateModel/abstractions.d.ts +1 -1
- package/features/contentModel/UpdateModel/abstractions.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js +8 -4
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.d.ts +1 -3
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js +5 -7
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/abstractions.d.ts +1 -1
- package/features/contentModelGroup/CreateGroup/abstractions.js.map +1 -1
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js +7 -3
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js +8 -4
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.d.ts +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.js.map +1 -1
- package/features/runtimeTenant/RuntimeTenant.d.ts +13 -0
- package/features/runtimeTenant/RuntimeTenant.js +22 -0
- package/features/runtimeTenant/RuntimeTenant.js.map +1 -0
- package/features/runtimeTenant/abstractions.d.ts +11 -0
- package/features/runtimeTenant/abstractions.js +5 -0
- package/features/runtimeTenant/abstractions.js.map +1 -0
- package/features/runtimeTenant/index.d.ts +2 -0
- package/features/runtimeTenant/index.js +2 -0
- package/package.json +20 -20
|
@@ -6,14 +6,17 @@ import { StorageOperations } from "../../shared/abstractions.js";
|
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
7
|
import { toSlug } from "../../../utils/toSlug.js";
|
|
8
8
|
import { generateAlphaNumericId } from "@webiny/utils";
|
|
9
|
+
import { RuntimeTenant } from "../../runtimeTenant/abstractions.js";
|
|
9
10
|
class CreateGroupRepositoryImpl {
|
|
10
|
-
constructor(groupCache, pluginGroupsProvider, storageOperations, tenantContext){
|
|
11
|
+
constructor(groupCache, pluginGroupsProvider, storageOperations, tenantContext, runtimeTenant){
|
|
11
12
|
this.groupCache = groupCache;
|
|
12
13
|
this.pluginGroupsProvider = pluginGroupsProvider;
|
|
13
14
|
this.storageOperations = storageOperations;
|
|
14
15
|
this.tenantContext = tenantContext;
|
|
16
|
+
this.runtimeTenant = runtimeTenant;
|
|
15
17
|
}
|
|
16
|
-
async execute(
|
|
18
|
+
async execute(initialGroup) {
|
|
19
|
+
const group = this.runtimeTenant.assign(initialGroup);
|
|
17
20
|
try {
|
|
18
21
|
const tenant = this.tenantContext.getTenant();
|
|
19
22
|
if (group.id) {
|
|
@@ -34,7 +37,7 @@ class CreateGroupRepositoryImpl {
|
|
|
34
37
|
group
|
|
35
38
|
});
|
|
36
39
|
this.groupCache.clear();
|
|
37
|
-
return Result.ok();
|
|
40
|
+
return Result.ok(group);
|
|
38
41
|
} catch (error) {
|
|
39
42
|
return Result.fail(new GroupPersistenceError(error));
|
|
40
43
|
}
|
|
@@ -68,7 +71,8 @@ const CreateGroupRepository_CreateGroupRepository = createImplementation({
|
|
|
68
71
|
GroupCache,
|
|
69
72
|
PluginGroupsProvider,
|
|
70
73
|
StorageOperations,
|
|
71
|
-
TenantContext
|
|
74
|
+
TenantContext,
|
|
75
|
+
RuntimeTenant
|
|
72
76
|
]
|
|
73
77
|
});
|
|
74
78
|
export { CreateGroupRepository_CreateGroupRepository as CreateGroupRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupSlugTakenError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { toSlug } from \"~/utils/toSlug.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * CreateGroupRepository - Validates and persists a new group.\n *\n * Responsibilities:\n * - Validate ID uniqueness (if provided)\n * - Validate slug uniqueness (or generate unique slug)\n * - Check for plugin group conflicts\n * - Persist to storage\n * - Clear GroupCache after successful create\n */\nclass CreateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupSlugTakenError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { toSlug } from \"~/utils/toSlug.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * CreateGroupRepository - Validates and persists a new group.\n *\n * Responsibilities:\n * - Validate ID uniqueness (if provided)\n * - Validate slug uniqueness (or generate unique slug)\n * - Check for plugin group conflicts\n * - Persist to storage\n * - Clear GroupCache after successful create\n */\nclass CreateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // 1. Validate ID uniqueness (if provided)\n if (group.id) {\n const existingById = await this.storageOperations.groups.list({\n where: {\n tenant: tenant.id,\n id: group.id\n }\n });\n\n if (existingById.length > 0) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n }\n\n // 2. Generate or validate slug\n const slugTaken = await this.isSlugTaken(group, tenant.id);\n if (slugTaken) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n\n // 3. Check for plugin group conflicts\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const pluginGroupConflict = pluginGroups.find(pg => pg.slug === group.slug);\n if (pluginGroupConflict) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n\n // 4. Persist to storage\n await this.storageOperations.groups.create({ group });\n\n // 5. Clear cache\n this.groupCache.clear();\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async isSlugTaken(group: CmsGroup, tenant: string): Promise<boolean> {\n // If slug is provided and not empty, validate it\n if (group.slug && group.slug.trim()) {\n const existingBySlug = await this.storageOperations.groups.list({\n where: {\n tenant,\n slug: group.slug\n }\n });\n\n return existingBySlug.length > 0;\n }\n\n // Generate slug from name\n const baseSlug = toSlug(group.name);\n const existingBySlug = await this.storageOperations.groups.list({\n where: {\n tenant,\n slug: baseSlug\n }\n });\n\n if (existingBySlug.length === 0) {\n // No conflict, use base slug\n group.slug = baseSlug;\n } else {\n // Conflict, append random suffix\n group.slug = `${baseSlug}-${generateAlphaNumericId(8)}`;\n }\n\n return false;\n }\n}\n\nexport const CreateGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: CreateGroupRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n StorageOperations,\n TenantContext,\n RuntimeTenant\n ]\n});\n"],"names":["CreateGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","tenantContext","runtimeTenant","initialGroup","group","tenant","existingById","Result","GroupSlugTakenError","slugTaken","pluginGroups","pluginGroupConflict","pg","error","GroupPersistenceError","existingBySlug","baseSlug","toSlug","generateAlphaNumericId","CreateGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","TenantContext","RuntimeTenant"],"mappings":";;;;;;;;;AAwBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YACA,MAAME,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,IAAID,MAAM,EAAE,EAAE;gBACV,MAAME,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;oBAC1D,OAAO;wBACH,QAAQD,OAAO,EAAE;wBACjB,IAAID,MAAM,EAAE;oBAChB;gBACJ;gBAEA,IAAIE,aAAa,MAAM,GAAG,GACtB,OAAOC,OAAO,IAAI,CAAC,IAAIC,oBAAoBJ,MAAM,IAAI;YAE7D;YAGA,MAAMK,YAAY,MAAM,IAAI,CAAC,WAAW,CAACL,OAAOC,OAAO,EAAE;YACzD,IAAII,WACA,OAAOF,OAAO,IAAI,CAAC,IAAIC,oBAAoBJ,MAAM,IAAI;YAIzD,MAAMM,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;YAC9D,MAAMC,sBAAsBD,aAAa,IAAI,CAACE,CAAAA,KAAMA,GAAG,IAAI,KAAKR,MAAM,IAAI;YAC1E,IAAIO,qBACA,OAAOJ,OAAO,IAAI,CAAC,IAAIC,oBAAoBJ,MAAM,IAAI;YAIzD,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAEA;YAAM;YAGnD,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOG,OAAO,EAAE,CAACH;QACrB,EAAE,OAAOS,OAAO;YACZ,OAAON,OAAO,IAAI,CAAC,IAAIO,sBAAsBD;QACjD;IACJ;IAEA,MAAc,YAAYT,KAAe,EAAEC,MAAc,EAAoB;QAEzE,IAAID,MAAM,IAAI,IAAIA,MAAM,IAAI,CAAC,IAAI,IAAI;YACjC,MAAMW,iBAAiB,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC5D,OAAO;oBACHV;oBACA,MAAMD,MAAM,IAAI;gBACpB;YACJ;YAEA,OAAOW,eAAe,MAAM,GAAG;QACnC;QAGA,MAAMC,WAAWC,OAAOb,MAAM,IAAI;QAClC,MAAMW,iBAAiB,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;YAC5D,OAAO;gBACHV;gBACA,MAAMW;YACV;QACJ;QAEA,IAAID,AAA0B,MAA1BA,eAAe,MAAM,EAErBX,MAAM,IAAI,GAAGY;aAGbZ,MAAM,IAAI,GAAG,GAAGY,SAAS,CAAC,EAAEE,uBAAuB,IAAI;QAG3D,OAAO;IACX;AACJ;AAEO,MAAMC,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -5,7 +5,6 @@ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.j
|
|
|
5
5
|
import { AccessControl } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
|
-
import { CmsContext } from "../../../features/shared/abstractions.js";
|
|
9
8
|
import type { CmsGroup } from "../../../types/index.js";
|
|
10
9
|
import type { CmsGroupCreateInput } from "../../../types/index.js";
|
|
11
10
|
/**
|
|
@@ -25,8 +24,7 @@ declare class CreateGroupUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
|
25
24
|
private accessControl;
|
|
26
25
|
private tenantContext;
|
|
27
26
|
private identityContext;
|
|
28
|
-
|
|
29
|
-
constructor(eventPublisher: EventPublisher.Interface, repository: CreateGroupRepository.Interface, accessControl: AccessControl.Interface, tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface, cmsContext: CmsContext.Interface);
|
|
27
|
+
constructor(eventPublisher: EventPublisher.Interface, repository: CreateGroupRepository.Interface, accessControl: AccessControl.Interface, tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface);
|
|
30
28
|
execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseAbstraction.Error>>;
|
|
31
29
|
}
|
|
32
30
|
export declare const CreateGroupUseCase: import("@webiny/di").Implementation<typeof CreateGroupUseCaseImpl>;
|
|
@@ -2,20 +2,19 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { CreateGroupRepository, CreateGroupUseCase } from "./abstractions.js";
|
|
3
3
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
4
4
|
import { GroupAfterCreateEvent, GroupBeforeCreateEventEvent, GroupCreateErrorEvent } from "./events.js";
|
|
5
|
-
import { AccessControl
|
|
5
|
+
import { AccessControl } from "../../shared/abstractions.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
8
|
import { GroupNotAuthorizedError, GroupValidationError } from "../../../domain/contentModelGroup/errors.js";
|
|
9
9
|
import { createZodError, mdbid } from "@webiny/utils";
|
|
10
10
|
import { createGroupCreateValidation } from "../../../domain/contentModelGroup/validation.js";
|
|
11
11
|
class CreateGroupUseCaseImpl {
|
|
12
|
-
constructor(eventPublisher, repository, accessControl, tenantContext, identityContext
|
|
12
|
+
constructor(eventPublisher, repository, accessControl, tenantContext, identityContext){
|
|
13
13
|
this.eventPublisher = eventPublisher;
|
|
14
14
|
this.repository = repository;
|
|
15
15
|
this.accessControl = accessControl;
|
|
16
16
|
this.tenantContext = tenantContext;
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
|
-
this.cmsContext = cmsContext;
|
|
19
18
|
}
|
|
20
19
|
async execute(input) {
|
|
21
20
|
const canAccess = await this.accessControl.canAccessGroup({
|
|
@@ -62,9 +61,9 @@ class CreateGroupUseCaseImpl {
|
|
|
62
61
|
return Result.fail(result.error);
|
|
63
62
|
}
|
|
64
63
|
await this.eventPublisher.publish(new GroupAfterCreateEvent({
|
|
65
|
-
group
|
|
64
|
+
group: result.value
|
|
66
65
|
}));
|
|
67
|
-
return Result.ok(
|
|
66
|
+
return Result.ok(result.value);
|
|
68
67
|
} catch (error) {
|
|
69
68
|
await this.eventPublisher.publish(new GroupCreateErrorEvent({
|
|
70
69
|
input,
|
|
@@ -83,8 +82,7 @@ const CreateGroupUseCase_CreateGroupUseCase = createImplementation({
|
|
|
83
82
|
CreateGroupRepository,
|
|
84
83
|
AccessControl,
|
|
85
84
|
TenantContext,
|
|
86
|
-
IdentityContext
|
|
87
|
-
CmsContext
|
|
85
|
+
IdentityContext
|
|
88
86
|
]
|
|
89
87
|
});
|
|
90
88
|
export { CreateGroupUseCase_CreateGroupUseCase as CreateGroupUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateGroupRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeCreateEventEvent } from \"./events.js\";\nimport { GroupAfterCreateEvent } from \"./events.js\";\nimport { GroupCreateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateGroupRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeCreateEventEvent } from \"./events.js\";\nimport { GroupAfterCreateEvent } from \"./events.js\";\nimport { GroupCreateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { mdbid } from \"@webiny/utils\";\nimport { createGroupCreateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupCreateInput } from \"~/types/index.js\";\n\n/**\n * CreateGroupUseCase - Orchestrates group creation.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Create domain group object\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass CreateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: CreateGroupRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(input: CmsGroupCreateInput): 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 // Validate input\n const validationResult = await createGroupCreateValidation().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 // Create domain group object\n const identity = this.identityContext.getIdentity();\n const tenant = this.tenantContext.getTenant();\n\n const id = data.id || mdbid();\n const group: CmsGroup = {\n ...data,\n id,\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n // Access control check on created group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group, rwd: \"w\" });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(new GroupBeforeCreateEventEvent({ group }));\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 GroupCreateErrorEvent({\n input,\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 GroupAfterCreateEvent({\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 GroupCreateErrorEvent({\n input,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const CreateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n CreateGroupRepository,\n AccessControl,\n TenantContext,\n IdentityContext\n ]\n});\n"],"names":["CreateGroupUseCaseImpl","eventPublisher","repository","accessControl","tenantContext","identityContext","input","canAccess","Result","GroupNotAuthorizedError","validationResult","createGroupCreateValidation","zodError","createZodError","GroupValidationError","data","identity","tenant","id","mdbid","group","Date","canAccessGroup","GroupBeforeCreateEventEvent","result","GroupCreateErrorEvent","GroupAfterCreateEvent","error","CreateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","CreateGroupRepository","AccessControl","TenantContext","IdentityContext"],"mappings":";;;;;;;;;;AAgCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,CACpD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAA0B,EAAuD;QAE3F,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,mBAAmB,MAAMC,8BAA8B,cAAc,CAACL;QAC5E,IAAI,CAACI,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOF,OAAO,IAAI,CACd,IAAIM,qBAAqBF,SAAS,OAAO,EAAEA,SAAS,IAAI,CAAE,aAAa;QAE/E;QACA,MAAMG,OAAOL,iBAAiB,IAAI;QAGlC,MAAMM,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAE3C,MAAMC,KAAKH,KAAK,EAAE,IAAII;QACtB,MAAMC,QAAkB;YACpB,GAAGL,IAAI;YACPG;YACA,QAAQD,OAAO,EAAE;YACjB,WAAW,IAAII,OAAO,WAAW;YACjC,SAAS,IAAIA,OAAO,WAAW;YAC/B,WAAW;gBACP,IAAIL,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;QAGA,MAAMM,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;YAAO,KAAK;QAAI;QACjF,IAAI,CAACE,gBACD,OAAOd,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIc,4BAA4B;gBAAEH;YAAM;YAG1E,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACJ;YAC7C,IAAII,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBnB;oBACAc;oBACA,OAAOI,OAAO,KAAK;gBACvB;gBAEJ,OAAOhB,OAAO,IAAI,CAACgB,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtB,OAAOF,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;gBACAc;gBACA,OAAOO;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -26,7 +26,7 @@ export declare namespace CreateGroupUseCase {
|
|
|
26
26
|
* CreateGroupRepository - Persists a new group to storage.
|
|
27
27
|
*/
|
|
28
28
|
export interface ICreateGroupRepository {
|
|
29
|
-
execute(group: CmsGroup): Promise<Result<
|
|
29
|
+
execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;
|
|
30
30
|
}
|
|
31
31
|
export interface ICreateGroupRepositoryErrors {
|
|
32
32
|
alreadyExists: GroupSlugTakenError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupCreateInput } from \"~/types/index.js\";\nimport type {\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupSlugTakenError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * CreateGroup Use Case\n */\nexport interface ICreateGroupUseCase {\n execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface ICreateGroupUseCaseErrors {\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = ICreateGroupUseCaseErrors[keyof ICreateGroupUseCaseErrors];\n\n/** Create a new content model group. */\nexport const CreateGroupUseCase = createAbstraction<ICreateGroupUseCase>(\"CreateGroupUseCase\");\n\nexport namespace CreateGroupUseCase {\n export type Interface = ICreateGroupUseCase;\n export type Input = CmsGroupCreateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * CreateGroupRepository - Persists a new group to storage.\n */\nexport interface ICreateGroupRepository {\n execute(group: CmsGroup): Promise<Result<
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupCreateInput } from \"~/types/index.js\";\nimport type {\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupSlugTakenError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * CreateGroup Use Case\n */\nexport interface ICreateGroupUseCase {\n execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface ICreateGroupUseCaseErrors {\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = ICreateGroupUseCaseErrors[keyof ICreateGroupUseCaseErrors];\n\n/** Create a new content model group. */\nexport const CreateGroupUseCase = createAbstraction<ICreateGroupUseCase>(\"CreateGroupUseCase\");\n\nexport namespace CreateGroupUseCase {\n export type Interface = ICreateGroupUseCase;\n export type Input = CmsGroupCreateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * CreateGroupRepository - Persists a new group to storage.\n */\nexport interface ICreateGroupRepository {\n execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;\n}\n\nexport interface ICreateGroupRepositoryErrors {\n alreadyExists: GroupSlugTakenError;\n storage: GroupPersistenceError;\n}\n\ntype RepositoryError = ICreateGroupRepositoryErrors[keyof ICreateGroupRepositoryErrors];\n\nexport const CreateGroupRepository =\n createAbstraction<ICreateGroupRepository>(\"CreateGroupRepository\");\n\nexport namespace CreateGroupRepository {\n export type Interface = ICreateGroupRepository;\n export type Error = RepositoryError;\n}\n"],"names":["CreateGroupUseCase","createAbstraction","CreateGroupRepository"],"mappings":";AA2BO,MAAMA,qBAAqBC,kBAAuC;AAwBlE,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -4,6 +4,7 @@ import { GroupCache } from "../../../features/contentModelGroup/shared/abstracti
|
|
|
4
4
|
import { PluginGroupsProvider } from "../../../features/contentModelGroup/shared/abstractions.js";
|
|
5
5
|
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import type { CmsGroup } from "../../../types/index.js";
|
|
7
|
+
import { RuntimeTenant } from "../../../features/runtimeTenant/abstractions.js";
|
|
7
8
|
/**
|
|
8
9
|
* DeleteGroupRepository - Validates and performs group deletion.
|
|
9
10
|
*
|
|
@@ -17,8 +18,9 @@ declare class DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interfa
|
|
|
17
18
|
private groupCache;
|
|
18
19
|
private pluginGroupsProvider;
|
|
19
20
|
private storageOperations;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
private runtimeTenant;
|
|
22
|
+
constructor(groupCache: GroupCache.Interface, pluginGroupsProvider: PluginGroupsProvider.Interface, storageOperations: StorageOperations.Interface, runtimeTenant: RuntimeTenant.Interface);
|
|
23
|
+
execute(initialGroup: CmsGroup): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
22
24
|
}
|
|
23
25
|
export declare const DeleteGroupRepository: import("@webiny/di").Implementation<typeof DeleteGroupRepositoryImpl>;
|
|
24
26
|
export {};
|
|
@@ -3,13 +3,16 @@ import { DeleteGroupRepository } from "./abstractions.js";
|
|
|
3
3
|
import { GroupCache, PluginGroupsProvider } from "../shared/abstractions.js";
|
|
4
4
|
import { GroupCannotDeleteCodeDefinedError, GroupHasModelsError, GroupPersistenceError } from "../../../domain/contentModelGroup/errors.js";
|
|
5
5
|
import { StorageOperations } from "../../shared/abstractions.js";
|
|
6
|
+
import { RuntimeTenant } from "../../runtimeTenant/abstractions.js";
|
|
6
7
|
class DeleteGroupRepositoryImpl {
|
|
7
|
-
constructor(groupCache, pluginGroupsProvider, storageOperations){
|
|
8
|
+
constructor(groupCache, pluginGroupsProvider, storageOperations, runtimeTenant){
|
|
8
9
|
this.groupCache = groupCache;
|
|
9
10
|
this.pluginGroupsProvider = pluginGroupsProvider;
|
|
10
11
|
this.storageOperations = storageOperations;
|
|
12
|
+
this.runtimeTenant = runtimeTenant;
|
|
11
13
|
}
|
|
12
|
-
async execute(
|
|
14
|
+
async execute(initialGroup) {
|
|
15
|
+
const group = this.runtimeTenant.assign(initialGroup);
|
|
13
16
|
try {
|
|
14
17
|
const pluginGroups = await this.pluginGroupsProvider.getGroups();
|
|
15
18
|
const isPluginGroup = pluginGroups.some((pg)=>pg.slug === group.slug);
|
|
@@ -37,7 +40,8 @@ const DeleteGroupRepository_DeleteGroupRepository = createImplementation({
|
|
|
37
40
|
dependencies: [
|
|
38
41
|
GroupCache,
|
|
39
42
|
PluginGroupsProvider,
|
|
40
|
-
StorageOperations
|
|
43
|
+
StorageOperations,
|
|
44
|
+
RuntimeTenant
|
|
41
45
|
]
|
|
42
46
|
});
|
|
43
47
|
export { DeleteGroupRepository_DeleteGroupRepository as DeleteGroupRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotDeleteCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupHasModelsError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * DeleteGroupRepository - Validates and performs group deletion.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot delete)\n * - Check if models reference this group (cannot delete)\n * - Persist deletion to storage\n * - Clear GroupCache after successful deletion\n */\nclass DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotDeleteCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupHasModelsError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * DeleteGroupRepository - Validates and performs group deletion.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot delete)\n * - Check if models reference this group (cannot delete)\n * - Persist deletion to storage\n * - Clear GroupCache after successful deletion\n */\nclass DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<void, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n // Check if this is a plugin-based group (cannot be deleted)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const isPluginGroup = pluginGroups.some(pg => pg.slug === group.slug);\n\n if (isPluginGroup) {\n return Result.fail(new GroupCannotDeleteCodeDefinedError(group.id));\n }\n\n // Check if any models reference this group\n const models = await this.storageOperations.models.list({\n where: {\n tenant: group.tenant\n }\n });\n\n const items = models.filter(model => model.group === group.slug);\n if (items.length > 0) {\n return Result.fail(new GroupHasModelsError());\n }\n\n // Perform deletion\n await this.storageOperations.groups.delete({ group });\n\n // Clear cache\n this.groupCache.clear();\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n}\n\nexport const DeleteGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: DeleteGroupRepositoryImpl,\n dependencies: [GroupCache, PluginGroupsProvider, StorageOperations, RuntimeTenant]\n});\n"],"names":["DeleteGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","runtimeTenant","initialGroup","group","pluginGroups","isPluginGroup","pg","Result","GroupCannotDeleteCodeDefinedError","models","items","model","GroupHasModelsError","error","GroupPersistenceError","DeleteGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","RuntimeTenant"],"mappings":";;;;;;AAqBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,CAChD;aAJUH,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAsD;QACtF,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YAEA,MAAME,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;YAC9D,MAAMC,gBAAgBD,aAAa,IAAI,CAACE,CAAAA,KAAMA,GAAG,IAAI,KAAKH,MAAM,IAAI;YAEpE,IAAIE,eACA,OAAOE,OAAO,IAAI,CAAC,IAAIC,kCAAkCL,MAAM,EAAE;YAIrE,MAAMM,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;gBACpD,OAAO;oBACH,QAAQN,MAAM,MAAM;gBACxB;YACJ;YAEA,MAAMO,QAAQD,OAAO,MAAM,CAACE,CAAAA,QAASA,MAAM,KAAK,KAAKR,MAAM,IAAI;YAC/D,IAAIO,MAAM,MAAM,GAAG,GACf,OAAOH,OAAO,IAAI,CAAC,IAAIK;YAI3B,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAET;YAAM;YAGnD,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOI,OAAO,EAAE;QACpB,EAAE,OAAOM,OAAO;YACZ,OAAON,OAAO,IAAI,CAAC,IAAIO,sBAAsBD;QACjD;IACJ;AACJ;AAEO,MAAME,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAYC;QAAsBC;QAAmBC;KAAc;AACtF"}
|
|
@@ -4,6 +4,7 @@ import { GroupCache } from "../../../features/contentModelGroup/shared/abstracti
|
|
|
4
4
|
import { PluginGroupsProvider } from "../../../features/contentModelGroup/shared/abstractions.js";
|
|
5
5
|
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import type { CmsGroup } from "../../../types/index.js";
|
|
7
|
+
import { RuntimeTenant } from "../../../features/runtimeTenant/abstractions.js";
|
|
7
8
|
/**
|
|
8
9
|
* UpdateGroupRepository - Validates and persists group updates.
|
|
9
10
|
*
|
|
@@ -16,8 +17,9 @@ declare class UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interfa
|
|
|
16
17
|
private groupCache;
|
|
17
18
|
private pluginGroupsProvider;
|
|
18
19
|
private storageOperations;
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
private runtimeTenant;
|
|
21
|
+
constructor(groupCache: GroupCache.Interface, pluginGroupsProvider: PluginGroupsProvider.Interface, storageOperations: StorageOperations.Interface, runtimeTenant: RuntimeTenant.Interface);
|
|
22
|
+
execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>>;
|
|
21
23
|
}
|
|
22
24
|
export declare const UpdateGroupRepository: import("@webiny/di").Implementation<typeof UpdateGroupRepositoryImpl>;
|
|
23
25
|
export {};
|
|
@@ -3,13 +3,16 @@ import { UpdateGroupRepository } from "./abstractions.js";
|
|
|
3
3
|
import { GroupCache, PluginGroupsProvider } from "../shared/abstractions.js";
|
|
4
4
|
import { GroupCannotUpdateCodeDefinedError, GroupPersistenceError } from "../../../domain/contentModelGroup/errors.js";
|
|
5
5
|
import { StorageOperations } from "../../shared/abstractions.js";
|
|
6
|
+
import { RuntimeTenant } from "../../runtimeTenant/abstractions.js";
|
|
6
7
|
class UpdateGroupRepositoryImpl {
|
|
7
|
-
constructor(groupCache, pluginGroupsProvider, storageOperations){
|
|
8
|
+
constructor(groupCache, pluginGroupsProvider, storageOperations, runtimeTenant){
|
|
8
9
|
this.groupCache = groupCache;
|
|
9
10
|
this.pluginGroupsProvider = pluginGroupsProvider;
|
|
10
11
|
this.storageOperations = storageOperations;
|
|
12
|
+
this.runtimeTenant = runtimeTenant;
|
|
11
13
|
}
|
|
12
|
-
async execute(
|
|
14
|
+
async execute(initialGroup) {
|
|
15
|
+
const group = this.runtimeTenant.assign(initialGroup);
|
|
13
16
|
try {
|
|
14
17
|
const pluginGroups = await this.pluginGroupsProvider.getGroups();
|
|
15
18
|
const isPluginGroup = pluginGroups.some((pg)=>pg.slug === group.slug);
|
|
@@ -18,7 +21,7 @@ class UpdateGroupRepositoryImpl {
|
|
|
18
21
|
group
|
|
19
22
|
});
|
|
20
23
|
this.groupCache.clear();
|
|
21
|
-
return Result.ok();
|
|
24
|
+
return Result.ok(group);
|
|
22
25
|
} catch (error) {
|
|
23
26
|
return Result.fail(new GroupPersistenceError(error));
|
|
24
27
|
}
|
|
@@ -30,7 +33,8 @@ const UpdateGroupRepository_UpdateGroupRepository = createImplementation({
|
|
|
30
33
|
dependencies: [
|
|
31
34
|
GroupCache,
|
|
32
35
|
PluginGroupsProvider,
|
|
33
|
-
StorageOperations
|
|
36
|
+
StorageOperations,
|
|
37
|
+
RuntimeTenant
|
|
34
38
|
]
|
|
35
39
|
});
|
|
36
40
|
export { UpdateGroupRepository_UpdateGroupRepository as UpdateGroupRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotUpdateCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * UpdateGroupRepository - Validates and persists group updates.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot update)\n * - Persist updates to storage\n * - Clear GroupCache after successful update\n */\nclass UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotUpdateCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * UpdateGroupRepository - Validates and persists group updates.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot update)\n * - Persist updates to storage\n * - Clear GroupCache after successful update\n */\nclass UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n // Check if this is a plugin-based group (cannot be updated)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const isPluginGroup = pluginGroups.some(pg => pg.slug === group.slug);\n\n if (isPluginGroup) {\n return Result.fail(new GroupCannotUpdateCodeDefinedError(group.id));\n }\n\n // Persist updates\n await this.storageOperations.groups.update({ group });\n\n // Clear cache\n this.groupCache.clear();\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n}\n\nexport const UpdateGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: UpdateGroupRepositoryImpl,\n dependencies: [GroupCache, PluginGroupsProvider, StorageOperations, RuntimeTenant]\n});\n"],"names":["UpdateGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","runtimeTenant","initialGroup","group","pluginGroups","isPluginGroup","pg","Result","GroupCannotUpdateCodeDefinedError","error","GroupPersistenceError","UpdateGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","RuntimeTenant"],"mappings":";;;;;;AAmBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,CAChD;aAJUH,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YAEA,MAAME,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;YAC9D,MAAMC,gBAAgBD,aAAa,IAAI,CAACE,CAAAA,KAAMA,GAAG,IAAI,KAAKH,MAAM,IAAI;YAEpE,IAAIE,eACA,OAAOE,OAAO,IAAI,CAAC,IAAIC,kCAAkCL,MAAM,EAAE;YAIrE,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAEA;YAAM;YAGnD,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOI,OAAO,EAAE,CAACJ;QACrB,EAAE,OAAOM,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD;QACjD;IACJ;AACJ;AAEO,MAAME,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBhB;IAChB,cAAc;QAACiB;QAAYC;QAAsBC;QAAmBC;KAAc;AACtF"}
|
|
@@ -59,9 +59,9 @@ class UpdateGroupUseCaseImpl {
|
|
|
59
59
|
}
|
|
60
60
|
await this.eventPublisher.publish(new GroupAfterUpdateEvent({
|
|
61
61
|
original,
|
|
62
|
-
group
|
|
62
|
+
group: result.value
|
|
63
63
|
}));
|
|
64
|
-
return Result.ok(
|
|
64
|
+
return Result.ok(result.value);
|
|
65
65
|
} catch (error) {
|
|
66
66
|
await this.eventPublisher.publish(new GroupUpdateErrorEvent({
|
|
67
67
|
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({ group: original });\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\n })\n );\n\n return Result.ok(
|
|
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({ group: original });\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,EAC3CC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;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,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,OAAOD;QAAS;QACjF,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMI,mBAAmB,MAAMC,8BAA8B,cAAc,CAACR;QAC5E,IAAI,CAACO,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOL,OAAO,IAAI,CACd,IAAIS,qBAAqBF,SAAS,OAAO,EAAEA,SAAS,IAAI,CAAE,aAAa;QAE/E;QACA,MAAMG,OAAOL,iBAAiB,IAAI;QAGlC,IAAIM,AAA6B,MAA7BA,OAAO,IAAI,CAACD,MAAM,MAAM,EACxB,OAAOV,OAAO,EAAE,CAACG;QAIrB,MAAMS,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,QAAkB;YACpB,GAAGV,QAAQ;YACX,GAAGO,IAAI;YACP,QAAQE,OAAO,EAAE;YACjB,SAAS,IAAIE,OAAO,WAAW;QACnC;QAEA,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,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"}
|
|
@@ -27,7 +27,7 @@ export declare namespace UpdateGroupUseCase {
|
|
|
27
27
|
* UpdateGroupRepository - Persists group updates to storage.
|
|
28
28
|
*/
|
|
29
29
|
export interface IUpdateGroupRepository {
|
|
30
|
-
execute(group: CmsGroup): Promise<Result<
|
|
30
|
+
execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;
|
|
31
31
|
}
|
|
32
32
|
export interface IUpdateGroupRepositoryErrors {
|
|
33
33
|
cannotUpdate: GroupCannotUpdateCodeDefinedError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupUpdateInput } from \"~/types/index.js\";\nimport type {\n GroupCannotUpdateCodeDefinedError,\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupNotFoundError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * UpdateGroup Use Case\n */\nexport interface IUpdateGroupUseCase {\n execute(groupId: string, input: CmsGroupUpdateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface IUpdateGroupUseCaseErrors {\n notFound: GroupNotFoundError;\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = IUpdateGroupUseCaseErrors[keyof IUpdateGroupUseCaseErrors];\n\n/** Update a content model group. */\nexport const UpdateGroupUseCase = createAbstraction<IUpdateGroupUseCase>(\"UpdateGroupUseCase\");\n\nexport namespace UpdateGroupUseCase {\n export type Interface = IUpdateGroupUseCase;\n export type Input = CmsGroupUpdateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * UpdateGroupRepository - Persists group updates to storage.\n */\nexport interface IUpdateGroupRepository {\n execute(group: CmsGroup): Promise<Result<
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupUpdateInput } from \"~/types/index.js\";\nimport type {\n GroupCannotUpdateCodeDefinedError,\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupNotFoundError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * UpdateGroup Use Case\n */\nexport interface IUpdateGroupUseCase {\n execute(groupId: string, input: CmsGroupUpdateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface IUpdateGroupUseCaseErrors {\n notFound: GroupNotFoundError;\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = IUpdateGroupUseCaseErrors[keyof IUpdateGroupUseCaseErrors];\n\n/** Update a content model group. */\nexport const UpdateGroupUseCase = createAbstraction<IUpdateGroupUseCase>(\"UpdateGroupUseCase\");\n\nexport namespace UpdateGroupUseCase {\n export type Interface = IUpdateGroupUseCase;\n export type Input = CmsGroupUpdateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * UpdateGroupRepository - Persists group updates to storage.\n */\nexport interface IUpdateGroupRepository {\n execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;\n}\n\nexport interface IUpdateGroupRepositoryErrors {\n cannotUpdate: GroupCannotUpdateCodeDefinedError;\n storage: GroupPersistenceError;\n}\n\ntype RepositoryError = IUpdateGroupRepositoryErrors[keyof IUpdateGroupRepositoryErrors];\n\nexport const UpdateGroupRepository =\n createAbstraction<IUpdateGroupRepository>(\"UpdateGroupRepository\");\n\nexport namespace UpdateGroupRepository {\n export type Interface = IUpdateGroupRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UpdateGroupUseCase","createAbstraction","UpdateGroupRepository"],"mappings":";AA6BO,MAAMA,qBAAqBC,kBAAuC;AAwBlE,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RuntimeTenant as Abstraction } from "./abstractions.js";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
|
|
3
|
+
declare class RuntimeTenantImpl implements Abstraction.Interface {
|
|
4
|
+
private tenantContext;
|
|
5
|
+
constructor(tenantContext: TenantContext.Interface);
|
|
6
|
+
assign<T extends {
|
|
7
|
+
tenant: string;
|
|
8
|
+
}>(obj: T): T;
|
|
9
|
+
}
|
|
10
|
+
export declare const RuntimeTenant: typeof RuntimeTenantImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IRuntimeTenant>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RuntimeTenant } from "./abstractions.js";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
|
|
3
|
+
class RuntimeTenantImpl {
|
|
4
|
+
constructor(tenantContext){
|
|
5
|
+
this.tenantContext = tenantContext;
|
|
6
|
+
}
|
|
7
|
+
assign(obj) {
|
|
8
|
+
return structuredClone({
|
|
9
|
+
...obj,
|
|
10
|
+
tenant: this.tenantContext.getTenant().id
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const RuntimeTenant_RuntimeTenant = RuntimeTenant.createImplementation({
|
|
15
|
+
implementation: RuntimeTenantImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
TenantContext
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { RuntimeTenant_RuntimeTenant as RuntimeTenant };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=RuntimeTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/runtimeTenant/RuntimeTenant.js","sources":["../../../src/features/runtimeTenant/RuntimeTenant.ts"],"sourcesContent":["import { RuntimeTenant as Abstraction } from \"./abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/exports/api/tenancy.js\";\n\nclass RuntimeTenantImpl implements Abstraction.Interface {\n public constructor(private tenantContext: TenantContext.Interface) {}\n\n public assign<T extends { tenant: string }>(obj: T): T {\n return structuredClone({ ...obj, tenant: this.tenantContext.getTenant().id });\n }\n}\n\nexport const RuntimeTenant = Abstraction.createImplementation({\n implementation: RuntimeTenantImpl,\n dependencies: [TenantContext]\n});\n"],"names":["RuntimeTenantImpl","tenantContext","obj","structuredClone","RuntimeTenant","Abstraction","TenantContext"],"mappings":";;AAGA,MAAMA;IACF,YAA2BC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,OAAqCC,GAAM,EAAK;QACnD,OAAOC,gBAAgB;YAAE,GAAGD,GAAG;YAAE,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAAC;IAC/E;AACJ;AAEO,MAAME,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBL;IAChB,cAAc;QAACM;KAAc;AACjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface HasTenant {
|
|
2
|
+
tenant: string;
|
|
3
|
+
}
|
|
4
|
+
export interface IRuntimeTenant {
|
|
5
|
+
assign<T extends HasTenant>(obj: T): T;
|
|
6
|
+
}
|
|
7
|
+
export declare const RuntimeTenant: import("@webiny/di").Abstraction<IRuntimeTenant>;
|
|
8
|
+
export declare namespace RuntimeTenant {
|
|
9
|
+
type Interface = IRuntimeTenant;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/runtimeTenant/abstractions.js","sources":["../../../src/features/runtimeTenant/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\ninterface HasTenant {\n tenant: string;\n}\n\nexport interface IRuntimeTenant {\n assign<T extends HasTenant>(obj: T): T;\n}\n\nexport const RuntimeTenant = createAbstraction<IRuntimeTenant>(\"Cms/RuntimeTenant\");\n\nexport namespace RuntimeTenant {\n export type Interface = IRuntimeTenant;\n}\n"],"names":["RuntimeTenant","createAbstraction"],"mappings":";AAUO,MAAMA,gBAAgBC,kBAAkC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.9-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@babel/code-frame": "8.0.0",
|
|
26
26
|
"@graphql-tools/merge": "9.2.0",
|
|
27
27
|
"@graphql-tools/schema": "10.0.36",
|
|
28
|
-
"@webiny/api": "6.4.
|
|
29
|
-
"@webiny/api-core": "6.4.
|
|
28
|
+
"@webiny/api": "6.4.9-beta.0",
|
|
29
|
+
"@webiny/api-core": "6.4.9-beta.0",
|
|
30
30
|
"@webiny/di": "1.0.2",
|
|
31
|
-
"@webiny/error": "6.4.
|
|
32
|
-
"@webiny/feature": "6.4.
|
|
33
|
-
"@webiny/handler": "6.4.
|
|
34
|
-
"@webiny/handler-aws": "6.4.
|
|
35
|
-
"@webiny/handler-db": "6.4.
|
|
36
|
-
"@webiny/handler-graphql": "6.4.
|
|
37
|
-
"@webiny/plugins": "6.4.
|
|
38
|
-
"@webiny/project": "6.4.
|
|
39
|
-
"@webiny/utils": "6.4.
|
|
40
|
-
"@webiny/validation": "6.4.
|
|
31
|
+
"@webiny/error": "6.4.9-beta.0",
|
|
32
|
+
"@webiny/feature": "6.4.9-beta.0",
|
|
33
|
+
"@webiny/handler": "6.4.9-beta.0",
|
|
34
|
+
"@webiny/handler-aws": "6.4.9-beta.0",
|
|
35
|
+
"@webiny/handler-db": "6.4.9-beta.0",
|
|
36
|
+
"@webiny/handler-graphql": "6.4.9-beta.0",
|
|
37
|
+
"@webiny/plugins": "6.4.9-beta.0",
|
|
38
|
+
"@webiny/project": "6.4.9-beta.0",
|
|
39
|
+
"@webiny/utils": "6.4.9-beta.0",
|
|
40
|
+
"@webiny/validation": "6.4.9-beta.0",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
42
|
"graphql": "16.14.2",
|
|
43
43
|
"graphql-tag": "2.12.7",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/babel__code-frame": "7.27.0",
|
|
53
53
|
"@types/pluralize": "0.0.33",
|
|
54
|
-
"@webiny/aws-sdk": "6.4.
|
|
55
|
-
"@webiny/build-tools": "6.4.
|
|
56
|
-
"@webiny/db-dynamodb": "6.4.
|
|
57
|
-
"@webiny/handler-db": "6.4.
|
|
58
|
-
"@webiny/project-utils": "6.4.
|
|
59
|
-
"@webiny/sdk": "6.4.
|
|
60
|
-
"@webiny/wcp": "6.4.
|
|
54
|
+
"@webiny/aws-sdk": "6.4.9-beta.0",
|
|
55
|
+
"@webiny/build-tools": "6.4.9-beta.0",
|
|
56
|
+
"@webiny/db-dynamodb": "6.4.9-beta.0",
|
|
57
|
+
"@webiny/handler-db": "6.4.9-beta.0",
|
|
58
|
+
"@webiny/project-utils": "6.4.9-beta.0",
|
|
59
|
+
"@webiny/sdk": "6.4.9-beta.0",
|
|
60
|
+
"@webiny/wcp": "6.4.9-beta.0",
|
|
61
61
|
"apollo-graphql": "0.9.7",
|
|
62
62
|
"graphql": "16.14.2",
|
|
63
63
|
"oxfmt": "0.58.0",
|