Skip to content

Commit fd3ec20

Browse files
docs: update wrapper client to accept all FernClient options
- Use ConstructorParameters to infer exact options type from generated client - Accept all client options (headers, timeout, maxRetries, etc.) except fetcher - Extract privateKey and pass remaining options to parent constructor - Add explanatory note about ConstructorParameters pattern - Update both custom fetcher and method override examples for consistency Addresses Swimburger's feedback about dynamically passing all options. Co-Authored-By: Chris McDonnell <[email protected]>
1 parent 4bf04e2 commit fd3ec20

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

fern/products/sdks/guides/dynamic-authentication.mdx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,27 @@ Extend the generated client to use the custom fetcher:
8282
import { PlantStoreClient as FernClient } from "../Client";
8383
import { createJwtFetcher } from "./jwtFetcher";
8484

85+
// Infer the exact options type from the generated client's constructor
86+
type FernClientOptions = ConstructorParameters<typeof FernClient>[0];
87+
// Accept all options except 'fetcher', and add our 'privateKey'
88+
type Options = Omit<FernClientOptions, "fetcher"> & { privateKey: string };
89+
8590
export class PlantStoreClient extends FernClient {
86-
constructor(options: { privateKey: string; environment: string }) {
91+
constructor(options: Options) {
92+
// Extract privateKey and pass all other options to the parent
93+
const { privateKey, ...clientOptions } = options;
8794
super({
88-
environment: options.environment,
89-
fetcher: createJwtFetcher(options.privateKey),
95+
...clientOptions,
96+
fetcher: createJwtFetcher(privateKey),
9097
});
9198
}
9299
}
93100
```
94101

102+
<Note>
103+
This pattern uses `ConstructorParameters` to infer the exact options type from the generated client, ensuring compatibility with all client options (headers, timeoutInSeconds, maxRetries, etc.) without hardcoding them. This keeps the wrapper future-proof as the generator adds new options.
104+
</Note>
105+
95106
### Export the wrapper client
96107

97108
Update your `index.ts` to export the wrapper instead of the generated client:
@@ -140,14 +151,16 @@ If you cannot enable `allowCustomFetcher` or prefer a simpler approach, you can
140151
import { PlantStoreClient as FernClient } from "../Client";
141152
import * as jwt from "jsonwebtoken";
142153

154+
type FernClientOptions = ConstructorParameters<typeof FernClient>[0];
155+
type Options = Omit<FernClientOptions, "fetcher"> & { privateKey: string };
156+
143157
export class PlantStoreClient extends FernClient {
144158
private privateKey: string;
145159

146-
constructor(options: { privateKey: string; environment: string }) {
147-
super({
148-
environment: options.environment,
149-
});
150-
this.privateKey = options.privateKey;
160+
constructor(options: Options) {
161+
const { privateKey, ...clientOptions } = options;
162+
super(clientOptions);
163+
this.privateKey = privateKey;
151164
}
152165

153166
private generateJWT(): string {

0 commit comments

Comments
 (0)