UNPKG

@river-build/sdk

Version:

For more details, visit the following resources:

40 lines 1.79 kB
import { createClient } from '@connectrpc/connect'; import { NotificationService } from '@river-build/proto'; import { dlog } from '@river-build/dlog'; import { getEnvVar, randomUrlSelector } from './utils'; import { createHttp2ConnectTransport } from './rpcCommon'; import { DEFAULT_RETRY_PARAMS, loggingInterceptor, retryInterceptor, setHeaderInterceptor, } from './rpcInterceptors'; const logInfo = dlog('csb:rpc:info'); let nextRpcClientNum = 0; export function makeNotificationRpcClient(dest, sessionToken, opts) { const transportId = nextRpcClientNum++; const retryParams = opts?.retryParams ?? DEFAULT_RETRY_PARAMS; const url = randomUrlSelector(dest); logInfo('makeNotificationRpcClient: Connecting to url=', url, ' allUrls=', dest, ' transportId =', transportId); const options = { baseUrl: url, interceptors: [ ...(opts?.interceptors ?? []), setHeaderInterceptor({ Authorization: sessionToken }), loggingInterceptor(transportId, 'NotificationService'), retryInterceptor(retryParams), ], defaultTimeoutMs: undefined, // default timeout is undefined, we add a timeout in the retryInterceptor }; if (getEnvVar('RIVER_DEBUG_TRANSPORT') !== 'true') { options.useBinaryFormat = true; } else { logInfo('makeNotificationRpcClient: running in debug mode, using JSON format'); options.useBinaryFormat = false; options.jsonOptions = { alwaysEmitImplicit: true, useProtoFieldName: true, }; } const transport = createHttp2ConnectTransport(options); const client = createClient(NotificationService, transport); client.url = url; return client; } //# sourceMappingURL=makeNotificationRpcClient.js.map