@webpodjs/sdk 0.0.0-stage → 0.1.1

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 (96) hide show
  1. package/README.md +246 -2
  2. package/dist/agent/backend.d.ts +68 -0
  3. package/dist/agent/backend.js +417 -0
  4. package/dist/agent/backend.js.map +1 -0
  5. package/dist/agent/fs.d.ts +45 -0
  6. package/dist/agent/fs.js +157 -0
  7. package/dist/agent/fs.js.map +1 -0
  8. package/dist/agent/protocol.d.ts +236 -0
  9. package/dist/agent/protocol.js +368 -0
  10. package/dist/agent/protocol.js.map +1 -0
  11. package/dist/coi-serviceworker.d.ts +0 -0
  12. package/dist/coi-serviceworker.js +33 -0
  13. package/dist/coi-serviceworker.js.map +1 -0
  14. package/dist/coi.d.ts +19 -0
  15. package/dist/coi.js +54 -0
  16. package/dist/coi.js.map +1 -0
  17. package/dist/errors.d.ts +5 -0
  18. package/dist/errors.js +9 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/features.d.ts +37 -0
  21. package/dist/features.js +125 -0
  22. package/dist/features.js.map +1 -0
  23. package/dist/fs/tar.d.ts +21 -0
  24. package/dist/fs/tar.js +332 -0
  25. package/dist/fs/tar.js.map +1 -0
  26. package/dist/fs/workspace.d.ts +19 -0
  27. package/dist/fs/workspace.js +233 -0
  28. package/dist/fs/workspace.js.map +1 -0
  29. package/dist/fs-router.d.ts +8 -0
  30. package/dist/fs-router.js +50 -0
  31. package/dist/fs-router.js.map +1 -0
  32. package/dist/host/backend.d.ts +115 -0
  33. package/dist/host/backend.js +475 -0
  34. package/dist/host/backend.js.map +1 -0
  35. package/dist/host/binding.d.ts +33 -0
  36. package/dist/host/binding.js +72 -0
  37. package/dist/host/binding.js.map +1 -0
  38. package/dist/host/channel.d.ts +41 -0
  39. package/dist/host/channel.js +168 -0
  40. package/dist/host/channel.js.map +1 -0
  41. package/dist/host/controller.d.ts +264 -0
  42. package/dist/host/controller.js +484 -0
  43. package/dist/host/controller.js.map +1 -0
  44. package/dist/host/devices.d.ts +134 -0
  45. package/dist/host/devices.js +317 -0
  46. package/dist/host/devices.js.map +1 -0
  47. package/dist/host/pump-worker.d.ts +1 -0
  48. package/dist/host/pump-worker.js +102 -0
  49. package/dist/host/pump-worker.js.map +1 -0
  50. package/dist/host/qmp.d.ts +8 -0
  51. package/dist/host/qmp.js +78 -0
  52. package/dist/host/qmp.js.map +1 -0
  53. package/dist/host/ring.d.ts +85 -0
  54. package/dist/host/ring.js +389 -0
  55. package/dist/host/ring.js.map +1 -0
  56. package/dist/index.d.ts +33 -0
  57. package/dist/index.js +19 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/net/client.d.ts +19 -0
  60. package/dist/net/client.js +230 -0
  61. package/dist/net/client.js.map +1 -0
  62. package/dist/net/options.d.ts +65 -0
  63. package/dist/net/options.js +8 -0
  64. package/dist/net/options.js.map +1 -0
  65. package/dist/net/preview.d.ts +27 -0
  66. package/dist/net/preview.js +233 -0
  67. package/dist/net/preview.js.map +1 -0
  68. package/dist/net/protocol.d.ts +65 -0
  69. package/dist/net/protocol.js +13 -0
  70. package/dist/net/protocol.js.map +1 -0
  71. package/dist/pod.d.ts +43 -0
  72. package/dist/pod.js +206 -0
  73. package/dist/pod.js.map +1 -0
  74. package/dist/preview-relay.d.ts +0 -0
  75. package/dist/preview-relay.html +4 -0
  76. package/dist/preview-relay.js +107 -0
  77. package/dist/preview-relay.js.map +1 -0
  78. package/dist/preview-serviceworker.d.ts +0 -0
  79. package/dist/preview-serviceworker.js +405 -0
  80. package/dist/preview-serviceworker.js.map +1 -0
  81. package/dist/streams.d.ts +14 -0
  82. package/dist/streams.js +58 -0
  83. package/dist/streams.js.map +1 -0
  84. package/dist/testing/index.d.ts +14 -0
  85. package/dist/testing/index.js +354 -0
  86. package/dist/testing/index.js.map +1 -0
  87. package/dist/timers.d.ts +18 -0
  88. package/dist/timers.js +68 -0
  89. package/dist/timers.js.map +1 -0
  90. package/dist/types.d.ts +163 -0
  91. package/dist/types.js +14 -0
  92. package/dist/types.js.map +1 -0
  93. package/dist/units.d.ts +2 -0
  94. package/dist/units.js +31 -0
  95. package/dist/units.js.map +1 -0
  96. package/package.json +53 -4
@@ -0,0 +1,230 @@
1
+ import { WebPodError } from "../errors.js";
2
+ import { HTTP_INITIAL_CREDIT, SKIP_REQUEST_HEADERS, SKIP_RESPONSE_HEADERS, TCP_INITIAL_CREDIT } from "./protocol.js";
3
+ function send(port, cmd, transfer = []) {
4
+ port.postMessage(cmd, transfer);
5
+ }
6
+ function toBytes(chunk) {
7
+ return chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);
8
+ }
9
+ const NULL_BODY = new Set([101, 103, 204, 205, 304]);
10
+ /** Parses `http://localhost:PORT/path` (or 127.0.0.1) into port and origin-form target. */
11
+ export function guestTarget(url) {
12
+ let u;
13
+ try {
14
+ u = new URL(url);
15
+ }
16
+ catch {
17
+ throw new WebPodError("EINVAL", `invalid URL: ${url}`);
18
+ }
19
+ if (u.protocol !== "http:" || !["localhost", "127.0.0.1", "[::1]"].includes(u.hostname)) {
20
+ throw new WebPodError("EINVAL", `pod.fetch only reaches guest services at http://localhost:PORT, got ${url}`);
21
+ }
22
+ return { port: u.port ? Number(u.port) : 80, target: u.pathname + u.search };
23
+ }
24
+ /** Sends one HTTP request to a guest port through the net Worker. */
25
+ export async function fetchOverPort(sink, input, init) {
26
+ const request = new Request(input, init);
27
+ const { port, target } = guestTarget(request.url);
28
+ const headers = [];
29
+ request.headers.forEach((value, name) => {
30
+ if (!SKIP_REQUEST_HEADERS.has(name))
31
+ headers.push([name, value]);
32
+ });
33
+ const hasBody = request.method !== "GET" && request.method !== "HEAD";
34
+ const body = hasBody ? new Uint8Array(await request.arrayBuffer()) : new Uint8Array(0);
35
+ const channel = new MessageChannel();
36
+ const local = channel.port1;
37
+ send(local, { t: "http", port, method: request.method, target, headers, bodyLength: body.byteLength });
38
+ if (body.byteLength > 0)
39
+ send(local, { t: "body", chunk: body.buffer }, [body.buffer]);
40
+ send(local, { t: "end" });
41
+ sink.openPort(channel.port2);
42
+ return responseFromPort(local, request.method, request.signal);
43
+ }
44
+ /** Builds a streaming Response from replies on `port`. */
45
+ export function responseFromPort(port, method, signal, mapHeaders) {
46
+ return new Promise((resolve, reject) => {
47
+ let controller;
48
+ let settled = false;
49
+ let done = false;
50
+ let unacked = 0;
51
+ const finish = () => {
52
+ done = true;
53
+ port.onmessage = null;
54
+ port.close();
55
+ };
56
+ // Credit-based backpressure: acknowledge bytes once the consumer has room for more.
57
+ const ack = () => {
58
+ if (unacked > 0 && !done) {
59
+ send(port, { t: "ack", bytes: unacked });
60
+ unacked = 0;
61
+ }
62
+ };
63
+ signal?.addEventListener("abort", () => {
64
+ send(port, { t: "cancel" });
65
+ finish();
66
+ if (!settled)
67
+ reject(new WebPodError("ABORTED", "request aborted"));
68
+ else
69
+ controller?.error(new WebPodError("ABORTED", "request aborted"));
70
+ });
71
+ port.onmessage = (event) => {
72
+ const m = event.data;
73
+ switch (m.t) {
74
+ case "head": {
75
+ const headers = new Headers();
76
+ for (const [name, value] of m.headers) {
77
+ if (SKIP_RESPONSE_HEADERS.has(name.toLowerCase()))
78
+ continue;
79
+ try {
80
+ headers.append(name, value);
81
+ }
82
+ catch {
83
+ // invalid header value from the guest: drop it
84
+ }
85
+ }
86
+ mapHeaders?.(headers);
87
+ const nullBody = method === "HEAD" || NULL_BODY.has(m.status);
88
+ const body = nullBody
89
+ ? null
90
+ : new ReadableStream({
91
+ start(c) {
92
+ controller = c;
93
+ },
94
+ pull() {
95
+ ack();
96
+ },
97
+ cancel() {
98
+ send(port, { t: "cancel" });
99
+ finish();
100
+ },
101
+ }, { highWaterMark: HTTP_INITIAL_CREDIT, size: (chunk) => chunk.byteLength });
102
+ settled = true;
103
+ resolve(new Response(body, { status: m.status, statusText: m.statusText, headers }));
104
+ break;
105
+ }
106
+ case "data": {
107
+ const bytes = toBytes(m.chunk);
108
+ controller?.enqueue(bytes);
109
+ unacked += bytes.byteLength;
110
+ if ((controller?.desiredSize ?? 0) > 0)
111
+ ack();
112
+ break;
113
+ }
114
+ case "end":
115
+ controller?.close();
116
+ finish();
117
+ break;
118
+ case "error":
119
+ finish();
120
+ if (!settled)
121
+ reject(new WebPodError("ECONNREFUSED", m.message));
122
+ else
123
+ controller?.error(new WebPodError("ECONNRESET", m.message));
124
+ break;
125
+ }
126
+ };
127
+ port.start();
128
+ });
129
+ }
130
+ /** Opens a TCP connection to a guest port through the net Worker. */
131
+ export function connectOverPort(sink, guestPort) {
132
+ if (!Number.isInteger(guestPort) || guestPort < 1 || guestPort > 65535) {
133
+ return Promise.reject(new WebPodError("EINVAL", `invalid port: ${guestPort}`));
134
+ }
135
+ const channel = new MessageChannel();
136
+ const port = channel.port1;
137
+ return new Promise((resolve, reject) => {
138
+ let readCtl;
139
+ let unacked = 0;
140
+ let connected = false;
141
+ let done = false;
142
+ const end = () => {
143
+ done = true;
144
+ port.onmessage = null;
145
+ port.close();
146
+ };
147
+ const readable = new ReadableStream({
148
+ start(c) {
149
+ readCtl = c;
150
+ },
151
+ pull() {
152
+ if (unacked > 0 && !done) {
153
+ send(port, { t: "ack", bytes: unacked });
154
+ unacked = 0;
155
+ }
156
+ },
157
+ cancel() {
158
+ if (!done)
159
+ send(port, { t: "abort" });
160
+ end();
161
+ },
162
+ }, { highWaterMark: TCP_INITIAL_CREDIT, size: (chunk) => chunk.byteLength });
163
+ const writable = new WritableStream({
164
+ write(chunk) {
165
+ if (done)
166
+ throw new WebPodError("ECONNRESET", "connection closed");
167
+ const copy = chunk.slice();
168
+ send(port, { t: "data", chunk: copy.buffer }, [copy.buffer]);
169
+ },
170
+ close() {
171
+ if (!done)
172
+ send(port, { t: "close" });
173
+ },
174
+ abort() {
175
+ if (!done)
176
+ send(port, { t: "abort" });
177
+ end();
178
+ },
179
+ });
180
+ port.onmessage = (event) => {
181
+ const m = event.data;
182
+ switch (m.t) {
183
+ case "connected":
184
+ connected = true;
185
+ resolve({
186
+ readable,
187
+ writable,
188
+ abort: () => {
189
+ if (!done)
190
+ send(port, { t: "abort" });
191
+ end();
192
+ readCtl?.error(new WebPodError("ECONNRESET", "aborted"));
193
+ },
194
+ });
195
+ break;
196
+ case "data": {
197
+ const bytes = toBytes(m.chunk);
198
+ readCtl?.enqueue(bytes);
199
+ unacked += bytes.byteLength;
200
+ if ((readCtl?.desiredSize ?? 0) > 0) {
201
+ send(port, { t: "ack", bytes: unacked });
202
+ unacked = 0;
203
+ }
204
+ break;
205
+ }
206
+ case "closed":
207
+ readCtl?.close();
208
+ break;
209
+ case "reset":
210
+ end();
211
+ if (!connected)
212
+ reject(new WebPodError("ECONNREFUSED", `nothing is listening on guest port ${guestPort}`));
213
+ else
214
+ readCtl?.error(new WebPodError("ECONNRESET", "connection reset by the guest"));
215
+ break;
216
+ case "error":
217
+ end();
218
+ if (!connected)
219
+ reject(new WebPodError("EINVAL", m.message));
220
+ else
221
+ readCtl?.error(new WebPodError("ECONNRESET", m.message));
222
+ break;
223
+ }
224
+ };
225
+ port.start();
226
+ send(port, { t: "connect", port: guestPort });
227
+ sink.openPort(channel.port2);
228
+ });
229
+ }
230
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/net/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErH,SAAS,IAAI,CAAC,IAAiB,EAAE,GAAmB,EAAE,WAA2B,EAAE;IACjF,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,OAAO,CAAC,KAA+B;IAC9C,OAAO,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC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AAE,CAAC;oBACN,IAAI,CAAC,SAAS;wBAAE,MAAM,CAAC,IAAI,WAAW,CAAC,cAAc,EAAE,sCAAsC,SAAS,EAAE,CAAC,CAAC,CAAC;;wBACtG,OAAO,EAAE,KAAK,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,+BAA+B,CAAC,CAAC,CAAC;oBACpF,MAAM;gBACR,KAAK,OAAO;oBACV,GAAG,EAAE,CAAC;oBACN,IAAI,CAAC,SAAS;wBAAE,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;;wBACxD,OAAO,EAAE,KAAK,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC9D,MAAM;YACV,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,65 @@
1
+ /** Where a class of guest traffic goes (webpod-net routes). */
2
+ export type NetworkVia = "fetch" | "websocket" | "cors-proxy" | "relay" | "deny";
3
+ export interface NetworkRoute {
4
+ /** `example.com`, `*.pypi.org`, `10.0.0.0/8` or `*` (default). */
5
+ host?: string;
6
+ /** One port or an inclusive range. */
7
+ ports?: number | [number, number];
8
+ protocol?: "http" | "tls" | "websocket" | "tcp" | "udp";
9
+ via: NetworkVia;
10
+ /**
11
+ * With `via: "fetch"`: `"non-safelisted"` sends only CORS-safelisted request headers (Accept,
12
+ * Accept-Language, Content-Language, simple Content-Type and Range values), so GET, HEAD and
13
+ * simple POST requests need no preflight. For origins that send CORS headers but refuse
14
+ * preflights, like registry.npmjs.org (npm's `npm-session` and similar headers would trigger
15
+ * one). Every other header is dropped, `Authorization` too: not for private registries.
16
+ */
17
+ stripHeaders?: "non-safelisted";
18
+ }
19
+ /** Guest networking (the net Worker's configuration). */
20
+ export interface NetworkOptions {
21
+ /** `"browser"` (default): HTTP(S) through `fetch()`, WebSocket through the browser. `"none"`: no egress. */
22
+ mode?: "browser" | "none";
23
+ /** A webpod CORS proxy (docs/cors-proxy-protocol.md) for `via: "cors-proxy"` routes. */
24
+ corsProxy?: string | {
25
+ url: string;
26
+ token?: string;
27
+ };
28
+ /**
29
+ * An L4 relay (docs/relay-protocol.md). Raw TCP goes through it by default when set. Pass a
30
+ * fixed `token` or `getToken()` (called for each connection and after the relay rejects an
31
+ * expired token), issued by your backend.
32
+ */
33
+ relay?: {
34
+ url: string;
35
+ token?: string;
36
+ getToken?: () => string | Promise<string>;
37
+ };
38
+ /**
39
+ * First match wins; then the public npm and PyPI registries -> fetch with `stripHeaders:
40
+ * "non-safelisted"` (route them through the CORS proxy for private packages), HTTP/TLS -> fetch,
41
+ * WebSocket -> websocket, TCP and UDP -> relay or deny (DNS stays local unless a rule routes
42
+ * port 53).
43
+ */
44
+ routes?: NetworkRoute[];
45
+ /** Link MTU; must match the engine's virtio-net host_mtu. Default 65520 (the QEMU-Wasm engine's). */
46
+ mtu?: number;
47
+ /**
48
+ * Join a LAN with the other pods of this page that use the same name (NET-506): their guests
49
+ * reach each other by host name over any protocol (`curl http://pod-b:8000`). `allow` limits
50
+ * the peers and ports this guest may open connections to (`["pod-b:8000", "db:5432-5433",
51
+ * "*:22", "cache"]`; `[]`: none); replies always pass. Default: every peer.
52
+ */
53
+ lan?: string | {
54
+ name: string;
55
+ allow?: string[];
56
+ };
57
+ /**
58
+ * This pod's name on the LAN (a DNS label). It also picks the pod's link (one /26 per name in
59
+ * 198.19.0.0/16), so addresses survive reboots and snapshot restores. Default: the persistent
60
+ * volume name, else `pod-<n>`.
61
+ */
62
+ hostname?: string;
63
+ }
64
+ /** The structured-clone-safe part of the options, for the net Worker. */
65
+ export declare function workerNetworkConfig(n: NetworkOptions): Record<string, unknown>;
@@ -0,0 +1,8 @@
1
+ /** The structured-clone-safe part of the options, for the net Worker. */
2
+ export function workerNetworkConfig(n) {
3
+ const routes = n.routes?.map((r) => ({ ...r, ports: typeof r.ports === "number" ? [r.ports, r.ports] : r.ports }));
4
+ const relay = n.relay ? { url: n.relay.url, ...(n.relay.token ? { token: n.relay.token } : {}) } : undefined;
5
+ const corsProxy = typeof n.corsProxy === "string" ? { url: n.corsProxy } : n.corsProxy;
6
+ return { mode: n.mode, corsProxy, relay, routes, mtu: n.mtu };
7
+ }
8
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/net/options.ts"],"names":[],"mappings":"AAwDA,yEAAyE;AACzE,MAAM,UAAU,mBAAmB,CAAC,CAAiB;IACnD,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACnH,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7G,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { NetPortSink } from "./protocol.js";
2
+ export interface ExposeOptions {
3
+ /**
4
+ * URL of the preview service worker (dist/preview-serviceworker.js, or a combined worker that
5
+ * imports it). Used only when no service worker controls the scope yet. Default
6
+ * `"./preview-serviceworker.js"` relative to the document.
7
+ */
8
+ serviceWorker?: string;
9
+ /** Registration scope; must contain the preview prefix. Default: the worker's directory. */
10
+ scope?: string;
11
+ /**
12
+ * URL of dist/preview-relay.html on an origin of its own: previews then run on that origin, where
13
+ * the guest's pages cannot reach this app's DOM, storage, OPFS or tokens. `{id}` in it is
14
+ * replaced by an id of the preview (random, one per pod and port, kept in this origin's
15
+ * localStorage), for an origin per preview: `https://{id}.preview.example-usercontent.com/preview-relay.html`.
16
+ * Without `{id}`, previews of all pods share that origin
17
+ * (`http://localhost:5174/preview-relay.html` next to an app on `http://localhost:5173`).
18
+ * That origin serves the relay, its preview service worker and a `webpod-preview.json` listing
19
+ * the app origins that may use it (`{ "hosts": [...] }`). Without `relay` (or `false`), previews
20
+ * are served from this origin: only preview code you trust (docs/deploy.md).
21
+ */
22
+ relay?: string | false;
23
+ }
24
+ /** Registers `podId` with the preview worker and returns the preview base URL for `port`. */
25
+ export declare function exposePort(podId: string, sink: NetPortSink, port: number, options?: ExposeOptions): Promise<string>;
26
+ /** Stops serving previews of `podId` from this page. */
27
+ export declare function unexposePod(podId: string): void;
@@ -0,0 +1,233 @@
1
+ import { WebPodError } from "../errors.js";
2
+ import { PREVIEW_SEGMENT } from "./protocol.js";
3
+ /** Per-page registry of pods whose previews this page serves on its own origin. */
4
+ const owned = new Map();
5
+ let listening = false;
6
+ function onMessage(event) {
7
+ const d = event.data;
8
+ if (!d || typeof d.podId !== "string")
9
+ return;
10
+ const sink = owned.get(d.podId);
11
+ if (d.type === "webpod-open-port" && sink && event.ports[0])
12
+ sink.openPort(event.ports[0]);
13
+ if (d.type === "webpod-ping")
14
+ event.ports[0]?.postMessage({ owner: sink !== undefined });
15
+ }
16
+ function container() {
17
+ const c = globalThis.navigator?.serviceWorker;
18
+ if (!c)
19
+ throw new WebPodError("UNSUPPORTED", "previews need service workers (secure context, not a private window in some browsers)");
20
+ return c;
21
+ }
22
+ async function registration(c, options) {
23
+ const existing = await c.getRegistration(options.scope);
24
+ const reg = existing ?? (await c.register(options.serviceWorker ?? "./preview-serviceworker.js", options.scope ? { scope: options.scope } : undefined));
25
+ // Not `c.ready`: it only resolves for a registration whose scope contains this document, and
26
+ // the preview scope need not (e.g. a worker served from /sdk/ for a page elsewhere).
27
+ if (!reg.active)
28
+ await activated(reg);
29
+ return reg;
30
+ }
31
+ function activated(reg) {
32
+ return new Promise((resolve, reject) => {
33
+ const sw = reg.installing ?? reg.waiting;
34
+ if (!sw)
35
+ return reg.active ? resolve() : reject(new WebPodError("UNSUPPORTED", "preview service worker did not install"));
36
+ const check = () => {
37
+ if (sw.state === "activated")
38
+ resolve();
39
+ else if (sw.state === "redundant")
40
+ reject(new WebPodError("UNSUPPORTED", "preview service worker failed to install"));
41
+ };
42
+ sw.addEventListener("statechange", check);
43
+ check();
44
+ });
45
+ }
46
+ /** Relays by URL, while they attach; then also in `attached`. */
47
+ const relays = new Map();
48
+ const attached = new Map();
49
+ /** Counts unexposePod calls by pod: an exposePort that awaited across one registers nothing. */
50
+ const generations = new Map();
51
+ /** Resolves once the preview worker knows the owner (`registered`), or after `ms` (older workers). */
52
+ function confirmed(register, ms) {
53
+ return new Promise((resolve) => {
54
+ const timer = setTimeout(resolve, ms);
55
+ register(() => {
56
+ clearTimeout(timer);
57
+ resolve();
58
+ });
59
+ });
60
+ }
61
+ /** Removes a relay that serves no pod any more: its documents get "Pod not running". */
62
+ function dropRelay(url, relay) {
63
+ attached.delete(url);
64
+ relays.delete(url);
65
+ relay.bridge.close();
66
+ relay.frame.remove();
67
+ }
68
+ const IDS_KEY = "webpod-preview-ids";
69
+ let memoryIds = {};
70
+ /** The id of the preview of `podId`:`port`: random, kept in localStorage (else for this page's life). */
71
+ function previewId(podId, port) {
72
+ const key = `${podId}:${port}`;
73
+ let ids = memoryIds;
74
+ try {
75
+ ids = { ...JSON.parse(globalThis.localStorage?.getItem(IDS_KEY) ?? "{}"), ...memoryIds };
76
+ }
77
+ catch {
78
+ // no storage: ids for this page's life
79
+ }
80
+ let id = ids[key];
81
+ if (typeof id !== "string" || !/^[0-9a-f]{32}$/.test(id)) {
82
+ id = crypto.randomUUID().replaceAll("-", "");
83
+ ids[key] = id;
84
+ memoryIds = { ...memoryIds, [key]: id };
85
+ try {
86
+ globalThis.localStorage?.setItem(IDS_KEY, JSON.stringify(ids));
87
+ }
88
+ catch {
89
+ // as above
90
+ }
91
+ }
92
+ return id;
93
+ }
94
+ function openRelay(url) {
95
+ let r = relays.get(url);
96
+ if (!r) {
97
+ r = attachRelay(url);
98
+ relays.set(url, r);
99
+ r.then((relay) => attached.set(url, relay), () => relays.delete(url));
100
+ }
101
+ return r;
102
+ }
103
+ function attachRelay(url) {
104
+ const target = new URL(url, globalThis.location?.href);
105
+ const doc = globalThis.document;
106
+ if (!doc)
107
+ return Promise.reject(new WebPodError("UNSUPPORTED", "a preview relay needs a page (document)"));
108
+ if (target.origin === globalThis.location?.origin) {
109
+ return Promise.reject(new WebPodError("EINVAL", `preview relay ${target.href} is on this page's origin; it needs one of its own`));
110
+ }
111
+ return new Promise((resolve, reject) => {
112
+ const frame = doc.createElement("iframe");
113
+ frame.hidden = true;
114
+ frame.setAttribute("aria-hidden", "true");
115
+ // What the relay needs (its origin's storage for the service worker), not navigating this page.
116
+ frame.setAttribute("sandbox", "allow-scripts allow-same-origin");
117
+ frame.title = "webpod preview relay";
118
+ const pods = new Map();
119
+ const registering = new Map();
120
+ const timer = setTimeout(() => fail(new WebPodError("UNSUPPORTED", `preview relay ${target.href} did not load`)), 20000);
121
+ const fail = (e) => {
122
+ clearTimeout(timer);
123
+ removeEventListener("message", onLoaded);
124
+ frame.remove();
125
+ reject(e);
126
+ };
127
+ const onLoaded = (event) => {
128
+ if (event.source !== frame.contentWindow || event.origin !== target.origin)
129
+ return;
130
+ if (event.data?.type !== "webpod-relay-loaded")
131
+ return;
132
+ removeEventListener("message", onLoaded);
133
+ const { port1, port2 } = new MessageChannel();
134
+ port1.onmessage = (e) => {
135
+ const m = e.data;
136
+ if (m.type === "ready") {
137
+ let scope = null;
138
+ try {
139
+ scope = new URL(String(m.scope));
140
+ }
141
+ catch {
142
+ // checked below
143
+ }
144
+ if (scope?.origin !== target.origin)
145
+ return fail(new WebPodError("EACCES", `preview relay ${target.href} answered for another origin`));
146
+ clearTimeout(timer);
147
+ resolve({ bridge: port1, frame, scope: scope.href, pods, registering });
148
+ }
149
+ else if (m.type === "registered" && typeof m.podId === "string") {
150
+ registering.get(m.podId)?.();
151
+ registering.delete(m.podId);
152
+ }
153
+ else if (m.type === "refused") {
154
+ fail(new WebPodError("EACCES", `preview relay refused this page: ${m.message}`));
155
+ }
156
+ else if (m.type === "open-port" && typeof m.podId === "string" && e.ports[0]) {
157
+ // Only pods this page registered through this relay: whatever runs on the preview
158
+ // origin cannot reach other pods. Any port of such a pod is the guest's own.
159
+ const sink = pods.get(m.podId);
160
+ if (sink)
161
+ sink.openPort(e.ports[0]);
162
+ else
163
+ e.ports[0].postMessage({ t: "error", message: `pod ${m.podId} is not running` });
164
+ }
165
+ };
166
+ frame.contentWindow?.postMessage({ type: "webpod-bridge" }, target.origin, [port2]);
167
+ };
168
+ addEventListener("message", onLoaded);
169
+ frame.src = target.href;
170
+ doc.body.appendChild(frame);
171
+ });
172
+ }
173
+ /** Registers `podId` with the preview worker and returns the preview base URL for `port`. */
174
+ export async function exposePort(podId, sink, port, options = {}) {
175
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
176
+ throw new WebPodError("EINVAL", `invalid port: ${port}`);
177
+ if (options.relay) {
178
+ const url = options.relay.replaceAll("{id}", previewId(podId, port));
179
+ const generation = generations.get(podId) ?? 0;
180
+ const relay = await openRelay(url);
181
+ if ((generations.get(podId) ?? 0) !== generation) {
182
+ // Disposed while its relay attached.
183
+ if (!relay.pods.size && attached.get(url) === relay)
184
+ dropRelay(url, relay);
185
+ throw new WebPodError("DISPOSED", `pod ${podId} is gone`);
186
+ }
187
+ relay.pods.set(podId, sink);
188
+ // Before the URL is out: a preview loading at once finds its owner.
189
+ await confirmed((done) => {
190
+ relay.registering.set(podId, done);
191
+ relay.bridge.postMessage({ type: "register", podId });
192
+ }, 5000);
193
+ return new URL(`${PREVIEW_SEGMENT}/${encodeURIComponent(podId)}/${port}/`, relay.scope).href;
194
+ }
195
+ const c = container();
196
+ if (!listening) {
197
+ c.addEventListener("message", onMessage);
198
+ c.startMessages();
199
+ listening = true;
200
+ }
201
+ owned.set(podId, sink);
202
+ const reg = await registration(c, options);
203
+ const active = reg.active;
204
+ if (active) {
205
+ await confirmed((done) => {
206
+ const ch = new MessageChannel();
207
+ ch.port1.onmessage = () => {
208
+ ch.port1.close();
209
+ done();
210
+ };
211
+ active.postMessage({ type: "webpod-register", podId }, [ch.port2]);
212
+ }, 1000);
213
+ }
214
+ return new URL(`${PREVIEW_SEGMENT}/${encodeURIComponent(podId)}/${port}/`, reg.scope).href;
215
+ }
216
+ /** Stops serving previews of `podId` from this page. */
217
+ export function unexposePod(podId) {
218
+ generations.set(podId, (generations.get(podId) ?? 0) + 1);
219
+ for (const [url, relay] of attached) {
220
+ if (!relay.pods.delete(podId))
221
+ continue;
222
+ relay.registering.delete(podId);
223
+ relay.bridge.postMessage({ type: "unregister", podId });
224
+ if (!relay.pods.size)
225
+ dropRelay(url, relay);
226
+ }
227
+ if (!owned.delete(podId))
228
+ return;
229
+ const c = globalThis.navigator?.serviceWorker;
230
+ c?.controller?.postMessage({ type: "webpod-unregister", podId });
231
+ void c?.getRegistration().then((r) => r?.active?.postMessage({ type: "webpod-unregister", podId }));
232
+ }
233
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/net/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA2BhD,mFAAmF;AACnF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;AAC7C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,SAAS,SAAS,CAAC,KAAmB;IACpC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAgD,CAAC;IACjE,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO;IAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa;QAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC,CAAC;AAC3F,CAAC;AAED,SAAS,SAAS;IAChB,MAAM,CAAC,GAAI,UAAU,CAAC,SAAmC,EAAE,aAAa,CAAC;IACzE,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,aAAa,EAAE,uFAAuF,CAAC,CAAC;IACtI,OAAO,CAAC,CAAC;AACX,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,CAA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