Skip to content

Commit a06cf01

Browse files
committed
add missing option params to all methods
1 parent b6d9219 commit a06cf01

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

packages/plexus-api/src/api.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,17 @@ export class ApiInstance {
282282
* @param {string} path The url to send the request to
283283
* @param {Record<string, any>} query The url query to send
284284
*/
285-
get<ResponseType = any>(path: string, query?: Record<string, any>) {
285+
get<ResponseType = any>(
286+
path: string,
287+
query?: Record<string, any>,
288+
options?: PlexusApiOptions
289+
) {
286290
const params = new URLSearchParams(query)
287291

288292
return this.send<ResponseType>(
289293
`${path}${params.toString().length > 0 ? `?${params.toString()}` : ''}`,
290294
{
295+
...options,
291296
method: 'GET',
292297
}
293298
)
@@ -302,9 +307,14 @@ export class ApiInstance {
302307
async post<
303308
ResponseType = any,
304309
BodyType extends Record<string, any> | string = {},
305-
>(path: string, body: BodyType = {} as BodyType) {
310+
>(
311+
path: string,
312+
body: BodyType = {} as BodyType,
313+
reqOptions = {} as PlexusApiOptions
314+
) {
306315
const bodyString = typeof body === 'string' ? body : JSON.stringify(body)
307316
const options = {
317+
...reqOptions,
308318
method: 'POST',
309319
body: bodyString,
310320
} as const
@@ -330,12 +340,14 @@ export class ApiInstance {
330340
*/
331341
put<ResponseType = any>(
332342
path: string,
333-
body: Record<string, any> | string = {}
343+
body: Record<string, any> | string = {},
344+
options?: PlexusApiOptions
334345
) {
335346
if (typeof body !== 'string') {
336347
body = JSON.stringify(body)
337348
}
338349
return this.send<ResponseType>(path, {
350+
...options,
339351
method: 'PUT',
340352
body,
341353
})
@@ -347,12 +359,14 @@ export class ApiInstance {
347359
*/
348360
delete<ResponseType = any>(
349361
path: string,
350-
body: Record<string, any> | string = {}
362+
body: Record<string, any> | string = {},
363+
options?: PlexusApiOptions
351364
) {
352365
if (typeof body !== 'string') {
353366
body = JSON.stringify(body)
354367
}
355368
return this.send<ResponseType>(path, {
369+
...options,
356370
method: 'DELETE',
357371
body,
358372
})
@@ -365,12 +379,14 @@ export class ApiInstance {
365379
*/
366380
patch<ResponseType = any>(
367381
path: string,
368-
body: Record<string, any> | string = {}
382+
body: Record<string, any> | string = {},
383+
options?: PlexusApiOptions
369384
) {
370385
if (typeof body !== 'string') {
371386
body = JSON.stringify(body)
372387
}
373388
return this.send<ResponseType>(path, {
389+
...options,
374390
method: 'PATCH',
375391
body,
376392
})
@@ -381,10 +397,15 @@ export class ApiInstance {
381397
* @param {Record<string, any>} variables Variables
382398
* @returns {Promise<PlexusApiRes<unknown>>} The response from the server
383399
*/
384-
gql<ResponseType = any>(query: string, variables?: Record<string, any>) {
400+
gql<ResponseType = any>(
401+
query: string,
402+
variables?: Record<string, any>,
403+
options?: PlexusApiOptions
404+
) {
385405
this._headers.set('Content-Type', 'application/json')
386406

387407
return this.send<ResponseType>('', {
408+
...options,
388409
method: 'POST',
389410
body: JSON.stringify({
390411
query,

0 commit comments

Comments
 (0)