Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openfga/sdk

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openfga/sdk - npm Package Compare versions

Comparing version 0.3.5 to 0.4.0

11

CHANGELOG.md
# Changelog
## v0.4.0
### [0.4.0](https://github.com/openfga/js-sdk/compare/v0.3.5...v0.4.0) (2024-04-30)
- feat: support the [ListUsers](https://github.com/openfga/rfcs/blob/main/20231214-listUsers-api.md) endpoint (#97)
- feat!: support overriding storeId per request (#97)
`OpenFgaClient` now supports specifying the storeId in the options to override it per request
[BREAKING CHANGE] the underlying `OpenFgaApi` now expects `storeId` as the first param on relevant methods,
if you are still using this class, make sure you update your references when needed.
## v0.3.5

@@ -4,0 +15,0 @@

@@ -470,2 +470,21 @@ /**

/**
* Object represents an OpenFGA Object. An Object is composed of a type and identifier (e.g. \'document:1\') See https://openfga.dev/docs/concepts#what-is-an-object
* @export
* @interface FgaObject
*/
export interface FgaObject {
/**
*
* @type {string}
* @memberof FgaObject
*/
type: string;
/**
*
* @type {string}
* @memberof FgaObject
*/
id: string;
}
/**
*

@@ -647,2 +666,64 @@ * @export

* @export
* @interface ListUsersRequest
*/
export interface ListUsersRequest {
/**
*
* @type {string}
* @memberof ListUsersRequest
*/
authorization_model_id?: string;
/**
*
* @type {FgaObject}
* @memberof ListUsersRequest
*/
object: FgaObject;
/**
*
* @type {string}
* @memberof ListUsersRequest
*/
relation: string;
/**
*
* @type {Array<UserTypeFilter>}
* @memberof ListUsersRequest
*/
user_filters: Array<UserTypeFilter>;
/**
*
* @type {Array<TupleKey>}
* @memberof ListUsersRequest
*/
contextual_tuples?: Array<TupleKey>;
/**
* Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation.
* @type {object}
* @memberof ListUsersRequest
*/
context?: object;
}
/**
*
* @export
* @interface ListUsersResponse
*/
export interface ListUsersResponse {
/**
*
* @type {Array<User>}
* @memberof ListUsersResponse
*/
users: Array<User>;
/**
*
* @type {Array<ObjectOrUserset>}
* @memberof ListUsersResponse
*/
excluded_users: Array<ObjectOrUserset>;
}
/**
*
* @export
* @interface Metadata

@@ -744,2 +825,21 @@ */

* @export
* @interface ObjectOrUserset
*/
export interface ObjectOrUserset {
/**
*
* @type {FgaObject}
* @memberof ObjectOrUserset
*/
object?: FgaObject;
/**
*
* @type {UsersetUser}
* @memberof ObjectOrUserset
*/
userset?: UsersetUser;
}
/**
*
* @export
* @interface ObjectRelation

@@ -1246,2 +1346,87 @@ */

* @export
* @interface TypedWildcard
*/
export interface TypedWildcard {
/**
*
* @type {string}
* @memberof TypedWildcard
*/
type: string;
}
/**
*
* @export
* @enum {string}
*/
export declare enum UnprocessableContentErrorCode {
NoThrottledErrorCode = "no_throttled_error_code",
ThrottledTimeoutError = "throttled_timeout_error"
}
/**
*
* @export
* @interface UnprocessableContentMessageResponse
*/
export interface UnprocessableContentMessageResponse {
/**
*
* @type {UnprocessableContentErrorCode}
* @memberof UnprocessableContentMessageResponse
*/
code?: UnprocessableContentErrorCode;
/**
*
* @type {string}
* @memberof UnprocessableContentMessageResponse
*/
message?: string;
}
/**
*
* @export
* @interface User
*/
export interface User {
/**
*
* @type {FgaObject}
* @memberof User
*/
object?: FgaObject;
/**
*
* @type {UsersetUser}
* @memberof User
*/
userset?: UsersetUser;
/**
*
* @type {TypedWildcard}
* @memberof User
*/
wildcard?: TypedWildcard;
}
/**
*
* @export
* @interface UserTypeFilter
*/
export interface UserTypeFilter {
/**
*
* @type {string}
* @memberof UserTypeFilter
*/
type: string;
/**
*
* @type {string}
* @memberof UserTypeFilter
*/
relation?: string;
}
/**
*
* @export
* @interface Users

@@ -1354,2 +1539,27 @@ */

* @export
* @interface UsersetUser
*/
export interface UsersetUser {
/**
*
* @type {string}
* @memberof UsersetUser
*/
type: string;
/**
*
* @type {string}
* @memberof UsersetUser
*/
id: string;
/**
*
* @type {string}
* @memberof UsersetUser
*/
relation: string;
}
/**
*
* @export
* @interface Usersets

@@ -1356,0 +1566,0 @@ */

12

dist/apiModel.js

@@ -16,3 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeName = exports.TupleOperation = exports.NullValue = exports.NotFoundErrorCode = exports.InternalErrorCode = exports.ErrorCode = void 0;
exports.UnprocessableContentErrorCode = exports.TypeName = exports.TupleOperation = exports.NullValue = exports.NotFoundErrorCode = exports.InternalErrorCode = exports.ErrorCode = void 0;
/**

@@ -144,1 +144,11 @@ *

})(TypeName || (exports.TypeName = TypeName = {}));
/**
*
* @export
* @enum {string}
*/
var UnprocessableContentErrorCode;
(function (UnprocessableContentErrorCode) {
UnprocessableContentErrorCode["NoThrottledErrorCode"] = "no_throttled_error_code";
UnprocessableContentErrorCode["ThrottledTimeoutError"] = "throttled_timeout_error";
})(UnprocessableContentErrorCode || (exports.UnprocessableContentErrorCode = UnprocessableContentErrorCode = {}));

2

dist/base.d.ts

@@ -34,4 +34,2 @@ /**

constructor(configuration: UserConfigurationParams | Configuration, axios?: AxiosInstance | undefined);
get storeId(): string;
set storeId(storeId: string);
}

@@ -50,9 +50,3 @@ "use strict";

}
get storeId() {
return this.configuration.storeId;
}
set storeId(storeId) {
this.configuration.storeId = storeId;
}
}
exports.BaseAPI = BaseAPI;

@@ -14,9 +14,28 @@ /**

import { OpenFgaApi } from "./api";
import { Assertion, CheckRequest, CheckRequestTupleKey, CheckResponse, CreateStoreRequest, CreateStoreResponse, ExpandRequestTupleKey, ExpandResponse, GetStoreResponse, ListObjectsRequest, ListObjectsResponse, ListStoresResponse, ReadAssertionsResponse, ReadAuthorizationModelResponse, ReadAuthorizationModelsResponse, ReadChangesResponse, ReadRequestTupleKey, ReadResponse, TupleKey, TupleKeyWithoutCondition, WriteAuthorizationModelRequest, WriteAuthorizationModelResponse } from "./apiModel";
import { Assertion, CheckRequest, CheckRequestTupleKey, CheckResponse, CreateStoreRequest, CreateStoreResponse, ExpandRequestTupleKey, ExpandResponse, GetStoreResponse, ListObjectsRequest, ListObjectsResponse, ListStoresResponse, ListUsersRequest, ListUsersResponse, ReadAssertionsResponse, ReadAuthorizationModelResponse, ReadAuthorizationModelsResponse, ReadChangesResponse, ReadRequestTupleKey, ReadResponse, TupleKey, TupleKeyWithoutCondition, WriteAuthorizationModelRequest, WriteAuthorizationModelResponse } from "./apiModel";
import { BaseAPI } from "./base";
import { PromiseResult } from "./common";
import { Configuration, RetryParams, UserConfigurationParams } from "./configuration";
export type ClientConfiguration = (UserConfigurationParams | Configuration) & {
export type UserClientConfigurationParams = UserConfigurationParams & {
storeId?: string;
authorizationModelId?: string;
};
export declare class ClientConfiguration extends Configuration {
/**
* provide storeId
*
* @type {string}
* @memberof ClientConfiguration
*/
storeId?: string;
/**
* provide authorizationModelId
*
* @type {string}
* @memberof ClientConfiguration
*/
authorizationModelId?: string;
constructor(params?: UserClientConfigurationParams);
isValid(): boolean;
}
export interface ClientRequestOpts {

@@ -26,6 +45,10 @@ retryParams?: RetryParams;

}
export interface StoreIdOpts {
storeId?: string;
}
export interface AuthorizationModelIdOpts {
authorizationModelId?: string;
}
export type ClientRequestOptsWithAuthZModelId = ClientRequestOpts & AuthorizationModelIdOpts;
export type ClientRequestOptsWithStoreId = ClientRequestOpts & StoreIdOpts;
export type ClientRequestOptsWithAuthZModelId = ClientRequestOpts & StoreIdOpts & AuthorizationModelIdOpts;
export type PaginationOptions = {

@@ -89,2 +112,5 @@ pageSize?: number;

};
export type ClientListUsersRequest = Omit<ListUsersRequest, "authorization_model_id" | "contextual_tuples"> & {
contextualTuples?: Array<TupleKey>;
};
export type ClientListRelationsRequest = Omit<ClientCheckRequest, "relation"> & {

@@ -98,3 +124,6 @@ relations?: string[];

authorizationModelId?: string;
constructor(configuration: ClientConfiguration, axios?: AxiosInstance | undefined);
storeId?: string;
protected configuration: ClientConfiguration;
constructor(configuration: ClientConfiguration | UserClientConfigurationParams, axios?: AxiosInstance | undefined);
protected getStoreId(options?: StoreIdOpts, isOptional?: boolean): string | undefined;
protected getAuthorizationModelId(options?: AuthorizationModelIdOpts): string | undefined;

@@ -141,3 +170,3 @@ /**

* GetStore - Get information about the current store
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -148,6 +177,6 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

*/
getStore(options?: ClientRequestOpts): PromiseResult<GetStoreResponse>;
getStore(options?: ClientRequestOptsWithStoreId): PromiseResult<GetStoreResponse>;
/**
* DeleteStore - Delete a store
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -158,3 +187,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

*/
deleteStore(options?: ClientRequestOpts): PromiseResult<void>;
deleteStore(options?: ClientRequestOptsWithStoreId): PromiseResult<void>;
/************************

@@ -173,7 +202,7 @@ * Authorization Models *

*/
readAuthorizationModels(options?: ClientRequestOpts & PaginationOptions): PromiseResult<ReadAuthorizationModelsResponse>;
readAuthorizationModels(options?: ClientRequestOptsWithStoreId & PaginationOptions): PromiseResult<ReadAuthorizationModelsResponse>;
/**
* WriteAuthorizationModel - Create a new version of the authorization model
* @param {WriteAuthorizationModelRequest} body
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -184,3 +213,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

*/
writeAuthorizationModel(body: WriteAuthorizationModelRequest, options?: ClientRequestOpts): PromiseResult<WriteAuthorizationModelResponse>;
writeAuthorizationModel(body: WriteAuthorizationModelRequest, options?: ClientRequestOptsWithStoreId): PromiseResult<WriteAuthorizationModelResponse>;
/**

@@ -219,3 +248,3 @@ * ReadAuthorizationModel - Read the current authorization model

*/
readChanges(body?: ClientReadChangesRequest, options?: ClientRequestOpts & PaginationOptions): PromiseResult<ReadChangesResponse>;
readChanges(body?: ClientReadChangesRequest, options?: ClientRequestOptsWithStoreId & PaginationOptions): PromiseResult<ReadChangesResponse>;
/**

@@ -232,3 +261,3 @@ * Read - Read tuples previously written to the store (does not evaluate)

*/
read(body?: ClientReadRequest, options?: ClientRequestOpts & PaginationOptions): PromiseResult<ReadResponse>;
read(body?: ClientReadRequest, options?: ClientRequestOptsWithStoreId & PaginationOptions): PromiseResult<ReadResponse>;
/**

@@ -340,2 +369,13 @@ * Write - Create or delete relationship tuples

listRelations(listRelationsRequest: ClientListRelationsRequest, options?: ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts): Promise<ClientListRelationsResponse>;
/**
* ListUsers - List the objects of a particular type that the user has a certain relation to (evaluates)
* @param {ClientListUsersRequest} body
* @param {ClientRequestOptsWithAuthZModelId} [options]
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration
* @param {object} [options.headers] - Custom headers to send alongside the request
* @param {object} [options.retryParams] - Override the retry parameters for this request
* @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request
* @param {number} [options.retryParams.minWaitInMs] - Override the minimum wait before a retry is initiated
*/
listUsers(body: ClientListUsersRequest, options?: ClientRequestOptsWithAuthZModelId): PromiseResult<ListUsersResponse>;
/**************

@@ -342,0 +382,0 @@ * Assertions *

@@ -30,9 +30,28 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenFgaClient = exports.ClientWriteStatus = void 0;
exports.OpenFgaClient = exports.ClientWriteStatus = exports.ClientConfiguration = void 0;
const asyncPool = require("tiny-async-pool");
const api_1 = require("./api");
const base_1 = require("./base");
const configuration_1 = require("./configuration");
const errors_1 = require("./errors");
const utils_1 = require("./utils");
const validation_1 = require("./validation");
class ClientConfiguration extends configuration_1.Configuration {
constructor(params = {}) {
super(params);
this.storeId = params.storeId;
this.authorizationModelId = params.authorizationModelId;
}
isValid() {
super.isValid();
if (this.storeId && !(0, validation_1.isWellFormedUlidString)(this.storeId)) {
throw new errors_1.FgaValidationError("storeId", "storeId must be in ULID format");
}
if (this.authorizationModelId && !(0, validation_1.isWellFormedUlidString)(this.authorizationModelId)) {
throw new errors_1.FgaValidationError("authorizationModelId", "authorizationModelId must be in ULID format");
}
return true;
}
}
exports.ClientConfiguration = ClientConfiguration;
const DEFAULT_MAX_METHOD_PARALLEL_REQS = 10;

@@ -50,10 +69,27 @@ const CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method";

this.axios = axios;
if (configuration instanceof ClientConfiguration) {
this.configuration = configuration;
}
else {
this.configuration = new ClientConfiguration(configuration);
}
this.configuration.isValid();
this.api = new api_1.OpenFgaApi(this.configuration, axios);
this.storeId = configuration.storeId;
this.authorizationModelId = configuration.authorizationModelId;
this.getAuthorizationModelId(); // validates the authorization model id
}
getStoreId(options = {}, isOptional = false) {
const storeId = (options === null || options === void 0 ? void 0 : options.storeId) || this.storeId;
if (storeId && !(0, validation_1.isWellFormedUlidString)(storeId)) {
throw new errors_1.FgaValidationError("storeId", "storeId must be in ULID format");
}
if (!isOptional && !storeId) {
throw new errors_1.FgaValidationError("storeId", "storeId is required");
}
return storeId;
}
getAuthorizationModelId(options = {}) {
const authorizationModelId = (options === null || options === void 0 ? void 0 : options.authorizationModelId) || this.authorizationModelId;
if (authorizationModelId && !(0, validation_1.isWellFormedUlidString)(authorizationModelId)) {
throw new errors_1.FgaValidationError("authorizationModelId");
throw new errors_1.FgaValidationError("authorizationModelId", "authorizationModelId must be in ULID format");
}

@@ -119,3 +155,3 @@ return authorizationModelId;

* GetStore - Get information about the current store
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -128,3 +164,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

return __awaiter(this, arguments, void 0, function* (options = {}) {
return this.api.getStore(options);
return this.api.getStore(this.getStoreId(options), options);
});

@@ -134,3 +170,3 @@ }

* DeleteStore - Delete a store
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -143,3 +179,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

return __awaiter(this, arguments, void 0, function* (options = {}) {
return this.api.deleteStore(options);
return this.api.deleteStore(this.getStoreId(options), options);
});

@@ -162,3 +198,3 @@ }

return __awaiter(this, arguments, void 0, function* (options = {}) {
return this.api.readAuthorizationModels(options.pageSize, options.continuationToken, options);
return this.api.readAuthorizationModels(this.getStoreId(options), options.pageSize, options.continuationToken, options);
});

@@ -169,3 +205,3 @@ }

* @param {WriteAuthorizationModelRequest} body
* @param {ClientRequestOpts} [options]
* @param {ClientRequestOptsWithStoreId} [options]
* @param {object} [options.headers] - Custom headers to send alongside the request

@@ -178,3 +214,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request

return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.writeAuthorizationModel(body, options);
return this.api.writeAuthorizationModel(this.getStoreId(options), body, options);
});

@@ -197,3 +233,3 @@ }

}
return this.api.readAuthorizationModel(authorizationModelId, options);
return this.api.readAuthorizationModel(this.getStoreId(options), authorizationModelId, options);
});

@@ -237,3 +273,3 @@ }

return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.readChanges(body === null || body === void 0 ? void 0 : body.type, options.pageSize, options.continuationToken, options);
return this.api.readChanges(this.getStoreId(options), body === null || body === void 0 ? void 0 : body.type, options.pageSize, options.continuationToken, options);
});

@@ -261,3 +297,3 @@ }

}
return this.api.read(readRequest, options);
return this.api.read(this.getStoreId(options), readRequest, options);
});

@@ -297,3 +333,3 @@ }

}
yield this.api.write(apiBody, options);
yield this.api.write(this.getStoreId(options), apiBody, options);
return {

@@ -432,3 +468,3 @@ writes: (writes === null || writes === void 0 ? void 0 : writes.map(tuple => ({

return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.check({
return this.api.check(this.getStoreId(options), {
tuple_key: {

@@ -509,3 +545,3 @@ user: body.user,

return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.expand({
return this.api.expand(this.getStoreId(options), {
authorization_model_id: this.getAuthorizationModelId(options),

@@ -528,3 +564,3 @@ tuple_key: body,

return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.listObjects({
return this.api.listObjects(this.getStoreId(options), {
authorization_model_id: this.getAuthorizationModelId(options),

@@ -572,2 +608,24 @@ user: body.user,

}
/**
* ListUsers - List the objects of a particular type that the user has a certain relation to (evaluates)
* @param {ClientListUsersRequest} body
* @param {ClientRequestOptsWithAuthZModelId} [options]
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration
* @param {object} [options.headers] - Custom headers to send alongside the request
* @param {object} [options.retryParams] - Override the retry parameters for this request
* @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request
* @param {number} [options.retryParams.minWaitInMs] - Override the minimum wait before a retry is initiated
*/
listUsers(body_1) {
return __awaiter(this, arguments, void 0, function* (body, options = {}) {
return this.api.listUsers(this.getStoreId(options), {
authorization_model_id: this.getAuthorizationModelId(options),
relation: body.relation,
object: body.object,
user_filters: body.user_filters,
context: body.context,
contextual_tuples: body.contextualTuples || [],
}, options);
});
}
/**************

@@ -587,3 +645,3 @@ * Assertions *

return __awaiter(this, arguments, void 0, function* (options = {}) {
return this.api.readAssertions(this.getAuthorizationModelId(options), options);
return this.api.readAssertions(this.getStoreId(options), this.getAuthorizationModelId(options), options);
});

@@ -603,3 +661,3 @@ }

return __awaiter(this, arguments, void 0, function* (assertions, options = {}) {
return this.api.writeAssertions(this.getAuthorizationModelId(options), {
return this.api.writeAssertions(this.getStoreId(options), this.getAuthorizationModelId(options), {
assertions: assertions.map(assertion => ({

@@ -606,0 +664,0 @@ tuple_key: {

@@ -14,3 +14,3 @@ /**

import { Configuration } from "./configuration";
import { Credentials } from "./credentials";
import type { Credentials } from "./credentials";
/**

@@ -62,3 +62,3 @@ *

*/
export declare const createRequestFunction: (axiosArgs: RequestArgs, axiosInstance: AxiosInstance, configuration: Configuration, credentials?: Credentials) => (axios?: AxiosInstance) => PromiseResult<any>;
export declare const createRequestFunction: (axiosArgs: RequestArgs, axiosInstance: AxiosInstance, configuration: Configuration, credentials: Credentials) => (axios?: AxiosInstance) => PromiseResult<any>;
export {};

@@ -24,3 +24,2 @@ "use strict";

exports.createRequestFunction = exports.attemptHttpRequest = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setBearerAuthToObject = exports.DUMMY_BASE_URL = void 0;
const credentials_1 = require("./credentials");
const errors_1 = require("./errors");

@@ -171,5 +170,2 @@ const utils_1 = require("./utils");

const minWaitInMs = retryParams ? retryParams.minWaitInMs : 0;
if (!credentials) {
credentials = credentials_1.Credentials.init(configuration);
}
return (...args_1) => __awaiter(this, [...args_1], void 0, function* (axios = axiosInstance) {

@@ -176,0 +172,0 @@ yield (0, exports.setBearerAuthToObject)(axiosArgs.options.headers, credentials);

@@ -27,3 +27,2 @@ /**

apiHost?: string;
storeId?: string;
credentials?: CredentialsConfig;

@@ -82,9 +81,2 @@ baseOptions?: any;

/**
* provide storeId
*
* @type {string}
* @memberof Configuration
*/
storeId: string;
/**
* base options for axios calls

@@ -91,0 +83,0 @@ *

@@ -22,3 +22,3 @@ "use strict";

const DEFAULT_MIN_WAIT_MS = 100;
const DEFAULT_USER_AGENT = "openfga-sdk js/0.3.5";
const DEFAULT_USER_AGENT = "openfga-sdk js/0.4.0";
function GetDefaultRetryParams(maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) {

@@ -55,3 +55,2 @@ return {

this.apiUrl = params.apiUrl;
this.storeId = params.storeId;
const credentialParams = params.credentials;

@@ -112,5 +111,2 @@ if (credentialParams) {

}
if (this.storeId && !(0, validation_1.isWellFormedUlidString)(this.storeId)) {
throw new errors_1.FgaValidationError("storeId");
}
if (((_a = this.retryParams) === null || _a === void 0 ? void 0 : _a.maxRetry) && this.retryParams.maxRetry > 15) {

@@ -130,2 +126,2 @@ throw new errors_1.FgaValidationError("Configuration.retryParams.maxRetry exceeds maximum allowed limit of 15");

*/
Configuration.sdkVersion = "0.3.5";
Configuration.sdkVersion = "0.4.0";
{
"name": "@openfga/sdk",
"version": "0.3.5",
"version": "0.4.0",
"description": "JavaScript and Node.js SDK for OpenFGA",

@@ -25,3 +25,3 @@ "author": "OpenFGA",

"dependencies": {
"axios": "^1.6.7",
"axios": "^1.6.8",
"tiny-async-pool": "^2.1.0"

@@ -31,6 +31,6 @@ },

"@types/jest": "^29.5.12",
"@types/node": "^20.11.28",
"@types/node": "^20.12.7",
"@types/tiny-async-pool": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"eslint": "^8.57.0",

@@ -40,3 +40,3 @@ "jest": "^29.7.0",

"ts-jest": "^29.1.2",
"typescript": "^5.4.2"
"typescript": "^5.4.5"
},

@@ -43,0 +43,0 @@ "files": [

@@ -41,5 +41,7 @@ # JavaScript and Node.js SDK for OpenFGA

- [List Relations](#list-relations)
- [List Users](#list-users)
- [Assertions](#assertions)
- [Read Assertions](#read-assertions)
- [Write Assertions](#write-assertions)
- [Retries](#retries)
- [API Endpoints](#api-endpoints)

@@ -100,3 +102,3 @@ - [Models](#models)

storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`
authorizationModelId: process.env.FGA_AUTHORIZATION_MODEL_ID, // Optional, can be overridden per request
authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request
});

@@ -113,3 +115,3 @@ ```

storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`
authorizationModelId: process.env.FGA_AUTHORIZATION_MODEL_ID, // Optional, can be overridden per request
authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request
credentials: {

@@ -132,3 +134,3 @@ method: CredentialsMethod.ApiToken,

storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`
authorizationModelId: process.env.FGA_AUTHORIZATION_MODEL_ID, // Optional, can be overridden per request
authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request
credentials: {

@@ -579,2 +581,45 @@ method: CredentialsMethod.ClientCredentials,

##### List Users
List the users who have a certain relation to a particular type.
[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListUsers)
```js
const options = {};
// To override the authorization model id for this request
options.authorization_model_id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw";
// Only a single filter is allowed for the time being
const userFilters = [{type: "user"}];
// user filters can also be of the form
// const userFilters = [{type: "team", relation: "member"}];
const response = await fgaClient.listUsers({
object: {
type: "document",
id: "roadmap"
},
relation: "can_read",
user_filters: userFilters,
context: {
"view_count": 100
},
contextualTuples:
[{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "editor",
object: "folder:product"
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
}]
}, options);
// response.users = [{object: {type: "user", id: "81684243-9356-4421-8fbf-a4f8d36aa31b"}}, {userset: { type: "user" }}, ...]
// response.excluded_users = [ {object: {type: "user", id: "4a455e27-d15a-4434-82e0-136f9c2aa4cf"}}, ... ]
```
#### Assertions

@@ -627,2 +672,24 @@

### Retries
If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 15 times with a minimum wait time of 100 milliseconds between each attempt.
To 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.
Apply your custom retry values by setting to `retryParams` on the to the configuration object passed to the `OpenFgaClient` call.
```javascript
const { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk';
const fgaClient = new OpenFgaClient({
apiUrl: process.env.FGA_API_URL, // required
storeId: process.env.FGA_STORE_ID, // not needed when calling `CreateStore` or `ListStores`
authorizationModelId: process.env.FGA_MODEL_ID, // Optional, can be overridden per request
retryParams: {
maxRetry: 3, // retry up to 3 times on API requests
minWaitInMs: 250 // wait a minimum of 250 milliseconds between requests
}
});
```
### API Endpoints

@@ -629,0 +696,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc