@webiny/api-core 6.6.0-alpha.1 → 6.6.0-alpha.11
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 +10 -2
- package/ApiCoreFeature.js.map +1 -1
- package/exports/api/tasks.d.ts +1 -0
- package/exports/api/tasks.js +1 -1
- package/exports/api.d.ts +2 -1
- package/exports/api.js +2 -1
- package/features/ai/Ai.d.ts +3 -1
- package/features/ai/Ai.js +36 -28
- package/features/ai/Ai.js.map +1 -1
- package/features/ai/AiModelRegistry.d.ts +14 -0
- package/features/ai/AiModelRegistry.js +39 -0
- package/features/ai/AiModelRegistry.js.map +1 -0
- package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
- package/features/ai/AiSdkToolHandlerResolver.js +19 -0
- package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
- package/features/ai/AiSdkTools.d.ts +4 -3
- package/features/ai/AiSdkTools.js +11 -9
- package/features/ai/AiSdkTools.js.map +1 -1
- package/features/ai/AnthropicSdkFactory.js +12 -4
- package/features/ai/AnthropicSdkFactory.js.map +1 -1
- package/features/ai/DEVELOPERS.md +183 -0
- package/features/ai/GoogleSdkFactory.d.ts +10 -0
- package/features/ai/GoogleSdkFactory.js +65 -0
- package/features/ai/GoogleSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.js +51 -11
- package/features/ai/OpenAiSdkFactory.js.map +1 -1
- package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
- package/features/ai/OpenRouterSdkFactory.js +112 -0
- package/features/ai/OpenRouterSdkFactory.js.map +1 -0
- package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
- package/features/ai/RemoteAiModelCatalog.js +74 -0
- package/features/ai/RemoteAiModelCatalog.js.map +1 -0
- package/features/ai/abstractions.d.ts +82 -6
- package/features/ai/abstractions.js +6 -2
- package/features/ai/abstractions.js.map +1 -1
- package/features/ai/feature.js +10 -0
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +2 -4
- package/features/ai/index.js +1 -1
- package/features/cdnCache/NullCdnCache.d.ts +8 -0
- package/features/cdnCache/NullCdnCache.js +11 -0
- package/features/cdnCache/NullCdnCache.js.map +1 -0
- package/features/cdnCache/abstractions.d.ts +20 -0
- package/features/cdnCache/abstractions.js +5 -0
- package/features/cdnCache/abstractions.js.map +1 -0
- package/features/cdnCache/feature.d.ts +8 -0
- package/features/cdnCache/feature.js +11 -0
- package/features/cdnCache/feature.js.map +1 -0
- package/features/cdnCache/index.d.ts +2 -0
- package/features/cdnCache/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.js +13 -1
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -1
- 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/{logger → httpClient}/feature.d.ts +1 -1
- 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/requestStorage/abstractions.d.ts +23 -0
- package/features/requestStorage/abstractions.js +5 -0
- package/features/requestStorage/abstractions.js.map +1 -0
- package/features/requestStorage/index.d.ts +1 -0
- package/features/requestStorage/index.js +1 -0
- package/features/security/IdentityContext/IdentityContext.d.ts +6 -2
- package/features/security/IdentityContext/IdentityContext.js +24 -7
- 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/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/feature.js +2 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.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/NotifyRoleChange/NotifyOnRoleCreatedHandler.d.ts +11 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js +22 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.d.ts +11 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js +22 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.d.ts +11 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js +22 -0
- package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.d.ts +11 -0
- package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js +40 -0
- package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/abstractions.d.ts +21 -0
- package/features/security/roles/NotifyRoleChange/abstractions.js +8 -0
- package/features/security/roles/NotifyRoleChange/abstractions.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/feature.d.ts +5 -0
- package/features/security/roles/NotifyRoleChange/feature.js +17 -0
- package/features/security/roles/NotifyRoleChange/feature.js.map +1 -0
- package/features/security/roles/NotifyRoleChange/index.d.ts +2 -0
- package/features/security/roles/NotifyRoleChange/index.js +2 -0
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +2 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/feature.js +2 -0
- package/features/security/roles/feature.js.map +1 -1
- package/features/security/shared/definedOnly.d.ts +1 -0
- package/features/security/shared/definedOnly.js +8 -0
- package/features/security/shared/definedOnly.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/NotifyTeamChange/NotifyOnTeamChangeHandlers.d.ts +29 -0
- package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js +58 -0
- package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js.map +1 -0
- package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.d.ts +11 -0
- package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js +40 -0
- package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js.map +1 -0
- package/features/security/teams/NotifyTeamChange/abstractions.d.ts +21 -0
- package/features/security/teams/NotifyTeamChange/abstractions.js +8 -0
- package/features/security/teams/NotifyTeamChange/abstractions.js.map +1 -0
- package/features/security/teams/NotifyTeamChange/feature.d.ts +5 -0
- package/features/security/teams/NotifyTeamChange/feature.js +15 -0
- package/features/security/teams/NotifyTeamChange/feature.js.map +1 -0
- package/features/security/teams/NotifyTeamChange/index.d.ts +2 -0
- package/features/security/teams/NotifyTeamChange/index.js +2 -0
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +2 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/teams/feature.js +2 -0
- package/features/security/teams/feature.js.map +1 -1
- package/features/task/TaskDefinition/abstractions.d.ts +13 -20
- package/features/task/TaskDefinition/abstractions.js.map +1 -1
- package/features/task/TaskService/abstractions.d.ts +7 -0
- package/features/task/TaskService/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 +6 -1
- package/features/wcp/WcpContext/WcpContext.js +17 -2
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +9 -73
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +25 -5
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpLicenseLoader.js.map +1 -1
- package/features/wcp/resolveWcpProjectEnvironment.d.ts +1 -1
- package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -1
- package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.d.ts +20 -0
- package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js +24 -0
- package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js.map +1 -0
- package/features/websockets/SendToIdentity/abstractions.d.ts +19 -0
- package/features/websockets/SendToIdentity/abstractions.js +5 -0
- package/features/websockets/SendToIdentity/abstractions.js.map +1 -0
- package/features/websockets/WebsocketServiceError.d.ts +7 -0
- package/features/websockets/WebsocketServiceError.js +14 -0
- package/features/websockets/WebsocketServiceError.js.map +1 -0
- package/features/websockets/index.d.ts +6 -0
- package/features/websockets/index.js +3 -0
- package/features/websockets/types.d.ts +15 -0
- package/features/websockets/types.js +0 -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 +1 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +4 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -1
- package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
- package/graphql/security/SecuritySchemaFactory.js +4 -0
- package/graphql/security/SecuritySchemaFactory.js.map +1 -1
- package/graphql/system/SystemSchemaFactory.d.ts +1 -0
- package/graphql/system/SystemSchemaFactory.js +4 -0
- package/graphql/system/SystemSchemaFactory.js.map +1 -1
- package/graphql/users/UsersSchemaFactory.d.ts +1 -0
- package/graphql/users/UsersSchemaFactory.js +4 -0
- package/graphql/users/UsersSchemaFactory.js.map +1 -1
- package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
- package/graphql/wcp/WcpSchemaFactory.js +5 -1
- 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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +21 -21
- 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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { Debugger } from "./Debugger.js";
|
|
3
|
+
import { GraphQLDebuggerTransport } from "./GraphQLDebuggerTransport.js";
|
|
4
|
+
import { DebuggerRouteDecorator } from "./DebuggerRouteDecorator.js";
|
|
5
|
+
const DebuggerFeature = createFeature({
|
|
6
|
+
name: "DebuggerFeature",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(Debugger).inContainerScope();
|
|
9
|
+
container.register(GraphQLDebuggerTransport);
|
|
10
|
+
container.registerDecorator(DebuggerRouteDecorator);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { DebuggerFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/feature.js","sources":["../../../src/features/debugger/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { Debugger } from \"./Debugger.js\";\nimport { GraphQLDebuggerTransport } from \"./GraphQLDebuggerTransport.js\";\nimport { DebuggerRouteDecorator } from \"./DebuggerRouteDecorator.js\";\n\nexport const DebuggerFeature = createFeature({\n name: \"DebuggerFeature\",\n register(container: Container) {\n /*\n * The session is request state, so it is container scoped: one instance per request,\n * shared by the route decorator that opens and flushes it and by every call site in\n * between. A transient registration would hand each of them a different instance and\n * nothing would ever be captured; a singleton would carry one identity's entries into the\n * next request.\n */\n container.register(Debugger).inContainerScope();\n container.register(GraphQLDebuggerTransport);\n container.registerDecorator(DebuggerRouteDecorator);\n }\n});\n"],"names":["DebuggerFeature","createFeature","container","Debugger","GraphQLDebuggerTransport","DebuggerRouteDecorator"],"mappings":";;;;AAMO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAoB;QAQzBA,UAAU,QAAQ,CAACC,UAAU,gBAAgB;QAC7CD,UAAU,QAAQ,CAACE;QACnBF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Debugger } from "./abstractions.js";
|
|
2
|
+
export { DebuggerTransport } from "./abstractions.js";
|
|
3
|
+
export type { DebugNamespace } from "./abstractions.js";
|
|
4
|
+
export type { DebugNamespaces } from "./abstractions.js";
|
|
5
|
+
export { DebuggerFeature } from "./feature.js";
|
|
6
|
+
export { DEBUG_HEADER } from "./DebuggerRouteDecorator.js";
|
|
7
|
+
export { DEBUG_PERMISSION } from "./permissions.js";
|
|
8
|
+
export { GRAPHQL_TARGET } from "./GraphQLDebuggerTransport.js";
|
|
9
|
+
export type { IGraphQLDeliveryTarget } from "./GraphQLDebuggerTransport.js";
|
|
10
|
+
export { DEFAULT_LIMITS } from "./limits.js";
|
|
11
|
+
export type { IDebuggerLimits } from "./limits.js";
|
|
12
|
+
export { DEBUGGER_PERMISSIONS_SCHEMA } from "./permissionsSchema.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Debugger, DebuggerTransport } from "./abstractions.js";
|
|
2
|
+
export { DebuggerFeature } from "./feature.js";
|
|
3
|
+
export { DEBUG_HEADER } from "./DebuggerRouteDecorator.js";
|
|
4
|
+
export { DEBUG_PERMISSION } from "./permissions.js";
|
|
5
|
+
export { GRAPHQL_TARGET } from "./GraphQLDebuggerTransport.js";
|
|
6
|
+
export { DEFAULT_LIMITS } from "./limits.js";
|
|
7
|
+
export { DEBUGGER_PERMISSIONS_SCHEMA } from "./permissionsSchema.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capture limits. None of these are settable by the client.
|
|
3
|
+
*/
|
|
4
|
+
export interface IDebuggerLimits {
|
|
5
|
+
/** Total serialized bytes a session may hold. Overflow drops entries from the front. */
|
|
6
|
+
totalBytes: number;
|
|
7
|
+
/** Maximum serialized size of a single entry, after the walk caps below are applied. */
|
|
8
|
+
entryBytes: number;
|
|
9
|
+
/** Runaway-loop guard. The byte budget is the real control. */
|
|
10
|
+
entryCount: number;
|
|
11
|
+
/** Maximum nesting depth walked before emitting a marker. */
|
|
12
|
+
depth: number;
|
|
13
|
+
/** Maximum characters kept from a single string value. */
|
|
14
|
+
stringLength: number;
|
|
15
|
+
/** Maximum items kept from a single array. */
|
|
16
|
+
arrayLength: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_LIMITS: IDebuggerLimits;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/limits.js","sources":["../../../src/features/debugger/limits.ts"],"sourcesContent":["/**\n * Capture limits. None of these are settable by the client.\n */\nexport interface IDebuggerLimits {\n /** Total serialized bytes a session may hold. Overflow drops entries from the front. */\n totalBytes: number;\n /** Maximum serialized size of a single entry, after the walk caps below are applied. */\n entryBytes: number;\n /** Runaway-loop guard. The byte budget is the real control. */\n entryCount: number;\n /** Maximum nesting depth walked before emitting a marker. */\n depth: number;\n /** Maximum characters kept from a single string value. */\n stringLength: number;\n /** Maximum items kept from a single array. */\n arrayLength: number;\n}\n\nexport const DEFAULT_LIMITS: IDebuggerLimits = {\n totalBytes: 4 * 1024 * 1024,\n entryBytes: 512 * 1024,\n entryCount: 10000,\n depth: 10,\n stringLength: 10000,\n arrayLength: 100\n};\n"],"names":["DEFAULT_LIMITS"],"mappings":"AAkBO,MAAMA,iBAAkC;IAC3C,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,OAAO;IACP,cAAc;IACd,aAAa;AACjB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface INamespaceFilter {
|
|
2
|
+
matches(namespace: string): boolean;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Builds a namespace matcher from the patterns requested by the client.
|
|
6
|
+
*
|
|
7
|
+
* A namespace matches when at least one positive pattern matches it and no negative pattern does.
|
|
8
|
+
*
|
|
9
|
+
* `minimatch` has its own native `!` negation which *inverts* the result rather than reporting a
|
|
10
|
+
* match, so `!cms.os.*` would return `true` for every namespace that does not match it. Patterns are
|
|
11
|
+
* therefore split into positive and negative lists here and matched positively, with `nonegate` set
|
|
12
|
+
* as a second guard.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createNamespaceFilter: (patterns: string[]) => INamespaceFilter;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { minimatch } from "minimatch";
|
|
2
|
+
const createNamespaceFilter = (patterns)=>{
|
|
3
|
+
const positive = [];
|
|
4
|
+
const negative = [];
|
|
5
|
+
for (const pattern of patterns){
|
|
6
|
+
if (pattern.startsWith("!")) {
|
|
7
|
+
const stripped = pattern.slice(1);
|
|
8
|
+
if (stripped) negative.push(stripped);
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (pattern) positive.push(pattern);
|
|
12
|
+
}
|
|
13
|
+
const cache = new Map();
|
|
14
|
+
const test = (namespace)=>{
|
|
15
|
+
const isIncluded = positive.some((pattern)=>minimatch(namespace, pattern, {
|
|
16
|
+
nonegate: true
|
|
17
|
+
}));
|
|
18
|
+
if (!isIncluded) return false;
|
|
19
|
+
return !negative.some((pattern)=>minimatch(namespace, pattern, {
|
|
20
|
+
nonegate: true
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
matches (namespace) {
|
|
25
|
+
const cached = cache.get(namespace);
|
|
26
|
+
if (void 0 !== cached) return cached;
|
|
27
|
+
const result = test(namespace);
|
|
28
|
+
cache.set(namespace, result);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export { createNamespaceFilter };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=matchNamespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/matchNamespace.js","sources":["../../../src/features/debugger/matchNamespace.ts"],"sourcesContent":["import { minimatch } from \"minimatch\";\n\nexport interface INamespaceFilter {\n matches(namespace: string): boolean;\n}\n\n/**\n * Builds a namespace matcher from the patterns requested by the client.\n *\n * A namespace matches when at least one positive pattern matches it and no negative pattern does.\n *\n * `minimatch` has its own native `!` negation which *inverts* the result rather than reporting a\n * match, so `!cms.os.*` would return `true` for every namespace that does not match it. Patterns are\n * therefore split into positive and negative lists here and matched positively, with `nonegate` set\n * as a second guard.\n */\nexport const createNamespaceFilter = (patterns: string[]): INamespaceFilter => {\n const positive: string[] = [];\n const negative: string[] = [];\n\n for (const pattern of patterns) {\n if (pattern.startsWith(\"!\")) {\n const stripped = pattern.slice(1);\n if (stripped) {\n negative.push(stripped);\n }\n continue;\n }\n if (pattern) {\n positive.push(pattern);\n }\n }\n\n /**\n * Matching is stable for the life of a session, so each distinct namespace is matched once.\n */\n const cache = new Map<string, boolean>();\n\n const test = (namespace: string): boolean => {\n const isIncluded = positive.some(pattern => {\n return minimatch(namespace, pattern, { nonegate: true });\n });\n\n if (!isIncluded) {\n return false;\n }\n\n return !negative.some(pattern => {\n return minimatch(namespace, pattern, { nonegate: true });\n });\n };\n\n return {\n matches(namespace) {\n const cached = cache.get(namespace);\n if (cached !== undefined) {\n return cached;\n }\n const result = test(namespace);\n cache.set(namespace, result);\n return result;\n }\n };\n};\n"],"names":["createNamespaceFilter","patterns","positive","negative","pattern","stripped","cache","Map","test","namespace","isIncluded","minimatch","cached","undefined","result"],"mappings":";AAgBO,MAAMA,wBAAwB,CAACC;IAClC,MAAMC,WAAqB,EAAE;IAC7B,MAAMC,WAAqB,EAAE;IAE7B,KAAK,MAAMC,WAAWH,SAAU;QAC5B,IAAIG,QAAQ,UAAU,CAAC,MAAM;YACzB,MAAMC,WAAWD,QAAQ,KAAK,CAAC;YAC/B,IAAIC,UACAF,SAAS,IAAI,CAACE;YAElB;QACJ;QACA,IAAID,SACAF,SAAS,IAAI,CAACE;IAEtB;IAKA,MAAME,QAAQ,IAAIC;IAElB,MAAMC,OAAO,CAACC;QACV,MAAMC,aAAaR,SAAS,IAAI,CAACE,CAAAA,UACtBO,UAAUF,WAAWL,SAAS;gBAAE,UAAU;YAAK;QAG1D,IAAI,CAACM,YACD,OAAO;QAGX,OAAO,CAACP,SAAS,IAAI,CAACC,CAAAA,UACXO,UAAUF,WAAWL,SAAS;gBAAE,UAAU;YAAK;IAE9D;IAEA,OAAO;QACH,SAAQK,SAAS;YACb,MAAMG,SAASN,MAAM,GAAG,CAACG;YACzB,IAAIG,AAAWC,WAAXD,QACA,OAAOA;YAEX,MAAME,SAASN,KAAKC;YACpBH,MAAM,GAAG,CAACG,WAAWK;YACrB,OAAOA;QACX;IACJ;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses the `x-webiny-debug` header into a namespace pattern list.
|
|
3
|
+
*
|
|
4
|
+
* Returns an empty array when capture was not requested. Never throws - a malformed header must not
|
|
5
|
+
* be able to fail the request it arrived on.
|
|
6
|
+
*/
|
|
7
|
+
export declare const parseNamespaceHeader: (value: string | string[] | undefined) => string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const parseNamespaceHeader = (value)=>{
|
|
2
|
+
if (!value) return [];
|
|
3
|
+
const raw = Array.isArray(value) ? value.join(",") : value;
|
|
4
|
+
const patterns = raw.split(",").map((item)=>item.trim()).filter(Boolean);
|
|
5
|
+
if (0 === patterns.length) return [];
|
|
6
|
+
if (1 === patterns.length) {
|
|
7
|
+
const only = patterns[0].toLowerCase();
|
|
8
|
+
if ("1" === only || "true" === only) return [
|
|
9
|
+
"*"
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
return patterns;
|
|
13
|
+
};
|
|
14
|
+
export { parseNamespaceHeader };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=parseNamespaceHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/parseNamespaceHeader.js","sources":["../../../src/features/debugger/parseNamespaceHeader.ts"],"sourcesContent":["/**\n * Parses the `x-webiny-debug` header into a namespace pattern list.\n *\n * Returns an empty array when capture was not requested. Never throws - a malformed header must not\n * be able to fail the request it arrived on.\n */\nexport const parseNamespaceHeader = (value: string | string[] | undefined): string[] => {\n if (!value) {\n return [];\n }\n\n /**\n * Duplicate headers arrive comma-joined from both Node and API Gateway. The array form is\n * accepted anyway, so a transport that keeps repeated headers apart cannot break parsing.\n */\n const raw = Array.isArray(value) ? value.join(\",\") : value;\n\n const patterns = raw\n .split(\",\")\n .map(item => item.trim())\n .filter(Boolean);\n\n if (patterns.length === 0) {\n return [];\n }\n\n /**\n * `1` and `true` are shorthand for \"everything\". Anything else is treated as a pattern list.\n */\n if (patterns.length === 1) {\n const only = patterns[0].toLowerCase();\n if (only === \"1\" || only === \"true\") {\n return [\"*\"];\n }\n }\n\n return patterns;\n};\n"],"names":["parseNamespaceHeader","value","raw","Array","patterns","item","Boolean","only"],"mappings":"AAMO,MAAMA,uBAAuB,CAACC;IACjC,IAAI,CAACA,OACD,OAAO,EAAE;IAOb,MAAMC,MAAMC,MAAM,OAAO,CAACF,SAASA,MAAM,IAAI,CAAC,OAAOA;IAErD,MAAMG,WAAWF,IACZ,KAAK,CAAC,KACN,GAAG,CAACG,CAAAA,OAAQA,KAAK,IAAI,IACrB,MAAM,CAACC;IAEZ,IAAIF,AAAoB,MAApBA,SAAS,MAAM,EACf,OAAO,EAAE;IAMb,IAAIA,AAAoB,MAApBA,SAAS,MAAM,EAAQ;QACvB,MAAMG,OAAOH,QAAQ,CAAC,EAAE,CAAC,WAAW;QACpC,IAAIG,AAAS,QAATA,QAAgBA,AAAS,WAATA,MAChB,OAAO;YAAC;SAAI;IAEpB;IAEA,OAAOH;AACX"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IdentityContext } from "../../features/security/IdentityContext/index.js";
|
|
2
|
+
export declare const DEBUG_PERMISSION = "dev-tools.debug";
|
|
3
|
+
/**
|
|
4
|
+
* Whether an identity may capture debug data.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately an exact match rather than `canAccess`, which grants on `*` and on `dev-tools.*`.
|
|
7
|
+
* Capture runs automatically for whoever holds this, so a wildcard would leave it permanently on for
|
|
8
|
+
* every full-access administrator - collecting record content on every request, indefinitely, for
|
|
9
|
+
* people who never asked for it.
|
|
10
|
+
*
|
|
11
|
+
* The consequence, which is intended: full access is not enough. The entity has to be granted
|
|
12
|
+
* deliberately, and that act is the opt-in.
|
|
13
|
+
*/
|
|
14
|
+
export declare const canCaptureDebugData: (identityContext: IdentityContext.Interface) => Promise<boolean>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const DEBUG_PERMISSION = "dev-tools.debug";
|
|
2
|
+
const canCaptureDebugData = async (identityContext)=>{
|
|
3
|
+
const permissions = await identityContext.listPermissions();
|
|
4
|
+
return permissions.some((permission)=>permission.name === DEBUG_PERMISSION);
|
|
5
|
+
};
|
|
6
|
+
export { DEBUG_PERMISSION, canCaptureDebugData };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/permissions.js","sources":["../../../src/features/debugger/permissions.ts"],"sourcesContent":["import type { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nexport const DEBUG_PERMISSION = \"dev-tools.debug\";\n\n/**\n * Whether an identity may capture debug data.\n *\n * Deliberately an exact match rather than `canAccess`, which grants on `*` and on `dev-tools.*`.\n * Capture runs automatically for whoever holds this, so a wildcard would leave it permanently on for\n * every full-access administrator - collecting record content on every request, indefinitely, for\n * people who never asked for it.\n *\n * The consequence, which is intended: full access is not enough. The entity has to be granted\n * deliberately, and that act is the opt-in.\n */\nexport const canCaptureDebugData = async (\n identityContext: IdentityContext.Interface\n): Promise<boolean> => {\n const permissions = await identityContext.listPermissions();\n return permissions.some(\n (permission: SecurityPermission) => permission.name === DEBUG_PERMISSION\n );\n};\n"],"names":["DEBUG_PERMISSION","canCaptureDebugData","identityContext","permissions","permission"],"mappings":"AAGO,MAAMA,mBAAmB;AAazB,MAAMC,sBAAsB,OAC/BC;IAEA,MAAMC,cAAc,MAAMD,gBAAgB,eAAe;IACzD,OAAOC,YAAY,IAAI,CACnB,CAACC,aAAmCA,WAAW,IAAI,KAAKJ;AAEhE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The debugger lives under the `dev-tools` prefix, alongside the playgrounds.
|
|
3
|
+
*
|
|
4
|
+
* `fullAccess: true` emits `dev-tools.*`, which glob matching would let through, but capture is gated
|
|
5
|
+
* on an exact match of `dev-tools.debug` (see `canCaptureDebugData`). Dev Tools full access alone
|
|
6
|
+
* does not turn capture on.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEBUGGER_PERMISSIONS_SCHEMA: {
|
|
9
|
+
readonly prefix: "dev-tools";
|
|
10
|
+
readonly fullAccess: true;
|
|
11
|
+
readonly entities: readonly [{
|
|
12
|
+
readonly id: "debug";
|
|
13
|
+
readonly title: "Debugger";
|
|
14
|
+
readonly permission: "dev-tools.debug";
|
|
15
|
+
readonly scopes: readonly ["full"];
|
|
16
|
+
}];
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createPermissionSchema } from "../security/permissions/index.js";
|
|
2
|
+
const DEBUGGER_PERMISSIONS_SCHEMA = createPermissionSchema({
|
|
3
|
+
prefix: "dev-tools",
|
|
4
|
+
fullAccess: true,
|
|
5
|
+
entities: [
|
|
6
|
+
{
|
|
7
|
+
id: "debug",
|
|
8
|
+
title: "Debugger",
|
|
9
|
+
permission: "dev-tools.debug",
|
|
10
|
+
scopes: [
|
|
11
|
+
"full"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
});
|
|
16
|
+
export { DEBUGGER_PERMISSIONS_SCHEMA };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=permissionsSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/permissionsSchema.js","sources":["../../../src/features/debugger/permissionsSchema.ts"],"sourcesContent":["import { createPermissionSchema } from \"~/features/security/permissions/index.js\";\n\n/**\n * The debugger lives under the `dev-tools` prefix, alongside the playgrounds.\n *\n * `fullAccess: true` emits `dev-tools.*`, which glob matching would let through, but capture is gated\n * on an exact match of `dev-tools.debug` (see `canCaptureDebugData`). Dev Tools full access alone\n * does not turn capture on.\n */\nexport const DEBUGGER_PERMISSIONS_SCHEMA = createPermissionSchema({\n prefix: \"dev-tools\",\n fullAccess: true,\n entities: [\n {\n id: \"debug\",\n title: \"Debugger\",\n permission: \"dev-tools.debug\",\n scopes: [\"full\"]\n }\n ]\n});\n"],"names":["DEBUGGER_PERMISSIONS_SCHEMA","createPermissionSchema"],"mappings":";AASO,MAAMA,8BAA8BC,uBAAuB;IAC9D,QAAQ;IACR,YAAY;IACZ,UAAU;QACN;YACI,IAAI;YACJ,OAAO;YACP,YAAY;YACZ,QAAQ;gBAAC;aAAO;QACpB;KACH;AACL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IDebuggerLimits } from "./limits.js";
|
|
2
|
+
export interface ISerializeResult {
|
|
3
|
+
json: string;
|
|
4
|
+
bytes: number;
|
|
5
|
+
/** True if the value was replaced by the per-entry cap marker. */
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a captured payload to JSON, never throwing and always producing valid JSON.
|
|
10
|
+
*/
|
|
11
|
+
export declare const serialize: (value: unknown, limits: IDebuggerLimits) => ISerializeResult;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const UNDEFINED = "#[Undefined value]";
|
|
2
|
+
const CIRCULAR = "#[Circular]";
|
|
3
|
+
const DEPTH_LIMIT = "#[Depth limit]";
|
|
4
|
+
const isPlainValue = (value)=>{
|
|
5
|
+
const type = typeof value;
|
|
6
|
+
return "string" === type || "number" === type || "boolean" === type || null === value;
|
|
7
|
+
};
|
|
8
|
+
const describeBinary = (value)=>{
|
|
9
|
+
const name = value.constructor?.name || "TypedArray";
|
|
10
|
+
return `#[${name} ${value.byteLength} bytes]`;
|
|
11
|
+
};
|
|
12
|
+
const walk = (value, limits, seen, depth)=>{
|
|
13
|
+
if (void 0 === value) return UNDEFINED;
|
|
14
|
+
if (isPlainValue(value)) {
|
|
15
|
+
if ("string" == typeof value && value.length > limits.stringLength) {
|
|
16
|
+
const kept = value.slice(0, limits.stringLength);
|
|
17
|
+
return `${kept}…(${value.length - limits.stringLength} more)`;
|
|
18
|
+
}
|
|
19
|
+
if ("number" == typeof value && !Number.isFinite(value)) return String(value);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if ("bigint" == typeof value) return `${value.toString()}n`;
|
|
23
|
+
if ("symbol" == typeof value) return String(value);
|
|
24
|
+
if ("function" == typeof value) return `#[Function: ${value.name || "anonymous"}]`;
|
|
25
|
+
if (value instanceof Error) return {
|
|
26
|
+
name: value.name,
|
|
27
|
+
message: value.message,
|
|
28
|
+
stack: value.stack
|
|
29
|
+
};
|
|
30
|
+
if (value instanceof Date) return value.toISOString();
|
|
31
|
+
if (value instanceof RegExp) return value.toString();
|
|
32
|
+
if (ArrayBuffer.isView(value)) return describeBinary(value);
|
|
33
|
+
if (value instanceof ArrayBuffer) return `#[ArrayBuffer ${value.byteLength} bytes]`;
|
|
34
|
+
if (depth >= limits.depth) return DEPTH_LIMIT;
|
|
35
|
+
if ("object" != typeof value || null === value) return String(value);
|
|
36
|
+
if (seen.has(value)) return CIRCULAR;
|
|
37
|
+
seen.add(value);
|
|
38
|
+
try {
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
const kept = value.slice(0, limits.arrayLength).map((item)=>walk(item, limits, seen, depth + 1));
|
|
41
|
+
if (value.length > limits.arrayLength) kept.push(`…(${value.length - limits.arrayLength} more items)`);
|
|
42
|
+
return kept;
|
|
43
|
+
}
|
|
44
|
+
if (value instanceof Map) {
|
|
45
|
+
const entries = [];
|
|
46
|
+
for (const [key, item] of value.entries()){
|
|
47
|
+
if (entries.length >= limits.arrayLength) {
|
|
48
|
+
entries.push(`…(${value.size - limits.arrayLength} more entries)`);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
entries.push([
|
|
52
|
+
walk(key, limits, seen, depth + 1),
|
|
53
|
+
walk(item, limits, seen, depth + 1)
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
__type: "Map",
|
|
58
|
+
entries
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (value instanceof Set) {
|
|
62
|
+
const items = [];
|
|
63
|
+
for (const item of value.values()){
|
|
64
|
+
if (items.length >= limits.arrayLength) {
|
|
65
|
+
items.push(`…(${value.size - limits.arrayLength} more items)`);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
items.push(walk(item, limits, seen, depth + 1));
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
__type: "Set",
|
|
72
|
+
items
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const result = {};
|
|
76
|
+
for (const key of Object.keys(value)){
|
|
77
|
+
let item;
|
|
78
|
+
try {
|
|
79
|
+
item = value[key];
|
|
80
|
+
} catch (ex) {
|
|
81
|
+
result[key] = `#[Throws: ${ex instanceof Error ? ex.message : String(ex)}]`;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (void 0 !== item) result[key] = walk(item, limits, seen, depth + 1);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
} finally{
|
|
88
|
+
seen.delete(value);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const serialize = (value, limits)=>{
|
|
92
|
+
let json;
|
|
93
|
+
try {
|
|
94
|
+
const walked = walk(value, limits, new WeakSet(), 0);
|
|
95
|
+
json = JSON.stringify(walked) ?? JSON.stringify(UNDEFINED);
|
|
96
|
+
} catch (ex) {
|
|
97
|
+
const message = ex instanceof Error ? ex.message : String(ex);
|
|
98
|
+
json = JSON.stringify({
|
|
99
|
+
__serializationFailed: true,
|
|
100
|
+
message
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
let bytes = Buffer.byteLength(json, "utf8");
|
|
104
|
+
let truncated = false;
|
|
105
|
+
if (bytes > limits.entryBytes) {
|
|
106
|
+
json = JSON.stringify({
|
|
107
|
+
truncated: true,
|
|
108
|
+
originalBytes: bytes
|
|
109
|
+
});
|
|
110
|
+
bytes = Buffer.byteLength(json, "utf8");
|
|
111
|
+
truncated = true;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
json,
|
|
115
|
+
bytes,
|
|
116
|
+
truncated
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export { serialize };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/serialize.js","sources":["../../../src/features/debugger/serialize.ts"],"sourcesContent":["import type { IDebuggerLimits } from \"./limits.js\";\n\nexport interface ISerializeResult {\n json: string;\n bytes: number;\n /** True if the value was replaced by the per-entry cap marker. */\n truncated: boolean;\n}\n\n/**\n * Markers stand in for values that cannot be represented as JSON.\n *\n * They are prefixed with `#` so a reader can tell at a glance that a value was substituted by the\n * serializer rather than being what the code actually held - the previous `[undefined]` read as an\n * array literal in documents that are full of real arrays.\n */\nconst UNDEFINED = \"#[Undefined value]\";\nconst CIRCULAR = \"#[Circular]\";\nconst DEPTH_LIMIT = \"#[Depth limit]\";\n\nconst isPlainValue = (value: unknown): boolean => {\n const type = typeof value;\n return type === \"string\" || type === \"number\" || type === \"boolean\" || value === null;\n};\n\nconst describeBinary = (value: ArrayBufferView): string => {\n const name = value.constructor?.name || \"TypedArray\";\n return `#[${name} ${value.byteLength} bytes]`;\n};\n\n/**\n * Walks a value into a JSON-safe structure, applying depth, string and array caps as it goes.\n *\n * Caps are applied during the walk rather than by slicing the finished JSON string, so the output is\n * always parseable.\n *\n * A custom `toJSON` is never invoked - own properties are enumerated instead. That means an object\n * is reported as its internals rather than its intended representation, which is what you want when\n * debugging, and it removes a whole class of failure where a third-party `toJSON` throws.\n */\nconst walk = (\n value: unknown,\n limits: IDebuggerLimits,\n seen: WeakSet<object>,\n depth: number\n): unknown => {\n if (value === undefined) {\n /**\n * Only reached for array elements and for a top-level payload. Object properties holding\n * `undefined` are dropped before they get here, matching `JSON.stringify`.\n *\n * Inside an array the element cannot be dropped without shifting every later index, and\n * `JSON.stringify` would turn it into `null` - which is a meaningful value in its own right.\n */\n return UNDEFINED;\n }\n\n if (isPlainValue(value)) {\n if (typeof value === \"string\" && value.length > limits.stringLength) {\n const kept = value.slice(0, limits.stringLength);\n return `${kept}…(${value.length - limits.stringLength} more)`;\n }\n /**\n * Infinity and NaN serialize to `null`, which silently loses the distinction. Keep them\n * readable instead.\n */\n if (typeof value === \"number\" && !Number.isFinite(value)) {\n return String(value);\n }\n return value;\n }\n\n if (typeof value === \"bigint\") {\n return `${value.toString()}n`;\n }\n\n if (typeof value === \"symbol\") {\n return String(value);\n }\n\n if (typeof value === \"function\") {\n return `#[Function: ${value.name || \"anonymous\"}]`;\n }\n\n if (value instanceof Error) {\n return {\n name: value.name,\n message: value.message,\n stack: value.stack\n };\n }\n\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n if (ArrayBuffer.isView(value)) {\n return describeBinary(value);\n }\n\n if (value instanceof ArrayBuffer) {\n return `#[ArrayBuffer ${value.byteLength} bytes]`;\n }\n\n if (depth >= limits.depth) {\n return DEPTH_LIMIT;\n }\n\n if (typeof value !== \"object\" || value === null) {\n return String(value);\n }\n\n if (seen.has(value)) {\n return CIRCULAR;\n }\n seen.add(value);\n\n try {\n if (Array.isArray(value)) {\n const kept = value.slice(0, limits.arrayLength).map(item => {\n return walk(item, limits, seen, depth + 1);\n });\n if (value.length > limits.arrayLength) {\n kept.push(`…(${value.length - limits.arrayLength} more items)`);\n }\n return kept;\n }\n\n if (value instanceof Map) {\n const entries: unknown[] = [];\n for (const [key, item] of value.entries()) {\n if (entries.length >= limits.arrayLength) {\n entries.push(`…(${value.size - limits.arrayLength} more entries)`);\n break;\n }\n entries.push([\n walk(key, limits, seen, depth + 1),\n walk(item, limits, seen, depth + 1)\n ]);\n }\n return { __type: \"Map\", entries };\n }\n\n if (value instanceof Set) {\n const items: unknown[] = [];\n for (const item of value.values()) {\n if (items.length >= limits.arrayLength) {\n items.push(`…(${value.size - limits.arrayLength} more items)`);\n break;\n }\n items.push(walk(item, limits, seen, depth + 1));\n }\n return { __type: \"Set\", items };\n }\n\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n /**\n * A getter can throw. One bad property must not take down the whole entry, let alone the\n * request that is being observed.\n */\n let item: unknown;\n try {\n item = (value as Record<string, unknown>)[key];\n } catch (ex) {\n result[key] = `#[Throws: ${ex instanceof Error ? ex.message : String(ex)}]`;\n continue;\n }\n\n /**\n * Drop the key, as `JSON.stringify` does.\n *\n * Captured payloads are frequently copies of something that went over the wire, and the\n * wire never carried these keys - keeping them would describe a request that was never\n * made.\n */\n if (item === undefined) {\n continue;\n }\n\n result[key] = walk(item, limits, seen, depth + 1);\n }\n return result;\n } finally {\n /**\n * Only guard against cycles along the current branch. Without this, a value referenced twice\n * as siblings would report the second one as circular.\n */\n seen.delete(value);\n }\n};\n\n/**\n * Serializes a captured payload to JSON, never throwing and always producing valid JSON.\n */\nexport const serialize = (value: unknown, limits: IDebuggerLimits): ISerializeResult => {\n let json: string;\n\n try {\n const walked = walk(value, limits, new WeakSet(), 0);\n json = JSON.stringify(walked) ?? JSON.stringify(UNDEFINED);\n } catch (ex) {\n const message = ex instanceof Error ? ex.message : String(ex);\n json = JSON.stringify({ __serializationFailed: true, message });\n }\n\n let bytes = Buffer.byteLength(json, \"utf8\");\n let truncated = false;\n\n if (bytes > limits.entryBytes) {\n /**\n * Slicing the string would produce invalid JSON, so the payload is replaced wholesale.\n */\n json = JSON.stringify({ truncated: true, originalBytes: bytes });\n bytes = Buffer.byteLength(json, \"utf8\");\n truncated = true;\n }\n\n return { json, bytes, truncated };\n};\n"],"names":["UNDEFINED","CIRCULAR","DEPTH_LIMIT","isPlainValue","value","type","describeBinary","name","walk","limits","seen","depth","undefined","kept","Number","String","Error","Date","RegExp","ArrayBuffer","Array","item","Map","entries","key","Set","items","result","Object","ex","serialize","json","walked","WeakSet","JSON","message","bytes","Buffer","truncated"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
export declare const DEFAULT_ENCRYPTION_ALGORITHM = "aes-256-gcm";
|
|
4
|
+
declare class BuildParamsEncryptionConfigImpl implements EncryptionConfig.Interface {
|
|
5
|
+
readonly passphrase: string | null;
|
|
6
|
+
readonly salt: string;
|
|
7
|
+
readonly algorithm: string;
|
|
8
|
+
constructor(buildParams: BuildParams.Interface);
|
|
9
|
+
}
|
|
10
|
+
export declare const BuildParamsEncryptionConfig: typeof BuildParamsEncryptionConfigImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IEncryptionConfig>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
const DEFAULT_ENCRYPTION_ALGORITHM = "aes-256-gcm";
|
|
4
|
+
class BuildParamsEncryptionConfigImpl {
|
|
5
|
+
constructor(buildParams){
|
|
6
|
+
this.passphrase = buildParams.get("EncryptionPassphrase") || null;
|
|
7
|
+
this.salt = buildParams.get("EncryptionSalt") ?? "";
|
|
8
|
+
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ENCRYPTION_ALGORITHM;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const BuildParamsEncryptionConfig = EncryptionConfig.createImplementation({
|
|
12
|
+
implementation: BuildParamsEncryptionConfigImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
BuildParams
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { BuildParamsEncryptionConfig, DEFAULT_ENCRYPTION_ALGORITHM };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=BuildParamsEncryptionConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/encryption/BuildParamsEncryptionConfig.js","sources":["../../../src/features/encryption/BuildParamsEncryptionConfig.ts"],"sourcesContent":["import { EncryptionConfig } from \"./abstractions.js\";\nimport { BuildParams } from \"../buildParams/abstractions.js\";\n\nexport const DEFAULT_ENCRYPTION_ALGORITHM = \"aes-256-gcm\";\n\nclass BuildParamsEncryptionConfigImpl implements EncryptionConfig.Interface {\n readonly passphrase: string | null;\n readonly salt: string;\n readonly algorithm: string;\n\n constructor(buildParams: BuildParams.Interface) {\n this.passphrase = buildParams.get<string>(\"EncryptionPassphrase\") || null;\n this.salt = buildParams.get<string>(\"EncryptionSalt\") ?? \"\";\n this.algorithm =\n buildParams.get<string>(\"EncryptionAlgorithm\") ?? DEFAULT_ENCRYPTION_ALGORITHM;\n }\n}\n\nexport const BuildParamsEncryptionConfig = EncryptionConfig.createImplementation({\n implementation: BuildParamsEncryptionConfigImpl,\n dependencies: [BuildParams]\n});\n"],"names":["DEFAULT_ENCRYPTION_ALGORITHM","BuildParamsEncryptionConfigImpl","buildParams","BuildParamsEncryptionConfig","EncryptionConfig","BuildParams"],"mappings":";;AAGO,MAAMA,+BAA+B;AAE5C,MAAMC;IAKF,YAAYC,WAAkC,CAAE;QAC5C,IAAI,CAAC,UAAU,GAAGA,YAAY,GAAG,CAAS,2BAA2B;QACrE,IAAI,CAAC,IAAI,GAAGA,YAAY,GAAG,CAAS,qBAAqB;QACzD,IAAI,CAAC,SAAS,GACVA,YAAY,GAAG,CAAS,0BAA0BF;IAC1D;AACJ;AAEO,MAAMG,8BAA8BC,iBAAiB,oBAAoB,CAAC;IAC7E,gBAAgBH;IAChB,cAAc;QAACI;KAAY;AAC/B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register in the ROOT container. Encryption is registered again in every request container, so a
|
|
3
|
+
* cache registered there would start empty on each request and derive the key every time.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EncryptionKeyCacheFeature: {
|
|
6
|
+
name: string;
|
|
7
|
+
register(container: import("@webiny/di").Container): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { MemoryEncryptionKeyCache } from "./MemoryEncryptionKeyCache.js";
|
|
3
|
+
const EncryptionKeyCacheFeature = createFeature({
|
|
4
|
+
name: "EncryptionKeyCache",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(MemoryEncryptionKeyCache).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { EncryptionKeyCacheFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=EncryptionKeyCacheFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/encryption/EncryptionKeyCacheFeature.js","sources":["../../../src/features/encryption/EncryptionKeyCacheFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MemoryEncryptionKeyCache } from \"./MemoryEncryptionKeyCache.js\";\n\n/**\n * Register in the ROOT container. Encryption is registered again in every request container, so a\n * cache registered there would start empty on each request and derive the key every time.\n */\nexport const EncryptionKeyCacheFeature = createFeature({\n name: \"EncryptionKeyCache\",\n register(container) {\n container.register(MemoryEncryptionKeyCache).inSingletonScope();\n }\n});\n"],"names":["EncryptionKeyCacheFeature","createFeature","container","MemoryEncryptionKeyCache"],"mappings":";;AAOO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,0BAA0B,gBAAgB;IACjE;AACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Encryption as EncryptionAbstraction } from "./abstractions.js";
|
|
2
|
-
import {
|
|
2
|
+
import { EncryptionKeyCache } from "./abstractions.js";
|
|
3
|
+
import { EncryptionConfig } from "./abstractions.js";
|
|
3
4
|
export declare class EncryptionImpl implements EncryptionAbstraction.Interface {
|
|
4
5
|
private key;
|
|
5
6
|
private algorithm;
|
|
6
|
-
constructor(
|
|
7
|
+
constructor(config: EncryptionConfig.Interface, keyCache: EncryptionKeyCache.Interface | undefined);
|
|
7
8
|
encrypt(value: string): Promise<string>;
|
|
8
9
|
decrypt(value: string): Promise<string>;
|
|
9
10
|
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import node_crypto from "node:crypto";
|
|
2
2
|
import { createImplementation } from "@webiny/feature/api";
|
|
3
|
-
import { Encryption } from "./abstractions.js";
|
|
4
|
-
import { BuildParams } from "../buildParams/abstractions.js";
|
|
5
|
-
const DEFAULT_ALGORITHM = "aes-256-gcm";
|
|
3
|
+
import { Encryption, EncryptionConfig, EncryptionKeyCache } from "./abstractions.js";
|
|
6
4
|
function keyLengthForAlgorithm(algorithm) {
|
|
7
5
|
const bits = parseInt(algorithm.split("-")[1]);
|
|
8
6
|
if (isNaN(bits)) throw new Error(`Cannot determine key length from algorithm "${algorithm}".`);
|
|
9
7
|
return bits / 8;
|
|
10
8
|
}
|
|
11
9
|
class EncryptionImpl {
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
14
|
-
if (passphrase) {
|
|
15
|
-
const salt = buildParams.get("EncryptionSalt") ?? "";
|
|
16
|
-
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ALGORITHM;
|
|
17
|
-
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
18
|
-
this.key = node_crypto.scryptSync(passphrase, salt, keyLength);
|
|
19
|
-
} else {
|
|
10
|
+
constructor(config, keyCache){
|
|
11
|
+
this.algorithm = config.algorithm;
|
|
12
|
+
if (!config.passphrase) {
|
|
20
13
|
this.key = null;
|
|
21
|
-
|
|
14
|
+
return;
|
|
22
15
|
}
|
|
16
|
+
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
17
|
+
if (keyCache) this.key = keyCache.getOrDerive(config.passphrase, config.salt, keyLength);
|
|
18
|
+
else this.key = node_crypto.scryptSync(config.passphrase, config.salt, keyLength);
|
|
23
19
|
}
|
|
24
20
|
async encrypt(value) {
|
|
25
21
|
if (!this.key) return value;
|
|
@@ -54,7 +50,13 @@ const EncryptionService_Encryption = createImplementation({
|
|
|
54
50
|
abstraction: Encryption,
|
|
55
51
|
implementation: EncryptionImpl,
|
|
56
52
|
dependencies: [
|
|
57
|
-
|
|
53
|
+
EncryptionConfig,
|
|
54
|
+
[
|
|
55
|
+
EncryptionKeyCache,
|
|
56
|
+
{
|
|
57
|
+
optional: true
|
|
58
|
+
}
|
|
59
|
+
]
|
|
58
60
|
]
|
|
59
61
|
});
|
|
60
62
|
export { EncryptionImpl, EncryptionService_Encryption as Encryption };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport { EncryptionKeyCache } from \"./abstractions.js\";\nimport { EncryptionConfig } from \"./abstractions.js\";\n\nfunction keyLengthForAlgorithm(algorithm: string): number {\n // Parse key size in bits from algorithm name (e.g. \"aes-256-gcm\" → 32 bytes).\n const bits = parseInt(algorithm.split(\"-\")[1]);\n if (isNaN(bits)) {\n throw new Error(`Cannot determine key length from algorithm \"${algorithm}\".`);\n }\n return bits / 8;\n}\n\nexport class EncryptionImpl implements EncryptionAbstraction.Interface {\n private key: Buffer | null;\n private algorithm: string;\n\n constructor(\n config: EncryptionConfig.Interface,\n // Registered in the root container, so the derived key outlives the request. Without it (in\n // tests, for example) the key is derived for every instance.\n keyCache: EncryptionKeyCache.Interface | undefined\n ) {\n this.algorithm = config.algorithm;\n\n if (!config.passphrase) {\n this.key = null;\n return;\n }\n\n // Salt is optional. It ensures two projects using the same passphrase derive different keys,\n // but since passphrases should be unique per project anyway, it's extra insurance rather than a necessity.\n const keyLength = keyLengthForAlgorithm(this.algorithm);\n if (keyCache) {\n this.key = keyCache.getOrDerive(config.passphrase, config.salt, keyLength);\n } else {\n this.key = crypto.scryptSync(config.passphrase, config.salt, keyLength);\n }\n }\n\n async encrypt(value: string): Promise<string> {\n if (!this.key) {\n return value;\n }\n const iv = crypto.randomBytes(12);\n const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);\n const encrypted = Buffer.concat([cipher.update(value, \"utf8\"), cipher.final()]);\n const authTag = (cipher as crypto.CipherGCM).getAuthTag();\n return Buffer.concat([iv, authTag, encrypted]).toString(\"base64\");\n }\n\n async decrypt(value: string): Promise<string> {\n if (!this.key) {\n return value;\n }\n const data = Buffer.from(value, \"base64\");\n const iv = data.subarray(0, 12);\n const authTag = data.subarray(12, 28);\n const ciphertext = data.subarray(28);\n const decipher = crypto.createDecipheriv(this.algorithm, this.key, iv);\n (decipher as crypto.DecipherGCM).setAuthTag(authTag);\n return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString(\"utf8\");\n }\n}\n\nexport const Encryption = createImplementation({\n abstraction: EncryptionAbstraction,\n implementation: EncryptionImpl,\n dependencies: [EncryptionConfig, [EncryptionKeyCache, { optional: true }]]\n});\n"],"names":["keyLengthForAlgorithm","algorithm","bits","parseInt","isNaN","Error","EncryptionImpl","config","keyCache","keyLength","crypto","value","iv","cipher","encrypted","Buffer","authTag","data","ciphertext","decipher","Encryption","createImplementation","EncryptionAbstraction","EncryptionConfig","EncryptionKeyCache"],"mappings":";;;AAMA,SAASA,sBAAsBC,SAAiB;IAE5C,MAAMC,OAAOC,SAASF,UAAU,KAAK,CAAC,IAAI,CAAC,EAAE;IAC7C,IAAIG,MAAMF,OACN,MAAM,IAAIG,MAAM,CAAC,4CAA4C,EAAEJ,UAAU,EAAE,CAAC;IAEhF,OAAOC,OAAO;AAClB;AAEO,MAAMI;IAIT,YACIC,MAAkC,EAGlCC,QAAkD,CACpD;QACE,IAAI,CAAC,SAAS,GAAGD,OAAO,SAAS;QAEjC,IAAI,CAACA,OAAO,UAAU,EAAE;YACpB,IAAI,CAAC,GAAG,GAAG;YACX;QACJ;QAIA,MAAME,YAAYT,sBAAsB,IAAI,CAAC,SAAS;QACtD,IAAIQ,UACA,IAAI,CAAC,GAAG,GAAGA,SAAS,WAAW,CAACD,OAAO,UAAU,EAAEA,OAAO,IAAI,EAAEE;aAEhE,IAAI,CAAC,GAAG,GAAGC,YAAAA,UAAiB,CAACH,OAAO,UAAU,EAAEA,OAAO,IAAI,EAAEE;IAErE;IAEA,MAAM,QAAQE,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMC,KAAKF,YAAAA,WAAkB,CAAC;QAC9B,MAAMG,SAASH,YAAAA,cAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAC/D,MAAME,YAAYC,OAAO,MAAM,CAAC;YAACF,OAAO,MAAM,CAACF,OAAO;YAASE,OAAO,KAAK;SAAG;QAC9E,MAAMG,UAAWH,OAA4B,UAAU;QACvD,OAAOE,OAAO,MAAM,CAAC;YAACH;YAAII;YAASF;SAAU,EAAE,QAAQ,CAAC;IAC5D;IAEA,MAAM,QAAQH,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMM,OAAOF,OAAO,IAAI,CAACJ,OAAO;QAChC,MAAMC,KAAKK,KAAK,QAAQ,CAAC,GAAG;QAC5B,MAAMD,UAAUC,KAAK,QAAQ,CAAC,IAAI;QAClC,MAAMC,aAAaD,KAAK,QAAQ,CAAC;QACjC,MAAME,WAAWT,YAAAA,gBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAClEO,SAAgC,UAAU,CAACH;QAC5C,OAAOD,OAAO,MAAM,CAAC;YAACI,SAAS,MAAM,CAACD;YAAaC,SAAS,KAAK;SAAG,EAAE,QAAQ,CAAC;IACnF;AACJ;AAEO,MAAMC,+BAAaC,qBAAqB;IAC3C,aAAaC;IACb,gBAAgBhB;IAChB,cAAc;QAACiB;QAAkB;YAACC;YAAoB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC9E"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncryptionKeyCache as Abstraction } from "./abstractions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps every derived key for the life of the container. Keys depend only on build params, so a
|
|
4
|
+
* process holds one or two at most.
|
|
5
|
+
*/
|
|
6
|
+
declare class MemoryEncryptionKeyCacheImpl implements Abstraction.Interface {
|
|
7
|
+
private readonly keys;
|
|
8
|
+
getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;
|
|
9
|
+
}
|
|
10
|
+
export declare const MemoryEncryptionKeyCache: typeof MemoryEncryptionKeyCacheImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IEncryptionKeyCache>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import node_crypto from "node:crypto";
|
|
2
|
+
import { EncryptionKeyCache } from "./abstractions.js";
|
|
3
|
+
class MemoryEncryptionKeyCacheImpl {
|
|
4
|
+
getOrDerive(passphrase, salt, keyLength) {
|
|
5
|
+
const cacheKey = JSON.stringify([
|
|
6
|
+
passphrase,
|
|
7
|
+
salt,
|
|
8
|
+
keyLength
|
|
9
|
+
]);
|
|
10
|
+
const cached = this.keys.get(cacheKey);
|
|
11
|
+
if (cached) return cached;
|
|
12
|
+
const key = node_crypto.scryptSync(passphrase, salt, keyLength);
|
|
13
|
+
this.keys.set(cacheKey, key);
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
constructor(){
|
|
17
|
+
this.keys = new Map();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const MemoryEncryptionKeyCache = EncryptionKeyCache.createImplementation({
|
|
21
|
+
implementation: MemoryEncryptionKeyCacheImpl,
|
|
22
|
+
dependencies: []
|
|
23
|
+
});
|
|
24
|
+
export { MemoryEncryptionKeyCache };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=MemoryEncryptionKeyCache.js.map
|