dispatch-node-sdk
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -20,3 +20,3 @@ 'use strict'; | ||
bookNewOffer: function bookNewOffer(offerData) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var accountId = offerData.accountId; | ||
@@ -23,0 +23,0 @@ var data = offerData.data; |
@@ -59,3 +59,3 @@ 'use strict'; | ||
value: function setForEntity(entityType, entityID, config) { | ||
var overwrite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var overwrite = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3]; | ||
@@ -62,0 +62,0 @@ return this.client.doAuthenticatedRequest('POST', '/config/' + entityType + '/' + entityID, { |
@@ -105,11 +105,2 @@ 'use strict'; | ||
var serviceMap = { | ||
config: { | ||
'https://api-dev.dispatch.me': 'https://config-dev.dispatch.me', | ||
'https://api-stg.dispatch.me': 'https://config-staging.dispatch.me', | ||
'https://api-sandbox.dispatch.me': 'https://config-sandbox.dispatch.me', | ||
'https://api.dispatch.me': 'https://config.dispatch.me' | ||
} | ||
}; | ||
/** | ||
@@ -125,6 +116,5 @@ * Class Dispatch is the high-level abstracted client for *front-end use only*. | ||
*/ | ||
var Dispatch = function () { | ||
function Dispatch(clientID, clientSecret) { | ||
var host = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'https://api.dispatch.me'; | ||
var host = arguments.length <= 2 || arguments[2] === undefined ? 'https://api.dispatch.me' : arguments[2]; | ||
@@ -241,4 +231,16 @@ _classCallCheck(this, Dispatch); | ||
value: function determineAuxiliaryAPIHost(serviceName) { | ||
var replaceValue = this.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
return serviceMap[serviceName] ? serviceMap[serviceName][this.host] : this.host.replace(replaceValue, serviceName); | ||
switch (serviceName) { | ||
case 'config': | ||
case 'files-api': | ||
{ | ||
if (this.host.includes('-dev.')) return 'https://' + serviceName + '-dev.dispatch.me';else if (this.host.includes('-stg.') || this.host.includes('-staging.')) return 'https://' + serviceName + '-staging.dispatch.me';else if (this.host.includes('-sandbox.')) return 'https://' + serviceName + '-sandbox.dispatch.me'; | ||
return 'https://' + serviceName + '.dispatch.me'; | ||
} | ||
default: | ||
{ | ||
// XXX This isn't a good way to do this, but leaving it here for backwards compatibility for now | ||
var replaceValue = this.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
return this.host.replace(replaceValue, serviceName); | ||
} | ||
} | ||
} | ||
@@ -501,3 +503,3 @@ | ||
var refreshToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var refreshToken = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
@@ -525,4 +527,4 @@ return this.getNoAuthClient().post('/oauth/token', { | ||
value: function getCollection(endpoint) { | ||
var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -555,3 +557,3 @@ var fullPath = endpoint; | ||
value: function getCollectionWithMeta(endpoint) { | ||
var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
@@ -583,3 +585,3 @@ return this.getCollection(endpoint, filter, { raw: true }).then(function (response) { | ||
value: function appendAnalyticsHeaders() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -617,4 +619,4 @@ var analytics = Object.assign({}, this.session, options.analytics); | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
@@ -677,3 +679,3 @@ var req = new _request2.default(method, endpoint, body, this.appendAnalyticsHeaders(options)); | ||
value: function uploadFile(file, name) { | ||
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'square_photo'; | ||
var type = arguments.length <= 2 || arguments[2] === undefined ? 'square_photo' : arguments[2]; | ||
var options = arguments[3]; | ||
@@ -700,3 +702,3 @@ | ||
value: function setSession() { | ||
var sessionVars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var sessionVars = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -734,3 +736,3 @@ this.session = sessionVars; | ||
function getMatchedWords() { | ||
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var result = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -766,3 +768,3 @@ var matches = result._highlightResult || {}; // eslint-disable-line no-underscore-dangle | ||
function arraysToStrings(obj) { | ||
var skipProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var skipProps = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
@@ -780,4 +782,3 @@ Object.getOwnPropertyNames(obj || {}).forEach(function (prop) { | ||
return this.getAuthClient().get(endpoints.SEARCH + '?organization_id=' + organizationID + '&q=' + query + limitQuery + filterQuery).then(function (response) { | ||
var replaceValue = _this8.authClient.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
host = _this8.authClient.host.replace(replaceValue, 'files-api'); | ||
host = _this8.determineAuxiliaryAPIHost('files-api'); | ||
@@ -850,3 +851,3 @@ // Build customers object for returning. | ||
var appointmentInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var appointmentInfo = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
@@ -853,0 +854,0 @@ var returnData = { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
sendNotification: function sendNotification(appointmentProperties) { | ||
var headerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var headerOptions = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -21,0 +21,0 @@ return client.doAuthenticatedRequest('PATCH', endpoints.APPOINTMENTS + '/' + id + '/notify', appointmentProperties, headerOptions); |
@@ -36,4 +36,4 @@ 'use strict'; | ||
value: function get() { | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -45,3 +45,3 @@ return this.client.getCollection(this.endpoint, query, opts); | ||
value: function getWithMeta() { | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -58,3 +58,3 @@ return this.client.getCollectionWithMeta(this.endpoint, query); | ||
value: function create(data) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -76,3 +76,3 @@ return this.client.doAuthenticatedRequest('POST', this.endpoint, data, options).then(function (response) { | ||
value: function update(id, data) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -79,0 +79,0 @@ return this.client.doAuthenticatedRequest('PATCH', this.getSingleEndpoint(id), data, options).then(function (response) { |
@@ -73,4 +73,4 @@ 'use strict'; | ||
function actOnOffer(client, id, action) { | ||
var body = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
var body = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4]; | ||
@@ -188,3 +188,3 @@ if (action === 'accept') { | ||
createAppointment: function createAppointment() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var data = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var options = arguments[1]; | ||
@@ -200,3 +200,3 @@ | ||
getAppointments: function getAppointments() { | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -231,3 +231,3 @@ if (query.filter) { | ||
getSurveys: function getSurveys() { | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -248,3 +248,3 @@ var DEFAULT_QUERY = { | ||
update: function update(jobProperties) { | ||
var headerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var headerOptions = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -251,0 +251,0 @@ return client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, jobProperties, headerOptions).then(function (response) { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
@@ -10,0 +10,0 @@ exports.default = organizationMethods; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
@@ -10,0 +10,0 @@ exports.default = userMethods; |
@@ -56,3 +56,3 @@ 'use strict'; | ||
value: function addForEntity(entityType, entityID, name) { | ||
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var config = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
@@ -59,0 +59,0 @@ var body = _extends({ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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; }; | ||
@@ -10,0 +10,0 @@ exports.stringify = stringify; |
@@ -88,3 +88,3 @@ 'use strict'; | ||
value: function get(endpoint) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -96,3 +96,3 @@ return this.doRequest('GET', endpoint, null, options); | ||
value: function post(endpoint, body) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -104,3 +104,3 @@ return this.doRequest('POST', endpoint, body, options); | ||
value: function put(endpoint, body) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -112,3 +112,3 @@ return this.doRequest('PUT', endpoint, body, options); | ||
value: function patch(endpoint, body) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -120,3 +120,3 @@ return this.doRequest('PATCH', endpoint, body, options); | ||
value: function _delete(endpoint) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -128,4 +128,4 @@ return this.doRequest('DELETE', endpoint, null, options); | ||
value: function doRequest(method, endpoint) { | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
@@ -132,0 +132,0 @@ var url = this.host + endpoint; |
@@ -13,4 +13,4 @@ "use strict"; | ||
function Request(method, endpoint) { | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
@@ -17,0 +17,0 @@ _classCallCheck(this, Request); |
@@ -25,11 +25,2 @@ import * as endpoints from './endpoints'; | ||
const serviceMap = { | ||
config: { | ||
'https://api-dev.dispatch.me': 'https://config-dev.dispatch.me', | ||
'https://api-stg.dispatch.me': 'https://config-staging.dispatch.me', | ||
'https://api-sandbox.dispatch.me': 'https://config-sandbox.dispatch.me', | ||
'https://api.dispatch.me': 'https://config.dispatch.me', | ||
}, | ||
}; | ||
/** | ||
@@ -142,4 +133,16 @@ * Class Dispatch is the high-level abstracted client for *front-end use only*. | ||
determineAuxiliaryAPIHost(serviceName) { | ||
const replaceValue = this.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
return serviceMap[serviceName] ? serviceMap[serviceName][this.host] : this.host.replace(replaceValue, serviceName); | ||
switch (serviceName) { | ||
case 'config': | ||
case 'files-api': { | ||
if (this.host.includes('-dev.')) return `https://${serviceName}-dev.dispatch.me`; | ||
else if (this.host.includes('-stg.') || this.host.includes('-staging.')) return `https://${serviceName}-staging.dispatch.me`; | ||
else if (this.host.includes('-sandbox.')) return `https://${serviceName}-sandbox.dispatch.me`; | ||
return `https://${serviceName}.dispatch.me`; | ||
} | ||
default: { | ||
// XXX This isn't a good way to do this, but leaving it here for backwards compatibility for now | ||
const replaceValue = this.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
return this.host.replace(replaceValue, serviceName); | ||
} | ||
} | ||
} | ||
@@ -556,4 +559,3 @@ | ||
.then(response => { | ||
const replaceValue = this.authClient.host.includes('wfm') ? 'wfm-api' : 'api'; | ||
host = this.authClient.host.replace(replaceValue, 'files-api'); | ||
host = this.determineAuxiliaryAPIHost('files-api'); | ||
@@ -560,0 +562,0 @@ // Build customers object for returning. |
@@ -925,12 +925,70 @@ import nock from 'nock'; | ||
describe('determineAuxiliaryAPIHost', () => { | ||
const client = new Dispatch(testClientID, testClientSecret, 'https://api-stg.dispatch.me'); | ||
const devClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-dev.dispatch.me'); | ||
const stagingClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-staging.dispatch.me'); | ||
const sandboxClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-sandbox.dispatch.me'); | ||
const prodClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api.dispatch.me'); | ||
it('determines the host of a service using our naming convention', () => { | ||
expect(client.determineAuxiliaryAPIHost('files-api')).toEqual('https://files-api-stg.dispatch.me'); | ||
describe('dev', () => { | ||
it('files', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
}); | ||
it('config', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('config')).toBe('https://config-dev.dispatch.me'); | ||
}); | ||
it('other', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('other')).toBe('https://other-dev.dispatch.me'); | ||
}); | ||
}); | ||
it('uses a host from the service map if specified', () => { | ||
expect(client.determineAuxiliaryAPIHost('config')).toEqual('https://config-staging.dispatch.me'); | ||
describe('staging', () => { | ||
it('files', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-staging.dispatch.me'); | ||
}); | ||
it('config', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('config')).toBe('https://config-staging.dispatch.me'); | ||
}); | ||
it('other', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('other')).toBe('https://other-staging.dispatch.me'); | ||
}); | ||
}); | ||
describe('sandbox', () => { | ||
it('files', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-sandbox.dispatch.me'); | ||
}); | ||
it('config', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('config')).toBe('https://config-sandbox.dispatch.me'); | ||
}); | ||
it('other', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('other')).toBe('https://other-sandbox.dispatch.me'); | ||
}); | ||
}); | ||
describe('production', () => { | ||
it('files', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
}); | ||
it('config', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('config')).toBe('https://config.dispatch.me'); | ||
}); | ||
it('other', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('other')).toBe('https://other.dispatch.me'); | ||
}); | ||
}); | ||
it('admin-api', () => { | ||
let client = new Dispatch(testClientID, testClientSecret, 'https://admin-api.dispatch.me'); | ||
expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
client = new Dispatch(testClientID, testClientSecret, 'https://admin-api-dev.dispatch.me'); | ||
expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "dispatch-node-sdk", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "High- and low-level libraries for interacting with the Dispatch API", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281516
7018