Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilio

Package Overview
Dependencies
Maintainers
1
Versions
305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

Makefile

90

lib/index.js

@@ -10,2 +10,3 @@ /**

var crypto = require('crypto'),
_ = require('underscore'),
RestClient = require('./RestClient');

@@ -35,2 +36,3 @@

});
var computed = crypto.createHmac('sha1', authToken).update(url).digest('Base64');
return twilioHeader === crypto.createHmac('sha1', authToken).update(url).digest('Base64');

@@ -47,7 +49,93 @@ };

initializer.validateExpressRequest = function(request, authToken) {
var url = request.protocol + '://' + request.headers.host + request.url;
var url = request.protocol + '://' + request.headers.host + request.originalUrl;
return initializer.validateRequest(authToken, request.header('X-Twilio-Signature'), url, request.body||{});
};
/**
Express middleware to accompany a Twilio webhook. Provides Twilio
request validation, and makes the response a little more friendly for our
TwiML generator. Request validation requires the express.urlencoded middleware
to have been applied (e.g. app.use(express.urlencoded()); in your app config).
Options:
- validate: {Boolean} whether or not the middleware should validate the request
came from Twilio. Default true. If the request does not originate from
Twilio, we will return a text body and a 403. If there is no configured
auth token and validate=true, this is an error condition, so we will return
a 500.
- includeHelpers: {Boolean} add helpers to the response object to improve support
for XML (TwiML) rendering. Default true.
Returns a middleware function.
Examples:
var webhookMiddleware = twilio.webhook();
var webhookMiddleware = twilio.webhook('asdha9dhjasd'); //init with auth token
var webhookMiddleware = twilio.webhook({
validate:false // don't attempt request validation
});
*/
initializer.webhook = function() {
var opts = {
validate:true,
includeHelpers:true
};
// Process arguments
var tokenString;
for (var i = 0, l = arguments.length; i<l; i++) {
var arg = arguments[i];
if (typeof arg === 'string') {
tokenString = arg;
} else {
opts = _.extend(opts, arg);
}
}
// set auth token from input or environment variable
opts.authToken = tokenString ? tokenString : process.env.TWILIO_AUTH_TOKEN;
// Create middleware function
return function hook(request, response, next) {
// Add helpers, unless disabled
if (opts.includeHelpers) {
var oldSend = response.send;
response.send = function() {
// This is a special TwiML-aware version of send. If we detect
// A twiml response object, we'll set the content-type and
// automatically call .toString()
if (arguments.length == 1 && arguments[0].legalNodes) {
response.type('text/xml');
oldSend.call(response,arguments[0].toString());
} else {
// Continue with old version of send
oldSend.apply(response,arguments);
}
};
}
// Do validation if requested
if (opts.validate) {
// Check for a valid auth token
if (!opts.authToken) {
console.error('[Twilio]: Error - Twilio auth token is required for webhook request validation.');
response.type('text/plain');
response.send(500, 'Webhook Error - we attempted to validate this request without first configuring our auth token.');
} else {
// Check that the request originated from Twilio
valid = initializer.validateExpressRequest(request,opts.authToken);
if (valid) {
next();
} else {
response.type('text/plain');
return response.send(403, 'Twilio Request Validation Failed.');
}
}
} else {
next();
}
};
};
//public module interface is a function, which passes through to RestClient constructor
module.exports = initializer;

@@ -110,4 +110,6 @@ /**

'Accept':'application/json',
'Accept-Charset': 'utf-8',
'User-Agent':'twilio-node/' + moduleinfo.version
};
options.timeout = 31000;

@@ -114,0 +116,0 @@ // Manually create POST body if there's a form object. Sadly, request

9

lib/TwimlResponse.js

@@ -23,7 +23,5 @@ var _ = require('underscore');

text = arg;
}
else if (typeof arg === 'function') {
} else if (typeof arg === 'function') {
builder = arg;
}
else {
} else {
attributes = arg;

@@ -107,4 +105,3 @@ }

buffer.push(esc(this.text));
}
else {
} else {
//process child tags

@@ -111,0 +108,0 @@ for (var i = 0, l = this.children.length; i < l; i++) {

{
"name": "twilio",
"description": "A Twilio helper library",
"version": "1.4.0",
"version": "1.5.0",
"author": "Kevin Whinnery <kevin.whinnery@gmail.com>",

@@ -21,3 +21,3 @@ "contributors": [

"dependencies": {
"request": "2.x",
"request": "2.27.x",
"underscore": "1.x",

@@ -28,5 +28,3 @@ "jwt-simple": "0.1.x",

"devDependencies": {
"express": "2.x",
"connect": "2.x",
"ejs": "0.8.x"
"express": "3.x"
},

@@ -33,0 +31,0 @@ "scripts": {

# twilio-node
[![NPM](https://nodei.co/npm/twilio.png?downloads=true&stars=true)](https://nodei.co/npm/twilio/)
[![Build Status](https://travis-ci.org/twilio/twilio-node.png?branch=master)](https://travis-ci.org/twilio/twilio-node)

@@ -8,1 +10,33 @@

[http://twilio.github.com/twilio-node/](http://twilio.github.com/twilio-node/)
## Contributing
Bug fixes, docs, and enhancements welcome! If you're not familiar with the GitHub pull request/contribution process, [this is a nice tutorial](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
#### Getting Started
Fork and clone the repository. Install dependencies with:
npm install
Run the existing test spec with `npm test`. This requires `jasmine-node` to be installed globally via npm:
[sudo] npm install -g jasmine-node
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:
jasmine-node spec -m .\*accounts.\*
To run live tests (such as `client.live.spec.js`) against your [Twilio account](https://www.twilio.com/user/account), you will need to create a local configuration file. In the project root directory, do the following:
* `cp config.sample.js config.js`
* Edit `config.js` with your account information, a Twilio number, and your own mobile number
* Run the live tests
#### Contributing Code
In your fork, create a new feature/bug fix branch, [per the guide listed above](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/). Write a Jasmine test spec for your new feature or bug fix, and hack until it passes! Submit a pull request, and it will be reviewed as soon as possible.
#### Contributing Docs
Right now, the docs are maintained in static HTML in the `gh-pages` branch of this repository. We hope to switch to a more robust documentation system soon, but for the time being, you can make documentation changes by editing [index.html](https://github.com/twilio/twilio-node/blob/gh-pages/index.html) directly.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc