Skip to content

Commit

Permalink
fix(js-sdk): raw response in client check (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Aug 18, 2023
2 parents 9c452a5 + d694c12 commit c60dd1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions config/clients/js/template/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,7 @@ export class {{appShortName}}Client 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 @@ -512,20 +509,16 @@ export class {{appShortName}}Client 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 config/clients/js/template/tests/client.test.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe("{{appTitleCaseName}} 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 c60dd1d

Please sign in to comment.