You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-2Lines changed: 52 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ This is an autogenerated JavaScript SDK for OpenFGA. It provides a wrapper aroun
18
18
-[Getting Started](#getting-started)
19
19
-[Initializing the API Client](#initializing-the-api-client)
20
20
-[Custom Headers](#custom-headers)
21
+
-[Custom HTTP Client](#custom-http-client)
21
22
-[Get your Store ID](#get-your-store-id)
22
23
-[Calling the API](#calling-the-api)
23
24
-[Stores](#stores)
@@ -84,7 +85,7 @@ Using [yarn](https://yarnpkg.com):
84
85
yarn add @openfga/sdk
85
86
```
86
87
87
-
####Supported Node.js Versions
88
+
### Supported Runtimes
88
89
89
90
For details on the supported Node.js versions and our support policy, see [SUPPORTED_RUNTIMES.md](./SUPPORTED_RUNTIMES.md).
90
91
@@ -94,7 +95,7 @@ For details on the supported Node.js versions and our support policy, see [SUPPO
94
95
95
96
[Learn how to initialize your SDK](https://openfga.dev/docs/getting-started/setup-sdk-client)
96
97
97
-
We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be performed on every request.
98
+
We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, and would be particularly costly in the client credentials flow, as that flow will be performed on every request. In Node.js, connection pooling is handled automatically by the runtime's native `fetch` implementation.
98
99
99
100
> The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors.
100
101
@@ -189,6 +190,55 @@ const result = await fgaClient.check({
189
190
});
190
191
```
191
192
193
+
### Custom HTTP Client
194
+
195
+
The SDK uses the native `fetch` API by default. You can provide a custom `HttpClient` to control the underlying HTTP behavior.
196
+
197
+
```javascript
198
+
const { OpenFgaClient } =require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk';
199
+
200
+
constfgaClient=newOpenFgaClient({
201
+
apiUrl:process.env.FGA_API_URL,
202
+
storeId:process.env.FGA_STORE_ID,
203
+
httpClient: {
204
+
fetch:globalThis.fetch.bind(globalThis), // or a custom fetch implementation
205
+
defaultHeaders: {
206
+
"X-Custom-Header":"value",
207
+
},
208
+
defaultTimeout:15000, // timeout in milliseconds (default: 10000)
209
+
},
210
+
});
211
+
```
212
+
213
+
The `HttpClient` interface accepts:
214
+
215
+
| Property | Type | Description |
216
+
| --- | --- | --- |
217
+
|`fetch`|`typeof globalThis.fetch`| The fetch function to use for HTTP requests |
218
+
|`defaultHeaders`|`Record<string, string>`|*(Optional)* Headers to include with every request |
219
+
|`defaultTimeout`|`number`|*(Optional)* Default request timeout in milliseconds |
220
+
221
+
#### Response Type
222
+
223
+
Most SDK methods that are a direct call to the API return an `FgaResponse<T>` on the `$response` property:
224
+
225
+
```typescript
226
+
interfaceFgaResponse<T> {
227
+
status:number;
228
+
statusText:string;
229
+
headers:Record<string, string>;
230
+
data:T;
231
+
}
232
+
```
233
+
234
+
You can access it via the `$response` property on the method's return value:
235
+
236
+
```javascript
237
+
const { headers, status } =awaitfgaClient.getStore().$response;
238
+
```
239
+
240
+
Methods that have custom logic, such as `clientBatchCheck`, `listRelations` and non-transactional `write` operations, will not contain this field.
241
+
192
242
### Get your Store ID
193
243
194
244
You need your store id to call the OpenFGA API (unless it is to call the [CreateStore](#create-store) or [ListStores](#list-stores) methods).
The OpenFGA JavaScript SDK follows the upstream [Node.js release policy](https://nodejs.org/en/about/previous-releases). We support Node.js versions that are currently in **LTS** or **Maintenance** status.
4
6
5
-
### Currently Supported Versions
7
+
####Currently Supported Versions
6
8
7
9
| Node.js Version | Upstream Support Status | Tested in CI/CD Pipelines |
@@ -11,12 +13,16 @@ The OpenFGA JavaScript SDK follows the upstream [Node.js release policy](https:/
11
13
|**24**| LTS | Yes |
12
14
|**25**| Current | Yes |
13
15
14
-
### Support Details
16
+
####Support Details
15
17
16
-
#### Best-Effort Support
18
+
#####Best-Effort Support
17
19
18
20
We will make a best effort to maintain compatibility with Node.js versions that have reached End-of-Life (EOL), but **we will not test** against them in our CI/CD pipelines. This means you may be able to use the JS SDK with older versions of Node.js (with yarn you can use the `--ignore-engines` flag), but you may not be able to run tests (because many of our testing dependencies have dropped support for EOL versions).
19
21
20
-
#### Long-term plan
22
+
#####Long-term plan
21
23
22
24
This best-effort support will not continue indefinitely. We plan to modernize our JS SDK, adopt more functionality now native to the language, and add support for alternate runtimes such as Deno, Cloudflare Workers, and Vercel Edge.
25
+
26
+
### Alternate Runtimes
27
+
28
+
Support for alternate runtimes such as Deno, Cloudflare Workers, and Vercel Edge is being gradually added. We will provide updates on our progress in the future.
0 commit comments