@glyphteck/veyl 0.31.0 → 0.31.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.
Files changed (3) hide show
  1. package/dist/cli.js +59 -15
  2. package/dist/index.js +59 -15
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -979,7 +979,7 @@ var package_default;
979
979
  var init_package = __esm(() => {
980
980
  package_default = {
981
981
  name: "veyl",
982
- version: "0.31.0",
982
+ version: "0.31.1",
983
983
  private: true,
984
984
  license: "Apache-2.0",
985
985
  workspaces: {
@@ -174256,6 +174256,12 @@ function findByKey(messages, target) {
174256
174256
  return (messages || []).find((message) => message?.id === key || message?.cid === key || getMessageKey(message) === key) || null;
174257
174257
  }
174258
174258
  function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174259
+ let activeReadWindow = null;
174260
+ function releaseActiveWindow() {
174261
+ const window2 = activeReadWindow;
174262
+ activeReadWindow = null;
174263
+ window2?.release?.();
174264
+ }
174259
174265
  async function readyRuntime() {
174260
174266
  const runtime = await getRuntime();
174261
174267
  await waitFor2(runtime.chat, (snapshot) => snapshot?.isChatDataReady === true);
@@ -174344,13 +174350,20 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174344
174350
  }
174345
174351
  async function read(peer, options2 = {}) {
174346
174352
  const window2 = await messageWindow(peer, options2);
174347
- if (!window2.chat)
174353
+ if (!window2.chat) {
174354
+ releaseActiveWindow();
174348
174355
  return { chat: null, messages: [] };
174356
+ }
174357
+ let retained = false;
174349
174358
  try {
174350
174359
  const { runtime, session, chat, messages } = window2;
174351
174360
  const lastPeer = [...messages].reverse().find((message) => isPeerMsg(message, session.chatPK));
174352
174361
  if (lastPeer)
174353
174362
  await runtime.chat.getSnapshot().markChatReadReceipt(chat.id, lastPeer, { messages });
174363
+ const previousWindow = activeReadWindow;
174364
+ activeReadWindow = window2;
174365
+ retained = true;
174366
+ previousWindow?.release?.();
174354
174367
  return {
174355
174368
  chat: simplifyAccountChat(chat, profileForChat(runtime, chat)),
174356
174369
  messages: messages.map((message) => simplifyAccountMessage(message, chat, session.chatPK, options2)),
@@ -174358,7 +174371,8 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174358
174371
  nextOlderThan: window2.history?.nextOlderThan || null
174359
174372
  };
174360
174373
  } finally {
174361
- window2.release?.();
174374
+ if (!retained)
174375
+ window2.release?.();
174362
174376
  }
174363
174377
  }
174364
174378
  async function markRead(peer, options2 = {}) {
@@ -174381,9 +174395,17 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174381
174395
  }
174382
174396
  }
174383
174397
  async function messageForPeer(peer, messageId, options2 = {}) {
174384
- const window2 = await messageWindow(peer, { ...options2, count: Math.max(positiveLimit2(options2.count, 100), 100), loadOlder: false });
174385
- if (!window2.chat)
174398
+ const { runtime, chat } = await chatForPeer(peer);
174399
+ if (!chat)
174386
174400
  throw new Error("chat not found");
174401
+ const retained = activeReadWindow;
174402
+ if (retained?.runtime === runtime && retained.chat?.id === chat.id) {
174403
+ const message = findByKey(retained.batch?.sourceMessages, messageId) || findByKey(retained.messages, messageId);
174404
+ if (message) {
174405
+ return { ...retained, release: undefined, message, target: getMessageKey(message) || cleanText(messageId) };
174406
+ }
174407
+ }
174408
+ const window2 = await messageWindow(peer, { ...options2, count: Math.max(positiveLimit2(options2.count, 100), 100), loadOlder: false });
174387
174409
  try {
174388
174410
  let message = findByKey(window2.batch?.sourceMessages, messageId) || findByKey(window2.messages, messageId);
174389
174411
  if (!message) {
@@ -174563,6 +174585,9 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174563
174585
  if (!chat)
174564
174586
  return { deleted: false, chat: null };
174565
174587
  const deleted = await runtime.chat.getSnapshot().deleteChat(chat, { cleanup: options2.cleanup !== false });
174588
+ if (deleted === true && activeReadWindow?.runtime === runtime && activeReadWindow.chat?.id === chat.id) {
174589
+ releaseActiveWindow();
174590
+ }
174566
174591
  return { deleted: deleted === true, chat: simplifyAccountChat(chat, profile) };
174567
174592
  }
174568
174593
  async function retention(peer, value) {
@@ -174596,7 +174621,8 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
174596
174621
  deleteChat,
174597
174622
  retention,
174598
174623
  messageWindow,
174599
- messageForPeer
174624
+ messageForPeer,
174625
+ releaseActiveWindow
174600
174626
  };
174601
174627
  }
174602
174628
  function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }) {
@@ -174616,6 +174642,17 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174616
174642
  return fees || null;
174617
174643
  return { ...fees, spark: stripRaw(fees.spark, options2) };
174618
174644
  }
174645
+ function summarizePaymentResult(value) {
174646
+ if (!value || typeof value !== "object")
174647
+ return value ?? null;
174648
+ const transfer = value.transfer && typeof value.transfer === "object" ? simplifyAccountTransfer(value.transfer) : null;
174649
+ return {
174650
+ kind: value.kind || null,
174651
+ id: value.id || value.transfer?.id || null,
174652
+ status: value.status || value.transfer?.status || null,
174653
+ transfer
174654
+ };
174655
+ }
174619
174656
  function cleanWithdrawal(withdrawal, options2 = {}) {
174620
174657
  if (!withdrawal)
174621
174658
  return null;
@@ -174723,8 +174760,8 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174723
174760
  return {
174724
174761
  id: result.result?.id || result.payment?.id || null,
174725
174762
  fees,
174726
- result: stripRaw(result.result, options2),
174727
- raw: options2.raw ? jsonSafe(result.payment) : undefined
174763
+ result: summarizePaymentResult(result.result),
174764
+ raw: options2.raw ? jsonSafe(result) : undefined
174728
174765
  };
174729
174766
  }
174730
174767
  async function lightningReceive(id, options2 = {}) {
@@ -174735,7 +174772,10 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174735
174772
  async function lightningSend(id, options2 = {}) {
174736
174773
  const { snapshot } = await readyWallet();
174737
174774
  const result = throwIfFailed(await snapshot.value.getLightningSendRequest(id), "could not read lightning send request");
174738
- return stripRaw(result.result, options2);
174775
+ return {
174776
+ ...summarizePaymentResult(result.result),
174777
+ raw: options2.raw ? jsonSafe(result.result) : undefined
174778
+ };
174739
174779
  }
174740
174780
  async function payInvoice(value, options2 = {}) {
174741
174781
  const raw = cleanText(value);
@@ -174757,7 +174797,8 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174757
174797
  type,
174758
174798
  id: result?.id || result?.result?.id || null,
174759
174799
  fees: result?.fees || null,
174760
- result: stripRaw(result?.result, options2)
174800
+ result: summarizePaymentResult(result?.result),
174801
+ raw: options2.raw ? jsonSafe(result) : undefined
174761
174802
  };
174762
174803
  }
174763
174804
  async function withdrawQuote(onchainAddress, sats, options2 = {}) {
@@ -175265,6 +175306,7 @@ class VeylHeadlessClient {
175265
175306
  }
175266
175307
  async createAccount(options2 = {}) {
175267
175308
  const username = cleanUsername3(options2.username);
175309
+ const profileName = this.store.profile || username;
175268
175310
  const network = String(options2.network || this.network).toUpperCase();
175269
175311
  const termsVersion = requireCurrentTermsVersion(options2.termsVersion);
175270
175312
  const machine = options2.credential || createMachineCredential();
@@ -175280,7 +175322,7 @@ class VeylHeadlessClient {
175280
175322
  await signInHeadless(this.auth, finish.token);
175281
175323
  this.autoLogin = true;
175282
175324
  const profile = await this.saveProfile({
175283
- profile: username,
175325
+ profile: profileName,
175284
175326
  username,
175285
175327
  uid: finish.uid,
175286
175328
  network,
@@ -175300,7 +175342,7 @@ class VeylHeadlessClient {
175300
175342
  }
175301
175343
  async loginAccount(options2 = {}) {
175302
175344
  const username = cleanOptionalUsername(options2.username);
175303
- const profile = await this.loadProfile(username);
175345
+ const profile = await this.loadProfile(this.store.profile || username);
175304
175346
  const credentialId = options2.credentialId || profile.credentialId;
175305
175347
  const privateKeyPem = options2.privateKeyPem || profile.privateKeyPem;
175306
175348
  if (!credentialId || !privateKeyPem) {
@@ -175339,6 +175381,7 @@ class VeylHeadlessClient {
175339
175381
  }
175340
175382
  async createPasskeyAccount(options2 = {}) {
175341
175383
  const username = cleanUsername3(options2.username);
175384
+ const profileName = this.store.profile || username;
175342
175385
  const network = String(options2.network || this.network).toUpperCase();
175343
175386
  const termsVersion = requireCurrentTermsVersion(options2.termsVersion);
175344
175387
  const flow = await runPasskeyBrowserFlow({
@@ -175355,7 +175398,7 @@ class VeylHeadlessClient {
175355
175398
  const machine = options2.credential || createMachineCredential();
175356
175399
  const credential = machine ? await this.addMachineCredential(machine) : null;
175357
175400
  const profile = await this.saveProfile({
175358
- profile: username,
175401
+ profile: profileName,
175359
175402
  username,
175360
175403
  uid: user.uid,
175361
175404
  network,
@@ -175375,7 +175418,7 @@ class VeylHeadlessClient {
175375
175418
  }
175376
175419
  async loginPasskeyAccount(options2 = {}) {
175377
175420
  const requested = cleanOptionalUsername(options2.username);
175378
- const stored = requested ? await this.store.load(requested) : await this.store.load();
175421
+ const stored = await this.store.load(this.store.profile || requested);
175379
175422
  const flow = await runPasskeyBrowserFlow({
175380
175423
  mode: "login",
175381
175424
  uid: options2.uid || stored?.uid,
@@ -175391,7 +175434,7 @@ class VeylHeadlessClient {
175391
175434
  const credential = machine ? await this.addMachineCredential(machine) : null;
175392
175435
  const profile = await this.saveProfile({
175393
175436
  ...stored || {},
175394
- profile: username || stored?.profile || user.uid,
175437
+ profile: this.store.profile || stored?.profile || username || user.uid,
175395
175438
  username: username || stored?.username || null,
175396
175439
  uid: user.uid,
175397
175440
  network: String(stored?.network || options2.network || this.network).toUpperCase(),
@@ -175700,6 +175743,7 @@ class VeylHeadlessClient {
175700
175743
  }
175701
175744
  closeVaultSession() {
175702
175745
  const session = this.session;
175746
+ this.runtimeChat.releaseActiveWindow();
175703
175747
  this.session = null;
175704
175748
  this.runtime = null;
175705
175749
  closeAccountSession(session);
package/dist/index.js CHANGED
@@ -173633,6 +173633,12 @@ function findByKey(messages, target) {
173633
173633
  return (messages || []).find((message) => message?.id === key || message?.cid === key || getMessageKey(message) === key) || null;
173634
173634
  }
173635
173635
  function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173636
+ let activeReadWindow = null;
173637
+ function releaseActiveWindow() {
173638
+ const window2 = activeReadWindow;
173639
+ activeReadWindow = null;
173640
+ window2?.release?.();
173641
+ }
173636
173642
  async function readyRuntime() {
173637
173643
  const runtime = await getRuntime();
173638
173644
  await waitFor2(runtime.chat, (snapshot) => snapshot?.isChatDataReady === true);
@@ -173721,13 +173727,20 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173721
173727
  }
173722
173728
  async function read(peer, options2 = {}) {
173723
173729
  const window2 = await messageWindow(peer, options2);
173724
- if (!window2.chat)
173730
+ if (!window2.chat) {
173731
+ releaseActiveWindow();
173725
173732
  return { chat: null, messages: [] };
173733
+ }
173734
+ let retained = false;
173726
173735
  try {
173727
173736
  const { runtime, session, chat, messages } = window2;
173728
173737
  const lastPeer = [...messages].reverse().find((message) => isPeerMsg(message, session.chatPK));
173729
173738
  if (lastPeer)
173730
173739
  await runtime.chat.getSnapshot().markChatReadReceipt(chat.id, lastPeer, { messages });
173740
+ const previousWindow = activeReadWindow;
173741
+ activeReadWindow = window2;
173742
+ retained = true;
173743
+ previousWindow?.release?.();
173731
173744
  return {
173732
173745
  chat: simplifyAccountChat(chat, profileForChat(runtime, chat)),
173733
173746
  messages: messages.map((message) => simplifyAccountMessage(message, chat, session.chatPK, options2)),
@@ -173735,7 +173748,8 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173735
173748
  nextOlderThan: window2.history?.nextOlderThan || null
173736
173749
  };
173737
173750
  } finally {
173738
- window2.release?.();
173751
+ if (!retained)
173752
+ window2.release?.();
173739
173753
  }
173740
173754
  }
173741
173755
  async function markRead(peer, options2 = {}) {
@@ -173758,9 +173772,17 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173758
173772
  }
173759
173773
  }
173760
173774
  async function messageForPeer(peer, messageId, options2 = {}) {
173761
- const window2 = await messageWindow(peer, { ...options2, count: Math.max(positiveLimit2(options2.count, 100), 100), loadOlder: false });
173762
- if (!window2.chat)
173775
+ const { runtime, chat } = await chatForPeer(peer);
173776
+ if (!chat)
173763
173777
  throw new Error("chat not found");
173778
+ const retained = activeReadWindow;
173779
+ if (retained?.runtime === runtime && retained.chat?.id === chat.id) {
173780
+ const message = findByKey(retained.batch?.sourceMessages, messageId) || findByKey(retained.messages, messageId);
173781
+ if (message) {
173782
+ return { ...retained, release: undefined, message, target: getMessageKey(message) || cleanText(messageId) };
173783
+ }
173784
+ }
173785
+ const window2 = await messageWindow(peer, { ...options2, count: Math.max(positiveLimit2(options2.count, 100), 100), loadOlder: false });
173764
173786
  try {
173765
173787
  let message = findByKey(window2.batch?.sourceMessages, messageId) || findByKey(window2.messages, messageId);
173766
173788
  if (!message) {
@@ -173940,6 +173962,9 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173940
173962
  if (!chat)
173941
173963
  return { deleted: false, chat: null };
173942
173964
  const deleted = await runtime.chat.getSnapshot().deleteChat(chat, { cleanup: options2.cleanup !== false });
173965
+ if (deleted === true && activeReadWindow?.runtime === runtime && activeReadWindow.chat?.id === chat.id) {
173966
+ releaseActiveWindow();
173967
+ }
173943
173968
  return { deleted: deleted === true, chat: simplifyAccountChat(chat, profile) };
173944
173969
  }
173945
173970
  async function retention(peer, value) {
@@ -173973,7 +173998,8 @@ function createRuntimeChatActions({ getRuntime, getSession, resolvePeer }) {
173973
173998
  deleteChat,
173974
173999
  retention,
173975
174000
  messageWindow,
173976
- messageForPeer
174001
+ messageForPeer,
174002
+ releaseActiveWindow
173977
174003
  };
173978
174004
  }
173979
174005
  function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }) {
@@ -173993,6 +174019,17 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
173993
174019
  return fees || null;
173994
174020
  return { ...fees, spark: stripRaw(fees.spark, options2) };
173995
174021
  }
174022
+ function summarizePaymentResult(value) {
174023
+ if (!value || typeof value !== "object")
174024
+ return value ?? null;
174025
+ const transfer = value.transfer && typeof value.transfer === "object" ? simplifyAccountTransfer(value.transfer) : null;
174026
+ return {
174027
+ kind: value.kind || null,
174028
+ id: value.id || value.transfer?.id || null,
174029
+ status: value.status || value.transfer?.status || null,
174030
+ transfer
174031
+ };
174032
+ }
173996
174033
  function cleanWithdrawal(withdrawal, options2 = {}) {
173997
174034
  if (!withdrawal)
173998
174035
  return null;
@@ -174100,8 +174137,8 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174100
174137
  return {
174101
174138
  id: result.result?.id || result.payment?.id || null,
174102
174139
  fees,
174103
- result: stripRaw(result.result, options2),
174104
- raw: options2.raw ? jsonSafe(result.payment) : undefined
174140
+ result: summarizePaymentResult(result.result),
174141
+ raw: options2.raw ? jsonSafe(result) : undefined
174105
174142
  };
174106
174143
  }
174107
174144
  async function lightningReceive(id, options2 = {}) {
@@ -174112,7 +174149,10 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174112
174149
  async function lightningSend(id, options2 = {}) {
174113
174150
  const { snapshot } = await readyWallet();
174114
174151
  const result = throwIfFailed(await snapshot.value.getLightningSendRequest(id), "could not read lightning send request");
174115
- return stripRaw(result.result, options2);
174152
+ return {
174153
+ ...summarizePaymentResult(result.result),
174154
+ raw: options2.raw ? jsonSafe(result.result) : undefined
174155
+ };
174116
174156
  }
174117
174157
  async function payInvoice(value, options2 = {}) {
174118
174158
  const raw = cleanText(value);
@@ -174134,7 +174174,8 @@ function createRuntimeMoneyActions({ getRuntime, getSession, resolvePeer, chat }
174134
174174
  type,
174135
174175
  id: result?.id || result?.result?.id || null,
174136
174176
  fees: result?.fees || null,
174137
- result: stripRaw(result?.result, options2)
174177
+ result: summarizePaymentResult(result?.result),
174178
+ raw: options2.raw ? jsonSafe(result) : undefined
174138
174179
  };
174139
174180
  }
174140
174181
  async function withdrawQuote(onchainAddress, sats, options2 = {}) {
@@ -174824,7 +174865,7 @@ var package_default;
174824
174865
  var init_package = __esm(() => {
174825
174866
  package_default = {
174826
174867
  name: "veyl",
174827
- version: "0.31.0",
174868
+ version: "0.31.1",
174828
174869
  private: true,
174829
174870
  license: "Apache-2.0",
174830
174871
  workspaces: {
@@ -175264,6 +175305,7 @@ class VeylHeadlessClient {
175264
175305
  }
175265
175306
  async createAccount(options2 = {}) {
175266
175307
  const username = cleanUsername3(options2.username);
175308
+ const profileName = this.store.profile || username;
175267
175309
  const network = String(options2.network || this.network).toUpperCase();
175268
175310
  const termsVersion = requireCurrentTermsVersion(options2.termsVersion);
175269
175311
  const machine = options2.credential || createMachineCredential();
@@ -175279,7 +175321,7 @@ class VeylHeadlessClient {
175279
175321
  await signInHeadless(this.auth, finish.token);
175280
175322
  this.autoLogin = true;
175281
175323
  const profile = await this.saveProfile({
175282
- profile: username,
175324
+ profile: profileName,
175283
175325
  username,
175284
175326
  uid: finish.uid,
175285
175327
  network,
@@ -175299,7 +175341,7 @@ class VeylHeadlessClient {
175299
175341
  }
175300
175342
  async loginAccount(options2 = {}) {
175301
175343
  const username = cleanOptionalUsername(options2.username);
175302
- const profile = await this.loadProfile(username);
175344
+ const profile = await this.loadProfile(this.store.profile || username);
175303
175345
  const credentialId = options2.credentialId || profile.credentialId;
175304
175346
  const privateKeyPem = options2.privateKeyPem || profile.privateKeyPem;
175305
175347
  if (!credentialId || !privateKeyPem) {
@@ -175338,6 +175380,7 @@ class VeylHeadlessClient {
175338
175380
  }
175339
175381
  async createPasskeyAccount(options2 = {}) {
175340
175382
  const username = cleanUsername3(options2.username);
175383
+ const profileName = this.store.profile || username;
175341
175384
  const network = String(options2.network || this.network).toUpperCase();
175342
175385
  const termsVersion = requireCurrentTermsVersion(options2.termsVersion);
175343
175386
  const flow = await runPasskeyBrowserFlow({
@@ -175354,7 +175397,7 @@ class VeylHeadlessClient {
175354
175397
  const machine = options2.credential || createMachineCredential();
175355
175398
  const credential = machine ? await this.addMachineCredential(machine) : null;
175356
175399
  const profile = await this.saveProfile({
175357
- profile: username,
175400
+ profile: profileName,
175358
175401
  username,
175359
175402
  uid: user.uid,
175360
175403
  network,
@@ -175374,7 +175417,7 @@ class VeylHeadlessClient {
175374
175417
  }
175375
175418
  async loginPasskeyAccount(options2 = {}) {
175376
175419
  const requested = cleanOptionalUsername(options2.username);
175377
- const stored = requested ? await this.store.load(requested) : await this.store.load();
175420
+ const stored = await this.store.load(this.store.profile || requested);
175378
175421
  const flow = await runPasskeyBrowserFlow({
175379
175422
  mode: "login",
175380
175423
  uid: options2.uid || stored?.uid,
@@ -175390,7 +175433,7 @@ class VeylHeadlessClient {
175390
175433
  const credential = machine ? await this.addMachineCredential(machine) : null;
175391
175434
  const profile = await this.saveProfile({
175392
175435
  ...stored || {},
175393
- profile: username || stored?.profile || user.uid,
175436
+ profile: this.store.profile || stored?.profile || username || user.uid,
175394
175437
  username: username || stored?.username || null,
175395
175438
  uid: user.uid,
175396
175439
  network: String(stored?.network || options2.network || this.network).toUpperCase(),
@@ -175699,6 +175742,7 @@ class VeylHeadlessClient {
175699
175742
  }
175700
175743
  closeVaultSession() {
175701
175744
  const session = this.session;
175745
+ this.runtimeChat.releaseActiveWindow();
175702
175746
  this.session = null;
175703
175747
  this.runtime = null;
175704
175748
  closeAccountSession(session);
package/package.json CHANGED
@@ -32,5 +32,5 @@
32
32
  "start": "node src/cli.js",
33
33
  "lint": "eslint src --quiet"
34
34
  },
35
- "version": "0.31.0"
35
+ "version": "0.31.1"
36
36
  }