@enbox/browser 0.3.84 → 0.3.85

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/README.md CHANGED
@@ -70,9 +70,10 @@ Before initializing the connection store, await `prepareBrowser(workerUrl,
70
70
  { registrationOptions: { type: 'module' } })` for a module worker, or pass an
71
71
  existing registration from this page's `navigator.serviceWorker` when a PWA
72
72
  tool owns registration. The helper waits for that worker to control the page
73
- and activates page polyfills, with a timeout and abort signal. It leaves update
74
- handling to the host; worker-side `activatePolyfills()` retains its existing
75
- immediate takeover behavior.
73
+ and activates page polyfills, with a timeout and abort signal. The application
74
+ owns update activation. Worker-side `activatePolyfills()` claims clients during
75
+ activation, but leaves waiting workers in place. Complete pending application
76
+ work before your update handler requests `skipWaiting()` and reloads the page.
76
77
 
77
78
  Current browser-conditioned packages work in page and worker builds without
78
79
  Enbox-specific Node-global, `process`, or IIFE shims. Follow the
package/dist/browser.mjs CHANGED
@@ -383,7 +383,7 @@ export*from"@enbox/api";import{ConnectClient as pr}from"@enbox/connect";function
383
383
  .overlay, .modal, .stage.fade-in > *, .pin-row.shake { animation: none; }
384
384
  .claimed-pulse::after { animation: none; }
385
385
  }
386
- `;var Kt=[{name:"Enbox",url:"https://enbox-wallet.pages.dev",description:"Manage your digital identity and data"},{name:"Prism",url:"https://prism-wallet.pages.dev",description:"A clear view into your digital identity"},{name:"Matcha",url:"https://matcha-wallet.pages.dev",description:"A fresh approach to digital identity"},{name:"Sumi",url:"https://sumi-wallet.pages.dev",description:"A refined home for your digital identity"},{name:"Taffy",url:"https://taffy-wallet.pages.dev",description:"A playful take on your digital identity"},{name:"Astoria",url:"https://astoria-wallet.pages.dev",description:"A grand home for your digital identity"},{name:"Quay",url:"https://quay-id.pages.dev",description:"A safe harbor for your digital identity"},{name:"Quoin",url:"https://quoin-id.pages.dev",description:"A cornerstone for your digital identity"}];function nt(t={}){let{wallets:e=Kt,walletUrl:n,timeout:r,appName:o,appIcon:i,applicationId:s,preferredMethod:a,rememberChoice:d,connectServerUrl:p,relayWalletPath:g,theme:x}=t;return{async requestAccess(C){let R=window.location.origin==="null"?window.location.href:window.location.origin;return tt({wallets:e,walletUrl:n,preferredMethod:a,rememberChoice:d,appName:o,appIcon:new URL(i??"/favicon.ico",R).href,applicationId:s,connectServerUrl:p,relayWalletPath:g,timeout:r,theme:x,mode:C.requestType,delegatePortableDid:C.delegatePortableDid,expectedProviderDid:C.expectedProviderDid,permissionRequests:C.permissionRequests})}}}import{createConnectionStore as Mr,createApplication as Ft}from"@enbox/api";var zt=new WeakMap;function Ar(t){let e={stores:t.stores,...t.protocols===void 0?{}:{protocols:t.protocols}};if(typeof t.connection=="function"){if(t.wallet!==void 0||t.connectHandler!==void 0)throw new TypeError("createApplication: a native connection factory owns its connect handler.");return Ft({...e,connection:t.connection})}if(t.wallet!==void 0&&t.connectHandler!==void 0)throw new TypeError("createApplication: choose wallet options or a connectHandler.");for(let i of["application","connectHandler","auth","agent"])if(t.connection!==void 0&&Object.hasOwn(t.connection,i))throw new TypeError(`createApplication: connection.${i} is owned by the application.`);let n=t.connectHandler===void 0?Object.freeze({...t.wallet}):void 0,r=t.connectHandler??nt(n),o=Ft({...e,connection:i=>Mr({...t.connection,application:i,connectHandler:r})});return n!==void 0&&zt.set(o,n),o}function Lr(t){return zt.get(t)}export*from"@enbox/auth/browser";import{CONNECT_DENIED_TOKEN as ei,ConnectProvider as ti}from"@enbox/connect";import{createDidDhtMethod as Or,DidDht as Gt,DidResolverCacheMemory as Jt,DidWeb as Qt,resolveDwnEndpointStatus as Wr,UniversalResolver as Xt}from"@enbox/dids";function pe(t){let e=t.indexOf("://dweb/");if(e===-1)return null;let n=t.slice(0,e);if(n!=="http"&&n!=="https")return null;let r=t.slice(e+8);if(r.length===0)return null;let o=r.indexOf("/");return o===-1?[r,""]:o===0?null:[r.slice(0,o),r.slice(o+1)]}var rt=new Xt({didResolvers:[Gt,Qt],cache:new Jt});function Ur({didDhtNetwork:t,didResolvers:e}){if(e!==void 0&&t!==void 0)throw new Error("activatePolyfills: didDhtNetwork cannot be combined with didResolvers. Configure the resolver list directly.");if(e===void 0&&t===void 0)return;let n=t===void 0?Gt:Or(t);rt=new Xt({didResolvers:e??[n,Qt],cache:new Jt})}var Vt=/^http:/,Le=/\/$/,Zt="drl";async function en(t){let e=await Wr(t,rt);return e.status==="ready"?e.endpoints:[]}async function tn(){if(!(typeof caches>"u"))return caches.open(Zt)}async function qr(t,e,n,r){let o=t.request.url.replace(Vt,"https:").replace(Le,""),i=await tn(),s=await i?.match(o);if(s){if(!navigator.onLine)return s;let a=await r?.onCacheCheck?.(t,o);if(a){let d=s.headers.get("dwn-cache-time");if(d&&Date.now()<Number(d)+(Number(a.ttl)||0))return s}}try{if(n)return await Nr(t,e,o,n,i,r);{let a=await rt.resolve(e);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})}}catch(a){return a instanceof Response?a:(console.log(`Error in DID URL fetch: ${a}`),new Response("DID URL fetch error",{status:500}))}}async function Nr(t,e,n,r,o,i){let s=await en(e);if(!s?.length)throw new Response("DWeb Node resolution failed: no valid endpoints found.",{status:530});let a;for(let d of s)try{let p=`${d.replace(Le,"")}/${e}/${r}`,g=await fetch(p,{headers:t.request.headers});if(g.ok)return await i?.onCacheCheck?.(t,n)&&o&&Ir(n,p,g,o),g;console.log(`DWN endpoint error: ${g.status}`),a=new Response("DWeb Node request failed",{status:g.status})}catch(p){console.log(`DWN endpoint error: ${p}`),a=new Response("DWeb Node request failed",{status:500})}return a}async function Ir(t,e,n,r){try{let o=n.clone(),i=new Headers(o.headers);i.append("dwn-cache-time",Date.now().toString()),i.append("dwn-composed-url",e);let s=new Response(o.body,{headers:i});await r.put(t,s)}catch(o){console.log(`Failed to cache DRL response: ${o}`)}}async function Br(t={}){try{if(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope){let e=self;e.skipWaiting(),e.addEventListener("activate",n=>{n.waitUntil(e.clients.claim())}),e.addEventListener("fetch",n=>{let r=pe(n.request.url);r&&n.respondWith(qr(n,r[0],r[1],t))})}else if(globalThis?.navigator?.serviceWorker){if(!await navigator.serviceWorker.getRegistration("/")){let n=t.path||document?.currentScript?.src||import.meta.url;n&&navigator.serviceWorker.register(n,{type:"module"}).catch(r=>{console.error("DWeb networking feature installation failed: ",r)})}}else throw new Error("DWeb networking features are not available for install in this environment")}catch(e){console.error("Error in installing networking features:",e)}}var nn=`
386
+ `;var Kt=[{name:"Enbox",url:"https://enbox-wallet.pages.dev",description:"Manage your digital identity and data"},{name:"Prism",url:"https://prism-wallet.pages.dev",description:"A clear view into your digital identity"},{name:"Matcha",url:"https://matcha-wallet.pages.dev",description:"A fresh approach to digital identity"},{name:"Sumi",url:"https://sumi-wallet.pages.dev",description:"A refined home for your digital identity"},{name:"Taffy",url:"https://taffy-wallet.pages.dev",description:"A playful take on your digital identity"},{name:"Astoria",url:"https://astoria-wallet.pages.dev",description:"A grand home for your digital identity"},{name:"Quay",url:"https://quay-id.pages.dev",description:"A safe harbor for your digital identity"},{name:"Quoin",url:"https://quoin-id.pages.dev",description:"A cornerstone for your digital identity"}];function nt(t={}){let{wallets:e=Kt,walletUrl:n,timeout:r,appName:o,appIcon:i,applicationId:s,preferredMethod:a,rememberChoice:d,connectServerUrl:p,relayWalletPath:g,theme:x}=t;return{async requestAccess(C){let R=window.location.origin==="null"?window.location.href:window.location.origin;return tt({wallets:e,walletUrl:n,preferredMethod:a,rememberChoice:d,appName:o,appIcon:new URL(i??"/favicon.ico",R).href,applicationId:s,connectServerUrl:p,relayWalletPath:g,timeout:r,theme:x,mode:C.requestType,delegatePortableDid:C.delegatePortableDid,expectedProviderDid:C.expectedProviderDid,permissionRequests:C.permissionRequests})}}}import{createConnectionStore as Mr,createApplication as Ft}from"@enbox/api";var zt=new WeakMap;function Ar(t){let e={stores:t.stores,...t.protocols===void 0?{}:{protocols:t.protocols}};if(typeof t.connection=="function"){if(t.wallet!==void 0||t.connectHandler!==void 0)throw new TypeError("createApplication: a native connection factory owns its connect handler.");return Ft({...e,connection:t.connection})}if(t.wallet!==void 0&&t.connectHandler!==void 0)throw new TypeError("createApplication: choose wallet options or a connectHandler.");for(let i of["application","connectHandler","auth","agent"])if(t.connection!==void 0&&Object.hasOwn(t.connection,i))throw new TypeError(`createApplication: connection.${i} is owned by the application.`);let n=t.connectHandler===void 0?Object.freeze({...t.wallet}):void 0,r=t.connectHandler??nt(n),o=Ft({...e,connection:i=>Mr({...t.connection,application:i,connectHandler:r})});return n!==void 0&&zt.set(o,n),o}function Lr(t){return zt.get(t)}export*from"@enbox/auth/browser";import{CONNECT_DENIED_TOKEN as ei,ConnectProvider as ti}from"@enbox/connect";import{createDidDhtMethod as Or,DidDht as Gt,DidResolverCacheMemory as Jt,DidWeb as Qt,resolveDwnEndpointStatus as Wr,UniversalResolver as Xt}from"@enbox/dids";function pe(t){let e=t.indexOf("://dweb/");if(e===-1)return null;let n=t.slice(0,e);if(n!=="http"&&n!=="https")return null;let r=t.slice(e+8);if(r.length===0)return null;let o=r.indexOf("/");return o===-1?[r,""]:o===0?null:[r.slice(0,o),r.slice(o+1)]}var rt=new Xt({didResolvers:[Gt,Qt],cache:new Jt});function Ur({didDhtNetwork:t,didResolvers:e}){if(e!==void 0&&t!==void 0)throw new Error("activatePolyfills: didDhtNetwork cannot be combined with didResolvers. Configure the resolver list directly.");if(e===void 0&&t===void 0)return;let n=t===void 0?Gt:Or(t);rt=new Xt({didResolvers:e??[n,Qt],cache:new Jt})}var Vt=/^http:/,Le=/\/$/,Zt="drl";async function en(t){let e=await Wr(t,rt);return e.status==="ready"?e.endpoints:[]}async function tn(){if(!(typeof caches>"u"))return caches.open(Zt)}async function qr(t,e,n,r){let o=t.request.url.replace(Vt,"https:").replace(Le,""),i=await tn(),s=await i?.match(o);if(s){if(!navigator.onLine)return s;let a=await r?.onCacheCheck?.(t,o);if(a){let d=s.headers.get("dwn-cache-time");if(d&&Date.now()<Number(d)+(Number(a.ttl)||0))return s}}try{if(n)return await Nr(t,e,o,n,i,r);{let a=await rt.resolve(e);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})}}catch(a){return a instanceof Response?a:(console.log(`Error in DID URL fetch: ${a}`),new Response("DID URL fetch error",{status:500}))}}async function Nr(t,e,n,r,o,i){let s=await en(e);if(!s?.length)throw new Response("DWeb Node resolution failed: no valid endpoints found.",{status:530});let a;for(let d of s)try{let p=`${d.replace(Le,"")}/${e}/${r}`,g=await fetch(p,{headers:t.request.headers});if(g.ok)return await i?.onCacheCheck?.(t,n)&&o&&Ir(n,p,g,o),g;console.log(`DWN endpoint error: ${g.status}`),a=new Response("DWeb Node request failed",{status:g.status})}catch(p){console.log(`DWN endpoint error: ${p}`),a=new Response("DWeb Node request failed",{status:500})}return a}async function Ir(t,e,n,r){try{let o=n.clone(),i=new Headers(o.headers);i.append("dwn-cache-time",Date.now().toString()),i.append("dwn-composed-url",e);let s=new Response(o.body,{headers:i});await r.put(t,s)}catch(o){console.log(`Failed to cache DRL response: ${o}`)}}async function Br(t={}){try{if(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope){let e=self;e.addEventListener("activate",n=>{n.waitUntil(e.clients.claim())}),e.addEventListener("fetch",n=>{let r=pe(n.request.url);r&&n.respondWith(qr(n,r[0],r[1],t))})}else if(globalThis?.navigator?.serviceWorker){if(!await navigator.serviceWorker.getRegistration("/")){let n=t.path||document?.currentScript?.src||import.meta.url;n&&navigator.serviceWorker.register(n,{type:"module"}).catch(r=>{console.error("DWeb networking feature installation failed: ",r)})}}else throw new Error("DWeb networking features are not available for install in this environment")}catch(e){console.error("Error in installing networking features:",e)}}var nn=`
387
387
  .drl-loading-overlay {
388
388
  position: fixed;
389
389
  inset: 0;