@calimero-network/mero-js 19.17.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/index.mjs CHANGED
@@ -420,9 +420,9 @@ function createHttpClient(transport) {
420
420
  }
421
421
  function createBrowserHttpClient(options) {
422
422
  const transport = {
423
- // Wrap fetch in arrow function to prevent "Illegal invocation" error
424
- // This preserves the correct 'this' context when fetch is called
425
- fetch: (url, init) => globalThis.fetch(url, init),
423
+ // globalThis.fetch must be called as a method on globalThis, not through a
424
+ // variable, or browsers throw "Illegal invocation".
425
+ fetch: (url, init) => options.fetch ? options.fetch(url, init) : globalThis.fetch(url, init),
426
426
  baseUrl: options.baseUrl,
427
427
  getAuthToken: options.getAuthToken,
428
428
  getProof: options.getProof,
@@ -2188,6 +2188,7 @@ var SseClient = class {
2188
2188
  this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
2189
2189
  this.getAuthToken = opts.getAuthToken;
2190
2190
  this.reconnectDelayMs = opts.reconnectDelayMs ?? 3e3;
2191
+ this.fetchImpl = (url, init) => opts.fetch ? opts.fetch(url, init) : globalThis.fetch(url, init);
2191
2192
  }
2192
2193
  on(event, handler) {
2193
2194
  const key = event;
@@ -2254,7 +2255,7 @@ var SseClient = class {
2254
2255
  try {
2255
2256
  const token = await this.getAuthToken();
2256
2257
  const url = `${this.baseUrl}/sse`;
2257
- const response = await fetch(url, {
2258
+ const response = await this.fetchImpl(url, {
2258
2259
  headers: {
2259
2260
  "Authorization": `Bearer ${token}`,
2260
2261
  "Accept": "text/event-stream"
@@ -2413,7 +2414,7 @@ var SseClient = class {
2413
2414
  const params = {};
2414
2415
  if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
2415
2416
  if (ids.groupIds && ids.groupIds.length > 0) params.groupIds = ids.groupIds;
2416
- const response = await fetch(`${this.baseUrl}/sse/subscription`, {
2417
+ const response = await this.fetchImpl(`${this.baseUrl}/sse/subscription`, {
2417
2418
  method: "POST",
2418
2419
  headers: {
2419
2420
  "Authorization": `Bearer ${token}`,
@@ -5784,6 +5785,7 @@ var MeroJs = class {
5784
5785
  const getProof = resolveProofSigner(this.config.requestProof);
5785
5786
  this.httpClient = createBrowserHttpClient({
5786
5787
  baseUrl: this.config.baseUrl,
5788
+ fetch: this.config.fetch,
5787
5789
  getProof,
5788
5790
  getAuthToken: async () => {
5789
5791
  const token = await this.getValidToken();
@@ -5854,6 +5856,7 @@ var MeroJs = class {
5854
5856
  if (!this.sseClient) {
5855
5857
  this.sseClient = new SseClient({
5856
5858
  baseUrl: this.config.baseUrl,
5859
+ fetch: this.config.fetch,
5857
5860
  getAuthToken: async () => {
5858
5861
  const token = await this.getValidToken();
5859
5862
  return token?.access_token || "";