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) 2.69 kB
import*as e from"ramda";import{findBoundsOfCoordinates as t}from"../../../src/utils/bounds.js";const n=async(e,t)=>fetch(t),s=e=>e=>n(0,e).then(e=>e.json()),a=e=>e=>n(0,e).then(e=>e.text()),l=e=>`https://api.content.locuslabs.com/${e}`,o=(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),r=[["zh-CN","zh-SG","zh-Hans"],["zh-TW","zh-HK","zh-MO","zh-Hant"]],c=e=>{const t=(e=>{const t=r.find(t=>t.includes(e));return t?t.filter(t=>t!==e):[]})(e),n=e.slice(0,2);return[t=>t===e,e=>t.includes(e),e=>e.slice(0,2)===n]},i=(e,t,n=null)=>{for(const s of c(t)){if(n&&s(n.locale))return n;const t=e.find(e=>s(e.locale));if(t)return t}return null},u=async(e,t,n)=>{const s={alpha:"alpha-a.locuslabs.com",beta:"beta-a.locuslabs.com",gamma:"gamma-a.locuslabs.com",prod:"a.locuslabs.com"},{assetStage:a,accountId:l,formatVersion:r}=e;let{venueId:c}=e;const u=`https://${s[a]||s.prod}/accounts/${l}`,d=r||"v5",h=e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getFiles?await globalThis[e.dataFetch].getFiles(e):await t(`${u}/${d}.json`),g=h[c]?h[c].venueCode:null;if(g){const t=Object.values(h).filter(e=>e.venueCode===g),s=h[c];for(const a of n){const n=i(t,a,s);if(n){c=n.id,e.venueId=`${c}`;break}}}if(!h[c])throw Error(`Attempt to access venue ${c} which is not within venue list: ${Object.keys(h)}`);const f=h[c].files,b=(e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getVenueData?await globalThis[e.dataFetch].getVenueData(e):await t(f.venueData))[c];b.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]}(b),b.venueList=h;const m=(e=>{const t=e.deepLinkProps?e.deepLinkProps.contentStage:null;return"alpha"===t||"beta"===t||"prod"===t?t:null})(e);return b.files=m?o(b.category,f,m,l,c):f,b},d=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 h=([e,t,...n])=>[t,e,...n],g=(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(h));var n,s,a};export{d as buildStructures,s as createFetchJson,a as createFetchText,i as findVenueForLocale,u as getVenueDataFromUrls,g as normalizeCoords};