{"version":3,"file":"runtime.mjs","names":[],"sources":["../../src/ui/runtime.ts"],"sourcesContent":["import type { ClientRuntimeConfig } from \"../types\";\n\nexport type { ClientRuntimeInfo } from \"../types\";\n\ndeclare global {\n  interface Window {\n    __RUNTIME_CONFIG__?: ClientRuntimeConfig;\n    __CSP_NONCE__?: string;\n  }\n}\n\nexport function getRuntimeConfig(): ClientRuntimeConfig {\n  if (typeof window === \"undefined\") {\n    throw new Error(\"Runtime config is only available in the browser\");\n  }\n\n  if (!window.__RUNTIME_CONFIG__) {\n    throw new Error(\"Missing runtime config\");\n  }\n\n  return window.__RUNTIME_CONFIG__;\n}\n\nexport function getCspNonce() {\n  if (typeof window === \"undefined\") {\n    return undefined;\n  }\n\n  return window.__CSP_NONCE__;\n}\n\nexport function buildRuntimeHref(pathname: string, runtimeConfig?: Partial<ClientRuntimeConfig>) {\n  const basePath = runtimeConfig?.runtime?.runtimeBasePath ?? \"/\";\n  if (basePath === \"/\") {\n    return pathname;\n  }\n\n  if (!pathname.startsWith(\"/\")) {\n    return `${basePath}/${pathname}`;\n  }\n\n  return pathname === \"/\" ? basePath : `${basePath}${pathname}`;\n}\n\nexport function buildPublishedAccountHref(accountId: string) {\n  return `/apps/${encodeURIComponent(accountId)}`;\n}\n\nexport function buildPublishedGatewayHref(accountId: string, gatewayId: string) {\n  return `${buildPublishedAccountHref(accountId)}/${encodeURIComponent(gatewayId)}`;\n}\n"],"mappings":";AAWA,SAAgB,mBAAwC;CACtD,IAAI,OAAO,WAAW,aACpB,MAAM,IAAI,MAAM,iDAAiD;CAGnE,IAAI,CAAC,OAAO,oBACV,MAAM,IAAI,MAAM,wBAAwB;CAG1C,OAAO,OAAO;AAChB;AAEA,SAAgB,cAAc;CAC5B,IAAI,OAAO,WAAW,aACpB;CAGF,OAAO,OAAO;AAChB;AAEA,SAAgB,iBAAiB,UAAkB,eAA8C;CAC/F,MAAM,WAAW,eAAe,SAAS,mBAAmB;CAC5D,IAAI,aAAa,KACf,OAAO;CAGT,IAAI,CAAC,SAAS,WAAW,GAAG,GAC1B,OAAO,GAAG,SAAS,GAAG;CAGxB,OAAO,aAAa,MAAM,WAAW,GAAG,WAAW;AACrD;AAEA,SAAgB,0BAA0B,WAAmB;CAC3D,OAAO,SAAS,mBAAmB,SAAS;AAC9C;AAEA,SAAgB,0BAA0B,WAAmB,WAAmB;CAC9E,OAAO,GAAG,0BAA0B,SAAS,EAAE,GAAG,mBAAmB,SAAS;AAChF"}