@@ -44,7 +44,7 @@ import {
44
44
import { BaseAPI } from "./base" ;
45
45
import { CallResult , PromiseResult } from "./common" ;
46
46
import { Configuration , RetryParams , UserConfigurationParams } from "./configuration" ;
47
- import { FgaRequiredParamError , FgaValidationError } from "./errors" ;
47
+ import { FgaApiAuthenticationError , FgaRequiredParamError , FgaValidationError } from "./errors" ;
48
48
import {
49
49
chunkArray ,
50
50
generateRandomIdWithNonUniqueFallback ,
@@ -395,48 +395,50 @@ export class OpenFgaClient extends BaseAPI {
395
395
} ;
396
396
}
397
397
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 ;
418
407
}
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
+ }
420
420
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 ;
433
427
}
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
+ }
435
440
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 ( ) } ;
440
442
}
441
443
442
444
/**
@@ -518,36 +520,32 @@ export class OpenFgaClient extends BaseAPI {
518
520
* @param {number } [options.retryParams.minWaitInMs] - Override the minimum wait before a retry is initiated
519
521
*/
520
522
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 ;
545
536
}
546
537
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 } ;
551
549
}
552
550
553
551
/**
0 commit comments