@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.cjs CHANGED
@@ -517,9 +517,9 @@ function createHttpClient(transport) {
517
517
  }
518
518
  function createBrowserHttpClient(options) {
519
519
  const transport = {
520
- // Wrap fetch in arrow function to prevent "Illegal invocation" error
521
- // This preserves the correct 'this' context when fetch is called
522
- fetch: (url, init) => globalThis.fetch(url, init),
520
+ // globalThis.fetch must be called as a method on globalThis, not through a
521
+ // variable, or browsers throw "Illegal invocation".
522
+ fetch: (url, init) => options.fetch ? options.fetch(url, init) : globalThis.fetch(url, init),
523
523
  baseUrl: options.baseUrl,
524
524
  getAuthToken: options.getAuthToken,
525
525
  getProof: options.getProof,
@@ -2285,6 +2285,7 @@ var SseClient = class {
2285
2285
  this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
2286
2286
  this.getAuthToken = opts.getAuthToken;
2287
2287
  this.reconnectDelayMs = opts.reconnectDelayMs ?? 3e3;
2288
+ this.fetchImpl = (url, init) => opts.fetch ? opts.fetch(url, init) : globalThis.fetch(url, init);
2288
2289
  }
2289
2290
  on(event, handler) {
2290
2291
  const key = event;
@@ -2351,7 +2352,7 @@ var SseClient = class {
2351
2352
  try {
2352
2353
  const token = await this.getAuthToken();
2353
2354
  const url = `${this.baseUrl}/sse`;
2354
- const response = await fetch(url, {
2355
+ const response = await this.fetchImpl(url, {
2355
2356
  headers: {
2356
2357
  "Authorization": `Bearer ${token}`,
2357
2358
  "Accept": "text/event-stream"
@@ -2510,7 +2511,7 @@ var SseClient = class {
2510
2511
  const params = {};
2511
2512
  if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
2512
2513
  if (ids.groupIds && ids.groupIds.length > 0) params.groupIds = ids.groupIds;
2513
- const response = await fetch(`${this.baseUrl}/sse/subscription`, {
2514
+ const response = await this.fetchImpl(`${this.baseUrl}/sse/subscription`, {
2514
2515
  method: "POST",
2515
2516
  headers: {
2516
2517
  "Authorization": `Bearer ${token}`,
@@ -5881,6 +5882,7 @@ var MeroJs = class {
5881
5882
  const getProof = resolveProofSigner(this.config.requestProof);
5882
5883
  this.httpClient = createBrowserHttpClient({
5883
5884
  baseUrl: this.config.baseUrl,
5885
+ fetch: this.config.fetch,
5884
5886
  getProof,
5885
5887
  getAuthToken: async () => {
5886
5888
  const token = await this.getValidToken();
@@ -5951,6 +5953,7 @@ var MeroJs = class {
5951
5953
  if (!this.sseClient) {
5952
5954
  this.sseClient = new SseClient({
5953
5955
  baseUrl: this.config.baseUrl,
5956
+ fetch: this.config.fetch,
5954
5957
  getAuthToken: async () => {
5955
5958
  const token = await this.getValidToken();
5956
5959
  return token?.access_token || "";