@calimero-network/mero-js 24.5.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.
- package/dist/account/create-context.js +17 -6
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.js +1 -1
- package/dist/account/session.d.ts +23 -1
- package/dist/account/session.js +96 -12
- package/dist/admin-api/admin-types.d.ts +2 -0
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +78 -13
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +78 -13
- package/dist/index.mjs.map +3 -3
- package/dist/mero-js.d.ts +4 -1
- package/dist/mero-js.js +6 -1
- package/dist/token-store/index.d.ts +8 -0
- package/dist/transport/mero-client.d.ts +9 -0
- package/dist/transport/mero-client.js +13 -5
- package/package.json +1 -1
package/dist/mero-js.d.ts
CHANGED
|
@@ -174,7 +174,10 @@ export declare class MeroJs {
|
|
|
174
174
|
* instance already rotated is adopted instead of replaying a stale token.
|
|
175
175
|
*/
|
|
176
176
|
private performTokenRefresh;
|
|
177
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Run `fn` under the refresh lock: the token store's own (shared across
|
|
179
|
+
* processes), else the cross-tab Web Lock, else directly.
|
|
180
|
+
*/
|
|
178
181
|
private withRefreshLock;
|
|
179
182
|
/**
|
|
180
183
|
* Perform the actual token refresh. Runs with the refresh lock held.
|
package/dist/mero-js.js
CHANGED
|
@@ -290,8 +290,13 @@ export class MeroJs {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* Run `fn` under the refresh lock: the token store's own (shared across
|
|
295
|
+
* processes), else the cross-tab Web Lock, else directly.
|
|
296
|
+
*/
|
|
294
297
|
withRefreshLock(fn) {
|
|
298
|
+
if (this.tokenStore?.withLock)
|
|
299
|
+
return this.tokenStore.withLock(fn);
|
|
295
300
|
const locks = getLockManager();
|
|
296
301
|
return locks ? locks.request(REFRESH_LOCK_NAME, fn) : fn();
|
|
297
302
|
}
|
|
@@ -3,6 +3,14 @@ export interface TokenStore {
|
|
|
3
3
|
getTokens(): TokenData | null;
|
|
4
4
|
setTokens(data: TokenData): void;
|
|
5
5
|
clear(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Run `fn` holding a lock that every process sharing this store respects.
|
|
8
|
+
* MeroJs holds it around a token refresh, so two processes on one store never
|
|
9
|
+
* spend the same single-use refresh token. Web Locks cover tabs of one
|
|
10
|
+
* browser; a store shared across processes (a file read by several CLIs, say)
|
|
11
|
+
* needs its own lock, and implements this. Takes precedence over Web Locks.
|
|
12
|
+
*/
|
|
13
|
+
withLock?<T>(fn: () => Promise<T>): Promise<T>;
|
|
6
14
|
}
|
|
7
15
|
export declare class MemoryTokenStore implements TokenStore {
|
|
8
16
|
private tokens;
|
|
@@ -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
|
|
136
|
-
this.
|
|
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
|
}
|