From 382b165b2ed448216f13f9ea51f96348e24a4c51 Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Tue, 28 Feb 2023 12:11:54 -0600 Subject: [PATCH 1/3] chore: upgraded serverless-runtime-types in twilio-run fixed typing issues that arose from using the upgraded package --- packages/twilio-run/package.json | 2 +- packages/twilio-run/src/runtime/internal/response.ts | 12 ++++++++++++ packages/twilio-run/src/runtime/route.ts | 12 ++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/twilio-run/package.json b/packages/twilio-run/package.json index 2ced79c0..930fa472 100644 --- a/packages/twilio-run/package.json +++ b/packages/twilio-run/package.json @@ -35,7 +35,7 @@ "license": "MIT", "dependencies": { "@twilio-labs/serverless-api": "^5.5.0", - "@twilio-labs/serverless-runtime-types": "2.1.0-rc.0", + "@twilio-labs/serverless-runtime-types": "^2.2.3", "@types/express": "4.17.7", "@types/inquirer": "^6.0.3", "@types/is-ci": "^2.0.0", diff --git a/packages/twilio-run/src/runtime/internal/response.ts b/packages/twilio-run/src/runtime/internal/response.ts index f21442e7..bfee253d 100644 --- a/packages/twilio-run/src/runtime/internal/response.ts +++ b/packages/twilio-run/src/runtime/internal/response.ts @@ -57,6 +57,18 @@ export class Response implements TwilioResponse { return this; } + setCookie( + key: string, + value: string, + attributes?: string[] | undefined + ): Response { + return this; + } + + removeCookie(key: string): Response { + return this; + } + appendHeader(key: string, value: HeaderValue): Response { debug('Appending header for %s', key, value); this.headers = this.headers || {}; diff --git a/packages/twilio-run/src/runtime/route.ts b/packages/twilio-run/src/runtime/route.ts index 6616afaa..760ecc7b 100644 --- a/packages/twilio-run/src/runtime/route.ts +++ b/packages/twilio-run/src/runtime/route.ts @@ -1,6 +1,7 @@ import { Context, ServerlessCallback, + ServerlessEventObject, ServerlessFunctionSignature, } from '@twilio-labs/serverless-runtime-types/types'; import { fork } from 'child_process'; @@ -62,7 +63,14 @@ export function constructContext( } const DOMAIN_NAME = url.replace(/^https?:\/\//, ''); const PATH = functionPath; - return { PATH, DOMAIN_NAME, ...env, getTwilioClient }; + return { + PATH, + DOMAIN_NAME, + ...env, + getTwilioClient, + SERVICE_SID: env.SERVICE_SID, + ENVIRONMENT_SID: env.ENVIRONMENT_SID, + }; } export function constructGlobalScope(config: StartCliConfig): void { @@ -205,7 +213,7 @@ export function functionToRoute( res: ExpressResponse, next: NextFunction ) { - const event = constructEvent(req); + const event = constructEvent(req); debug('Event for %s: %o', req.path, event); const context = constructContext(config, req.path); debug('Context for %s: %p', req.path, context); From d855ac001ce2cf7ec09a96a92bf59770b6f91d1a Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Tue, 28 Feb 2023 12:29:34 -0600 Subject: [PATCH 2/3] chore: adding cookie functionality to Response Cookies are stored with a value and optional list of attributes --- .../twilio-run/src/runtime/internal/response.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/twilio-run/src/runtime/internal/response.ts b/packages/twilio-run/src/runtime/internal/response.ts index bfee253d..9053f18f 100644 --- a/packages/twilio-run/src/runtime/internal/response.ts +++ b/packages/twilio-run/src/runtime/internal/response.ts @@ -15,15 +15,25 @@ type Headers = { [key: string]: HeaderValue; }; +type CookieValue = { + value: string; + attributes?: string[] | undefined; +}; +type Cookies = { + [key: string]: CookieValue; +}; + export class Response implements TwilioResponse { private body: null | any; private statusCode: number; private headers: Headers; + private cookies: Cookies; constructor(options?: ResponseOptions) { this.body = null; this.statusCode = 200; this.headers = {}; + this.cookies = {}; if (options && options.statusCode) { this.statusCode = options.statusCode; @@ -62,10 +72,14 @@ export class Response implements TwilioResponse { value: string, attributes?: string[] | undefined ): Response { + debug('Setting cookie %s', key, value, attributes); + this.cookies[key] = { value, attributes }; return this; } removeCookie(key: string): Response { + debug('Deleting cookie %s', key); + delete this.cookies[key]; return this; } From ad52bb6469dbec6ab9639db2754bcb500acdbb54 Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Tue, 28 Feb 2023 12:40:15 -0600 Subject: [PATCH 3/3] chore: added changeset details added changeset --- .changeset/nervous-dingos-ring.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nervous-dingos-ring.md diff --git a/.changeset/nervous-dingos-ring.md b/.changeset/nervous-dingos-ring.md new file mode 100644 index 00000000..187d822b --- /dev/null +++ b/.changeset/nervous-dingos-ring.md @@ -0,0 +1,5 @@ +--- +'twilio-run': minor +--- + +Upgraded serverless-runtime-types package and fixed typing errors that arose