@@ -184,6 +184,10 @@ type RelayfileWorkspaceHandle = {
184184type TokenProvider = ( ) => Promise < string | undefined >
185185type RelayFileSyncFactory = ( options : RelayFileSyncOptions ) => RelayFileSync
186186
187+ type IntegrationRelayFileSyncOptionsInput = Omit < RelayFileSyncOptions , 'token' > & {
188+ tokenProvider : TokenProvider
189+ }
190+
187191type IntegrationEventBridgeDeps = {
188192 broker ?: BrokerEventBridge
189193 getWorkspaceHandle ?: ( ) => Promise < RelayfileWorkspaceHandle >
@@ -264,6 +268,16 @@ export function resetIntegrationEventTelemetryForTests(): void {
264268 aggregatedWarnings . clear ( )
265269}
266270
271+ export function integrationRelayFileSyncOptions (
272+ input : IntegrationRelayFileSyncOptionsInput
273+ ) : RelayFileSyncOptions {
274+ const { tokenProvider, ...options } = input
275+ return {
276+ ...options ,
277+ token : tokenProvider
278+ }
279+ }
280+
267281function toErrorMessage ( error : unknown ) : string {
268282 if ( error instanceof Error ) {
269283 const message = error . message . trim ( )
@@ -274,21 +288,21 @@ function toErrorMessage(error: unknown): string {
274288 return message || 'empty string error'
275289 }
276290 if ( isRecord ( error ) ) {
277- const message = error . message
291+ const record = error as Record < string , unknown >
292+ const message = record . message
278293 if ( typeof message === 'string' && message . trim ( ) ) return message . trim ( )
279- const reason = error . reason
294+ const reason = record . reason
280295 if ( typeof reason === 'string' && reason . trim ( ) ) return reason . trim ( )
281296 const parts = [
282- typeof error . name === 'string' && error . name . trim ( ) ? error . name . trim ( ) : null ,
283- typeof error . type === 'string' && error . type . trim ( ) ? `type=${ error . type . trim ( ) } ` : null ,
284- typeof error . code === 'string' && error . code . trim ( ) ? `code=${ error . code . trim ( ) } ` : typeof error . code === 'number' ? `code=${ error . code } ` : null ,
285- typeof error . status === 'string' && error . status . trim ( ) ? `status=${ error . status . trim ( ) } ` : typeof error . status === 'number' ? `status=${ error . status } ` : null ,
286- typeof error . statusCode === 'string' && error . statusCode . trim ( ) ? `statusCode=${ error . statusCode . trim ( ) } ` : typeof error . statusCode === 'number' ? `statusCode=${ error . statusCode } ` : null ,
287- typeof error . httpStatus === 'string' && error . httpStatus . trim ( ) ? `httpStatus=${ error . httpStatus . trim ( ) } ` : typeof error . httpStatus === 'number' ? `httpStatus=${ error . httpStatus } ` : null
297+ typeof record . name === 'string' && record . name . trim ( ) ? record . name . trim ( ) : null ,
298+ typeof record . type === 'string' && record . type . trim ( ) ? `type=${ record . type . trim ( ) } ` : null ,
299+ typeof record . code === 'string' && record . code . trim ( ) ? `code=${ record . code . trim ( ) } ` : typeof record . code === 'number' ? `code=${ record . code } ` : null ,
300+ typeof record . status === 'string' && record . status . trim ( ) ? `status=${ record . status . trim ( ) } ` : typeof record . status === 'number' ? `status=${ record . status } ` : null ,
301+ typeof record . statusCode === 'string' && record . statusCode . trim ( ) ? `statusCode=${ record . statusCode . trim ( ) } ` : typeof record . statusCode === 'number' ? `statusCode=${ record . statusCode } ` : null ,
302+ typeof record . httpStatus === 'string' && record . httpStatus . trim ( ) ? `httpStatus=${ record . httpStatus . trim ( ) } ` : typeof record . httpStatus === 'number' ? `httpStatus=${ record . httpStatus } ` : null
288303 ] . filter ( ( entry ) : entry is string => entry !== null )
289304 if ( parts . length > 0 ) return parts . join ( ' ' )
290-
291- const constructorName = ( error as { constructor ?: { name ?: string } } ) . constructor ?. name
305+ const constructorName = record . constructor ?. name
292306 if ( constructorName && constructorName !== 'Object' ) return constructorName
293307
294308 try {
@@ -770,11 +784,11 @@ export function createWorkspaceScopedEventClient(
770784 from : options ?. from ?? 'now' ,
771785 transport : baseUrl ? 'websocket' : 'polling'
772786 } )
773- sync = syncFactory ( {
787+ sync = syncFactory ( integrationRelayFileSyncOptions ( {
774788 client,
775789 workspaceId,
776790 baseUrl,
777- token ,
791+ tokenProvider ,
778792 from : options ?. from ?? 'now' ,
779793 paths : relayfilePathFilters ,
780794 onPollingFallback : ( info ) => {
@@ -787,7 +801,7 @@ export function createWorkspaceScopedEventClient(
787801 }
788802 )
789803 }
790- } )
804+ } ) )
791805 sync . on ( 'event' , handleEvent )
792806 sync . on ( 'state' , ( state ) => {
793807 if ( state === 'open' ) consecutiveStreamErrors = 0
0 commit comments