@floegence/floe-webapp-protocol 0.35.2 → 0.35.3
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 +3 -20
- package/dist/controlplane.d.ts +1 -13
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -6
- package/dist/index2.js +52 -79
- package/package.json +2 -2
- package/dist/index4.js +0 -19
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type JSX } from 'solid-js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Client } from '@floegence/flowersec-core';
|
|
3
|
+
import { type BrowserReconnectConfig } from '@floegence/flowersec-core/browser';
|
|
3
4
|
import { type AutoReconnectConfig, type ConnectionStatus } from '@floegence/flowersec-core/reconnect';
|
|
4
|
-
import { type ControlplaneConfig } from './controlplane';
|
|
5
5
|
import type { ProtocolContract, RpcClientLike } from './contract';
|
|
6
6
|
interface ProtocolContextValue {
|
|
7
7
|
status: () => ConnectionStatus;
|
|
@@ -15,24 +15,7 @@ interface ProtocolContextValue {
|
|
|
15
15
|
disconnect: () => void;
|
|
16
16
|
}
|
|
17
17
|
export type { AutoReconnectConfig, ConnectionStatus };
|
|
18
|
-
export
|
|
19
|
-
mode?: 'tunnel' | 'direct';
|
|
20
|
-
observer?: ClientObserverLike;
|
|
21
|
-
keepaliveIntervalMs?: number;
|
|
22
|
-
connectTimeoutMs?: number;
|
|
23
|
-
handshakeTimeoutMs?: number;
|
|
24
|
-
autoReconnect?: AutoReconnectConfig;
|
|
25
|
-
controlplane?: ControlplaneConfig;
|
|
26
|
-
/**
|
|
27
|
-
* Provide a fresh grant for each connection attempt.
|
|
28
|
-
*
|
|
29
|
-
* This is the recommended way to support "reconnect requires new ticket/grant"
|
|
30
|
-
* flows (e.g. entry_ticket -> channel_init -> grant_client).
|
|
31
|
-
*/
|
|
32
|
-
getGrant?: () => Promise<ChannelInitGrant>;
|
|
33
|
-
grant?: ChannelInitGrant;
|
|
34
|
-
directInfo?: DirectConnectInfo;
|
|
35
|
-
}
|
|
18
|
+
export type ConnectConfig = BrowserReconnectConfig;
|
|
36
19
|
export declare function ProtocolProvider(props: {
|
|
37
20
|
children: JSX.Element;
|
|
38
21
|
contract: ProtocolContract;
|
package/dist/controlplane.d.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ControlplaneConfig {
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
endpointId: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Request a tunnel grant (ChannelInitGrant) from the controlplane.
|
|
8
|
-
*
|
|
9
|
-
* HTTP contract (documented in `docs/protocol.md`):
|
|
10
|
-
* - POST `${baseUrl}/v1/channel/init`, body: { endpoint_id }
|
|
11
|
-
* - Response: `{ grant_client: ChannelInitGrant }`
|
|
12
|
-
*/
|
|
13
|
-
export declare function requestChannelGrant(config: ControlplaneConfig): Promise<ChannelInitGrant>;
|
|
1
|
+
export { requestChannelGrant, requestEntryChannelGrant, type ControlplaneConfig, type EntryControlplaneConfig, } from '@floegence/flowersec-core/browser';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ProtocolProvider, useProtocol, type ConnectionStatus, type ConnectConfig, type AutoReconnectConfig } from './client';
|
|
2
2
|
export { useRpc, RpcError, ProtocolNotConnectedError } from './rpc';
|
|
3
|
-
export { requestChannelGrant, type ControlplaneConfig } from './controlplane';
|
|
3
|
+
export { requestChannelGrant, requestEntryChannelGrant, type ControlplaneConfig, type EntryControlplaneConfig } from './controlplane';
|
|
4
4
|
export type { ProtocolContract, RpcClientLike, RpcHelpers } from './contract';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ProtocolProvider as e, useProtocol as t } from "./index2.js";
|
|
2
|
-
import { ProtocolNotConnectedError as
|
|
3
|
-
import { requestChannelGrant as
|
|
2
|
+
import { ProtocolNotConnectedError as c, RpcError as l, useRpc as p } from "./index3.js";
|
|
3
|
+
import { requestChannelGrant as s, requestEntryChannelGrant as u } from "@floegence/flowersec-core/browser";
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
c as ProtocolNotConnectedError,
|
|
6
6
|
e as ProtocolProvider,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
l as RpcError,
|
|
8
|
+
s as requestChannelGrant,
|
|
9
|
+
u as requestEntryChannelGrant,
|
|
9
10
|
t as useProtocol,
|
|
10
|
-
|
|
11
|
+
p as useRpc
|
|
11
12
|
};
|
package/dist/index2.js
CHANGED
|
@@ -1,111 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createStore as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
status:
|
|
10
|
-
error:
|
|
11
|
-
client:
|
|
12
|
-
}),
|
|
1
|
+
import { createContext as y, onCleanup as P, createComponent as g, useContext as C } from "solid-js";
|
|
2
|
+
import { createStore as x } from "solid-js/store";
|
|
3
|
+
import { createBrowserReconnectConfig as b } from "@floegence/flowersec-core/browser";
|
|
4
|
+
import { RpcProxy as v } from "@floegence/flowersec-core/rpc";
|
|
5
|
+
import { createReconnectManager as N } from "@floegence/flowersec-core/reconnect";
|
|
6
|
+
const f = y();
|
|
7
|
+
function F(o) {
|
|
8
|
+
const r = N(), i = r.state(), [s, d] = x({
|
|
9
|
+
status: i.status,
|
|
10
|
+
error: i.error,
|
|
11
|
+
client: i.client
|
|
12
|
+
}), h = o.contract, c = new v(), p = {
|
|
13
13
|
rpc: {
|
|
14
|
-
call: (t,
|
|
15
|
-
notify: (t,
|
|
16
|
-
onNotify: (t,
|
|
14
|
+
call: (t, n) => c.call(t, n),
|
|
15
|
+
notify: (t, n) => c.notify(t, n),
|
|
16
|
+
onNotify: (t, n) => c.onNotify(t, n)
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
t.client ?
|
|
19
|
+
i.client && c.attach(i.client.rpc);
|
|
20
|
+
const m = r.subscribe((t) => {
|
|
21
|
+
t.client ? c.attach(t.client.rpc) : c.detach(), d({
|
|
22
22
|
status: t.status,
|
|
23
23
|
error: t.error,
|
|
24
24
|
client: t.client
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
|
-
let
|
|
28
|
-
const l = async (t,
|
|
29
|
-
const u =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
connectOnce: async ({
|
|
33
|
-
signal: P,
|
|
34
|
-
observer: b
|
|
35
|
-
}) => {
|
|
36
|
-
const {
|
|
37
|
-
connectTunnelBrowser: C,
|
|
38
|
-
connectDirectBrowser: T
|
|
39
|
-
} = await import("@floegence/flowersec-core/browser"), d = {
|
|
40
|
-
observer: b,
|
|
41
|
-
signal: P,
|
|
42
|
-
keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
|
|
43
|
-
connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
|
|
44
|
-
handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
|
|
45
|
-
};
|
|
46
|
-
if ((t.mode ?? "tunnel") === "tunnel") {
|
|
47
|
-
const f = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await R(t.controlplane) : null);
|
|
48
|
-
if (!f)
|
|
49
|
-
throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
|
|
50
|
-
return C(f, d);
|
|
51
|
-
}
|
|
52
|
-
if (!t.directInfo)
|
|
53
|
-
throw new Error("Direct mode requires `directInfo`");
|
|
54
|
-
return T(t.directInfo, d);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
if (e === "hard") {
|
|
58
|
-
await o.connect(u);
|
|
27
|
+
let a = null, e = null;
|
|
28
|
+
const l = async (t, n) => {
|
|
29
|
+
const u = b(t);
|
|
30
|
+
if (n === "hard") {
|
|
31
|
+
await r.connect(u);
|
|
59
32
|
return;
|
|
60
33
|
}
|
|
61
|
-
await
|
|
62
|
-
},
|
|
34
|
+
await r.connectIfNeeded(u);
|
|
35
|
+
}, w = {
|
|
63
36
|
status: () => s.status,
|
|
64
37
|
error: () => s.error,
|
|
65
38
|
client: () => s.client,
|
|
66
|
-
rpcTransport: () =>
|
|
67
|
-
contract: () =>
|
|
39
|
+
rpcTransport: () => p,
|
|
40
|
+
contract: () => h,
|
|
68
41
|
connect: async (t) => {
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
if (!(
|
|
72
|
-
if (
|
|
73
|
-
await
|
|
42
|
+
a = t;
|
|
43
|
+
const n = r.state();
|
|
44
|
+
if (!(n.status === "connected" && n.client) && !(n.status === "connecting" && !e)) {
|
|
45
|
+
if (e) {
|
|
46
|
+
await e;
|
|
74
47
|
return;
|
|
75
48
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}), await
|
|
49
|
+
e = l(t, "if_needed").finally(() => {
|
|
50
|
+
e = null;
|
|
51
|
+
}), await e;
|
|
79
52
|
}
|
|
80
53
|
},
|
|
81
54
|
reconnect: async (t) => {
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
55
|
+
const n = t ?? a;
|
|
56
|
+
if (!n)
|
|
84
57
|
throw new Error("reconnect() requires a config before the first connect() call");
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
}),
|
|
58
|
+
return e || (a = n, e = l(n, "hard").finally(() => {
|
|
59
|
+
e = null;
|
|
60
|
+
}), e);
|
|
88
61
|
},
|
|
89
62
|
disconnect: () => {
|
|
90
|
-
|
|
63
|
+
c.detach(), r.disconnect();
|
|
91
64
|
}
|
|
92
65
|
};
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
value:
|
|
66
|
+
return P(() => {
|
|
67
|
+
m(), c.detach(), r.disconnect();
|
|
68
|
+
}), g(f.Provider, {
|
|
69
|
+
value: w,
|
|
97
70
|
get children() {
|
|
98
|
-
return
|
|
71
|
+
return o.children;
|
|
99
72
|
}
|
|
100
73
|
});
|
|
101
74
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
75
|
+
function M() {
|
|
76
|
+
const o = C(f);
|
|
77
|
+
if (!o)
|
|
105
78
|
throw new Error("useProtocol must be used within a ProtocolProvider");
|
|
106
|
-
return
|
|
79
|
+
return o;
|
|
107
80
|
}
|
|
108
81
|
export {
|
|
109
|
-
|
|
110
|
-
|
|
82
|
+
F as ProtocolProvider,
|
|
83
|
+
M as useProtocol
|
|
111
84
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-protocol",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.3",
|
|
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.16.
|
|
33
|
+
"@floegence/flowersec-core": "^0.16.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"solid-js": "^1.9.11",
|
package/dist/index4.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { assertChannelInitGrant as r } from "@floegence/flowersec-core";
|
|
2
|
-
async function o(t) {
|
|
3
|
-
const n = await fetch(`${t.baseUrl}/v1/channel/init`, {
|
|
4
|
-
method: "POST",
|
|
5
|
-
credentials: "omit",
|
|
6
|
-
cache: "no-store",
|
|
7
|
-
headers: { "Content-Type": "application/json" },
|
|
8
|
-
body: JSON.stringify({ endpoint_id: t.endpointId })
|
|
9
|
-
});
|
|
10
|
-
if (!n.ok)
|
|
11
|
-
throw new Error(`Failed to get channel grant: ${n.status}`);
|
|
12
|
-
const e = await n.json();
|
|
13
|
-
if (!e?.grant_client)
|
|
14
|
-
throw new Error("Invalid controlplane response: missing `grant_client`");
|
|
15
|
-
return r(e.grant_client);
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
o as requestChannelGrant
|
|
19
|
-
};
|