Comparing version 0.4.0 to 0.4.1
@@ -10,4 +10,8 @@ var util = require('util'); | ||
* of `flow` or `credentials`. | ||
* @option {OauthFlow} [flow] The flow to use to get credentials when needed. | ||
* @option {Object} [credentials] Initial credentials to use. | ||
* @option {OauthFlow} [flow] The flow to use to get credentials | ||
* when needed. | ||
* @option {String|Object} [credentials] Initial credentials to use. This can | ||
* be either the object returned from an access token request (which | ||
* contains the token and some other metadata) or just the `access_token` | ||
* field. | ||
* @constructor | ||
@@ -17,3 +21,7 @@ */ | ||
Authenticator.call(this); | ||
this.credentials = options.credentials || null; | ||
if (typeof(options.credentials) === 'string') { | ||
this.credentials = { access_token: options.credentials }; | ||
} else { | ||
this.credentials = options.credentials || null; | ||
} | ||
this.flow = options.flow || null; | ||
@@ -20,0 +28,0 @@ } |
@@ -19,2 +19,3 @@ var Dispatcher = require('./dispatcher'); | ||
* @param {String} [redirectUri] Default redirect URI for this client | ||
* @param {String} [asanaBaseUrl] Base URL for Asana, for debugging | ||
*/ | ||
@@ -108,9 +109,12 @@ function Client(dispatcher, options) { | ||
/** | ||
* Configure the client to authenticate via Oauth. Authorization | ||
* will be obtained by running an Oauth flow. | ||
* Configure the client to authenticate via Oauth. Credentials can be | ||
* supplied, or they can be obtained by running an Oauth flow. | ||
* @param {Object} options Options for Oauth. Includes any options for | ||
* the selected flow. | ||
* @option {Function} [flowType] Type of OauthFlow to use to obtain user | ||
* @option {Function} [flowType] Type of OauthFlow to use to obtain user | ||
* authorization. Defaults to autodetect based on environment. | ||
* @return {Client} this | ||
* @option {Object} [credentials] Credentials to use; no flow required to | ||
* obtain authorization. This object should at a minimum contain an | ||
* `access_token` string field. | ||
* @return {Client} this | ||
*/ | ||
@@ -120,8 +124,15 @@ Client.prototype.useOauth = function(options) { | ||
options.app = this.app; | ||
var FlowType = options.flowType || autoDetect(); | ||
if (FlowType === null) { | ||
throw new Error('Could not autodetect Oauth flow type'); | ||
var authenticator; | ||
if (options.credentials) { | ||
authenticator = | ||
new OauthAuthenticator({ credentials: options.credentials }); | ||
} else { | ||
var FlowType = options.flowType || autoDetect(); | ||
if (FlowType === null) { | ||
throw new Error('Could not autodetect Oauth flow type'); | ||
} | ||
var flow = new FlowType(options); | ||
authenticator = new OauthAuthenticator({ flow: flow }); | ||
} | ||
var flow = new FlowType(options); | ||
this.dispatcher.setAuthenticator(new OauthAuthenticator({ flow: flow })); | ||
this.dispatcher.setAuthenticator(authenticator); | ||
return this; | ||
@@ -135,5 +146,10 @@ }; | ||
Client.create = function(options) { | ||
return new Client(new Dispatcher(), options); | ||
options = options || {}; | ||
return new Client( | ||
new Dispatcher({ | ||
asanaBaseUrl: options.asanaBaseUrl | ||
}), | ||
options); | ||
}; | ||
module.exports = Client; |
@@ -18,6 +18,9 @@ var errors = require('./errors'); | ||
* @classdesc A HTTP wrapper for the Asana API | ||
* @param {Authenticator} [authenticator] Object to use for authentication. | ||
* @param {Object} options for default behavior of the Dispatcher | ||
* @option {Authenticator} [authenticator] Object to use for authentication. | ||
* Can also be set later with `setAuthenticator`. | ||
* @option {String} [asanaBaseUrl] Base URL for Asana, for debugging | ||
*/ | ||
function Dispatcher(authenticator) { | ||
function Dispatcher(options) { | ||
options = options || {}; | ||
/** | ||
@@ -27,10 +30,15 @@ * The object to use to handle authentication. | ||
*/ | ||
this.authenticator = authenticator || null; | ||
this.authenticator = options.authenticator || null; | ||
/** | ||
* The base URL for Asana | ||
* @type {String} | ||
*/ | ||
this.asanaBaseUrl = options.asanaBaseUrl || 'https://app.asana.com/' | ||
} | ||
/** | ||
* The root Url for the current version of the Asana API. | ||
* The relative API path for the current version of the Asana API. | ||
* @type {String} | ||
*/ | ||
Dispatcher.ROOT_URL = 'https://app.asana.com/api/1.0'; | ||
Dispatcher.API_PATH = 'api/1.0'; | ||
@@ -42,4 +50,4 @@ /** | ||
*/ | ||
Dispatcher.url = function(path) { | ||
return Dispatcher.ROOT_URL + path; | ||
Dispatcher.prototype.url = function(path) { | ||
return this.asanaBaseUrl + Dispatcher.API_PATH + path; | ||
}; | ||
@@ -110,3 +118,3 @@ | ||
method: 'GET', | ||
url: Dispatcher.url(path), | ||
url: this.url(path), | ||
json: true | ||
@@ -131,3 +139,3 @@ }; | ||
method: 'POST', | ||
url: Dispatcher.url(path), | ||
url: this.url(path), | ||
json: { | ||
@@ -151,3 +159,3 @@ data: data | ||
method: 'PUT', | ||
url: Dispatcher.url(path), | ||
url: this.url(path), | ||
json: { | ||
@@ -170,3 +178,3 @@ data: data | ||
method: 'DELETE', | ||
url: Dispatcher.url(path) | ||
url: this.url(path) | ||
}; | ||
@@ -173,0 +181,0 @@ return this.dispatch(params, dispatchOptions); |
{ | ||
"name": "asana", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A node.js client for the Asana API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
586826
14094
11