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
2 lines (1 loc) • 4.56 kB
JavaScript
import*as o from"ramda";import e from"zousan";import{buildStructuresLookup as t}from"../../../src/utils/buildStructureLookup.js";import{debugIsTrue as i}from"../../../src/utils/configUtils.js";import{toLang as a}from"../../../src/utils/i18n.js";async function n(a,n){const s=a.log.sublog("poiDataManager"),u=()=>{a.bus.send("venueData/loadPoiData")};let p=new e;const d=(o,e)=>{const{position:t}=o,i=e.floorIdToStructure(t.floorId);if(!i)return s.error(`No structure found for floorId: ${t.floorId} for POI ${o.poiId}`),{...o};const a=e.floorIdToFloor(t.floorId),n={...t,structureName:i.name,buildingId:i.id,floorName:a.name,floorOrdinal:a.ordinal};return{...o,position:n}},c=(o,e)=>{o.roomInfo||(o.roomInfo=[]),o.roomInfo.push(e)},l=o.pipe(o.propOr([],"externalIds"),o.find(o.propEq("roomId","type")),o.prop("id"),o.unless(o.isNil,o.tail));a.bus.on("venueData/poiDataLoaded",(async({pois:e,structures:n})=>{if(e=((e,t)=>o.pipe(o.values,o.map((o=>{o.distance=null,o.isNavigable=void 0===o.isNavigable||!0===o.isNavigable,o.capacity&&c(o,{name:`Seats ${o.capacity.join("-")}`,svgId:"number-of-seats"}),o.category.startsWith("meeting")&&c(o,{name:a.gt()("poiView:Conference Room"),svgId:"conference-room"});const e=l(o);return e&&(o.roomId=e),[o.poiId,d(o,t)]})),o.fromPairs)(e))(e,t(n)),i(a,"pseudoTransPois"))for(const o in e)e[o]=r(e[o],a.i18n().language);e=function(o){const e=[];return Object.values(o).forEach((o=>{try{const t=o.position;t?["buildingId","structureName","floorId","floorName","floorOrdinal","latitude","longitude"].forEach((i=>{null!==t[i]&&void 0!==t[i]||e.push({id:o.poiId,e:`invalid position property: ${i}: ${t[i]}`})})):e.push({poi:o,e:"No position information"})}catch(t){s.error(t),e.push({id:o.poiId,e:t.message})}})),e.length&&(s.warn("badPois:",e),e.forEach((e=>{delete o[e.id]}))),o}(e),await async function(o){for(const e of Object.values(o))await y(e);return o}(e),p.resolve(e),a.config.debug&&a.env.isBrowser&&(window._pois=e),a.config.debug&&async function(o){const e=Date.now(),t=[],i=await a.bus.get("wayfinder/_getNavGraph");Object.values(o).forEach((o=>{try{const e=o.position;i.findClosestNode(e.floorId,e.latitude,e.longitude)||t.push({id:o.poiId,e:"No closest Navgraph Node"})}catch(e){s.error(e),t.push({id:o.poiId,e:e.message})}})),t.length&&s.warn("badPois:",t),s(`Total time for navgraph POI check: ${Date.now()-e}ms`)}(e)})),a.bus.on("poi/getById",(async({id:o})=>p.then((e=>e[o])))),a.bus.on("poi/getByFloorId",(async({floorId:e})=>p.then(o.pickBy(o.pathEq(e,["position","floorId"]))))),a.bus.on("poi/getByCategoryId",(async({categoryId:e})=>p.then(o.pickBy((o=>o.category===e||o.category.startsWith(e+".")))))),a.bus.on("poi/getAll",(async()=>p));const f=["queue","primaryQueueId"],m=(e,t,i)=>{const a=o.path(["queue","queueType"],t);if(!a)return null;const n=e[a],r=o.path(f,t);return i.filter(o.pathEq(r,f)).filter((o=>o.poiId!==t.poiId)).map((e=>{const t=o.path(["queue","queueSubtype"],e),i=g(t)(n);return{poiId:e.poiId,...i}}))},g=e=>{return o.pipe(o.find(o.propEq(e,"id")),(t=`No queue found with ID: ${e}`,o=>{if(null!=o)return o;throw Error(t)}),o.pick(["displayText","imageId"]));var t};async function y(t){if(!t)return;const i="undefined"==typeof window?1:window.devicePixelRatio||1;return o.length(t.images)?t.images[0].startsWith("https:")||(t.images=await e.all(t.images.map((o=>a.bus.get("venueData/getPoiImageUrl",{imageName:o,size:`${Math.round(351*i)}x${Math.round(197*i)}`}))))):t.images=[],t}a.bus.on("poi/addOtherSecurityLanes",(({poi:e})=>(async e=>{if(!o.path(f,e))return e;const t=await a.bus.get("venueData/getQueueTypes"),i=await a.bus.get("poi/getByCategoryId",{categoryId:"security"}),n=Object.values(i);return e.queue.otherQueues=m(t,e,n),e})(e)));const h=o.memoizeWith(o.identity,o.pipe(o.pluck("category"),o.values,o.uniq));a.bus.on("poi/getAllCategories",(async()=>p.then(h))),a.bus.on("venueData/loadNewVenue",(()=>{p=new e,u()})),a.bus.on("poi/setDynamicData",(({plugin:e,idValuesMap:t})=>{p.then((i=>{for(const a in t){const n=i[a].dynamicData||{};n[e]={...t[a]};const r=o.mergeRight(i[a],{dynamicData:n});i[a]=r}}))}));return{init:u,runTest:async o=>(await o(),p),internal:{addImages:y,pseudoTransPoi:r}}}function r(o,e){return["description","nearbyLandmark","name","phone","operationHours"].forEach((t=>{o[t]&&(o[t]=a(o[t],e))})),o.keywords&&(o.keywords=o.keywords.map((o=>(o.name=a(o.name,e),o)))),o.position.floorName&&(o.position.floorName=a(o.position.floorName,e)),o.position.structureName&&(o.position.structureName=a(o.position.structureName,e)),o}export{n as create};