@calimero-network/mero-js 24.5.0 → 24.6.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.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +2 -2
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +2 -2
- 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/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;
|