@arbidocs/client 0.4.32 → 0.4.33

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 CHANGED
@@ -641,6 +641,10 @@ function createWorkspaceReopener(deps) {
641
641
  var DB_NAME = "arbi-crypto";
642
642
  var DB_VERSION = 2;
643
643
  var db = null;
644
+ var memorySession = null;
645
+ function canPersistSession() {
646
+ return !!crypto?.subtle;
647
+ }
644
648
  async function initializeDatabase() {
645
649
  return new Promise((resolve, reject) => {
646
650
  const request = indexedDB.open(DB_NAME, DB_VERSION);
@@ -760,7 +764,8 @@ async function decryptWithWrappingKey(ciphertext, iv) {
760
764
  return new Uint8Array(decrypted);
761
765
  }
762
766
  async function saveSession(sessionData) {
763
- if (!crypto?.subtle) {
767
+ if (!canPersistSession()) {
768
+ memorySession = sessionData;
764
769
  return;
765
770
  }
766
771
  await ensureDatabase();
@@ -804,8 +809,8 @@ async function saveSession(sessionData) {
804
809
  }
805
810
  }
806
811
  async function getSession() {
807
- if (!crypto?.subtle) {
808
- return null;
812
+ if (!canPersistSession()) {
813
+ return memorySession;
809
814
  }
810
815
  await ensureDatabase();
811
816
  if (!db) {
@@ -871,6 +876,10 @@ async function updateSigningPrivateKey(newSigningPrivateKey) {
871
876
  }
872
877
  }
873
878
  async function clearSession() {
879
+ memorySession = null;
880
+ if (!canPersistSession()) {
881
+ return;
882
+ }
874
883
  await ensureDatabase();
875
884
  if (!db) {
876
885
  throw new Error("Database not initialized");
@@ -915,7 +924,8 @@ async function clearWrappingKey() {
915
924
  });
916
925
  }
917
926
  async function clearAllData() {
918
- if (!crypto?.subtle) {
927
+ memorySession = null;
928
+ if (!canPersistSession()) {
919
929
  return;
920
930
  }
921
931
  await clearSession();
@@ -1450,6 +1460,7 @@ exports.base64Encode = base64Encode;
1450
1460
  exports.base64ToBytes = base64ToBytes;
1451
1461
  exports.buildWebSocketUrl = buildWebSocketUrl;
1452
1462
  exports.bytesToBase64 = bytesToBase64;
1463
+ exports.canPersistSession = canPersistSession;
1453
1464
  exports.changePasswordWithRekey = changePasswordWithRekey;
1454
1465
  exports.clearAllData = clearAllData;
1455
1466
  exports.clearSession = clearSession;