@webiny/api-core 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.5387e5f7c8
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/ApiCoreFeature.js +8 -0
- package/ApiCoreFeature.js.map +1 -1
- package/exports/api/tasks.d.ts +1 -0
- package/exports/api/tasks.js +1 -1
- package/exports/api.d.ts +1 -1
- package/exports/api.js +1 -1
- package/features/ai/Ai.d.ts +3 -1
- package/features/ai/Ai.js +36 -28
- package/features/ai/Ai.js.map +1 -1
- package/features/ai/AiModelRegistry.d.ts +14 -0
- package/features/ai/AiModelRegistry.js +39 -0
- package/features/ai/AiModelRegistry.js.map +1 -0
- package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
- package/features/ai/AiSdkToolHandlerResolver.js +19 -0
- package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
- package/features/ai/AiSdkTools.d.ts +4 -3
- package/features/ai/AiSdkTools.js +11 -9
- package/features/ai/AiSdkTools.js.map +1 -1
- package/features/ai/AnthropicSdkFactory.js +12 -4
- package/features/ai/AnthropicSdkFactory.js.map +1 -1
- package/features/ai/DEVELOPERS.md +183 -0
- package/features/ai/GoogleSdkFactory.d.ts +10 -0
- package/features/ai/GoogleSdkFactory.js +65 -0
- package/features/ai/GoogleSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.js +51 -11
- package/features/ai/OpenAiSdkFactory.js.map +1 -1
- package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
- package/features/ai/OpenRouterSdkFactory.js +112 -0
- package/features/ai/OpenRouterSdkFactory.js.map +1 -0
- package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
- package/features/ai/RemoteAiModelCatalog.js +74 -0
- package/features/ai/RemoteAiModelCatalog.js.map +1 -0
- package/features/ai/abstractions.d.ts +102 -7
- package/features/ai/abstractions.js +6 -2
- package/features/ai/abstractions.js.map +1 -1
- package/features/ai/feature.js +10 -0
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +2 -4
- package/features/ai/index.js +1 -1
- package/features/dateFormatter/DefaultDateFormatter.d.ts +15 -0
- package/features/dateFormatter/DefaultDateFormatter.js +20 -0
- package/features/dateFormatter/DefaultDateFormatter.js.map +1 -0
- package/features/dateFormatter/abstractions.d.ts +13 -0
- package/features/dateFormatter/abstractions.js +5 -0
- package/features/dateFormatter/abstractions.js.map +1 -0
- package/features/dateFormatter/feature.d.ts +4 -0
- package/features/dateFormatter/feature.js +11 -0
- package/features/dateFormatter/feature.js.map +1 -0
- package/features/dateFormatter/index.d.ts +3 -0
- package/features/dateFormatter/index.js +2 -0
- package/features/encryption/EncryptionKeyCacheFeature.d.ts +8 -0
- package/features/encryption/EncryptionKeyCacheFeature.js +11 -0
- package/features/encryption/EncryptionKeyCacheFeature.js.map +1 -0
- package/features/encryption/EncryptionService.d.ts +2 -1
- package/features/encryption/EncryptionService.js +11 -4
- package/features/encryption/EncryptionService.js.map +1 -1
- package/features/encryption/MemoryEncryptionKeyCache.d.ts +13 -0
- package/features/encryption/MemoryEncryptionKeyCache.js +26 -0
- package/features/encryption/MemoryEncryptionKeyCache.js.map +1 -0
- package/features/encryption/abstractions.d.ts +11 -0
- package/features/encryption/abstractions.js +2 -1
- package/features/encryption/abstractions.js.map +1 -1
- package/features/encryption/index.d.ts +1 -0
- package/features/encryption/index.js +1 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.d.ts +13 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +61 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -0
- package/features/httpClient/HttpClient.d.ts +7 -0
- package/features/httpClient/HttpClient.js +72 -0
- package/features/httpClient/HttpClient.js.map +1 -0
- package/features/httpClient/HttpRequestError.d.ts +10 -0
- package/features/httpClient/HttpRequestError.js +13 -0
- package/features/httpClient/HttpRequestError.js.map +1 -0
- package/features/httpClient/HttpStatusError.d.ts +12 -0
- package/features/httpClient/HttpStatusError.js +12 -0
- package/features/httpClient/HttpStatusError.js.map +1 -0
- package/features/httpClient/abstractions.d.ts +32 -0
- package/features/httpClient/abstractions.js +5 -0
- package/features/httpClient/abstractions.js.map +1 -0
- package/features/httpClient/feature.d.ts +4 -0
- package/features/httpClient/feature.js +11 -0
- package/features/httpClient/feature.js.map +1 -0
- package/features/httpClient/index.d.ts +3 -0
- package/features/httpClient/index.js +3 -0
- package/features/requestContext/RawAssumePermissions.d.ts +14 -0
- package/features/requestContext/RawAssumePermissions.js +19 -0
- package/features/requestContext/RawAssumePermissions.js.map +1 -0
- package/features/requestContext/abstractions.d.ts +22 -0
- package/features/requestContext/abstractions.js +2 -1
- package/features/requestContext/abstractions.js.map +1 -1
- package/features/requestContext/extractAssumePermissions.d.ts +14 -0
- package/features/requestContext/extractAssumePermissions.js +32 -0
- package/features/requestContext/extractAssumePermissions.js.map +1 -0
- package/features/requestContext/feature.d.ts +2 -1
- package/features/requestContext/feature.js +2 -0
- package/features/requestContext/feature.js.map +1 -1
- package/features/requestContext/index.d.ts +3 -1
- package/features/requestContext/index.js +2 -1
- package/features/security/IdentityContext/IdentityContext.d.ts +3 -3
- package/features/security/IdentityContext/IdentityContext.js +6 -6
- package/features/security/IdentityContext/IdentityContext.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +11 -6
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +9 -3
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/shared/schemas.d.ts +2 -2
- package/features/security/apiKeys/shared/schemas.js +2 -2
- package/features/security/apiKeys/shared/schemas.js.map +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.d.ts +30 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js +60 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js.map +1 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +3 -3
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js +5 -5
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js.map +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.js +2 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.js.map +1 -1
- package/features/security/roles/CreateRole/CreateRoleUseCase.js +11 -6
- package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
- package/features/security/roles/CreateRole/schema.d.ts +1 -1
- package/features/security/roles/CreateRole/schema.js +1 -1
- package/features/security/roles/CreateRole/schema.js.map +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +9 -3
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/UpdateRole/schema.d.ts +1 -1
- package/features/security/roles/UpdateRole/schema.js +1 -1
- package/features/security/roles/UpdateRole/schema.js.map +1 -1
- package/features/security/shared/description.d.ts +4 -0
- package/features/security/shared/description.js +7 -0
- package/features/security/shared/description.js.map +1 -0
- package/features/security/shared/index.d.ts +1 -0
- package/features/security/shared/index.js +1 -0
- package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js +20 -8
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
- package/features/security/teams/CreateTeam/schema.d.ts +1 -1
- package/features/security/teams/CreateTeam/schema.js +1 -1
- package/features/security/teams/CreateTeam/schema.js.map +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -5
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/teams/UpdateTeam/schema.d.ts +1 -1
- package/features/security/teams/UpdateTeam/schema.js +1 -1
- package/features/security/teams/UpdateTeam/schema.js.map +1 -1
- package/features/security/teams/shared/resolveRoleIdentifiers.d.ts +17 -0
- package/features/security/teams/shared/resolveRoleIdentifiers.js +32 -0
- package/features/security/teams/shared/resolveRoleIdentifiers.js.map +1 -0
- package/features/slugify/DefaultSlugify.d.ts +8 -0
- package/features/slugify/DefaultSlugify.js +20 -0
- package/features/slugify/DefaultSlugify.js.map +1 -0
- package/features/slugify/abstractions.d.ts +12 -0
- package/features/slugify/abstractions.js +5 -0
- package/features/slugify/abstractions.js.map +1 -0
- package/features/slugify/feature.d.ts +4 -0
- package/features/slugify/feature.js +11 -0
- package/features/slugify/feature.js.map +1 -0
- package/features/slugify/index.d.ts +3 -0
- package/features/slugify/index.js +2 -0
- package/features/stringFormatter/DefaultStringFormatter.d.ts +17 -0
- package/features/stringFormatter/DefaultStringFormatter.js +19 -0
- package/features/stringFormatter/DefaultStringFormatter.js.map +1 -0
- package/features/stringFormatter/abstractions.d.ts +11 -0
- package/features/stringFormatter/abstractions.js +5 -0
- package/features/stringFormatter/abstractions.js.map +1 -0
- package/features/stringFormatter/feature.d.ts +4 -0
- package/features/stringFormatter/feature.js +13 -0
- package/features/stringFormatter/feature.js.map +1 -0
- package/features/stringFormatter/index.d.ts +3 -0
- package/features/stringFormatter/index.js +2 -0
- package/features/task/TaskDefinition/abstractions.d.ts +69 -4
- package/features/task/TaskDefinition/abstractions.js +2 -1
- package/features/task/TaskDefinition/abstractions.js.map +1 -1
- package/features/tenancy/TenantContext/TenantContext.d.ts +1 -0
- package/features/tenancy/TenantContext/TenantContext.js +13 -8
- package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +6 -0
- package/features/wcp/WcpContext/WcpContext.js +18 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +9 -69
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +63 -35
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpFeature.js +2 -0
- package/features/wcp/WcpFeature.js.map +1 -1
- package/features/wcp/WcpLicenseLoader.d.ts +25 -0
- package/features/wcp/WcpLicenseLoader.js +58 -0
- package/features/wcp/WcpLicenseLoader.js.map +1 -0
- package/features/wcp/WcpLicenseProvider.d.ts +6 -14
- package/features/wcp/WcpLicenseProvider.js +3 -7
- package/features/wcp/WcpLicenseProvider.js.map +1 -1
- package/features/wcp/resolveWcpProjectEnvironment.d.ts +9 -0
- package/features/wcp/resolveWcpProjectEnvironment.js +23 -0
- package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -0
- package/graphql/ApiCoreSchemaFactory.d.ts +1 -0
- package/graphql/ApiCoreSchemaFactory.js +7 -1
- package/graphql/ApiCoreSchemaFactory.js.map +1 -1
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +10 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +53 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -0
- package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
- package/graphql/security/SecuritySchemaFactory.js +4 -0
- package/graphql/security/SecuritySchemaFactory.js.map +1 -1
- package/graphql/system/SystemSchemaFactory.d.ts +1 -0
- package/graphql/system/SystemSchemaFactory.js +4 -0
- package/graphql/system/SystemSchemaFactory.js.map +1 -1
- package/graphql/users/UsersSchemaFactory.d.ts +1 -0
- package/graphql/users/UsersSchemaFactory.js +4 -0
- package/graphql/users/UsersSchemaFactory.js.map +1 -1
- package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
- package/graphql/wcp/WcpSchemaFactory.js +5 -0
- package/graphql/wcp/WcpSchemaFactory.js.map +1 -1
- package/idp/JwksCache.d.ts +14 -3
- package/idp/JwksCache.js +97 -17
- package/idp/JwksCache.js.map +1 -1
- package/idp/JwksStoreFeature.d.ts +8 -0
- package/idp/JwksStoreFeature.js +11 -0
- package/idp/JwksStoreFeature.js.map +1 -0
- package/idp/MemoryJwksStore.d.ts +14 -0
- package/idp/MemoryJwksStore.js +21 -0
- package/idp/MemoryJwksStore.js.map +1 -0
- package/idp/OidcJwtIdentityProvider.js +5 -1
- package/idp/OidcJwtIdentityProvider.js.map +1 -1
- package/idp/abstractions.d.ts +24 -0
- package/idp/abstractions.js +2 -1
- package/idp/abstractions.js.map +1 -1
- package/idp/feature.js +1 -2
- package/idp/feature.js.map +1 -1
- package/idp/index.d.ts +1 -0
- package/idp/index.js +1 -0
- package/package.json +20 -18
- package/testing/environment.d.ts +14 -0
- package/testing/environment.js +18 -0
- package/testing/environment.js.map +1 -0
- package/features/wcp/loadWcpLicense.d.ts +0 -2
- package/features/wcp/loadWcpLicense.js +0 -51
- package/features/wcp/loadWcpLicense.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport { FeatureFlags } from \"../../featureFlags/abstractions.js\";\n\nconst identityStorage = new AsyncLocalStorage<Identity | undefined>();\n\nclass IdentityContextImpl implements Abstraction.Interface {\n private identity: Identity = new AnonymousIdentity();\n\n constructor(\n private authorizationContext: AuthorizationContext.Interface,\n private featureFlags: FeatureFlags.Interface\n ) {}\n\n // ========================================================================\n // Identity Methods\n // ========================================================================\n\n getIdentity(): Identity {\n // Check for identity override first (from withIdentity())\n const override = identityStorage.getStore();\n if (override !== undefined) {\n return override;\n }\n return this.identity;\n }\n\n setIdentity(identity: Identity | undefined): void {\n // If undefined, set to anonymous identity\n this.identity = identity ?? new AnonymousIdentity();\n\n // Clear permissions cache when identity changes\n this.authorizationContext.clearPermissionsCache();\n }\n\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T> {\n return identityStorage.run(identity, cb);\n }\n\n // ========================================================================\n // Authorization State Methods\n // ========================================================================\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationContext.withoutAuthorization(cb);\n }\n\n isAuthorizationEnabled(): boolean {\n return this.authorizationContext.isAuthorizationEnabled();\n }\n\n // ========================================================================\n // Permission Methods\n // ========================================================================\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null> {\n if (!this.isAuthorizationEnabled()) {\n return { name: \"*\" } as TPermission;\n }\n\n const permissions = await this.listPermissions();\n\n // Try exact match first\n const exactMatch = permissions.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as TPermission;\n }\n\n // Try pattern matching\n const patternMatch = permissions.find(p => minimatch(name, p.name));\n if (patternMatch) {\n return patternMatch as TPermission;\n }\n\n return null;\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]> {\n if (!this.isAuthorizationEnabled()) {\n return [{ name: \"*\" }] as TPermission[];\n }\n\n const permissions = await this.listPermissions();\n\n return permissions.filter(p => {\n if (p.name === name) {\n return true;\n }\n return minimatch(name, p.name);\n }) as TPermission[];\n }\n\n async listPermissions(): Promise<SecurityPermission[]> {\n const permissions = await this.authorizationContext.loadPermissions(this.getIdentity());\n // TODO: extract this into a decorator\n return this.applyAaclLogic(permissions);\n }\n\n async hasFullAccess(): Promise<boolean> {\n const permissions = await this.listPermissions();\n return permissions.some(p => p.name === \"*\");\n }\n\n // ========================================================================\n // Private Helper Methods\n // ========================================================================\n\n private applyAaclLogic(permissions: SecurityPermission[]): SecurityPermission[] {\n const aaclEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer\");\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n\n if (aaclEnabled) {\n // Add AACL metadata permission\n return [\n ...permissions,\n {\n name: \"aacl\",\n teams: teamsEnabled\n } as AaclPermission\n ];\n }\n\n // If AACL is not enabled, filter out custom Webiny apps permissions\n return filterOutCustomWbyAppsPermissions(permissions);\n }\n}\n\nexport const IdentityContext = createImplementation({\n abstraction: Abstraction,\n implementation: IdentityContextImpl,\n dependencies: [AuthorizationContext, FeatureFlags]\n});\n"],"names":["identityStorage","AsyncLocalStorage","IdentityContextImpl","authorizationContext","featureFlags","AnonymousIdentity","override","undefined","identity","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","FeatureFlags"],"mappings":";;;;;;;;AAYA,MAAMA,kBAAkB,IAAIC;AAE5B,MAAMC;IAGF,YACYC,oBAAoD,EACpDC,YAAoC,CAC9C;aAFUD,oBA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M,kBAAiD;QACnD,MAAMF,cAAc,MAAM,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW;QAEpF,OAAO,IAAI,CAAC,cAAc,CAACA;IAC/B;IAEA,MAAM,gBAAkC;QACpC,MAAMA,cAAc,MAAM,IAAI,CAAC,eAAe;QAC9C,OAAOA,YAAY,IAAI,CAACE,CAAAA,IAAKA,AAAW,QAAXA,EAAE,IAAI;IACvC;IAMQ,eAAeF,WAAiC,EAAwB;QAC5E,MAAMK,cAAc,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QACtD,MAAMC,eAAe,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QAEvD,IAAID,aAEA,OAAO;eACAL;YACH;gBACI,MAAM;gBACN,OAAOM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAsBC;KAAa;AACtD"}
|
|
@@ -8,6 +8,7 @@ import { createApiKeyInputSchema } from "../shared/schemas.js";
|
|
|
8
8
|
import { ApiKeyAfterCreateEvent, ApiKeyBeforeCreateEvent } from "./events.js";
|
|
9
9
|
import { generateToken } from "../shared/generateToken.js";
|
|
10
10
|
import { ApiKeyNotAuthorizedError, ApiKeyValidationError } from "../shared/errors.js";
|
|
11
|
+
import { descriptionOnCreate } from "../../shared/description.js";
|
|
11
12
|
class CreateApiKeyUseCaseImpl {
|
|
12
13
|
constructor(identityContext, eventPublisher, repository){
|
|
13
14
|
this.identityContext = identityContext;
|
|
@@ -22,13 +23,17 @@ class CreateApiKeyUseCaseImpl {
|
|
|
22
23
|
const token = generateToken();
|
|
23
24
|
const identity = this.identityContext.getIdentity();
|
|
24
25
|
const data = validation.data;
|
|
26
|
+
const createInput = {
|
|
27
|
+
...data,
|
|
28
|
+
description: descriptionOnCreate(data.description)
|
|
29
|
+
};
|
|
25
30
|
const apiKey = {
|
|
26
31
|
id: mdbid(),
|
|
27
|
-
name:
|
|
28
|
-
slug:
|
|
29
|
-
description:
|
|
32
|
+
name: createInput.name,
|
|
33
|
+
slug: createInput.slug,
|
|
34
|
+
description: descriptionOnCreate(createInput.description),
|
|
30
35
|
token,
|
|
31
|
-
permissions:
|
|
36
|
+
permissions: createInput.permissions,
|
|
32
37
|
createdOn: new Date().toISOString(),
|
|
33
38
|
createdBy: {
|
|
34
39
|
id: identity.id,
|
|
@@ -38,13 +43,13 @@ class CreateApiKeyUseCaseImpl {
|
|
|
38
43
|
};
|
|
39
44
|
await this.eventPublisher.publish(new ApiKeyBeforeCreateEvent({
|
|
40
45
|
apiKey,
|
|
41
|
-
input:
|
|
46
|
+
input: createInput
|
|
42
47
|
}));
|
|
43
48
|
const result = await this.repository.create(apiKey);
|
|
44
49
|
if (result.isFail()) return Result.fail(result.error);
|
|
45
50
|
await this.eventPublisher.publish(new ApiKeyAfterCreateEvent({
|
|
46
51
|
apiKey,
|
|
47
|
-
input:
|
|
52
|
+
input: createInput
|
|
48
53
|
}));
|
|
49
54
|
return Result.ok(apiKey);
|
|
50
55
|
}
|
|
@@ -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:
|
|
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\";\nimport { descriptionOnCreate } from \"../../shared/description.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 // Normalised up front so that null reaches neither the entity nor the published events.\n const createInput: CreateApiKeyInput = {\n ...data,\n description: descriptionOnCreate(data.description)\n };\n\n const apiKey: ApiKey = {\n id: mdbid(),\n name: createInput.name,\n slug: createInput.slug,\n description: descriptionOnCreate(createInput.description),\n token,\n permissions: createInput.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: createInput })\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: createInput })\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","createInput","descriptionOnCreate","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;QAG3B,MAAMC,aAAaC,wBAAwB,SAAS,CAACL;QACrD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,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;QAG5B,MAAMO,cAAiC;YACnC,GAAGD,IAAI;YACP,aAAaE,oBAAoBF,KAAK,WAAW;QACrD;QAEA,MAAMG,SAAiB;YACnB,IAAIC;YACJ,MAAMH,YAAY,IAAI;YACtB,MAAMA,YAAY,IAAI;YACtB,aAAaC,oBAAoBD,YAAY,WAAW;YACxDJ;YACA,aAAaI,YAAY,WAAW;YACpC,WAAW,IAAII,OAAO,WAAW;YACjC,WAAW;gBACP,IAAIN,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIO,wBAAwB;YAAEH;YAAQ,OAAOF;QAAY;QAG7D,MAAMM,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,uBAAuB;YAAEL;YAAQ,OAAOF;QAAY;QAG5D,OAAOT,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAMM,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBxB;IAChB,cAAc;QAACyB;QAAiBC;QAAgBC;KAAkB;AACtE"}
|
|
@@ -6,6 +6,7 @@ import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
|
6
6
|
import { updateApiKeyInputSchema } from "../shared/schemas.js";
|
|
7
7
|
import { ApiKeyAfterUpdateEvent, ApiKeyBeforeUpdateEvent } from "./events.js";
|
|
8
8
|
import { ApiKeyNotAuthorizedError, ApiKeyValidationError } from "../shared/errors.js";
|
|
9
|
+
import { descriptionOnUpdate } from "../../shared/description.js";
|
|
9
10
|
class UpdateApiKeyUseCaseImpl {
|
|
10
11
|
constructor(repository, identityContext, eventPublisher){
|
|
11
12
|
this.repository = repository;
|
|
@@ -20,21 +21,26 @@ class UpdateApiKeyUseCaseImpl {
|
|
|
20
21
|
const existingResult = await this.repository.get(id);
|
|
21
22
|
if (existingResult.isFail()) return Result.fail(existingResult.error);
|
|
22
23
|
const existingApiKey = existingResult.value;
|
|
24
|
+
const { description, ...rest } = validation.data;
|
|
25
|
+
const changes = {
|
|
26
|
+
...rest,
|
|
27
|
+
...descriptionOnUpdate(description)
|
|
28
|
+
};
|
|
23
29
|
const updatedApiKey = {
|
|
24
30
|
...existingApiKey,
|
|
25
|
-
...
|
|
31
|
+
...changes
|
|
26
32
|
};
|
|
27
33
|
await this.eventPublisher.publish(new ApiKeyBeforeUpdateEvent({
|
|
28
34
|
original: existingApiKey,
|
|
29
35
|
updated: updatedApiKey,
|
|
30
|
-
input:
|
|
36
|
+
input: changes
|
|
31
37
|
}));
|
|
32
38
|
const result = await this.repository.update(updatedApiKey);
|
|
33
39
|
if (result.isFail()) return Result.fail(result.error);
|
|
34
40
|
await this.eventPublisher.publish(new ApiKeyAfterUpdateEvent({
|
|
35
41
|
original: existingApiKey,
|
|
36
42
|
updated: updatedApiKey,
|
|
37
|
-
input:
|
|
43
|
+
input: changes
|
|
38
44
|
}));
|
|
39
45
|
return Result.ok(updatedApiKey);
|
|
40
46
|
}
|
|
@@ -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 ...
|
|
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\";\nimport { descriptionOnUpdate } from \"../../shared/description.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 // `description` is pulled out of the spread because it is the one field that accepts null.\n // Normalising it here keeps null out of both the entity and the published events, whose\n // input type declares `description?: string`.\n const { description, ...rest } = validation.data;\n\n const changes: UpdateApiKeyInput = {\n ...rest,\n ...descriptionOnUpdate(description)\n };\n\n const updatedApiKey: ApiKey = {\n ...existingApiKey,\n ...changes\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeUpdateEvent({\n original: existingApiKey,\n updated: updatedApiKey,\n input: changes\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: changes\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","description","rest","changes","descriptionOnUpdate","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,MA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from "zod";
|
|
|
2
2
|
export declare const createApiKeyInputSchema: z.ZodObject<{
|
|
3
3
|
name: z.ZodString;
|
|
4
4
|
slug: z.ZodString;
|
|
5
|
-
description: z.ZodString
|
|
5
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
6
6
|
permissions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
}, z.core.$loose>>>>;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
10
|
export declare const updateApiKeyInputSchema: z.ZodObject<{
|
|
11
11
|
name: z.ZodOptional<z.ZodString>;
|
|
12
|
-
description: z.ZodOptional<z.ZodString
|
|
12
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
13
|
permissions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
14
14
|
name: z.ZodString;
|
|
15
15
|
}, z.core.$loose>>>>;
|
|
@@ -2,14 +2,14 @@ import { z } from "zod";
|
|
|
2
2
|
const createApiKeyInputSchema = z.object({
|
|
3
3
|
name: z.string().min(1),
|
|
4
4
|
slug: z.string().min(1),
|
|
5
|
-
description: z.string(),
|
|
5
|
+
description: z.string().max(500).nullish(),
|
|
6
6
|
permissions: z.array(z.looseObject({
|
|
7
7
|
name: z.string()
|
|
8
8
|
})).optional().default([])
|
|
9
9
|
});
|
|
10
10
|
const updateApiKeyInputSchema = z.object({
|
|
11
11
|
name: z.string().min(1).optional(),
|
|
12
|
-
description: z.string().
|
|
12
|
+
description: z.string().max(500).nullish(),
|
|
13
13
|
permissions: z.array(z.looseObject({
|
|
14
14
|
name: z.string()
|
|
15
15
|
})).optional().default([])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/shared/schemas.js","sources":["../../../../../src/features/security/apiKeys/shared/schemas.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createApiKeyInputSchema = z.object({\n name: z.string().min(1),\n slug: z.string().min(1),\n description: z.string(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const updateApiKeyInputSchema = z.object({\n name: z.string().min(1).optional(),\n description: z.string().
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/shared/schemas.js","sources":["../../../../../src/features/security/apiKeys/shared/schemas.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createApiKeyInputSchema = z.object({\n name: z.string().min(1),\n slug: z.string().min(1),\n // Nullable in the GraphQL schema - see `descriptionOnCreate` for why this is `.nullish()`.\n // This was a bare `z.string()`, so an API key created without a description was rejected\n // whether the client sent null or omitted the field entirely. `max` matches teams and roles.\n description: z.string().max(500).nullish(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const updateApiKeyInputSchema = z.object({\n name: z.string().min(1).optional(),\n // Nullable in the GraphQL schema - see `descriptionOnUpdate` for why this is `.nullish()` and\n // must not carry a `.transform()`. `max` matches teams and roles.\n description: z.string().max(500).nullish(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const listApiKeysInputSchema = z.object({\n where: z\n .object({\n name: z.string().optional(),\n name_contains: z.string().optional(),\n description: z.string().optional(),\n description_contains: z.string().optional()\n })\n .optional(),\n limit: z.number().int().positive().max(100).optional(),\n after: z.string().optional(),\n sort: z.array(z.enum([\"createdOn_ASC\", \"createdOn_DESC\"])).optional()\n});\n"],"names":["createApiKeyInputSchema","z","updateApiKeyInputSchema","listApiKeysInputSchema"],"mappings":";AAEO,MAAMA,0BAA0BC,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IAIrB,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAMC,0BAA0BD,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAGhC,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAME,yBAAyBF,EAAE,MAAM,CAAC;IAC3C,OAAOA,EAAAA,MACI,CAAC;QACJ,MAAMA,EAAE,MAAM,GAAG,QAAQ;QACzB,eAAeA,EAAE,MAAM,GAAG,QAAQ;QAClC,aAAaA,EAAE,MAAM,GAAG,QAAQ;QAChC,sBAAsBA,EAAE,MAAM,GAAG,QAAQ;IAC7C,GACC,QAAQ;IACb,OAAOA,EAAE,MAAM,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAC,KAAK,QAAQ;IACpD,OAAOA,EAAE,MAAM,GAAG,QAAQ;IAC1B,MAAMA,EAAE,KAAK,CAACA,CAAC,CAADA,OAAM,CAAC;QAAC;QAAiB;KAAiB,GAAG,QAAQ;AACvE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FeatureFlags } from "../../../../features/featureFlags/abstractions.js";
|
|
2
|
+
import { RawAssumePermissions } from "../../../../features/requestContext/abstractions.js";
|
|
3
|
+
import { Identity } from "../../../../features/security/IdentityContext/index.js";
|
|
4
|
+
import { RolesRepository } from "../../../../features/security/roles/shared/abstractions.js";
|
|
5
|
+
import { TeamsRepository } from "../../../../features/security/teams/shared/abstractions.js";
|
|
6
|
+
import { PermissionsProcessor } from "./abstractions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates the request against a role or team the caller asked to preview, instead of against the
|
|
9
|
+
* caller's own roles. This is what makes "view the Admin as an Editor" honest: lists shrink and
|
|
10
|
+
* writes fail server-side, rather than the Admin merely hiding buttons over unrestricted data.
|
|
11
|
+
*
|
|
12
|
+
* Previewing is available only to callers who already have full access, and it can only ever take
|
|
13
|
+
* permissions away. See the guard in `getPermissions` for why the check cannot go through
|
|
14
|
+
* IdentityContext.
|
|
15
|
+
*/
|
|
16
|
+
declare class AssumedPermissionsImpl implements PermissionsProcessor.Interface {
|
|
17
|
+
private rawAssumePermissions;
|
|
18
|
+
private featureFlags;
|
|
19
|
+
private rolesRepository;
|
|
20
|
+
private teamsRepository;
|
|
21
|
+
private decoratee;
|
|
22
|
+
constructor(rawAssumePermissions: RawAssumePermissions.Interface, featureFlags: FeatureFlags.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface, decoratee: PermissionsProcessor.Interface);
|
|
23
|
+
getPermissions(identity: Identity): Promise<PermissionsProcessor.Permissions | null>;
|
|
24
|
+
private loadAssumedRoles;
|
|
25
|
+
private loadRoles;
|
|
26
|
+
}
|
|
27
|
+
export declare const AssumedPermissions: typeof AssumedPermissionsImpl & {
|
|
28
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IPermissionsProcessor>;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FeatureFlags } from "../../../featureFlags/abstractions.js";
|
|
2
|
+
import { RawAssumePermissions } from "../../../requestContext/abstractions.js";
|
|
3
|
+
import { RolesRepository } from "../../roles/shared/abstractions.js";
|
|
4
|
+
import { TeamsRepository } from "../../teams/shared/abstractions.js";
|
|
5
|
+
import { getPermissionsFromRoles } from "../../utils/getPermissionsFromRoles.js";
|
|
6
|
+
import { PermissionsProcessor } from "./abstractions.js";
|
|
7
|
+
function grantsFullAccess(permissions) {
|
|
8
|
+
return permissions.some((permission)=>"*" === permission.name);
|
|
9
|
+
}
|
|
10
|
+
class AssumedPermissionsImpl {
|
|
11
|
+
constructor(rawAssumePermissions, featureFlags, rolesRepository, teamsRepository, decoratee){
|
|
12
|
+
this.rawAssumePermissions = rawAssumePermissions;
|
|
13
|
+
this.featureFlags = featureFlags;
|
|
14
|
+
this.rolesRepository = rolesRepository;
|
|
15
|
+
this.teamsRepository = teamsRepository;
|
|
16
|
+
this.decoratee = decoratee;
|
|
17
|
+
}
|
|
18
|
+
async getPermissions(identity) {
|
|
19
|
+
const target = this.rawAssumePermissions.get();
|
|
20
|
+
const own = await this.decoratee.getPermissions(identity);
|
|
21
|
+
if (!target) return own;
|
|
22
|
+
if (!own || !grantsFullAccess(own)) return own;
|
|
23
|
+
const roles = await this.loadAssumedRoles(target);
|
|
24
|
+
return getPermissionsFromRoles(roles);
|
|
25
|
+
}
|
|
26
|
+
async loadAssumedRoles(target) {
|
|
27
|
+
if ("role" === target.type) return this.loadRoles([
|
|
28
|
+
target.id
|
|
29
|
+
]);
|
|
30
|
+
const teamsEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams");
|
|
31
|
+
if (!teamsEnabled) return [];
|
|
32
|
+
const teamResult = await this.teamsRepository.get({
|
|
33
|
+
id: target.id
|
|
34
|
+
});
|
|
35
|
+
if (teamResult.isFail()) return [];
|
|
36
|
+
return this.loadRoles(teamResult.value.roles);
|
|
37
|
+
}
|
|
38
|
+
async loadRoles(roleIds) {
|
|
39
|
+
if (0 === roleIds.length) return [];
|
|
40
|
+
const result = await this.rolesRepository.list({
|
|
41
|
+
where: {
|
|
42
|
+
id_in: roleIds
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (result.isFail()) return [];
|
|
46
|
+
return result.value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const AssumedPermissions = PermissionsProcessor.createDecorator({
|
|
50
|
+
decorator: AssumedPermissionsImpl,
|
|
51
|
+
dependencies: [
|
|
52
|
+
RawAssumePermissions,
|
|
53
|
+
FeatureFlags,
|
|
54
|
+
RolesRepository,
|
|
55
|
+
TeamsRepository
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
export { AssumedPermissions };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=AssumedPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.ts"],"sourcesContent":["import { FeatureFlags } from \"~/features/featureFlags/abstractions.js\";\nimport { RawAssumePermissions } from \"~/features/requestContext/abstractions.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { getPermissionsFromRoles } from \"~/features/security/utils/getPermissionsFromRoles.js\";\nimport type { SecurityRole } from \"~/types/security.js\";\nimport { PermissionsProcessor } from \"./abstractions.js\";\n\nfunction grantsFullAccess(permissions: PermissionsProcessor.Permissions): boolean {\n return permissions.some(permission => permission.name === \"*\");\n}\n\n/**\n * Evaluates the request against a role or team the caller asked to preview, instead of against the\n * caller's own roles. This is what makes \"view the Admin as an Editor\" honest: lists shrink and\n * writes fail server-side, rather than the Admin merely hiding buttons over unrestricted data.\n *\n * Previewing is available only to callers who already have full access, and it can only ever take\n * permissions away. See the guard in `getPermissions` for why the check cannot go through\n * IdentityContext.\n */\nclass AssumedPermissionsImpl implements PermissionsProcessor.Interface {\n constructor(\n private rawAssumePermissions: RawAssumePermissions.Interface,\n private featureFlags: FeatureFlags.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface,\n private decoratee: PermissionsProcessor.Interface\n ) {}\n\n async getPermissions(identity: Identity): Promise<PermissionsProcessor.Permissions | null> {\n const target = this.rawAssumePermissions.get();\n const own = await this.decoratee.getPermissions(identity);\n\n if (!target) {\n return own;\n }\n\n /*\n * The guard runs against the caller's OWN permissions, and they have to come from the\n * decoratee. IdentityContext.hasFullAccess() would resolve them through the Authorizer,\n * which lands back in this decorator, so the check would be re-entrant. Order matters too:\n * read the real permissions, verify them, and only then substitute.\n */\n if (!own || !grantsFullAccess(own)) {\n return own;\n }\n\n const roles = await this.loadAssumedRoles(target);\n\n /*\n * A preview request that resolves to no roles grants nothing. Falling back to `own` would\n * hand the caller their real full access while the Admin still claims they are previewing\n * a restricted role, which is the one outcome this feature must never produce.\n */\n return getPermissionsFromRoles(roles);\n }\n\n private async loadAssumedRoles(target: RawAssumePermissions.Target): Promise<SecurityRole[]> {\n if (target.type === \"role\") {\n return this.loadRoles([target.id]);\n }\n\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n if (!teamsEnabled) {\n return [];\n }\n\n const teamResult = await this.teamsRepository.get({ id: target.id });\n if (teamResult.isFail()) {\n return [];\n }\n\n return this.loadRoles(teamResult.value.roles);\n }\n\n private async loadRoles(roleIds: string[]): Promise<SecurityRole[]> {\n if (roleIds.length === 0) {\n return [];\n }\n\n const result = await this.rolesRepository.list({ where: { id_in: roleIds } });\n if (result.isFail()) {\n return [];\n }\n\n return result.value;\n }\n}\n\nexport const AssumedPermissions = PermissionsProcessor.createDecorator({\n decorator: AssumedPermissionsImpl,\n dependencies: [RawAssumePermissions, FeatureFlags, RolesRepository, TeamsRepository]\n});\n"],"names":["grantsFullAccess","permissions","permission","AssumedPermissionsImpl","rawAssumePermissions","featureFlags","rolesRepository","teamsRepository","decoratee","identity","target","own","roles","getPermissionsFromRoles","teamsEnabled","teamResult","roleIds","result","AssumedPermissions","PermissionsProcessor","RawAssumePermissions","FeatureFlags","RolesRepository","TeamsRepository"],"mappings":";;;;;;AASA,SAASA,iBAAiBC,WAA6C;IACnE,OAAOA,YAAY,IAAI,CAACC,CAAAA,aAAcA,AAAoB,QAApBA,WAAW,IAAI;AACzD;AAWA,MAAMC;IACF,YACYC,oBAAoD,EACpDC,YAAoC,EACpCC,eAA0C,EAC1CC,eAA0C,EAC1CC,SAAyC,CACnD;aALUJ,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;a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uthorizer/GetPermissionsFromIdentity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FeatureFlags } from "../../../../features/featureFlags/abstractions.js";
|
|
2
2
|
import { Identity } from "../../../../features/security/IdentityContext/index.js";
|
|
3
3
|
import { PermissionsProcessor } from "./abstractions.js";
|
|
4
4
|
import { RolesRepository } from "../../../../features/security/roles/shared/abstractions.js";
|
|
@@ -7,11 +7,11 @@ import { AdminUsersRepository } from "../../../../features/users/shared/abstract
|
|
|
7
7
|
export type RoleId = string | undefined;
|
|
8
8
|
export type TeamId = string | undefined;
|
|
9
9
|
declare class GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcessor.Interface {
|
|
10
|
-
private
|
|
10
|
+
private featureFlags;
|
|
11
11
|
private usersRepository;
|
|
12
12
|
private rolesRepository;
|
|
13
13
|
private teamsRepository;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(featureFlags: FeatureFlags.Interface, usersRepository: AdminUsersRepository.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface);
|
|
15
15
|
getPermissions(identity: Identity): Promise<{
|
|
16
16
|
name: string;
|
|
17
17
|
_src: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FeatureFlags } from "../../../featureFlags/abstractions.js";
|
|
2
2
|
import { PermissionsProcessor } from "./abstractions.js";
|
|
3
3
|
import { RolesRepository } from "../../roles/shared/abstractions.js";
|
|
4
4
|
import { TeamsRepository } from "../../teams/shared/abstractions.js";
|
|
5
5
|
import { getPermissionsFromRoles } from "../../utils/getPermissionsFromRoles.js";
|
|
6
6
|
import { AdminUsersRepository } from "../../../users/shared/abstractions.js";
|
|
7
7
|
class GetPermissionsFromGroupsAndTeamsImpl {
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
8
|
+
constructor(featureFlags, usersRepository, rolesRepository, teamsRepository){
|
|
9
|
+
this.featureFlags = featureFlags;
|
|
10
10
|
this.usersRepository = usersRepository;
|
|
11
11
|
this.rolesRepository = rolesRepository;
|
|
12
12
|
this.teamsRepository = teamsRepository;
|
|
@@ -32,7 +32,7 @@ class GetPermissionsFromGroupsAndTeamsImpl {
|
|
|
32
32
|
const loadedRolesByIds = rolesResult.isOk() ? rolesResult.value : [];
|
|
33
33
|
loadedRoles.push(...loadedRolesByIds);
|
|
34
34
|
}
|
|
35
|
-
if (this.
|
|
35
|
+
if (this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams")) {
|
|
36
36
|
teamIds.push(...user.teams ?? []);
|
|
37
37
|
const filteredTeamIds = teamIds.filter(Boolean);
|
|
38
38
|
const dedupedTeamIds = Array.from(new Set(filteredTeamIds));
|
|
@@ -65,7 +65,7 @@ class GetPermissionsFromGroupsAndTeamsImpl {
|
|
|
65
65
|
const GetPermissionsFromIdentity = PermissionsProcessor.createImplementation({
|
|
66
66
|
implementation: GetPermissionsFromGroupsAndTeamsImpl,
|
|
67
67
|
dependencies: [
|
|
68
|
-
|
|
68
|
+
FeatureFlags,
|
|
69
69
|
AdminUsersRepository,
|
|
70
70
|
RolesRepository,
|
|
71
71
|
TeamsRepository
|
package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.ts"],"sourcesContent":["import { FeatureFlags } from \"~/features/featureFlags/abstractions.js\";\nimport type { SecurityRole } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\nimport { PermissionsProcessor } from \"./abstractions.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { getPermissionsFromRoles } from \"~/features/security/utils/getPermissionsFromRoles.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\n\nexport type RoleId = string | undefined;\nexport type TeamId = string | undefined;\n\nclass GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcessor.Interface {\n constructor(\n private featureFlags: FeatureFlags.Interface,\n private usersRepository: AdminUsersRepository.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface\n ) {}\n\n async getPermissions(identity: Identity) {\n const userResult = await this.usersRepository.get({ id: identity.id });\n if (userResult.isFail()) {\n return null;\n }\n\n const user = userResult.value;\n\n // Load roles that are associated with the current identity. Also load roles\n // that are assigned via one or more teams (if the Teams feature is enabled).\n const roleIds: RoleId[] = [];\n const teamIds: TeamId[] = [];\n\n roleIds.push(...(user.roles ?? []));\n\n const filteredRoleIds = roleIds.filter(Boolean) as string[];\n const dedupedRoleIds = Array.from(new Set(filteredRoleIds));\n\n const loadedRoles: SecurityRole[] = [];\n\n if (dedupedRoleIds.length > 0) {\n const rolesResult = await this.rolesRepository.list({\n where: { id_in: dedupedRoleIds }\n });\n\n const loadedRolesByIds = rolesResult.isOk() ? rolesResult.value : [];\n loadedRoles.push(...loadedRolesByIds);\n }\n\n if (this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\")) {\n teamIds.push(...(user.teams ?? []));\n\n const filteredTeamIds = teamIds.filter(Boolean) as string[];\n const dedupedTeamIds = Array.from(new Set(filteredTeamIds));\n\n if (dedupedTeamIds.length > 0) {\n const teamsResult = await this.teamsRepository.list({\n where: { id_in: dedupedTeamIds }\n });\n\n const loadedTeams = teamsResult.isOk() ? teamsResult.value : [];\n\n // Upon returning teams, we're filtering out team roles that were already loaded.\n // Also note that `team.roles` contains role IDs, not slugs.\n const roleIdsFromTeams = loadedTeams\n .flatMap(team => team.roles)\n .filter(roleId => {\n const alreadyLoaded = loadedRoles.find(role => role.id === roleId);\n return !alreadyLoaded;\n });\n\n if (roleIdsFromTeams.length > 0) {\n const moreRolesResult = await this.rolesRepository.list({\n where: { id_in: roleIdsFromTeams }\n });\n\n const rolesFromTeams = moreRolesResult.isOk() ? moreRolesResult.value : [];\n loadedRoles.push(...rolesFromTeams);\n }\n }\n }\n\n if (loadedRoles.length > 0) {\n return getPermissionsFromRoles(loadedRoles);\n }\n\n return null;\n }\n}\n\nexport const GetPermissionsFromIdentity = PermissionsProcessor.createImplementation({\n implementation: GetPermissionsFromGroupsAndTeamsImpl,\n dependencies: [FeatureFlags, AdminUsersRepository, RolesRepository, TeamsRepository]\n});\n"],"names":["GetPermissionsFromGroupsAndTeamsImpl","featureFlags","usersRepository","rolesRepository","teamsRepository","identity","userResult","user","roleIds","teamIds","filteredRoleIds","Boolean","dedupedRoleIds","Array","Set","loadedRoles","rolesResult","loadedRolesByIds","filteredTeamIds","dedupedTeamIds","teamsResult","loadedTeams","roleIdsFromTeams","team","roleId","alreadyLoaded","role","moreRolesResult","rolesFromTeams","getPermissionsFromRoles","GetPermissionsFromIdentity","PermissionsProcessor","FeatureFlags","AdminUsersRepository","RolesRepository","TeamsRepository"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACYC,YAAoC,EACpCC,eAA+C,EAC/CC,eAA0C,EAC1CC,eAA0C,CACpD;aAJUH,YAAY,GAAZA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,eAAeC,QAAkB,EAAE;QACrC,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YAAE,IAAID,SAAS,EAAE;QAAC;QACpE,IAAIC,WAAW,MAAM,IACjB,OAAO;QAGX,MAAMC,OAAOD,WAAW,KAAK;QAI7B,MAAME,UAAoB,EAAE;QAC5B,MAAMC,UAAoB,EAAE;QAE5BD,QAAQ,IAA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KAAK,GAAG,EAAE;oBAC1EZ,YAAY,IAAI,IAAIa;gBACxB;YACJ;QACJ;QAEA,IAAIb,YAAY,MAAM,GAAG,GACrB,OAAOc,wBAAwBd;QAGnC,OAAO;IACX;AACJ;AAEO,MAAMe,6BAA6BC,qBAAqB,oBAAoB,CAAC;IAChF,gBAAgB/B;IAChB,cAAc;QAACgC;QAAcC;QAAsBC;QAAiBC;KAAgB;AACxF"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { RolesTeamsAuthorizer } from "./RolesTeamsAuthorizer.js";
|
|
3
3
|
import { GetPermissionsFromIdentity } from "./GetPermissionsFromIdentity.js";
|
|
4
|
+
import { AssumedPermissions } from "./AssumedPermissions.js";
|
|
4
5
|
const GroupsTeamsAuthorizerFeature = createFeature({
|
|
5
6
|
name: "GroupsTeamsAuthorizer",
|
|
6
7
|
register (container) {
|
|
7
8
|
container.register(RolesTeamsAuthorizer).inSingletonScope();
|
|
8
9
|
container.register(GetPermissionsFromIdentity);
|
|
10
|
+
container.registerDecorator(AssumedPermissions);
|
|
9
11
|
}
|
|
10
12
|
});
|
|
11
13
|
export { GroupsTeamsAuthorizerFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/feature.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RolesTeamsAuthorizer } from \"./RolesTeamsAuthorizer.js\";\nimport { GetPermissionsFromIdentity } from \"./GetPermissionsFromIdentity.js\";\n\nexport const GroupsTeamsAuthorizerFeature = createFeature({\n name: \"GroupsTeamsAuthorizer\",\n register(container) {\n container.register(RolesTeamsAuthorizer).inSingletonScope();\n container.register(GetPermissionsFromIdentity);\n }\n});\n"],"names":["GroupsTeamsAuthorizerFeature","createFeature","container","RolesTeamsAuthorizer","GetPermissionsFromIdentity"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/feature.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RolesTeamsAuthorizer } from \"./RolesTeamsAuthorizer.js\";\nimport { GetPermissionsFromIdentity } from \"./GetPermissionsFromIdentity.js\";\nimport { AssumedPermissions } from \"./AssumedPermissions.js\";\n\nexport const GroupsTeamsAuthorizerFeature = createFeature({\n name: \"GroupsTeamsAuthorizer\",\n register(container) {\n container.register(RolesTeamsAuthorizer).inSingletonScope();\n container.register(GetPermissionsFromIdentity);\n container.registerDecorator(AssumedPermissions);\n }\n});\n"],"names":["GroupsTeamsAuthorizerFeature","createFeature","container","RolesTeamsAuthorizer","GetPermissionsFromIdentity","AssumedPermissions"],"mappings":";;;;AAKO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sBAAsB,gBAAgB;QACzDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -7,6 +7,7 @@ import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
|
7
7
|
import { createRoleValidation } from "./schema.js";
|
|
8
8
|
import { RoleAfterCreateEvent, RoleBeforeCreateEvent } from "./events.js";
|
|
9
9
|
import { NotAuthorizedError, RoleExistsError, RoleValidationError } from "../shared/errors.js";
|
|
10
|
+
import { descriptionOnCreate } from "../../shared/description.js";
|
|
10
11
|
class CreateRoleUseCaseImpl {
|
|
11
12
|
constructor(identityContext, eventPublisher, repository){
|
|
12
13
|
this.identityContext = identityContext;
|
|
@@ -24,12 +25,16 @@ class CreateRoleUseCaseImpl {
|
|
|
24
25
|
slug: data.slug
|
|
25
26
|
});
|
|
26
27
|
if (existingRoleResult.isOk()) return Result.fail(new RoleExistsError(data.slug));
|
|
28
|
+
const createInput = {
|
|
29
|
+
...data,
|
|
30
|
+
description: descriptionOnCreate(data.description)
|
|
31
|
+
};
|
|
27
32
|
const role = {
|
|
28
33
|
id: mdbid(),
|
|
29
|
-
name:
|
|
30
|
-
slug:
|
|
31
|
-
description:
|
|
32
|
-
permissions:
|
|
34
|
+
name: createInput.name,
|
|
35
|
+
slug: createInput.slug,
|
|
36
|
+
description: descriptionOnCreate(createInput.description),
|
|
37
|
+
permissions: createInput.permissions,
|
|
33
38
|
system: input.system || false,
|
|
34
39
|
createdOn: new Date().toISOString(),
|
|
35
40
|
createdBy: {
|
|
@@ -41,13 +46,13 @@ class CreateRoleUseCaseImpl {
|
|
|
41
46
|
};
|
|
42
47
|
await this.eventPublisher.publish(new RoleBeforeCreateEvent({
|
|
43
48
|
role,
|
|
44
|
-
input:
|
|
49
|
+
input: createInput
|
|
45
50
|
}));
|
|
46
51
|
const result = await this.repository.create(role);
|
|
47
52
|
if (result.isFail()) return Result.fail(result.error);
|
|
48
53
|
await this.eventPublisher.publish(new RoleAfterCreateEvent({
|
|
49
54
|
role,
|
|
50
|
-
input:
|
|
55
|
+
input: createInput
|
|
51
56
|
}));
|
|
52
57
|
return Result.ok(role);
|
|
53
58
|
}
|
|
@@ -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:
|
|
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\";\nimport { descriptionOnCreate } from \"../../shared/description.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 // Normalised up front so that null reaches neither the entity nor the published events.\n const createInput: CreateRoleInput = {\n ...data,\n description: descriptionOnCreate(data.description)\n };\n\n const role: Role = {\n id: mdbid(),\n name: createInput.name,\n slug: createInput.slug,\n description: descriptionOnCreate(createInput.description),\n permissions: createInput.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(new RoleBeforeCreateEvent({ role, input: createInput }));\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(new RoleAfterCreateEvent({ role, input: createInput }));\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","createInput","descriptionOnCreate","role","mdbid","Date","RoleBeforeCreateEvent","result","RoleAfterCreateEvent","CreateRoleUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","RolesRepository"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,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AII,OAAO,MAAM,IACb,OAAOf,OAAO,IAAI,CAACe,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAEL;YAAM,OAAOF;QAAY;QAEtF,OAAOT,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAMM,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBzB;IAChB,cAAc;QAAC0B;QAAiBC;QAAgBC;KAAgB;AACpE"}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const createRoleValidation: z.ZodObject<{
|
|
3
3
|
name: z.ZodString;
|
|
4
4
|
slug: z.ZodString;
|
|
5
|
-
description: z.
|
|
5
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
6
6
|
permissions: z.ZodArray<z.ZodObject<{
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
}, z.core.$loose>>;
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
const createRoleValidation = z.object({
|
|
3
3
|
name: z.string().min(3),
|
|
4
4
|
slug: z.string().min(3),
|
|
5
|
-
description: z.string().max(500).
|
|
5
|
+
description: z.string().max(500).nullish(),
|
|
6
6
|
permissions: z.array(z.looseObject({
|
|
7
7
|
name: z.string()
|
|
8
8
|
}))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/roles/CreateRole/schema.js","sources":["../../../../../src/features/security/roles/CreateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createRoleValidation = z.object({\n name: z.string().min(3),\n slug: z.string().min(3),\n description: z.string().max(500).
|
|
1
|
+
{"version":3,"file":"features/security/roles/CreateRole/schema.js","sources":["../../../../../src/features/security/roles/CreateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createRoleValidation = z.object({\n name: z.string().min(3),\n slug: z.string().min(3),\n // Nullable in the GraphQL schema - see `descriptionOnCreate` for why this is `.nullish()`.\n // `.optional().default(\"\")` did NOT cover this: Zod applies a default to `undefined` only, so\n // an explicit null still failed validation.\n description: z.string().max(500).nullish(),\n permissions: z.array(z.looseObject({ name: z.string() }))\n});\n"],"names":["createRoleValidation","z"],"mappings":";AAEO,MAAMA,uBAAuBC,EAAE,MAAM,CAAC;IACzC,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IAIrB,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAE,KAAK,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG;AAC1D"}
|
|
@@ -5,6 +5,7 @@ import { IdentityContext } from "../../IdentityContext/abstractions.js";
|
|
|
5
5
|
import { EventPublisher } from "../../../eventPublisher/index.js";
|
|
6
6
|
import { updateRoleValidation } from "./schema.js";
|
|
7
7
|
import { RoleAfterUpdateEvent, RoleBeforeUpdateEvent } from "./events.js";
|
|
8
|
+
import { descriptionOnUpdate } from "../../shared/description.js";
|
|
8
9
|
import { CannotUpdatePluginRolesError, NotAuthorizedError, RoleValidationError } from "../shared/errors.js";
|
|
9
10
|
class UpdateRoleUseCaseImpl {
|
|
10
11
|
constructor(repository, identityContext, eventPublisher){
|
|
@@ -23,21 +24,26 @@ 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
|
+
const { description, ...rest } = validation.data;
|
|
28
|
+
const changes = {
|
|
29
|
+
...rest,
|
|
30
|
+
...descriptionOnUpdate(description)
|
|
31
|
+
};
|
|
26
32
|
const updatedRole = {
|
|
27
33
|
...existingRole,
|
|
28
|
-
...
|
|
34
|
+
...changes
|
|
29
35
|
};
|
|
30
36
|
await this.eventPublisher.publish(new RoleBeforeUpdateEvent({
|
|
31
37
|
original: existingRole,
|
|
32
38
|
updated: updatedRole,
|
|
33
|
-
input:
|
|
39
|
+
input: changes
|
|
34
40
|
}));
|
|
35
41
|
const result = await this.repository.update(updatedRole);
|
|
36
42
|
if (result.isFail()) return Result.fail(result.error);
|
|
37
43
|
await this.eventPublisher.publish(new RoleAfterUpdateEvent({
|
|
38
44
|
original: existingRole,
|
|
39
45
|
updated: updatedRole,
|
|
40
|
-
input:
|
|
46
|
+
input: changes
|
|
41
47
|
}));
|
|
42
48
|
return Result.ok(updatedRole);
|
|
43
49
|
}
|