@floegence/floe-webapp-protocol 0.35.2 → 0.35.4

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
@@ -1,7 +1,7 @@
1
1
  import { type JSX } from 'solid-js';
2
- import type { ChannelInitGrant, Client, ClientObserverLike, DirectConnectInfo } from '@floegence/flowersec-core';
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 interface ConnectConfig {
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;
@@ -1,13 +1 @@
1
- import { type ChannelInitGrant } from '@floegence/flowersec-core';
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 { ControlplaneRequestError, 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 { ControlplaneRequestError, 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,13 @@
1
1
  import { ProtocolProvider as e, useProtocol as t } from "./index2.js";
2
- import { ProtocolNotConnectedError as n, RpcError as p, useRpc as l } from "./index3.js";
3
- import { requestChannelGrant as f } from "./index4.js";
2
+ import { ProtocolNotConnectedError as l, RpcError as c, useRpc as p } from "./index3.js";
3
+ import { ControlplaneRequestError as s, requestChannelGrant as u, requestEntryChannelGrant as C } from "@floegence/flowersec-core/browser";
4
4
  export {
5
- n as ProtocolNotConnectedError,
5
+ s as ControlplaneRequestError,
6
+ l as ProtocolNotConnectedError,
6
7
  e as ProtocolProvider,
7
- p as RpcError,
8
- f as requestChannelGrant,
8
+ c as RpcError,
9
+ u as requestChannelGrant,
10
+ C as requestEntryChannelGrant,
9
11
  t as useProtocol,
10
- l as useRpc
12
+ p as useRpc
11
13
  };
package/dist/index2.js CHANGED
@@ -1,111 +1,84 @@
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 = {
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, e) => r.call(t, e),
15
- notify: (t, e) => r.notify(t, e),
16
- onNotify: (t, e) => r.onNotify(t, e)
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
- a.client && r.attach(a.client.rpc);
20
- const y = o.subscribe((t) => {
21
- t.client ? r.attach(t.client.rpc) : r.detach(), h({
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 i = null, n = null;
28
- const l = async (t, e) => {
29
- const u = {
30
- autoReconnect: t.autoReconnect,
31
- observer: t.observer,
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 o.connectIfNeeded(u);
62
- }, v = {
34
+ await r.connectIfNeeded(u);
35
+ }, w = {
63
36
  status: () => s.status,
64
37
  error: () => s.error,
65
38
  client: () => s.client,
66
- rpcTransport: () => w,
67
- contract: () => p,
39
+ rpcTransport: () => p,
40
+ contract: () => h,
68
41
  connect: async (t) => {
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;
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
- n = l(t, "if_needed").finally(() => {
77
- n = null;
78
- }), await n;
49
+ e = l(t, "if_needed").finally(() => {
50
+ e = null;
51
+ }), await e;
79
52
  }
80
53
  },
81
54
  reconnect: async (t) => {
82
- const e = t ?? i;
83
- if (!e)
55
+ const n = t ?? a;
56
+ if (!n)
84
57
  throw new Error("reconnect() requires a config before the first connect() call");
85
- return n || (i = e, n = l(e, "hard").finally(() => {
86
- n = null;
87
- }), n);
58
+ return e || (a = n, e = l(n, "hard").finally(() => {
59
+ e = null;
60
+ }), e);
88
61
  },
89
62
  disconnect: () => {
90
- r.detach(), o.disconnect();
63
+ c.detach(), r.disconnect();
91
64
  }
92
65
  };
93
- return x(() => {
94
- y(), r.detach(), o.disconnect();
95
- }), I(m.Provider, {
96
- value: v,
66
+ return P(() => {
67
+ m(), c.detach(), r.disconnect();
68
+ }), g(f.Provider, {
69
+ value: w,
97
70
  get children() {
98
- return c.children;
71
+ return o.children;
99
72
  }
100
73
  });
101
74
  }
102
- function j() {
103
- const c = M(m);
104
- if (!c)
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 c;
79
+ return o;
107
80
  }
108
81
  export {
109
- _ as ProtocolProvider,
110
- j as useProtocol
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.2",
3
+ "version": "0.35.4",
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.1"
33
+ "@floegence/flowersec-core": "^0.16.3"
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
- };