UNPKG

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

148 lines (142 loc) 4.98 kB
'use strict'; 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: "getSecurityWaitTimes", args: [{ name: "isOpen", type: "boolean", optional: true }] }, { command: "search", args: [ { name: "term", type: "string", minLength: 2 }, { name: "details", type: "boolean", optional: true } ] }, { command: "getFlightStatus", args: [ { name: "term", type: "string", optional: true }, { name: "type", type: "string", optional: true } ] } ]; function handleHeadless(app) { const pickRouteSummary = (route) => { const routeRecord = route; return { distance: routeRecord.distance, time: routeRecord.time, steps: routeRecord.steps, navline: routeRecord.navline, waypoints: routeRecord.waypoints }; }; 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 }; } const route = await app.bus.get("wayfinder/getRoute", { fromEndpoint, toEndpoint, options }); return pickRouteSummary(route); }); app.bus.on( "clientAPI/getDirectionsMultiple", async ({ locations, accessible, queueTypes }) => { const endpoints = await Promise.all(locations.map(async (location$1) => location.locationToEndpoint(app, location$1))); const options = { requiresAccessibility: !!accessible }; if (queueTypes) { options.selectedSecurityLanes = { SecurityLane: queueTypes }; } const routes = await Promise.all( R__namespace.aperture(2, endpoints).map( async (pair) => app.bus.get("wayfinder/getRoute", { fromEndpoint: pair[0], toEndpoint: pair[1], options }) ) ); const directions = routes.map(pickRouteSummary); return { total: { distance: R__namespace.sum(directions.map((direction) => Number(direction.distance ?? 0))), time: R__namespace.sum(directions.map((direction) => Number(direction.time ?? 0))) }, 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)); app.bus.on( "clientAPI/getSecurityWaitTimes", async ({ isOpen }) => app.bus.get("dynamicPois/getSecurityWaitTimes", { isOpen }) ); app.bus.on("clientAPI/getVenueData", async () => { const venueData = await app.bus.get("venueData/getVenueData"); return Object.fromEntries(Object.entries(venueData).filter(([, value]) => typeof value !== "function")); }); 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; }) ); app.bus.on( "clientAPI/getFlightStatus", async ({ term, type = "all" }) => app.bus.get("flightStatus/query", { term, type }) ); } exports.handleHeadless = handleHeadless; exports.headlessCommands = headlessCommands;