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

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