@floegence/floe-webapp-protocol 0.40.3 → 0.40.5

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,23 +1,23 @@
1
1
  import { type JSX } from 'solid-js';
2
- import type { Client } from '@floegence/flowersec-core';
3
- import { type BrowserReconnectConfig } from '@floegence/flowersec-core/browser';
4
- import { type AutoReconnectConfig, type ConnectionStatus } from '@floegence/flowersec-core/reconnect';
5
- import type { ProtocolContract, RpcClientLike } from './contract';
2
+ import { type ArtifactSource, type ConnectionControllerOptions, type ConnectionState, type Session } from '@floegence/flowersec-core';
3
+ import type { ProtocolContract } from './contract';
6
4
  interface ProtocolContextValue {
7
- status: () => ConnectionStatus;
5
+ status: () => ConnectionState;
8
6
  error: () => Error | null;
9
- client: () => Client | null;
10
- rpcTransport: () => RpcClientLike;
7
+ session: () => Session | null;
8
+ rpcTransport: () => Session['rpc'] | null;
11
9
  contract: () => ProtocolContract;
12
10
  connect: (config: ConnectConfig) => Promise<void>;
13
- /** Force a hard reconnect (disconnect old client and build a new one). */
14
11
  reconnect: (config?: ConnectConfig) => Promise<void>;
15
12
  disconnect: () => void;
16
13
  }
17
- export type { AutoReconnectConfig, ConnectionStatus };
18
- export type ConnectConfig = BrowserReconnectConfig;
14
+ export type ConnectConfig = Readonly<{
15
+ source: ArtifactSource;
16
+ controller?: ConnectionControllerOptions;
17
+ }>;
19
18
  export declare function ProtocolProvider(props: {
20
19
  children: JSX.Element;
21
20
  contract: ProtocolContract;
22
21
  }): JSX.Element;
23
22
  export declare function useProtocol(): ProtocolContextValue;
23
+ export {};
@@ -1,2 +1,20 @@
1
- export { type RequestConnectArtifactInput, type RequestEntryConnectArtifactInput, ControlplaneRequestError, requestConnectArtifact, requestEntryConnectArtifact, } from '@floegence/flowersec-core/controlplane';
2
- export { type ConnectArtifact, assertConnectArtifact, } from '@floegence/flowersec-core/browser';
1
+ import { type Artifact, type JsonObject } from '@floegence/flowersec-core';
2
+ export type RequestConnectArtifactInput = Readonly<{
3
+ baseUrl: string;
4
+ endpointId: string;
5
+ payload?: JsonObject;
6
+ correlation?: Readonly<{
7
+ traceId?: string;
8
+ }>;
9
+ fetch?: typeof globalThis.fetch;
10
+ }>;
11
+ export type RequestEntryConnectArtifactInput = RequestConnectArtifactInput & Readonly<{
12
+ entryTicket: string;
13
+ }>;
14
+ export declare class ControlplaneRequestError extends Error {
15
+ readonly status: number;
16
+ readonly code: string;
17
+ constructor(status: number, code: string, message: string);
18
+ }
19
+ export declare function requestConnectArtifact(input: RequestConnectArtifactInput): Promise<Artifact>;
20
+ export declare function requestEntryConnectArtifact(input: RequestEntryConnectArtifactInput): Promise<Artifact>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ProtocolProvider, useProtocol, type ConnectionStatus, type ConnectConfig, type AutoReconnectConfig } from './client';
1
+ export { ProtocolProvider, useProtocol, type ConnectConfig } from './client';
2
2
  export { useRpc, RpcError, ProtocolNotConnectedError } from './rpc';
3
- export { assertConnectArtifact, ControlplaneRequestError, requestConnectArtifact, requestEntryConnectArtifact, type ConnectArtifact, type RequestConnectArtifactInput, type RequestEntryConnectArtifactInput, } from './controlplane';
3
+ export { ControlplaneRequestError, requestConnectArtifact, requestEntryConnectArtifact, type RequestConnectArtifactInput, type RequestEntryConnectArtifactInput, } from './controlplane';
4
4
  export type { ProtocolContract, RpcClientLike, RpcHelpers } from './contract';
package/dist/index.js CHANGED
@@ -1,15 +1,13 @@
1
1
  import { ProtocolProvider as t, useProtocol as e } from "./index2.js";
2
- import { ProtocolNotConnectedError as n, RpcError as f, useRpc as p } from "./index3.js";
3
- import { ControlplaneRequestError as a, requestConnectArtifact as l, requestEntryConnectArtifact as u } from "@floegence/flowersec-core/controlplane";
4
- import { assertConnectArtifact as i } from "@floegence/flowersec-core/browser";
2
+ import { ProtocolNotConnectedError as n, RpcError as p, useRpc as f } from "./index3.js";
3
+ import { ControlplaneRequestError as s, requestConnectArtifact as u, requestEntryConnectArtifact as C } from "./index4.js";
5
4
  export {
6
- a as ControlplaneRequestError,
5
+ s as ControlplaneRequestError,
7
6
  n as ProtocolNotConnectedError,
8
7
  t as ProtocolProvider,
9
- f as RpcError,
10
- i as assertConnectArtifact,
11
- l as requestConnectArtifact,
12
- u as requestEntryConnectArtifact,
8
+ p as RpcError,
9
+ u as requestConnectArtifact,
10
+ C as requestEntryConnectArtifact,
13
11
  e as useProtocol,
14
- p as useRpc
12
+ f as useRpc
15
13
  };
package/dist/index2.js CHANGED
@@ -1,83 +1,67 @@
1
- import { createContext as P, onCleanup as C, createComponent as x, useContext as b } from "solid-js";
2
- import { createStore as v } from "solid-js/store";
3
- import { createBrowserReconnectConfig as A } from "@floegence/flowersec-core/browser";
4
- import { RpcProxy as N } from "@floegence/flowersec-core/rpc";
5
- import { createReconnectManager as R } from "@floegence/flowersec-core/reconnect";
6
- const h = P();
7
- function W(o) {
8
- const r = R(), s = r.state(), [a, p] = v({
9
- status: s.status,
10
- error: s.error,
11
- client: s.client
12
- }), m = o.contract, c = new N(), w = {
13
- rpc: {
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
- }
18
- };
19
- s.client && c.attach(s.client.rpc);
20
- const y = r.subscribe((t) => {
21
- t.client ? c.attach(t.client.rpc) : c.detach(), p({
22
- status: t.status,
23
- error: t.error,
24
- client: t.client
1
+ import { createContext as C, onCleanup as v, createComponent as P, useContext as b } from "solid-js";
2
+ import { createStore as h } from "solid-js/store";
3
+ import "@floegence/flowersec-core";
4
+ import { createConnectionController as y } from "@floegence/flowersec-core/browser";
5
+ const f = C();
6
+ function T(o) {
7
+ const [s, i] = h({
8
+ status: "idle",
9
+ error: null,
10
+ session: null
11
+ }), d = o.contract;
12
+ let e = null, c = null, l = null, n = null;
13
+ const w = (t) => {
14
+ const r = t.failure;
15
+ i({
16
+ status: t.state,
17
+ session: t.currentSession ?? null,
18
+ error: r === void 0 ? null : new Error(`${r.phase}:${r.code}`)
25
19
  });
26
- });
27
- let l = null, u = null, e = null;
28
- const f = (t) => ((l !== t || u === null) && (l = t, u = A(t)), u), d = async (t, n) => {
29
- if (n === "hard") {
30
- await r.connect(t);
31
- return;
32
- }
33
- await r.connectIfNeeded(t);
34
- }, g = {
35
- status: () => a.status,
36
- error: () => a.error,
37
- client: () => a.client,
38
- rpcTransport: () => w,
39
- contract: () => m,
40
- connect: async (t) => {
41
- const n = f(t), i = r.state();
42
- if (!(i.status === "connected" && i.client) && !(i.status === "connecting" && !e)) {
43
- if (e) {
44
- await e;
45
- return;
46
- }
47
- e = d(n, "if_needed").finally(() => {
48
- e = null;
49
- }), await e;
50
- }
51
- },
20
+ }, u = async () => {
21
+ c?.(), c = null;
22
+ const t = e;
23
+ e = null, t && await t.close(), i({
24
+ status: "idle",
25
+ session: null,
26
+ error: null
27
+ });
28
+ }, m = async (t) => {
29
+ await u(), l = t, e = y(t.source, t.controller), c = e.subscribe(w), e.start(), await e.waitForSession();
30
+ }, a = async (t) => n || (n = (async () => {
31
+ e && l?.source === t.source && e.state === "connected" || await m(t);
32
+ })().finally(() => {
33
+ n = null;
34
+ }), n), p = {
35
+ status: () => s.status,
36
+ error: () => s.error,
37
+ session: () => s.session,
38
+ rpcTransport: () => s.session?.rpc ?? null,
39
+ contract: () => d,
40
+ connect: a,
52
41
  reconnect: async (t) => {
53
- const n = t ?? l;
54
- if (!n)
55
- throw new Error("reconnect() requires a config before the first connect() call");
56
- const i = f(n);
57
- return e || (e = d(i, "hard").finally(() => {
58
- e = null;
59
- }), e);
42
+ const r = t ?? l;
43
+ if (!r) throw new Error("reconnect() requires a config before the first connect() call");
44
+ await a(r);
60
45
  },
61
46
  disconnect: () => {
62
- c.detach(), r.disconnect();
47
+ u();
63
48
  }
64
49
  };
65
- return C(() => {
66
- y(), c.detach(), r.disconnect();
67
- }), x(h.Provider, {
68
- value: g,
50
+ return v(() => {
51
+ c?.(), e?.close();
52
+ }), P(f.Provider, {
53
+ value: p,
69
54
  get children() {
70
55
  return o.children;
71
56
  }
72
57
  });
73
58
  }
74
- function _() {
75
- const o = b(h);
76
- if (!o)
77
- throw new Error("useProtocol must be used within a ProtocolProvider");
59
+ function g() {
60
+ const o = b(f);
61
+ if (!o) throw new Error("useProtocol must be used within a ProtocolProvider");
78
62
  return o;
79
63
  }
80
64
  export {
81
- W as ProtocolProvider,
82
- _ as useProtocol
65
+ T as ProtocolProvider,
66
+ g as useProtocol
83
67
  };
package/dist/index3.js CHANGED
@@ -1,6 +1,5 @@
1
- import { useProtocol as y } from "./index2.js";
2
- import { RpcProxyDetachedError as d } from "@floegence/flowersec-core/rpc";
3
- class u extends Error {
1
+ import { useProtocol as u } from "./index2.js";
2
+ class d extends Error {
4
3
  constructor() {
5
4
  super("Not connected"), this.name = "ProtocolNotConnectedError";
6
5
  }
@@ -8,53 +7,58 @@ class u extends Error {
8
7
  class p extends Error {
9
8
  typeId;
10
9
  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;
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;
13
12
  }
14
13
  }
15
- function h(c) {
16
- const t = async (r, e) => {
17
- const a = c.rpcTransport();
18
- let o;
14
+ function y(c) {
15
+ const o = async (r, e) => {
16
+ const n = c.rpcTransport();
17
+ if (!n) throw new d();
18
+ let t;
19
19
  try {
20
- o = await a.rpc.call(r, e);
21
- } catch (n) {
22
- throw n instanceof d ? new u() : new p({ typeId: r, code: -1, message: "RPC transport error", cause: n });
20
+ t = await n.call(r, e, (s) => s);
21
+ } catch (s) {
22
+ throw new p({ typeId: r, code: -1, message: "RPC transport error", cause: s });
23
23
  }
24
- if (o.error)
24
+ if (!t.ok)
25
25
  throw new p({
26
26
  typeId: r,
27
- code: o.error.code,
28
- message: o.error.message ?? `RPC error: ${o.error.code}`,
29
- cause: o.error
27
+ code: t.error.code,
28
+ message: t.error.message ?? `RPC error: ${t.error.code}`,
29
+ cause: t.error
30
30
  });
31
- return o.payload;
32
- }, s = async (r, e, a) => {
33
- const o = c.rpcTransport();
31
+ return t.payload;
32
+ }, a = async (r, e, n) => {
33
+ const t = c.rpcTransport();
34
+ if (!t) {
35
+ if (n.detached === "ignore") return;
36
+ throw new d();
37
+ }
34
38
  try {
35
- await o.rpc.notify(r, e);
36
- } catch (n) {
37
- if (n instanceof d) {
38
- if (a.detached === "ignore") return;
39
- throw new u();
40
- }
41
- throw new p({ typeId: r, code: -1, message: "RPC notify transport error", cause: n });
39
+ await t.notify(r, e);
40
+ } catch (s) {
41
+ throw new p({ typeId: r, code: -1, message: "RPC notify transport error", cause: s });
42
42
  }
43
43
  };
44
- return { call: t, notify: async (r, e) => {
45
- await s(r, e, { detached: "throw" });
44
+ return { call: o, notify: async (r, e) => {
45
+ await a(r, e, { detached: "throw" });
46
46
  }, notifyBestEffort: async (r, e) => {
47
- await s(r, e, { detached: "ignore" });
48
- }, onNotify: (r, e) => c.rpcTransport().rpc.onNotify(r, (o) => {
49
- e(o);
50
- }) };
47
+ await a(r, e, { detached: "ignore" });
48
+ }, onNotify: (r, e) => {
49
+ const n = c.rpcTransport();
50
+ return n ? n.onNotify(r, (t) => {
51
+ e(t);
52
+ }) : () => {
53
+ };
54
+ } };
51
55
  }
52
- function E(c) {
53
- const t = y(), s = c?.contract ?? t.contract(), i = h(t), f = s.createRpc(i);
56
+ function l(c) {
57
+ const o = u(), a = c?.contract ?? o.contract(), i = y(o), f = a.createRpc(i);
54
58
  return Object.assign(f, i);
55
59
  }
56
60
  export {
57
- u as ProtocolNotConnectedError,
61
+ d as ProtocolNotConnectedError,
58
62
  p as RpcError,
59
- E as useRpc
63
+ l as useRpc
60
64
  };
package/dist/index4.js ADDED
@@ -0,0 +1,42 @@
1
+ import { parseArtifact as f } from "@floegence/flowersec-core";
2
+ class a extends Error {
3
+ constructor(c, o, e) {
4
+ super(e), this.status = c, this.code = o, this.name = "ControlplaneRequestError";
5
+ }
6
+ }
7
+ async function i(t) {
8
+ const c = t.fetch ?? globalThis.fetch, o = new URL(t.baseUrl);
9
+ if (o.protocol !== "https:") throw new a(0, "transport_policy_denied", "controlplane transport policy denied");
10
+ const e = "entryTicket" in t, s = new URL(`/v1/connect/artifact${e ? "/entry" : ""}`, o).toString(), l = {
11
+ endpoint_id: t.endpointId,
12
+ ...t.payload === void 0 ? {} : { payload: t.payload },
13
+ ...!e && t.correlation === void 0 ? {} : e ? {} : { correlation: { trace_id: t.correlation?.traceId } }
14
+ }, r = await c(s, {
15
+ method: "POST",
16
+ headers: {
17
+ accept: "application/json",
18
+ "content-type": "application/json",
19
+ ...e ? { authorization: `Bearer ${t.entryTicket}` } : {}
20
+ },
21
+ body: JSON.stringify(l),
22
+ credentials: "omit",
23
+ redirect: "error"
24
+ });
25
+ if (!r.ok) throw new a(r.status, "request_failed", `controlplane request failed: ${r.status}`);
26
+ const n = await r.json();
27
+ if (n.connect_artifact === void 0)
28
+ throw new a(200, "invalid_request", "Invalid controlplane response: missing `connect_artifact`");
29
+ const d = typeof n.connect_artifact == "string" || n.connect_artifact instanceof Uint8Array ? n.connect_artifact : JSON.stringify(n.connect_artifact);
30
+ return f(d);
31
+ }
32
+ function y(t) {
33
+ return i(t);
34
+ }
35
+ function h(t) {
36
+ return i(t);
37
+ }
38
+ export {
39
+ a as ControlplaneRequestError,
40
+ y as requestConnectArtifact,
41
+ h as requestEntryConnectArtifact
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-protocol",
3
- "version": "0.40.3",
3
+ "version": "0.40.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "solid-js": "^1.8.0"
34
34
  },
35
35
  "dependencies": {
36
- "@floegence/flowersec-core": "^0.27.0"
36
+ "@floegence/flowersec-core": "2.0.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "solid-js": "^1.9.11",