Skip to content

Commit 18c8f03

Browse files
authored
feat!: support server-side batch check endpoiont (#185)
2 parents 24f8188 + 55a053f commit 18c8f03

File tree

14 files changed

+689
-36
lines changed

14 files changed

+689
-36
lines changed

.openapi-generator/FILES

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
.github/ISSUE_TEMPLATE/config.yaml
88
.github/ISSUE_TEMPLATE/feature_request.yaml
99
.github/dependabot.yaml
10-
.github/workflows/main.yaml
11-
.github/workflows/semgrep.yaml
1210
.gitignore
1311
.gitignore
1412
.madgerc

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
- fix: error correctly if apiUrl is not provided (#161)
77
- feat: add support for `start_time` parameter in `ReadChanges` endpoint
88
- BREAKING: As of this release, the min node version required by the SDK is now v16.15.0
9+
- feat!: add support for server-side `BatchCheck` method.
10+
11+
BREAKING CHNAGES:
12+
13+
- The minimum noce version required by this SDK is now v16.15.0
14+
- 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`.
915

1016
## v0.7.0
1117

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ yarn add @openfga/sdk
8989

9090
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.
9191

92-
> The `OpenFgaClient` will by default retry API requests up to 15 times on 429 and 5xx errors.
92+
> The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors.
9393
9494
#### No Credentials
9595

@@ -446,7 +446,7 @@ const result = await fgaClient.check({
446446
##### Batch Check
447447

448448
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.
449-
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up.
449+
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
450450

451451
```javascript
452452
const options = {
@@ -667,7 +667,7 @@ const response = await fgaClient.writeAssertions([{
667667

668668
### Retries
669669

670-
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.
670+
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.
671671

672672
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.
673673

api.ts

Lines changed: 84 additions & 0 deletions
Large diffs are not rendered by default.

apiModel.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,123 @@ export interface AuthorizationModel {
152152
*/
153153
conditions?: { [key: string]: Condition; };
154154
}
155+
/**
156+
*
157+
* @export
158+
* @interface BatchCheckItem
159+
*/
160+
export interface BatchCheckItem {
161+
/**
162+
*
163+
* @type {CheckRequestTupleKey}
164+
* @memberof BatchCheckItem
165+
*/
166+
tuple_key: CheckRequestTupleKey;
167+
/**
168+
*
169+
* @type {ContextualTupleKeys}
170+
* @memberof BatchCheckItem
171+
*/
172+
contextual_tuples?: ContextualTupleKeys;
173+
/**
174+
*
175+
* @type {object}
176+
* @memberof BatchCheckItem
177+
*/
178+
context?: object;
179+
/**
180+
* correlation_id must be a string containing only letters, numbers, or hyphens, with length ≤ 36 characters.
181+
* @type {string}
182+
* @memberof BatchCheckItem
183+
*/
184+
correlation_id: string;
185+
}
186+
/**
187+
*
188+
* @export
189+
* @interface BatchCheckRequest
190+
*/
191+
export interface BatchCheckRequest {
192+
/**
193+
*
194+
* @type {Array<BatchCheckItem>}
195+
* @memberof BatchCheckRequest
196+
*/
197+
checks: Array<BatchCheckItem>;
198+
/**
199+
*
200+
* @type {string}
201+
* @memberof BatchCheckRequest
202+
*/
203+
authorization_model_id?: string;
204+
/**
205+
*
206+
* @type {ConsistencyPreference}
207+
* @memberof BatchCheckRequest
208+
*/
209+
consistency?: ConsistencyPreference;
210+
}
211+
212+
213+
/**
214+
*
215+
* @export
216+
* @interface BatchCheckResponse
217+
*/
218+
export interface BatchCheckResponse {
219+
/**
220+
* map keys are the correlation_id values from the BatchCheckItems in the request
221+
* @type {{ [key: string]: BatchCheckSingleResult; }}
222+
* @memberof BatchCheckResponse
223+
*/
224+
result?: { [key: string]: BatchCheckSingleResult; };
225+
}
226+
/**
227+
*
228+
* @export
229+
* @interface BatchCheckSingleResult
230+
*/
231+
export interface BatchCheckSingleResult {
232+
/**
233+
*
234+
* @type {boolean}
235+
* @memberof BatchCheckSingleResult
236+
*/
237+
allowed?: boolean;
238+
/**
239+
*
240+
* @type {CheckError}
241+
* @memberof BatchCheckSingleResult
242+
*/
243+
error?: CheckError;
244+
}
245+
/**
246+
*
247+
* @export
248+
* @interface CheckError
249+
*/
250+
export interface CheckError {
251+
/**
252+
*
253+
* @type {ErrorCode}
254+
* @memberof CheckError
255+
*/
256+
input_error?: ErrorCode;
257+
/**
258+
*
259+
* @type {InternalErrorCode}
260+
* @memberof CheckError
261+
*/
262+
internal_error?: InternalErrorCode;
263+
/**
264+
*
265+
* @type {string}
266+
* @memberof CheckError
267+
*/
268+
message?: string;
269+
}
270+
271+
155272
/**
156273
*
157274
* @export

0 commit comments

Comments
 (0)