atriusmaps-node-sdk 3.3.1026 → 3.3.1027

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "3.3.1026";
5
+ var version = "3.3.1027";
6
6
  var pkg = {
7
7
  version: version};
8
8
 
@@ -45,6 +45,7 @@ function prepareSDKConfig(sc) {
45
45
  defaultSearchTerms,
46
46
  venueId,
47
47
  accountId,
48
+ auth,
48
49
  poiCategories,
49
50
  preserveStateInURL,
50
51
  supportURLDeepLinks,
@@ -91,7 +92,8 @@ function prepareSDKConfig(sc) {
91
92
  venueDataLoader: {
92
93
  dataFetch,
93
94
  venueId,
94
- accountId
95
+ accountId,
96
+ ...auth ? { auth } : {}
95
97
  },
96
98
  sdkServer: {
97
99
  headless
@@ -23,7 +23,6 @@ function _interopNamespaceDefault(e) {
23
23
 
24
24
  var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
25
25
 
26
- const USE_AUTH_WHEN_NOT_PROD_STAGE = false;
27
26
  async function create(app, config) {
28
27
  const log = app.log.sublog("venueDataLoader");
29
28
  let venueDataLoaded = new Zousan();
@@ -34,10 +33,13 @@ async function create(app, config) {
34
33
  const getVenueDefForLang = (venueData, lang) => Object.values(venueData.venueList).filter((venueDef) => venueDef.locale === lang).sort((a, b) => countMatchedPrefix(b.id, venueData.id) - countMatchedPrefix(a.id, venueData.id)).at(0);
35
34
  const calculateBaseVenueId = (venueData) => getVenueDefForLang(venueData, "en")?.id;
36
35
  async function loadVenueData(vConfig, languagesToTry) {
37
- if (vConfig.assetStage && vConfig.assetStage !== "prod" && location.hostname !== "localhost" && USE_AUTH_WHEN_NOT_PROD_STAGE) ;
38
36
  const fetchJson = venueLoadingUtils.createFetchJson();
39
37
  const fetchText = venueLoadingUtils.createFetchText();
40
- const venueData = await venueLoadingUtils.getVenueDataFromUrls(vConfig, fetchJson, languagesToTry);
38
+ const fetchManifestJson = venueLoadingUtils.createFetchManifestJson(
39
+ vConfig.auth,
40
+ () => app.bus.send("venueData/authExpired", { reason: "signedUrlExpired" })
41
+ );
42
+ const venueData = await venueLoadingUtils.getVenueDataFromUrls(vConfig, fetchJson, languagesToTry, fetchManifestJson);
41
43
  const { accountId, venueId } = vConfig;
42
44
  venueData.assetStage = vConfig.assetStage;
43
45
  venueData.defaultOrdinal = venueData.defaultOrdinal || getDefaultOrdinal(venueData);
@@ -35,17 +35,39 @@ const fetchURL = async (token, url) => {
35
35
  };
36
36
  const createFetchJson = (token) => (url) => fetchURL(token, url).then((response) => response.json());
37
37
  const createFetchText = (token) => (url) => fetchURL(token, url).then((response) => response.text());
38
+ const createFetchManifestJson = (auth, onAuthExpired) => async (url) => {
39
+ const response = await fetch(url);
40
+ if (auth?.type === "kiosk" && response.status === 403) {
41
+ await onAuthExpired?.();
42
+ throw new Error("Kiosk signed manifest URL expired");
43
+ }
44
+ return response.json();
45
+ };
38
46
  const fetchStyleDoc = (venueId, venueCategory) => {
39
47
  const styleUrl = `https://style.maps.atrius.com/v2/style?venueId=${venueId}&category=${venueCategory}`;
40
48
  return fetchURL(null, styleUrl).then((response) => response.json()).then((body) => body.data);
41
49
  };
42
50
  const baseContentUrl = (contentStage) => `https://api.content.locuslabs.com/${contentStage}`;
43
51
  const remapContentUrl = (url, category, contentStage, accountId, venueId, key) => {
52
+ if (isSignedUrl(url)) {
53
+ return url;
54
+ }
44
55
  if (key === "theme" || key === "style") {
45
56
  return `${baseContentUrl(contentStage)}/${category}/${key}/${venueId}/${accountId}/${key}.json`;
46
57
  }
47
58
  return url.replace(/https:\/\/content.locuslabs.com/gi, baseContentUrl(contentStage));
48
59
  };
60
+ const isSignedUrl = (url) => {
61
+ if (typeof url !== "string") {
62
+ return false;
63
+ }
64
+ try {
65
+ const searchParams = new URL(url).searchParams;
66
+ return ["Expires", "Signature", "Key-Pair-Id"].every((name) => searchParams.has(name));
67
+ } catch {
68
+ return false;
69
+ }
70
+ };
49
71
  const remapEachURLForContentStage = (category, files, contentStage, accountId, venueId) => R__namespace.mapObjIndexed((file, key) => remapContentUrl(file, category, contentStage, accountId, venueId, key), files);
50
72
  const getContentStage = (vconfig) => {
51
73
  const stage = vconfig.deepLinkProps ? vconfig.deepLinkProps.contentStage : null;
@@ -80,7 +102,7 @@ const findVenueForLocale = (venues, browserLang, currentVenue = null) => {
80
102
  }
81
103
  return null;
82
104
  };
83
- const getVenueDataFromUrls = async (vconfig, fetchJson, languagesToTry) => {
105
+ const getVenueDataFromUrls = async (vconfig, fetchJson, languagesToTry, fetchManifestJson = fetchJson) => {
84
106
  const stages = {
85
107
  alpha: "alpha-a.locuslabs.com",
86
108
  beta: "beta-a.locuslabs.com",
@@ -92,7 +114,11 @@ const getVenueDataFromUrls = async (vconfig, fetchJson, languagesToTry) => {
92
114
  const stageUrl = stages[assetStage] || stages.prod;
93
115
  const accountUrl = `https://${stageUrl}/accounts/${accountId}`;
94
116
  const assetFormat = formatVersion || "v5";
95
- const venueList = vconfig.dataFetch && globalThis[vconfig.dataFetch] && globalThis[vconfig.dataFetch].getFiles ? await globalThis[vconfig.dataFetch].getFiles(vconfig) : await fetchJson(`${accountUrl}/${assetFormat}.json`);
117
+ const usesKioskAuth = vconfig.auth?.type === "kiosk";
118
+ if (usesKioskAuth && (typeof vconfig.auth.signedManifestUrl !== "string" || !vconfig.auth.signedManifestUrl.trim())) {
119
+ throw new Error("Kiosk auth requires a non-empty signedManifestUrl");
120
+ }
121
+ const venueList = !usesKioskAuth && vconfig.dataFetch && globalThis[vconfig.dataFetch] && globalThis[vconfig.dataFetch].getFiles ? await globalThis[vconfig.dataFetch].getFiles(vconfig) : await fetchManifestJson(usesKioskAuth ? vconfig.auth.signedManifestUrl : `${accountUrl}/${assetFormat}.json`);
96
122
  const venueCode = venueList[venueId] ? venueList[venueId].venueCode : null;
97
123
  if (venueCode) {
98
124
  const venuesWithSameVenueCode = Object.values(venueList).filter((v) => v.venueCode === venueCode);
@@ -110,7 +136,7 @@ const getVenueDataFromUrls = async (vconfig, fetchJson, languagesToTry) => {
110
136
  throw Error(`Attempt to access venue ${venueId} which is not within venue list: ${Object.keys(venueList)}`);
111
137
  }
112
138
  const files = venueList[venueId].files;
113
- const fetchedData = vconfig.dataFetch && globalThis[vconfig.dataFetch] && globalThis[vconfig.dataFetch].getVenueData ? await globalThis[vconfig.dataFetch].getVenueData(vconfig) : await fetchJson(files.venueData);
139
+ const fetchedData = !usesKioskAuth && vconfig.dataFetch && globalThis[vconfig.dataFetch] && globalThis[vconfig.dataFetch].getVenueData ? await globalThis[vconfig.dataFetch].getVenueData(vconfig) : await fetchJson(files.venueData);
114
140
  const venueData = fetchedData[venueId];
115
141
  if (venueData.tileServerAuthInfo) {
116
142
  embellishTilemapVenueData(venueData);
@@ -177,6 +203,7 @@ const normalizeCoords = (coords, venueBounds) => {
177
203
 
178
204
  exports.buildStructures = buildStructures;
179
205
  exports.createFetchJson = createFetchJson;
206
+ exports.createFetchManifestJson = createFetchManifestJson;
180
207
  exports.createFetchText = createFetchText;
181
208
  exports.fetchStyleDoc = fetchStyleDoc;
182
209
  exports.findVenueForLocale = findVenueForLocale;
@@ -1 +1 @@
1
- var a="3.3.1026",e={version:a};export{e as default,a as version};
1
+ var a="3.3.1027",e={version:a};export{e as default,a as version};
@@ -1 +1 @@
1
- import{b64DecodeUnicode as e,filterOb as i}from"../../../src/utils/funcs.js";import{setDeepLinksForParms as n}from"../../../src/configs/postproc-mol-url-parms.js";import{setStateFromStateString as o}from"../../../src/configs/postproc-stateTracking.js";const t=(e,i)=>{if(void 0===e)return;const n=e.toString();return n.length>i?n.substring(0,i):n},s=(e,i)=>void 0!==i?{[e]:i}:{},a=e=>{if(!e||"object"!=typeof e)return;const i={};return Object.keys(e).slice(0,10).forEach(n=>{let o=t(n.toString().replaceAll(/[^a-zA-Z0-9_]/g,""),128)??"X";o.match(/^[a-zA-Z]+/)||(o=`X${o}`);let s=e[n];null==s&&(s=""),i[o]=t(String(s),128)??""}),i};function r(e,i,n){Object.keys(e).filter(e=>e.startsWith(`${i}-`)).forEach(i=>{n[i]=e[i]})}function l(l){const{name:c,debug:p,headless:u,theme:d,defaultSearchTerms:g,venueId:h,accountId:m,poiCategories:f,preserveStateInURL:S,supportURLDeepLinks:v,initState:k,deepLinkParms:L,uiHide:P,renderDiv:w,parentConfig:A,desktopViewMinWidth:y,forceDesktop:V,hostAppId:b,hostAppVersion:j,hostAppProperties:D,logFilter:I,searchPlaceholder:Z,dataFetch:F,engineName:C,dynamicPoisUrlBaseV1:O,plugins:R,analytics2ActiveFlag:T,enablePoiSelection:U,showSurround:x,minZoom:M,maxZoom:W,noLangOptions:z,pinnedLocation:B,pinnedLocationZoom:H,pinnedLocationFocusAtStart:E,pinnedLocationBearing:N,pinnedLocationPitch:X}=l,$=A?[A]:u?["sdkHeadless"]:["sdkVisual"],_={name:c,engineName:C,extends:$,debug:p,logFilter:I,theme:d,uiHide:P,renderDiv:w,configPostProc:[],plugins:{venueDataLoader:{dataFetch:F,venueId:h,accountId:m},sdkServer:{headless:u},analytics2:{hostAppId:b?t(b,128):void 0,hostAppVersion:j?t(j,128):void 0,hostAppProperties:a(D)}},uuid:"undefined"!=typeof document&&document.location?document.location.host:"unknown"};if(void 0!==T&&(_.plugins.analytics2={..._.plugins.analytics2,active:T}),u||(_.plugins["online/headerOnline"]={searchPlaceholder:Z},_.plugins.mapRenderer={...s("enablePoiSelection",U),surroundConfig:x?{}:null,viewLimits:{...s("maxZoom",W),...s("minZoom",M)}},_.plugins.userMenu={noLangOptions:z},B&&(_.plugins["online/pinnedLocation"]={location:B,zoom:H,focusAtStart:E,bearing:N,pitch:X})),_.plugins.searchService=g?{defaultSearchTerms:g}:{},r(l,"defaultSearchTerms",_.plugins.searchService),$.includes("sdkVisual")&&(_.plugins["online/homeView"]=f?{poiCategories:f}:{},r(l,"poiCategories",_.plugins["online/homeView"])),R&&"object"==typeof R){const e=R;e.draw&&(_.plugins.draw=e.draw),e.flightStatus&&(_.plugins.flightStatus=e.flightStatus,_.plugins["online/flightDetails"]={},_.plugins["online/flightDetailsSearch"]={})}return S&&((_.configPostProc??[]).push("stateTracking"),_.plugins.deepLinking={trackURL:!0}),v&&(_.configPostProc??[]).push("mol-url-parms"),k&&o(_,e(k),!0),L&&n(_,new URLSearchParams(L),!0),void 0!==y&&(_.desktopViewMinWidth=y),V&&(_.desktopViewMinWidth=0),O&&(_.plugins.dynamicPois={urlBaseV1:O}),i((e,i)=>void 0!==i,_)}export{l as default};
1
+ import{b64DecodeUnicode as e,filterOb as i}from"../../../src/utils/funcs.js";import{setDeepLinksForParms as n}from"../../../src/configs/postproc-mol-url-parms.js";import{setStateFromStateString as o}from"../../../src/configs/postproc-stateTracking.js";const t=(e,i)=>{if(void 0===e)return;const n=e.toString();return n.length>i?n.substring(0,i):n},s=(e,i)=>void 0!==i?{[e]:i}:{},a=e=>{if(!e||"object"!=typeof e)return;const i={};return Object.keys(e).slice(0,10).forEach(n=>{let o=t(n.toString().replaceAll(/[^a-zA-Z0-9_]/g,""),128)??"X";o.match(/^[a-zA-Z]+/)||(o=`X${o}`);let s=e[n];null==s&&(s=""),i[o]=t(String(s),128)??""}),i};function r(e,i,n){Object.keys(e).filter(e=>e.startsWith(`${i}-`)).forEach(i=>{n[i]=e[i]})}function l(l){const{name:c,debug:p,headless:u,theme:d,defaultSearchTerms:g,venueId:h,accountId:m,auth:f,poiCategories:S,preserveStateInURL:v,supportURLDeepLinks:k,initState:L,deepLinkParms:P,uiHide:w,renderDiv:A,parentConfig:y,desktopViewMinWidth:V,forceDesktop:b,hostAppId:j,hostAppVersion:D,hostAppProperties:I,logFilter:Z,searchPlaceholder:F,dataFetch:C,engineName:O,dynamicPoisUrlBaseV1:R,plugins:T,analytics2ActiveFlag:U,enablePoiSelection:x,showSurround:M,minZoom:W,maxZoom:z,noLangOptions:B,pinnedLocation:H,pinnedLocationZoom:E,pinnedLocationFocusAtStart:N,pinnedLocationBearing:X,pinnedLocationPitch:$}=l,_=y?[y]:u?["sdkHeadless"]:["sdkVisual"],q={name:c,engineName:O,extends:_,debug:p,logFilter:Z,theme:d,uiHide:w,renderDiv:A,configPostProc:[],plugins:{venueDataLoader:{dataFetch:C,venueId:h,accountId:m,...f?{auth:f}:{}},sdkServer:{headless:u},analytics2:{hostAppId:j?t(j,128):void 0,hostAppVersion:D?t(D,128):void 0,hostAppProperties:a(I)}},uuid:"undefined"!=typeof document&&document.location?document.location.host:"unknown"};if(void 0!==U&&(q.plugins.analytics2={...q.plugins.analytics2,active:U}),u||(q.plugins["online/headerOnline"]={searchPlaceholder:F},q.plugins.mapRenderer={...s("enablePoiSelection",x),surroundConfig:M?{}:null,viewLimits:{...s("maxZoom",z),...s("minZoom",W)}},q.plugins.userMenu={noLangOptions:B},H&&(q.plugins["online/pinnedLocation"]={location:H,zoom:E,focusAtStart:N,bearing:X,pitch:$})),q.plugins.searchService=g?{defaultSearchTerms:g}:{},r(l,"defaultSearchTerms",q.plugins.searchService),_.includes("sdkVisual")&&(q.plugins["online/homeView"]=S?{poiCategories:S}:{},r(l,"poiCategories",q.plugins["online/homeView"])),T&&"object"==typeof T){const e=T;e.draw&&(q.plugins.draw=e.draw),e.flightStatus&&(q.plugins.flightStatus=e.flightStatus,q.plugins["online/flightDetails"]={},q.plugins["online/flightDetailsSearch"]={})}return v&&((q.configPostProc??[]).push("stateTracking"),q.plugins.deepLinking={trackURL:!0}),k&&(q.configPostProc??[]).push("mol-url-parms"),L&&o(q,e(L),!0),P&&n(q,new URLSearchParams(P),!0),void 0!==V&&(q.desktopViewMinWidth=V),b&&(q.desktopViewMinWidth=0),R&&(q.plugins.dynamicPois={urlBaseV1:R}),i((e,i)=>void 0!==i,q)}export{l as default};
@@ -1 +1 @@
1
- import*as e from"ramda";import t from"zousan";import{fetchStyleDoc as a,normalizeCoords as n,getVenueDataFromUrls as s,buildStructures as r,createFetchJson as o,createFetchText as u}from"./venueLoadingUtils.js";async function i(i,d){const l=i.log.sublog("venueDataLoader");let c=new t,p=new t;const v=t=>t.defaultStructureId||e.path(["structureOrder",0],t)||e.path(["selectorOrder",0],t)||e.pipe(e.prop("structures"),Object.values,e.path([0,"id"]))(t),g=(e,t)=>e.split("").reduce((a,n,s)=>e.substring(0,s+1)===t.substring(0,s+1)?s:a,-1)+1,b=e=>((e,t)=>Object.values(e.venueList).filter(e=>e.locale===t).sort((t,a)=>g(a.id,e.id)-g(t.id,e.id)).at(0))(e,"en")?.id;async function m(t,a){t.assetStage&&"prod"!==t.assetStage&&location.hostname;const n=o(),d=u(),l=await s(t,n,a),{accountId:p,venueId:g}=t;return l.assetStage=t.assetStage,l.defaultOrdinal=l.defaultOrdinal||function(t){const a=v(t),n=Object.values(t.structures).find(e.propEq(a,"id"));return n.levels[n.defaultLevelId].ordinal}(l),l.structures=r(l),l.baseVenueId=b(l),l.getTranslatedContentPath=e=>`https://content.locuslabs.com/${l.category}/${e}/${g}/${p}`,l.fetchJson=n,l.fetchText=d,i.config.debug&&i.env.isBrowser&&(window._venueData=l),l.queueTypes&&(l.securityQueueTypes=(()=>{const e=l.queueTypes.find(e=>"SecurityLane"===e.id);return e?e.subtypes.map(e=>e.id):[]})()),i.bus.send("venueData/venueDataLoaded",{venueData:l}),c.resolve(l),c}function f(e){const t={id:"venueDataLoader"};return e.id!==d.venueId&&(t.vid=e.id),t.lang=i.i18n().language,"prod"!==e.assetStage&&(t.stage=e.assetStage),i.bus.send("deepLinking/notifyState",t),e}i.bus.on("debugTools/fileDrop",async({file:e,content:t})=>{if("application/json"===e.type){const e=JSON.parse(t);if(e.basemap&&e["basemap.venue"])return n=JSON.parse(t),void i.bus.send("map/replaceTheme",{theme:n});if(e.metadata&&e.metadata["mapbox:type"])return a=t,void i.bus.send("map/replaceStyle",{styleSrc:a})}var a,n});async function h(e){const t={...e},a=await i.bus.get("poi/getAll");return Object.values(t).forEach(e=>e.filter(e=>"poi"===e.properties.aiLayer&&"Point"===e.geometry.type).forEach(e=>{const t=a[e.properties.id];t?t.mapLabel?e.properties.text=t.mapLabel:!1!==d.copyPOINamesToMap&&(e.properties.text=function(e){let t=e.name;return d.poiMapNameXForm?(Object.keys(d.poiMapNameXForm).filter(t=>((e,t)=>e===t||0===e.indexOf(t+"."))(e.category,t)).forEach(e=>{d.poiMapNameXForm[e].forEach(e=>t=t.replace(new RegExp(e.replace),e.with))}),t):t}(t)):l.warn(`Unknown poi in style: ${e.properties.id}`)})),t}async function y(a){return e.pipe(e.prop("structures"),e.map(e.prop("levels")),e.chain(e.keys),e.prepend(a.id),e.map(e=>a.files.geoJson.replace("${geoJsonId}",e)),e.map(a.fetchJson),e.map(e.andThen(e=>[e.id,D(e.id,e.features,a.id,a.structures)])),e=>t.all(e),e.andThen(e.fromPairs))(a)}const D=(t,a,n,s)=>{const r=t.replace(/-[^-]*$/,""),o=r===n?"landscape-background":`ordinal: ${s.find(e.hasPath(["levels",t])).levels[t].ordinal}`;return a.map(a=>{var s,u,i;return s="properties",u={venueId:n,structureId:r,ordinalId:o,levelId:t},i=a,a=e.over(e.lensProp(s),t=>e.mergeRight(t||{},u),i),a=e.assoc("id",a.properties.subid,a)})};i.bus.on("venueData/loadMap",async()=>{c.then(async e=>{const t=e.files.spritesheet,n=e.files.glyphs,{id:s,bounds:r,structures:o,venueCenter:u,venueRadius:l,defaultOrdinal:c}=e,[v,g,b]=await Promise.all([a(e.baseVenueId,e.category),e.fetchJson(e.files.theme),e.venueList[s].mapTokens?Promise.resolve({[s]:[]}):y(e).then(h)]),m={mapFeatures:b,mapStyleSource:v,mapTheme:g,badgesSpriteUrl:t,mapGlyphsUrl:n,structures:o,defaultOrdinal:c,venueBounds:{n:r.ne.lat,s:r.sw.lat,e:r.ne.lng,w:r.sw.lng},venueId:s,venueCenter:u,venueRadius:l,accountId:d.accountId,secure:void 0!==d.auth,tileServerAuthInfo:e.tileServerAuthInfo};p.resolve(m),i.bus.send("venueData/mapDataLoaded",m)})});const I=e=>null==e.shouldDisplay||e.shouldDisplay;i.bus.on("venueData/loadBuildingSelectorData",()=>c.then(async t=>{const a={buildings:t.structures.filter(I).map(e.evolve({levels:e.pipe(e.values,e.sortWith([e.descend(e.prop("ordinal"))]))})),structureOrder:t.structureOrder,selectorOrder:t.selectorOrder};return i.bus.send("venueData/buildingSelectorDataLoaded",a),a})),i.bus.on("venueData/normalizeCoords",({coords:e})=>c.then(t=>n(e,t.bounds)));const w={edges:[],nodes:[]};i.bus.on("venueData/loadNavGraph",async()=>c.then(async e=>{const t={navGraphData:e.files.nav?await e.fetchJson(e.files.nav):w,structures:e.structures};return i.bus.send("venueData/navGraphLoaded",t),t})),i.bus.on("venueData/loadPoiData",async()=>c.then(async e=>{const t=d.useOldDataModel?e.files.poisOld||e.files.pois:e.files.pois||e.files.poisOld;if(t){const a=await e.fetchJson(t);i.bus.send("venueData/poiDataLoaded",{pois:a,structures:e.structures})}})),i.bus.on("venueData/getVenueCenter",async()=>c.then(async e=>({lat:e.venueCenter[0],lng:e.venueCenter[1],ordinal:0}))),i.bus.on("venueData/getContentUrl",({type:e,name:t=""})=>c.then(a=>a.files[e]+t)),i.bus.on("venueData/getFloorIdToNameMap",()=>c.then(e.pipe(e.prop("structures"),e.map(e.prop("levels")),e.chain(e.values),e.map(e.props(["id","name"])),e.fromPairs))),i.bus.on("venueData/getFloorIdName",({floorId:t})=>c.then(async a=>{const n=e.pipe(e.values,e.find(e.hasPath(["levels",t])))(a.structures);return n?{structureId:n.id,structureName:n.name,floorName:n.levels[t].name}:null}));const S=(t,a)=>()=>c.then(e.pipe(e.prop(t),e.defaultTo(a)));function O(e,t){const a=T(t);if(a.includes(e))return e;const n=e.split("-").slice(1).join("-");return a.find(e=>new RegExp(`${t.baseVenueId}.?.?-${n}`).test(e))}i.bus.on("venueData/getVenueData",()=>c),i.bus.on("venueData/getVenueName",S("name")),i.bus.on("venueData/getVenueCategory",S("category")),i.bus.on("venueData/getVenueTimezone",S("tz")),i.bus.on("venueData/getAccountId",()=>d.accountId),i.bus.on("venueData/getVenueId",S("id")),i.bus.on("venueData/getPositioningSupported",S("positioningSupported")),i.bus.on("venueData/getStructures",S("structures")),i.bus.on("venueData/loadNewVenue",async({venueId:e,accountId:a,assetStage:n=d.assetStage})=>{c.reject(new Error("loadNewVenue called - previous loading ignored")),p.reject(new Error("loadNewVenue called - previous loading ignored")),c=new t,p=new t,m({...d,venueId:e,accountId:a,assetStage:n},[]).then(f)}),i.bus.on("venueData/getPoiImageUrl",({imageName:e,size:t})=>`https://img.locuslabs.com/resize/${d.accountId}/png/transparent/${t}contain/poi/${e}`),i.bus.on("venueData/getDistributionId",()=>c.then(e=>`${e.baseVenueId}-${d.accountId}`)),i.bus.on("venueData/getCustomKeywords",()=>c.then(e=>{const t=d.useOldDataModel&&e.files.searchOld||e.files.search;return e.fetchJson(t)})),i.bus.on("venueData/isGrabEnabled",S("enableGrab")),i.bus.on("venueData/getGrabPoiIds",S("grabPoiIds",[])),i.bus.on("venueData/getAssetsTimestamp",S("version")),i.bus.on("venueData/getTranslatedFloorId",async({floorId:e})=>c.then(t=>O(e,t)));const T=e=>e.structures.reduce((e,t)=>e.concat(Object.keys(t.levels)),[]);i.bus.on("venueData/getQueueTypes",()=>c.then(e=>{const t=["tsapre","clear","globalEntry"];return e.queueTypes?e.queueTypes.reduce((e,a)=>{const{id:n,subtypes:s}=a,r=s.map(e=>{const a=t.includes(e.id)&&`security-logo-${e.id.toLowerCase()}`;return{...e,imageId:a}});return e[n]=r,e},{}):{}}));return{init:async()=>{let e=[];null===new URLSearchParams("undefined"==typeof window?"":window.location.search).get("lang")&&(e="undefined"==typeof window?[]:navigator.languages);const t=d.deepLinkProps||{};t.lang&&e.unshift(t.lang);const a=t.vid||d.venueId,n=d.useDynamicUrlParams&&t.stage?t.stage:d.assetStage,s=t.accountId||("alpha"===n?"A1VPTJKREFJWX5":d.accountId);m({...d,venueId:a,accountId:s,assetStage:n},e).then(f)},runTest:async({testRoutine:e,reset:a=!1,venueData:n=null})=>{let s,r;return(a||n)&&(c=new t,p=new t),n&&(c=t.resolve(n)),await e(),c.v&&(s=await c),p.v&&(r=await p),{venueDataObj:s,mapDataObj:r}},internal:{calculateBaseVenueId:b,getDefaultStructureId:v,getTranslatedFloorId:O,setConfigProperty:(e,t)=>{d[e]=t}}}}export{i as create};
1
+ import*as e from"ramda";import t from"zousan";import{fetchStyleDoc as a,normalizeCoords as n,getVenueDataFromUrls as s,buildStructures as r,createFetchJson as u,createFetchText as o,createFetchManifestJson as i}from"./venueLoadingUtils.js";async function d(d,l){const c=d.log.sublog("venueDataLoader");let p=new t,v=new t;const g=t=>t.defaultStructureId||e.path(["structureOrder",0],t)||e.path(["selectorOrder",0],t)||e.pipe(e.prop("structures"),Object.values,e.path([0,"id"]))(t),b=(e,t)=>e.split("").reduce((a,n,s)=>e.substring(0,s+1)===t.substring(0,s+1)?s:a,-1)+1,f=e=>((e,t)=>Object.values(e.venueList).filter(e=>e.locale===t).sort((t,a)=>b(a.id,e.id)-b(t.id,e.id)).at(0))(e,"en")?.id;async function m(t,a){const n=u(),l=o(),c=i(t.auth,()=>d.bus.send("venueData/authExpired",{reason:"signedUrlExpired"})),v=await s(t,n,a,c),{accountId:b,venueId:m}=t;return v.assetStage=t.assetStage,v.defaultOrdinal=v.defaultOrdinal||function(t){const a=g(t),n=Object.values(t.structures).find(e.propEq(a,"id"));return n.levels[n.defaultLevelId].ordinal}(v),v.structures=r(v),v.baseVenueId=f(v),v.getTranslatedContentPath=e=>`https://content.locuslabs.com/${v.category}/${e}/${m}/${b}`,v.fetchJson=n,v.fetchText=l,d.config.debug&&d.env.isBrowser&&(window._venueData=v),v.queueTypes&&(v.securityQueueTypes=(()=>{const e=v.queueTypes.find(e=>"SecurityLane"===e.id);return e?e.subtypes.map(e=>e.id):[]})()),d.bus.send("venueData/venueDataLoaded",{venueData:v}),p.resolve(v),p}function h(e){const t={id:"venueDataLoader"};return e.id!==l.venueId&&(t.vid=e.id),t.lang=d.i18n().language,"prod"!==e.assetStage&&(t.stage=e.assetStage),d.bus.send("deepLinking/notifyState",t),e}d.bus.on("debugTools/fileDrop",async({file:e,content:t})=>{if("application/json"===e.type){const e=JSON.parse(t);if(e.basemap&&e["basemap.venue"])return n=JSON.parse(t),void d.bus.send("map/replaceTheme",{theme:n});if(e.metadata&&e.metadata["mapbox:type"])return a=t,void d.bus.send("map/replaceStyle",{styleSrc:a})}var a,n});async function y(e){const t={...e},a=await d.bus.get("poi/getAll");return Object.values(t).forEach(e=>e.filter(e=>"poi"===e.properties.aiLayer&&"Point"===e.geometry.type).forEach(e=>{const t=a[e.properties.id];t?t.mapLabel?e.properties.text=t.mapLabel:!1!==l.copyPOINamesToMap&&(e.properties.text=function(e){let t=e.name;return l.poiMapNameXForm?(Object.keys(l.poiMapNameXForm).filter(t=>((e,t)=>e===t||0===e.indexOf(t+"."))(e.category,t)).forEach(e=>{l.poiMapNameXForm[e].forEach(e=>t=t.replace(new RegExp(e.replace),e.with))}),t):t}(t)):c.warn(`Unknown poi in style: ${e.properties.id}`)})),t}async function D(a){return e.pipe(e.prop("structures"),e.map(e.prop("levels")),e.chain(e.keys),e.prepend(a.id),e.map(e=>a.files.geoJson.replace("${geoJsonId}",e)),e.map(a.fetchJson),e.map(e.andThen(e=>[e.id,I(e.id,e.features,a.id,a.structures)])),e=>t.all(e),e.andThen(e.fromPairs))(a)}const I=(t,a,n,s)=>{const r=t.replace(/-[^-]*$/,""),u=r===n?"landscape-background":`ordinal: ${s.find(e.hasPath(["levels",t])).levels[t].ordinal}`;return a.map(a=>{var s,o,i;return s="properties",o={venueId:n,structureId:r,ordinalId:u,levelId:t},i=a,a=e.over(e.lensProp(s),t=>e.mergeRight(t||{},o),i),a=e.assoc("id",a.properties.subid,a)})};d.bus.on("venueData/loadMap",async()=>{p.then(async e=>{const t=e.files.spritesheet,n=e.files.glyphs,{id:s,bounds:r,structures:u,venueCenter:o,venueRadius:i,defaultOrdinal:c}=e,[p,g,b]=await Promise.all([a(e.baseVenueId,e.category),e.fetchJson(e.files.theme),e.venueList[s].mapTokens?Promise.resolve({[s]:[]}):D(e).then(y)]),f={mapFeatures:b,mapStyleSource:p,mapTheme:g,badgesSpriteUrl:t,mapGlyphsUrl:n,structures:u,defaultOrdinal:c,venueBounds:{n:r.ne.lat,s:r.sw.lat,e:r.ne.lng,w:r.sw.lng},venueId:s,venueCenter:o,venueRadius:i,accountId:l.accountId,secure:void 0!==l.auth,tileServerAuthInfo:e.tileServerAuthInfo};v.resolve(f),d.bus.send("venueData/mapDataLoaded",f)})});const w=e=>null==e.shouldDisplay||e.shouldDisplay;d.bus.on("venueData/loadBuildingSelectorData",()=>p.then(async t=>{const a={buildings:t.structures.filter(w).map(e.evolve({levels:e.pipe(e.values,e.sortWith([e.descend(e.prop("ordinal"))]))})),structureOrder:t.structureOrder,selectorOrder:t.selectorOrder};return d.bus.send("venueData/buildingSelectorDataLoaded",a),a})),d.bus.on("venueData/normalizeCoords",({coords:e})=>p.then(t=>n(e,t.bounds)));const S={edges:[],nodes:[]};d.bus.on("venueData/loadNavGraph",async()=>p.then(async e=>{const t={navGraphData:e.files.nav?await e.fetchJson(e.files.nav):S,structures:e.structures};return d.bus.send("venueData/navGraphLoaded",t),t})),d.bus.on("venueData/loadPoiData",async()=>p.then(async e=>{const t=l.useOldDataModel?e.files.poisOld||e.files.pois:e.files.pois||e.files.poisOld;if(t){const a=await e.fetchJson(t);d.bus.send("venueData/poiDataLoaded",{pois:a,structures:e.structures})}})),d.bus.on("venueData/getVenueCenter",async()=>p.then(async e=>({lat:e.venueCenter[0],lng:e.venueCenter[1],ordinal:0}))),d.bus.on("venueData/getContentUrl",({type:e,name:t=""})=>p.then(a=>a.files[e]+t)),d.bus.on("venueData/getFloorIdToNameMap",()=>p.then(e.pipe(e.prop("structures"),e.map(e.prop("levels")),e.chain(e.values),e.map(e.props(["id","name"])),e.fromPairs))),d.bus.on("venueData/getFloorIdName",({floorId:t})=>p.then(async a=>{const n=e.pipe(e.values,e.find(e.hasPath(["levels",t])))(a.structures);return n?{structureId:n.id,structureName:n.name,floorName:n.levels[t].name}:null}));const O=(t,a)=>()=>p.then(e.pipe(e.prop(t),e.defaultTo(a)));function T(e,t){const a=P(t);if(a.includes(e))return e;const n=e.split("-").slice(1).join("-");return a.find(e=>new RegExp(`${t.baseVenueId}.?.?-${n}`).test(e))}d.bus.on("venueData/getVenueData",()=>p),d.bus.on("venueData/getVenueName",O("name")),d.bus.on("venueData/getVenueCategory",O("category")),d.bus.on("venueData/getVenueTimezone",O("tz")),d.bus.on("venueData/getAccountId",()=>l.accountId),d.bus.on("venueData/getVenueId",O("id")),d.bus.on("venueData/getPositioningSupported",O("positioningSupported")),d.bus.on("venueData/getStructures",O("structures")),d.bus.on("venueData/loadNewVenue",async({venueId:e,accountId:a,assetStage:n=l.assetStage})=>{p.reject(new Error("loadNewVenue called - previous loading ignored")),v.reject(new Error("loadNewVenue called - previous loading ignored")),p=new t,v=new t,m({...l,venueId:e,accountId:a,assetStage:n},[]).then(h)}),d.bus.on("venueData/getPoiImageUrl",({imageName:e,size:t})=>`https://img.locuslabs.com/resize/${l.accountId}/png/transparent/${t}contain/poi/${e}`),d.bus.on("venueData/getDistributionId",()=>p.then(e=>`${e.baseVenueId}-${l.accountId}`)),d.bus.on("venueData/getCustomKeywords",()=>p.then(e=>{const t=l.useOldDataModel&&e.files.searchOld||e.files.search;return e.fetchJson(t)})),d.bus.on("venueData/isGrabEnabled",O("enableGrab")),d.bus.on("venueData/getGrabPoiIds",O("grabPoiIds",[])),d.bus.on("venueData/getAssetsTimestamp",O("version")),d.bus.on("venueData/getTranslatedFloorId",async({floorId:e})=>p.then(t=>T(e,t)));const P=e=>e.structures.reduce((e,t)=>e.concat(Object.keys(t.levels)),[]);d.bus.on("venueData/getQueueTypes",()=>p.then(e=>{const t=["tsapre","clear","globalEntry"];return e.queueTypes?e.queueTypes.reduce((e,a)=>{const{id:n,subtypes:s}=a,r=s.map(e=>{const a=t.includes(e.id)&&`security-logo-${e.id.toLowerCase()}`;return{...e,imageId:a}});return e[n]=r,e},{}):{}}));return{init:async()=>{let e=[];null===new URLSearchParams("undefined"==typeof window?"":window.location.search).get("lang")&&(e="undefined"==typeof window?[]:navigator.languages);const t=l.deepLinkProps||{};t.lang&&e.unshift(t.lang);const a=t.vid||l.venueId,n=l.useDynamicUrlParams&&t.stage?t.stage:l.assetStage,s=t.accountId||("alpha"===n?"A1VPTJKREFJWX5":l.accountId);m({...l,venueId:a,accountId:s,assetStage:n},e).then(h)},runTest:async({testRoutine:e,reset:a=!1,venueData:n=null})=>{let s,r;return(a||n)&&(p=new t,v=new t),n&&(p=t.resolve(n)),await e(),p.v&&(s=await p),v.v&&(r=await v),{venueDataObj:s,mapDataObj:r}},internal:{calculateBaseVenueId:f,getDefaultStructureId:g,getTranslatedFloorId:T,setConfigProperty:(e,t)=>{l[e]=t}}}}export{d as create};
@@ -1 +1 @@
1
- import*as e from"ramda";import{findBoundsOfCoordinates as t}from"../../../src/utils/bounds.js";const n=async(e,t)=>e?fetch(t,{headers:{Authorization:e}}):fetch(t),s=e=>t=>n(e,t).then(e=>e.json()),a=e=>t=>n(e,t).then(e=>e.text()),l=(e,t)=>n(null,`https://style.maps.atrius.com/v2/style?venueId=${e}&category=${t}`).then(e=>e.json()).then(e=>e.data),o=e=>`https://api.content.locuslabs.com/${e}`,r=(t,n,s,a,l)=>e.mapObjIndexed((e,n)=>((e,t,n,s,a,l)=>"theme"===l||"style"===l?`${o(n)}/${t}/${l}/${a}/${s}/${l}.json`:e.replace(/https:\/\/content.locuslabs.com/gi,o(n)))(e,t,s,a,l,n),n),c=[["zh-CN","zh-SG","zh-Hans"],["zh-TW","zh-HK","zh-MO","zh-Hant"]],i=e=>{const t=(e=>{const t=c.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]},u=(e,t,n=null)=>{for(const s of i(t)){if(n&&s(n.locale))return n;const t=e.find(e=>s(e.locale));if(t)return t}return null},d=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:o}=e;let{venueId:c}=e;const i=`https://${s[a]||s.prod}/accounts/${l}`,d=o||"v5",h=e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getFiles?await globalThis[e.dataFetch].getFiles(e):await t(`${i}/${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=u(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,m=(e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getVenueData?await globalThis[e.dataFetch].getVenueData(e):await t(f.venueData))[c];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=h;const b=(e=>{const t=e.deepLinkProps?e.deepLinkProps.contentStage:null;return"alpha"===t||"beta"===t||"prod"===t?t:null})(e);return m.files=b?r(m.category,f,b,l,c):f,m},h=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 g=([e,t,...n])=>[t,e,...n],f=(e,t)=>{return!e||!Array.isArray(e)||e.length<1?e:(n=e[0][0],s=t.ne.lng,a=t.sw.lng,n>=Math.min(s,a)&&n<=Math.max(s,a)?e:e.map(g));var n,s,a};export{h as buildStructures,s as createFetchJson,a as createFetchText,l as fetchStyleDoc,u as findVenueForLocale,d as getVenueDataFromUrls,f as normalizeCoords};
1
+ import*as e from"ramda";import{findBoundsOfCoordinates as t}from"../../../src/utils/bounds.js";const n=async(e,t)=>e?fetch(t,{headers:{Authorization:e}}):fetch(t),s=e=>t=>n(e,t).then(e=>e.json()),a=e=>t=>n(e,t).then(e=>e.text()),o=(e,t)=>async n=>{const s=await fetch(n);if("kiosk"===e?.type&&403===s.status)throw await(t?.()),new Error("Kiosk signed manifest URL expired");return s.json()},r=(e,t)=>n(null,`https://style.maps.atrius.com/v2/style?venueId=${e}&category=${t}`).then(e=>e.json()).then(e=>e.data),l=e=>`https://api.content.locuslabs.com/${e}`,i=e=>{if("string"!=typeof e)return!1;try{const t=new URL(e).searchParams;return["Expires","Signature","Key-Pair-Id"].every(e=>t.has(e))}catch{return!1}},c=(t,n,s,a,o)=>e.mapObjIndexed((e,n)=>((e,t,n,s,a,o)=>i(e)?e:"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),u=[["zh-CN","zh-SG","zh-Hans"],["zh-TW","zh-HK","zh-MO","zh-Hant"]],d=e=>{const t=(e=>{const t=u.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]},h=(e,t,n=null)=>{for(const s of d(t)){if(n&&s(n.locale))return n;const t=e.find(e=>s(e.locale));if(t)return t}return null},g=async(e,t,n,s=t)=>{const a={alpha:"alpha-a.locuslabs.com",beta:"beta-a.locuslabs.com",gamma:"gamma-a.locuslabs.com",prod:"a.locuslabs.com"},{assetStage:o,accountId:r,formatVersion:l}=e;let{venueId:i}=e;const u=`https://${a[o]||a.prod}/accounts/${r}`,d=l||"v5",g="kiosk"===e.auth?.type;if(g&&("string"!=typeof e.auth.signedManifestUrl||!e.auth.signedManifestUrl.trim()))throw new Error("Kiosk auth requires a non-empty signedManifestUrl");const f=!g&&e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getFiles?await globalThis[e.dataFetch].getFiles(e):await s(g?e.auth.signedManifestUrl:`${u}/${d}.json`),m=f[i]?f[i].venueCode:null;if(m){const t=Object.values(f).filter(e=>e.venueCode===m),s=f[i];for(const a of n){const n=h(t,a,s);if(n){i=n.id,e.venueId=`${i}`;break}}}if(!f[i])throw Error(`Attempt to access venue ${i} which is not within venue list: ${Object.keys(f)}`);const p=f[i].files,b=(!g&&e.dataFetch&&globalThis[e.dataFetch]&&globalThis[e.dataFetch].getVenueData?await globalThis[e.dataFetch].getVenueData(e):await t(p.venueData))[i];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=f;const v=(e=>{const t=e.deepLinkProps?e.deepLinkProps.contentStage:null;return"alpha"===t||"beta"===t||"prod"===t?t:null})(e);return b.files=v?c(b.category,p,v,r,i):p,b},f=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 m=([e,t,...n])=>[t,e,...n],p=(e,t)=>{return!e||!Array.isArray(e)||e.length<1?e:(n=e[0][0],s=t.ne.lng,a=t.sw.lng,n>=Math.min(s,a)&&n<=Math.max(s,a)?e:e.map(m));var n,s,a};export{f as buildStructures,s as createFetchJson,o as createFetchManifestJson,a as createFetchText,r as fetchStyleDoc,h as findVenueForLocale,g as getVenueDataFromUrls,p as normalizeCoords};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atriusmaps-node-sdk",
3
- "version": "3.3.1026",
3
+ "version": "3.3.1027",
4
4
  "description": "This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information",
5
5
  "keywords": [
6
6
  "map",