Skip to content

Commit 5e3a6f4

Browse files
authored
release: v0.3.3 (#70)
2 parents 385c945 + 8b78e1d commit 5e3a6f4

File tree

5 files changed

+303
-314
lines changed

5 files changed

+303
-314
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Changelog
22

3+
## v0.3.3
4+
5+
### [0.3.3](https://github.com/openfga/js-sdk/compare/v0.3.2...v0.3.3) (2024-02-26)
6+
7+
- fix: do not call ReadAuthorizationModel on BatchCheck or non-Transactional Write
8+
39
## v0.3.2
410

5-
### [0.3.1](https://github.com/openfga/js-sdk/compare/v0.3.1...v0.3.2) (2024-02-13)
11+
### [0.3.2](https://github.com/openfga/js-sdk/compare/v0.3.1...v0.3.2) (2024-02-13)
612

713
- feat: add example project
814
- feat: add support for `apiUrl` configuration option and deprecate `apiScheme` and `apiHost`

client.ts

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
import { BaseAPI } from "./base";
4545
import { CallResult, PromiseResult } from "./common";
4646
import { Configuration, RetryParams, UserConfigurationParams } from "./configuration";
47-
import { FgaRequiredParamError, FgaValidationError } from "./errors";
47+
import {FgaApiAuthenticationError, FgaRequiredParamError, FgaValidationError} from "./errors";
4848
import {
4949
chunkArray,
5050
generateRandomIdWithNonUniqueFallback,
@@ -395,48 +395,50 @@ export class OpenFgaClient extends BaseAPI {
395395
};
396396
}
397397

398-
// We initiate two chains in parallel (to avoid unnecessary latency)
399-
// 1- the actual request that we'll return at the end
400-
// 2- a request to check whether the store ID, auth model ID, and credentials are valid
401-
return Promise.all([
402-
(async () => {
403-
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "Write");
404-
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());
405-
406-
const writeResponses: ClientWriteSingleResponse[][] = [];
407-
if (writes?.length) {
408-
for await (const singleChunkResponse of asyncPool(maxParallelRequests, chunkArray(writes, maxPerChunk),
409-
(chunk) => this.writeTuples(chunk,{ ...options, headers, transaction: undefined }).catch(err => ({
410-
writes: chunk.map(tuple => ({
411-
tuple_key: tuple,
412-
status: ClientWriteStatus.FAILURE,
413-
err,
414-
})),
415-
deletes: []
416-
})))) {
417-
writeResponses.push(singleChunkResponse.writes);
398+
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "Write");
399+
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());
400+
401+
const writeResponses: ClientWriteSingleResponse[][] = [];
402+
if (writes?.length) {
403+
for await (const singleChunkResponse of asyncPool(maxParallelRequests, chunkArray(writes, maxPerChunk),
404+
(chunk) => this.writeTuples(chunk,{ ...options, headers, transaction: undefined }).catch(err => {
405+
if (err instanceof FgaApiAuthenticationError) {
406+
throw err;
418407
}
419-
}
408+
return {
409+
writes: chunk.map(tuple => ({
410+
tuple_key: tuple,
411+
status: ClientWriteStatus.FAILURE,
412+
err,
413+
})),
414+
deletes: []
415+
};
416+
}))) {
417+
writeResponses.push(singleChunkResponse.writes);
418+
}
419+
}
420420

421-
const deleteResponses: ClientWriteSingleResponse[][] = [];
422-
if (deletes?.length) {
423-
for await (const singleChunkResponse of asyncPool(maxParallelRequests, chunkArray(deletes, maxPerChunk),
424-
(chunk) => this.deleteTuples(chunk, { ...options, headers, transaction: undefined }).catch(err => ({
425-
writes: [],
426-
deletes: chunk.map(tuple => ({
427-
tuple_key: tuple,
428-
status: ClientWriteStatus.FAILURE,
429-
err,
430-
}))
431-
})))) {
432-
deleteResponses.push(singleChunkResponse.deletes);
421+
const deleteResponses: ClientWriteSingleResponse[][] = [];
422+
if (deletes?.length) {
423+
for await (const singleChunkResponse of asyncPool(maxParallelRequests, chunkArray(deletes, maxPerChunk),
424+
(chunk) => this.deleteTuples(chunk, { ...options, headers, transaction: undefined }).catch(err => {
425+
if (err instanceof FgaApiAuthenticationError) {
426+
throw err;
433427
}
434-
}
428+
return {
429+
writes: [],
430+
deletes: chunk.map(tuple => ({
431+
tuple_key: tuple,
432+
status: ClientWriteStatus.FAILURE,
433+
err,
434+
})),
435+
};
436+
}))) {
437+
deleteResponses.push(singleChunkResponse.deletes);
438+
}
439+
}
435440

436-
return { writes: writeResponses.flat(), deletes: deleteResponses.flat() };
437-
})(),
438-
this.checkValidApiConnection(options),
439-
]).then(res => res[0]);
441+
return { writes: writeResponses.flat(), deletes: deleteResponses.flat() };
440442
}
441443

442444
/**
@@ -518,36 +520,32 @@ export class OpenFgaClient extends BaseAPI {
518520
* @param {number} [options.retryParams.minWaitInMs] - Override the minimum wait before a retry is initiated
519521
*/
520522
async batchCheck(body: ClientBatchCheckRequest, options: ClientRequestOptsWithAuthZModelId & BatchCheckRequestOpts = {}): Promise<ClientBatchCheckResponse> {
521-
// We initiate two chains in parallel (to avoid unnecessary latency)
522-
// 1- the actual request that we'll return at the end
523-
// 2- a request to check whether the store ID, auth model ID, and credentials are valid
524-
return Promise.all([
525-
(async () => {
526-
const { headers = {}, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS } = options;
527-
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "BatchCheck");
528-
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());
529-
530-
const responses: ClientBatchCheckSingleResponse[] = [];
531-
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers })
532-
.then(response => {
533-
(response as ClientBatchCheckSingleResponse)._request = tuple;
534-
return response as ClientBatchCheckSingleResponse;
535-
})
536-
.catch(err => {
537-
return {
538-
allowed: undefined,
539-
error: err,
540-
_request: tuple,
541-
};
542-
})
543-
)) {
544-
responses.push(singleCheckResponse);
523+
const { headers = {}, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS } = options;
524+
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "BatchCheck");
525+
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());
526+
527+
const responses: ClientBatchCheckSingleResponse[] = [];
528+
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers })
529+
.then(response => {
530+
(response as ClientBatchCheckSingleResponse)._request = tuple;
531+
return response as ClientBatchCheckSingleResponse;
532+
})
533+
.catch(err => {
534+
if (err instanceof FgaApiAuthenticationError) {
535+
throw err;
545536
}
546537

547-
return { responses };
548-
})(),
549-
this.checkValidApiConnection(options),
550-
]).then(res => res[0]);
538+
return {
539+
allowed: undefined,
540+
error: err,
541+
_request: tuple,
542+
};
543+
})
544+
)) {
545+
responses.push(singleCheckResponse);
546+
}
547+
548+
return { responses };
551549
}
552550

553551
/**

0 commit comments

Comments
 (0)