@floegence/floe-webapp-protocol 0.33.11 → 0.34.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/client.d.ts +2 -1
- package/dist/index2.js +69 -59
- package/dist/index3.js +28 -32
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { type JSX } from 'solid-js';
|
|
|
2
2
|
import type { ChannelInitGrant, Client, ClientObserverLike, DirectConnectInfo } from '@floegence/flowersec-core';
|
|
3
3
|
import { type AutoReconnectConfig, type ConnectionStatus } from '@floegence/flowersec-core/reconnect';
|
|
4
4
|
import { type ControlplaneConfig } from './controlplane';
|
|
5
|
-
import type { ProtocolContract } from './contract';
|
|
5
|
+
import type { ProtocolContract, RpcClientLike } from './contract';
|
|
6
6
|
interface ProtocolContextValue {
|
|
7
7
|
status: () => ConnectionStatus;
|
|
8
8
|
error: () => Error | null;
|
|
9
9
|
client: () => Client | null;
|
|
10
|
+
rpcTransport: () => RpcClientLike;
|
|
10
11
|
contract: () => ProtocolContract;
|
|
11
12
|
connect: (config: ConnectConfig) => Promise<void>;
|
|
12
13
|
/** Force a hard reconnect (disconnect old client and build a new one). */
|
package/dist/index2.js
CHANGED
|
@@ -1,101 +1,111 @@
|
|
|
1
|
-
import { onCleanup as
|
|
2
|
-
import { createStore as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { onCleanup as x, createComponent as I, useContext as M, createContext as k } from "solid-js";
|
|
2
|
+
import { createStore as q } from "solid-js/store";
|
|
3
|
+
import { RpcProxy as E } from "@floegence/flowersec-core/rpc";
|
|
4
|
+
import { createReconnectManager as G } from "@floegence/flowersec-core/reconnect";
|
|
5
|
+
import { requestChannelGrant as R } from "./index4.js";
|
|
6
|
+
const m = k();
|
|
7
|
+
function _(c) {
|
|
8
|
+
const o = G(), a = o.state(), [s, h] = q({
|
|
9
|
+
status: a.status,
|
|
10
|
+
error: a.error,
|
|
11
|
+
client: a.client
|
|
12
|
+
}), p = c.contract, r = new E(), w = {
|
|
13
|
+
rpc: {
|
|
14
|
+
call: (t, e) => r.call(t, e),
|
|
15
|
+
notify: (t, e) => r.notify(t, e),
|
|
16
|
+
onNotify: (t, e) => r.onNotify(t, e)
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
a.client && r.attach(a.client.rpc);
|
|
20
|
+
const y = o.subscribe((t) => {
|
|
21
|
+
t.client ? r.attach(t.client.rpc) : r.detach(), h({
|
|
13
22
|
status: t.status,
|
|
14
23
|
error: t.error,
|
|
15
24
|
client: t.client
|
|
16
25
|
});
|
|
17
26
|
});
|
|
18
|
-
let
|
|
19
|
-
const
|
|
20
|
-
const
|
|
27
|
+
let i = null, n = null;
|
|
28
|
+
const l = async (t, e) => {
|
|
29
|
+
const u = {
|
|
21
30
|
autoReconnect: t.autoReconnect,
|
|
22
31
|
observer: t.observer,
|
|
23
32
|
connectOnce: async ({
|
|
24
|
-
signal:
|
|
25
|
-
observer:
|
|
33
|
+
signal: P,
|
|
34
|
+
observer: b
|
|
26
35
|
}) => {
|
|
27
36
|
const {
|
|
28
|
-
connectTunnelBrowser:
|
|
29
|
-
connectDirectBrowser:
|
|
30
|
-
} = await import("@floegence/flowersec-core/browser"),
|
|
31
|
-
observer:
|
|
32
|
-
signal:
|
|
37
|
+
connectTunnelBrowser: C,
|
|
38
|
+
connectDirectBrowser: T
|
|
39
|
+
} = await import("@floegence/flowersec-core/browser"), d = {
|
|
40
|
+
observer: b,
|
|
41
|
+
signal: P,
|
|
33
42
|
keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
|
|
34
43
|
connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
|
|
35
44
|
handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
|
|
36
45
|
};
|
|
37
46
|
if ((t.mode ?? "tunnel") === "tunnel") {
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
47
|
+
const f = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await R(t.controlplane) : null);
|
|
48
|
+
if (!f)
|
|
40
49
|
throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
|
|
41
|
-
return
|
|
50
|
+
return C(f, d);
|
|
42
51
|
}
|
|
43
52
|
if (!t.directInfo)
|
|
44
53
|
throw new Error("Direct mode requires `directInfo`");
|
|
45
|
-
return
|
|
54
|
+
return T(t.directInfo, d);
|
|
46
55
|
}
|
|
47
56
|
};
|
|
48
|
-
if (
|
|
49
|
-
await
|
|
57
|
+
if (e === "hard") {
|
|
58
|
+
await o.connect(u);
|
|
50
59
|
return;
|
|
51
60
|
}
|
|
52
|
-
await
|
|
53
|
-
},
|
|
54
|
-
status: () =>
|
|
55
|
-
error: () =>
|
|
56
|
-
client: () =>
|
|
57
|
-
|
|
61
|
+
await o.connectIfNeeded(u);
|
|
62
|
+
}, v = {
|
|
63
|
+
status: () => s.status,
|
|
64
|
+
error: () => s.error,
|
|
65
|
+
client: () => s.client,
|
|
66
|
+
rpcTransport: () => w,
|
|
67
|
+
contract: () => p,
|
|
58
68
|
connect: async (t) => {
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (!(
|
|
62
|
-
if (
|
|
63
|
-
await
|
|
69
|
+
i = t;
|
|
70
|
+
const e = o.state();
|
|
71
|
+
if (!(e.status === "connected" && e.client) && !(e.status === "connecting" && !n)) {
|
|
72
|
+
if (n) {
|
|
73
|
+
await n;
|
|
64
74
|
return;
|
|
65
75
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}), await
|
|
76
|
+
n = l(t, "if_needed").finally(() => {
|
|
77
|
+
n = null;
|
|
78
|
+
}), await n;
|
|
69
79
|
}
|
|
70
80
|
},
|
|
71
81
|
reconnect: async (t) => {
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
82
|
+
const e = t ?? i;
|
|
83
|
+
if (!e)
|
|
74
84
|
throw new Error("reconnect() requires a config before the first connect() call");
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
}),
|
|
85
|
+
return n || (i = e, n = l(e, "hard").finally(() => {
|
|
86
|
+
n = null;
|
|
87
|
+
}), n);
|
|
78
88
|
},
|
|
79
89
|
disconnect: () => {
|
|
80
|
-
|
|
90
|
+
r.detach(), o.disconnect();
|
|
81
91
|
}
|
|
82
92
|
};
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
}), I(
|
|
86
|
-
value:
|
|
93
|
+
return x(() => {
|
|
94
|
+
y(), r.detach(), o.disconnect();
|
|
95
|
+
}), I(m.Provider, {
|
|
96
|
+
value: v,
|
|
87
97
|
get children() {
|
|
88
|
-
return
|
|
98
|
+
return c.children;
|
|
89
99
|
}
|
|
90
100
|
});
|
|
91
101
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
if (!
|
|
102
|
+
function j() {
|
|
103
|
+
const c = M(m);
|
|
104
|
+
if (!c)
|
|
95
105
|
throw new Error("useProtocol must be used within a ProtocolProvider");
|
|
96
|
-
return
|
|
106
|
+
return c;
|
|
97
107
|
}
|
|
98
108
|
export {
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
_ as ProtocolProvider,
|
|
110
|
+
j as useProtocol
|
|
101
111
|
};
|
package/dist/index3.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useProtocol as
|
|
2
|
-
|
|
1
|
+
import { useProtocol as d } from "./index2.js";
|
|
2
|
+
import { RpcProxyDetachedError as u } from "@floegence/flowersec-core/rpc";
|
|
3
|
+
class f extends Error {
|
|
3
4
|
constructor() {
|
|
4
5
|
super("Not connected"), this.name = "ProtocolNotConnectedError";
|
|
5
6
|
}
|
|
@@ -7,50 +8,45 @@ class p extends Error {
|
|
|
7
8
|
class a extends Error {
|
|
8
9
|
typeId;
|
|
9
10
|
code;
|
|
10
|
-
constructor(
|
|
11
|
-
super(
|
|
11
|
+
constructor(t) {
|
|
12
|
+
super(t.message ?? `RPC error: ${t.code}`, { cause: t.cause }), this.name = "RpcError", this.typeId = t.typeId, this.code = t.code;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
return { call: async (
|
|
16
|
-
const
|
|
17
|
-
if (!t) throw new p();
|
|
15
|
+
function l(e) {
|
|
16
|
+
return { call: async (o, c) => {
|
|
17
|
+
const n = e.rpcTransport();
|
|
18
18
|
let r;
|
|
19
19
|
try {
|
|
20
|
-
r = await
|
|
21
|
-
} catch (
|
|
22
|
-
throw new a({ typeId:
|
|
20
|
+
r = await n.rpc.call(o, c);
|
|
21
|
+
} catch (i) {
|
|
22
|
+
throw i instanceof u ? new f() : new a({ typeId: o, code: -1, message: "RPC transport error", cause: i });
|
|
23
23
|
}
|
|
24
24
|
if (r.error)
|
|
25
25
|
throw new a({
|
|
26
|
-
typeId:
|
|
26
|
+
typeId: o,
|
|
27
27
|
code: r.error.code,
|
|
28
28
|
message: r.error.message ?? `RPC error: ${r.error.code}`,
|
|
29
29
|
cause: r.error
|
|
30
30
|
});
|
|
31
31
|
return r.payload;
|
|
32
|
-
}, notify: async (
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, onNotify: (e,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
n(r);
|
|
44
|
-
}) : () => {
|
|
45
|
-
};
|
|
46
|
-
} };
|
|
32
|
+
}, notify: async (o, c) => {
|
|
33
|
+
const n = e.rpcTransport();
|
|
34
|
+
try {
|
|
35
|
+
await n.rpc.notify(o, c);
|
|
36
|
+
} catch (r) {
|
|
37
|
+
if (r instanceof u) return;
|
|
38
|
+
throw new a({ typeId: o, code: -1, message: "RPC notify transport error", cause: r });
|
|
39
|
+
}
|
|
40
|
+
}, onNotify: (o, c) => e.rpcTransport().rpc.onNotify(o, (r) => {
|
|
41
|
+
c(r);
|
|
42
|
+
}) };
|
|
47
43
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
return Object.assign(
|
|
44
|
+
function m(e) {
|
|
45
|
+
const t = d(), p = e?.contract ?? t.contract(), s = l(t), o = p.createRpc(s);
|
|
46
|
+
return Object.assign(o, s);
|
|
51
47
|
}
|
|
52
48
|
export {
|
|
53
|
-
|
|
49
|
+
f as ProtocolNotConnectedError,
|
|
54
50
|
a as RpcError,
|
|
55
|
-
|
|
51
|
+
m as useRpc
|
|
56
52
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"solid-js": "^1.8.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@floegence/flowersec-core": "^0.
|
|
33
|
+
"@floegence/flowersec-core": "^0.15.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"solid-js": "^1.9.11",
|