Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
5
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.35 to 0.0.36

29

dist/lib/dispatch.js

@@ -420,2 +420,31 @@ 'use strict';

/**
* Retrieve a collection from the API at the given endpoint with meta data.
*
* @param {String} endpoint Endpoint (with no query string)
* @param {Object} filter Optional query filters
* @return {Promise}
*/
}, {
key: 'getCollectionWithMeta',
value: function getCollectionWithMeta(endpoint) {
var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
return this.getCollection(endpoint, filter, { raw: true }).then(function (response) {
var meta = {};
var data = Object.keys(response).length > 2 ? {} : [];
Object.keys(response).forEach(function (prop) {
if (prop === 'meta') {
meta = response[prop];
} else if (Array.isArray(data)) {
data = response[prop];
} else {
data[prop] = response[prop];
}
});
return { meta: meta, data: data };
});
}
/**
* Append analyitcs tags and a transaction ID to the headers.

@@ -422,0 +451,0 @@ * @param {Object} options A set of options for a request.

@@ -35,2 +35,9 @@ 'use strict';

}, {
key: 'getWithMeta',
value: function getWithMeta() {
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
return this.client.getCollectionWithMeta(this.endpoint, query);
}
}, {
key: 'getOne',

@@ -37,0 +44,0 @@ value: function getOne(id) {

@@ -284,2 +284,26 @@ import _ from 'underscore';

/**
* Retrieve a collection from the API at the given endpoint with meta data.
*
* @param {String} endpoint Endpoint (with no query string)
* @param {Object} filter Optional query filters
* @return {Promise}
*/
getCollectionWithMeta(endpoint, filter = null) {
return this.getCollection(endpoint, filter, { raw: true }).then(response => {
let meta = {};
let data = Object.keys(response).length > 2 ? {} : [];
Object.keys(response).forEach(prop => {
if (prop === 'meta') {
meta = response[prop];
} else if (Array.isArray(data)) {
data = response[prop];
} else {
data[prop] = response[prop];
}
});
return { meta, data };
});
}
/**
* Append analyitcs tags and a transaction ID to the headers.

@@ -286,0 +310,0 @@ * @param {Object} options A set of options for a request.

@@ -132,2 +132,89 @@ import nock from 'nock';

it('should return meta data with getCollectionMeta', done => {
const client = new Dispatch(testClientID, testClientSecret, 'https://api-dev.dispatch.me');
const query = { limit: 1, offset: 0 };
client.setBearerToken(testBearerToken, testRefreshToken);
nock('https://api-dev.dispatch.me').get('/v1/customers?limit=1&offset=0').reply(200, {
customers: [{
id: 6394,
phone_numbers: {
'+15555555555': {
type: 'Mobile',
number: '+15555555555',
primary: true,
},
},
notes: null,
external_ids: [
'qbo:1-64:0',
],
}],
meta: {
total: 419,
limit: 1,
offset: 0,
},
});
client.getCollectionWithMeta('/v1/customers', query).then(response => {
expect(response.data.length).toEqual(1);
expect(response.meta).toEqual({
total: 419,
limit: 1,
offset: 0,
});
done();
}).catch(done);
});
it('should return meta data as an object (if !meta props are more than 1) with getCollectionMeta', done => {
const client = new Dispatch(testClientID, testClientSecret, 'https://api-dev.dispatch.me');
const query = { limit: 1, offset: 0 };
client.setBearerToken(testBearerToken, testRefreshToken);
nock('https://api-dev.dispatch.me').get('/v1/customers?limit=1&offset=0').reply(200, {
customers: [{
id: 6394,
phone_numbers: {
'+15555555555': {
type: 'Mobile',
number: '+15555555555',
primary: true,
},
},
notes: null,
external_ids: [
'qbo:1-64:0',
],
}],
something_else: [{
id: 6394,
phone_numbers: {
'+15555555555': {
type: 'Mobile',
number: '+15555555555',
primary: true,
},
},
notes: null,
external_ids: [
'qbo:1-64:0',
],
}],
meta: {
total: 419,
limit: 1,
offset: 0,
},
});
client.getCollectionWithMeta('/v1/customers', query).then(response => {
expect(Object.keys(response.data).length).toEqual(2);
expect(response.meta).toEqual({
total: 419,
limit: 1,
offset: 0,
});
done();
}).catch(done);
});
it('should return raw response from collection when raw=true', (done) => {

@@ -134,0 +221,0 @@ const client = new Dispatch(testClientID, testClientSecret);

4

lib/entities/Collection.js

@@ -17,2 +17,6 @@ /**

getWithMeta(query = {}) {
return this.client.getCollectionWithMeta(this.endpoint, query);
}
getOne(id) {

@@ -19,0 +23,0 @@ return this.client.getModel(this.endpoint, id);

@@ -32,2 +32,15 @@ import expect from 'expect';

describe('getWithMeta', () => {
it('should call endpoint with correct query string and meta data', () => {
const client = new Dispatch(testClientID, testClientSecret);
client.setBearerToken(testBearerToken, testRefreshToken);
const scope = nock('https://api.dispatch.me')
.get(`${endpoints.CUSTOMERS}?limit=1&offset=0`)
.reply(200);
const col = new Collection(client, endpoints.CUSTOMERS);
col.getWithMeta({ limit: 1, offset: 0 });
expect(scope.isDone()).toEqual(true);
});
});
describe('getOne', () => {

@@ -34,0 +47,0 @@ it('should call endpoint with correct query string', () => {

2

package.json
{
"name": "dispatch-node-sdk",
"version": "0.0.35",
"version": "0.0.36",
"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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc