Skip to content

Commit

Permalink
FRIDGE-814 upgrade to twilio 4.23.0, fix tests (#509)
Browse files Browse the repository at this point in the history
* FRIDGE-814 upgrade to twilio 4.23.0, fix tests

* improvement(@twilio-labs/serverless-runtime-types, @twilio/runtime-handler, twilio-run): Twilio SDK

Twilio SDK bump from 3.x to 4.23 with fixes to types, tests

BREAKING CHANGE: Underlying Twilio SDK was bumped by a major version, Twilio SDK 3.x to 4.23. This
might require changes in how importing this package will work.

fix #473 #483 #455

* FRIDGE-814 revert logger.ts

* FRIDGE-814 add changeset

* improvement(plugin-serverless plugin-assets runtime-handler serverless-api serverless-twilio-runtime

change node.js to 18 minimum in required and in docs where necessary

BREAKING CHANGE: minimum Node.js now 18

* FRIDGE-814 remove node 16 github actions, make it use npm@10

* FRIDGE-814 replace deprecated npm-run-all with a maintained fork

* FRIDGE-814 remove npm-run-all deps and convert commands to regular as the package seems broken on windows

* add typescript install explicitly

* Revert "FRIDGE-814 remove node 16 github actions, make it use npm@10"

This reverts commit 2ca5371.

* remove node 16

* update snapshots

* fix snapshots
  • Loading branch information
makserik authored Mar 20, 2024
1 parent 5d8247b commit 6d65bea
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .changeset/strong-pugs-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@twilio-labs/serverless-runtime-types': major
'@twilio/runtime-handler': major
'twilio-run': major
---

Twilio SDK from 3.x to 4.23.0. Required Node version bumped to 18 min.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [ lts/-2, lts/-1, lts/*]
node-version: [ lts/-1, lts/*]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ dist/
packages/serverless-api/docs/

.idea

**/.DS_Store
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ If you are planning to contribute something that does not have an open issue yet

## Requirements

Make sure you have Node.js 14 or newer installed. Due to compatibility with Twilio
Functions this project has to support at least Node.js 14.0.0.
Make sure you have Node.js 18 or newer installed. Due to compatibility with Twilio
Functions this project has to support at least Node.js 18.0.0.

We are using the npm CLI to manage our project. You'll need at least `npm` version 8 or newer.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@changesets/cli": "^2.26.0",
"@commitlint/cli": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@twilio/test-dep": "npm:twilio@3.84.0",
"@twilio/test-dep": "npm:twilio@4.23.0",
"@types/jest": "^29.2.4",
"all-contributors-cli": "^6.1.2",
"commitizen": "^4.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"rimraf": "^3.0.2"
},
"engines": {
"node": ">=14"
"node": ">=18"
},
"files": [
"/oclif.manifest.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"oclif": "^4.0.0"
},
"engines": {
"node": ">=14.0.0"
"node": ">=18.0.0"
},
"files": [
"/oclif.manifest.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { requireFromProject } from '../../../src/dev-runtime/utils/requireFromProject';

const PROJECT_DIR = join(__dirname, '../../../../twilio-run');

// only works if test-dep version is different from root package version
jest.mock('../../../../twilio-run/node_modules/@twilio/test-dep', () => {
const x = jest.genMockFromModule('@twilio/test-dep');
(x as any)['__TYPE__'] = 'PROJECT_BASED';
Expand Down
10 changes: 5 additions & 5 deletions packages/runtime-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
"build": "tsc",
"watch": "tsc --watch",
"build:noemit": "tsc --noEmit",
"clean": "rimraf ./dist"
"clean": "rimraf ./dist ./node_modules"
},
"devDependencies": {
"@twilio/test-dep": "npm:[email protected]",
"@types/common-tags": "^1.8.0",
"@types/cookie-parser": "^1.4.2",
"@types/debug": "^4.1.4",
"@types/express-useragent": "^0.2.21",
"@types/jest": "^26.0.24",
"@types/lodash.debounce": "^4.0.6",
"@types/node": "^14.0.19",
"@types/node": "^18.0.0",
"@types/supertest": "^2.0.8",
"npm-run-all": "^4.1.5",
"rimraf": "^2.6.3",
"supertest": "^3.1.0",
"typescript": "^4.9.4",
"@twilio/test-dep": "npm:[email protected]"
"typescript": "^4.9.4"
},
"bugs": {
"url": "https://github.com/twilio-labs/serverless-toolkit/issues"
Expand All @@ -69,7 +69,7 @@
"nocache": "^2.1.0",
"normalize.css": "^8.0.1",
"serialize-error": "^7.0.1",
"twilio": "3.80.0"
"twilio": "4.23.0"
},
"gitHead": "6db273648ed19474f4125042556b10c051529912"
}
2 changes: 1 addition & 1 deletion packages/serverless-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@types/mime-types": "^2.1.0",
"@types/node": "^14.17.19",
"@types/node": "^18.0.0",
"@types/recursive-readdir": "^2.2.0",
"debug": "^4.1.1",
"fast-redact": "^1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-runtime-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@types/express": "^4.17.11",
"@types/qs": "^6.9.4",
"twilio": "^4.20.1"
"twilio": "^4.23.0"
},
"devDependencies": {
"@types/express": "^4.17.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-twilio-runtime/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Serverless Framework plugin to deploy to the Twilio Runtime.

### Pre-requisites

- Node.js v12.x (this is the runtime version supported by Twilio Functions)
- Node.js v18.x (this is the runtime version supported by Twilio Functions)
- Serverless CLI v1.50.0+. You can run npm i -g serverless if you don't already have it.
- A Twilio account. If you don't have one you can [sign up quickly](https://www.twilio.com/try-twilio).

Expand Down
35 changes: 28 additions & 7 deletions packages/twilio-run/__tests__/runtime/internal/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ test('has correct defaults', () => {
const response = new Response();
expect(response['body']).toBeNull();
expect(response['statusCode']).toBe(200);
expect(response['headers']).toEqual({});
expect(response['headers']).toEqual({
'Set-Cookie': [],
});
});

test('sets status code, body and headers from constructor', () => {
Expand All @@ -24,6 +26,7 @@ test('sets status code, body and headers from constructor', () => {
'Access-Control-Allow-Origin': 'example.com',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
'Access-Control-Allow-Headers': 'Content-Type',
'Set-Cookie': [],
});
});

Expand All @@ -45,7 +48,9 @@ test('sets body correctly', () => {

test('sets headers correctly', () => {
const response = new Response();
expect(response['headers']).toEqual({});
expect(response['headers']).toEqual({
'Set-Cookie': [],
});
response.setHeaders({
'Access-Control-Allow-Origin': 'example.com',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
Expand All @@ -64,26 +69,33 @@ test('sets headers correctly', () => {

test('appends a new header correctly', () => {
const response = new Response();
expect(response['headers']).toEqual({});
expect(response['headers']).toEqual({
'Set-Cookie': [],
});
response.appendHeader('Access-Control-Allow-Origin', 'dkundel.com');
expect(response['headers']).toEqual({
'Access-Control-Allow-Origin': 'dkundel.com',
'Set-Cookie': [],
});
response.appendHeader('Content-Type', 'application/json');
expect(response['headers']).toEqual({
'Access-Control-Allow-Origin': 'dkundel.com',
'Content-Type': 'application/json',
'Set-Cookie': [],
});
});

test('appends a header correctly with no existing one', () => {
const response = new Response();
expect(response['headers']).toEqual({});
expect(response['headers']).toEqual({
'Set-Cookie': [],
});
// @ts-ignore
response['headers'] = undefined;
response.appendHeader('Access-Control-Allow-Origin', 'dkundel.com');
expect(response['headers']).toEqual({
'Access-Control-Allow-Origin': 'dkundel.com',
'Set-Cookie': [],
});
});

Expand Down Expand Up @@ -121,7 +133,10 @@ test('calls express response correctly', () => {

expect(mockRes.send).toHaveBeenCalledWith(`I'm a teapot!`);
expect(mockRes.status).toHaveBeenCalledWith(418);
expect(mockRes.set).toHaveBeenCalledWith({ 'Content-Type': 'text/plain' });
expect(mockRes.set).toHaveBeenCalledWith({
'Content-Type': 'text/plain',
'Set-Cookie': [],
});
});

test('serializes a response', () => {
Expand All @@ -134,7 +149,10 @@ test('serializes a response', () => {

expect(serialized.body).toEqual("I'm a teapot!");
expect(serialized.statusCode).toEqual(418);
expect(serialized.headers).toEqual({ 'Content-Type': 'text/plain' });
expect(serialized.headers).toEqual({
'Content-Type': 'text/plain',
'Set-Cookie': [],
});
});

test('serializes a response with content type set to application/json', () => {
Expand All @@ -149,5 +167,8 @@ test('serializes a response with content type set to application/json', () => {
JSON.stringify({ url: 'https://dkundel.com' })
);
expect(serialized.statusCode).toEqual(200);
expect(serialized.headers).toEqual({ 'Content-Type': 'application/json' });
expect(serialized.headers).toEqual({
'Content-Type': 'application/json',
'Set-Cookie': [],
});
});
10 changes: 5 additions & 5 deletions packages/twilio-run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"license": "MIT",
"dependencies": {
"@twilio-labs/serverless-api": "^5.5.1",
"@twilio-labs/serverless-runtime-types": "2.1.0-rc.0",
"@twilio-labs/serverless-runtime-types": "3.0.0",
"@types/express": "4.17.7",
"@types/inquirer": "^6.0.3",
"@types/is-ci": "^2.0.0",
Expand Down Expand Up @@ -76,7 +76,7 @@
"serialize-error": "^7.0.1",
"terminal-link": "^1.3.0",
"title": "^3.4.1",
"twilio": "^3.60.0",
"twilio": "^4.23.0",
"type-fest": "^0.15.1",
"window-size": "^1.1.1",
"wrap-ansi": "^7.0.0",
Expand All @@ -102,7 +102,7 @@
"@types/lodash.kebabcase": "^4.1.6",
"@types/lodash.startcase": "^4.4.6",
"@types/mock-fs": "^4.10.0",
"@types/node": "^14.0.19",
"@types/node": "^18.0.0",
"@types/prompts": "^2.0.1",
"@types/supertest": "^2.0.8",
"@types/title": "^1.0.5",
Expand All @@ -113,7 +113,7 @@
"nock": "^12.0.2",
"supertest": "^3.1.0",
"typescript": "^4.9.4",
"@twilio/test-dep": "npm:twilio@3.60.0"
"@twilio/test-dep": "npm:twilio@4.22.0"
},
"files": [
"bin/",
Expand All @@ -122,7 +122,7 @@
"README.md"
],
"engines": {
"node": ">=12.22.1"
"node": ">=18.0.0"
},
"gitHead": "6db273648ed19474f4125042556b10c051529912"
}
3 changes: 2 additions & 1 deletion packages/twilio-run/src/runtime/internal/functionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { serializeError } from 'serialize-error';
import { getRouteMap } from '../internal/route-cache';
import { constructContext, constructGlobalScope, isTwiml } from '../route';
import { Response } from './response';
import { Headers } from '@twilio/runtime-handler/dist/dev-runtime/types';

const sendDebugMessage = (debugMessage: string, ...debugArgs: any) => {
process.send && process.send({ debugMessage, debugArgs });
};

export type Reply = {
body?: string | number | boolean | object;
headers?: { [key: string]: number | string };
headers?: Headers;
statusCode: number;
};

Expand Down
Loading

0 comments on commit 6d65bea

Please sign in to comment.