@brett_lamy/ui 3.1.0 → 5.0.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.
- package/README.md +4 -4
- package/dist/components/animated-height.d.ts +3 -1
- package/dist/components/animated-height.d.ts.map +1 -1
- package/dist/components/animated-height.js +11 -11
- package/dist/components/artifact-chat-container.d.ts.map +1 -1
- package/dist/components/artifact-chat-container.js +81 -82
- package/dist/components/button.d.ts +4 -3
- package/dist/components/button.d.ts.map +1 -1
- package/dist/components/button.js +22 -9
- package/dist/components/canvas.d.ts +91 -0
- package/dist/components/canvas.d.ts.map +1 -0
- package/dist/components/canvas.js +296 -0
- package/dist/components/composer/composer-cards.d.ts +55 -0
- package/dist/components/composer/composer-cards.d.ts.map +1 -0
- package/dist/components/composer/composer-cards.js +351 -0
- package/dist/components/composer/composer.d.ts +9 -1
- package/dist/components/composer/composer.d.ts.map +1 -1
- package/dist/components/composer/composer.js +179 -154
- package/dist/components/context-menu.d.ts +25 -0
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +127 -0
- package/dist/components/credenza.d.ts.map +1 -1
- package/dist/components/credenza.js +52 -92
- package/dist/components/cron-editor.d.ts +47 -0
- package/dist/components/cron-editor.d.ts.map +1 -0
- package/dist/components/cron-editor.js +297 -0
- package/dist/components/dropdown-menu.d.ts +3 -1
- package/dist/components/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu.js +5 -5
- package/dist/components/edge-drawer.d.ts.map +1 -1
- package/dist/components/edge-drawer.js +1 -0
- package/dist/components/file-upload.d.ts +121 -0
- package/dist/components/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload.js +405 -0
- package/dist/components/filter-input.d.ts +22 -0
- package/dist/components/filter-input.d.ts.map +1 -0
- package/dist/components/filter-input.js +126 -0
- package/dist/components/filter.d.ts +154 -0
- package/dist/components/filter.d.ts.map +1 -0
- package/dist/components/filter.js +815 -0
- package/dist/components/floating-chat.d.ts.map +1 -1
- package/dist/components/floating-chat.js +71 -88
- package/dist/components/floating-sheet.d.ts +21 -5
- package/dist/components/floating-sheet.d.ts.map +1 -1
- package/dist/components/floating-sheet.js +113 -116
- package/dist/components/markdown-editor.d.ts +2 -0
- package/dist/components/markdown-editor.d.ts.map +1 -1
- package/dist/components/markdown-editor.js +46 -45
- package/dist/components/markdown-view.d.ts +6 -1
- package/dist/components/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view.js +13 -11
- package/dist/components/navigation-stack.d.ts +3 -5
- package/dist/components/navigation-stack.d.ts.map +1 -1
- package/dist/components/navigation-stack.js +212 -382
- package/dist/components/passkey-enroll-dialog.d.ts +36 -0
- package/dist/components/passkey-enroll-dialog.d.ts.map +1 -0
- package/dist/components/passkey-enroll-dialog.js +234 -0
- package/dist/components/result-table.d.ts +38 -0
- package/dist/components/result-table.d.ts.map +1 -0
- package/dist/components/result-table.js +161 -0
- package/dist/components/schema-tree.d.ts +19 -0
- package/dist/components/schema-tree.d.ts.map +1 -0
- package/dist/components/schema-tree.js +172 -0
- package/dist/components/side-drawer.d.ts.map +1 -1
- package/dist/components/side-drawer.js +117 -143
- package/dist/components/slider.d.ts.map +1 -1
- package/dist/components/slider.js +4 -1
- package/dist/components/spinner-shapes.d.ts +263 -0
- package/dist/components/spinner-shapes.d.ts.map +1 -0
- package/dist/components/spinner-shapes.js +771 -0
- package/dist/components/spinner.d.ts +133 -3
- package/dist/components/spinner.d.ts.map +1 -1
- package/dist/components/spinner.js +445 -29
- package/dist/components/sql-console.d.ts +28 -0
- package/dist/components/sql-console.d.ts.map +1 -0
- package/dist/components/sql-console.js +348 -0
- package/dist/components/sql-editor.d.ts +47 -0
- package/dist/components/sql-editor.d.ts.map +1 -0
- package/dist/components/sql-editor.js +170 -0
- package/dist/components/tab-view.d.ts +2 -2
- package/dist/components/tab-view.d.ts.map +1 -1
- package/dist/components/tab-view.js +63 -49
- package/dist/components/tailscale-login-button.d.ts +53 -0
- package/dist/components/tailscale-login-button.d.ts.map +1 -0
- package/dist/components/tailscale-login-button.js +197 -0
- package/dist/components/time-input.d.ts +46 -0
- package/dist/components/time-input.d.ts.map +1 -0
- package/dist/components/time-input.js +258 -0
- package/dist/components/toast.d.ts +5 -2
- package/dist/components/toast.d.ts.map +1 -1
- package/dist/components/toast.js +249 -125
- package/dist/components/vault-gate.d.ts +60 -0
- package/dist/components/vault-gate.d.ts.map +1 -0
- package/dist/components/vault-gate.js +382 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +86 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -85
- package/dist/lib/back-history.d.ts +5 -0
- package/dist/lib/back-history.d.ts.map +1 -0
- package/dist/lib/back-history.js +44 -0
- package/dist/lib/canvas-math.d.ts +82 -0
- package/dist/lib/canvas-math.d.ts.map +1 -0
- package/dist/lib/canvas-math.js +226 -0
- package/dist/lib/controllable-state.d.ts +4 -0
- package/dist/lib/controllable-state.d.ts.map +1 -0
- package/dist/lib/controllable-state.js +11 -0
- package/dist/lib/cron.d.ts +55 -0
- package/dist/lib/cron.d.ts.map +1 -0
- package/dist/lib/cron.js +269 -0
- package/dist/lib/edge-swipe.d.ts +36 -0
- package/dist/lib/edge-swipe.d.ts.map +1 -0
- package/dist/lib/edge-swipe.js +73 -0
- package/dist/lib/file-upload.d.ts +187 -0
- package/dist/lib/file-upload.d.ts.map +1 -0
- package/dist/lib/file-upload.js +349 -0
- package/dist/lib/filter-query.d.ts +90 -0
- package/dist/lib/filter-query.d.ts.map +1 -0
- package/dist/lib/filter-query.js +459 -0
- package/dist/lib/filter.d.ts +120 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/filter.js +399 -0
- package/dist/lib/format-bytes.d.ts +3 -0
- package/dist/lib/format-bytes.d.ts.map +1 -0
- package/dist/lib/format-bytes.js +16 -0
- package/dist/lib/gpu-cron.d.ts +51 -0
- package/dist/lib/gpu-cron.d.ts.map +1 -0
- package/dist/lib/gpu-cron.js +81 -0
- package/dist/lib/gpu-query/featurize.d.ts +19 -0
- package/dist/lib/gpu-query/featurize.d.ts.map +1 -0
- package/dist/lib/gpu-query/featurize.js +88 -0
- package/dist/lib/gpu-query/index.d.ts +73 -0
- package/dist/lib/gpu-query/index.d.ts.map +1 -0
- package/dist/lib/gpu-query/index.js +117 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts +30 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.d.ts +8 -0
- package/dist/lib/gpu-query/model.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.js +91 -0
- package/dist/lib/gpu-query/schema.d.ts +40 -0
- package/dist/lib/gpu-query/schema.d.ts.map +1 -0
- package/dist/lib/gpu-query/schema.js +0 -0
- package/dist/lib/gpu-query/webgpu.d.ts +12 -0
- package/dist/lib/gpu-query/webgpu.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.d.ts +17 -0
- package/dist/lib/gpu-query/weights.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.js +40 -0
- package/dist/lib/gpu-query/weights.json.d.ts +3 -0
- package/dist/lib/gpu-query/weights2.js +25 -0
- package/dist/lib/gpu-time.d.ts +77 -0
- package/dist/lib/gpu-time.d.ts.map +1 -0
- package/dist/lib/gpu-time.js +260 -0
- package/dist/lib/morph-path.d.ts +22 -0
- package/dist/lib/morph-path.d.ts.map +1 -0
- package/dist/lib/morph-path.js +42 -0
- package/dist/lib/passkey.d.ts +120 -0
- package/dist/lib/passkey.d.ts.map +1 -0
- package/dist/lib/passkey.js +186 -0
- package/dist/lib/persistent-state.d.ts +9 -0
- package/dist/lib/persistent-state.d.ts.map +1 -0
- package/dist/lib/persistent-state.js +37 -0
- package/dist/lib/pglite-core.d.ts +219 -0
- package/dist/lib/pglite-core.d.ts.map +1 -0
- package/dist/lib/pglite-core.js +273 -0
- package/dist/lib/pglite-files.d.ts +7 -0
- package/dist/lib/pglite-files.d.ts.map +1 -0
- package/dist/lib/pglite-files.js +17 -0
- package/dist/lib/pglite-schema.d.ts +58 -0
- package/dist/lib/pglite-schema.d.ts.map +1 -0
- package/dist/lib/pglite-schema.js +105 -0
- package/dist/lib/pglite-storage.d.ts +33 -0
- package/dist/lib/pglite-storage.d.ts.map +1 -0
- package/dist/lib/pglite-storage.js +55 -0
- package/dist/lib/pglite-transfer.d.ts +53 -0
- package/dist/lib/pglite-transfer.d.ts.map +1 -0
- package/dist/lib/pglite-transfer.js +126 -0
- package/dist/lib/pglite.d.ts +106 -0
- package/dist/lib/pglite.d.ts.map +1 -0
- package/dist/lib/pglite.js +298 -0
- package/dist/lib/pull-to-refresh.d.ts +24 -0
- package/dist/lib/pull-to-refresh.d.ts.map +1 -0
- package/dist/lib/pull-to-refresh.js +74 -0
- package/dist/lib/scroll-hidden.d.ts +6 -0
- package/dist/lib/scroll-hidden.d.ts.map +1 -0
- package/dist/lib/scroll-hidden.js +21 -0
- package/dist/lib/sheet-drag.d.ts +10 -2
- package/dist/lib/sheet-drag.d.ts.map +1 -1
- package/dist/lib/sheet-drag.js +72 -69
- package/dist/lib/sql-format.d.ts +62 -0
- package/dist/lib/sql-format.d.ts.map +1 -0
- package/dist/lib/sql-format.js +175 -0
- package/dist/lib/sql-lex.d.ts +25 -0
- package/dist/lib/sql-lex.d.ts.map +1 -0
- package/dist/lib/sql-lex.js +135 -0
- package/dist/lib/tab-lock.d.ts +28 -0
- package/dist/lib/tab-lock.d.ts.map +1 -0
- package/dist/lib/tab-lock.js +80 -0
- package/dist/lib/tailscale-connect.d.ts +56 -0
- package/dist/lib/tailscale-connect.d.ts.map +1 -0
- package/dist/lib/tailscale-connect.js +99 -0
- package/dist/lib/tailscale-fake.d.ts +33 -0
- package/dist/lib/tailscale-fake.d.ts.map +1 -0
- package/dist/lib/tailscale-fake.js +80 -0
- package/dist/lib/tailscale-policy.d.ts +71 -0
- package/dist/lib/tailscale-policy.d.ts.map +1 -0
- package/dist/lib/tailscale-policy.js +244 -0
- package/dist/lib/tailscale-react.d.ts +20 -0
- package/dist/lib/tailscale-react.d.ts.map +1 -0
- package/dist/lib/tailscale-react.js +37 -0
- package/dist/lib/tailscale-router/bridge.d.ts +60 -0
- package/dist/lib/tailscale-router/bridge.d.ts.map +1 -0
- package/dist/lib/tailscale-router/bridge.js +198 -0
- package/dist/lib/tailscale-router/react.d.ts +19 -0
- package/dist/lib/tailscale-router/react.d.ts.map +1 -0
- package/dist/lib/tailscale-router/react.js +52 -0
- package/dist/lib/tailscale.d.ts +204 -0
- package/dist/lib/tailscale.d.ts.map +1 -0
- package/dist/lib/tailscale.js +443 -0
- package/dist/lib/title-flight.d.ts +34 -0
- package/dist/lib/title-flight.d.ts.map +1 -0
- package/dist/lib/title-flight.js +123 -0
- package/dist/lib/vault-react.d.ts +49 -0
- package/dist/lib/vault-react.d.ts.map +1 -0
- package/dist/lib/vault-react.js +196 -0
- package/dist/lib/vault-storage.d.ts +30 -0
- package/dist/lib/vault-storage.d.ts.map +1 -0
- package/dist/lib/vault-storage.js +105 -0
- package/dist/lib/vault.d.ts +200 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +641 -0
- package/dist/tailscale-sw.js +332 -0
- package/package.json +35 -5
- package/dist/components/icon-button.d.ts +0 -19
- package/dist/components/icon-button.d.ts.map +0 -1
- package/dist/components/icon-button.js +0 -31
- package/dist/components/measure-h.d.ts +0 -7
- package/dist/components/measure-h.d.ts.map +0 -1
- package/dist/components/measure-h.js +0 -20
- package/dist/components/snap-sheet.d.ts +0 -13
- package/dist/components/snap-sheet.d.ts.map +0 -1
- package/dist/components/snap-sheet.js +0 -100
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
//#region src/lib/tailscale-policy.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
constructor(e) {
|
|
4
|
+
super(e), this.name = "TailscalePolicyError";
|
|
5
|
+
}
|
|
6
|
+
}, t = 33554432, n = 6e4, r = (e) => e === 4 ? 32 : 128;
|
|
7
|
+
function i(e) {
|
|
8
|
+
let t = e.split(".");
|
|
9
|
+
if (t.length !== 4) return null;
|
|
10
|
+
let n = 0n;
|
|
11
|
+
for (let e of t) {
|
|
12
|
+
if (!/^\d{1,3}$/.test(e)) return null;
|
|
13
|
+
let t = Number(e);
|
|
14
|
+
if (t > 255) return null;
|
|
15
|
+
n = n << 8n | BigInt(t);
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
function a(e) {
|
|
20
|
+
let t = e;
|
|
21
|
+
if (!/^[0-9a-f:.]+$/i.test(t) || !t.includes(":")) return null;
|
|
22
|
+
if (t.lastIndexOf(".") >= 0) {
|
|
23
|
+
let e = t.lastIndexOf(":"), n = i(t.slice(e + 1));
|
|
24
|
+
if (n === null) return null;
|
|
25
|
+
t = `${t.slice(0, e + 1)}${(n >> 16n).toString(16)}:${(n & 65535n).toString(16)}`;
|
|
26
|
+
}
|
|
27
|
+
let n = t.split("::");
|
|
28
|
+
if (n.length > 2) return null;
|
|
29
|
+
let r = (e) => e === "" ? [] : e.split(":"), a = r(n[0] ?? ""), o = n.length === 2 ? r(n[1] ?? "") : [], s = 8 - a.length - o.length;
|
|
30
|
+
if (n.length === 2 ? s < 1 : s !== 0) return null;
|
|
31
|
+
let c = [
|
|
32
|
+
...a,
|
|
33
|
+
...n.length === 2 ? Array(s).fill("0") : [],
|
|
34
|
+
...o
|
|
35
|
+
], l = 0n;
|
|
36
|
+
for (let e of c) {
|
|
37
|
+
if (!/^[0-9a-f]{1,4}$/i.test(e)) return null;
|
|
38
|
+
l = l << 16n | BigInt(parseInt(e, 16));
|
|
39
|
+
}
|
|
40
|
+
return l;
|
|
41
|
+
}
|
|
42
|
+
function o(e) {
|
|
43
|
+
let t = e.startsWith("[") && e.endsWith("]") ? e.slice(1, -1) : e, n = i(t);
|
|
44
|
+
if (n !== null) return {
|
|
45
|
+
family: 4,
|
|
46
|
+
value: n
|
|
47
|
+
};
|
|
48
|
+
let r = a(t);
|
|
49
|
+
return r === null ? null : {
|
|
50
|
+
family: 6,
|
|
51
|
+
value: r
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function s(e) {
|
|
55
|
+
let [t, n, ...i] = e.split("/");
|
|
56
|
+
if (i.length || t === void 0) return null;
|
|
57
|
+
let a = o(t);
|
|
58
|
+
if (!a) return null;
|
|
59
|
+
let s = n === void 0 ? r(a.family) : /^\d{1,3}$/.test(n) ? Number(n) : -1;
|
|
60
|
+
return s < 0 || s > r(a.family) ? null : {
|
|
61
|
+
...a,
|
|
62
|
+
prefix: s
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function c(e, t) {
|
|
66
|
+
if (e.family !== t.family) return !1;
|
|
67
|
+
let n = BigInt(r(e.family) - t.prefix);
|
|
68
|
+
return e.value >> n === t.value >> n;
|
|
69
|
+
}
|
|
70
|
+
var l = {
|
|
71
|
+
family: 4,
|
|
72
|
+
value: 100n << 24n | 64n << 16n,
|
|
73
|
+
prefix: 10
|
|
74
|
+
}, u = {
|
|
75
|
+
family: 6,
|
|
76
|
+
value: 278700719120864n << 80n,
|
|
77
|
+
prefix: 48
|
|
78
|
+
}, d = {
|
|
79
|
+
family: 4,
|
|
80
|
+
value: 127n << 24n,
|
|
81
|
+
prefix: 8
|
|
82
|
+
}, f = {
|
|
83
|
+
family: 6,
|
|
84
|
+
value: 1n,
|
|
85
|
+
prefix: 128
|
|
86
|
+
};
|
|
87
|
+
function p(e) {
|
|
88
|
+
let t = o(e);
|
|
89
|
+
return t !== null && (c(t, l) || c(t, u));
|
|
90
|
+
}
|
|
91
|
+
function m(e) {
|
|
92
|
+
let t = e.toLowerCase();
|
|
93
|
+
return t.endsWith(".ts.net") || p(t);
|
|
94
|
+
}
|
|
95
|
+
function h(e) {
|
|
96
|
+
try {
|
|
97
|
+
return new URL(`http://${e}`).hostname.toLowerCase();
|
|
98
|
+
} catch {
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function g(t, n) {
|
|
103
|
+
let r = t.trim().toLowerCase();
|
|
104
|
+
if (!r || r === "*" || r === "." || r === "*.") throw new e(`${n}: "${t}" is not a host. To route everything use intercept: 'all'.`);
|
|
105
|
+
let i = r.startsWith("*.") ? "*." : r.startsWith(".") ? "." : "", a = h(r.slice(i.length));
|
|
106
|
+
if (!a || /[/\s]/.test(r)) throw new e(`${n}: "${t}" is not a valid host pattern.`);
|
|
107
|
+
return i + a;
|
|
108
|
+
}
|
|
109
|
+
function _(e, t) {
|
|
110
|
+
return t.startsWith("*.") ? e.endsWith(t.slice(1)) : t.startsWith(".") ? e === t.slice(1) || e.endsWith(t) : e === t;
|
|
111
|
+
}
|
|
112
|
+
var v = (e) => s(e) !== null;
|
|
113
|
+
function y(e, t) {
|
|
114
|
+
let n = [], r = [];
|
|
115
|
+
for (let i of e ?? []) {
|
|
116
|
+
let e = i.trim();
|
|
117
|
+
v(e) ? r.push(b(e)) : n.push(g(i, t));
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
hosts: n,
|
|
121
|
+
cidrs: r
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function b(t) {
|
|
125
|
+
let n = s(t);
|
|
126
|
+
if (!n) throw new e(`"${t}" is not a CIDR range.`);
|
|
127
|
+
return t.trim().toLowerCase().includes("/") ? t.trim().toLowerCase() : `${t.trim().toLowerCase()}/${n.prefix}`;
|
|
128
|
+
}
|
|
129
|
+
var x = (e) => [...new Set(e)];
|
|
130
|
+
function S(r = {}) {
|
|
131
|
+
let i = r.intercept ?? "tailnet";
|
|
132
|
+
if (i !== "tailnet" && i !== "all") throw new e(`intercept must be 'tailnet' or 'all', not "${String(i)}".`);
|
|
133
|
+
let a = y([...r.hosts ?? [], ...r.cidrs ?? []], "hosts"), o = y(r.exclude, "exclude");
|
|
134
|
+
for (let t of r.cidrs ?? []) if (!v(t.trim())) throw new e(`cidrs: "${t}" is not a CIDR range.`);
|
|
135
|
+
let s = r.whenUnavailable ?? "network";
|
|
136
|
+
if (s !== "network" && s !== "error") throw new e("whenUnavailable must be 'network' or 'error'.");
|
|
137
|
+
let c = x(r.schemes ?? ["http", "https"]);
|
|
138
|
+
if (!c.length || c.some((e) => e !== "http" && e !== "https")) throw new e("schemes may contain 'http' and 'https' only.");
|
|
139
|
+
return {
|
|
140
|
+
v: 1,
|
|
141
|
+
intercept: i,
|
|
142
|
+
hosts: x(a.hosts),
|
|
143
|
+
cidrs: x(a.cidrs),
|
|
144
|
+
shortNames: r.shortNames === !0,
|
|
145
|
+
exclude: x([...o.hosts, ...o.cidrs]),
|
|
146
|
+
schemes: c,
|
|
147
|
+
methods: r.methods?.length ? x(r.methods.map((e) => e.toUpperCase())) : null,
|
|
148
|
+
sameOrigin: r.sameOrigin === !0,
|
|
149
|
+
whenUnavailable: s,
|
|
150
|
+
maxBodyBytes: C(r.maxBodyBytes, t),
|
|
151
|
+
timeoutMs: C(r.timeoutMs, n)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function C(e, t) {
|
|
155
|
+
return typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : t;
|
|
156
|
+
}
|
|
157
|
+
var w = (e, t) => e === "localhost" || e.endsWith(".localhost") || t !== null && (c(t, d) || c(t, f));
|
|
158
|
+
function T(e, t, n, r) {
|
|
159
|
+
let i;
|
|
160
|
+
try {
|
|
161
|
+
i = typeof e == "string" ? new URL(e, r) : e;
|
|
162
|
+
} catch {
|
|
163
|
+
return {
|
|
164
|
+
route: !1,
|
|
165
|
+
reason: "invalid-url"
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
let a = i.protocol.slice(0, -1);
|
|
169
|
+
if (a !== "http" && a !== "https" || !n.schemes.includes(a)) return {
|
|
170
|
+
route: !1,
|
|
171
|
+
reason: "scheme"
|
|
172
|
+
};
|
|
173
|
+
if (!n.sameOrigin && r !== void 0 && i.origin === r) return {
|
|
174
|
+
route: !1,
|
|
175
|
+
reason: "same-origin"
|
|
176
|
+
};
|
|
177
|
+
let s = i.hostname.toLowerCase(), d = o(s);
|
|
178
|
+
return w(s, d) ? {
|
|
179
|
+
route: !1,
|
|
180
|
+
reason: "loopback"
|
|
181
|
+
} : n.methods && !n.methods.includes(t.toUpperCase()) ? {
|
|
182
|
+
route: !1,
|
|
183
|
+
reason: "method"
|
|
184
|
+
} : E(s, d, n.exclude) ? {
|
|
185
|
+
route: !1,
|
|
186
|
+
reason: "excluded"
|
|
187
|
+
} : n.intercept === "all" ? {
|
|
188
|
+
route: !0,
|
|
189
|
+
reason: "all"
|
|
190
|
+
} : s.endsWith(".ts.net") ? {
|
|
191
|
+
route: !0,
|
|
192
|
+
reason: "tailnet-name"
|
|
193
|
+
} : d && (c(d, l) || c(d, u)) ? {
|
|
194
|
+
route: !0,
|
|
195
|
+
reason: "tailnet-address"
|
|
196
|
+
} : E(s, d, n.hosts) ? {
|
|
197
|
+
route: !0,
|
|
198
|
+
reason: "host"
|
|
199
|
+
} : E(s, d, n.cidrs) ? {
|
|
200
|
+
route: !0,
|
|
201
|
+
reason: "cidr"
|
|
202
|
+
} : n.shortNames && d === null && !s.includes(".") && s !== "" ? {
|
|
203
|
+
route: !0,
|
|
204
|
+
reason: "short-name"
|
|
205
|
+
} : {
|
|
206
|
+
route: !1,
|
|
207
|
+
reason: "no-match"
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function E(e, t, n) {
|
|
211
|
+
for (let r of n) if (r.includes("/")) {
|
|
212
|
+
let e = s(r);
|
|
213
|
+
if (e && t && c(t, e)) return !0;
|
|
214
|
+
} else if (_(e, r)) return !0;
|
|
215
|
+
return !1;
|
|
216
|
+
}
|
|
217
|
+
function D(e) {
|
|
218
|
+
let t = "";
|
|
219
|
+
for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
|
|
220
|
+
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
221
|
+
}
|
|
222
|
+
function O(e) {
|
|
223
|
+
let t = atob(e.replace(/-/g, "+").replace(/_/g, "/"));
|
|
224
|
+
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
225
|
+
}
|
|
226
|
+
function k(e) {
|
|
227
|
+
return D(new TextEncoder().encode(JSON.stringify(e)));
|
|
228
|
+
}
|
|
229
|
+
function A(e) {
|
|
230
|
+
try {
|
|
231
|
+
let t = JSON.parse(new TextDecoder().decode(O(e)));
|
|
232
|
+
return !t || typeof t != "object" || t.v !== 1 ? null : S(t);
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function j(e) {
|
|
238
|
+
let t = [];
|
|
239
|
+
e.intercept === "all" ? t.push("every cross-origin request") : (t.push("*.ts.net and Tailscale addresses"), e.hosts.length && t.push(e.hosts.join(", ")), e.cidrs.length && t.push(e.cidrs.join(", ")), e.shortNames && t.push("short names"));
|
|
240
|
+
let n = `Routes ${t.join(", ")}`;
|
|
241
|
+
return e.exclude.length ? `${n}, except ${e.exclude.join(", ")}.` : `${n}.`;
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
export { t as DEFAULT_MAX_BODY_BYTES, n as DEFAULT_TIMEOUT_MS, e as TailscalePolicyError, A as decodeTailscalePolicy, j as describeTailscalePolicy, k as encodeTailscalePolicy, p as isTailnetAddress, m as isTailnetHost, T as matchTailscalePolicy, S as resolveTailscalePolicy };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Tailscale, TailscaleOptions, TailscaleSnapshot } from './tailscale';
|
|
3
|
+
export interface TailscaleProviderProps {
|
|
4
|
+
/** An existing controller (`createTailscale`). Takes precedence over `options`. */
|
|
5
|
+
tailscale?: Tailscale;
|
|
6
|
+
/** Options for a controller the provider creates once, on first render. Later changes are ignored; change `key` to start over. */
|
|
7
|
+
options?: TailscaleOptions;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/** Provides a Tailscale controller and runs its lifecycle: activated on mount (a saved session is restored), stopped on unmount. StrictMode safe. */
|
|
11
|
+
export declare function TailscaleProvider({ tailscale, options, children }: TailscaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
/** The nearest provider's controller, or null outside one (components use this to work without a provider). */
|
|
13
|
+
export declare function useOptionalTailscale(override?: Tailscale): Tailscale | null;
|
|
14
|
+
/** The controller, with the component subscribed to its snapshot: `useTailscale().signIn()`. */
|
|
15
|
+
export declare function useTailscale(tailscale?: Tailscale): Tailscale;
|
|
16
|
+
/** The snapshot: `status`, `loginUrl`, `error`, `selfName`, `tailnet`, `addresses`, `peers`, `hasSession`. A new object per change. */
|
|
17
|
+
export declare function useTailscaleStatus(tailscale?: Tailscale): TailscaleSnapshot;
|
|
18
|
+
/** A stable `fetch` that sends what matches the controller's policy through the tailnet (see `createTailscaleFetch`). */
|
|
19
|
+
export declare function useTailscaleFetch(tailscale?: Tailscale): typeof fetch;
|
|
20
|
+
//# sourceMappingURL=tailscale-react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailscale-react.d.ts","sourceRoot":"","sources":["../../src/lib/tailscale-react.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiF,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACtH,OAAO,EAAyC,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAUvI,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,kIAAkI;IAClI,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,qJAAqJ;AACrJ,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,sBAAsB,2CAMzF;AAED,+GAA+G;AAC/G,wBAAgB,oBAAoB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAG3E;AAQD,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAI7D;AAED,uIAAuI;AACvI,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,iBAAiB,CAG3E;AAED,yHAAyH;AACzH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,KAAK,CAGrE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createTailscale as e, createTailscaleFetch as t } from "./tailscale.js";
|
|
3
|
+
import { createContext as n, useContext as r, useEffect as i, useMemo as a, useState as o, useSyncExternalStore as s } from "react";
|
|
4
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
5
|
+
//#region src/lib/tailscale-react.tsx
|
|
6
|
+
var l = n(null);
|
|
7
|
+
function u({ tailscale: t, options: n, children: r }) {
|
|
8
|
+
let [a] = o(() => t ? null : e(n)), s = t ?? a;
|
|
9
|
+
if (!s) throw Error("TailscaleProvider needs `tailscale` or `options`.");
|
|
10
|
+
return i(() => s.activate(), [s]), /* @__PURE__ */ c(l.Provider, {
|
|
11
|
+
value: s,
|
|
12
|
+
children: r
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function d(e) {
|
|
16
|
+
let t = r(l);
|
|
17
|
+
return e ?? t;
|
|
18
|
+
}
|
|
19
|
+
function f(e) {
|
|
20
|
+
let t = d(e);
|
|
21
|
+
if (!t) throw Error("useTailscale must be used inside <TailscaleProvider> (or be given a controller).");
|
|
22
|
+
return t;
|
|
23
|
+
}
|
|
24
|
+
function p(e) {
|
|
25
|
+
let t = f(e);
|
|
26
|
+
return s(t.subscribe, t.getSnapshot, t.getServerSnapshot), t;
|
|
27
|
+
}
|
|
28
|
+
function m(e) {
|
|
29
|
+
let t = f(e);
|
|
30
|
+
return s(t.subscribe, t.getSnapshot, t.getServerSnapshot);
|
|
31
|
+
}
|
|
32
|
+
function h(e) {
|
|
33
|
+
let n = f(e);
|
|
34
|
+
return a(() => t(n), [n]);
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { u as TailscaleProvider, d as useOptionalTailscale, p as useTailscale, h as useTailscaleFetch, m as useTailscaleStatus };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ResolvedTailscalePolicy, TailscalePolicy } from '../tailscale-policy';
|
|
2
|
+
import { TailscaleRequest, TailscaleResponse } from '../tailscale';
|
|
3
|
+
/** What the router needs from the connection: `createTailscale()`'s controller satisfies it. */
|
|
4
|
+
export interface TailscaleRouteTarget {
|
|
5
|
+
fetch(request: TailscaleRequest): Promise<TailscaleResponse>;
|
|
6
|
+
getSnapshot(): {
|
|
7
|
+
status: string;
|
|
8
|
+
};
|
|
9
|
+
subscribe(listener: () => void): () => void;
|
|
10
|
+
}
|
|
11
|
+
/** The request as the router offers it to `shouldRoute`. */
|
|
12
|
+
export interface TailscaleRoutedRequest {
|
|
13
|
+
url: string;
|
|
14
|
+
method: string;
|
|
15
|
+
headers: Array<[string, string]>;
|
|
16
|
+
destination: string;
|
|
17
|
+
mode: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TailscaleRouterOptions {
|
|
20
|
+
tailscale: TailscaleRouteTarget;
|
|
21
|
+
policy?: TailscalePolicy;
|
|
22
|
+
/** The worker script's URL. Default `tailscale-sw.js` next to the document's base URL (your `public/` root). */
|
|
23
|
+
serviceWorkerUrl?: string;
|
|
24
|
+
/** Default: the script's directory. A worker only sees pages under its scope. */
|
|
25
|
+
scope?: string;
|
|
26
|
+
/** A last say, in the page, for each matched request: return false to send it to the normal network instead. */
|
|
27
|
+
shouldRoute?: (request: TailscaleRoutedRequest) => boolean | Promise<boolean>;
|
|
28
|
+
/** Unregister the worker on `dispose()`. Default false: it stays installed, and idle, for the next visit. */
|
|
29
|
+
unregisterOnDispose?: boolean;
|
|
30
|
+
/** For tests: a stand-in for `navigator.serviceWorker`, and whether the page is a secure context. */
|
|
31
|
+
env?: {
|
|
32
|
+
serviceWorker?: ServiceWorkerContainer | null;
|
|
33
|
+
isSecureContext?: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export type TailscaleRouterStatus = 'unsupported' | 'registering' | 'active' | 'uncontrolled' | 'error';
|
|
37
|
+
export interface TailscaleRouterState {
|
|
38
|
+
status: TailscaleRouterStatus;
|
|
39
|
+
/** Why it is unsupported or failed, in plain words. */
|
|
40
|
+
detail: string | null;
|
|
41
|
+
/** Requests this page has served for the worker. */
|
|
42
|
+
routed: number;
|
|
43
|
+
policy: ResolvedTailscalePolicy;
|
|
44
|
+
}
|
|
45
|
+
export interface TailscaleRouterHandle {
|
|
46
|
+
getState(): TailscaleRouterState;
|
|
47
|
+
subscribe(listener: () => void): () => void;
|
|
48
|
+
/** Resolves once registered and attached (or settled as unsupported / error). */
|
|
49
|
+
ready: Promise<TailscaleRouterState>;
|
|
50
|
+
/** Detach (and unregister, if asked to). */
|
|
51
|
+
dispose(): Promise<void>;
|
|
52
|
+
/** Remove the worker from this origin. */
|
|
53
|
+
unregister(): Promise<boolean>;
|
|
54
|
+
}
|
|
55
|
+
/** The worker URL for a policy: the policy travels in the `p` parameter. */
|
|
56
|
+
export declare function tailscaleServiceWorkerUrl(policy: ResolvedTailscalePolicy, base?: string, relativeTo?: string): string;
|
|
57
|
+
/** Why a page cannot use the router, or null. */
|
|
58
|
+
export declare function tailscaleRouterUnsupportedReason(env?: TailscaleRouterOptions['env']): string | null;
|
|
59
|
+
export declare function registerTailscaleRouter(options: TailscaleRouterOptions): TailscaleRouterHandle;
|
|
60
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/lib/tailscale-router/bridge.ts"],"names":[],"mappings":"AAUA,OAAO,EAAuE,KAAK,uBAAuB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACjK,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,gGAAgG;AAChG,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,WAAW,IAAI;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC7C;AAED,4DAA4D;AAC5D,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,oBAAoB,CAAC;IAChC,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,gHAAgH;IAChH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gHAAgH;IAChH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9E,6GAA6G;IAC7G,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,qGAAqG;IACrG,GAAG,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACpF;AAED,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,cAAc,GAAG,OAAO,CAAC;AAExG,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,uDAAuD;IACvD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,IAAI,oBAAoB,CAAC;IACjC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,iFAAiF;IACjF,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACrC,4CAA4C;IAC5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,0CAA0C;IAC1C,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAChC;AAED,4EAA4E;AAC5E,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,uBAAuB,EAAE,IAAI,SAAoB,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAIhI;AAED,iDAAiD;AACjD,wBAAgB,gCAAgC,CAAC,GAAG,GAAE,sBAAsB,CAAC,KAAK,CAAM,GAAG,MAAM,GAAG,IAAI,CAMvG;AAiBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,sBAAsB,GAAG,qBAAqB,CA8J9F"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { encodeTailscalePolicy as e, matchTailscalePolicy as t, resolveTailscalePolicy as n } from "../tailscale-policy.js";
|
|
2
|
+
//#region src/lib/tailscale-router/bridge.ts
|
|
3
|
+
function r(t, n = "tailscale-sw.js", r) {
|
|
4
|
+
let i = new URL(n, r ?? (typeof document < "u" ? document.baseURI : "http://localhost/"));
|
|
5
|
+
return i.searchParams.set("p", e(t)), i.href;
|
|
6
|
+
}
|
|
7
|
+
function i(e = {}) {
|
|
8
|
+
return e.isSecureContext ?? (typeof window < "u" && window.isSecureContext) ? (e.serviceWorker === void 0 ? typeof navigator < "u" && navigator.serviceWorker : e.serviceWorker) ? null : "This browser has no service workers (or they are turned off, as in some private windows)." : "Service workers need HTTPS (or localhost).";
|
|
9
|
+
}
|
|
10
|
+
var a = /* @__PURE__ */ new Set([
|
|
11
|
+
101,
|
|
12
|
+
103,
|
|
13
|
+
204,
|
|
14
|
+
205,
|
|
15
|
+
304
|
|
16
|
+
]);
|
|
17
|
+
function o(e) {
|
|
18
|
+
let o = n(e.policy), s = /* @__PURE__ */ new Set(), c = {
|
|
19
|
+
status: "registering",
|
|
20
|
+
detail: null,
|
|
21
|
+
routed: 0,
|
|
22
|
+
policy: o
|
|
23
|
+
}, l = (e) => {
|
|
24
|
+
c = {
|
|
25
|
+
...c,
|
|
26
|
+
...e
|
|
27
|
+
}, s.forEach((e) => e());
|
|
28
|
+
}, u = i(e.env), d = e.env?.serviceWorker === void 0 ? typeof navigator < "u" ? navigator.serviceWorker : null : e.env.serviceWorker, f = !1, p = null, m = null, h = /* @__PURE__ */ new Map(), g = () => e.tailscale.getSnapshot().status === "connected", _ = typeof location < "u" ? location.origin : void 0, v = e.tailscale.subscribe(() => p?.postMessage({
|
|
29
|
+
type: "status",
|
|
30
|
+
connected: g()
|
|
31
|
+
}));
|
|
32
|
+
async function y(n, r) {
|
|
33
|
+
let i = new AbortController();
|
|
34
|
+
h.set(r.id, i);
|
|
35
|
+
try {
|
|
36
|
+
let s = {
|
|
37
|
+
url: r.url,
|
|
38
|
+
method: r.method,
|
|
39
|
+
headers: r.headers,
|
|
40
|
+
destination: r.destination,
|
|
41
|
+
mode: r.mode
|
|
42
|
+
};
|
|
43
|
+
if (!t(r.url, r.method, o, _).route || e.shouldRoute && !await e.shouldRoute(s)) {
|
|
44
|
+
n.postMessage({
|
|
45
|
+
type: "passthrough",
|
|
46
|
+
id: r.id
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!g()) {
|
|
51
|
+
n.postMessage({
|
|
52
|
+
type: "unavailable",
|
|
53
|
+
id: r.id
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let u = await e.tailscale.fetch({
|
|
58
|
+
url: r.url,
|
|
59
|
+
method: r.method,
|
|
60
|
+
headers: r.headers,
|
|
61
|
+
body: r.body ? new Uint8Array(r.body) : null,
|
|
62
|
+
redirect: r.redirect,
|
|
63
|
+
signal: i.signal
|
|
64
|
+
});
|
|
65
|
+
if (r.redirect === "error" && u.status >= 300 && u.status < 400) throw TypeError("Redirect refused (redirect: \"error\").");
|
|
66
|
+
if (n.postMessage({
|
|
67
|
+
type: "head",
|
|
68
|
+
id: r.id,
|
|
69
|
+
status: u.status,
|
|
70
|
+
statusText: u.statusText ?? "",
|
|
71
|
+
headers: u.headers
|
|
72
|
+
}), l({ routed: c.routed + 1 }), a.has(u.status) || r.method === "HEAD" || !u.body) {
|
|
73
|
+
n.postMessage({
|
|
74
|
+
type: "end",
|
|
75
|
+
id: r.id
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (u.body instanceof Uint8Array) {
|
|
80
|
+
let e = u.body.slice().buffer;
|
|
81
|
+
n.postMessage({
|
|
82
|
+
type: "chunk",
|
|
83
|
+
id: r.id,
|
|
84
|
+
data: e
|
|
85
|
+
}, [e]);
|
|
86
|
+
} else {
|
|
87
|
+
let e = u.body.getReader();
|
|
88
|
+
for (;;) {
|
|
89
|
+
if (i.signal.aborted) {
|
|
90
|
+
await e.cancel();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let { done: t, value: a } = await e.read();
|
|
94
|
+
if (t) break;
|
|
95
|
+
let o = a.slice().buffer;
|
|
96
|
+
n.postMessage({
|
|
97
|
+
type: "chunk",
|
|
98
|
+
id: r.id,
|
|
99
|
+
data: o
|
|
100
|
+
}, [o]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
n.postMessage({
|
|
104
|
+
type: "end",
|
|
105
|
+
id: r.id
|
|
106
|
+
});
|
|
107
|
+
} catch (e) {
|
|
108
|
+
n.postMessage({
|
|
109
|
+
type: "error",
|
|
110
|
+
id: r.id,
|
|
111
|
+
message: e instanceof Error ? e.message : String(e)
|
|
112
|
+
});
|
|
113
|
+
} finally {
|
|
114
|
+
h.delete(r.id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function b(e) {
|
|
118
|
+
if (f || !e) return;
|
|
119
|
+
p?.close();
|
|
120
|
+
let t = new MessageChannel();
|
|
121
|
+
p = t.port1;
|
|
122
|
+
let n = t.port1;
|
|
123
|
+
n.onmessage = (e) => {
|
|
124
|
+
let t = e.data;
|
|
125
|
+
t.type === "request" ? y(n, t) : t.type === "cancel" && typeof t.id == "number" && h.get(t.id)?.abort();
|
|
126
|
+
}, e.postMessage({
|
|
127
|
+
type: "bl-ts/attach",
|
|
128
|
+
v: 1,
|
|
129
|
+
connected: g()
|
|
130
|
+
}, [t.port2]);
|
|
131
|
+
}
|
|
132
|
+
let x = (e) => {
|
|
133
|
+
e.data?.type === "bl-ts/needs-attach" && b(d?.controller ?? m?.active ?? null);
|
|
134
|
+
}, S = () => {
|
|
135
|
+
d?.controller && (b(d.controller), c.status === "uncontrolled" && l({
|
|
136
|
+
status: "active",
|
|
137
|
+
detail: null
|
|
138
|
+
}));
|
|
139
|
+
}, C = (async () => {
|
|
140
|
+
if (u || !d) return l({
|
|
141
|
+
status: "unsupported",
|
|
142
|
+
detail: u
|
|
143
|
+
}), c;
|
|
144
|
+
try {
|
|
145
|
+
let t = r(o, e.serviceWorkerUrl);
|
|
146
|
+
d.addEventListener("message", x), d.addEventListener("controllerchange", S), m = await d.register(t, {
|
|
147
|
+
scope: e.scope,
|
|
148
|
+
updateViaCache: "none"
|
|
149
|
+
});
|
|
150
|
+
let n = m.active ?? m.waiting ?? m.installing;
|
|
151
|
+
if (n && n.state !== "activated" && await new Promise((e) => {
|
|
152
|
+
let t = () => {
|
|
153
|
+
(n.state === "activated" || n.state === "redundant") && (n.removeEventListener("statechange", t), e());
|
|
154
|
+
};
|
|
155
|
+
n.addEventListener("statechange", t), t();
|
|
156
|
+
}), f || (d.controller || await new Promise((e) => {
|
|
157
|
+
let t = setTimeout(e, 3e3);
|
|
158
|
+
d.addEventListener("controllerchange", () => {
|
|
159
|
+
clearTimeout(t), e();
|
|
160
|
+
}, { once: !0 });
|
|
161
|
+
}), f)) return c;
|
|
162
|
+
b(d.controller ?? m.active), l(d.controller ? {
|
|
163
|
+
status: "active",
|
|
164
|
+
detail: null
|
|
165
|
+
} : {
|
|
166
|
+
status: "uncontrolled",
|
|
167
|
+
detail: "This page is not controlled by the worker (a hard reload bypasses it). Reload normally."
|
|
168
|
+
});
|
|
169
|
+
} catch (e) {
|
|
170
|
+
l({
|
|
171
|
+
status: "error",
|
|
172
|
+
detail: e instanceof Error ? e.message : String(e)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return c;
|
|
176
|
+
})();
|
|
177
|
+
return {
|
|
178
|
+
getState: () => c,
|
|
179
|
+
subscribe(e) {
|
|
180
|
+
return s.add(e), () => s.delete(e);
|
|
181
|
+
},
|
|
182
|
+
ready: C,
|
|
183
|
+
async dispose() {
|
|
184
|
+
if (!f) {
|
|
185
|
+
f = !0, v(), h.forEach((e) => e.abort()), d?.removeEventListener("message", x), d?.removeEventListener("controllerchange", S);
|
|
186
|
+
try {
|
|
187
|
+
(d?.controller ?? m?.active)?.postMessage({ type: "bl-ts/detach" });
|
|
188
|
+
} catch {}
|
|
189
|
+
p?.close(), p = null, e.unregisterOnDispose && (await C, await m?.unregister());
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async unregister() {
|
|
193
|
+
return await C, m ? m.unregister() : !1;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { o as registerTailscaleRouter, i as tailscaleRouterUnsupportedReason, r as tailscaleServiceWorkerUrl };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Tailscale } from '../tailscale';
|
|
2
|
+
import { TailscaleRouterHandle, TailscaleRouterOptions, TailscaleRouterState } from './bridge';
|
|
3
|
+
export interface UseTailscaleRouterOptions extends Omit<TailscaleRouterOptions, 'tailscale'> {
|
|
4
|
+
/** Default: the provider's controller. */
|
|
5
|
+
tailscale?: Tailscale;
|
|
6
|
+
/** Do nothing while false. Default true. */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Registers the request router for the provider's connection and returns its state (`unsupported`, `registering`, `active`, `uncontrolled`, `error`). */
|
|
10
|
+
export declare function useTailscaleRouter({ tailscale, enabled, policy, ...rest }?: UseTailscaleRouterOptions): TailscaleRouterState & {
|
|
11
|
+
router: TailscaleRouterHandle | null;
|
|
12
|
+
};
|
|
13
|
+
export interface TailscaleRouterProps extends UseTailscaleRouterOptions {
|
|
14
|
+
/** Called when the router's state changes. */
|
|
15
|
+
onStateChange?: (state: TailscaleRouterState) => void;
|
|
16
|
+
}
|
|
17
|
+
/** Renders nothing; runs `useTailscaleRouter`. */
|
|
18
|
+
export declare function TailscaleRouter({ onStateChange, ...options }: TailscaleRouterProps): null;
|
|
19
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/lib/tailscale-router/react.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAA2B,KAAK,qBAAqB,EAAE,KAAK,sBAAsB,EAAE,KAAK,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAQ5J,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC;IAC1F,0CAA0C;IAC1C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,0JAA0J;AAC1J,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,EAAE,OAAc,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAE,yBAA8B,GAAG,oBAAoB,GAAG;IAAE,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;CAAE,CAuBlL;AAED,MAAM,WAAW,oBAAqB,SAAQ,yBAAyB;IACrE,8CAA8C;IAC9C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACvD;AAED,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,EAAE,oBAAoB,GAAG,IAAI,CAOzF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { resolveTailscalePolicy as e } from "../tailscale-policy.js";
|
|
3
|
+
import { useOptionalTailscale as t } from "../tailscale-react.js";
|
|
4
|
+
import { registerTailscaleRouter as n } from "./bridge.js";
|
|
5
|
+
import { useEffect as r, useRef as i, useState as a } from "react";
|
|
6
|
+
//#region src/lib/tailscale-router/react.ts
|
|
7
|
+
function o({ tailscale: o, enabled: s = !0, policy: c, ...l } = {}) {
|
|
8
|
+
let u = t(o);
|
|
9
|
+
if (!u) throw Error("useTailscaleRouter must be used inside <TailscaleProvider> (or be given a controller).");
|
|
10
|
+
let d = JSON.stringify(e(c)), f = i(l);
|
|
11
|
+
f.current = l;
|
|
12
|
+
let [p, m] = a(null), [h, g] = a(() => ({
|
|
13
|
+
status: "registering",
|
|
14
|
+
detail: null,
|
|
15
|
+
routed: 0,
|
|
16
|
+
policy: e(c)
|
|
17
|
+
}));
|
|
18
|
+
return r(() => {
|
|
19
|
+
if (!s) return;
|
|
20
|
+
let e = n({
|
|
21
|
+
...f.current,
|
|
22
|
+
tailscale: u,
|
|
23
|
+
policy: JSON.parse(d)
|
|
24
|
+
});
|
|
25
|
+
m(e), g(e.getState());
|
|
26
|
+
let t = e.subscribe(() => g(e.getState()));
|
|
27
|
+
return () => {
|
|
28
|
+
t(), e.dispose(), m(null);
|
|
29
|
+
};
|
|
30
|
+
}, [
|
|
31
|
+
u,
|
|
32
|
+
d,
|
|
33
|
+
s
|
|
34
|
+
]), {
|
|
35
|
+
...h,
|
|
36
|
+
router: p
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function s({ onStateChange: e, ...t }) {
|
|
40
|
+
let n = o(t), a = i(e);
|
|
41
|
+
a.current = e;
|
|
42
|
+
let { status: s, detail: c, routed: l } = n;
|
|
43
|
+
return r(() => {
|
|
44
|
+
a.current?.(n);
|
|
45
|
+
}, [
|
|
46
|
+
s,
|
|
47
|
+
c,
|
|
48
|
+
l
|
|
49
|
+
]), null;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { s as TailscaleRouter, o as useTailscaleRouter };
|