Skip to content

Commit

Permalink
feat(runtime-types): add cookie/header support for types (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkundel authored Jul 13, 2021
1 parent e9ef02e commit e04fbcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/serverless-runtime-types/example/functions/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
23 changes: 18 additions & 5 deletions packages/serverless-runtime-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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<T>,
event: U,
Expand Down

0 comments on commit e04fbcb

Please sign in to comment.