Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support server-side batch check endpoiont #185

Merged
merged 18 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
.github/ISSUE_TEMPLATE/config.yaml
.github/ISSUE_TEMPLATE/feature_request.yaml
.github/dependabot.yaml
.github/workflows/main.yaml
.github/workflows/semgrep.yaml
.gitignore
.gitignore
.madgerc
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
- fix: error correctly if apiUrl is not provided (#161)
- feat: add support for `start_time` parameter in `ReadChanges` endpoint
- BREAKING: As of this release, the min node version required by the SDK is now v16.15.0
- feat!: add support for server-side `BatchCheck` method.

BREAKING CHNAGES:

- The minimum noce 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

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ yarn add @openfga/sdk

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.

#### No Credentials

Expand Down Expand Up @@ -446,7 +446,7 @@ const result = await fgaClient.check({
##### Batch Check

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.

```javascript
const options = {
Expand Down Expand Up @@ -667,7 +667,7 @@ const response = await fgaClient.writeAssertions([{

### 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.
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.

Expand Down
84 changes: 84 additions & 0 deletions api.ts

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions apiModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,123 @@ export interface AuthorizationModel {
*/
conditions?: { [key: string]: Condition; };
}
/**
*
* @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
Expand Down
Loading
Loading