Skip to content

Commit

Permalink
Support JWT for batch requests
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Dec 4, 2021
1 parent 6098e30 commit 1d4effb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,29 @@ export class Remote {

batch(
batchObj: BatchArrayInput,
options?: { isNotification?: false },
options?: { isNotification?: false; jwt?: string },
): Promise<BatchArrayOutput>;
batch(
batchObj: BatchArrayInput,
options: { isNotification: true },
options: { isNotification: true; jwt?: string },
): Promise<undefined>;
batch(
batchObj: BatchObjectInput,
): Promise<BatchObjectOutput>;
batch(
batchObj: BatchArrayInput | BatchObjectInput,
{ isNotification }: { isNotification?: boolean } = {},
{ isNotification, jwt }: { isNotification?: boolean; jwt?: string } = {},
): Promise<
BatchArrayOutput | BatchObjectOutput | undefined
> {
return send(this.resource, {
...this.fetchInit,
headers: jwt
? new Headers([
...this.fetchInit.headers.entries(),
["Authorization", `Bearer ${jwt}`],
])
: this.fetchInit.headers,
body: JSON.stringify(
createRequestBatch(batchObj, isNotification),
),
Expand Down Expand Up @@ -130,7 +136,7 @@ export class Remote {
call(
method: RpcRequest["method"],
params: RpcRequest["params"],
options: { isNotification: true },
options: { isNotification: true; jwt?: string },
): Promise<undefined>;
call(
method: RpcRequest["method"],
Expand Down

0 comments on commit 1d4effb

Please sign in to comment.