Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
6
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.50 to 0.0.51

1

dist/lib/configuration.js

@@ -17,3 +17,2 @@ 'use strict';

*/
var Configuration = function () {

@@ -20,0 +19,0 @@ function Configuration(client) {

1

dist/lib/dispatch.js

@@ -116,2 +116,3 @@ 'use strict';

attachment: (0, _attachment2.default)(this),
billingDocuments: new _Collection2.default(this, endpoints.BILLING_DOCUMENTS),
brands: new _Collection2.default(this, endpoints.BRANDS),

@@ -118,0 +119,0 @@ customer: (0, _customer2.default)(this),

@@ -17,3 +17,2 @@ 'use strict';

*/
var Collection = function () {

@@ -20,0 +19,0 @@ function Collection(client, endpoint) {

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

});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = jobMethods;

@@ -15,2 +18,44 @@

/**
* Get the billing documents by doc type for a specific job.
* @param {Object} client The dispatch client instance.
* @param {String} id The id of the job to get the billing documents for.
* @param {String} docType The doc type of the billing document to get (Estimate/Inovice).
* @return {Promise} A Promise with the billing documents as the response.
*/
function getBillingDocuments(client, id, docType) {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: docType,
job_id: id
}
});
}
/**
* Add a billing document with a doc type to a specific job.
* @param {Object} client The dispatch client instance.
* @param {String} id The id of the job to add the billing document to.
* @param {String} docType The doc type of the billing document to add (Estimate/Inovice).
* @return {Promise} A Promise with the billing document as the response.
*/
function addBillingDocument(client, id, docType) {
return client.entities.jobs.getOne(id).then(function (_ref) {
var organization_id = _ref.organization_id;
var _ref$customer = _ref.customer;
var customer = _ref$customer === undefined ? {} : _ref$customer;
return client.entities.billingDocuments.create({
customer: _extends({}, customer, {
customer_id: customer.id
}),
doc_type: docType,
job_id: id,
organization_id: organization_id
}).then(function (response) {
return response.billing_document;
});
});
}
function jobMethods(client) {

@@ -41,18 +86,16 @@ return function (id) {

addEstimate: function addEstimate() {
return addBillingDocument(client, id, 'Estimate');
},
getEstimates: function getEstimates() {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Estimate',
job_id: id
}
});
return getBillingDocuments(client, id, 'Estimate');
},
addInvoice: function addInvoice() {
return addBillingDocument(client, id, 'Invoice');
},
getInvoices: function getInvoices() {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Invoice',
job_id: id
}
});
return getBillingDocuments(client, id, 'Invoice');
},

@@ -59,0 +102,0 @@

@@ -30,3 +30,2 @@ 'use strict';

/**

@@ -44,3 +43,2 @@ * Low-level client for interacting with the API.

*/
var RawClient = function () {

@@ -47,0 +45,0 @@ function RawClient(options) {

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

attachment: attachmentMethods(this),
billingDocuments: new Collection(this, endpoints.BILLING_DOCUMENTS),
brands: new Collection(this, endpoints.BRANDS),

@@ -51,0 +52,0 @@ customer: customerMethods(this),

import * as endpoints from '../endpoints';
/**
* Get the billing documents by doc type for a specific job.
* @param {Object} client The dispatch client instance.
* @param {String} id The id of the job to get the billing documents for.
* @param {String} docType The doc type of the billing document to get (Estimate/Inovice).
* @return {Promise} A Promise with the billing documents as the response.
*/
function getBillingDocuments(client, id, docType) {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: docType,
job_id: id,
},
});
}
/**
* Add a billing document with a doc type to a specific job.
* @param {Object} client The dispatch client instance.
* @param {String} id The id of the job to add the billing document to.
* @param {String} docType The doc type of the billing document to add (Estimate/Inovice).
* @return {Promise} A Promise with the billing document as the response.
*/
function addBillingDocument(client, id, docType) {
return client.entities.jobs.getOne(id).then(({ organization_id, customer = {} }) => {
return client.entities.billingDocuments.create({
customer: {
...customer,
customer_id: customer.id,
},
doc_type: docType,
job_id: id,
organization_id,
}).then(response => response.billing_document);
});
}
export default function jobMethods(client) {

@@ -27,20 +64,10 @@ return id => ({

getEstimates: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Estimate',
job_id: id,
},
});
},
addEstimate: () => addBillingDocument(client, id, 'Estimate'),
getInvoices: () => {
return client.getCollection(endpoints.BILLING_DOCUMENTS, {
filter: {
doc_type: 'Invoice',
job_id: id,
},
});
},
getEstimates: () => getBillingDocuments(client, id, 'Estimate'),
addInvoice: () => addBillingDocument(client, id, 'Invoice'),
getInvoices: () => getBillingDocuments(client, id, 'Invoice'),
addNote: (text, options) => {

@@ -47,0 +74,0 @@ const body = {

@@ -105,2 +105,42 @@ import expect from 'expect';

describe('addEstimate', () => {
it('should post the new billing document to the API', () => {
const testJob = {
id: 123,
organization_id: 1,
customer: {
id: 2,
},
doc_type: 'Estimate',
};
const client = new Dispatch(testClientID, testClientSecret);
client.setBearerToken(testBearerToken, testRefreshToken);
const jobRequest = nock('https://api.dispatch.me')
.get(`${endpoints.JOBS}?filter[id_eq]=123`)
.reply(200, {
jobs: [testJob],
});
const estimateRequest = nock('https://api.dispatch.me')
.post(endpoints.BILLING_DOCUMENTS, {
customer: {
...testJob.customer,
customer_id: testJob.customer.id,
},
doc_type: 'Estimate',
job_id: testJob.id,
organization_id: testJob.organization_id,
})
.reply(200, {
billing_document: {},
});
client.entities.job(123).addEstimate().then(() => {
expect(jobRequest.isDone()).toEqual(true);
expect(estimateRequest.isDone()).toEqual(true);
});
});
});
describe('getInvoices', () => {

@@ -118,3 +158,42 @@ it('should call endpoint with correct query string', () => {

describe('addInvoice', () => {
it('should post the new billing document to the API', () => {
const testJob = {
id: 123,
organization_id: 1,
customer: {
id: 2,
},
doc_type: 'Invoice',
};
const client = new Dispatch(testClientID, testClientSecret);
client.setBearerToken(testBearerToken, testRefreshToken);
const jobRequest = nock('https://api.dispatch.me')
.get(`${endpoints.JOBS}?filter[id_eq]=123`)
.reply(200, {
jobs: [testJob],
});
const estimateRequest = nock('https://api.dispatch.me')
.post(endpoints.BILLING_DOCUMENTS, {
customer: {
...testJob.customer,
customer_id: testJob.customer.id,
},
doc_type: 'Invoice',
job_id: testJob.id,
organization_id: testJob.organization_id,
})
.reply(200, {
billing_document: {},
});
client.entities.job(123).addInvoice().then(() => {
expect(jobRequest.isDone()).toEqual(true);
expect(estimateRequest.isDone()).toEqual(true);
});
});
});
describe('createAppointment', () => {

@@ -121,0 +200,0 @@ it('should call endpoint with correct body', () => {

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

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

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