diff --git a/packages/serverless-runtime-types/example/functions/demo.js b/packages/serverless-runtime-types/example/functions/demo.js index cb2cef1f..4a8b327a 100644 --- a/packages/serverless-runtime-types/example/functions/demo.js +++ b/packages/serverless-runtime-types/example/functions/demo.js @@ -2,11 +2,12 @@ /** * @param {import('@twilio-labs/serverless-runtime-types').Context} context - * @param {{}} event + * @param {import('@twilio-labs/serverless-runtime-types').ServerlessEventObject<{}, {}, { token: string }>} event * @param {import('@twilio-labs/serverless-runtime-types').ServerlessCallback} callback */ -exports.handler = function(context, event, callback) { +exports.handler = function (context, event, callback) { let twiml = new Twilio.twiml.MessagingResponse(); + console.log(event.cookies.token); twiml.message('Hello World'); callback(null, twiml); }; diff --git a/packages/serverless-runtime-types/types.d.ts b/packages/serverless-runtime-types/types.d.ts index ccc0018a..60c5e5c3 100644 --- a/packages/serverless-runtime-types/types.d.ts +++ b/packages/serverless-runtime-types/types.d.ts @@ -22,10 +22,12 @@ export type AssetResourceMap = { }; export interface TwilioResponse { - setStatusCode(code: number): void; - setBody(body: string | object): void; - appendHeader(key: string, value: string): void; - setHeaders(headers: { [key: string]: string }): void; + setStatusCode(code: number): TwilioResponse; + setBody(body: string | object): TwilioResponse; + appendHeader(key: string, value: string): TwilioResponse; + setHeaders(headers: { [key: string]: string }): TwilioResponse; + setCookie(key: string, value: string, attributes?: string[]): TwilioResponse; + removeCookie(key: string): TwilioResponse; } export type RuntimeSyncClientOptions = TwilioClientOptions & { @@ -53,9 +55,20 @@ export type ServerlessCallback = ( payload?: object | string | number | boolean ) => void; +export type ServerlessEventObject< + RequestBodyAndQuery = {}, + Headers = {}, + Cookies = {} +> = { + request: { + cookies: Cookies; + headers: Headers; + }; +} & RequestBodyAndQuery; + export type ServerlessFunctionSignature< T extends EnvironmentVariables = {}, - U extends {} = {} + U extends ServerlessEventObject = { request: { cookies: {}; headers: {} } } > = ( context: Context, event: U,