@openfga/sdk
Advanced tools
Comparing version 0.6.1 to 0.6.2
# Changelog | ||
## v0.6.2 | ||
### [0.6.2](https://github.com/openfga/js-sdk/compare/v0.6.1...v0.6.2) (2024-07-31) | ||
- feat: add support for specifying consistency when evaluating or reading (#129) | ||
Note: To use this feature, you need to be running OpenFGA v1.5.7+ with the experimental flag | ||
`enable-consistency-params` enabled. See the [v1.5.7 release notes](https://github.com/openfga/openfga/releases/tag/v1.5.7) for details. | ||
## v0.6.1 | ||
@@ -4,0 +11,0 @@ |
@@ -158,2 +158,8 @@ /** | ||
context?: object; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof CheckRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
@@ -289,2 +295,12 @@ /** | ||
/** | ||
* - 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} | ||
*/ | ||
export declare enum ConsistencyPreference { | ||
Unspecified = "UNSPECIFIED", | ||
MinimizeLatency = "MINIMIZE_LATENCY", | ||
HigherConsistency = "HIGHER_CONSISTENCY" | ||
} | ||
/** | ||
* | ||
@@ -438,2 +454,8 @@ * @export | ||
authorization_model_id?: string; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof ExpandRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
@@ -632,2 +654,8 @@ /** | ||
context?: object; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof ListObjectsRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
@@ -708,2 +736,8 @@ /** | ||
context?: object; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof ListUsersRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
@@ -951,2 +985,8 @@ /** | ||
continuation_token?: string; | ||
/** | ||
* | ||
* @type {ConsistencyPreference} | ||
* @memberof ReadRequest | ||
*/ | ||
consistency?: ConsistencyPreference; | ||
} | ||
@@ -953,0 +993,0 @@ /** |
@@ -16,4 +16,15 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnprocessableContentErrorCode = 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 = exports.ConsistencyPreference = 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 ConsistencyPreference; | ||
(function (ConsistencyPreference) { | ||
ConsistencyPreference["Unspecified"] = "UNSPECIFIED"; | ||
ConsistencyPreference["MinimizeLatency"] = "MINIMIZE_LATENCY"; | ||
ConsistencyPreference["HigherConsistency"] = "HIGHER_CONSISTENCY"; | ||
})(ConsistencyPreference || (exports.ConsistencyPreference = ConsistencyPreference = {})); | ||
/** | ||
* | ||
@@ -20,0 +31,0 @@ * @export |
@@ -14,3 +14,3 @@ /** | ||
import { OpenFgaApi } from "./api"; | ||
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 { 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 { BaseAPI } from "./base"; | ||
@@ -51,4 +51,8 @@ import { PromiseResult } from "./common"; | ||
} | ||
export interface ConsistencyOpts { | ||
consistency?: ConsistencyPreference; | ||
} | ||
export type ClientRequestOptsWithStoreId = ClientRequestOpts & StoreIdOpts; | ||
export type ClientRequestOptsWithAuthZModelId = ClientRequestOpts & StoreIdOpts & AuthorizationModelIdOpts; | ||
export type ClientRequestOptsWithConsistency = ClientRequestOpts & StoreIdOpts & AuthorizationModelIdOpts & ConsistencyOpts; | ||
export type PaginationOptions = { | ||
@@ -109,9 +113,9 @@ pageSize?: number; | ||
export type ClientReadRequest = ReadRequestTupleKey; | ||
export type ClientListObjectsRequest = Omit<ListObjectsRequest, "authorization_model_id" | "contextual_tuples"> & { | ||
export type ClientListObjectsRequest = Omit<ListObjectsRequest, "authorization_model_id" | "contextual_tuples" | "consistency"> & { | ||
contextualTuples?: Array<TupleKey>; | ||
}; | ||
export type ClientListUsersRequest = Omit<ListUsersRequest, "authorization_model_id" | "contextual_tuples"> & { | ||
export type ClientListUsersRequest = Omit<ListUsersRequest, "authorization_model_id" | "contextual_tuples" | "consistency"> & { | ||
contextualTuples?: Array<TupleKey>; | ||
}; | ||
export type ClientListRelationsRequest = Omit<ClientCheckRequest, "relation"> & { | ||
export type ClientListRelationsRequest = Omit<ClientCheckRequest, "relation" | "consistency"> & { | ||
relations?: string[]; | ||
@@ -246,6 +250,7 @@ }; | ||
* @param {ClientReadRequest} body | ||
* @param {ClientRequestOpts & PaginationOptions} [options] | ||
* @param {ClientRequestOpts & PaginationOptions & ConsistencyOpts} [options] | ||
* @param {number} [options.pageSize] | ||
* @param {string} [options.continuationToken] | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
* @param {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -255,3 +260,3 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
*/ | ||
read(body?: ClientReadRequest, options?: ClientRequestOptsWithStoreId & PaginationOptions): PromiseResult<ReadResponse>; | ||
read(body?: ClientReadRequest, options?: ClientRequestOptsWithStoreId & PaginationOptions & ConsistencyOpts): PromiseResult<ReadResponse>; | ||
/** | ||
@@ -308,5 +313,6 @@ * Write - Create or delete relationship tuples | ||
* @param {ClientCheckRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -316,3 +322,3 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
*/ | ||
check(body: ClientCheckRequest, options?: ClientRequestOptsWithAuthZModelId): PromiseResult<CheckResponse>; | ||
check(body: ClientCheckRequest, options?: ClientRequestOptsWithConsistency): PromiseResult<CheckResponse>; | ||
/** | ||
@@ -329,3 +335,3 @@ * BatchCheck - Run a set of checks (evaluates) | ||
*/ | ||
batchCheck(body: ClientBatchCheckRequest, options?: ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts): Promise<ClientBatchCheckResponse>; | ||
batchCheck(body: ClientBatchCheckRequest, options?: ClientRequestOptsWithConsistency & BatchCheckRequestOpts): Promise<ClientBatchCheckResponse>; | ||
/** | ||
@@ -336,5 +342,6 @@ * Expand - Expands the relationships in userset tree format (evaluates) | ||
* @param {string} body.object The object, must be of the form: `<type>:<id>` | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -344,9 +351,10 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
*/ | ||
expand(body: ClientExpandRequest, options?: ClientRequestOptsWithAuthZModelId): PromiseResult<ExpandResponse>; | ||
expand(body: ClientExpandRequest, options?: ClientRequestOptsWithConsistency): PromiseResult<ExpandResponse>; | ||
/** | ||
* ListObjects - List the objects of a particular type that the user has a certain relation to (evaluates) | ||
* @param {ClientListObjectsRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -356,3 +364,3 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
*/ | ||
listObjects(body: ClientListObjectsRequest, options?: ClientRequestOptsWithAuthZModelId): PromiseResult<ListObjectsResponse>; | ||
listObjects(body: ClientListObjectsRequest, options?: ClientRequestOptsWithConsistency): PromiseResult<ListObjectsResponse>; | ||
/** | ||
@@ -368,9 +376,10 @@ * ListRelations - List all the relations a user has with an object (evaluates) | ||
*/ | ||
listRelations(listRelationsRequest: ClientListRelationsRequest, options?: ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts): Promise<ClientListRelationsResponse>; | ||
listRelations(listRelationsRequest: ClientListRelationsRequest, options?: ClientRequestOptsWithConsistency & 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 {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -380,3 +389,3 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
*/ | ||
listUsers(body: ClientListUsersRequest, options?: ClientRequestOptsWithAuthZModelId): PromiseResult<ListUsersResponse>; | ||
listUsers(body: ClientListUsersRequest, options?: ClientRequestOptsWithConsistency): PromiseResult<ListUsersResponse>; | ||
/************** | ||
@@ -383,0 +392,0 @@ * Assertions * |
@@ -232,6 +232,7 @@ "use strict"; | ||
* @param {ClientReadRequest} body | ||
* @param {ClientRequestOpts & PaginationOptions} [options] | ||
* @param {ClientRequestOpts & PaginationOptions & ConsistencyOpts} [options] | ||
* @param {number} [options.pageSize] | ||
* @param {string} [options.continuationToken] | ||
* @param {object} [options.headers] - Custom headers to send alongside the request | ||
* @param {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -377,5 +378,6 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
* @param {ClientCheckRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -437,5 +439,6 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
* @param {string} body.object The object, must be of the form: `<type>:<id>` | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -454,5 +457,6 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
* @param {ClientListObjectsRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -506,5 +510,6 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request | ||
* @param {ClientListUsersRequest} body | ||
* @param {ClientRequestOptsWithAuthZModelId} [options] | ||
* @param {ClientRequestOptsWithConsistency} [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 {ConsistencyPreference} [options.consistency] - The consistency preference to use | ||
* @param {object} [options.retryParams] - Override the retry parameters for this request | ||
@@ -511,0 +516,0 @@ * @param {number} [options.retryParams.maxRetry] - Override the max number of retries on each API request |
@@ -20,3 +20,3 @@ "use strict"; | ||
const telemetry_1 = require("./telemetry"); | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.1"); | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.2"); | ||
const durationHist = meter.createHistogram("fga-client.request.duration", { | ||
@@ -23,0 +23,0 @@ description: "The duration of requests", |
@@ -23,3 +23,3 @@ "use strict"; | ||
const DEFAULT_MIN_WAIT_MS = 100; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.6.1"; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.6.2"; | ||
function GetDefaultRetryParams(maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) { | ||
@@ -123,2 +123,2 @@ return { | ||
*/ | ||
Configuration.sdkVersion = "0.6.1"; | ||
Configuration.sdkVersion = "0.6.2"; |
@@ -49,3 +49,3 @@ "use strict"; | ||
case types_1.CredentialsMethod.ClientCredentials: { | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.1"); | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.2"); | ||
this.tokenCounter = meter.createCounter("fga-client.credentials.request"); | ||
@@ -52,0 +52,0 @@ break; |
{ | ||
"name": "@openfga/sdk", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "JavaScript and Node.js SDK for OpenFGA", | ||
@@ -32,3 +32,3 @@ "author": "OpenFGA", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.12.7", | ||
"@types/node": "^22.0.0", | ||
"@types/tiny-async-pool": "^2.0.3", | ||
@@ -35,0 +35,0 @@ "@typescript-eslint/eslint-plugin": "^7.7.1", |
@@ -717,3 +717,3 @@ # JavaScript and Node.js SDK for OpenFGA | ||
This 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) | ||
This 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) | ||
@@ -720,0 +720,0 @@ ## Contributing |
1405474
6843