{"id":13626447,"url":"https://github.com/openfga/js-sdk","last_synced_at":"2025-04-16T14:33:36.976Z","repository":{"id":37416756,"uuid":"482956841","full_name":"openfga/js-sdk","owner":"openfga","description":"OpenFGA SDK for node.js and JavaScript - https://www.npmjs.com/package/@openfga/sdk","archived":false,"fork":false,"pushed_at":"2024-04-09T18:36:47.000Z","size":1116,"stargazers_count":37,"open_issues_count":5,"forks_count":8,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-04-14T15:07:36.510Z","etag":null,"topics":["access-control","authorization","fga","fine-grained-authorization","openfga","security","zanzibar"],"latest_commit_sha":null,"homepage":"https://openfga.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openfga.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-04-18T18:38:25.000Z","updated_at":"2024-04-22T06:32:00.931Z","dependencies_parsed_at":"2024-01-01T10:26:13.636Z","dependency_job_id":"89390a77-cb03-49e8-93de-9df455b1129e","html_url":"https://github.com/openfga/js-sdk","commit_stats":{"total_commits":31,"total_committers":4,"mean_commits":7.75,"dds":0.09677419354838712,"last_synced_commit":"6168670835649d6bf7beb04784d53f4d17b1f3ae"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfga%2Fjs-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfga%2Fjs-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfga%2Fjs-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfga%2Fjs-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openfga","download_url":"https://codeload.github.com/openfga/js-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223716521,"owners_count":17191059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["access-control","authorization","fga","fine-grained-authorization","openfga","security","zanzibar"],"created_at":"2024-08-01T21:02:18.971Z","updated_at":"2025-04-16T14:33:36.948Z","avatar_url":"https://github.com/openfga.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# JavaScript and Node.js SDK for OpenFGA\n\n[![npm](https://img.shields.io/npm/v/@openfga/sdk.svg?style=flat)](https://www.npmjs.com/package/@openfga/sdk)\n[![Release](https://img.shields.io/github/v/release/openfga/js-sdk?sort=semver\u0026color=green)](https://github.com/openfga/js-sdk/releases)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenfga%2Fjs-sdk.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenfga%2Fjs-sdk?ref=badge_shield)\n[![Join our community](https://img.shields.io/badge/slack-cncf_%23openfga-40abb8.svg?logo=slack)](https://openfga.dev/community)\n[![Twitter](https://img.shields.io/twitter/follow/openfga?color=%23179CF0\u0026logo=twitter\u0026style=flat-square \"@openfga on Twitter\")](https://twitter.com/openfga)\n\nThis is an autogenerated JavaScript SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api), and includes TS typings.\n\n## Table of Contents\n\n- [About OpenFGA](#about)\n- [Resources](#resources)\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n  - [Initializing the API Client](#initializing-the-api-client)\n  - [Get your Store ID](#get-your-store-id)\n  - [Calling the API](#calling-the-api)\n    - [Stores](#stores)\n      - [List All Stores](#list-stores)\n      - [Create a Store](#create-store)\n      - [Get a Store](#get-store)\n      - [Delete a Store](#delete-store)\n    - [Authorization Models](#authorization-models)\n      - [Read Authorization Models](#read-authorization-models)\n      - [Write Authorization Model](#write-authorization-model)\n      - [Read a Single Authorization Model](#read-a-single-authorization-model)\n      - [Read the Latest Authorization Model](#read-the-latest-authorization-model)\n    - [Relationship Tuples](#relationship-tuples)\n      - [Read Relationship Tuple Changes (Watch)](#read-relationship-tuple-changes-watch)\n      - [Read Relationship Tuples](#read-relationship-tuples)\n      - [Write (Create and Delete) Relationship Tuples](#write-create-and-delete-relationship-tuples)\n    - [Relationship Queries](#relationship-queries)\n      - [Check](#check)\n      - [Batch Check](#batch-check)\n      - [Expand](#expand)\n      - [List Objects](#list-objects)\n      - [List Relations](#list-relations)\n      - [List Users](#list-users)\n    - [Assertions](#assertions)\n      - [Read Assertions](#read-assertions)\n      - [Write Assertions](#write-assertions)\n  - [Retries](#retries)\n  - [API Endpoints](#api-endpoints)\n  - [Models](#models)\n  - [OpenTelemetry](#opentelemetry)\n- [Contributing](#contributing)\n  - [Issues](#issues)\n  - [Pull Requests](#pull-requests)\n- [License](#license)\n\n## About\n\n[OpenFGA](https://openfga.dev) is an open source Fine-Grained Authorization solution inspired by [Google's Zanzibar paper](https://research.google/pubs/pub48190/). It was created by the FGA team at [Auth0](https://auth0.com) based on [Auth0 Fine-Grained Authorization (FGA)](https://fga.dev), available under [a permissive license (Apache-2)](https://github.com/openfga/rfcs/blob/main/LICENSE) and welcomes community contributions.\n\nOpenFGA is designed to make it easy for application builders to model their permission layer, and to add and integrate fine-grained authorization into their applications. OpenFGA’s design is optimized for reliability and low latency at a high scale.\n\n\n## Resources\n\n- [OpenFGA Documentation](https://openfga.dev/docs)\n- [OpenFGA API Documentation](https://openfga.dev/api/service)\n- [Twitter](https://twitter.com/openfga)\n- [OpenFGA Community](https://openfga.dev/community)\n- [Zanzibar Academy](https://zanzibar.academy)\n- [Google's Zanzibar Paper (2019)](https://research.google/pubs/pub48190/)\n\n## Installation\n\nUsing [npm](https://npmjs.org):\n\n```shell\nnpm install @openfga/sdk\n```\n\nUsing [yarn](https://yarnpkg.com):\n\n```shell\nyarn add @openfga/sdk\n```\n\n## Getting Started\n\n### Initializing the API Client\n\n[Learn how to initialize your SDK](https://openfga.dev/docs/getting-started/setup-sdk-client)\n\nWe 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.\n\n\u003e The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors.\n\n#### No Credentials\n\n```javascript\nconst { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk';\n\nconst fgaClient = new OpenFgaClient({\n  apiUrl: process.env.FGA_API_URL, // required\n  storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`\n  authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request\n});\n```\n\n#### API Token\n\n```javascript\nconst { OpenFgaClient, CredentialsMethod } = require('@openfga/sdk'); // OR import { OpenFgaClient, CredentialsMethod } from '@openfga/sdk';\n\nconst fgaClient = new OpenFgaClient({\n  apiUrl: process.env.FGA_API_URL, // required\n  storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`\n  authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request\n  credentials: {\n    method: CredentialsMethod.ApiToken,\n    config: {\n      token: process.env.FGA_API_TOKEN, // will be passed as the \"Authorization: Bearer ${ApiToken}\" request header\n    }\n  }\n});\n```\n\n#### Client Credentials\n\n```javascript\nconst { OpenFgaClient, CredentialsMethod } = require('@openfga/sdk'); // OR import { OpenFgaClient, CredentialsMethod } from '@openfga/sdk';\n\nconst fgaClient = new OpenFgaClient({\n  apiUrl: process.env.FGA_API_URL, // required\n  storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`\n  authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request\n  credentials: {\n    method: CredentialsMethod.ClientCredentials,\n    config: {\n      apiTokenIssuer: process.env.FGA_API_TOKEN_ISSUER,\n      apiAudience: process.env.FGA_API_AUDIENCE,\n      clientId: process.env.FGA_CLIENT_ID,\n      clientSecret: process.env.FGA_CLIENT_SECRET,\n    }\n  }\n});\n```\n\n\n### Get your Store ID\n\nYou need your store id to call the OpenFGA API (unless it is to call the [CreateStore](#create-store) or [ListStores](#list-stores) methods).\n\nIf your server is configured with [authentication enabled](https://openfga.dev/docs/getting-started/setup-openfga#configuring-authentication), you also need to have your credentials ready.\n\n### Calling the API\n\n\u003e Note regarding casing in the OpenFgaClient:\n\u003e All input parameters are in `camelCase`, all response parameters will match the API and are in `snake_case`.\n\n\u003e Note: The Client interface might see several changes over the next few months as we get more feedback before it stabilizes.\n\n#### Stores\n\n##### List Stores\n\nGet a paginated list of stores.\n\n[API Documentation](https://openfga.dev/api/service#/Stores/ListStores)\n\n```javascript\nconst options = { pageSize: 10, continuationToken: \"...\" };\n\nconst { stores } = await fgaClient.listStores(options);\n\n// stores = [{ \"id\": \"01FQH7V8BEG3GPQW93KTRFR8JB\", \"name\": \"FGA Demo Store\", \"created_at\": \"2022-01-01T00:00:00.000Z\", \"updated_at\": \"2022-01-01T00:00:00.000Z\" }]\n```\n\n##### Create Store\n\nInitialize a store.\n\n[API Documentation](https://openfga.dev/api/service#/Stores/CreateStore)\n\n```javascript\nconst { id: storeId } = await fgaClient.createStore({\n  name: \"FGA Demo Store\",\n});\n\n// storeId = \"01FQH7V8BEG3GPQW93KTRFR8JB\"\n```\n\n##### Get Store\n\nGet information about the current store.\n\n[API Documentation](https://openfga.dev/api/service#/Stores/GetStore)\n\n```javascript\nconst store = await fgaClient.getStore();\n\n// store = { \"id\": \"01FQH7V8BEG3GPQW93KTRFR8JB\", \"name\": \"FGA Demo Store\", \"created_at\": \"2022-01-01T00:00:00.000Z\", \"updated_at\": \"2022-01-01T00:00:00.000Z\" }\n```\n\n##### Delete Store\n\nDelete a store.\n\n[API Documentation](https://openfga.dev/api/service#/Stores/DeleteStore)\n\n```javascript\nawait fgaClient.deleteStore();\n```\n\n#### Authorization Models\n\n##### Read Authorization Models\n\nRead all authorization models in the store.\n\n[API Documentation](https://openfga.dev/api/service#/Authorization%20Models/ReadAuthorizationModels)\n\n\u003e  Requires a client initialized with a storeId\n\n```javascript\nconst options = { pageSize: 10, continuationToken: \"...\" };\n\nconst { authorization_models: authorizationModels } = await fgaClient.readAuthorizationModels(options);\n\n/*\nauthorizationModels = [\n { id: \"01GXSA8YR785C4FYS3C0RTG7B1\", schema_version: \"1.1\", type_definitions: [...] },\n { id: \"01GXSBM5PVYHCJNRNKXMB4QZTW\", schema_version: \"1.1\", type_definitions: [...] }];\n*/\n```\n\n##### Write Authorization Model\n\nCreate a new authorization model.\n\n[API Documentation](https://openfga.dev/api/service#/Authorization%20Models/WriteAuthorizationModel)\n\n\u003e Note: To learn how to build your authorization model, check the Docs at https://openfga.dev/docs.\n\n\u003e Learn more about [the OpenFGA configuration language](https://openfga.dev/docs/configuration-language).\n\n\u003e You can use the [OpenFGA Syntax Transformer](https://github.com/openfga/syntax-transformer) to convert between the friendly DSL and the JSON authorization model.\n\n```javascript\nconst { authorization_model_id: id } = await fgaClient.writeAuthorizationModel({\n  schema_version: \"1.1\",\n  type_definitions: [{\n      type: \"user\",\n    }, {\n    type: \"document\",\n    relations: {\n      \"writer\": { \"this\": {} },\n      \"viewer\": {\n        \"union\": {\n          \"child\": [\n            { \"this\": {} },\n            { \"computedUserset\": {\n               \"object\": \"\",\n              \"relation\": \"writer\" }\n            }\n          ]\n        }\n      }\n    } }],\n});\n\n// id = \"01GXSA8YR785C4FYS3C0RTG7B1\"\n```\n\n##### Read a Single Authorization Model\n\nRead a particular authorization model.\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nconst { authorization_model: authorizationModel } = await fgaClient.readAuthorizationModel(options);\n\n// authorizationModel = { id: \"01GXSA8YR785C4FYS3C0RTG7B1\", schema_version: \"1.1\", type_definitions: [...] }\n```\n\n##### Read the Latest Authorization Model\n\nReads the latest authorization model (note: this ignores the model id in configuration).\n\n[API Documentation](https://openfga.dev/api/service#/Authorization%20Models/ReadAuthorizationModel)\n\n```javascript\nconst { authorization_model: authorizationModel } = await fgaClient.readLatestAuthorizationModel();\n\n// authorizationModel = { id: \"01GXSA8YR785C4FYS3C0RTG7B1\", schema_version: \"1.1\", type_definitions: [...] }\n```\n\n#### Relationship Tuples\n\n##### Read Relationship Tuple Changes (Watch)\n\nReads the list of historical relationship tuple writes and deletes.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/ReadChanges)\n\n```javascript\nconst type = 'document';\nconst startTime = \"2022-01-01T00:00:00Z\"\nconst options = {\n  pageSize: 25,\n  continuationToken: 'eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==',\n};\n\nconst response = await fgaClient.readChanges({ type, startTime }, options);\n\n// response.continuation_token = ...\n// response.changes = [\n//   { tuple_key: { user, relation, object }, operation: \"writer\", timestamp: ... },\n//   { tuple_key: { user, relation, object }, operation: \"viewer\", timestamp: ... }\n// ]\n```\n\n##### Read Relationship Tuples\n\nReads the relationship tuples stored in the database. It does not evaluate nor exclude invalid tuples according to the authorization model.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/Read)\n\n```javascript\n// Find if a relationship tuple stating that a certain user is a viewer of a certain document\nconst body = {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n};\n\n// Find all relationship tuples where a certain user has any relation to a certain document\nconst body = {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n};\n\n// Find all relationship tuples where a certain user is a viewer of any document\nconst body = {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:\",\n};\n\n// Find all relationship tuples where a certain user has any relation with any document\nconst body = {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  object: \"document:\",\n};\n\n// Find all relationship tuples where any user has any relation with a particular document\nconst body = {\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n};\n\n// Read all stored relationship tuples\nconst body = {};\n\nconst { tuples } = await fgaClient.read(body);\n\n// In all the above situations, the response will be of the form:\n// tuples = [{ key: { user, relation, object }, timestamp: ... }]\n```\n\n##### Write (Create and Delete) Relationship Tuples\n\nCreate and/or delete relationship tuples to update the system state.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/Write)\n\n###### Transaction mode (default)\n\nBy default, write runs in a transaction mode where any invalid operation (deleting a non-existing tuple, creating an existing tuple, one of the tuples was invalid) or a server error will fail the entire operation.\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nawait fgaClient.write({\n  writes: [{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"viewer\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }],\n  deletes: [{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"editor\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }],\n}, options);\n\n// Convenience functions are available\nawait fgaClient.writeTuples([{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"viewer\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }], options);\nawait fgaClient.deleteTuples([{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"editor\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }], options);\n\n// if any error is encountered in the transaction mode, an error will be thrown\n```\n\n###### Non-transaction mode\n\nThe SDK will split the writes into separate requests and send them in parallel chunks (default = 1 item per chunk, each chunk is a transaction).\n\n```\n// if you'd like to disable the transaction mode for writes (requests will be sent in parallel writes)\noptions.transaction = {\n  disable: true,\n  maxPerChunk: 1, // defaults to 1 - each chunk is a transaction (even in non-transaction mode)\n  maxParallelRequests: 10, // max requests to issue in parallel\n};\n\nconst response = await fgaClient.write({\n  writes: [{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"viewer\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }],\n  deletes: [{ user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"editor\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\" }],\n}, options);\n\n/*\nresponse = {\n  writes: [{ tuple_key: { user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"viewer\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\", status: \"success\" } }],\n  deletes: [{ tuple_key: { user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", relation: \"editor\", object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\", status: \"failure\", err: \u003cFgaError ...\u003e  } }],\n};\n*/\n```\n\n#### Relationship Queries\n\n##### Check\n\nCheck if a user has a particular relation with an object.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/Check)\n\n```javascript\nconst options = {\n  // if you'd like to override the authorization model id for this request\n  authorizationModelId: \"01GXSA8YR785C4FYS3C0RTG7B1\",\n};\n\nconst result = await fgaClient.check({\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n}, options);\n\n// result = { allowed: true }\n```\n\n##### Batch Check\n\nSimilar to [check](#check), but instead of checking a single user-object relationship, accepts a list of relationships to check. Requires OpenFGA version 1.8.0 or greater.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/BatchCheck)\n\n```javascript\nconst options = {\n  // if you'd like to override the authorization model id for this request\n  authorizationModelId: \"01GXSA8YR785C4FYS3C0RTG7B1\",\n}\n\nconst corrId = randomUUID();\nconst { result } = await fgaClient.batchCheck({\n    checks: [\n      {\n        // should have access\n        user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n        relation: \"viewer\",\n        object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n        context: {\n          ViewCount: 100\n        },\n        // optional correliationId to associate request and response. One will be generated\n        // if not provided\n        correlationId: corrId,\n      },\n      {\n        // should NOT have access\n        user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n        relation: \"viewer\",\n        object: \"document:7772ab2a-d83f-756d-9397-c5ed9f3cb888\",\n      }\n    ]\n  }, options);\n\n  const userAllowed = result.filter(r =\u003e r.correlationId === corrId);\n  console.log(`User is allowed access to ${userAllowed.length} documents`);\n  userAllowed.forEach(item =\u003e {\n    console.log(`User is allowed access to ${item.request.object}`);\n  });\n  /*\n  {\n    \"result\": [\n      {\n        \"allowed\": true,\n        \"request\": {\n          \"user\": \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n          \"relation\": \"viewer\",\n          \"object\": \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n          \"correlationId\": \"4187674b-0ec0-4ed5-abb5-327bd21c89a3\"\n        },\n        \"correlationId\": \"4187674b-0ec0-4ed5-abb5-327bd21c89a3\"\n      },\n      {\n        \"allowed\": true,\n        \"request\": {\n          \"user\": \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n          \"relation\": \"viewer\",\n          \"object\": \"document:7772ab2a-d83f-756d-9397-c5ed9f3cb888\",\n          \"context\": {\n            \"ViewCount\": 100\n          },\n          \"correlationId\": \"5874b4fb-10f1-4e0c-ae32-559220b06dc8\"\n        },\n        \"correlationId\": \"5874b4fb-10f1-4e0c-ae32-559220b06dc8\"\n      }\n    ]\n  }\n  */\n```\n\nIf you are using an OpenFGA version less than 1.8.0, you can use the `clientBatchCheck` function, \nwhich calls `check` in parallel. It will return `allowed: false` if it encounters an error, and will return the error in the body.\nIf 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.\n\n```javascript\nconst { responses } = await fgaClient.clientBatchCheck([{\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5\",\n}, {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"member\",\n  object: \"document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5\",\n}, {\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n  contextualTuples: [{\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"writer\",\n    object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\"\n  }],\n}], options);\n\n/*\nresult = [{\n  allowed: false,\n  _request: {\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"viewer\",\n    object: \"document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5\",\n  }\n}, {\n  allowed: false,\n  _request: {\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"member\",\n    object: \"document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5\",\n  },\n  err: \u003cFgaError ...\u003e\n}, {\n  allowed: true,\n  _request: {\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"viewer\",\n    object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n    contextualTuples: [{\n      user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n      relation: \"writer\",\n      object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\"\n    }],\n  }},\n]\n*/\n```\n\n#### Expand\n\nExpands the relationships in userset tree format.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/Expand)\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nconst { tree } = await fgaClient.expand({\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n}, options);\n\n// tree  = { root: { name: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a#viewer\", leaf: { users: { users: [\"user:81684243-9356-4421-8fbf-a4f8d36aa31b\", \"user:f52a4f7a-054d-47ff-bb6e-3ac81269988f\"] } } } }\n```\n\n##### List Objects\n\n List the objects of a particular type that the user has a certain relation to.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListObjects)\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nconst response = await fgaClient.listObjects({\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  type: \"document\",\n  contextualTuples: [{\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"writer\",\n    object: \"document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5\"\n  }],\n}, options);\n\n// response.objects = [\"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\"]\n```\n\n##### List Relations\n\nList the relations a user has with an object. This wraps around [BatchCheck](#batchcheck) to allow checking multiple relationships at once.\n\nNote: Any error encountered when checking any relation will be treated as `allowed: false`;\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorization_model_id = \"1uHxCSuTP0VKPYSnkq1pbb1jeZw\";\n\nconst response = await fgaClient.listRelations({\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n  relations: [\"can_view\", \"can_edit\", \"can_delete\"],\n  contextualTuples: [{\n    user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n    relation: \"writer\",\n    object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\"\n  }],\n}, options);\n\n// response.relations = [\"can_view\", \"can_edit\"]\n```\n\n##### List Users\n\nList the users who have a certain relation to a particular type.\n\n[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListUsers)\n\n```js\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorization_model_id = \"1uHxCSuTP0VKPYSnkq1pbb1jeZw\";\n\n// Only a single filter is allowed for the time being\nconst userFilters = [{type: \"user\"}];\n// user filters can also be of the form\n// const userFilters = [{type: \"team\", relation: \"member\"}];\n\nconst response = await fgaClient.listUsers({\n  object: {\n    type: \"document\",\n    id: \"roadmap\"\n  },\n  relation: \"can_read\",\n  user_filters: userFilters,\n  context: {\n    \"view_count\": 100\n  },\n  contextualTuples:\n    [{\n      user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n      relation: \"editor\",\n      object: \"folder:product\"\n    }, {\n      user: \"folder:product\",\n      relation: \"parent\",\n      object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\"\n    }]\n}, options);\n\n// response.users = [{object: {type: \"user\", id: \"81684243-9356-4421-8fbf-a4f8d36aa31b\"}}, {userset: { type: \"user\" }}, ...]\n```\n\n#### Assertions\n\n##### Read Assertions\n\nRead assertions for a particular authorization model.\n\n[API Documentation](https://openfga.dev/api/service#/Assertions/Read%20Assertions)\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nconst response = await fgaClient.readAssertions(options);\n\n/*\nresponse.assertions = [{\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n  expectation: true,\n}];\n*/\n```\n\n##### Write Assertions\n\nUpdate the assertions for a particular authorization model.\n\n[API Documentation](https://openfga.dev/api/service#/Assertions/Write%20Assertions)\n\n```javascript\nconst options = {};\n\n// To override the authorization model id for this request\noptions.authorizationModelId = \"01GXSA8YR785C4FYS3C0RTG7B1\";\n\nconst response = await fgaClient.writeAssertions([{\n  user: \"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\n  relation: \"viewer\",\n  object: \"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a\",\n  expectation: true,\n}], options);\n```\n\n\n### Retries\n\nIf a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 3 times with a minimum wait time of 100 milliseconds between each attempt.\n\nTo customize this behavior, create an object with `maxRetry` and `minWaitInMs` properties. `maxRetry` determines the maximum number of retries (up to 15), while `minWaitInMs` sets the minimum wait time between retries in milliseconds.\n\nApply your custom retry values by setting to `retryParams` on the configuration object passed to the `OpenFgaClient` call.\n\n```javascript\nconst { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk';\n\nconst fgaClient = new OpenFgaClient({\n  apiUrl: process.env.FGA_API_URL, // required\n  storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`\n  authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request\n  retryParams: {\n    maxRetry: 3, // retry up to 3 times on API requests\n    minWaitInMs: 250 // wait a minimum of 250 milliseconds between requests\n  }\n});\n```\n\n### API Endpoints\n\n| Method | HTTP request | Description |\n| ------------- | ------------- | ------------- |\n| [**ListStores**](https://openfga.dev/api/service#/Stores/ListStores) | **GET** /stores | List all stores |\n| [**CreateStore**](https://openfga.dev/api/service#/Stores/CreateStore) | **POST** /stores | Create a store |\n| [**GetStore**](https://openfga.dev/api/service#/Stores/GetStore) | **GET** /stores/{store_id} | Get a store |\n| [**DeleteStore**](https://openfga.dev/api/service#/Stores/DeleteStore) | **DELETE** /stores/{store_id} | Delete a store |\n| [**ReadAuthorizationModels**](https://openfga.dev/api/service#/Authorization%20Models/ReadAuthorizationModels) | **GET** /stores/{store_id}/authorization-models | Return all the authorization models for a particular store |\n| [**WriteAuthorizationModel**](https://openfga.dev/api/service#/Authorization%20Models/WriteAuthorizationModel) | **POST** /stores/{store_id}/authorization-models | Create a new authorization model |\n| [**ReadAuthorizationModel**](https://openfga.dev/api/service#/Authorization%20Models/ReadAuthorizationModel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model |\n| [**ReadChanges**](https://openfga.dev/api/service#/Relationship%20Tuples/ReadChanges) | **GET** /stores/{store_id}/changes | Return a list of all the tuple changes |\n| [**Read**](https://openfga.dev/api/service#/Relationship%20Tuples/Read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules |\n| [**Write**](https://openfga.dev/api/service#/Relationship%20Tuples/Write) | **POST** /stores/{store_id}/write | Add or delete tuples from the store |\n| [**Check**](https://openfga.dev/api/service#/Relationship%20Queries/Check) | **POST** /stores/{store_id}/check | Check whether a user is authorized to access an object |\n| [**BatchCheck**](https://openfga.dev/api/service#/Relationship%20Queries/BatchCheck) | **POST** /stores/{store_id}/batch-check | Similar to check, but accepts a list of relations to check |\n| [**Expand**](https://openfga.dev/api/service#/Relationship%20Queries/Expand) | **POST** /stores/{store_id}/expand | Expand all relationships in userset tree format, and following userset rewrite rules.  Useful to reason about and debug a certain relationship |\n| [**ListObjects**](https://openfga.dev/api/service#/Relationship%20Queries/ListObjects) | **POST** /stores/{store_id}/list-objects | [EXPERIMENTAL] Get all objects of the given type that the user has a relation with |\n| [**ReadAssertions**](https://openfga.dev/api/service#/Assertions/ReadAssertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID |\n| [**WriteAssertions**](https://openfga.dev/api/service#/Assertions/WriteAssertions) | **PUT** /stores/{store_id}/assertions/{authorization_model_id} | Upsert assertions for an authorization model ID |\n\n\n### Models\n\n[Models](https://github.com/openfga/js-sdk/blob/main/apiModel.ts)\n\n\n### OpenTelemetry\n\nThis SDK supports producing metrics that can be consumed as part of an [OpenTelemetry](https://opentelemetry.io/) setup. For more information, please see [the documentation](https://github.com/openfga/js-sdk/blob/main/docs/opentelemetry.md)\n\n## Contributing\n\n### Issues\n\nIf you have found a bug or if you have a feature request, please report them on the [sdk-generator repo](https://github.com/openfga/sdk-generator/issues) issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.\n\n### Pull Requests\n\nWhile we accept Pull Requests on this repository, the SDKs are autogenerated so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well. \n\n## Author\n\n[OpenFGA](https://github.com/openfga)\n\n## License\n\nThis project is licensed under the Apache-2.0 license. See the [LICENSE](https://github.com/openfga/js-sdk/blob/main/LICENSE) file for more info.\n\nThe code in this repo was auto generated by [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) from a template based on the [typescript-axios template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript-axios) and [go template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/go), licensed under the [Apache License 2.0](https://github.com/OpenAPITools/openapi-generator/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfga%2Fjs-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenfga%2Fjs-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfga%2Fjs-sdk/lists"}