diff --git a/src/lambda/formatters.ts b/src/lambda/formatters.ts index d9103be..322b001 100644 --- a/src/lambda/formatters.ts +++ b/src/lambda/formatters.ts @@ -2,12 +2,13 @@ import jsonBigInt from 'json-bigint' import { isObject } from '../object' -export const formattedResponse = ({ StatusCode, Payload }: { StatusCode?: any, Payload?: any }): object => { +export const formattedResponse = ({ StatusCode, Payload }: { StatusCode?: number, Payload?: any }): object => { const payloadFormatted = JSON.parse(Payload || '{}') return { status: payloadFormatted.statusCode || StatusCode, - body: payloadFormatted.body ? JSON.parse(payloadFormatted.body) : {} + body: payloadFormatted.body ? JSON.parse(payloadFormatted.body) : {}, + ...(payloadFormatted.headers ? { headers: JSON.parse(payloadFormatted.headers) } : null) } } diff --git a/src/lambda/interfaces.ts b/src/lambda/interfaces.ts index 48b3406..9f07f6a 100644 --- a/src/lambda/interfaces.ts +++ b/src/lambda/interfaces.ts @@ -7,6 +7,10 @@ export interface Error { message?: string } +export type Headers = { + [header: string]: string | number | boolean +} + export interface lambdaParameters { port?: string region?: string diff --git a/src/lambda/lambdaResponses.ts b/src/lambda/lambdaResponses.ts index 278dab8..22686ca 100644 --- a/src/lambda/lambdaResponses.ts +++ b/src/lambda/lambdaResponses.ts @@ -1,11 +1,12 @@ import { isNumber } from '../number' import { objToStr } from '../object' import { ProxyResult } from 'aws-lambda' -import type { Error } from './interfaces' +import type { Error, Headers } from './interfaces' -export const lambdaResp = (statusCode: number, body?: object | string): ProxyResult => ({ +export const lambdaResp = (statusCode: number, body?: object | string, headers?: Headers): ProxyResult => ({ statusCode, - ...(body ? { body: objToStr(body) } : { body: '' }) + ...(body ? { body: objToStr(body) } : { body: '' }), + ...(headers ? { headers } : null) }) export const lambdaRespError = (err: Error): ProxyResult => {