@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,102 @@
|
|
|
1
|
+
import { HandlerExecution, HttpRouteHandler } from "@webiny/event-handler-core";
|
|
2
|
+
import { Debugger } from "./abstractions.js";
|
|
3
|
+
import { IdentityContext } from "../security/IdentityContext/index.js";
|
|
4
|
+
import { Logger } from "../logger/index.js";
|
|
5
|
+
import { parseNamespaceHeader } from "./parseNamespaceHeader.js";
|
|
6
|
+
import { canCaptureDebugData } from "./permissions.js";
|
|
7
|
+
import { GRAPHQL_TARGET } from "./GraphQLDebuggerTransport.js";
|
|
8
|
+
const DEBUG_HEADER = "x-webiny-debug";
|
|
9
|
+
const isPlainObject = (value)=>"object" == typeof value && null !== value && !Array.isArray(value);
|
|
10
|
+
const isGraphQLResult = (value)=>isPlainObject(value) && ("data" in value || "errors" in value);
|
|
11
|
+
const isResponseBuilder = (value)=>isPlainObject(value) && "function" == typeof value.toResponse;
|
|
12
|
+
const readBody = (result, response)=>{
|
|
13
|
+
if (isResponseBuilder(result)) return result.toResponse().body;
|
|
14
|
+
if (result) return result.body;
|
|
15
|
+
return response.toResponse().body;
|
|
16
|
+
};
|
|
17
|
+
const resolveTarget = (body)=>{
|
|
18
|
+
const candidate = Array.isArray(body) ? body.at(-1) : body;
|
|
19
|
+
if (isGraphQLResult(candidate)) return candidate;
|
|
20
|
+
};
|
|
21
|
+
const readOperationNames = (body)=>{
|
|
22
|
+
const operations = Array.isArray(body) ? body : [
|
|
23
|
+
body
|
|
24
|
+
];
|
|
25
|
+
return operations.map((operation)=>{
|
|
26
|
+
if (isPlainObject(operation) && "string" == typeof operation.operationName) return operation.operationName;
|
|
27
|
+
}).filter((name)=>Boolean(name));
|
|
28
|
+
};
|
|
29
|
+
const readDebugHeader = (headers)=>{
|
|
30
|
+
if (!headers) return;
|
|
31
|
+
for (const key of Object.keys(headers))if (key.toLowerCase() === DEBUG_HEADER) return headers[key];
|
|
32
|
+
};
|
|
33
|
+
const describeError = (error)=>{
|
|
34
|
+
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
35
|
+
return "Unknown error.";
|
|
36
|
+
};
|
|
37
|
+
class DebuggerRouteDecoratorImpl {
|
|
38
|
+
constructor(debuggerService, identityContext, logger, handlerExecution, decoratee){
|
|
39
|
+
this.debuggerService = debuggerService;
|
|
40
|
+
this.identityContext = identityContext;
|
|
41
|
+
this.logger = logger;
|
|
42
|
+
this.handlerExecution = handlerExecution;
|
|
43
|
+
this.decoratee = decoratee;
|
|
44
|
+
}
|
|
45
|
+
async handle(request, response) {
|
|
46
|
+
this.start(request);
|
|
47
|
+
let result;
|
|
48
|
+
try {
|
|
49
|
+
result = await this.decoratee.handle(request, response);
|
|
50
|
+
} catch (ex) {
|
|
51
|
+
this.debuggerService.discard();
|
|
52
|
+
throw ex;
|
|
53
|
+
}
|
|
54
|
+
await this.flush(request, readBody(result, response));
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
start(request) {
|
|
58
|
+
try {
|
|
59
|
+
const requested = parseNamespaceHeader(readDebugHeader(request.headers));
|
|
60
|
+
const namespaces = requested.length > 0 ? requested : [
|
|
61
|
+
"*"
|
|
62
|
+
];
|
|
63
|
+
this.debuggerService.start({
|
|
64
|
+
namespaces
|
|
65
|
+
});
|
|
66
|
+
} catch {}
|
|
67
|
+
}
|
|
68
|
+
async flush(request, body) {
|
|
69
|
+
try {
|
|
70
|
+
const result = resolveTarget(body);
|
|
71
|
+
if (!result) return void this.debuggerService.discard();
|
|
72
|
+
if (this.identityContext.getIdentity().isAnonymous()) return void this.debuggerService.discard();
|
|
73
|
+
const isAuthorized = this.identityContext.isAuthorizationEnabled() && await canCaptureDebugData(this.identityContext);
|
|
74
|
+
if (!isAuthorized) return void this.debuggerService.discard();
|
|
75
|
+
const target = {
|
|
76
|
+
type: GRAPHQL_TARGET,
|
|
77
|
+
result,
|
|
78
|
+
requestId: this.handlerExecution.getId(),
|
|
79
|
+
operations: readOperationNames(request.body),
|
|
80
|
+
url: request.path
|
|
81
|
+
};
|
|
82
|
+
await this.debuggerService.flush(target);
|
|
83
|
+
} catch (ex) {
|
|
84
|
+
this.logger.error({
|
|
85
|
+
error: describeError(ex)
|
|
86
|
+
}, "Debugger failed to flush.");
|
|
87
|
+
this.debuggerService.discard();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const DebuggerRouteDecorator = HttpRouteHandler.createDecorator({
|
|
92
|
+
decorator: DebuggerRouteDecoratorImpl,
|
|
93
|
+
dependencies: [
|
|
94
|
+
Debugger,
|
|
95
|
+
IdentityContext,
|
|
96
|
+
Logger,
|
|
97
|
+
HandlerExecution
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
export { DEBUG_HEADER, DebuggerRouteDecorator };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=DebuggerRouteDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/DebuggerRouteDecorator.js","sources":["../../../src/features/debugger/DebuggerRouteDecorator.ts"],"sourcesContent":["import { HttpRouteHandler } from \"@webiny/event-handler-core\";\nimport { HandlerExecution } from \"@webiny/event-handler-core\";\nimport type { IHttpResponse } from \"@webiny/event-handler-core\";\nimport type { IHttpResponseBuilder } from \"@webiny/event-handler-core\";\nimport { Debugger } from \"./abstractions.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { Logger } from \"~/features/logger/index.js\";\nimport { parseNamespaceHeader } from \"./parseNamespaceHeader.js\";\nimport { canCaptureDebugData } from \"./permissions.js\";\nimport { GRAPHQL_TARGET } from \"./GraphQLDebuggerTransport.js\";\nimport type { IGraphQLDeliveryTarget } from \"./GraphQLDebuggerTransport.js\";\n\nexport const DEBUG_HEADER = \"x-webiny-debug\";\n\ntype RouteResult = IHttpResponse | IHttpResponseBuilder | void;\n\nconst isPlainObject = (value: unknown): value is Record<string, any> => {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\n/**\n * A GraphQL result carries `data` or `errors`. Anything else (asset delivery, a plain string body)\n * is not ours to write to.\n */\nconst isGraphQLResult = (value: unknown): value is Record<string, any> => {\n return isPlainObject(value) && (\"data\" in value || \"errors\" in value);\n};\n\nconst isResponseBuilder = (value: unknown): value is IHttpResponseBuilder => {\n return isPlainObject(value) && typeof value.toResponse === \"function\";\n};\n\n/**\n * Finds the body a route produced, whichever of its three return styles it used. The body object is\n * the same reference the transport later serializes, so writing to it is enough.\n */\nconst readBody = (result: RouteResult, response: IHttpResponseBuilder): unknown => {\n if (isResponseBuilder(result)) {\n return result.toResponse().body;\n }\n if (result) {\n return result.body;\n }\n return response.toResponse().body;\n};\n\n/**\n * Batched requests produce an array of results. The session spans the whole HTTP request, so it is\n * attached once, to the last element. Duplicating it per operation would multiply it against the\n * byte budget.\n */\nconst resolveTarget = (body: unknown): Record<string, any> | undefined => {\n const candidate = Array.isArray(body) ? body.at(-1) : body;\n if (isGraphQLResult(candidate)) {\n return candidate;\n }\n return undefined;\n};\n\nconst readOperationNames = (body: unknown): string[] => {\n const operations = Array.isArray(body) ? body : [body];\n return operations\n .map(operation => {\n if (isPlainObject(operation) && typeof operation.operationName === \"string\") {\n return operation.operationName;\n }\n return undefined;\n })\n .filter((name): name is string => Boolean(name));\n};\n\n/**\n * Header names are case-insensitive, and the casing that reaches a route depends on the transport.\n */\nconst readDebugHeader = (headers: Record<string, string> | undefined): string | undefined => {\n if (!headers) {\n return undefined;\n }\n for (const key of Object.keys(headers)) {\n if (key.toLowerCase() === DEBUG_HEADER) {\n return headers[key];\n }\n }\n return undefined;\n};\n\nconst describeError = (error: unknown): string => {\n if (error instanceof Error) {\n return `${error.name}: ${error.message}`;\n }\n return \"Unknown error.\";\n};\n\n/**\n * Opens a capture session around every HTTP route and hands it over once the route has produced its\n * response.\n *\n * It wraps the route rather than the GraphQL execution, because CMS resolvers run nested GraphQL\n * executions internally. Attaching there would put the session on a result that is then thrown\n * away; at the route there is exactly one response per request.\n */\nclass DebuggerRouteDecoratorImpl implements HttpRouteHandler.Interface {\n public constructor(\n private readonly debuggerService: Debugger.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly logger: Logger.Interface,\n private readonly handlerExecution: HandlerExecution.Interface,\n private readonly decoratee: HttpRouteHandler.Interface\n ) {}\n\n public async handle(\n request: HttpRouteHandler.Request,\n response: HttpRouteHandler.Response\n ): Promise<RouteResult> {\n this.start(request);\n\n let result: RouteResult;\n try {\n result = await this.decoratee.handle(request, response);\n } catch (ex) {\n this.debuggerService.discard();\n throw ex;\n }\n\n await this.flush(request, readBody(result, response));\n\n return result;\n }\n\n /**\n * A session starts on every request, and the permission check at flush decides whether anything\n * is delivered or the whole thing is discarded.\n *\n * Nothing is required from the client. The header is honoured when present, so a direct API\n * client can narrow what it captures.\n */\n private start(request: HttpRouteHandler.Request): void {\n /**\n * Must never throw: a malformed header must not turn into a 500 for the whole request.\n */\n try {\n const requested = parseNamespaceHeader(readDebugHeader(request.headers));\n const namespaces = requested.length > 0 ? requested : [\"*\"];\n\n this.debuggerService.start({ namespaces });\n } catch {\n // A debugger that cannot start is not a reason to fail the request.\n }\n }\n\n /**\n * Performs the permission gate and hands the session to the transports.\n *\n * The whole body is guarded: an error here would turn a working response into a 500, and only\n * for the identities that are allowed to debug.\n */\n private async flush(request: HttpRouteHandler.Request, body: unknown): Promise<void> {\n try {\n const result = resolveTarget(body);\n if (!result) {\n this.debuggerService.discard();\n return;\n }\n\n /**\n * Anonymous callers are rejected before permissions are resolved, because listing them\n * runs every registered authorizer, and some of those hit the database.\n */\n if (this.identityContext.getIdentity().isAnonymous()) {\n this.debuggerService.discard();\n return;\n }\n\n /**\n * Permission lookups return a wildcard whenever authorization is disabled, so a flush\n * running inside a `withoutAuthorization` scope would pass for anyone.\n */\n const isAuthorized =\n this.identityContext.isAuthorizationEnabled() &&\n (await canCaptureDebugData(this.identityContext));\n\n if (!isAuthorized) {\n /**\n * Nothing is written. Reporting the denial would tell every unauthorized caller that\n * the feature exists, and the Admin app already knows from the identity's own\n * permissions whether capture is available to it.\n */\n this.debuggerService.discard();\n return;\n }\n\n const target: IGraphQLDeliveryTarget = {\n type: GRAPHQL_TARGET,\n result,\n requestId: this.handlerExecution.getId(),\n operations: readOperationNames(request.body),\n /**\n * Which endpoint this was. An Admin session talks to several (the main API and the\n * CMS manage, read and preview endpoints) and knowing which one produced an entry is\n * most of the context when reading a report.\n */\n url: request.path\n };\n\n await this.debuggerService.flush(target);\n } catch (ex) {\n /**\n * Only the message, never the session or the payload.\n */\n this.logger.error({ error: describeError(ex) }, \"Debugger failed to flush.\");\n this.debuggerService.discard();\n }\n }\n}\n\nexport const DebuggerRouteDecorator = HttpRouteHandler.createDecorator({\n decorator: DebuggerRouteDecoratorImpl,\n dependencies: [Debugger, IdentityContext, Logger, HandlerExecution]\n});\n"],"names":["DEBUG_HEADER","isPlainObject","value","Array","isGraphQLResult","isResponseBuilder","readBody","result","response","resolveTarget","body","candidate","readOperationNames","operations","operation","name","Boolean","readDebugHeader","headers","key","Object","describeError","error","Error","DebuggerRouteDecoratorImpl","debuggerService","identityContext","logger","handlerExecution","decoratee","request","ex","requested","parseNamespaceHeader","namespaces","isAuthorized","canCaptureDebugData","target","GRAPHQL_TARGET","DebuggerRouteDecorator","HttpRouteHandler","Debugger","IdentityContext","Logger","HandlerExecution"],"mappings":";;;;;;;AAYO,MAAMA,eAAe;AAI5B,MAAMC,gBAAgB,CAACC,QACZ,AAAiB,YAAjB,OAAOA,SAAsBA,AAAU,SAAVA,SAAkB,CAACC,MAAM,OAAO,CAACD;AAOzE,MAAME,kBAAkB,CAACF,QACdD,cAAcC,UAAW,WAAUA,SAAS,YAAYA,KAAI;AAGvE,MAAMG,oBAAoB,CAACH,QAChBD,cAAcC,UAAU,AAA4B,cAA5B,OAAOA,MAAM,UAAU;AAO1D,MAAMI,WAAW,CAACC,QAAqBC;IACnC,IAAIH,kBAAkBE,SAClB,OAAOA,OAAO,UAAU,GAAG,IAAI;IAEnC,IAAIA,QACA,OAAOA,OAAO,IAAI;IAEtB,OAAOC,SAAS,UAAU,GAAG,IAAI;AACrC;AAOA,MAAMC,gBAAgB,CAACC;IACnB,MAAMC,YAAYR,MAAM,OAAO,CAACO,QAAQA,KAAK,EAAE,CAAC,MAAMA;IACtD,IAAIN,gBAAgBO,YAChB,OAAOA;AAGf;AAEA,MAAMC,qBAAqB,CAACF;IACxB,MAAMG,aAAaV,MAAM,OAAO,CAACO,QAAQA,OAAO;QAACA;KAAK;IACtD,OAAOG,WACF,GAAG,CAACC,CAAAA;QACD,IAAIb,cAAca,cAAc,AAAmC,YAAnC,OAAOA,UAAU,aAAa,EAC1D,OAAOA,UAAU,aAAa;IAGtC,GACC,MAAM,CAAC,CAACC,OAAyBC,QAAQD;AAClD;AAKA,MAAME,kBAAkB,CAACC;IACrB,IAAI,CAACA,SACD;IAEJ,KAAK,MAAMC,OAAOC,OAAO,IAAI,CAACF,SAC1B,IAAIC,IAAI,WAAW,OAAOnB,cACtB,OAAOkB,OAAO,CAACC,IAAI;AAI/B;AAEA,MAAME,gBAAgB,CAACC;IACnB,IAAIA,iBAAiBC,OACjB,OAAO,GAAGD,MAAM,IAAI,CAAC,EAAE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AAiC;gBACnC,MAAMC;gBACN/B;gBACA,WAAW,IAAI,CAAC,gBAAgB,CAAC,KAAK;gBACtC,YAAYK,mBAAmBkB,QAAQ,IAAI;gBAM3C,KAAKA,QAAQ,IAAI;YACrB;YAEA,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK,CAACO;QACrC,EAAE,OAAON,IAAI;YAIT,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAOV,cAAcU;YAAI,GAAG;YAChD,IAAI,CAAC,eAAe,CAAC,OAAO;QAChC;IACJ;AACJ;AAEO,MAAMQ,yBAAyBC,iBAAiB,eAAe,CAAC;IACnE,WAAWhB;IACX,cAAc;QAACiB;QAAUC;QAAiBC;QAAQC;KAAiB;AACvE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DebuggerTransport as DebuggerTransportAbstraction } from "./abstractions.js";
|
|
2
|
+
import type { IDebugDeliveryTarget } from "./abstractions.js";
|
|
3
|
+
import type { IDebuggerTransportDeliverParams } from "./abstractions.js";
|
|
4
|
+
export declare const GRAPHQL_TARGET = "graphql";
|
|
5
|
+
export interface IGraphQLDeliveryTarget extends IDebugDeliveryTarget {
|
|
6
|
+
type: typeof GRAPHQL_TARGET;
|
|
7
|
+
/**
|
|
8
|
+
* Already resolved to a single result object - never the array. Batched requests are reduced to
|
|
9
|
+
* their last element by the route decorator, so this transport never has to know about batching.
|
|
10
|
+
*/
|
|
11
|
+
result: Record<string, any>;
|
|
12
|
+
requestId: string;
|
|
13
|
+
operations: string[];
|
|
14
|
+
url: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes a finished session into the GraphQL response's `extensions` property.
|
|
18
|
+
*/
|
|
19
|
+
export declare class GraphQLDebuggerTransportImpl implements DebuggerTransportAbstraction.Interface {
|
|
20
|
+
canDeliver(target: IDebugDeliveryTarget): boolean;
|
|
21
|
+
deliver({ target, session }: IDebuggerTransportDeliverParams): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Merges a value under `extensions.debug`, never assigning `extensions` wholesale - other plugins
|
|
25
|
+
* write to it too.
|
|
26
|
+
*/
|
|
27
|
+
export declare const writeExtension: (result: Record<string, any>, debug: Record<string, any>) => void;
|
|
28
|
+
export declare const GraphQLDebuggerTransport: import("@webiny/di").Implementation<typeof GraphQLDebuggerTransportImpl>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { DebuggerTransport } from "./abstractions.js";
|
|
3
|
+
const GRAPHQL_TARGET = "graphql";
|
|
4
|
+
const isGraphQLTarget = (target)=>target.type === GRAPHQL_TARGET;
|
|
5
|
+
class GraphQLDebuggerTransportImpl {
|
|
6
|
+
canDeliver(target) {
|
|
7
|
+
return isGraphQLTarget(target);
|
|
8
|
+
}
|
|
9
|
+
deliver({ target, session }) {
|
|
10
|
+
if (!isGraphQLTarget(target)) return;
|
|
11
|
+
if (0 === session.entries.length) return;
|
|
12
|
+
const entries = session.entries.map((entry)=>({
|
|
13
|
+
seq: entry.seq,
|
|
14
|
+
namespace: entry.namespace,
|
|
15
|
+
timestamp: entry.timestamp,
|
|
16
|
+
elapsed: entry.elapsed,
|
|
17
|
+
data: JSON.parse(entry.json)
|
|
18
|
+
}));
|
|
19
|
+
writeExtension(target.result, {
|
|
20
|
+
enabled: true,
|
|
21
|
+
requestId: target.requestId,
|
|
22
|
+
url: target.url,
|
|
23
|
+
namespaces: session.namespaces,
|
|
24
|
+
operations: target.operations,
|
|
25
|
+
entries,
|
|
26
|
+
bytes: session.bytes,
|
|
27
|
+
dropped: session.dropped,
|
|
28
|
+
truncated: session.truncated
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const writeExtension = (result, debug)=>{
|
|
33
|
+
result.extensions = {
|
|
34
|
+
...result.extensions,
|
|
35
|
+
debug
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const GraphQLDebuggerTransport = createImplementation({
|
|
39
|
+
abstraction: DebuggerTransport,
|
|
40
|
+
implementation: GraphQLDebuggerTransportImpl,
|
|
41
|
+
dependencies: []
|
|
42
|
+
});
|
|
43
|
+
export { GRAPHQL_TARGET, GraphQLDebuggerTransport, GraphQLDebuggerTransportImpl, writeExtension };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=GraphQLDebuggerTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/GraphQLDebuggerTransport.js","sources":["../../../src/features/debugger/GraphQLDebuggerTransport.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { DebuggerTransport as DebuggerTransportAbstraction } from \"./abstractions.js\";\nimport type { IDebugDeliveryTarget } from \"./abstractions.js\";\nimport type { IDebuggerTransportDeliverParams } from \"./abstractions.js\";\n\nexport const GRAPHQL_TARGET = \"graphql\";\n\nexport interface IGraphQLDeliveryTarget extends IDebugDeliveryTarget {\n type: typeof GRAPHQL_TARGET;\n /**\n * Already resolved to a single result object - never the array. Batched requests are reduced to\n * their last element by the route decorator, so this transport never has to know about batching.\n */\n result: Record<string, any>;\n requestId: string;\n operations: string[];\n url: string;\n}\n\nconst isGraphQLTarget = (target: IDebugDeliveryTarget): target is IGraphQLDeliveryTarget => {\n return target.type === GRAPHQL_TARGET;\n};\n\n/**\n * Writes a finished session into the GraphQL response's `extensions` property.\n */\nexport class GraphQLDebuggerTransportImpl implements DebuggerTransportAbstraction.Interface {\n public canDeliver(target: IDebugDeliveryTarget): boolean {\n return isGraphQLTarget(target);\n }\n\n public deliver({ target, session }: IDebuggerTransportDeliverParams): void {\n if (!isGraphQLTarget(target)) {\n return;\n }\n\n /**\n * Nothing matched the filter on this request. Writing an envelope with an empty `entries`\n * array would put a payload on every response for no benefit, and give whoever reads the\n * report a pile of blanks to scroll past.\n */\n if (session.entries.length === 0) {\n return;\n }\n\n const entries = session.entries.map(entry => {\n return {\n seq: entry.seq,\n namespace: entry.namespace,\n timestamp: entry.timestamp,\n elapsed: entry.elapsed,\n /**\n * Entries are buffered as strings so the payload graph can be released at capture\n * time. Parsing here is what puts structured data in the response rather than JSON\n * inside JSON.\n */\n data: JSON.parse(entry.json)\n };\n });\n\n writeExtension(target.result, {\n enabled: true,\n requestId: target.requestId,\n url: target.url,\n namespaces: session.namespaces,\n operations: target.operations,\n entries,\n bytes: session.bytes,\n dropped: session.dropped,\n truncated: session.truncated\n });\n }\n}\n\n/**\n * Merges a value under `extensions.debug`, never assigning `extensions` wholesale - other plugins\n * write to it too.\n */\nexport const writeExtension = (result: Record<string, any>, debug: Record<string, any>): void => {\n result.extensions = { ...result.extensions, debug };\n};\n\nexport const GraphQLDebuggerTransport = createImplementation({\n abstraction: DebuggerTransportAbstraction,\n implementation: GraphQLDebuggerTransportImpl,\n dependencies: []\n});\n"],"names":["GRAPHQL_TARGET","isGraphQLTarget","target","GraphQLDebuggerTransportImpl","session","entries","entry","JSON","writeExtension","result","debug","GraphQLDebuggerTransport","createImplementation","DebuggerTransportAbstraction"],"mappings":";;AAKO,MAAMA,iBAAiB;AAc9B,MAAMC,kBAAkB,CAACC,SACdA,OAAO,IAAI,KAAKF;AAMpB,MAAMG;IACF,WAAWD,MAA4B,EAAW;QACrD,OAAOD,gBAAgBC;IAC3B;IAEO,QAAQ,EAAEA,MAAM,EAAEE,OAAO,EAAmC,EAAQ;QACvE,IAAI,CAACH,gBAAgBC,SACjB;QAQJ,IAAIE,AAA2B,MAA3BA,QAAQ,OAAO,CAAC,MAAM,EACtB;QAGJ,MAAMC,UAAUD,QAAQ,OAAO,CAAC,GAAG,CAACE,CAAAA,QACzB;gBACH,KAAKA,MAAM,GAAG;gBACd,WAAWA,MAAM,SAAS;gBAC1B,WAAWA,MAAM,SAAS;gBAC1B,SAASA,MAAM,OAAO;gBAMtB,MAAMC,KAAK,KAAK,CAACD,MAAM,IAAI;YAC/B;QAGJE,eAAeN,OAAO,MAAM,EAAE;YAC1B,SAAS;YACT,WAAWA,OAAO,SAAS;YAC3B,KAAKA,OAAO,GAAG;YACf,YAAYE,QAAQ,UAAU;YAC9B,YAAYF,OAAO,UAAU;YAC7BG;YACA,OAAOD,QAAQ,KAAK;YACpB,SAASA,QAAQ,OAAO;YACxB,WAAWA,QAAQ,SAAS;QAChC;IACJ;AACJ;AAMO,MAAMI,iBAAiB,CAACC,QAA6BC;IACxDD,OAAO,UAAU,GAAG;QAAE,GAAGA,OAAO,UAAU;QAAEC;IAAM;AACtD;AAEO,MAAMC,2BAA2BC,qBAAqB;IACzD,aAAaC;IACb,gBAAgBV;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createNamespaceFilter } from "../matchNamespace.js";
|
|
3
|
+
import { parseNamespaceHeader } from "../parseNamespaceHeader.js";
|
|
4
|
+
describe("parseNamespaceHeader", ()=>{
|
|
5
|
+
it("should not start a session when the header is absent or empty", ()=>{
|
|
6
|
+
expect(parseNamespaceHeader(void 0)).toEqual([]);
|
|
7
|
+
expect(parseNamespaceHeader("")).toEqual([]);
|
|
8
|
+
expect(parseNamespaceHeader(" ")).toEqual([]);
|
|
9
|
+
});
|
|
10
|
+
it("should treat the truthy shorthands as capture-all", ()=>{
|
|
11
|
+
expect(parseNamespaceHeader("1")).toEqual([
|
|
12
|
+
"*"
|
|
13
|
+
]);
|
|
14
|
+
expect(parseNamespaceHeader("true")).toEqual([
|
|
15
|
+
"*"
|
|
16
|
+
]);
|
|
17
|
+
expect(parseNamespaceHeader("*")).toEqual([
|
|
18
|
+
"*"
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
it("should trim tokens, since duplicate headers arrive comma-joined with spaces", ()=>{
|
|
22
|
+
expect(parseNamespaceHeader("cms.os.*, fm.*")).toEqual([
|
|
23
|
+
"cms.os.*",
|
|
24
|
+
"fm.*"
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
it("should accept the array form of a repeated header", ()=>{
|
|
28
|
+
expect(parseNamespaceHeader([
|
|
29
|
+
"cms.os.*",
|
|
30
|
+
"fm.*"
|
|
31
|
+
])).toEqual([
|
|
32
|
+
"cms.os.*",
|
|
33
|
+
"fm.*"
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("createNamespaceFilter", ()=>{
|
|
38
|
+
it("should match everything for the wildcard", ()=>{
|
|
39
|
+
const filter = createNamespaceFilter([
|
|
40
|
+
"*"
|
|
41
|
+
]);
|
|
42
|
+
expect(filter.matches("cms.os.list")).toBe(true);
|
|
43
|
+
expect(filter.matches("core.anything")).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
it("should match a prefix glob across dots", ()=>{
|
|
46
|
+
const filter = createNamespaceFilter([
|
|
47
|
+
"cms.*"
|
|
48
|
+
]);
|
|
49
|
+
expect(filter.matches("cms.os.list")).toBe(true);
|
|
50
|
+
expect(filter.matches("fm.file.get")).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
it("should exclude rather than invert on negation", ()=>{
|
|
53
|
+
const filter = createNamespaceFilter([
|
|
54
|
+
"*",
|
|
55
|
+
"!cms.os.*"
|
|
56
|
+
]);
|
|
57
|
+
expect(filter.matches("cms.os.list")).toBe(false);
|
|
58
|
+
expect(filter.matches("fm.file.get")).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
it("should require at least one positive match", ()=>{
|
|
61
|
+
const filter = createNamespaceFilter([
|
|
62
|
+
"!cms.os.*"
|
|
63
|
+
]);
|
|
64
|
+
expect(filter.matches("fm.file.get")).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=matchNamespace.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/__tests__/matchNamespace.test.js","sources":["../../../../src/features/debugger/__tests__/matchNamespace.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { createNamespaceFilter } from \"../matchNamespace.js\";\nimport { parseNamespaceHeader } from \"../parseNamespaceHeader.js\";\n\ndescribe(\"parseNamespaceHeader\", () => {\n it(\"should not start a session when the header is absent or empty\", () => {\n expect(parseNamespaceHeader(undefined)).toEqual([]);\n expect(parseNamespaceHeader(\"\")).toEqual([]);\n expect(parseNamespaceHeader(\" \")).toEqual([]);\n });\n\n it(\"should treat the truthy shorthands as capture-all\", () => {\n expect(parseNamespaceHeader(\"1\")).toEqual([\"*\"]);\n expect(parseNamespaceHeader(\"true\")).toEqual([\"*\"]);\n expect(parseNamespaceHeader(\"*\")).toEqual([\"*\"]);\n });\n\n it(\"should trim tokens, since duplicate headers arrive comma-joined with spaces\", () => {\n expect(parseNamespaceHeader(\"cms.os.*, fm.*\")).toEqual([\"cms.os.*\", \"fm.*\"]);\n });\n\n it(\"should accept the array form of a repeated header\", () => {\n expect(parseNamespaceHeader([\"cms.os.*\", \"fm.*\"])).toEqual([\"cms.os.*\", \"fm.*\"]);\n });\n});\n\ndescribe(\"createNamespaceFilter\", () => {\n it(\"should match everything for the wildcard\", () => {\n const filter = createNamespaceFilter([\"*\"]);\n\n expect(filter.matches(\"cms.os.list\")).toBe(true);\n expect(filter.matches(\"core.anything\")).toBe(true);\n });\n\n it(\"should match a prefix glob across dots\", () => {\n const filter = createNamespaceFilter([\"cms.*\"]);\n\n expect(filter.matches(\"cms.os.list\")).toBe(true);\n expect(filter.matches(\"fm.file.get\")).toBe(false);\n });\n\n it(\"should exclude rather than invert on negation\", () => {\n const filter = createNamespaceFilter([\"*\", \"!cms.os.*\"]);\n\n expect(filter.matches(\"cms.os.list\")).toBe(false);\n expect(filter.matches(\"fm.file.get\")).toBe(true);\n });\n\n it(\"should require at least one positive match\", () => {\n const filter = createNamespaceFilter([\"!cms.os.*\"]);\n\n expect(filter.matches(\"fm.file.get\")).toBe(false);\n });\n});\n"],"names":["describe","it","expect","parseNamespaceHeader","undefined","filter","createNamespaceFil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DJ,OAAOG,OAAO,OAAO,CAAC,gBAAgB,IAAI,CAAC;IAC/C;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { serialize } from "../serialize.js";
|
|
3
|
+
import { DEFAULT_LIMITS } from "../limits.js";
|
|
4
|
+
const limits = (overrides = {})=>({
|
|
5
|
+
...DEFAULT_LIMITS,
|
|
6
|
+
...overrides
|
|
7
|
+
});
|
|
8
|
+
const parse = (value, overrides = {})=>{
|
|
9
|
+
const result = serialize(value, limits(overrides));
|
|
10
|
+
return {
|
|
11
|
+
...result,
|
|
12
|
+
parsed: JSON.parse(result.json)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
describe("serialize", ()=>{
|
|
16
|
+
it("should always produce parseable JSON", ()=>{
|
|
17
|
+
const circular = {
|
|
18
|
+
name: "root"
|
|
19
|
+
};
|
|
20
|
+
circular.self = circular;
|
|
21
|
+
const { parsed } = parse(circular);
|
|
22
|
+
expect(parsed).toEqual({
|
|
23
|
+
name: "root",
|
|
24
|
+
self: "#[Circular]"
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it("should not report siblings as circular", ()=>{
|
|
28
|
+
const shared = {
|
|
29
|
+
id: 1
|
|
30
|
+
};
|
|
31
|
+
const { parsed } = parse({
|
|
32
|
+
a: shared,
|
|
33
|
+
b: shared
|
|
34
|
+
});
|
|
35
|
+
expect(parsed).toEqual({
|
|
36
|
+
a: {
|
|
37
|
+
id: 1
|
|
38
|
+
},
|
|
39
|
+
b: {
|
|
40
|
+
id: 1
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it("should serialize an Error, which JSON.stringify renders as an empty object", ()=>{
|
|
45
|
+
const error = new Error("Boom");
|
|
46
|
+
const { parsed } = parse({
|
|
47
|
+
error
|
|
48
|
+
});
|
|
49
|
+
expect(parsed.error.name).toBe("Error");
|
|
50
|
+
expect(parsed.error.message).toBe("Boom");
|
|
51
|
+
expect(typeof parsed.error.stack).toBe("string");
|
|
52
|
+
});
|
|
53
|
+
it("should serialize a BigInt, which JSON.stringify throws on", ()=>{
|
|
54
|
+
const { parsed } = parse({
|
|
55
|
+
value: BigInt(123)
|
|
56
|
+
});
|
|
57
|
+
expect(parsed).toEqual({
|
|
58
|
+
value: "123n"
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it("should describe binary data without including its contents", ()=>{
|
|
62
|
+
const { parsed } = parse({
|
|
63
|
+
buffer: Buffer.from("hello world")
|
|
64
|
+
});
|
|
65
|
+
expect(parsed).toEqual({
|
|
66
|
+
buffer: "#[Buffer 11 bytes]"
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
it("should serialize Map and Set", ()=>{
|
|
70
|
+
const { parsed } = parse({
|
|
71
|
+
map: new Map([
|
|
72
|
+
[
|
|
73
|
+
"a",
|
|
74
|
+
1
|
|
75
|
+
]
|
|
76
|
+
]),
|
|
77
|
+
set: new Set([
|
|
78
|
+
1,
|
|
79
|
+
2
|
|
80
|
+
])
|
|
81
|
+
});
|
|
82
|
+
expect(parsed.map).toEqual({
|
|
83
|
+
__type: "Map",
|
|
84
|
+
entries: [
|
|
85
|
+
[
|
|
86
|
+
"a",
|
|
87
|
+
1
|
|
88
|
+
]
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
expect(parsed.set).toEqual({
|
|
92
|
+
__type: "Set",
|
|
93
|
+
items: [
|
|
94
|
+
1,
|
|
95
|
+
2
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it("should drop an undefined property, so a logged payload matches what was sent", ()=>{
|
|
100
|
+
const { parsed } = parse({
|
|
101
|
+
kept: 1,
|
|
102
|
+
dropped: void 0
|
|
103
|
+
});
|
|
104
|
+
expect(parsed).toEqual({
|
|
105
|
+
kept: 1
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
it("should keep undefined array elements, where dropping would shift every later index", ()=>{
|
|
109
|
+
const { parsed } = parse({
|
|
110
|
+
items: [
|
|
111
|
+
1,
|
|
112
|
+
void 0,
|
|
113
|
+
3
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
expect(parsed).toEqual({
|
|
117
|
+
items: [
|
|
118
|
+
1,
|
|
119
|
+
"#[Undefined value]",
|
|
120
|
+
3
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it("should not throw when a getter throws", ()=>{
|
|
125
|
+
const value = {
|
|
126
|
+
get exploding () {
|
|
127
|
+
throw new Error("Nope");
|
|
128
|
+
},
|
|
129
|
+
safe: 1
|
|
130
|
+
};
|
|
131
|
+
const { parsed } = parse(value);
|
|
132
|
+
expect(parsed.exploding).toBe("#[Throws: Nope]");
|
|
133
|
+
expect(parsed.safe).toBe(1);
|
|
134
|
+
});
|
|
135
|
+
it("should cap depth", ()=>{
|
|
136
|
+
const { parsed } = parse({
|
|
137
|
+
a: {
|
|
138
|
+
b: {
|
|
139
|
+
c: {
|
|
140
|
+
d: "deep"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
depth: 2
|
|
146
|
+
});
|
|
147
|
+
expect(parsed).toEqual({
|
|
148
|
+
a: {
|
|
149
|
+
b: "#[Depth limit]"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
it("should cap string length and say how much was cut", ()=>{
|
|
154
|
+
const { parsed } = parse({
|
|
155
|
+
text: "x".repeat(20)
|
|
156
|
+
}, {
|
|
157
|
+
stringLength: 5
|
|
158
|
+
});
|
|
159
|
+
expect(parsed).toEqual({
|
|
160
|
+
text: "xxxxx…(15 more)"
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
it("should cap array length and say how much was cut", ()=>{
|
|
164
|
+
const { parsed } = parse({
|
|
165
|
+
items: [
|
|
166
|
+
1,
|
|
167
|
+
2,
|
|
168
|
+
3,
|
|
169
|
+
4,
|
|
170
|
+
5
|
|
171
|
+
]
|
|
172
|
+
}, {
|
|
173
|
+
arrayLength: 2
|
|
174
|
+
});
|
|
175
|
+
expect(parsed).toEqual({
|
|
176
|
+
items: [
|
|
177
|
+
1,
|
|
178
|
+
2,
|
|
179
|
+
"…(3 more items)"
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
it("should replace the payload wholesale when it exceeds the per-entry cap", ()=>{
|
|
184
|
+
const result = parse({
|
|
185
|
+
text: "x".repeat(5000)
|
|
186
|
+
}, {
|
|
187
|
+
entryBytes: 100,
|
|
188
|
+
stringLength: 100000
|
|
189
|
+
});
|
|
190
|
+
expect(result.truncated).toBe(true);
|
|
191
|
+
expect(result.parsed.truncated).toBe(true);
|
|
192
|
+
expect(result.parsed.originalBytes).toBeGreaterThan(100);
|
|
193
|
+
expect(result.bytes).toBeLessThanOrEqual(100);
|
|
194
|
+
});
|
|
195
|
+
it("should never invoke a custom toJSON, so it cannot be broken by one", ()=>{
|
|
196
|
+
const value = {
|
|
197
|
+
id: 1,
|
|
198
|
+
toJSON () {
|
|
199
|
+
throw new Error("Nope");
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const { parsed } = parse({
|
|
203
|
+
value
|
|
204
|
+
});
|
|
205
|
+
expect(parsed.value.id).toBe(1);
|
|
206
|
+
expect(parsed.value.toJSON).toBe("#[Function: toJSON]");
|
|
207
|
+
});
|
|
208
|
+
it("should keep non-finite numbers readable instead of turning them into null", ()=>{
|
|
209
|
+
const { parsed } = parse({
|
|
210
|
+
a: 1 / 0,
|
|
211
|
+
b: 0 / 0
|
|
212
|
+
});
|
|
213
|
+
expect(parsed).toEqual({
|
|
214
|
+
a: "Infinity",
|
|
215
|
+
b: "NaN"
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
//# sourceMappingURL=serialize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/__tests__/serialize.test.js","sources":["../../../../src/features/debugger/__tests__/serialize.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { serialize } from \"../serialize.js\";\nimport { DEFAULT_LIMITS, type IDebuggerLimits } from \"../limits.js\";\n\nconst limits = (overrides: Partial<IDebuggerLimits> = {}): IDebuggerLimits => {\n return { ...DEFAULT_LIMITS, ...overrides };\n};\n\nconst parse = (value: unknown, overrides: Partial<IDebuggerLimits> = {}) => {\n const result = serialize(value, limits(overrides));\n return { ...result, parsed: JSON.parse(result.json) };\n};\n\ndescribe(\"serialize\", () => {\n it(\"should always produce parseable JSON\", () => {\n const circular: Record<string, unknown> = { name: \"root\" };\n circular.self = circular;\n\n const { parsed } = parse(circular);\n\n expect(parsed).toEqual({ name: \"root\", self: \"#[Circular]\" });\n });\n\n it(\"should not report siblings as circular\", () => {\n const shared = { id: 1 };\n\n const { parsed } = parse({ a: shared, b: shared });\n\n expect(parsed).toEqual({ a: { id: 1 }, b: { id: 1 } });\n });\n\n it(\"should serialize an Error, which JSON.stringify renders as an empty object\", () => {\n const error = new Error(\"Boom\");\n\n const { parsed } = parse({ error });\n\n expect(parsed.error.name).toBe(\"Error\");\n expect(parsed.error.message).toBe(\"Boom\");\n expect(typeof parsed.error.stack).toBe(\"string\");\n });\n\n it(\"should serialize a BigInt, which JSON.stringify throws on\", () => {\n const { parsed } = parse({ value: BigInt(123) });\n\n expect(parsed).toEqual({ value: \"123n\" });\n });\n\n it(\"should describe binary data without including its contents\", () => {\n const { parsed } = parse({ buffer: Buffer.from(\"hello world\") });\n\n expect(parsed).toEqual({ buffer: \"#[Buffer 11 bytes]\" });\n });\n\n it(\"should serialize Map and Set\", () => {\n const { parsed } = parse({\n map: new Map([[\"a\", 1]]),\n set: new Set([1, 2])\n });\n\n expect(parsed.map).toEqual({ __type: \"Map\", entries: [[\"a\", 1]] });\n expect(parsed.set).toEqual({ __type: \"Set\", items: [1, 2] });\n });\n\n it(\"should drop an undefined property, so a logged payload matches what was sent\", () => {\n const { parsed } = parse({ kept: 1, dropped: undefined });\n\n expect(parsed).toEqual({ kept: 1 });\n });\n\n it(\"should keep undefined array elements, where dropping would shift every later index\", () => {\n const { parsed } = parse({ items: [1, undefined, 3] });\n\n expect(parsed).toEqual({ items: [1, \"#[Undefined value]\", 3] });\n });\n\n it(\"should not throw when a getter throws\", () => {\n const value = {\n get exploding() {\n throw new Error(\"Nope\");\n },\n safe: 1\n };\n\n const { parsed } = parse(value);\n\n expect(parsed.exploding).toBe(\"#[Throws: Nope]\");\n expect(parsed.safe).toBe(1);\n });\n\n it(\"should cap depth\", () => {\n const { parsed } = parse({ a: { b: { c: { d: \"deep\" } } } }, { depth: 2 });\n\n expect(parsed).toEqual({ a: { b: \"#[Depth limit]\" } });\n });\n\n it(\"should cap string length and say how much was cut\", () => {\n const { parsed } = parse({ text: \"x\".repeat(20) }, { stringLength: 5 });\n\n expect(parsed).toEqual({ text: \"xxxxx…(15 more)\" });\n });\n\n it(\"should cap array length and say how much was cut\", () => {\n const { parsed } = parse({ items: [1, 2, 3, 4, 5] }, { arrayLength: 2 });\n\n expect(parsed).toEqual({ items: [1, 2, \"…(3 more items)\"] });\n });\n\n it(\"should replace the payload wholesale when it exceeds the per-entry cap\", () => {\n const result = parse({ text: \"x\".repeat(5000) }, { entryBytes: 100, stringLength: 100000 });\n\n expect(result.truncated).toBe(true);\n expect(result.parsed.truncated).toBe(true);\n expect(result.parsed.originalBytes).toBeGreaterThan(100);\n expect(result.bytes).toBeLessThanOrEqual(100);\n });\n\n it(\"should never invoke a custom toJSON, so it cannot be broken by one\", () => {\n const value = {\n id: 1,\n toJSON() {\n throw new Error(\"Nope\");\n }\n };\n\n const { parsed } = parse({ value });\n\n expect(parsed.value.id).toBe(1);\n expect(parsed.value.toJSON).toBe(\"#[Function: toJSON]\");\n });\n\n it(\"should keep non-finite numbers readable instead of turning them into null\", () => {\n const { parsed } = parse({ a: Infinity, b: NaN });\n\n expect(parsed).toEqual({ a: \"Infinity\", b: \"NaN\" });\n });\n});\n"],"names":["limits","overrides","DEFAULT_LIMITS","parse","value","result","serialize","JSON","describe","it","circular","parsed","expect","shared","error","Error","BigInt","Buffer","Map","Set","undefined","Infinity","NaN"],"mappings":";;;AAIA,MAAMA,SAAS,CAACC,YAAsC,CAAC,CAAC,GAC7C;QAAE,GAAGC,cAAc;QAAE,GAAGD,SAAS;IAAC;AAG7C,MAAME,QAAQ,CAACC,OAAgBH,YAAsC,CAAC,CAAC;IACnE,MAAMI,SAASC,UAAUF,OAAOJ,OAAOC;IACvC,OAAO;QAAE,GAAGI,MAAM;QAAE,QAAQE,KAAK,KAAK,CAACF,OAAO,IAAI;IAAE;AACxD;AAEAG,SAAS,aAAa;IAClBC,GAAG,wCAAwC;QACvC,MAAMC,WAAoC;YAAE,MAAM;QAAO;QACzDA,SAAS,IAAI,GAAGA;QAEhB,MAAM,EAAEC,MAAM,EAAE,GAAGR,MAAMO;QAEzBE,OAAOD,QAAQ,OAAO,CAAC;YAAE,MAAM;YAAQ,MAAM;QAAc;IAC/D;IAEAF,GAAG,0CAA0C;QACzC,MAAMI,SAAS;YAAE,IAAI;QAAE;QAEvB,MAAM,EAAEF,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAGU;YAAQ,GAAGA;QAAO;QAEhDD,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;gBAAE,IAAI;YAAE;YAAG,GAAG;gBAAE,IAAI;YAAE;QAAE;IACxD;IAEAF,GAAG,8EAA8E;QAC7E,MAAMK,QAAQ,IAAIC,MAAM;QAExB,MAAM,EAAEJ,MAAM,EAAE,GAAGR,MAAM;YAAEW;QAAM;QAEjCF,OAAOD,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;QAC/BC,OAAOD,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;QAClCC,OAAO,OAAOD,OAAO,KAAK,CAAC,KAAK,EAAE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EAAE,GAAGR,MAAM;YAAEC;QAAM;QAEjCQ,OAAOD,OAAO,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC;QAC7BC,OAAOD,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;IACrC;IAEAF,GAAG,6EAA6E;QAC5E,MAAM,EAAEE,MAAM,EAAE,GAAGR,MAAM;YAAE,GAAGkB,KAAQ;YAAE,GAAGC,KAAG;QAAC;QAE/CV,OAAOD,QAAQ,OAAO,CAAC;YAAE,GAAG;YAAY,GAAG;QAAM;IACrD;AACJ"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry of debug namespace prefixes.
|
|
3
|
+
*
|
|
4
|
+
* Packages augment this interface to claim their own prefix:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* declare module "@webiny/api-core/features/debugger/abstractions.js" {
|
|
8
|
+
* interface DebugNamespaces {
|
|
9
|
+
* cms: `cms.${string}`;
|
|
10
|
+
* }
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The module specifier must be exactly the one above - a relative path augments nothing.
|
|
15
|
+
*/
|
|
16
|
+
export interface DebugNamespaces {
|
|
17
|
+
core: `core.${string}`;
|
|
18
|
+
}
|
|
19
|
+
export type DebugNamespace = DebugNamespaces[keyof DebugNamespaces];
|
|
20
|
+
/**
|
|
21
|
+
* Produces the payload to capture. Invoked only when capture is active, so building an expensive
|
|
22
|
+
* payload costs nothing when the debugger is off.
|
|
23
|
+
*/
|
|
24
|
+
export interface IDebugPayloadFactory {
|
|
25
|
+
(): unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface IDebugEntry {
|
|
28
|
+
seq: number;
|
|
29
|
+
namespace: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
/** Milliseconds since the session started. */
|
|
32
|
+
elapsed: number;
|
|
33
|
+
/** Already serialized and capped. Valid JSON. */
|
|
34
|
+
json: string;
|
|
35
|
+
bytes: number;
|
|
36
|
+
}
|
|
37
|
+
export interface IDebugSession {
|
|
38
|
+
namespaces: string[];
|
|
39
|
+
startedAt: number;
|
|
40
|
+
entries: IDebugEntry[];
|
|
41
|
+
bytes: number;
|
|
42
|
+
/** Entries discarded from the front of the buffer because the total budget was exceeded. */
|
|
43
|
+
dropped: number;
|
|
44
|
+
/** True once any single entry's payload was replaced by the per-entry cap marker. */
|
|
45
|
+
truncated: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface IDebuggerStartParams {
|
|
48
|
+
namespaces: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface IDebugDeliveryTarget {
|
|
51
|
+
type: string;
|
|
52
|
+
}
|
|
53
|
+
export interface IDebuggerTransportDeliverParams {
|
|
54
|
+
target: IDebugDeliveryTarget;
|
|
55
|
+
session: IDebugSession;
|
|
56
|
+
}
|
|
57
|
+
export interface IDebugger {
|
|
58
|
+
/**
|
|
59
|
+
* Opens a capture session, replacing any existing one.
|
|
60
|
+
*/
|
|
61
|
+
start(params: IDebuggerStartParams): void;
|
|
62
|
+
/**
|
|
63
|
+
* Captures a payload, if a session is open and the namespace matches its filter.
|
|
64
|
+
* Never throws.
|
|
65
|
+
*/
|
|
66
|
+
log(namespace: DebugNamespace, payload: IDebugPayloadFactory): void;
|
|
67
|
+
/**
|
|
68
|
+
* Whether a namespace would currently be captured. For guarding expensive work *around* a log
|
|
69
|
+
* call - `log` already performs this check itself.
|
|
70
|
+
*/
|
|
71
|
+
isEnabled(namespace: DebugNamespace): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Hands the session to every transport that can deliver it, then closes it.
|
|
74
|
+
*/
|
|
75
|
+
flush(target: IDebugDeliveryTarget): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Closes the session without delivering it.
|
|
78
|
+
*/
|
|
79
|
+
discard(): void;
|
|
80
|
+
}
|
|
81
|
+
export interface IDebuggerTransport {
|
|
82
|
+
canDeliver(target: IDebugDeliveryTarget): boolean;
|
|
83
|
+
deliver(params: IDebuggerTransportDeliverParams): Promise<void> | void;
|
|
84
|
+
}
|
|
85
|
+
/** Captures debug payloads for the current request, for delivery to a permitted identity. */
|
|
86
|
+
export declare const Debugger: import("@webiny/di").Abstraction<IDebugger>;
|
|
87
|
+
export declare namespace Debugger {
|
|
88
|
+
type Interface = IDebugger;
|
|
89
|
+
type Session = IDebugSession;
|
|
90
|
+
type Entry = IDebugEntry;
|
|
91
|
+
type StartParams = IDebuggerStartParams;
|
|
92
|
+
type PayloadFactory = IDebugPayloadFactory;
|
|
93
|
+
}
|
|
94
|
+
/** Delivers a finished debug session to a sink. */
|
|
95
|
+
export declare const DebuggerTransport: import("@webiny/di").Abstraction<IDebuggerTransport>;
|
|
96
|
+
export declare namespace DebuggerTransport {
|
|
97
|
+
type Interface = IDebuggerTransport;
|
|
98
|
+
type Target = IDebugDeliveryTarget;
|
|
99
|
+
type DeliverParams = IDebuggerTransportDeliverParams;
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/debugger/abstractions.js","sources":["../../../src/features/debugger/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * Registry of debug namespace prefixes.\n *\n * Packages augment this interface to claim their own prefix:\n *\n * ```ts\n * declare module \"@webiny/api-core/features/debugger/abstractions.js\" {\n * interface DebugNamespaces {\n * cms: `cms.${string}`;\n * }\n * }\n * ```\n *\n * The module specifier must be exactly the one above - a relative path augments nothing.\n */\nexport interface DebugNamespaces {\n core: `core.${string}`;\n}\n\nexport type DebugNamespace = DebugNamespaces[keyof DebugNamespaces];\n\n/**\n * Produces the payload to capture. Invoked only when capture is active, so building an expensive\n * payload costs nothing when the debugger is off.\n */\nexport interface IDebugPayloadFactory {\n (): unknown;\n}\n\nexport interface IDebugEntry {\n seq: number;\n namespace: string;\n timestamp: number;\n /** Milliseconds since the session started. */\n elapsed: number;\n /** Already serialized and capped. Valid JSON. */\n json: string;\n bytes: number;\n}\n\nexport interface IDebugSession {\n namespaces: string[];\n startedAt: number;\n entries: IDebugEntry[];\n bytes: number;\n /** Entries discarded from the front of the buffer because the total budget was exceeded. */\n dropped: number;\n /** True once any single entry's payload was replaced by the per-entry cap marker. */\n truncated: boolean;\n}\n\nexport interface IDebuggerStartParams {\n namespaces: string[];\n}\n\nexport interface IDebugDeliveryTarget {\n type: string;\n}\n\nexport interface IDebuggerTransportDeliverParams {\n target: IDebugDeliveryTarget;\n session: IDebugSession;\n}\n\nexport interface IDebugger {\n /**\n * Opens a capture session, replacing any existing one.\n */\n start(params: IDebuggerStartParams): void;\n /**\n * Captures a payload, if a session is open and the namespace matches its filter.\n * Never throws.\n */\n log(namespace: DebugNamespace, payload: IDebugPayloadFactory): void;\n /**\n * Whether a namespace would currently be captured. For guarding expensive work *around* a log\n * call - `log` already performs this check itself.\n */\n isEnabled(namespace: DebugNamespace): boolean;\n /**\n * Hands the session to every transport that can deliver it, then closes it.\n */\n flush(target: IDebugDeliveryTarget): Promise<void>;\n /**\n * Closes the session without delivering it.\n */\n discard(): void;\n}\n\nexport interface IDebuggerTransport {\n canDeliver(target: IDebugDeliveryTarget): boolean;\n deliver(params: IDebuggerTransportDeliverParams): Promise<void> | void;\n}\n\n/** Captures debug payloads for the current request, for delivery to a permitted identity. */\nexport const Debugger = createAbstraction<IDebugger>(\"Debugger\");\n\nexport namespace Debugger {\n export type Interface = IDebugger;\n export type Session = IDebugSession;\n export type Entry = IDebugEntry;\n export type StartParams = IDebuggerStartParams;\n export type PayloadFactory = IDebugPayloadFactory;\n}\n\n/** Delivers a finished debug session to a sink. */\nexport const DebuggerTransport = createAbstraction<IDebuggerTransport>(\"DebuggerTransport\");\n\nexport namespace DebuggerTransport {\n export type Interface = IDebuggerTransport;\n export type Target = IDebugDeliveryTarget;\n export type DeliverParams = IDebuggerTransportDeliverParams;\n}\n"],"names":["Debugger","createAbstraction","DebuggerTransport"],"mappings":";AAiGO,MAAMA,WAAWC,kBAA6B;AAW9C,MAAMC,oBAAoBD,kBAAsC"}
|