@fkn/lib 0.9.57 → 0.9.58
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/{account-generation-ORsS9Z2F.js → account-generation-2ZvMy2tZ.js} +1 -1
- package/{account-generation-B6qSQaTA.cjs → account-generation-DIsOqkSQ.cjs} +1 -1
- package/{account-storage-Bi47np3p.cjs → account-storage-CPTct4Vz.cjs} +1 -1
- package/{account-storage-CVlvzWav.js → account-storage-Cmzz-67T.js} +2 -2
- package/account.cjs +1 -1
- package/account.d.ts +1 -1
- package/account.js +2 -2
- package/{api-DTJ5gCWb.d.ts → api-BD_XUANc.d.ts} +24 -1
- package/{api-DvS3QcoU.js → api-C-N5AVos.js} +4 -4
- package/{api-CNYWAaFu.cjs → api-ibGqkmtA.cjs} +1 -1
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -1
- package/cloud/dns.d.ts +1 -1
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -1
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.js +1 -1
- package/cloud/net.d.ts +1 -1
- package/{cloud-zSEiIhvg.js → cloud-B6B2XcRU.js} +205 -184
- package/{cloud-DdAgVqlV.d.ts → cloud-BEoUa04G.d.ts} +3 -3
- package/cloud-C0hcBrFd.cjs +1 -0
- package/cloud.cjs +1 -1
- package/cloud.d.ts +3 -3
- package/cloud.js +2 -2
- package/{contract-t5YLkrMK.d.ts → contract-B8Rqx5BD.d.ts} +43 -3
- package/contract.cjs +1 -1
- package/contract.d.ts +3 -3
- package/contract.js +2 -2
- package/dgram.cjs +1 -1
- package/dgram.d.ts +10 -5
- package/dgram.js +64 -60
- package/dns.cjs +1 -1
- package/dns.d.ts +1 -1
- package/dns.js +1 -1
- package/extension-AidgSVhb.js +101 -0
- package/{extension-kE9yzbkW.d.ts → extension-C_eOfEjv.d.ts} +3 -2
- package/extension-M8bUhlML.cjs +1 -0
- package/extension.cjs +1 -1
- package/extension.d.ts +3 -3
- package/extension.js +1 -1
- package/fs/promises.cjs +1 -1
- package/fs/promises.js +1 -1
- package/{fs-igMZHzs7.cjs → fs-BlRxCJQW.cjs} +1 -1
- package/{fs-dqvJytOJ.js → fs-C_RmxWk9.js} +2 -2
- package/fs.cjs +1 -1
- package/fs.js +2 -2
- package/http.cjs +1 -1
- package/http.d.ts +4 -1
- package/http.js +2 -1
- package/{index-BQ5OZQhf.d.ts → index-C5DdoMGo.d.ts} +38 -1
- package/index.cjs +1 -1
- package/index.d.ts +7 -5
- package/index.js +53 -51
- package/{net-C94nCjW2.d.ts → net-CvJwokcz.d.ts} +14 -7
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +52 -46
- package/package.json +1 -1
- package/packages.cjs +1 -1
- package/packages.d.ts +1 -1
- package/packages.js +1 -1
- package/proxy-C1RlnrDC.js +61 -0
- package/proxy-CII2NFYV.cjs +1 -0
- package/{proxy-C-Y5NiAa.d.ts → proxy-z0Y8IgW7.d.ts} +2 -2
- package/relay-choice-BGwXRC5d.js +14 -0
- package/relay-choice-BmXlqfD2.d.ts +28 -0
- package/relay-choice-JC_JJY_M.cjs +1 -0
- package/rooms.cjs +1 -1
- package/rooms.d.ts +1 -1
- package/rooms.js +1 -1
- package/storage.cjs +1 -1
- package/storage.d.ts +1 -1
- package/storage.js +3 -3
- package/cloud-V4wvwQaO.cjs +0 -1
- package/extension-52n-tLJd.cjs +0 -1
- package/extension-DPNgKyHp.js +0 -95
- package/proxy-Cp9iO8Wr.js +0 -60
- package/proxy-D9PZwEZJ.cjs +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as AttachFrameFunction } from "./index-
|
|
2
|
-
import { t as cloudFetch } from "./proxy-
|
|
1
|
+
import { r as AttachFrameFunction } from "./index-C5DdoMGo.js";
|
|
2
|
+
import { t as cloudFetch } from "./proxy-z0Y8IgW7.js";
|
|
3
3
|
import { t as dns_d_exports } from "./dns.js";
|
|
4
4
|
import { n as fs_d_exports } from "./fs-DCJAYoYy.js";
|
|
5
|
-
import { s as net_d_exports } from "./net-
|
|
5
|
+
import { s as net_d_exports } from "./net-CvJwokcz.js";
|
|
6
6
|
import { t as dgram_d_exports } from "./dgram.js";
|
|
7
7
|
import { t as http_d_exports } from "./http.js";
|
|
8
8
|
//#region src/cloud/frame.d.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./lib-BiQ6cOZ7.cjs"),n=require("./hosts-GNBhZO3-.cjs"),r=require("./api-ibGqkmtA.cjs"),i=require("./busy-BXbVH595.cjs"),a=require("./contract.cjs"),o=require("./relay-choice-JC_JJY_M.cjs"),s=require("./proxy-CII2NFYV.cjs"),c=require("./attach-policy.cjs"),l=require("./dns.cjs"),u=require("./cloud/fs.cjs"),d=require("./net.cjs"),f=require("./dgram.cjs"),p=require("./http.cjs");let m=require("osra");var h=async()=>{let e=()=>r.s(`frame consent`);try{let t=await e();return{request:typeof t.frameConsent.request==`function`?t.frameConsent.request:void 0,ensure:t.frameConsent.ensure}}catch(t){if(!(t instanceof r.n))throw t;return{request:void 0,ensure:t=>e().then(e=>e.frameConsent.ensure(t))}}},g=`frame: this frame no longer holds the document the app attached it to`,_=!1,v=()=>{_||(_=!0,console.warn(`[fkn-frame] this FKN broker is too old to ask for permission categories, so nothing was asked for upfront and each capability is asked for as it is first used. Reloading the page picks up the current broker.`))},y=e=>[...e].flatMap(e=>{try{return[new URL(e).hostname]}catch{return[]}}),b=e=>typeof e?.reason==`string`?{reason:e.reason}:{},x=(e,t,n)=>n===null?`frame.${e}: the user did not grant ${t} here`:`frame.${e}: the user did not grant ${t} on ${n}`,S=e=>{let{assertLive:r,attach:i,consent:a,current:o,declaredHosts:s,documentHost:l,freshBlank:u,session:d,approvedOrigins:f}=e,p=new Set,m=()=>{try{return new URL(o()).hostname}catch{return``}},h=async()=>l?await l():m(),_=()=>n.t([...s,...y(f)]),S=async(e,t)=>(await e([t]))[0]??!1;return{gate:async({operation:e,args:o,phase:l})=>{r();let v=n.m(e,o);if(v===null)return;let y=t.h(v);if(y===void 0||y===`auto`)return;if(e===`fetch`){let e=c.frameFetchVerdict({session:d,declaredHosts:s,approvedOrigins:f},l===`ensure`?void 0:o[0],{classifier:`fetchTarget`});if(l===`ensure`&&!d)throw t.k(e.kind===`refuse`?e.reason:``,`fetch`);if(l!==`ensure`&&e.kind===`refuse`)throw t.k(e.reason,`fetch`);let{request:r,ensure:i}=await a();if(!r){if(e.kind===`refuse`)throw t.k(e.reason,`fetch`);if(!await i({scope:n.c(o[0],o[1]).scope,hosts:e.promptHosts}))throw t.k(`frame.fetch: the user did not grant this`,`fetch`);return}let u=e.kind===`consent`?e.targetHost:await h(),p=n.t([u,...s]);if(!p.length)throw t.k(`frame: navigate the frame before fetch`,`fetch`);if(await S(r,{category:`network`,hosts:p,...b(t.T(o))})===!1)throw t.k(x(`fetch`,`network`,u||null),`fetch`);return}let C=await h();if(!C)throw t.k(`frame: navigate the frame before ${e}`,e);if(!_().includes(C))throw t.k(g,e);let w=t.m(v);if(w===void 0||w===`evaluation`&&C===m()&&await u?.()||y===`critical`&&p.has(`${v} ${C}`))return;let{request:T}=await a();if(!T)return;let E=n.t([C,...s]),D=b(t.T(o)),O=y===`critical`?{key:v,hosts:E,attach:i,...D}:{category:w,hosts:E,...D},k=await S(T,O);if(k===!1)throw t.k(x(e,w,null),e);if(k===`once`&&l!==`ensure`)for(let e of E)p.add(`${v} ${e}`)},requestCategories:async e=>{r(),t.f(`frame.requestPermissions`,e);let o=await h(),c=n.t(o?[o,...s]:s);if(!c.length)throw TypeError(`frame.requestPermissions: navigate the frame or declare domains first`);let l=e.map(e=>{let n=e.key;return n===void 0?{named:void 0,critical:!1,category:e.category}:{named:n,critical:t.h(n)===`critical`,category:t.p(n)}}),u=({named:e,critical:t,category:n},r)=>({category:n,...t?{key:e}:{},hosts:c,allow:r}),{request:d}=await a();if(!d)return v(),l.map(e=>u(e,!1));let f=await d(l.map(({named:t,critical:n,category:r},a)=>{let o=b(e[a]);return n?{key:t,hosts:c,attach:i,...o}:{category:r,hosts:c,...o}}));return l.map((e,t)=>u(e,f[t]!==void 0&&f[t]!==!1))},boundary:_}},C=e=>e,w=5e3,T=new Set([]),E=()=>`https://fkn.app`,D=e=>e===`persistent`?``:`incognito-${crypto.randomUUID()}`,O=(e,n,r)=>{let i,a=new Promise((e,a)=>{i=setTimeout(()=>a(typeof r==`string`?new t.E(r):r()),n)});return Promise.race([e,a]).finally(()=>clearTimeout(i))},k=e=>Object.assign(Error(e),{name:t.D}),A=`frame.postMessage: this FKN page predates frame messaging; reload the app to load the current one`,j=`frame.addScriptTag: this render proxy predates addScriptTag; reload the app`,M=`frame.addScriptTag: no answer within ${t.l}ms; the script may or may not have run`,N=`frame.clearCookies: this FKN page predates clearCookies; reload the app to load the current one`,P=`frame.clearCookies: this attachment reaches no site yet; attach a url, goto one, or declare it in domains`,F=3e4,I=`attachFrame: this FKN page predates storageState; reload the app to load the current one`,L=2e4,R=async(e,n)=>{if(typeof e.seed!=`function`)throw t.N(I,`storageState`,`cloud`);try{await O(e.seed(n),L,`attachFrame: the render proxy did not take the storageState seed`)}catch(e){throw t.O(e)?t.N(I,`storageState`,`cloud`):e}},z=`frame.clearCookies: the render proxy did not answer within ${F}ms; the cookies may or may not be gone, and calling it again is safe`,B=e=>t.O(e)&&e.message===t.j(`addScriptTag`).message,V=!1,ee=()=>{V||(V=!0,console.warn(`[fkn-frame] this FKN page predates frame messaging, so the page's messages and documents are never reported. Reloading the app loads the current one.`))},te=({from:e,origin:t,attach:n,signal:r})=>i=>{let a=r=>{if(r.source===null||r.source!==e()||r.origin!==t)return;let a=r.data;typeof a==`object`&&a&&a.type===`fkn-frame-message`&&a.attach===n&&typeof a.origin==`string`&&(a.kind===`message`?i({type:`message`,data:a.data,origin:a.origin,ports:r.ports}):a.kind===`document`&&i({type:`document`,origin:a.origin}))};return window.addEventListener(`message`,a,{signal:r}),()=>window.removeEventListener(`message`,a)},ne=e=>{if(typeof e!=`function`)return()=>Promise.resolve(e);let t=null;return()=>t??=e().catch(e=>{throw t=null,e})},H=({control:e,target:n,blank:r=!1,session:i,declaredHosts:a,approvedOrigins:o,attach:s,assertLive:c,guard:l,consent:u,onNavigated:d,relay:f})=>{let p=n,m=r&&i!==``,h=async()=>{if(!m)return!1;let t=typeof e.blank==`function`?await l(()=>e.blank()):``;return(typeof t!=`string`||t.split(`#`)[0]!==n.split(`#`)[0])&&(m=!1),m},_=Promise.resolve(),{gate:v,requestCategories:y,boundary:b}=S({session:i,declaredHosts:a,approvedOrigins:o,attach:s,assertLive:c,documentHost:typeof e.documentHost==`function`?()=>l(()=>e.documentHost()):void 0,current:()=>p,consent:ne(u),freshBlank:h});return t.y({backend:`cloud`,executor:{execute:(n,r,i)=>T.has(r)?Promise.reject(t.j(r,`cloud`)):(c(),l(()=>e.executeLocator(n,r,i))),highlight:async()=>{}},gate:v,requestPermissions:y,evaluate:async(n,r)=>(c(),await v({parts:[],operation:`evaluate`,args:[n],phase:`execute`}),O(l(()=>e.executeLocator([],`evaluate`,[n,r])),t.l,t.u)),addScriptTag:async(n,r)=>{c();let i=[n,r];await v({parts:[],operation:`addScriptTag`,args:i,phase:`execute`});try{await O(l(()=>e.executeLocator([],`addScriptTag`,i)),t.l,M)}catch(e){throw B(e)?t.N(j,`addScriptTag`,`cloud`):e}},clearCookies:async n=>{if(c(),typeof e.clearCookies!=`function`)throw t.N(N,`clearCookies`,`cloud`);if(b().length===0)throw t.k(P,`clearCookies`);await O(l(()=>e.clearCookies(n)),F,z)},postMessage:(n,r,i)=>{if(c(),typeof e.messaging!=`function`)throw t.N(A,`postMessage`,`cloud`);if(r!==`*`&&!b().includes(new URL(r).hostname))throw t.k(g,`postMessage`);let{port1:a,port2:o}=new MessageChannel;a.postMessage({data:n,transfer:i},i);let s=[o,r],u=_.then(async()=>(await v({parts:[],operation:`postMessage`,args:s,phase:`execute`}),{answer:l(()=>e.executeLocator([],`postMessage`,s))}));return _=u.catch(()=>{}),u.then(async({answer:e})=>{await e})},listen:t=>(typeof e.messaging!=`function`&&ee(),f(t)),goto:async(n,{timeout:r,...i}={})=>{let a=new URL(n,location.href).href;c(),m=!1;let s=(()=>{try{return new URL(a).origin}catch{return``}})(),u=s!==``&&!o.has(s);u&&o.add(s);try{await O(l(()=>e.goto(a,r===void 0?i:{...i,timeoutMs:r})),(r??3e4)+w,`cloud.attachFrame: the render proxy did not answer goto; the frame may have been detached or its page reloaded`)}catch(e){throw u&&o.delete(s),t.c(e)}p=a,d()},url:()=>p})},U=async e=>{if(e===void 0){let e=await r.s(`a relay`).catch(()=>void 0);if(typeof e?.relay?.resolve!=`function`)return;let t=await e.relay.resolve().catch(()=>void 0);return t&&`id`in t?t.id:void 0}let t=await r.s(`a relay choice`);o.t(t,`attachFrame`);let n=await t.relay.resolve(e);if(`refused`in n)throw o.i(`attachFrame: ${n.refused}`);return n.id},W=async(e,t)=>{if((typeof e.relay==`function`?await e.relay():``)!==t)throw o.i(`attachFrame: ${a.RELAY_CHOICE_UNSUPPORTED}`)},re=250,ie=500,G=65e3,ae=2e3,oe=2e3,se=2,ce=2e3,le=2e3,ue=({origin:e,target:t,session:n,domains:r,attach:i})=>{let a=new URL(`/attach-window`,e);return a.searchParams.set(`attach`,i),t&&a.searchParams.set(`url`,t),n&&a.searchParams.set(`session`,n),r.length&&a.searchParams.set(`domains`,r.join(`,`)),a.href},de=(e,t)=>{let n=document.createElement(`iframe`),r=new URL(`/attach-jar`,e);return r.searchParams.set(`attach`,t),n.src=r.href,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`style`,`display:none`),(document.body??document.documentElement).appendChild(n),n},fe=(e,t)=>{let n=new MutationObserver(()=>{e.isConnected||t.aborted||(n.disconnect(),console.warn(`cloud.attachFrame: the window's jar anchor was removed from this page, so a sign-in in the window no longer reaches this app's cookie jar`))});e.parentNode&&n.observe(e.parentNode,{childList:!0}),n.observe(document.documentElement,{childList:!0}),t.addEventListener(`abort`,()=>n.disconnect(),{once:!0})},K=()=>k(`cloud.attachFrame: the attached window closed, reloaded or left the page FKN attached; attach a fresh window`),q=()=>k(`cloud.attachFrame: the attached window stopped answering; attach a fresh window`),pe=()=>k(`cloud.attachFrame: the window went away before it connected; attach a fresh window`),me=()=>k(`cloud.attachFrame: the window closed before it connected. Either the user closed it, or this page's Cross-Origin-Opener-Policy cut its link to the window`),he=async(e,r,s)=>{if(typeof window>`u`)throw Error(`cloud.attachFrame needs a window realm`);let{domains:c=[],permissions:l,relay:u}=e,{url:d,width:f,height:p}=t.s(e.window);if(window.origin===`null`)throw new t._(`opaque-opener`);let h=E(),g=crypto.randomUUID(),_=D(r),v=n.t(c),y=new Set;d&&y.add(new URL(d).origin);let b=r===`persistent`?de(h,g):null,x=window.open(ue({origin:h,target:s===void 0?d:``,session:_,domains:v,attach:g}),`_blank`,`popup,width=${f},height=${p}`);if(!x)throw b?.remove(),new t.g;let S=new AbortController,w=!1,T=null,k=(e,t=!1)=>{if(T===null){T=e,S.abort(t?q():K());try{x.closed||x.postMessage({type:a.ATTACH_WINDOW_MESSAGE.detach,attach:g,...t?{unanswered:t}:{}},h)}catch{}b&&setTimeout(()=>b.remove(),le)}};b&&fe(b,S.signal);let A=new Promise((e,t)=>{S.signal.addEventListener(`abort`,()=>t(S.signal.reason),{once:!0})});A.catch(()=>{});let j=A.then(()=>{},()=>{}),M=()=>{if(S.signal.aborted)throw S.signal.reason},N=e=>S.signal.aborted?Promise.reject(S.signal.reason):Promise.race([e(),A]),P=e=>e.source===x&&e.origin===h;window.addEventListener(`message`,e=>{if(!P(e))return;let n=e.data;typeof n==`object`&&n&&n.attach===g&&(n.type===a.ATTACH_WINDOW_MESSAGE.refused?k(new t._(n.reason)):n.type===a.ATTACH_WINDOW_MESSAGE.gone&&k(w?K():pe()))},{signal:S.signal}),window.addEventListener(`pagehide`,()=>k(K()),{signal:S.signal});let F=U(u),I,L,z=()=>{let e=()=>{try{x.postMessage({type:a.ATTACH_WINDOW_MESSAGE.hello,attach:g,...I?{relay:I}:{}},h)}catch{}};e(),L=setInterval(e,re)};u===void 0&&z();let B=setInterval(()=>{x.closed&&k(w?K():me())},ie);S.signal.addEventListener(`abort`,()=>{clearInterval(L),clearInterval(B)},{once:!0});let V=async e=>{try{return await Promise.race([e,A])}catch(e){throw T??e}};try{u!==void 0&&(I=await V(F),z());let e=await V(O((0,m.expose)({},{key:a.ATTACH_WINDOW_KEY,transport:{emit:(e,t)=>x.postMessage(e,h,t??[]),receive:e=>{let t=t=>{P(t)&&e(t.data,{source:t.source,origin:t.origin})};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)}},unregisterSignal:S.signal,revivableModules:C(t.ft)}),a.WINDOW_HANDSHAKE_TIMEOUT_MS,`cloud.attachFrame: timed out connecting to the window`));w=!0,clearInterval(L);let n=0,r=setInterval(()=>{O(N(()=>e.ping()),oe,`ping`).then(()=>{n=0},()=>{S.signal.aborted||(document.visibilityState===`hidden`?n=0:++n>=se&&k(q(),!0))})},ae);S.signal.addEventListener(`abort`,()=>clearInterval(r),{once:!0}),I&&await V(O(W(e,I),G,`cloud.attachFrame: the window never became ready`)),await V(O(e.ready(),G,`cloud.attachFrame: the window never became ready`)),s!==void 0&&await V(R(e,s)),i.r(`attached frame`,S.signal);let c=H({control:e,target:d,session:_,declaredHosts:v,approvedOrigins:y,attach:g,assertLive:M,guard:N,consent:{request:t=>N(()=>e.requestConsent(t)),ensure:t=>N(()=>e.requestConsent([t])).then(([e])=>e!==void 0&&e!==!1)},onNavigated:()=>{},relay:te({from:()=>x,origin:h,attach:g,signal:S.signal})}),f=null,p=Object.assign(c,{close:()=>f??=(async()=>{S.signal.aborted||await O(Promise.allSettled([N(()=>e.flushCookies()),N(()=>e.sweepStorage())]),ce,`close`).catch(()=>{});try{x.close()}catch{}k(K())})(),closed:j});return I?o.a(p,I):F.then(e=>o.a(p,e)),s!==void 0&&d&&await V(p.goto(d)),l?.length&&await V(p.requestPermissions(l)),p}catch(e){let n=T??e;if(!(n instanceof t._))try{x.close()}catch{}throw k(n),n}},ge=2e4,J=65e3,Y=e=>!e||e===`about:blank`,_e=`cloud.attachFrame: this FKN page predates blank pages; reload the app to load the current one`,ve=`cloud.attachFrame: cookies: 'native' needs the FKN browser extension; the cloud render proxy has no browser cookies`,X=e=>e.split(`#`)[0]??``,Z=({iframe:e,lockdown:n,cookies:r,blank:i})=>{if(i===void 0)return``;if(typeof i!=`object`||!i)throw TypeError(`attachFrame: blank must be an object { url }`);let a=Object.keys(i).find(e=>e!==`url`);if(a!==void 0)throw TypeError(`attachFrame: blank takes { url }, not "${a}"`);let{url:o}=i,s=(()=>{try{return typeof o==`string`?new URL(o):null}catch{return null}})();if(!s||s.protocol!==`http:`&&s.protocol!==`https:`)throw TypeError(`attachFrame: blank.url must be an absolute http or https url, not "${String(o)}"`);let c=e.getAttribute(`src`)??``;if(!Y(c))throw TypeError(`attachFrame: blank needs an iframe with no src; this one has "${c}"`);if(n)throw TypeError(`attachFrame: blank does not combine with lockdown`);if(r===`native`)throw TypeError(`attachFrame: blank runs on the cloud render proxy, which has no browser cookies; pass cookies: 'persistent' or 'ephemeral'`);if(t.x(s.href),!Oe())throw Error(`attachFrame: a blank page is served by the cloud render proxy, which this build does not configure`);return s.href},ye=({target:e,blank:t,session:n,domains:r,attach:i,relay:a})=>{let o=new URL(`/attach-frame`,E());return t?o.searchParams.set(`blank`,t):e&&o.searchParams.set(`url`,e),n&&o.searchParams.set(`session`,n),r.length&&o.searchParams.set(`domains`,r.join(`,`)),o.searchParams.set(`attach`,i),a&&o.searchParams.set(`relay`,a),o.href},be=(e,t)=>{let n=()=>{a(),t()},r=e.parentNode,i=new MutationObserver(()=>{(!e.isConnected||e.parentNode!==r)&&(a(),t())}),a=()=>{window.removeEventListener(`pagehide`,n),i.disconnect()};window.addEventListener(`pagehide`,n,{once:!0}),r&&i.observe(r,{childList:!0}),e.isConnected||(a(),t())},xe=()=>k(`cloud.attachFrame: the attached iframe left the document or was reloaded; attach a fresh iframe`),Se=(e,t)=>{let n=[...e.split(`;`),...t.split(`;`)].map(e=>e.trim()).filter(Boolean);return[...new Set(n)].join(`; `)},Ce=[300,1200,4e3],Q=e=>{let t=()=>{if(!e.isConnected)return;let t=e.style.height,n=e.getBoundingClientRect();n.height&&(e.style.height=`${n.height-1}px`,setTimeout(()=>{e.style.height=t},50))};t();for(let e of Ce)setTimeout(t,e)},we=e=>{let t=e.getAttribute(`sandbox`);if(t===null)return;let n=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),r=[`allow-scripts`,`allow-same-origin`].filter(e=>!n.has(e));if(r.length)throw Error(`cloud.attachFrame: the iframe's sandbox attribute must include ${r.join(` and `)} for the render proxy to load`)},Te=async(e,n)=>{let r=typeof e.blank==`function`?await O(e.blank(),J,`cloud.attachFrame: the render proxy never became ready`):``;if(typeof r!=`string`||X(r)!==X(n))throw t.N(_e,`blank`,`cloud`)},Ee=async(e,s,c)=>{let l=Z(e),{iframe:u,domains:d=[],permissions:f,relay:p}=e;if(typeof window>`u`)throw Error(`cloud.attachFrame needs a window realm`);if(!u.isConnected)throw Error(`cloud.attachFrame: the iframe must be connected to the document before attaching`);we(u);let g=u.getAttribute(`src`)??``,_=(()=>{if(Y(g))return null;try{return new URL(u.src||g,location.href)}catch{throw Error(`cloud.attachFrame: the iframe src is not a valid URL: ${g}`)}})();if(_){let e=new URL(`/attach-frame`,E());if(_.origin===e.origin&&_.pathname===e.pathname)throw Error(`cloud.attachFrame: this iframe is already attached; navigate with the Frame returned by that attach or use a fresh iframe`)}let v=_?.href??``;v&&t.x(v);let y=c===void 0?v:``,b=D(s),x=n.t(d),S=new Set;try{S.add(new URL(l||v).origin)}catch{}let w=U(p),T=p===void 0?void 0:await w,k=new AbortController,A=u.referrerPolicy,j=u.allow,M=crypto.randomUUID();if(u.referrerPolicy=`origin`,u.allow=Se(r.m(),u.allow),u.src=ye({target:y,blank:l,session:b,domains:x,attach:M,relay:T}),!u.contentWindow)throw Error(`cloud.attachFrame: the iframe window is not available`);try{let e=await O((0,m.expose)({},{key:a.ATTACH_FRAME_KEY,origin:E(),transport:{receive:window,emit:u.contentWindow},unregisterSignal:k.signal,revivableModules:C(t.ft)}),ge,`cloud.attachFrame: timed out connecting to the render proxy page`);T&&await O(W(e,T),J,`cloud.attachFrame: the render proxy never became ready`),await O(e.ready(),J,`cloud.attachFrame: the render proxy never became ready`),l&&await Te(e,l),c!==void 0&&await R(e,c),(v||l)&&Q(u),be(u,()=>k.abort()),i.r(`attached frame`,k.signal);let n=u.contentWindow,r=H({control:e,target:l||v,blank:l!==``,session:b,declaredHosts:x,approvedOrigins:S,attach:M,assertLive:()=>{if(k.signal.aborted||!u.isConnected||u.contentWindow!==n)throw k.abort(),xe()},guard:e=>e(),consent:h,onNavigated:()=>Q(u),relay:te({from:()=>n,origin:E(),attach:M,signal:k.signal})});return T?o.a(r,T):w.then(e=>o.a(r,e)),c!==void 0&&v&&await r.goto(v),f?.length&&await r.requestPermissions(f),r}catch(e){throw k.abort(),u.referrerPolicy=A,u.allow=j,u.src=y||`about:blank`,e}},De=(async e=>{let{kind:n,cookies:r,storageState:i}=t.o(e);if(r===`native`)throw TypeError(ve);return n===`window`?he(e,r,i):Ee(e,r,i)}),Oe=()=>typeof window<`u`&&!0,ke=async()=>{let e=await r.o.then(e=>e.cloud.quota());return{premium:e.premium,overQuota:e.overQuota,throttled:e.overQuota&&!e.premium,usedBytes:e.usedBytes,limitBytes:e.limitBytes,remainingBytes:e.remaining,bytesPerSecond:e.bytesPerSecond,bitsPerSecond:e.bytesPerSecond*8}},Ae=e.t({attachFrame:()=>De,available:()=>$,dgram:()=>f.t,dns:()=>l.t,fetch:()=>s.t,fs:()=>u.t,http:()=>p.t,net:()=>d.t,quota:()=>ke}),$=()=>r.l;Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return $}});
|
package/cloud.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./proxy-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./proxy-CII2NFYV.cjs"),t=require("./cloud-C0hcBrFd.cjs"),n=require("./dns.cjs"),r=require("./cloud/fs.cjs"),i=require("./net.cjs"),a=require("./dgram.cjs"),o=require("./http.cjs");exports.attachFrame=t.i,exports.available=t.t,Object.defineProperty(exports,"dgram",{enumerable:!0,get:function(){return a.t}}),Object.defineProperty(exports,"dns",{enumerable:!0,get:function(){return n.t}}),exports.fetch=e.t,Object.defineProperty(exports,"fs",{enumerable:!0,get:function(){return r.t}}),Object.defineProperty(exports,"http",{enumerable:!0,get:function(){return o.t}}),Object.defineProperty(exports,"net",{enumerable:!0,get:function(){return i.t}}),exports.quota=t.r;
|
package/cloud.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as cloudFetch } from "./proxy-
|
|
2
|
-
import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-
|
|
1
|
+
import { t as cloudFetch } from "./proxy-z0Y8IgW7.js";
|
|
2
|
+
import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-BEoUa04G.js";
|
|
3
3
|
import { t as dns_d_exports } from "./dns.js";
|
|
4
4
|
import { n as fs_d_exports } from "./fs-DCJAYoYy.js";
|
|
5
|
-
import { s as net_d_exports } from "./net-
|
|
5
|
+
import { s as net_d_exports } from "./net-CvJwokcz.js";
|
|
6
6
|
import { t as dgram_d_exports } from "./dgram.js";
|
|
7
7
|
import { t as http_d_exports } from "./http.js";
|
|
8
8
|
export { type QuotaStatus, attachFrame, available, dgram_d_exports as dgram, dns_d_exports as dns, cloudFetch as fetch, fs_d_exports as fs, http_d_exports as http, net_d_exports as net, quota };
|
package/cloud.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "./proxy-
|
|
2
|
-
import { i as t, r as n, t as r } from "./cloud-
|
|
1
|
+
import { t as e } from "./proxy-C1RlnrDC.js";
|
|
2
|
+
import { i as t, r as n, t as r } from "./cloud-B6B2XcRU.js";
|
|
3
3
|
import { t as i } from "./dns.js";
|
|
4
4
|
import { t as a } from "./cloud/fs.js";
|
|
5
5
|
import { t as o } from "./net.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as StorageState,
|
|
1
|
+
import { D as RelayChoice, O as StorageState, nt as SelectorPart, u as ClearCookiesWire } from "./index-C5DdoMGo.js";
|
|
2
2
|
import { o as TcpSocketOption, x as UdpSocketOption } from "./wire-Fk5pJaoy.js";
|
|
3
3
|
//#region ../web-extension/lib/lib/storage-state.d.ts
|
|
4
4
|
/**
|
|
@@ -193,7 +193,7 @@ type ShellFrameMessage = {
|
|
|
193
193
|
};
|
|
194
194
|
/** What an app and its window post to each other, every message carrying the attach id. */
|
|
195
195
|
declare const ATTACH_WINDOW_MESSAGE: {
|
|
196
|
-
/** app to window, repeated until the channel connects */
|
|
196
|
+
/** app to window, repeated until the channel connects; `relay`, when the app chose one, is the relay id its render proxy dials */
|
|
197
197
|
readonly hello: 'fkn-attach-window';
|
|
198
198
|
/** window to app, `{ reason }`: the window loaded nothing and exposes nothing */
|
|
199
199
|
readonly refused: 'fkn-attach-window-refused';
|
|
@@ -341,6 +341,11 @@ type ShellControl = {
|
|
|
341
341
|
* TypeError from the shell's controller. Absent from a shell that predates it.
|
|
342
342
|
*/
|
|
343
343
|
seed?(seed: JarSeed): Promise<void>;
|
|
344
|
+
/**
|
|
345
|
+
* The relay id every socket of this shell dials (`?relay=`), `''` for the app's default relay.
|
|
346
|
+
* Absent from a shell that predates relay choice, which ignores `?relay=`.
|
|
347
|
+
*/
|
|
348
|
+
relay?(): Promise<string>;
|
|
344
349
|
};
|
|
345
350
|
/**
|
|
346
351
|
* What a middle page exposes to the library, inline (`ATTACH_FRAME_KEY`) and for a window
|
|
@@ -408,6 +413,12 @@ type MiddleControl = {
|
|
|
408
413
|
* which the library refuses by name.
|
|
409
414
|
*/
|
|
410
415
|
seed?(state: StorageState): Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Its shell's own `relay()` answer, `''` from a shell that predates it. The library sends a
|
|
418
|
+
* choice's relay as `?relay=` and refuses the attach unless this echoes it before `ready`. Absent
|
|
419
|
+
* from a middle page that predates relay choice.
|
|
420
|
+
*/
|
|
421
|
+
relay?(): Promise<string>;
|
|
411
422
|
};
|
|
412
423
|
/** What a window's middle page adds to its channel. */
|
|
413
424
|
type WindowMiddleControl = MiddleControl & {
|
|
@@ -1137,6 +1148,18 @@ declare const STORAGE_REFUSALS: {
|
|
|
1137
1148
|
readonly message: 'storage: storage is unavailable';
|
|
1138
1149
|
};
|
|
1139
1150
|
};
|
|
1151
|
+
/** The response header naming the relay that served a cloud.fetch, set by the broker over anything the upstream sent. */
|
|
1152
|
+
declare const RELAY_HEADER = "fkn-relay";
|
|
1153
|
+
/** The `name` of the error a call with a `RelayChoice` no relay can serve is refused with, matched by name since only that survives each hop. */
|
|
1154
|
+
declare const RELAY_UNAVAILABLE = "RelayUnavailableError";
|
|
1155
|
+
/** Why a call carrying a `RelayChoice` is refused when the FKN page it reaches predates relay choice. */
|
|
1156
|
+
declare const RELAY_CHOICE_UNSUPPORTED = "this FKN page cannot choose a relay; reload the app to load the current one";
|
|
1157
|
+
/** What `relay.resolve` answers: the relay a call with that choice goes through now, or why none can, as data rather than a throw. */
|
|
1158
|
+
type RelayResolution = {
|
|
1159
|
+
id: string;
|
|
1160
|
+
} | {
|
|
1161
|
+
refused: string;
|
|
1162
|
+
};
|
|
1140
1163
|
type IpFamily = 'IPv4' | 'IPv6';
|
|
1141
1164
|
/** Viewport rect plus optional corner radii, as the overlay host reports them. */
|
|
1142
1165
|
type OverlayRect = {
|
|
@@ -1183,14 +1206,20 @@ type ProxyFetchInput = string | URL | Request;
|
|
|
1183
1206
|
* A spread request is the app's own choice and is not announced: the header keeps naming the
|
|
1184
1207
|
* session's node, which every request not carrying this flag still goes through. Only the cloud
|
|
1185
1208
|
* backend reads it; the extension and the desktop fetch from the user's own address and ignore it.
|
|
1209
|
+
* With `relay`, spreading rotates over the relays the choice leaves.
|
|
1210
|
+
*
|
|
1211
|
+
* `relay` narrows the relays THIS request may go through (`RelayChoice`); the answer names the one
|
|
1212
|
+
* that served it in `RELAY_HEADER`.
|
|
1186
1213
|
*/
|
|
1187
1214
|
type ProxyFetchInit = (RequestInit & {
|
|
1188
1215
|
spread?: boolean;
|
|
1216
|
+
relay?: RelayChoice;
|
|
1189
1217
|
}) | undefined;
|
|
1190
1218
|
type ProxyFetch = (input: ProxyFetchInput, init: ProxyFetchInit) => Promise<Response>;
|
|
1191
1219
|
type TcpSocketOptions = {
|
|
1192
1220
|
remoteAddress: string;
|
|
1193
1221
|
remotePort: number;
|
|
1222
|
+
relay?: RelayChoice;
|
|
1194
1223
|
};
|
|
1195
1224
|
type TcpSocketResult = {
|
|
1196
1225
|
localAddress: string;
|
|
@@ -1206,24 +1235,29 @@ type TcpSocketResult = {
|
|
|
1206
1235
|
destroySoon: () => Promise<void>;
|
|
1207
1236
|
resetAndDestroy: () => Promise<void>;
|
|
1208
1237
|
setOption: (option: TcpSocketOption) => Promise<void>;
|
|
1238
|
+
/** the relay the socket goes through, absent on a broker that predates relay choice and on a loopback socket */
|
|
1239
|
+
relay?: string;
|
|
1209
1240
|
};
|
|
1210
1241
|
type TcpSocketListenerOptions = {
|
|
1211
1242
|
localAddress: string;
|
|
1212
1243
|
localPort: number;
|
|
1213
1244
|
onConnection: (connection: TcpSocketResult) => void | Promise<void>;
|
|
1214
1245
|
onClose?: (error?: Error) => void | Promise<void>;
|
|
1246
|
+
relay?: RelayChoice;
|
|
1215
1247
|
};
|
|
1216
1248
|
type TcpSocketListenerResult = {
|
|
1217
1249
|
localAddress: string;
|
|
1218
1250
|
localFamily: IpFamily;
|
|
1219
1251
|
localPort: number;
|
|
1220
1252
|
close: () => Promise<void>;
|
|
1253
|
+
relay?: string;
|
|
1221
1254
|
};
|
|
1222
1255
|
type UdpSocketOptions = {
|
|
1223
1256
|
type: 'udp4' | 'udp6';
|
|
1224
1257
|
port: number;
|
|
1225
1258
|
address: string;
|
|
1226
1259
|
dataPort?: boolean;
|
|
1260
|
+
relay?: RelayChoice;
|
|
1227
1261
|
};
|
|
1228
1262
|
type UdpDatagram = {
|
|
1229
1263
|
data: ArrayBuffer;
|
|
@@ -1260,6 +1294,7 @@ type UdpSocketResult = {
|
|
|
1260
1294
|
}) => Promise<void>;
|
|
1261
1295
|
close: () => Promise<void>;
|
|
1262
1296
|
setOption: (option: UdpSocketOption) => Promise<void>;
|
|
1297
|
+
relay?: string;
|
|
1263
1298
|
};
|
|
1264
1299
|
/**
|
|
1265
1300
|
* Everything the broker exposes over osra.
|
|
@@ -1331,6 +1366,11 @@ type Resolvers = {
|
|
|
1331
1366
|
};
|
|
1332
1367
|
relay: {
|
|
1333
1368
|
prompt: () => Promise<string>;
|
|
1369
|
+
/**
|
|
1370
|
+
* The relay a WebVPN call with this choice goes through now (the default relay without one), or
|
|
1371
|
+
* the reason none can. Absent from a broker that predates relay choice, which drops a choice.
|
|
1372
|
+
*/
|
|
1373
|
+
resolve: (choice?: RelayChoice) => Promise<RelayResolution>;
|
|
1334
1374
|
};
|
|
1335
1375
|
packages: {
|
|
1336
1376
|
search: (query: PackageQuery) => Promise<PackagesFail | {
|
|
@@ -1427,4 +1467,4 @@ type Resolvers = {
|
|
|
1427
1467
|
hideInstallPrompt: () => void;
|
|
1428
1468
|
};
|
|
1429
1469
|
//#endregion
|
|
1430
|
-
export {
|
|
1470
|
+
export { RoomCreateOptions as $, MiddleGotoOptions as A, StorageFail as At, ProxyFetch as B, TcpSocketListenerResult as Bt, FrameMessageRelay as C, SetOverlayHost as Ct, IpFamily as D, ShellJarUnreachable as Dt, InstalledPackage as E, ShellGotoOptions as Et, PackageResult as F, StoredHandle as Ft, RELAY_HEADER as G, UdpSocketResult as Gt, ProxyFetchInput as H, TcpSocketResult as Ht, PackagesErrorCode as I, StoredObject as It, Radii as J, WINDOW_JAR_MODE_TIMEOUT_MS as Jt, RELAY_UNAVAILABLE as K, WINDOW_HANDSHAKE_TIMEOUT_MS as Kt, PackagesFail as L, StoredPage as Lt, OverlayRect as M, StoragePutOptions as Mt, OverlayState as N, StoragePutWire as Nt, JAR_ANCHOR_MESSAGE as O, StorageEntry as Ot, PackageQuery as P, StorageQuota as Pt, RoomClaimOptions as Q, JarSeedCookie as Qt, PickOptions as R, SurfaceRect as Rt, FrameFetchScope as S, STORAGE_REFUSALS as St, InstallOptions as T, ShellFrameMessage as Tt, Quota as U, UdpDatagram as Ut, ProxyFetchInit as V, TcpSocketOptions as Vt, RELAY_CHOICE_UNSUPPORTED as W, UdpSocketOptions as Wt, Resolvers as X, WriteData as Xt, RelayResolution as Y, WindowMiddleControl as Yt, RoomBacklog as Z, JarSeed as Zt, DnsLookup as _, SHELL_ATTACH_ERROR as _t, AccountChange as a, RoomJoinOptions as at, FrameConsentAnswer as b, SHELL_JAR_MESSAGE as bt, AdoptRequest as c, RoomMember as ct, ConflictRequest as d, RoomPermission as dt, RoomDefaults as et, ConflictSide as f, RoomPermissions as ft, DisplayLevel as g, RoomsFail as gt, DisplayCause as h, RoomsErrorCode as ht, Account as i, RoomHandle as it, MountDescriptor as j, StorageProgress as jt, MiddleControl as k, StorageErrorCode as kt, AdoptState as l, RoomMessage as lt, ConnectOptions as m, RoomType as mt, ATTACH_WINDOW_KEY as n, RoomEnvelope as nt, AccountPinOptions as o, RoomJson as ot, ConnectAvailability as p, RoomSchema as pt, ROOM_TEMPORARY_MS as q, WINDOW_HELLO_TIMEOUT_MS as qt, ATTACH_WINDOW_MESSAGE as r, RoomEvent as rt, AddressLookupResult as s, RoomMailbox as st, ATTACH_FRAME_KEY as t, RoomEnd as tt, ConflictChoice as u, RoomOpenOptions as ut, EncryptionState as v, SHELL_CONTROL_KEY as vt, HiddenSurface as w, ShellControl as wt, FrameConsentRequest as x, SHELL_JAR_UNREACHABLE as xt, FRAME_MESSAGE as y, SHELL_FRAME_MESSAGE as yt, Placement as z, TcpSocketListenerOptions as zt };
|
package/contract.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`fkn-attach-frame`,t=`fkn-attach-window`,n=`sdbx-control`,r=`sdbx-attach-error`,i=`fkn-frame-message`,a=`sdbx-frame-message`,o={hello:`fkn-attach-window`,refused:`fkn-attach-window-refused`,gone:`fkn-attach-window-gone`,detach:`fkn-attach-window-detach`},s={request:`sdbx-jar-request`,port:`sdbx-jar-port`,mode:`sdbx-jar-mode`},c=[`bad-attach`,`no-storage`,`bad-jar`,`no-parent`,`no-jar-host`,`no-token`,`no-indexeddb`,`failed`],l={hello:`fkn-jar-hello`,ready:`fkn-jar-ready`,port:`fkn-jar-port`,who:`fkn-jar-who`,host:`fkn-jar-host`},u=2e4,d=3e4,f=6e4,p={default:6048e5,min:6e4,max:31536e6},m={notAFile:{code:`invalid`,message:`storage: the data is not a Blob or a ReadableStream`},badSize:{code:`invalid`,message:`storage: a stream needs the size it will deliver, a whole number of bytes`},shortStream:{code:`invalid`,message:`storage: the stream did not deliver the size it declared`},tooLarge:{code:`invalid`,message:`storage: the file is too large to store`},badKey:{code:`invalid`,message:`storage: the key is not 32 bytes base64url`},badUrl:{code:`invalid`,message:`storage: the url does not name a stored object`},badLimit:{code:`invalid`,message:`storage: the limit is out of range`},badCursor:{code:`invalid`,message:`storage: the cursor is not one list answered`},notFound:{code:`not-found`,message:`storage: no object at this url`},integrity:{code:`integrity`,message:`storage: the object does not match its key`},needsAccount:{code:`denied`,message:`storage: storing needs an account`},notCreator:{code:`denied`,message:`storage: only the app that stored the object can delete it`},quota:{code:`quota`,message:`storage: storage quota exceeded`},tooMany:{code:`too-many`,message:`storage: too many stored objects`},tooManyThisHour:{code:`too-many`,message:`storage: too many objects stored this hour, try again later`},accountChanged:{code:`account-changed`,message:`storage: the signed-in account changed`},unavailable:{code:`unavailable`,message:`storage: storage is unavailable`}};exports.ATTACH_FRAME_KEY=e,exports.ATTACH_WINDOW_KEY=t,exports.ATTACH_WINDOW_MESSAGE=o,exports.FRAME_MESSAGE=i,exports.JAR_ANCHOR_MESSAGE=l,exports.ROOM_TEMPORARY_MS=p,exports.SHELL_ATTACH_ERROR=r,exports.SHELL_CONTROL_KEY=n,exports.SHELL_FRAME_MESSAGE=a,exports.SHELL_JAR_MESSAGE=s,exports.SHELL_JAR_UNREACHABLE=c,exports.STORAGE_REFUSALS=m,exports.WINDOW_HANDSHAKE_TIMEOUT_MS=f,exports.WINDOW_HELLO_TIMEOUT_MS=u,exports.WINDOW_JAR_MODE_TIMEOUT_MS=d;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`fkn-attach-frame`,t=`fkn-attach-window`,n=`sdbx-control`,r=`sdbx-attach-error`,i=`fkn-frame-message`,a=`sdbx-frame-message`,o={hello:`fkn-attach-window`,refused:`fkn-attach-window-refused`,gone:`fkn-attach-window-gone`,detach:`fkn-attach-window-detach`},s={request:`sdbx-jar-request`,port:`sdbx-jar-port`,mode:`sdbx-jar-mode`},c=[`bad-attach`,`no-storage`,`bad-jar`,`no-parent`,`no-jar-host`,`no-token`,`no-indexeddb`,`failed`],l={hello:`fkn-jar-hello`,ready:`fkn-jar-ready`,port:`fkn-jar-port`,who:`fkn-jar-who`,host:`fkn-jar-host`},u=2e4,d=3e4,f=6e4,p={default:6048e5,min:6e4,max:31536e6},m={notAFile:{code:`invalid`,message:`storage: the data is not a Blob or a ReadableStream`},badSize:{code:`invalid`,message:`storage: a stream needs the size it will deliver, a whole number of bytes`},shortStream:{code:`invalid`,message:`storage: the stream did not deliver the size it declared`},tooLarge:{code:`invalid`,message:`storage: the file is too large to store`},badKey:{code:`invalid`,message:`storage: the key is not 32 bytes base64url`},badUrl:{code:`invalid`,message:`storage: the url does not name a stored object`},badLimit:{code:`invalid`,message:`storage: the limit is out of range`},badCursor:{code:`invalid`,message:`storage: the cursor is not one list answered`},notFound:{code:`not-found`,message:`storage: no object at this url`},integrity:{code:`integrity`,message:`storage: the object does not match its key`},needsAccount:{code:`denied`,message:`storage: storing needs an account`},notCreator:{code:`denied`,message:`storage: only the app that stored the object can delete it`},quota:{code:`quota`,message:`storage: storage quota exceeded`},tooMany:{code:`too-many`,message:`storage: too many stored objects`},tooManyThisHour:{code:`too-many`,message:`storage: too many objects stored this hour, try again later`},accountChanged:{code:`account-changed`,message:`storage: the signed-in account changed`},unavailable:{code:`unavailable`,message:`storage: storage is unavailable`}},h=`fkn-relay`,g=`RelayUnavailableError`,_=`this FKN page cannot choose a relay; reload the app to load the current one`;exports.ATTACH_FRAME_KEY=e,exports.ATTACH_WINDOW_KEY=t,exports.ATTACH_WINDOW_MESSAGE=o,exports.FRAME_MESSAGE=i,exports.JAR_ANCHOR_MESSAGE=l,exports.RELAY_CHOICE_UNSUPPORTED=_,exports.RELAY_HEADER=h,exports.RELAY_UNAVAILABLE=g,exports.ROOM_TEMPORARY_MS=p,exports.SHELL_ATTACH_ERROR=r,exports.SHELL_CONTROL_KEY=n,exports.SHELL_FRAME_MESSAGE=a,exports.SHELL_JAR_MESSAGE=s,exports.SHELL_JAR_UNREACHABLE=c,exports.STORAGE_REFUSALS=m,exports.WINDOW_HANDSHAKE_TIMEOUT_MS=f,exports.WINDOW_HELLO_TIMEOUT_MS=u,exports.WINDOW_JAR_MODE_TIMEOUT_MS=d;
|
package/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as CookieMatchWire, u as ClearCookiesWire } from "./index-
|
|
2
|
-
import { $ as
|
|
1
|
+
import { D as RelayChoice, d as CookieMatchWire, u as ClearCookiesWire } from "./index-C5DdoMGo.js";
|
|
2
|
+
import { $ as RoomCreateOptions, A as MiddleGotoOptions, At as StorageFail, B as ProxyFetch, Bt as TcpSocketListenerResult, C as FrameMessageRelay, Ct as SetOverlayHost, D as IpFamily, Dt as ShellJarUnreachable, E as InstalledPackage, Et as ShellGotoOptions, F as PackageResult, Ft as StoredHandle, G as RELAY_HEADER, Gt as UdpSocketResult, H as ProxyFetchInput, Ht as TcpSocketResult, I as PackagesErrorCode, It as StoredObject, J as Radii, Jt as WINDOW_JAR_MODE_TIMEOUT_MS, K as RELAY_UNAVAILABLE, Kt as WINDOW_HANDSHAKE_TIMEOUT_MS, L as PackagesFail, Lt as StoredPage, M as OverlayRect, Mt as StoragePutOptions, N as OverlayState, Nt as StoragePutWire, O as JAR_ANCHOR_MESSAGE, Ot as StorageEntry, P as PackageQuery, Pt as StorageQuota, Q as RoomClaimOptions, Qt as JarSeedCookie, R as PickOptions, Rt as SurfaceRect, S as FrameFetchScope, St as STORAGE_REFUSALS, T as InstallOptions, Tt as ShellFrameMessage, U as Quota, Ut as UdpDatagram, V as ProxyFetchInit, Vt as TcpSocketOptions, W as RELAY_CHOICE_UNSUPPORTED, Wt as UdpSocketOptions, X as Resolvers, Xt as WriteData, Y as RelayResolution, Yt as WindowMiddleControl, Z as RoomBacklog, Zt as JarSeed, _ as DnsLookup, _t as SHELL_ATTACH_ERROR, a as AccountChange, at as RoomJoinOptions, b as FrameConsentAnswer, bt as SHELL_JAR_MESSAGE, c as AdoptRequest, ct as RoomMember, d as ConflictRequest, dt as RoomPermission, et as RoomDefaults, f as ConflictSide, ft as RoomPermissions, g as DisplayLevel, gt as RoomsFail, h as DisplayCause, ht as RoomsErrorCode, i as Account, it as RoomHandle, j as MountDescriptor, jt as StorageProgress, k as MiddleControl, kt as StorageErrorCode, l as AdoptState, lt as RoomMessage, m as ConnectOptions, mt as RoomType, n as ATTACH_WINDOW_KEY, nt as RoomEnvelope, o as AccountPinOptions, ot as RoomJson, p as ConnectAvailability, pt as RoomSchema, q as ROOM_TEMPORARY_MS, qt as WINDOW_HELLO_TIMEOUT_MS, r as ATTACH_WINDOW_MESSAGE, rt as RoomEvent, s as AddressLookupResult, st as RoomMailbox, t as ATTACH_FRAME_KEY, tt as RoomEnd, u as ConflictChoice, ut as RoomOpenOptions, v as EncryptionState, vt as SHELL_CONTROL_KEY, w as HiddenSurface, wt as ShellControl, x as FrameConsentRequest, xt as SHELL_JAR_UNREACHABLE, y as FRAME_MESSAGE, yt as SHELL_FRAME_MESSAGE, z as Placement, zt as TcpSocketListenerOptions } from "./contract-B8Rqx5BD.js";
|
|
3
3
|
import { o as TcpSocketOption, x as UdpSocketOption } from "./wire-Fk5pJaoy.js";
|
|
4
|
-
export { ATTACH_FRAME_KEY, ATTACH_WINDOW_KEY, ATTACH_WINDOW_MESSAGE, Account, AccountChange, AccountPinOptions, AddressLookupResult, AdoptRequest, AdoptState, type ClearCookiesWire, ConflictChoice, ConflictRequest, ConflictSide, ConnectAvailability, ConnectOptions, type CookieMatchWire, DisplayCause, DisplayLevel, DnsLookup, EncryptionState, FRAME_MESSAGE, FrameConsentAnswer, FrameConsentRequest, FrameFetchScope, FrameMessageRelay, HiddenSurface, InstallOptions, InstalledPackage, IpFamily, JAR_ANCHOR_MESSAGE, type JarSeed, type JarSeedCookie, MiddleControl, MiddleGotoOptions, MountDescriptor, OverlayRect, OverlayState, PackageQuery, PackageResult, PackagesErrorCode, PackagesFail, PickOptions, Placement, ProxyFetch, ProxyFetchInit, ProxyFetchInput, Quota, ROOM_TEMPORARY_MS, Radii, Resolvers, RoomBacklog, RoomClaimOptions, RoomCreateOptions, RoomDefaults, RoomEnd, RoomEnvelope, RoomEvent, RoomHandle, RoomJoinOptions, RoomJson, RoomMailbox, RoomMember, RoomMessage, RoomOpenOptions, RoomPermission, RoomPermissions, RoomSchema, RoomType, RoomsErrorCode, RoomsFail, SHELL_ATTACH_ERROR, SHELL_CONTROL_KEY, SHELL_FRAME_MESSAGE, SHELL_JAR_MESSAGE, SHELL_JAR_UNREACHABLE, STORAGE_REFUSALS, SetOverlayHost, ShellControl, ShellFrameMessage, ShellGotoOptions, ShellJarUnreachable, StorageEntry, StorageErrorCode, StorageFail, StorageProgress, StoragePutOptions, StoragePutWire, StorageQuota, StoredHandle, StoredObject, StoredPage, SurfaceRect, TcpSocketListenerOptions, TcpSocketListenerResult, type TcpSocketOption, TcpSocketOptions, TcpSocketResult, UdpDatagram, type UdpSocketOption, UdpSocketOptions, UdpSocketResult, WINDOW_HANDSHAKE_TIMEOUT_MS, WINDOW_HELLO_TIMEOUT_MS, WINDOW_JAR_MODE_TIMEOUT_MS, WindowMiddleControl, WriteData };
|
|
4
|
+
export { ATTACH_FRAME_KEY, ATTACH_WINDOW_KEY, ATTACH_WINDOW_MESSAGE, Account, AccountChange, AccountPinOptions, AddressLookupResult, AdoptRequest, AdoptState, type ClearCookiesWire, ConflictChoice, ConflictRequest, ConflictSide, ConnectAvailability, ConnectOptions, type CookieMatchWire, DisplayCause, DisplayLevel, DnsLookup, EncryptionState, FRAME_MESSAGE, FrameConsentAnswer, FrameConsentRequest, FrameFetchScope, FrameMessageRelay, HiddenSurface, InstallOptions, InstalledPackage, IpFamily, JAR_ANCHOR_MESSAGE, type JarSeed, type JarSeedCookie, MiddleControl, MiddleGotoOptions, MountDescriptor, OverlayRect, OverlayState, PackageQuery, PackageResult, PackagesErrorCode, PackagesFail, PickOptions, Placement, ProxyFetch, ProxyFetchInit, ProxyFetchInput, Quota, RELAY_CHOICE_UNSUPPORTED, RELAY_HEADER, RELAY_UNAVAILABLE, ROOM_TEMPORARY_MS, Radii, type RelayChoice, RelayResolution, Resolvers, RoomBacklog, RoomClaimOptions, RoomCreateOptions, RoomDefaults, RoomEnd, RoomEnvelope, RoomEvent, RoomHandle, RoomJoinOptions, RoomJson, RoomMailbox, RoomMember, RoomMessage, RoomOpenOptions, RoomPermission, RoomPermissions, RoomSchema, RoomType, RoomsErrorCode, RoomsFail, SHELL_ATTACH_ERROR, SHELL_CONTROL_KEY, SHELL_FRAME_MESSAGE, SHELL_JAR_MESSAGE, SHELL_JAR_UNREACHABLE, STORAGE_REFUSALS, SetOverlayHost, ShellControl, ShellFrameMessage, ShellGotoOptions, ShellJarUnreachable, StorageEntry, StorageErrorCode, StorageFail, StorageProgress, StoragePutOptions, StoragePutWire, StorageQuota, StoredHandle, StoredObject, StoredPage, SurfaceRect, TcpSocketListenerOptions, TcpSocketListenerResult, type TcpSocketOption, TcpSocketOptions, TcpSocketResult, UdpDatagram, type UdpSocketOption, UdpSocketOptions, UdpSocketResult, WINDOW_HANDSHAKE_TIMEOUT_MS, WINDOW_HELLO_TIMEOUT_MS, WINDOW_JAR_MODE_TIMEOUT_MS, WindowMiddleControl, WriteData };
|
package/contract.js
CHANGED
|
@@ -96,6 +96,6 @@ var e = "fkn-attach-frame", t = "fkn-attach-window", n = "sdbx-control", r = "sd
|
|
|
96
96
|
code: "unavailable",
|
|
97
97
|
message: "storage: storage is unavailable"
|
|
98
98
|
}
|
|
99
|
-
};
|
|
99
|
+
}, h = "fkn-relay", g = "RelayUnavailableError", _ = "this FKN page cannot choose a relay; reload the app to load the current one";
|
|
100
100
|
//#endregion
|
|
101
|
-
export { e as ATTACH_FRAME_KEY, t as ATTACH_WINDOW_KEY, o as ATTACH_WINDOW_MESSAGE, i as FRAME_MESSAGE, l as JAR_ANCHOR_MESSAGE, p as ROOM_TEMPORARY_MS, r as SHELL_ATTACH_ERROR, n as SHELL_CONTROL_KEY, a as SHELL_FRAME_MESSAGE, s as SHELL_JAR_MESSAGE, c as SHELL_JAR_UNREACHABLE, m as STORAGE_REFUSALS, f as WINDOW_HANDSHAKE_TIMEOUT_MS, u as WINDOW_HELLO_TIMEOUT_MS, d as WINDOW_JAR_MODE_TIMEOUT_MS };
|
|
101
|
+
export { e as ATTACH_FRAME_KEY, t as ATTACH_WINDOW_KEY, o as ATTACH_WINDOW_MESSAGE, i as FRAME_MESSAGE, l as JAR_ANCHOR_MESSAGE, _ as RELAY_CHOICE_UNSUPPORTED, h as RELAY_HEADER, g as RELAY_UNAVAILABLE, p as ROOM_TEMPORARY_MS, r as SHELL_ATTACH_ERROR, n as SHELL_CONTROL_KEY, a as SHELL_FRAME_MESSAGE, s as SHELL_JAR_MESSAGE, c as SHELL_JAR_UNREACHABLE, m as STORAGE_REFUSALS, f as WINDOW_HANDSHAKE_TIMEOUT_MS, u as WINDOW_HELLO_TIMEOUT_MS, d as WINDOW_JAR_MODE_TIMEOUT_MS };
|
package/dgram.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-CNYWAaFu.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./utils-BpHmMkIR.cjs"),i=require("./wire.cjs");let a=require("buffer"),o=require("events"),s=require("ip-address");var c=e.t({Socket:()=>l,createSocket:()=>h,default:()=>g}),l=class extends o.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){if(!this._webVPNUdpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before bind`));return}this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:i.UDP_PORT_ACK_TYPE,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,i=0;for(;i+4<=e.byteLength;){let o=t.getUint32(i);i+=4;let s=i+o;if(s>e.byteLength)break;let c=i+4,l=t.getUint8(c);c+=1;let u,d,f;if(l===2){if(!this._remoteAddress){i=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,f=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=p(n)),c+=n.byteLength,f=t.getUint16(c),c+=2}let m=t.getUint32(c);c+=4;try{this.emit(`message`,a.Buffer.from(e.slice(c,c+m)),{address:u,family:d,port:f,size:m})}catch(e){n||(n=!0,r=e)}i=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return u;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=s.Address4.isValid(e)?f(e):m(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(s.Address4.isValid(e)){let n=f(e),r=t&&s.Address4.isValid(t)?f(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(s.Address6.isValid(e)){let t=m(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=r.i(...e),i=this._type===`udp6`?`::`:`0.0.0.0`,a=this.__webvpn_udp_socket_init__(t.s(`a udp socket`).then(e=>e.cloud.webvpn.udpSocket({type:this._type,address:n.address??i,port:n.port,dataPort:!0})));return n.callback&&a.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,a.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(s.Address4.isValid(e)){let n=f(e),r=t&&s.Address4.isValid(t)?f(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(s.Address6.isValid(e)){let t=m(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=r.a(...e),n=d(t.message),i=n;if(t.hasRange){let{offset:e,length:r}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(r)||r<0||r>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});i=n.subarray(e,e+r)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,r=t.address??a,o=this._remoteAddress!==void 0&&t.address===void 0;if(this._dataPort&&(o||s.Address4.isValid(r)||s.Address6.isValid(r))){this._portSend(i,o?void 0:r,o?void 0:t.port),n?.call(this,null,i.byteLength);return}e.send({port:t.port,address:r,message:i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}).then(()=>n?.call(this,null,i.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},u=new Uint8Array([2]),d=e=>{if(typeof e==`string`)return r.s.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(d),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},f=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},p=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},m=e=>{let t=new s.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},h=(e,t)=>{let n=new l(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},g={Socket:l,createSocket:h};exports.Socket=l,exports.createSocket=h,exports.default=g,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}});
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-ibGqkmtA.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./relay-choice-JC_JJY_M.cjs"),i=require("./utils-BpHmMkIR.cjs"),a=require("./wire.cjs");let o=require("buffer"),s=require("events"),c=require("ip-address");var l=e.t({Socket:()=>u,createSocket:()=>g,default:()=>_}),u=class extends s.EventEmitter{_type;_localAddress;_remoteAddress;_connectedLocally;_connectGeneration=0;_destroyed=!1;_busyRelease;_webVPNUdpSocketPromise;_dataPort;_socketId;_sendQueue=[];_sendQueueBytes=0;_sendFlushScheduled=!1;_peerTailCache=new Map;_relayChoice;_relay;constructor(e){if(super(e),!e)throw Error(`Missing options`);this._type=e.type,this._relayChoice=e.relay,e.connection&&this.__webvpn_udp_socket_init__(e.connection)}_lastRecvBufferSize=0;_lastSendBufferSize=0;_lastTtl=64;_lastMulticastTtl=1;_lastMulticastLoopback=!0;_setUdpOption(e){if(!this._webVPNUdpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before bind`));return}this._webVPNUdpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}_dataPortAcks=!1;_dataPortConsumedBytes=0;_dataPortAckedBytes=0;_ackDataPortBatch(e){if(!this._dataPortAcks||!this._dataPort||(this._dataPortConsumedBytes+=e,this._dataPortAckedBytes!==0&&this._dataPortConsumedBytes-this._dataPortAckedBytes<524288))return;this._dataPortAckedBytes=this._dataPortConsumedBytes;let t={type:a.UDP_PORT_ACK_TYPE,consumedBytes:this._dataPortConsumedBytes};this._dataPort.postMessage(t)}_onTransportClosed(e){this._destroyed||(this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0,this.listenerCount(`error`)>0&&this.emit(`error`,Error(e||`WebVPN session closed`)),this.emit(`close`))}_onDataPortBatch(e){let t=new DataView(e),n=!1,r,i=0;for(;i+4<=e.byteLength;){let a=t.getUint32(i);i+=4;let s=i+a;if(s>e.byteLength)break;let c=i+4,l=t.getUint8(c);c+=1;let u,d,f;if(l===2){if(!this._remoteAddress){i=s;continue}u=this._remoteAddress.address,d=this._remoteAddress.family,f=this._remoteAddress.port}else{let n=new Uint8Array(e,c,l===0?4:16);l===0?(d=`IPv4`,u=`${n[0]}.${n[1]}.${n[2]}.${n[3]}`):(d=`IPv6`,u=m(n)),c+=n.byteLength,f=t.getUint16(c),c+=2}let p=t.getUint32(c);c+=4;try{this.emit(`message`,o.Buffer.from(e.slice(c,c+p)),{address:u,family:d,port:f,size:p})}catch(e){n||(n=!0,r=e)}i=s}if(n)throw r}_peerTail(e,t){if(e===void 0||t===void 0)return d;let n=`${e}|${t}`,r=this._peerTailCache.get(n);if(r)return r;let i=c.Address4.isValid(e)?p(e):h(e),a=new Uint8Array(1+i.byteLength+2);return a[0]=i.byteLength===4?0:1,a.set(i,1),new DataView(a.buffer).setUint16(1+i.byteLength,t),this._peerTailCache.size>=4096&&this._peerTailCache.clear(),this._peerTailCache.set(n,a),a}_portSend(e,t,n){let r=this._peerTail(t,n),i=new Uint8Array(8+r.byteLength+4+e.byteLength),a=new DataView(i.buffer);a.setUint32(0,i.byteLength-4),a.setUint32(4,this._socketId),i.set(r,8),a.setUint32(8+r.byteLength,e.byteLength),i.set(e,12+r.byteLength),this._sendQueue.push(i),this._sendQueueBytes+=i.byteLength,!this._sendFlushScheduled&&(this._sendFlushScheduled=!0,queueMicrotask(()=>{this._sendFlushScheduled=!1;let e=this._sendQueue,t=this._sendQueueBytes;if(this._sendQueue=[],this._sendQueueBytes=0,!e.length||!this._dataPort)return;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;this._dataPort.postMessage(n.buffer,[n.buffer])}))}addMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:5,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:7,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}address(){if(!this._localAddress)throw Error(`EBADF`);return this._localAddress}bind(...e){let n=i.i(...e),a=this._type===`udp6`?`::`:`0.0.0.0`,o=this._relayChoice,s=this.__webvpn_udp_socket_init__(t.s(`a udp socket`).then(e=>(o!==void 0&&r.t(e,`dgram.createSocket`),e.cloud.webvpn.udpSocket({type:this._type,address:n.address??a,port:n.port,dataPort:!0,relay:o}))));return n.callback&&s.then(e=>{e&&n.callback.call(this)}),this}__webvpn_udp_socket_init__(e,t){return t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort}),this._busyRelease??=n.t(`udp socket`),this._webVPNUdpSocketPromise=e.then(e=>{if(e.dataPort)this._socketId=e.socketId,this._dataPort=e.dataPort,this._dataPortAcks=e.dataPortAcks===!0,this._dataPort.onmessage=e=>{try{this._onDataPortBatch(e.data)}finally{this._ackDataPortBatch(e.data.byteLength)}};else{let t=e.dataReadableStream.getReader();(async()=>{for(;;){let{value:e,done:n}=await t.read();if(n)return;this.emit(`message`,o.Buffer.from(e.data),{address:e.address,family:e.family,port:e.port,size:e.size})}})().catch(e=>this._onTransportClosed(e instanceof Error?e.message:void 0))}return e.closed?.then(e=>this._onTransportClosed(e?.reason)).catch(()=>{}),this._relay=e.relay,this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e}).catch(e=>{this.emit(`error`,e)}),this._webVPNUdpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNUdpSocketPromise}close(e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);return this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=this._destroyed;this._destroyed=!0,this._busyRelease?.(),this._dataPort?.close(),this._dataPort=void 0;try{await t.close()}finally{try{e&&e()}finally{n||this.emit(`close`)}}}).catch(()=>{}),this}connect(...e){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not bound`);let n=e[0],r=this._type===`udp6`?`::1`:`127.0.0.1`,i=typeof e[1]==`string`?e[1]:r,a=typeof e.at(-1)==`function`?e.at(-1):void 0,o=await t.connect({remotePort:n,remoteAddress:i});this._connectedLocally=o?.local===!0,this._remoteAddress=o?.address?{address:o.address,family:o.family,port:o.port}:{address:i,family:this._type===`udp6`?`IPv6`:`IPv4`,port:n},this._connectGeneration+=1,a&&a()}).catch(e=>{this.emit(`error`,e)})}disconnect(){if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);let e=this._remoteAddress,t=this._connectedLocally,n=this._connectGeneration;this._remoteAddress=void 0,this._connectedLocally=void 0,this._webVPNUdpSocketPromise.then(e=>e?.disconnect?.()).catch(r=>{this._connectGeneration===n&&(this._remoteAddress=e,this._connectedLocally=t),this.emit(`error`,r)})}dropMembership(e,t){if(c.Address4.isValid(e)){let n=p(e),r=t&&c.Address4.isValid(t)?p(t):new Uint8Array([0,0,0,0]);this._setUdpOption({type:6,group:n,interface:r})}else if(c.Address6.isValid(e)){let t=h(e);this._setUdpOption({type:8,group:t,ifIndex:0})}else this.emit(`error`,Error(`Invalid multicast address: ${e}`))}getRecvBufferSize(){return this._lastRecvBufferSize}getSendBufferSize(){return this._lastSendBufferSize}getSendQueueSize(){return 0}getSendQueueCount(){return 0}ref(){return this}remoteAddress(){if(!this._remoteAddress)throw Error(`ERR_SOCKET_DGRAM_NOT_CONNECTED`);return{address:this._remoteAddress.address,family:this._remoteAddress.family,port:this._remoteAddress.port}}send(...e){this._webVPNUdpSocketPromise||this.bind();let t=i.a(...e),n=f(t.message),r=n;if(t.hasRange){let{offset:e,length:i}=t;if(!Number.isInteger(e)||e<0||e>n.byteLength)throw Object.assign(RangeError(`"offset" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});if(!Number.isInteger(i)||i<0||i>n.byteLength-e)throw Object.assign(RangeError(`"length" is outside of buffer bounds`),{code:`ERR_BUFFER_OUT_OF_BOUNDS`});r=n.subarray(e,e+i)}let a=this._type===`udp6`?`::1`:`127.0.0.1`;if(!this._webVPNUdpSocketPromise)throw Error(`Socket not bound`);this._webVPNUdpSocketPromise.then(e=>{if(!e)throw Error(`Socket not bound`);let n=t.callback,i=t.address??a,o=this._remoteAddress!==void 0&&t.address===void 0;if(this._dataPort&&(o||c.Address4.isValid(i)||c.Address6.isValid(i))){this._portSend(r,o?void 0:i,o?void 0:t.port),n?.call(this,null,r.byteLength);return}e.send({port:t.port,address:i,message:r.byteOffset===0&&r.byteLength===r.buffer.byteLength?r.buffer:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)}).then(()=>n?.call(this,null,r.byteLength),e=>n?n.call(this,e,0):this.emit(`error`,e))})}setBroadcast(e){this._setUdpOption({type:0,value:e})}setMulticastInterface(e){}setMulticastLoopback(e){return this._setUdpOption({type:3,value:e}),this._setUdpOption({type:4,value:e}),this._lastMulticastLoopback=e,e}setMulticastTTL(e){return this._setUdpOption({type:2,value:e}),this._lastMulticastTtl=e,e}setRecvBufferSize(e){this._setUdpOption({type:10,value:e}),this._lastRecvBufferSize=e}setSendBufferSize(e){this._setUdpOption({type:9,value:e}),this._lastSendBufferSize=e}setTTL(e){return this._setUdpOption({type:1,value:e}),this._lastTtl=e,e}unref(){return this}addSourceSpecificMembership(e,t,n){}dropSourceSpecificMembership(e,t,n){}async[Symbol.asyncDispose](){await new Promise(e=>{this.close(e)})}},d=new Uint8Array([2]),f=e=>{if(typeof e==`string`)return i.s.encode(e);if(e instanceof Uint8Array)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(Array.isArray(e)){let t=e.map(f),n=new Uint8Array(t.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of t)n.set(e,r),r+=e.byteLength;return n}return new Uint8Array(e)},p=e=>{let t=e.split(`.`).map(e=>parseInt(e,10));if(t.length!==4||t.some(e=>Number.isNaN(e)||e<0||e>255))throw Error(`Invalid IPv4 address: ${e}`);return new Uint8Array(t)},m=e=>{let t=[];for(let n=0;n<16;n+=2)t.push(e[n]<<8|e[n+1]);let n=-1,r=1;for(let e=0;e<8;){if(t[e]!==0){e++;continue}let i=e;for(;i<8&&t[i]===0;)i++;i-e>r&&(n=e,r=i-e),e=i}return n===-1?t.map(e=>e.toString(16)).join(`:`):`${t.slice(0,n).map(e=>e.toString(16)).join(`:`)}::${t.slice(n+r).map(e=>e.toString(16)).join(`:`)}`},h=e=>{let t=new c.Address6(e).getBitsBase16(0,128).match(/.{2}/g);if(!t||t.length!==16)throw Error(`Invalid IPv6 address: ${e}`);return new Uint8Array(t.map(e=>parseInt(e,16)))},g=(e,t)=>{let n=new u(typeof e==`string`?{type:e}:e);return t&&n.on(`message`,t),n},_={Socket:u,createSocket:g};exports.Socket=u,exports.createSocket=g,exports.default=_,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}});
|
package/dgram.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as RelayChoice } from "./index-C5DdoMGo.js";
|
|
2
|
+
import { Gt as UdpSocketResult, X as Resolvers } from "./contract-B8Rqx5BD.js";
|
|
2
3
|
import { x as UdpSocketOption } from "./wire-Fk5pJaoy.js";
|
|
3
|
-
import "./api-
|
|
4
|
+
import "./api-BD_XUANc.js";
|
|
5
|
+
import { t as RelayOption } from "./relay-choice-BmXlqfD2.js";
|
|
4
6
|
import { Buffer } from "buffer";
|
|
5
7
|
import { AddressInfo } from "net";
|
|
6
|
-
import { EventEmitter } from "events";
|
|
7
8
|
import { BindOptions, RemoteInfo, Socket as Socket$2, SocketOptions, SocketType } from "dgram";
|
|
9
|
+
import { EventEmitter } from "events";
|
|
8
10
|
declare namespace dgram_d_exports {
|
|
9
11
|
export { Socket, createSocket, _default as default };
|
|
10
12
|
}
|
|
@@ -38,7 +40,10 @@ export declare class Socket extends EventEmitter implements Socket$2 {
|
|
|
38
40
|
_sendQueueBytes: number;
|
|
39
41
|
_sendFlushScheduled: boolean;
|
|
40
42
|
_peerTailCache: Map<string, Uint8Array<ArrayBufferLike>>;
|
|
41
|
-
|
|
43
|
+
_relayChoice?: RelayChoice;
|
|
44
|
+
/** the relay serving this socket once it is bound, read through `relayOf` */
|
|
45
|
+
_relay?: string;
|
|
46
|
+
constructor(options: SocketOptions & EventEmitterOptions & RelayOption & {
|
|
42
47
|
connection?: ReturnType<WebVpnUdpSocket>;
|
|
43
48
|
});
|
|
44
49
|
_lastRecvBufferSize: number;
|
|
@@ -105,7 +110,7 @@ export declare class Socket extends EventEmitter implements Socket$2 {
|
|
|
105
110
|
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string | undefined): void;
|
|
106
111
|
[Symbol.asyncDispose](): Promise<void>;
|
|
107
112
|
}
|
|
108
|
-
export declare const createSocket: (options: SocketType | SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void) => Socket;
|
|
113
|
+
export declare const createSocket: (options: SocketType | (SocketOptions & RelayOption), callback?: (msg: Buffer, rinfo: RemoteInfo) => void) => Socket;
|
|
109
114
|
declare const _default: {
|
|
110
115
|
Socket: typeof Socket;
|
|
111
116
|
createSocket: typeof createSocket;
|