@calimero-network/mero-js 24.6.0 → 24.7.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.
@@ -82,6 +82,13 @@ export interface RelayTransportConfig {
82
82
  * would have that caller take the client apart to put it back together.
83
83
  */
84
84
  relay: RelayClient | RelayClientConfig;
85
+ /**
86
+ * Fetch for everything this client sends the relay: intents (unless `relay`
87
+ * names its own), admin reads, the observing login and events. Typically a
88
+ * sealed fetch (`createAttestedSealedFetch`), so none of it can be read where
89
+ * TLS ends. Defaults to global `fetch`.
90
+ */
91
+ fetch?: typeof fetch;
85
92
  /**
86
93
  * A session on the relay, if this client has one.
87
94
  *
@@ -156,6 +163,8 @@ export declare class MeroClient {
156
163
  private readonly proofAuthorizer;
157
164
  private readonly relayUrl;
158
165
  private proofEvents;
166
+ /** The relay transport's `fetch`, if one was given. */
167
+ private readonly relayFetch;
159
168
  private relayPresence;
160
169
  constructor(config: MeroClientConfig);
161
170
  /**
@@ -88,7 +88,7 @@ function missingNodeKey(surface) {
88
88
  * authors is the device that observes, and taking a second copy from the caller
89
89
  * is how the two come to name different keys.
90
90
  */
91
- function buildObserver(relay, observe) {
91
+ function buildObserver(relay, observe, fetchImpl) {
92
92
  const nodeKey = observe?.nodeKey;
93
93
  if (!nodeKey)
94
94
  return null;
@@ -100,7 +100,7 @@ function buildObserver(relay, observe) {
100
100
  signer: observe?.signer ? async () => observe.signer : () => relay.authorSigner(),
101
101
  clientName: observe?.clientName,
102
102
  ttlSeconds: observe?.ttlSeconds,
103
- fetch: observe?.fetch,
103
+ fetch: observe?.fetch ?? fetchImpl,
104
104
  timeoutMs: observe?.timeoutMs,
105
105
  });
106
106
  }
@@ -128,12 +128,18 @@ export class MeroClient {
128
128
  this.proofAuthorizer = null;
129
129
  this.relayUrl = null;
130
130
  this.proofEvents = null;
131
+ /** The relay transport's `fetch`, if one was given. */
132
+ this.relayFetch = undefined;
131
133
  this.relayPresence = null;
132
134
  if (config.transport === 'relay') {
133
135
  this.transport = 'relay';
134
136
  this.nodeClient = null;
135
- const relay = config.relay instanceof RelayClient ? config.relay : new RelayClient(config.relay);
136
- this.relayObserver = buildObserver(relay, config.observe);
137
+ const fetchImpl = config.fetch;
138
+ this.relayFetch = fetchImpl;
139
+ const relay = config.relay instanceof RelayClient
140
+ ? config.relay
141
+ : new RelayClient({ ...config.relay, fetch: config.relay.fetch ?? fetchImpl });
142
+ this.relayObserver = buildObserver(relay, config.observe, fetchImpl);
137
143
  this.rpcTransport = new RelayTransport(relay, this.relayObserver);
138
144
  this.relayUrl = relay.relayUrl;
139
145
  if (config.proof) {
@@ -150,12 +156,13 @@ export class MeroClient {
150
156
  this.relayAdmin = createAdminApiClient({
151
157
  baseUrl: relay.relayUrl,
152
158
  getAuthToken: typeof token === 'string' ? async () => token : token,
159
+ fetch: fetchImpl,
153
160
  });
154
161
  }
155
162
  else if (this.proofAuthorizer) {
156
163
  const authorizeRequest = this.proofAuthorizer;
157
164
  this.relayAdmin = createAdminApiClientFromHttpClient(createHttpClient({
158
- fetch: (url, init) => globalThis.fetch(url, init),
165
+ fetch: (url, init) => fetchImpl ? fetchImpl(url, init) : globalThis.fetch(url, init),
159
166
  baseUrl: relay.relayUrl,
160
167
  authorizeRequest,
161
168
  }), { baseUrl: relay.relayUrl });
@@ -281,6 +288,7 @@ export class MeroClient {
281
288
  this.proofEvents ?? (this.proofEvents = new SseClient({
282
289
  baseUrl: this.relayUrl,
283
290
  authorize: this.proofAuthorizer,
291
+ fetch: this.relayFetch,
284
292
  }));
285
293
  return this.proofEvents;
286
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "24.6.0",
3
+ "version": "24.7.0",
4
4
  "description": "Pure JavaScript SDK for Calimero",
5
5
  "type": "module",
6
6
  "exports": {