-
Notifications
You must be signed in to change notification settings - Fork 4
docs: add allowCustomFetcher config flag documentation for TypeScript SDK #2059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,40 @@ groups: | |||||
| noSerdeLayer: false | ||||||
| ``` | ||||||
|
|
||||||
| <ParamField path="allowCustomFetcher" type="boolean" default="false" toc={true}> | ||||||
| When enabled, the generated SDK accepts a `fetcher` parameter in the client options. This allows you to wrap the default fetcher with custom logic, enabling dynamic authentication patterns like JWT signing, OAuth token refresh, or HMAC signing. | ||||||
|
||||||
|
|
||||||
| The custom fetcher acts as middleware for all HTTP requests, giving you a single injection point for authentication logic without overriding individual methods. | ||||||
|
|
||||||
| ```yaml title="generators.yml" | ||||||
| config: | ||||||
| allowCustomFetcher: true | ||||||
| ``` | ||||||
|
|
||||||
| With this enabled, you can provide a custom fetcher when instantiating the client: | ||||||
|
|
||||||
| ```typescript | ||||||
| import { PlantStoreClient } from "plant-store-sdk"; | ||||||
| import { fetcher as defaultFetcher } from "plant-store-sdk/core"; | ||||||
|
|
||||||
| const customFetcher = async (args) => { | ||||||
| // Add custom authentication logic here | ||||||
| const headers = { | ||||||
| ...args.headers, | ||||||
| Authorization: `Bearer ${getToken()}`, | ||||||
| }; | ||||||
| return defaultFetcher({ ...args, headers }); | ||||||
| }; | ||||||
|
|
||||||
| const client = new PlantStoreClient({ | ||||||
| environment: "https://api.plantstore.com", | ||||||
| fetcher: customFetcher, | ||||||
| }); | ||||||
| ``` | ||||||
|
||||||
|
|
||||||
| See [Dynamic authentication](/sdks/generators/typescript/dynamic-authentication) for detailed implementation examples. | ||||||
|
||||||
| See [Dynamic authentication](/sdks/generators/typescript/dynamic-authentication) for detailed implementation examples. | |
| See [Dynamic authentication](/sdks/generators/typescript/dynamic-authentication) for an example of adding authentication middleware with a custom fetcher. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [vale] reported by reviewdog 🐶
[FernStyles.Acronyms] 'HMAC' has no definition.