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

174 lines (170 loc) 5.24 kB
'use strict'; var funcs = require('../../../src/utils/funcs.js'); var postprocMolUrlParms = require('../../../src/configs/postproc-mol-url-parms.js'); var postprocStateTracking = require('../../../src/configs/postproc-stateTracking.js'); const trunc = (value, len) => { if (value === void 0) { return void 0; } const stringValue = value.toString(); return stringValue.length > len ? stringValue.substring(0, len) : stringValue; }; const setIfDef = (name, value) => value !== void 0 ? { [name]: value } : {}; const validateHostAppProperties = (hostAppProperties) => { if (!hostAppProperties || typeof hostAppProperties !== "object") { return void 0; } const ret = {}; const keys = Object.keys(hostAppProperties).slice(0, 10); keys.forEach((key) => { let cleanKey = trunc(key.toString().replaceAll(/[^a-zA-Z0-9_]/g, ""), 128) ?? "X"; if (!cleanKey.match(/^[a-zA-Z]+/)) { cleanKey = `X${cleanKey}`; } let cleanVal = hostAppProperties[key]; if (cleanVal === null || cleanVal === void 0) { cleanVal = ""; } ret[cleanKey] = trunc(String(cleanVal), 128) ?? ""; }); return ret; }; function handleI18NParm(sdkConfig, prefix, configDest) { Object.keys(sdkConfig).filter((key) => key.startsWith(`${prefix}-`)).forEach((key) => { configDest[key] = sdkConfig[key]; }); } function prepareSDKConfig(sc) { const { name, debug, headless, theme, defaultSearchTerms, venueId, accountId, poiCategories, preserveStateInURL, supportURLDeepLinks, initState, deepLinkParms, uiHide, renderDiv, parentConfig, desktopViewMinWidth, forceDesktop, hostAppId, hostAppVersion, hostAppProperties, logFilter, searchPlaceholder, dataFetch, engineName, dynamicPoisUrlBaseV1, plugins, analytics2ActiveFlag, enablePoiSelection, showSurround, minZoom, maxZoom, noLangOptions, pinnedLocation, pinnedLocationZoom, pinnedLocationFocusAtStart, pinnedLocationBearing, pinnedLocationPitch } = sc; const extendsConfig = parentConfig ? [parentConfig] : headless ? ["sdkHeadless"] : ["sdkVisual"]; const config = { name, engineName, extends: extendsConfig, debug, logFilter, theme, uiHide, renderDiv, configPostProc: [], plugins: { venueDataLoader: { dataFetch, venueId, accountId }, sdkServer: { headless }, analytics2: { hostAppId: hostAppId ? trunc(hostAppId, 128) : void 0, hostAppVersion: hostAppVersion ? trunc(hostAppVersion, 128) : void 0, hostAppProperties: validateHostAppProperties(hostAppProperties) } }, uuid: typeof document !== "undefined" && document.location ? document.location.host : "unknown" }; if (analytics2ActiveFlag !== void 0) { config.plugins.analytics2 = { ...config.plugins.analytics2, active: analytics2ActiveFlag }; } if (!headless) { config.plugins["online/headerOnline"] = { searchPlaceholder }; config.plugins.mapRenderer = { ...setIfDef("enablePoiSelection", enablePoiSelection), surroundConfig: showSurround ? {} : null, viewLimits: { ...setIfDef("maxZoom", maxZoom), ...setIfDef("minZoom", minZoom) } }; config.plugins.userMenu = { noLangOptions }; if (pinnedLocation) { config.plugins["online/pinnedLocation"] = { location: pinnedLocation, zoom: pinnedLocationZoom, focusAtStart: pinnedLocationFocusAtStart, bearing: pinnedLocationBearing, pitch: pinnedLocationPitch }; } } config.plugins.searchService = defaultSearchTerms ? { defaultSearchTerms } : {}; handleI18NParm(sc, "defaultSearchTerms", config.plugins.searchService); if (extendsConfig.includes("sdkVisual")) { config.plugins["online/homeView"] = poiCategories ? { poiCategories } : {}; handleI18NParm(sc, "poiCategories", config.plugins["online/homeView"]); } if (plugins && typeof plugins === "object") { const pluginMap = plugins; if (pluginMap.draw) { config.plugins.draw = pluginMap.draw; } if (pluginMap.flightStatus) { config.plugins.flightStatus = pluginMap.flightStatus; config.plugins["online/flightDetails"] = {}; config.plugins["online/flightDetailsSearch"] = {}; } } if (preserveStateInURL) { (config.configPostProc ?? []).push("stateTracking"); config.plugins.deepLinking = { trackURL: true }; } if (supportURLDeepLinks) { (config.configPostProc ?? []).push("mol-url-parms"); } if (initState) { postprocStateTracking.setStateFromStateString(config, funcs.b64DecodeUnicode(initState), true); } if (deepLinkParms) { postprocMolUrlParms.setDeepLinksForParms(config, new URLSearchParams(deepLinkParms), true); } if (desktopViewMinWidth !== void 0) { config.desktopViewMinWidth = desktopViewMinWidth; } if (forceDesktop) { config.desktopViewMinWidth = 0; } if (dynamicPoisUrlBaseV1) { config.plugins.dynamicPois = { urlBaseV1: dynamicPoisUrlBaseV1 }; } return funcs.filterOb((_, value) => value !== void 0, config); } module.exports = prepareSDKConfig;