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) • 2.3 kB
JavaScript
import*as e from"ramda";import{findBoundsOfCoordinates as t}from"../../../src/utils/bounds.js";import{global as n}from"../../../src/utils/configUtils.js";const s=async(e,t)=>fetch(t),a=e=>e=>s(0,e).then((e=>e.json())),o=e=>e=>s(0,e).then((e=>e.text())),l=e=>`https://api.content.locuslabs.com/${e}`,r=(t,n,s,a,o)=>e.mapObjIndexed(((e,n)=>((e,t,n,s,a,o)=>"theme"===o||"style"===o?`${l(n)}/${t}/${o}/${a}/${s}/${o}.json`:e.replace(/https:\/\/content.locuslabs.com/gi,l(n)))(e,t,s,a,o,n)),n),c=async(e,t,s)=>{const a={alpha:"alpha-a.locuslabs.com",beta:"beta-a.locuslabs.com",gamma:"gamma-a.locuslabs.com",prod:"a.locuslabs.com"},{assetStage:o,accountId:l,formatVersion:c}=e;let{venueId:i}=e;const u=`https://${a[o]||a.prod}/accounts/${l}`,d=c||"v5",g=e.dataFetch&&n[e.dataFetch]&&n[e.dataFetch].getFiles?await n[e.dataFetch].getFiles(e):await t(`${u}/${d}.json`);if(s.length>0){const t=s.map((e=>e.slice(0,2)));for(let n=0;n<t.length;n+=1)if(g[`${i}${t[n]}`]){i=`${i}${t[n]}`,e.venueId=`${i}`;break}}if(!g[i])throw Error(`Attempt to access venue ${i} which is not within venue list: ${Object.keys(g)}`);const h=g[i].files,m=(e.dataFetch&&n[e.dataFetch]&&n[e.dataFetch].getVenueData?await n[e.dataFetch].getVenueData(e):await t(h.venueData))[i];m.tileServerAuthInfo&&function(e){const t={defaultOrdinal:0,defaultStructureId:"singleBuilding",formatVersion:"v5",structures:{singleBuilding:{name:"singleBuilding",boundsPolygon:[],defaultLevelId:"singleLevel",id:"singleBuilding",levels:{singleLevel:{boundsPolygon:[],clfloor:0,details:"",id:"singleLevel",name:"singleLevel",ordinal:0}}}},structureOrder:["singleBuilding"]};for(const n in t)e[n]=t[n]}(m),m.venueList=g;const p=(e=>{const t=e.deepLinkProps?e.deepLinkProps.contentStage:null;return"alpha"===t||"beta"===t||"prod"===t?t:null})(e);return m.files=p?r(m.category,h,p,l,i):h,m},i=e=>{const{structureOrder:n,structures:s}=e;return n.map((e=>{const n=s[e];Object.values(n.levels).forEach((e=>e.bounds=t(e.boundsPolygon)));const a=t(n.boundsPolygon);return{...n,bounds:a}}))};const u=([e,t,...n])=>[t,e,...n],d=(e,t)=>{return!e||!Array.isArray(e)||e.length<1?e:(n=e[0][0],s=t.ne.lng,a=t.sw.lng,(n>s?n<=a:e=>a)?e:e.map(u));var n,s,a};export{i as buildStructures,a as createFetchJson,o as createFetchText,c as getVenueDataFromUrls,d as normalizeCoords};