Socket
Socket
Sign inDemoInstall

xero-node

Package Overview
Dependencies
4
Maintainers
1
Versions
164
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

78

index.js
"use strict";
/**
* @class Xero
*/
const OAuth = require("oauth");

@@ -23,2 +19,6 @@ const QueryString = require("querystring");

/**
* @class Xero
*/
class Xero {

@@ -41,6 +41,6 @@

// Set the Consumer Properties
this.ConsumerKey = properties.consumerKey;
this.ConsumerSecret = properties.consumerSecret;
this.CallbackUrl = properties.callbackUrl;
this.ApiVersion = properties.apiVersion;
this._ConsumerKey = properties.consumerKey;
this._ConsumerSecret = properties.consumerSecret;
this._CallbackUrl = properties.callbackUrl;
this._ApiVersion = properties.apiVersion;

@@ -50,16 +50,16 @@ if (properties.hasOwnProperty("accessToken") &&

) {
this.AccessToken = properties.accessToken;
this.AccessTokenSecret = properties.accessTokenSecret;
this._AccessToken = properties.accessToken;
this._AccessTokenSecret = properties.accessTokenSecret;
} else {
this.AccessToken = null;
this.AccessTokenSecret = null;
this._AccessToken = null;
this._AccessTokenSecret = null;
}
this.OAuth = new OAuth.OAuth(
this._OAuth = new OAuth.OAuth(
XERO_URLS.REQUEST_TOKEN,
XERO_URLS.ACCESS_TOKEN,
this.ConsumerKey,
this.ConsumerSecret,
this._ConsumerKey,
this._ConsumerSecret,
XERO_OAUTH.VERSION,
this.CallbackUrl,
this._CallbackUrl,
XERO_OAUTH.SIGNATURE_METHOD

@@ -71,2 +71,23 @@ );

/**
* Formats OAuth Error
* @param error
* @returns {*}
* @private
*/
static _handleOAuthError(error) {
if (error.hasOwnProperty("statusCode") &&
error.hasOwnProperty("data")
) {
return {
statusCode: error.statusCode,
data: QueryString.parse(error.data)
}
} else {
return error;
}
}
/**
* Gets OAuth request tokens

@@ -79,9 +100,9 @@ * @returns {Promise}

this.OAuth.getOAuthRequestToken(
this._OAuth.getOAuthRequestToken(
{
oauth_callback: this.CallbackUrl
oauth_callback: this._CallbackUrl
},
(error, requestToken, requestTokenSecret) => {
if (error) {
return reject(error);
return reject(Xero._handleOAuthError(error));
} else {

@@ -92,3 +113,3 @@

oauth_token: requestToken,
oauth_callback: this.CallbackUrl
oauth_callback: this._CallbackUrl
});

@@ -119,3 +140,3 @@

return new Promise((resolve, reject) => {
this.OAuth.getOAuthAccessToken(
this._OAuth.getOAuthAccessToken(
requestToken,

@@ -126,6 +147,6 @@ requestTokenSecret,

if (error) {
return reject(error);
return reject(Xero._handleOAuthError());
} else {
this.AccessToken = accessToken;
this.AccessTokenSecret = accessSecret;
this._AccessToken = accessToken;
this._AccessTokenSecret = accessSecret;

@@ -148,3 +169,3 @@ return resolve({

_validateProperties() {
if (!this.AccessToken || !this.AccessTokenSecret) {
if (!this._AccessToken || !this._AccessTokenSecret) {
throw new Error("Access Tokens Missing");

@@ -167,3 +188,3 @@ }

// Make the request
let url = XERO_URLS.API_ENDPOINT + this.ApiVersion + endpoint;
let url = XERO_URLS.API_ENDPOINT + this._ApiVersion + endpoint;

@@ -175,5 +196,8 @@ if (parameters) {

return new Promise((resolve, reject) => {
this.OAuth.get(url, this.AccessToken, this.AccessTokenSecret, (error, data) => {
this._OAuth.get(url, this._AccessToken, this._AccessTokenSecret, (error, data) => {
if (error) {
return reject(error);

@@ -180,0 +204,0 @@ } else {

{
"name": "xero-node",
"version": "1.0.0",
"version": "1.1.0",
"description": "OAuth Node Wrapper for Xero",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,1 +5,6 @@ # Xero Node

See Examples folder for how to use
## References
https://oauth.net/core/1.0a/
https://app.xero.com/Application
https://developer.xero.com/documentation/api/
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc