@@ -133,9 +133,15 @@ public struct ClientOptions {
133133
134134struct ApiCacheKey {
135135 let api : ClientOptions . Api
136+ let exclusive : Bool
137+
138+ init ( api: ClientOptions . Api , exclusive: Bool = false ) {
139+ self . api = api
140+ self . exclusive = exclusive
141+ }
136142
137143 var stringValue : String {
138- " \( api. env. url) | \( api. appVersion ?? " nil " ) | \( api. gatewayHost ?? " nil " ) "
144+ " \( api. env. url) | \( api. appVersion ?? " nil " ) | \( api. gatewayHost ?? " nil " ) | \( exclusive ) "
139145 }
140146}
141147
@@ -478,6 +484,59 @@ public final class Client {
478484 return newClient
479485 }
480486
487+ @available( * , deprecated, message: " This function will be removed on d14n cutover. Use connectToApiBackend instead. " )
488+ public static func connectToApiBackendExclusive( api: ClientOptions . Api)
489+ async throws
490+ -> XmtpApiClient
491+ {
492+ let cacheKey = ApiCacheKey ( api: api, exclusive: true ) . stringValue
493+
494+ // Check for an existing connected client
495+ if let cached = await apiCache. getClient ( forKey: cacheKey) ,
496+ try await isConnected ( api: cached)
497+ {
498+ return cached
499+ }
500+
501+ // Either not cached or not connected; create new client
502+ let newClient = try await connectToBackendExclusive (
503+ v3Host: api. env. url,
504+ gatewayHost: api. gatewayHost,
505+ clientMode: FfiClientMode . default,
506+ appVersion: api. appVersion,
507+ authCallback: nil ,
508+ authHandle: nil
509+ )
510+ await apiCache. setClient ( newClient, forKey: cacheKey)
511+ return newClient
512+ }
513+
514+ @available( * , deprecated, message: " This function will be removed on d14n cutover. Use connectToSyncApiBackend instead. " )
515+ public static func connectToSyncApiBackendExclusive( api: ClientOptions . Api)
516+ async throws
517+ -> XmtpApiClient
518+ {
519+ let cacheKey = ApiCacheKey ( api: api, exclusive: true ) . stringValue
520+
521+ // Check for an existing connected client
522+ if let cached = await apiCache. getSyncClient ( forKey: cacheKey) ,
523+ try await isConnected ( api: cached)
524+ {
525+ return cached
526+ }
527+
528+ // Either not cached or not connected; create new client
529+ let newClient = try await connectToBackendExclusive (
530+ v3Host: api. env. url,
531+ gatewayHost: api. gatewayHost,
532+ clientMode: FfiClientMode . default,
533+ appVersion: api. appVersion,
534+ authCallback: nil ,
535+ authHandle: nil
536+ )
537+ await apiCache. setSyncClient ( newClient, forKey: cacheKey)
538+ return newClient
539+ }
481540 public static func getOrCreateInboxId(
482541 api: ClientOptions . Api, publicIdentity: PublicIdentity
483542 ) async throws -> InboxId {
0 commit comments