@floegence/floe-webapp-protocol 0.40.4 → 0.40.6
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 +10 -10
- package/dist/controlplane.d.ts +20 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -9
- package/dist/index2.js +52 -68
- package/dist/index3.js +40 -36
- package/dist/index4.js +42 -0
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { type JSX } from 'solid-js';
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
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: () =>
|
|
5
|
+
status: () => ConnectionState;
|
|
8
6
|
error: () => Error | null;
|
|
9
|
-
|
|
10
|
-
rpcTransport: () =>
|
|
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
|
|
18
|
-
|
|
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 {};
|
package/dist/controlplane.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
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
|
|
1
|
+
export { ProtocolProvider, useProtocol, type ConnectConfig } from './client';
|
|
2
2
|
export { useRpc, RpcError, ProtocolNotConnectedError } from './rpc';
|
|
3
|
-
export {
|
|
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
|
|
3
|
-
import { ControlplaneRequestError as
|
|
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
|
-
|
|
5
|
+
s as ControlplaneRequestError,
|
|
7
6
|
n as ProtocolNotConnectedError,
|
|
8
7
|
t as ProtocolProvider,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
u as requestEntryConnectArtifact,
|
|
8
|
+
p as RpcError,
|
|
9
|
+
u as requestConnectArtifact,
|
|
10
|
+
C as requestEntryConnectArtifact,
|
|
13
11
|
e as useProtocol,
|
|
14
|
-
|
|
12
|
+
f as useRpc
|
|
15
13
|
};
|
package/dist/index2.js
CHANGED
|
@@ -1,83 +1,67 @@
|
|
|
1
|
-
import { createContext as
|
|
2
|
-
import { createStore as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
54
|
-
if (!
|
|
55
|
-
|
|
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
|
-
|
|
47
|
+
u();
|
|
63
48
|
}
|
|
64
49
|
};
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
}),
|
|
68
|
-
value:
|
|
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(
|
|
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
|
-
|
|
82
|
-
|
|
65
|
+
T as ProtocolProvider,
|
|
66
|
+
g as useProtocol
|
|
83
67
|
};
|
package/dist/index3.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useProtocol as
|
|
2
|
-
|
|
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(
|
|
12
|
-
super(
|
|
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
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
} catch (
|
|
22
|
-
throw
|
|
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 (
|
|
24
|
+
if (!t.ok)
|
|
25
25
|
throw new p({
|
|
26
26
|
typeId: r,
|
|
27
|
-
code:
|
|
28
|
-
message:
|
|
29
|
-
cause:
|
|
27
|
+
code: t.error.code,
|
|
28
|
+
message: t.error.message ?? `RPC error: ${t.error.code}`,
|
|
29
|
+
cause: t.error
|
|
30
30
|
});
|
|
31
|
-
return
|
|
32
|
-
},
|
|
33
|
-
const
|
|
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
|
|
36
|
-
} catch (
|
|
37
|
-
|
|
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:
|
|
45
|
-
await
|
|
44
|
+
return { call: o, notify: async (r, e) => {
|
|
45
|
+
await a(r, e, { detached: "throw" });
|
|
46
46
|
}, notifyBestEffort: async (r, e) => {
|
|
47
|
-
await
|
|
48
|
-
}, onNotify: (r, e) =>
|
|
49
|
-
|
|
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
|
|
53
|
-
const
|
|
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
|
-
|
|
61
|
+
d as ProtocolNotConnectedError,
|
|
58
62
|
p as RpcError,
|
|
59
|
-
|
|
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
|
+
"version": "0.40.6",
|
|
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": "
|
|
36
|
+
"@floegence/flowersec-core": "2.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"solid-js": "^1.9.11",
|