@calimero-network/mero-js 13.0.0 → 13.1.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/ephemeral/codec.d.ts +4 -0
- package/dist/ephemeral/codec.js +12 -0
- package/dist/ephemeral/index.d.ts +51 -0
- package/dist/ephemeral/index.js +81 -0
- package/dist/ephemeral/types.d.ts +22 -0
- package/dist/ephemeral/types.js +1 -0
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +104 -23
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +104 -23
- package/dist/index.mjs.map +3 -3
- package/dist/mero-js.d.ts +9 -0
- package/dist/mero-js.js +16 -0
- package/dist/rpc/index.d.ts +8 -0
- package/dist/rpc/index.js +28 -20
- package/package.json +1 -1
package/dist/mero-js.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { AuthCallbackResult, AuthLoginOptions } from './auth/index.js';
|
|
|
5
5
|
import { RpcClient } from './rpc/index.js';
|
|
6
6
|
import { SseClient } from './events/sse.js';
|
|
7
7
|
import { WsClient } from './events/ws.js';
|
|
8
|
+
import { EphemeralClient } from './ephemeral/index.js';
|
|
8
9
|
export interface MeroJsConfig {
|
|
9
10
|
/** Base URL for the Calimero node */
|
|
10
11
|
baseUrl: string;
|
|
@@ -48,6 +49,7 @@ export declare class MeroJs {
|
|
|
48
49
|
private sseClient;
|
|
49
50
|
private wsClient;
|
|
50
51
|
private wsWarned;
|
|
52
|
+
private ephemeralClient?;
|
|
51
53
|
constructor(config: MeroJsConfig);
|
|
52
54
|
/**
|
|
53
55
|
* Get the Auth API client
|
|
@@ -65,6 +67,13 @@ export declare class MeroJs {
|
|
|
65
67
|
* Get the SSE event client (lazy initialized)
|
|
66
68
|
*/
|
|
67
69
|
get events(): SseClient;
|
|
70
|
+
/**
|
|
71
|
+
* Get the ephemeral-presence client (lazy initialized).
|
|
72
|
+
*
|
|
73
|
+
* Shares this instance's SSE client, so `subscribe` reuses the one event
|
|
74
|
+
* stream rather than opening a second connection.
|
|
75
|
+
*/
|
|
76
|
+
get ephemeral(): EphemeralClient;
|
|
68
77
|
/**
|
|
69
78
|
* Get the WebSocket event client (lazy initialized).
|
|
70
79
|
* @experimental Use `events` (SSE) for production. WsClient is experimental.
|
package/dist/mero-js.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
|
|
|
5
5
|
import { RpcClient } from './rpc/index.js';
|
|
6
6
|
import { SseClient } from './events/sse.js';
|
|
7
7
|
import { WsClient } from './events/ws.js';
|
|
8
|
+
import { EphemeralClient } from './ephemeral/index.js';
|
|
8
9
|
/** Name of the Web Lock that serializes token refresh across tabs / webviews. */
|
|
9
10
|
const REFRESH_LOCK_NAME = 'mero-js:token-refresh';
|
|
10
11
|
/** Returns `navigator.locks` when the runtime supports the Web Locks API. */
|
|
@@ -141,6 +142,21 @@ export class MeroJs {
|
|
|
141
142
|
}
|
|
142
143
|
return this.sseClient;
|
|
143
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the ephemeral-presence client (lazy initialized).
|
|
147
|
+
*
|
|
148
|
+
* Shares this instance's SSE client, so `subscribe` reuses the one event
|
|
149
|
+
* stream rather than opening a second connection.
|
|
150
|
+
*/
|
|
151
|
+
get ephemeral() {
|
|
152
|
+
if (!this.ephemeralClient) {
|
|
153
|
+
this.ephemeralClient = new EphemeralClient({
|
|
154
|
+
httpClient: this.httpClient,
|
|
155
|
+
sse: this.events,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return this.ephemeralClient;
|
|
159
|
+
}
|
|
144
160
|
/**
|
|
145
161
|
* Get the WebSocket event client (lazy initialized).
|
|
146
162
|
* @experimental Use `events` (SSE) for production. WsClient is experimental.
|
package/dist/rpc/index.d.ts
CHANGED
|
@@ -17,6 +17,14 @@ export declare class RpcError extends Error {
|
|
|
17
17
|
data?: unknown;
|
|
18
18
|
constructor(code: number, message: string, data?: unknown, type?: string);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* POST a JSON-RPC call and unwrap `result`, converting an `error` payload into
|
|
22
|
+
* an `RpcError`. The node returns `{ type, data }` (not always `{ code,
|
|
23
|
+
* message }`), so this is the one place that normalization lives — every
|
|
24
|
+
* JSON-RPC caller in this SDK shares it rather than re-deriving a bare
|
|
25
|
+
* `Error(message)` and dropping the typed detail.
|
|
26
|
+
*/
|
|
27
|
+
export declare function jsonRpcCall<T>(httpClient: HttpClient, method: string, params: unknown): Promise<T>;
|
|
20
28
|
export declare class RpcClient {
|
|
21
29
|
private httpClient;
|
|
22
30
|
constructor(opts: {
|
package/dist/rpc/index.js
CHANGED
|
@@ -7,32 +7,40 @@ export class RpcError extends Error {
|
|
|
7
7
|
this.type = type;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* POST a JSON-RPC call and unwrap `result`, converting an `error` payload into
|
|
12
|
+
* an `RpcError`. The node returns `{ type, data }` (not always `{ code,
|
|
13
|
+
* message }`), so this is the one place that normalization lives — every
|
|
14
|
+
* JSON-RPC caller in this SDK shares it rather than re-deriving a bare
|
|
15
|
+
* `Error(message)` and dropping the typed detail.
|
|
16
|
+
*/
|
|
17
|
+
export async function jsonRpcCall(httpClient, method, params) {
|
|
18
|
+
const response = await httpClient.post('/jsonrpc', {
|
|
19
|
+
jsonrpc: '2.0',
|
|
20
|
+
id: 1,
|
|
21
|
+
method,
|
|
22
|
+
params,
|
|
23
|
+
});
|
|
24
|
+
if (response.error) {
|
|
25
|
+
const err = response.error;
|
|
26
|
+
throw new RpcError(err.code ?? -1, err.message ?? err.type ?? 'RPC error', err.data, err.type);
|
|
27
|
+
}
|
|
28
|
+
return response.result;
|
|
29
|
+
}
|
|
10
30
|
export class RpcClient {
|
|
11
31
|
constructor(opts) {
|
|
12
32
|
this.httpClient = opts.httpClient;
|
|
13
33
|
}
|
|
14
34
|
async execute(params) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
argsJson: params.argsJson ?? {},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
const response = await this.httpClient.post('/jsonrpc', body);
|
|
26
|
-
if (response.error) {
|
|
27
|
-
const err = response.error;
|
|
28
|
-
const code = err.code ?? -1;
|
|
29
|
-
const message = err.message ?? err.type ?? 'RPC error';
|
|
30
|
-
throw new RpcError(code, message, err.data, err.type);
|
|
31
|
-
}
|
|
32
|
-
if (response.result && 'output' in response.result) {
|
|
33
|
-
return response.result.output;
|
|
35
|
+
const result = await jsonRpcCall(this.httpClient, 'execute', {
|
|
36
|
+
contextId: params.contextId,
|
|
37
|
+
method: params.method,
|
|
38
|
+
argsJson: params.argsJson ?? {},
|
|
39
|
+
});
|
|
40
|
+
if (result && 'output' in result) {
|
|
41
|
+
return result.output;
|
|
34
42
|
}
|
|
35
|
-
return
|
|
43
|
+
return result;
|
|
36
44
|
}
|
|
37
45
|
/**
|
|
38
46
|
* One-tap owner-driven convert: re-signs the caller's identity-gated entries
|