atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
108 lines (94 loc) • 3.99 kB
JavaScript
;
var R = require('ramda');
var location = require('../../../src/utils/location.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
const headlessCommands = [
{ command: 'destroy' },
{
command: 'getDirections',
args: [
{ name: 'from', type: 'location' },
{ name: 'to', type: 'location' },
{ name: 'accessible', type: 'boolean', optional: true },
{ name: 'queueTypes', type: 'list', itemType: { type: 'string' }, optional: true }
]
},
{
command: 'getDirectionsMultiple',
args: [
{ name: 'locations', type: 'list', itemType: { type: 'location' } },
{ name: 'accessible', type: 'boolean', optional: true },
{ name: 'queueTypes', type: 'list', itemType: { type: 'string' }, optional: true }
]
},
{ command: 'getPOIDetails', args: [{ name: 'poiId', type: 'integer', min: 0 }] },
{ command: 'getAllPOIs' },
{ command: 'getStructures' },
{ command: 'getVenueData' },
{
command: 'search',
args: [
{ name: 'term', type: 'string', minLength: 2 },
{ name: 'details', type: 'boolean', optional: true }
]
}
];
function handleHeadless (app) {
app.bus.on('clientAPI/destroy', async () => app.destroy());
app.bus.on('clientAPI/getDirections', async ({ from, to, accessible, queueTypes }) => {
const fromEndpoint = await location.locationToEndpoint(app, from);
const toEndpoint = await location.locationToEndpoint(app, to);
const options = { requiresAccessibility: !!accessible };
if (queueTypes)
options.selectedSecurityLanes = { SecurityLane: queueTypes };
return app.bus.get('wayfinder/getRoute', { fromEndpoint, toEndpoint, options })
.then(R__namespace.pick(['distance', 'time', 'steps', 'navline', 'waypoints']))
});
app.bus.on('clientAPI/getDirectionsMultiple', async ({ locations, accessible, queueTypes }) => {
const endpoints = await Promise.all(locations.map(async l => location.locationToEndpoint(app, l)));
const options = { requiresAccessibility: !!accessible };
if (queueTypes)
options.selectedSecurityLanes = { SecurityLane: queueTypes };
const routes = await Promise.all(R__namespace.aperture(2, endpoints).map(async a =>
app.bus.get('wayfinder/getRoute', { fromEndpoint: a[0], toEndpoint: a[1], options })));
const directions = R__namespace.map(R__namespace.pick(['distance', 'time', 'steps', 'navline', 'waypoints']), routes);
return {
total: {
distance: R__namespace.sum(R__namespace.map(d => d.distance, directions)),
time: R__namespace.sum(R__namespace.map(d => d.time, directions))
},
directions
}
});
app.bus.on('clientAPI/getPOIDetails', async ({ poiId }) => app.bus.get('poi/getById', { id: poiId }));
app.bus.on('clientAPI/getAllPOIs', async () => app.bus.get('poi/getAll'));
app.bus.on('clientAPI/getStructures', () => location.getStructures(app));
const isNotFunction = o => typeof o !== 'function';
app.bus.on('clientAPI/getVenueData', async () => {
const vd = await app.bus.get('venueData/getVenueData');
return R__namespace.filter(isNotFunction, vd)
});
app.bus.on('clientAPI/search', async ({ term, details }) => app.bus.get('search/queryAsync', { term }).then(poiList => {
const poiIdList = poiList.map(poi => poi.poiId);
app.bus.send('event/search', { referrer: 'prog', searchMethod: null, query: term, entities: poiIdList });
return details ? poiList : poiIdList
}));
}
exports.handleHeadless = handleHeadless;
exports.headlessCommands = headlessCommands;