From c4975bfa13fe7b35be153fbc0ac697486fece1c2 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Mon, 6 May 2024 20:24:48 -0700 Subject: [PATCH] headers for api witness --- packages/payloadset/packages/api/src/Config.ts | 1 + packages/payloadset/packages/api/src/Payload.ts | 1 + packages/payloadset/packages/api/src/Witness.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/payloadset/packages/api/src/Config.ts b/packages/payloadset/packages/api/src/Config.ts index 6596d8069..74583bdc0 100644 --- a/packages/payloadset/packages/api/src/Config.ts +++ b/packages/payloadset/packages/api/src/Config.ts @@ -9,6 +9,7 @@ export type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema export type ApiCallWitnessConfigBase = WitnessConfig<{ accept?: 'application/json' + headers?: Record queries?: ApiCall['queries'] schema: ApiCallWitnessConfigSchema timeout?: number diff --git a/packages/payloadset/packages/api/src/Payload.ts b/packages/payloadset/packages/api/src/Payload.ts index 5ccf652ef..f527c7e8f 100644 --- a/packages/payloadset/packages/api/src/Payload.ts +++ b/packages/payloadset/packages/api/src/Payload.ts @@ -9,6 +9,7 @@ export type Verb = 'get' | 'post' export type Queries = Record export interface ApiCallFields { + headers?: Record queries?: Queries verb?: Verb } diff --git a/packages/payloadset/packages/api/src/Witness.ts b/packages/payloadset/packages/api/src/Witness.ts index 410e59150..975b9ecbd 100644 --- a/packages/payloadset/packages/api/src/Witness.ts +++ b/packages/payloadset/packages/api/src/Witness.ts @@ -78,6 +78,10 @@ export class ApiCallWitness): Record { + return { ...this.params.headers, ...this.config.headers, ...headers } + } + protected override async observeHandler(inPayloads: ApiCall[] = []): Promise { await this.started('throw') try { @@ -110,7 +114,7 @@ export class ApiCallWitness { + private async httpGet(url: string, call: Hash, headers?: Record): Promise { const result: ApiCallResult = { call, schema: ApiCallResultSchema, @@ -118,7 +122,7 @@ export class ApiCallWitness(url) if (response.status >= 200 && response.status < 300) { const jsonResult = result as ApiCallJsonResult