Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
1
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dispatch-node-sdk - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

.nvmrc

84

dist/lib/dispatch.js

@@ -7,4 +7,2 @@ 'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -20,2 +18,8 @@

var _endpoints = require('./endpoints');
var endpoints = _interopRequireWildcard(_endpoints);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -27,2 +31,4 @@

function Dispatch(clientID, clientSecret) {
var _this = this;
var host = arguments.length <= 2 || arguments[2] === undefined ? 'https://api.dispatch.me' : arguments[2];

@@ -35,2 +41,16 @@

this.host = host;
this.entities = {
job: function job(jobId) {
return {
getNotes: function getNotes() {
var filters = {
file_token_null: 1,
entity_type: 'Job',
entity_id: jobId
};
return _this.getCollection(endpoints.ATTACHMENTS, filters);
}
};
}
};
}

@@ -99,3 +119,3 @@

value: function loginEmailPassword(email, password) {
var _this = this;
var _this2 = this;

@@ -109,3 +129,3 @@ return this.getNoAuthClient().post('/oauth/token', {

}).then(function (response) {
return _this.handleBearerToken(response.access_token, response.refresh_token);
return _this2.handleBearerToken(response.access_token, response.refresh_token);
});

@@ -137,6 +157,6 @@ }

value: function loginPhoneNumber(phoneNumber, verificationCode) {
var _this2 = this;
var _this3 = this;
return this.getNoAuthClient().post('/v1/phone_numbers/' + phoneNumber + '/verification_codes/' + verificationCode).then(function (response) {
return _this2.handleBearerToken(response.access_token, response.refresh_token);
return _this3.handleBearerToken(response.access_token, response.refresh_token);
});

@@ -160,3 +180,3 @@ }

value: function exchangeToken() {
var _this3 = this;
var _this4 = this;

@@ -171,3 +191,3 @@ var refreshToken = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];

}).then(function (response) {
return _this3.handleBearerToken(response.access_token, response.refresh_token);
return _this4.handleBearerToken(response.access_token, response.refresh_token);
});

@@ -177,4 +197,3 @@ }

/**
* Retrieve a collection from the API at the given endpoint. Promise resolves with
* an array of Models, which expose methods like `get`, `set`, `refresh`, and `save`.
* Retrieve a collection from the API at the given endpoint.
*

@@ -190,36 +209,12 @@ * @param {String} endpoint Endpoint (with no query string)

var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var returnModels = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2];
var fullPath = endpoint;
if (filter) {
var queryParams = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = filter[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var k = _step$value[0];
var v = _step$value[1];
queryParams.push('filter[' + k + ']=' + encodeURIComponent(v));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
fullPath = fullPath + '?' + queryParams.join('&');
(function () {
var queryParams = [];
Object.getOwnPropertyNames(filter).forEach(function (prop) {
queryParams.push('filter[' + prop + ']=' + encodeURIComponent(filter[prop]));
});
fullPath = fullPath + '?' + queryParams.join('&');
})();
}

@@ -230,7 +225,2 @@

var data = response[Object.keys(response)[0]];
if (returnModels) {
return data.map(function (entity) {
return new _model2.default(entity, endpoint, client);
});
}
return data;

@@ -270,3 +260,3 @@ });

entity_id: entityID
}, '/v1/attachments', this.getAuthClient());
}, endpoints.ATTACHMENTS, this.getAuthClient());
return note.save();

@@ -273,0 +263,0 @@ }

import RawClient, { AUTH_MODE_NONE, AUTH_MODE_BEARER } from './rawClient';
import Model from './model';
import * as endpoints from './endpoints';
import * as queryString from './queryString';
import jobMethods from './entities/job';
import Collection from './entities/Collection';
const DEFAULT_PER_PAGE = 20;
export default class Dispatch {

@@ -9,2 +14,6 @@ constructor(clientID, clientSecret, host = 'https://api.dispatch.me') {

this.host = host;
this.entities = {
job: jobMethods(this),
jobs: new Collection(this, endpoints.JOBS),
};
}

@@ -113,4 +122,3 @@

/**
* Retrieve a collection from the API at the given endpoint. Promise resolves with
* an array of Models, which expose methods like `get`, `set`, `refresh`, and `save`.
* Retrieve a collection from the API at the given endpoint.
*

@@ -121,11 +129,8 @@ * @param {String} endpoint Endpoint (with no query string)

*/
getCollection(endpoint, filter = null, returnModels = true) {
getCollection(endpoint, filter = null) {
let fullPath = endpoint;
if (filter) {
const queryParams = [];
for (const [k, v] of filter) {
queryParams.push(`filter[${k}]=${encodeURIComponent(v)}`);
}
fullPath = `${fullPath}?${queryParams.join('&')}`;
const queryParams = queryString.stringify(filter);
fullPath = `${fullPath}?${queryParams}`;
}

@@ -136,5 +141,2 @@

const data = response[Object.keys(response)[0]];
if (returnModels) {
return data.map(entity => new Model(entity, endpoint, client));
}
return data;

@@ -152,4 +154,3 @@ });

getModel(endpoint, id) {
const model = new Model({ id }, endpoint, this.getAuthClient());
return model.refresh();
return this.getAuthClient().get(`${endpoint}?filter[id_eq]=${id}`).then(response => response[Object.keys(response)[0]][0]);
}

@@ -169,5 +170,5 @@

entity_id: entityID,
}, '/v1/attachments', this.getAuthClient());
}, endpoints.ATTACHMENTS, this.getAuthClient());
return note.save();
}
}
{
"name": "dispatch-node-sdk",
"version": "0.0.4",
"version": "0.0.5",
"description": "High- and low-level libraries for interacting with the Dispatch API",
"main": "dist/lib/index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive 'lib/**/*_test.js'",
"test:cover": "istanbul cover _mocha -- --compilers js:babel-core/register --recursive 'lib/**/*_test.js'",
"test": "mocha --compilers js:babel-core/register --recursive 'lib/**/*.tests.js'",
"test:cover": "istanbul cover _mocha -- --compilers js:babel-core/register --recursive 'lib/**/*.tests.js'",
"test:watch": "npm test -- --watch",
"build": "node_modules/.bin/babel lib/*.js --out-dir dist/",
"build": "node_modules/.bin/babel lib --out-dir dist/lib --ignore 'lib/*.tests.js'",
"lint": "node_modules/.bin/eslint .",

@@ -12,0 +12,0 @@ "jscs": "jscs .",

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