@@ -54,25 +54,14 @@ extension Authenticating {
5454 /// The client uses `@dynamicMemberLookup` to provide direct access to the underlying
5555 /// client's methods and properties, making authenticated requests feel natural.
5656 @dynamicMemberLookup
57- public struct Client <
58- AuthRouter: ParserPrinter & Sendable ,
59- API: Equatable & Sendable ,
60- APIRouter: ParserPrinter & Sendable ,
61- ClientOutput: Sendable
62- > : Sendable
63- where
64- APIRouter. Input == URLRequestData ,
65- APIRouter. Output == API ,
66- AuthRouter. Input == URLRequestData ,
67- AuthRouter. Output == Auth
68- {
57+ public struct Client : Sendable {
6958
7059 private let baseURL : URL
7160 private let auth : Auth
7261
7362 private let router : APIRouter
7463 private let buildClient : @Sendable ( @escaping @Sendable ( API) throws -> URLRequest ) -> ClientOutput
75- private let authenticatedRouter : Authenticating < Auth > . API < API > . Router < AuthRouter , APIRouter >
64+ private let authenticatedRouter : Router
7665
7766 /// Creates a new authenticated client.
7867 ///
@@ -93,7 +82,7 @@ extension Authenticating {
9382 self . auth = auth
9483 self . router = router
9584 self . buildClient = buildClient
96- self . authenticatedRouter = Authenticating . API . Router (
85+ self . authenticatedRouter = Router (
9786 baseURL: baseURL,
9887 authRouter: authRouter,
9988 router: router
@@ -102,15 +91,15 @@ extension Authenticating {
10291
10392 /// Provides dynamic access to the underlying client's properties and methods.
10493 ///
105- /// This subscript automatically wraps all API calls with authentication,
106- /// ensuring that every request includes the necessary authentication headers.
94+ /// This allows you to access closure properties directly on the authenticated client:
10795 ///
108- /// - Parameter keyPath: The key path to a property or method on the underlying client.
109- /// - Returns: The value at the specified key path, with authentication automatically applied.
96+ /// ```swift
97+ /// let response = try await authenticatedClient.send(.getUser(id: "123"))
98+ /// ```
11099 public subscript< T> ( dynamicMember keyPath: KeyPath < ClientOutput , T > ) -> T {
111100 @Sendable
112101 func makeRequest( for api: API ) throws -> URLRequest {
113- let data = try authenticatedRouter. print ( . init ( auth: auth, api: api) )
102+ let data = try authenticatedRouter. print ( Authenticating . API ( auth: auth, api: api) )
114103
115104 guard let request = URLRequest ( data: data) else {
116105 throw Error . requestError
@@ -127,6 +116,37 @@ extension Authenticating {
127116 } [ keyPath: keyPath]
128117 }
129118 }
119+
120+ /// Provides access to the underlying client with all authentication automatically applied.
121+ ///
122+ /// This computed property returns the client instance with authentication headers
123+ /// automatically injected into every request. This allows you to call methods
124+ /// with proper parameter labels:
125+ ///
126+ /// ```swift
127+ /// // With proper method syntax:
128+ /// let response = try await authenticatedClient.client.send(request)
129+ /// ```
130+ public var client : ClientOutput {
131+ @Sendable
132+ func makeRequest( for api: API ) throws -> URLRequest {
133+ let data = try authenticatedRouter. print ( Authenticating . API ( auth: auth, api: api) )
134+
135+ guard let request = URLRequest ( data: data) else {
136+ throw Error . requestError
137+ }
138+
139+ return request
140+ }
141+
142+ return withEscapedDependencies { dependencies in
143+ buildClient { api in
144+ try dependencies. yield {
145+ try makeRequest ( for: api)
146+ }
147+ }
148+ }
149+ }
130150 }
131151}
132152
@@ -143,7 +163,7 @@ public enum Error: Swift.Error {
143163
144164// MARK: - Bearer Authentication Conveniences
145165
146- extension Authenticating . Client {
166+ extension AuthenticatingClient where Auth == BearerAuth {
147167 /// Creates a new client with Bearer token authentication.
148168 ///
149169 /// This convenience initializer is available when using Bearer authentication
@@ -199,7 +219,7 @@ extension Authenticating.Client where APIRouter: TestDependencyKey, APIRouter.Va
199219
200220// MARK: - Basic Authentication Conveniences
201221
202- extension Authenticating . Client {
222+ extension AuthenticatingClient where Auth == BasicAuth {
203223 /// Creates a new client with Basic authentication.
204224 ///
205225 /// This convenience initializer is available when using Basic authentication
0 commit comments