@glyphteck/veyl 0.66.2 → 0.67.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.js CHANGED
@@ -7921,7 +7921,7 @@ function closeSessionResources({ wallet, chatPK, chatPrivateKey, chatSigningSecr
7921
7921
  close(vaultAccess);
7922
7922
  close(vaultSigner);
7923
7923
  close(localCache);
7924
- pending.push(lockWallet(wallet));
7924
+ lockWallet(wallet);
7925
7925
  lockChat(chatPrivateKey, chatPK);
7926
7926
  cleanBytes(chatSigningSecret, notificationPrivateKey, notificationPublicKey);
7927
7927
  return Promise.allSettled(pending).then(() => {
@@ -8550,12 +8550,16 @@ function settingsState(settings = defaultSettings) {
8550
8550
  }
8551
8551
  };
8552
8552
  }
8553
+ function isAccountAuthenticationError(error) {
8554
+ const code = typeof error?.code === "string" ? error.code.toLowerCase() : "";
8555
+ return code === "permission-denied" || code.endsWith("/permission-denied") || code === "unauthenticated" || code.endsWith("/unauthenticated");
8556
+ }
8553
8557
  function createUser({ cloud, network, avatarCache = null, diag = null, onSessionRevoked = null }) {
8554
8558
  if (!cloud) {
8555
8559
  throw new Error("createUser requires { cloud }");
8556
8560
  }
8557
- if (avatarCache && [avatarCache.read, avatarCache.write, avatarCache.remove, avatarCache.removeAll].some((method) => typeof method !== "function")) {
8558
- throw new Error("avatarCache requires read, write, remove, and removeAll");
8561
+ if (avatarCache && [avatarCache.read, avatarCache.write, avatarCache.remove].some((method) => typeof method !== "function")) {
8562
+ throw new Error("avatarCache requires read, write, and remove");
8559
8563
  }
8560
8564
  let activeNetwork = network;
8561
8565
  let state = defaultUser;
@@ -8693,9 +8697,6 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8693
8697
  return;
8694
8698
  runCacheTask("user.avatar.cache.remove", () => avatarCache.remove(uid));
8695
8699
  }
8696
- function clearCachedAvatars() {
8697
- runCacheTask("user.avatar.cache.clear", () => avatarCache.removeAll());
8698
- }
8699
8700
  async function fetchAvatar(uid, { version = null, force = false, clear = false, persist = true } = {}) {
8700
8701
  if (!uid)
8701
8702
  return;
@@ -8778,6 +8779,54 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8778
8779
  function isCurrentUser(uid, session) {
8779
8780
  return started && authSession === session && userUid === uid;
8780
8781
  }
8782
+ function revokeAuthentication(authUser, {
8783
+ code = "",
8784
+ local = false,
8785
+ reason = "session-inactive"
8786
+ } = {}) {
8787
+ if (revokingSession)
8788
+ return;
8789
+ revokingSession = true;
8790
+ let callback;
8791
+ try {
8792
+ callback = onSessionRevoked?.({
8793
+ uid: authUser.uid,
8794
+ code,
8795
+ reason
8796
+ });
8797
+ } catch (error) {
8798
+ callback = Promise.reject(error);
8799
+ }
8800
+ markDiag(diag, "user.auth.revoked", {
8801
+ code,
8802
+ local,
8803
+ reason
8804
+ });
8805
+ setState((user) => ({
8806
+ ...user,
8807
+ authSessionReady: true,
8808
+ authSessionActive: false,
8809
+ authCredential: null
8810
+ }));
8811
+ let operation = Promise.resolve(callback).catch((error) => markError(diag, "user.session.revoke.local", Date.now(), error));
8812
+ if (!local) {
8813
+ operation = operation.then(() => cloud.auth.logout()).catch((error) => markError(diag, "user.session.revoke.auth", Date.now(), error));
8814
+ }
8815
+ operation.finally(() => {
8816
+ if (userUid === authUser.uid) {
8817
+ revokingSession = false;
8818
+ }
8819
+ });
8820
+ }
8821
+ function revokeAuthenticationError(authUser, error, reason) {
8822
+ if (!isAccountAuthenticationError(error))
8823
+ return false;
8824
+ revokeAuthentication(authUser, {
8825
+ code: error?.code || "",
8826
+ reason
8827
+ });
8828
+ return true;
8829
+ }
8781
8830
  function watchUser(authUser) {
8782
8831
  if (!started)
8783
8832
  return;
@@ -8787,7 +8836,6 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8787
8836
  closeUserWatches();
8788
8837
  markDiag(diag, "user.auth.state", { signedIn: !!authUser });
8789
8838
  if (!authUser) {
8790
- const signedOutUid = userUid;
8791
8839
  revokingSession = false;
8792
8840
  userUid = null;
8793
8841
  clearSettingsKey(settingsKey);
@@ -8796,17 +8844,11 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8796
8844
  agreementStored = null;
8797
8845
  agreementOverride = null;
8798
8846
  agreementAcceptance = null;
8799
- if (signedOutUid) {
8800
- clearCachedAvatars();
8801
- }
8802
8847
  avatarFetch = { uid: null, key: null, promise: null };
8803
8848
  setState({ ...defaultUser, authReady: true });
8804
8849
  return;
8805
8850
  }
8806
8851
  const authUidChanged = userUid !== authUser.uid;
8807
- if (userUid && authUidChanged) {
8808
- clearCachedAvatars();
8809
- }
8810
8852
  userUid = authUser.uid;
8811
8853
  if (authUidChanged) {
8812
8854
  clearSettingsKey(settingsKey);
@@ -8836,32 +8878,28 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8836
8878
  userWatches.push(cloud.auth.session.watch(authUser.uid, current((authSessionState) => {
8837
8879
  if (authSessionState?.active) {
8838
8880
  const authCredential = authSessionState.authCredential;
8839
- setState((user) => user.authCredential?.kind === authCredential?.kind && user.authCredential?.id === authCredential?.id ? user : { ...user, authCredential });
8840
- return;
8841
- }
8842
- if (revokingSession)
8843
- return;
8844
- revokingSession = true;
8845
- if (cloud.auth.session.isLocalTermination?.(authUser.uid, authSessionState?.generation)) {
8846
- Promise.resolve(onSessionRevoked?.({ uid: authUser.uid })).catch((error) => markError(diag, "user.session.revoke.local", Date.now(), error)).finally(() => {
8847
- if (userUid === authUser.uid) {
8848
- revokingSession = false;
8849
- }
8881
+ setState((user) => user.authSessionReady && user.authSessionActive && user.authCredential?.kind === authCredential?.kind && user.authCredential?.id === authCredential?.id ? user : {
8882
+ ...user,
8883
+ authSessionReady: true,
8884
+ authSessionActive: true,
8885
+ authCredential
8850
8886
  });
8851
8887
  return;
8852
8888
  }
8853
- Promise.resolve(onSessionRevoked?.({ uid: authUser.uid })).catch((error) => markError(diag, "user.session.revoke.local", Date.now(), error)).then(() => cloud.auth.logout()).catch((error) => markError(diag, "user.session.revoke.auth", Date.now(), error)).finally(() => {
8854
- if (userUid === authUser.uid) {
8855
- revokingSession = false;
8856
- }
8889
+ revokeAuthentication(authUser, {
8890
+ local: cloud.auth.session.isLocalTermination?.(authUser.uid, authSessionState?.generation) === true,
8891
+ reason: "session-inactive"
8857
8892
  });
8858
8893
  }), current((error) => {
8859
8894
  markError(diag, "user.session.listen", authStartedAt, error);
8895
+ revokeAuthenticationError(authUser, error, "session-listener");
8860
8896
  })));
8861
8897
  userWatches.push(cloud.user.admin.watch(authUser.uid, current((allowed) => {
8862
8898
  setState((user) => ({ ...user, isAdmin: allowed, adminReady: true }));
8863
8899
  }), current((error) => {
8864
8900
  markError(diag, "user.admin.listen", authStartedAt, error);
8901
+ if (revokeAuthenticationError(authUser, error, "admin-listener"))
8902
+ return;
8865
8903
  setState((user) => ({ ...user, isAdmin: false, adminReady: true }));
8866
8904
  })));
8867
8905
  userWatches.push(cloud.user.private.watch(authUser.uid, current((privateData, info = {}) => {
@@ -8885,6 +8923,8 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8885
8923
  }));
8886
8924
  }), current((error) => {
8887
8925
  markError(diag, "user.settings.snapshot", authStartedAt, error);
8926
+ if (revokeAuthenticationError(authUser, error, "settings-listener"))
8927
+ return;
8888
8928
  settingsStored = null;
8889
8929
  agreementStored = null;
8890
8930
  setState((user) => ({
@@ -8897,6 +8937,8 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8897
8937
  setState((user) => ({ ...user, banned: banned ?? null }));
8898
8938
  }), current((error) => {
8899
8939
  markError(diag, "user.moderation.listen", authStartedAt, error);
8940
+ if (revokeAuthenticationError(authUser, error, "moderation-listener"))
8941
+ return;
8900
8942
  setState((user) => ({ ...user, banned: null }));
8901
8943
  })));
8902
8944
  userWatches.push(cloud.user.blocked.watch(authUser.uid, current((blocked, info = {}) => {
@@ -8909,6 +8951,8 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8909
8951
  });
8910
8952
  }), current((error) => {
8911
8953
  markError(diag, "user.blocked.listen", authStartedAt, error);
8954
+ if (revokeAuthenticationError(authUser, error, "blocked-listener"))
8955
+ return;
8912
8956
  setState((user) => ({ ...user, blockedReady: false }));
8913
8957
  })));
8914
8958
  userWatches.push(cloud.user.profile.watch(authUser.uid, current((profileData, info = {}) => {
@@ -8955,6 +8999,8 @@ function createUser({ cloud, network, avatarCache = null, diag = null, onSession
8955
8999
  }
8956
9000
  }), current((error) => {
8957
9001
  markError(diag, "user.profile.snapshot", authStartedAt, error);
9002
+ if (revokeAuthenticationError(authUser, error, "profile-listener"))
9003
+ return;
8958
9004
  avatarFetch = { uid: null, key: null, promise: null };
8959
9005
  setState((user) => ({
8960
9006
  ...user,
@@ -9185,6 +9231,8 @@ var init_user = __esm(() => {
9185
9231
  defaultUser = {
9186
9232
  uid: null,
9187
9233
  authReady: false,
9234
+ authSessionReady: false,
9235
+ authSessionActive: false,
9188
9236
  authCredential: null,
9189
9237
  profileReady: false,
9190
9238
  username: null,
@@ -45673,20 +45721,36 @@ function openAccount(options = {}) {
45673
45721
  let closePromise = null;
45674
45722
  let state;
45675
45723
  let chatSession = null;
45724
+ let revokedUid = null;
45725
+ let revocationPromise = null;
45676
45726
  let nextAgreement = agreementContract(options.agreement || CURRENT_AGREEMENT);
45677
45727
  const listeners = new Set;
45678
45728
  let activeWriteTail = Promise.resolve();
45679
45729
  const sessionCloseWork = new Set;
45680
45730
  const operationBarrier = createAccountOperationCloseBarrier();
45731
+ function revokeSession(details = {}) {
45732
+ const { uid = null } = details;
45733
+ const accountUid = uid || state?.uid || null;
45734
+ if (accountUid && revokedUid === accountUid) {
45735
+ return revocationPromise || Promise.resolve();
45736
+ }
45737
+ revokedUid = accountUid;
45738
+ let callback;
45739
+ try {
45740
+ callback = options.onSessionRevoked?.({ ...details, uid: accountUid });
45741
+ } catch (error) {
45742
+ callback = Promise.reject(error);
45743
+ }
45744
+ lock();
45745
+ revocationPromise = Promise.resolve(callback);
45746
+ return revocationPromise;
45747
+ }
45681
45748
  const user = options.user || createUser({
45682
45749
  cloud,
45683
45750
  network: options.network || defaultNetwork,
45684
45751
  avatarCache,
45685
45752
  diag,
45686
- onSessionRevoked: ({ uid } = {}) => {
45687
- lock();
45688
- options.onSessionRevoked?.({ uid: uid || state?.uid || null });
45689
- }
45753
+ onSessionRevoked: revokeSession
45690
45754
  });
45691
45755
  state = emptyState(user.getSnapshot(), options.network || defaultNetwork);
45692
45756
  const chat = createChatSession({
@@ -45935,6 +45999,24 @@ function openAccount(options = {}) {
45935
45999
  code: error?.code || "",
45936
46000
  message: error?.message || String(error)
45937
46001
  });
46002
+ if (isAccountAuthenticationError(error)) {
46003
+ revokeSession({
46004
+ uid,
46005
+ code: error?.code || "",
46006
+ reason: "vault-listener"
46007
+ }).catch((revocationError) => {
46008
+ diag?.("account.session.revoke.error", {
46009
+ code: revocationError?.code || "",
46010
+ message: revocationError?.message || String(revocationError)
46011
+ });
46012
+ }).then(() => cloud.auth.logout()).catch((logoutError) => {
46013
+ diag?.("account.session.revoke.auth.error", {
46014
+ code: logoutError?.code || "",
46015
+ message: logoutError?.message || String(logoutError)
46016
+ });
46017
+ });
46018
+ return;
46019
+ }
45938
46020
  lock();
45939
46021
  emit2({ vault: null, vaultReady: true, vaultError: error });
45940
46022
  });
@@ -46399,8 +46481,8 @@ function normalizePasskeyLoginError(error, options = {}) {
46399
46481
  return error;
46400
46482
  }
46401
46483
  function normalizePasskeyRegisterError(error, options = {}) {
46402
- if (error?.name === "InvalidStateError" || error?.code === "functions/already-exists") {
46403
- return passkeyError(PASSKEY_PROVIDER_ALREADY_LINKED, "this provider already has a passkey for this account. choose another provider, device, or security key", error);
46484
+ if (error?.name === "CredentialAlreadyExistsException" || error?.name === "InvalidStateError" || error?.code === "functions/already-exists") {
46485
+ return passkeyError(PASSKEY_PROVIDER_ALREADY_LINKED, "you already have a passkey for this account", error);
46404
46486
  }
46405
46487
  if (error?.code === "functions/failed-precondition") {
46406
46488
  return passkeyError(PASSKEY_RP_MISMATCH, "This passkey belongs to a different Glyphteck passkey setup.", error);
@@ -56423,7 +56505,7 @@ var package_default;
56423
56505
  var init_package2 = __esm(() => {
56424
56506
  package_default = {
56425
56507
  name: "veyl",
56426
- version: "0.66.2",
56508
+ version: "0.67.0",
56427
56509
  packageManager: "bun@1.4.0",
56428
56510
  private: true,
56429
56511
  license: "UNLICENSED",
@@ -57535,7 +57617,7 @@ var init_client = __esm(() => {
57535
57617
  ]);
57536
57618
  });
57537
57619
 
57538
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/chunk-BCcL9Bmk.js
57620
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/chunk-BCcL9Bmk.js
57539
57621
  var init_chunk_BCcL9Bmk = () => {};
57540
57622
 
57541
57623
  // ../../node_modules/.bun/@bufbuild+protobuf@2.14.0/node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js
@@ -58307,7 +58389,7 @@ var init_wire2 = __esm(() => {
58307
58389
  init_size_delimited();
58308
58390
  });
58309
58391
 
58310
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/empty-mxtQJySK.js
58392
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/empty-mxtQJySK.js
58311
58393
  function createBaseTimestamp() {
58312
58394
  return {
58313
58395
  seconds: 0,
@@ -58652,7 +58734,7 @@ var init_empty_mxtQJySK = __esm(() => {
58652
58734
  };
58653
58735
  });
58654
58736
 
58655
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/proto/spark.js
58737
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/proto/spark.js
58656
58738
  function networkFromJSON(object) {
58657
58739
  switch (object) {
58658
58740
  case 0:
@@ -95033,7 +95115,7 @@ var init_dist3 = __esm(() => {
95033
95115
  };
95034
95116
  });
95035
95117
 
95036
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/sdk-types-CKSuGSGE.js
95118
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/sdk-types-CKSuGSGE.js
95037
95119
  function getAllProperties2(object) {
95038
95120
  const properties = /* @__PURE__ */ new Set;
95039
95121
  let current = object;
@@ -95877,7 +95959,7 @@ var init_sdk_types_CKSuGSGE = __esm(() => {
95877
95959
  }({});
95878
95960
  });
95879
95961
 
95880
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/multisig-BPUmc7A3.js
95962
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/multisig-BPUmc7A3.js
95881
95963
  function createBaseMultisigConfig() {
95882
95964
  return {
95883
95965
  version: 0,
@@ -96106,7 +96188,7 @@ var init_multisig_BPUmc7A3 = __esm(() => {
96106
96188
  };
96107
96189
  });
96108
96190
 
96109
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/proto/spark_token.js
96191
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/proto/spark_token.js
96110
96192
  function tokenOutputStatusFromJSON(object) {
96111
96193
  switch (object) {
96112
96194
  case 0:
@@ -109409,7 +109491,7 @@ var require_bolt11 = __commonJS(function(exports, module) {
109409
109491
  };
109410
109492
  });
109411
109493
 
109412
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/spark-wallet-CwB3Fuv1.js
109494
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/spark-wallet-CwB3Fuv1.js
109413
109495
  function parseSignature(signature) {
109414
109496
  if (signature.length !== 64)
109415
109497
  throw new Error(`Invalid signature length: expected 64, got ${signature.length}`);
@@ -153312,7 +153394,7 @@ var require_lib5 = __commonJS(function(exports) {
153312
153394
  exports.retryMiddleware = retryMiddleware;
153313
153395
  });
153314
153396
 
153315
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/spark-wallet.node-bD67u0Y4.js
153397
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/spark-wallet.node-bD67u0Y4.js
153316
153398
  import { createHash } from "crypto";
153317
153399
  import { createWriteStream, mkdirSync } from "node:fs";
153318
153400
  import { dirname } from "node:path";
@@ -155911,7 +155993,7 @@ var init_spark_wallet_node_bD67u0Y4 = __esm(() => {
155911
155993
  };
155912
155994
  });
155913
155995
 
155914
- // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+4b9ddefa68fc59f4/node_modules/@buildonspark/spark-sdk/dist/index.node.js
155996
+ // ../../node_modules/.bun/@buildonspark+spark-sdk@0.9.0+8e98cae01074b602/node_modules/@buildonspark/spark-sdk/dist/index.node.js
155915
155997
  import nodeCrypto from "crypto";
155916
155998
  var cryptoImpl2;
155917
155999
  var init_index_node = __esm(() => {
@@ -158468,7 +158550,7 @@ var init_index_esm3 = __esm(() => {
158468
158550
  registerCoreComponents("");
158469
158551
  });
158470
158552
 
158471
- // ../../node_modules/.bun/firebase@12.18.0+d12ebd0fb199560c/node_modules/firebase/app/dist/index.mjs
158553
+ // ../../node_modules/.bun/firebase@12.18.0+40ac9e013e4b1dea/node_modules/firebase/app/dist/index.mjs
158472
158554
  var name3 = "firebase", version2 = "12.18.0";
158473
158555
  var init_dist4 = __esm(() => {
158474
158556
  init_index_esm3();
@@ -158476,7 +158558,7 @@ var init_dist4 = __esm(() => {
158476
158558
  registerVersion(name3, version2, "app");
158477
158559
  });
158478
158560
 
158479
- // ../../node_modules/.bun/@firebase+auth@1.13.5+452031b0f0005c63/node_modules/@firebase/auth/dist/node-esm/totp-C24pd8aS.js
158561
+ // ../../node_modules/.bun/@firebase+auth@1.13.5+a89daa0b3e4af1f5/node_modules/@firebase/auth/dist/node-esm/totp-C24pd8aS.js
158480
158562
  function _debugErrorMap() {
158481
158563
  return {
158482
158564
  ["admin-restricted-operation"]: "This operation is restricted to administrators only.",
@@ -162450,7 +162532,7 @@ var init_totp_C24pd8aS = __esm(() => {
162450
162532
  };
162451
162533
  });
162452
162534
 
162453
- // ../../node_modules/.bun/@firebase+auth@1.13.5+452031b0f0005c63/node_modules/@firebase/auth/dist/node-esm/index.js
162535
+ // ../../node_modules/.bun/@firebase+auth@1.13.5+a89daa0b3e4af1f5/node_modules/@firebase/auth/dist/node-esm/index.js
162454
162536
  var init_node_esm = __esm(() => {
162455
162537
  init_totp_C24pd8aS();
162456
162538
  init_index_esm3();
@@ -162459,7 +162541,7 @@ var init_node_esm = __esm(() => {
162459
162541
  init_index_esm2();
162460
162542
  });
162461
162543
 
162462
- // ../../node_modules/.bun/firebase@12.18.0+d12ebd0fb199560c/node_modules/firebase/auth/dist/index.mjs
162544
+ // ../../node_modules/.bun/firebase@12.18.0+40ac9e013e4b1dea/node_modules/firebase/auth/dist/index.mjs
162463
162545
  var exports_dist = {};
162464
162546
  __export(exports_dist, {
162465
162547
  ActionCodeOperation: () => ActionCodeOperation,
@@ -197104,7 +197186,7 @@ var init_index_node2 = __esm(() => {
197104
197186
  registerFirestore("node");
197105
197187
  });
197106
197188
 
197107
- // ../../node_modules/.bun/firebase@12.18.0+d12ebd0fb199560c/node_modules/firebase/firestore/dist/index.mjs
197189
+ // ../../node_modules/.bun/firebase@12.18.0+40ac9e013e4b1dea/node_modules/firebase/firestore/dist/index.mjs
197108
197190
  var exports_dist2 = {};
197109
197191
  __export(exports_dist2, {
197110
197192
  AbstractUserDataWriter: () => AbstractUserDataWriter,
@@ -197807,7 +197889,7 @@ var init_index_esm4 = __esm(() => {
197807
197889
  registerFunctions();
197808
197890
  });
197809
197891
 
197810
- // ../../node_modules/.bun/firebase@12.18.0+d12ebd0fb199560c/node_modules/firebase/functions/dist/index.mjs
197892
+ // ../../node_modules/.bun/firebase@12.18.0+40ac9e013e4b1dea/node_modules/firebase/functions/dist/index.mjs
197811
197893
  var exports_dist3 = {};
197812
197894
  __export(exports_dist3, {
197813
197895
  FunctionsError: () => FunctionsError,
@@ -201664,18 +201746,25 @@ class Fleet {
201664
201746
  const client2 = this.client(profile);
201665
201747
  return operation(client2, publicAccount(record));
201666
201748
  }
201749
+ failRecord(record, error) {
201750
+ const message = error?.message || String(error);
201751
+ record.error ||= message;
201752
+ record.status = "error";
201753
+ record.controller.abort(error);
201754
+ if (record.failureEmitted)
201755
+ return;
201756
+ record.failureEmitted = true;
201757
+ this.emit("account-error", {
201758
+ account: publicAccount(record),
201759
+ error: record.error
201760
+ });
201761
+ }
201667
201762
  queuePolicies(record, event2) {
201668
201763
  record.pendingEvents += 1;
201669
201764
  if (record.pendingEvents > this.maxPendingEvents) {
201670
201765
  record.pendingEvents -= 1;
201671
201766
  const error = new Error(`fleet event backlog exceeded for ${record.profile.profile}`);
201672
- record.error = error.message;
201673
- record.status = "error";
201674
- record.controller.abort(error);
201675
- this.emit("account-error", {
201676
- account: publicAccount(record),
201677
- error: error.message
201678
- });
201767
+ this.failRecord(record, error);
201679
201768
  return;
201680
201769
  }
201681
201770
  if (this.policyReloading) {
@@ -201724,69 +201813,64 @@ class Fleet {
201724
201813
  unsubscribeRevoked: () => {},
201725
201814
  startedPolicies: [],
201726
201815
  reloadEvents: [],
201727
- closed: false
201816
+ closed: false,
201817
+ failureEmitted: false
201728
201818
  };
201729
201819
  this.records.set(profile.profile, record);
201730
201820
  this.emit("account-starting", { account: publicAccount(record) });
201731
- const baseOptions = typeof this.clientOptions === "function" ? await this.clientOptions(profile) : this.clientOptions;
201732
- record.client = await this.openClient({
201733
- ...baseOptions || {},
201734
- profile: profile.profile,
201735
- ...profile.network ? { network: profile.network } : {}
201736
- }, profile);
201737
- await record.client.ensureUnlocked();
201738
- for (const policy of this.policies) {
201739
- record.startedPolicies.push(policy);
201740
- await policy.start?.({
201741
- account: profile,
201742
- client: record.client,
201743
- fleet: this
201744
- });
201745
- }
201746
- let readyResolve;
201747
- let readyReject;
201748
- const ready2 = new Promise((resolve2, reject) => {
201749
- readyResolve = resolve2;
201750
- readyReject = reject;
201751
- });
201752
- record.unsubscribeRevoked = record.client.subscribeSessionRevoked?.(() => {
201753
- const error = new Error("account session revoked");
201754
- record.error = error.message;
201755
- record.status = "error";
201756
- controller.abort(error);
201757
- readyReject(error);
201758
- this.emit("account-error", {
201759
- account: publicAccount(record),
201760
- error: error.message
201761
- });
201762
- }) || (() => {});
201763
- const accountEventOptions = typeof this.eventOptions === "function" ? await this.eventOptions(profile) : this.eventOptions;
201764
- record.listenTask = record.client.listen({
201765
- ...accountEventOptions || {},
201766
- signal: controller.signal,
201767
- onEvent: (event2) => {
201768
- if (event2?.type === "ready")
201769
- readyResolve();
201770
- this.emit("account-event", {
201771
- account: publicAccount(record),
201772
- event: event2
201821
+ try {
201822
+ const baseOptions = typeof this.clientOptions === "function" ? await this.clientOptions(profile) : this.clientOptions;
201823
+ record.client = await this.openClient({
201824
+ ...baseOptions || {},
201825
+ profile: profile.profile,
201826
+ ...profile.network ? { network: profile.network } : {}
201827
+ }, profile);
201828
+ await record.client.ensureUnlocked();
201829
+ for (const policy of this.policies) {
201830
+ record.startedPolicies.push(policy);
201831
+ await policy.start?.({
201832
+ account: profile,
201833
+ client: record.client,
201834
+ fleet: this
201773
201835
  });
201774
- this.queuePolicies(record, event2);
201775
201836
  }
201776
- }).catch((error) => {
201777
- if (controller.signal.aborted)
201778
- return;
201779
- record.error = error?.message || String(error);
201780
- record.status = "error";
201781
- readyReject(error);
201782
- this.emit("account-error", {
201783
- account: publicAccount(record),
201784
- error: record.error
201837
+ let readyResolve;
201838
+ let readyReject;
201839
+ const ready2 = new Promise((resolve2, reject) => {
201840
+ readyResolve = resolve2;
201841
+ readyReject = reject;
201842
+ });
201843
+ record.unsubscribeRevoked = record.client.subscribeSessionRevoked?.(() => {
201844
+ const error = new Error("account session revoked");
201845
+ this.failRecord(record, error);
201846
+ readyReject(error);
201847
+ }) || (() => {});
201848
+ const accountEventOptions = typeof this.eventOptions === "function" ? await this.eventOptions(profile) : this.eventOptions;
201849
+ record.listenTask = record.client.listen({
201850
+ ...accountEventOptions || {},
201851
+ signal: controller.signal,
201852
+ onEvent: (event2) => {
201853
+ if (event2?.type === "ready")
201854
+ readyResolve();
201855
+ this.emit("account-event", {
201856
+ account: publicAccount(record),
201857
+ event: event2
201858
+ });
201859
+ this.queuePolicies(record, event2);
201860
+ }
201861
+ }).catch((error) => {
201862
+ if (controller.signal.aborted)
201863
+ return;
201864
+ this.failRecord(record, error);
201865
+ readyReject(error);
201785
201866
  });
201786
- });
201787
- await waitFor3(ready2, this.startTimeoutMs, `fleet profile start timed out: ${profile.profile}`);
201788
- record.status = "ready";
201789
- this.emit("account-ready", { account: publicAccount(record) });
201867
+ await waitFor3(ready2, this.startTimeoutMs, `fleet profile start timed out: ${profile.profile}`);
201868
+ record.status = "ready";
201869
+ this.emit("account-ready", { account: publicAccount(record) });
201870
+ } catch (error) {
201871
+ this.failRecord(record, error);
201872
+ throw error;
201873
+ }
201790
201874
  }
201791
201875
  async stopRecordPolicies(record) {
201792
201876
  const errors = [];
@@ -201998,10 +202082,13 @@ class Fleet {
201998
202082
  }
201999
202083
  };
202000
202084
  record.controller.abort();
202001
- await attempt(() => record.listenTask);
202002
- errors.push(...await this.stopRecordPolicies(record));
202003
202085
  await attempt(() => record.unsubscribeRevoked());
202004
- await attempt(() => record.client?.close());
202086
+ errors.push(...await this.stopRecordPolicies(record));
202087
+ const closeTask = Promise.resolve().then(() => record.client?.close());
202088
+ await Promise.all([
202089
+ attempt(() => record.listenTask),
202090
+ attempt(() => closeTask)
202091
+ ]);
202005
202092
  record.closed = true;
202006
202093
  record.status = errors.length || record.error ? "error" : "stopped";
202007
202094
  if (errors.length) {
package/package.json CHANGED
@@ -42,5 +42,5 @@
42
42
  "start": "node src/cli.js",
43
43
  "lint": "eslint src --quiet"
44
44
  },
45
- "version": "0.66.2"
45
+ "version": "0.67.0"
46
46
  }