@openfga/sdk
Advanced tools
Comparing version 0.7.0 to 0.8.0
# Changelog | ||
## [Unreleased](https://github.com/openfga/js-sdk/compare/v0.8.0...HEAD) | ||
## v0.8.0 | ||
### [0.8.0](https://github.com/openfga/js-sdk/compare/v0.7.0...v0.8.0) (2025-01-14) | ||
- feat!: add support for server-side `BatchCheck` method. This is a more efficient way to check on multiple tuples than calling the existing client-side `BatchCheck`. Using this method requires an OpenFGA [v1.8.0+](https://github.com/openfga/openfga/releases/tag/v1.8.0) server. | ||
- The existing `BatchCheck` method has been renamed to `clientBatchCheck` and it now bundles the results in a field called `result` instead of `responses`. | ||
- The existing `BatchCheckResponse` has been renamed to `ClientBatchCheckResponse`. | ||
- feat: add support for startTime` parameter in `ReadChanges` endpoint | ||
- feat: support contextual tuples and context in assertions | ||
- feat: support contextual tuples in Expand | ||
- fix: error correctly if apiUrl is not provided - thanks @Waheedsys (#161) | ||
- fix: use provided axios instance in credentials refresh - thanks @Siddhant-K-code (#193) | ||
- fix!: The minimum node version required by this SDK is now v16.15.0 | ||
- chore(docs): various cleanup and improvements - thanks @tmsagarofficial (#164), @vil02 (https://github.com/openfga/sdk-generator/pull/424, https://github.com/openfga/sdk-generator/pull/422), @sccalabr (https://github.com/openfga/sdk-generator/pull/433) | ||
BREAKING CHANGES: | ||
- The minimum node version required by this SDK is now v16.15.0 | ||
- Usage of the existing `batchCheck` method should now use the `clientBatchCheck` method. The existing `BatchCheckResponse` has been renamed to `ClientBatchCheckResponse` and it now bundles the results in a field called `result` instead of `responses`. | ||
## v0.7.0 | ||
@@ -192,3 +214,3 @@ | ||
- [BREAKING] feat(list-objects)!: response has been changed to include the object type | ||
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:roadmap"]}` | ||
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]}` | ||
@@ -195,0 +217,0 @@ Fixes: |
@@ -63,2 +63,14 @@ /** | ||
expectation: boolean; | ||
/** | ||
* | ||
* @type {Array<TupleKey>} | ||
* @memberof Assertion | ||
*/ | ||
contextual_tuples?: Array<TupleKey>; | ||
/** | ||
* Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | ||
* @type {object} | ||
* @memberof Assertion | ||
*/ | ||
context?: object; | ||
} | ||
@@ -93,2 +105,18 @@ /** | ||
* @export | ||
* @enum {string} | ||
*/ | ||
export declare enum AuthErrorCode { | ||
NoAuthError = "no_auth_error", | ||
AuthFailedInvalidSubject = "auth_failed_invalid_subject", | ||
AuthFailedInvalidAudience = "auth_failed_invalid_audience", | ||
AuthFailedInvalidIssuer = "auth_failed_invalid_issuer", | ||
InvalidClaims = "invalid_claims", | ||
AuthFailedInvalidBearerToken = "auth_failed_invalid_bearer_token", | ||
BearerTokenMissing = "bearer_token_missing", | ||
Unauthenticated = "unauthenticated", | ||
Forbidden = "forbidden" | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface AuthorizationModel | ||
@@ -127,2 +155,117 @@ */ | ||
* @export | ||
* @interface BatchCheckItem | ||
*/ | ||
export interface BatchCheckItem { | ||
/** | ||
* | ||
* @type {CheckRequestTupleKey} | ||
* @memberof BatchCheckItem | ||
*/ | ||
tuple_key: CheckRequestTupleKey; | ||
/** | ||
* | ||
* @type {ContextualTupleKeys} | ||
* @memberof BatchCheckItem | ||
*/ | ||
contextual_tuples?: ContextualTupleKeys; | ||
/** | ||
* | ||
* @type {object} | ||
* @memberof BatchCheckItem | ||
*/ | ||
context?: object; | ||
/** | ||
* correlation_id must be a string containing only letters, numbers, or hyphens, with length ≤ 36 characters. | ||
* @type {string} | ||
* @memberof BatchCheckItem | ||
*/ | ||
correlation_id: string; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface BatchCheckRequest | ||
*/ | ||
export interface BatchCheckRequest { | ||
/** | ||
* | ||
* @type {Array<BatchCheckItem>} | ||
* @memberof BatchCheckRequest | ||
*/ | ||
checks: Array<BatchCheckItem>; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof BatchCheckRequest | ||
*/ | ||
authorization_model_id?: string; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof BatchCheckRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface BatchCheckResponse | ||
*/ | ||
export interface BatchCheckResponse { | ||
/** | ||
* map keys are the correlation_id values from the BatchCheckItems in the request | ||
* @type {{ [key: string]: BatchCheckSingleResult; }} | ||
* @memberof BatchCheckResponse | ||
*/ | ||
result?: { | ||
[key: string]: BatchCheckSingleResult; | ||
}; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface BatchCheckSingleResult | ||
*/ | ||
export interface BatchCheckSingleResult { | ||
/** | ||
* | ||
* @type {boolean} | ||
* @memberof BatchCheckSingleResult | ||
*/ | ||
allowed?: boolean; | ||
/** | ||
* | ||
* @type {CheckError} | ||
* @memberof BatchCheckSingleResult | ||
*/ | ||
error?: CheckError; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface CheckError | ||
*/ | ||
export interface CheckError { | ||
/** | ||
* | ||
* @type {ErrorCode} | ||
* @memberof CheckError | ||
*/ | ||
input_error?: ErrorCode; | ||
/** | ||
* | ||
* @type {InternalErrorCode} | ||
* @memberof CheckError | ||
*/ | ||
internal_error?: InternalErrorCode; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof CheckError | ||
*/ | ||
message?: string; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface CheckRequest | ||
@@ -297,3 +440,3 @@ */ | ||
/** | ||
* - UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency. | ||
* Controls the consistency preferences when calling the query APIs. - UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY. - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency. | ||
* @export | ||
@@ -436,3 +579,5 @@ * @enum {string} | ||
InvalidAuthorizationModel = "invalid_authorization_model", | ||
UnsupportedSchemaVersion = "unsupported_schema_version" | ||
UnsupportedSchemaVersion = "unsupported_schema_version", | ||
Cancelled = "cancelled", | ||
InvalidStartTime = "invalid_start_time" | ||
} | ||
@@ -463,2 +608,8 @@ /** | ||
consistency?: ConsistencyPreference; | ||
/** | ||
* | ||
* @type {ContextualTupleKeys} | ||
* @memberof ExpandRequest | ||
*/ | ||
contextual_tuples?: ContextualTupleKeys; | ||
} | ||
@@ -519,2 +670,21 @@ /** | ||
* @export | ||
* @interface ForbiddenResponse | ||
*/ | ||
export interface ForbiddenResponse { | ||
/** | ||
* | ||
* @type {AuthErrorCode} | ||
* @memberof ForbiddenResponse | ||
*/ | ||
code?: AuthErrorCode; | ||
/** | ||
* | ||
* @type {string} | ||
* @memberof ForbiddenResponse | ||
*/ | ||
message?: string; | ||
} | ||
/** | ||
* | ||
* @export | ||
* @interface GetStoreResponse | ||
@@ -562,3 +732,2 @@ */ | ||
InternalError = "internal_error", | ||
Cancelled = "cancelled", | ||
DeadlineExceeded = "deadline_exceeded", | ||
@@ -565,0 +734,0 @@ AlreadyExists = "already_exists", |
@@ -16,8 +16,25 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnprocessableContentErrorCode = exports.TypeName = exports.TupleOperation = exports.NullValue = exports.NotFoundErrorCode = exports.InternalErrorCode = exports.ErrorCode = exports.ConsistencyPreference = void 0; | ||
exports.UnprocessableContentErrorCode = exports.TypeName = exports.TupleOperation = exports.NullValue = exports.NotFoundErrorCode = exports.InternalErrorCode = exports.ErrorCode = exports.ConsistencyPreference = exports.AuthErrorCode = void 0; | ||
/** | ||
* - UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency. | ||
* | ||
* @export | ||
* @enum {string} | ||
*/ | ||
var AuthErrorCode; | ||
(function (AuthErrorCode) { | ||
AuthErrorCode["NoAuthError"] = "no_auth_error"; | ||
AuthErrorCode["AuthFailedInvalidSubject"] = "auth_failed_invalid_subject"; | ||
AuthErrorCode["AuthFailedInvalidAudience"] = "auth_failed_invalid_audience"; | ||
AuthErrorCode["AuthFailedInvalidIssuer"] = "auth_failed_invalid_issuer"; | ||
AuthErrorCode["InvalidClaims"] = "invalid_claims"; | ||
AuthErrorCode["AuthFailedInvalidBearerToken"] = "auth_failed_invalid_bearer_token"; | ||
AuthErrorCode["BearerTokenMissing"] = "bearer_token_missing"; | ||
AuthErrorCode["Unauthenticated"] = "unauthenticated"; | ||
AuthErrorCode["Forbidden"] = "forbidden"; | ||
})(AuthErrorCode || (exports.AuthErrorCode = AuthErrorCode = {})); | ||
/** | ||
* Controls the consistency preferences when calling the query APIs. - UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY. - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency. | ||
* @export | ||
* @enum {string} | ||
*/ | ||
var ConsistencyPreference; | ||
@@ -84,2 +101,4 @@ (function (ConsistencyPreference) { | ||
ErrorCode["UnsupportedSchemaVersion"] = "unsupported_schema_version"; | ||
ErrorCode["Cancelled"] = "cancelled"; | ||
ErrorCode["InvalidStartTime"] = "invalid_start_time"; | ||
})(ErrorCode || (exports.ErrorCode = ErrorCode = {})); | ||
@@ -95,3 +114,2 @@ /** | ||
InternalErrorCode["InternalError"] = "internal_error"; | ||
InternalErrorCode["Cancelled"] = "cancelled"; | ||
InternalErrorCode["DeadlineExceeded"] = "deadline_exceeded"; | ||
@@ -98,0 +116,0 @@ InternalErrorCode["AlreadyExists"] = "already_exists"; |
@@ -37,3 +37,3 @@ "use strict"; | ||
this.configuration.isValid(); | ||
this.credentials = credentials_1.Credentials.init(this.configuration); | ||
this.credentials = credentials_1.Credentials.init(this.configuration, this.axios); | ||
if (!this.axios) { | ||
@@ -40,0 +40,0 @@ const httpAgent = new http.Agent({ keepAlive: true }); |
@@ -14,3 +14,3 @@ /** | ||
import { OpenFgaApi } from "./api"; | ||
import { Assertion, CheckRequest, CheckRequestTupleKey, CheckResponse, ConsistencyPreference, CreateStoreRequest, CreateStoreResponse, ExpandRequestTupleKey, ExpandResponse, GetStoreResponse, ListObjectsRequest, ListObjectsResponse, ListStoresResponse, ListUsersRequest, ListUsersResponse, ReadAssertionsResponse, ReadAuthorizationModelResponse, ReadAuthorizationModelsResponse, ReadChangesResponse, ReadRequestTupleKey, ReadResponse, TupleKey, TupleKeyWithoutCondition, WriteAuthorizationModelRequest, WriteAuthorizationModelResponse } from "./apiModel"; | ||
import { Assertion, CheckError, CheckRequest, CheckRequestTupleKey, CheckResponse, ConsistencyPreference, ContextualTupleKeys, CreateStoreRequest, CreateStoreResponse, ExpandRequest, ExpandRequestTupleKey, ExpandResponse, GetStoreResponse, ListObjectsRequest, ListObjectsResponse, ListStoresResponse, ListUsersRequest, ListUsersResponse, ReadAssertionsResponse, ReadAuthorizationModelResponse, ReadAuthorizationModelsResponse, ReadChangesResponse, ReadRequestTupleKey, ReadResponse, TupleKey, TupleKeyWithoutCondition, WriteAuthorizationModelRequest, WriteAuthorizationModelResponse } from "./apiModel"; | ||
import { BaseAPI } from "./base"; | ||
@@ -64,4 +64,4 @@ import { PromiseResult } from "./common"; | ||
}; | ||
export type ClientBatchCheckRequest = ClientCheckRequest[]; | ||
export type ClientBatchCheckSingleResponse = { | ||
export type ClientBatchCheckClientRequest = ClientCheckRequest[]; | ||
export type ClientBatchCheckSingleClientResponse = { | ||
_request: ClientCheckRequest; | ||
@@ -75,4 +75,31 @@ } & ({ | ||
}); | ||
export interface ClientBatchCheckClientResponse { | ||
result: ClientBatchCheckSingleClientResponse[]; | ||
} | ||
export interface ClientBatchCheckClientRequestOpts { | ||
maxParallelRequests?: number; | ||
} | ||
export type ClientBatchCheckItem = { | ||
user: string; | ||
relation: string; | ||
object: string; | ||
correlationId?: string; | ||
contextualTuples?: ContextualTupleKeys; | ||
context?: object; | ||
}; | ||
export type ClientBatchCheckRequest = { | ||
checks: ClientBatchCheckItem[]; | ||
}; | ||
export interface ClientBatchCheckRequestOpts { | ||
maxParallelRequests?: number; | ||
maxBatchSize?: number; | ||
} | ||
export type ClientBatchCheckSingleResponse = { | ||
allowed: boolean; | ||
request: ClientBatchCheckItem; | ||
correlationId: string; | ||
error?: CheckError; | ||
}; | ||
export interface ClientBatchCheckResponse { | ||
responses: ClientBatchCheckSingleResponse[]; | ||
result: ClientBatchCheckSingleResponse[]; | ||
} | ||
@@ -86,5 +113,2 @@ export interface ClientWriteRequestOpts { | ||
} | ||
export interface BatchCheckRequestOpts { | ||
maxParallelRequests?: number; | ||
} | ||
export interface ClientWriteRequest { | ||
@@ -112,4 +136,7 @@ writes?: TupleKey[]; | ||
type: string; | ||
startTime?: string; | ||
} | ||
export type ClientExpandRequest = ExpandRequestTupleKey; | ||
export type ClientExpandRequest = ExpandRequestTupleKey & Omit<ExpandRequest, "tuple_key" | "authorization_model_id" | "contextual_tuples" | "consistency"> & { | ||
contextualTuples?: Array<TupleKey>; | ||
}; | ||
export type ClientReadRequest = ReadRequestTupleKey; | ||
@@ -243,2 +270,3 @@ export type ClientListObjectsRequest = Omit<ListObjectsRequest, "authorization_model_id" | "contextual_tuples" | "consistency"> & { | ||
* @param {string} [options.continuationToken] | ||
* @param {string} [body.startTime] | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
@@ -324,7 +352,8 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request | ||
/** | ||
* BatchCheck - Run a set of checks (evaluates) | ||
* @param {ClientBatchCheckRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts} [options] | ||
* BatchCheck - Run a set of checks (evaluates) by calling the single check endpoint multiple times in parallel. | ||
* @param {ClientBatchCheckClientRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & ClientBatchCheckClientRequestOpts} [options] | ||
* @param {number} [options.maxParallelRequests] - Max number of requests to issue in parallel. Defaults to `10` | ||
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration | ||
* @param {string} [options.consistency] - Optional consistency level for the request. Default is `MINIMIZE_LATENCY` | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
@@ -335,4 +364,21 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request | ||
*/ | ||
batchCheck(body: ClientBatchCheckRequest, options?: ClientRequestOptsWithConsistency & BatchCheckRequestOpts): Promise<ClientBatchCheckResponse>; | ||
clientBatchCheck(body: ClientBatchCheckClientRequest, options?: ClientRequestOptsWithConsistency & ClientBatchCheckClientRequestOpts): Promise<ClientBatchCheckClientResponse>; | ||
private singleBatchCheck; | ||
/** | ||
* BatchCheck - Run a set of checks (evaluates) by calling the batch-check endpoint. | ||
* Given the provided list of checks, it will call batch check, splitting the checks into batches based | ||
* on the `options.maxBatchSize` parameter (default 50 checks) if needed. | ||
* @param {ClientBatchCheckClientRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & ClientBatchCheckClientRequestOpts} [options] | ||
* @param {number} [options.maxParallelRequests] - Max number of requests to issue in parallel, if executing multiple requests. Defaults to `10` | ||
* @param {number} [options.maxBatchSize] - Max number of checks to include in a single batch check request. Defaults to `50`. | ||
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration. | ||
* @param {string} [options.consistency] - | ||
* @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 | ||
*/ | ||
batchCheck(body: ClientBatchCheckRequest, options?: ClientRequestOptsWithConsistency & ClientBatchCheckRequestOpts): Promise<ClientBatchCheckResponse>; | ||
/** | ||
* Expand - Expands the relationships in userset tree format (evaluates) | ||
@@ -373,3 +419,3 @@ * @param {ClientExpandRequest} body | ||
*/ | ||
listRelations(listRelationsRequest: ClientListRelationsRequest, options?: ClientRequestOptsWithConsistency & BatchCheckRequestOpts): Promise<ClientListRelationsResponse>; | ||
listRelations(listRelationsRequest: ClientListRelationsRequest, options?: ClientRequestOptsWithConsistency & ClientBatchCheckClientRequestOpts): Promise<ClientListRelationsResponse>; | ||
/** | ||
@@ -376,0 +422,0 @@ * ListUsers - List the objects of a particular type that the user has a certain relation to (evaluates) |
@@ -41,2 +41,3 @@ "use strict"; | ||
const DEFAULT_MAX_METHOD_PARALLEL_REQS = 10; | ||
const DEFAULT_MAX_BATCH_SIZE = 50; | ||
const CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method"; | ||
@@ -222,2 +223,3 @@ const CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id"; | ||
* @param {string} [options.continuationToken] | ||
* @param {string} [body.startTime] | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
@@ -229,3 +231,3 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request | ||
async readChanges(body, options = {}) { | ||
return this.api.readChanges(this.getStoreId(options), body?.type, options.pageSize, options.continuationToken, options); | ||
return this.api.readChanges(this.getStoreId(options), body?.type, options.pageSize, options.continuationToken, body?.startTime, options); | ||
} | ||
@@ -403,7 +405,8 @@ /** | ||
/** | ||
* BatchCheck - Run a set of checks (evaluates) | ||
* @param {ClientBatchCheckRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts} [options] | ||
* BatchCheck - Run a set of checks (evaluates) by calling the single check endpoint multiple times in parallel. | ||
* @param {ClientBatchCheckClientRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & ClientBatchCheckClientRequestOpts} [options] | ||
* @param {number} [options.maxParallelRequests] - Max number of requests to issue in parallel. Defaults to `10` | ||
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration | ||
* @param {string} [options.consistency] - Optional consistency level for the request. Default is `MINIMIZE_LATENCY` | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
@@ -414,7 +417,7 @@ * @param {object} [options.retryParams] - Override the retry parameters for this request | ||
*/ | ||
async batchCheck(body, options = {}) { | ||
async clientBatchCheck(body, options = {}) { | ||
const { headers = {}, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS } = options; | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "BatchCheck"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "ClientBatchCheck"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const responses = []; | ||
const result = []; | ||
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers }) | ||
@@ -435,7 +438,84 @@ .then(response => { | ||
}))) { | ||
responses.push(singleCheckResponse); | ||
result.push(singleCheckResponse); | ||
} | ||
return { responses }; | ||
return { result }; | ||
} | ||
singleBatchCheck(body, options = {}) { | ||
return this.api.batchCheck(this.getStoreId(options), body, options); | ||
} | ||
/** | ||
* BatchCheck - Run a set of checks (evaluates) by calling the batch-check endpoint. | ||
* Given the provided list of checks, it will call batch check, splitting the checks into batches based | ||
* on the `options.maxBatchSize` parameter (default 50 checks) if needed. | ||
* @param {ClientBatchCheckClientRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId & ClientBatchCheckClientRequestOpts} [options] | ||
* @param {number} [options.maxParallelRequests] - Max number of requests to issue in parallel, if executing multiple requests. Defaults to `10` | ||
* @param {number} [options.maxBatchSize] - Max number of checks to include in a single batch check request. Defaults to `50`. | ||
* @param {string} [options.authorizationModelId] - Overrides the authorization model id in the configuration. | ||
* @param {string} [options.consistency] - | ||
* @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 | ||
*/ | ||
async batchCheck(body, options = {}) { | ||
const { headers = {}, maxBatchSize = DEFAULT_MAX_BATCH_SIZE, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS, } = options; | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const correlationIdToCheck = new Map(); | ||
const transformed = []; | ||
// Validate and transform checks | ||
for (const check of body.checks) { | ||
// Generate a correlation ID if not provided | ||
if (!check.correlationId) { | ||
check.correlationId = (0, utils_1.generateRandomIdWithNonUniqueFallback)(); | ||
} | ||
// Ensure that correlation IDs are unique | ||
if (correlationIdToCheck.has(check.correlationId)) { | ||
throw new errors_1.FgaValidationError("correlationId", "When calling batchCheck, correlation IDs must be unique"); | ||
} | ||
correlationIdToCheck.set(check.correlationId, check); | ||
// Transform the check into the BatchCheckItem format | ||
transformed.push({ | ||
tuple_key: { | ||
user: check.user, | ||
relation: check.relation, | ||
object: check.object, | ||
}, | ||
context: check.context, | ||
contextual_tuples: check.contextualTuples, | ||
correlation_id: check.correlationId, | ||
}); | ||
} | ||
// Split the transformed checks into batches based on maxBatchSize | ||
const batchedChecks = (0, utils_1.chunkArray)(transformed, maxBatchSize); | ||
// Execute batch checks in parallel with a limit of maxParallelRequests | ||
const results = []; | ||
const batchResponses = asyncPool(maxParallelRequests, batchedChecks, async (batch) => { | ||
const batchRequest = { | ||
checks: batch, | ||
authorization_model_id: options.authorizationModelId, | ||
consistency: options.consistency, | ||
}; | ||
const response = await this.singleBatchCheck(batchRequest, { ...options, headers }); | ||
return response.result; | ||
}); | ||
// Collect the responses and associate them with their correlation IDs | ||
for await (const response of batchResponses) { | ||
if (response) { | ||
for (const [correlationId, result] of Object.entries(response)) { | ||
const check = correlationIdToCheck.get(correlationId); | ||
if (check && result) { | ||
results.push({ | ||
allowed: result.allowed || false, | ||
request: check, | ||
correlationId, | ||
error: result.error, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return { result: results }; | ||
} | ||
/** | ||
* Expand - Expands the relationships in userset tree format (evaluates) | ||
@@ -456,3 +536,7 @@ * @param {ClientExpandRequest} body | ||
authorization_model_id: this.getAuthorizationModelId(options), | ||
tuple_key: body, | ||
tuple_key: { | ||
object: body.object, | ||
relation: body.relation, | ||
}, | ||
contextual_tuples: { tuple_keys: body.contextualTuples || [] }, | ||
consistency: options.consistency | ||
@@ -501,3 +585,3 @@ }, options); | ||
} | ||
const batchCheckResults = await this.batchCheck(relations.map(relation => ({ | ||
const batchCheckResults = await this.clientBatchCheck(relations.map(relation => ({ | ||
user, | ||
@@ -509,7 +593,7 @@ relation, | ||
})), { ...options, headers, maxParallelRequests }); | ||
const firstErrorResponse = batchCheckResults.responses.find(response => response.error); | ||
const firstErrorResponse = batchCheckResults.result.find(response => response.error); | ||
if (firstErrorResponse) { | ||
throw firstErrorResponse.error; | ||
} | ||
return { relations: batchCheckResults.responses.filter(result => result.allowed).map(result => result._request.relation) }; | ||
return { relations: batchCheckResults.result.filter(result => result.allowed).map(result => result._request.relation) }; | ||
} | ||
@@ -516,0 +600,0 @@ /** |
@@ -21,6 +21,6 @@ "use strict"; | ||
// default maximum number of retry | ||
const DEFAULT_MAX_RETRY = 15; | ||
const DEFAULT_MAX_RETRY = 3; | ||
// default minimum wait period in retry - but will backoff exponentially | ||
const DEFAULT_MIN_WAIT_MS = 100; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.7.0"; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.8.0"; | ||
function GetDefaultRetryParams(maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) { | ||
@@ -102,5 +102,4 @@ return { | ||
isValid() { | ||
if (!this.apiUrl) { | ||
(0, validation_1.assertParamExists)("Configuration", "apiScheme", this.apiScheme); | ||
(0, validation_1.assertParamExists)("Configuration", "apiHost", this.apiHost); | ||
if (!this.apiUrl && !this.apiHost) { | ||
(0, validation_1.assertParamExists)("Configuration", "apiUrl", this.apiUrl); | ||
} | ||
@@ -127,2 +126,2 @@ if (!(0, validation_1.isWellFormedUriString)(this.getBasePath())) { | ||
*/ | ||
Configuration.sdkVersion = "0.7.0"; | ||
Configuration.sdkVersion = "0.8.0"; |
@@ -26,4 +26,4 @@ /** | ||
baseOptions?: any; | ||
}): Credentials; | ||
constructor(authConfig: AuthCredentialsConfig, axios: AxiosInstance | undefined, telemetryConfig: TelemetryConfiguration, baseOptions?: any); | ||
}, axios?: AxiosInstance): Credentials; | ||
constructor(authConfig: AuthCredentialsConfig, axios: AxiosInstance | undefined, telemetryConfig: TelemetryConfiguration, baseOptions?: any | undefined); | ||
/** | ||
@@ -30,0 +30,0 @@ * Sets the default config values |
@@ -23,4 +23,4 @@ "use strict"; | ||
class Credentials { | ||
static init(configuration) { | ||
return new Credentials(configuration.credentials, axios_1.default, configuration.telemetry, configuration.baseOptions); | ||
static init(configuration, axios = axios_1.default) { | ||
return new Credentials(configuration.credentials, axios, configuration.telemetry, configuration.baseOptions); | ||
} | ||
@@ -138,3 +138,3 @@ constructor(authConfig, axios = axios_1.default, telemetryConfig, baseOptions) { | ||
minWaitInMs: 100, | ||
}, axios_1.default); | ||
}, this.axios); | ||
const response = wrappedResponse?.response; | ||
@@ -141,0 +141,0 @@ if (response) { |
@@ -0,1 +1,12 @@ | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
export declare enum TelemetryAttribute { | ||
@@ -9,2 +20,3 @@ FgaClientRequestClientId = "fga-client.request.client_id", | ||
HttpClientRequestDuration = "http.client.request.duration", | ||
FgaClientRequestBatchCheckSize = "fga-client.request.batch_check_size", | ||
HttpHost = "http.host", | ||
@@ -35,2 +47,3 @@ HttpRequestMethod = "http.request.method", | ||
}): Record<string, string | number>; | ||
static fromRequestBody(body: any, attributes?: Record<string, string | number>): Record<string, string | number>; | ||
} |
"use strict"; | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,2 +25,3 @@ exports.TelemetryAttributes = exports.TelemetryAttribute = void 0; | ||
TelemetryAttribute["HttpClientRequestDuration"] = "http.client.request.duration"; | ||
TelemetryAttribute["FgaClientRequestBatchCheckSize"] = "fga-client.request.batch_check_size"; | ||
TelemetryAttribute["HttpHost"] = "http.host"; | ||
@@ -73,3 +85,15 @@ TelemetryAttribute["HttpRequestMethod"] = "http.request.method"; | ||
} | ||
static fromRequestBody(body, attributes = {}) { | ||
if (body?.authorization_model_id) { | ||
attributes[TelemetryAttribute.FgaClientRequestModelId] = body.authorization_model_id; | ||
} | ||
if (body?.tuple_key?.user) { | ||
attributes[TelemetryAttribute.FgaClientUser] = body.tuple_key.user; | ||
} | ||
if (body?.checks?.length) { | ||
attributes[TelemetryAttribute.FgaClientRequestBatchCheckSize] = body.checks.length; | ||
} | ||
return attributes; | ||
} | ||
} | ||
exports.TelemetryAttributes = TelemetryAttributes; |
@@ -0,1 +1,12 @@ | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
import { TelemetryAttribute } from "./attributes"; | ||
@@ -2,0 +13,0 @@ import { TelemetryMetric, MetricRecorder } from "./metrics"; |
"use strict"; | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -89,3 +100,4 @@ exports.TelemetryConfiguration = void 0; | ||
// This not included by default as it has a very high cardinality which could increase costs for users | ||
// TelemetryAttribute.FgaClientUser | ||
// TelemetryAttribute.FgaClientUser, | ||
// TelemetryAttribute.FgaClientRequestBatchCheckSize | ||
]); | ||
@@ -115,2 +127,3 @@ /** | ||
attributes_1.TelemetryAttribute.FgaClientUser, | ||
attributes_1.TelemetryAttribute.FgaClientRequestBatchCheckSize, | ||
]); |
@@ -0,1 +1,12 @@ | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
export interface TelemetryCounter { | ||
@@ -2,0 +13,0 @@ name: string; |
"use strict"; | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +14,0 @@ exports.TelemetryCounters = void 0; |
@@ -0,1 +1,12 @@ | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
export interface TelemetryHistogram { | ||
@@ -2,0 +13,0 @@ name: string; |
"use strict"; | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +14,0 @@ exports.TelemetryHistograms = void 0; |
@@ -0,1 +1,12 @@ | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
import { Counter, Histogram, Meter } from "@opentelemetry/api"; | ||
@@ -2,0 +13,0 @@ import { TelemetryCounter } from "./counters"; |
"use strict"; | ||
/** | ||
* JavaScript and Node.js SDK for OpenFGA | ||
* | ||
* API version: 1.x | ||
* Website: https://openfga.dev | ||
* Documentation: https://openfga.dev/docs | ||
* Support: https://openfga.dev/community | ||
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) | ||
* | ||
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +14,0 @@ exports.MetricRecorder = exports.TelemetryMetric = void 0; |
{ | ||
"name": "@openfga/sdk", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "JavaScript and Node.js SDK for OpenFGA", | ||
@@ -26,16 +26,16 @@ "author": "OpenFGA", | ||
"@opentelemetry/api": "^1.9.0", | ||
"axios": "^1.7.5", | ||
"axios": "^1.7.9", | ||
"tiny-async-pool": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^22.5.0", | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.10.5", | ||
"@types/tiny-async-pool": "^2.0.3", | ||
"@typescript-eslint/eslint-plugin": "^8.2.0", | ||
"@typescript-eslint/parser": "^8.2.0", | ||
"@typescript-eslint/eslint-plugin": "^8.19.1", | ||
"@typescript-eslint/parser": "^8.19.1", | ||
"eslint": "^8.57.0", | ||
"jest": "^29.7.0", | ||
"nock": "^13.5.5", | ||
"nock": "^13.5.6", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.5.4" | ||
"typescript": "^5.7.2" | ||
}, | ||
@@ -58,3 +58,3 @@ "files": [ | ||
"engines": { | ||
"node": ">=14.17.0" | ||
"node": ">=16.15.0" | ||
}, | ||
@@ -61,0 +61,0 @@ "publishConfig": { |
@@ -90,5 +90,5 @@ # JavaScript and Node.js SDK for OpenFGA | ||
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 preformed on every request. | ||
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. | ||
> The `OpenFgaClient` will by default retry API requests up to 15 times on 429 and 5xx errors. | ||
> The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors. | ||
@@ -110,3 +110,3 @@ #### No Credentials | ||
```javascript | ||
const { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk'; | ||
const { OpenFgaClient, CredentialsMethod } = require('@openfga/sdk'); // OR import { OpenFgaClient, CredentialsMethod } from '@openfga/sdk'; | ||
@@ -129,3 +129,3 @@ const fgaClient = new OpenFgaClient({ | ||
```javascript | ||
const { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk'; | ||
const { OpenFgaClient, CredentialsMethod } = require('@openfga/sdk'); // OR import { OpenFgaClient, CredentialsMethod } from '@openfga/sdk'; | ||
@@ -311,2 +311,3 @@ const fgaClient = new OpenFgaClient({ | ||
const type = 'document'; | ||
const startTime = "2022-01-01T00:00:00Z" | ||
const options = { | ||
@@ -317,3 +318,3 @@ pageSize: 25, | ||
const response = await fgaClient.readChanges({ type }, options); | ||
const response = await fgaClient.readChanges({ type, startTime }, options); | ||
@@ -338,3 +339,3 @@ // response.continuation_token = ... | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
}; | ||
@@ -345,3 +346,3 @@ | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
}; | ||
@@ -364,3 +365,3 @@ | ||
const body = { | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
}; | ||
@@ -394,9 +395,9 @@ | ||
await fgaClient.write({ | ||
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }], | ||
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }], | ||
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], | ||
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], | ||
}, options); | ||
// Convenience functions are available | ||
await fgaClient.writeTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }], options); | ||
await fgaClient.deleteTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }], options); | ||
await fgaClient.writeTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], options); | ||
await fgaClient.deleteTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], options); | ||
@@ -419,4 +420,4 @@ // if any error is encountered in the transaction mode, an error will be thrown | ||
const response = await fgaClient.write({ | ||
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }], | ||
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }], | ||
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], | ||
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], | ||
}, options); | ||
@@ -426,4 +427,4 @@ | ||
response = { | ||
writes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap", status: "success" } }], | ||
deletes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap", status: "failure", err: <FgaError ...> } }], | ||
writes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", status: "success" } }], | ||
deletes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", status: "failure", err: <FgaError ...> } }], | ||
}; | ||
@@ -450,3 +451,3 @@ */ | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
}, options); | ||
@@ -460,3 +461,3 @@ | ||
Run a set of [checks](#check). Batch Check will return `allowed: false` if it encounters an error, and will return the error in the body. | ||
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up. | ||
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up. | ||
@@ -471,15 +472,15 @@ ```javascript | ||
relation: "viewer", | ||
object: "document:budget", | ||
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5", | ||
}, { | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
relation: "member", | ||
object: "document:budget", | ||
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5", | ||
}, { | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
contextualTuples: [{ | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
relation: "writer", | ||
object: "document:roadmap" | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" | ||
}], | ||
@@ -494,3 +495,3 @@ }], options); | ||
relation: "viewer", | ||
object: "document:budget", | ||
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5", | ||
} | ||
@@ -502,3 +503,3 @@ }, { | ||
relation: "member", | ||
object: "document:budget", | ||
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5", | ||
}, | ||
@@ -511,7 +512,7 @@ err: <FgaError ...> | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
contextualTuples: [{ | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
relation: "writer", | ||
object: "document:roadmap" | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" | ||
}], | ||
@@ -537,6 +538,6 @@ }}, | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
}, options); | ||
// tree = { root: { name: "document:roadmap#viewer", leaf: { users: { users: ["user:81684243-9356-4421-8fbf-a4f8d36aa31b", "user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"] } } } } | ||
// 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"] } } } } | ||
``` | ||
@@ -563,7 +564,7 @@ | ||
relation: "writer", | ||
object: "document:budget" | ||
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5" | ||
}], | ||
}, options); | ||
// response.objects = ["document:roadmap"] | ||
// response.objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"] | ||
``` | ||
@@ -585,3 +586,3 @@ | ||
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
relations: ["can_view", "can_edit", "can_delete"], | ||
@@ -591,3 +592,3 @@ contextualTuples: [{ | ||
relation: "writer", | ||
object: "document:roadmap" | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" | ||
}], | ||
@@ -634,3 +635,3 @@ }, options); | ||
relation: "parent", | ||
object: "document:roadmap" | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" | ||
}] | ||
@@ -662,3 +663,3 @@ }, options); | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
expectation: true, | ||
@@ -684,3 +685,3 @@ }]; | ||
relation: "viewer", | ||
object: "document:roadmap", | ||
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", | ||
expectation: true, | ||
@@ -693,7 +694,7 @@ }], options); | ||
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. | ||
If 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. | ||
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. | ||
Apply your custom retry values by setting to `retryParams` on the configuration object passed to the `OpenFgaClient` call. | ||
@@ -752,3 +753,3 @@ ```javascript | ||
All changes made to this repo will be overwritten on the next generation, so we kindly ask that you send all pull requests related to the SDKs to the [sdk-generator repo](https://github.com/openfga/sdk-generator) instead. | ||
While 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. | ||
@@ -755,0 +756,0 @@ ## Author |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1491104
7870
739
Updatedaxios@^1.7.9