@floegence/floe-webapp-protocol 0.8.9 → 0.9.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/dist/index2.js +88 -105
- package/dist/index3.js +32 -36
- package/dist/index4.js +9 -9
- package/package.json +6 -6
package/dist/index2.js
CHANGED
|
@@ -2,14 +2,14 @@ import { createContext as T, onCleanup as E, createComponent as P, useContext as
|
|
|
2
2
|
import { createStore as A } from "solid-js/store";
|
|
3
3
|
import { requestChannelGrant as W } from "./index4.js";
|
|
4
4
|
const R = T();
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function x(c) {
|
|
6
|
+
return c?.enabled ? {
|
|
7
7
|
enabled: !0,
|
|
8
|
-
maxAttempts: Math.max(1,
|
|
9
|
-
initialDelayMs: Math.max(0,
|
|
10
|
-
maxDelayMs: Math.max(0,
|
|
11
|
-
factor: Math.max(1,
|
|
12
|
-
jitterRatio: Math.max(0,
|
|
8
|
+
maxAttempts: Math.max(1, c.maxAttempts ?? 5),
|
|
9
|
+
initialDelayMs: Math.max(0, c.initialDelayMs ?? 500),
|
|
10
|
+
maxDelayMs: Math.max(0, c.maxDelayMs ?? 1e4),
|
|
11
|
+
factor: Math.max(1, c.factor ?? 1.8),
|
|
12
|
+
jitterRatio: Math.max(0, c.jitterRatio ?? 0.2)
|
|
13
13
|
} : {
|
|
14
14
|
enabled: !1,
|
|
15
15
|
maxAttempts: 1,
|
|
@@ -19,150 +19,133 @@ function y(a) {
|
|
|
19
19
|
jitterRatio: 0.2
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function j(
|
|
23
|
-
const
|
|
24
|
-
return Math.max(0, Math.round(
|
|
22
|
+
function j(c, a) {
|
|
23
|
+
const s = Math.min(a.maxDelayMs, a.initialDelayMs * Math.pow(a.factor, c)), l = a.jitterRatio <= 0 ? 0 : s * a.jitterRatio * (Math.random() * 2 - 1);
|
|
24
|
+
return Math.max(0, Math.round(s + l));
|
|
25
25
|
}
|
|
26
|
-
function H(
|
|
27
|
-
const [
|
|
26
|
+
function H(c) {
|
|
27
|
+
const [a, s] = A({
|
|
28
28
|
status: "disconnected",
|
|
29
29
|
error: null,
|
|
30
30
|
client: null
|
|
31
31
|
});
|
|
32
|
-
let l = 0,
|
|
32
|
+
let l = 0, i = null, u = null, m = null;
|
|
33
33
|
const h = () => {
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
m =
|
|
37
|
-
|
|
38
|
-
},
|
|
34
|
+
u && (clearTimeout(u), u = null), m?.(), m = null;
|
|
35
|
+
}, f = (n) => new Promise((t) => {
|
|
36
|
+
m = t, u = setTimeout(() => {
|
|
37
|
+
u = null, m = null, t();
|
|
38
|
+
}, n);
|
|
39
39
|
}), M = () => {
|
|
40
|
-
h(),
|
|
40
|
+
h(), i = null, l += 1, a.client && a.client.close(), s({
|
|
41
41
|
status: "disconnected",
|
|
42
42
|
error: null,
|
|
43
43
|
client: null
|
|
44
44
|
});
|
|
45
|
-
},
|
|
46
|
-
if (
|
|
47
|
-
if (!
|
|
48
|
-
|
|
45
|
+
}, y = (n, t, r) => {
|
|
46
|
+
if (n !== l || i !== t || a.status !== "connected") return;
|
|
47
|
+
if (!x(t.autoReconnect).enabled) {
|
|
48
|
+
s({
|
|
49
49
|
status: "error",
|
|
50
|
-
error:
|
|
50
|
+
error: r,
|
|
51
51
|
client: null
|
|
52
52
|
});
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
h(), l += 1;
|
|
56
|
-
const
|
|
57
|
-
|
|
56
|
+
const o = l;
|
|
57
|
+
s({
|
|
58
58
|
status: "connecting",
|
|
59
|
-
error:
|
|
59
|
+
error: r,
|
|
60
60
|
client: null
|
|
61
|
-
}),
|
|
61
|
+
}), w(o, t).catch(() => {
|
|
62
62
|
});
|
|
63
|
-
},
|
|
64
|
-
const
|
|
63
|
+
}, b = (n, t) => {
|
|
64
|
+
const r = t.observer;
|
|
65
65
|
return {
|
|
66
|
-
onConnect: (...
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
onConnect: (...e) => r?.onConnect?.(...e),
|
|
67
|
+
onAttach: (...e) => r?.onAttach?.(...e),
|
|
68
|
+
onHandshake: (...e) => r?.onHandshake?.(...e),
|
|
69
|
+
onWsClose: (e, o) => {
|
|
70
|
+
r?.onWsClose?.(e, o), e === "peer_or_error" && y(n, t, new Error(`WebSocket closed (${o ?? "unknown"})`));
|
|
69
71
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return (n = t == null ? void 0 : t.onAttach) == null ? void 0 : n.call(t, ...o);
|
|
72
|
+
onWsError: (e) => {
|
|
73
|
+
r?.onWsError?.(e), y(n, t, new Error(`WebSocket error: ${e}`));
|
|
73
74
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return (n = t == null ? void 0 : t.onHandshake) == null ? void 0 : n.call(t, ...o);
|
|
77
|
-
},
|
|
78
|
-
onWsClose: (o, n) => {
|
|
79
|
-
var s;
|
|
80
|
-
(s = t == null ? void 0 : t.onWsClose) == null || s.call(t, o, n), o === "peer_or_error" && w(r, e, new Error(`WebSocket closed (${n ?? "unknown"})`));
|
|
81
|
-
},
|
|
82
|
-
onWsError: (o) => {
|
|
83
|
-
var n;
|
|
84
|
-
(n = t == null ? void 0 : t.onWsError) == null || n.call(t, o), w(r, e, new Error(`WebSocket error: ${o}`));
|
|
85
|
-
},
|
|
86
|
-
onRpcCall: (...o) => {
|
|
87
|
-
var n;
|
|
88
|
-
return (n = t == null ? void 0 : t.onRpcCall) == null ? void 0 : n.call(t, ...o);
|
|
89
|
-
},
|
|
90
|
-
onRpcNotify: (...o) => {
|
|
91
|
-
var n;
|
|
92
|
-
return (n = t == null ? void 0 : t.onRpcNotify) == null ? void 0 : n.call(t, ...o);
|
|
93
|
-
}
|
|
75
|
+
onRpcCall: (...e) => r?.onRpcCall?.(...e),
|
|
76
|
+
onRpcNotify: (...e) => r?.onRpcNotify?.(...e)
|
|
94
77
|
};
|
|
95
|
-
},
|
|
78
|
+
}, v = async (n, t) => {
|
|
96
79
|
const {
|
|
97
|
-
connectTunnelBrowser:
|
|
98
|
-
connectDirectBrowser:
|
|
99
|
-
} = await import("@floegence/flowersec-core/browser"),
|
|
100
|
-
observer:
|
|
101
|
-
keepaliveIntervalMs:
|
|
102
|
-
connectTimeoutMs:
|
|
103
|
-
handshakeTimeoutMs:
|
|
80
|
+
connectTunnelBrowser: r,
|
|
81
|
+
connectDirectBrowser: e
|
|
82
|
+
} = await import("@floegence/flowersec-core/browser"), o = {
|
|
83
|
+
observer: b(n, t),
|
|
84
|
+
keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
|
|
85
|
+
connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
|
|
86
|
+
handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
|
|
104
87
|
};
|
|
105
|
-
if ((
|
|
106
|
-
const p =
|
|
88
|
+
if ((t.mode ?? "tunnel") === "tunnel") {
|
|
89
|
+
const p = t.grant ?? (t.controlplane ? await W(t.controlplane) : null);
|
|
107
90
|
if (!p)
|
|
108
91
|
throw new Error("Tunnel mode requires `grant` or `controlplane` config");
|
|
109
|
-
return
|
|
92
|
+
return r(p, o);
|
|
110
93
|
}
|
|
111
|
-
if (!
|
|
94
|
+
if (!t.directInfo)
|
|
112
95
|
throw new Error("Direct mode requires `directInfo`");
|
|
113
|
-
return
|
|
114
|
-
},
|
|
115
|
-
const
|
|
116
|
-
let
|
|
96
|
+
return e(t.directInfo, o);
|
|
97
|
+
}, w = async (n, t) => {
|
|
98
|
+
const r = x(t.autoReconnect);
|
|
99
|
+
let e = 0;
|
|
117
100
|
for (; ; ) {
|
|
118
|
-
if (
|
|
119
|
-
|
|
101
|
+
if (n !== l || i !== t) return;
|
|
102
|
+
e += 1;
|
|
120
103
|
try {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
104
|
+
const o = await v(n, t);
|
|
105
|
+
if (n !== l) {
|
|
106
|
+
o.close();
|
|
124
107
|
return;
|
|
125
108
|
}
|
|
126
|
-
if (
|
|
127
|
-
|
|
109
|
+
if (i !== t) {
|
|
110
|
+
o.close();
|
|
128
111
|
return;
|
|
129
112
|
}
|
|
130
|
-
|
|
113
|
+
s({
|
|
131
114
|
status: "connected",
|
|
132
|
-
client:
|
|
115
|
+
client: o,
|
|
133
116
|
error: null
|
|
134
117
|
});
|
|
135
118
|
return;
|
|
136
|
-
} catch (
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
if (!(
|
|
140
|
-
throw
|
|
119
|
+
} catch (o) {
|
|
120
|
+
const d = o instanceof Error ? o : new Error(String(o));
|
|
121
|
+
if (n !== l || i !== t) return;
|
|
122
|
+
if (!(r.enabled && e < r.maxAttempts))
|
|
123
|
+
throw s({
|
|
141
124
|
status: "error",
|
|
142
|
-
error:
|
|
125
|
+
error: d,
|
|
143
126
|
client: null
|
|
144
|
-
}),
|
|
145
|
-
|
|
127
|
+
}), d;
|
|
128
|
+
s({
|
|
146
129
|
status: "connecting",
|
|
147
|
-
error:
|
|
130
|
+
error: d,
|
|
148
131
|
client: null
|
|
149
132
|
});
|
|
150
|
-
const D = j(
|
|
151
|
-
await
|
|
133
|
+
const D = j(e - 1, r);
|
|
134
|
+
await f(D);
|
|
152
135
|
}
|
|
153
136
|
}
|
|
154
|
-
},
|
|
155
|
-
status: () =>
|
|
156
|
-
error: () =>
|
|
157
|
-
client: () =>
|
|
158
|
-
connect: async (
|
|
137
|
+
}, C = {
|
|
138
|
+
status: () => a.status,
|
|
139
|
+
error: () => a.error,
|
|
140
|
+
client: () => a.client,
|
|
141
|
+
connect: async (n) => {
|
|
159
142
|
h(), l += 1;
|
|
160
|
-
const
|
|
161
|
-
|
|
143
|
+
const t = l;
|
|
144
|
+
i = n, a.client && a.client.close(), s({
|
|
162
145
|
status: "connecting",
|
|
163
146
|
error: null,
|
|
164
147
|
client: null
|
|
165
|
-
}), await
|
|
148
|
+
}), await w(t, n);
|
|
166
149
|
},
|
|
167
150
|
disconnect: () => {
|
|
168
151
|
M();
|
|
@@ -171,17 +154,17 @@ function H(a) {
|
|
|
171
154
|
return E(() => {
|
|
172
155
|
M();
|
|
173
156
|
}), P(R.Provider, {
|
|
174
|
-
value:
|
|
157
|
+
value: C,
|
|
175
158
|
get children() {
|
|
176
|
-
return
|
|
159
|
+
return c.children;
|
|
177
160
|
}
|
|
178
161
|
});
|
|
179
162
|
}
|
|
180
163
|
function N() {
|
|
181
|
-
const
|
|
182
|
-
if (!
|
|
164
|
+
const c = k(R);
|
|
165
|
+
if (!c)
|
|
183
166
|
throw new Error("useProtocol must be used within a ProtocolProvider");
|
|
184
|
-
return
|
|
167
|
+
return c;
|
|
185
168
|
}
|
|
186
169
|
export {
|
|
187
170
|
H as ProtocolProvider,
|
package/dist/index3.js
CHANGED
|
@@ -1,56 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useProtocol as E } from "./index2.js";
|
|
5
|
-
import { TypeIds as c } from "./index5.js";
|
|
6
|
-
class u extends Error {
|
|
1
|
+
import { useProtocol as l } from "./index2.js";
|
|
2
|
+
import { TypeIds as t } from "./index5.js";
|
|
3
|
+
class i extends Error {
|
|
7
4
|
constructor() {
|
|
8
5
|
super("Not connected"), this.name = "ProtocolNotConnectedError";
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
class
|
|
8
|
+
class n extends Error {
|
|
9
|
+
typeId;
|
|
10
|
+
code;
|
|
12
11
|
constructor(r) {
|
|
13
|
-
super(r.message ?? `RPC error: ${r.code}`, { cause: r.cause });
|
|
14
|
-
s(this, "typeId");
|
|
15
|
-
s(this, "code");
|
|
16
|
-
this.name = "RpcError", this.typeId = r.typeId, this.code = r.code;
|
|
12
|
+
super(r.message ?? `RPC error: ${r.code}`, { cause: r.cause }), this.name = "RpcError", this.typeId = r.typeId, this.code = r.code;
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
throw new
|
|
24
|
-
let
|
|
15
|
+
function u() {
|
|
16
|
+
const c = l(), r = async (e, a) => {
|
|
17
|
+
const s = c.client();
|
|
18
|
+
if (!s)
|
|
19
|
+
throw new i();
|
|
20
|
+
let o;
|
|
25
21
|
try {
|
|
26
|
-
|
|
27
|
-
} catch (
|
|
28
|
-
throw new
|
|
22
|
+
o = await s.rpc.call(e, a);
|
|
23
|
+
} catch (d) {
|
|
24
|
+
throw new n({ typeId: e, code: -1, message: "RPC transport error", cause: d });
|
|
29
25
|
}
|
|
30
|
-
if (
|
|
31
|
-
throw new
|
|
32
|
-
typeId:
|
|
33
|
-
code:
|
|
34
|
-
message:
|
|
35
|
-
cause:
|
|
26
|
+
if (o.error)
|
|
27
|
+
throw new n({
|
|
28
|
+
typeId: e,
|
|
29
|
+
code: o.error.code,
|
|
30
|
+
message: o.error.message ?? `RPC error: ${o.error.code}`,
|
|
31
|
+
cause: o.error
|
|
36
32
|
});
|
|
37
|
-
return
|
|
33
|
+
return o.payload;
|
|
38
34
|
};
|
|
39
35
|
return {
|
|
40
36
|
// File system operations
|
|
41
37
|
fs: {
|
|
42
|
-
list: (
|
|
43
|
-
readFile: (
|
|
44
|
-
writeFile: (
|
|
45
|
-
delete: (
|
|
46
|
-
getHome: () =>
|
|
38
|
+
list: (e) => r(t.FS_LIST, e),
|
|
39
|
+
readFile: (e) => r(t.FS_READ_FILE, e),
|
|
40
|
+
writeFile: (e) => r(t.FS_WRITE_FILE, e),
|
|
41
|
+
delete: (e) => r(t.FS_DELETE, e),
|
|
42
|
+
getHome: () => r(t.FS_GET_HOME, {})
|
|
47
43
|
},
|
|
48
44
|
// Raw call for custom operations
|
|
49
|
-
call:
|
|
45
|
+
call: r
|
|
50
46
|
};
|
|
51
47
|
}
|
|
52
48
|
export {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
i as ProtocolNotConnectedError,
|
|
50
|
+
n as RpcError,
|
|
51
|
+
u as useRpc
|
|
56
52
|
};
|
package/dist/index4.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { assertChannelInitGrant as r } from "@floegence/flowersec-core";
|
|
2
|
-
async function
|
|
3
|
-
const
|
|
2
|
+
async function o(t) {
|
|
3
|
+
const n = await fetch(`${t.baseUrl}/v1/channel/init`, {
|
|
4
4
|
method: "POST",
|
|
5
5
|
headers: { "Content-Type": "application/json" },
|
|
6
|
-
body: JSON.stringify({ endpoint_id:
|
|
6
|
+
body: JSON.stringify({ endpoint_id: t.endpointId })
|
|
7
7
|
});
|
|
8
|
-
if (!
|
|
9
|
-
throw new Error(`Failed to get channel grant: ${
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
8
|
+
if (!n.ok)
|
|
9
|
+
throw new Error(`Failed to get channel grant: ${n.status}`);
|
|
10
|
+
const e = await n.json();
|
|
11
|
+
if (!e?.grant_client)
|
|
12
12
|
throw new Error("Invalid controlplane response: missing `grant_client`");
|
|
13
|
-
return r(
|
|
13
|
+
return r(e.grant_client);
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
|
-
|
|
16
|
+
o as requestChannelGrant
|
|
17
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"solid-js": "^1.8.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@floegence/flowersec-core": "^0.
|
|
27
|
+
"@floegence/flowersec-core": "^0.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"solid-js": "^1.9.
|
|
31
|
-
"typescript": "^5.
|
|
32
|
-
"vite": "^
|
|
33
|
-
"vite-plugin-solid": "^2.11.
|
|
30
|
+
"solid-js": "^1.9.11",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"vite": "^7.3.1",
|
|
33
|
+
"vite-plugin-solid": "^2.11.10"
|
|
34
34
|
}
|
|
35
35
|
}
|