@webiny/api-core 6.4.11 → 6.6.0-alpha.1
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.d.ts +2 -2
- package/ApiCoreFeature.js +29 -5
- package/ApiCoreFeature.js.map +1 -1
- package/exports/api/security/api-key.d.ts +1 -0
- package/exports/api/security/api-key.js +1 -0
- package/exports/api.d.ts +3 -1
- package/exports/api.js +2 -1
- package/features/ai/Ai.d.ts +3 -3
- package/features/ai/Ai.js +60 -23
- package/features/ai/Ai.js.map +1 -1
- package/features/ai/AnthropicSdkFactory.js +12 -0
- package/features/ai/AnthropicSdkFactory.js.map +1 -1
- package/features/ai/OpenAiSdkFactory.js +16 -0
- package/features/ai/OpenAiSdkFactory.js.map +1 -1
- package/features/ai/TextExtractor/DefaultTextExtractor.d.ts +9 -0
- package/features/ai/TextExtractor/DefaultTextExtractor.js +28 -0
- package/features/ai/TextExtractor/DefaultTextExtractor.js.map +1 -0
- package/features/ai/TextExtractor/abstractions.d.ts +12 -0
- package/features/ai/TextExtractor/abstractions.js +5 -0
- package/features/ai/TextExtractor/abstractions.js.map +1 -0
- package/features/ai/TextExtractor/index.d.ts +3 -0
- package/features/ai/TextExtractor/index.js +2 -0
- package/features/ai/TextExtractor/parsers/docxParser.d.ts +1 -0
- package/features/ai/TextExtractor/parsers/docxParser.js +111 -0
- package/features/ai/TextExtractor/parsers/docxParser.js.map +1 -0
- package/features/ai/abstractions.d.ts +18 -7
- package/features/ai/abstractions.js +1 -2
- package/features/ai/abstractions.js.map +1 -1
- package/features/ai/events.d.ts +59 -0
- package/features/ai/events.js +41 -0
- package/features/ai/events.js.map +1 -0
- package/features/ai/feature.js +6 -2
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +8 -2
- package/features/ai/index.js +4 -1
- package/features/ai/toolPipeline/AiOutputToolRegistry.d.ts +11 -0
- package/features/ai/toolPipeline/AiOutputToolRegistry.js +31 -0
- package/features/ai/toolPipeline/AiOutputToolRegistry.js.map +1 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.d.ts +10 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.js +36 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.js.map +1 -0
- package/features/ai/toolPipeline/abstractions.d.ts +23 -0
- package/features/ai/toolPipeline/abstractions.js +7 -0
- package/features/ai/toolPipeline/abstractions.js.map +1 -0
- package/features/ai/toolPipeline/index.d.ts +2 -0
- package/features/ai/toolPipeline/index.js +1 -0
- 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/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.d.ts +13 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +49 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -0
- package/features/hashing/ScryptHasher.d.ts +11 -0
- package/features/hashing/ScryptHasher.js +74 -0
- package/features/hashing/ScryptHasher.js.map +1 -0
- package/features/hashing/abstractions.d.ts +18 -0
- package/features/hashing/abstractions.js +5 -0
- package/features/hashing/abstractions.js.map +1 -0
- package/features/hashing/feature.d.ts +4 -0
- package/features/hashing/feature.js +11 -0
- package/features/hashing/feature.js.map +1 -0
- package/features/hashing/index.d.ts +2 -0
- package/features/hashing/index.js +1 -0
- package/features/requestContext/RawAuthToken.d.ts +14 -0
- package/features/requestContext/RawAuthToken.js +19 -0
- package/features/requestContext/RawAuthToken.js.map +1 -0
- package/features/requestContext/RawTenantId.d.ts +14 -0
- package/features/requestContext/RawTenantId.js +19 -0
- package/features/requestContext/RawTenantId.js.map +1 -0
- package/features/requestContext/RequestIdentityLoader.d.ts +19 -0
- package/features/requestContext/RequestIdentityLoader.js +26 -0
- package/features/requestContext/RequestIdentityLoader.js.map +1 -0
- package/features/requestContext/RequestTenantLoader.d.ts +18 -0
- package/features/requestContext/RequestTenantLoader.js +52 -0
- package/features/requestContext/RequestTenantLoader.js.map +1 -0
- package/features/requestContext/abstractions.d.ts +53 -0
- package/features/requestContext/abstractions.js +8 -0
- package/features/requestContext/abstractions.js.map +1 -0
- package/features/requestContext/feature.d.ts +11 -0
- package/features/requestContext/feature.js +17 -0
- package/features/requestContext/feature.js.map +1 -0
- package/features/requestContext/index.d.ts +2 -0
- package/features/requestContext/index.js +2 -0
- 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/ApiKeyAuthenticator.d.ts +14 -0
- package/features/security/apiKeys/ApiKeyAuthenticator.js +36 -0
- package/features/security/apiKeys/ApiKeyAuthenticator.js.map +1 -0
- package/features/security/apiKeys/ApiKeyAuthorizer.d.ts +10 -0
- package/features/security/apiKeys/ApiKeyAuthorizer.js +15 -0
- package/features/security/apiKeys/ApiKeyAuthorizer.js.map +1 -0
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +11 -6
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +1 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.d.ts +1 -3
- package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.d.ts +1 -3
- package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.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/feature.js +11 -2
- package/features/security/apiKeys/feature.js.map +1 -1
- package/features/security/apiKeys/shared/ApiKeyProvider.d.ts +3 -5
- package/features/security/apiKeys/shared/ApiKeyProvider.js +6 -21
- package/features/security/apiKeys/shared/ApiKeyProvider.js.map +1 -1
- package/features/security/apiKeys/shared/ApiKeysRepository.d.ts +1 -0
- package/features/security/apiKeys/shared/ApiKeysRepository.js +19 -4
- package/features/security/apiKeys/shared/ApiKeysRepository.js.map +1 -1
- package/features/security/apiKeys/shared/generateToken.d.ts +1 -1
- package/features/security/apiKeys/shared/generateToken.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/apiKeys/shared/types.d.ts +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +4 -4
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js +5 -5
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.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/Installer/RolesInstaller.js +0 -1
- package/features/security/roles/Installer/RolesInstaller.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/security/utils/getPermissionsFromRoles.d.ts +1 -1
- package/features/serviceDiscovery/ServiceDiscovery.d.ts +17 -0
- package/features/serviceDiscovery/ServiceDiscovery.js +22 -0
- package/features/serviceDiscovery/ServiceDiscovery.js.map +1 -0
- package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.d.ts +1 -0
- package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js +111 -0
- package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js.map +1 -0
- package/features/serviceDiscovery/index.d.ts +3 -0
- package/features/serviceDiscovery/index.js +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/storageOperations/abstractions.d.ts +21 -0
- package/features/storageOperations/abstractions.js +10 -0
- package/features/storageOperations/abstractions.js.map +1 -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 +76 -4
- package/features/task/TaskDefinition/abstractions.js +2 -1
- package/features/task/TaskDefinition/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +1 -1
- package/features/tenancy/InstallTenant/InstallTenantUseCase.d.ts +1 -1
- package/features/tenancy/UpdateTenant/UpdateTenantUseCase.d.ts +2 -2
- package/features/users/CreateUser/decorators/CreateUserWithWcpIncrement.d.ts +1 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +10 -5
- package/features/wcp/WcpContext/WcpContext.js +23 -2
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +25 -7
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +57 -25
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpContext/feature.d.ts +1 -2
- package/features/wcp/WcpContext/feature.js +2 -2
- package/features/wcp/WcpContext/feature.js.map +1 -1
- package/features/wcp/WcpContext/index.d.ts +0 -1
- package/features/wcp/WcpContext/types.d.ts +0 -4
- package/features/wcp/WcpFeature.d.ts +1 -1
- package/features/wcp/WcpFeature.js +7 -2
- 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 +21 -0
- package/features/wcp/WcpLicenseProvider.js +14 -0
- package/features/wcp/WcpLicenseProvider.js.map +1 -0
- 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 +15 -0
- package/graphql/ApiCoreSchemaFactory.js +52 -0
- package/graphql/ApiCoreSchemaFactory.js.map +1 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +9 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +49 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -0
- package/graphql/security/NotAuthorizedResponse.d.ts +1 -1
- package/graphql/security/NotAuthorizedResponse.js +1 -1
- package/graphql/security/NotAuthorizedResponse.js.map +1 -1
- package/graphql/security/SecuritySchemaFactory.d.ts +14 -0
- package/graphql/security/SecuritySchemaFactory.js +23 -0
- package/graphql/security/SecuritySchemaFactory.js.map +1 -0
- package/graphql/security/addApiKeySchema.d.ts +2 -0
- package/graphql/security/{apiKey.gql.js → addApiKeySchema.js} +45 -27
- package/graphql/security/addApiKeySchema.js.map +1 -0
- package/graphql/security/addIdentitySchema.d.ts +2 -0
- package/graphql/security/{identity.gql.js → addIdentitySchema.js} +52 -35
- package/graphql/security/addIdentitySchema.js.map +1 -0
- package/graphql/security/addRoleSchema.d.ts +2 -0
- package/graphql/security/addRoleSchema.js +137 -0
- package/graphql/security/addRoleSchema.js.map +1 -0
- package/graphql/security/addSecurityBaseSchema.d.ts +2 -0
- package/graphql/security/{base.gql.js → addSecurityBaseSchema.js} +14 -16
- package/graphql/security/addSecurityBaseSchema.js.map +1 -0
- package/graphql/security/addTeamSchema.d.ts +2 -0
- package/graphql/security/addTeamSchema.js +157 -0
- package/graphql/security/addTeamSchema.js.map +1 -0
- package/graphql/system/SystemSchemaFactory.d.ts +9 -0
- package/graphql/system/SystemSchemaFactory.js +66 -0
- package/graphql/system/SystemSchemaFactory.js.map +1 -0
- package/graphql/users/UsersSchemaFactory.d.ts +9 -0
- package/graphql/users/UsersSchemaFactory.js +191 -0
- package/graphql/users/UsersSchemaFactory.js.map +1 -0
- package/graphql/wcp/WcpSchemaFactory.d.ts +9 -0
- package/graphql/wcp/{graphql.js → WcpSchemaFactory.js} +28 -18
- package/graphql/wcp/WcpSchemaFactory.js.map +1 -0
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/package.json +21 -24
- package/testing/environment.d.ts +14 -0
- package/testing/environment.js +18 -0
- package/testing/environment.js.map +1 -0
- package/types/core.d.ts +17 -5
- package/types/security.d.ts +1 -7
- package/types/tenancy.d.ts +0 -17
- package/types/users.d.ts +0 -13
- package/createApiCore.d.ts +0 -7
- package/createApiCore.js +0 -22
- package/createApiCore.js.map +0 -1
- package/features/ai/AiModelRegistry.d.ts +0 -12
- package/features/ai/AiModelRegistry.js +0 -28
- package/features/ai/AiModelRegistry.js.map +0 -1
- package/graphql/security/apiKey.gql.d.ts +0 -4
- package/graphql/security/apiKey.gql.js.map +0 -1
- package/graphql/security/base.gql.d.ts +0 -4
- package/graphql/security/base.gql.js.map +0 -1
- package/graphql/security/identity.gql.d.ts +0 -4
- package/graphql/security/identity.gql.js.map +0 -1
- package/graphql/security/index.d.ts +0 -1
- package/graphql/security/index.js +0 -15
- package/graphql/security/index.js.map +0 -1
- package/graphql/security/role.gql.d.ts +0 -4
- package/graphql/security/role.gql.js +0 -106
- package/graphql/security/role.gql.js.map +0 -1
- package/graphql/security/team.gql.d.ts +0 -4
- package/graphql/security/team.gql.js +0 -119
- package/graphql/security/team.gql.js.map +0 -1
- package/graphql/system/createSystemGraphQL.d.ts +0 -2
- package/graphql/system/createSystemGraphQL.js +0 -54
- package/graphql/system/createSystemGraphQL.js.map +0 -1
- package/graphql/users/user.gql.d.ts +0 -3
- package/graphql/users/user.gql.js +0 -167
- package/graphql/users/user.gql.js.map +0 -1
- package/graphql/wcp/graphql.d.ts +0 -2
- package/graphql/wcp/graphql.js.map +0 -1
- package/legacy/security/LegacyContext.d.ts +0 -36
- package/legacy/security/LegacyContext.js +0 -152
- package/legacy/security/LegacyContext.js.map +0 -1
- package/legacy/security/createSecurityContext.d.ts +0 -3
- package/legacy/security/createSecurityContext.js +0 -10
- package/legacy/security/createSecurityContext.js.map +0 -1
- package/legacy/security/plugins/apiKeyAuthentication.d.ts +0 -7
- package/legacy/security/plugins/apiKeyAuthentication.js +0 -20
- package/legacy/security/plugins/apiKeyAuthentication.js.map +0 -1
- package/legacy/security/plugins/apiKeyAuthorization.d.ts +0 -6
- package/legacy/security/plugins/apiKeyAuthorization.js +0 -13
- package/legacy/security/plugins/apiKeyAuthorization.js.map +0 -1
- package/legacy/security/plugins/authenticateUsingCookie.d.ts +0 -5
- package/legacy/security/plugins/authenticateUsingCookie.js +0 -23
- package/legacy/security/plugins/authenticateUsingCookie.js.map +0 -1
- package/legacy/security/plugins/authenticateUsingHttpHeader.d.ts +0 -5
- package/legacy/security/plugins/authenticateUsingHttpHeader.js +0 -20
- package/legacy/security/plugins/authenticateUsingHttpHeader.js.map +0 -1
- package/legacy/security/plugins/secureHeaders.d.ts +0 -1
- package/legacy/security/plugins/secureHeaders.js +0 -30
- package/legacy/security/plugins/secureHeaders.js.map +0 -1
- package/legacy/tenancy/LegacyContext.d.ts +0 -15
- package/legacy/tenancy/LegacyContext.js +0 -57
- package/legacy/tenancy/LegacyContext.js.map +0 -1
- package/legacy/tenancy/createTenancyContext.d.ts +0 -3
- package/legacy/tenancy/createTenancyContext.js +0 -31
- package/legacy/tenancy/createTenancyContext.js.map +0 -1
- package/legacy/users/LegacyContext.d.ts +0 -13
- package/legacy/users/LegacyContext.js +0 -55
- package/legacy/users/LegacyContext.js.map +0 -1
- package/legacy/users/createAdminUsersContext.d.ts +0 -3
- package/legacy/users/createAdminUsersContext.js +0 -12
- package/legacy/users/createAdminUsersContext.js.map +0 -1
- package/legacy/wcp/LegacyWcpContext.d.ts +0 -33
- package/legacy/wcp/LegacyWcpContext.js +0 -84
- package/legacy/wcp/LegacyWcpContext.js.map +0 -1
- package/legacy/wcp/context.d.ts +0 -5
- package/legacy/wcp/context.js +0 -46
- package/legacy/wcp/context.js.map +0 -1
|
@@ -2,12 +2,12 @@ import { IdentityContext as Abstraction } from "./abstractions.js";
|
|
|
2
2
|
import { Identity } from "./Identity.js";
|
|
3
3
|
import { AuthorizationContext } from "../authorization/AuthorizationContext/index.js";
|
|
4
4
|
import type { SecurityPermission } from "../../../types/security.js";
|
|
5
|
-
import {
|
|
5
|
+
import { FeatureFlags } from "../../featureFlags/abstractions.js";
|
|
6
6
|
declare class IdentityContextImpl implements Abstraction.Interface {
|
|
7
7
|
private authorizationContext;
|
|
8
|
-
private
|
|
8
|
+
private featureFlags;
|
|
9
9
|
private identity;
|
|
10
|
-
constructor(authorizationContext: AuthorizationContext.Interface,
|
|
10
|
+
constructor(authorizationContext: AuthorizationContext.Interface, featureFlags: FeatureFlags.Interface);
|
|
11
11
|
getIdentity(): Identity;
|
|
12
12
|
setIdentity(identity: Identity | undefined): void;
|
|
13
13
|
withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;
|
|
@@ -5,12 +5,12 @@ import { IdentityContext } from "./abstractions.js";
|
|
|
5
5
|
import { AnonymousIdentity } from "./AnonymousIdentity.js";
|
|
6
6
|
import { AuthorizationContext } from "../authorization/AuthorizationContext/index.js";
|
|
7
7
|
import { filterOutCustomWbyAppsPermissions } from "../utils/filterOutCustomWbyAppsPermissions.js";
|
|
8
|
-
import {
|
|
8
|
+
import { FeatureFlags } from "../../featureFlags/abstractions.js";
|
|
9
9
|
const identityStorage = new AsyncLocalStorage();
|
|
10
10
|
class IdentityContextImpl {
|
|
11
|
-
constructor(authorizationContext,
|
|
11
|
+
constructor(authorizationContext, featureFlags){
|
|
12
12
|
this.authorizationContext = authorizationContext;
|
|
13
|
-
this.
|
|
13
|
+
this.featureFlags = featureFlags;
|
|
14
14
|
this.identity = new AnonymousIdentity();
|
|
15
15
|
}
|
|
16
16
|
getIdentity() {
|
|
@@ -63,8 +63,8 @@ class IdentityContextImpl {
|
|
|
63
63
|
return permissions.some((p)=>"*" === p.name);
|
|
64
64
|
}
|
|
65
65
|
applyAaclLogic(permissions) {
|
|
66
|
-
const aaclEnabled = this.
|
|
67
|
-
const teamsEnabled = this.
|
|
66
|
+
const aaclEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer");
|
|
67
|
+
const teamsEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams");
|
|
68
68
|
if (aaclEnabled) return [
|
|
69
69
|
...permissions,
|
|
70
70
|
{
|
|
@@ -80,7 +80,7 @@ const IdentityContext_IdentityContext = createImplementation({
|
|
|
80
80
|
implementation: IdentityContextImpl,
|
|
81
81
|
dependencies: [
|
|
82
82
|
AuthorizationContext,
|
|
83
|
-
|
|
83
|
+
FeatureFlags
|
|
84
84
|
]
|
|
85
85
|
});
|
|
86
86
|
export { IdentityContext_IdentityContext as IdentityContext };
|
|
@@ -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,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aAJJ,QAAQ,GAAa,IAAIC;IAK9B;IAMH,cAAwB;QAEpB,MAAMC,WAAWN,gBAAgB,QAAQ;QACzC,IAAIM,AAAaC,WAAbD,UACA,OAAOA;QAEX,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,YAAYE,QAA8B,EAAQ;QAE9C,IAAI,CAAC,QAAQ,GAAGA,YAAY,IAAIH;QAGhC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB;IACnD;IAEA,aAAgBG,QAA8B,EAAEC,EAAoB,EAAc;QAC9E,OAAOT,gBAAgB,GAAG,CAACQ,UAAUC;IACzC;IAMA,qBAAwBA,EAAoB,EAAc;QACtD,OAAO,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAACA;IAC1D;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,oBAAoB,CAAC,sBAAsB;IAC3D;IAMA,MAAM,cACFC,IAAY,EACe;QAC3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAE,MAAM;QAAI;QAGvB,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAG9C,MAAMC,aAAaD,YAAY,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKH;QACpD,IAAIE,YACA,OAAOA;QAIX,MAAME,eAAeH,YAAY,IAAI,CAACE,CAAAA,IAAKE,UAAUL,MAAMG,EAAE,IAAI;QACjE,IAAIC,cACA,OAAOA;QAGX,OAAO;IACX;IAEA,MAAM,eACFJ,IAAY,EACU;QACtB,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAC;gBAAE,MAAM;YAAI;SAAE;QAG1B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAE9C,OAAOA,YAAY,MAAM,CAACE,CAAAA;YACtB,IAAIA,EAAE,IAAI,KAAKH,MACX,OAAO;YAEX,OAAOK,UAAUL,MAAMG,EAAE,IAAI;QACjC;IACJ;IAEA,MAAM,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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger } from "../../../features/logger/index.js";
|
|
2
|
+
import type { IAuthenticator } from "../../../features/security/authentication/Authenticator/abstractions.js";
|
|
3
|
+
import type { IApiKeysRepository } from "./shared/abstractions.js";
|
|
4
|
+
import type { IdentityData } from "../../../features/security/IdentityContext/Identity.js";
|
|
5
|
+
declare class ApiKeyAuthenticatorImpl implements IAuthenticator {
|
|
6
|
+
private repository;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(repository: IApiKeysRepository, logger: Logger.Interface);
|
|
9
|
+
authenticate(token: string): Promise<IdentityData | null>;
|
|
10
|
+
}
|
|
11
|
+
export declare const ApiKeyAuthenticator: typeof ApiKeyAuthenticatorImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<IAuthenticator>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Authenticator } from "../authentication/Authenticator/abstractions.js";
|
|
2
|
+
import { ApiKeysRepository } from "./shared/abstractions.js";
|
|
3
|
+
import { Logger } from "../../logger/index.js";
|
|
4
|
+
class ApiKeyAuthenticatorImpl {
|
|
5
|
+
constructor(repository, logger){
|
|
6
|
+
this.repository = repository;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
async authenticate(token) {
|
|
10
|
+
if ("string" != typeof token || !token.startsWith("wat_")) return null;
|
|
11
|
+
const result = await this.repository.getByToken(token);
|
|
12
|
+
if (!result.isOk()) {
|
|
13
|
+
this.logger.warn({
|
|
14
|
+
error: result.error
|
|
15
|
+
}, "API key authentication failed; request will proceed as anonymous.");
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const apiKey = result.value;
|
|
19
|
+
return {
|
|
20
|
+
id: apiKey.id,
|
|
21
|
+
displayName: apiKey.name,
|
|
22
|
+
type: "api-key",
|
|
23
|
+
permissions: apiKey.permissions
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const ApiKeyAuthenticator = Authenticator.createImplementation({
|
|
28
|
+
implementation: ApiKeyAuthenticatorImpl,
|
|
29
|
+
dependencies: [
|
|
30
|
+
ApiKeysRepository,
|
|
31
|
+
Logger
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
export { ApiKeyAuthenticator };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=ApiKeyAuthenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/ApiKeyAuthenticator.js","sources":["../../../../src/features/security/apiKeys/ApiKeyAuthenticator.ts"],"sourcesContent":["import { Authenticator } from \"~/features/security/authentication/Authenticator/abstractions.js\";\nimport { ApiKeysRepository } from \"./shared/abstractions.js\";\nimport { Logger } from \"~/features/logger/index.js\";\nimport type { IAuthenticator } from \"~/features/security/authentication/Authenticator/abstractions.js\";\nimport type { IApiKeysRepository } from \"./shared/abstractions.js\";\nimport type { IdentityData } from \"~/features/security/IdentityContext/Identity.js\";\n\nclass ApiKeyAuthenticatorImpl implements IAuthenticator {\n constructor(\n private repository: IApiKeysRepository,\n private logger: Logger.Interface\n ) {}\n\n async authenticate(token: string): Promise<IdentityData | null> {\n if (typeof token !== \"string\" || !token.startsWith(\"wat_\")) {\n return null;\n }\n const result = await this.repository.getByToken(token);\n if (!result.isOk()) {\n // The token looked like an API key (\"wat_\") but could not be resolved. Log it — otherwise\n // this degrades silently to an anonymous request (which is what made the tenant-ordering\n // bug so hard to find). A genuine unknown/revoked key logs here too, which is acceptable.\n this.logger.warn(\n { error: result.error },\n \"API key authentication failed; request will proceed as anonymous.\"\n );\n return null;\n }\n const apiKey = result.value;\n return {\n id: apiKey.id,\n displayName: apiKey.name,\n type: \"api-key\",\n permissions: apiKey.permissions\n };\n }\n}\n\nexport const ApiKeyAuthenticator = Authenticator.createImplementation({\n implementation: ApiKeyAuthenticatorImpl,\n dependencies: [ApiKeysRepository, Logger]\n});\n"],"names":["ApiKeyAuthenticatorImpl","repository","logger","token","result","apiKey","ApiKeyAuthenticator","Authenticator","ApiKeysRepository","Logger"],"mappings":";;;AAOA,MAAMA;IACF,YACYC,UAA8B,EAC9BC,MAAwB,CAClC;aAFUD,UAAU,GAAVA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,aAAaC,KAAa,EAAgC;QAC5D,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,CAACA,MAAM,UAAU,CAAC,SAC/C,OAAO;QAEX,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAACD;QAChD,IAAI,CAACC,OAAO,IAAI,IAAI;YAIhB,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ;gBAAE,OAAOA,OAAO,KAAK;YAAC,GACtB;YAEJ,OAAO;QACX;QACA,MAAMC,SAASD,OAAO,KAAK;QAC3B,OAAO;YACH,IAAIC,OAAO,EAAE;YACb,aAAaA,OAAO,IAAI;YACxB,MAAM;YACN,aAAaA,OAAO,WAAW;QACnC;IACJ;AACJ;AAEO,MAAMC,sBAAsBC,cAAc,oBAAoB,CAAC;IAClE,gBAAgBP;IAChB,cAAc;QAACQ;QAAmBC;KAAO;AAC7C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IAuthorizer } from "../../../features/security/authorization/Authorizer/abstractions.js";
|
|
2
|
+
import type { Identity } from "../../../features/security/IdentityContext/Identity.js";
|
|
3
|
+
import type { SecurityPermission } from "../../../types/security.js";
|
|
4
|
+
declare class ApiKeyAuthorizerImpl implements IAuthorizer {
|
|
5
|
+
authorize(identity: Identity): Promise<SecurityPermission[] | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const ApiKeyAuthorizer: typeof ApiKeyAuthorizerImpl & {
|
|
8
|
+
__abstraction: import("@webiny/di").Abstraction<IAuthorizer>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Authorizer } from "../authorization/Authorizer/abstractions.js";
|
|
2
|
+
class ApiKeyAuthorizerImpl {
|
|
3
|
+
async authorize(identity) {
|
|
4
|
+
if (!identity || "api-key" !== identity.type) return null;
|
|
5
|
+
const permissions = identity.permissions;
|
|
6
|
+
return Array.isArray(permissions) ? permissions : [];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const ApiKeyAuthorizer = Authorizer.createImplementation({
|
|
10
|
+
implementation: ApiKeyAuthorizerImpl,
|
|
11
|
+
dependencies: []
|
|
12
|
+
});
|
|
13
|
+
export { ApiKeyAuthorizer };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=ApiKeyAuthorizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/ApiKeyAuthorizer.js","sources":["../../../../src/features/security/apiKeys/ApiKeyAuthorizer.ts"],"sourcesContent":["import { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { IAuthorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { Identity } from \"~/features/security/IdentityContext/Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nclass ApiKeyAuthorizerImpl implements IAuthorizer {\n async authorize(identity: Identity): Promise<SecurityPermission[] | null> {\n if (!identity || identity.type !== \"api-key\") {\n return null;\n }\n const permissions = (identity as any).permissions;\n return Array.isArray(permissions) ? (permissions as SecurityPermission[]) : [];\n }\n}\n\nexport const ApiKeyAuthorizer = Authorizer.createImplementation({\n implementation: ApiKeyAuthorizerImpl,\n dependencies: []\n});\n"],"names":["ApiKeyAuthorizerImpl","identity","permissions","Array","ApiKeyAuthorizer","Authorizer"],"mappings":";AAKA,MAAMA;IACF,MAAM,UAAUC,QAAkB,EAAwC;QACtE,IAAI,CAACA,YAAYA,AAAkB,cAAlBA,SAAS,IAAI,EAC1B,OAAO;QAEX,MAAMC,cAAeD,SAAiB,WAAW;QACjD,OAAOE,MAAM,OAAO,CAACD,eAAgBA,cAAuC,EAAE;IAClF;AACJ;AAEO,MAAME,mBAAmBC,WAAW,oBAAoB,CAAC;IAC5D,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -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"}
|
|
@@ -7,7 +7,7 @@ declare class GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interf
|
|
|
7
7
|
private repository;
|
|
8
8
|
private identityContext;
|
|
9
9
|
constructor(repository: ApiKeysRepository.Interface, identityContext: IdentityContext.Interface);
|
|
10
|
-
execute(id: string): Promise<Result<ApiKey
|
|
10
|
+
execute(id: string): Promise<Result<ApiKey, GetApiKeyUseCaseAbstraction.Error>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const GetApiKeyUseCase: typeof GetApiKeyUseCaseImpl & {
|
|
13
13
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKey>;
|
|
@@ -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 { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.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<ApiKey
|
|
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 { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.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<ApiKey, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n return this.repository.get(id);\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","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAA8D;QAClF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;IAC/B;AACJ;AAEO,MAAMI,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAmBC;KAAgB;AACtD"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { Result } from "@webiny/feature/api";
|
|
2
1
|
import { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from "./abstractions.js";
|
|
3
2
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
|
-
import type { ApiKey } from "../shared/types.js";
|
|
5
3
|
declare class GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {
|
|
6
4
|
private repository;
|
|
7
5
|
constructor(repository: ApiKeysRepository.Interface);
|
|
8
|
-
execute(slug: string): Promise<Result<ApiKey |
|
|
6
|
+
execute(slug: string): Promise<import("@webiny/feature/api/Result.js").Result<import("../shared/types.js").ApiKey, import("../shared/errors.js").ApiKeyNotFoundError | import("../shared/errors.js").ApiKeyPersistenceError | import("../shared/errors.js").ApiKeyValidationError>>;
|
|
9
7
|
}
|
|
10
8
|
export declare const GetApiKeyBySlugUseCase: typeof GetApiKeyBySlugUseCaseImpl & {
|
|
11
9
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKeyBySlug>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.ts"],"sourcesContent":["import { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nclass GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {\n constructor(private repository: ApiKeysRepository.Interface) {}\n\n async execute(slug: string) {\n return this.repository.getBySlug(slug);\n }\n}\n\nexport const GetApiKeyBySlugUseCase = GetApiKeyBySlugUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyBySlugUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyBySlugUseCaseImpl","repository","slug","GetApiKeyBySlugUseCase","GetApiKeyBySlugUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,IAAY,EAAE;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAACA;IACrC;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAAsD,CAAC;IACzF,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
|
|
@@ -5,7 +5,7 @@ export interface IGetApiKeyBySlugErrors {
|
|
|
5
5
|
}
|
|
6
6
|
type GetApiKeyBySlugError = IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors] | ApiKeysRepository.Error;
|
|
7
7
|
export interface IGetApiKeyBySlug {
|
|
8
|
-
execute(slug: string): Promise<Result<ApiKey
|
|
8
|
+
execute(slug: string): Promise<Result<ApiKey, GetApiKeyBySlugError>>;
|
|
9
9
|
}
|
|
10
10
|
/** Retrieve an API key by its slug. */
|
|
11
11
|
export declare const GetApiKeyBySlugUseCase: import("@webiny/di").Abstraction<IGetApiKeyBySlug>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyBySlugErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyBySlugError =\n | IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyBySlug {\n execute(slug: string): Promise<Result<ApiKey
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyBySlugErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyBySlugError =\n | IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyBySlug {\n execute(slug: string): Promise<Result<ApiKey, GetApiKeyBySlugError>>;\n}\n\n/** Retrieve an API key by its slug. */\nexport const GetApiKeyBySlugUseCase = createAbstraction<IGetApiKeyBySlug>(\"GetApiKeyBySlugUseCase\");\n\nexport namespace GetApiKeyBySlugUseCase {\n export type Interface = IGetApiKeyBySlug;\n export type Error = GetApiKeyBySlugError;\n}\n"],"names":["GetApiKeyBySlugUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,yBAAyBC,kBAAoC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { Result } from "@webiny/feature/api";
|
|
2
1
|
import { GetApiKeyByTokenUseCase as GetApiKeyByTokenUseCaseAbstraction } from "./abstractions.js";
|
|
3
2
|
import { ApiKeysRepository } from "../shared/abstractions.js";
|
|
4
|
-
import type { ApiKey } from "../shared/types.js";
|
|
5
3
|
declare class GetApiKeyByTokenUseCaseImpl implements GetApiKeyByTokenUseCaseAbstraction.Interface {
|
|
6
4
|
private repository;
|
|
7
5
|
constructor(repository: ApiKeysRepository.Interface);
|
|
8
|
-
execute(token: string): Promise<Result<ApiKey |
|
|
6
|
+
execute(token: string): Promise<import("@webiny/feature/api/Result.js").Result<import("../shared/types.js").ApiKey, import("../shared/errors.js").ApiKeyNotFoundError | import("../shared/errors.js").ApiKeyPersistenceError | import("../shared/errors.js").ApiKeyValidationError>>;
|
|
9
7
|
}
|
|
10
8
|
export declare const GetApiKeyByTokenUseCase: typeof GetApiKeyByTokenUseCaseImpl & {
|
|
11
9
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKeyByToken>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.ts"],"sourcesContent":["import { GetApiKeyByTokenUseCase as GetApiKeyByTokenUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nclass GetApiKeyByTokenUseCaseImpl implements GetApiKeyByTokenUseCaseAbstraction.Interface {\n constructor(private repository: ApiKeysRepository.Interface) {}\n\n async execute(token: string) {\n return this.repository.getByToken(token);\n }\n}\n\nexport const GetApiKeyByTokenUseCase = GetApiKeyByTokenUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyByTokenUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyByTokenUseCaseImpl","repository","token","GetApiKeyByTokenUseCase","GetApiKeyByTokenUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,KAAa,EAAE;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAACA;IACtC;AACJ;AAEO,MAAMC,kDAA0BC,wBAAAA,oBAAuD,CAAC;IAC3F,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
|
|
@@ -5,7 +5,7 @@ export interface IGetApiKeyByTokenErrors {
|
|
|
5
5
|
}
|
|
6
6
|
type GetApiKeyByTokenError = IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors] | ApiKeysRepository.Error;
|
|
7
7
|
export interface IGetApiKeyByToken {
|
|
8
|
-
execute(token: string): Promise<Result<ApiKey
|
|
8
|
+
execute(token: string): Promise<Result<ApiKey, GetApiKeyByTokenError>>;
|
|
9
9
|
}
|
|
10
10
|
/** Retrieve an API key by its token value. */
|
|
11
11
|
export declare const GetApiKeyByTokenUseCase: import("@webiny/di").Abstraction<IGetApiKeyByToken>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyByTokenErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyByTokenError =\n | IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyByToken {\n execute(token: string): Promise<Result<ApiKey
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyByTokenErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyByTokenError =\n | IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyByToken {\n execute(token: string): Promise<Result<ApiKey, GetApiKeyByTokenError>>;\n}\n\n/** Retrieve an API key by its token value. */\nexport const GetApiKeyByTokenUseCase =\n createAbstraction<IGetApiKeyByToken>(\"GetApiKeyByTokenUseCase\");\n\nexport namespace GetApiKeyByTokenUseCase {\n export type Interface = IGetApiKeyByToken;\n export type Error = GetApiKeyByTokenError;\n}\n"],"names":["GetApiKeyByTokenUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,0BACTC,kBAAqC"}
|
|
@@ -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,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;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,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACR;QACjD,IAAIQ,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,iBAAiBD,eAAe,KAAK;QAK3C,MAAM,EAAEE,WAAW,EAAE,GAAGC,MAAM,GAAGN,WAAW,IAAI;QAEhD,MAAMO,UAA6B;YAC/B,GAAGD,IAAI;YACP,GAAGE,oBAAoBH,YAAY;QACvC;QAEA,MAAMI,gBAAwB;YAC1B,GAAGL,cAAc;YACjB,GAAGG,OAAO;QACd;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,wBAAwB;YACxB,UAAUN;YACV,SAASK;YACT,OAAOF;QACX;QAGJ,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOb,OAAO,IAAI,CAACa,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YACvB,UAAUR;YACV,SAASK;YACT,OAAOF;QACX;QAGJ,OAAOT,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAMI,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBvB;IAChB,cAAc;QAACwB;QAAmBC;QAAiBC;KAAe;AACtE"}
|
|
@@ -7,12 +7,21 @@ import { ListApiKeysFeature } from "./ListApiKeys/feature.js";
|
|
|
7
7
|
import { CreateApiKeyFeature } from "./CreateApiKey/feature.js";
|
|
8
8
|
import { UpdateApiKeyFeature } from "./UpdateApiKey/feature.js";
|
|
9
9
|
import { DeleteApiKeyFeature } from "./DeleteApiKey/feature.js";
|
|
10
|
-
import { ApiKeyProvider } from "./shared/
|
|
10
|
+
import { ApiKeyFactory, ApiKeyProvider } from "./shared/abstractions.js";
|
|
11
|
+
import { ApiKeyProvider as ApiKeyProvider_js_ApiKeyProvider } from "./shared/ApiKeyProvider.js";
|
|
12
|
+
import { ApiKeyAuthenticator } from "./ApiKeyAuthenticator.js";
|
|
13
|
+
import { ApiKeyAuthorizer } from "./ApiKeyAuthorizer.js";
|
|
14
|
+
import { TenantContext } from "../../tenancy/TenantContext/index.js";
|
|
11
15
|
const ApiKeysFeature = createFeature({
|
|
12
16
|
name: "ApiKeys",
|
|
13
17
|
register (container) {
|
|
14
18
|
container.register(ApiKeysRepository).inSingletonScope();
|
|
15
|
-
container.
|
|
19
|
+
container.registerFactory(ApiKeyProvider, ()=>{
|
|
20
|
+
const tenantContext = container.resolve(TenantContext);
|
|
21
|
+
return new ApiKeyProvider_js_ApiKeyProvider(tenantContext, ()=>container.resolveAll(ApiKeyFactory));
|
|
22
|
+
});
|
|
23
|
+
container.register(ApiKeyAuthenticator);
|
|
24
|
+
container.register(ApiKeyAuthorizer);
|
|
16
25
|
GetApiKeyFeature.register(container);
|
|
17
26
|
GetApiKeyByTokenFeature.register(container);
|
|
18
27
|
GetApiKeyBySlugFeature.register(container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/feature.js","sources":["../../../../src/features/security/apiKeys/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ApiKeysRepository } from \"./shared/ApiKeysRepository.js\";\nimport { GetApiKeyFeature } from \"./GetApiKey/feature.js\";\nimport { GetApiKeyByTokenFeature } from \"./GetApiKeyByToken/feature.js\";\nimport { GetApiKeyBySlugFeature } from \"./GetApiKeyBySlug/feature.js\";\nimport { ListApiKeysFeature } from \"./ListApiKeys/feature.js\";\nimport { CreateApiKeyFeature } from \"./CreateApiKey/feature.js\";\nimport { UpdateApiKeyFeature } from \"./UpdateApiKey/feature.js\";\nimport { DeleteApiKeyFeature } from \"./DeleteApiKey/feature.js\";\nimport { ApiKeyProvider } from \"./shared/ApiKeyProvider.js\";\n\nexport const ApiKeysFeature = createFeature({\n name: \"ApiKeys\",\n register(container) {\n // Register repository in singleton scope\n container.register(ApiKeysRepository).inSingletonScope();\n container.
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/feature.js","sources":["../../../../src/features/security/apiKeys/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ApiKeysRepository } from \"./shared/ApiKeysRepository.js\";\nimport { GetApiKeyFeature } from \"./GetApiKey/feature.js\";\nimport { GetApiKeyByTokenFeature } from \"./GetApiKeyByToken/feature.js\";\nimport { GetApiKeyBySlugFeature } from \"./GetApiKeyBySlug/feature.js\";\nimport { ListApiKeysFeature } from \"./ListApiKeys/feature.js\";\nimport { CreateApiKeyFeature } from \"./CreateApiKey/feature.js\";\nimport { UpdateApiKeyFeature } from \"./UpdateApiKey/feature.js\";\nimport { DeleteApiKeyFeature } from \"./DeleteApiKey/feature.js\";\nimport {\n ApiKeyFactory,\n ApiKeyProvider as ApiKeyProviderAbstraction\n} from \"~/features/security/apiKeys/shared/abstractions.js\";\nimport { ApiKeyProvider } from \"./shared/ApiKeyProvider.js\";\nimport { ApiKeyAuthenticator } from \"./ApiKeyAuthenticator.js\";\nimport { ApiKeyAuthorizer } from \"./ApiKeyAuthorizer.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nexport const ApiKeysFeature = createFeature({\n name: \"ApiKeys\",\n register(container) {\n // Register repository in singleton scope\n container.register(ApiKeysRepository).inSingletonScope();\n\n container.registerFactory(ApiKeyProviderAbstraction, () => {\n const tenantContext = container.resolve(TenantContext);\n return new ApiKeyProvider(tenantContext, () => {\n return container.resolveAll(ApiKeyFactory);\n });\n });\n container.register(ApiKeyAuthenticator);\n container.register(ApiKeyAuthorizer);\n\n // Register all use cases\n GetApiKeyFeature.register(container);\n GetApiKeyByTokenFeature.register(container);\n GetApiKeyBySlugFeature.register(container);\n ListApiKeysFeature.register(container);\n CreateApiKeyFeature.register(container);\n UpdateApiKeyFeature.register(container);\n DeleteApiKeyFeature.register(container);\n }\n});\n"],"names":["ApiKeysFeature","createFeature","container","ApiKeysRepository","ApiKeyProviderAbstraction","tenantContext","TenantContext","ApiKeyProvider","ApiKeyFactory","ApiKeyAuthenticator","ApiKeyAuthorizer","GetApiKeyFeature","GetApiKeyByTokenFeature","GetApiKeyBySlugFeature","ListApiKeysFeature","CreateApiKeyFeature","UpdateApiKeyFeature","DeleteApiKeyFeature"],"mappings":";;;;;;;;;;;;;;AAkBO,MAAMA,iBAAiBC,cAAc;IACxC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,QAAQ,CAACC,mBAAmB,gBAAgB;QAEtDD,UAAU,eAAe,CAACE,gBAA2B;YACjD,MAAMC,gBAAgBH,UAAU,OAAO,CAACI;YACxC,OAAO,IAAIC,iCAAeF,eAAe,IAC9BH,UAAU,UAAU,CAACM;QAEpC;QACAN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QAGnBC,iBAAiB,QAAQ,CAACT;QAC1BU,wBAAwB,QAAQ,CAACV;QACjCW,uBAAuB,QAAQ,CAACX;QAChCY,mBAAmB,QAAQ,CAACZ;QAC5Ba,oBAAoB,QAAQ,CAACb;QAC7Bc,oBAAoB,QAAQ,CAACd;QAC7Be,oBAAoB,QAAQ,CAACf;IACjC;AACJ"}
|
|
@@ -2,14 +2,12 @@ import { TenantContext } from "../../../../features/tenancy/TenantContext/index.
|
|
|
2
2
|
import { ApiKeyFactory } from "./abstractions.js";
|
|
3
3
|
import { ApiKeyProvider as ProviderAbstraction } from "./abstractions.js";
|
|
4
4
|
import type { ApiKey } from "./types.js";
|
|
5
|
-
declare class
|
|
5
|
+
export declare class ApiKeyProvider implements ProviderAbstraction.Interface {
|
|
6
6
|
private tenantContext;
|
|
7
|
-
private
|
|
7
|
+
private getApiKeyFactories;
|
|
8
8
|
private cache;
|
|
9
|
-
constructor(tenantContext: TenantContext.Interface,
|
|
9
|
+
constructor(tenantContext: TenantContext.Interface, getApiKeyFactories: () => ApiKeyFactory.Interface[]);
|
|
10
10
|
getByToken(token: string): Promise<ApiKey | null>;
|
|
11
11
|
getBySlug(slug: string): Promise<ApiKey | null>;
|
|
12
12
|
private getCache;
|
|
13
13
|
}
|
|
14
|
-
export declare const ApiKeyProvider: import("@webiny/di").Implementation<typeof ApiKeyProviderImpl>;
|
|
15
|
-
export {};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
-
import { TenantContext } from "../../../tenancy/TenantContext/index.js";
|
|
3
|
-
import { ApiKeyFactory, ApiKeyProvider } from "./abstractions.js";
|
|
4
1
|
import { SystemIdentityValue } from "../../../../domain/identity/SystemIdentityValue.js";
|
|
5
|
-
class
|
|
6
|
-
constructor(tenantContext,
|
|
2
|
+
class ApiKeyProvider {
|
|
3
|
+
constructor(tenantContext, getApiKeyFactories){
|
|
7
4
|
this.tenantContext = tenantContext;
|
|
8
|
-
this.
|
|
5
|
+
this.getApiKeyFactories = getApiKeyFactories;
|
|
9
6
|
}
|
|
10
7
|
async getByToken(token) {
|
|
11
8
|
const cache = await this.getCache();
|
|
@@ -19,7 +16,8 @@ class ApiKeyProviderImpl {
|
|
|
19
16
|
}
|
|
20
17
|
async getCache() {
|
|
21
18
|
if (void 0 === this.cache) {
|
|
22
|
-
const
|
|
19
|
+
const apiKeyFactories = this.getApiKeyFactories();
|
|
20
|
+
const results = await Promise.all(apiKeyFactories.map((factory)=>factory.execute()));
|
|
23
21
|
this.cache = results.flat().map((codeKey)=>({
|
|
24
22
|
...codeKey,
|
|
25
23
|
id: codeKey.slug,
|
|
@@ -33,19 +31,6 @@ class ApiKeyProviderImpl {
|
|
|
33
31
|
return this.cache;
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
abstraction: ApiKeyProvider,
|
|
38
|
-
implementation: ApiKeyProviderImpl,
|
|
39
|
-
dependencies: [
|
|
40
|
-
TenantContext,
|
|
41
|
-
[
|
|
42
|
-
ApiKeyFactory,
|
|
43
|
-
{
|
|
44
|
-
multiple: true
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
export { ApiKeyProvider_ApiKeyProvider as ApiKeyProvider };
|
|
34
|
+
export { ApiKeyProvider };
|
|
50
35
|
|
|
51
36
|
//# sourceMappingURL=ApiKeyProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/shared/ApiKeyProvider.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeyProvider.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/shared/ApiKeyProvider.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeyProvider.ts"],"sourcesContent":["import { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyFactory } from \"./abstractions.js\";\nimport { ApiKeyProvider as ProviderAbstraction } from \"./abstractions.js\";\nimport type { ApiKey } from \"./types.js\";\nimport { SystemIdentityValue } from \"~/domain/identity/SystemIdentityValue.js\";\n\nexport class ApiKeyProvider implements ProviderAbstraction.Interface {\n private cache: ApiKey[] | undefined;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private getApiKeyFactories: () => ApiKeyFactory.Interface[]\n ) {}\n\n async getByToken(token: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.token === token);\n return apiKey || null;\n }\n\n async getBySlug(slug: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.slug === slug);\n return apiKey || null;\n }\n\n private async getCache(): Promise<ApiKey[]> {\n if (this.cache === undefined) {\n const apiKeyFactories = this.getApiKeyFactories();\n const results = await Promise.all(apiKeyFactories.map(factory => factory.execute()));\n this.cache = results.flat().map<ApiKey>(codeKey => {\n return {\n ...codeKey,\n id: codeKey.slug,\n slug: codeKey.slug,\n description: \"\",\n tenant: this.tenantContext.getTenant().id,\n createdOn: new Date().toISOString(),\n createdBy: SystemIdentityValue.create()\n };\n });\n }\n\n return this.cache;\n }\n}\n"],"names":["ApiKeyProvider","tenantContext","getApiKeyFactories","token","cache","apiKey","key","slug","undefined","apiKeyFactories","results","Promise","factory","codeKey","Date","SystemIdentityValue"],"mappings":";AAMO,MAAMA;IAGT,YACYC,aAAsC,EACtCC,kBAAmD,CAC7D;aAFUD,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,WAAWC,KAAa,EAA0B;QACpD,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,KAAK,KAAKH;QAC/C,OAAOE,UAAU;IACrB;IAEA,MAAM,UAAUE,IAAY,EAA0B;QAClD,MAAMH,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,IAAI,KAAKC;QAC9C,OAAOF,UAAU;IACrB;IAEA,MAAc,WAA8B;QACxC,IAAI,AAAeG,WAAf,IAAI,CAAC,KAAK,EAAgB;YAC1B,MAAMC,kBAAkB,IAAI,CAAC,kBAAkB;YAC/C,MAAMC,UAAU,MAAMC,QAAQ,GAAG,CAACF,gBAAgB,GAAG,CAACG,CAAAA,UAAWA,QAAQ,OAAO;YAChF,IAAI,CAAC,KAAK,GAAGF,QAAQ,IAAI,GAAG,GAAG,CAASG,CAAAA,UAC7B;oBACH,GAAGA,OAAO;oBACV,IAAIA,QAAQ,IAAI;oBAChB,MAAMA,QAAQ,IAAI;oBAClB,aAAa;oBACb,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;oBACzC,WAAW,IAAIC,OAAO,WAAW;oBACjC,WAAWC,oBAAoB,MAAM;gBACzC;QAER;QAEA,OAAO,IAAI,CAAC,KAAK;IACrB;AACJ"}
|
|
@@ -8,6 +8,7 @@ declare class ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
|
8
8
|
private tenantContext;
|
|
9
9
|
private storageOperations;
|
|
10
10
|
private apiKeyProvider;
|
|
11
|
+
private resolving;
|
|
11
12
|
constructor(tenantContext: TenantContext.Interface, storageOperations: SecurityStorageOperations.Interface, apiKeyProvider: ApiKeyProvider.Interface);
|
|
12
13
|
get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>>;
|
|
13
14
|
getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>>;
|