Skip to content

Commit

Permalink
fix: raw response in client check (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Aug 18, 2023
2 parents 12414f3 + 9ddda5e commit ddf5f76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,7 @@ export class OpenFgaClient extends BaseAPI {
},
contextual_tuples: { tuple_keys: body.contextualTuples || [] },
authorization_model_id: this.getAuthorizationModelId(options)
}, options).then(response => ({
...response,
allowed: response.allowed || false,
}));
}, options);
}

/**
Expand All @@ -523,20 +520,16 @@ export class OpenFgaClient extends BaseAPI {

const responses: ClientBatchCheckSingleResponse[] = [];
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers })
.then(({ allowed, $response: response }) => {
const result = {
allowed: allowed || false,
_request: tuple,
};
setNotEnumerableProperty(result, "$response", response);
return result as ClientBatchCheckSingleResponse;
.then(response => {
(response as ClientBatchCheckSingleResponse)._request = tuple;
return response as ClientBatchCheckSingleResponse;
})
.catch(err => {
return {
allowed: false,
allowed: undefined,
error: err,
_request: tuple,
} as unknown as ClientBatchCheckSingleResponse;
};
})
)) {
responses.push(singleCheckResponse);
Expand Down
2 changes: 1 addition & 1 deletion tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ describe("OpenFGA Client", () => {
.toMatchObject(expect.arrayContaining([
{ _request: tuples[0], allowed: true, },
{ _request: tuples[1], allowed: false },
{ _request: tuples[2], allowed: false, error: expect.any(Error) },
{ _request: tuples[2], error: expect.any(Error) },
]));
});
});
Expand Down

0 comments on commit ddf5f76

Please sign in to comment.