@cratis/chronicle.contracts 15.25.0 → 15.25.2
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/ChronicleConnection.ts +127 -49
- package/dist/ChronicleConnection.d.ts +2 -0
- package/dist/ChronicleConnection.d.ts.map +1 -1
- package/dist/ChronicleConnection.js +90 -42
- package/dist/ChronicleConnection.js.map +1 -1
- package/dist/cjs/ChronicleConnection.d.ts +2 -0
- package/dist/cjs/ChronicleConnection.d.ts.map +1 -1
- package/dist/cjs/ChronicleConnection.js +89 -41
- package/dist/cjs/ChronicleConnection.js.map +1 -1
- package/dist/esm/ChronicleConnection.d.ts +2 -0
- package/dist/esm/ChronicleConnection.d.ts.map +1 -1
- package/dist/esm/ChronicleConnection.js +90 -42
- package/dist/esm/ChronicleConnection.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChronicleConnection.js","sources":["../../ChronicleConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as grpc from '@grpc/grpc-js';\nimport { createClient } from 'nice-grpc';\n\n// Import service definitions from generated files\nimport { EventStoresDefinition, NamespacesDefinition } from './generated/cratis_chronicle_contracts';\nimport { RecommendationsDefinition } from './generated/recommendations';\nimport { IdentitiesDefinition } from './generated/identities';\nimport { EventSequencesDefinition } from './generated/eventsequences';\nimport { EventTypesDefinition } from './generated/events';\nimport { ConstraintsDefinition } from './generated/events_constraints';\nimport { ObserversDefinition, FailedPartitionsDefinition } from './generated/observation';\nimport { ReactorsDefinition } from './generated/observation_reactors';\nimport { ReducersDefinition } from './generated/observation_reducers';\nimport { ProjectionsDefinition } from './generated/projections';\nimport { ReadModelsDefinition } from './generated/readmodels';\nimport { JobsDefinition } from './generated/jobs';\nimport { EventSeedingDefinition } from './generated/seeding';\nimport { ServerDefinition } from './generated/host';\nimport { ConnectionServiceDefinition } from './generated/clients';\n\n// Import client types\nimport type {\n EventStoresClient,\n NamespacesClient,\n RecommendationsClient,\n IdentitiesClient,\n EventSequencesClient,\n EventTypesClient,\n ConstraintsClient,\n ObserversClient,\n FailedPartitionsClient,\n ReactorsClient,\n ReducersClient,\n ProjectionsClient,\n ReadModelsClient,\n JobsClient,\n EventSeedingClient,\n ServerClient,\n ConnectionServiceClient,\n} from './generated/index';\n\nimport type { ChronicleServices } from './ChronicleServices';\nimport { ChronicleConnectionString, AuthenticationMode } from './ChronicleConnectionString';\nimport { ITokenProvider, OAuthTokenProvider, NoOpTokenProvider } from './TokenProvider';\n\n/**\n * Configuration options for Chronicle connection\n */\nexport interface ChronicleConnectionOptions {\n /**\n * The connection string (e.g., 'chronicle://localhost:35000' or 'chronicle://user:pass@localhost:35000')\n * Can also be a ChronicleConnectionString instance\n */\n connectionString?: string | ChronicleConnectionString;\n\n /**\n * The host and port of the Chronicle server (e.g., 'localhost:35000')\n * This is used if connectionString is not provided\n */\n serverAddress?: string;\n\n /**\n * Optional gRPC credentials (defaults to credentials based on connection string)\n */\n credentials?: grpc.ChannelCredentials;\n\n /**\n * Optional connection timeout in milliseconds (defaults to 10000)\n */\n connectTimeout?: number;\n\n /**\n * Optional maximum receive message size in bytes\n */\n maxReceiveMessageSize?: number;\n\n /**\n * Optional maximum send message size in bytes\n */\n maxSendMessageSize?: number;\n\n /**\n * Optional correlation ID for tracking requests\n */\n correlationId?: string;\n\n /**\n * Optional authentication authority URL. If not set, uses the Chronicle server itself as the authority\n */\n authority?: string;\n\n /**\n * Optional management port for authentication endpoint (defaults to 8080)\n */\n managementPort?: number;\n}\n\n/**\n * Manages the connection to Chronicle Kernel and provides access to all gRPC services\n */\nexport class ChronicleConnection implements ChronicleServices {\n private readonly channel: grpc.Channel;\n private readonly services: ChronicleServices;\n private readonly _connectionString: ChronicleConnectionString;\n private readonly tokenProvider: ITokenProvider;\n private _isConnected = false;\n\n /**\n * Event stores service\n */\n get eventStores(): EventStoresClient {\n return this.services.eventStores;\n }\n\n /**\n * Namespaces service\n */\n get namespaces(): NamespacesClient {\n return this.services.namespaces;\n }\n\n /**\n * Recommendations service\n */\n get recommendations(): RecommendationsClient {\n return this.services.recommendations;\n }\n\n /**\n * Identities service\n */\n get identities(): IdentitiesClient {\n return this.services.identities;\n }\n\n /**\n * Event sequences service\n */\n get eventSequences(): EventSequencesClient {\n return this.services.eventSequences;\n }\n\n /**\n * Event types service\n */\n get eventTypes(): EventTypesClient {\n return this.services.eventTypes;\n }\n\n /**\n * Constraints service\n */\n get constraints(): ConstraintsClient {\n return this.services.constraints;\n }\n\n /**\n * Observers service\n */\n get observers(): ObserversClient {\n return this.services.observers;\n }\n\n /**\n * Failed partitions service\n */\n get failedPartitions(): FailedPartitionsClient {\n return this.services.failedPartitions;\n }\n\n /**\n * Reactors service\n */\n get reactors(): ReactorsClient {\n return this.services.reactors;\n }\n\n /**\n * Reducers service\n */\n get reducers(): ReducersClient {\n return this.services.reducers;\n }\n\n /**\n * Projections service\n */\n get projections(): ProjectionsClient {\n return this.services.projections;\n }\n\n /**\n * Read models service\n */\n get readModels(): ReadModelsClient {\n return this.services.readModels;\n }\n\n /**\n * Jobs service\n */\n get jobs(): JobsClient {\n return this.services.jobs;\n }\n\n /**\n * Event seeding service\n */\n get eventSeeding(): EventSeedingClient {\n return this.services.eventSeeding;\n }\n\n /**\n * Server service\n */\n get server(): ServerClient {\n return this.services.server;\n }\n\n /**\n * Connection service for managing the connection\n */\n private connectionService: ConnectionServiceClient;\n\n /**\n * Gets the connection string used for this connection\n */\n get connectionString(): ChronicleConnectionString {\n return this._connectionString;\n }\n\n /**\n * Creates a new Chronicle connection\n * @param options Connection configuration options\n */\n constructor(options: ChronicleConnectionOptions) {\n // Parse connection string or create from serverAddress\n if (options.connectionString) {\n this._connectionString =\n typeof options.connectionString === 'string'\n ? new ChronicleConnectionString(options.connectionString)\n : options.connectionString;\n } else if (options.serverAddress) {\n this._connectionString = new ChronicleConnectionString(\n `chronicle://${options.serverAddress}`\n );\n } else {\n this._connectionString = ChronicleConnectionString.Default;\n }\n\n // Create server address string\n const serverAddress = `${this._connectionString.serverAddress.host}:${this._connectionString.serverAddress.port}`;\n\n // Create token provider for authentication\n this.tokenProvider = this.createTokenProvider(options);\n\n // Create channel options\n const channelOptions: grpc.ChannelOptions = {};\n\n if (options.maxReceiveMessageSize) {\n channelOptions['grpc.max_receive_message_length'] = options.maxReceiveMessageSize;\n }\n\n if (options.maxSendMessageSize) {\n channelOptions['grpc.max_send_message_length'] = options.maxSendMessageSize;\n }\n\n // Create gRPC channel credentials\n let channelCredentials = options.credentials;\n if (!channelCredentials) {\n channelCredentials = this._connectionString.createCredentials();\n\n if (!this._connectionString.disableTls) {\n const callCredentials = this.createAuthCallCredentials();\n if (callCredentials) {\n channelCredentials = grpc.credentials.combineChannelCredentials(\n channelCredentials,\n callCredentials\n );\n }\n }\n }\n\n // Create the gRPC channel\n this.channel = new grpc.Channel(serverAddress, channelCredentials, channelOptions);\n\n // Create services using nice-grpc's createClient\n this.connectionService = createClient(ConnectionServiceDefinition, this.channel);\n this.services = this.createServices();\n }\n\n private createServices(): ChronicleServices {\n return {\n eventStores: createClient(EventStoresDefinition, this.channel),\n namespaces: createClient(NamespacesDefinition, this.channel),\n recommendations: createClient(RecommendationsDefinition, this.channel),\n identities: createClient(IdentitiesDefinition, this.channel),\n eventSequences: createClient(EventSequencesDefinition, this.channel),\n eventTypes: createClient(EventTypesDefinition, this.channel),\n constraints: createClient(ConstraintsDefinition, this.channel),\n observers: createClient(ObserversDefinition, this.channel),\n failedPartitions: createClient(FailedPartitionsDefinition, this.channel),\n reactors: createClient(ReactorsDefinition, this.channel),\n reducers: createClient(ReducersDefinition, this.channel),\n projections: createClient(ProjectionsDefinition, this.channel),\n readModels: createClient(ReadModelsDefinition, this.channel),\n jobs: createClient(JobsDefinition, this.channel),\n eventSeeding: createClient(EventSeedingDefinition, this.channel),\n server: createClient(ServerDefinition, this.channel),\n };\n }\n\n /**\n * Creates a token provider based on connection configuration\n */\n private createTokenProvider(options: ChronicleConnectionOptions): ITokenProvider {\n try {\n const authMode = this._connectionString.authenticationMode;\n\n if (authMode === AuthenticationMode.ClientCredentials) {\n const username = this._connectionString.username;\n const password = this._connectionString.password;\n\n if (!username || !password) {\n return new NoOpTokenProvider();\n }\n\n // Determine the authority URL\n const managementPort = options.managementPort || 8080;\n let authorityHost: string;\n let authorityPort: number;\n\n if (options.authority) {\n // Parse custom authority URL\n const authorityUrl = new URL(options.authority);\n authorityHost = authorityUrl.hostname;\n authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;\n } else {\n // Use Chronicle server as authority\n authorityHost = this._connectionString.serverAddress.host;\n authorityPort = managementPort;\n }\n\n const scheme = this._connectionString.disableTls ? 'http' : 'https';\n const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;\n\n return new OAuthTokenProvider(tokenEndpoint, username, password);\n }\n\n // For API key or other modes, no token provider needed (handled by connection string)\n return new NoOpTokenProvider();\n } catch {\n // If authentication mode check fails (no auth configured), use no-op provider\n return new NoOpTokenProvider();\n }\n }\n\n /**\n * Creates call credentials with bearer token from token provider\n */\n private createAuthCallCredentials(): grpc.CallCredentials | undefined {\n // Insecure channels cannot compose with call credentials — skip when TLS is disabled.\n if (this._connectionString.disableTls) {\n return undefined;\n }\n return grpc.credentials.createFromMetadataGenerator(async (params, callback) => {\n try {\n const token = await this.tokenProvider.getAccessToken();\n const metadata = new grpc.Metadata();\n\n if (token) {\n metadata.add('authorization', `Bearer ${token}`);\n } else {\n // Check for API key authentication\n try {\n const authMode = this._connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && this._connectionString.apiKey) {\n metadata.add('api-key', this._connectionString.apiKey);\n }\n } catch {\n // No API key configured\n }\n }\n\n callback(null, metadata);\n } catch (error) {\n callback(error as Error, new grpc.Metadata());\n }\n });\n }\n\n /**\n * Gets whether the connection is established\n */\n get isConnected(): boolean {\n return this._isConnected;\n }\n\n /**\n * Connects to the Chronicle Kernel\n * @returns Promise that resolves when connected\n */\n async connect(): Promise<void> {\n if (this._isConnected) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n const deadline = new Date();\n deadline.setSeconds(deadline.getSeconds() + 10);\n\n this.channel.watchConnectivityState(\n this.channel.getConnectivityState(true),\n deadline,\n (error) => {\n if (error) {\n this._isConnected = false;\n reject(error);\n } else {\n const state = this.channel.getConnectivityState(false);\n if (state === grpc.connectivityState.READY) {\n this._isConnected = true;\n resolve();\n } else {\n this._isConnected = false;\n reject(new Error(`Connection failed with state: ${state}`));\n }\n }\n }\n );\n });\n }\n\n /**\n * Disconnects from the Chronicle Kernel\n */\n disconnect(): void {\n this._isConnected = false;\n this.channel.close();\n }\n\n /**\n * Disposes the connection and cleans up resources\n */\n dispose(): void {\n this.disconnect();\n }\n}\n\n"],"names":["ChronicleConnectionString","grpc","createClient","ConnectionServiceDefinition","EventStoresDefinition","NamespacesDefinition","RecommendationsDefinition","IdentitiesDefinition","EventSequencesDefinition","EventTypesDefinition","ConstraintsDefinition","ObserversDefinition","FailedPartitionsDefinition","ReactorsDefinition","ReducersDefinition","ProjectionsDefinition","ReadModelsDefinition","JobsDefinition","EventSeedingDefinition","ServerDefinition","AuthenticationMode","NoOpTokenProvider","OAuthTokenProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuGa,mBAAmB,CAAA;AACX,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,iBAAiB;AACjB,IAAA,aAAa;IACtB,YAAY,GAAG,KAAK;AAK5B,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,eAAe,GAAA;AACf,QAAA,OA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AAY,GAAG,KAAK;AACzB,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;IACxB;IAKA,OAAO,GAAA;QACH,IAAI,CAAC,UAAU,EAAE;IACrB;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ChronicleConnection.js","sources":["../../ChronicleConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as grpc from '@grpc/grpc-js';\nimport { createClient, createClientFactory } from 'nice-grpc';\nimport type { ClientMiddleware } from 'nice-grpc-common';\nimport { Metadata } from 'nice-grpc-common';\n\n// Import service definitions from generated files\nimport { EventStoresDefinition, NamespacesDefinition } from './generated/cratis_chronicle_contracts';\nimport { RecommendationsDefinition } from './generated/recommendations';\nimport { IdentitiesDefinition } from './generated/identities';\nimport { EventSequencesDefinition } from './generated/eventsequences';\nimport { EventTypesDefinition } from './generated/events';\nimport { ConstraintsDefinition } from './generated/events_constraints';\nimport { ObserversDefinition, FailedPartitionsDefinition } from './generated/observation';\nimport { ReactorsDefinition } from './generated/observation_reactors';\nimport { ReducersDefinition } from './generated/observation_reducers';\nimport { ProjectionsDefinition } from './generated/projections';\nimport { ReadModelsDefinition } from './generated/readmodels';\nimport { JobsDefinition } from './generated/jobs';\nimport { EventSeedingDefinition } from './generated/seeding';\nimport { ServerDefinition } from './generated/host';\nimport { ConnectionServiceDefinition } from './generated/clients';\n\n// Import client types\nimport type {\n EventStoresClient,\n NamespacesClient,\n RecommendationsClient,\n IdentitiesClient,\n EventSequencesClient,\n EventTypesClient,\n ConstraintsClient,\n ObserversClient,\n FailedPartitionsClient,\n ReactorsClient,\n ReducersClient,\n ProjectionsClient,\n ReadModelsClient,\n JobsClient,\n EventSeedingClient,\n ServerClient,\n ConnectionServiceClient,\n} from './generated/index';\n\nimport type { ChronicleServices } from './ChronicleServices';\nimport { ChronicleConnectionString, AuthenticationMode } from './ChronicleConnectionString';\nimport { ITokenProvider, OAuthTokenProvider, NoOpTokenProvider } from './TokenProvider';\n\n/**\n * Configuration options for Chronicle connection\n */\nexport interface ChronicleConnectionOptions {\n /**\n * The connection string (e.g., 'chronicle://localhost:35000' or 'chronicle://user:pass@localhost:35000')\n * Can also be a ChronicleConnectionString instance\n */\n connectionString?: string | ChronicleConnectionString;\n\n /**\n * The host and port of the Chronicle server (e.g., 'localhost:35000')\n * This is used if connectionString is not provided\n */\n serverAddress?: string;\n\n /**\n * Optional gRPC credentials (defaults to credentials based on connection string)\n */\n credentials?: grpc.ChannelCredentials;\n\n /**\n * Optional connection timeout in milliseconds (defaults to 10000)\n */\n connectTimeout?: number;\n\n /**\n * Optional maximum receive message size in bytes\n */\n maxReceiveMessageSize?: number;\n\n /**\n * Optional maximum send message size in bytes\n */\n maxSendMessageSize?: number;\n\n /**\n * Optional correlation ID for tracking requests\n */\n correlationId?: string;\n\n /**\n * Optional authentication authority URL. If not set, uses the Chronicle server itself as the authority\n */\n authority?: string;\n\n /**\n * Optional management port for authentication endpoint (defaults to 8080)\n */\n managementPort?: number;\n}\n\n/**\n * Manages the connection to Chronicle Kernel and provides access to all gRPC services\n */\nexport class ChronicleConnection implements ChronicleServices {\n private readonly channel: grpc.Channel;\n private readonly services: ChronicleServices;\n private readonly _connectionString: ChronicleConnectionString;\n private readonly tokenProvider: ITokenProvider;\n private _isConnected = false;\n\n /**\n * Event stores service\n */\n get eventStores(): EventStoresClient {\n return this.services.eventStores;\n }\n\n /**\n * Namespaces service\n */\n get namespaces(): NamespacesClient {\n return this.services.namespaces;\n }\n\n /**\n * Recommendations service\n */\n get recommendations(): RecommendationsClient {\n return this.services.recommendations;\n }\n\n /**\n * Identities service\n */\n get identities(): IdentitiesClient {\n return this.services.identities;\n }\n\n /**\n * Event sequences service\n */\n get eventSequences(): EventSequencesClient {\n return this.services.eventSequences;\n }\n\n /**\n * Event types service\n */\n get eventTypes(): EventTypesClient {\n return this.services.eventTypes;\n }\n\n /**\n * Constraints service\n */\n get constraints(): ConstraintsClient {\n return this.services.constraints;\n }\n\n /**\n * Observers service\n */\n get observers(): ObserversClient {\n return this.services.observers;\n }\n\n /**\n * Failed partitions service\n */\n get failedPartitions(): FailedPartitionsClient {\n return this.services.failedPartitions;\n }\n\n /**\n * Reactors service\n */\n get reactors(): ReactorsClient {\n return this.services.reactors;\n }\n\n /**\n * Reducers service\n */\n get reducers(): ReducersClient {\n return this.services.reducers;\n }\n\n /**\n * Projections service\n */\n get projections(): ProjectionsClient {\n return this.services.projections;\n }\n\n /**\n * Read models service\n */\n get readModels(): ReadModelsClient {\n return this.services.readModels;\n }\n\n /**\n * Jobs service\n */\n get jobs(): JobsClient {\n return this.services.jobs;\n }\n\n /**\n * Event seeding service\n */\n get eventSeeding(): EventSeedingClient {\n return this.services.eventSeeding;\n }\n\n /**\n * Server service\n */\n get server(): ServerClient {\n return this.services.server;\n }\n\n /**\n * Connection service for managing the connection\n */\n private connectionService: ConnectionServiceClient;\n\n /**\n * Gets the connection string used for this connection\n */\n get connectionString(): ChronicleConnectionString {\n return this._connectionString;\n }\n\n /**\n * Creates a new Chronicle connection\n * @param options Connection configuration options\n */\n constructor(options: ChronicleConnectionOptions) {\n // Parse connection string or create from serverAddress\n if (options.connectionString) {\n this._connectionString =\n typeof options.connectionString === 'string'\n ? new ChronicleConnectionString(options.connectionString)\n : options.connectionString;\n } else if (options.serverAddress) {\n this._connectionString = new ChronicleConnectionString(\n `chronicle://${options.serverAddress}`\n );\n } else {\n this._connectionString = ChronicleConnectionString.Default;\n }\n\n // Create server address string\n const serverAddress = `${this._connectionString.serverAddress.host}:${this._connectionString.serverAddress.port}`;\n\n // Create token provider for authentication\n this.tokenProvider = this.createTokenProvider(options);\n\n // Create channel options\n const channelOptions: grpc.ChannelOptions = {};\n\n if (options.maxReceiveMessageSize) {\n channelOptions['grpc.max_receive_message_length'] = options.maxReceiveMessageSize;\n }\n\n if (options.maxSendMessageSize) {\n channelOptions['grpc.max_send_message_length'] = options.maxSendMessageSize;\n }\n\n // Create gRPC channel credentials\n let channelCredentials = options.credentials;\n if (!channelCredentials) {\n channelCredentials = this._connectionString.createCredentials();\n\n if (!this._connectionString.disableTls) {\n const callCredentials = this.createAuthCallCredentials();\n if (callCredentials) {\n channelCredentials = grpc.credentials.combineChannelCredentials(\n channelCredentials,\n callCredentials\n );\n }\n }\n }\n\n // Create the gRPC channel\n this.channel = new grpc.Channel(serverAddress, channelCredentials, channelOptions);\n\n // Create services using nice-grpc's createClient\n this.connectionService = createClient(ConnectionServiceDefinition, this.channel);\n this.services = this.createServices();\n }\n\n private createServices(): ChronicleServices {\n console.log('[Chronicle] Creating services with middleware');\n // Create a client factory and attach auth middleware for all calls\n let factory = createClientFactory();\n \n console.log('[Chronicle] Attaching auth middleware');\n // Attach authentication middleware that works for both TLS and insecure channels\n factory = factory.use(this.createAuthMiddleware());\n console.log('[Chronicle] Middleware attached, creating service clients');\n\n return {\n eventStores: factory.create(EventStoresDefinition, this.channel),\n namespaces: factory.create(NamespacesDefinition, this.channel),\n recommendations: factory.create(RecommendationsDefinition, this.channel),\n identities: factory.create(IdentitiesDefinition, this.channel),\n eventSequences: factory.create(EventSequencesDefinition, this.channel),\n eventTypes: factory.create(EventTypesDefinition, this.channel),\n constraints: factory.create(ConstraintsDefinition, this.channel),\n observers: factory.create(ObserversDefinition, this.channel),\n failedPartitions: factory.create(FailedPartitionsDefinition, this.channel),\n reactors: factory.create(ReactorsDefinition, this.channel),\n reducers: factory.create(ReducersDefinition, this.channel),\n projections: factory.create(ProjectionsDefinition, this.channel),\n readModels: factory.create(ReadModelsDefinition, this.channel),\n jobs: factory.create(JobsDefinition, this.channel),\n eventSeeding: factory.create(EventSeedingDefinition, this.channel),\n server: factory.create(ServerDefinition, this.channel),\n };\n }\n\n /**\n * Creates a token provider based on connection configuration\n */\n private createTokenProvider(options: ChronicleConnectionOptions): ITokenProvider {\n const hasUsername = !!this._connectionString.username;\n const hasPassword = !!this._connectionString.password;\n const hasApiKey = !!this._connectionString.apiKey;\n\n if (hasApiKey) {\n // API key authentication is handled directly through call metadata.\n return new NoOpTokenProvider();\n }\n\n if (hasUsername !== hasPassword) {\n // Incomplete client credentials cannot produce a valid OAuth token.\n return new NoOpTokenProvider();\n }\n\n if (hasUsername && hasPassword) {\n return this.createOAuthTokenProvider(\n options,\n this._connectionString.username!,\n this._connectionString.password!\n );\n }\n\n // Development support: no app credentials provided, so use default dev credentials.\n return this.createOAuthTokenProvider(\n options,\n ChronicleConnectionString.DEVELOPMENT_CLIENT,\n ChronicleConnectionString.DEVELOPMENT_CLIENT_SECRET\n );\n }\n\n private createOAuthTokenProvider(\n options: ChronicleConnectionOptions,\n username: string,\n password: string\n ): ITokenProvider {\n const managementPort = options.managementPort || 8080;\n let authorityHost: string;\n let authorityPort: number;\n\n if (options.authority) {\n const authorityUrl = new URL(options.authority);\n authorityHost = authorityUrl.hostname;\n authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;\n } else {\n authorityHost = this._connectionString.serverAddress.host;\n authorityPort = managementPort;\n }\n\n const scheme = this._connectionString.disableTls ? 'http' : 'https';\n const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;\n\n return new OAuthTokenProvider(tokenEndpoint, username, password);\n }\n\n /**\n * Creates call credentials with bearer token from token provider\n */\n private createAuthCallCredentials(): grpc.CallCredentials | undefined {\n // Insecure channels cannot compose with call credentials — skip when TLS is disabled.\n if (this._connectionString.disableTls) {\n return undefined;\n }\n return grpc.credentials.createFromMetadataGenerator(async (params, callback) => {\n try {\n const token = await this.tokenProvider.getAccessToken();\n const metadata = new grpc.Metadata();\n\n if (token) {\n metadata.add('authorization', `Bearer ${token}`);\n } else {\n // Check for API key authentication\n try {\n const authMode = this._connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && this._connectionString.apiKey) {\n metadata.add('api-key', this._connectionString.apiKey);\n }\n } catch {\n // No API key configured\n }\n }\n\n callback(null, metadata);\n } catch (error) {\n callback(error as Error, new grpc.Metadata());\n }\n });\n }\n\n /**\n * Gets whether the connection is established\n */\n get isConnected(): boolean {\n return this._isConnected;\n }\n\n /**\n * Creates a middleware that injects authentication headers for all calls.\n * This works for both TLS and insecure channels, similar to gRPC interceptors in C#.\n */\n private createAuthMiddleware(): ClientMiddleware {\n const tokenProvider = this.tokenProvider;\n const connectionString = this._connectionString;\n\n return async function* authMiddleware(call, options) {\n try {\n const token = await tokenProvider.getAccessToken();\n \n if (token) {\n // Create metadata object with the Bearer token\n // The Metadata factory function from nice-grpc-common accepts an object\n const authMetadata = Metadata({ authorization: `Bearer ${token}` });\n \n // Merge with existing metadata if present\n if (options.metadata) {\n const mergedMetadata = Metadata(options.metadata);\n mergedMetadata.set('authorization', `Bearer ${token}`);\n options.metadata = mergedMetadata;\n } else {\n options.metadata = authMetadata;\n }\n } else {\n // Fallback to API key if no token\n try {\n const authMode = connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && connectionString.apiKey) {\n const apiKeyMetadata = Metadata({ 'api-key': connectionString.apiKey });\n \n if (options.metadata) {\n const mergedMetadata = Metadata(options.metadata);\n mergedMetadata.set('api-key', connectionString.apiKey);\n options.metadata = mergedMetadata;\n } else {\n options.metadata = apiKeyMetadata;\n }\n }\n } catch {\n // No API key configured, continue without additional auth\n }\n }\n } catch (error) {\n // If token retrieval fails, continue without additional auth headers\n // This allows the connection to proceed with channel-level credentials if available\n }\n \n // Pass through to next middleware/handler, properly returning the response\n return yield* call.next(call.request, options);\n };\n }\n\n /**\n * Connects to the Chronicle Kernel\n * @returns Promise that resolves when connected\n */\n async connect(): Promise<void> {\n if (this._isConnected) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n const deadline = new Date();\n deadline.setSeconds(deadline.getSeconds() + 10);\n\n this.channel.watchConnectivityState(\n this.channel.getConnectivityState(true),\n deadline,\n (error) => {\n if (error) {\n this._isConnected = false;\n reject(error);\n } else {\n const state = this.channel.getConnectivityState(false);\n if (state === grpc.connectivityState.READY) {\n this._isConnected = true;\n resolve();\n } else {\n this._isConnected = false;\n reject(new Error(`Connection failed with state: ${state}`));\n }\n }\n }\n );\n });\n }\n\n /**\n * Disconnects from the Chronicle Kernel\n */\n disconnect(): void {\n this._isConnected = false;\n this.channel.close();\n }\n\n /**\n * Disposes the connection and cleans up resources\n */\n dispose(): void {\n this.disconnect();\n }\n}\n\n"],"names":["ChronicleConnectionString","grpc","createClient","ConnectionServiceDefinition","createClientFactory","EventStoresDefinition","NamespacesDefinition","RecommendationsDefinition","IdentitiesDefinition","EventSequencesDefinition","EventTypesDefinition","ConstraintsDefinition","ObserversDefinition","FailedPartitionsDefinition","ReactorsDefinition","ReducersDefinition","ProjectionsDefinition","ReadModelsDefinition","JobsDefinition","EventSeedingDefinition","ServerDefinition","NoOpTokenProvider","OAuthTokenProvider","AuthenticationMode","Metadata"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAyGa,mBAAmB,CAAA;AACX,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,iBAAiB;AACjB,IAAA,aAAa;IACtB,YAAY,GAAG,KAAK;AAK5B,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,eAAe,GAAA;AACf,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe;IACxC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,cAAc,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc;IACvC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,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ACP,oBAAA,IAAI,CAAC,YAAY,GAAG,KAAK;oBACzB,MAAM,CAAC,KAAK,CAAC;gBACjB;qBAAO;oBACH,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC;oBACtD,IAAI,KAAK,KAAKvB,eAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE;AACxC,wBAAA,IAAI,CAAC,YAAY,GAAG,IAAI;AACxB,wBAAA,OAAO,EAAE;oBACb;yBAAO;AACH,wBAAA,IAAI,CAAC,YAAY,GAAG,KAAK;wBACzB,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAA,CAAE,CAAC,CAAC;oBAC/D;gBACJ;AACJ,YAAA,CAAC,CACJ;AACL,QAAA,CAAC,CAAC;IACN;IAKA,UAAU,GAAA;AACN,QAAA,IAAI,CAAC,YAAY,GAAG,KAAK;AACzB,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;IACxB;IAKA,OAAO,GAAA;QACH,IAAI,CAAC,UAAU,EAAE;IACrB;AACH;;;;"}
|
|
@@ -40,8 +40,10 @@ export declare class ChronicleConnection implements ChronicleServices {
|
|
|
40
40
|
constructor(options: ChronicleConnectionOptions);
|
|
41
41
|
private createServices;
|
|
42
42
|
private createTokenProvider;
|
|
43
|
+
private createOAuthTokenProvider;
|
|
43
44
|
private createAuthCallCredentials;
|
|
44
45
|
get isConnected(): boolean;
|
|
46
|
+
private createAuthMiddleware;
|
|
45
47
|
connect(): Promise<void>;
|
|
46
48
|
disconnect(): void;
|
|
47
49
|
dispose(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChronicleConnection.d.ts","sourceRoot":"","sources":["../../ChronicleConnection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ChronicleConnection.d.ts","sourceRoot":"","sources":["../../ChronicleConnection.ts"],"names":[],"mappings":"AAGA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KD,IAAI,cAAc,IAAI,oBAAoB,CAEzC;IAKD,IAAI,UAAU,IAAI,gBAAgB,CAEjC;IAKD,IAAI,WAAW,IAAI,iBAAiB,CAEnC;IAKD,IAAI,SAAS,IAAI,eAAe,CAE/B;IAKD,IAAI,gBAAgB,IAAI,sBAAsB,CAE7C;IAKD,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAKD,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAKD,IAAI,WAAW,IAAI,iBAAiB,CAEnC;IAKD,IAAI,UAAU,IAAI,gBAAgB,CAEjC;IAKD,IAAI,IAAI,IAAI,UAAU,CAErB;IAKD,IAAI,YAAY,IAAI,kBAAkB,CAErC;IAKD,IAAI,MAAM,IAAI,YAAY,CAEzB;IAKD,OAAO,CAAC,iBAAiB,CAA0B;IAKnD,IAAI,gBAAgB,IAAI,yBAAyB,CAEhD;gBAMW,OAAO,EAAE,0BAA0B;IAwD/C,OAAO,CAAC,cAAc;IAiCtB,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,yBAAyB;IAkCjC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAMD,OAAO,CAAC,oBAAoB;IAsDtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC9B,UAAU,IAAI,IAAI;IAQlB,OAAO,IAAI,IAAI;CAGlB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as grpc from '@grpc/grpc-js';
|
|
2
|
-
import { createClient } from 'nice-grpc';
|
|
2
|
+
import { createClient, createClientFactory } from 'nice-grpc';
|
|
3
|
+
import { Metadata } from 'nice-grpc-common';
|
|
3
4
|
import { NamespacesDefinition, EventStoresDefinition } from './generated/cratis_chronicle_contracts.js';
|
|
4
5
|
import { RecommendationsDefinition } from './generated/recommendations.js';
|
|
5
6
|
import { IdentitiesDefinition } from './generated/identities.js';
|
|
@@ -113,55 +114,61 @@ class ChronicleConnection {
|
|
|
113
114
|
this.services = this.createServices();
|
|
114
115
|
}
|
|
115
116
|
createServices() {
|
|
117
|
+
console.log('[Chronicle] Creating services with middleware');
|
|
118
|
+
let factory = createClientFactory();
|
|
119
|
+
console.log('[Chronicle] Attaching auth middleware');
|
|
120
|
+
factory = factory.use(this.createAuthMiddleware());
|
|
121
|
+
console.log('[Chronicle] Middleware attached, creating service clients');
|
|
116
122
|
return {
|
|
117
|
-
eventStores:
|
|
118
|
-
namespaces:
|
|
119
|
-
recommendations:
|
|
120
|
-
identities:
|
|
121
|
-
eventSequences:
|
|
122
|
-
eventTypes:
|
|
123
|
-
constraints:
|
|
124
|
-
observers:
|
|
125
|
-
failedPartitions:
|
|
126
|
-
reactors:
|
|
127
|
-
reducers:
|
|
128
|
-
projections:
|
|
129
|
-
readModels:
|
|
130
|
-
jobs:
|
|
131
|
-
eventSeeding:
|
|
132
|
-
server:
|
|
123
|
+
eventStores: factory.create(EventStoresDefinition, this.channel),
|
|
124
|
+
namespaces: factory.create(NamespacesDefinition, this.channel),
|
|
125
|
+
recommendations: factory.create(RecommendationsDefinition, this.channel),
|
|
126
|
+
identities: factory.create(IdentitiesDefinition, this.channel),
|
|
127
|
+
eventSequences: factory.create(EventSequencesDefinition, this.channel),
|
|
128
|
+
eventTypes: factory.create(EventTypesDefinition, this.channel),
|
|
129
|
+
constraints: factory.create(ConstraintsDefinition, this.channel),
|
|
130
|
+
observers: factory.create(ObserversDefinition, this.channel),
|
|
131
|
+
failedPartitions: factory.create(FailedPartitionsDefinition, this.channel),
|
|
132
|
+
reactors: factory.create(ReactorsDefinition, this.channel),
|
|
133
|
+
reducers: factory.create(ReducersDefinition, this.channel),
|
|
134
|
+
projections: factory.create(ProjectionsDefinition, this.channel),
|
|
135
|
+
readModels: factory.create(ReadModelsDefinition, this.channel),
|
|
136
|
+
jobs: factory.create(JobsDefinition, this.channel),
|
|
137
|
+
eventSeeding: factory.create(EventSeedingDefinition, this.channel),
|
|
138
|
+
server: factory.create(ServerDefinition, this.channel),
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
createTokenProvider(options) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const password = this._connectionString.password;
|
|
141
|
-
if (!username || !password) {
|
|
142
|
-
return new NoOpTokenProvider();
|
|
143
|
-
}
|
|
144
|
-
const managementPort = options.managementPort || 8080;
|
|
145
|
-
let authorityHost;
|
|
146
|
-
let authorityPort;
|
|
147
|
-
if (options.authority) {
|
|
148
|
-
const authorityUrl = new URL(options.authority);
|
|
149
|
-
authorityHost = authorityUrl.hostname;
|
|
150
|
-
authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
authorityHost = this._connectionString.serverAddress.host;
|
|
154
|
-
authorityPort = managementPort;
|
|
155
|
-
}
|
|
156
|
-
const scheme = this._connectionString.disableTls ? 'http' : 'https';
|
|
157
|
-
const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;
|
|
158
|
-
return new OAuthTokenProvider(tokenEndpoint, username, password);
|
|
159
|
-
}
|
|
142
|
+
const hasUsername = !!this._connectionString.username;
|
|
143
|
+
const hasPassword = !!this._connectionString.password;
|
|
144
|
+
const hasApiKey = !!this._connectionString.apiKey;
|
|
145
|
+
if (hasApiKey) {
|
|
160
146
|
return new NoOpTokenProvider();
|
|
161
147
|
}
|
|
162
|
-
|
|
148
|
+
if (hasUsername !== hasPassword) {
|
|
163
149
|
return new NoOpTokenProvider();
|
|
164
150
|
}
|
|
151
|
+
if (hasUsername && hasPassword) {
|
|
152
|
+
return this.createOAuthTokenProvider(options, this._connectionString.username, this._connectionString.password);
|
|
153
|
+
}
|
|
154
|
+
return this.createOAuthTokenProvider(options, ChronicleConnectionString.DEVELOPMENT_CLIENT, ChronicleConnectionString.DEVELOPMENT_CLIENT_SECRET);
|
|
155
|
+
}
|
|
156
|
+
createOAuthTokenProvider(options, username, password) {
|
|
157
|
+
const managementPort = options.managementPort || 8080;
|
|
158
|
+
let authorityHost;
|
|
159
|
+
let authorityPort;
|
|
160
|
+
if (options.authority) {
|
|
161
|
+
const authorityUrl = new URL(options.authority);
|
|
162
|
+
authorityHost = authorityUrl.hostname;
|
|
163
|
+
authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
authorityHost = this._connectionString.serverAddress.host;
|
|
167
|
+
authorityPort = managementPort;
|
|
168
|
+
}
|
|
169
|
+
const scheme = this._connectionString.disableTls ? 'http' : 'https';
|
|
170
|
+
const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;
|
|
171
|
+
return new OAuthTokenProvider(tokenEndpoint, username, password);
|
|
165
172
|
}
|
|
166
173
|
createAuthCallCredentials() {
|
|
167
174
|
if (this._connectionString.disableTls) {
|
|
@@ -194,6 +201,47 @@ class ChronicleConnection {
|
|
|
194
201
|
get isConnected() {
|
|
195
202
|
return this._isConnected;
|
|
196
203
|
}
|
|
204
|
+
createAuthMiddleware() {
|
|
205
|
+
const tokenProvider = this.tokenProvider;
|
|
206
|
+
const connectionString = this._connectionString;
|
|
207
|
+
return async function* authMiddleware(call, options) {
|
|
208
|
+
try {
|
|
209
|
+
const token = await tokenProvider.getAccessToken();
|
|
210
|
+
if (token) {
|
|
211
|
+
const authMetadata = Metadata({ authorization: `Bearer ${token}` });
|
|
212
|
+
if (options.metadata) {
|
|
213
|
+
const mergedMetadata = Metadata(options.metadata);
|
|
214
|
+
mergedMetadata.set('authorization', `Bearer ${token}`);
|
|
215
|
+
options.metadata = mergedMetadata;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
options.metadata = authMetadata;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
try {
|
|
223
|
+
const authMode = connectionString.authenticationMode;
|
|
224
|
+
if (authMode === AuthenticationMode.ApiKey && connectionString.apiKey) {
|
|
225
|
+
const apiKeyMetadata = Metadata({ 'api-key': connectionString.apiKey });
|
|
226
|
+
if (options.metadata) {
|
|
227
|
+
const mergedMetadata = Metadata(options.metadata);
|
|
228
|
+
mergedMetadata.set('api-key', connectionString.apiKey);
|
|
229
|
+
options.metadata = mergedMetadata;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
options.metadata = apiKeyMetadata;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
}
|
|
242
|
+
return yield* call.next(call.request, options);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
197
245
|
async connect() {
|
|
198
246
|
if (this._isConnected) {
|
|
199
247
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChronicleConnection.js","sources":["../../ChronicleConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as grpc from '@grpc/grpc-js';\nimport { createClient } from 'nice-grpc';\n\n// Import service definitions from generated files\nimport { EventStoresDefinition, NamespacesDefinition } from './generated/cratis_chronicle_contracts';\nimport { RecommendationsDefinition } from './generated/recommendations';\nimport { IdentitiesDefinition } from './generated/identities';\nimport { EventSequencesDefinition } from './generated/eventsequences';\nimport { EventTypesDefinition } from './generated/events';\nimport { ConstraintsDefinition } from './generated/events_constraints';\nimport { ObserversDefinition, FailedPartitionsDefinition } from './generated/observation';\nimport { ReactorsDefinition } from './generated/observation_reactors';\nimport { ReducersDefinition } from './generated/observation_reducers';\nimport { ProjectionsDefinition } from './generated/projections';\nimport { ReadModelsDefinition } from './generated/readmodels';\nimport { JobsDefinition } from './generated/jobs';\nimport { EventSeedingDefinition } from './generated/seeding';\nimport { ServerDefinition } from './generated/host';\nimport { ConnectionServiceDefinition } from './generated/clients';\n\n// Import client types\nimport type {\n EventStoresClient,\n NamespacesClient,\n RecommendationsClient,\n IdentitiesClient,\n EventSequencesClient,\n EventTypesClient,\n ConstraintsClient,\n ObserversClient,\n FailedPartitionsClient,\n ReactorsClient,\n ReducersClient,\n ProjectionsClient,\n ReadModelsClient,\n JobsClient,\n EventSeedingClient,\n ServerClient,\n ConnectionServiceClient,\n} from './generated/index';\n\nimport type { ChronicleServices } from './ChronicleServices';\nimport { ChronicleConnectionString, AuthenticationMode } from './ChronicleConnectionString';\nimport { ITokenProvider, OAuthTokenProvider, NoOpTokenProvider } from './TokenProvider';\n\n/**\n * Configuration options for Chronicle connection\n */\nexport interface ChronicleConnectionOptions {\n /**\n * The connection string (e.g., 'chronicle://localhost:35000' or 'chronicle://user:pass@localhost:35000')\n * Can also be a ChronicleConnectionString instance\n */\n connectionString?: string | ChronicleConnectionString;\n\n /**\n * The host and port of the Chronicle server (e.g., 'localhost:35000')\n * This is used if connectionString is not provided\n */\n serverAddress?: string;\n\n /**\n * Optional gRPC credentials (defaults to credentials based on connection string)\n */\n credentials?: grpc.ChannelCredentials;\n\n /**\n * Optional connection timeout in milliseconds (defaults to 10000)\n */\n connectTimeout?: number;\n\n /**\n * Optional maximum receive message size in bytes\n */\n maxReceiveMessageSize?: number;\n\n /**\n * Optional maximum send message size in bytes\n */\n maxSendMessageSize?: number;\n\n /**\n * Optional correlation ID for tracking requests\n */\n correlationId?: string;\n\n /**\n * Optional authentication authority URL. If not set, uses the Chronicle server itself as the authority\n */\n authority?: string;\n\n /**\n * Optional management port for authentication endpoint (defaults to 8080)\n */\n managementPort?: number;\n}\n\n/**\n * Manages the connection to Chronicle Kernel and provides access to all gRPC services\n */\nexport class ChronicleConnection implements ChronicleServices {\n private readonly channel: grpc.Channel;\n private readonly services: ChronicleServices;\n private readonly _connectionString: ChronicleConnectionString;\n private readonly tokenProvider: ITokenProvider;\n private _isConnected = false;\n\n /**\n * Event stores service\n */\n get eventStores(): EventStoresClient {\n return this.services.eventStores;\n }\n\n /**\n * Namespaces service\n */\n get namespaces(): NamespacesClient {\n return this.services.namespaces;\n }\n\n /**\n * Recommendations service\n */\n get recommendations(): RecommendationsClient {\n return this.services.recommendations;\n }\n\n /**\n * Identities service\n */\n get identities(): IdentitiesClient {\n return this.services.identities;\n }\n\n /**\n * Event sequences service\n */\n get eventSequences(): EventSequencesClient {\n return this.services.eventSequences;\n }\n\n /**\n * Event types service\n */\n get eventTypes(): EventTypesClient {\n return this.services.eventTypes;\n }\n\n /**\n * Constraints service\n */\n get constraints(): ConstraintsClient {\n return this.services.constraints;\n }\n\n /**\n * Observers service\n */\n get observers(): ObserversClient {\n return this.services.observers;\n }\n\n /**\n * Failed partitions service\n */\n get failedPartitions(): FailedPartitionsClient {\n return this.services.failedPartitions;\n }\n\n /**\n * Reactors service\n */\n get reactors(): ReactorsClient {\n return this.services.reactors;\n }\n\n /**\n * Reducers service\n */\n get reducers(): ReducersClient {\n return this.services.reducers;\n }\n\n /**\n * Projections service\n */\n get projections(): ProjectionsClient {\n return this.services.projections;\n }\n\n /**\n * Read models service\n */\n get readModels(): ReadModelsClient {\n return this.services.readModels;\n }\n\n /**\n * Jobs service\n */\n get jobs(): JobsClient {\n return this.services.jobs;\n }\n\n /**\n * Event seeding service\n */\n get eventSeeding(): EventSeedingClient {\n return this.services.eventSeeding;\n }\n\n /**\n * Server service\n */\n get server(): ServerClient {\n return this.services.server;\n }\n\n /**\n * Connection service for managing the connection\n */\n private connectionService: ConnectionServiceClient;\n\n /**\n * Gets the connection string used for this connection\n */\n get connectionString(): ChronicleConnectionString {\n return this._connectionString;\n }\n\n /**\n * Creates a new Chronicle connection\n * @param options Connection configuration options\n */\n constructor(options: ChronicleConnectionOptions) {\n // Parse connection string or create from serverAddress\n if (options.connectionString) {\n this._connectionString =\n typeof options.connectionString === 'string'\n ? new ChronicleConnectionString(options.connectionString)\n : options.connectionString;\n } else if (options.serverAddress) {\n this._connectionString = new ChronicleConnectionString(\n `chronicle://${options.serverAddress}`\n );\n } else {\n this._connectionString = ChronicleConnectionString.Default;\n }\n\n // Create server address string\n const serverAddress = `${this._connectionString.serverAddress.host}:${this._connectionString.serverAddress.port}`;\n\n // Create token provider for authentication\n this.tokenProvider = this.createTokenProvider(options);\n\n // Create channel options\n const channelOptions: grpc.ChannelOptions = {};\n\n if (options.maxReceiveMessageSize) {\n channelOptions['grpc.max_receive_message_length'] = options.maxReceiveMessageSize;\n }\n\n if (options.maxSendMessageSize) {\n channelOptions['grpc.max_send_message_length'] = options.maxSendMessageSize;\n }\n\n // Create gRPC channel credentials\n let channelCredentials = options.credentials;\n if (!channelCredentials) {\n channelCredentials = this._connectionString.createCredentials();\n\n if (!this._connectionString.disableTls) {\n const callCredentials = this.createAuthCallCredentials();\n if (callCredentials) {\n channelCredentials = grpc.credentials.combineChannelCredentials(\n channelCredentials,\n callCredentials\n );\n }\n }\n }\n\n // Create the gRPC channel\n this.channel = new grpc.Channel(serverAddress, channelCredentials, channelOptions);\n\n // Create services using nice-grpc's createClient\n this.connectionService = createClient(ConnectionServiceDefinition, this.channel);\n this.services = this.createServices();\n }\n\n private createServices(): ChronicleServices {\n return {\n eventStores: createClient(EventStoresDefinition, this.channel),\n namespaces: createClient(NamespacesDefinition, this.channel),\n recommendations: createClient(RecommendationsDefinition, this.channel),\n identities: createClient(IdentitiesDefinition, this.channel),\n eventSequences: createClient(EventSequencesDefinition, this.channel),\n eventTypes: createClient(EventTypesDefinition, this.channel),\n constraints: createClient(ConstraintsDefinition, this.channel),\n observers: createClient(ObserversDefinition, this.channel),\n failedPartitions: createClient(FailedPartitionsDefinition, this.channel),\n reactors: createClient(ReactorsDefinition, this.channel),\n reducers: createClient(ReducersDefinition, this.channel),\n projections: createClient(ProjectionsDefinition, this.channel),\n readModels: createClient(ReadModelsDefinition, this.channel),\n jobs: createClient(JobsDefinition, this.channel),\n eventSeeding: createClient(EventSeedingDefinition, this.channel),\n server: createClient(ServerDefinition, this.channel),\n };\n }\n\n /**\n * Creates a token provider based on connection configuration\n */\n private createTokenProvider(options: ChronicleConnectionOptions): ITokenProvider {\n try {\n const authMode = this._connectionString.authenticationMode;\n\n if (authMode === AuthenticationMode.ClientCredentials) {\n const username = this._connectionString.username;\n const password = this._connectionString.password;\n\n if (!username || !password) {\n return new NoOpTokenProvider();\n }\n\n // Determine the authority URL\n const managementPort = options.managementPort || 8080;\n let authorityHost: string;\n let authorityPort: number;\n\n if (options.authority) {\n // Parse custom authority URL\n const authorityUrl = new URL(options.authority);\n authorityHost = authorityUrl.hostname;\n authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;\n } else {\n // Use Chronicle server as authority\n authorityHost = this._connectionString.serverAddress.host;\n authorityPort = managementPort;\n }\n\n const scheme = this._connectionString.disableTls ? 'http' : 'https';\n const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;\n\n return new OAuthTokenProvider(tokenEndpoint, username, password);\n }\n\n // For API key or other modes, no token provider needed (handled by connection string)\n return new NoOpTokenProvider();\n } catch {\n // If authentication mode check fails (no auth configured), use no-op provider\n return new NoOpTokenProvider();\n }\n }\n\n /**\n * Creates call credentials with bearer token from token provider\n */\n private createAuthCallCredentials(): grpc.CallCredentials | undefined {\n // Insecure channels cannot compose with call credentials — skip when TLS is disabled.\n if (this._connectionString.disableTls) {\n return undefined;\n }\n return grpc.credentials.createFromMetadataGenerator(async (params, callback) => {\n try {\n const token = await this.tokenProvider.getAccessToken();\n const metadata = new grpc.Metadata();\n\n if (token) {\n metadata.add('authorization', `Bearer ${token}`);\n } else {\n // Check for API key authentication\n try {\n const authMode = this._connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && this._connectionString.apiKey) {\n metadata.add('api-key', this._connectionString.apiKey);\n }\n } catch {\n // No API key configured\n }\n }\n\n callback(null, metadata);\n } catch (error) {\n callback(error as Error, new grpc.Metadata());\n }\n });\n }\n\n /**\n * Gets whether the connection is established\n */\n get isConnected(): boolean {\n return this._isConnected;\n }\n\n /**\n * Connects to the Chronicle Kernel\n * @returns Promise that resolves when connected\n */\n async connect(): Promise<void> {\n if (this._isConnected) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n const deadline = new Date();\n deadline.setSeconds(deadline.getSeconds() + 10);\n\n this.channel.watchConnectivityState(\n this.channel.getConnectivityState(true),\n deadline,\n (error) => {\n if (error) {\n this._isConnected = false;\n reject(error);\n } else {\n const state = this.channel.getConnectivityState(false);\n if (state === grpc.connectivityState.READY) {\n this._isConnected = true;\n resolve();\n } else {\n this._isConnected = false;\n reject(new Error(`Connection failed with state: ${state}`));\n }\n }\n }\n );\n });\n }\n\n /**\n * Disconnects from the Chronicle Kernel\n */\n disconnect(): void {\n this._isConnected = false;\n this.channel.close();\n }\n\n /**\n * Disposes the connection and cleans up resources\n */\n dispose(): void {\n this.disconnect();\n }\n}\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;MAuGa,mBAAmB,CAAA;AACX,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,iBAAiB;AACjB,IAAA,aAAa;IACtB,YAAY,GAAG,KAAK;AAK5B,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,eAAe,GAAA;AACf,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe;IACxC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,cAAc,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc;IACvC;AAKA,IAAA,IAAI,UAAU,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU;IACnC;AAKA,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC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AI,IAAI,EAAE;YAC3B,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC;AAE/C,YAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAC/B,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,EACvC,QAAQ,EACR,CAAC,KAAK,KAAI;gBACN,IAAI,KAAK,EAAE;AACP,oBAAA,IAAI,CAAC,YAAY,GAAG,KAAK;oBACzB,MAAM,CAAC,KAAK,CAAC;gBACjB;qBAAO;oBACH,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC;oBACtD,IAAI,KAAK,KAAK,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE;AACxC,wBAAA,IAAI,CAAC,YAAY,GAAG,IAAI;AACxB,wBAAA,OAAO,EAAE;oBACb;yBAAO;AACH,wBAAA,IAAI,CAAC,YAAY,GAAG,KAAK;wBACzB,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAA,CAAE,CAAC,CAAC;oBAC/D;gBACJ;AACJ,YAAA,CAAC,CACJ;AACL,QAAA,CAAC,CAAC;IACN;IAKA,UAAU,GAAA;AACN,QAAA,IAAI,CAAC,YAAY,GAAG,KAAK;AACzB,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;IACxB;IAKA,OAAO,GAAA;QACH,IAAI,CAAC,UAAU,EAAE;IACrB;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ChronicleConnection.js","sources":["../../ChronicleConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as grpc from '@grpc/grpc-js';\nimport { createClient, createClientFactory } from 'nice-grpc';\nimport type { ClientMiddleware } from 'nice-grpc-common';\nimport { Metadata } from 'nice-grpc-common';\n\n// Import service definitions from generated files\nimport { EventStoresDefinition, NamespacesDefinition } from './generated/cratis_chronicle_contracts';\nimport { RecommendationsDefinition } from './generated/recommendations';\nimport { IdentitiesDefinition } from './generated/identities';\nimport { EventSequencesDefinition } from './generated/eventsequences';\nimport { EventTypesDefinition } from './generated/events';\nimport { ConstraintsDefinition } from './generated/events_constraints';\nimport { ObserversDefinition, FailedPartitionsDefinition } from './generated/observation';\nimport { ReactorsDefinition } from './generated/observation_reactors';\nimport { ReducersDefinition } from './generated/observation_reducers';\nimport { ProjectionsDefinition } from './generated/projections';\nimport { ReadModelsDefinition } from './generated/readmodels';\nimport { JobsDefinition } from './generated/jobs';\nimport { EventSeedingDefinition } from './generated/seeding';\nimport { ServerDefinition } from './generated/host';\nimport { ConnectionServiceDefinition } from './generated/clients';\n\n// Import client types\nimport type {\n EventStoresClient,\n NamespacesClient,\n RecommendationsClient,\n IdentitiesClient,\n EventSequencesClient,\n EventTypesClient,\n ConstraintsClient,\n ObserversClient,\n FailedPartitionsClient,\n ReactorsClient,\n ReducersClient,\n ProjectionsClient,\n ReadModelsClient,\n JobsClient,\n EventSeedingClient,\n ServerClient,\n ConnectionServiceClient,\n} from './generated/index';\n\nimport type { ChronicleServices } from './ChronicleServices';\nimport { ChronicleConnectionString, AuthenticationMode } from './ChronicleConnectionString';\nimport { ITokenProvider, OAuthTokenProvider, NoOpTokenProvider } from './TokenProvider';\n\n/**\n * Configuration options for Chronicle connection\n */\nexport interface ChronicleConnectionOptions {\n /**\n * The connection string (e.g., 'chronicle://localhost:35000' or 'chronicle://user:pass@localhost:35000')\n * Can also be a ChronicleConnectionString instance\n */\n connectionString?: string | ChronicleConnectionString;\n\n /**\n * The host and port of the Chronicle server (e.g., 'localhost:35000')\n * This is used if connectionString is not provided\n */\n serverAddress?: string;\n\n /**\n * Optional gRPC credentials (defaults to credentials based on connection string)\n */\n credentials?: grpc.ChannelCredentials;\n\n /**\n * Optional connection timeout in milliseconds (defaults to 10000)\n */\n connectTimeout?: number;\n\n /**\n * Optional maximum receive message size in bytes\n */\n maxReceiveMessageSize?: number;\n\n /**\n * Optional maximum send message size in bytes\n */\n maxSendMessageSize?: number;\n\n /**\n * Optional correlation ID for tracking requests\n */\n correlationId?: string;\n\n /**\n * Optional authentication authority URL. If not set, uses the Chronicle server itself as the authority\n */\n authority?: string;\n\n /**\n * Optional management port for authentication endpoint (defaults to 8080)\n */\n managementPort?: number;\n}\n\n/**\n * Manages the connection to Chronicle Kernel and provides access to all gRPC services\n */\nexport class ChronicleConnection implements ChronicleServices {\n private readonly channel: grpc.Channel;\n private readonly services: ChronicleServices;\n private readonly _connectionString: ChronicleConnectionString;\n private readonly tokenProvider: ITokenProvider;\n private _isConnected = false;\n\n /**\n * Event stores service\n */\n get eventStores(): EventStoresClient {\n return this.services.eventStores;\n }\n\n /**\n * Namespaces service\n */\n get namespaces(): NamespacesClient {\n return this.services.namespaces;\n }\n\n /**\n * Recommendations service\n */\n get recommendations(): RecommendationsClient {\n return this.services.recommendations;\n }\n\n /**\n * Identities service\n */\n get identities(): IdentitiesClient {\n return this.services.identities;\n }\n\n /**\n * Event sequences service\n */\n get eventSequences(): EventSequencesClient {\n return this.services.eventSequences;\n }\n\n /**\n * Event types service\n */\n get eventTypes(): EventTypesClient {\n return this.services.eventTypes;\n }\n\n /**\n * Constraints service\n */\n get constraints(): ConstraintsClient {\n return this.services.constraints;\n }\n\n /**\n * Observers service\n */\n get observers(): ObserversClient {\n return this.services.observers;\n }\n\n /**\n * Failed partitions service\n */\n get failedPartitions(): FailedPartitionsClient {\n return this.services.failedPartitions;\n }\n\n /**\n * Reactors service\n */\n get reactors(): ReactorsClient {\n return this.services.reactors;\n }\n\n /**\n * Reducers service\n */\n get reducers(): ReducersClient {\n return this.services.reducers;\n }\n\n /**\n * Projections service\n */\n get projections(): ProjectionsClient {\n return this.services.projections;\n }\n\n /**\n * Read models service\n */\n get readModels(): ReadModelsClient {\n return this.services.readModels;\n }\n\n /**\n * Jobs service\n */\n get jobs(): JobsClient {\n return this.services.jobs;\n }\n\n /**\n * Event seeding service\n */\n get eventSeeding(): EventSeedingClient {\n return this.services.eventSeeding;\n }\n\n /**\n * Server service\n */\n get server(): ServerClient {\n return this.services.server;\n }\n\n /**\n * Connection service for managing the connection\n */\n private connectionService: ConnectionServiceClient;\n\n /**\n * Gets the connection string used for this connection\n */\n get connectionString(): ChronicleConnectionString {\n return this._connectionString;\n }\n\n /**\n * Creates a new Chronicle connection\n * @param options Connection configuration options\n */\n constructor(options: ChronicleConnectionOptions) {\n // Parse connection string or create from serverAddress\n if (options.connectionString) {\n this._connectionString =\n typeof options.connectionString === 'string'\n ? new ChronicleConnectionString(options.connectionString)\n : options.connectionString;\n } else if (options.serverAddress) {\n this._connectionString = new ChronicleConnectionString(\n `chronicle://${options.serverAddress}`\n );\n } else {\n this._connectionString = ChronicleConnectionString.Default;\n }\n\n // Create server address string\n const serverAddress = `${this._connectionString.serverAddress.host}:${this._connectionString.serverAddress.port}`;\n\n // Create token provider for authentication\n this.tokenProvider = this.createTokenProvider(options);\n\n // Create channel options\n const channelOptions: grpc.ChannelOptions = {};\n\n if (options.maxReceiveMessageSize) {\n channelOptions['grpc.max_receive_message_length'] = options.maxReceiveMessageSize;\n }\n\n if (options.maxSendMessageSize) {\n channelOptions['grpc.max_send_message_length'] = options.maxSendMessageSize;\n }\n\n // Create gRPC channel credentials\n let channelCredentials = options.credentials;\n if (!channelCredentials) {\n channelCredentials = this._connectionString.createCredentials();\n\n if (!this._connectionString.disableTls) {\n const callCredentials = this.createAuthCallCredentials();\n if (callCredentials) {\n channelCredentials = grpc.credentials.combineChannelCredentials(\n channelCredentials,\n callCredentials\n );\n }\n }\n }\n\n // Create the gRPC channel\n this.channel = new grpc.Channel(serverAddress, channelCredentials, channelOptions);\n\n // Create services using nice-grpc's createClient\n this.connectionService = createClient(ConnectionServiceDefinition, this.channel);\n this.services = this.createServices();\n }\n\n private createServices(): ChronicleServices {\n console.log('[Chronicle] Creating services with middleware');\n // Create a client factory and attach auth middleware for all calls\n let factory = createClientFactory();\n \n console.log('[Chronicle] Attaching auth middleware');\n // Attach authentication middleware that works for both TLS and insecure channels\n factory = factory.use(this.createAuthMiddleware());\n console.log('[Chronicle] Middleware attached, creating service clients');\n\n return {\n eventStores: factory.create(EventStoresDefinition, this.channel),\n namespaces: factory.create(NamespacesDefinition, this.channel),\n recommendations: factory.create(RecommendationsDefinition, this.channel),\n identities: factory.create(IdentitiesDefinition, this.channel),\n eventSequences: factory.create(EventSequencesDefinition, this.channel),\n eventTypes: factory.create(EventTypesDefinition, this.channel),\n constraints: factory.create(ConstraintsDefinition, this.channel),\n observers: factory.create(ObserversDefinition, this.channel),\n failedPartitions: factory.create(FailedPartitionsDefinition, this.channel),\n reactors: factory.create(ReactorsDefinition, this.channel),\n reducers: factory.create(ReducersDefinition, this.channel),\n projections: factory.create(ProjectionsDefinition, this.channel),\n readModels: factory.create(ReadModelsDefinition, this.channel),\n jobs: factory.create(JobsDefinition, this.channel),\n eventSeeding: factory.create(EventSeedingDefinition, this.channel),\n server: factory.create(ServerDefinition, this.channel),\n };\n }\n\n /**\n * Creates a token provider based on connection configuration\n */\n private createTokenProvider(options: ChronicleConnectionOptions): ITokenProvider {\n const hasUsername = !!this._connectionString.username;\n const hasPassword = !!this._connectionString.password;\n const hasApiKey = !!this._connectionString.apiKey;\n\n if (hasApiKey) {\n // API key authentication is handled directly through call metadata.\n return new NoOpTokenProvider();\n }\n\n if (hasUsername !== hasPassword) {\n // Incomplete client credentials cannot produce a valid OAuth token.\n return new NoOpTokenProvider();\n }\n\n if (hasUsername && hasPassword) {\n return this.createOAuthTokenProvider(\n options,\n this._connectionString.username!,\n this._connectionString.password!\n );\n }\n\n // Development support: no app credentials provided, so use default dev credentials.\n return this.createOAuthTokenProvider(\n options,\n ChronicleConnectionString.DEVELOPMENT_CLIENT,\n ChronicleConnectionString.DEVELOPMENT_CLIENT_SECRET\n );\n }\n\n private createOAuthTokenProvider(\n options: ChronicleConnectionOptions,\n username: string,\n password: string\n ): ITokenProvider {\n const managementPort = options.managementPort || 8080;\n let authorityHost: string;\n let authorityPort: number;\n\n if (options.authority) {\n const authorityUrl = new URL(options.authority);\n authorityHost = authorityUrl.hostname;\n authorityPort = authorityUrl.port ? parseInt(authorityUrl.port, 10) : managementPort;\n } else {\n authorityHost = this._connectionString.serverAddress.host;\n authorityPort = managementPort;\n }\n\n const scheme = this._connectionString.disableTls ? 'http' : 'https';\n const tokenEndpoint = `${scheme}://${authorityHost}:${authorityPort}/connect/token`;\n\n return new OAuthTokenProvider(tokenEndpoint, username, password);\n }\n\n /**\n * Creates call credentials with bearer token from token provider\n */\n private createAuthCallCredentials(): grpc.CallCredentials | undefined {\n // Insecure channels cannot compose with call credentials — skip when TLS is disabled.\n if (this._connectionString.disableTls) {\n return undefined;\n }\n return grpc.credentials.createFromMetadataGenerator(async (params, callback) => {\n try {\n const token = await this.tokenProvider.getAccessToken();\n const metadata = new grpc.Metadata();\n\n if (token) {\n metadata.add('authorization', `Bearer ${token}`);\n } else {\n // Check for API key authentication\n try {\n const authMode = this._connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && this._connectionString.apiKey) {\n metadata.add('api-key', this._connectionString.apiKey);\n }\n } catch {\n // No API key configured\n }\n }\n\n callback(null, metadata);\n } catch (error) {\n callback(error as Error, new grpc.Metadata());\n }\n });\n }\n\n /**\n * Gets whether the connection is established\n */\n get isConnected(): boolean {\n return this._isConnected;\n }\n\n /**\n * Creates a middleware that injects authentication headers for all calls.\n * This works for both TLS and insecure channels, similar to gRPC interceptors in C#.\n */\n private createAuthMiddleware(): ClientMiddleware {\n const tokenProvider = this.tokenProvider;\n const connectionString = this._connectionString;\n\n return async function* authMiddleware(call, options) {\n try {\n const token = await tokenProvider.getAccessToken();\n \n if (token) {\n // Create metadata object with the Bearer token\n // The Metadata factory function from nice-grpc-common accepts an object\n const authMetadata = Metadata({ authorization: `Bearer ${token}` });\n \n // Merge with existing metadata if present\n if (options.metadata) {\n const mergedMetadata = Metadata(options.metadata);\n mergedMetadata.set('authorization', `Bearer ${token}`);\n options.metadata = mergedMetadata;\n } else {\n options.metadata = authMetadata;\n }\n } else {\n // Fallback to API key if no token\n try {\n const authMode = connectionString.authenticationMode;\n if (authMode === AuthenticationMode.ApiKey && connectionString.apiKey) {\n const apiKeyMetadata = Metadata({ 'api-key': connectionString.apiKey });\n \n if (options.metadata) {\n const mergedMetadata = Metadata(options.metadata);\n mergedMetadata.set('api-key', connectionString.apiKey);\n options.metadata = mergedMetadata;\n } else {\n options.metadata = apiKeyMetadata;\n }\n }\n } catch {\n // No API key configured, continue without additional auth\n }\n }\n } catch (error) {\n // If token retrieval fails, continue without additional auth headers\n // This allows the connection to proceed with channel-level credentials if available\n }\n \n // Pass through to next middleware/handler, properly returning the response\n return yield* call.next(call.request, options);\n };\n }\n\n /**\n * Connects to the Chronicle Kernel\n * @returns Promise that resolves when connected\n */\n async connect(): Promise<void> {\n if (this._isConnected) {\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n const deadline = new Date();\n deadline.setSeconds(deadline.getSeconds() + 10);\n\n this.channel.watchConnectivityState(\n this.channel.getConnectivityState(true),\n deadline,\n (error) => {\n if (error) {\n this._isConnected = false;\n reject(error);\n } else {\n const state = this.channel.getConnectivityState(false);\n if (state === grpc.connectivityState.READY) {\n this._isConnected = true;\n resolve();\n } else {\n this._isConnected = false;\n reject(new Error(`Connection failed with state: ${state}`));\n }\n }\n }\n );\n });\n }\n\n /**\n * Disconnects from the Chronicle Kernel\n */\n disconnect(): void {\n this._isConnected = false;\n this.channel.close();\n }\n\n /**\n * Disposes the connection and cleans up resources\n */\n dispose(): void {\n this.disconnect();\n }\n}\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;MAyGa,mBAAmB,CAAA;AACX,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,iBAAiB;AACjB,IAAA,aAAa;IACtB,YAAY,GAAG,KAAK;AAK5B,IAAA,IAAI,WAAW,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,WA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