@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 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 P, createComponent as I, useContext as M, createContext as y } 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 k } from "./index4.js";
5
- const d = y();
6
- function S(o) {
7
- const n = x(), [c, m] = T({
8
- status: n.state().status,
9
- error: n.state().error,
10
- client: n.state().client
11
- }), f = o.contract, w = n.subscribe((t) => {
12
- m({
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 s = null, e = null;
19
- const a = async (t, r) => {
20
- const i = {
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: p,
25
- observer: v
33
+ signal: P,
34
+ observer: b
26
35
  }) => {
27
36
  const {
28
- connectTunnelBrowser: b,
29
- connectDirectBrowser: C
30
- } = await import("@floegence/flowersec-core/browser"), l = {
31
- observer: v,
32
- signal: p,
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 u = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await k(t.controlplane) : null);
39
- if (!u)
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 b(u, l);
50
+ return C(f, d);
42
51
  }
43
52
  if (!t.directInfo)
44
53
  throw new Error("Direct mode requires `directInfo`");
45
- return C(t.directInfo, l);
54
+ return T(t.directInfo, d);
46
55
  }
47
56
  };
48
- if (r === "hard") {
49
- await n.connect(i);
57
+ if (e === "hard") {
58
+ await o.connect(u);
50
59
  return;
51
60
  }
52
- await n.connectIfNeeded(i);
53
- }, h = {
54
- status: () => c.status,
55
- error: () => c.error,
56
- client: () => c.client,
57
- contract: () => f,
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
- s = t;
60
- const r = n.state();
61
- if (!(r.status === "connected" && r.client) && !(r.status === "connecting" && !e)) {
62
- if (e) {
63
- await e;
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
- e = a(t, "if_needed").finally(() => {
67
- e = null;
68
- }), await e;
76
+ n = l(t, "if_needed").finally(() => {
77
+ n = null;
78
+ }), await n;
69
79
  }
70
80
  },
71
81
  reconnect: async (t) => {
72
- const r = t ?? s;
73
- if (!r)
82
+ const e = t ?? i;
83
+ if (!e)
74
84
  throw new Error("reconnect() requires a config before the first connect() call");
75
- return e || (s = r, e = a(r, "hard").finally(() => {
76
- e = null;
77
- }), e);
85
+ return n || (i = e, n = l(e, "hard").finally(() => {
86
+ n = null;
87
+ }), n);
78
88
  },
79
89
  disconnect: () => {
80
- n.disconnect();
90
+ r.detach(), o.disconnect();
81
91
  }
82
92
  };
83
- return P(() => {
84
- w(), n.disconnect();
85
- }), I(d.Provider, {
86
- value: h,
93
+ return x(() => {
94
+ y(), r.detach(), o.disconnect();
95
+ }), I(m.Provider, {
96
+ value: v,
87
97
  get children() {
88
- return o.children;
98
+ return c.children;
89
99
  }
90
100
  });
91
101
  }
92
- function A() {
93
- const o = M(d);
94
- if (!o)
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 o;
106
+ return c;
97
107
  }
98
108
  export {
99
- S as ProtocolProvider,
100
- A as useProtocol
109
+ _ as ProtocolProvider,
110
+ j as useProtocol
101
111
  };
package/dist/index3.js CHANGED
@@ -1,5 +1,6 @@
1
- import { useProtocol as u } from "./index2.js";
2
- class p extends Error {
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(o) {
11
- super(o.message ?? `RPC error: ${o.code}`, { cause: o.cause }), this.name = "RpcError", this.typeId = o.typeId, this.code = o.code;
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 d(c) {
15
- return { call: async (e, n) => {
16
- const t = c.client();
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 t.rpc.call(e, n);
21
- } catch (l) {
22
- throw new a({ typeId: e, code: -1, message: "RPC transport error", cause: l });
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: e,
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 (e, n) => {
33
- const t = c.client();
34
- if (t)
35
- try {
36
- await t.rpc.notify(e, n);
37
- } catch (r) {
38
- throw new a({ typeId: e, code: -1, message: "RPC notify transport error", cause: r });
39
- }
40
- }, onNotify: (e, n) => {
41
- const t = c.client();
42
- return t ? t.rpc.onNotify(e, (r) => {
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 y(c) {
49
- const o = u(), i = c?.contract ?? o.contract(), s = d(o), e = i.createRpc(s);
50
- return Object.assign(e, s);
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
- p as ProtocolNotConnectedError,
49
+ f as ProtocolNotConnectedError,
54
50
  a as RpcError,
55
- y as useRpc
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.33.11",
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.14.1"
33
+ "@floegence/flowersec-core": "^0.15.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "solid-js": "^1.9.11",