@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 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 y(a) {
6
- return a != null && a.enabled ? {
5
+ function x(c) {
6
+ return c?.enabled ? {
7
7
  enabled: !0,
8
- maxAttempts: Math.max(1, a.maxAttempts ?? 5),
9
- initialDelayMs: Math.max(0, a.initialDelayMs ?? 500),
10
- maxDelayMs: Math.max(0, a.maxDelayMs ?? 1e4),
11
- factor: Math.max(1, a.factor ?? 1.8),
12
- jitterRatio: Math.max(0, a.jitterRatio ?? 0.2)
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(a, c) {
23
- const i = Math.min(c.maxDelayMs, c.initialDelayMs * Math.pow(c.factor, a)), l = c.jitterRatio <= 0 ? 0 : i * c.jitterRatio * (Math.random() * 2 - 1);
24
- return Math.max(0, Math.round(i + l));
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(a) {
27
- const [c, i] = A({
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, u = null, d = null, m = null;
32
+ let l = 0, i = null, u = null, m = null;
33
33
  const h = () => {
34
- d && (clearTimeout(d), d = null), m == null || m(), m = null;
35
- }, b = (r) => new Promise((e) => {
36
- m = e, d = setTimeout(() => {
37
- d = null, m = null, e();
38
- }, r);
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(), u = null, l += 1, c.client && c.client.close(), i({
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
- }, w = (r, e, t) => {
46
- if (r !== l || u !== e || c.status !== "connected") return;
47
- if (!y(e.autoReconnect).enabled) {
48
- i({
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: t,
50
+ error: r,
51
51
  client: null
52
52
  });
53
53
  return;
54
54
  }
55
55
  h(), l += 1;
56
- const n = l;
57
- i({
56
+ const o = l;
57
+ s({
58
58
  status: "connecting",
59
- error: t,
59
+ error: r,
60
60
  client: null
61
- }), x(n, e).catch(() => {
61
+ }), w(o, t).catch(() => {
62
62
  });
63
- }, C = (r, e) => {
64
- const t = e.observer;
63
+ }, b = (n, t) => {
64
+ const r = t.observer;
65
65
  return {
66
- onConnect: (...o) => {
67
- var n;
68
- return (n = t == null ? void 0 : t.onConnect) == null ? void 0 : n.call(t, ...o);
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
- onAttach: (...o) => {
71
- var n;
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
- onHandshake: (...o) => {
75
- var n;
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
- }, f = async (r, e) => {
78
+ }, v = async (n, t) => {
96
79
  const {
97
- connectTunnelBrowser: t,
98
- connectDirectBrowser: o
99
- } = await import("@floegence/flowersec-core/browser"), n = {
100
- observer: C(r, e),
101
- keepaliveIntervalMs: e.keepaliveIntervalMs ?? 15e3,
102
- connectTimeoutMs: e.connectTimeoutMs ?? 1e4,
103
- handshakeTimeoutMs: e.handshakeTimeoutMs ?? 1e4
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 ((e.mode ?? "tunnel") === "tunnel") {
106
- const p = e.grant ?? (e.controlplane ? await W(e.controlplane) : null);
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 t(p, n);
92
+ return r(p, o);
110
93
  }
111
- if (!e.directInfo)
94
+ if (!t.directInfo)
112
95
  throw new Error("Direct mode requires `directInfo`");
113
- return o(e.directInfo, n);
114
- }, x = async (r, e) => {
115
- const t = y(e.autoReconnect);
116
- let o = 0;
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 (r !== l || u !== e) return;
119
- o += 1;
101
+ if (n !== l || i !== t) return;
102
+ e += 1;
120
103
  try {
121
- const n = await f(r, e);
122
- if (r !== l) {
123
- n.close();
104
+ const o = await v(n, t);
105
+ if (n !== l) {
106
+ o.close();
124
107
  return;
125
108
  }
126
- if (u !== e) {
127
- n.close();
109
+ if (i !== t) {
110
+ o.close();
128
111
  return;
129
112
  }
130
- i({
113
+ s({
131
114
  status: "connected",
132
- client: n,
115
+ client: o,
133
116
  error: null
134
117
  });
135
118
  return;
136
- } catch (n) {
137
- const s = n instanceof Error ? n : new Error(String(n));
138
- if (r !== l || u !== e) return;
139
- if (!(t.enabled && o < t.maxAttempts))
140
- throw i({
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: s,
125
+ error: d,
143
126
  client: null
144
- }), s;
145
- i({
127
+ }), d;
128
+ s({
146
129
  status: "connecting",
147
- error: s,
130
+ error: d,
148
131
  client: null
149
132
  });
150
- const D = j(o - 1, t);
151
- await b(D);
133
+ const D = j(e - 1, r);
134
+ await f(D);
152
135
  }
153
136
  }
154
- }, v = {
155
- status: () => c.status,
156
- error: () => c.error,
157
- client: () => c.client,
158
- connect: async (r) => {
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 e = l;
161
- u = r, c.client && c.client.close(), i({
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 x(e, r);
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: v,
157
+ value: C,
175
158
  get children() {
176
- return a.children;
159
+ return c.children;
177
160
  }
178
161
  });
179
162
  }
180
163
  function N() {
181
- const a = k(R);
182
- if (!a)
164
+ const c = k(R);
165
+ if (!c)
183
166
  throw new Error("useProtocol must be used within a ProtocolProvider");
184
- return a;
167
+ return c;
185
168
  }
186
169
  export {
187
170
  H as ProtocolProvider,
package/dist/index3.js CHANGED
@@ -1,56 +1,52 @@
1
- var i = Object.defineProperty;
2
- var p = (o, e, r) => e in o ? i(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r;
3
- var s = (o, e, r) => p(o, typeof e != "symbol" ? e + "" : e, r);
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 a extends Error {
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 w() {
20
- const o = E(), e = async (r, d) => {
21
- const n = o.client();
22
- if (!n)
23
- throw new u();
24
- let t;
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
- t = await n.rpc.call(r, d);
27
- } catch (l) {
28
- throw new a({ typeId: r, code: -1, message: "RPC transport error", cause: l });
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 (t.error)
31
- throw new a({
32
- typeId: r,
33
- code: t.error.code,
34
- message: t.error.message ?? `RPC error: ${t.error.code}`,
35
- cause: t.error
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 t.payload;
33
+ return o.payload;
38
34
  };
39
35
  return {
40
36
  // File system operations
41
37
  fs: {
42
- list: (r) => e(c.FS_LIST, r),
43
- readFile: (r) => e(c.FS_READ_FILE, r),
44
- writeFile: (r) => e(c.FS_WRITE_FILE, r),
45
- delete: (r) => e(c.FS_DELETE, r),
46
- getHome: () => e(c.FS_GET_HOME, {})
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: e
45
+ call: r
50
46
  };
51
47
  }
52
48
  export {
53
- u as ProtocolNotConnectedError,
54
- a as RpcError,
55
- w as useRpc
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 a(e) {
3
- const t = await fetch(`${e.baseUrl}/v1/channel/init`, {
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: e.endpointId })
6
+ body: JSON.stringify({ endpoint_id: t.endpointId })
7
7
  });
8
- if (!t.ok)
9
- throw new Error(`Failed to get channel grant: ${t.status}`);
10
- const n = await t.json();
11
- if (!(n != null && n.grant_client))
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(n.grant_client);
13
+ return r(e.grant_client);
14
14
  }
15
15
  export {
16
- a as requestChannelGrant
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.8.9",
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.1.0"
27
+ "@floegence/flowersec-core": "^0.7.0"
28
28
  },
29
29
  "devDependencies": {
30
- "solid-js": "^1.9.3",
31
- "typescript": "^5.7.2",
32
- "vite": "^6.0.7",
33
- "vite-plugin-solid": "^2.11.0"
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
  }