Skip to content

Commit 6d65bea

Browse files
authored
FRIDGE-814 upgrade to twilio 4.23.0, fix tests (#509)
* 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
1 parent 5d8247b commit 6d65bea

File tree

17 files changed

+137
-39
lines changed

17 files changed

+137
-39
lines changed

.changeset/strong-pugs-battle.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@twilio-labs/serverless-runtime-types': major
3+
'@twilio/runtime-handler': major
4+
'twilio-run': major
5+
---
6+
7+
Twilio SDK from 3.x to 4.23.0. Required Node version bumped to 18 min.

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [macos-latest, windows-latest, ubuntu-latest]
19-
node-version: [ lts/-2, lts/-1, lts/*]
19+
node-version: [ lts/-1, lts/*]
2020

2121
steps:
2222
- uses: actions/checkout@v3

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ dist/
7474
packages/serverless-api/docs/
7575

7676
.idea
77+
78+
**/.DS_Store

docs/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ If you are planning to contribute something that does not have an open issue yet
1414

1515
## Requirements
1616

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

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@changesets/cli": "^2.26.0",
2727
"@commitlint/cli": "^19.1.0",
2828
"@commitlint/config-conventional": "^19.1.0",
29-
"@twilio/test-dep": "npm:twilio@3.84.0",
29+
"@twilio/test-dep": "npm:twilio@4.23.0",
3030
"@types/jest": "^29.2.4",
3131
"all-contributors-cli": "^6.1.2",
3232
"commitizen": "^4.2.4",

packages/plugin-assets/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"rimraf": "^3.0.2"
2424
},
2525
"engines": {
26-
"node": ">=14"
26+
"node": ">=18"
2727
},
2828
"files": [
2929
"/oclif.manifest.json",

packages/plugin-serverless/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"oclif": "^4.0.0"
2323
},
2424
"engines": {
25-
"node": ">=14.0.0"
25+
"node": ">=18.0.0"
2626
},
2727
"files": [
2828
"/oclif.manifest.json",

packages/runtime-handler/__tests__/dev-runtime/utils/requireFromProject.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'path';
22
import { requireFromProject } from '../../../src/dev-runtime/utils/requireFromProject';
33

44
const PROJECT_DIR = join(__dirname, '../../../../twilio-run');
5-
5+
// only works if test-dep version is different from root package version
66
jest.mock('../../../../twilio-run/node_modules/@twilio/test-dep', () => {
77
const x = jest.genMockFromModule('@twilio/test-dep');
88
(x as any)['__TYPE__'] = 'PROJECT_BASED';

packages/runtime-handler/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636
"build": "tsc",
3737
"watch": "tsc --watch",
3838
"build:noemit": "tsc --noEmit",
39-
"clean": "rimraf ./dist"
39+
"clean": "rimraf ./dist ./node_modules"
4040
},
4141
"devDependencies": {
42+
"@twilio/test-dep": "npm:[email protected]",
4243
"@types/common-tags": "^1.8.0",
4344
"@types/cookie-parser": "^1.4.2",
4445
"@types/debug": "^4.1.4",
4546
"@types/express-useragent": "^0.2.21",
4647
"@types/jest": "^26.0.24",
4748
"@types/lodash.debounce": "^4.0.6",
48-
"@types/node": "^14.0.19",
49+
"@types/node": "^18.0.0",
4950
"@types/supertest": "^2.0.8",
5051
"npm-run-all": "^4.1.5",
5152
"rimraf": "^2.6.3",
5253
"supertest": "^3.1.0",
53-
"typescript": "^4.9.4",
54-
"@twilio/test-dep": "npm:[email protected]"
54+
"typescript": "^4.9.4"
5555
},
5656
"bugs": {
5757
"url": "https://github.com/twilio-labs/serverless-toolkit/issues"
@@ -69,7 +69,7 @@
6969
"nocache": "^2.1.0",
7070
"normalize.css": "^8.0.1",
7171
"serialize-error": "^7.0.1",
72-
"twilio": "3.80.0"
72+
"twilio": "4.23.0"
7373
},
7474
"gitHead": "6db273648ed19474f4125042556b10c051529912"
7575
}

packages/serverless-api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"dependencies": {
5555
"@types/mime-types": "^2.1.0",
56-
"@types/node": "^14.17.19",
56+
"@types/node": "^18.0.0",
5757
"@types/recursive-readdir": "^2.2.0",
5858
"debug": "^4.1.1",
5959
"fast-redact": "^1.5.0",

packages/serverless-runtime-types/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"@types/express": "^4.17.11",
3232
"@types/qs": "^6.9.4",
33-
"twilio": "^4.20.1"
33+
"twilio": "^4.23.0"
3434
},
3535
"devDependencies": {
3636
"@types/express": "^4.17.11",

packages/serverless-twilio-runtime/Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Serverless Framework plugin to deploy to the Twilio Runtime.
88

99
### Pre-requisites
1010

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

packages/twilio-run/__tests__/runtime/internal/response.test.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ test('has correct defaults', () => {
55
const response = new Response();
66
expect(response['body']).toBeNull();
77
expect(response['statusCode']).toBe(200);
8-
expect(response['headers']).toEqual({});
8+
expect(response['headers']).toEqual({
9+
'Set-Cookie': [],
10+
});
911
});
1012

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

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

4649
test('sets headers correctly', () => {
4750
const response = new Response();
48-
expect(response['headers']).toEqual({});
51+
expect(response['headers']).toEqual({
52+
'Set-Cookie': [],
53+
});
4954
response.setHeaders({
5055
'Access-Control-Allow-Origin': 'example.com',
5156
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
@@ -64,26 +69,33 @@ test('sets headers correctly', () => {
6469

6570
test('appends a new header correctly', () => {
6671
const response = new Response();
67-
expect(response['headers']).toEqual({});
72+
expect(response['headers']).toEqual({
73+
'Set-Cookie': [],
74+
});
6875
response.appendHeader('Access-Control-Allow-Origin', 'dkundel.com');
6976
expect(response['headers']).toEqual({
7077
'Access-Control-Allow-Origin': 'dkundel.com',
78+
'Set-Cookie': [],
7179
});
7280
response.appendHeader('Content-Type', 'application/json');
7381
expect(response['headers']).toEqual({
7482
'Access-Control-Allow-Origin': 'dkundel.com',
7583
'Content-Type': 'application/json',
84+
'Set-Cookie': [],
7685
});
7786
});
7887

7988
test('appends a header correctly with no existing one', () => {
8089
const response = new Response();
81-
expect(response['headers']).toEqual({});
90+
expect(response['headers']).toEqual({
91+
'Set-Cookie': [],
92+
});
8293
// @ts-ignore
8394
response['headers'] = undefined;
8495
response.appendHeader('Access-Control-Allow-Origin', 'dkundel.com');
8596
expect(response['headers']).toEqual({
8697
'Access-Control-Allow-Origin': 'dkundel.com',
98+
'Set-Cookie': [],
8799
});
88100
});
89101

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

122134
expect(mockRes.send).toHaveBeenCalledWith(`I'm a teapot!`);
123135
expect(mockRes.status).toHaveBeenCalledWith(418);
124-
expect(mockRes.set).toHaveBeenCalledWith({ 'Content-Type': 'text/plain' });
136+
expect(mockRes.set).toHaveBeenCalledWith({
137+
'Content-Type': 'text/plain',
138+
'Set-Cookie': [],
139+
});
125140
});
126141

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

135150
expect(serialized.body).toEqual("I'm a teapot!");
136151
expect(serialized.statusCode).toEqual(418);
137-
expect(serialized.headers).toEqual({ 'Content-Type': 'text/plain' });
152+
expect(serialized.headers).toEqual({
153+
'Content-Type': 'text/plain',
154+
'Set-Cookie': [],
155+
});
138156
});
139157

140158
test('serializes a response with content type set to application/json', () => {
@@ -149,5 +167,8 @@ test('serializes a response with content type set to application/json', () => {
149167
JSON.stringify({ url: 'https://dkundel.com' })
150168
);
151169
expect(serialized.statusCode).toEqual(200);
152-
expect(serialized.headers).toEqual({ 'Content-Type': 'application/json' });
170+
expect(serialized.headers).toEqual({
171+
'Content-Type': 'application/json',
172+
'Set-Cookie': [],
173+
});
153174
});

packages/twilio-run/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"license": "MIT",
3636
"dependencies": {
3737
"@twilio-labs/serverless-api": "^5.5.1",
38-
"@twilio-labs/serverless-runtime-types": "2.1.0-rc.0",
38+
"@twilio-labs/serverless-runtime-types": "3.0.0",
3939
"@types/express": "4.17.7",
4040
"@types/inquirer": "^6.0.3",
4141
"@types/is-ci": "^2.0.0",
@@ -76,7 +76,7 @@
7676
"serialize-error": "^7.0.1",
7777
"terminal-link": "^1.3.0",
7878
"title": "^3.4.1",
79-
"twilio": "^3.60.0",
79+
"twilio": "^4.23.0",
8080
"type-fest": "^0.15.1",
8181
"window-size": "^1.1.1",
8282
"wrap-ansi": "^7.0.0",
@@ -102,7 +102,7 @@
102102
"@types/lodash.kebabcase": "^4.1.6",
103103
"@types/lodash.startcase": "^4.4.6",
104104
"@types/mock-fs": "^4.10.0",
105-
"@types/node": "^14.0.19",
105+
"@types/node": "^18.0.0",
106106
"@types/prompts": "^2.0.1",
107107
"@types/supertest": "^2.0.8",
108108
"@types/title": "^1.0.5",
@@ -113,7 +113,7 @@
113113
"nock": "^12.0.2",
114114
"supertest": "^3.1.0",
115115
"typescript": "^4.9.4",
116-
"@twilio/test-dep": "npm:twilio@3.60.0"
116+
"@twilio/test-dep": "npm:twilio@4.22.0"
117117
},
118118
"files": [
119119
"bin/",
@@ -122,7 +122,7 @@
122122
"README.md"
123123
],
124124
"engines": {
125-
"node": ">=12.22.1"
125+
"node": ">=18.0.0"
126126
},
127127
"gitHead": "6db273648ed19474f4125042556b10c051529912"
128128
}

packages/twilio-run/src/runtime/internal/functionRunner.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { serializeError } from 'serialize-error';
33
import { getRouteMap } from '../internal/route-cache';
44
import { constructContext, constructGlobalScope, isTwiml } from '../route';
55
import { Response } from './response';
6+
import { Headers } from '@twilio/runtime-handler/dist/dev-runtime/types';
67

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

1112
export type Reply = {
1213
body?: string | number | boolean | object;
13-
headers?: { [key: string]: number | string };
14+
headers?: Headers;
1415
statusCode: number;
1516
};
1617

0 commit comments

Comments
 (0)