@kedaruma/revlm-client 1.0.52 → 1.0.53
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +40 -21
- package/dist/index.mjs +40 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -206,6 +206,11 @@ declare class Revlm {
|
|
|
206
206
|
private logLevel;
|
|
207
207
|
private refreshPromise;
|
|
208
208
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
209
|
+
private canLog;
|
|
210
|
+
logError(...args: any[]): void;
|
|
211
|
+
logWarn(...args: any[]): void;
|
|
212
|
+
logInfo(...args: any[]): void;
|
|
213
|
+
logDebug(...args: any[]): void;
|
|
209
214
|
setToken(token: string): void;
|
|
210
215
|
getToken(): string | undefined;
|
|
211
216
|
clearToken(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,11 @@ declare class Revlm {
|
|
|
206
206
|
private logLevel;
|
|
207
207
|
private refreshPromise;
|
|
208
208
|
constructor(baseUrl: string, opts?: RevlmOptions);
|
|
209
|
+
private canLog;
|
|
210
|
+
logError(...args: any[]): void;
|
|
211
|
+
logWarn(...args: any[]): void;
|
|
212
|
+
logInfo(...args: any[]): void;
|
|
213
|
+
logDebug(...args: any[]): void;
|
|
209
214
|
setToken(token: string): void;
|
|
210
215
|
getToken(): string | undefined;
|
|
211
216
|
clearToken(): void;
|
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.53",
|
|
39
39
|
private: false,
|
|
40
40
|
description: "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
|
|
41
41
|
keywords: [
|
|
@@ -216,6 +216,12 @@ var RevlmDBDatabase = class {
|
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
// src/Revlm.ts
|
|
219
|
+
var LOG_LEVEL_RANK = {
|
|
220
|
+
error: 0,
|
|
221
|
+
warn: 1,
|
|
222
|
+
info: 2,
|
|
223
|
+
debug: 3
|
|
224
|
+
};
|
|
219
225
|
function normalizeLogLevel(value) {
|
|
220
226
|
if (!value) return "info";
|
|
221
227
|
const lowered = value.toLowerCase();
|
|
@@ -266,20 +272,33 @@ var Revlm = class {
|
|
|
266
272
|
if (!this.fetchImpl) {
|
|
267
273
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
268
274
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
275
|
+
this.logInfo("\u{1F680} Revlm Client Init", {
|
|
276
|
+
version: getRevlmClientVersion(),
|
|
277
|
+
baseUrl: this.baseUrl,
|
|
278
|
+
autoSetToken: this.autoSetToken,
|
|
279
|
+
autoRefreshOn401: this.autoRefreshOn401,
|
|
280
|
+
provisionalEnabled: this.provisionalEnabled,
|
|
281
|
+
provisionalAuthDomain: this.provisionalAuthDomain || void 0,
|
|
282
|
+
provisionalAuthSecretMaster: maskSecret(this.provisionalAuthSecretMaster),
|
|
283
|
+
defaultHeaders: Object.keys(this.defaultHeaders || {}),
|
|
284
|
+
fetchImplProvided: !!opts.fetchImpl,
|
|
285
|
+
logLevel: this.logLevel
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
canLog(level) {
|
|
289
|
+
return LOG_LEVEL_RANK[this.logLevel] >= LOG_LEVEL_RANK[level];
|
|
290
|
+
}
|
|
291
|
+
logError(...args) {
|
|
292
|
+
if (this.canLog("error")) console.error(...args);
|
|
293
|
+
}
|
|
294
|
+
logWarn(...args) {
|
|
295
|
+
if (this.canLog("warn")) console.warn(...args);
|
|
296
|
+
}
|
|
297
|
+
logInfo(...args) {
|
|
298
|
+
if (this.canLog("info")) console.log(...args);
|
|
299
|
+
}
|
|
300
|
+
logDebug(...args) {
|
|
301
|
+
if (this.canLog("debug")) console.log(...args);
|
|
283
302
|
}
|
|
284
303
|
setToken(token) {
|
|
285
304
|
this._token = token;
|
|
@@ -391,7 +410,7 @@ var Revlm = class {
|
|
|
391
410
|
if (!payload || typeof payload.exp !== "number") return;
|
|
392
411
|
const now = Math.floor(Date.now() / 1e3);
|
|
393
412
|
const ttlSec = payload.exp - now;
|
|
394
|
-
|
|
413
|
+
this.logDebug("### token ttl", {
|
|
395
414
|
event,
|
|
396
415
|
path,
|
|
397
416
|
ttlSec,
|
|
@@ -434,7 +453,7 @@ var Revlm = class {
|
|
|
434
453
|
if (refreshRes.reason === "not_expired") {
|
|
435
454
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
436
455
|
}
|
|
437
|
-
|
|
456
|
+
this.logDebug("### refresh failed:", {
|
|
438
457
|
reason: refreshRes.reason,
|
|
439
458
|
status: refreshRes.status,
|
|
440
459
|
error: refreshRes.error
|
|
@@ -450,7 +469,7 @@ var Revlm = class {
|
|
|
450
469
|
const now = Math.floor(Date.now() / 1e3);
|
|
451
470
|
const oldExp = beforePayload?.exp;
|
|
452
471
|
const newExp = afterPayload?.exp;
|
|
453
|
-
|
|
472
|
+
this.logDebug("### refresh success", {
|
|
454
473
|
path,
|
|
455
474
|
oldExp,
|
|
456
475
|
newExp,
|
|
@@ -514,13 +533,13 @@ var Revlm = class {
|
|
|
514
533
|
if (this.cookieCheckPromise) return this.cookieCheckPromise;
|
|
515
534
|
this.cookieCheckPromise = (async () => {
|
|
516
535
|
const first = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
517
|
-
|
|
536
|
+
this.logDebug("### cookie check", { step: "first", ok: first.ok, reason: first.reason, status: first.status });
|
|
518
537
|
if (first.ok) return;
|
|
519
538
|
if (first.reason !== "cookie_missing") {
|
|
520
539
|
throw new Error(`Cookie check failed: ${first.reason || first.error || "unknown_error"}`);
|
|
521
540
|
}
|
|
522
541
|
const second = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
523
|
-
|
|
542
|
+
this.logDebug("### cookie check", { step: "second", ok: second.ok, reason: second.reason, status: second.status });
|
|
524
543
|
if (!second.ok) {
|
|
525
544
|
throw new Error("Cookie support missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
526
545
|
}
|
|
@@ -604,7 +623,7 @@ var App = class {
|
|
|
604
623
|
throw new Error("Unsupported credentials type");
|
|
605
624
|
}
|
|
606
625
|
const res = await this.revlm.login(cred.email, cred.password);
|
|
607
|
-
|
|
626
|
+
this.revlm.logInfo("### App:login res:", res);
|
|
608
627
|
if (!res || !res.ok || !res.token) {
|
|
609
628
|
const errMsg = res && !res.ok ? res.error : "login failed";
|
|
610
629
|
const err = new Error(errMsg);
|
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.53",
|
|
11
11
|
private: false,
|
|
12
12
|
description: "TypeScript client SDK for talking to the Revlm server replacement for MongoDB Realm.",
|
|
13
13
|
keywords: [
|
|
@@ -172,6 +172,12 @@ var RevlmDBDatabase = class {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
// src/Revlm.ts
|
|
175
|
+
var LOG_LEVEL_RANK = {
|
|
176
|
+
error: 0,
|
|
177
|
+
warn: 1,
|
|
178
|
+
info: 2,
|
|
179
|
+
debug: 3
|
|
180
|
+
};
|
|
175
181
|
function normalizeLogLevel(value) {
|
|
176
182
|
if (!value) return "info";
|
|
177
183
|
const lowered = value.toLowerCase();
|
|
@@ -222,20 +228,33 @@ var Revlm = class {
|
|
|
222
228
|
if (!this.fetchImpl) {
|
|
223
229
|
throw new Error("No fetch implementation available. Provide fetchImpl in options or run in Node 18+ with global fetch.");
|
|
224
230
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
this.logInfo("\u{1F680} Revlm Client Init", {
|
|
232
|
+
version: getRevlmClientVersion(),
|
|
233
|
+
baseUrl: this.baseUrl,
|
|
234
|
+
autoSetToken: this.autoSetToken,
|
|
235
|
+
autoRefreshOn401: this.autoRefreshOn401,
|
|
236
|
+
provisionalEnabled: this.provisionalEnabled,
|
|
237
|
+
provisionalAuthDomain: this.provisionalAuthDomain || void 0,
|
|
238
|
+
provisionalAuthSecretMaster: maskSecret(this.provisionalAuthSecretMaster),
|
|
239
|
+
defaultHeaders: Object.keys(this.defaultHeaders || {}),
|
|
240
|
+
fetchImplProvided: !!opts.fetchImpl,
|
|
241
|
+
logLevel: this.logLevel
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
canLog(level) {
|
|
245
|
+
return LOG_LEVEL_RANK[this.logLevel] >= LOG_LEVEL_RANK[level];
|
|
246
|
+
}
|
|
247
|
+
logError(...args) {
|
|
248
|
+
if (this.canLog("error")) console.error(...args);
|
|
249
|
+
}
|
|
250
|
+
logWarn(...args) {
|
|
251
|
+
if (this.canLog("warn")) console.warn(...args);
|
|
252
|
+
}
|
|
253
|
+
logInfo(...args) {
|
|
254
|
+
if (this.canLog("info")) console.log(...args);
|
|
255
|
+
}
|
|
256
|
+
logDebug(...args) {
|
|
257
|
+
if (this.canLog("debug")) console.log(...args);
|
|
239
258
|
}
|
|
240
259
|
setToken(token) {
|
|
241
260
|
this._token = token;
|
|
@@ -347,7 +366,7 @@ var Revlm = class {
|
|
|
347
366
|
if (!payload || typeof payload.exp !== "number") return;
|
|
348
367
|
const now = Math.floor(Date.now() / 1e3);
|
|
349
368
|
const ttlSec = payload.exp - now;
|
|
350
|
-
|
|
369
|
+
this.logDebug("### token ttl", {
|
|
351
370
|
event,
|
|
352
371
|
path,
|
|
353
372
|
ttlSec,
|
|
@@ -390,7 +409,7 @@ var Revlm = class {
|
|
|
390
409
|
if (refreshRes.reason === "not_expired") {
|
|
391
410
|
return this.requestWithRetry(path, method, body, { allowAuthRetry: false, retrying: true });
|
|
392
411
|
}
|
|
393
|
-
|
|
412
|
+
this.logDebug("### refresh failed:", {
|
|
394
413
|
reason: refreshRes.reason,
|
|
395
414
|
status: refreshRes.status,
|
|
396
415
|
error: refreshRes.error
|
|
@@ -406,7 +425,7 @@ var Revlm = class {
|
|
|
406
425
|
const now = Math.floor(Date.now() / 1e3);
|
|
407
426
|
const oldExp = beforePayload?.exp;
|
|
408
427
|
const newExp = afterPayload?.exp;
|
|
409
|
-
|
|
428
|
+
this.logDebug("### refresh success", {
|
|
410
429
|
path,
|
|
411
430
|
oldExp,
|
|
412
431
|
newExp,
|
|
@@ -470,13 +489,13 @@ var Revlm = class {
|
|
|
470
489
|
if (this.cookieCheckPromise) return this.cookieCheckPromise;
|
|
471
490
|
this.cookieCheckPromise = (async () => {
|
|
472
491
|
const first = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
473
|
-
|
|
492
|
+
this.logDebug("### cookie check", { step: "first", ok: first.ok, reason: first.reason, status: first.status });
|
|
474
493
|
if (first.ok) return;
|
|
475
494
|
if (first.reason !== "cookie_missing") {
|
|
476
495
|
throw new Error(`Cookie check failed: ${first.reason || first.error || "unknown_error"}`);
|
|
477
496
|
}
|
|
478
497
|
const second = await this.requestWithRetry("/cookie-check", "POST", void 0, { allowAuthRetry: false, retrying: false });
|
|
479
|
-
|
|
498
|
+
this.logDebug("### cookie check", { step: "second", ok: second.ok, reason: second.reason, status: second.status });
|
|
480
499
|
if (!second.ok) {
|
|
481
500
|
throw new Error("Cookie support missing. Provide a cookie-aware fetch implementation for Node/RN.");
|
|
482
501
|
}
|
|
@@ -560,7 +579,7 @@ var App = class {
|
|
|
560
579
|
throw new Error("Unsupported credentials type");
|
|
561
580
|
}
|
|
562
581
|
const res = await this.revlm.login(cred.email, cred.password);
|
|
563
|
-
|
|
582
|
+
this.revlm.logInfo("### App:login res:", res);
|
|
564
583
|
if (!res || !res.ok || !res.token) {
|
|
565
584
|
const errMsg = res && !res.ok ? res.error : "login failed";
|
|
566
585
|
const err = new Error(errMsg);
|