twilio 3.79.0 → 3.80.0

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/README.md CHANGED
@@ -28,6 +28,10 @@ This library supports the following Node.js implementations:
28
28
 
29
29
  TypeScript is supported for TypeScript version 2.9 and above.
30
30
 
31
+ ## Installation
32
+
33
+ `npm install twilio` or `yarn add twilio`
34
+
31
35
  ## Sample Usage
32
36
 
33
37
  Check out these [code examples](examples) in JavaScript and TypeScript to get up and running quickly.
@@ -138,7 +142,7 @@ npm test
138
142
  To run just one specific test file instead of the whole suite, provide a JavaScript regular expression that will match your spec file's name, like:
139
143
 
140
144
  ```bash
141
- npm run test -- -m .\*client.\*
145
+ npm run test:javascript -- -m .\*client.\*
142
146
  ```
143
147
 
144
148
  [apidocs]: https://www.twilio.com/docs/api
@@ -1,13 +1,15 @@
1
- import { HttpMethod } from '../interfaces';
2
- import Response = require('../http/response');
1
+ import { HttpMethod } from "../interfaces";
2
+ import Response = require("../http/response");
3
3
 
4
4
  declare class RequestClient {
5
- constructor();
5
+ constructor(opts?: RequestClient.RequestClientOptions);
6
6
  /**
7
7
  * Make an HTTP request
8
8
  * @param opts The request options
9
9
  */
10
- request<TData>(opts: RequestClient.RequestOptions<TData>): Promise<Response<TData>>;
10
+ request<TData>(
11
+ opts: RequestClient.RequestOptions<TData>
12
+ ): Promise<Response<TData>>;
11
13
  }
12
14
 
13
15
  declare namespace RequestClient {
@@ -54,9 +56,17 @@ declare namespace RequestClient {
54
56
  forever?: boolean;
55
57
  }
56
58
 
59
+ export interface RequestClientOptions {
60
+ /**
61
+ * A timeout in milliseconds. This will be used as the HTTPS agent's socket
62
+ * timeout, and as the default request timeout.
63
+ */
64
+ timeout?: number;
65
+ }
66
+
57
67
  export interface Headers {
58
68
  [header: string]: string;
59
69
  }
60
70
  }
61
71
 
62
- export = RequestClient;
72
+ export = RequestClient;
@@ -6,12 +6,42 @@ var fs = require('fs');
6
6
  var HttpsProxyAgent = require('https-proxy-agent');
7
7
  var Q = require('q');
8
8
  var qs = require('qs');
9
+ var url = require('url');
10
+ var https = require('https');
9
11
  var Response = require('../http/response');
10
12
  var Request = require('../http/request');
11
13
 
12
- axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
14
+ const DEFAULT_CONTENT_TYPE = 'application/x-www-form-urlencoded';
15
+ const DEFAULT_TIMEOUT = 30000;
13
16
 
14
- var RequestClient = function () { };
17
+ /**
18
+ * Make http request
19
+ * @param {object} opts - The options argument
20
+ * @param {string} opts.timeout - A custom timeout to use. This will be used as the socket timeout, and as the default request timeout.
21
+ */
22
+ var RequestClient = function (opts) {
23
+ opts = opts || {};
24
+ this.defaultTimeout = opts.timeout || DEFAULT_TIMEOUT;
25
+
26
+ // construct an https agent
27
+ let agentOpts = {
28
+ timeout: this.defaultTimeout,
29
+ };
30
+
31
+ let agent;
32
+ if (process.env.HTTP_PROXY) {
33
+ // Note: if process.env.HTTP_PROXY is set, we're not able to apply the given
34
+ // socket timeout. See: https://github.com/TooTallNate/node-https-proxy-agent/pull/96
35
+ agent = new HttpsProxyAgent(process.env.HTTP_PROXY);
36
+ } else {
37
+ agent = new https.Agent(agentOpts);
38
+ }
39
+
40
+ // construct an axios instance
41
+ this.axios = axios.create();
42
+ this.axios.defaults.headers.post['Content-Type'] = DEFAULT_CONTENT_TYPE;
43
+ this.axios.defaults.httpsAgent = agent;
44
+ };
15
45
 
16
46
  /**
17
47
  * Make http request
@@ -53,12 +83,11 @@ RequestClient.prototype.request = function (opts) {
53
83
  }
54
84
 
55
85
  var options = {
56
- timeout: opts.timeout || 30000,
86
+ timeout: opts.timeout || this.defaultTimeout,
57
87
  maxRedirects: opts.allowRedirects ? 10 : 0, // Same number of allowed redirects as request module default
58
88
  url: opts.uri,
59
89
  method: opts.method,
60
90
  headers: opts.headers,
61
- httpsAgent: process.env.HTTP_PROXY ? new HttpsProxyAgent(process.env.HTTP_PROXY) : undefined,
62
91
  proxy: false,
63
92
  validateStatus: status => status >= 100 && status < 600,
64
93
  };
@@ -99,7 +128,7 @@ RequestClient.prototype.request = function (opts) {
99
128
  this.lastResponse = undefined;
100
129
  this.lastRequest = new Request(optionsRequest);
101
130
 
102
- axios(options).then((response) => {
131
+ this.axios(options).then((response) => {
103
132
  if (opts.logLevel === 'debug') {
104
133
  console.log(`response.statusCode: ${response.status}`)
105
134
  console.log(`response.headers: ${JSON.stringify(response.headers)}`)
@@ -122,7 +151,7 @@ RequestClient.prototype.filterLoggingHeaders = function (headers){
122
151
  return Object.keys(headers).filter((header) => {
123
152
  return !'authorization'.includes(header.toLowerCase());
124
153
  });
125
- }
154
+ };
126
155
 
127
156
  RequestClient.prototype.logRequest = function (options){
128
157
  console.log('-- BEGIN Twilio API Request --');
@@ -140,6 +169,6 @@ RequestClient.prototype.logRequest = function (options){
140
169
  }
141
170
 
142
171
  console.log('-- END Twilio API Request --');
143
- }
172
+ };
144
173
 
145
174
  module.exports = RequestClient;
@@ -14,15 +14,17 @@ import { InteractionChannelParticipantList } from './interactionChannel/interact
14
14
  import { InteractionChannelParticipantListInstance } from './interactionChannel/interactionChannelParticipant';
15
15
  import { SerializableClass } from '../../../../interfaces';
16
16
 
17
+ type InteractionChannelChannelStatus = 'setup'|'active'|'failed'|'closed';
18
+
17
19
  type InteractionChannelStatus = 'close'|'closed'|'wrapup';
18
20
 
19
- type InteractionChannelType = 'voice'|'sms'|'email'|'web'|'whatsapp'|'chat';
21
+ type InteractionChannelType = 'voice'|'sms'|'email'|'web'|'whatsapp'|'chat'|'messenger'|'gbm';
20
22
 
21
23
  /**
22
24
  * Initialize the InteractionChannelList
23
25
  *
24
26
  * @param version - Version of the resource
25
- * @param interactionSid - The unique string that identifies the resource
27
+ * @param interactionSid - The unique string that identifies the resource.
26
28
  */
27
29
  declare function InteractionChannelList(version: V1, interactionSid: string): InteractionChannelListInstance;
28
30
 
@@ -213,9 +215,12 @@ interface InteractionChannelPayload extends InteractionChannelResource, Page.Twi
213
215
  }
214
216
 
215
217
  interface InteractionChannelResource {
218
+ error_code: number;
219
+ error_message: string;
216
220
  interaction_sid: string;
217
221
  links: string;
218
222
  sid: string;
223
+ status: InteractionChannelChannelStatus;
219
224
  type: InteractionChannelType;
220
225
  url: string;
221
226
  }
@@ -263,12 +268,14 @@ declare class InteractionChannelInstance extends SerializableClass {
263
268
  *
264
269
  * @param version - Version of the resource
265
270
  * @param payload - The instance payload
266
- * @param interactionSid - The unique string that identifies the resource
271
+ * @param interactionSid - The unique string that identifies the resource.
267
272
  * @param sid - The unique string that identifies the resource
268
273
  */
269
274
  constructor(version: V1, payload: InteractionChannelPayload, interactionSid: string, sid: string);
270
275
 
271
276
  private _proxy: InteractionChannelContext;
277
+ errorCode: number;
278
+ errorMessage: string;
272
279
  /**
273
280
  * fetch a InteractionChannelInstance
274
281
  *
@@ -286,6 +293,7 @@ declare class InteractionChannelInstance extends SerializableClass {
286
293
  */
287
294
  participants(): InteractionChannelParticipantListInstance;
288
295
  sid: string;
296
+ status: InteractionChannelChannelStatus;
289
297
  /**
290
298
  * Provide a user-friendly representation
291
299
  */
@@ -324,4 +332,4 @@ declare class InteractionChannelPage extends Page<V1, InteractionChannelPayload,
324
332
  toJSON(): any;
325
333
  }
326
334
 
327
- export { InteractionChannelContext, InteractionChannelInstance, InteractionChannelInstanceUpdateOptions, InteractionChannelList, InteractionChannelListInstance, InteractionChannelListInstanceEachOptions, InteractionChannelListInstanceOptions, InteractionChannelListInstancePageOptions, InteractionChannelPage, InteractionChannelPayload, InteractionChannelResource, InteractionChannelSolution, InteractionChannelStatus, InteractionChannelType }
335
+ export { InteractionChannelChannelStatus, InteractionChannelContext, InteractionChannelInstance, InteractionChannelInstanceUpdateOptions, InteractionChannelList, InteractionChannelListInstance, InteractionChannelListInstanceEachOptions, InteractionChannelListInstanceOptions, InteractionChannelListInstancePageOptions, InteractionChannelPage, InteractionChannelPayload, InteractionChannelResource, InteractionChannelSolution, InteractionChannelStatus, InteractionChannelType }
@@ -17,6 +17,8 @@ var InteractionChannelInviteList = require(
17
17
  var InteractionChannelParticipantList = require(
18
18
  './interactionChannel/interactionChannelParticipant').InteractionChannelParticipantList;
19
19
  var Page = require('../../../../base/Page'); /* jshint ignore:line */
20
+ var deserialize = require(
21
+ '../../../../base/deserialize'); /* jshint ignore:line */
20
22
  var serialize = require('../../../../base/serialize'); /* jshint ignore:line */
21
23
  var values = require('../../../../base/values'); /* jshint ignore:line */
22
24
 
@@ -32,7 +34,7 @@ var InteractionChannelContext;
32
34
  * @constructor Twilio.FlexApi.V1.InteractionContext.InteractionChannelList
33
35
  *
34
36
  * @param {Twilio.FlexApi.V1} version - Version of the resource
35
- * @param {string} interactionSid - The unique string that identifies the resource
37
+ * @param {string} interactionSid - The unique string that identifies the resource.
36
38
  */
37
39
  /* jshint ignore:end */
38
40
  InteractionChannelList = function InteractionChannelList(version,
@@ -413,14 +415,18 @@ InteractionChannelPage.prototype[util.inspect.custom] = function inspect(depth,
413
415
  *
414
416
  * @property {string} sid - The unique string that identifies the resource
415
417
  * @property {string} interactionSid -
416
- * The unique string that identifies the resource
418
+ * The unique string that identifies the resource.
417
419
  * @property {interaction_channel.type} type - The Interaction Channel's type.
420
+ * @property {interaction_channel.channel_status} status -
421
+ * The status of this channel.
422
+ * @property {number} errorCode - The Twilio error code for a failed channel.
423
+ * @property {string} errorMessage - The error message for a failed channel.
418
424
  * @property {string} url - The url
419
425
  * @property {string} links - The links
420
426
  *
421
427
  * @param {V1} version - Version of the resource
422
428
  * @param {InteractionChannelPayload} payload - The instance payload
423
- * @param {sid} interactionSid - The unique string that identifies the resource
429
+ * @param {sid} interactionSid - The unique string that identifies the resource.
424
430
  * @param {sid} sid - The unique string that identifies the resource
425
431
  */
426
432
  /* jshint ignore:end */
@@ -432,6 +438,9 @@ InteractionChannelInstance = function InteractionChannelInstance(version,
432
438
  this.sid = payload.sid; // jshint ignore:line
433
439
  this.interactionSid = payload.interaction_sid; // jshint ignore:line
434
440
  this.type = payload.type; // jshint ignore:line
441
+ this.status = payload.status; // jshint ignore:line
442
+ this.errorCode = deserialize.integer(payload.error_code); // jshint ignore:line
443
+ this.errorMessage = payload.error_message; // jshint ignore:line
435
444
  this.url = payload.url; // jshint ignore:line
436
445
  this.links = payload.links; // jshint ignore:line
437
446
 
@@ -69,6 +69,7 @@ interface VerificationCheckResource {
69
69
  payee: string;
70
70
  service_sid: string;
71
71
  sid: string;
72
+ sna_attempts_error_codes: object[];
72
73
  status: string;
73
74
  to: string;
74
75
  valid: boolean;
@@ -97,6 +98,7 @@ declare class VerificationCheckInstance extends SerializableClass {
97
98
  payee: string;
98
99
  serviceSid: string;
99
100
  sid: string;
101
+ snaAttemptsErrorCodes: object[];
100
102
  status: string;
101
103
  to: string;
102
104
  /**
@@ -59,6 +59,7 @@ VerificationCheckList = function VerificationCheckList(version, serviceSid) {
59
59
  * @memberof Twilio.Verify.V2.ServiceContext.VerificationCheckList#
60
60
  *
61
61
  * @param {object} [opts] - Options for request
62
+ * @param {string} [opts.code] - The verification string
62
63
  * @param {string} [opts.to] - The phone number or email to verify
63
64
  * @param {string} [opts.verificationSid] -
64
65
  * A SID that uniquely identifies the Verification Check
@@ -66,7 +67,6 @@ VerificationCheckList = function VerificationCheckList(version, serviceSid) {
66
67
  * The amount of the associated PSD2 compliant transaction.
67
68
  * @param {string} [opts.payee] -
68
69
  * The payee of the associated PSD2 compliant transaction
69
- * @param {string} [opts.code] - The verification string
70
70
  * @param {function} [callback] - Callback to handle processed record
71
71
  *
72
72
  * @returns {Promise} Resolves to processed VerificationCheckInstance
@@ -81,11 +81,11 @@ VerificationCheckList = function VerificationCheckList(version, serviceSid) {
81
81
 
82
82
  var deferred = Q.defer();
83
83
  var data = values.of({
84
+ 'Code': _.get(opts, 'code'),
84
85
  'To': _.get(opts, 'to'),
85
86
  'VerificationSid': _.get(opts, 'verificationSid'),
86
87
  'Amount': _.get(opts, 'amount'),
87
- 'Payee': _.get(opts, 'payee'),
88
- 'Code': _.get(opts, 'code')
88
+ 'Payee': _.get(opts, 'payee')
89
89
  });
90
90
 
91
91
  var promise = this._version.create({uri: this._uri, method: 'POST', data: data});
@@ -216,6 +216,8 @@ VerificationCheckPage.prototype[util.inspect.custom] = function inspect(depth,
216
216
  * The ISO 8601 date and time in GMT when the Verification Check resource was created
217
217
  * @property {Date} dateUpdated -
218
218
  * The ISO 8601 date and time in GMT when the Verification Check resource was last updated
219
+ * @property {object} snaAttemptsErrorCodes -
220
+ * List of error codes as a result of attempting a verification using the `sna` channel.
219
221
  *
220
222
  * @param {V2} version - Version of the resource
221
223
  * @param {VerificationCheckPayload} payload - The instance payload
@@ -239,6 +241,7 @@ VerificationCheckInstance = function VerificationCheckInstance(version, payload,
239
241
  this.payee = payload.payee; // jshint ignore:line
240
242
  this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line
241
243
  this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line
244
+ this.snaAttemptsErrorCodes = payload.sna_attempts_error_codes; // jshint ignore:line
242
245
 
243
246
  // Context
244
247
  this._context = undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "twilio",
3
3
  "description": "A Twilio helper library",
4
- "version": "3.79.0",
4
+ "version": "3.80.0",
5
5
  "author": "API Team <api@twilio.com>",
6
6
  "contributors": [
7
7
  {