lazypock 0.17.0 → 0.17.1
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.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.global.js +22 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/auth.ts +37 -3
package/dist/index.cjs
CHANGED
|
@@ -386,20 +386,24 @@ var AuthStore = class {
|
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
388
|
* Set the auth collection name (used internally by auto-refresh).
|
|
389
|
+
*
|
|
390
|
+
* Persisted, so it survives a reload together with the token and model.
|
|
389
391
|
* @param name The collection name, or null for superuser tokens.
|
|
390
392
|
*/
|
|
391
393
|
setCollectionName(name) {
|
|
392
394
|
this._collectionName = name;
|
|
395
|
+
void this.persistCollectionName();
|
|
393
396
|
}
|
|
394
397
|
/**
|
|
395
398
|
* Load persisted auth state from storage.
|
|
396
399
|
* Should be called once at application startup.
|
|
397
400
|
*/
|
|
398
401
|
async init() {
|
|
399
|
-
const [token, model, expiresAt] = await Promise.all([
|
|
402
|
+
const [token, model, expiresAt, collectionName] = await Promise.all([
|
|
400
403
|
this.storage.get("auth_token"),
|
|
401
404
|
this.storage.get("auth_model"),
|
|
402
|
-
this.storage.get("auth_expires_at")
|
|
405
|
+
this.storage.get("auth_expires_at"),
|
|
406
|
+
this.storage.get("auth_collection")
|
|
403
407
|
]);
|
|
404
408
|
if (token) this._token = token;
|
|
405
409
|
if (expiresAt) this._tokenExpiresAt = parseInt(expiresAt, 10) || null;
|
|
@@ -409,6 +413,11 @@ var AuthStore = class {
|
|
|
409
413
|
} catch {
|
|
410
414
|
}
|
|
411
415
|
}
|
|
416
|
+
if (collectionName) {
|
|
417
|
+
this._collectionName = collectionName;
|
|
418
|
+
} else if (this._model && typeof this._model.collectionName === "string") {
|
|
419
|
+
this._collectionName = this._model.collectionName;
|
|
420
|
+
}
|
|
412
421
|
}
|
|
413
422
|
/**
|
|
414
423
|
* Update the current auth token and model, persist to storage, and notify listeners.
|
|
@@ -419,15 +428,19 @@ var AuthStore = class {
|
|
|
419
428
|
this._token = token;
|
|
420
429
|
this._model = model;
|
|
421
430
|
this._tokenExpiresAt = Date.now() + TOKEN_TTL_MS;
|
|
431
|
+
if (!this._collectionName && model && typeof model.collectionName === "string") {
|
|
432
|
+
this._collectionName = model.collectionName;
|
|
433
|
+
}
|
|
422
434
|
void Promise.all([
|
|
423
435
|
this.storage.set("auth_token", token),
|
|
424
436
|
this.storage.set("auth_expires_at", String(this._tokenExpiresAt)),
|
|
425
|
-
model ? this.storage.set("auth_model", JSON.stringify(model)) : this.storage.remove("auth_model")
|
|
437
|
+
model ? this.storage.set("auth_model", JSON.stringify(model)) : this.storage.remove("auth_model"),
|
|
438
|
+
this.persistCollectionName()
|
|
426
439
|
]);
|
|
427
440
|
this.notify();
|
|
428
441
|
}
|
|
429
442
|
/**
|
|
430
|
-
* Clear all auth state (token, model, expiry) and notify listeners.
|
|
443
|
+
* Clear all auth state (token, model, expiry, collection) and notify listeners.
|
|
431
444
|
*/
|
|
432
445
|
clear() {
|
|
433
446
|
this._token = "";
|
|
@@ -437,10 +450,14 @@ var AuthStore = class {
|
|
|
437
450
|
void Promise.all([
|
|
438
451
|
this.storage.remove("auth_token"),
|
|
439
452
|
this.storage.remove("auth_expires_at"),
|
|
440
|
-
this.storage.remove("auth_model")
|
|
453
|
+
this.storage.remove("auth_model"),
|
|
454
|
+
this.storage.remove("auth_collection")
|
|
441
455
|
]);
|
|
442
456
|
this.notify();
|
|
443
457
|
}
|
|
458
|
+
persistCollectionName() {
|
|
459
|
+
return this._collectionName ? this.storage.set("auth_collection", this._collectionName) : this.storage.remove("auth_collection");
|
|
460
|
+
}
|
|
444
461
|
/**
|
|
445
462
|
* Register a listener for auth state changes.
|
|
446
463
|
* @param fn Callback invoked with (model, token) on every change.
|