Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
2
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.31 to 0.0.32

dist/lib/entities/user.js

5

dist/lib/dispatch.js

@@ -69,2 +69,6 @@ 'use strict';

var _user = require('./entities/user');
var _user2 = _interopRequireDefault(_user);
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; } }

@@ -111,2 +115,3 @@

organizations: new _Collection2.default(this, endpoints.ORGANIZATIONS),
user: (0, _user2.default)(this),
users: new _Collection2.default(this, endpoints.USERS)

@@ -113,0 +118,0 @@ };

12

dist/lib/entities/attachment.js

@@ -6,5 +6,8 @@ 'use strict';

});
exports.default = attachmentMethods;
exports.default = function (client) {
var attachment = function attachment(id) {
var _endpoints = require('../endpoints');
function attachmentMethods(client) {
return function (id) {
return {

@@ -28,5 +31,2 @@ update: function update(text, options) {

};
return attachment;
};
var _endpoints = require('../endpoints');
}

@@ -6,5 +6,8 @@ 'use strict';

});
exports.default = customerMethods;
exports.default = function (client) {
var customer = function customer(id) {
var _endpoints = require('../endpoints');
function customerMethods(client) {
return function (id) {
return {

@@ -18,5 +21,2 @@ update: function update(customerProperties) {

};
return customer;
};
var _endpoints = require('../endpoints');
}

@@ -6,5 +6,12 @@ 'use strict';

});
exports.default = jobMethods;
exports.default = function (client) {
var job = function job(id) {
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 jobMethods(client) {
return function (id) {
return {

@@ -21,2 +28,3 @@ getNotes: function getNotes() {

},
getPhotos: function getPhotos() {

@@ -117,10 +125,2 @@ var query = {

};
return job;
};
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; } }
}

@@ -7,15 +7,32 @@ 'use strict';

exports.default = function (client) {
var organization = function organization(id) {
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
exports.default = organizationMethods;
var _endpoints = require('../endpoints');
var _workHours = require('../workHours');
function organizationMethods(client) {
return function (id) {
return {
addCustomer: function addCustomer(customer) {
if (!id || !customer) throw new Error('Usage: organization(id).addCustomer(customer)');
return client.doAuthenticatedRequest('POST', '' + _endpoints.CUSTOMERS, Object.assign({}, { organization_id: id }, customer)).then(function (response) {
return response.customer;
});
},
dateIsInWorkHours: function dateIsInWorkHours(date) {
if (!id || !date) throw new Error('Usage: organization(id).dateIsInWorkHours(date)');
return client.entities.organizations.getOne(id).then(function (organization) {
if (organization.working_hours && _typeof(organization.working_hours) === 'object' && Object.keys(organization.working_hours).length > 0 && organization.timezone) {
return (0, _workHours.inWorkHours)(organization.working_hours, organization.timezone, date);
}
return false;
}).catch(function () {
throw new Error('Could not find organization when querying for work hours!');
});
}
};
};
return organization;
};
var _endpoints = require('../endpoints');
}

@@ -12,3 +12,3 @@ 'use strict';

*/
var dataURItoBlob = exports.dataURItoBlob = function dataURItoBlob(dataURI) {
function dataURItoBlob(dataURI) {
var byteString = void 0;

@@ -31,2 +31,4 @@ if (dataURI.split(',')[0].indexOf('base64') >= 0) {

return new Blob([ia], { type: mimeString });
};
}
exports.dataURItoBlob = dataURItoBlob;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.AUTH_MODE_BEARER = exports.AUTH_MODE_NONE = exports.AUTH_MODE_HMAC = exports.APIError = exports.ForbiddenError = exports.UnprocessableEntityError = exports.NotFoundError = exports.UnauthorizedError = exports.timezoneMap = exports.RawClient = undefined;
exports.AUTH_MODE_BEARER = exports.AUTH_MODE_NONE = exports.AUTH_MODE_HMAC = exports.APIError = exports.ForbiddenError = exports.UnprocessableEntityError = exports.NotFoundError = exports.UnauthorizedError = exports.inWorkHours = exports.timezoneMap = exports.getCurrentTimeInTimezone = exports.RawClient = undefined;

@@ -17,8 +17,8 @@ var _dispatch = require('./dispatch');

var _timezoneMap = require('./timezoneMap');
var _timezones = require('./timezones');
var _timezoneMap2 = _interopRequireDefault(_timezoneMap);
var _errors = require('./errors');
var _workHours = require('./workHours');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -28,3 +28,5 @@

exports.RawClient = _rawClient2.default;
exports.timezoneMap = _timezoneMap2.default;
exports.getCurrentTimeInTimezone = _timezones.getCurrentTimeInTimezone;
exports.timezoneMap = _timezones.timezoneMap;
exports.inWorkHours = _workHours.inWorkHours;
exports.UnauthorizedError = _errors.UnauthorizedError;

@@ -31,0 +33,0 @@ exports.NotFoundError = _errors.NotFoundError;

@@ -17,2 +17,3 @@ import _ from 'underscore';

import Configuration from './configuration';
import userMethods from './entities/user';

@@ -49,2 +50,3 @@ /**

organizations: new Collection(this, endpoints.ORGANIZATIONS),
user: userMethods(this),
users: new Collection(this, endpoints.USERS),

@@ -51,0 +53,0 @@ };

@@ -240,3 +240,3 @@ import nock from 'nock';

const client = new Dispatch(testClientID, testClientSecret);
nock('https://api.dispatch.me').get('/').times(1).reply(function () {
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() {
expect(this.req.headers['x-transaction-id']).toExist();

@@ -263,3 +263,3 @@ done();

const client = new Dispatch(testClientID, testClientSecret);
nock('https://api.dispatch.me').get('/').times(1).reply(function () {
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() {
expect(this.req.headers['x-analytics-tags']).toEqual('foo:bar,bar:foo');

@@ -286,3 +286,3 @@ done();

const client = new Dispatch(testClientID, testClientSecret);
nock('https://api.dispatch.me').get('/').times(1).reply(function () {
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() {
expect(this.req.headers['x-analytics-tags']).toEqual('baz:bing,foo:bar,bar:foo');

@@ -289,0 +289,0 @@ done();

import { ATTACHMENTS } from '../endpoints';
export default function(client) {
const attachment = function(id) {
return {
update: (text, options) => {
return client.doAuthenticatedRequest('PATCH', `${ATTACHMENTS}/${id}`, {
description: text,
}, options).then(response => {
return response.attachment;
});
},
export default function attachmentMethods(client) {
return id => ({
update: (text, options) => {
return client.doAuthenticatedRequest('PATCH', `${ATTACHMENTS}/${id}`, {
description: text,
}, options).then(response => {
return response.attachment;
});
},
delete: (options) => {
return client.doAuthenticatedRequest('DELETE', `${ATTACHMENTS}/${id}`, null, options)
.then(() => {
// endpoint returns no content on successful request
// return id of successfully deleted item b/c its useful for resolve callbacks
return id;
});
},
};
};
return attachment;
delete: (options) => {
return client.doAuthenticatedRequest('DELETE', `${ATTACHMENTS}/${id}`, null, options)
.then(() => {
// endpoint returns no content on successful request
// return id of successfully deleted item b/c its useful for resolve callbacks
return id;
});
},
});
}
import { CUSTOMERS } from '../endpoints';
export default function(client) {
const customer = function(id) {
return {
update: (customerProperties) => {
return client
.doAuthenticatedRequest('PATCH', `${CUSTOMERS}/${id}`, customerProperties)
.then(response => response.customer);
},
};
};
return customer;
export default function customerMethods(client) {
return id => ({
update: (customerProperties) => {
return client
.doAuthenticatedRequest('PATCH', `${CUSTOMERS}/${id}`, customerProperties)
.then(response => response.customer);
},
});
}
import * as endpoints from '../endpoints';
export default function(client) {
const job = function(id) {
return {
getNotes: () => {
const query = {
filter: {
file_token_null: 1,
entity_type: 'Job',
entity_id: id,
},
};
return client.getCollection(endpoints.ATTACHMENTS, query);
},
getPhotos: () => {
const query = {
filter: {
file_token_not_eq: 'null',
entity_type: 'Job',
entity_id: id,
},
};
return client.getCollection(endpoints.ATTACHMENTS, query);
},
getEstimates: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Estimate',
job_id: id,
},
});
},
getInvoices: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Invoice',
job_id: id,
},
});
},
addNote: (text, options) => {
const body = {
export default function jobMethods(client) {
return id => ({
getNotes: () => {
const query = {
filter: {
file_token_null: 1,
entity_type: 'Job',
entity_id: id,
description: text,
};
},
};
return client.getCollection(endpoints.ATTACHMENTS, query);
},
return client.doAuthenticatedRequest('POST', endpoints.ATTACHMENTS, body, options).then(response => response.attachment);
},
addPhoto: (fileToken, name, description, options) => {
const body = {
getPhotos: () => {
const query = {
filter: {
file_token_not_eq: 'null',
entity_type: 'Job',
entity_id: id,
description,
name,
file_token: fileToken,
};
},
};
return client.getCollection(endpoints.ATTACHMENTS, query);
},
return client.doAuthenticatedRequest('POST', endpoints.ATTACHMENTS, body, options).then(response => response.attachment);
},
getEstimates: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Estimate',
job_id: id,
},
});
},
createAppointment: (data = {}, options) => {
const body = Object.assign({}, data, { job_id: id });
getInvoices: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Invoice',
job_id: id,
},
});
},
return client.doAuthenticatedRequest('POST', endpoints.APPOINTMENTS, body, options);
},
addNote: (text, options) => {
const body = {
entity_type: 'Job',
entity_id: id,
description: text,
};
getAppointments: (query = {}) => {
if (query.filter) {
query.filter = Object.assign({}, query.filter, {
job_id_eq: id,
});
} else {
query.filter = {
job_id_eq: id,
};
}
return client.getCollection(endpoints.APPOINTMENTS, query);
},
return client.doAuthenticatedRequest('POST', endpoints.ATTACHMENTS, body, options).then(response => response.attachment);
},
getScheduledAppointment: () => {
return client.entities.job(id).getAppointments({
filter: {
status_eq: 'scheduled',
},
limit: 1,
sort: 'time+desc',
})
.then(appts => {
if (appts.length) {
return appts[0];
}
return null;
addPhoto: (fileToken, name, description, options) => {
const body = {
entity_type: 'Job',
entity_id: id,
description,
name,
file_token: fileToken,
};
return client.doAuthenticatedRequest('POST', endpoints.ATTACHMENTS, body, options).then(response => response.attachment);
},
createAppointment: (data = {}, options) => {
const body = Object.assign({}, data, { job_id: id });
return client.doAuthenticatedRequest('POST', endpoints.APPOINTMENTS, body, options);
},
getAppointments: (query = {}) => {
if (query.filter) {
query.filter = Object.assign({}, query.filter, {
job_id_eq: id,
});
},
};
};
} else {
query.filter = {
job_id_eq: id,
};
}
return client.getCollection(endpoints.APPOINTMENTS, query);
},
return job;
getScheduledAppointment: () => {
return client.entities.job(id).getAppointments({
filter: {
status_eq: 'scheduled',
},
limit: 1,
sort: 'time+desc',
})
.then(appts => {
if (appts.length) {
return appts[0];
}
return null;
});
},
});
}
import { CUSTOMERS } from '../endpoints';
import { inWorkHours } from '../workHours';
export default function(client) {
const organization = function(id) {
return {
addCustomer: (customer) => {
return client
.doAuthenticatedRequest('POST', `${CUSTOMERS}`, Object.assign({}, { organization_id: id }, customer))
.then(response => response.customer);
},
};
};
return organization;
export default function organizationMethods(client) {
return id => ({
addCustomer: (customer) => {
if (!id || !customer) throw new Error('Usage: organization(id).addCustomer(customer)');
return client
.doAuthenticatedRequest('POST', `${CUSTOMERS}`, Object.assign({}, { organization_id: id }, customer))
.then(response => response.customer);
},
dateIsInWorkHours: date => {
if (!id || !date) throw new Error('Usage: organization(id).dateIsInWorkHours(date)');
return client.entities.organizations.getOne(id)
.then(organization => {
if (organization.working_hours && typeof organization.working_hours === 'object' &&
Object.keys(organization.working_hours).length > 0 && organization.timezone) {
return inWorkHours(organization.working_hours, organization.timezone, date);
}
return false;
})
.catch(() => {
throw new Error('Could not find organization when querying for work hours!');
});
},
});
}

@@ -1,5 +0,7 @@

import expect from 'expect';
import expect, { spyOn, restoreSpies } from 'expect';
import Dispatch from '../dispatch';
import nock from 'nock';
import * as endpoints from '../endpoints';
import * as workHours from '../workHours';
const testClientID = '12345';

@@ -9,8 +11,41 @@ const testClientSecret = '54321';

const testRefreshToken = 'this is the refresh token';
const testWorkHours = {
0: [],
1: [
'08:00:00 - 11:00:00',
'12:00:00 - 16:00:00',
],
2: [
'08:00:00 - 11:00:00',
'12:00:00 - 16:00:00',
],
3: [
'08:00:00 - 11:00:00',
'12:00:00 - 16:00:00',
],
4: [
'08:00:00 - 11:00:00',
'12:00:00 - 16:00:00',
],
5: [
'08:00:00 - 11:00:00',
'12:00:00 - 16:00:00',
],
6: [],
};
describe('organization', () => {
let client;
before(() => {
client = new Dispatch(testClientID, testClientSecret);
client.setBearerToken(testBearerToken, testRefreshToken);
});
afterEach(() => {
restoreSpies();
});
describe('addCustomer', () => {
it('should call endpoint with correct body', () => {
const client = new Dispatch(testClientID, testClientSecret);
client.setBearerToken(testBearerToken, testRefreshToken);
const customer = {

@@ -43,2 +78,50 @@ first_name: 'Ron',

});
describe('dateIsInWorkHours', () => {
it('should work for an organization that has hours and timezone set', done => {
spyOn(client.entities.organizations, 'getOne').andReturn(Promise.resolve({
timezone: 'Pacific Time (US & Canada)',
working_hours: testWorkHours,
}));
spyOn(workHours, 'inWorkHours').andReturn(true);
const date = new Date();
client.entities.organization(5).dateIsInWorkHours(date).then(result => {
expect(result).toEqual(true);
expect(workHours.inWorkHours).toHaveBeenCalledWith(testWorkHours, 'Pacific Time (US & Canada)', date);
done();
});
});
it('should return false for an organization that has no timezone set', done => {
spyOn(client.entities.organizations, 'getOne').andReturn(Promise.resolve({
working_hours: testWorkHours,
}));
spyOn(workHours, 'inWorkHours').andReturn(true);
const date = new Date();
client.entities.organization(5).dateIsInWorkHours(date).then(result => {
expect(result).toEqual(false);
expect(workHours.inWorkHours).toNotHaveBeenCalled();
done();
});
});
it('should return false for an organization that has no working_hours set', done => {
spyOn(client.entities.organizations, 'getOne').andReturn(Promise.resolve({
timezone: 'Pacific Time (US & Canada)',
}));
spyOn(workHours, 'inWorkHours').andReturn(true);
const date = new Date();
client.entities.organization(5).dateIsInWorkHours(date).then(result => {
expect(result).toEqual(false);
expect(workHours.inWorkHours).toNotHaveBeenCalled();
done();
});
});
});
});

@@ -7,3 +7,3 @@ /**

*/
export const dataURItoBlob = function(dataURI) {
function dataURItoBlob(dataURI) {
let byteString;

@@ -26,2 +26,4 @@ if (dataURI.split(',')[0].indexOf('base64') >= 0) {

return new Blob([ia], { type: mimeString });
};
}
export { dataURItoBlob };
import Dispatch from './dispatch';
import RawClient, { AUTH_MODE_BEARER, AUTH_MODE_NONE, AUTH_MODE_HMAC } from './rawClient';
import timezoneMap from './timezoneMap';
import { getCurrentTimeInTimezone, timezoneMap } from './timezones';
import {

@@ -11,2 +11,3 @@ UnauthorizedError,

} from './errors';
import { inWorkHours } from './workHours';

@@ -16,3 +17,5 @@ export default Dispatch;

RawClient,
getCurrentTimeInTimezone,
timezoneMap,
inWorkHours,
UnauthorizedError,

@@ -19,0 +22,0 @@ NotFoundError,

{
"name": "dispatch-node-sdk",
"version": "0.0.31",
"version": "0.0.32",
"description": "High- and low-level libraries for interacting with the Dispatch API",

@@ -39,2 +39,3 @@ "main": "dist/lib/index.js",

"moment": "^2.13.0",
"moment-timezone": "^0.5.4",
"node-uuid": "^1.4.7",

@@ -41,0 +42,0 @@ "simplecheck": "^0.1.2",

@@ -160,1 +160,57 @@ Dispatch JavaScript SDK

## Organization-Scope Functions
These functions are available on client.entities.organization(id).
### addCustomer
```js
client.entities.organization(5).addCustomer({
first_name: 'Ron',
last_name: 'Swanson',
email: 'rswan@pr.com',
home_address: {
street_1: '2475 Mountain Avenue',
street_2: '',
postal_code: '50265',
city: 'West Des Moines',
state: 'IA',
},
phone_number: '+17069203204',
phone_numbers: {
'+17069203204': {
type: 'Mobile',
number: '+17069203204',
primary: true,
},
},
}).then(result => {
// result is the created customer object returned from the API
});
```
### dateIsInWorkHours
Checks whether a date falls during an organization's defined work hours. The organization must have a `timezone` defined for this to work. Otherwise it always returns `false`.
```js
const date = new Date();
client.entities.organization(5).dateIsInWorkHours(date).then(result => {
// result is true or false
});
```
## User-Scope Functions
These functions are available on client.entities.user(id).
### dateIsInWorkHours
Checks whether a date falls during a user's defined work hours, or during that user's organization's defined work hours if the user does not have work hours defined. Either the user or the organization must have a `timezone` defined for this to work. Otherwise it always returns `false`.
```js
const date = new Date();
client.entities.user(5).dateIsInWorkHours(date).then(result => {
// result is true or false
});
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc