@pontive/pontkit-loader 1.0.0 → 1.0.2

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 $=__CORE_ELEMENTS_VERSION__,U=["/__auth/auth/v1/runtime-config","/auth/v1/runtime-config"],j=1500,K=/^\d+\.\d+\.\d+$/;function F(t){return typeof t=="string"&&K.test(t)}function b(t){return typeof t=="string"&&/^https?:\/\//.test(t)}function P(t){return typeof t=="string"&&/^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t)}async function V(t={}){const a=t.fetchImpl??globalThis.fetch;if(typeof a!="function")return null;const l=t.urls??D(),d=t.timeoutMs??j;for(const e of l){const p=await W(a,e,d);if(p)return p}return null}function D(){return typeof window<"u"&&typeof window.__pontRuntimeConfigUrl=="string"?[window.__pontRuntimeConfigUrl]:U}async function W(t,a,l){const d=typeof AbortController=="function"?new AbortController:null,e=d?setTimeout(()=>d.abort(),l):null;try{const p=await t(a,{headers:{accept:"application/json"},signal:d?.signal});if(!p.ok)return null;const n=await p.json();if(!n||!F(n.core_elements_version))return null;const g={core_elements_version:n.core_elements_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&&b(n.assets.js)&&b(n.assets.css)&&(g.assets={js:n.assets.js,css:n.assets.css}),n.integrity&&P(n.integrity.js)&&P(n.integrity.css)&&(g.integrity={js:n.integrity.js,css:n.integrity.css}),g}catch{return null}finally{e&&clearTimeout(e)}}let v=null,T=null;const S="@pontive/pontkit-core",q=[t=>`https://cdn.jsdelivr.net/npm/${S}@${t}/dist/index.mjs`,t=>`https://unpkg.com/${S}@${t}/dist/index.mjs`,t=>`https://esm.sh/${S}@${t}/dist/index.mjs`],z=[t=>`https://cdn.jsdelivr.net/npm/${S}@${t}/dist/styles.css`,t=>`https://unpkg.com/${S}@${t}/dist/styles.css`,t=>`https://esm.sh/${S}@${t}/dist/styles.css`],B=$;function X(t,a){return new Promise((l,d)=>{const e=document.createElement("link");e.rel="stylesheet",e.href=t,a&&(e.integrity=a,e.crossOrigin="anonymous"),e.onload=()=>l(),e.onerror=p=>d(p),document.head.appendChild(e)})}function Z(t,a){return new Promise((l,d)=>{const e=document.createElement("script");e.type="module",e.src=t,e.integrity=a,e.crossOrigin="anonymous",e.onload=()=>l(),e.onerror=()=>d(new Error(`core-elements module at ${t} failed to load or did not match its integrity hash`)),document.head.appendChild(e)}).then(()=>import(t))}async function x(){return typeof window>"u"||typeof document>"u"?null:window.__pontLoaded?window.__pontCoreSdk:window.__pontLoading?window.__pontLoading:(T||(T=J().catch(t=>{throw T=null,window.__pontLoading=void 0,t}),window.__pontLoading=T),T)}async function J(){const t=await V(),a=t?.core_elements_version??B,l=q.map(n=>n(a)),d=z.map(n=>n(a));t?.assets&&(l.unshift(t.assets.js),d.unshift(t.assets.css));const e=t?.integrity;let p=null;for(let n=0;n<l.length;n++){const g=l[n],G=d[n];try{let R=function(i){if(!i)return i;const C=[];let _=!1,m=null;const h=new Promise(o=>{m=o}),y=new Proxy(i,{get(o,c,f){if(c==="configure")return(...u)=>{const r=o.configure?.(...u);_=!0;try{C.forEach(({prop:w,args:I,resolve:A,reject:E})=>{try{const M=o[w].apply(o,I);M&&typeof M.then=="function"?M.then(A).catch(E):A(M)}catch(L){E(L)}})}catch{}C.length=0;try{y.__configured=!0}catch{}return m?.(),r};const s=o[c];return typeof s=="function"?(...u)=>{if(!_)return new Promise((r,w)=>{C.push({prop:c,args:u,resolve:r,reject:w})});try{return s.apply(o,u)}catch(r){throw r}}:s}});try{y.__whenConfigured=h,y.__configured=_}catch{}try{i.__whenConfigured=h,i.__configured=_;const o=i.configure;typeof o=="function"&&(i.configure=(...f)=>{const s=o.apply(i,f);_=!0;try{C.forEach(({prop:u,args:r,resolve:w,reject:I})=>{try{const E=i[u].apply(i,r);E&&typeof E.then=="function"?E.then(w).catch(I):w(E)}catch(A){I(A)}})}catch{}C.length=0;try{i.__configured=!0}catch{}return m?.(),s});const c=i.startLoginflow;typeof c=="function"&&(i.startLoginflow=(...f)=>_?c.apply(i,f):new Promise((s,u)=>{h.then(()=>{try{const r=c.apply(i,f);r&&typeof r.then=="function"?r.then(s).catch(u):s(r)}catch(r){u(r)}}).catch(()=>{try{const r=c.apply(i,f);r&&typeof r.then=="function"?r.then(s).catch(u):s(r)}catch(r){u(r)}})}))}catch{}try{h.then(()=>{setTimeout(()=>{try{document.querySelectorAll("pont-signin, pont-signup").forEach(o=>{try{if(o.__pontInitRetried)return;o.__pontInitRetried=!0;const c=o.__pontRetryInit;if(typeof c=="function"){try{c.call(o)}catch(f){console.error(f)}return}if(o.__pontFailedForConfig)try{o.connectedCallback?.()}catch(f){console.error(f)}}catch{}})}catch{}},0)})}catch{}return y};await X(G,e?.css);const k=e?await Z(g,e.js):await import(g),H=k.useAuthProvider?.(),N=R(H);try{k.Auth=N,k.useAuthProvider=()=>N}catch{}window.__pontCoreSdk={...k,Auth:N},v=window.__pontCoreSdk,window.__pontLoaded=!0,window.__pontLoading=void 0;try{const i=C=>{const _=customElements.get(C);if(!_)return;const m=_.prototype;if(m.__pontConfiguredPatched)return;m.__pontConfiguredPatched=!0;const h=m.connectedCallback;typeof h=="function"&&(m.connectedCallback=function(...y){const o=window.__pontCoreSdk?.Auth,c=o?.__whenConfigured,f=!!o?.__configured;if(c&&!f){c.then(()=>{try{h.apply(this,y)}catch(s){console.error(s)}}).catch(()=>{try{h.apply(this,y)}catch(s){console.error(s)}});return}try{h.apply(this,y)}catch(s){if(s&&typeof s.message=="string"&&s.message.includes("Auth.configure() must be called")&&c){c.then(()=>{try{h.apply(this,y)}catch(u){console.error(u)}});return}throw s}})};["pont-signin","pont-signup"].forEach(i)}catch{}return console.log(`PontKit Web Components loaded (${a}) from:`,g),v}catch(R){console.error(`Failed loading from ${g}`,R),p=R}}throw console.error("❌ Failed to load PontKit web components from all CDNs.",p),p}let O=null;async function Q(){typeof window>"u"||window.__pontCoreSdk?.openAccountSettingsModal||(O||(O=x().then(()=>{window.__pontCoreSdk?.openAccountSettingsModal||console.warn("[pontive-react] Core sdk loaded but modal functions are missing.")}).catch(t=>{throw console.error("[pontive-react] Failed to load core SDK:",t),t})),await O)}exports.CORE_ELEMENTS_VERSION=$;exports.RUNTIME_CONFIG_PATHS=U;exports.RUNTIME_CONFIG_TIMEOUT_MS=j;exports.ensureCoreSdkLoaded=Q;exports.fetchRuntimeConfig=V;exports.isExactVersion=F;exports.isSriHash=P;exports.loadWebComponents=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $="1.1.1",U=["/__auth/auth/v1/runtime-config","/auth/v1/runtime-config"],j=1500,K=/^\d+\.\d+\.\d+$/;function F(t){return typeof t=="string"&&K.test(t)}function b(t){return typeof t=="string"&&/^https?:\/\//.test(t)}function N(t){return typeof t=="string"&&/^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t)}async function V(t={}){const a=t.fetchImpl??globalThis.fetch;if(typeof a!="function")return null;const l=t.urls??D(),d=t.timeoutMs??j;for(const e of l){const p=await W(a,e,d);if(p)return p}return null}function D(){return typeof window<"u"&&typeof window.__pontRuntimeConfigUrl=="string"?[window.__pontRuntimeConfigUrl]:U}async function W(t,a,l){const d=typeof AbortController=="function"?new AbortController:null,e=d?setTimeout(()=>d.abort(),l):null;try{const p=await t(a,{headers:{accept:"application/json"},signal:d?.signal});if(!p.ok)return null;const n=await p.json();if(!n||!F(n.core_elements_version))return null;const g={core_elements_version:n.core_elements_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&&b(n.assets.js)&&b(n.assets.css)&&(g.assets={js:n.assets.js,css:n.assets.css}),n.integrity&&N(n.integrity.js)&&N(n.integrity.css)&&(g.integrity={js:n.integrity.js,css:n.integrity.css}),g}catch{return null}finally{e&&clearTimeout(e)}}let v=null,T=null;const E="@pontive/pontkit-core",q=[t=>`https://cdn.jsdelivr.net/npm/${E}@${t}/dist/index.mjs`,t=>`https://unpkg.com/${E}@${t}/dist/index.mjs`,t=>`https://esm.sh/${E}@${t}/dist/index.mjs`],z=[t=>`https://cdn.jsdelivr.net/npm/${E}@${t}/dist/styles.css`,t=>`https://unpkg.com/${E}@${t}/dist/styles.css`,t=>`https://esm.sh/${E}@${t}/dist/styles.css`],B=$;function X(t,a){return new Promise((l,d)=>{const e=document.createElement("link");e.rel="stylesheet",e.href=t,a&&(e.integrity=a,e.crossOrigin="anonymous"),e.onload=()=>l(),e.onerror=p=>d(p),document.head.appendChild(e)})}function Z(t,a){return new Promise((l,d)=>{const e=document.createElement("script");e.type="module",e.src=t,e.integrity=a,e.crossOrigin="anonymous",e.onload=()=>l(),e.onerror=()=>d(new Error(`core-elements module at ${t} failed to load or did not match its integrity hash`)),document.head.appendChild(e)}).then(()=>import(t))}async function x(){return typeof window>"u"||typeof document>"u"?null:window.__pontLoaded?window.__pontCoreSdk:window.__pontLoading?window.__pontLoading:(T||(T=J().catch(t=>{throw T=null,window.__pontLoading=void 0,t}),window.__pontLoading=T),T)}async function J(){const t=await V(),a=t?.core_elements_version??B,l=q.map(n=>n(a)),d=z.map(n=>n(a));t?.assets&&(l.unshift(t.assets.js),d.unshift(t.assets.css));const e=t?.integrity;let p=null;for(let n=0;n<l.length;n++){const g=l[n],G=d[n];try{let k=function(i){if(!i)return i;const C=[];let _=!1,m=null;const h=new Promise(o=>{m=o}),y=new Proxy(i,{get(o,c,f){if(c==="configure")return(...u)=>{const r=o.configure?.(...u);_=!0;try{C.forEach(({prop:w,args:I,resolve:A,reject:S})=>{try{const M=o[w].apply(o,I);M&&typeof M.then=="function"?M.then(A).catch(S):A(M)}catch(O){S(O)}})}catch{}C.length=0;try{y.__configured=!0}catch{}return m?.(),r};const s=o[c];return typeof s=="function"?(...u)=>{if(!_)return new Promise((r,w)=>{C.push({prop:c,args:u,resolve:r,reject:w})});try{return s.apply(o,u)}catch(r){throw r}}:s}});try{y.__whenConfigured=h,y.__configured=_}catch{}try{i.__whenConfigured=h,i.__configured=_;const o=i.configure;typeof o=="function"&&(i.configure=(...f)=>{const s=o.apply(i,f);_=!0;try{C.forEach(({prop:u,args:r,resolve:w,reject:I})=>{try{const S=i[u].apply(i,r);S&&typeof S.then=="function"?S.then(w).catch(I):w(S)}catch(A){I(A)}})}catch{}C.length=0;try{i.__configured=!0}catch{}return m?.(),s});const c=i.startLoginflow;typeof c=="function"&&(i.startLoginflow=(...f)=>_?c.apply(i,f):new Promise((s,u)=>{h.then(()=>{try{const r=c.apply(i,f);r&&typeof r.then=="function"?r.then(s).catch(u):s(r)}catch(r){u(r)}}).catch(()=>{try{const r=c.apply(i,f);r&&typeof r.then=="function"?r.then(s).catch(u):s(r)}catch(r){u(r)}})}))}catch{}try{h.then(()=>{setTimeout(()=>{try{document.querySelectorAll("pont-signin, pont-signup").forEach(o=>{try{if(o.__pontInitRetried)return;o.__pontInitRetried=!0;const c=o.__pontRetryInit;if(typeof c=="function"){try{c.call(o)}catch(f){console.error(f)}return}if(o.__pontFailedForConfig)try{o.connectedCallback?.()}catch(f){console.error(f)}}catch{}})}catch{}},0)})}catch{}return y};await X(G,e?.css);const P=e?await Z(g,e.js):await import(g),H=P.useAuthProvider?.(),R=k(H);try{P.Auth=R,P.useAuthProvider=()=>R}catch{}window.__pontCoreSdk={...P,Auth:R},v=window.__pontCoreSdk,window.__pontLoaded=!0,window.__pontLoading=void 0;try{const i=C=>{const _=customElements.get(C);if(!_)return;const m=_.prototype;if(m.__pontConfiguredPatched)return;m.__pontConfiguredPatched=!0;const h=m.connectedCallback;typeof h=="function"&&(m.connectedCallback=function(...y){const o=window.__pontCoreSdk?.Auth,c=o?.__whenConfigured,f=!!o?.__configured;if(c&&!f){c.then(()=>{try{h.apply(this,y)}catch(s){console.error(s)}}).catch(()=>{try{h.apply(this,y)}catch(s){console.error(s)}});return}try{h.apply(this,y)}catch(s){if(s&&typeof s.message=="string"&&s.message.includes("Auth.configure() must be called")&&c){c.then(()=>{try{h.apply(this,y)}catch(u){console.error(u)}});return}throw s}})};["pont-signin","pont-signup"].forEach(i)}catch{}return console.log(`PontKit Web Components loaded (${a}) from:`,g),v}catch(k){console.error(`Failed loading from ${g}`,k),p=k}}throw console.error("❌ Failed to load PontKit web components from all CDNs.",p),p}let L=null;async function Q(){typeof window>"u"||window.__pontCoreSdk?.openAccountSettingsModal||(L||(L=x().then(()=>{window.__pontCoreSdk?.openAccountSettingsModal||console.warn("[pontive-react] Core sdk loaded but modal functions are missing.")}).catch(t=>{throw console.error("[pontive-react] Failed to load core SDK:",t),t})),await L)}exports.CORE_ELEMENTS_VERSION=$;exports.RUNTIME_CONFIG_PATHS=U;exports.RUNTIME_CONFIG_TIMEOUT_MS=j;exports.ensureCoreSdkLoaded=Q;exports.fetchRuntimeConfig=V;exports.isExactVersion=F;exports.isSriHash=N;exports.loadWebComponents=x;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/core-elements-version.ts","../src/runtime-config.ts","../src/load-web-components.ts","../src/sdk-loaded.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/core-elements-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 CORE_ELEMENTS_VERSION: string = __CORE_ELEMENTS_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// (CORE_ELEMENTS_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 (`/__auth/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 core_elements_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 \"/__auth/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.core_elements_version)) return null;\n\n const config: RuntimeConfig = {\n core_elements_version: body.core_elements_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 { CORE_ELEMENTS_VERSION } from \"./core-elements-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet coreSdk: 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 `coreSdk` while it was still null, log that the\n// SDK's modal functions were missing, and carry on as if 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. CORE_ELEMENTS_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 = CORE_ELEMENTS_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(`core-elements 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.__pontCoreSdk;\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?.core_elements_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 // 2️⃣ Load CSS first\n await loadCss(cssCdn, integrity?.css);\n\n // 3️⃣ Load JS 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 // 4️⃣ Expose globally\n // Wrap Auth so calls made before `configure()` won't throw. Instead\n // we queue them and flush once configure() is called by the provider.\n function createSafeAuth(auth: any) {\n if (!auth) return auth;\n type QItem = {\n prop: string | symbol;\n args: any[];\n resolve: (v: any) => void;\n reject: (e: any) => void;\n };\n const queue: QItem[] = [];\n let configured = false;\n\n // Expose a configured promise and flag on the proxy so other parts\n // of the app can wait for Auth to be configured (helps avoid errors\n // thrown by custom elements that start flows on connect).\n let resolveWhenConfigured: (() => void) | null = null;\n const whenConfigured = new Promise<void>((res) => {\n resolveWhenConfigured = res;\n });\n\n const proxy = new Proxy(auth, {\n get(target, prop, receiver) {\n if (prop === \"configure\") {\n return (...args: any[]) => {\n const res = (target as any).configure?.(...args);\n configured = true;\n try {\n // flush queued calls\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (target as any)[p];\n const r = fn.apply(target, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n // ignore flushing errors\n }\n queue.length = 0;\n // mark proxy as configured and resolve the promise\n try {\n (proxy as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const val = (target as any)[prop];\n if (typeof val === \"function\") {\n return (...args: any[]) => {\n if (!configured) {\n // queue the call and return a Promise that resolves when flushed\n return new Promise((resolve, reject) => {\n queue.push({ prop, args, resolve, reject });\n });\n }\n try {\n return val.apply(target, args);\n } catch (e) {\n // preserve throwing behavior for already-configured\n throw e;\n }\n };\n }\n return val;\n },\n });\n\n // Attach the whenConfigured promise and configured flag to the proxy\n try {\n (proxy as any).__whenConfigured = whenConfigured;\n (proxy as any).__configured = configured;\n } catch (e) {\n /* ignore */\n }\n\n // Also patch the original `auth` object (if present) so that direct\n // imports and in-module usages get queued behavior too. This ensures\n // that calls like `Auth.startLoginflow()` won't throw even if they\n // happen before `configure()` is invoked.\n try {\n // Mark the original with the same hooks\n (auth as any).__whenConfigured = whenConfigured;\n (auth as any).__configured = configured;\n\n const origConfigure = (auth as any).configure;\n if (typeof origConfigure === \"function\") {\n (auth as any).configure = (...args: any[]) => {\n const res = origConfigure.apply(auth, args);\n configured = true;\n try {\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (auth as any)[p];\n const r = fn.apply(auth, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n /* ignore */\n }\n queue.length = 0;\n try {\n (auth as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const origStart = (auth as any).startLoginflow;\n if (typeof origStart === \"function\") {\n (auth as any).startLoginflow = (...args: any[]) => {\n if (!configured) {\n return new Promise((resolve, reject) => {\n whenConfigured\n .then(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n })\n .catch(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n });\n }\n\n return origStart.apply(auth, args);\n };\n }\n } catch (e) {\n /* ignore */\n }\n\n // When auth is configured, call an explicit retry method on any\n // sign-in/up elements that implement it. Prefer an explicit retry\n // API so elements can be idempotent and avoid duplicate flows.\n try {\n whenConfigured.then(() => {\n setTimeout(() => {\n try {\n document\n .querySelectorAll(\"pont-signin, pont-signup\")\n .forEach((el) => {\n try {\n if ((el as any).__pontInitRetried) return;\n (el as any).__pontInitRetried = true;\n // Prefer an explicit retry API implemented by the element\n // (e.g., `__pontRetryInit`) to avoid re-running the\n // entire `connectedCallback` which may cause duplicates.\n const retry = (el as any).__pontRetryInit;\n if (typeof retry === \"function\") {\n try {\n retry.call(el);\n } catch (e) {\n console.error(e);\n }\n return;\n }\n\n // Fallback: only call connectedCallback if the element\n // provides an explicit flag saying it previously failed\n // due to missing Auth (set by our connectedCallback wrapper\n // when we detect that specific error).\n if ((el as any).__pontFailedForConfig) {\n try {\n (el as any).connectedCallback?.();\n } catch (e) {\n console.error(e);\n }\n }\n } catch (_) {\n // ignore per-element errors\n }\n });\n } catch (_) {\n /* ignore */\n }\n }, 0);\n });\n } catch (e) {\n /* ignore */\n }\n\n return proxy;\n }\n\n // Replace module exports so consumers that import `Auth` directly\n // get the safe proxy as well. Also ensure `useAuthProvider()` returns\n // the proxy.\n const realAuth = module.useAuthProvider?.();\n const safeAuth = createSafeAuth(realAuth);\n\n try {\n (module as any).Auth = safeAuth;\n (module as any).useAuthProvider = () => safeAuth;\n } catch (e) {\n /* ignore */\n }\n\n window.__pontCoreSdk = {\n ...module,\n Auth: safeAuth,\n };\n\n coreSdk = window.__pontCoreSdk;\n\n // Set only once the SDK is actually on the window, so a copy of this\n // package that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n // Patch known elements that may start flows on connect so they wait\n // for Auth to be configured instead of throwing. This avoids noisy\n // runtime errors like \"Auth.configure() must be called\".\n try {\n const patchElement = (tagName: string) => {\n const ctor = customElements.get(tagName);\n if (!ctor) return;\n const proto = ctor.prototype as any;\n if (proto.__pontConfiguredPatched) return;\n proto.__pontConfiguredPatched = true;\n\n const orig = proto.connectedCallback;\n if (typeof orig !== \"function\") return;\n\n proto.connectedCallback = function (...args: any[]) {\n const auth = window.__pontCoreSdk?.Auth as any;\n const whenConfigured = auth?.__whenConfigured as\n | Promise<void>\n | undefined;\n const configured = !!auth?.__configured;\n\n if (whenConfigured && !configured) {\n // delay initial connect work until Auth is configured\n whenConfigured\n .then(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n })\n .catch(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n });\n return;\n }\n\n try {\n orig.apply(this, args);\n } catch (e: any) {\n // If it still throws with the configure error, retry after configured\n if (\n e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"Auth.configure() must be called\") &&\n whenConfigured\n ) {\n whenConfigured.then(() => {\n try {\n orig.apply(this, args);\n } catch (err) {\n console.error(err);\n }\n });\n return;\n }\n throw e;\n }\n };\n };\n\n // Elements known to start auth flows on connect\n [\"pont-signin\", \"pont-signup\"].forEach(patchElement);\n } catch (e) {\n /* ignore patch errors */\n }\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return coreSdk;\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","import { loadWebComponents } from \"./load-web-components\";\n\nlet coreSdkLoadPromise: Promise<void> | null = null;\n\n/**\n * Ensures the core SDK is loaded and the global functions are available.\n * Returns a promise that resolves when the SDK is ready.\n */\nexport async function ensureCoreSdkLoaded(): Promise<void> {\n // Nothing to ensure without a browser, and the check below would throw before\n // reaching loadWebComponents' own guard.\n if (typeof window === \"undefined\") {\n return;\n }\n\n // If the functions already exist, we're done.\n if (window.__pontCoreSdk?.openAccountSettingsModal) {\n return;\n }\n\n // Otherwise, start loading the SDK if not already loading.\n if (!coreSdkLoadPromise) {\n coreSdkLoadPromise = loadWebComponents()\n .then(() => {\n // The first SDK script attaches the functions synchronously when it executes.\n if (!window.__pontCoreSdk?.openAccountSettingsModal) {\n console.warn(\n \"[pontive-react] Core sdk loaded but modal functions are missing.\",\n );\n }\n })\n .catch((err) => {\n console.error(\"[pontive-react] Failed to load core SDK:\", err);\n throw err;\n });\n }\n\n await coreSdkLoadPromise;\n}\n"],"names":["CORE_ELEMENTS_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","coreSdk","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","createSafeAuth","auth","queue","configured","resolveWhenConfigured","whenConfigured","res","proxy","target","prop","receiver","args","p","a","r","val","e","origConfigure","origStart","el","retry","module","realAuth","safeAuth","patchElement","tagName","ctor","proto","orig","coreSdkLoadPromise","ensureCoreSdkLoaded"],"mappings":"gFAcO,MAAMA,EAAgC,0BCgBhCC,EAAuB,CAClC,iCACA,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,EAAWI,EAAKD,CAAS,EACtD,GAAIE,EAAQ,OAAOA,CACrB,CAEA,OAAO,IACT,CAEA,SAASH,GAAmC,CAC1C,OAAI,OAAO,OAAW,KAAe,OAAO,OAAO,wBAA2B,SACrE,CAAC,OAAO,sBAAsB,EAGhCX,CACT,CAEA,eAAee,EACbN,EACAI,EACAD,EAC+B,CAC/B,MAAMI,EAAa,OAAO,iBAAoB,WAAa,IAAI,gBAAoB,KAC7EC,EAAQD,EAAa,WAAW,IAAMA,EAAW,MAAA,EAASJ,CAAS,EAAI,KAE7E,GAAI,CACF,MAAMM,E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CAEL,OAAO,eAAe,0BACzB,QAAQ,KACN,kEAAA,CAGN,CAAC,EACA,MAAOH,GAAQ,CACd,cAAQ,MAAM,2CAA4CA,CAAG,EACvDA,CACR,CAAC,GAGL,MAAM2C,EACR"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/core-elements-version.ts","../src/runtime-config.ts","../src/load-web-components.ts","../src/sdk-loaded.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/core-elements-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 CORE_ELEMENTS_VERSION: string = __CORE_ELEMENTS_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// (CORE_ELEMENTS_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 (`/__auth/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 core_elements_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 \"/__auth/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.core_elements_version)) return null;\n\n const config: RuntimeConfig = {\n core_elements_version: body.core_elements_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 { CORE_ELEMENTS_VERSION } from \"./core-elements-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet coreSdk: 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 `coreSdk` while it was still null, log that the\n// SDK's modal functions were missing, and carry on as if 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. CORE_ELEMENTS_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 = CORE_ELEMENTS_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(`core-elements 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.__pontCoreSdk;\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?.core_elements_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 // 2️⃣ Load CSS first\n await loadCss(cssCdn, integrity?.css);\n\n // 3️⃣ Load JS 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 // 4️⃣ Expose globally\n // Wrap Auth so calls made before `configure()` won't throw. Instead\n // we queue them and flush once configure() is called by the provider.\n function createSafeAuth(auth: any) {\n if (!auth) return auth;\n type QItem = {\n prop: string | symbol;\n args: any[];\n resolve: (v: any) => void;\n reject: (e: any) => void;\n };\n const queue: QItem[] = [];\n let configured = false;\n\n // Expose a configured promise and flag on the proxy so other parts\n // of the app can wait for Auth to be configured (helps avoid errors\n // thrown by custom elements that start flows on connect).\n let resolveWhenConfigured: (() => void) | null = null;\n const whenConfigured = new Promise<void>((res) => {\n resolveWhenConfigured = res;\n });\n\n const proxy = new Proxy(auth, {\n get(target, prop, receiver) {\n if (prop === \"configure\") {\n return (...args: any[]) => {\n const res = (target as any).configure?.(...args);\n configured = true;\n try {\n // flush queued calls\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (target as any)[p];\n const r = fn.apply(target, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n // ignore flushing errors\n }\n queue.length = 0;\n // mark proxy as configured and resolve the promise\n try {\n (proxy as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const val = (target as any)[prop];\n if (typeof val === \"function\") {\n return (...args: any[]) => {\n if (!configured) {\n // queue the call and return a Promise that resolves when flushed\n return new Promise((resolve, reject) => {\n queue.push({ prop, args, resolve, reject });\n });\n }\n try {\n return val.apply(target, args);\n } catch (e) {\n // preserve throwing behavior for already-configured\n throw e;\n }\n };\n }\n return val;\n },\n });\n\n // Attach the whenConfigured promise and configured flag to the proxy\n try {\n (proxy as any).__whenConfigured = whenConfigured;\n (proxy as any).__configured = configured;\n } catch (e) {\n /* ignore */\n }\n\n // Also patch the original `auth` object (if present) so that direct\n // imports and in-module usages get queued behavior too. This ensures\n // that calls like `Auth.startLoginflow()` won't throw even if they\n // happen before `configure()` is invoked.\n try {\n // Mark the original with the same hooks\n (auth as any).__whenConfigured = whenConfigured;\n (auth as any).__configured = configured;\n\n const origConfigure = (auth as any).configure;\n if (typeof origConfigure === \"function\") {\n (auth as any).configure = (...args: any[]) => {\n const res = origConfigure.apply(auth, args);\n configured = true;\n try {\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (auth as any)[p];\n const r = fn.apply(auth, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n /* ignore */\n }\n queue.length = 0;\n try {\n (auth as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const origStart = (auth as any).startLoginflow;\n if (typeof origStart === \"function\") {\n (auth as any).startLoginflow = (...args: any[]) => {\n if (!configured) {\n return new Promise((resolve, reject) => {\n whenConfigured\n .then(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n })\n .catch(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n });\n }\n\n return origStart.apply(auth, args);\n };\n }\n } catch (e) {\n /* ignore */\n }\n\n // When auth is configured, call an explicit retry method on any\n // sign-in/up elements that implement it. Prefer an explicit retry\n // API so elements can be idempotent and avoid duplicate flows.\n try {\n whenConfigured.then(() => {\n setTimeout(() => {\n try {\n document\n .querySelectorAll(\"pont-signin, pont-signup\")\n .forEach((el) => {\n try {\n if ((el as any).__pontInitRetried) return;\n (el as any).__pontInitRetried = true;\n // Prefer an explicit retry API implemented by the element\n // (e.g., `__pontRetryInit`) to avoid re-running the\n // entire `connectedCallback` which may cause duplicates.\n const retry = (el as any).__pontRetryInit;\n if (typeof retry === \"function\") {\n try {\n retry.call(el);\n } catch (e) {\n console.error(e);\n }\n return;\n }\n\n // Fallback: only call connectedCallback if the element\n // provides an explicit flag saying it previously failed\n // due to missing Auth (set by our connectedCallback wrapper\n // when we detect that specific error).\n if ((el as any).__pontFailedForConfig) {\n try {\n (el as any).connectedCallback?.();\n } catch (e) {\n console.error(e);\n }\n }\n } catch (_) {\n // ignore per-element errors\n }\n });\n } catch (_) {\n /* ignore */\n }\n }, 0);\n });\n } catch (e) {\n /* ignore */\n }\n\n return proxy;\n }\n\n // Replace module exports so consumers that import `Auth` directly\n // get the safe proxy as well. Also ensure `useAuthProvider()` returns\n // the proxy.\n const realAuth = module.useAuthProvider?.();\n const safeAuth = createSafeAuth(realAuth);\n\n try {\n (module as any).Auth = safeAuth;\n (module as any).useAuthProvider = () => safeAuth;\n } catch (e) {\n /* ignore */\n }\n\n window.__pontCoreSdk = {\n ...module,\n Auth: safeAuth,\n };\n\n coreSdk = window.__pontCoreSdk;\n\n // Set only once the SDK is actually on the window, so a copy of this\n // package that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n // Patch known elements that may start flows on connect so they wait\n // for Auth to be configured instead of throwing. This avoids noisy\n // runtime errors like \"Auth.configure() must be called\".\n try {\n const patchElement = (tagName: string) => {\n const ctor = customElements.get(tagName);\n if (!ctor) return;\n const proto = ctor.prototype as any;\n if (proto.__pontConfiguredPatched) return;\n proto.__pontConfiguredPatched = true;\n\n const orig = proto.connectedCallback;\n if (typeof orig !== \"function\") return;\n\n proto.connectedCallback = function (...args: any[]) {\n const auth = window.__pontCoreSdk?.Auth as any;\n const whenConfigured = auth?.__whenConfigured as\n | Promise<void>\n | undefined;\n const configured = !!auth?.__configured;\n\n if (whenConfigured && !configured) {\n // delay initial connect work until Auth is configured\n whenConfigured\n .then(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n })\n .catch(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n });\n return;\n }\n\n try {\n orig.apply(this, args);\n } catch (e: any) {\n // If it still throws with the configure error, retry after configured\n if (\n e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"Auth.configure() must be called\") &&\n whenConfigured\n ) {\n whenConfigured.then(() => {\n try {\n orig.apply(this, args);\n } catch (err) {\n console.error(err);\n }\n });\n return;\n }\n throw e;\n }\n };\n };\n\n // Elements known to start auth flows on connect\n [\"pont-signin\", \"pont-signup\"].forEach(patchElement);\n } catch (e) {\n /* ignore patch errors */\n }\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return coreSdk;\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","import { loadWebComponents } from \"./load-web-components\";\n\nlet coreSdkLoadPromise: Promise<void> | null = null;\n\n/**\n * Ensures the core SDK is loaded and the global functions are available.\n * Returns a promise that resolves when the SDK is ready.\n */\nexport async function ensureCoreSdkLoaded(): Promise<void> {\n // Nothing to ensure without a browser, and the check below would throw before\n // reaching loadWebComponents' own guard.\n if (typeof window === \"undefined\") {\n return;\n }\n\n // If the functions already exist, we're done.\n if (window.__pontCoreSdk?.openAccountSettingsModal) {\n return;\n }\n\n // Otherwise, start loading the SDK if not already loading.\n if (!coreSdkLoadPromise) {\n coreSdkLoadPromise = loadWebComponents()\n .then(() => {\n // The first SDK script attaches the functions synchronously when it executes.\n if (!window.__pontCoreSdk?.openAccountSettingsModal) {\n console.warn(\n \"[pontive-react] Core sdk loaded but modal functions are missing.\",\n );\n }\n })\n .catch((err) => {\n console.error(\"[pontive-react] Failed to load core SDK:\", err);\n throw err;\n });\n }\n\n await coreSdkLoadPromise;\n}\n"],"names":["CORE_ELEMENTS_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","coreSdk","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","createSafeAuth","auth","queue","configured","resolveWhenConfigured","whenConfigured","res","proxy","target","prop","receiver","args","p","a","r","val","e","origConfigure","origStart","el","retry","module","realAuth","safeAuth","patchElement","tagName","ctor","proto","orig","coreSdkLoadPromise","ensureCoreSdkLoaded"],"mappings":"gFAcO,MAAMA,EAAgC,QCgBhCC,EAAuB,CAClC,iCACA,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,eA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B,CACF,CAAC,EACH,MACF,CAEA,GAAI,CACFY,EAAK,MAAM,KAAMjB,CAAI,CACvB,OAASK,EAAQ,CAEf,GACEA,GACA,OAAOA,EAAE,SAAY,UACrBA,EAAE,QAAQ,SAAS,iCAAiC,GACpDX,EACA,CACAA,EAAe,KAAK,IAAM,CACxB,GAAI,CACFuB,EAAK,MAAM,KAAMjB,CAAI,CACvB,OAASzB,EAAK,CACZ,QAAQ,MAAMA,CAAG,CACnB,CACF,CAAC,EACD,MACF,CACA,MAAM8B,CACR,CACF,EACF,EAGA,CAAC,cAAe,aAAa,EAAE,QAAQQ,CAAY,CACrD,MAAY,CAEZ,CAEA,eAAQ,IACN,kCAAkChC,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,CCjgBA,IAAIiC,EAA2C,KAM/C,eAAsBC,GAAqC,CAGrD,OAAO,OAAW,KAKlB,OAAO,eAAe,2BAKrBD,IACHA,EAAqBxC,IAClB,KAAK,IAAM,CAEL,OAAO,eAAe,0BACzB,QAAQ,KACN,kEAAA,CAGN,CAAC,EACA,MAAOH,GAAQ,CACd,cAAQ,MAAM,2CAA4CA,CAAG,EACvDA,CACR,CAAC,GAGL,MAAM2C,EACR"}
package/dist/index.js CHANGED
@@ -1,30 +1,30 @@
1
- const F = __CORE_ELEMENTS_VERSION__, U = [
1
+ const j = "1.1.1", F = [
2
2
  "/__auth/auth/v1/runtime-config",
3
3
  "/auth/v1/runtime-config"
4
- ], x = 1500, V = /^\d+\.\d+\.\d+$/;
5
- function K(t) {
6
- return typeof t == "string" && V.test(t);
4
+ ], J = 1500, x = /^\d+\.\d+\.\d+$/;
5
+ function V(t) {
6
+ return typeof t == "string" && x.test(t);
7
7
  }
8
- function I(t) {
8
+ function R(t) {
9
9
  return typeof t == "string" && /^https?:\/\//.test(t);
10
10
  }
11
- function M(t) {
11
+ function b(t) {
12
12
  return typeof t == "string" && /^sha(256|384|512)-[A-Za-z0-9+/]+=*$/.test(t);
13
13
  }
14
- async function D(t = {}) {
14
+ async function K(t = {}) {
15
15
  const a = t.fetchImpl ?? globalThis.fetch;
16
16
  if (typeof a != "function") return null;
17
- const l = t.urls ?? G(), f = t.timeoutMs ?? x;
17
+ const l = t.urls ?? D(), f = t.timeoutMs ?? 1500;
18
18
  for (const e of l) {
19
- const p = await H(a, e, f);
19
+ const p = await G(a, e, f);
20
20
  if (p) return p;
21
21
  }
22
22
  return null;
23
23
  }
24
- function G() {
25
- return typeof window < "u" && typeof window.__pontRuntimeConfigUrl == "string" ? [window.__pontRuntimeConfigUrl] : U;
24
+ function D() {
25
+ return typeof window < "u" && typeof window.__pontRuntimeConfigUrl == "string" ? [window.__pontRuntimeConfigUrl] : F;
26
26
  }
27
- async function H(t, a, l) {
27
+ async function G(t, a, l) {
28
28
  const f = typeof AbortController == "function" ? new AbortController() : null, e = f ? setTimeout(() => f.abort(), l) : null;
29
29
  try {
30
30
  const p = await t(a, {
@@ -33,13 +33,13 @@ async function H(t, a, l) {
33
33
  });
34
34
  if (!p.ok) return null;
35
35
  const n = await p.json();
36
- if (!n || !K(n.core_elements_version)) return null;
36
+ if (!n || !V(n.core_elements_version)) return null;
37
37
  const g = {
38
38
  core_elements_version: n.core_elements_version,
39
39
  source: typeof n.source == "string" ? n.source : void 0,
40
40
  catalog_revision: typeof n.catalog_revision == "number" ? n.catalog_revision : void 0
41
41
  };
42
- return n.assets && I(n.assets.js) && I(n.assets.css) && (g.assets = { js: n.assets.js, css: n.assets.css }), n.integrity && M(n.integrity.js) && M(n.integrity.css) && (g.integrity = { js: n.integrity.js, css: n.integrity.css }), g;
42
+ return n.assets && R(n.assets.js) && R(n.assets.css) && (g.assets = { js: n.assets.js, css: n.assets.css }), n.integrity && b(n.integrity.js) && b(n.integrity.css) && (g.integrity = { js: n.integrity.js, css: n.integrity.css }), g;
43
43
  } catch {
44
44
  return null;
45
45
  } finally {
@@ -47,22 +47,22 @@ async function H(t, a, l) {
47
47
  }
48
48
  }
49
49
  let N = null, k = null;
50
- const S = "@pontive/pontkit-core", W = [
51
- (t) => `https://cdn.jsdelivr.net/npm/${S}@${t}/dist/index.mjs`,
52
- (t) => `https://unpkg.com/${S}@${t}/dist/index.mjs`,
53
- (t) => `https://esm.sh/${S}@${t}/dist/index.mjs`
54
- ], q = [
55
- (t) => `https://cdn.jsdelivr.net/npm/${S}@${t}/dist/styles.css`,
56
- (t) => `https://unpkg.com/${S}@${t}/dist/styles.css`,
57
- (t) => `https://esm.sh/${S}@${t}/dist/styles.css`
58
- ], z = F;
59
- function B(t, a) {
50
+ const E = "@pontive/pontkit-core", H = [
51
+ (t) => `https://cdn.jsdelivr.net/npm/${E}@${t}/dist/index.mjs`,
52
+ (t) => `https://unpkg.com/${E}@${t}/dist/index.mjs`,
53
+ (t) => `https://esm.sh/${E}@${t}/dist/index.mjs`
54
+ ], W = [
55
+ (t) => `https://cdn.jsdelivr.net/npm/${E}@${t}/dist/styles.css`,
56
+ (t) => `https://unpkg.com/${E}@${t}/dist/styles.css`,
57
+ (t) => `https://esm.sh/${E}@${t}/dist/styles.css`
58
+ ], q = j;
59
+ function z(t, a) {
60
60
  return new Promise((l, f) => {
61
61
  const e = document.createElement("link");
62
62
  e.rel = "stylesheet", e.href = t, a && (e.integrity = a, e.crossOrigin = "anonymous"), e.onload = () => l(), e.onerror = (p) => f(p), document.head.appendChild(e);
63
63
  });
64
64
  }
65
- function X(t, a) {
65
+ function B(t, a) {
66
66
  return new Promise((l, f) => {
67
67
  const e = document.createElement("script");
68
68
  e.type = "module", e.src = t, e.integrity = a, e.crossOrigin = "anonymous", e.onload = () => l(), e.onerror = () => f(new Error(`core-elements module at ${t} failed to load or did not match its integrity hash`)), document.head.appendChild(e);
@@ -75,13 +75,13 @@ function X(t, a) {
75
75
  )
76
76
  );
77
77
  }
78
- async function Z() {
79
- return typeof window > "u" || typeof document > "u" ? null : window.__pontLoaded ? window.__pontCoreSdk : window.__pontLoading ? window.__pontLoading : (k || (k = J().catch((t) => {
78
+ async function X() {
79
+ return typeof window > "u" || typeof document > "u" ? null : window.__pontLoaded ? window.__pontCoreSdk : window.__pontLoading ? window.__pontLoading : (k || (k = Z().catch((t) => {
80
80
  throw k = null, window.__pontLoading = void 0, t;
81
81
  }), window.__pontLoading = k), k);
82
82
  }
83
- async function J() {
84
- const t = await D(), a = t?.core_elements_version ?? z, l = W.map((n) => n(a)), f = q.map((n) => n(a));
83
+ async function Z() {
84
+ const t = await K(), a = t?.core_elements_version ?? q, l = H.map((n) => n(a)), f = W.map((n) => n(a));
85
85
  t?.assets && (l.unshift(t.assets.js), f.unshift(t.assets.css));
86
86
  const e = t?.integrity;
87
87
  let p = null;
@@ -101,12 +101,12 @@ async function J() {
101
101
  const r = o.configure?.(...u);
102
102
  _ = !0;
103
103
  try {
104
- C.forEach(({ prop: w, args: $, resolve: A, reject: E }) => {
104
+ C.forEach(({ prop: w, args: $, resolve: A, reject: S }) => {
105
105
  try {
106
106
  const v = o[w].apply(o, $);
107
- v && typeof v.then == "function" ? v.then(A).catch(E) : A(v);
108
- } catch (b) {
109
- E(b);
107
+ v && typeof v.then == "function" ? v.then(A).catch(S) : A(v);
108
+ } catch (M) {
109
+ S(M);
110
110
  }
111
111
  });
112
112
  } catch {
@@ -145,8 +145,8 @@ async function J() {
145
145
  try {
146
146
  C.forEach(({ prop: u, args: r, resolve: w, reject: $ }) => {
147
147
  try {
148
- const E = i[u].apply(i, r);
149
- E && typeof E.then == "function" ? E.then(w).catch($) : w(E);
148
+ const S = i[u].apply(i, r);
149
+ S && typeof S.then == "function" ? S.then(w).catch($) : w(S);
150
150
  } catch (A) {
151
151
  $(A);
152
152
  }
@@ -214,20 +214,20 @@ async function J() {
214
214
  }
215
215
  return y;
216
216
  };
217
- await B(O, e?.css);
218
- const L = e ? await X(g, e.js) : await import(
217
+ await z(O, e?.css);
218
+ const T = e ? await B(g, e.js) : await import(
219
219
  /* webpackIgnore: true */
220
220
  /* turbopackIgnore: true */
221
221
  /* @vite-ignore */
222
222
  g
223
- ), j = L.useAuthProvider?.(), R = P(j);
223
+ ), U = T.useAuthProvider?.(), I = P(U);
224
224
  try {
225
- L.Auth = R, L.useAuthProvider = () => R;
225
+ T.Auth = I, T.useAuthProvider = () => I;
226
226
  } catch {
227
227
  }
228
228
  window.__pontCoreSdk = {
229
- ...L,
230
- Auth: R
229
+ ...T,
230
+ Auth: I
231
231
  }, N = window.__pontCoreSdk, window.__pontLoaded = !0, window.__pontLoading = void 0;
232
232
  try {
233
233
  const i = (C) => {
@@ -288,24 +288,24 @@ async function J() {
288
288
  p
289
289
  ), p;
290
290
  }
291
- let T = null;
291
+ let L = null;
292
292
  async function Q() {
293
- typeof window > "u" || window.__pontCoreSdk?.openAccountSettingsModal || (T || (T = Z().then(() => {
293
+ typeof window > "u" || window.__pontCoreSdk?.openAccountSettingsModal || (L || (L = X().then(() => {
294
294
  window.__pontCoreSdk?.openAccountSettingsModal || console.warn(
295
295
  "[pontive-react] Core sdk loaded but modal functions are missing."
296
296
  );
297
297
  }).catch((t) => {
298
298
  throw console.error("[pontive-react] Failed to load core SDK:", t), t;
299
- })), await T);
299
+ })), await L);
300
300
  }
301
301
  export {
302
- F as CORE_ELEMENTS_VERSION,
303
- U as RUNTIME_CONFIG_PATHS,
304
- x as RUNTIME_CONFIG_TIMEOUT_MS,
302
+ j as CORE_ELEMENTS_VERSION,
303
+ F as RUNTIME_CONFIG_PATHS,
304
+ J as RUNTIME_CONFIG_TIMEOUT_MS,
305
305
  Q as ensureCoreSdkLoaded,
306
- D as fetchRuntimeConfig,
307
- K as isExactVersion,
308
- M as isSriHash,
309
- Z as loadWebComponents
306
+ K as fetchRuntimeConfig,
307
+ V as isExactVersion,
308
+ b as isSriHash,
309
+ X as loadWebComponents
310
310
  };
311
311
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/core-elements-version.ts","../src/runtime-config.ts","../src/load-web-components.ts","../src/sdk-loaded.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/core-elements-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 CORE_ELEMENTS_VERSION: string = __CORE_ELEMENTS_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// (CORE_ELEMENTS_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 (`/__auth/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 core_elements_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 \"/__auth/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.core_elements_version)) return null;\n\n const config: RuntimeConfig = {\n core_elements_version: body.core_elements_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 { CORE_ELEMENTS_VERSION } from \"./core-elements-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet coreSdk: 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 `coreSdk` while it was still null, log that the\n// SDK's modal functions were missing, and carry on as if 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. CORE_ELEMENTS_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 = CORE_ELEMENTS_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(`core-elements 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.__pontCoreSdk;\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?.core_elements_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 // 2️⃣ Load CSS first\n await loadCss(cssCdn, integrity?.css);\n\n // 3️⃣ Load JS 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 // 4️⃣ Expose globally\n // Wrap Auth so calls made before `configure()` won't throw. Instead\n // we queue them and flush once configure() is called by the provider.\n function createSafeAuth(auth: any) {\n if (!auth) return auth;\n type QItem = {\n prop: string | symbol;\n args: any[];\n resolve: (v: any) => void;\n reject: (e: any) => void;\n };\n const queue: QItem[] = [];\n let configured = false;\n\n // Expose a configured promise and flag on the proxy so other parts\n // of the app can wait for Auth to be configured (helps avoid errors\n // thrown by custom elements that start flows on connect).\n let resolveWhenConfigured: (() => void) | null = null;\n const whenConfigured = new Promise<void>((res) => {\n resolveWhenConfigured = res;\n });\n\n const proxy = new Proxy(auth, {\n get(target, prop, receiver) {\n if (prop === \"configure\") {\n return (...args: any[]) => {\n const res = (target as any).configure?.(...args);\n configured = true;\n try {\n // flush queued calls\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (target as any)[p];\n const r = fn.apply(target, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n // ignore flushing errors\n }\n queue.length = 0;\n // mark proxy as configured and resolve the promise\n try {\n (proxy as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const val = (target as any)[prop];\n if (typeof val === \"function\") {\n return (...args: any[]) => {\n if (!configured) {\n // queue the call and return a Promise that resolves when flushed\n return new Promise((resolve, reject) => {\n queue.push({ prop, args, resolve, reject });\n });\n }\n try {\n return val.apply(target, args);\n } catch (e) {\n // preserve throwing behavior for already-configured\n throw e;\n }\n };\n }\n return val;\n },\n });\n\n // Attach the whenConfigured promise and configured flag to the proxy\n try {\n (proxy as any).__whenConfigured = whenConfigured;\n (proxy as any).__configured = configured;\n } catch (e) {\n /* ignore */\n }\n\n // Also patch the original `auth` object (if present) so that direct\n // imports and in-module usages get queued behavior too. This ensures\n // that calls like `Auth.startLoginflow()` won't throw even if they\n // happen before `configure()` is invoked.\n try {\n // Mark the original with the same hooks\n (auth as any).__whenConfigured = whenConfigured;\n (auth as any).__configured = configured;\n\n const origConfigure = (auth as any).configure;\n if (typeof origConfigure === \"function\") {\n (auth as any).configure = (...args: any[]) => {\n const res = origConfigure.apply(auth, args);\n configured = true;\n try {\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (auth as any)[p];\n const r = fn.apply(auth, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n /* ignore */\n }\n queue.length = 0;\n try {\n (auth as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const origStart = (auth as any).startLoginflow;\n if (typeof origStart === \"function\") {\n (auth as any).startLoginflow = (...args: any[]) => {\n if (!configured) {\n return new Promise((resolve, reject) => {\n whenConfigured\n .then(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n })\n .catch(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n });\n }\n\n return origStart.apply(auth, args);\n };\n }\n } catch (e) {\n /* ignore */\n }\n\n // When auth is configured, call an explicit retry method on any\n // sign-in/up elements that implement it. Prefer an explicit retry\n // API so elements can be idempotent and avoid duplicate flows.\n try {\n whenConfigured.then(() => {\n setTimeout(() => {\n try {\n document\n .querySelectorAll(\"pont-signin, pont-signup\")\n .forEach((el) => {\n try {\n if ((el as any).__pontInitRetried) return;\n (el as any).__pontInitRetried = true;\n // Prefer an explicit retry API implemented by the element\n // (e.g., `__pontRetryInit`) to avoid re-running the\n // entire `connectedCallback` which may cause duplicates.\n const retry = (el as any).__pontRetryInit;\n if (typeof retry === \"function\") {\n try {\n retry.call(el);\n } catch (e) {\n console.error(e);\n }\n return;\n }\n\n // Fallback: only call connectedCallback if the element\n // provides an explicit flag saying it previously failed\n // due to missing Auth (set by our connectedCallback wrapper\n // when we detect that specific error).\n if ((el as any).__pontFailedForConfig) {\n try {\n (el as any).connectedCallback?.();\n } catch (e) {\n console.error(e);\n }\n }\n } catch (_) {\n // ignore per-element errors\n }\n });\n } catch (_) {\n /* ignore */\n }\n }, 0);\n });\n } catch (e) {\n /* ignore */\n }\n\n return proxy;\n }\n\n // Replace module exports so consumers that import `Auth` directly\n // get the safe proxy as well. Also ensure `useAuthProvider()` returns\n // the proxy.\n const realAuth = module.useAuthProvider?.();\n const safeAuth = createSafeAuth(realAuth);\n\n try {\n (module as any).Auth = safeAuth;\n (module as any).useAuthProvider = () => safeAuth;\n } catch (e) {\n /* ignore */\n }\n\n window.__pontCoreSdk = {\n ...module,\n Auth: safeAuth,\n };\n\n coreSdk = window.__pontCoreSdk;\n\n // Set only once the SDK is actually on the window, so a copy of this\n // package that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n // Patch known elements that may start flows on connect so they wait\n // for Auth to be configured instead of throwing. This avoids noisy\n // runtime errors like \"Auth.configure() must be called\".\n try {\n const patchElement = (tagName: string) => {\n const ctor = customElements.get(tagName);\n if (!ctor) return;\n const proto = ctor.prototype as any;\n if (proto.__pontConfiguredPatched) return;\n proto.__pontConfiguredPatched = true;\n\n const orig = proto.connectedCallback;\n if (typeof orig !== \"function\") return;\n\n proto.connectedCallback = function (...args: any[]) {\n const auth = window.__pontCoreSdk?.Auth as any;\n const whenConfigured = auth?.__whenConfigured as\n | Promise<void>\n | undefined;\n const configured = !!auth?.__configured;\n\n if (whenConfigured && !configured) {\n // delay initial connect work until Auth is configured\n whenConfigured\n .then(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n })\n .catch(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n });\n return;\n }\n\n try {\n orig.apply(this, args);\n } catch (e: any) {\n // If it still throws with the configure error, retry after configured\n if (\n e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"Auth.configure() must be called\") &&\n whenConfigured\n ) {\n whenConfigured.then(() => {\n try {\n orig.apply(this, args);\n } catch (err) {\n console.error(err);\n }\n });\n return;\n }\n throw e;\n }\n };\n };\n\n // Elements known to start auth flows on connect\n [\"pont-signin\", \"pont-signup\"].forEach(patchElement);\n } catch (e) {\n /* ignore patch errors */\n }\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return coreSdk;\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","import { loadWebComponents } from \"./load-web-components\";\n\nlet coreSdkLoadPromise: Promise<void> | null = null;\n\n/**\n * Ensures the core SDK is loaded and the global functions are available.\n * Returns a promise that resolves when the SDK is ready.\n */\nexport async function ensureCoreSdkLoaded(): Promise<void> {\n // Nothing to ensure without a browser, and the check below would throw before\n // reaching loadWebComponents' own guard.\n if (typeof window === \"undefined\") {\n return;\n }\n\n // If the functions already exist, we're done.\n if (window.__pontCoreSdk?.openAccountSettingsModal) {\n return;\n }\n\n // Otherwise, start loading the SDK if not already loading.\n if (!coreSdkLoadPromise) {\n coreSdkLoadPromise = loadWebComponents()\n .then(() => {\n // The first SDK script attaches the functions synchronously when it executes.\n if (!window.__pontCoreSdk?.openAccountSettingsModal) {\n console.warn(\n \"[pontive-react] Core sdk loaded but modal functions are missing.\",\n );\n }\n })\n .catch((err) => {\n console.error(\"[pontive-react] Failed to load core SDK:\", err);\n throw err;\n });\n }\n\n await coreSdkLoadPromise;\n}\n"],"names":["CORE_ELEMENTS_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","coreSdk","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","createSafeAuth","auth","queue","configured","resolveWhenConfigured","whenConfigured","res","proxy","target","prop","receiver","args","p","a","r","val","e","origConfigure","origStart","el","retry","module","realAuth","safeAuth","patchElement","tagName","ctor","proto","orig","coreSdkLoadPromise","ensureCoreSdkLoaded"],"mappings":"AAcO,MAAMA,IAAgC,2BCgBhCC,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,IAAq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AAA,QACF;AAGA,SAAC,eAAe,aAAa,EAAE,QAAQQ,CAAY;AAAA,MACrD,QAAY;AAAA,MAEZ;AAEA,qBAAQ;AAAA,QACN,kCAAkChC,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;ACjgBA,IAAIiC,IAA2C;AAM/C,eAAsBC,IAAqC;AAGzD,EAAI,OAAO,SAAW,OAKlB,OAAO,eAAe,6BAKrBD,MACHA,IAAqBxC,IAClB,KAAK,MAAM;AAEV,IAAK,OAAO,eAAe,4BACzB,QAAQ;AAAA,MACN;AAAA,IAAA;AAAA,EAGN,CAAC,EACA,MAAM,CAACH,MAAQ;AACd,kBAAQ,MAAM,4CAA4CA,CAAG,GACvDA;AAAA,EACR,CAAC,IAGL,MAAM2C;AACR;"}
1
+ {"version":3,"file":"index.js","sources":["../src/core-elements-version.ts","../src/runtime-config.ts","../src/load-web-components.ts","../src/sdk-loaded.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/core-elements-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 CORE_ELEMENTS_VERSION: string = __CORE_ELEMENTS_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// (CORE_ELEMENTS_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 (`/__auth/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 core_elements_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 \"/__auth/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.core_elements_version)) return null;\n\n const config: RuntimeConfig = {\n core_elements_version: body.core_elements_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 { CORE_ELEMENTS_VERSION } from \"./core-elements-version\";\nimport { fetchRuntimeConfig } from \"./runtime-config\";\n\nlet coreSdk: 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 `coreSdk` while it was still null, log that the\n// SDK's modal functions were missing, and carry on as if 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. CORE_ELEMENTS_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 = CORE_ELEMENTS_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(`core-elements 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.__pontCoreSdk;\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?.core_elements_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 // 2️⃣ Load CSS first\n await loadCss(cssCdn, integrity?.css);\n\n // 3️⃣ Load JS 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 // 4️⃣ Expose globally\n // Wrap Auth so calls made before `configure()` won't throw. Instead\n // we queue them and flush once configure() is called by the provider.\n function createSafeAuth(auth: any) {\n if (!auth) return auth;\n type QItem = {\n prop: string | symbol;\n args: any[];\n resolve: (v: any) => void;\n reject: (e: any) => void;\n };\n const queue: QItem[] = [];\n let configured = false;\n\n // Expose a configured promise and flag on the proxy so other parts\n // of the app can wait for Auth to be configured (helps avoid errors\n // thrown by custom elements that start flows on connect).\n let resolveWhenConfigured: (() => void) | null = null;\n const whenConfigured = new Promise<void>((res) => {\n resolveWhenConfigured = res;\n });\n\n const proxy = new Proxy(auth, {\n get(target, prop, receiver) {\n if (prop === \"configure\") {\n return (...args: any[]) => {\n const res = (target as any).configure?.(...args);\n configured = true;\n try {\n // flush queued calls\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (target as any)[p];\n const r = fn.apply(target, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n // ignore flushing errors\n }\n queue.length = 0;\n // mark proxy as configured and resolve the promise\n try {\n (proxy as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const val = (target as any)[prop];\n if (typeof val === \"function\") {\n return (...args: any[]) => {\n if (!configured) {\n // queue the call and return a Promise that resolves when flushed\n return new Promise((resolve, reject) => {\n queue.push({ prop, args, resolve, reject });\n });\n }\n try {\n return val.apply(target, args);\n } catch (e) {\n // preserve throwing behavior for already-configured\n throw e;\n }\n };\n }\n return val;\n },\n });\n\n // Attach the whenConfigured promise and configured flag to the proxy\n try {\n (proxy as any).__whenConfigured = whenConfigured;\n (proxy as any).__configured = configured;\n } catch (e) {\n /* ignore */\n }\n\n // Also patch the original `auth` object (if present) so that direct\n // imports and in-module usages get queued behavior too. This ensures\n // that calls like `Auth.startLoginflow()` won't throw even if they\n // happen before `configure()` is invoked.\n try {\n // Mark the original with the same hooks\n (auth as any).__whenConfigured = whenConfigured;\n (auth as any).__configured = configured;\n\n const origConfigure = (auth as any).configure;\n if (typeof origConfigure === \"function\") {\n (auth as any).configure = (...args: any[]) => {\n const res = origConfigure.apply(auth, args);\n configured = true;\n try {\n queue.forEach(({ prop: p, args: a, resolve, reject }) => {\n try {\n const fn = (auth as any)[p];\n const r = fn.apply(auth, a);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n } catch (e) {\n /* ignore */\n }\n queue.length = 0;\n try {\n (auth as any).__configured = true;\n } catch (e) {\n /* ignore */\n }\n resolveWhenConfigured?.();\n return res;\n };\n }\n\n const origStart = (auth as any).startLoginflow;\n if (typeof origStart === \"function\") {\n (auth as any).startLoginflow = (...args: any[]) => {\n if (!configured) {\n return new Promise((resolve, reject) => {\n whenConfigured\n .then(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n })\n .catch(() => {\n try {\n const r = origStart.apply(auth, args);\n if (r && typeof r.then === \"function\") {\n r.then(resolve).catch(reject);\n } else {\n resolve(r);\n }\n } catch (err) {\n reject(err);\n }\n });\n });\n }\n\n return origStart.apply(auth, args);\n };\n }\n } catch (e) {\n /* ignore */\n }\n\n // When auth is configured, call an explicit retry method on any\n // sign-in/up elements that implement it. Prefer an explicit retry\n // API so elements can be idempotent and avoid duplicate flows.\n try {\n whenConfigured.then(() => {\n setTimeout(() => {\n try {\n document\n .querySelectorAll(\"pont-signin, pont-signup\")\n .forEach((el) => {\n try {\n if ((el as any).__pontInitRetried) return;\n (el as any).__pontInitRetried = true;\n // Prefer an explicit retry API implemented by the element\n // (e.g., `__pontRetryInit`) to avoid re-running the\n // entire `connectedCallback` which may cause duplicates.\n const retry = (el as any).__pontRetryInit;\n if (typeof retry === \"function\") {\n try {\n retry.call(el);\n } catch (e) {\n console.error(e);\n }\n return;\n }\n\n // Fallback: only call connectedCallback if the element\n // provides an explicit flag saying it previously failed\n // due to missing Auth (set by our connectedCallback wrapper\n // when we detect that specific error).\n if ((el as any).__pontFailedForConfig) {\n try {\n (el as any).connectedCallback?.();\n } catch (e) {\n console.error(e);\n }\n }\n } catch (_) {\n // ignore per-element errors\n }\n });\n } catch (_) {\n /* ignore */\n }\n }, 0);\n });\n } catch (e) {\n /* ignore */\n }\n\n return proxy;\n }\n\n // Replace module exports so consumers that import `Auth` directly\n // get the safe proxy as well. Also ensure `useAuthProvider()` returns\n // the proxy.\n const realAuth = module.useAuthProvider?.();\n const safeAuth = createSafeAuth(realAuth);\n\n try {\n (module as any).Auth = safeAuth;\n (module as any).useAuthProvider = () => safeAuth;\n } catch (e) {\n /* ignore */\n }\n\n window.__pontCoreSdk = {\n ...module,\n Auth: safeAuth,\n };\n\n coreSdk = window.__pontCoreSdk;\n\n // Set only once the SDK is actually on the window, so a copy of this\n // package that sees the flag can trust what it reads next to it.\n window.__pontLoaded = true;\n window.__pontLoading = undefined;\n\n // Patch known elements that may start flows on connect so they wait\n // for Auth to be configured instead of throwing. This avoids noisy\n // runtime errors like \"Auth.configure() must be called\".\n try {\n const patchElement = (tagName: string) => {\n const ctor = customElements.get(tagName);\n if (!ctor) return;\n const proto = ctor.prototype as any;\n if (proto.__pontConfiguredPatched) return;\n proto.__pontConfiguredPatched = true;\n\n const orig = proto.connectedCallback;\n if (typeof orig !== \"function\") return;\n\n proto.connectedCallback = function (...args: any[]) {\n const auth = window.__pontCoreSdk?.Auth as any;\n const whenConfigured = auth?.__whenConfigured as\n | Promise<void>\n | undefined;\n const configured = !!auth?.__configured;\n\n if (whenConfigured && !configured) {\n // delay initial connect work until Auth is configured\n whenConfigured\n .then(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n })\n .catch(() => {\n try {\n orig.apply(this, args);\n } catch (e) {\n console.error(e);\n }\n });\n return;\n }\n\n try {\n orig.apply(this, args);\n } catch (e: any) {\n // If it still throws with the configure error, retry after configured\n if (\n e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"Auth.configure() must be called\") &&\n whenConfigured\n ) {\n whenConfigured.then(() => {\n try {\n orig.apply(this, args);\n } catch (err) {\n console.error(err);\n }\n });\n return;\n }\n throw e;\n }\n };\n };\n\n // Elements known to start auth flows on connect\n [\"pont-signin\", \"pont-signup\"].forEach(patchElement);\n } catch (e) {\n /* ignore patch errors */\n }\n\n console.log(\n `PontKit Web Components loaded (${resolvedVersion}) from:`,\n cdn,\n );\n\n return coreSdk;\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","import { loadWebComponents } from \"./load-web-components\";\n\nlet coreSdkLoadPromise: Promise<void> | null = null;\n\n/**\n * Ensures the core SDK is loaded and the global functions are available.\n * Returns a promise that resolves when the SDK is ready.\n */\nexport async function ensureCoreSdkLoaded(): Promise<void> {\n // Nothing to ensure without a browser, and the check below would throw before\n // reaching loadWebComponents' own guard.\n if (typeof window === \"undefined\") {\n return;\n }\n\n // If the functions already exist, we're done.\n if (window.__pontCoreSdk?.openAccountSettingsModal) {\n return;\n }\n\n // Otherwise, start loading the SDK if not already loading.\n if (!coreSdkLoadPromise) {\n coreSdkLoadPromise = loadWebComponents()\n .then(() => {\n // The first SDK script attaches the functions synchronously when it executes.\n if (!window.__pontCoreSdk?.openAccountSettingsModal) {\n console.warn(\n \"[pontive-react] Core sdk loaded but modal functions are missing.\",\n );\n }\n })\n .catch((err) => {\n console.error(\"[pontive-react] Failed to load core SDK:\", err);\n throw err;\n });\n }\n\n await coreSdkLoadPromise;\n}\n"],"names":["CORE_ELEMENTS_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","coreSdk","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","createSafeAuth","auth","queue","configured","resolveWhenConfigured","whenConfigured","res","proxy","target","prop","receiver","args","p","a","r","val","e","origConfigure","origStart","el","retry","module","realAuth","safeAuth","patchElement","tagName","ctor","proto","orig","coreSdkLoadPromise","ensureCoreSdkLoaded"],"mappings":"AAcO,MAAMA,IAAgC,SCgBhCC,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,GACAD,GAC+B;AAC/B,QAAMI,IAAa,OAAO,mBAAoB,aAAa,IAAI,oBAAoB,MAC7EC,IAAQD,IAAa,WAAW,MAAMA,EAAW,MAAA,GAASJ,CAAS,IAAI;AAE7E,MAAI;AACF,UAAMM,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AA4CA,CAAG,GACvDA;AAAA,EACR,CAAC,IAGL,MAAM2C;AACR;"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The framework-neutral half of the auth proxy.
3
+ *
4
+ * An app is cross-site with its auth server unless the auth endpoints are
5
+ * served from the app's own origin, and a cross-site refresh cookie is a
6
+ * third-party cookie: dropped by Safari outright, withheld everywhere under
7
+ * SameSite=Lax. A proxy on the app's origin is what makes those cookies
8
+ * first-party.
9
+ *
10
+ * None of this is Next-specific, and the Vite adapter is here rather than in
11
+ * @pontive/pontkit-nextjs because a Vite app depending on a package named for
12
+ * another meta-framework is a wart, not a design. @pontive/pontkit-nextjs keeps
13
+ * only its own adapter and imports these primitives.
14
+ *
15
+ * Nothing here imports Vite: the proxy entry is described structurally, so a
16
+ * consumer's Vite version is not part of this package's types.
17
+ */
18
+ export { DEFAULT_BASE_PATH, DEFAULT_FORWARDED_PATHS, authOrigin, isUnder, normaliseBasePath, } from './target';
19
+ export { viteAuthProxy } from './vite';
20
+ export type { ViteAuthProxyOptions, ViteProxyEntry } from './vite';
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Where a proxied request is sent, and which requests are sent at all.
3
+ *
4
+ * Deliberately not shared with `resolveAuthBaseUrl` in the SDK, which answers a
5
+ * different question. That one resolves what the BROWSER should call and its
6
+ * most useful answer — a bare path like `/__auth` — is meaningless here: a
7
+ * proxy runs on a server, where there is no page origin for a path to be
8
+ * relative to. Sharing them would mean one function with a mode flag, and the
9
+ * mode that is wrong in either direction is silent.
10
+ */
11
+ /**
12
+ * The endpoints an app-level proxy has to carry, and the reason the list is
13
+ * short.
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
17
+ * to be same-origin, because they are the ones carrying cookies under
18
+ * `SameSite=Lax`.
19
+ *
20
+ * Everything else on the auth server is a top-level navigation — `/authorize`,
21
+ * the hosted sign-in page, `/end_session` as a redirect — and a `Lax` cookie is
22
+ * sent on those already, whatever origin they are served from. Proxying them
23
+ * would not help, and it would break: the authorization server builds those
24
+ * URLs absolute, on its own hostname, so the browser leaves the proxy at the
25
+ * first redirect anyway.
26
+ *
27
+ * The two prefixes are the same pair the dev-server proxy uses (auth-api,
28
+ * `docs/auth-domains-and-token-storage.md` §3). That is not a coincidence to be
29
+ * tidied away: local development against a shared sandbox domain is the same
30
+ * cross-site problem this solves in production, and the two configurations
31
+ * being identical is what makes the local one a rehearsal.
32
+ */
33
+ export declare const DEFAULT_FORWARDED_PATHS: readonly ["/auth/v1", "/oauth2"];
34
+ /**
35
+ * Where the endpoints hang off the app's own origin.
36
+ *
37
+ * `__`-prefixed by convention — Clerk uses `/__clerk`, Firebase `/__/auth` —
38
+ * because it has to be a path no real route of the app will ever want.
39
+ */
40
+ export declare const DEFAULT_BASE_PATH = "/__auth";
41
+ /**
42
+ * The auth server, as an origin.
43
+ *
44
+ * Accepts `tenant.idp.us.pontive.app` or `https://tenant.idp.us.pontive.app`,
45
+ * and nothing with a path: the upstream path comes from the incoming request,
46
+ * and a base path here would be silently prepended to endpoints the auth server
47
+ * does not serve.
48
+ *
49
+ * `http://` is inferred for loopback only, and accepted only there. A proxy is
50
+ * the one hop a refresh token cannot be carried over in the clear — it is the
51
+ * hop that exists precisely so the cookie is first-party — and the failure is
52
+ * invisible from the browser, which sees its own `https://` origin either way.
53
+ */
54
+ export declare function authOrigin(authHost: string): string;
55
+ /**
56
+ * A base path with a leading slash and no trailing one, so joining is
57
+ * unambiguous.
58
+ *
59
+ * `"/"` normalises to `""`, which mounts the endpoints at the origin root —
60
+ * `/auth/v1/...` and `/oauth2/...` where the app itself is served. That is the
61
+ * shape a Vite dev server has always used, and it stays available because in
62
+ * development the app owns the whole origin and there is nothing to collide
63
+ * with. A deployed app usually does not, which is what the prefix is for.
64
+ */
65
+ export declare function normaliseBasePath(basePath: string): string;
66
+ /** Whether `pathname` is `prefix` itself or something under it. */
67
+ export declare function isUnder(pathname: string, prefix: string): boolean;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The shape of one entry in Vite's `server.proxy`.
3
+ *
4
+ * Declared here rather than imported from Vite so that nothing which imports
5
+ * this module needs Vite installed, and so the published types do not depend on
6
+ * a particular version of it. It is structural: Vite accepts this object.
7
+ */
8
+ export interface ViteProxyEntry {
9
+ target: string;
10
+ changeOrigin: boolean;
11
+ rewrite: (path: string) => string;
12
+ }
13
+ export interface ViteAuthProxyOptions {
14
+ authHost: string;
15
+ basePath?: string;
16
+ paths?: readonly string[];
17
+ }
18
+ /**
19
+ * The auth endpoints, proxied through a Vite dev server.
20
+ *
21
+ * ```ts
22
+ * // vite.config.ts
23
+ * server: { proxy: viteAuthProxy({ authHost: env.VITE_SB_AUTH_DOMAIN }) }
24
+ * ```
25
+ *
26
+ * Vite already has a proxy; what it does not have is the knowledge of which
27
+ * paths to carry and what to do with Host, and both of those are easy to get
28
+ * wrong in ways that fail silently. So this is a config generator rather than a
29
+ * request handler — `createAuthProxy` is for runtimes that have no proxy of
30
+ * their own.
31
+ *
32
+ * Worth doing even where the browser would tolerate the cross-site setup,
33
+ * because it is the same topology production runs on: a dev server that proxies
34
+ * is rehearsing the deployment, and a dev server that does not is testing a
35
+ * configuration no user will ever have. It is also the only way an embedded
36
+ * sign-in flow works in Safari, which blocks third-party cookies outright.
37
+ */
38
+ export declare function viteAuthProxy(options: ViteAuthProxyOptions): Record<string, ViteProxyEntry>;
package/dist/proxy.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=["/auth/v1","/oauth2"],a="/__auth";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;
2
+ //# sourceMappingURL=proxy.cjs.map
@@ -0,0 +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 `/__auth` — 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, `/end_session` 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 = \"/__auth\";\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,UAe1B,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"}
package/dist/proxy.js ADDED
@@ -0,0 +1,58 @@
1
+ const i = ["/auth/v1", "/oauth2"], a = "/__auth";
2
+ function c(r) {
3
+ const t = (r ?? "").trim();
4
+ if (!t)
5
+ throw new TypeError("authHost is required");
6
+ const o = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/i.test(
7
+ t.replace(/^https?:\/\//i, "").split("/")[0]
8
+ ), s = /^https?:\/\//i.test(t) ? "" : `${o ? "http" : "https"}://`;
9
+ let e;
10
+ try {
11
+ e = new URL(`${s}${t}`);
12
+ } catch {
13
+ throw new TypeError(`authHost "${t}" is not a hostname or an origin`);
14
+ }
15
+ if (e.pathname !== "/" || e.search || e.hash)
16
+ throw new TypeError(
17
+ `authHost "${t}" must be a bare origin — the path comes from the request being proxied`
18
+ );
19
+ if (e.protocol !== "https:" && !o)
20
+ throw new TypeError(`authHost "${t}" must be https outside loopback`);
21
+ return e.origin;
22
+ }
23
+ function u(r) {
24
+ const t = (r ?? "").trim().replace(/\/+$/, "");
25
+ if (t === "")
26
+ return "";
27
+ if (!t.startsWith("/"))
28
+ throw new TypeError(`basePath "${r}" must start with "/"`);
29
+ return t;
30
+ }
31
+ function p(r, t) {
32
+ return r === t || r.startsWith(`${t}/`);
33
+ }
34
+ function f(r) {
35
+ const t = c(r.authHost), o = u(r.basePath ?? a), s = r.paths ?? i, e = {};
36
+ for (const h of s)
37
+ e[`${o}${h}`] = {
38
+ target: t,
39
+ // The single most important line, and the one a hand-written config
40
+ // leaves out. Without it the auth server is asked to answer as
41
+ // `localhost:5173` — a Host it has no project for — and the reply is a
42
+ // CORS refusal and an empty issuer rather than anything that says so.
43
+ changeOrigin: !0,
44
+ // Only the base path comes off. The prefix below it is the path the auth
45
+ // server actually serves.
46
+ rewrite: (n) => o ? n.replace(o, "") : n
47
+ };
48
+ return e;
49
+ }
50
+ export {
51
+ a as DEFAULT_BASE_PATH,
52
+ i as DEFAULT_FORWARDED_PATHS,
53
+ c as authOrigin,
54
+ p as isUnder,
55
+ u as normaliseBasePath,
56
+ f as viteAuthProxy
57
+ };
58
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +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 `/__auth` — 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, `/end_session` 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 = \"/__auth\";\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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pontive/pontkit-loader",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "description": "Loads @pontive/pontkit-core from the CDN at the release the platform decides.",
6
6
  "type": "module",
@@ -12,6 +12,11 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "require": "./dist/index.cjs"
15
+ },
16
+ "./proxy": {
17
+ "types": "./dist/proxy/index.d.ts",
18
+ "import": "./dist/proxy.js",
19
+ "require": "./dist/proxy.cjs"
15
20
  }
16
21
  },
17
22
  "files": [