@webiny/api-core 6.6.0-alpha.0 → 6.6.0-alpha.10
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 +12 -2
- 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/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 +5 -1
- package/features/ai/Ai.js +72 -29
- 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 +24 -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 +67 -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/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 +102 -7
- package/features/ai/abstractions.js +6 -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 +12 -0
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +5 -3
- package/features/ai/index.js +3 -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/debugger/Debugger.d.ts +30 -0
- package/features/debugger/Debugger.js +142 -0
- package/features/debugger/Debugger.js.map +1 -0
- package/features/debugger/DebuggerRouteDecorator.d.ts +45 -0
- package/features/debugger/DebuggerRouteDecorator.js +102 -0
- package/features/debugger/DebuggerRouteDecorator.js.map +1 -0
- package/features/debugger/GraphQLDebuggerTransport.d.ts +28 -0
- package/features/debugger/GraphQLDebuggerTransport.js +45 -0
- package/features/debugger/GraphQLDebuggerTransport.js.map +1 -0
- package/features/debugger/__tests__/matchNamespace.test.d.ts +1 -0
- package/features/debugger/__tests__/matchNamespace.test.js +68 -0
- package/features/debugger/__tests__/matchNamespace.test.js.map +1 -0
- package/features/debugger/__tests__/serialize.test.d.ts +1 -0
- package/features/debugger/__tests__/serialize.test.js +220 -0
- package/features/debugger/__tests__/serialize.test.js.map +1 -0
- package/features/debugger/abstractions.d.ts +100 -0
- package/features/debugger/abstractions.js +6 -0
- package/features/debugger/abstractions.js.map +1 -0
- package/features/debugger/feature.d.ts +5 -0
- package/features/debugger/feature.js +15 -0
- package/features/debugger/feature.js.map +1 -0
- package/features/debugger/index.d.ts +12 -0
- package/features/debugger/index.js +7 -0
- package/features/debugger/limits.d.ts +18 -0
- package/features/debugger/limits.js +11 -0
- package/features/debugger/limits.js.map +1 -0
- package/features/debugger/matchNamespace.d.ts +14 -0
- package/features/debugger/matchNamespace.js +35 -0
- package/features/debugger/matchNamespace.js.map +1 -0
- package/features/debugger/parseNamespaceHeader.d.ts +7 -0
- package/features/debugger/parseNamespaceHeader.js +16 -0
- package/features/debugger/parseNamespaceHeader.js.map +1 -0
- package/features/debugger/permissions.d.ts +14 -0
- package/features/debugger/permissions.js +8 -0
- package/features/debugger/permissions.js.map +1 -0
- package/features/debugger/permissionsSchema.d.ts +17 -0
- package/features/debugger/permissionsSchema.js +18 -0
- package/features/debugger/permissionsSchema.js.map +1 -0
- package/features/debugger/serialize.d.ts +11 -0
- package/features/debugger/serialize.js +121 -0
- package/features/debugger/serialize.js.map +1 -0
- package/features/encryption/BuildParamsEncryptionConfig.d.ts +13 -0
- package/features/encryption/BuildParamsEncryptionConfig.js +19 -0
- package/features/encryption/BuildParamsEncryptionConfig.js.map +1 -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 +3 -2
- package/features/encryption/EncryptionService.js +15 -13
- 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 +26 -0
- package/features/encryption/abstractions.js +3 -1
- package/features/encryption/abstractions.js.map +1 -1
- package/features/encryption/feature.js +2 -0
- package/features/encryption/feature.js.map +1 -1
- package/features/encryption/index.d.ts +3 -0
- package/features/encryption/index.js +3 -1
- 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/hashing/BuildParamsHashingConfig.d.ts +11 -0
- package/features/hashing/BuildParamsHashingConfig.js +18 -0
- package/features/hashing/BuildParamsHashingConfig.js.map +1 -0
- package/features/hashing/ScryptHasher.d.ts +2 -2
- package/features/hashing/ScryptHasher.js +6 -8
- package/features/hashing/ScryptHasher.js.map +1 -1
- package/features/hashing/abstractions.d.ts +15 -0
- package/features/hashing/abstractions.js +2 -1
- package/features/hashing/abstractions.js.map +1 -1
- package/features/hashing/feature.js +2 -0
- package/features/hashing/feature.js.map +1 -1
- package/features/hashing/index.d.ts +1 -0
- package/features/hashing/index.js +1 -1
- 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/keyValueStore/GlobalKeyValueStore.d.ts +9 -3
- package/features/keyValueStore/GlobalKeyValueStore.js +12 -2
- package/features/keyValueStore/GlobalKeyValueStore.js.map +1 -1
- package/features/keyValueStore/KeyValueStore.d.ts +6 -2
- package/features/keyValueStore/KeyValueStore.js +13 -3
- package/features/keyValueStore/KeyValueStore.js.map +1 -1
- package/features/keyValueStore/KeyValueStoreRepository.d.ts +8 -2
- package/features/keyValueStore/KeyValueStoreRepository.js +82 -4
- package/features/keyValueStore/KeyValueStoreRepository.js.map +1 -1
- package/features/keyValueStore/abstractions.d.ts +132 -14
- package/features/keyValueStore/abstractions.js.map +1 -1
- package/features/keyValueStore/errors.d.ts +29 -0
- package/features/keyValueStore/errors.js +49 -1
- package/features/keyValueStore/errors.js.map +1 -1
- package/features/keyValueStore/index.d.ts +4 -1
- package/features/keyValueStore/index.js +1 -1
- package/features/logger/NullLogger.d.ts +10 -0
- package/features/logger/NullLogger.js +12 -0
- package/features/logger/NullLogger.js.map +1 -0
- package/features/logger/index.d.ts +1 -0
- package/features/logger/index.js +1 -0
- package/features/publicUrls/NullPublicUrls.d.ts +11 -0
- package/features/publicUrls/NullPublicUrls.js +17 -0
- package/features/publicUrls/NullPublicUrls.js.map +1 -0
- package/features/publicUrls/PublicUrl.d.ts +24 -0
- package/features/publicUrls/PublicUrl.js +43 -0
- package/features/publicUrls/PublicUrl.js.map +1 -0
- package/features/publicUrls/__tests__/PublicUrl.test.d.ts +1 -0
- package/features/publicUrls/__tests__/PublicUrl.test.js +38 -0
- package/features/publicUrls/__tests__/PublicUrl.test.js.map +1 -0
- package/features/publicUrls/__tests__/PublicUrls.test.d.ts +1 -0
- package/features/publicUrls/__tests__/PublicUrls.test.js +14 -0
- package/features/publicUrls/__tests__/PublicUrls.test.js.map +1 -0
- package/features/publicUrls/abstractions.d.ts +27 -0
- package/features/publicUrls/abstractions.js +5 -0
- package/features/publicUrls/abstractions.js.map +1 -0
- package/features/publicUrls/feature.d.ts +8 -0
- package/features/publicUrls/feature.js +11 -0
- package/features/publicUrls/feature.js.map +1 -0
- package/features/publicUrls/index.d.ts +3 -0
- package/features/publicUrls/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 +8 -4
- package/features/security/IdentityContext/IdentityContext.js +28 -11
- package/features/security/IdentityContext/IdentityContext.js.map +1 -1
- package/features/security/IdentityContext/abstractions.d.ts +6 -1
- package/features/security/IdentityContext/abstractions.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/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 +7 -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/AuthorizationContext/AuthorizationContext.d.ts +13 -3
- package/features/security/authorization/AuthorizationContext/AuthorizationContext.js +35 -22
- package/features/security/authorization/AuthorizationContext/AuthorizationContext.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
- package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
- package/features/security/authorization/AuthorizationContext/feature.js +6 -1
- package/features/security/authorization/AuthorizationContext/feature.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/Installer/RolesInstaller.js +1 -0
- 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/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/{logger → slugify}/feature.d.ts +1 -1
- 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 +5 -1
- package/features/tenancy/TenantContext/TenantContext.js +31 -23
- package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
- package/features/users/shared/loaders.js.map +1 -1
- package/features/users/shared/types.d.ts +9 -7
- package/features/wcp/WcpContext/WcpContext.d.ts +11 -0
- package/features/wcp/WcpContext/WcpContext.js +33 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +14 -60
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +77 -25
- 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 +6 -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 +22 -22
- package/testing/environment.d.ts +14 -0
- package/testing/environment.js +18 -0
- package/testing/environment.js.map +1 -0
- package/types/security.d.ts +1 -1
- package/types/users.d.ts +2 -3
- package/features/logger/LoggerService.d.ts +0 -14
- package/features/logger/LoggerService.js +0 -48
- package/features/logger/LoggerService.js.map +0 -1
- package/features/logger/feature.js +0 -11
- package/features/logger/feature.js.map +0 -1
- 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/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,14 +7,19 @@ 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";
|
|
11
12
|
import { ApiKeyAuthenticator } from "./ApiKeyAuthenticator.js";
|
|
12
13
|
import { ApiKeyAuthorizer } from "./ApiKeyAuthorizer.js";
|
|
14
|
+
import { TenantContext } from "../../tenancy/TenantContext/index.js";
|
|
13
15
|
const ApiKeysFeature = createFeature({
|
|
14
16
|
name: "ApiKeys",
|
|
15
17
|
register (container) {
|
|
16
18
|
container.register(ApiKeysRepository).inSingletonScope();
|
|
17
|
-
container.
|
|
19
|
+
container.registerFactory(ApiKeyProvider, ()=>{
|
|
20
|
+
const tenantContext = container.resolve(TenantContext);
|
|
21
|
+
return new ApiKeyProvider_js_ApiKeyProvider(tenantContext, ()=>container.resolveAll(ApiKeyFactory));
|
|
22
|
+
});
|
|
18
23
|
container.register(ApiKeyAuthenticator);
|
|
19
24
|
container.register(ApiKeyAuthorizer);
|
|
20
25
|
GetApiKeyFeature.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\";\nimport { ApiKeyAuthenticator } from \"./ApiKeyAuthenticator.js\";\nimport { ApiKeyAuthorizer } from \"./ApiKeyAuthorizer.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>>;
|
|
@@ -8,6 +8,7 @@ class ApiKeysRepositoryImpl {
|
|
|
8
8
|
this.tenantContext = tenantContext;
|
|
9
9
|
this.storageOperations = storageOperations;
|
|
10
10
|
this.apiKeyProvider = apiKeyProvider;
|
|
11
|
+
this.resolving = false;
|
|
11
12
|
}
|
|
12
13
|
async get(id) {
|
|
13
14
|
try {
|
|
@@ -30,8 +31,15 @@ class ApiKeysRepositoryImpl {
|
|
|
30
31
|
tenant: tenant.id
|
|
31
32
|
});
|
|
32
33
|
if (apiKey) return Result.ok(apiKey);
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (!this.resolving) {
|
|
35
|
+
this.resolving = true;
|
|
36
|
+
try {
|
|
37
|
+
const factoryApiKey = await this.apiKeyProvider.getByToken(token);
|
|
38
|
+
if (factoryApiKey) return Result.ok(factoryApiKey);
|
|
39
|
+
} finally{
|
|
40
|
+
this.resolving = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
return Result.fail(new ApiKeyNotFoundError());
|
|
36
44
|
} catch (error) {
|
|
37
45
|
return Result.fail(new ApiKeyPersistenceError(error));
|
|
@@ -45,8 +53,15 @@ class ApiKeysRepositoryImpl {
|
|
|
45
53
|
tenant: tenant.id
|
|
46
54
|
});
|
|
47
55
|
if (apiKey) return Result.ok(apiKey);
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
if (!this.resolving) {
|
|
57
|
+
this.resolving = true;
|
|
58
|
+
try {
|
|
59
|
+
const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);
|
|
60
|
+
if (factoryApiKey) return Result.ok(factoryApiKey);
|
|
61
|
+
} finally{
|
|
62
|
+
this.resolving = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
50
65
|
return Result.fail(new ApiKeyNotFoundError());
|
|
51
66
|
} catch (error) {
|
|
52
67
|
return Result.fail(new ApiKeyPersistenceError(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/shared/ApiKeysRepository.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeysRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { ApiKeysRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ApiKeyProvider } from \"./abstractions.js\";\nimport type { ApiKey, ListApiKeysInput } from \"./types.js\";\nimport { SecurityStorageOperations } from \"~/features/security/shared/abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyNotFoundError, ApiKeyPersistenceError, ApiKeyValidationError } from \"./errors.js\";\n\n// TODO: create an ApiKeyMapper\n\nclass ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private storageOperations: SecurityStorageOperations.Interface,\n private apiKeyProvider: ApiKeyProvider.Interface\n ) {}\n\n async get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKey({ id, tenant: tenant.id });\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(error);\n }\n }\n\n async getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/shared/ApiKeysRepository.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeysRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { ApiKeysRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ApiKeyProvider } from \"./abstractions.js\";\nimport type { ApiKey, ListApiKeysInput } from \"./types.js\";\nimport { SecurityStorageOperations } from \"~/features/security/shared/abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyNotFoundError, ApiKeyPersistenceError, ApiKeyValidationError } from \"./errors.js\";\n\n// TODO: create an ApiKeyMapper\n\nclass ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {\n private resolving = false;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private storageOperations: SecurityStorageOperations.Interface,\n private apiKeyProvider: ApiKeyProvider.Interface\n ) {}\n\n async get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKey({ id, tenant: tenant.id });\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(error);\n }\n }\n\n async getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyByToken({\n token,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n if (!this.resolving) {\n this.resolving = true;\n try {\n const factoryApiKey = await this.apiKeyProvider.getByToken(token);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n } finally {\n this.resolving = false;\n }\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async getBySlug(slug: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyBySlug({\n slug,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n if (!this.resolving) {\n this.resolving = true;\n try {\n const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n } finally {\n this.resolving = false;\n }\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async list(params: ListApiKeysInput): Promise<Result<ApiKey[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const result = await this.storageOperations.listApiKeys({\n where: { tenant: tenant.id },\n ...params\n });\n return Result.ok(result);\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async create(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n // Check if an API key with the same slug already exists\n const existingKeyResult = await this.getBySlug(apiKey.slug);\n\n // If we found a key, it's a duplicate slug - return validation error\n if (existingKeyResult.isOk()) {\n return Result.fail(\n new ApiKeyValidationError(`API key with slug \"${apiKey.slug}\" already exists.`)\n );\n }\n\n // \"NotFound\" error is ok. Everything else is not ok.\n if (existingKeyResult.error.code !== \"ApiKey/NotFound\") {\n return Result.fail(existingKeyResult.error);\n }\n\n // Slug is unique, proceed with creation\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.createApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async update(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.updateApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async delete(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.deleteApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n}\n\nexport const ApiKeysRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: ApiKeysRepositoryImpl,\n dependencies: [TenantContext, SecurityStorageOperations, ApiKeyProvider]\n});\n"],"names":["ApiKeysRepositoryImpl","tenantContext","storageOperations","apiKeyProvider","id","tenant","apiKey","Result","ApiKeyNotFoundError","error","token","factoryApiKey","ApiKeyPersistenceError","slug","params","result","existingKeyResult","ApiKeyValidationError","ApiKeysRepository","createImplementation","RepositoryAbstraction","TenantContext","SecurityStorageOperations","ApiKeyProvider"],"mappings":";;;;;AAWA,MAAMA;IAGF,YACYC,aAAsC,EACtCC,iBAAsD,EACtDC,cAAwC,CAClD;aAHUF,aAAa,GAAbA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aALJ,SAAS,GAAG;IAMjB;IAEH,MAAM,IAAIC,EAAU,EAAwD;QACxE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBAAEF;gBAAI,QAAQC,OAAO,EAAE;YAAC;YAC9E,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAGrB,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAACE;QACvB;IACJ;IAEA,MAAM,WAAWC,KAAa,EAAwD;QAClF,IAAI;YACA,MAAML,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC;gBACzDI;gBACA,QAAQL,OAAO,EAAE;YACrB;YAEA,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAGrB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;gBACjB,IAAI,CAAC,SAAS,GAAG;gBACjB,IAAI;oBACA,MAAMK,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACD;oBAC3D,IAAIC,eACA,OAAOJ,OAAO,EAAE,CAACI;gBAEzB,SAAU;oBACN,IAAI,CAAC,SAAS,GAAG;gBACrB;YACJ;YAEA,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,UAAUI,IAAY,EAAwD;QAChF,IAAI;YACA,MAAMR,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC;gBACxDO;gBACA,QAAQR,OAAO,EAAE;YACrB;YAEA,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAGrB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;gBACjB,IAAI,CAAC,SAAS,GAAG;gBACjB,IAAI;oBACA,MAAMK,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAACE;oBAC1D,IAAIF,eACA,OAAOJ,OAAO,EAAE,CAACI;gBAEzB,SAAU;oBACN,IAAI,CAAC,SAAS,GAAG;gBACrB;YACJ;YAEA,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,KAAKK,MAAwB,EAA0D;QACzF,IAAI;YACA,MAAMT,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMU,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC;gBACpD,OAAO;oBAAE,QAAQV,OAAO,EAAE;gBAAC;gBAC3B,GAAGS,MAAM;YACb;YACA,OAAOP,OAAO,EAAE,CAACQ;QACrB,EAAE,OAAON,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,OAAOH,MAAc,EAAsD;QAC7E,IAAI;YAEA,MAAMU,oBAAoB,MAAM,IAAI,CAAC,SAAS,CAACV,OAAO,IAAI;YAG1D,IAAIU,kBAAkB,IAAI,IACtB,OAAOT,OAAO,IAAI,CACd,IAAIU,sBAAsB,CAAC,mBAAmB,EAAEX,OAAO,IAAI,CAAC,iBAAiB,CAAC;YAKtF,IAAIU,AAAiC,sBAAjCA,kBAAkB,KAAK,CAAC,IAAI,EAC5B,OAAOT,OAAO,IAAI,CAACS,kBAAkB,KAAK;YAI9C,MAAMX,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;gBAAE,QAAQ;oBAAE,GAAGC,MAAM;oBAAE,QAAQD,OAAO,EAAE;gBAAC;YAAE;YACrF,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,OAAOH,MAAc,EAAsD;QAC7E,IAAI;YACA,MAAMD,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;gBAAE,QAAQ;oBAAE,GAAGC,MAAM;oBAAE,QAAQD,OAAO,EAAE;gBAAC;YAAE;YAErF,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,OAAOH,MAAc,EAAsD;QAC7E,IAAI;YACA,MAAMD,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;gBAAE,QAAQ;oBAAE,GAAGC,MAAM;oBAAE,QAAQD,OAAO,EAAE;gBAAC;YAAE;YAErF,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;AACJ;AAEO,MAAMS,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAeC;QAA2BC;KAAe;AAC5E"}
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* When authentication plugins kick in, they will be able to tell if they should handle
|
|
5
5
|
* the token by checking the first letter.
|
|
6
6
|
*/
|
|
7
|
-
export declare const generateToken: (tokenLength?: number) => string
|
|
7
|
+
export declare const generateToken: (tokenLength?: number) => `wat_${string}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/apiKeys/shared/generateToken.js","sources":["../../../../../src/features/security/apiKeys/shared/generateToken.ts"],"sourcesContent":["import crypto from \"crypto\";\n\n/**\n * Generates a random token for API keys.\n * API Keys are prefixed with letter \"wat_\" to make token verification easier.\n * When authentication plugins kick in, they will be able to tell if they should handle\n * the token by checking the first letter.\n */\nexport const generateToken = (tokenLength = 40): string => {\n const token = crypto.randomBytes(Math.ceil(tokenLength / 2)).toString(\"hex\");\n\n // API Keys are prefixed with letters \"wat_\" to make token verification easier\n if (token.startsWith(\"wat_\")) {\n return token
|
|
1
|
+
{"version":3,"file":"features/security/apiKeys/shared/generateToken.js","sources":["../../../../../src/features/security/apiKeys/shared/generateToken.ts"],"sourcesContent":["import crypto from \"crypto\";\n\n/**\n * Generates a random token for API keys.\n * API Keys are prefixed with letter \"wat_\" to make token verification easier.\n * When authentication plugins kick in, they will be able to tell if they should handle\n * the token by checking the first letter.\n */\nexport const generateToken = (tokenLength = 40): `wat_${string}` => {\n const token = crypto.randomBytes(Math.ceil(tokenLength / 2)).toString(\"hex\");\n\n // API Keys are prefixed with letters \"wat_\" to make token verification easier\n if (token.startsWith(\"wat_\")) {\n return token as `wat_${string}`;\n }\n\n return `wat_${token.slice(0, tokenLength - 4)}`;\n};\n"],"names":["generateToken","tokenLength","token","crypto","Math"],"mappings":";AAQO,MAAMA,gBAAgB,CAACC,cAAc,EAAE;IAC1C,MAAMC,QAAQC,SAAAA,WAAkB,CAACC,KAAK,IAAI,CAACH,cAAc,IAAI,QAAQ,CAAC;IAGtE,IAAIC,MAAM,UAAU,CAAC,SACjB,OAAOA;IAGX,OAAO,CAAC,IAAI,EAAEA,MAAM,KAAK,CAAC,GAAGD,cAAc,IAAI;AACnD"}
|
|
@@ -2,14 +2,14 @@ import { z } 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"}
|
|
@@ -2,16 +2,26 @@ import { AuthorizationContext as Abstraction, PermissionTransformer } from "./ab
|
|
|
2
2
|
import { Authorizer } from "../Authorizer/index.js";
|
|
3
3
|
import type { SecurityPermission } from "../../../../types/security.js";
|
|
4
4
|
import { Identity } from "../../../../features/security/IdentityContext/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Loads and caches permissions per identity object and tenant for the lifetime of the request.
|
|
7
|
+
* `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the
|
|
8
|
+
* tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the
|
|
9
|
+
* object (not by id or a fingerprint) means two identities with the same id but a different
|
|
10
|
+
* context never share an entry (R69). A failed load is evicted, so the next check retries.
|
|
11
|
+
*/
|
|
5
12
|
export declare class AuthorizationContext implements Abstraction.Interface {
|
|
6
13
|
private getAuthorizers;
|
|
7
14
|
private getTransformers;
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
|
|
15
|
+
private getTenantId;
|
|
16
|
+
private permissionsByIdentity;
|
|
17
|
+
private readonly authorizationEnabledOverrides;
|
|
18
|
+
constructor(getAuthorizers: () => Authorizer.Interface[], getTransformers: () => PermissionTransformer.Interface[], getTenantId: () => string | null);
|
|
11
19
|
loadPermissions(identity: Identity): Promise<SecurityPermission[]>;
|
|
12
20
|
isAuthorizationEnabled(): boolean;
|
|
13
21
|
withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
22
|
+
withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
|
|
14
23
|
clearPermissionsCache(): void;
|
|
24
|
+
private authorize;
|
|
15
25
|
private transformPermissions;
|
|
16
26
|
private deduplicatePermissions;
|
|
17
27
|
}
|
|
@@ -1,37 +1,50 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
-
const
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const NO_TENANT = "";
|
|
3
3
|
class AuthorizationContext {
|
|
4
|
-
constructor(getAuthorizers, getTransformers){
|
|
4
|
+
constructor(getAuthorizers, getTransformers, getTenantId){
|
|
5
5
|
this.getAuthorizers = getAuthorizers;
|
|
6
6
|
this.getTransformers = getTransformers;
|
|
7
|
+
this.getTenantId = getTenantId;
|
|
8
|
+
this.permissionsByIdentity = new WeakMap();
|
|
9
|
+
this.authorizationEnabledOverrides = new AsyncLocalStorage();
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
loadPermissions(identity) {
|
|
12
|
+
let byTenant = this.permissionsByIdentity.get(identity);
|
|
13
|
+
if (!byTenant) {
|
|
14
|
+
byTenant = new Map();
|
|
15
|
+
this.permissionsByIdentity.set(identity, byTenant);
|
|
16
|
+
}
|
|
17
|
+
const tenantKey = this.getTenantId() ?? NO_TENANT;
|
|
18
|
+
const cached = byTenant.get(tenantKey);
|
|
19
|
+
if (cached) return cached;
|
|
20
|
+
const loader = this.authorize(identity);
|
|
21
|
+
byTenant.set(tenantKey, loader);
|
|
22
|
+
const cache = byTenant;
|
|
23
|
+
loader.catch(()=>{
|
|
24
|
+
if (cache.get(tenantKey) === loader) cache.delete(tenantKey);
|
|
22
25
|
});
|
|
23
|
-
return
|
|
26
|
+
return loader;
|
|
24
27
|
}
|
|
25
28
|
isAuthorizationEnabled() {
|
|
26
|
-
const override =
|
|
29
|
+
const override = this.authorizationEnabledOverrides.getStore();
|
|
27
30
|
return override ?? true;
|
|
28
31
|
}
|
|
29
32
|
withoutAuthorization(cb) {
|
|
30
|
-
return
|
|
33
|
+
return this.authorizationEnabledOverrides.run(false, cb);
|
|
34
|
+
}
|
|
35
|
+
withAuthorization(cb) {
|
|
36
|
+
return this.authorizationEnabledOverrides.run(true, cb);
|
|
31
37
|
}
|
|
32
38
|
clearPermissionsCache() {
|
|
33
|
-
this.
|
|
34
|
-
|
|
39
|
+
this.permissionsByIdentity = new WeakMap();
|
|
40
|
+
}
|
|
41
|
+
async authorize(identity) {
|
|
42
|
+
const authorizers = this.getAuthorizers();
|
|
43
|
+
for (const authorizer of authorizers){
|
|
44
|
+
const permissions = await authorizer.authorize(identity);
|
|
45
|
+
if (Array.isArray(permissions)) return this.transformPermissions(permissions);
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
35
48
|
}
|
|
36
49
|
transformPermissions(permissions) {
|
|
37
50
|
const transformers = this.getTransformers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\n/** Tenant key used when no tenant is set yet (before the tenant is resolved). */\nconst NO_TENANT = \"\";\n\ntype PermissionsByTenant = Map<string, Promise<SecurityPermission[]>>;\n\n/**\n * Loads and caches permissions per identity object and tenant for the lifetime of the request.\n * `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the\n * tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the\n * object (not by id or a fingerprint) means two identities with the same id but a different\n * context never share an entry (R69). A failed load is evicted, so the next check retries.\n */\nexport class AuthorizationContext implements Abstraction.Interface {\n private permissionsByIdentity = new WeakMap<Identity, PermissionsByTenant>();\n /*\n * `withoutAuthorization()` and `withAuthorization()` switch authorization on or off for their\n * callback's async call chain only.\n */\n private readonly authorizationEnabledOverrides = new AsyncLocalStorage<boolean>();\n\n constructor(\n private getAuthorizers: () => Authorizer.Interface[],\n private getTransformers: () => PermissionTransformer.Interface[],\n private getTenantId: () => string | null\n ) {}\n\n loadPermissions(identity: Identity): Promise<SecurityPermission[]> {\n let byTenant = this.permissionsByIdentity.get(identity);\n if (!byTenant) {\n byTenant = new Map();\n this.permissionsByIdentity.set(identity, byTenant);\n }\n\n const tenantKey = this.getTenantId() ?? NO_TENANT;\n const cached = byTenant.get(tenantKey);\n if (cached) {\n return cached;\n }\n\n const loader = this.authorize(identity);\n byTenant.set(tenantKey, loader);\n const cache = byTenant;\n loader.catch(() => {\n if (cache.get(tenantKey) === loader) {\n cache.delete(tenantKey);\n }\n });\n return loader;\n }\n\n isAuthorizationEnabled(): boolean {\n const override = this.authorizationEnabledOverrides.getStore();\n return override ?? true;\n }\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationEnabledOverrides.run(false, cb);\n }\n\n withAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationEnabledOverrides.run(true, cb);\n }\n\n clearPermissionsCache(): void {\n this.permissionsByIdentity = new WeakMap();\n }\n\n private async authorize(identity: Identity): Promise<SecurityPermission[]> {\n // Execute authorizers in sequence until one returns permissions\n const authorizers = this.getAuthorizers();\n for (const authorizer of authorizers) {\n const permissions = await authorizer.authorize(identity);\n if (Array.isArray(permissions)) {\n return this.transformPermissions(permissions);\n }\n }\n\n // No authorizer returned permissions\n return [];\n }\n\n private transformPermissions(permissions: SecurityPermission[]) {\n const transformers = this.getTransformers();\n if (transformers.length === 0) {\n return this.deduplicatePermissions(permissions);\n }\n\n const transformed = permissions\n .map(permission => {\n // A transformer can return one or multiple permissions, so we flatten the result.\n return transformers.map(t => t.execute(permission)).flat();\n })\n .flat();\n\n return this.deduplicatePermissions(transformed);\n }\n\n private deduplicatePermissions(permissions: SecurityPermission[]) {\n const seen = new Set<string>();\n\n return permissions.filter(permission => {\n const key = JSON.stringify(permission);\n if (seen.has(key)) {\n return false;\n }\n seen.add(key);\n return true;\n });\n }\n}\n"],"names":["NO_TENANT","AuthorizationContext","getAuthorizers","getTransformers","getTenantId","WeakMap","AsyncLocalStorage","identity","byTenant","Map","tenantKey","cached","loader","cache","override","cb","authorizers","authorizer","permissions","Array","transformers","transformed","permission","t","seen","Set","key","JSON"],"mappings":";AAOA,MAAMA,YAAY;AAWX,MAAMC;IAQT,YACYC,cAA4C,EAC5CC,eAAwD,EACxDC,WAAgC,CAC1C;aAHUF,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;aAVJ,qBAAqB,GAAG,IAAIC;QAInC,KACgB,6BAA6B,GAAG,IAAIC;IAMlD;IAEH,gBAAgBC,QAAkB,EAAiC;QAC/D,IAAIC,WAAW,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACD;QAC9C,IAAI,CAACC,UAAU;YACXA,WAAW,IAAIC;YACf,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACF,UAAUC;QAC7C;QAEA,MAAME,YAAY,IAAI,CAAC,WAAW,MAAMV;QACxC,MAAMW,SAASH,SAAS,GAAG,CAACE;QAC5B,IAAIC,QACA,OAAOA;QAGX,MAAMC,SAAS,IAAI,CAAC,SAAS,CAACL;QAC9BC,SAAS,GAAG,CAACE,WAAWE;QACxB,MAAMC,QAAQL;QACdI,OAAO,KAAK,CAAC;YACT,IAAIC,MAAM,GAAG,CAACH,eAAeE,QACzBC,MAAM,MAAM,CAACH;QAErB;QACA,OAAOE;IACX;IAEA,yBAAkC;QAC9B,MAAME,WAAW,IAAI,CAAC,6BAA6B,CAAC,QAAQ;QAC5D,OAAOA,YAAY;IACvB;IAEA,qBAAwBC,EAAoB,EAAc;QACtD,OAAO,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,OAAOA;IACzD;IAEA,kBAAqBA,EAAoB,EAAc;QACnD,OAAO,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,MAAMA;IACxD;IAEA,wBAA8B;QAC1B,IAAI,CAAC,qBAAqB,GAAG,IAAIV;IACrC;IAEA,MAAc,UAAUE,QAAkB,EAAiC;QAEvE,MAAMS,cAAc,IAAI,CAAC,cAAc;QACvC,KAAK,MAAMC,cAAcD,YAAa;YAClC,MAAME,cAAc,MAAMD,WAAW,SAAS,CAACV;YAC/C,IAAIY,MAAM,OAAO,CAACD,cACd,OAAO,IAAI,CAAC,oBAAoB,CAACA;QAEzC;QAGA,OAAO,EAAE;IACb;IAEQ,qBAAqBA,WAAiC,EAAE;QAC5D,MAAME,eAAe,IAAI,CAAC,eAAe;QACzC,IAAIA,AAAwB,MAAxBA,aAAa,MAAM,EACnB,OAAO,IAAI,CAAC,sBAAsB,CAACF;QAGvC,MAAMG,cAAcH,YACf,GAAG,CAACI,CAAAA,aAEMF,aAAa,GAAG,CAACG,CAAAA,IAAKA,EAAE,OAAO,CAACD,aAAa,IAAI,IAE3D,IAAI;QAET,OAAO,IAAI,CAAC,sBAAsB,CAACD;IACvC;IAEQ,uBAAuBH,WAAiC,EAAE;QAC9D,MAAMM,OAAO,IAAIC;QAEjB,OAAOP,YAAY,MAAM,CAACI,CAAAA;YACtB,MAAMI,MAAMC,KAAK,SAAS,CAACL;YAC3B,IAAIE,KAAK,GAAG,CAACE,MACT,OAAO;YAEXF,KAAK,GAAG,CAACE;YACT,OAAO;QACX;IACJ;AACJ"}
|