@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/events/sse.d.ts +2 -0
- package/dist/events/sse.js +5 -2
- package/dist/http-client/http-factory.d.ts +1 -0
- package/dist/http-client/http-factory.js +3 -3
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +8 -5
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +8 -5
- package/dist/index.mjs.map +2 -2
- package/dist/mero-js.d.ts +2 -0
- package/dist/mero-js.js +2 -0
- package/package.json +1 -1
package/dist/events/sse.d.ts
CHANGED
|
@@ -30,10 +30,12 @@ export declare class SseClient {
|
|
|
30
30
|
private subscribedGroupIds;
|
|
31
31
|
private closed;
|
|
32
32
|
private listeners;
|
|
33
|
+
private fetchImpl;
|
|
33
34
|
constructor(opts: {
|
|
34
35
|
baseUrl: string;
|
|
35
36
|
getAuthToken: () => Promise<string>;
|
|
36
37
|
reconnectDelayMs?: number;
|
|
38
|
+
fetch?: typeof fetch;
|
|
37
39
|
});
|
|
38
40
|
on(event: 'connect', handler: SseConnectHandler): void;
|
|
39
41
|
on(event: 'event', handler: SseEventHandler): void;
|
package/dist/events/sse.js
CHANGED
|
@@ -44,6 +44,9 @@ export class SseClient {
|
|
|
44
44
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, '');
|
|
45
45
|
this.getAuthToken = opts.getAuthToken;
|
|
46
46
|
this.reconnectDelayMs = opts.reconnectDelayMs ?? 3000;
|
|
47
|
+
// globalThis.fetch must be called as a method on globalThis, not through a
|
|
48
|
+
// variable, or browsers throw "Illegal invocation".
|
|
49
|
+
this.fetchImpl = (url, init) => opts.fetch ? opts.fetch(url, init) : globalThis.fetch(url, init);
|
|
47
50
|
}
|
|
48
51
|
on(event, handler) {
|
|
49
52
|
const key = event;
|
|
@@ -122,7 +125,7 @@ export class SseClient {
|
|
|
122
125
|
try {
|
|
123
126
|
const token = await this.getAuthToken();
|
|
124
127
|
const url = `${this.baseUrl}/sse`;
|
|
125
|
-
const response = await
|
|
128
|
+
const response = await this.fetchImpl(url, {
|
|
126
129
|
headers: {
|
|
127
130
|
'Authorization': `Bearer ${token}`,
|
|
128
131
|
'Accept': 'text/event-stream',
|
|
@@ -300,7 +303,7 @@ export class SseClient {
|
|
|
300
303
|
params.contextIds = ids.contextIds;
|
|
301
304
|
if (ids.groupIds && ids.groupIds.length > 0)
|
|
302
305
|
params.groupIds = ids.groupIds;
|
|
303
|
-
const response = await
|
|
306
|
+
const response = await this.fetchImpl(`${this.baseUrl}/sse/subscription`, {
|
|
304
307
|
method: 'POST',
|
|
305
308
|
headers: {
|
|
306
309
|
'Authorization': `Bearer ${token}`,
|
|
@@ -2,6 +2,7 @@ import { Transport, HttpClient } from './http-types.js';
|
|
|
2
2
|
export declare function createHttpClient(transport: Transport): HttpClient;
|
|
3
3
|
export declare function createBrowserHttpClient(options: {
|
|
4
4
|
baseUrl: string;
|
|
5
|
+
fetch?: typeof fetch;
|
|
5
6
|
getAuthToken?: () => Promise<string | undefined>;
|
|
6
7
|
getProof?: Transport['getProof'];
|
|
7
8
|
onTokenRefresh?: (newToken: string) => Promise<void>;
|
|
@@ -6,9 +6,9 @@ export function createHttpClient(transport) {
|
|
|
6
6
|
// Factory function for browser environments
|
|
7
7
|
export function createBrowserHttpClient(options) {
|
|
8
8
|
const transport = {
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
fetch: (url, init) => globalThis.fetch(url, init),
|
|
9
|
+
// globalThis.fetch must be called as a method on globalThis, not through a
|
|
10
|
+
// variable, or browsers throw "Illegal invocation".
|
|
11
|
+
fetch: (url, init) => options.fetch ? options.fetch(url, init) : globalThis.fetch(url, init),
|
|
12
12
|
baseUrl: options.baseUrl,
|
|
13
13
|
getAuthToken: options.getAuthToken,
|
|
14
14
|
getProof: options.getProof,
|