Skip to content

Commit b471067

Browse files
author
childish-sambino
authored
feat!: Merge branch '4.0.0-rc' to main (#883)
1 parent d9244e3 commit b471067

File tree

2,216 files changed

+277714
-600804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,216 files changed

+277714
-600804
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
],
118118
"quotes": [
119119
2,
120-
"single"
120+
"double"
121121
],
122122
"indent": [
123123
2,

.github/workflows/test-and-deploy.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
timeout-minutes: 20
1818
strategy:
1919
matrix:
20-
node: [ 6, 8, 10, 12, 14, 16, lts/* ]
20+
node: [ 14, 16, 18, lts/* ]
2121
steps:
2222
- name: Checkout twilio-node
2323
uses: actions/checkout@v3
@@ -33,6 +33,16 @@ jobs:
3333
- name: Run Unit Tests
3434
run: npm run ci
3535

36+
- name: Run Cluster Tests
37+
if: (!github.event.pull_request.head.repo.fork)
38+
env:
39+
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
40+
TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY}}
41+
TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }}
42+
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
43+
TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }}
44+
run: npm run cluster
45+
3646
- name: SonarCloud Scan
3747
if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.node == 'lts/*' && !github.event.pull_request.head.repo.fork }}
3848
uses: SonarSource/sonarcloud-github-action@master

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Logs ###
1+
### Logs ###
22
logs
33
*.log
44

@@ -14,13 +14,13 @@ pids
1414
node_modules
1515

1616
### Test coverage ###
17-
spec/coverage
17+
coverage
1818

1919
### Custom ignores ###
2020
config.js
2121
.idea
2222

23-
### jsdoc dir ###
23+
### typedoc dir ###
2424
docs
2525

2626
### ide / editors ###
@@ -29,3 +29,6 @@ docs
2929
### Libraries don't need locks files ###
3030
yarn.lock
3131
package-lock.json
32+
33+
**/.openapi-generator*
34+
dist

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"newcap": true,
4545

4646
// Enforce use of single quotation marks for strings.
47-
"quotmark": "single",
47+
"quotmark": "double",
4848

4949
// Enforce placing 'use strict' at the top function scope
5050
"strict": true,

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.github
2+
coverage
3+
dist
4+
docs
5+
6+
babel.config.js
7+
*.md
8+
*.json

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:12.17
1+
FROM node:14
22

33
RUN mkdir /twilio
44
WORKDIR /twilio
@@ -8,7 +8,9 @@ ENV NODE_PATH /usr/local/lib/node_modules
88
COPY lib ./lib
99
COPY spec ./spec
1010
COPY examples ./examples
11-
COPY index.js .
12-
COPY package* ./
11+
COPY index.ts package.json babel.config.js tsconfig.json ./
12+
13+
RUN npm config set unsafe-perm true # Needed to run prepublish as root.
1314

1415
RUN npm install . --include=dev
16+
RUN npm install -g .

Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
.PHONY: test-install install test test-docker docs clean
1+
.PHONY: test-install install test test-docker docs clean prettier
22

33
test-install:
44
npm install --only=dev
55

66
install:
7-
@node --version || (echo "Node is not installed, please install Node >= 0.12"; exit 1);
7+
@node --version || (echo "Node is not installed, please install Node >= 14"; exit 1);
88
rm -f package-lock.json
99
npm install
1010

1111
test:
1212
npm test
1313

14-
test-docker:
15-
docker build -t twilio/twilio-node .
16-
docker run twilio/twilio-node npm run ci
17-
1814
docs:
19-
npm run jsdoc
15+
npm run typedoc
2016

2117
clean:
22-
rm -rf node_modules
18+
rm -rf node_modules dist
19+
20+
prettier:
21+
npm run prettier
2322

2423
API_DEFINITIONS_SHA=$(shell git log --oneline | grep Regenerated | head -n1 | cut -d ' ' -f 5)
2524
CURRENT_TAG=$(shell expr "${GITHUB_TAG}" : ".*-rc.*" >/dev/null && echo "rc" || echo "latest")

PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Please enter each Issue number you are resolving in your PR after one of the fol
1212
e.g.
1313
Fixes #1
1414
Closes #2
15+
16+
Note: If you made changes to the Request Validation logic, please run `npm run webhook-test` locally and ensure all test cases pass
1517
-->
1618

1719
# Fixes #

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,16 @@ The Node library documentation can be found [here][libdocs].
1919

2020
This library supports the following Node.js implementations:
2121

22-
* Node.js 6
23-
* Node.js 8
24-
* Node.js 10
25-
* Node.js 12
2622
* Node.js 14
2723
* Node.js 16
24+
* Node.js 18
2825

2926
TypeScript is supported for TypeScript version 2.9 and above.
3027

3128
## Installation
3229

3330
`npm install twilio` or `yarn add twilio`
3431

35-
### Installing Release Candidates
36-
37-
Or, if you're wanting to install the latest release candidate use:
38-
39-
`npm install twilio@rc` or `yarn add twilio@rc`
40-
4132
## Sample Usage
4233

4334
Check out these [code examples](examples) in JavaScript and TypeScript to get up and running quickly.
@@ -48,15 +39,44 @@ Check out these [code examples](examples) in JavaScript and TypeScript to get up
4839

4940
If your environment requires SSL decryption, you can set the path to CA bundle in the env var `TWILIO_CA_BUNDLE`.
5041

42+
### Client Initialization
43+
If you invoke any V2010 operations without specifying an account SID, `twilio-node` will automatically use the `TWILIO_ACCOUNT_SID` value that the client was initialized with. This is useful for when you'd like to, for example, fetch resources for your main account but also your subaccount. See below:
44+
45+
```javascript
46+
var accountSid = process.env.TWILIO_ACCOUNT_SID; // Your Account SID from www.twilio.com/console
47+
var authToken = process.env.TWILIO_AUTH_TOKEN; // Your Auth Token from www.twilio.com/console
48+
var subaccountSid = process.env.TWILIO_ACCOUNT_SUBACCOUNT_SID; // Your Subaccount SID from www.twilio.com/console
49+
50+
const client = require('twilio')(accountSid, authToken);
51+
const mainAccountCalls = client.api.v2010.account.calls.list; // SID not specified, so defaults to accountSid
52+
const subaccountCalls = client.api.v2010.account(subaccountSid).calls.list // SID specified as subaccountSid
53+
```
54+
5155
### Lazy Loading
5256

53-
`twilio-node` supports lazy loading required modules for faster loading time. Lazy loading is disabled by default. To enable lazy loading, simply instantiate the Twilio client with the `lazyLoading` flag set to `true`:
57+
`twilio-node` supports lazy loading required modules for faster loading time. Lazy loading is enabled by default. To disable lazy loading, simply instantiate the Twilio client with the `lazyLoading` flag set to `false`:
58+
```javascript
59+
var accountSid = process.env.TWILIO_ACCOUNT_SID; // Your Account SID from www.twilio.com/console
60+
var authToken = process.env.TWILIO_AUTH_TOKEN; // Your Auth Token from www.twilio.com/console
61+
62+
const client = require('twilio')(accountSid, authToken, {
63+
lazyLoading: false
64+
});
65+
```
66+
67+
### Enable Auto-Retry with Exponential Backoff
68+
69+
`twilio-node` supports automatic retry with exponential backoff when API requests receive an [Error 429 response](https://support.twilio.com/hc/en-us/articles/360044308153-Twilio-API-response-Error-429-Too-Many-Requests-). This retry with exponential backoff feature is disabled by default. To enable this feature, instantiate the Twilio client with the `autoRetry` flag set to `true`.
70+
71+
Optionally, the maximum number of retries performed by this feature can be set with the `maxRetries` flag. The default maximum number of retries is `3`.
72+
5473
```javascript
5574
var accountSid = process.env.TWILIO_ACCOUNT_SID; // Your Account SID from www.twilio.com/console
5675
var authToken = process.env.TWILIO_AUTH_TOKEN; // Your Auth Token from www.twilio.com/console
5776

5877
const client = require('twilio')(accountSid, authToken, {
59-
lazyLoading: true
78+
autoRetry: true,
79+
maxRetries: 3
6080
});
6181
```
6282

UPGRADE.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
1-
Upgrade Guide
1+
# Upgrade Guide
22

3-
After 3.0.0 all MINOR and MAJOR version bumps will have upgrade notes posted here.
3+
_All `MAJOR` version bumps will have upgrade notes posted here._
4+
5+
[2023-01-25] 3.x.x to 4.x.x
6+
-----------------------------
7+
8+
* Supported Node.js versions updated
9+
* Upgrade to Node.js >= 14
10+
* Dropped support for Node.js < 14 ([#791](https://github.com/twilio/twilio-node/pull/791))
11+
* Added support for Node.js 18 ([#794](https://github.com/twilio/twilio-node/pull/794))
12+
* Lazy loading enabled by default ([#752](https://github.com/twilio/twilio-node/pull/752))
13+
* Required Twilio modules now lazy load by default
14+
* See the [README](README.md) for how to disable lazy loading
15+
* Type changes from `object` to `Record` ([#873](https://github.com/twilio/twilio-node/pull/873))
16+
* Certain response properties now use the `Record` type with `string` keys
17+
* Including the `subresourceUris` property for v2010 APIs and the `links` properties for non-v2010 APIs
18+
* Creating an AccessToken requires an `identity` in the options ([#875](https://github.com/twilio/twilio-node/pull/875))
19+
* JWT token building deprecations
20+
* `ConversationsGrant` has been deprecated in favor of `VoiceGrant` ([#783](https://github.com/twilio/twilio-node/pull/783))
21+
* `IpMessagingGrant` has been removed ([#784](https://github.com/twilio/twilio-node/pull/784))
22+
* TwiML function deprecations ([#788](https://github.com/twilio/twilio-node/pull/788))
23+
* `Refer.referSip()` replaced by `Refer.sip()`
24+
* `ssmlBreak()` replaced by `break_()`
25+
* `ssmlEmphasis()` replaced by `emphasis()`
26+
* `ssmlLang()` replaced by `lang()`
27+
* `ssmlP()` replaced by `p()`
28+
* `ssmlPhoneme()` replaced by `phoneme()`
29+
* `ssmlProsody()` replaced by `prosody()`
30+
* `ssmlS()` replaced by `s()`
31+
* `ssmlSayAs()` replaced by `sayAs()`
32+
* `ssmlSub()` replaced by `sub()`
33+
* `ssmlW()` replaced by `w()`
34+
* Old:
35+
```js
36+
const response = new VoiceResponse();
37+
const say = response.say("Hello");
38+
say.ssmlEmphasis("you");
39+
```
40+
* New:
41+
```js
42+
const response = new VoiceResponse();
43+
const say = response.say("Hello");
44+
say.emphasis("you");
45+
```
46+
* TaskRouter Workers Statistics operations updated ([#820](https://github.com/twilio/twilio-node/pull/820))
47+
* Cumulative and Real-Time Workers Statistics no longer accept a WorkerSid
48+
* `GET /v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics`
49+
* Old: `client.taskrouter.v1.workspaces('WS...').workers('WK...).cumulativeStatistics()`
50+
* New: `client.taskrouter.v1.workspaces('WS...').workers.cumulativeStatistics()`
51+
* `GET /v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics`
52+
* Old: `client.taskrouter.v1.workspaces('WS...').workers('WK...).realTimeStatistics()`
53+
* New: `client.taskrouter.v1.workspaces('WS...').workers.realTimeStatistics()`
454

555
[2017-05-22] 3.1.x to 3.2.x
656
---------------------------

babel.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
plugins: [
7+
'babel-plugin-replace-ts-export-assignment',
8+
],
9+
};

cluster_test.spec.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
jest.setTimeout(15000);
2+
3+
import twilio from "./lib/";
4+
5+
const fromNumber = process.env.TWILIO_FROM_NUMBER;
6+
const toNumber = process.env.TWILIO_TO_NUMBER;
7+
const apiKey = process.env.TWILIO_API_KEY;
8+
const apiSecret = process.env.TWILIO_API_SECRET;
9+
const accountSid = process.env.TWILIO_ACCOUNT_SID;
10+
const testClient = twilio(apiKey, apiSecret, { accountSid });
11+
const twiml = new twilio.twiml.VoiceResponse();
12+
13+
test("Should send a text", () => {
14+
return testClient.messages
15+
.create({
16+
body: "hello world",
17+
to: toNumber,
18+
from: fromNumber,
19+
})
20+
.then((msg) => {
21+
expect(msg.sid).not.toBeUndefined();
22+
expect(msg.to).toBe(toNumber);
23+
expect(msg.from).toBe(fromNumber);
24+
expect(msg.body).toBe("hello world");
25+
});
26+
});
27+
28+
test("Should list incoming numbers", () => {
29+
return testClient.incomingPhoneNumbers.list().then((incomingPhoneNumbers) => {
30+
expect(incomingPhoneNumbers).not.toBeNull();
31+
expect(incomingPhoneNumbers.length).toBeGreaterThanOrEqual(2);
32+
});
33+
});
34+
35+
test("Should list a incoming number", () => {
36+
return testClient.incomingPhoneNumbers
37+
.list({ limit: 1 })
38+
.then((incomingPhoneNumbers) => {
39+
expect(incomingPhoneNumbers).not.toBeUndefined();
40+
expect(incomingPhoneNumbers.length).toEqual(1);
41+
});
42+
});
43+
44+
test("Should allow special characters for friendly and identity name", async () => {
45+
const friendlyName = "service|friendly&name";
46+
const identityName = "user|identity&string";
47+
const conversation = await testClient.conversations.v1.conversations.create({
48+
friendlyName: friendlyName,
49+
});
50+
const participant = await testClient.conversations.v1
51+
.conversations(conversation.sid)
52+
.participants.create({ identity: identityName });
53+
54+
expect(conversation).not.toBeNull();
55+
expect(participant).not.toBeNull();
56+
expect(conversation.friendlyName).toBe(friendlyName);
57+
expect(participant.identity).toBe(identityName);
58+
59+
const removeConversation = await testClient.conversations.v1
60+
.conversations(conversation.sid)
61+
.remove();
62+
63+
expect(removeConversation).toBeTruthy();
64+
});
65+
66+
test("Should list available numbers", () => {
67+
return testClient
68+
.availablePhoneNumbers("US")
69+
.tollFree.list({ limit: 2 })
70+
.then((tollFree) => {
71+
expect(tollFree).not.toBeNull();
72+
expect(tollFree.length).toEqual(2);
73+
});
74+
});
75+
76+
test("Should call with twiml string", () => {
77+
return testClient.calls
78+
.create({
79+
twiml: twiml.toString(),
80+
to: toNumber,
81+
from: fromNumber,
82+
})
83+
.then((call) => expect(call.sid).toBeDefined());
84+
});
85+
86+
test("Should call with twiml object", () => {
87+
return testClient.calls
88+
.create({
89+
twiml: twiml,
90+
to: toNumber,
91+
from: fromNumber,
92+
})
93+
.then((call) => expect(call.sid).toBeDefined());
94+
});

0 commit comments

Comments
 (0)