From 7b904fb6a982cea695d1767716256fdd0467787f Mon Sep 17 00:00:00 2001 From: Michael Faille Date: Sun, 20 Apr 2025 03:09:59 -0700 Subject: [PATCH 1/2] feat: upgrade Twilio SDK to v5 and require as peer dependency WHAT: - Upgraded the core `twilio` Node.js helper library to v5.5.2 across relevant packages (`runtime-handler`, `create-twilio-function` defaults, test dependencies). - Changed `@twilio-labs/serverless-runtime-types` and `@twilio-labs/twilio-run` to declare `twilio` as a `peerDependency` (^5.5.2) instead of a direct dependency. - Updated internal type definitions (`ClientOpts`) for compatibility with `twilio@5.x`. - Updated Twilio Console URL generation logic in `twilio-run`. - Updated default dependencies (`typescript`, `serverlessRuntimeTypes`) used by `create-twilio-function`. WHY: - Aligns the toolkit with the latest Twilio SDK features, improvements, and security updates available in v5. - Resolves potential version conflicts and type mismatches (e.g., TS2322/TS2352) by ensuring a single `twilio` instance is used, managed explicitly by the consuming project. This promotes a more stable and predictable dependency graph. BREAKING CHANGE: Consumers of `@twilio-labs/twilio-run` or projects directly importing types from `@twilio-labs/serverless-runtime-types` MUST now explicitly install `twilio` as a direct dependency in their own project. Add the `twilio` dependency: ```bash npm install twilio@^5.5.2 --save-dev yarn add twilio@^5.5.2 --dev ``` --- .changeset/heavy-moose-appear.md | 27 +++++++++++++++++++ package.json | 5 +++- packages/create-twilio-function/package.json | 2 +- .../src/create-twilio-function/versions.js | 6 ++--- packages/runtime-handler/package.json | 2 +- packages/serverless-runtime-types/README.md | 11 ++++++++ .../serverless-runtime-types/package.json | 8 +++--- packages/serverless-runtime-types/types.d.ts | 9 ++++--- packages/twilio-run/package.json | 6 +++-- .../src/runtime/internal/runtime.ts | 6 ++--- packages/twilio-run/src/runtime/route.ts | 4 +-- 11 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 .changeset/heavy-moose-appear.md diff --git a/.changeset/heavy-moose-appear.md b/.changeset/heavy-moose-appear.md new file mode 100644 index 00000000..e57be21f --- /dev/null +++ b/.changeset/heavy-moose-appear.md @@ -0,0 +1,27 @@ +--- +'@twilio-labs/serverless-runtime-types': major +'twilio-run': major +'create-twilio-function': minor +'@twilio/runtime-handler': minor +--- + +feat: Upgrade Twilio SDK to v5 and use peer dependency + +**WHAT:** +- Upgraded the core `twilio` Node.js helper library to v5.5.2 across the toolkit. +- Changed `@twilio-labs/serverless-runtime-types` and `@twilio-labs/twilio-run` to require `twilio` as a `peerDependency` instead of a direct dependency. +- Updated type definitions (`ClientOpts`) for compatibility with `twilio@5.x`. +- Updated default dependencies (`twilio`, `typescript`, `serverlessRuntimeTypes`) used by `@twilio-labs/create-twilio-function`. + +**WHY:** +- Aligns the toolkit with the latest Twilio SDK features, improvements, and security updates. +- Resolves potential type conflicts (e.g., `TS2322`/`TS2352`) by ensuring a single `twilio` instance, managed by the user's project. + +**HOW:** +**BREAKING CHANGE:** Users of `@twilio-labs/twilio-run` or projects importing types from `@twilio-labs/serverless-runtime-types` **must** now add `twilio` as a direct dependency to their project: +```bash +npm install twilio@^5.5.2 +# or +yarn add twilio@^5.5.2 +``` +After updating toolkit packages and adding `twilio`, perform a clean install (delete `node_modules` and lock file, then run `npm install` or `yarn install`). diff --git a/package.json b/package.json index 3d599527..4f7ba461 100644 --- a/package.json +++ b/package.json @@ -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@4.22.0", + "@twilio/test-dep": "npm:twilio@5.2.2", "@types/jest": "^29.2.4", "all-contributors-cli": "^6.1.2", "commitizen": "^4.2.4", @@ -45,6 +45,9 @@ "typedoc": "^0.27.4", "typescript": "^5.3.3" }, + "peerDependencies": { + "twilio": "^5.5.2" + }, "lint-staged": { "*.{js,jsx,ts,tsx}": [ "prettier --write", diff --git a/packages/create-twilio-function/package.json b/packages/create-twilio-function/package.json index 9e196579..d6cd533c 100644 --- a/packages/create-twilio-function/package.json +++ b/packages/create-twilio-function/package.json @@ -24,7 +24,7 @@ }, "license": "MIT", "devDependencies": { - "@twilio/runtime-handler": "^2.0.3", + "@twilio/runtime-handler": "^2.1.0", "nock": "^11.3.4" }, "dependencies": { diff --git a/packages/create-twilio-function/src/create-twilio-function/versions.js b/packages/create-twilio-function/src/create-twilio-function/versions.js index c2817478..f6c057cf 100644 --- a/packages/create-twilio-function/src/create-twilio-function/versions.js +++ b/packages/create-twilio-function/src/create-twilio-function/versions.js @@ -1,13 +1,13 @@ const pkgJson = require('../../package.json'); module.exports = { - twilio: '5.0.3', + twilio: '5.5.2', twilioRuntimeHandler: pkgJson.devDependencies[ '@twilio/runtime-handler' ].replace(/[\^~]/, ''), twilioRun: pkgJson.dependencies['twilio-run'], node: '18', - typescript: '^5.3.3', - serverlessRuntimeTypes: '^4.0.0', + typescript: '^5.8.0', + serverlessRuntimeTypes: '^4.0.1', copyfiles: '^2.4.1', }; diff --git a/packages/runtime-handler/package.json b/packages/runtime-handler/package.json index ba9a62d0..5797b6d7 100644 --- a/packages/runtime-handler/package.json +++ b/packages/runtime-handler/package.json @@ -70,7 +70,7 @@ "nocache": "^2.1.0", "normalize.css": "^8.0.1", "serialize-error": "^7.0.1", - "twilio": "4.23.0" + "twilio": "5.5.2" }, "gitHead": "6db273648ed19474f4125042556b10c051529912" } diff --git a/packages/serverless-runtime-types/README.md b/packages/serverless-runtime-types/README.md index 716c4209..7a84730a 100644 --- a/packages/serverless-runtime-types/README.md +++ b/packages/serverless-runtime-types/README.md @@ -22,6 +22,17 @@ npm install @twilio-labs/serverless-runtime-types ``` +**Peer Dependency Requirement:** + +This package requires the core `twilio` Node.js library as a **peer dependency** (version `^5.5.2` or compatible). This is necessary to ensure type consistency and prevent version conflicts within your project. + +**You MUST explicitly install both `@twilio-labs/serverless-runtime-types` and a compatible version of `twilio` in your project.** + +```bash +# Using npm +npm install @twilio-labs/serverless-runtime-types twilio@^5.5.2 --save-dev +``` + ## Example ### In JavaScript diff --git a/packages/serverless-runtime-types/package.json b/packages/serverless-runtime-types/package.json index 03691c36..4a5a18bb 100644 --- a/packages/serverless-runtime-types/package.json +++ b/packages/serverless-runtime-types/package.json @@ -29,12 +29,14 @@ }, "dependencies": { "@types/express": "^4.17.21", - "@types/qs": "^6.9.4", - "twilio": "^4.23.0" + "@types/qs": "^6.9.4" }, + "peerDependencies": { + "twilio": "^5.5.2" + }, "devDependencies": { "all-contributors-cli": "^6.7.0", - "typescript": "^5.3.3" + "typescript": "^5.8.0" }, "publishConfig": { "access": "public" diff --git a/packages/serverless-runtime-types/types.d.ts b/packages/serverless-runtime-types/types.d.ts index 0d682b92..ae3acd37 100644 --- a/packages/serverless-runtime-types/types.d.ts +++ b/packages/serverless-runtime-types/types.d.ts @@ -2,7 +2,7 @@ import * as twilio from 'twilio'; import { ServiceContext } from 'twilio/lib/rest/sync/v1/service'; import { SyncListListInstance } from 'twilio/lib/rest/sync/v1/service/syncList'; import { SyncMapListInstance } from 'twilio/lib/rest/sync/v1/service/syncMap'; -import { TwilioClientOptions } from 'twilio/lib/rest/Twilio'; +import { ClientOpts } from 'twilio'; export type EnvironmentVariables = { [key: string]: string | undefined; @@ -187,7 +187,7 @@ export interface TwilioResponse { removeCookie(key: string): TwilioResponse; } -export type RuntimeSyncClientOptions = TwilioClientOptions & { +export type RuntimeSyncClientOptions = ClientOpts & { serviceName?: string; }; @@ -360,7 +360,7 @@ export type Context = { * }; * ``` */ - getTwilioClient(options?: TwilioClientOptions): twilio.Twilio; + getTwilioClient(options?: ClientOpts): twilio.Twilio; /** * The domain name for the Service that contains this Function. */ @@ -412,6 +412,7 @@ export type GlobalTwilio = Omit & { export { ServiceContext } from 'twilio/lib/rest/sync/v1/service'; export { SyncListListInstance } from 'twilio/lib/rest/sync/v1/service/syncList'; export { SyncMapListInstance } from 'twilio/lib/rest/sync/v1/service/syncMap'; -export { TwilioClientOptions } from 'twilio/lib/rest/Twilio'; +export { ClientOpts as TwilioClientOptions } from 'twilio/lib/rest/Twilio'; + export type TwilioClient = twilio.Twilio; export type TwilioPackage = typeof twilio; diff --git a/packages/twilio-run/package.json b/packages/twilio-run/package.json index 7d47865b..89c81733 100644 --- a/packages/twilio-run/package.json +++ b/packages/twilio-run/package.json @@ -76,12 +76,14 @@ "serialize-error": "^7.0.1", "terminal-link": "^1.3.0", "title": "^3.4.1", - "twilio": "^4.23.0", "type-fest": "^0.15.1", "window-size": "^1.1.1", "wrap-ansi": "^7.0.0", "yargs": "^17.2.1" }, + "peerDependencies": { + "twilio": "^5.5.2" + }, "optionalDependencies": { "ngrok": "^3.3.0" }, @@ -113,7 +115,7 @@ "nock": "^12.0.2", "supertest": "^3.1.0", "typescript": "^4.9.4", - "@twilio/test-dep": "npm:twilio@4.22.0" + "@twilio/test-dep": "npm:twilio@5.5.2" }, "files": [ "bin/", diff --git a/packages/twilio-run/src/runtime/internal/runtime.ts b/packages/twilio-run/src/runtime/internal/runtime.ts index 62a02ea4..87e57591 100644 --- a/packages/twilio-run/src/runtime/internal/runtime.ts +++ b/packages/twilio-run/src/runtime/internal/runtime.ts @@ -16,7 +16,7 @@ import { getDebugFunction } from '../../utils/logger'; const debug = getDebugFunction('twilio-run:runtime'); -const { getCachedResources } = require('./route-cache'); +import { getCachedResources } from './route-cache'; function getAssets(): AssetResourceMap { const { assets } = getCachedResources(); @@ -72,9 +72,9 @@ export function create({ env }: StartCliConfig): RuntimeInstance { .join(',')})`, }); const client = twilio(env.ACCOUNT_SID, env.AUTH_TOKEN, options); - const service = (client.sync.v1.services( + const service = client.sync.v1.services( serviceName || 'default' - ) as unknown) as RuntimeSyncServiceContext; + ) as unknown as RuntimeSyncServiceContext; service.maps = service.syncMaps; service.lists = service.syncLists; diff --git a/packages/twilio-run/src/runtime/route.ts b/packages/twilio-run/src/runtime/route.ts index 342fa55a..4480c09f 100644 --- a/packages/twilio-run/src/runtime/route.ts +++ b/packages/twilio-run/src/runtime/route.ts @@ -4,6 +4,7 @@ import { ServerlessEventObject, ServerlessFunctionSignature, } from '@twilio-labs/serverless-runtime-types/types'; + import { fork } from 'child_process'; import { NextFunction, @@ -23,7 +24,6 @@ import { cleanUpStackTrace } from '../utils/stack-trace/clean-up'; import { Reply } from './internal/functionRunner'; import { Response } from './internal/response'; import * as Runtime from './internal/runtime'; -import * as PATH from 'path'; const RUNNER_PATH = process.env.NODE_ENV === 'test' @@ -40,7 +40,7 @@ export function constructEvent( return { ...req.query, ...req.body }; } -export function constructContext( +export function constructContext( { url, env }: StartCliConfig, functionPath: string ): Context<{ From e69ef08ea805d3be5926cdcae617e0673d5a9871 Mon Sep 17 00:00:00 2001 From: Michael Faille Date: Tue, 13 May 2025 00:26:29 -0700 Subject: [PATCH 2/2] chore(twilio-run): align test-dep with sdk v5.6.0 Updates the @twilio/test-dep (npm alias for `twilio`) development dependency to v5.6.0 in packages/twilio-run/package.json and in the root package.json. This change ensures consistent versions of the Twilio SDK are used during testing, aligning with the broader upgrade to Twilio SDK v5.6.0 across the toolkit. This supports efforts to stabilize the test environment following the core SDK update. feat: align @twilio/test-dep with twilio sdk v5.6 updated the @twilio/test-dep development dependency in package.json and packages/twilio-run/package.json to v5.6.0. this ensures consistent testing dependencies following the Twilio SDK upgrade. --- .changeset/heavy-moose-appear.md | 31 ++++++++++--------- package.json | 4 +-- .../src/create-twilio-function/versions.js | 2 +- packages/plugin-serverless/package.json | 2 +- packages/runtime-handler/README.md | 2 +- packages/runtime-handler/package.json | 4 +-- packages/serverless-runtime-types/README.md | 4 +-- .../serverless-runtime-types/package.json | 2 +- packages/twilio-run/package.json | 4 +-- 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.changeset/heavy-moose-appear.md b/.changeset/heavy-moose-appear.md index e57be21f..f4ae25e8 100644 --- a/.changeset/heavy-moose-appear.md +++ b/.changeset/heavy-moose-appear.md @@ -5,23 +5,24 @@ '@twilio/runtime-handler': minor --- -feat: Upgrade Twilio SDK to v5 and use peer dependency +feat: Upgrade Twilio SDK to v5.6.0 & peer dependency + +**IMPACT:** +- `@twilio-labs/serverless-runtime-types`: Major (peer dependency) +- `twilio-run`: Major (peer dependency) +- `create-twilio-function`: Minor (default SDK version) +- `@twilio/runtime-handler`: Minor (version upgrade) **WHAT:** -- Upgraded the core `twilio` Node.js helper library to v5.5.2 across the toolkit. -- Changed `@twilio-labs/serverless-runtime-types` and `@twilio-labs/twilio-run` to require `twilio` as a `peerDependency` instead of a direct dependency. -- Updated type definitions (`ClientOpts`) for compatibility with `twilio@5.x`. -- Updated default dependencies (`twilio`, `typescript`, `serverlessRuntimeTypes`) used by `@twilio-labs/create-twilio-function`. +- Twilio SDK upgraded to v5.6.0. +- `@twilio-labs/serverless-runtime-types` & `twilio-run` now require `twilio` as a `peerDependency`. +- Type definitions updated for Twilio v5.x compatibility. +- Default dependencies in `create-twilio-function` updated. **WHY:** -- Aligns the toolkit with the latest Twilio SDK features, improvements, and security updates. -- Resolves potential type conflicts (e.g., `TS2322`/`TS2352`) by ensuring a single `twilio` instance, managed by the user's project. +- Latest Twilio SDK features and fixes. +- Prevents type conflicts by centralizing `twilio` dependency in user projects. -**HOW:** -**BREAKING CHANGE:** Users of `@twilio-labs/twilio-run` or projects importing types from `@twilio-labs/serverless-runtime-types` **must** now add `twilio` as a direct dependency to their project: -```bash -npm install twilio@^5.5.2 -# or -yarn add twilio@^5.5.2 -``` -After updating toolkit packages and adding `twilio`, perform a clean install (delete `node_modules` and lock file, then run `npm install` or `yarn install`). +**ACTION:** +- **BREAKING:** Projects using `@twilio-labs/twilio-run` or `@twilio-labs/serverless-runtime-types` MUST add `twilio@^5.6.0` as a direct dependency (`npm install twilio@^5.6.0` or `yarn add twilio@^5.6.0`). +- Clean install (`node_modules` deletion and lock file removal) is required after updating toolkit packages and adding `twilio`. diff --git a/package.json b/package.json index 4f7ba461..24e185ec 100644 --- a/package.json +++ b/package.json @@ -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@5.2.2", + "@twilio/test-dep": "npm:twilio@5.6.0", "@types/jest": "^29.2.4", "all-contributors-cli": "^6.1.2", "commitizen": "^4.2.4", @@ -46,7 +46,7 @@ "typescript": "^5.3.3" }, "peerDependencies": { - "twilio": "^5.5.2" + "twilio": "^5.6.0" }, "lint-staged": { "*.{js,jsx,ts,tsx}": [ diff --git a/packages/create-twilio-function/src/create-twilio-function/versions.js b/packages/create-twilio-function/src/create-twilio-function/versions.js index f6c057cf..bc4ed511 100644 --- a/packages/create-twilio-function/src/create-twilio-function/versions.js +++ b/packages/create-twilio-function/src/create-twilio-function/versions.js @@ -1,7 +1,7 @@ const pkgJson = require('../../package.json'); module.exports = { - twilio: '5.5.2', + twilio: '5.6.0', twilioRuntimeHandler: pkgJson.devDependencies[ '@twilio/runtime-handler' ].replace(/[\^~]/, ''), diff --git a/packages/plugin-serverless/package.json b/packages/plugin-serverless/package.json index fb4ce4ba..712e6969 100644 --- a/packages/plugin-serverless/package.json +++ b/packages/plugin-serverless/package.json @@ -10,7 +10,7 @@ "dependencies": { "@oclif/core": "^1.14.2", "@twilio/cli-core": "^7.0.0", - "create-twilio-function": "^3.4.5", + "create-twilio-function": "^3.5.0", "lodash.camelcase": "^4.3.0", "lodash.kebabcase": "^4.1.1", "twilio-run": "^4.1.0" diff --git a/packages/runtime-handler/README.md b/packages/runtime-handler/README.md index bd40d152..44586c89 100644 --- a/packages/runtime-handler/README.md +++ b/packages/runtime-handler/README.md @@ -7,7 +7,7 @@ Define the version of the `@twilio/runtime-handler` inside your `dependencies` s ```json { "dependencies": { - "@twilio/runtime-handler": "1.1.0" + "@twilio/runtime-handler": "2.1.0" } } ``` diff --git a/packages/runtime-handler/package.json b/packages/runtime-handler/package.json index 5797b6d7..eb4424ab 100644 --- a/packages/runtime-handler/package.json +++ b/packages/runtime-handler/package.json @@ -39,7 +39,7 @@ "clean": "rimraf ./dist" }, "devDependencies": { - "@twilio/test-dep": "npm:twilio@4.22.0", + "@twilio/test-dep": "npm:twilio@5.6.0", "@types/common-tags": "^1.8.0", "@types/cookie-parser": "^1.4.2", "@types/debug": "^4.1.4", @@ -70,7 +70,7 @@ "nocache": "^2.1.0", "normalize.css": "^8.0.1", "serialize-error": "^7.0.1", - "twilio": "5.5.2" + "twilio": "5.6.0" }, "gitHead": "6db273648ed19474f4125042556b10c051529912" } diff --git a/packages/serverless-runtime-types/README.md b/packages/serverless-runtime-types/README.md index 7a84730a..550d64c2 100644 --- a/packages/serverless-runtime-types/README.md +++ b/packages/serverless-runtime-types/README.md @@ -24,13 +24,13 @@ npm install @twilio-labs/serverless-runtime-types **Peer Dependency Requirement:** -This package requires the core `twilio` Node.js library as a **peer dependency** (version `^5.5.2` or compatible). This is necessary to ensure type consistency and prevent version conflicts within your project. +This package requires the core `twilio` Node.js library as a **peer dependency** (version `^5.6.0` or compatible). This is necessary to ensure type consistency and prevent version conflicts within your project. **You MUST explicitly install both `@twilio-labs/serverless-runtime-types` and a compatible version of `twilio` in your project.** ```bash # Using npm -npm install @twilio-labs/serverless-runtime-types twilio@^5.5.2 --save-dev +npm install @twilio-labs/serverless-runtime-types twilio@^5.6.0 --save-dev ``` ## Example diff --git a/packages/serverless-runtime-types/package.json b/packages/serverless-runtime-types/package.json index 4a5a18bb..263853de 100644 --- a/packages/serverless-runtime-types/package.json +++ b/packages/serverless-runtime-types/package.json @@ -32,7 +32,7 @@ "@types/qs": "^6.9.4" }, "peerDependencies": { - "twilio": "^5.5.2" + "twilio": "^5.6.0" }, "devDependencies": { "all-contributors-cli": "^6.7.0", diff --git a/packages/twilio-run/package.json b/packages/twilio-run/package.json index 89c81733..69bfbffc 100644 --- a/packages/twilio-run/package.json +++ b/packages/twilio-run/package.json @@ -82,7 +82,7 @@ "yargs": "^17.2.1" }, "peerDependencies": { - "twilio": "^5.5.2" + "twilio": "^5.6.0" }, "optionalDependencies": { "ngrok": "^3.3.0" @@ -115,7 +115,7 @@ "nock": "^12.0.2", "supertest": "^3.1.0", "typescript": "^4.9.4", - "@twilio/test-dep": "npm:twilio@5.5.2" + "@twilio/test-dep": "npm:twilio@5.6.0" }, "files": [ "bin/",