@kedaruma/revlm-client 1.0.50 → 1.0.52
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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -2
- package/dist/index.mjs +18 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -204,12 +204,14 @@ declare class Revlm {
|
|
|
204
204
|
private autoRefreshOn401;
|
|
205
205
|
private cookieCheckPromise?;
|
|
206
206
|
private logLevel;
|
|
207
|
+
private refreshPromise;
|
|
207
208
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
208
209
|
setToken(token: string): void;
|
|
209
210
|
getToken(): string | undefined;
|
|
210
211
|
clearToken(): void;
|
|
211
212
|
logout(): void;
|
|
212
213
|
refreshToken(): Promise<RevlmResponse>;
|
|
214
|
+
private refreshTokenSingleFlight;
|
|
213
215
|
verifyToken(): Promise<RevlmResponse>;
|
|
214
216
|
private makeHeaders;
|
|
215
217
|
private parseResponse;
|
package/dist/index.d.ts
CHANGED
|
@@ -204,12 +204,14 @@ declare class Revlm {
|
|
|
204
204
|
private autoRefreshOn401;
|
|
205
205
|
private cookieCheckPromise?;
|
|
206
206
|
private logLevel;
|
|
207
|
+
private refreshPromise;
|
|
207
208
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
208
209
|
setToken(token: string): void;
|
|
209
210
|
getToken(): string | undefined;
|
|
210
211
|
clearToken(): void;
|
|
211
212
|
logout(): void;
|
|
212
213
|
refreshToken(): Promise<RevlmResponse>;
|
|
214
|
+
private refreshTokenSingleFlight;
|
|
213
215
|
verifyToken(): Promise<RevlmResponse>;
|
|
214
216
|
private makeHeaders;
|
|
215
217
|
private parseResponse;
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@kedaruma/revlm-client",
|
|
38
|
-
version: "1.0.
|
|
38
|
+
version: "1.0.52",
|
|
39
39
|
private: false,
|
|
40
40
|
description: "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
|
|
41
41
|
keywords: [
|
|
@@ -251,6 +251,7 @@ var Revlm = class {
|
|
|
251
251
|
autoRefreshOn401;
|
|
252
252
|
cookieCheckPromise;
|
|
253
253
|
logLevel;
|
|
254
|
+
refreshPromise;
|
|
254
255
|
constructor(baseUrl, opts = {}) {
|
|
255
256
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
256
257
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -303,6 +304,18 @@ var Revlm = class {
|
|
|
303
304
|
}
|
|
304
305
|
return res;
|
|
305
306
|
}
|
|
307
|
+
async refreshTokenSingleFlight() {
|
|
308
|
+
if (!this.refreshPromise) {
|
|
309
|
+
this.refreshPromise = (async () => {
|
|
310
|
+
try {
|
|
311
|
+
return await this.refreshToken();
|
|
312
|
+
} finally {
|
|
313
|
+
this.refreshPromise = void 0;
|
|
314
|
+
}
|
|
315
|
+
})();
|
|
316
|
+
}
|
|
317
|
+
return this.refreshPromise;
|
|
318
|
+
}
|
|
306
319
|
// Verify current token with server. If invalid/expired, clear local token.
|
|
307
320
|
async verifyToken() {
|
|
308
321
|
if (!this._token) return { ok: false, error: "No token set" };
|
|
@@ -416,8 +429,11 @@ var Revlm = class {
|
|
|
416
429
|
}
|
|
417
430
|
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
418
431
|
const beforePayload = this.decodeJwtPayload(this._token || "");
|
|
419
|
-
const refreshRes = await this.
|
|
432
|
+
const refreshRes = await this.refreshTokenSingleFlight();
|
|
420
433
|
if (!refreshRes.ok) {
|
|
434
|
+
if (refreshRes.reason === "not_expired") {
|
|
435
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
436
|
+
}
|
|
421
437
|
console.warn("### refresh failed:", {
|
|
422
438
|
reason: refreshRes.reason,
|
|
423
439
|
status: refreshRes.status,
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var require_package = __commonJS({
|
|
|
7
7
|
"package.json"(exports, module) {
|
|
8
8
|
module.exports = {
|
|
9
9
|
name: "@kedaruma/revlm-client",
|
|
10
|
-
version: "1.0.
|
|
10
|
+
version: "1.0.52",
|
|
11
11
|
private: false,
|
|
12
12
|
description: "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
|
|
13
13
|
keywords: [
|
|
@@ -207,6 +207,7 @@ var Revlm = class {
|
|
|
207
207
|
autoRefreshOn401;
|
|
208
208
|
cookieCheckPromise;
|
|
209
209
|
logLevel;
|
|
210
|
+
refreshPromise;
|
|
210
211
|
constructor(baseUrl, opts = {}) {
|
|
211
212
|
if (!baseUrl) throw new Error("baseUrl is required");
|
|
212
213
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
@@ -259,6 +260,18 @@ var Revlm = class {
|
|
|
259
260
|
}
|
|
260
261
|
return res;
|
|
261
262
|
}
|
|
263
|
+
async refreshTokenSingleFlight() {
|
|
264
|
+
if (!this.refreshPromise) {
|
|
265
|
+
this.refreshPromise = (async () => {
|
|
266
|
+
try {
|
|
267
|
+
return await this.refreshToken();
|
|
268
|
+
} finally {
|
|
269
|
+
this.refreshPromise = void 0;
|
|
270
|
+
}
|
|
271
|
+
})();
|
|
272
|
+
}
|
|
273
|
+
return this.refreshPromise;
|
|
274
|
+
}
|
|
262
275
|
// Verify current token with server. If invalid/expired, clear local token.
|
|
263
276
|
async verifyToken() {
|
|
264
277
|
if (!this._token) return { ok: false, error: "No token set" };
|
|
@@ -372,8 +385,11 @@ var Revlm = class {
|
|
|
372
385
|
}
|
|
373
386
|
if (allowAuthRetry && !retrying && res.status === 401 && !this.shouldSkipAuthRetry(path)) {
|
|
374
387
|
const beforePayload = this.decodeJwtPayload(this._token || "");
|
|
375
|
-
const refreshRes = await this.
|
|
388
|
+
const refreshRes = await this.refreshTokenSingleFlight();
|
|
376
389
|
if (!refreshRes.ok) {
|
|
390
|
+
if (refreshRes.reason === "not_expired") {
|
|
391
|
+
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
392
|
+
}
|
|
377
393
|
console.warn("### refresh failed:", {
|
|
378
394
|
reason: refreshRes.reason,
|
|
379
395
|
status: refreshRes.status,
|