UNPKG

@river-build/sdk

Version:

For more details, visit the following resources:

39 lines 1.71 kB
import { createClient } from '@connectrpc/connect'; import { AuthenticationService } from '@river-build/proto'; import { dlog } from '@river-build/dlog'; import { getEnvVar, randomUrlSelector } from './utils'; import { DEFAULT_RETRY_PARAMS, loggingInterceptor, retryInterceptor } from './rpcInterceptors'; import { createHttp2ConnectTransport } from './rpcCommon'; const logInfo = dlog('csb:auto-rpc:info'); let nextRpcClientNum = 0; export function makeAuthenticationRpcClient(dest, opts) { const transportId = nextRpcClientNum++; const retryParams = opts?.retryParams ?? DEFAULT_RETRY_PARAMS; const url = randomUrlSelector(dest); logInfo('makeAuthenticationRpcClient: Connecting to url=', url, ' allUrls=', dest, ' transportId =', transportId); const options = { baseUrl: url, interceptors: [ ...(opts?.interceptors ?? []), loggingInterceptor(transportId, 'AuthenticationService'), 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('makeAuthenticationRpcClient: running in debug mode, using JSON format'); options.useBinaryFormat = false; options.jsonOptions = { alwaysEmitImplicit: true, useProtoFieldName: true, }; } const transport = createHttp2ConnectTransport(options); const client = createClient(AuthenticationService, transport); client.url = url; return client; } //# sourceMappingURL=makeAuthenticationRpcClient.js.map