@floegence/floe-webapp-protocol 0.16.0 → 0.18.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 CHANGED
@@ -9,6 +9,8 @@ interface ProtocolContextValue {
9
9
  client: () => Client | null;
10
10
  contract: () => ProtocolContract;
11
11
  connect: (config: ConnectConfig) => Promise<void>;
12
+ /** Force a hard reconnect (disconnect old client and build a new one). */
13
+ reconnect: (config?: ConnectConfig) => Promise<void>;
12
14
  disconnect: () => void;
13
15
  }
14
16
  export type { AutoReconnectConfig, ConnectionStatus };
package/dist/index2.js CHANGED
@@ -1,74 +1,88 @@
1
- import { createContext as h, onCleanup as v, createComponent as P, useContext as b } from "solid-js";
2
- import { createStore as M } from "solid-js/store";
3
- import { createReconnectManager as C } from "@floegence/flowersec-core/reconnect";
4
- import { requestChannelGrant as T } from "./index4.js";
5
- const s = h();
6
- function f(r) {
7
- const e = C(), [n, a] = M({
8
- status: e.state().status,
9
- error: e.state().error,
10
- client: e.state().client
11
- }), u = r.contract, i = e.subscribe((t) => {
12
- a({
1
+ import { onCleanup as C, createComponent as P, useContext as M, createContext as I } from "solid-js";
2
+ import { createStore as T } from "solid-js/store";
3
+ import { createReconnectManager as x } from "@floegence/flowersec-core/reconnect";
4
+ import { requestChannelGrant as y } from "./index4.js";
5
+ const u = I();
6
+ function D(o) {
7
+ const n = x(), [c, d] = T({
8
+ status: n.state().status,
9
+ error: n.state().error,
10
+ client: n.state().client
11
+ }), m = o.contract, w = n.subscribe((t) => {
12
+ d({
13
13
  status: t.status,
14
14
  error: t.error,
15
15
  client: t.client
16
16
  });
17
- }), l = {
18
- status: () => n.status,
19
- error: () => n.error,
20
- client: () => n.client,
21
- contract: () => u,
22
- connect: async (t) => {
23
- await e.connect({
24
- autoReconnect: t.autoReconnect,
25
- observer: t.observer,
26
- connectOnce: async ({
27
- signal: m,
28
- observer: d
29
- }) => {
30
- const {
31
- connectTunnelBrowser: w,
32
- connectDirectBrowser: p
33
- } = await import("@floegence/flowersec-core/browser"), o = {
34
- observer: d,
35
- signal: m,
36
- keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
37
- connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
38
- handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
39
- };
40
- if ((t.mode ?? "tunnel") === "tunnel") {
41
- const c = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await T(t.controlplane) : null);
42
- if (!c)
43
- throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
44
- return w(c, o);
45
- }
46
- if (!t.directInfo)
47
- throw new Error("Direct mode requires `directInfo`");
48
- return p(t.directInfo, o);
17
+ });
18
+ let s = null, r = null;
19
+ const h = async (t) => {
20
+ await n.connect({
21
+ autoReconnect: t.autoReconnect,
22
+ observer: t.observer,
23
+ connectOnce: async ({
24
+ signal: e,
25
+ observer: p
26
+ }) => {
27
+ const {
28
+ connectTunnelBrowser: v,
29
+ connectDirectBrowser: b
30
+ } = await import("@floegence/flowersec-core/browser"), i = {
31
+ observer: p,
32
+ signal: e,
33
+ keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
34
+ connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
35
+ handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
36
+ };
37
+ if ((t.mode ?? "tunnel") === "tunnel") {
38
+ const l = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await y(t.controlplane) : null);
39
+ if (!l)
40
+ throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
41
+ return v(l, i);
49
42
  }
50
- });
43
+ if (!t.directInfo)
44
+ throw new Error("Direct mode requires `directInfo`");
45
+ return b(t.directInfo, i);
46
+ }
47
+ });
48
+ }, a = async (t) => {
49
+ const e = t ?? s;
50
+ if (!e)
51
+ throw new Error("reconnect() requires a config before the first connect() call");
52
+ return r || (s = e, r = h(e).finally(() => {
53
+ r = null;
54
+ }), r);
55
+ }, f = {
56
+ status: () => c.status,
57
+ error: () => c.error,
58
+ client: () => c.client,
59
+ contract: () => m,
60
+ connect: async (t) => {
61
+ s = t;
62
+ const e = n.state();
63
+ e.status === "connected" && e.client || e.status === "connecting" && !r || await a(t);
51
64
  },
65
+ reconnect: a,
52
66
  disconnect: () => {
53
- e.disconnect();
67
+ n.disconnect();
54
68
  }
55
69
  };
56
- return v(() => {
57
- i(), e.disconnect();
58
- }), P(s.Provider, {
59
- value: l,
70
+ return C(() => {
71
+ w(), n.disconnect();
72
+ }), P(u.Provider, {
73
+ value: f,
60
74
  get children() {
61
- return r.children;
75
+ return o.children;
62
76
  }
63
77
  });
64
78
  }
65
- function y() {
66
- const r = b(s);
67
- if (!r)
79
+ function O() {
80
+ const o = M(u);
81
+ if (!o)
68
82
  throw new Error("useProtocol must be used within a ProtocolProvider");
69
- return r;
83
+ return o;
70
84
  }
71
85
  export {
72
- f as ProtocolProvider,
73
- y as useProtocol
86
+ D as ProtocolProvider,
87
+ O as useProtocol
74
88
  };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-protocol",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
8
9
  "exports": {
9
10
  ".": {
10
11
  "types": "./dist/index.d.ts",