@pontive/pontkit-loader 1.14.0 → 1.15.0

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.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m="1.58.0",_=["/__pontive/auth/v1/runtime-config","/auth/v1/runtime-config"],g=1500,C=/^\d+\.\d+\.\d+$/;function w(t){return typeof t=="string"&&C.test(t)}function f(t){return typeof t=="string"&&/^https?:\/\//.test(t)}function u(t){return typeof t=="string"&&/^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t)}async function h(t={}){const e=t.fetchImpl??globalThis.fetch;if(typeof e!="function")return null;const i=t.urls??E(),s=t.timeoutMs??g;for(const o of i){const r=await T(e,o,s);if(r)return r}return null}function E(){return typeof window<"u"&&typeof window.__pontRuntimeConfigUrl=="string"?[window.__pontRuntimeConfigUrl]:_}async function T(t,e,i){const s=typeof AbortController=="function"?new AbortController:null,o=s?setTimeout(()=>s.abort(),i):null;try{const r=await t(e,{headers:{accept:"application/json"},signal:s?.signal});if(!r.ok)return null;const n=await r.json();if(!n||!w(n.pontkit_version))return null;const c={pontkit_version:n.pontkit_version,source:typeof n.source=="string"?n.source:void 0,catalog_revision:typeof n.catalog_revision=="number"?n.catalog_revision:void 0};return n.assets&&f(n.assets.js)&&f(n.assets.css)&&(c.assets={js:n.assets.js,css:n.assets.css}),n.integrity&&u(n.integrity.js)&&u(n.integrity.css)&&(c.integrity={js:n.integrity.js,css:n.integrity.css}),c}catch{return null}finally{o&&clearTimeout(o)}}let p=null,l=null;const a="@pontive/pontkit-core",S=[t=>`https://cdn.jsdelivr.net/npm/${a}@${t}/dist/index.mjs`,t=>`https://unpkg.com/${a}@${t}/dist/index.mjs`,t=>`https://esm.sh/${a}@${t}/dist/index.mjs`],O=[t=>`https://cdn.jsdelivr.net/npm/${a}@${t}/dist/styles.css`,t=>`https://unpkg.com/${a}@${t}/dist/styles.css`,t=>`https://esm.sh/${a}@${t}/dist/styles.css`],I=m;function N(t,e){return new Promise((i,s)=>{const o=document.createElement("link");o.rel="stylesheet",o.href=t,e&&(o.integrity=e,o.crossOrigin="anonymous"),o.onload=()=>i(),o.onerror=r=>s(r),document.head.appendChild(o)})}function $(t,e){return new Promise((i,s)=>{const o=document.createElement("script");o.type="module",o.src=t,o.integrity=e,o.crossOrigin="anonymous",o.onload=()=>i(),o.onerror=()=>s(new Error(`pontkit-core module at ${t} failed to load or did not match its integrity hash`)),document.head.appendChild(o)}).then(()=>import(t))}async function j(){return typeof window>"u"||typeof document>"u"?null:window.__pontLoaded?window.__pontCore:window.__pontLoading?window.__pontLoading:(l||(l=v().catch(t=>{throw l=null,window.__pontLoading=void 0,t}),window.__pontLoading=l),l)}async function v(){const t=await h(),e=t?.pontkit_version??I,i=S.map(n=>n(e)),s=O.map(n=>n(e));t?.assets&&(i.unshift(t.assets.js),s.unshift(t.assets.css));const o=t?.integrity;let r=null;for(let n=0;n<i.length;n++){const c=i[n],y=s[n];try{await N(y,o?.css);const d=o?await $(c,o.js):await import(c);return window.__pontCore=d,p=d,window.__pontLoaded=!0,window.__pontLoading=void 0,console.log(`PontKit Web Components loaded (${e}) from:`,c),p}catch(d){console.error(`Failed loading from ${c}`,d),r=d}}throw console.error("❌ Failed to load PontKit web components from all CDNs.",r),r}exports.PONTKIT_CORE_VERSION=m;exports.RUNTIME_CONFIG_PATHS=_;exports.RUNTIME_CONFIG_TIMEOUT_MS=g;exports.fetchRuntimeConfig=h;exports.isExactVersion=w;exports.isSriHash=u;exports.loadWebComponents=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m="1.58.0",_=["/__pontive/v1/frontend/runtime-config","/v1/frontend/runtime-config"],g=1500,C=/^\d+\.\d+\.\d+$/;function w(t){return typeof t=="string"&&C.test(t)}function f(t){return typeof t=="string"&&/^https?:\/\//.test(t)}function u(t){return typeof t=="string"&&/^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t)}async function y(t={}){const e=t.fetchImpl??globalThis.fetch;if(typeof e!="function")return null;const i=t.urls??E(),s=t.timeoutMs??g;for(const o of i){const r=await T(e,o,s);if(r)return r}return null}function E(){return typeof window<"u"&&typeof window.__pontRuntimeConfigUrl=="string"?[window.__pontRuntimeConfigUrl]:_}async function T(t,e,i){const s=typeof AbortController=="function"?new AbortController:null,o=s?setTimeout(()=>s.abort(),i):null;try{const r=await t(e,{headers:{accept:"application/json"},signal:s?.signal});if(!r.ok)return null;const n=await r.json();if(!n||!w(n.pontkit_version))return null;const c={pontkit_version:n.pontkit_version,source:typeof n.source=="string"?n.source:void 0,catalog_revision:typeof n.catalog_revision=="number"?n.catalog_revision:void 0};return n.assets&&f(n.assets.js)&&f(n.assets.css)&&(c.assets={js:n.assets.js,css:n.assets.css}),n.integrity&&u(n.integrity.js)&&u(n.integrity.css)&&(c.integrity={js:n.integrity.js,css:n.integrity.css}),c}catch{return null}finally{o&&clearTimeout(o)}}let p=null,a=null;const d="@pontive/pontkit-core",S=[t=>`https://cdn.jsdelivr.net/npm/${d}@${t}/dist/index.mjs`,t=>`https://unpkg.com/${d}@${t}/dist/index.mjs`,t=>`https://esm.sh/${d}@${t}/dist/index.mjs`],O=[t=>`https://cdn.jsdelivr.net/npm/${d}@${t}/dist/styles.css`,t=>`https://unpkg.com/${d}@${t}/dist/styles.css`,t=>`https://esm.sh/${d}@${t}/dist/styles.css`],I=m;function N(t,e){return new Promise((i,s)=>{const o=document.createElement("link");o.rel="stylesheet",o.href=t,e&&(o.integrity=e,o.crossOrigin="anonymous"),o.onload=()=>i(),o.onerror=r=>s(r),document.head.appendChild(o)})}function $(t,e){return new Promise((i,s)=>{const o=document.createElement("script");o.type="module",o.src=t,o.integrity=e,o.crossOrigin="anonymous",o.onload=()=>i(),o.onerror=()=>s(new Error(`pontkit-core module at ${t} failed to load or did not match its integrity hash`)),document.head.appendChild(o)}).then(()=>import(t))}async function j(){return typeof window>"u"||typeof document>"u"?null:window.__pontLoaded?window.__pontCore:window.__pontLoading?window.__pontLoading:(a||(a=v().catch(t=>{throw a=null,window.__pontLoading=void 0,t}),window.__pontLoading=a),a)}async function v(){const t=await y(),e=t?.pontkit_version??I,i=S.map(n=>n(e)),s=O.map(n=>n(e));t?.assets&&(i.unshift(t.assets.js),s.unshift(t.assets.css));const o=t?.integrity;let r=null;for(let n=0;n<i.length;n++){const c=i[n],h=s[n];try{await N(h,o?.css);const l=o?await $(c,o.js):await import(c);return window.__pontCore=l,p=l,window.__pontLoaded=!0,window.__pontLoading=void 0,console.log(`PontKit Web Components loaded (${e}) from:`,c),p}catch(l){console.error(`Failed loading from ${c}`,l),r=l}}throw console.error("❌ Failed to load PontKit web components from all CDNs.",r),r}exports.PONTKIT_CORE_VERSION=m;exports.RUNTIME_CONFIG_PATHS=_;exports.RUNTIME_CONFIG_TIMEOUT_MS=g;exports.fetchRuntimeConfig=y;exports.isExactVersion=w;exports.isSriHash=u;exports.loadWebComponents=j;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/pontkit-core-version.ts","../src/runtime-config.ts","../src/load-web-components.ts"],"sourcesContent":["/**\n * The exact `@pontive/pontkit-core` release this build loads from the CDN.\n *\n * It is the version installed as a dev dependency when the package was built —\n * i.e. the one the test suite ran against — baked in by `define` in\n * vite.config.ts and vitest.config.ts (see scripts/pontkit-core-version.mjs).\n * An exact version, never a range: an exact release is immutable on the CDN,\n * cacheable forever, and the only form that admits an integrity hash.\n *\n * Nothing at runtime may replace this with \"whatever is newest\" — that is the\n * defect it exists to end. The platform's runtime-config endpoint will be\n * allowed to override it, because that answer is the one the platform has\n * gated (pontive-spec/21-element-versioning-and-compatibility.md §9).\n */\nexport const PONTKIT_CORE_VERSION: string = __PONTKIT_CORE_VERSION__;\n","// Which @pontive/pontkit-core release to load, asked of the platform.\n//\n// The platform decides which release a project's screens render with — one\n// deployment default, an optional per-project canary — and publishes the answer\n// at `GET /auth/v1/runtime-config` on the project's auth server\n// (pontive-spec/21-element-versioning-and-compatibility.md §9). This package\n// reads it once, before importing the bundle, so an embedded widget renders\n// with the same release the hosted login pages do. The build-time stamp\n// (PONTKIT_CORE_VERSION) is the fallback when the answer cannot be read.\n//\n// The endpoint is reached through the app's own origin when the SDK's proxy is\n// mounted (`/__pontive/auth/v1/...`), and directly on `/auth/v1/...` when the app\n// itself runs on the auth domain. Both are tried; a host page can name a URL\n// outright with `window.__pontRuntimeConfigUrl`.\n\n/** The shape of GET /auth/v1/runtime-config. */\nexport interface RuntimeConfig {\n pontkit_version: string;\n catalog_revision?: number;\n source?: string;\n assets?: { js: string; css: string };\n /**\n * Subresource-integrity hashes (\"sha384-…\") of the release's module and\n * stylesheet, recorded by the platform when the release was gated. When\n * present the loader passes them to the browser, which refuses bytes that\n * differ — from the platform origin or from any public CDN alike.\n */\n integrity?: { js: string; css: string };\n}\n\nexport const RUNTIME_CONFIG_PATHS = [\n \"/__pontive/auth/v1/runtime-config\",\n \"/auth/v1/runtime-config\",\n] as const;\n\n/** How long to wait for the platform before loading the stamped release. */\nexport const RUNTIME_CONFIG_TIMEOUT_MS = 1500;\n\nconst EXACT_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nexport interface FetchRuntimeConfigOptions {\n fetchImpl?: typeof fetch;\n urls?: readonly string[];\n timeoutMs?: number;\n}\n\n/** Whether `value` names one release rather than a range or garbage. */\nexport function isExactVersion(value: unknown): value is string {\n return typeof value === \"string\" && EXACT_VERSION.test(value);\n}\n\nfunction isHttpUrl(value: unknown): value is string {\n return typeof value === \"string\" && /^https?:\\/\\//.test(value);\n}\n\n/** Whether `value` is a well-formed SRI value the browser will accept. */\nexport function isSriHash(value: unknown): value is string {\n return typeof value === \"string\" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(value);\n}\n\n/**\n * Reads the platform's runtime config, or null when no candidate URL answers\n * with one that can be trusted. Never throws: the caller's fallback is the\n * stamped release, and a reachability problem should not become a page error.\n */\nexport async function fetchRuntimeConfig(\n options: FetchRuntimeConfigOptions = {},\n): Promise<RuntimeConfig | null> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") return null;\n\n const urls = options.urls ?? candidateUrls();\n const timeoutMs = options.timeoutMs ?? RUNTIME_CONFIG_TIMEOUT_MS;\n\n for (const url of urls) {\n const config = await readOne(fetchImpl, url, timeoutMs);\n if (config) return config;\n }\n\n return null;\n}\n\nfunction candidateUrls(): readonly string[] {\n if (typeof window !== \"undefined\" && typeof window.__pontRuntimeConfigUrl === \"string\") {\n return [window.__pontRuntimeConfigUrl];\n }\n\n return RUNTIME_CONFIG_PATHS;\n}\n\nasync function readOne(\n fetchImpl: typeof fetch,\n url: string,\n timeoutMs: number,\n): Promise<RuntimeConfig | null> {\n const controller = typeof AbortController === \"function\" ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;\n\n try {\n const response = await fetchImpl(url, {\n headers: { accept: \"application/json\" },\n signal: controller?.signal,\n });\n if (!response.ok) return null;\n\n const body = (await response.json()) as Partial<RuntimeConfig> | null;\n if (!body || !isExactVersion(body.pontkit_version)) return null;\n\n const config: RuntimeConfig = {\n pontkit_version: body.pontkit_version,\n source: typeof body.source === \"string\" ? body.source : undefined,\n catalog_revision:\n typeof body.catalog_revision === \"number\" ? body.catalog_revision : undefined,\n };\n\n // Assets are taken only as a pair of absolute URLs; anything else means\n // \"load from the CDN list by version\".\n if (body.assets && isHttpUrl(body.assets.js) && isHttpUrl(body.assets.css)) {\n config.assets = { js: body.assets.js, css: body.assets.css };\n }\n\n // Half a pair is no pair: the browser would check one file and not the\n // other, and nobody would notice the unchecked one.\n if (body.integrity && isSriHash(body.integrity.js) && isSriHash(body.integrity.css)) {\n config.integrity = { js: body.integrity.js, css: body.integrity.css };\n }\n\n return config;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n","import { PONTKIT_CORE_VERSION } from \"./pontkit-core-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet core: any = null;\n\n// The load in flight, if any. This is the guard, and it is a promise rather\n// than a boolean on purpose: a flag set before the first `await` let a second\n// concurrent caller return `core` while it was still null and carry on as if\n// it were ready. A\n// promise gives every caller the same eventual answer. It is cleared on failure\n// so a later call can retry rather than inherit a latched failure.\nlet loadPromise: Promise<any> | null = null;\n\nconst PACKAGE_NAME = \"@pontive/pontkit-core\";\n\n// Base CDN templates (version will be injected)\nconst CDN_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n];\n\nconst CSS_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/styles.css`,\n];\n\n// Which release loads is decided by the PLATFORM, and failing that at BUILD\n// time — never by asking a registry at runtime. This package used to fetch jsDelivr's version list and take the\n// newest entry of any major — the `1.x` filter had been commented out — with\n// `^1` as the fallback when the fetch failed, a different major from the 2.x\n// the wrappers target. Whatever npm happened to hold newest is not a version\n// anyone tested against, and a customer's page picked it up on the next reload\n// with nothing in their build having changed.\n//\n// Now the project's auth server says which release its screens load\n// (GET /auth/v1/runtime-config, see ./runtime-config.ts), so an embedded widget\n// renders with the same bundle the hosted login pages do, and a canary or a\n// promotion reaches it without a rebuild. PONTKIT_CORE_VERSION — the exact\n// release this package was built and tested with — is the fallback when that\n// endpoint cannot be read.\nconst FALLBACK_VERSION = PONTKIT_CORE_VERSION;\n\nfunction loadCss(url: string, integrity?: string) {\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = url;\n if (integrity) {\n // SRI is only enforced on a CORS-mode fetch; the platform origin and the\n // public CDNs all answer with Access-Control-Allow-Origin: *.\n link.integrity = integrity;\n link.crossOrigin = \"anonymous\";\n }\n link.onload = () => resolve();\n link.onerror = (err) => reject(err);\n document.head.appendChild(link);\n });\n}\n\n// Loads the module through a <script type=\"module\"> carrying the integrity\n// attribute, then imports it. A dynamic import() cannot carry SRI, but the\n// script element can, and once it has fetched and verified the module the\n// browser's module map holds it under that URL — the import() that follows\n// resolves from the map without a second fetch. A hash mismatch fails the\n// script's load, the promise rejects, and the loader moves to the next\n// source, which is the right outcome: bytes the platform did not gate must not\n// run, wherever they came from.\nfunction loadVerifiedModule(url: string, integrity: string): Promise<any> {\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = \"module\";\n script.src = url;\n script.integrity = integrity;\n script.crossOrigin = \"anonymous\";\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error(`pontkit-core module at ${url} failed to load or did not match its integrity hash`));\n document.head.appendChild(script);\n }).then(\n () =>\n import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n url\n ),\n );\n}\n\nexport async function loadWebComponents(): Promise<any> {\n // No DOM means no custom elements to define and no CDN to fetch from.\n //\n // Returning rather than throwing matters because src/index.ts calls this at\n // module scope: under a server renderer the rejection surfaced as a console\n // error on every render, reporting a failure that is not one. Checked before\n // the guards below so the browser still loads normally after hydration.\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return null;\n }\n\n // Another copy of this package on the same page already finished loading.\n if (window.__pontLoaded) {\n return window.__pontCore;\n }\n\n // Another copy of this package on the same page is loading right now.\n if (window.__pontLoading) {\n return window.__pontLoading;\n }\n\n if (!loadPromise) {\n loadPromise = loadFromCdn().catch((err) => {\n loadPromise = null;\n window.__pontLoading = undefined;\n throw err;\n });\n\n window.__pontLoading = loadPromise;\n }\n\n return loadPromise;\n}\n\nasync function loadFromCdn(): Promise<any> {\n const runtime = await fetchRuntimeConfig();\n const resolvedVersion = runtime?.pontkit_version ?? FALLBACK_VERSION;\n\n const CDN_SOURCES = CDN_TEMPLATES.map((fn) => fn(resolvedVersion));\n const CSS_SOURCES = CSS_TEMPLATES.map((fn) => fn(resolvedVersion));\n\n // The platform's own asset location goes first when it names one; the public\n // CDNs stay as the fallback list for the same version.\n if (runtime?.assets) {\n CDN_SOURCES.unshift(runtime.assets.js);\n CSS_SOURCES.unshift(runtime.assets.css);\n }\n\n // The hashes describe the npm release's bytes, which every source below\n // serves verbatim, so they apply to all of them — not only to the\n // platform's. A source whose bytes differ is a source that must not run.\n const integrity = runtime?.integrity;\n\n let lastError: unknown = null;\n\n for (let i = 0; i < CDN_SOURCES.length; i++) {\n const cdn = CDN_SOURCES[i];\n const cssCdn = CSS_SOURCES[i];\n\n try {\n // The stylesheet first, so the elements never render unstyled.\n await loadCss(cssCdn, integrity?.css);\n\n // Then the module.\n //\n // All three ignore directives, and none of them is optional.\n //\n // `cdn` is a full URL resolved at runtime, so a bundler that tries to\n // resolve it statically cannot: webpack and Turbopack turn a dynamic\n // import with a variable specifier into a module-graph lookup and throw\n // `Cannot find module 'https://…'` at runtime — no network request is ever\n // made, and the message reads as though the CDN were at fault. Next.js\n // uses Turbopack in development and webpack in production, so an app\n // built with it failed on every CDN in the list identically.\n //\n // `@vite-ignore` alone covered only Vite. Each bundler reads its own\n // comment and ignores the others, so all three coexist and each one keeps\n // this a real runtime import.\n const module: any = integrity\n ? await loadVerifiedModule(cdn, integrity.js)\n : await import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n cdn\n );\n\n // The elements define themselves on import. The module is kept on the\n // window so a second copy of this package on the page (two bindings,\n // two bundles) answers from it instead of loading the bundle again.\n // There is no SDK in it: the provider element is given one by its host\n // (the React `Provider` injects @pontive/oidc-client's `Auth`).\n window.__pontCore = module;\n core = module;\n\n // Set only once the module is on the window, so a copy of this package\n // that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return core;\n } catch (err) {\n console.error(`Failed loading from ${cdn}`, err);\n lastError = err;\n }\n }\n\n console.error(\n \"❌ Failed to load PontKit web components from all CDNs.\",\n lastError,\n );\n throw lastError;\n}\n"],"names":["PONTKIT_CORE_VERSION","RUNTIME_CONFIG_PATHS","RUNTIME_CONFIG_TIMEOUT_MS","EXACT_VERSION","isExactVersion","value","isHttpUrl","isSriHash","fetchRuntimeConfig","options","fetchImpl","urls","candidateUrls","timeoutMs","url","config","readOne","controller","timer","response","body","core","loadPromise","PACKAGE_NAME","CDN_TEMPLATES","v","CSS_TEMPLATES","FALLBACK_VERSION","loadCss","integrity","resolve","reject","link","err","loadVerifiedModule","script","loadWebComponents","loadFromCdn","runtime","resolvedVersion","CDN_SOURCES","fn","CSS_SOURCES","lastError","i","cdn","cssCdn","module"],"mappings":"gFAcO,MAAMA,EAA+B,SCgB/BC,EAAuB,CAClC,oCACA,yBACF,EAGaC,EAA4B,KAEnCC,EAAgB,kBASf,SAASC,EAAeC,EAAiC,CAC9D,OAAO,OAAOA,GAAU,UAAYF,EAAc,KAAKE,CAAK,CAC9D,CAEA,SAASC,EAAUD,EAAiC,CAClD,OAAO,OAAOA,GAAU,UAAY,eAAe,KAAKA,CAAK,CAC/D,CAGO,SAASE,EAAUF,EAAiC,CACzD,OAAO,OAAOA,GAAU,UAAY,sCAAsC,KAAKA,CAAK,CACtF,CAOA,eAAsBG,EACpBC,EAAqC,GACN,CAC/B,MAAMC,EAAYD,EAAQ,WAAa,WAAW,MAClD,GAAI,OAAOC,GAAc,WAAY,OAAO,KAE5C,MAAMC,EAAOF,EAAQ,MAAQG,EAAA,EACvBC,EAAYJ,EAAQ,WAAaP,EAEvC,UAAWY,KAAOH,EAAM,CACtB,MAAMI,EAAS,MAAMC,EAAQN,EAAW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lBA,EACT,CAEA,eAAee,GAA4B,CACzC,MAAMC,EAAU,MAAM9B,EAAA,EAChB+B,EAAkBD,GAAS,iBAAmBX,EAE9Ca,EAAchB,EAAc,IAAKiB,GAAOA,EAAGF,CAAe,CAAC,EAC3DG,EAAchB,EAAc,IAAKe,GAAOA,EAAGF,CAAe,CAAC,EAI7DD,GAAS,SACXE,EAAY,QAAQF,EAAQ,OAAO,EAAE,EACrCI,EAAY,QAAQJ,EAAQ,OAAO,GAAG,GAMxC,MAAMT,EAAYS,GAAS,UAE3B,IAAIK,EAAqB,KAEzB,QAASC,EAAI,EAAGA,EAAIJ,EAAY,OAAQI,IAAK,CAC3C,MAAMC,EAAML,EAAYI,CAAC,EACnBE,EAASJ,EAAYE,CAAC,EAE5B,GAAI,CAEF,MAAMhB,EAAQkB,EAAQjB,GAAW,GAAG,EAiBpC,MAAMkB,EAAclB,EAChB,MAAMK,EAAmBW,EAAKhB,EAAU,EAAE,EAC1C,MAAM,OAIJgB,GAQN,cAAO,WAAaE,EACpB1B,EAAO0B,EAIP,OAAO,aAAe,GACtB,OAAO,cAAgB,OAEvB,QAAQ,IACN,kCAAkCR,CAAe,UACjDM,CAAA,EAGKxB,CACT,OAASY,EAAK,CACZ,QAAQ,MAAM,uBAAuBY,CAAG,GAAIZ,CAAG,EAC/CU,EAAYV,CACd,CACF,CAEA,cAAQ,MACN,yDACAU,CAAA,EAEIA,CACR"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/pontkit-core-version.ts","../src/runtime-config.ts","../src/load-web-components.ts"],"sourcesContent":["/**\n * The exact `@pontive/pontkit-core` release this build loads from the CDN.\n *\n * It is the version installed as a dev dependency when the package was built —\n * i.e. the one the test suite ran against — baked in by `define` in\n * vite.config.ts and vitest.config.ts (see scripts/pontkit-core-version.mjs).\n * An exact version, never a range: an exact release is immutable on the CDN,\n * cacheable forever, and the only form that admits an integrity hash.\n *\n * Nothing at runtime may replace this with \"whatever is newest\" — that is the\n * defect it exists to end. The platform's runtime-config endpoint will be\n * allowed to override it, because that answer is the one the platform has\n * gated (pontive-spec/21-element-versioning-and-compatibility.md §9).\n */\nexport const PONTKIT_CORE_VERSION: string = __PONTKIT_CORE_VERSION__;\n","// Which @pontive/pontkit-core release to load, asked of the platform.\n//\n// The platform decides which release a project's screens render with — one\n// deployment default, an optional per-project canary — and publishes the answer\n// at `GET /v1/frontend/runtime-config` on the project's auth server\n// (pontive-spec/21-element-versioning-and-compatibility.md §9). This package\n// reads it once, before importing the bundle, so an embedded widget renders\n// with the same release the hosted login pages do. The build-time stamp\n// (PONTKIT_CORE_VERSION) is the fallback when the answer cannot be read.\n//\n// The endpoint is reached through the app's own origin when the SDK's proxy is\n// mounted (`/__pontive/v1/frontend/...`), and directly on `/v1/frontend/...` when the app\n// itself runs on the auth domain. Both are tried; a host page can name a URL\n// outright with `window.__pontRuntimeConfigUrl`.\n\n/** The shape of GET /v1/frontend/runtime-config. */\nexport interface RuntimeConfig {\n pontkit_version: string;\n catalog_revision?: number;\n source?: string;\n assets?: { js: string; css: string };\n /**\n * Subresource-integrity hashes (\"sha384-…\") of the release's module and\n * stylesheet, recorded by the platform when the release was gated. When\n * present the loader passes them to the browser, which refuses bytes that\n * differ — from the platform origin or from any public CDN alike.\n */\n integrity?: { js: string; css: string };\n}\n\nexport const RUNTIME_CONFIG_PATHS = [\n \"/__pontive/v1/frontend/runtime-config\",\n \"/v1/frontend/runtime-config\",\n] as const;\n\n/** How long to wait for the platform before loading the stamped release. */\nexport const RUNTIME_CONFIG_TIMEOUT_MS = 1500;\n\nconst EXACT_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nexport interface FetchRuntimeConfigOptions {\n fetchImpl?: typeof fetch;\n urls?: readonly string[];\n timeoutMs?: number;\n}\n\n/** Whether `value` names one release rather than a range or garbage. */\nexport function isExactVersion(value: unknown): value is string {\n return typeof value === \"string\" && EXACT_VERSION.test(value);\n}\n\nfunction isHttpUrl(value: unknown): value is string {\n return typeof value === \"string\" && /^https?:\\/\\//.test(value);\n}\n\n/** Whether `value` is a well-formed SRI value the browser will accept. */\nexport function isSriHash(value: unknown): value is string {\n return typeof value === \"string\" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(value);\n}\n\n/**\n * Reads the platform's runtime config, or null when no candidate URL answers\n * with one that can be trusted. Never throws: the caller's fallback is the\n * stamped release, and a reachability problem should not become a page error.\n */\nexport async function fetchRuntimeConfig(\n options: FetchRuntimeConfigOptions = {},\n): Promise<RuntimeConfig | null> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") return null;\n\n const urls = options.urls ?? candidateUrls();\n const timeoutMs = options.timeoutMs ?? RUNTIME_CONFIG_TIMEOUT_MS;\n\n for (const url of urls) {\n const config = await readOne(fetchImpl, url, timeoutMs);\n if (config) return config;\n }\n\n return null;\n}\n\nfunction candidateUrls(): readonly string[] {\n if (typeof window !== \"undefined\" && typeof window.__pontRuntimeConfigUrl === \"string\") {\n return [window.__pontRuntimeConfigUrl];\n }\n\n return RUNTIME_CONFIG_PATHS;\n}\n\nasync function readOne(\n fetchImpl: typeof fetch,\n url: string,\n timeoutMs: number,\n): Promise<RuntimeConfig | null> {\n const controller = typeof AbortController === \"function\" ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;\n\n try {\n const response = await fetchImpl(url, {\n headers: { accept: \"application/json\" },\n signal: controller?.signal,\n });\n if (!response.ok) return null;\n\n const body = (await response.json()) as Partial<RuntimeConfig> | null;\n if (!body || !isExactVersion(body.pontkit_version)) return null;\n\n const config: RuntimeConfig = {\n pontkit_version: body.pontkit_version,\n source: typeof body.source === \"string\" ? body.source : undefined,\n catalog_revision:\n typeof body.catalog_revision === \"number\" ? body.catalog_revision : undefined,\n };\n\n // Assets are taken only as a pair of absolute URLs; anything else means\n // \"load from the CDN list by version\".\n if (body.assets && isHttpUrl(body.assets.js) && isHttpUrl(body.assets.css)) {\n config.assets = { js: body.assets.js, css: body.assets.css };\n }\n\n // Half a pair is no pair: the browser would check one file and not the\n // other, and nobody would notice the unchecked one.\n if (body.integrity && isSriHash(body.integrity.js) && isSriHash(body.integrity.css)) {\n config.integrity = { js: body.integrity.js, css: body.integrity.css };\n }\n\n return config;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n","import { PONTKIT_CORE_VERSION } from \"./pontkit-core-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet core: any = null;\n\n// The load in flight, if any. This is the guard, and it is a promise rather\n// than a boolean on purpose: a flag set before the first `await` let a second\n// concurrent caller return `core` while it was still null and carry on as if\n// it were ready. A\n// promise gives every caller the same eventual answer. It is cleared on failure\n// so a later call can retry rather than inherit a latched failure.\nlet loadPromise: Promise<any> | null = null;\n\nconst PACKAGE_NAME = \"@pontive/pontkit-core\";\n\n// Base CDN templates (version will be injected)\nconst CDN_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n];\n\nconst CSS_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/styles.css`,\n];\n\n// Which release loads is decided by the PLATFORM, and failing that at BUILD\n// time — never by asking a registry at runtime. This package used to fetch jsDelivr's version list and take the\n// newest entry of any major — the `1.x` filter had been commented out — with\n// `^1` as the fallback when the fetch failed, a different major from the 2.x\n// the wrappers target. Whatever npm happened to hold newest is not a version\n// anyone tested against, and a customer's page picked it up on the next reload\n// with nothing in their build having changed.\n//\n// Now the project's auth server says which release its screens load\n// (GET /v1/frontend/runtime-config, see ./runtime-config.ts), so an embedded widget\n// renders with the same bundle the hosted login pages do, and a canary or a\n// promotion reaches it without a rebuild. PONTKIT_CORE_VERSION — the exact\n// release this package was built and tested with — is the fallback when that\n// endpoint cannot be read.\nconst FALLBACK_VERSION = PONTKIT_CORE_VERSION;\n\nfunction loadCss(url: string, integrity?: string) {\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = url;\n if (integrity) {\n // SRI is only enforced on a CORS-mode fetch; the platform origin and the\n // public CDNs all answer with Access-Control-Allow-Origin: *.\n link.integrity = integrity;\n link.crossOrigin = \"anonymous\";\n }\n link.onload = () => resolve();\n link.onerror = (err) => reject(err);\n document.head.appendChild(link);\n });\n}\n\n// Loads the module through a <script type=\"module\"> carrying the integrity\n// attribute, then imports it. A dynamic import() cannot carry SRI, but the\n// script element can, and once it has fetched and verified the module the\n// browser's module map holds it under that URL — the import() that follows\n// resolves from the map without a second fetch. A hash mismatch fails the\n// script's load, the promise rejects, and the loader moves to the next\n// source, which is the right outcome: bytes the platform did not gate must not\n// run, wherever they came from.\nfunction loadVerifiedModule(url: string, integrity: string): Promise<any> {\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = \"module\";\n script.src = url;\n script.integrity = integrity;\n script.crossOrigin = \"anonymous\";\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error(`pontkit-core module at ${url} failed to load or did not match its integrity hash`));\n document.head.appendChild(script);\n }).then(\n () =>\n import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n url\n ),\n );\n}\n\nexport async function loadWebComponents(): Promise<any> {\n // No DOM means no custom elements to define and no CDN to fetch from.\n //\n // Returning rather than throwing matters because src/index.ts calls this at\n // module scope: under a server renderer the rejection surfaced as a console\n // error on every render, reporting a failure that is not one. Checked before\n // the guards below so the browser still loads normally after hydration.\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return null;\n }\n\n // Another copy of this package on the same page already finished loading.\n if (window.__pontLoaded) {\n return window.__pontCore;\n }\n\n // Another copy of this package on the same page is loading right now.\n if (window.__pontLoading) {\n return window.__pontLoading;\n }\n\n if (!loadPromise) {\n loadPromise = loadFromCdn().catch((err) => {\n loadPromise = null;\n window.__pontLoading = undefined;\n throw err;\n });\n\n window.__pontLoading = loadPromise;\n }\n\n return loadPromise;\n}\n\nasync function loadFromCdn(): Promise<any> {\n const runtime = await fetchRuntimeConfig();\n const resolvedVersion = runtime?.pontkit_version ?? FALLBACK_VERSION;\n\n const CDN_SOURCES = CDN_TEMPLATES.map((fn) => fn(resolvedVersion));\n const CSS_SOURCES = CSS_TEMPLATES.map((fn) => fn(resolvedVersion));\n\n // The platform's own asset location goes first when it names one; the public\n // CDNs stay as the fallback list for the same version.\n if (runtime?.assets) {\n CDN_SOURCES.unshift(runtime.assets.js);\n CSS_SOURCES.unshift(runtime.assets.css);\n }\n\n // The hashes describe the npm release's bytes, which every source below\n // serves verbatim, so they apply to all of them — not only to the\n // platform's. A source whose bytes differ is a source that must not run.\n const integrity = runtime?.integrity;\n\n let lastError: unknown = null;\n\n for (let i = 0; i < CDN_SOURCES.length; i++) {\n const cdn = CDN_SOURCES[i];\n const cssCdn = CSS_SOURCES[i];\n\n try {\n // The stylesheet first, so the elements never render unstyled.\n await loadCss(cssCdn, integrity?.css);\n\n // Then the module.\n //\n // All three ignore directives, and none of them is optional.\n //\n // `cdn` is a full URL resolved at runtime, so a bundler that tries to\n // resolve it statically cannot: webpack and Turbopack turn a dynamic\n // import with a variable specifier into a module-graph lookup and throw\n // `Cannot find module 'https://…'` at runtime — no network request is ever\n // made, and the message reads as though the CDN were at fault. Next.js\n // uses Turbopack in development and webpack in production, so an app\n // built with it failed on every CDN in the list identically.\n //\n // `@vite-ignore` alone covered only Vite. Each bundler reads its own\n // comment and ignores the others, so all three coexist and each one keeps\n // this a real runtime import.\n const module: any = integrity\n ? await loadVerifiedModule(cdn, integrity.js)\n : await import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n cdn\n );\n\n // The elements define themselves on import. The module is kept on the\n // window so a second copy of this package on the page (two bindings,\n // two bundles) answers from it instead of loading the bundle again.\n // There is no SDK in it: the provider element is given one by its host\n // (the React `Provider` injects @pontive/oidc-client's `Auth`).\n window.__pontCore = module;\n core = module;\n\n // Set only once the module is on the window, so a copy of this package\n // that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return core;\n } catch (err) {\n console.error(`Failed loading from ${cdn}`, err);\n lastError = err;\n }\n }\n\n console.error(\n \"❌ Failed to load PontKit web components from all CDNs.\",\n lastError,\n );\n throw lastError;\n}\n"],"names":["PONTKIT_CORE_VERSION","RUNTIME_CONFIG_PATHS","RUNTIME_CONFIG_TIMEOUT_MS","EXACT_VERSION","isExactVersion","value","isHttpUrl","isSriHash","fetchRuntimeConfig","options","fetchImpl","urls","candidateUrls","timeoutMs","url","config","readOne","controller","timer","response","body","core","loadPromise","PACKAGE_NAME","CDN_TEMPLATES","v","CSS_TEMPLATES","FALLBACK_VERSION","loadCss","integrity","resolve","reject","link","err","loadVerifiedModule","script","loadWebComponents","loadFromCdn","runtime","resolvedVersion","CDN_SOURCES","fn","CSS_SOURCES","lastError","i","cdn","cssCdn","module"],"mappings":"gFAcO,MAAMA,EAA+B,SCgB/BC,EAAuB,CAClC,wCACA,6BACF,EAGaC,EAA4B,KAEnCC,EAAgB,kBASf,SAASC,EAAeC,EAAiC,CAC9D,OAAO,OAAOA,GAAU,UAAYF,EAAc,KAAKE,CAAK,CAC9D,CAEA,SAASC,EAAUD,EAAiC,CAClD,OAAO,OAAOA,GAAU,UAAY,eAAe,KAAKA,CAAK,CAC/D,CAGO,SAASE,EAAUF,EAAiC,CACzD,OAAO,OAAOA,GAAU,UAAY,sCAAsC,KAAKA,CAAK,CACtF,CAOA,eAAsBG,EACpBC,EAAqC,GACN,CAC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
+ "/v1/frontend/runtime-config"
4
4
  ], I = 1500, w = /^\d+\.\d+\.\d+$/;
5
- function h(t) {
5
+ function y(t) {
6
6
  return typeof t == "string" && w.test(t);
7
7
  }
8
8
  function u(t) {
@@ -11,7 +11,7 @@ function u(t) {
11
11
  function f(t) {
12
12
  return typeof t == "string" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t);
13
13
  }
14
- async function y(t = {}) {
14
+ async function h(t = {}) {
15
15
  const s = t.fetchImpl ?? globalThis.fetch;
16
16
  if (typeof s != "function") return null;
17
17
  const i = t.urls ?? C(), e = t.timeoutMs ?? 1500;
@@ -33,7 +33,7 @@ async function E(t, s, i) {
33
33
  });
34
34
  if (!r.ok) return null;
35
35
  const n = await r.json();
36
- if (!n || !h(n.pontkit_version)) return null;
36
+ if (!n || !y(n.pontkit_version)) return null;
37
37
  const c = {
38
38
  pontkit_version: n.pontkit_version,
39
39
  source: typeof n.source == "string" ? n.source : void 0,
@@ -81,7 +81,7 @@ async function N() {
81
81
  }), window.__pontLoading = a), a);
82
82
  }
83
83
  async function O() {
84
- const t = await y(), s = t?.pontkit_version ?? $, i = T.map((n) => n(s)), e = S.map((n) => n(s));
84
+ const t = await h(), s = t?.pontkit_version ?? $, i = T.map((n) => n(s)), e = S.map((n) => n(s));
85
85
  t?.assets && (i.unshift(t.assets.js), e.unshift(t.assets.css));
86
86
  const o = t?.integrity;
87
87
  let r = null;
@@ -112,8 +112,8 @@ export {
112
112
  _ as PONTKIT_CORE_VERSION,
113
113
  g as RUNTIME_CONFIG_PATHS,
114
114
  I as RUNTIME_CONFIG_TIMEOUT_MS,
115
- y as fetchRuntimeConfig,
116
- h as isExactVersion,
115
+ h as fetchRuntimeConfig,
116
+ y as isExactVersion,
117
117
  f as isSriHash,
118
118
  N as loadWebComponents
119
119
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/pontkit-core-version.ts","../src/runtime-config.ts","../src/load-web-components.ts"],"sourcesContent":["/**\n * The exact `@pontive/pontkit-core` release this build loads from the CDN.\n *\n * It is the version installed as a dev dependency when the package was built —\n * i.e. the one the test suite ran against — baked in by `define` in\n * vite.config.ts and vitest.config.ts (see scripts/pontkit-core-version.mjs).\n * An exact version, never a range: an exact release is immutable on the CDN,\n * cacheable forever, and the only form that admits an integrity hash.\n *\n * Nothing at runtime may replace this with \"whatever is newest\" — that is the\n * defect it exists to end. The platform's runtime-config endpoint will be\n * allowed to override it, because that answer is the one the platform has\n * gated (pontive-spec/21-element-versioning-and-compatibility.md §9).\n */\nexport const PONTKIT_CORE_VERSION: string = __PONTKIT_CORE_VERSION__;\n","// Which @pontive/pontkit-core release to load, asked of the platform.\n//\n// The platform decides which release a project's screens render with — one\n// deployment default, an optional per-project canary — and publishes the answer\n// at `GET /auth/v1/runtime-config` on the project's auth server\n// (pontive-spec/21-element-versioning-and-compatibility.md §9). This package\n// reads it once, before importing the bundle, so an embedded widget renders\n// with the same release the hosted login pages do. The build-time stamp\n// (PONTKIT_CORE_VERSION) is the fallback when the answer cannot be read.\n//\n// The endpoint is reached through the app's own origin when the SDK's proxy is\n// mounted (`/__pontive/auth/v1/...`), and directly on `/auth/v1/...` when the app\n// itself runs on the auth domain. Both are tried; a host page can name a URL\n// outright with `window.__pontRuntimeConfigUrl`.\n\n/** The shape of GET /auth/v1/runtime-config. */\nexport interface RuntimeConfig {\n pontkit_version: string;\n catalog_revision?: number;\n source?: string;\n assets?: { js: string; css: string };\n /**\n * Subresource-integrity hashes (\"sha384-…\") of the release's module and\n * stylesheet, recorded by the platform when the release was gated. When\n * present the loader passes them to the browser, which refuses bytes that\n * differ — from the platform origin or from any public CDN alike.\n */\n integrity?: { js: string; css: string };\n}\n\nexport const RUNTIME_CONFIG_PATHS = [\n \"/__pontive/auth/v1/runtime-config\",\n \"/auth/v1/runtime-config\",\n] as const;\n\n/** How long to wait for the platform before loading the stamped release. */\nexport const RUNTIME_CONFIG_TIMEOUT_MS = 1500;\n\nconst EXACT_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nexport interface FetchRuntimeConfigOptions {\n fetchImpl?: typeof fetch;\n urls?: readonly string[];\n timeoutMs?: number;\n}\n\n/** Whether `value` names one release rather than a range or garbage. */\nexport function isExactVersion(value: unknown): value is string {\n return typeof value === \"string\" && EXACT_VERSION.test(value);\n}\n\nfunction isHttpUrl(value: unknown): value is string {\n return typeof value === \"string\" && /^https?:\\/\\//.test(value);\n}\n\n/** Whether `value` is a well-formed SRI value the browser will accept. */\nexport function isSriHash(value: unknown): value is string {\n return typeof value === \"string\" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(value);\n}\n\n/**\n * Reads the platform's runtime config, or null when no candidate URL answers\n * with one that can be trusted. Never throws: the caller's fallback is the\n * stamped release, and a reachability problem should not become a page error.\n */\nexport async function fetchRuntimeConfig(\n options: FetchRuntimeConfigOptions = {},\n): Promise<RuntimeConfig | null> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") return null;\n\n const urls = options.urls ?? candidateUrls();\n const timeoutMs = options.timeoutMs ?? RUNTIME_CONFIG_TIMEOUT_MS;\n\n for (const url of urls) {\n const config = await readOne(fetchImpl, url, timeoutMs);\n if (config) return config;\n }\n\n return null;\n}\n\nfunction candidateUrls(): readonly string[] {\n if (typeof window !== \"undefined\" && typeof window.__pontRuntimeConfigUrl === \"string\") {\n return [window.__pontRuntimeConfigUrl];\n }\n\n return RUNTIME_CONFIG_PATHS;\n}\n\nasync function readOne(\n fetchImpl: typeof fetch,\n url: string,\n timeoutMs: number,\n): Promise<RuntimeConfig | null> {\n const controller = typeof AbortController === \"function\" ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;\n\n try {\n const response = await fetchImpl(url, {\n headers: { accept: \"application/json\" },\n signal: controller?.signal,\n });\n if (!response.ok) return null;\n\n const body = (await response.json()) as Partial<RuntimeConfig> | null;\n if (!body || !isExactVersion(body.pontkit_version)) return null;\n\n const config: RuntimeConfig = {\n pontkit_version: body.pontkit_version,\n source: typeof body.source === \"string\" ? body.source : undefined,\n catalog_revision:\n typeof body.catalog_revision === \"number\" ? body.catalog_revision : undefined,\n };\n\n // Assets are taken only as a pair of absolute URLs; anything else means\n // \"load from the CDN list by version\".\n if (body.assets && isHttpUrl(body.assets.js) && isHttpUrl(body.assets.css)) {\n config.assets = { js: body.assets.js, css: body.assets.css };\n }\n\n // Half a pair is no pair: the browser would check one file and not the\n // other, and nobody would notice the unchecked one.\n if (body.integrity && isSriHash(body.integrity.js) && isSriHash(body.integrity.css)) {\n config.integrity = { js: body.integrity.js, css: body.integrity.css };\n }\n\n return config;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n","import { PONTKIT_CORE_VERSION } from \"./pontkit-core-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet core: any = null;\n\n// The load in flight, if any. This is the guard, and it is a promise rather\n// than a boolean on purpose: a flag set before the first `await` let a second\n// concurrent caller return `core` while it was still null and carry on as if\n// it were ready. A\n// promise gives every caller the same eventual answer. It is cleared on failure\n// so a later call can retry rather than inherit a latched failure.\nlet loadPromise: Promise<any> | null = null;\n\nconst PACKAGE_NAME = \"@pontive/pontkit-core\";\n\n// Base CDN templates (version will be injected)\nconst CDN_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n];\n\nconst CSS_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/styles.css`,\n];\n\n// Which release loads is decided by the PLATFORM, and failing that at BUILD\n// time — never by asking a registry at runtime. This package used to fetch jsDelivr's version list and take the\n// newest entry of any major — the `1.x` filter had been commented out — with\n// `^1` as the fallback when the fetch failed, a different major from the 2.x\n// the wrappers target. Whatever npm happened to hold newest is not a version\n// anyone tested against, and a customer's page picked it up on the next reload\n// with nothing in their build having changed.\n//\n// Now the project's auth server says which release its screens load\n// (GET /auth/v1/runtime-config, see ./runtime-config.ts), so an embedded widget\n// renders with the same bundle the hosted login pages do, and a canary or a\n// promotion reaches it without a rebuild. PONTKIT_CORE_VERSION — the exact\n// release this package was built and tested with — is the fallback when that\n// endpoint cannot be read.\nconst FALLBACK_VERSION = PONTKIT_CORE_VERSION;\n\nfunction loadCss(url: string, integrity?: string) {\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = url;\n if (integrity) {\n // SRI is only enforced on a CORS-mode fetch; the platform origin and the\n // public CDNs all answer with Access-Control-Allow-Origin: *.\n link.integrity = integrity;\n link.crossOrigin = \"anonymous\";\n }\n link.onload = () => resolve();\n link.onerror = (err) => reject(err);\n document.head.appendChild(link);\n });\n}\n\n// Loads the module through a <script type=\"module\"> carrying the integrity\n// attribute, then imports it. A dynamic import() cannot carry SRI, but the\n// script element can, and once it has fetched and verified the module the\n// browser's module map holds it under that URL — the import() that follows\n// resolves from the map without a second fetch. A hash mismatch fails the\n// script's load, the promise rejects, and the loader moves to the next\n// source, which is the right outcome: bytes the platform did not gate must not\n// run, wherever they came from.\nfunction loadVerifiedModule(url: string, integrity: string): Promise<any> {\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = \"module\";\n script.src = url;\n script.integrity = integrity;\n script.crossOrigin = \"anonymous\";\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error(`pontkit-core module at ${url} failed to load or did not match its integrity hash`));\n document.head.appendChild(script);\n }).then(\n () =>\n import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n url\n ),\n );\n}\n\nexport async function loadWebComponents(): Promise<any> {\n // No DOM means no custom elements to define and no CDN to fetch from.\n //\n // Returning rather than throwing matters because src/index.ts calls this at\n // module scope: under a server renderer the rejection surfaced as a console\n // error on every render, reporting a failure that is not one. Checked before\n // the guards below so the browser still loads normally after hydration.\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return null;\n }\n\n // Another copy of this package on the same page already finished loading.\n if (window.__pontLoaded) {\n return window.__pontCore;\n }\n\n // Another copy of this package on the same page is loading right now.\n if (window.__pontLoading) {\n return window.__pontLoading;\n }\n\n if (!loadPromise) {\n loadPromise = loadFromCdn().catch((err) => {\n loadPromise = null;\n window.__pontLoading = undefined;\n throw err;\n });\n\n window.__pontLoading = loadPromise;\n }\n\n return loadPromise;\n}\n\nasync function loadFromCdn(): Promise<any> {\n const runtime = await fetchRuntimeConfig();\n const resolvedVersion = runtime?.pontkit_version ?? FALLBACK_VERSION;\n\n const CDN_SOURCES = CDN_TEMPLATES.map((fn) => fn(resolvedVersion));\n const CSS_SOURCES = CSS_TEMPLATES.map((fn) => fn(resolvedVersion));\n\n // The platform's own asset location goes first when it names one; the public\n // CDNs stay as the fallback list for the same version.\n if (runtime?.assets) {\n CDN_SOURCES.unshift(runtime.assets.js);\n CSS_SOURCES.unshift(runtime.assets.css);\n }\n\n // The hashes describe the npm release's bytes, which every source below\n // serves verbatim, so they apply to all of them — not only to the\n // platform's. A source whose bytes differ is a source that must not run.\n const integrity = runtime?.integrity;\n\n let lastError: unknown = null;\n\n for (let i = 0; i < CDN_SOURCES.length; i++) {\n const cdn = CDN_SOURCES[i];\n const cssCdn = CSS_SOURCES[i];\n\n try {\n // The stylesheet first, so the elements never render unstyled.\n await loadCss(cssCdn, integrity?.css);\n\n // Then the module.\n //\n // All three ignore directives, and none of them is optional.\n //\n // `cdn` is a full URL resolved at runtime, so a bundler that tries to\n // resolve it statically cannot: webpack and Turbopack turn a dynamic\n // import with a variable specifier into a module-graph lookup and throw\n // `Cannot find module 'https://…'` at runtime — no network request is ever\n // made, and the message reads as though the CDN were at fault. Next.js\n // uses Turbopack in development and webpack in production, so an app\n // built with it failed on every CDN in the list identically.\n //\n // `@vite-ignore` alone covered only Vite. Each bundler reads its own\n // comment and ignores the others, so all three coexist and each one keeps\n // this a real runtime import.\n const module: any = integrity\n ? await loadVerifiedModule(cdn, integrity.js)\n : await import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n cdn\n );\n\n // The elements define themselves on import. The module is kept on the\n // window so a second copy of this package on the page (two bindings,\n // two bundles) answers from it instead of loading the bundle again.\n // There is no SDK in it: the provider element is given one by its host\n // (the React `Provider` injects @pontive/oidc-client's `Auth`).\n window.__pontCore = module;\n core = module;\n\n // Set only once the module is on the window, so a copy of this package\n // that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return core;\n } catch (err) {\n console.error(`Failed loading from ${cdn}`, err);\n lastError = err;\n }\n }\n\n console.error(\n \"❌ Failed to load PontKit web components from all CDNs.\",\n lastError,\n );\n throw lastError;\n}\n"],"names":["PONTKIT_CORE_VERSION","RUNTIME_CONFIG_PATHS","RUNTIME_CONFIG_TIMEOUT_MS","EXACT_VERSION","isExactVersion","value","isHttpUrl","isSriHash","fetchRuntimeConfig","options","fetchImpl","urls","candidateUrls","timeoutMs","url","config","readOne","controller","timer","response","body","core","loadPromise","PACKAGE_NAME","CDN_TEMPLATES","v","CSS_TEMPLATES","FALLBACK_VERSION","loadCss","integrity","resolve","reject","link","err","loadVerifiedModule","script","loadWebComponents","loadFromCdn","runtime","resolvedVersion","CDN_SOURCES","fn","CSS_SOURCES","lastError","i","cdn","cssCdn","module"],"mappings":"AAcO,MAAMA,IAA+B,UCgB/BC,IAAuB;AAAA,EAClC;AAAA,EACA;AACF,GAGaC,IAA4B,MAEnCC,IAAgB;AASf,SAASC,EAAe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AW,GAAG;AAiBpC,YAAMkB,IAAclB,IAChB,MAAMK,EAAmBW,GAAKhB,EAAU,EAAE,IAC1C,MAAM;AAAA;AAAA;AAAA;AAAA,QAIJgB;AAAA;AAQN,oBAAO,aAAaE,GACpB1B,IAAO0B,GAIP,OAAO,eAAe,IACtB,OAAO,gBAAgB,QAEvB,QAAQ;AAAA,QACN,kCAAkCR,CAAe;AAAA,QACjDM;AAAA,MAAA,GAGKxB;AAAA,IACT,SAASY,GAAK;AACZ,cAAQ,MAAM,uBAAuBY,CAAG,IAAIZ,CAAG,GAC/CU,IAAYV;AAAA,IACd;AAAA,EACF;AAEA,gBAAQ;AAAA,IACN;AAAA,IACAU;AAAA,EAAA,GAEIA;AACR;"}
1
+ {"version":3,"file":"index.js","sources":["../src/pontkit-core-version.ts","../src/runtime-config.ts","../src/load-web-components.ts"],"sourcesContent":["/**\n * The exact `@pontive/pontkit-core` release this build loads from the CDN.\n *\n * It is the version installed as a dev dependency when the package was built —\n * i.e. the one the test suite ran against — baked in by `define` in\n * vite.config.ts and vitest.config.ts (see scripts/pontkit-core-version.mjs).\n * An exact version, never a range: an exact release is immutable on the CDN,\n * cacheable forever, and the only form that admits an integrity hash.\n *\n * Nothing at runtime may replace this with \"whatever is newest\" — that is the\n * defect it exists to end. The platform's runtime-config endpoint will be\n * allowed to override it, because that answer is the one the platform has\n * gated (pontive-spec/21-element-versioning-and-compatibility.md §9).\n */\nexport const PONTKIT_CORE_VERSION: string = __PONTKIT_CORE_VERSION__;\n","// Which @pontive/pontkit-core release to load, asked of the platform.\n//\n// The platform decides which release a project's screens render with — one\n// deployment default, an optional per-project canary — and publishes the answer\n// at `GET /v1/frontend/runtime-config` on the project's auth server\n// (pontive-spec/21-element-versioning-and-compatibility.md §9). This package\n// reads it once, before importing the bundle, so an embedded widget renders\n// with the same release the hosted login pages do. The build-time stamp\n// (PONTKIT_CORE_VERSION) is the fallback when the answer cannot be read.\n//\n// The endpoint is reached through the app's own origin when the SDK's proxy is\n// mounted (`/__pontive/v1/frontend/...`), and directly on `/v1/frontend/...` when the app\n// itself runs on the auth domain. Both are tried; a host page can name a URL\n// outright with `window.__pontRuntimeConfigUrl`.\n\n/** The shape of GET /v1/frontend/runtime-config. */\nexport interface RuntimeConfig {\n pontkit_version: string;\n catalog_revision?: number;\n source?: string;\n assets?: { js: string; css: string };\n /**\n * Subresource-integrity hashes (\"sha384-…\") of the release's module and\n * stylesheet, recorded by the platform when the release was gated. When\n * present the loader passes them to the browser, which refuses bytes that\n * differ — from the platform origin or from any public CDN alike.\n */\n integrity?: { js: string; css: string };\n}\n\nexport const RUNTIME_CONFIG_PATHS = [\n \"/__pontive/v1/frontend/runtime-config\",\n \"/v1/frontend/runtime-config\",\n] as const;\n\n/** How long to wait for the platform before loading the stamped release. */\nexport const RUNTIME_CONFIG_TIMEOUT_MS = 1500;\n\nconst EXACT_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nexport interface FetchRuntimeConfigOptions {\n fetchImpl?: typeof fetch;\n urls?: readonly string[];\n timeoutMs?: number;\n}\n\n/** Whether `value` names one release rather than a range or garbage. */\nexport function isExactVersion(value: unknown): value is string {\n return typeof value === \"string\" && EXACT_VERSION.test(value);\n}\n\nfunction isHttpUrl(value: unknown): value is string {\n return typeof value === \"string\" && /^https?:\\/\\//.test(value);\n}\n\n/** Whether `value` is a well-formed SRI value the browser will accept. */\nexport function isSriHash(value: unknown): value is string {\n return typeof value === \"string\" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(value);\n}\n\n/**\n * Reads the platform's runtime config, or null when no candidate URL answers\n * with one that can be trusted. Never throws: the caller's fallback is the\n * stamped release, and a reachability problem should not become a page error.\n */\nexport async function fetchRuntimeConfig(\n options: FetchRuntimeConfigOptions = {},\n): Promise<RuntimeConfig | null> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") return null;\n\n const urls = options.urls ?? candidateUrls();\n const timeoutMs = options.timeoutMs ?? RUNTIME_CONFIG_TIMEOUT_MS;\n\n for (const url of urls) {\n const config = await readOne(fetchImpl, url, timeoutMs);\n if (config) return config;\n }\n\n return null;\n}\n\nfunction candidateUrls(): readonly string[] {\n if (typeof window !== \"undefined\" && typeof window.__pontRuntimeConfigUrl === \"string\") {\n return [window.__pontRuntimeConfigUrl];\n }\n\n return RUNTIME_CONFIG_PATHS;\n}\n\nasync function readOne(\n fetchImpl: typeof fetch,\n url: string,\n timeoutMs: number,\n): Promise<RuntimeConfig | null> {\n const controller = typeof AbortController === \"function\" ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;\n\n try {\n const response = await fetchImpl(url, {\n headers: { accept: \"application/json\" },\n signal: controller?.signal,\n });\n if (!response.ok) return null;\n\n const body = (await response.json()) as Partial<RuntimeConfig> | null;\n if (!body || !isExactVersion(body.pontkit_version)) return null;\n\n const config: RuntimeConfig = {\n pontkit_version: body.pontkit_version,\n source: typeof body.source === \"string\" ? body.source : undefined,\n catalog_revision:\n typeof body.catalog_revision === \"number\" ? body.catalog_revision : undefined,\n };\n\n // Assets are taken only as a pair of absolute URLs; anything else means\n // \"load from the CDN list by version\".\n if (body.assets && isHttpUrl(body.assets.js) && isHttpUrl(body.assets.css)) {\n config.assets = { js: body.assets.js, css: body.assets.css };\n }\n\n // Half a pair is no pair: the browser would check one file and not the\n // other, and nobody would notice the unchecked one.\n if (body.integrity && isSriHash(body.integrity.js) && isSriHash(body.integrity.css)) {\n config.integrity = { js: body.integrity.js, css: body.integrity.css };\n }\n\n return config;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n","import { PONTKIT_CORE_VERSION } from \"./pontkit-core-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet core: any = null;\n\n// The load in flight, if any. This is the guard, and it is a promise rather\n// than a boolean on purpose: a flag set before the first `await` let a second\n// concurrent caller return `core` while it was still null and carry on as if\n// it were ready. A\n// promise gives every caller the same eventual answer. It is cleared on failure\n// so a later call can retry rather than inherit a latched failure.\nlet loadPromise: Promise<any> | null = null;\n\nconst PACKAGE_NAME = \"@pontive/pontkit-core\";\n\n// Base CDN templates (version will be injected)\nconst CDN_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/index.mjs`,\n];\n\nconst CSS_TEMPLATES = [\n (v: string) =>\n `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://unpkg.com/${PACKAGE_NAME}@${v}/dist/styles.css`,\n (v: string) => `https://esm.sh/${PACKAGE_NAME}@${v}/dist/styles.css`,\n];\n\n// Which release loads is decided by the PLATFORM, and failing that at BUILD\n// time — never by asking a registry at runtime. This package used to fetch jsDelivr's version list and take the\n// newest entry of any major — the `1.x` filter had been commented out — with\n// `^1` as the fallback when the fetch failed, a different major from the 2.x\n// the wrappers target. Whatever npm happened to hold newest is not a version\n// anyone tested against, and a customer's page picked it up on the next reload\n// with nothing in their build having changed.\n//\n// Now the project's auth server says which release its screens load\n// (GET /v1/frontend/runtime-config, see ./runtime-config.ts), so an embedded widget\n// renders with the same bundle the hosted login pages do, and a canary or a\n// promotion reaches it without a rebuild. PONTKIT_CORE_VERSION — the exact\n// release this package was built and tested with — is the fallback when that\n// endpoint cannot be read.\nconst FALLBACK_VERSION = PONTKIT_CORE_VERSION;\n\nfunction loadCss(url: string, integrity?: string) {\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = url;\n if (integrity) {\n // SRI is only enforced on a CORS-mode fetch; the platform origin and the\n // public CDNs all answer with Access-Control-Allow-Origin: *.\n link.integrity = integrity;\n link.crossOrigin = \"anonymous\";\n }\n link.onload = () => resolve();\n link.onerror = (err) => reject(err);\n document.head.appendChild(link);\n });\n}\n\n// Loads the module through a <script type=\"module\"> carrying the integrity\n// attribute, then imports it. A dynamic import() cannot carry SRI, but the\n// script element can, and once it has fetched and verified the module the\n// browser's module map holds it under that URL — the import() that follows\n// resolves from the map without a second fetch. A hash mismatch fails the\n// script's load, the promise rejects, and the loader moves to the next\n// source, which is the right outcome: bytes the platform did not gate must not\n// run, wherever they came from.\nfunction loadVerifiedModule(url: string, integrity: string): Promise<any> {\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = \"module\";\n script.src = url;\n script.integrity = integrity;\n script.crossOrigin = \"anonymous\";\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error(`pontkit-core module at ${url} failed to load or did not match its integrity hash`));\n document.head.appendChild(script);\n }).then(\n () =>\n import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n url\n ),\n );\n}\n\nexport async function loadWebComponents(): Promise<any> {\n // No DOM means no custom elements to define and no CDN to fetch from.\n //\n // Returning rather than throwing matters because src/index.ts calls this at\n // module scope: under a server renderer the rejection surfaced as a console\n // error on every render, reporting a failure that is not one. Checked before\n // the guards below so the browser still loads normally after hydration.\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return null;\n }\n\n // Another copy of this package on the same page already finished loading.\n if (window.__pontLoaded) {\n return window.__pontCore;\n }\n\n // Another copy of this package on the same page is loading right now.\n if (window.__pontLoading) {\n return window.__pontLoading;\n }\n\n if (!loadPromise) {\n loadPromise = loadFromCdn().catch((err) => {\n loadPromise = null;\n window.__pontLoading = undefined;\n throw err;\n });\n\n window.__pontLoading = loadPromise;\n }\n\n return loadPromise;\n}\n\nasync function loadFromCdn(): Promise<any> {\n const runtime = await fetchRuntimeConfig();\n const resolvedVersion = runtime?.pontkit_version ?? FALLBACK_VERSION;\n\n const CDN_SOURCES = CDN_TEMPLATES.map((fn) => fn(resolvedVersion));\n const CSS_SOURCES = CSS_TEMPLATES.map((fn) => fn(resolvedVersion));\n\n // The platform's own asset location goes first when it names one; the public\n // CDNs stay as the fallback list for the same version.\n if (runtime?.assets) {\n CDN_SOURCES.unshift(runtime.assets.js);\n CSS_SOURCES.unshift(runtime.assets.css);\n }\n\n // The hashes describe the npm release's bytes, which every source below\n // serves verbatim, so they apply to all of them — not only to the\n // platform's. A source whose bytes differ is a source that must not run.\n const integrity = runtime?.integrity;\n\n let lastError: unknown = null;\n\n for (let i = 0; i < CDN_SOURCES.length; i++) {\n const cdn = CDN_SOURCES[i];\n const cssCdn = CSS_SOURCES[i];\n\n try {\n // The stylesheet first, so the elements never render unstyled.\n await loadCss(cssCdn, integrity?.css);\n\n // Then the module.\n //\n // All three ignore directives, and none of them is optional.\n //\n // `cdn` is a full URL resolved at runtime, so a bundler that tries to\n // resolve it statically cannot: webpack and Turbopack turn a dynamic\n // import with a variable specifier into a module-graph lookup and throw\n // `Cannot find module 'https://…'` at runtime — no network request is ever\n // made, and the message reads as though the CDN were at fault. Next.js\n // uses Turbopack in development and webpack in production, so an app\n // built with it failed on every CDN in the list identically.\n //\n // `@vite-ignore` alone covered only Vite. Each bundler reads its own\n // comment and ignores the others, so all three coexist and each one keeps\n // this a real runtime import.\n const module: any = integrity\n ? await loadVerifiedModule(cdn, integrity.js)\n : await import(\n /* webpackIgnore: true */\n /* turbopackIgnore: true */\n /* @vite-ignore */\n cdn\n );\n\n // The elements define themselves on import. The module is kept on the\n // window so a second copy of this package on the page (two bindings,\n // two bundles) answers from it instead of loading the bundle again.\n // There is no SDK in it: the provider element is given one by its host\n // (the React `Provider` injects @pontive/oidc-client's `Auth`).\n window.__pontCore = module;\n core = module;\n\n // Set only once the module is on the window, so a copy of this package\n // that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return core;\n } catch (err) {\n console.error(`Failed loading from ${cdn}`, err);\n lastError = err;\n }\n }\n\n console.error(\n \"❌ Failed to load PontKit web components from all CDNs.\",\n lastError,\n );\n throw lastError;\n}\n"],"names":["PONTKIT_CORE_VERSION","RUNTIME_CONFIG_PATHS","RUNTIME_CONFIG_TIMEOUT_MS","EXACT_VERSION","isExactVersion","value","isHttpUrl","isSriHash","fetchRuntimeConfig","options","fetchImpl","urls","candidateUrls","timeoutMs","url","config","readOne","controller","timer","response","body","core","loadPromise","PACKAGE_NAME","CDN_TEMPLATES","v","CSS_TEMPLATES","FALLBACK_VERSION","loadCss","integrity","resolve","reject","link","err","loadVerifiedModule","script","loadWebComponents","loadFromCdn","runtime","resolvedVersion","CDN_SOURCES","fn","CSS_SOURCES","lastError","i","cdn","cssCdn","module"],"mappings":"AAcO,MAAMA,IAA+B,UCgB/BC,IAAuB;AAAA,EAClC;AAAA,EACA;AACF,GAGaC,IAA4B,MAEnCC,IAAgB;AASf,SAASC,EAAeC,GAAiC;AAC9D,SAAO,OAAOA,KAAU,YAAYF,EAAc,KAAKE,CAAK;AAC9D;AAEA,SAASC,EAAUD,GAAiC;AAClD,SAAO,OAAOA,KAAU,YAAY,eAAe,KAAKA,CAAK;AAC/D;AAGO,SAASE,EAAUF,GAAiC;AACzD,SAAO,OAAOA,KAAU,YAAY,sCAAsC,KAAKA,CAAK;AACtF;AAOA,eAAsBG,EACpBC,IAAqC,IACN;AAC/B,QAAMC,IAAYD,EAAQ,aAAa,WAAW;AAClD,MAAI,OAAOC,KAAc,WAAY,QAAO;AAE5C,QAAMC,IAAOF,EAAQ,QAAQG,EAAA,GACvBC,IAAYJ,EAAQ,aAAa;AAEvC,aAAWK,KAAOH,GAAM;AACtB,UAAMI,IAAS,MAAMC,EAAQN,GAAWI,GAAKD,CAAS;AACtD,QAAIE,EAAQ,QAAOA;AAAA,EACrB;AAEA,SAAO;AACT;AAEA,SAASH,IAAmC;AAC1C,SAAI,OAAO,SAAW,OAAe,OAAO,OAAO,0BAA2B,WACrE,CAAC,OAAO,sBAAsB,IAGhCX;AACT;AAEA,eAAee,EACbN,GACAI,GAC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X,IAGlBA;AACT;AAEA,eAAee,IAA4B;AACzC,QAAMC,IAAU,MAAM9B,EAAA,GAChB+B,IAAkBD,GAAS,mBAAmBX,GAE9Ca,IAAchB,EAAc,IAAI,CAACiB,MAAOA,EAAGF,CAAe,CAAC,GAC3DG,IAAchB,EAAc,IAAI,CAACe,MAAOA,EAAGF,CAAe,CAAC;AAIjE,EAAID,GAAS,WACXE,EAAY,QAAQF,EAAQ,OAAO,EAAE,GACrCI,EAAY,QAAQJ,EAAQ,OAAO,GAAG;AAMxC,QAAMT,IAAYS,GAAS;AAE3B,MAAIK,IAAqB;AAEzB,WAASC,IAAI,GAAGA,IAAIJ,EAAY,QAAQI,KAAK;AAC3C,UAAMC,IAAML,EAAYI,CAAC,GACnBE,IAASJ,EAAYE,CAAC;AAE5B,QAAI;AAEF,YAAMhB,EAAQkB,GAAQjB,GAAW,GAAG;AAiBpC,YAAMkB,IAAclB,IAChB,MAAMK,EAAmBW,GAAKhB,EAAU,EAAE,IAC1C,MAAM;AAAA;AAAA;AAAA;AAAA,QAIJgB;AAAA;AAQN,oBAAO,aAAaE,GACpB1B,IAAO0B,GAIP,OAAO,eAAe,IACtB,OAAO,gBAAgB,QAEvB,QAAQ;AAAA,QACN,kCAAkCR,CAAe;AAAA,QACjDM;AAAA,MAAA,GAGKxB;AAAA,IACT,SAASY,GAAK;AACZ,cAAQ,MAAM,uBAAuBY,CAAG,IAAIZ,CAAG,GAC/CU,IAAYV;AAAA,IACd;AAAA,EACF;AAEA,gBAAQ;AAAA,IACN;AAAA,IACAU;AAAA,EAAA,GAEIA;AACR;"}
@@ -12,8 +12,10 @@
12
12
  * The endpoints an app-level proxy has to carry, and the reason the list is
13
13
  * short.
14
14
  *
15
- * These are the requests the browser makes with `fetch` — the auth flow, the
16
- * token endpoint, userinfo, logout, branding CSS. They are the ones that need
15
+ * These are the requests the browser makes with `fetch` — pontkit's frontend
16
+ * API (`/v1/frontend`: the auth flow, runtime config, widget messages, the
17
+ * theme), the signed-in user's own surface (`/v1/me`: profile, sessions,
18
+ * memberships, billing), and the token endpoint, userinfo and logout. They are the ones that need
17
19
  * to be same-origin, because they are the ones carrying cookies under
18
20
  * `SameSite=Lax`.
19
21
  *
@@ -24,13 +26,13 @@
24
26
  * URLs absolute, on its own hostname, so the browser leaves the proxy at the
25
27
  * first redirect anyway.
26
28
  *
27
- * The two prefixes are the same pair the dev-server proxy uses (auth-api,
29
+ * The prefixes are the same the dev-server proxy uses (auth-api,
28
30
  * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be
29
31
  * tidied away: local development against a shared sandbox domain is the same
30
32
  * cross-site problem this solves in production, and the two configurations
31
33
  * being identical is what makes the local one a rehearsal.
32
34
  */
33
- export declare const DEFAULT_FORWARDED_PATHS: readonly ["/auth/v1", "/oauth2"];
35
+ export declare const DEFAULT_FORWARDED_PATHS: readonly ["/v1/frontend", "/v1/me", "/oauth2"];
34
36
  /**
35
37
  * Where the endpoints hang off the app's own origin.
36
38
  *
@@ -57,7 +59,7 @@ export declare function authOrigin(authHost: string): string;
57
59
  * unambiguous.
58
60
  *
59
61
  * `"/"` normalises to `""`, which mounts the endpoints at the origin root —
60
- * `/auth/v1/...` and `/oauth2/...` where the app itself is served. That is the
62
+ * `/v1/frontend/...`, `/v1/me/...` and `/oauth2/...` where the app itself is served. That is the
61
63
  * shape a Vite dev server has always used, and it stays available because in
62
64
  * development the app owns the whole origin and there is nothing to collide
63
65
  * with. A deployed app usually does not, which is what the prefix is for.
package/dist/proxy.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=["/auth/v1","/oauth2"],a="/__pontive";function h(r){const t=(r??"").trim();if(!t)throw new TypeError("authHost is required");const o=/^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/i.test(t.replace(/^https?:\/\//i,"").split("/")[0]),s=/^https?:\/\//i.test(t)?"":`${o?"http":"https"}://`;let e;try{e=new URL(`${s}${t}`)}catch{throw new TypeError(`authHost "${t}" is not a hostname or an origin`)}if(e.pathname!=="/"||e.search||e.hash)throw new TypeError(`authHost "${t}" must be a bare origin — the path comes from the request being proxied`);if(e.protocol!=="https:"&&!o)throw new TypeError(`authHost "${t}" must be https outside loopback`);return e.origin}function u(r){const t=(r??"").trim().replace(/\/+$/,"");if(t==="")return"";if(!t.startsWith("/"))throw new TypeError(`basePath "${r}" must start with "/"`);return t}function p(r,t){return r===t||r.startsWith(`${t}/`)}function l(r){const t=h(r.authHost),o=u(r.basePath??a),s=r.paths??n,e={};for(const c of s)e[`${o}${c}`]={target:t,changeOrigin:!0,rewrite:i=>o?i.replace(o,""):i};return e}exports.DEFAULT_BASE_PATH=a;exports.DEFAULT_FORWARDED_PATHS=n;exports.authOrigin=h;exports.isUnder=p;exports.normaliseBasePath=u;exports.viteAuthProxy=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=["/v1/frontend","/v1/me","/oauth2"],a="/__pontive";function h(r){const t=(r??"").trim();if(!t)throw new TypeError("authHost is required");const o=/^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/i.test(t.replace(/^https?:\/\//i,"").split("/")[0]),s=/^https?:\/\//i.test(t)?"":`${o?"http":"https"}://`;let e;try{e=new URL(`${s}${t}`)}catch{throw new TypeError(`authHost "${t}" is not a hostname or an origin`)}if(e.pathname!=="/"||e.search||e.hash)throw new TypeError(`authHost "${t}" must be a bare origin — the path comes from the request being proxied`);if(e.protocol!=="https:"&&!o)throw new TypeError(`authHost "${t}" must be https outside loopback`);return e.origin}function c(r){const t=(r??"").trim().replace(/\/+$/,"");if(t==="")return"";if(!t.startsWith("/"))throw new TypeError(`basePath "${r}" must start with "/"`);return t}function p(r,t){return r===t||r.startsWith(`${t}/`)}function l(r){const t=h(r.authHost),o=c(r.basePath??a),s=r.paths??i,e={};for(const u of s)e[`${o}${u}`]={target:t,changeOrigin:!0,rewrite:n=>o?n.replace(o,""):n};return e}exports.DEFAULT_BASE_PATH=a;exports.DEFAULT_FORWARDED_PATHS=i;exports.authOrigin=h;exports.isUnder=p;exports.normaliseBasePath=c;exports.viteAuthProxy=l;
2
2
  //# sourceMappingURL=proxy.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.cjs","sources":["../src/proxy/target.ts","../src/proxy/vite.ts"],"sourcesContent":["/**\n * Where a proxied request is sent, and which requests are sent at all.\n *\n * Deliberately not shared with `resolveAuthBaseUrl` in the SDK, which answers a\n * different question. That one resolves what the BROWSER should call and its\n * most useful answer — a bare path like `/__pontive` — is meaningless here: a\n * proxy runs on a server, where there is no page origin for a path to be\n * relative to. Sharing them would mean one function with a mode flag, and the\n * mode that is wrong in either direction is silent.\n */\n\n/**\n * The endpoints an app-level proxy has to carry, and the reason the list is\n * short.\n *\n * These are the requests the browser makes with `fetch` — the auth flow, the\n * token endpoint, userinfo, logout, branding CSS. They are the ones that need\n * to be same-origin, because they are the ones carrying cookies under\n * `SameSite=Lax`.\n *\n * Everything else on the auth server is a top-level navigation — `/authorize`,\n * the hosted sign-in page, `/logout` as a redirect — and a `Lax` cookie is\n * sent on those already, whatever origin they are served from. Proxying them\n * would not help, and it would break: the authorization server builds those\n * URLs absolute, on its own hostname, so the browser leaves the proxy at the\n * first redirect anyway.\n *\n * The two prefixes are the same pair the dev-server proxy uses (auth-api,\n * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be\n * tidied away: local development against a shared sandbox domain is the same\n * cross-site problem this solves in production, and the two configurations\n * being identical is what makes the local one a rehearsal.\n */\nexport const DEFAULT_FORWARDED_PATHS = [\"/auth/v1\", \"/oauth2\"] as const;\n\n/**\n * Where the endpoints hang off the app's own origin.\n *\n * `__`-prefixed by convention — Clerk uses `/__clerk`, Firebase `/__/auth` —\n * because it has to be a path no real route of the app will ever want.\n */\nexport const DEFAULT_BASE_PATH = \"/__pontive\";\n\n/**\n * The auth server, as an origin.\n *\n * Accepts `tenant.idp.us.pontive.app` or `https://tenant.idp.us.pontive.app`,\n * and nothing with a path: the upstream path comes from the incoming request,\n * and a base path here would be silently prepended to endpoints the auth server\n * does not serve.\n *\n * `http://` is inferred for loopback only, and accepted only there. A proxy is\n * the one hop a refresh token cannot be carried over in the clear — it is the\n * hop that exists precisely so the cookie is first-party — and the failure is\n * invisible from the browser, which sees its own `https://` origin either way.\n */\nexport function authOrigin(authHost: string): string {\n const configured = (authHost ?? \"\").trim();\n\n if (!configured) {\n throw new TypeError(\"authHost is required\");\n }\n\n const loopback = /^(localhost|127\\.0\\.0\\.1|\\[::1\\])(:\\d+)?$/i.test(\n configured.replace(/^https?:\\/\\//i, \"\").split(\"/\")[0],\n );\n\n const scheme = /^https?:\\/\\//i.test(configured) ? \"\" : `${loopback ? \"http\" : \"https\"}://`;\n\n let url: URL;\n try {\n url = new URL(`${scheme}${configured}`);\n } catch {\n throw new TypeError(`authHost \"${configured}\" is not a hostname or an origin`);\n }\n\n if (url.pathname !== \"/\" || url.search || url.hash) {\n throw new TypeError(\n `authHost \"${configured}\" must be a bare origin — the path comes from the request being proxied`,\n );\n }\n\n if (url.protocol !== \"https:\" && !loopback) {\n throw new TypeError(`authHost \"${configured}\" must be https outside loopback`);\n }\n\n return url.origin;\n}\n\n/**\n * A base path with a leading slash and no trailing one, so joining is\n * unambiguous.\n *\n * `\"/\"` normalises to `\"\"`, which mounts the endpoints at the origin root —\n * `/auth/v1/...` and `/oauth2/...` where the app itself is served. That is the\n * shape a Vite dev server has always used, and it stays available because in\n * development the app owns the whole origin and there is nothing to collide\n * with. A deployed app usually does not, which is what the prefix is for.\n */\nexport function normaliseBasePath(basePath: string): string {\n const trimmed = (basePath ?? \"\").trim().replace(/\\/+$/, \"\");\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n if (!trimmed.startsWith(\"/\")) {\n throw new TypeError(`basePath \"${basePath}\" must start with \"/\"`);\n }\n\n return trimmed;\n}\n\n/** Whether `pathname` is `prefix` itself or something under it. */\nexport function isUnder(pathname: string, prefix: string): boolean {\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","import {\n DEFAULT_BASE_PATH,\n DEFAULT_FORWARDED_PATHS,\n authOrigin,\n normaliseBasePath,\n} from \"./target\";\n\n/**\n * The shape of one entry in Vite's `server.proxy`.\n *\n * Declared here rather than imported from Vite so that nothing which imports\n * this module needs Vite installed, and so the published types do not depend on\n * a particular version of it. It is structural: Vite accepts this object.\n */\nexport interface ViteProxyEntry {\n target: string;\n changeOrigin: boolean;\n rewrite: (path: string) => string;\n}\n\nexport interface ViteAuthProxyOptions {\n authHost: string;\n basePath?: string;\n paths?: readonly string[];\n}\n\n/**\n * The auth endpoints, proxied through a Vite dev server.\n *\n * ```ts\n * // vite.config.ts\n * server: { proxy: viteAuthProxy({ authHost: env.VITE_SB_AUTH_DOMAIN }) }\n * ```\n *\n * Vite already has a proxy; what it does not have is the knowledge of which\n * paths to carry and what to do with Host, and both of those are easy to get\n * wrong in ways that fail silently. So this is a config generator rather than a\n * request handler — `createAuthProxy` is for runtimes that have no proxy of\n * their own.\n *\n * Worth doing even where the browser would tolerate the cross-site setup,\n * because it is the same topology production runs on: a dev server that proxies\n * is rehearsing the deployment, and a dev server that does not is testing a\n * configuration no user will ever have. It is also the only way an embedded\n * sign-in flow works in Safari, which blocks third-party cookies outright.\n */\nexport function viteAuthProxy(\n options: ViteAuthProxyOptions,\n): Record<string, ViteProxyEntry> {\n const target = authOrigin(options.authHost);\n const basePath = normaliseBasePath(options.basePath ?? DEFAULT_BASE_PATH);\n const paths = options.paths ?? DEFAULT_FORWARDED_PATHS;\n\n const proxy: Record<string, ViteProxyEntry> = {};\n\n for (const prefix of paths) {\n proxy[`${basePath}${prefix}`] = {\n target,\n // The single most important line, and the one a hand-written config\n // leaves out. Without it the auth server is asked to answer as\n // `localhost:5173` — a Host it has no project for — and the reply is a\n // CORS refusal and an empty issuer rather than anything that says so.\n changeOrigin: true,\n // Only the base path comes off. The prefix below it is the path the auth\n // server actually serves.\n rewrite: (path: string) => (basePath ? path.replace(basePath, \"\") : path),\n };\n }\n\n return proxy;\n}\n"],"names":["DEFAULT_FORWARDED_PATHS","DEFAULT_BASE_PATH","authOrigin","authHost","configured","loopback","scheme","url","normaliseBasePath","basePath","trimmed","isUnder","pathname","prefix","viteAuthProxy","options","target","paths","proxy","path"],"mappings":"gFAiCO,MAAMA,EAA0B,CAAC,WAAY,SAAS,EAQhDC,EAAoB,aAe1B,SAASC,EAAWC,EAA0B,CACnD,MAAMC,GAAcD,GAAY,IAAI,KAAA,EAEpC,GAAI,CAACC,EACH,MAAM,IAAI,UAAU,sBAAsB,EAG5C,MAAMC,EAAW,6CAA6C,KAC5DD,EAAW,QAAQ,gBAAiB,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC,CAAA,EAGhDE,EAAS,gBAAgB,KAAKF,CAAU,EAAI,GAAK,GAAGC,EAAW,OAAS,OAAO,MAErF,IAAIE,EACJ,GAAI,CACFA,EAAM,IAAI,IAAI,GAAGD,CAAM,GAAGF,CAAU,EAAE,CACxC,MAAQ,CACN,MAAM,IAAI,UAAU,aAAaA,CAAU,kCAAkC,CAC/E,CAEA,GAAIG,EAAI,WAAa,KAAOA,EAAI,QAAUA,EAAI,KAC5C,MAAM,IAAI,UACR,aAAaH,CAAU,yEAAA,EAI3B,GAAIG,EAAI,WAAa,UAAY,CAACF,EAChC,MAAM,IAAI,UAAU,aAAaD,CAAU,kCAAkC,EAG/E,OAAOG,EAAI,MACb,CAYO,SAASC,EAAkBC,EAA0B,CAC1D,MAAMC,GAAWD,GAAY,IAAI,OAAO,QAAQ,OAAQ,EAAE,EAE1D,GAAIC,IAAY,GACd,MAAO,GAGT,GAAI,CAACA,EAAQ,WAAW,GAAG,EACzB,MAAM,IAAI,UAAU,aAAaD,CAAQ,uBAAuB,EAGlE,OAAOC,CACT,CAGO,SAASC,EAAQC,EAAkBC,EAAyB,CACjE,OAAOD,IAAaC,GAAUD,EAAS,WAAW,GAAGC,CAAM,GAAG,CAChE,CCtEO,SAASC,EACdC,EACgC,CAChC,MAAMC,EAASd,EAAWa,EAAQ,QAAQ,EACpCN,EAAWD,EAAkBO,EAAQ,UAAYd,CAAiB,EAClEgB,EAAQF,EAAQ,OAASf,EAEzBkB,EAAwC,CAAA,EAE9C,UAAWL,KAAUI,EACnBC,EAAM,GAAGT,CAAQ,GAAGI,CAAM,EAAE,EAAI,CAC9B,OAAAG,EAKA,aAAc,GAGd,QAAUG,GAAkBV,EAAWU,EAAK,QAAQV,EAAU,EAAE,EAAIU,CAAA,EAIxE,OAAOD,CACT"}
1
+ {"version":3,"file":"proxy.cjs","sources":["../src/proxy/target.ts","../src/proxy/vite.ts"],"sourcesContent":["/**\n * Where a proxied request is sent, and which requests are sent at all.\n *\n * Deliberately not shared with `resolveAuthBaseUrl` in the SDK, which answers a\n * different question. That one resolves what the BROWSER should call and its\n * most useful answer — a bare path like `/__pontive` — is meaningless here: a\n * proxy runs on a server, where there is no page origin for a path to be\n * relative to. Sharing them would mean one function with a mode flag, and the\n * mode that is wrong in either direction is silent.\n */\n\n/**\n * The endpoints an app-level proxy has to carry, and the reason the list is\n * short.\n *\n * These are the requests the browser makes with `fetch` — pontkit's frontend\n * API (`/v1/frontend`: the auth flow, runtime config, widget messages, the\n * theme), the signed-in user's own surface (`/v1/me`: profile, sessions,\n * memberships, billing), and the token endpoint, userinfo and logout. They are the ones that need\n * to be same-origin, because they are the ones carrying cookies under\n * `SameSite=Lax`.\n *\n * Everything else on the auth server is a top-level navigation — `/authorize`,\n * the hosted sign-in page, `/logout` as a redirect — and a `Lax` cookie is\n * sent on those already, whatever origin they are served from. Proxying them\n * would not help, and it would break: the authorization server builds those\n * URLs absolute, on its own hostname, so the browser leaves the proxy at the\n * first redirect anyway.\n *\n * The prefixes are the same the dev-server proxy uses (auth-api,\n * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be\n * tidied away: local development against a shared sandbox domain is the same\n * cross-site problem this solves in production, and the two configurations\n * being identical is what makes the local one a rehearsal.\n */\nexport const DEFAULT_FORWARDED_PATHS = [\"/v1/frontend\", \"/v1/me\", \"/oauth2\"] as const;\n\n/**\n * Where the endpoints hang off the app's own origin.\n *\n * `__`-prefixed by convention — Clerk uses `/__clerk`, Firebase `/__/auth` —\n * because it has to be a path no real route of the app will ever want.\n */\nexport const DEFAULT_BASE_PATH = \"/__pontive\";\n\n/**\n * The auth server, as an origin.\n *\n * Accepts `tenant.idp.us.pontive.app` or `https://tenant.idp.us.pontive.app`,\n * and nothing with a path: the upstream path comes from the incoming request,\n * and a base path here would be silently prepended to endpoints the auth server\n * does not serve.\n *\n * `http://` is inferred for loopback only, and accepted only there. A proxy is\n * the one hop a refresh token cannot be carried over in the clear — it is the\n * hop that exists precisely so the cookie is first-party — and the failure is\n * invisible from the browser, which sees its own `https://` origin either way.\n */\nexport function authOrigin(authHost: string): string {\n const configured = (authHost ?? \"\").trim();\n\n if (!configured) {\n throw new TypeError(\"authHost is required\");\n }\n\n const loopback = /^(localhost|127\\.0\\.0\\.1|\\[::1\\])(:\\d+)?$/i.test(\n configured.replace(/^https?:\\/\\//i, \"\").split(\"/\")[0],\n );\n\n const scheme = /^https?:\\/\\//i.test(configured) ? \"\" : `${loopback ? \"http\" : \"https\"}://`;\n\n let url: URL;\n try {\n url = new URL(`${scheme}${configured}`);\n } catch {\n throw new TypeError(`authHost \"${configured}\" is not a hostname or an origin`);\n }\n\n if (url.pathname !== \"/\" || url.search || url.hash) {\n throw new TypeError(\n `authHost \"${configured}\" must be a bare origin — the path comes from the request being proxied`,\n );\n }\n\n if (url.protocol !== \"https:\" && !loopback) {\n throw new TypeError(`authHost \"${configured}\" must be https outside loopback`);\n }\n\n return url.origin;\n}\n\n/**\n * A base path with a leading slash and no trailing one, so joining is\n * unambiguous.\n *\n * `\"/\"` normalises to `\"\"`, which mounts the endpoints at the origin root —\n * `/v1/frontend/...`, `/v1/me/...` and `/oauth2/...` where the app itself is served. That is the\n * shape a Vite dev server has always used, and it stays available because in\n * development the app owns the whole origin and there is nothing to collide\n * with. A deployed app usually does not, which is what the prefix is for.\n */\nexport function normaliseBasePath(basePath: string): string {\n const trimmed = (basePath ?? \"\").trim().replace(/\\/+$/, \"\");\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n if (!trimmed.startsWith(\"/\")) {\n throw new TypeError(`basePath \"${basePath}\" must start with \"/\"`);\n }\n\n return trimmed;\n}\n\n/** Whether `pathname` is `prefix` itself or something under it. */\nexport function isUnder(pathname: string, prefix: string): boolean {\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","import {\n DEFAULT_BASE_PATH,\n DEFAULT_FORWARDED_PATHS,\n authOrigin,\n normaliseBasePath,\n} from \"./target\";\n\n/**\n * The shape of one entry in Vite's `server.proxy`.\n *\n * Declared here rather than imported from Vite so that nothing which imports\n * this module needs Vite installed, and so the published types do not depend on\n * a particular version of it. It is structural: Vite accepts this object.\n */\nexport interface ViteProxyEntry {\n target: string;\n changeOrigin: boolean;\n rewrite: (path: string) => string;\n}\n\nexport interface ViteAuthProxyOptions {\n authHost: string;\n basePath?: string;\n paths?: readonly string[];\n}\n\n/**\n * The auth endpoints, proxied through a Vite dev server.\n *\n * ```ts\n * // vite.config.ts\n * server: { proxy: viteAuthProxy({ authHost: env.VITE_SB_AUTH_DOMAIN }) }\n * ```\n *\n * Vite already has a proxy; what it does not have is the knowledge of which\n * paths to carry and what to do with Host, and both of those are easy to get\n * wrong in ways that fail silently. So this is a config generator rather than a\n * request handler — `createAuthProxy` is for runtimes that have no proxy of\n * their own.\n *\n * Worth doing even where the browser would tolerate the cross-site setup,\n * because it is the same topology production runs on: a dev server that proxies\n * is rehearsing the deployment, and a dev server that does not is testing a\n * configuration no user will ever have. It is also the only way an embedded\n * sign-in flow works in Safari, which blocks third-party cookies outright.\n */\nexport function viteAuthProxy(\n options: ViteAuthProxyOptions,\n): Record<string, ViteProxyEntry> {\n const target = authOrigin(options.authHost);\n const basePath = normaliseBasePath(options.basePath ?? DEFAULT_BASE_PATH);\n const paths = options.paths ?? DEFAULT_FORWARDED_PATHS;\n\n const proxy: Record<string, ViteProxyEntry> = {};\n\n for (const prefix of paths) {\n proxy[`${basePath}${prefix}`] = {\n target,\n // The single most important line, and the one a hand-written config\n // leaves out. Without it the auth server is asked to answer as\n // `localhost:5173` — a Host it has no project for — and the reply is a\n // CORS refusal and an empty issuer rather than anything that says so.\n changeOrigin: true,\n // Only the base path comes off. The prefix below it is the path the auth\n // server actually serves.\n rewrite: (path: string) => (basePath ? path.replace(basePath, \"\") : path),\n };\n }\n\n return proxy;\n}\n"],"names":["DEFAULT_FORWARDED_PATHS","DEFAULT_BASE_PATH","authOrigin","authHost","configured","loopback","scheme","url","normaliseBasePath","basePath","trimmed","isUnder","pathname","prefix","viteAuthProxy","options","target","paths","proxy","path"],"mappings":"gFAmCO,MAAMA,EAA0B,CAAC,eAAgB,SAAU,SAAS,EAQ9DC,EAAoB,aAe1B,SAASC,EAAWC,EAA0B,CACnD,MAAMC,GAAcD,GAAY,IAAI,KAAA,EAEpC,GAAI,CAACC,EACH,MAAM,IAAI,UAAU,sBAAsB,EAG5C,MAAMC,EAAW,6CAA6C,KAC5DD,EAAW,QAAQ,gBAAiB,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC,CAAA,EAGhDE,EAAS,gBAAgB,KAAKF,CAAU,EAAI,GAAK,GAAGC,EAAW,OAAS,OAAO,MAErF,IAAIE,EACJ,GAAI,CACFA,EAAM,IAAI,IAAI,GAAGD,CAAM,GAAGF,CAAU,EAAE,CACxC,MAAQ,CACN,MAAM,IAAI,UAAU,aAAaA,CAAU,kCAAkC,CAC/E,CAEA,GAAIG,EAAI,WAAa,KAAOA,EAAI,QAAUA,EAAI,KAC5C,MAAM,IAAI,UACR,aAAaH,CAAU,yEAAA,EAI3B,GAAIG,EAAI,WAAa,UAAY,CAACF,EAChC,MAAM,IAAI,UAAU,aAAaD,CAAU,kCAAkC,EAG/E,OAAOG,EAAI,MACb,CAYO,SAASC,EAAkBC,EAA0B,CAC1D,MAAMC,GAAWD,GAAY,IAAI,OAAO,QAAQ,OAAQ,EAAE,EAE1D,GAAIC,IAAY,GACd,MAAO,GAGT,GAAI,CAACA,EAAQ,WAAW,GAAG,EACzB,MAAM,IAAI,UAAU,aAAaD,CAAQ,uBAAuB,EAGlE,OAAOC,CACT,CAGO,SAASC,EAAQC,EAAkBC,EAAyB,CACjE,OAAOD,IAAaC,GAAUD,EAAS,WAAW,GAAGC,CAAM,GAAG,CAChE,CCxEO,SAASC,EACdC,EACgC,CAChC,MAAMC,EAASd,EAAWa,EAAQ,QAAQ,EACpCN,EAAWD,EAAkBO,EAAQ,UAAYd,CAAiB,EAClEgB,EAAQF,EAAQ,OAASf,EAEzBkB,EAAwC,CAAA,EAE9C,UAAWL,KAAUI,EACnBC,EAAM,GAAGT,CAAQ,GAAGI,CAAM,EAAE,EAAI,CAC9B,OAAAG,EAKA,aAAc,GAGd,QAAUG,GAAkBV,EAAWU,EAAK,QAAQV,EAAU,EAAE,EAAIU,CAAA,EAIxE,OAAOD,CACT"}
package/dist/proxy.js CHANGED
@@ -1,4 +1,4 @@
1
- const h = ["/auth/v1", "/oauth2"], a = "/__pontive";
1
+ const h = ["/v1/frontend", "/v1/me", "/oauth2"], a = "/__pontive";
2
2
  function c(r) {
3
3
  const t = (r ?? "").trim();
4
4
  if (!t)
package/dist/proxy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sources":["../src/proxy/target.ts","../src/proxy/vite.ts"],"sourcesContent":["/**\n * Where a proxied request is sent, and which requests are sent at all.\n *\n * Deliberately not shared with `resolveAuthBaseUrl` in the SDK, which answers a\n * different question. That one resolves what the BROWSER should call and its\n * most useful answer — a bare path like `/__pontive` — is meaningless here: a\n * proxy runs on a server, where there is no page origin for a path to be\n * relative to. Sharing them would mean one function with a mode flag, and the\n * mode that is wrong in either direction is silent.\n */\n\n/**\n * The endpoints an app-level proxy has to carry, and the reason the list is\n * short.\n *\n * These are the requests the browser makes with `fetch` — the auth flow, the\n * token endpoint, userinfo, logout, branding CSS. They are the ones that need\n * to be same-origin, because they are the ones carrying cookies under\n * `SameSite=Lax`.\n *\n * Everything else on the auth server is a top-level navigation — `/authorize`,\n * the hosted sign-in page, `/logout` as a redirect — and a `Lax` cookie is\n * sent on those already, whatever origin they are served from. Proxying them\n * would not help, and it would break: the authorization server builds those\n * URLs absolute, on its own hostname, so the browser leaves the proxy at the\n * first redirect anyway.\n *\n * The two prefixes are the same pair the dev-server proxy uses (auth-api,\n * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be\n * tidied away: local development against a shared sandbox domain is the same\n * cross-site problem this solves in production, and the two configurations\n * being identical is what makes the local one a rehearsal.\n */\nexport const DEFAULT_FORWARDED_PATHS = [\"/auth/v1\", \"/oauth2\"] as const;\n\n/**\n * Where the endpoints hang off the app's own origin.\n *\n * `__`-prefixed by convention — Clerk uses `/__clerk`, Firebase `/__/auth` —\n * because it has to be a path no real route of the app will ever want.\n */\nexport const DEFAULT_BASE_PATH = \"/__pontive\";\n\n/**\n * The auth server, as an origin.\n *\n * Accepts `tenant.idp.us.pontive.app` or `https://tenant.idp.us.pontive.app`,\n * and nothing with a path: the upstream path comes from the incoming request,\n * and a base path here would be silently prepended to endpoints the auth server\n * does not serve.\n *\n * `http://` is inferred for loopback only, and accepted only there. A proxy is\n * the one hop a refresh token cannot be carried over in the clear — it is the\n * hop that exists precisely so the cookie is first-party — and the failure is\n * invisible from the browser, which sees its own `https://` origin either way.\n */\nexport function authOrigin(authHost: string): string {\n const configured = (authHost ?? \"\").trim();\n\n if (!configured) {\n throw new TypeError(\"authHost is required\");\n }\n\n const loopback = /^(localhost|127\\.0\\.0\\.1|\\[::1\\])(:\\d+)?$/i.test(\n configured.replace(/^https?:\\/\\//i, \"\").split(\"/\")[0],\n );\n\n const scheme = /^https?:\\/\\//i.test(configured) ? \"\" : `${loopback ? \"http\" : \"https\"}://`;\n\n let url: URL;\n try {\n url = new URL(`${scheme}${configured}`);\n } catch {\n throw new TypeError(`authHost \"${configured}\" is not a hostname or an origin`);\n }\n\n if (url.pathname !== \"/\" || url.search || url.hash) {\n throw new TypeError(\n `authHost \"${configured}\" must be a bare origin — the path comes from the request being proxied`,\n );\n }\n\n if (url.protocol !== \"https:\" && !loopback) {\n throw new TypeError(`authHost \"${configured}\" must be https outside loopback`);\n }\n\n return url.origin;\n}\n\n/**\n * A base path with a leading slash and no trailing one, so joining is\n * unambiguous.\n *\n * `\"/\"` normalises to `\"\"`, which mounts the endpoints at the origin root —\n * `/auth/v1/...` and `/oauth2/...` where the app itself is served. That is the\n * shape a Vite dev server has always used, and it stays available because in\n * development the app owns the whole origin and there is nothing to collide\n * with. A deployed app usually does not, which is what the prefix is for.\n */\nexport function normaliseBasePath(basePath: string): string {\n const trimmed = (basePath ?? \"\").trim().replace(/\\/+$/, \"\");\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n if (!trimmed.startsWith(\"/\")) {\n throw new TypeError(`basePath \"${basePath}\" must start with \"/\"`);\n }\n\n return trimmed;\n}\n\n/** Whether `pathname` is `prefix` itself or something under it. */\nexport function isUnder(pathname: string, prefix: string): boolean {\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","import {\n DEFAULT_BASE_PATH,\n DEFAULT_FORWARDED_PATHS,\n authOrigin,\n normaliseBasePath,\n} from \"./target\";\n\n/**\n * The shape of one entry in Vite's `server.proxy`.\n *\n * Declared here rather than imported from Vite so that nothing which imports\n * this module needs Vite installed, and so the published types do not depend on\n * a particular version of it. It is structural: Vite accepts this object.\n */\nexport interface ViteProxyEntry {\n target: string;\n changeOrigin: boolean;\n rewrite: (path: string) => string;\n}\n\nexport interface ViteAuthProxyOptions {\n authHost: string;\n basePath?: string;\n paths?: readonly string[];\n}\n\n/**\n * The auth endpoints, proxied through a Vite dev server.\n *\n * ```ts\n * // vite.config.ts\n * server: { proxy: viteAuthProxy({ authHost: env.VITE_SB_AUTH_DOMAIN }) }\n * ```\n *\n * Vite already has a proxy; what it does not have is the knowledge of which\n * paths to carry and what to do with Host, and both of those are easy to get\n * wrong in ways that fail silently. So this is a config generator rather than a\n * request handler — `createAuthProxy` is for runtimes that have no proxy of\n * their own.\n *\n * Worth doing even where the browser would tolerate the cross-site setup,\n * because it is the same topology production runs on: a dev server that proxies\n * is rehearsing the deployment, and a dev server that does not is testing a\n * configuration no user will ever have. It is also the only way an embedded\n * sign-in flow works in Safari, which blocks third-party cookies outright.\n */\nexport function viteAuthProxy(\n options: ViteAuthProxyOptions,\n): Record<string, ViteProxyEntry> {\n const target = authOrigin(options.authHost);\n const basePath = normaliseBasePath(options.basePath ?? DEFAULT_BASE_PATH);\n const paths = options.paths ?? DEFAULT_FORWARDED_PATHS;\n\n const proxy: Record<string, ViteProxyEntry> = {};\n\n for (const prefix of paths) {\n proxy[`${basePath}${prefix}`] = {\n target,\n // The single most important line, and the one a hand-written config\n // leaves out. Without it the auth server is asked to answer as\n // `localhost:5173` — a Host it has no project for — and the reply is a\n // CORS refusal and an empty issuer rather than anything that says so.\n changeOrigin: true,\n // Only the base path comes off. The prefix below it is the path the auth\n // server actually serves.\n rewrite: (path: string) => (basePath ? path.replace(basePath, \"\") : path),\n };\n }\n\n return proxy;\n}\n"],"names":["DEFAULT_FORWARDED_PATHS","DEFAULT_BASE_PATH","authOrigin","authHost","configured","loopback","scheme","url","normaliseBasePath","basePath","trimmed","isUnder","pathname","prefix","viteAuthProxy","options","target","paths","proxy","path"],"mappings":"AAiCO,MAAMA,IAA0B,CAAC,YAAY,SAAS,GAQhDC,IAAoB;AAe1B,SAASC,EAAWC,GAA0B;AACnD,QAAMC,KAAcD,KAAY,IAAI,KAAA;AAEpC,MAAI,CAACC;AACH,UAAM,IAAI,UAAU,sBAAsB;AAG5C,QAAMC,IAAW,6CAA6C;AAAA,IAC5DD,EAAW,QAAQ,iBAAiB,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAAA,GAGhDE,IAAS,gBAAgB,KAAKF,CAAU,IAAI,KAAK,GAAGC,IAAW,SAAS,OAAO;AAErF,MAAIE;AACJ,MAAI;AACF,IAAAA,IAAM,IAAI,IAAI,GAAGD,CAAM,GAAGF,CAAU,EAAE;AAAA,EACxC,QAAQ;AACN,UAAM,IAAI,UAAU,aAAaA,CAAU,kCAAkC;AAAA,EAC/E;AAEA,MAAIG,EAAI,aAAa,OAAOA,EAAI,UAAUA,EAAI;AAC5C,UAAM,IAAI;AAAA,MACR,aAAaH,CAAU;AAAA,IAAA;AAI3B,MAAIG,EAAI,aAAa,YAAY,CAACF;AAChC,UAAM,IAAI,UAAU,aAAaD,CAAU,kCAAkC;AAG/E,SAAOG,EAAI;AACb;AAYO,SAASC,EAAkBC,GAA0B;AAC1D,QAAMC,KAAWD,KAAY,IAAI,OAAO,QAAQ,QAAQ,EAAE;AAE1D,MAAIC,MAAY;AACd,WAAO;AAGT,MAAI,CAACA,EAAQ,WAAW,GAAG;AACzB,UAAM,IAAI,UAAU,aAAaD,CAAQ,uBAAuB;AAGlE,SAAOC;AACT;AAGO,SAASC,EAAQC,GAAkBC,GAAyB;AACjE,SAAOD,MAAaC,KAAUD,EAAS,WAAW,GAAGC,CAAM,GAAG;AAChE;ACtEO,SAASC,EACdC,GACgC;AAChC,QAAMC,IAASd,EAAWa,EAAQ,QAAQ,GACpCN,IAAWD,EAAkBO,EAAQ,YAAYd,CAAiB,GAClEgB,IAAQF,EAAQ,SAASf,GAEzBkB,IAAwC,CAAA;AAE9C,aAAWL,KAAUI;AACnB,IAAAC,EAAM,GAAGT,CAAQ,GAAGI,CAAM,EAAE,IAAI;AAAA,MAC9B,QAAAG;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,cAAc;AAAA;AAAA;AAAA,MAGd,SAAS,CAACG,MAAkBV,IAAWU,EAAK,QAAQV,GAAU,EAAE,IAAIU;AAAA,IAAA;AAIxE,SAAOD;AACT;"}
1
+ {"version":3,"file":"proxy.js","sources":["../src/proxy/target.ts","../src/proxy/vite.ts"],"sourcesContent":["/**\n * Where a proxied request is sent, and which requests are sent at all.\n *\n * Deliberately not shared with `resolveAuthBaseUrl` in the SDK, which answers a\n * different question. That one resolves what the BROWSER should call and its\n * most useful answer — a bare path like `/__pontive` — is meaningless here: a\n * proxy runs on a server, where there is no page origin for a path to be\n * relative to. Sharing them would mean one function with a mode flag, and the\n * mode that is wrong in either direction is silent.\n */\n\n/**\n * The endpoints an app-level proxy has to carry, and the reason the list is\n * short.\n *\n * These are the requests the browser makes with `fetch` — pontkit's frontend\n * API (`/v1/frontend`: the auth flow, runtime config, widget messages, the\n * theme), the signed-in user's own surface (`/v1/me`: profile, sessions,\n * memberships, billing), and the token endpoint, userinfo and logout. They are the ones that need\n * to be same-origin, because they are the ones carrying cookies under\n * `SameSite=Lax`.\n *\n * Everything else on the auth server is a top-level navigation — `/authorize`,\n * the hosted sign-in page, `/logout` as a redirect — and a `Lax` cookie is\n * sent on those already, whatever origin they are served from. Proxying them\n * would not help, and it would break: the authorization server builds those\n * URLs absolute, on its own hostname, so the browser leaves the proxy at the\n * first redirect anyway.\n *\n * The prefixes are the same the dev-server proxy uses (auth-api,\n * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be\n * tidied away: local development against a shared sandbox domain is the same\n * cross-site problem this solves in production, and the two configurations\n * being identical is what makes the local one a rehearsal.\n */\nexport const DEFAULT_FORWARDED_PATHS = [\"/v1/frontend\", \"/v1/me\", \"/oauth2\"] as const;\n\n/**\n * Where the endpoints hang off the app's own origin.\n *\n * `__`-prefixed by convention — Clerk uses `/__clerk`, Firebase `/__/auth` —\n * because it has to be a path no real route of the app will ever want.\n */\nexport const DEFAULT_BASE_PATH = \"/__pontive\";\n\n/**\n * The auth server, as an origin.\n *\n * Accepts `tenant.idp.us.pontive.app` or `https://tenant.idp.us.pontive.app`,\n * and nothing with a path: the upstream path comes from the incoming request,\n * and a base path here would be silently prepended to endpoints the auth server\n * does not serve.\n *\n * `http://` is inferred for loopback only, and accepted only there. A proxy is\n * the one hop a refresh token cannot be carried over in the clear — it is the\n * hop that exists precisely so the cookie is first-party — and the failure is\n * invisible from the browser, which sees its own `https://` origin either way.\n */\nexport function authOrigin(authHost: string): string {\n const configured = (authHost ?? \"\").trim();\n\n if (!configured) {\n throw new TypeError(\"authHost is required\");\n }\n\n const loopback = /^(localhost|127\\.0\\.0\\.1|\\[::1\\])(:\\d+)?$/i.test(\n configured.replace(/^https?:\\/\\//i, \"\").split(\"/\")[0],\n );\n\n const scheme = /^https?:\\/\\//i.test(configured) ? \"\" : `${loopback ? \"http\" : \"https\"}://`;\n\n let url: URL;\n try {\n url = new URL(`${scheme}${configured}`);\n } catch {\n throw new TypeError(`authHost \"${configured}\" is not a hostname or an origin`);\n }\n\n if (url.pathname !== \"/\" || url.search || url.hash) {\n throw new TypeError(\n `authHost \"${configured}\" must be a bare origin — the path comes from the request being proxied`,\n );\n }\n\n if (url.protocol !== \"https:\" && !loopback) {\n throw new TypeError(`authHost \"${configured}\" must be https outside loopback`);\n }\n\n return url.origin;\n}\n\n/**\n * A base path with a leading slash and no trailing one, so joining is\n * unambiguous.\n *\n * `\"/\"` normalises to `\"\"`, which mounts the endpoints at the origin root —\n * `/v1/frontend/...`, `/v1/me/...` and `/oauth2/...` where the app itself is served. That is the\n * shape a Vite dev server has always used, and it stays available because in\n * development the app owns the whole origin and there is nothing to collide\n * with. A deployed app usually does not, which is what the prefix is for.\n */\nexport function normaliseBasePath(basePath: string): string {\n const trimmed = (basePath ?? \"\").trim().replace(/\\/+$/, \"\");\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n if (!trimmed.startsWith(\"/\")) {\n throw new TypeError(`basePath \"${basePath}\" must start with \"/\"`);\n }\n\n return trimmed;\n}\n\n/** Whether `pathname` is `prefix` itself or something under it. */\nexport function isUnder(pathname: string, prefix: string): boolean {\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","import {\n DEFAULT_BASE_PATH,\n DEFAULT_FORWARDED_PATHS,\n authOrigin,\n normaliseBasePath,\n} from \"./target\";\n\n/**\n * The shape of one entry in Vite's `server.proxy`.\n *\n * Declared here rather than imported from Vite so that nothing which imports\n * this module needs Vite installed, and so the published types do not depend on\n * a particular version of it. It is structural: Vite accepts this object.\n */\nexport interface ViteProxyEntry {\n target: string;\n changeOrigin: boolean;\n rewrite: (path: string) => string;\n}\n\nexport interface ViteAuthProxyOptions {\n authHost: string;\n basePath?: string;\n paths?: readonly string[];\n}\n\n/**\n * The auth endpoints, proxied through a Vite dev server.\n *\n * ```ts\n * // vite.config.ts\n * server: { proxy: viteAuthProxy({ authHost: env.VITE_SB_AUTH_DOMAIN }) }\n * ```\n *\n * Vite already has a proxy; what it does not have is the knowledge of which\n * paths to carry and what to do with Host, and both of those are easy to get\n * wrong in ways that fail silently. So this is a config generator rather than a\n * request handler — `createAuthProxy` is for runtimes that have no proxy of\n * their own.\n *\n * Worth doing even where the browser would tolerate the cross-site setup,\n * because it is the same topology production runs on: a dev server that proxies\n * is rehearsing the deployment, and a dev server that does not is testing a\n * configuration no user will ever have. It is also the only way an embedded\n * sign-in flow works in Safari, which blocks third-party cookies outright.\n */\nexport function viteAuthProxy(\n options: ViteAuthProxyOptions,\n): Record<string, ViteProxyEntry> {\n const target = authOrigin(options.authHost);\n const basePath = normaliseBasePath(options.basePath ?? DEFAULT_BASE_PATH);\n const paths = options.paths ?? DEFAULT_FORWARDED_PATHS;\n\n const proxy: Record<string, ViteProxyEntry> = {};\n\n for (const prefix of paths) {\n proxy[`${basePath}${prefix}`] = {\n target,\n // The single most important line, and the one a hand-written config\n // leaves out. Without it the auth server is asked to answer as\n // `localhost:5173` — a Host it has no project for — and the reply is a\n // CORS refusal and an empty issuer rather than anything that says so.\n changeOrigin: true,\n // Only the base path comes off. The prefix below it is the path the auth\n // server actually serves.\n rewrite: (path: string) => (basePath ? path.replace(basePath, \"\") : path),\n };\n }\n\n return proxy;\n}\n"],"names":["DEFAULT_FORWARDED_PATHS","DEFAULT_BASE_PATH","authOrigin","authHost","configured","loopback","scheme","url","normaliseBasePath","basePath","trimmed","isUnder","pathname","prefix","vite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AAQ,SAASf,GAEzBkB,IAAwC,CAAA;AAE9C,aAAWL,KAAUI;AACnB,IAAAC,EAAM,GAAGT,CAAQ,GAAGI,CAAM,EAAE,IAAI;AAAA,MAC9B,QAAAG;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,cAAc;AAAA;AAAA;AAAA,MAGd,SAAS,CAACG,MAAkBV,IAAWU,EAAK,QAAQV,GAAU,EAAE,IAAIU;AAAA,IAAA;AAIxE,SAAOD;AACT;"}
@@ -1,4 +1,4 @@
1
- /** The shape of GET /auth/v1/runtime-config. */
1
+ /** The shape of GET /v1/frontend/runtime-config. */
2
2
  export interface RuntimeConfig {
3
3
  pontkit_version: string;
4
4
  catalog_revision?: number;
@@ -18,7 +18,7 @@ export interface RuntimeConfig {
18
18
  css: string;
19
19
  };
20
20
  }
21
- export declare const RUNTIME_CONFIG_PATHS: readonly ["/__pontive/auth/v1/runtime-config", "/auth/v1/runtime-config"];
21
+ export declare const RUNTIME_CONFIG_PATHS: readonly ["/__pontive/v1/frontend/runtime-config", "/v1/frontend/runtime-config"];
22
22
  /** How long to wait for the platform before loading the stamped release. */
23
23
  export declare const RUNTIME_CONFIG_TIMEOUT_MS = 1500;
24
24
  export interface FetchRuntimeConfigOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pontive/pontkit-loader",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "license": "MIT",
5
5
  "description": "Loads @pontive/pontkit-core from the CDN at the release the platform decides.",
6
6
  "type": "module",