@fkn/lib 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/account.cjs +1 -1
  2. package/account.js +2 -2
  3. package/api/account.d.ts +7 -0
  4. package/api/broker-bridge.d.ts +12 -0
  5. package/api/connect-store.d.ts +9 -0
  6. package/api/connect.d.ts +2 -0
  7. package/api/data-plane.d.ts +28 -0
  8. package/api/dns/index.d.ts +1 -0
  9. package/api/dns/lookup.d.ts +8 -0
  10. package/api/index.d.ts +78 -0
  11. package/api/install-prompt.d.ts +2 -0
  12. package/api/local-net/index.d.ts +43 -0
  13. package/api/overlay-mount.d.ts +2 -0
  14. package/api/overlay.d.ts +17 -0
  15. package/api/packages/host.d.ts +12 -0
  16. package/api/packages/identity.d.ts +1 -0
  17. package/api/packages/index.d.ts +34 -0
  18. package/api/packages/picker.d.ts +28 -0
  19. package/api/packages/registry.d.ts +20 -0
  20. package/api/packages/store.d.ts +6 -0
  21. package/api/packages/types.d.ts +56 -0
  22. package/api/preconnect.d.ts +1 -0
  23. package/api/proxy/index.d.ts +1 -0
  24. package/api/proxy/proxy-fetch.d.ts +5 -0
  25. package/api/quota.d.ts +10 -0
  26. package/api/rate-token.d.ts +3 -0
  27. package/api/session-limit.d.ts +1 -0
  28. package/api/storage.d.ts +20 -0
  29. package/api/toast.d.ts +1 -0
  30. package/api/token-source.d.ts +4 -0
  31. package/api/ui-events.d.ts +8 -0
  32. package/api/ui-host.d.ts +2 -0
  33. package/api/webvpn/index.d.ts +3 -0
  34. package/api/webvpn/packets/metadata.d.ts +31 -0
  35. package/api/webvpn/packets/tcp-listener.d.ts +39 -0
  36. package/api/webvpn/packets/tcp.d.ts +88 -0
  37. package/api/webvpn/packets/udp.d.ts +183 -0
  38. package/api/webvpn/packets/utils.d.ts +24 -0
  39. package/api/webvpn/tcp-listener.d.ts +11 -0
  40. package/api/webvpn/tcp.d.ts +33 -0
  41. package/api/webvpn/udp.d.ts +33 -0
  42. package/api/webvpn/utils.d.ts +26 -0
  43. package/api/webvpn/webtransport.d.ts +62 -0
  44. package/api/worker/client.d.ts +3 -0
  45. package/api/worker/protocol.d.ts +15 -0
  46. package/{api-CDb2pv7C.cjs → api-DD5v1qP9.cjs} +1 -1
  47. package/{background-TtzKw6g0.js → background-BVBbBOmL.js} +41 -66
  48. package/background-B_VgpARk.cjs +1 -0
  49. package/cloud/dgram.cjs +1 -1
  50. package/cloud/dgram.js +2 -4
  51. package/cloud/dns.cjs +1 -1
  52. package/cloud/dns.js +0 -1
  53. package/cloud/fs/promises.cjs +1 -1
  54. package/cloud/fs/promises.js +0 -3
  55. package/cloud/fs.cjs +1 -1
  56. package/cloud/fs.js +3 -4
  57. package/cloud/http.cjs +1 -1
  58. package/cloud/http.js +0 -3
  59. package/cloud/net.cjs +1 -1
  60. package/cloud/net.js +2 -3
  61. package/cloud-5o7yJHeX.cjs +1 -0
  62. package/cloud-BFyf2uC7.js +112 -0
  63. package/cloud.cjs +1 -1
  64. package/cloud.js +8 -12
  65. package/connect-button-BBEjXzB3.cjs +1 -0
  66. package/connect-button-Ds9KpXHe.js +7 -0
  67. package/desktop.cjs +1 -1
  68. package/desktop.js +1 -1
  69. package/dgram-CE43gJq9.cjs +1 -0
  70. package/{dgram-DS5_yPc5.js → dgram-wtjARbt0.js} +30 -22
  71. package/dgram.cjs +1 -1
  72. package/dgram.js +1 -3
  73. package/dns.cjs +1 -1
  74. package/dns.js +2 -2
  75. package/extension-CPj10qwa.js +67 -0
  76. package/extension-D-NUXxzF.cjs +1 -0
  77. package/extension.cjs +1 -1
  78. package/extension.js +3 -5
  79. package/fs/promises.cjs +1 -1
  80. package/fs/promises.js +1 -4
  81. package/fs-BfmfMBiw.cjs +1 -0
  82. package/{fs-CQ-eWjXw.js → fs-D6nNf1mR.js} +4 -4
  83. package/fs.cjs +1 -1
  84. package/fs.js +1 -4
  85. package/http.cjs +2 -2
  86. package/http.js +7 -7
  87. package/index.cjs +1 -1
  88. package/index.js +23 -38
  89. package/{account.d.ts → lib/account.d.ts} +5 -8
  90. package/lib/api.d.ts +300 -0
  91. package/lib/auto.d.ts +5 -0
  92. package/lib/cloud/dgram.d.ts +2 -0
  93. package/lib/cloud/dns.d.ts +1 -0
  94. package/lib/cloud/frame.d.ts +3 -0
  95. package/lib/cloud/fs-promises.d.ts +5 -0
  96. package/lib/cloud/fs.d.ts +22 -0
  97. package/lib/cloud/http.d.ts +2 -0
  98. package/lib/cloud/net.d.ts +2 -0
  99. package/lib/cloud.d.ts +10 -0
  100. package/lib/connect-button.d.ts +1 -0
  101. package/lib/connect.d.ts +1 -0
  102. package/{desktop.d.ts → lib/desktop.d.ts} +6 -8
  103. package/lib/dns.d.ts +6 -0
  104. package/lib/dom.d.ts +2 -0
  105. package/lib/extension-prompt.d.ts +1 -0
  106. package/lib/extension.d.ts +4 -0
  107. package/lib/fkn-target.d.ts +1 -0
  108. package/lib/frame.d.ts +2 -0
  109. package/lib/fs/content-type.d.ts +1 -0
  110. package/lib/fs/hybrid.d.ts +10 -0
  111. package/lib/fs/index.d.ts +87 -0
  112. package/lib/fs/opfs.d.ts +8 -0
  113. package/lib/fs/promises.d.ts +8 -0
  114. package/lib/fs/types.d.ts +16 -0
  115. package/lib/index.d.ts +18 -0
  116. package/lib/node-fs/index.d.ts +95 -0
  117. package/lib/node-fs/shared.d.ts +39 -0
  118. package/lib/node-fs/store.d.ts +21 -0
  119. package/lib/opfs/index.d.ts +84 -0
  120. package/lib/opfs/promises.d.ts +8 -0
  121. package/lib/overlay.d.ts +14 -0
  122. package/lib/packages.d.ts +69 -0
  123. package/lib/proxy.d.ts +5 -0
  124. package/lib/quota.d.ts +20 -0
  125. package/lib/react.d.ts +7 -0
  126. package/lib/relay.d.ts +5 -0
  127. package/lib/storage.d.ts +22 -0
  128. package/lib/webvpn/dgram.d.ts +86 -0
  129. package/lib/webvpn/http.d.ts +180 -0
  130. package/lib/webvpn/index.d.ts +1 -0
  131. package/lib/webvpn/net.d.ts +132 -0
  132. package/lib/webvpn/utils.d.ts +32 -0
  133. package/net-CpuAhaQC.cjs +1 -0
  134. package/{net-Bl6_W3bd.js → net-DKMWPXb_.js} +3 -3
  135. package/net.cjs +1 -1
  136. package/net.js +2 -3
  137. package/node-fs-C0eKnboT.cjs +1 -0
  138. package/{node-fs-Bd_UUx1m.js → node-fs-Dbf93qP7.js} +40 -17
  139. package/opfs/promises.cjs +1 -1
  140. package/opfs/promises.js +2 -3
  141. package/{opfs-BfcYLPGb.js → opfs-7_GmzQ93.js} +1 -1
  142. package/opfs-uClkgnb5.cjs +1 -0
  143. package/opfs.cjs +1 -1
  144. package/opfs.js +33 -32
  145. package/package.json +31 -21
  146. package/packages.cjs +1 -0
  147. package/packages.js +150 -0
  148. package/{locator-DxAsGV_o.js → proxy-C8SG1Beo.js} +542 -344
  149. package/proxy-bPaU3-Cz.cjs +53 -0
  150. package/react.cjs +1 -0
  151. package/react.js +18 -0
  152. package/{chunk-CPXzm0be.js → rolldown-runtime-DF993M8W.js} +1 -1
  153. package/rolldown-runtime-Doa5O59j.cjs +1 -0
  154. package/sandbox.d.ts +7 -0
  155. package/storage-OkwsFLN1.cjs +1 -0
  156. package/{storage-BcJfnkm3.js → storage-TmeyhZGt.js} +2 -2
  157. package/{utils-BsNRWMfl.cjs → utils-CoimMjf9.cjs} +1 -1
  158. package/background-Dk_vaVP1.cjs +0 -1
  159. package/chunk-B6C_zzib.cjs +0 -1
  160. package/cloud/dgram.d.ts +0 -537
  161. package/cloud/dns.d.ts +0 -12
  162. package/cloud/fs/promises.d.ts +0 -45
  163. package/cloud/fs.d.ts +0 -75
  164. package/cloud/http.d.ts +0 -767
  165. package/cloud/net.d.ts +0 -606
  166. package/cloud-BrY9dKwV.cjs +0 -1
  167. package/cloud-C-LK4DWa.js +0 -33
  168. package/cloud.d.ts +0 -1053
  169. package/dgram-C5rGcbej.cjs +0 -1
  170. package/dgram.d.ts +0 -541
  171. package/dns.d.ts +0 -12
  172. package/extension-9Uv_0HdS.cjs +0 -1
  173. package/extension-Dgz0UTy0.js +0 -245
  174. package/extension.d.ts +0 -852
  175. package/favicon.svg +0 -5
  176. package/fs/promises.d.ts +0 -65
  177. package/fs-Bc6087fG.cjs +0 -1
  178. package/fs.d.ts +0 -138
  179. package/http.d.ts +0 -767
  180. package/index.d.ts +0 -2254
  181. package/locator-Cf7M3QKN.cjs +0 -53
  182. package/net-C5kWnI4C.cjs +0 -1
  183. package/net.d.ts +0 -606
  184. package/node-fs-lrlD_zqB.cjs +0 -1
  185. package/opfs/promises.d.ts +0 -46
  186. package/opfs-Dsi4FkJU.cjs +0 -1
  187. package/opfs.d.ts +0 -83
  188. package/proxy-A9UvWUaF.cjs +0 -1
  189. package/proxy-wiZN4eTR.js +0 -14
  190. package/storage-C2-_-bTO.cjs +0 -1
  191. /package/{api-ByfayMm1.js → api--bnCFd4w.js} +0 -0
  192. /package/{utils-CNydj3OT.js → utils-DPtyxGQu.js} +0 -0
package/package.json CHANGED
@@ -1,105 +1,115 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
4
4
  "main": "index.js",
5
- "types": "index.d.ts",
5
+ "types": "lib/index.d.ts",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./index.d.ts",
9
+ "types": "./lib/index.d.ts",
10
10
  "import": "./index.js",
11
11
  "require": "./index.cjs"
12
12
  },
13
13
  "./fs": {
14
- "types": "./fs.d.ts",
14
+ "types": "./lib/fs/index.d.ts",
15
15
  "import": "./fs.js",
16
16
  "require": "./fs.cjs"
17
17
  },
18
18
  "./fs/promises": {
19
- "types": "./fs/promises.d.ts",
19
+ "types": "./lib/fs/promises.d.ts",
20
20
  "import": "./fs/promises.js",
21
21
  "require": "./fs/promises.cjs"
22
22
  },
23
23
  "./opfs": {
24
- "types": "./opfs.d.ts",
24
+ "types": "./lib/opfs/index.d.ts",
25
25
  "import": "./opfs.js",
26
26
  "require": "./opfs.cjs"
27
27
  },
28
28
  "./opfs/promises": {
29
- "types": "./opfs/promises.d.ts",
29
+ "types": "./lib/opfs/promises.d.ts",
30
30
  "import": "./opfs/promises.js",
31
31
  "require": "./opfs/promises.cjs"
32
32
  },
33
33
  "./cloud": {
34
- "types": "./cloud.d.ts",
34
+ "types": "./lib/cloud.d.ts",
35
35
  "import": "./cloud.js",
36
36
  "require": "./cloud.cjs"
37
37
  },
38
38
  "./cloud/fs": {
39
- "types": "./cloud/fs.d.ts",
39
+ "types": "./lib/cloud/fs.d.ts",
40
40
  "import": "./cloud/fs.js",
41
41
  "require": "./cloud/fs.cjs"
42
42
  },
43
43
  "./cloud/fs/promises": {
44
- "types": "./cloud/fs/promises.d.ts",
44
+ "types": "./lib/cloud/fs-promises.d.ts",
45
45
  "import": "./cloud/fs/promises.js",
46
46
  "require": "./cloud/fs/promises.cjs"
47
47
  },
48
48
  "./cloud/net": {
49
- "types": "./cloud/net.d.ts",
49
+ "types": "./lib/cloud/net.d.ts",
50
50
  "import": "./cloud/net.js",
51
51
  "require": "./cloud/net.cjs"
52
52
  },
53
53
  "./cloud/dgram": {
54
- "types": "./cloud/dgram.d.ts",
54
+ "types": "./lib/cloud/dgram.d.ts",
55
55
  "import": "./cloud/dgram.js",
56
56
  "require": "./cloud/dgram.cjs"
57
57
  },
58
58
  "./cloud/http": {
59
- "types": "./cloud/http.d.ts",
59
+ "types": "./lib/cloud/http.d.ts",
60
60
  "import": "./cloud/http.js",
61
61
  "require": "./cloud/http.cjs"
62
62
  },
63
63
  "./cloud/dns": {
64
- "types": "./cloud/dns.d.ts",
64
+ "types": "./lib/cloud/dns.d.ts",
65
65
  "import": "./cloud/dns.js",
66
66
  "require": "./cloud/dns.cjs"
67
67
  },
68
68
  "./net": {
69
- "types": "./net.d.ts",
69
+ "types": "./lib/webvpn/net.d.ts",
70
70
  "import": "./net.js",
71
71
  "require": "./net.cjs"
72
72
  },
73
73
  "./dgram": {
74
- "types": "./dgram.d.ts",
74
+ "types": "./lib/webvpn/dgram.d.ts",
75
75
  "import": "./dgram.js",
76
76
  "require": "./dgram.cjs"
77
77
  },
78
78
  "./http": {
79
- "types": "./http.d.ts",
79
+ "types": "./lib/webvpn/http.d.ts",
80
80
  "import": "./http.js",
81
81
  "require": "./http.cjs"
82
82
  },
83
83
  "./dns": {
84
- "types": "./dns.d.ts",
84
+ "types": "./lib/dns.d.ts",
85
85
  "import": "./dns.js",
86
86
  "require": "./dns.cjs"
87
87
  },
88
88
  "./extension": {
89
- "types": "./extension.d.ts",
89
+ "types": "./lib/extension.d.ts",
90
90
  "import": "./extension.js",
91
91
  "require": "./extension.cjs"
92
92
  },
93
93
  "./desktop": {
94
- "types": "./desktop.d.ts",
94
+ "types": "./lib/desktop.d.ts",
95
95
  "import": "./desktop.js",
96
96
  "require": "./desktop.cjs"
97
97
  },
98
98
  "./account": {
99
- "types": "./account.d.ts",
99
+ "types": "./lib/account.d.ts",
100
100
  "import": "./account.js",
101
101
  "require": "./account.cjs"
102
102
  },
103
+ "./packages": {
104
+ "types": "./lib/packages.d.ts",
105
+ "import": "./packages.js",
106
+ "require": "./packages.cjs"
107
+ },
108
+ "./react": {
109
+ "types": "./lib/react.d.ts",
110
+ "import": "./react.js",
111
+ "require": "./react.cjs"
112
+ },
103
113
  "./package.json": "./package.json"
104
114
  },
105
115
  "dependencies": {
package/packages.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-Doa5O59j.cjs"),t=require("./api-DD5v1qP9.cjs");let n=require("osra");var r=e.n({attach:()=>_,connect:()=>g,install:()=>p,list:()=>m,onConnect:()=>O,pick:()=>f,search:()=>d,uninstall:()=>h}),i=`https://fkn.app`,a=`fkn-packages-connection`,o=3e4,s=(e,t)=>Object.assign(Error(t),{code:e}),c=async()=>{if(!t.n)throw s(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.t},l=(e,t,r)=>(0,n.expose)(e??{},{transport:t,key:a,unregisterSignal:r}),u=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw s(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let c=new AbortController,u=new Promise((e,n)=>{let a=setTimeout(()=>n(s(`timeout`,`packages.connect: the package did not complete the connection`)),o);c.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(s(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:c.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(s(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:c.signal}),i?.then(()=>n(s(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([l(e,t,a.signal),u])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{c.abort()}},d=async e=>{let t=await(await c()).packages.search(e);if(`error`in t)throw s(t.error,t.message);return t.results},f=async(e,t)=>{let n=await(await c()).packages.pick(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?[]:n.results},p=async(e,t)=>{let n=await(await c()).packages.install(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?null:n.installed},m=async()=>(await(await c()).packages.list()).results,h=async e=>{let t=await(await c()).packages.uninstall(e);if(`error`in t)throw s(t.error,t.message)},g=(async(e,t={})=>{let n=await(await c()).packages.connect(e,{protocol:t.protocol});if(`error`in n)throw s(n.error,n.message);let{port:r,closed:i}=n;if(t.raw)return{closed:i,port:r};let a=await u(t.payload,r,{signal:t.signal,closed:i});return t.signal&&t.signal.addEventListener(`abort`,()=>{try{r.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:a,closed:i,port:r}}),_=(e,t,n)=>u(t,e,{signal:n?.signal}),v=null,y=[],b=new Map,x=!1,S=!1,C=e=>{let t=b.get(e);t&&(b.delete(e),t())},w=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},T=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&C(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw w(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>b.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},E=()=>{x||typeof window>`u`||window.parent===window||(x=!0,window.addEventListener(`message`,e=>{if(e.source!==window.parent||e.origin!==i)return;let t=e.data;if(t?.type===`fkn-packages-port`){let n=e.ports[0];if(!n)return;let r={port:n,from:typeof t.from==`string`?t.from:``,protocol:typeof t.protocol==`string`?t.protocol:null,uri:typeof t.uri==`string`?t.uri:``,name:typeof t.name==`string`?t.name:``,version:typeof t.version==`string`?t.version:``};v?T(r,v).catch(e=>console.warn(`packages.onConnect:`,e)):y.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...b.keys()])C(e)}))},D=()=>{S||typeof window>`u`||window.parent===window||(S=!0,window.parent.postMessage({type:`fkn-packages-ready`},i))},O=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};E();let n={createPayload:e,handler:t};for(v=n,D();y.length&&v===n;)T(y.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{v===n&&(v=null)}}};exports.attach=_,exports.connect=g,exports.install=p,exports.list=m,exports.onConnect=O,exports.pick=f,exports.search=d,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}}),exports.uninstall=h;
package/packages.js ADDED
@@ -0,0 +1,150 @@
1
+ import { n as e } from "./rolldown-runtime-DF993M8W.js";
2
+ import { n as t, t as n } from "./api--bnCFd4w.js";
3
+ import { expose as r } from "osra";
4
+ //#region src/lib/packages.ts
5
+ var i = /* @__PURE__ */ e({
6
+ attach: () => v,
7
+ connect: () => _,
8
+ install: () => m,
9
+ list: () => h,
10
+ onConnect: () => k,
11
+ pick: () => p,
12
+ search: () => f,
13
+ uninstall: () => g
14
+ }), a = "https://fkn.app", o = "fkn-packages-connection", s = 3e4, c = (e, t) => Object.assign(Error(t), { code: e }), l = async () => {
15
+ if (!t) throw c("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
16
+ return n;
17
+ }, u = (e, t, n) => r(e ?? {}, {
18
+ transport: t,
19
+ key: o,
20
+ unregisterSignal: n
21
+ }), d = async (e, t, n = {}) => {
22
+ let { signal: r, closed: i } = n;
23
+ if (r?.aborted) throw c("unavailable", "packages.connect: aborted before connecting");
24
+ let a = new AbortController();
25
+ r && r.addEventListener("abort", () => a.abort(r.reason), { once: !0 });
26
+ let o = new AbortController(), l = new Promise((e, n) => {
27
+ let a = setTimeout(() => n(c("timeout", "packages.connect: the package did not complete the connection")), s);
28
+ o.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
29
+ if (e.data?.type === "fkn-packages-nack") {
30
+ let t = e.data.message;
31
+ n(c("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
32
+ }
33
+ }, { signal: o.signal }), t.start(), r && r.addEventListener("abort", () => n(c("unavailable", "packages.connect: aborted before connecting")), {
34
+ once: !0,
35
+ signal: o.signal
36
+ }), i?.then(() => n(c("unavailable", "packages.connect: the package closed before connecting")));
37
+ });
38
+ try {
39
+ return await Promise.race([u(e, t, a.signal), l]);
40
+ } catch (e) {
41
+ a.abort(e);
42
+ try {
43
+ t.close();
44
+ } catch {}
45
+ throw e;
46
+ } finally {
47
+ o.abort();
48
+ }
49
+ }, f = async (e) => {
50
+ let t = await (await l()).packages.search(e);
51
+ if ("error" in t) throw c(t.error, t.message);
52
+ return t.results;
53
+ }, p = async (e, t) => {
54
+ let n = await (await l()).packages.pick(e, t);
55
+ if ("error" in n) throw c(n.error, n.message);
56
+ return "declined" in n ? [] : n.results;
57
+ }, m = async (e, t) => {
58
+ let n = await (await l()).packages.install(e, t);
59
+ if ("error" in n) throw c(n.error, n.message);
60
+ return "declined" in n ? null : n.installed;
61
+ }, h = async () => (await (await l()).packages.list()).results, g = async (e) => {
62
+ let t = await (await l()).packages.uninstall(e);
63
+ if ("error" in t) throw c(t.error, t.message);
64
+ }, _ = (async (e, t = {}) => {
65
+ let n = await (await l()).packages.connect(e, { protocol: t.protocol });
66
+ if ("error" in n) throw c(n.error, n.message);
67
+ let { port: r, closed: i } = n;
68
+ if (t.raw) return {
69
+ closed: i,
70
+ port: r
71
+ };
72
+ let a = await d(t.payload, r, {
73
+ signal: t.signal,
74
+ closed: i
75
+ });
76
+ return t.signal && t.signal.addEventListener("abort", () => {
77
+ try {
78
+ r.postMessage({ type: "fkn-packages-disconnect" });
79
+ } catch {}
80
+ }, { once: !0 }), {
81
+ remote: a,
82
+ closed: i,
83
+ port: r
84
+ };
85
+ }), v = (e, t, n) => d(t, e, { signal: n?.signal }), y = null, b = [], x = /* @__PURE__ */ new Map(), S = !1, C = !1, w = (e) => {
86
+ let t = x.get(e);
87
+ t && (x.delete(e), t());
88
+ }, T = (e, t) => {
89
+ try {
90
+ e.postMessage({
91
+ type: "fkn-packages-nack",
92
+ message: t
93
+ });
94
+ } catch {}
95
+ try {
96
+ e.close();
97
+ } catch {}
98
+ }, E = async (e, t) => {
99
+ let { port: n, ...r } = e;
100
+ e.port.addEventListener("message", (t) => {
101
+ t.data?.type === "fkn-packages-disconnect" && w(e.port);
102
+ });
103
+ let i;
104
+ try {
105
+ i = await t.createPayload(r);
106
+ } catch (t) {
107
+ throw T(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
108
+ }
109
+ let a = new Promise((t) => x.set(e.port, t)), o = await u(i, e.port);
110
+ t.handler?.({
111
+ ...r,
112
+ remote: o,
113
+ closed: a,
114
+ port: e.port
115
+ });
116
+ }, D = () => {
117
+ S || typeof window > "u" || window.parent === window || (S = !0, window.addEventListener("message", (e) => {
118
+ if (e.source !== window.parent || e.origin !== a) return;
119
+ let t = e.data;
120
+ if (t?.type === "fkn-packages-port") {
121
+ let n = e.ports[0];
122
+ if (!n) return;
123
+ let r = {
124
+ port: n,
125
+ from: typeof t.from == "string" ? t.from : "",
126
+ protocol: typeof t.protocol == "string" ? t.protocol : null,
127
+ uri: typeof t.uri == "string" ? t.uri : "",
128
+ name: typeof t.name == "string" ? t.name : "",
129
+ version: typeof t.version == "string" ? t.version : ""
130
+ };
131
+ y ? E(r, y).catch((e) => console.warn("packages.onConnect:", e)) : b.push(r);
132
+ }
133
+ if (t?.type === "fkn-packages-close") for (let e of [...x.keys()]) w(e);
134
+ }));
135
+ }, O = () => {
136
+ C || typeof window > "u" || window.parent === window || (C = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, a));
137
+ }, k = (e, t) => {
138
+ if (typeof window > "u") return { unsubscribe: () => {} };
139
+ D();
140
+ let n = {
141
+ createPayload: e,
142
+ handler: t
143
+ };
144
+ for (y = n, O(); b.length && y === n;) E(b.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
145
+ return { unsubscribe: () => {
146
+ y === n && (y = null);
147
+ } };
148
+ };
149
+ //#endregion
150
+ export { v as attach, _ as connect, m as install, h as list, k as onConnect, p as pick, f as search, i as t, g as uninstall };