twilio 4.0.2 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import lib from "./lib";
2
+ export = lib;
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const lib_1 = __importDefault(require("./lib"));
9
+ module.exports = lib_1.default;
@@ -1,81 +1,84 @@
1
1
  /// <reference types="node" />
2
2
  import RequestClient from "./RequestClient";
3
3
  import { HttpMethod } from "../interfaces";
4
- export interface ClientOpts {
5
- httpClient?: RequestClient;
6
- accountSid?: string;
7
- env?: NodeJS.ProcessEnv;
8
- edge?: string;
9
- region?: string;
10
- lazyLoading?: boolean;
11
- logLevel?: string;
12
- userAgentExtensions?: string[];
13
- autoRetry?: boolean;
14
- maxRetries?: number;
15
- }
16
- export interface RequestOpts {
17
- method?: HttpMethod;
18
- uri?: string;
19
- username?: string;
20
- password?: string;
21
- headers?: Headers;
22
- params?: object;
23
- data?: object;
24
- timeout?: number;
25
- allowRedirects?: boolean;
26
- logLevel?: string;
27
- }
28
- /**
29
- * Parent class for Twilio Client that implements request & validation logic
30
- */
31
- export declare class BaseTwilio {
32
- username: string;
33
- password: string;
34
- accountSid: string;
35
- opts?: ClientOpts;
36
- env?: NodeJS.ProcessEnv;
37
- edge?: string;
38
- region?: string;
39
- logLevel?: string;
40
- autoRetry: boolean;
41
- maxRetries?: number;
42
- userAgentExtensions?: string[];
43
- _httpClient?: RequestClient;
44
- /**
45
- * Create a BaseTwilio instance
46
- *
47
- * @param username -
48
- * The username used for authentication. This is normally account sid, but if using key/secret auth will be
49
- * the api key sid.
50
- * @param password -
51
- * The password used for authentication. This is normally auth token, but if using key/secret auth will be
52
- * the secret.
53
- * @param opts - The options argument
54
- *
55
- * @returns A new instance of BaseTwilio
56
- */
57
- constructor(username?: string, password?: string, opts?: ClientOpts);
58
- get httpClient(): RequestClient;
59
- /**
60
- * Makes a request to the Twilio API using the configured http client.
61
- * Authentication information is automatically added if none is provided.
62
- *
63
- * @param opts - The options argument
64
- */
65
- request(opts: RequestOpts): Promise<any>;
66
- /**
67
- * Adds a region and/or edge to a given hostname
68
- *
69
- * @param hostname - A URI hostname (e.g. api.twilio.com)
70
- * @param targetEdge - The targeted edge location (e.g. sydney)
71
- * @param targetRegion - The targeted region location (e.g. au1)
72
- */
73
- getHostname(hostname: string, targetEdge: string | undefined, targetRegion: string | undefined): string;
4
+ declare namespace Twilio {
5
+ interface ClientOpts {
6
+ httpClient?: RequestClient;
7
+ accountSid?: string;
8
+ env?: NodeJS.ProcessEnv;
9
+ edge?: string;
10
+ region?: string;
11
+ lazyLoading?: boolean;
12
+ logLevel?: string;
13
+ userAgentExtensions?: string[];
14
+ autoRetry?: boolean;
15
+ maxRetries?: number;
16
+ }
17
+ interface RequestOpts {
18
+ method?: HttpMethod;
19
+ uri?: string;
20
+ username?: string;
21
+ password?: string;
22
+ headers?: Headers;
23
+ params?: object;
24
+ data?: object;
25
+ timeout?: number;
26
+ allowRedirects?: boolean;
27
+ logLevel?: string;
28
+ }
74
29
  /**
75
- * Validates that a request to the new SSL certificate is successful.
76
- *
77
- * @throws RestException if the request fails
78
- *
30
+ * Parent class for Twilio Client that implements request & validation logic
79
31
  */
80
- validateSslCert(): Promise<any>;
32
+ class Client {
33
+ username: string;
34
+ password: string;
35
+ accountSid: string;
36
+ opts?: ClientOpts;
37
+ env?: NodeJS.ProcessEnv;
38
+ edge?: string;
39
+ region?: string;
40
+ logLevel?: string;
41
+ autoRetry: boolean;
42
+ maxRetries?: number;
43
+ userAgentExtensions?: string[];
44
+ _httpClient?: RequestClient;
45
+ /**
46
+ * Create a BaseTwilio instance
47
+ *
48
+ * @param username -
49
+ * The username used for authentication. This is normally account sid, but if using key/secret auth will be
50
+ * the api key sid.
51
+ * @param password -
52
+ * The password used for authentication. This is normally auth token, but if using key/secret auth will be
53
+ * the secret.
54
+ * @param opts - The options argument
55
+ *
56
+ * @returns A new instance of BaseTwilio
57
+ */
58
+ constructor(username?: string, password?: string, opts?: ClientOpts);
59
+ get httpClient(): RequestClient;
60
+ /**
61
+ * Makes a request to the Twilio API using the configured http client.
62
+ * Authentication information is automatically added if none is provided.
63
+ *
64
+ * @param opts - The options argument
65
+ */
66
+ request(opts: RequestOpts): Promise<any>;
67
+ /**
68
+ * Adds a region and/or edge to a given hostname
69
+ *
70
+ * @param hostname - A URI hostname (e.g. api.twilio.com)
71
+ * @param targetEdge - The targeted edge location (e.g. sydney)
72
+ * @param targetRegion - The targeted region location (e.g. au1)
73
+ */
74
+ getHostname(hostname: string, targetEdge: string | undefined, targetRegion: string | undefined): string;
75
+ /**
76
+ * Validates that a request to the new SSL certificate is successful.
77
+ *
78
+ * @throws RestException if the request fails
79
+ *
80
+ */
81
+ validateSslCert(): Promise<any>;
82
+ }
81
83
  }
84
+ export = Twilio;
@@ -2,171 +2,173 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BaseTwilio = void 0;
7
5
  const RequestClient_1 = __importDefault(require("./RequestClient")); /* jshint ignore:line */
8
6
  const os = require("os"); /* jshint ignore:line */
9
7
  const url = require("url"); /* jshint ignore:line */
10
8
  const moduleInfo = require("../../package.json"); /* jshint ignore:line */
11
9
  const util = require("util"); /* jshint ignore:line */
12
10
  const RestException = require("../base/RestException"); /* jshint ignore:line */
13
- /* jshint ignore:start */
14
- /**
15
- * Parent class for Twilio Client that implements request & validation logic
16
- */
17
- /* jshint ignore:end */
18
- class BaseTwilio {
11
+ var Twilio;
12
+ (function (Twilio) {
19
13
  /* jshint ignore:start */
20
14
  /**
21
- * Create a BaseTwilio instance
22
- *
23
- * @param username -
24
- * The username used for authentication. This is normally account sid, but if using key/secret auth will be
25
- * the api key sid.
26
- * @param password -
27
- * The password used for authentication. This is normally auth token, but if using key/secret auth will be
28
- * the secret.
29
- * @param opts - The options argument
30
- *
31
- * @returns A new instance of BaseTwilio
15
+ * Parent class for Twilio Client that implements request & validation logic
32
16
  */
33
17
  /* jshint ignore:end */
34
- constructor(username, password, opts) {
35
- this.opts = opts || {};
36
- this.env = this.opts.env || process.env;
37
- this.username =
38
- username ||
39
- this.env.TWILIO_ACCOUNT_SID ||
40
- (() => {
41
- throw new Error("username is required");
42
- })();
43
- this.password =
44
- password ||
45
- this.env.TWILIO_AUTH_TOKEN ||
46
- (() => {
47
- throw new Error("password is required");
48
- })();
49
- this.accountSid = this.opts.accountSid || this.username;
50
- this.edge = this.opts.edge || this.env.TWILIO_EDGE;
51
- this.region = this.opts.region || this.env.TWILIO_REGION;
52
- this.logLevel = this.opts.logLevel || this.env.TWILIO_LOG_LEVEL;
53
- this.autoRetry = this.opts.autoRetry || false;
54
- this.maxRetries = this.opts.maxRetries;
55
- this.userAgentExtensions = this.opts.userAgentExtensions || [];
56
- this._httpClient = this.opts.httpClient;
57
- if (this.opts.lazyLoading === false) {
58
- this._httpClient = this.httpClient;
18
+ class Client {
19
+ /* jshint ignore:start */
20
+ /**
21
+ * Create a BaseTwilio instance
22
+ *
23
+ * @param username -
24
+ * The username used for authentication. This is normally account sid, but if using key/secret auth will be
25
+ * the api key sid.
26
+ * @param password -
27
+ * The password used for authentication. This is normally auth token, but if using key/secret auth will be
28
+ * the secret.
29
+ * @param opts - The options argument
30
+ *
31
+ * @returns A new instance of BaseTwilio
32
+ */
33
+ /* jshint ignore:end */
34
+ constructor(username, password, opts) {
35
+ this.opts = opts || {};
36
+ this.env = this.opts.env || process.env;
37
+ this.username =
38
+ username ||
39
+ this.env.TWILIO_ACCOUNT_SID ||
40
+ (() => {
41
+ throw new Error("username is required");
42
+ })();
43
+ this.password =
44
+ password ||
45
+ this.env.TWILIO_AUTH_TOKEN ||
46
+ (() => {
47
+ throw new Error("password is required");
48
+ })();
49
+ this.accountSid = this.opts.accountSid || this.username;
50
+ this.edge = this.opts.edge || this.env.TWILIO_EDGE;
51
+ this.region = this.opts.region || this.env.TWILIO_REGION;
52
+ this.logLevel = this.opts.logLevel || this.env.TWILIO_LOG_LEVEL;
53
+ this.autoRetry = this.opts.autoRetry || false;
54
+ this.maxRetries = this.opts.maxRetries;
55
+ this.userAgentExtensions = this.opts.userAgentExtensions || [];
56
+ this._httpClient = this.opts.httpClient;
57
+ if (this.opts.lazyLoading === false) {
58
+ this._httpClient = this.httpClient;
59
+ }
60
+ if (!this.accountSid.startsWith("AC")) {
61
+ const apiKeyMsg = this.accountSid.startsWith("SK")
62
+ ? ". The given SID indicates an API Key which requires the accountSid to be passed as an additional option"
63
+ : "";
64
+ throw new Error("accountSid must start with AC" + apiKeyMsg);
65
+ }
59
66
  }
60
- if (!this.accountSid.startsWith("AC")) {
61
- const apiKeyMsg = this.accountSid.startsWith("SK")
62
- ? ". The given SID indicates an API Key which requires the accountSid to be passed as an additional option"
63
- : "";
64
- throw new Error("accountSid must start with AC" + apiKeyMsg);
67
+ get httpClient() {
68
+ if (!this._httpClient) {
69
+ this._httpClient = new RequestClient_1.default({
70
+ autoRetry: this.autoRetry,
71
+ maxRetries: this.maxRetries,
72
+ });
73
+ }
74
+ return this._httpClient;
65
75
  }
66
- }
67
- get httpClient() {
68
- if (!this._httpClient) {
69
- this._httpClient = new RequestClient_1.default({
70
- autoRetry: this.autoRetry,
71
- maxRetries: this.maxRetries,
76
+ /* jshint ignore:start */
77
+ /**
78
+ * Makes a request to the Twilio API using the configured http client.
79
+ * Authentication information is automatically added if none is provided.
80
+ *
81
+ * @param opts - The options argument
82
+ */
83
+ /* jshint ignore:end */
84
+ request(opts) {
85
+ opts = opts || {};
86
+ if (!opts.method) {
87
+ throw new Error("method is required");
88
+ }
89
+ if (!opts.uri) {
90
+ throw new Error("uri is required");
91
+ }
92
+ const username = opts.username || this.username;
93
+ const password = opts.password || this.password;
94
+ const headers = opts.headers || {};
95
+ const pkgVersion = moduleInfo.version;
96
+ const osName = os.platform();
97
+ const osArch = os.arch();
98
+ const nodeVersion = process.version;
99
+ headers["User-Agent"] = util.format("twilio-node/%s (%s %s) node/%s", pkgVersion, osName, osArch, nodeVersion);
100
+ this.userAgentExtensions?.forEach((extension) => {
101
+ headers["User-Agent"] += ` ${extension}`;
102
+ });
103
+ headers["Accept-Charset"] = "utf-8";
104
+ if (opts.method === "post" && !headers["Content-Type"]) {
105
+ headers["Content-Type"] = "application/x-www-form-urlencoded";
106
+ }
107
+ if (!headers["Accept"]) {
108
+ headers["Accept"] = "application/json";
109
+ }
110
+ var uri = new url.URL(opts.uri);
111
+ uri.hostname = this.getHostname(uri.hostname, this.edge, this.region);
112
+ return this.httpClient?.request({
113
+ method: opts.method,
114
+ uri: uri.href,
115
+ username: username,
116
+ password: password,
117
+ headers: headers,
118
+ params: opts.params,
119
+ data: opts.data,
120
+ timeout: opts.timeout,
121
+ allowRedirects: opts.allowRedirects,
122
+ logLevel: opts.logLevel,
72
123
  });
73
124
  }
74
- return this._httpClient;
75
- }
76
- /* jshint ignore:start */
77
- /**
78
- * Makes a request to the Twilio API using the configured http client.
79
- * Authentication information is automatically added if none is provided.
80
- *
81
- * @param opts - The options argument
82
- */
83
- /* jshint ignore:end */
84
- request(opts) {
85
- opts = opts || {};
86
- if (!opts.method) {
87
- throw new Error("method is required");
88
- }
89
- if (!opts.uri) {
90
- throw new Error("uri is required");
91
- }
92
- const username = opts.username || this.username;
93
- const password = opts.password || this.password;
94
- const headers = opts.headers || {};
95
- const pkgVersion = moduleInfo.version;
96
- const osName = os.platform();
97
- const osArch = os.arch();
98
- const nodeVersion = process.version;
99
- headers["User-Agent"] = util.format("twilio-node/%s (%s %s) node/%s", pkgVersion, osName, osArch, nodeVersion);
100
- this.userAgentExtensions?.forEach((extension) => {
101
- headers["User-Agent"] += ` ${extension}`;
102
- });
103
- headers["Accept-Charset"] = "utf-8";
104
- if (opts.method === "post" && !headers["Content-Type"]) {
105
- headers["Content-Type"] = "application/x-www-form-urlencoded";
106
- }
107
- if (!headers["Accept"]) {
108
- headers["Accept"] = "application/json";
109
- }
110
- var uri = new url.URL(opts.uri);
111
- uri.hostname = this.getHostname(uri.hostname, this.edge, this.region);
112
- return this.httpClient?.request({
113
- method: opts.method,
114
- uri: uri.href,
115
- username: username,
116
- password: password,
117
- headers: headers,
118
- params: opts.params,
119
- data: opts.data,
120
- timeout: opts.timeout,
121
- allowRedirects: opts.allowRedirects,
122
- logLevel: opts.logLevel,
123
- });
124
- }
125
- /* jshint ignore:start */
126
- /**
127
- * Adds a region and/or edge to a given hostname
128
- *
129
- * @param hostname - A URI hostname (e.g. api.twilio.com)
130
- * @param targetEdge - The targeted edge location (e.g. sydney)
131
- * @param targetRegion - The targeted region location (e.g. au1)
132
- */
133
- /* jshint ignore:end */
134
- getHostname(hostname, targetEdge, targetRegion) {
135
- const defaultRegion = "us1";
136
- const domain = hostname.split(".").slice(-2).join(".");
137
- const prefix = hostname.split("." + domain)[0];
138
- let [product, edge, region] = prefix.split(".");
139
- if (edge && !region) {
140
- region = edge;
141
- edge = undefined;
125
+ /* jshint ignore:start */
126
+ /**
127
+ * Adds a region and/or edge to a given hostname
128
+ *
129
+ * @param hostname - A URI hostname (e.g. api.twilio.com)
130
+ * @param targetEdge - The targeted edge location (e.g. sydney)
131
+ * @param targetRegion - The targeted region location (e.g. au1)
132
+ */
133
+ /* jshint ignore:end */
134
+ getHostname(hostname, targetEdge, targetRegion) {
135
+ const defaultRegion = "us1";
136
+ const domain = hostname.split(".").slice(-2).join(".");
137
+ const prefix = hostname.split("." + domain)[0];
138
+ let [product, edge, region] = prefix.split(".");
139
+ if (edge && !region) {
140
+ region = edge;
141
+ edge = undefined;
142
+ }
143
+ region = targetRegion || region || (targetEdge && defaultRegion);
144
+ if (!region) {
145
+ return hostname;
146
+ }
147
+ edge = targetEdge || edge;
148
+ return [product, edge, region, domain].filter((part) => part).join(".");
142
149
  }
143
- region = targetRegion || region || (targetEdge && defaultRegion);
144
- if (!region) {
145
- return hostname;
150
+ /* jshint ignore:start */
151
+ /**
152
+ * Validates that a request to the new SSL certificate is successful.
153
+ *
154
+ * @throws RestException if the request fails
155
+ *
156
+ */
157
+ /* jshint ignore:end */
158
+ validateSslCert() {
159
+ return this.httpClient
160
+ ?.request({
161
+ method: "get",
162
+ uri: "https://api.twilio.com:8443/2010-04-01/.json",
163
+ })
164
+ .then((response) => {
165
+ if (response["statusCode"] < 200 || response["statusCode"] >= 300) {
166
+ throw new RestException(response);
167
+ }
168
+ return response;
169
+ });
146
170
  }
147
- edge = targetEdge || edge;
148
- return [product, edge, region, domain].filter((part) => part).join(".");
149
- }
150
- /* jshint ignore:start */
151
- /**
152
- * Validates that a request to the new SSL certificate is successful.
153
- *
154
- * @throws RestException if the request fails
155
- *
156
- */
157
- /* jshint ignore:end */
158
- validateSslCert() {
159
- return this.httpClient
160
- ?.request({
161
- method: "get",
162
- uri: "https://api.twilio.com:8443/2010-04-01/.json",
163
- })
164
- .then((response) => {
165
- if (response["statusCode"] < 200 || response["statusCode"] >= 300) {
166
- throw new RestException(response);
167
- }
168
- return response;
169
- });
170
171
  }
171
- }
172
- exports.BaseTwilio = BaseTwilio;
172
+ Twilio.Client = Client;
173
+ })(Twilio || (Twilio = {}));
174
+ module.exports = Twilio;
@@ -1,4 +1,4 @@
1
- import { BaseTwilio, RequestOpts } from "./BaseTwilio";
1
+ import { Client as BaseTwilio, RequestOpts } from "./BaseTwilio";
2
2
  /**
3
3
  * Base domain object
4
4
  */
@@ -2,104 +2,8 @@
2
2
  import { HttpMethod } from "../interfaces";
3
3
  import { AxiosInstance } from "axios";
4
4
  import Response from "../http/response";
5
- import Request from "../http/request";
6
- import { Headers } from "../http/request";
7
- export interface RequestOptions<TData = any, TParams = object> {
8
- /**
9
- * The HTTP method
10
- */
11
- method: HttpMethod;
12
- /**
13
- * The request URI
14
- */
15
- uri: string;
16
- /**
17
- * The username used for auth
18
- */
19
- username?: string;
20
- /**
21
- * The password used for auth
22
- */
23
- password?: string;
24
- /**
25
- * The request headers
26
- */
27
- headers?: Headers;
28
- /**
29
- * The object of params added as query string to the request
30
- */
31
- params?: TParams;
32
- /**
33
- * The form data that should be submitted
34
- */
35
- data?: TData;
36
- /**
37
- * The request timeout in milliseconds
38
- */
39
- timeout?: number;
40
- /**
41
- * Should the client follow redirects
42
- */
43
- allowRedirects?: boolean;
44
- /**
45
- * Set to true to use the forever-agent
46
- */
47
- forever?: boolean;
48
- /**
49
- * Set to 'debug' to enable debug logging
50
- */
51
- logLevel?: string;
52
- }
53
- export interface RequestClientOptions {
54
- /**
55
- * A timeout in milliseconds. This will be used as the HTTPS agent's socket
56
- * timeout, AND as the default request timeout.
57
- */
58
- timeout?: number;
59
- /**
60
- * https.Agent keepAlive option
61
- */
62
- keepAlive?: boolean;
63
- /**
64
- * https.Agent keepAliveMSecs option
65
- */
66
- keepAliveMsecs?: number;
67
- /**
68
- * https.Agent maxSockets option
69
- */
70
- maxSockets?: number;
71
- /**
72
- * https.Agent maxTotalSockets option
73
- */
74
- maxTotalSockets?: number;
75
- /**
76
- * https.Agent maxFreeSockets option
77
- */
78
- maxFreeSockets?: number;
79
- /**
80
- * https.Agent scheduling option
81
- */
82
- scheduling?: "fifo" | "lifo" | undefined;
83
- /**
84
- * The private CA certificate bundle (if private SSL certificate)
85
- */
86
- ca?: string | Buffer;
87
- /**
88
- * Enable auto-retry with exponential backoff when receiving 429 Errors from
89
- * the API. Disabled by default.
90
- */
91
- autoRetry?: boolean;
92
- /**
93
- * Maximum retry delay in milliseconds for 429 Error response retries.
94
- * Defaults to 3000.
95
- */
96
- maxRetryDelay?: number;
97
- /**
98
- * Maximum number of request retries for 429 Error responses. Defaults to 3.
99
- */
100
- maxRetries?: number;
101
- }
102
- export default class RequestClient {
5
+ import Request, { Headers } from "../http/request";
6
+ declare class RequestClient {
103
7
  defaultTimeout: number;
104
8
  axios: AxiosInstance;
105
9
  lastResponse?: Response<any>;
@@ -121,7 +25,7 @@ export default class RequestClient {
121
25
  * @param opts.maxRetryDelay - Max retry delay in milliseconds for 429 Too Many Request response retries. Defaults to 3000.
122
26
  * @param opts.maxRetries - Max number of request retries for 429 Too Many Request responses. Defaults to 3.
123
27
  */
124
- constructor(opts?: RequestClientOptions);
28
+ constructor(opts?: RequestClient.RequestClientOptions);
125
29
  /**
126
30
  * Make http request
127
31
  * @param opts - The options argument
@@ -137,7 +41,105 @@ export default class RequestClient {
137
41
  * @param opts.forever - Set to true to use the forever-agent
138
42
  * @param opts.logLevel - Show debug logs
139
43
  */
140
- request<TData>(opts: RequestOptions<TData>): Promise<Response<TData>>;
44
+ request<TData>(opts: RequestClient.RequestOptions<TData>): Promise<Response<TData>>;
141
45
  filterLoggingHeaders(headers: Headers): string[];
142
46
  private logRequest;
143
47
  }
48
+ declare namespace RequestClient {
49
+ interface RequestOptions<TData = any, TParams = object> {
50
+ /**
51
+ * The HTTP method
52
+ */
53
+ method: HttpMethod;
54
+ /**
55
+ * The request URI
56
+ */
57
+ uri: string;
58
+ /**
59
+ * The username used for auth
60
+ */
61
+ username?: string;
62
+ /**
63
+ * The password used for auth
64
+ */
65
+ password?: string;
66
+ /**
67
+ * The request headers
68
+ */
69
+ headers?: Headers;
70
+ /**
71
+ * The object of params added as query string to the request
72
+ */
73
+ params?: TParams;
74
+ /**
75
+ * The form data that should be submitted
76
+ */
77
+ data?: TData;
78
+ /**
79
+ * The request timeout in milliseconds
80
+ */
81
+ timeout?: number;
82
+ /**
83
+ * Should the client follow redirects
84
+ */
85
+ allowRedirects?: boolean;
86
+ /**
87
+ * Set to true to use the forever-agent
88
+ */
89
+ forever?: boolean;
90
+ /**
91
+ * Set to 'debug' to enable debug logging
92
+ */
93
+ logLevel?: string;
94
+ }
95
+ interface RequestClientOptions {
96
+ /**
97
+ * A timeout in milliseconds. This will be used as the HTTPS agent's socket
98
+ * timeout, AND as the default request timeout.
99
+ */
100
+ timeout?: number;
101
+ /**
102
+ * https.Agent keepAlive option
103
+ */
104
+ keepAlive?: boolean;
105
+ /**
106
+ * https.Agent keepAliveMSecs option
107
+ */
108
+ keepAliveMsecs?: number;
109
+ /**
110
+ * https.Agent maxSockets option
111
+ */
112
+ maxSockets?: number;
113
+ /**
114
+ * https.Agent maxTotalSockets option
115
+ */
116
+ maxTotalSockets?: number;
117
+ /**
118
+ * https.Agent maxFreeSockets option
119
+ */
120
+ maxFreeSockets?: number;
121
+ /**
122
+ * https.Agent scheduling option
123
+ */
124
+ scheduling?: "fifo" | "lifo" | undefined;
125
+ /**
126
+ * The private CA certificate bundle (if private SSL certificate)
127
+ */
128
+ ca?: string | Buffer;
129
+ /**
130
+ * Enable auto-retry with exponential backoff when receiving 429 Errors from
131
+ * the API. Disabled by default.
132
+ */
133
+ autoRetry?: boolean;
134
+ /**
135
+ * Maximum retry delay in milliseconds for 429 Error response retries.
136
+ * Defaults to 3000.
137
+ */
138
+ maxRetryDelay?: number;
139
+ /**
140
+ * Maximum number of request retries for 429 Error responses. Defaults to 3.
141
+ */
142
+ maxRetries?: number;
143
+ }
144
+ }
145
+ export = RequestClient;
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
28
  const axios_1 = __importDefault(require("axios"));
30
29
  const fs = __importStar(require("fs"));
31
30
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
@@ -38,7 +37,7 @@ const DEFAULT_TIMEOUT = 30000;
38
37
  const DEFAULT_INITIAL_RETRY_INTERVAL_MILLIS = 100;
39
38
  const DEFAULT_MAX_RETRY_DELAY = 3000;
40
39
  const DEFAULT_MAX_RETRIES = 3;
41
- function getExpontentialBackoffResponseHandler(axios, opts) {
40
+ function getExponentialBackoffResponseHandler(axios, opts) {
42
41
  const maxIntervalMillis = opts.maxIntervalMillis;
43
42
  const maxRetries = opts.maxRetries;
44
43
  return function (res) {
@@ -110,7 +109,7 @@ class RequestClient {
110
109
  this.axios.defaults.headers.post["Content-Type"] = DEFAULT_CONTENT_TYPE;
111
110
  this.axios.defaults.httpsAgent = agent;
112
111
  if (opts.autoRetry) {
113
- this.axios.interceptors.response.use(getExpontentialBackoffResponseHandler(this.axios, {
112
+ this.axios.interceptors.response.use(getExponentialBackoffResponseHandler(this.axios, {
114
113
  maxIntervalMillis: this.maxRetryDelay,
115
114
  maxRetries: this.maxRetries,
116
115
  }));
@@ -220,4 +219,4 @@ class RequestClient {
220
219
  console.log("-- END Twilio API Request --");
221
220
  }
222
221
  }
223
- exports.default = RequestClient;
222
+ module.exports = RequestClient;
@@ -1,4 +1,4 @@
1
- import { BaseTwilio, ClientOpts } from "../base/BaseTwilio";
1
+ import { Client, ClientOpts, RequestOpts } from "../base/BaseTwilio";
2
2
  import Accounts from "./Accounts";
3
3
  import Api from "./Api";
4
4
  import Autopilot from "./Autopilot";
@@ -61,7 +61,7 @@ import { ValidationRequestListInstance } from "./api/v2010/account/validationReq
61
61
  /**
62
62
  * Twilio Client to interact with the Rest API
63
63
  */
64
- declare class Twilio extends BaseTwilio {
64
+ declare class Twilio extends Client {
65
65
  /** (Twilio.Accounts) - accounts domain */
66
66
  _accounts?: Accounts;
67
67
  /** (Twilio.Api) - api domain */
@@ -263,4 +263,10 @@ declare class Twilio extends BaseTwilio {
263
263
  /** Getter for (Twilio.Api.V2010.AccountContext.ValidationRequestListInstance) validationRequests resource */
264
264
  get validationRequests(): ValidationRequestListInstance;
265
265
  }
266
+ declare namespace Twilio {
267
+ interface RequestClientOptions extends ClientOpts {
268
+ }
269
+ interface RequestOptions extends RequestOpts {
270
+ }
271
+ }
266
272
  export = Twilio;
@@ -15,7 +15,7 @@ const BaseTwilio_1 = require("../base/BaseTwilio");
15
15
  * Twilio Client to interact with the Rest API
16
16
  */
17
17
  /* jshint ignore:end */
18
- class Twilio extends BaseTwilio_1.BaseTwilio {
18
+ class Twilio extends BaseTwilio_1.Client {
19
19
  /* jshint ignore:start */
20
20
  /**
21
21
  * Creates a new instance of Twilio Client
@@ -63,4 +63,4 @@ declare namespace FaxResponse {
63
63
  }
64
64
  export {};
65
65
  }
66
- export default FaxResponse;
66
+ export = FaxResponse;
@@ -8,7 +8,6 @@
8
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
11
  const TwiML_1 = __importDefault(require("./TwiML"));
13
12
  class FaxResponse extends TwiML_1.default {
14
13
  /**
@@ -64,4 +63,4 @@ class FaxResponse extends TwiML_1.default {
64
63
  }
65
64
  FaxResponse.Receive = Receive;
66
65
  })(FaxResponse || (FaxResponse = {}));
67
- exports.default = FaxResponse;
66
+ module.exports = FaxResponse;
@@ -114,4 +114,4 @@ declare namespace MessagingResponse {
114
114
  constructor(redirect: XMLElement);
115
115
  }
116
116
  }
117
- export default MessagingResponse;
117
+ export = MessagingResponse;
@@ -8,7 +8,6 @@
8
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
11
  const TwiML_1 = __importDefault(require("./TwiML"));
13
12
  class MessagingResponse extends TwiML_1.default {
14
13
  /**
@@ -117,4 +116,4 @@ class MessagingResponse extends TwiML_1.default {
117
116
  }
118
117
  MessagingResponse.Redirect = Redirect;
119
118
  })(MessagingResponse || (MessagingResponse = {}));
120
- exports.default = MessagingResponse;
119
+ module.exports = MessagingResponse;
@@ -2445,4 +2445,4 @@ declare namespace VoiceResponse {
2445
2445
  }
2446
2446
  export {};
2447
2447
  }
2448
- export default VoiceResponse;
2448
+ export = VoiceResponse;
@@ -8,7 +8,6 @@
8
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
11
  const TwiML_1 = __importDefault(require("./TwiML"));
13
12
  class VoiceResponse extends TwiML_1.default {
14
13
  /**
@@ -1431,4 +1430,4 @@ class VoiceResponse extends TwiML_1.default {
1431
1430
  }
1432
1431
  VoiceResponse.VirtualAgent = VirtualAgent;
1433
1432
  })(VoiceResponse || (VoiceResponse = {}));
1434
- exports.default = VoiceResponse;
1433
+ module.exports = VoiceResponse;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "twilio",
3
3
  "description": "A Twilio helper library",
4
- "version": "4.0.2",
4
+ "version": "4.1.1",
5
5
  "author": "API Team <api@twilio.com>",
6
6
  "contributors": [
7
7
  {
@@ -69,7 +69,9 @@
69
69
  "typedoc": "typedoc --entryPointStrategy expand src --out docs --logLevel Error"
70
70
  },
71
71
  "files": [
72
- "lib"
72
+ "lib",
73
+ "index.js",
74
+ "index.d.ts"
73
75
  ],
74
76
  "main": "./lib",
75
77
  "types": "./index.d.ts",