@calimero-network/mero-js 19.16.0 → 19.18.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/mero-js.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { AuthApiClient } from './auth-api/index.js';
2
2
  import type { AdminApiClient } from './admin-api/index.js';
3
3
  import type { TokenStore } from './token-store/index.js';
4
+ import type { ProofRequest, ProofSignerOptions } from './request/index.js';
4
5
  import type { AuthCallbackResult, AuthLoginOptions } from './auth/index.js';
5
6
  import { RpcClient } from './rpc/index.js';
6
7
  import { SseClient } from './events/sse.js';
@@ -20,6 +21,8 @@ export interface MeroJsConfig {
20
21
  timeoutMs?: number;
21
22
  /** Request credentials mode for fetch (omit, same-origin, include) */
22
23
  requestCredentials?: RequestCredentials;
24
+ /** Custom fetch for every HTTP request (`auth`, `admin`, `rpc`, `events`). Defaults to global `fetch`. */
25
+ fetch?: typeof fetch;
23
26
  /** Optional token store for persistence */
24
27
  tokenStore?: TokenStore;
25
28
  /**
@@ -44,6 +47,40 @@ export interface MeroJsConfig {
44
47
  * instead — it returns a connection that can write without one.
45
48
  */
46
49
  cloud?: CloudClientConfig;
50
+ /**
51
+ * Sign every request with a device key, instead of or alongside a session.
52
+ *
53
+ * A session is a bearer token: obtained once, presented many times. A
54
+ * request-carried proof commits to one method, one path and one body, so it
55
+ * is minted per call and cannot be lifted onto another request. It is what
56
+ * lets a client talk to a relay it has no account on — nothing was ever
57
+ * issued to it.
58
+ *
59
+ * Pass the keys and let the SDK mint each proof:
60
+ *
61
+ * ```ts
62
+ * new MeroJs({
63
+ * baseUrl,
64
+ * requestProof: { credential, session, signerSecret },
65
+ * });
66
+ * ```
67
+ *
68
+ * …or pass your own signer, when the key must not reach the SDK at all — a
69
+ * hardware token, or a worker that holds it:
70
+ *
71
+ * ```ts
72
+ * new MeroJs({ baseUrl, requestProof: (req) => myWorker.sign(req) });
73
+ * ```
74
+ *
75
+ * The node only honours this when it runs with `--delegated-access`; a node
76
+ * that does not answers `403`, which is distinct from the `401` a bad proof
77
+ * gets.
78
+ *
79
+ * Applies to the request/response API. `events` (SSE) and `ws` are long-lived
80
+ * connections rather than requests, so a per-request signature does not
81
+ * describe them — they still use the session.
82
+ */
83
+ requestProof?: ProofSignerOptions | ((request: ProofRequest) => Promise<string | undefined>);
47
84
  }
48
85
  export interface TokenData {
49
86
  access_token: string;
package/dist/mero-js.js CHANGED
@@ -2,11 +2,24 @@ import { createBrowserHttpClient } from './http-client/index.js';
2
2
  import { createAuthApiClientFromHttpClient } from './auth-api/index.js';
3
3
  import { createAdminApiClientFromHttpClient } from './admin-api/index.js';
4
4
  import { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
5
+ import { createProofSigner } from './request/index.js';
5
6
  import { RpcClient } from './rpc/index.js';
6
7
  import { SseClient } from './events/sse.js';
7
8
  import { WsClient } from './events/ws.js';
8
9
  import { EphemeralClient } from './ephemeral/index.js';
9
10
  import { CloudClient } from './cloud/cloud-client.js';
11
+ /**
12
+ * Accept either the keys or a ready signer.
13
+ *
14
+ * Taking a callback as well as an options object is not a convenience: it is
15
+ * how a caller keeps the signing key out of the SDK entirely when it lives
16
+ * somewhere the SDK cannot reach.
17
+ */
18
+ function resolveProofSigner(config) {
19
+ if (!config)
20
+ return undefined;
21
+ return typeof config === 'function' ? config : createProofSigner(config);
22
+ }
10
23
  /** Name of the Web Lock that serializes token refresh across tabs / webviews. */
11
24
  const REFRESH_LOCK_NAME = 'mero-js:token-refresh';
12
25
  /** Returns `navigator.locks` when the runtime supports the Web Locks API. */
@@ -58,8 +71,14 @@ export class MeroJs {
58
71
  // Create HTTP client with token management
59
72
  // For Tauri, explicitly set credentials to 'omit' to avoid network errors
60
73
  const isTauri = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
74
+ // One signer for the whole connection: `authClient` and `adminClient` are
75
+ // both built FROM this transport, so wiring it here covers every request
76
+ // either of them makes.
77
+ const getProof = resolveProofSigner(this.config.requestProof);
61
78
  this.httpClient = createBrowserHttpClient({
62
79
  baseUrl: this.config.baseUrl,
80
+ fetch: this.config.fetch,
81
+ getProof,
63
82
  getAuthToken: async () => {
64
83
  const token = await this.getValidToken();
65
84
  return token?.access_token || '';
@@ -135,6 +154,7 @@ export class MeroJs {
135
154
  if (!this.sseClient) {
136
155
  this.sseClient = new SseClient({
137
156
  baseUrl: this.config.baseUrl,
157
+ fetch: this.config.fetch,
138
158
  getAuthToken: async () => {
139
159
  const token = await this.getValidToken();
140
160
  return token?.access_token || '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "19.16.0",
3
+ "version": "19.18.0",
4
4
  "description": "Pure JavaScript SDK for Calimero",
5
5
  "type": "module",
6
6
  "exports": {