@webiny/api-core 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/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +2 -0
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +2 -2
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js +7 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/abstractions.d.ts +3 -3
- package/features/security/apiKeys/GetApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.d.ts +2 -2
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js +4 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/abstractions.d.ts +3 -4
- package/features/security/apiKeys/ListApiKeys/abstractions.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +2 -0
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/shared/hideToken.d.ts +8 -0
- package/features/security/apiKeys/shared/hideToken.js +11 -0
- package/features/security/apiKeys/shared/hideToken.js.map +1 -0
- package/features/security/apiKeys/shared/types.d.ts +7 -0
- package/features/security/roles/CreateRole/CreateRoleUseCase.js +6 -0
- package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
- package/features/security/roles/DeleteRole/DeleteRoleUseCase.js +2 -1
- package/features/security/roles/DeleteRole/DeleteRoleUseCase.js.map +1 -1
- package/features/security/roles/DeleteRole/abstractions.d.ts +2 -1
- package/features/security/roles/DeleteRole/abstractions.js.map +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +10 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/UpdateRole/abstractions.d.ts +2 -1
- package/features/security/roles/UpdateRole/abstractions.js.map +1 -1
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.d.ts +5 -2
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.js +16 -3
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.js.map +1 -1
- package/features/security/roles/shared/errors.d.ts +8 -0
- package/features/security/roles/shared/errors.js +15 -1
- package/features/security/roles/shared/errors.js.map +1 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js +17 -2
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -2
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/utils/canAssignRolesAndTeams.d.ts +16 -0
- package/features/security/utils/canAssignRolesAndTeams.js +31 -0
- package/features/security/utils/canAssignRolesAndTeams.js.map +1 -0
- package/features/security/utils/canGrantPermissions.d.ts +53 -0
- package/features/security/utils/canGrantPermissions.js +122 -0
- package/features/security/utils/canGrantPermissions.js.map +1 -0
- package/features/security/utils/verifyJwtUsingJwk.d.ts +16 -1
- package/features/security/utils/verifyJwtUsingJwk.js +22 -4
- package/features/security/utils/verifyJwtUsingJwk.js.map +1 -1
- package/features/system/InstallSystem/InstallSystemUseCase.d.ts +1 -1
- package/features/tenancy/CreateTenant/CreateTenantRepository.js +1 -0
- package/features/tenancy/CreateTenant/CreateTenantRepository.js.map +1 -1
- package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +5 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js +10 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js.map +1 -1
- package/features/tenancy/CreateTenant/abstractions.d.ts +2 -1
- package/features/tenancy/CreateTenant/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/decorators/CreateTenantWithWcpIncrement.d.ts +1 -1
- package/features/tenancy/CreateTenant/errors.d.ts +6 -0
- package/features/tenancy/CreateTenant/errors.js +11 -1
- package/features/tenancy/CreateTenant/errors.js.map +1 -1
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js +1 -0
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js.map +1 -1
- package/features/tenancy/TenantContext/TenantContext.d.ts +2 -0
- package/features/tenancy/TenantContext/TenantContext.js +18 -21
- package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
- package/features/tenancy/TenantContext/abstractions.d.ts +5 -0
- package/features/tenancy/TenantContext/abstractions.js.map +1 -1
- package/features/users/CreateUser/CreateUserUseCase.d.ts +5 -1
- package/features/users/CreateUser/CreateUserUseCase.js +18 -2
- package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
- package/features/users/UpdateUser/UpdateUserUseCase.d.ts +5 -1
- package/features/users/UpdateUser/UpdateUserUseCase.js +24 -2
- package/features/users/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/graphql/security/apiKey.gql.js +1 -0
- package/graphql/security/apiKey.gql.js.map +1 -1
- package/idp/OidcJwtIdentityProvider.js +4 -1
- package/idp/OidcJwtIdentityProvider.js.map +1 -1
- package/package.json +22 -22
|
@@ -4,6 +4,7 @@ import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
|
4
4
|
import { CreateApiKeyUseCase } from "./abstractions.js";
|
|
5
5
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
6
6
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
7
|
+
import { hasFullAccessOrNoAuthorization } from "../../utils/canGrantPermissions.js";
|
|
7
8
|
import { createApiKeyInputSchema } from "../shared/schemas.js";
|
|
8
9
|
import { ApiKeyAfterCreateEvent, ApiKeyBeforeCreateEvent } from "./events.js";
|
|
9
10
|
import { generateToken } from "../shared/generateToken.js";
|
|
@@ -17,6 +18,7 @@ class CreateApiKeyUseCaseImpl {
|
|
|
17
18
|
async execute(input) {
|
|
18
19
|
const hasPermission = await this.identityContext.getPermission("security.apiKey");
|
|
19
20
|
if (!hasPermission) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
21
|
+
if (!await hasFullAccessOrNoAuthorization(this.identityContext)) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
20
22
|
const validation = createApiKeyInputSchema.safeParse(input);
|
|
21
23
|
if (!validation.success) return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));
|
|
22
24
|
const token = generateToken();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateApiKeyUseCase as CreateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeCreateEvent, ApiKeyAfterCreateEvent } from \"./events.js\";\nimport type { ApiKey, CreateApiKeyInput } from \"../shared/types.js\";\nimport type { ApiKeyPermission } from \"~/types/security.js\";\nimport { generateToken } from \"../shared/generateToken.js\";\nimport { ApiKeyValidationError, ApiKeyNotAuthorizedError } from \"../shared/errors.js\";\n\nclass CreateApiKeyUseCaseImpl implements CreateApiKeyUseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: ApiKeysRepository.Interface\n ) {}\n\n async execute(\n input: CreateApiKeyInput\n ): Promise<Result<ApiKey, CreateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission =\n await this.identityContext.getPermission<ApiKeyPermission>(\"security.apiKey\");\n\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = createApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const token = generateToken();\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n const apiKey: ApiKey = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n token,\n permissions: data.permissions,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeCreateEvent({ apiKey, input: validation.data })\n );\n\n const result = await this.repository.create(apiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterCreateEvent({ apiKey, input: validation.data })\n );\n\n return Result.ok(apiKey);\n }\n}\n\nexport const CreateApiKeyUseCase = CreateApiKeyUseCaseAbstraction.createImplementation({\n implementation: CreateApiKeyUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, ApiKeysRepository]\n});\n"],"names":["CreateApiKeyUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","ApiKeyNotAuthorizedError","validation","createApiKeyInputSchema","ApiKeyValidationError","token","generateToken","identity","data","apiKey","mdbid","Date","ApiKeyBeforeCreateEvent","result","ApiKeyAfterCreateEvent","CreateApiKeyUseCase","CreateApiKeyUseCaseAbstraction","IdentityContext","EventPublisher","ApiKeysRepository"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateApiKeyUseCase as CreateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { hasFullAccessOrNoAuthorization } from \"../../utils/canGrantPermissions.js\";\nimport { createApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeCreateEvent, ApiKeyAfterCreateEvent } from \"./events.js\";\nimport type { ApiKey, CreateApiKeyInput } from \"../shared/types.js\";\nimport type { ApiKeyPermission } from \"~/types/security.js\";\nimport { generateToken } from \"../shared/generateToken.js\";\nimport { ApiKeyValidationError, ApiKeyNotAuthorizedError } from \"../shared/errors.js\";\n\nclass CreateApiKeyUseCaseImpl implements CreateApiKeyUseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: ApiKeysRepository.Interface\n ) {}\n\n async execute(\n input: CreateApiKeyInput\n ): Promise<Result<ApiKey, CreateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission =\n await this.identityContext.getPermission<ApiKeyPermission>(\"security.apiKey\");\n\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n // Security: an API key can carry any permission, so only full access may write one.\n if (!(await hasFullAccessOrNoAuthorization(this.identityContext))) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = createApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const token = generateToken();\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n const apiKey: ApiKey = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n token,\n permissions: data.permissions,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeCreateEvent({ apiKey, input: validation.data })\n );\n\n const result = await this.repository.create(apiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterCreateEvent({ apiKey, input: validation.data })\n );\n\n return Result.ok(apiKey);\n }\n}\n\nexport const CreateApiKeyUseCase = CreateApiKeyUseCaseAbstraction.createImplementation({\n implementation: CreateApiKeyUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, ApiKeysRepository]\n});\n"],"names":["CreateApiKeyUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","ApiKeyNotAuthorizedError","hasFullAccessOrNoAuthorization","validation","createApiKeyInputSchema","ApiKeyValidationError","token","generateToken","identity","data","apiKey","mdbid","Date","ApiKeyBeforeCreateEvent","result","ApiKeyAfterCreateEvent","CreateApiKeyUseCase","CreateApiKeyUseCaseAbstraction","IdentityContext","EventPublisher","ApiKeysRepository"],"mappings":";;;;;;;;;;;AAcA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAuC,CACjD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAAwB,EACqC;QAC7D,MAAMC,gBACF,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAmB;QAE/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,IAAI,CAAE,MAAMC,+BAA+B,IAAI,CAAC,eAAe,GAC3D,OAAOF,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAME,aAAaC,wBAAwB,SAAS,CAACN;QACrD,IAAI,CAACK,WAAW,OAAO,EACnB,OAAOH,OAAO,IAAI,CAAC,IAAIK,sBAAsBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGnF,MAAMG,QAAQC;QACd,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,OAAON,WAAW,IAAI;QAE5B,MAAMO,SAAiB;YACnB,IAAIC;YACJ,MAAMF,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAC7BH;YACA,aAAaG,KAAK,WAAW;YAC7B,WAAW,IAAIG,OAAO,WAAW;YACjC,WAAW;gBACP,IAAIJ,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIK,wBAAwB;YAAEH;YAAQ,OAAOP,WAAW,IAAI;QAAC;QAGjE,MAAMW,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOd,OAAO,IAAI,CAACc,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YAAEL;YAAQ,OAAOP,WAAW,IAAI;QAAC;QAGhE,OAAOH,OAAO,EAAE,CAACU;IACrB;AACJ;AAEO,MAAMM,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBvB;IAChB,cAAc;QAACwB;QAAiBC;QAAgBC;KAAkB;AACtE"}
|
|
@@ -2,12 +2,12 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ReadableApiKey } from "../shared/types.js";
|
|
6
6
|
declare class GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {
|
|
7
7
|
private repository;
|
|
8
8
|
private identityContext;
|
|
9
9
|
constructor(repository: ApiKeysRepository.Interface, identityContext: IdentityContext.Interface);
|
|
10
|
-
execute(id: string): Promise<Result<
|
|
10
|
+
execute(id: string): Promise<Result<ReadableApiKey, GetApiKeyUseCaseAbstraction.Error>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const GetApiKeyUseCase: typeof GetApiKeyUseCaseImpl & {
|
|
13
13
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKey>;
|
|
@@ -3,6 +3,7 @@ import { GetApiKeyUseCase } from "./abstractions.js";
|
|
|
3
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
5
|
import { ApiKeyNotAuthorizedError } from "../shared/errors.js";
|
|
6
|
+
import { hideTokenUnlessFullAccess } from "../shared/hideToken.js";
|
|
6
7
|
class GetApiKeyUseCaseImpl {
|
|
7
8
|
constructor(repository, identityContext){
|
|
8
9
|
this.repository = repository;
|
|
@@ -11,7 +12,12 @@ class GetApiKeyUseCaseImpl {
|
|
|
11
12
|
async execute(id) {
|
|
12
13
|
const hasPermission = await this.identityContext.getPermission("security.apiKey");
|
|
13
14
|
if (!hasPermission) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
14
|
-
|
|
15
|
+
const result = await this.repository.get(id);
|
|
16
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
+
const [apiKey] = await hideTokenUnlessFullAccess(this.identityContext, [
|
|
18
|
+
result.value
|
|
19
|
+
]);
|
|
20
|
+
return Result.ok(apiKey);
|
|
15
21
|
}
|
|
16
22
|
}
|
|
17
23
|
const GetApiKeyUseCase_GetApiKeyUseCase = GetApiKeyUseCase.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type { ReadableApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\nimport { hideTokenUnlessFullAccess } from \"../shared/hideToken.js\";\n\nclass GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(id: string): Promise<Result<ReadableApiKey, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const result = await this.repository.get(id);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const [apiKey] = await hideTokenUnlessFullAccess(this.identityContext, [result.value]);\n return Result.ok(apiKey);\n }\n}\n\nexport const GetApiKeyUseCase = GetApiKeyUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["GetApiKeyUseCaseImpl","repository","identityContext","id","hasPermission","Result","ApiKeyNotAuthorizedError","result","apiKey","hideTokenUnlessFullAccess","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;;AAQA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAAsE;QAC1F,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACJ;QACzC,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAM,CAACC,OAAO,GAAG,MAAMC,0BAA0B,IAAI,CAAC,eAAe,EAAE;YAACF,OAAO,KAAK;SAAC;QACrF,OAAOF,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAME,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBX;IAChB,cAAc;QAACY;QAAmBC;KAAgB;AACtD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ReadableApiKey } from "../shared/types.js";
|
|
3
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
4
|
import type { ApiKeyNotAuthorizedError } from "../../../../features/security/apiKeys/shared/errors.js";
|
|
5
5
|
export interface IGetApiKeyErrors {
|
|
@@ -7,9 +7,9 @@ export interface IGetApiKeyErrors {
|
|
|
7
7
|
}
|
|
8
8
|
type GetApiKeyError = IGetApiKeyErrors[keyof IGetApiKeyErrors] | ApiKeysRepository.Error;
|
|
9
9
|
export interface IGetApiKey {
|
|
10
|
-
execute(id: string): Promise<Result<
|
|
10
|
+
execute(id: string): Promise<Result<ReadableApiKey | null, GetApiKeyError>>;
|
|
11
11
|
}
|
|
12
|
-
/** Retrieve an API key by ID. */
|
|
12
|
+
/** Retrieve an API key by ID. The `token` is only returned to full access. */
|
|
13
13
|
export declare const GetApiKeyUseCase: import("@webiny/di").Abstraction<IGetApiKey>;
|
|
14
14
|
export declare namespace GetApiKeyUseCase {
|
|
15
15
|
type Interface = IGetApiKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKey/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKey/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ReadableApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport type { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\n\nexport interface IGetApiKeyErrors {\n notAuthorized: ApiKeyNotAuthorizedError;\n}\n\ntype GetApiKeyError = IGetApiKeyErrors[keyof IGetApiKeyErrors] | ApiKeysRepository.Error;\n\nexport interface IGetApiKey {\n execute(id: string): Promise<Result<ReadableApiKey | null, GetApiKeyError>>;\n}\n\n/** Retrieve an API key by ID. The `token` is only returned to full access. */\nexport const GetApiKeyUseCase = createAbstraction<IGetApiKey>(\"GetApiKeyUseCase\");\n\nexport namespace GetApiKeyUseCase {\n export type Interface = IGetApiKey;\n export type Error = GetApiKeyError;\n}\n"],"names":["GetApiKeyUseCase","createAbstraction"],"mappings":";AAiBO,MAAMA,mBAAmBC,kBAA8B"}
|
|
@@ -2,12 +2,12 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { ListApiKeysUseCase as ListApiKeysUseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ListApiKeysInput, ReadableApiKey } from "../shared/types.js";
|
|
6
6
|
declare class ListApiKeysUseCaseImpl implements ListApiKeysUseCaseAbstraction.Interface {
|
|
7
7
|
private repository;
|
|
8
8
|
private identityContext;
|
|
9
9
|
constructor(repository: ApiKeysRepository.Interface, identityContext: IdentityContext.Interface);
|
|
10
|
-
execute(params?: ListApiKeysInput): Promise<Result<
|
|
10
|
+
execute(params?: ListApiKeysInput): Promise<Result<ReadableApiKey[], ListApiKeysUseCaseAbstraction.Error>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const ListApiKeysUseCase: typeof ListApiKeysUseCaseImpl & {
|
|
13
13
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListApiKeys>;
|
|
@@ -4,6 +4,7 @@ import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
5
|
import { listApiKeysInputSchema } from "../shared/schemas.js";
|
|
6
6
|
import { ApiKeyNotAuthorizedError, ApiKeyValidationError } from "../shared/errors.js";
|
|
7
|
+
import { hideTokenUnlessFullAccess } from "../shared/hideToken.js";
|
|
7
8
|
class ListApiKeysUseCaseImpl {
|
|
8
9
|
constructor(repository, identityContext){
|
|
9
10
|
this.repository = repository;
|
|
@@ -14,7 +15,9 @@ class ListApiKeysUseCaseImpl {
|
|
|
14
15
|
if (!hasPermission) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
15
16
|
const validation = listApiKeysInputSchema.safeParse(params);
|
|
16
17
|
if (!validation.success) return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));
|
|
17
|
-
|
|
18
|
+
const result = await this.repository.list(validation.data);
|
|
19
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
20
|
+
return Result.ok(await hideTokenUnlessFullAccess(this.identityContext, result.value));
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
const ListApiKeysUseCase_ListApiKeysUseCase = ListApiKeysUseCase.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js","sources":["../../../../../src/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListApiKeysUseCase as ListApiKeysUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { listApiKeysInputSchema } from \"../shared/schemas.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js","sources":["../../../../../src/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListApiKeysUseCase as ListApiKeysUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { listApiKeysInputSchema } from \"../shared/schemas.js\";\nimport type { ListApiKeysInput, ReadableApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError, ApiKeyValidationError } from \"../shared/errors.js\";\nimport { hideTokenUnlessFullAccess } from \"../shared/hideToken.js\";\n\nclass ListApiKeysUseCaseImpl implements ListApiKeysUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(\n params: ListApiKeysInput = {}\n ): Promise<Result<ReadableApiKey[], ListApiKeysUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = listApiKeysInputSchema.safeParse(params);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const result = await this.repository.list(validation.data);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(await hideTokenUnlessFullAccess(this.identityContext, result.value));\n }\n}\n\nexport const ListApiKeysUseCase = ListApiKeysUseCaseAbstraction.createImplementation({\n implementation: ListApiKeysUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["ListApiKeysUseCaseImpl","repository","identityContext","params","hasPermission","Result","ApiKeyNotAuthorizedError","validation","listApiKeysInputSchema","ApiKeyValidationError","result","hideTokenUnlessFullAccess","ListApiKeysUseCase","ListApiKeysUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;;;AASA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QACFC,SAA2B,CAAC,CAAC,EACyC;QACtE,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,uBAAuB,SAAS,CAACL;QACpD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,sBAAsBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGnF,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAACH,WAAW,IAAI;QACzD,IAAIG,OAAO,MAAM,IACb,OAAOL,OAAO,IAAI,CAACK,OAAO,KAAK;QAGnC,OAAOL,OAAO,EAAE,CAAC,MAAMM,0BAA0B,IAAI,CAAC,eAAe,EAAED,OAAO,KAAK;IACvF;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAAkD,CAAC;IACjF,gBAAgBb;IAChB,cAAc;QAACc;QAAmBC;KAAgB;AACtD"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type { ListApiKeysInput } from "../shared/types.js";
|
|
3
|
-
import type { ApiKey } from "../../../../types/security.js";
|
|
2
|
+
import type { ListApiKeysInput, ReadableApiKey } from "../shared/types.js";
|
|
4
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
5
4
|
import { ApiKeyNotAuthorizedError, ApiKeyValidationError } from "../shared/errors.js";
|
|
6
5
|
export interface IListApiKeysErrors {
|
|
@@ -9,9 +8,9 @@ export interface IListApiKeysErrors {
|
|
|
9
8
|
}
|
|
10
9
|
type ListApiKeysError = IListApiKeysErrors[keyof IListApiKeysErrors] | ApiKeysRepository.Error;
|
|
11
10
|
export interface IListApiKeys {
|
|
12
|
-
execute(params?: ListApiKeysInput): Promise<Result<
|
|
11
|
+
execute(params?: ListApiKeysInput): Promise<Result<ReadableApiKey[], ListApiKeysError>>;
|
|
13
12
|
}
|
|
14
|
-
/** List all API keys. */
|
|
13
|
+
/** List all API keys. The `token` is only returned to full access. */
|
|
15
14
|
export declare const ListApiKeysUseCase: import("@webiny/di").Abstraction<IListApiKeys>;
|
|
16
15
|
export declare namespace ListApiKeysUseCase {
|
|
17
16
|
type Interface = IListApiKeys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/ListApiKeys/abstractions.js","sources":["../../../../../src/features/security/apiKeys/ListApiKeys/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ListApiKeysInput } from \"../shared/types.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/ListApiKeys/abstractions.js","sources":["../../../../../src/features/security/apiKeys/ListApiKeys/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ListApiKeysInput, ReadableApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { ApiKeyNotAuthorizedError, ApiKeyValidationError } from \"../shared/errors.js\";\n\nexport interface IListApiKeysErrors {\n notAuthorized: ApiKeyNotAuthorizedError;\n validation: ApiKeyValidationError;\n}\n\ntype ListApiKeysError = IListApiKeysErrors[keyof IListApiKeysErrors] | ApiKeysRepository.Error;\n\nexport interface IListApiKeys {\n execute(params?: ListApiKeysInput): Promise<Result<ReadableApiKey[], ListApiKeysError>>;\n}\n\n/** List all API keys. The `token` is only returned to full access. */\nexport const ListApiKeysUseCase = createAbstraction<IListApiKeys>(\"ListApiKeysUseCase\");\n\nexport namespace ListApiKeysUseCase {\n export type Interface = IListApiKeys;\n export type Error = ListApiKeysError;\n}\n"],"names":["ListApiKeysUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,qBAAqBC,kBAAgC"}
|
|
@@ -2,6 +2,7 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { UpdateApiKeyUseCase } from "./abstractions.js";
|
|
3
3
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
|
+
import { hasFullAccessOrNoAuthorization } from "../../utils/canGrantPermissions.js";
|
|
5
6
|
import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
6
7
|
import { updateApiKeyInputSchema } from "../shared/schemas.js";
|
|
7
8
|
import { ApiKeyAfterUpdateEvent, ApiKeyBeforeUpdateEvent } from "./events.js";
|
|
@@ -15,6 +16,7 @@ class UpdateApiKeyUseCaseImpl {
|
|
|
15
16
|
async execute(id, input) {
|
|
16
17
|
const hasPermission = await this.identityContext.getPermission("security.apiKey");
|
|
17
18
|
if (!hasPermission) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
19
|
+
if (!await hasFullAccessOrNoAuthorization(this.identityContext)) return Result.fail(new ApiKeyNotAuthorizedError());
|
|
18
20
|
const validation = updateApiKeyInputSchema.safeParse(input);
|
|
19
21
|
if (!validation.success) return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));
|
|
20
22
|
const existingResult = await this.repository.get(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateApiKeyUseCase as UpdateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeUpdateEvent, ApiKeyAfterUpdateEvent } from \"./events.js\";\nimport type { ApiKey, UpdateApiKeyInput } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError, ApiKeyValidationError } from \"../shared/errors.js\";\n\nclass UpdateApiKeyUseCaseImpl implements UpdateApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(\n id: string,\n input: UpdateApiKeyInput\n ): Promise<Result<ApiKey, UpdateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = updateApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get(id);\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingApiKey = existingResult.value;\n\n const updatedApiKey: ApiKey = {\n ...existingApiKey,\n ...validation.data\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeUpdateEvent({\n original: existingApiKey,\n updated: updatedApiKey,\n input: validation.data\n })\n );\n\n const result = await this.repository.update(updatedApiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterUpdateEvent({\n original: existingApiKey,\n updated: updatedApiKey,\n input: validation.data\n })\n );\n\n return Result.ok(updatedApiKey);\n }\n}\n\nexport const UpdateApiKeyUseCase = UpdateApiKeyUseCaseAbstraction.createImplementation({\n implementation: UpdateApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateApiKeyUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","ApiKeyNotAuthorizedError","validation","updateApiKeyInputSchema","ApiKeyValidationError","existingResult","existingApiKey","updatedApiKey","ApiKeyBeforeUpdateEvent","result","ApiKeyAfterUpdateEvent","UpdateApiKeyUseCase","UpdateApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext","EventPublisher"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateApiKeyUseCase as UpdateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { hasFullAccessOrNoAuthorization } from \"../../utils/canGrantPermissions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeUpdateEvent, ApiKeyAfterUpdateEvent } from \"./events.js\";\nimport type { ApiKey, UpdateApiKeyInput } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError, ApiKeyValidationError } from \"../shared/errors.js\";\n\nclass UpdateApiKeyUseCaseImpl implements UpdateApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(\n id: string,\n input: UpdateApiKeyInput\n ): Promise<Result<ApiKey, UpdateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n // Security: an API key can carry any permission, so only full access may write one.\n if (!(await hasFullAccessOrNoAuthorization(this.identityContext))) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = updateApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get(id);\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingApiKey = existingResult.value;\n\n const updatedApiKey: ApiKey = {\n ...existingApiKey,\n ...validation.data\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeUpdateEvent({\n original: existingApiKey,\n updated: updatedApiKey,\n input: validation.data\n })\n );\n\n const result = await this.repository.update(updatedApiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterUpdateEvent({\n original: existingApiKey,\n updated: updatedApiKey,\n input: validation.data\n })\n );\n\n return Result.ok(updatedApiKey);\n }\n}\n\nexport const UpdateApiKeyUseCase = UpdateApiKeyUseCaseAbstraction.createImplementation({\n implementation: UpdateApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateApiKeyUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","ApiKeyNotAuthorizedError","hasFullAccessOrNoAuthorization","validation","updateApiKeyInputSchema","ApiKeyValidationError","existingResult","existingApiKey","updatedApiKey","ApiKeyBeforeUpdateEvent","result","ApiKeyAfterUpdateEvent","UpdateApiKeyUseCase","UpdateApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;;AAWA,MAAMA;IAKF,YACIC,UAAuC,EACvCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QACFC,EAAU,EACVC,KAAwB,EACqC;QAC7D,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,IAAI,CAAE,MAAMC,+BAA+B,IAAI,CAAC,eAAe,GAC3D,OAAOF,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAME,aAAaC,wBAAwB,SAAS,CAACN;QACrD,IAAI,CAACK,WAAW,OAAO,EACnB,OAAOH,OAAO,IAAI,CAAC,IAAIK,sBAAsBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGnF,MAAMG,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACT;QACjD,IAAIS,eAAe,MAAM,IACrB,OAAON,OAAO,IAAI,CAACM,eAAe,KAAK;QAG3C,MAAMC,iBAAiBD,eAAe,KAAK;QAE3C,MAAME,gBAAwB;YAC1B,GAAGD,cAAc;YACjB,GAAGJ,WAAW,IAAI;QACtB;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIM,wBAAwB;YACxB,UAAUF;YACV,SAASC;YACT,OAAOL,WAAW,IAAI;QAC1B;QAGJ,MAAMO,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOV,OAAO,IAAI,CAACU,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YACvB,UAAUJ;YACV,SAASC;YACT,OAAOL,WAAW,IAAI;QAC1B;QAGJ,OAAOH,OAAO,EAAE,CAACQ;IACrB;AACJ;AAEO,MAAMI,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBpB;IAChB,cAAc;QAACqB;QAAmBC;QAAiBC;KAAe;AACtE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IdentityContext } from "../../../../features/security/IdentityContext/abstractions.js";
|
|
2
|
+
import type { ApiKey, ReadableApiKey } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Security: an API key's token grants all of the key's permissions (possibly full access), so it
|
|
5
|
+
* is only returned to full access (or code running without authorization). Everyone else who may
|
|
6
|
+
* read API keys gets them without the token. Returns copies, the given keys are not modified.
|
|
7
|
+
*/
|
|
8
|
+
export declare const hideTokenUnlessFullAccess: (identityContext: IdentityContext.Interface, apiKeys: ApiKey[]) => Promise<ReadableApiKey[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { hasFullAccessOrNoAuthorization } from "../../utils/canGrantPermissions.js";
|
|
2
|
+
const hideTokenUnlessFullAccess = async (identityContext, apiKeys)=>{
|
|
3
|
+
if (await hasFullAccessOrNoAuthorization(identityContext)) return apiKeys;
|
|
4
|
+
return apiKeys.map((apiKey)=>({
|
|
5
|
+
...apiKey,
|
|
6
|
+
token: null
|
|
7
|
+
}));
|
|
8
|
+
};
|
|
9
|
+
export { hideTokenUnlessFullAccess };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=hideToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/shared/hideToken.js","sources":["../../../../../src/features/security/apiKeys/shared/hideToken.ts"],"sourcesContent":["import type { IdentityContext } from \"~/features/security/IdentityContext/abstractions.js\";\nimport { hasFullAccessOrNoAuthorization } from \"~/features/security/utils/canGrantPermissions.js\";\nimport type { ApiKey, ReadableApiKey } from \"./types.js\";\n\n/**\n * Security: an API key's token grants all of the key's permissions (possibly full access), so it\n * is only returned to full access (or code running without authorization). Everyone else who may\n * read API keys gets them without the token. Returns copies, the given keys are not modified.\n */\nexport const hideTokenUnlessFullAccess = async (\n identityContext: IdentityContext.Interface,\n apiKeys: ApiKey[]\n): Promise<ReadableApiKey[]> => {\n if (await hasFullAccessOrNoAuthorization(identityContext)) {\n return apiKeys;\n }\n return apiKeys.map(apiKey => ({ ...apiKey, token: null }));\n};\n"],"names":["hideTokenUnlessFullAccess","identityContext","apiKeys","hasFullAccessOrNoAuthorization","apiKey"],"mappings":";AASO,MAAMA,4BAA4B,OACrCC,iBACAC;IAEA,IAAI,MAAMC,+BAA+BF,kBACrC,OAAOC;IAEX,OAAOA,QAAQ,GAAG,CAACE,CAAAA,SAAW;YAAE,GAAGA,MAAM;YAAE,OAAO;QAAK;AAC3D"}
|
|
@@ -9,6 +9,13 @@ export interface ApiKey {
|
|
|
9
9
|
createdBy: CreatedBy;
|
|
10
10
|
createdOn: string;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* An API key as returned by reading use cases (list, get). The `token` is null unless the caller
|
|
14
|
+
* has full access (or runs without authorization), as the token grants the key's permissions.
|
|
15
|
+
*/
|
|
16
|
+
export type ReadableApiKey = Omit<ApiKey, "token"> & {
|
|
17
|
+
token: ApiKey["token"] | null;
|
|
18
|
+
};
|
|
12
19
|
export interface CreateApiKeyInput {
|
|
13
20
|
name: string;
|
|
14
21
|
slug: string;
|
|
@@ -4,6 +4,7 @@ import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
|
4
4
|
import { CreateRoleUseCase } from "./abstractions.js";
|
|
5
5
|
import { RolesRepository } from "../shared/abstractions.js";
|
|
6
6
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
7
|
+
import { CANNOT_GRANT_PERMISSIONS_MESSAGE, canGrantPermissions } from "../../utils/canGrantPermissions.js";
|
|
7
8
|
import { createRoleValidation } from "./schema.js";
|
|
8
9
|
import { RoleAfterCreateEvent, RoleBeforeCreateEvent } from "./events.js";
|
|
9
10
|
import { NotAuthorizedError, RoleExistsError, RoleValidationError } from "../shared/errors.js";
|
|
@@ -20,6 +21,11 @@ class CreateRoleUseCaseImpl {
|
|
|
20
21
|
if (!validation.success) return Result.fail(new RoleValidationError(validation.error.issues[0].message));
|
|
21
22
|
const identity = this.identityContext.getIdentity();
|
|
22
23
|
const data = validation.data;
|
|
24
|
+
if (!await canGrantPermissions(this.identityContext, [
|
|
25
|
+
data.permissions
|
|
26
|
+
])) return Result.fail(new NotAuthorizedError({
|
|
27
|
+
message: CANNOT_GRANT_PERMISSIONS_MESSAGE
|
|
28
|
+
}));
|
|
23
29
|
const existingRoleResult = await this.repository.get({
|
|
24
30
|
slug: data.slug
|
|
25
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/CreateRole/CreateRoleUseCase.js","sources":["../../../../../src/features/security/roles/CreateRole/CreateRoleUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createRoleValidation } from \"./schema.js\";\nimport { RoleBeforeCreateEvent, RoleAfterCreateEvent } from \"./events.js\";\nimport type { Role, CreateRoleInput } from \"../shared/types.js\";\nimport { NotAuthorizedError, RoleExistsError, RoleValidationError } from \"../shared/errors.js\";\n\nclass CreateRoleUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: RolesRepository.Interface\n ) {}\n\n async execute(input: CreateRoleInput): Promise<Result<Role, UseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = createRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n // Check if role with same slug already exists\n const existingRoleResult = await this.repository.get({ slug: data.slug });\n if (existingRoleResult.isOk()) {\n return Result.fail(new RoleExistsError(data.slug));\n }\n\n const role: Role = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n permissions: data.permissions,\n system: input.system || false,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n plugin: false\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeCreateEvent({ role, input: validation.data })\n );\n\n const result = await this.repository.create(role);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterCreateEvent({ role, input: validation.data })\n );\n\n return Result.ok(role);\n }\n}\n\nexport const CreateRoleUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateRoleUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, RolesRepository]\n});\n"],"names":["CreateRoleUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","NotAuthorizedError","validation","createRoleValidation","RoleValidationError","identity","data","existingRoleResult","RoleExistsError","role","mdbid","Date","RoleBeforeCreateEvent","result","RoleAfterCreateEvent","CreateRoleUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","RolesRepository"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/security/roles/CreateRole/CreateRoleUseCase.js","sources":["../../../../../src/features/security/roles/CreateRole/CreateRoleUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport {\n canGrantPermissions,\n CANNOT_GRANT_PERMISSIONS_MESSAGE\n} from \"../../utils/canGrantPermissions.js\";\nimport { createRoleValidation } from \"./schema.js\";\nimport { RoleBeforeCreateEvent, RoleAfterCreateEvent } from \"./events.js\";\nimport type { Role, CreateRoleInput } from \"../shared/types.js\";\nimport { NotAuthorizedError, RoleExistsError, RoleValidationError } from \"../shared/errors.js\";\n\nclass CreateRoleUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: RolesRepository.Interface\n ) {}\n\n async execute(input: CreateRoleInput): Promise<Result<Role, UseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = createRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n // Security: a role may only carry permissions the caller holds.\n if (!(await canGrantPermissions(this.identityContext, [data.permissions]))) {\n return Result.fail(\n new NotAuthorizedError({ message: CANNOT_GRANT_PERMISSIONS_MESSAGE })\n );\n }\n\n // Check if role with same slug already exists\n const existingRoleResult = await this.repository.get({ slug: data.slug });\n if (existingRoleResult.isOk()) {\n return Result.fail(new RoleExistsError(data.slug));\n }\n\n const role: Role = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n permissions: data.permissions,\n system: input.system || false,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n plugin: false\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeCreateEvent({ role, input: validation.data })\n );\n\n const result = await this.repository.create(role);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterCreateEvent({ role, input: validation.data })\n );\n\n return Result.ok(role);\n }\n}\n\nexport const CreateRoleUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateRoleUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, RolesRepository]\n});\n"],"names":["CreateRoleUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","NotAuthorizedError","validation","createRoleValidation","RoleValidationError","identity","data","canGrantPermissions","CANNOT_GRANT_PERMISSIONS_MESSAGE","existingRoleResult","RoleExistsError","role","mdbid","Date","RoleBeforeCreateEvent","result","RoleAfterCreateEvent","CreateRoleUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","RolesRepository"],"mappings":";;;;;;;;;;AAgBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAqC,CAC/C;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAmD;QACnF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAE/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,OAAOJ,WAAW,IAAI;QAG5B,IAAI,CAAE,MAAMK,oBAAoB,IAAI,CAAC,eAAe,EAAE;YAACD,KAAK,WAAW;SAAC,GACpE,OAAON,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAASO;QAAiC;QAK3E,MAAMC,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,MAAMH,KAAK,IAAI;QAAC;QACvE,IAAIG,mBAAmB,IAAI,IACvB,OAAOT,OAAO,IAAI,CAAC,IAAIU,gBAAgBJ,KAAK,IAAI;QAGpD,MAAMK,OAAa;YACf,IAAIC;YACJ,MAAMN,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAC7B,aAAaA,KAAK,WAAW;YAC7B,QAAQR,MAAM,MAAM,IAAI;YACxB,WAAW,IAAIe,OAAO,WAAW;YACjC,WAAW;gBACP,IAAIR,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;YACA,QAAQ;QACZ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIS,sBAAsB;YAAEH;YAAM,OAAOT,WAAW,IAAI;QAAC;QAG7D,MAAMa,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOf,OAAO,IAAI,CAACe,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YAAEL;YAAM,OAAOT,WAAW,IAAI;QAAC;QAG5D,OAAOF,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAMM,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBzB;IAChB,cAAc;QAAC0B;QAAiBC;QAAgBC;KAAgB;AACpE"}
|
|
@@ -4,7 +4,7 @@ import { RolesRepository } from "../shared/abstractions.js";
|
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
5
|
import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
6
6
|
import { RoleAfterDeleteEvent, RoleBeforeDeleteEvent } from "./events.js";
|
|
7
|
-
import { CannotDeletePluginRolesError, NotAuthorizedError } from "../shared/errors.js";
|
|
7
|
+
import { CannotDeletePluginRolesError, CannotDeleteSystemRolesError, NotAuthorizedError } from "../shared/errors.js";
|
|
8
8
|
class DeleteRoleUseCaseImpl {
|
|
9
9
|
constructor(repository, identityContext, eventPublisher){
|
|
10
10
|
this.repository = repository;
|
|
@@ -20,6 +20,7 @@ class DeleteRoleUseCaseImpl {
|
|
|
20
20
|
if (existingResult.isFail()) return Result.fail(existingResult.error);
|
|
21
21
|
const existingRole = existingResult.value;
|
|
22
22
|
if (existingRole.plugin) return Result.fail(new CannotDeletePluginRolesError());
|
|
23
|
+
if (existingRole.system && this.identityContext.isAuthorizationEnabled()) return Result.fail(new CannotDeleteSystemRolesError());
|
|
23
24
|
await this.eventPublisher.publish(new RoleBeforeDeleteEvent({
|
|
24
25
|
role: existingRole
|
|
25
26
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/DeleteRole/DeleteRoleUseCase.js","sources":["../../../../../src/features/security/roles/DeleteRole/DeleteRoleUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { DeleteRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { RoleBeforeDeleteEvent, RoleAfterDeleteEvent } from \"./events.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/security/roles/DeleteRole/DeleteRoleUseCase.js","sources":["../../../../../src/features/security/roles/DeleteRole/DeleteRoleUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { DeleteRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { RoleBeforeDeleteEvent, RoleAfterDeleteEvent } from \"./events.js\";\nimport {\n NotAuthorizedError,\n CannotDeletePluginRolesError,\n CannotDeleteSystemRolesError\n} from \"../shared/errors.js\";\n\nclass DeleteRoleUseCaseImpl implements UseCaseAbstraction.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotDeletePluginRolesError());\n }\n\n // Security: system roles (e.g. \"Full Access\") are managed by the system only. Installers\n // run without authorization, so they can still roll back the roles they created.\n if (existingRole.system && this.identityContext.isAuthorizationEnabled()) {\n return Result.fail(new CannotDeleteSystemRolesError());\n }\n\n await this.eventPublisher.publish(new RoleBeforeDeleteEvent({ role: existingRole }));\n\n const result = await this.repository.delete(existingRole);\n\n if (result.isFail()) {\n return result;\n }\n\n await this.eventPublisher.publish(new RoleAfterDeleteEvent({ role: existingRole }));\n\n return Result.ok();\n }\n}\n\nexport const DeleteRoleUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["DeleteRoleUseCaseImpl","repository","identityContext","eventPublisher","id","hasPermission","Result","NotAuthorizedError","existingResult","existingRole","CannotDeletePluginRolesError","CannotDeleteSystemRolesError","RoleBeforeDeleteEvent","result","RoleAfterDeleteEvent","DeleteRoleUseCase","createImplementation","UseCaseAbstraction","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;AAaA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAEJ;QAAG;QACtD,IAAII,eAAe,MAAM,IACrB,OAAOF,OAAO,IAAI,CAACE,eAAe,KAAK;QAG3C,MAAMC,eAAeD,eAAe,KAAK;QAGzC,IAAIC,aAAa,MAAM,EACnB,OAAOH,OAAO,IAAI,CAAC,IAAII;QAK3B,IAAID,aAAa,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,sBAAsB,IAClE,OAAOH,OAAO,IAAI,CAAC,IAAIK;QAG3B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,sBAAsB;YAAE,MAAMH;QAAa;QAEjF,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOA;QAGX,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAE,MAAML;QAAa;QAEhF,OAAOH,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMS,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBjB;IAChB,cAAc;QAACkB;QAAiBC;QAAiBC;KAAe;AACpE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { Role } from "../shared/types.js";
|
|
3
3
|
import { RolesRepository } from "../shared/abstractions.js";
|
|
4
|
-
import { NotAuthorizedError, CannotDeletePluginRolesError } from "../shared/errors.js";
|
|
4
|
+
import { NotAuthorizedError, CannotDeletePluginRolesError, CannotDeleteSystemRolesError } from "../shared/errors.js";
|
|
5
5
|
export interface IDeleteRoleErrors {
|
|
6
6
|
notAuthorized: NotAuthorizedError;
|
|
7
7
|
cannotDeletePlugin: CannotDeletePluginRolesError;
|
|
8
|
+
cannotDeleteSystem: CannotDeleteSystemRolesError;
|
|
8
9
|
}
|
|
9
10
|
type DeleteRoleError = IDeleteRoleErrors[keyof IDeleteRoleErrors] | RolesRepository.Error;
|
|
10
11
|
export interface IDeleteRole {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/DeleteRole/abstractions.js","sources":["../../../../../src/features/security/roles/DeleteRole/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { Role } from \"../shared/types.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/security/roles/DeleteRole/abstractions.js","sources":["../../../../../src/features/security/roles/DeleteRole/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { Role } from \"../shared/types.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n CannotDeletePluginRolesError,\n CannotDeleteSystemRolesError\n} from \"../shared/errors.js\";\n\nexport interface IDeleteRoleErrors {\n notAuthorized: NotAuthorizedError;\n cannotDeletePlugin: CannotDeletePluginRolesError;\n cannotDeleteSystem: CannotDeleteSystemRolesError;\n}\n\ntype DeleteRoleError = IDeleteRoleErrors[keyof IDeleteRoleErrors] | RolesRepository.Error;\n\nexport interface IDeleteRole {\n execute(id: string): Promise<Result<void, DeleteRoleError>>;\n}\n\n/** Delete a security role. */\nexport const DeleteRoleUseCase = createAbstraction<IDeleteRole>(\"DeleteRoleUseCase\");\n\nexport namespace DeleteRoleUseCase {\n export type Interface = IDeleteRole;\n export type Error = DeleteRoleError;\n}\n\nexport interface RoleBeforeDeletePayload {\n role: Role;\n}\n\nexport interface RoleAfterDeletePayload {\n role: Role;\n}\n"],"names":["DeleteRoleUseCase","createAbstraction"],"mappings":";AAuBO,MAAMA,oBAAoBC,kBAA+B"}
|
|
@@ -2,10 +2,11 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { UpdateRoleUseCase } from "./abstractions.js";
|
|
3
3
|
import { RolesRepository } from "../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
5
|
+
import { CANNOT_GRANT_PERMISSIONS_MESSAGE, canGrantPermissions } from "../../utils/canGrantPermissions.js";
|
|
5
6
|
import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
6
7
|
import { updateRoleValidation } from "./schema.js";
|
|
7
8
|
import { RoleAfterUpdateEvent, RoleBeforeUpdateEvent } from "./events.js";
|
|
8
|
-
import { CannotUpdatePluginRolesError, NotAuthorizedError, RoleValidationError } from "../shared/errors.js";
|
|
9
|
+
import { CannotUpdatePluginRolesError, CannotUpdateSystemRolesError, NotAuthorizedError, RoleValidationError } from "../shared/errors.js";
|
|
9
10
|
class UpdateRoleUseCaseImpl {
|
|
10
11
|
constructor(repository, identityContext, eventPublisher){
|
|
11
12
|
this.repository = repository;
|
|
@@ -23,6 +24,14 @@ class UpdateRoleUseCaseImpl {
|
|
|
23
24
|
if (existingResult.isFail()) return Result.fail(existingResult.error);
|
|
24
25
|
const existingRole = existingResult.value;
|
|
25
26
|
if (existingRole.plugin) return Result.fail(new CannotUpdatePluginRolesError());
|
|
27
|
+
if (existingRole.system && this.identityContext.isAuthorizationEnabled()) return Result.fail(new CannotUpdateSystemRolesError());
|
|
28
|
+
const permissionsToCheck = [
|
|
29
|
+
existingRole.permissions
|
|
30
|
+
];
|
|
31
|
+
if (validation.data.permissions) permissionsToCheck.push(validation.data.permissions);
|
|
32
|
+
if (!await canGrantPermissions(this.identityContext, permissionsToCheck)) return Result.fail(new NotAuthorizedError({
|
|
33
|
+
message: CANNOT_GRANT_PERMISSIONS_MESSAGE
|
|
34
|
+
}));
|
|
26
35
|
const updatedRole = {
|
|
27
36
|
...existingRole,
|
|
28
37
|
...validation.data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n const updatedRole: Role = {\n ...existingRole,\n ...validation.data\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport {\n canGrantPermissions,\n CANNOT_GRANT_PERMISSIONS_MESSAGE\n} from \"../../utils/canGrantPermissions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n CannotUpdateSystemRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n // Security: system roles (e.g. \"Full Access\") are managed by the system only.\n if (existingRole.system && this.identityContext.isAuthorizationEnabled()) {\n return Result.fail(new CannotUpdateSystemRolesError());\n }\n\n // Security: a role may only carry permissions the caller holds. The role's current\n // permissions are checked too, so a role the caller can't grant can't be renamed or\n // trimmed into something else either.\n const permissionsToCheck = [existingRole.permissions];\n if (validation.data.permissions) {\n permissionsToCheck.push(validation.data.permissions);\n }\n if (!(await canGrantPermissions(this.identityContext, permissionsToCheck))) {\n return Result.fail(\n new NotAuthorizedError({ message: CANNOT_GRANT_PERMISSIONS_MESSAGE })\n );\n }\n\n const updatedRole: Role = {\n ...existingRole,\n ...validation.data\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","CannotUpdateSystemRolesError","permissionsToCheck","canGrantPermissions","CANNOT_GRANT_PERMISSIONS_MESSAGE","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;;AAmBA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAEC,KAAsB,EAAwC;QACpF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAER;QAAG;QACtD,IAAIQ,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,eAAeD,eAAe,KAAK;QAGzC,IAAIC,aAAa,MAAM,EACnB,OAAON,OAAO,IAAI,CAAC,IAAIO;QAI3B,IAAID,aAAa,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,sBAAsB,IAClE,OAAON,OAAO,IAAI,CAAC,IAAIQ;QAM3B,MAAMC,qBAAqB;YAACH,aAAa,WAAW;SAAC;QACrD,IAAIJ,WAAW,IAAI,CAAC,WAAW,EAC3BO,mBAAmB,IAAI,CAACP,WAAW,IAAI,CAAC,WAAW;QAEvD,IAAI,CAAE,MAAMQ,oBAAoB,IAAI,CAAC,eAAe,EAAED,qBAClD,OAAOT,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAASU;QAAiC;QAI3E,MAAMC,cAAoB;YACtB,GAAGN,YAAY;YACf,GAAGJ,WAAW,IAAI;QACtB;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIW,sBAAsB;YACtB,UAAUP;YACV,SAASM;YACT,OAAOV,WAAW,IAAI;QAC1B;QAGJ,MAAMY,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOd,OAAO,IAAI,CAACc,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YACrB,UAAUT;YACV,SAASM;YACT,OAAOV,WAAW,IAAI;QAC1B;QAGJ,OAAOF,OAAO,EAAE,CAACY;IACrB;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAA4B,CAAC;IAC1D,gBAAgBxB;IAChB,cAAc;QAACyB;QAAiBC;QAAiBC;KAAe;AACpE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { Role, UpdateRoleInput as UpdateRoleUseCaseInput } from "../shared/types.js";
|
|
3
3
|
import { RolesRepository } from "../shared/abstractions.js";
|
|
4
|
-
import { NotAuthorizedError, CannotUpdatePluginRolesError, RoleValidationError } from "../shared/errors.js";
|
|
4
|
+
import { NotAuthorizedError, CannotUpdatePluginRolesError, CannotUpdateSystemRolesError, RoleValidationError } from "../shared/errors.js";
|
|
5
5
|
export interface IUpdateRoleUseCaseErrors {
|
|
6
6
|
notAuthorized: NotAuthorizedError;
|
|
7
7
|
cannotUpdatePlugin: CannotUpdatePluginRolesError;
|
|
8
|
+
cannotUpdateSystem: CannotUpdateSystemRolesError;
|
|
8
9
|
validation: RoleValidationError;
|
|
9
10
|
}
|
|
10
11
|
type UpdateRoleUseCaseError = IUpdateRoleUseCaseErrors[keyof IUpdateRoleUseCaseErrors] | RolesRepository.Error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/UpdateRole/abstractions.js","sources":["../../../../../src/features/security/roles/UpdateRole/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { Role, UpdateRoleInput as UpdateRoleUseCaseInput } from \"../shared/types.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nexport interface IUpdateRoleUseCaseErrors {\n notAuthorized: NotAuthorizedError;\n cannotUpdatePlugin: CannotUpdatePluginRolesError;\n validation: RoleValidationError;\n}\n\ntype UpdateRoleUseCaseError =\n | IUpdateRoleUseCaseErrors[keyof IUpdateRoleUseCaseErrors]\n | RolesRepository.Error;\n\nexport interface IUpdateRoleUseCase {\n execute(\n id: string,\n input: UpdateRoleUseCaseInput\n ): Promise<Result<Role, UpdateRoleUseCaseError>>;\n}\n\n/** Update an existing security role. */\nexport const UpdateRoleUseCase = createAbstraction<IUpdateRoleUseCase>(\"UpdateRoleUseCase\");\n\nexport namespace UpdateRoleUseCase {\n export type Interface = IUpdateRoleUseCase;\n export type Error = UpdateRoleUseCaseError;\n}\n\nexport interface RoleBeforeUpdatePayload {\n original: Role;\n updated: Role;\n input: UpdateRoleUseCaseInput;\n}\n\nexport interface RoleAfterUpdatePayload {\n original: Role;\n updated: Role;\n input: UpdateRoleUseCaseInput;\n}\n"],"names":["UpdateRoleUseCase","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/security/roles/UpdateRole/abstractions.js","sources":["../../../../../src/features/security/roles/UpdateRole/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { Role, UpdateRoleInput as UpdateRoleUseCaseInput } from \"../shared/types.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n CannotUpdateSystemRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nexport interface IUpdateRoleUseCaseErrors {\n notAuthorized: NotAuthorizedError;\n cannotUpdatePlugin: CannotUpdatePluginRolesError;\n cannotUpdateSystem: CannotUpdateSystemRolesError;\n validation: RoleValidationError;\n}\n\ntype UpdateRoleUseCaseError =\n | IUpdateRoleUseCaseErrors[keyof IUpdateRoleUseCaseErrors]\n | RolesRepository.Error;\n\nexport interface IUpdateRoleUseCase {\n execute(\n id: string,\n input: UpdateRoleUseCaseInput\n ): Promise<Result<Role, UpdateRoleUseCaseError>>;\n}\n\n/** Update an existing security role. */\nexport const UpdateRoleUseCase = createAbstraction<IUpdateRoleUseCase>(\"UpdateRoleUseCase\");\n\nexport namespace UpdateRoleUseCase {\n export type Interface = IUpdateRoleUseCase;\n export type Error = UpdateRoleUseCaseError;\n}\n\nexport interface RoleBeforeUpdatePayload {\n original: Role;\n updated: Role;\n input: UpdateRoleUseCaseInput;\n}\n\nexport interface RoleAfterUpdatePayload {\n original: Role;\n updated: Role;\n input: UpdateRoleUseCaseInput;\n}\n"],"names":["UpdateRoleUseCase","createAbstraction"],"mappings":";AA8BO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { RolesRepository } from "../abstractions.js";
|
|
3
3
|
import type { Role, GetRoleInput, ListRolesInput } from "../types.js";
|
|
4
|
+
import { TenantContext } from "../../../../../features/tenancy/TenantContext/index.js";
|
|
4
5
|
declare class RolesRepositoryCachingDecoratorImpl implements RolesRepository.Interface {
|
|
6
|
+
private tenantContext;
|
|
5
7
|
private decoratee;
|
|
6
|
-
private readonly
|
|
7
|
-
constructor(decoratee: RolesRepository.Interface);
|
|
8
|
+
private readonly caches;
|
|
9
|
+
constructor(tenantContext: TenantContext.Interface, decoratee: RolesRepository.Interface);
|
|
10
|
+
private get cache();
|
|
8
11
|
get(params: GetRoleInput): Promise<Result<Role, RolesRepository.Error>>;
|
|
9
12
|
list(params: ListRolesInput): Promise<Result<Role[], RolesRepository.Error>>;
|
|
10
13
|
create(role: Role): Promise<Result<void, RolesRepository.Error>>;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { RolesRepository } from "../abstractions.js";
|
|
3
3
|
import { ListCache } from "./ListCache.js";
|
|
4
|
+
import { TenantContext } from "../../../../tenancy/TenantContext/index.js";
|
|
4
5
|
class RolesRepositoryCachingDecoratorImpl {
|
|
5
|
-
constructor(decoratee){
|
|
6
|
+
constructor(tenantContext, decoratee){
|
|
7
|
+
this.tenantContext = tenantContext;
|
|
6
8
|
this.decoratee = decoratee;
|
|
7
|
-
this.
|
|
9
|
+
this.caches = new Map();
|
|
10
|
+
}
|
|
11
|
+
get cache() {
|
|
12
|
+
const tenantId = this.tenantContext.getTenant().id;
|
|
13
|
+
let cache = this.caches.get(tenantId);
|
|
14
|
+
if (!cache) {
|
|
15
|
+
cache = new ListCache();
|
|
16
|
+
this.caches.set(tenantId, cache);
|
|
17
|
+
}
|
|
18
|
+
return cache;
|
|
8
19
|
}
|
|
9
20
|
async get(params) {
|
|
10
21
|
if (this.cache.hasItems()) {
|
|
@@ -47,7 +58,9 @@ class RolesRepositoryCachingDecoratorImpl {
|
|
|
47
58
|
}
|
|
48
59
|
const RolesRepositoryCachingDecorator = RolesRepository.createDecorator({
|
|
49
60
|
decorator: RolesRepositoryCachingDecoratorImpl,
|
|
50
|
-
dependencies: [
|
|
61
|
+
dependencies: [
|
|
62
|
+
TenantContext
|
|
63
|
+
]
|
|
51
64
|
});
|
|
52
65
|
export { RolesRepositoryCachingDecorator };
|
|
53
66
|
|