@haex-space/vault-sdk 3.1.0 → 3.2.2

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 (45) hide show
  1. package/dist/{client-C0DPNG62.d.mts → client-GeColu97.d.mts} +263 -2
  2. package/dist/{client-B_B6rLIw.d.ts → client-z1jTcuQE.d.ts} +263 -2
  3. package/dist/index.d.mts +76 -6
  4. package/dist/index.d.ts +76 -6
  5. package/dist/index.js +244 -47
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +241 -48
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/node.d.mts +1 -1
  10. package/dist/node.d.ts +1 -1
  11. package/dist/nuxt.js +16 -6
  12. package/dist/nuxt.js.map +1 -1
  13. package/dist/nuxt.mjs +16 -6
  14. package/dist/nuxt.mjs.map +1 -1
  15. package/dist/react.d.mts +2 -2
  16. package/dist/react.d.ts +2 -2
  17. package/dist/react.js +237 -46
  18. package/dist/react.js.map +1 -1
  19. package/dist/react.mjs +237 -46
  20. package/dist/react.mjs.map +1 -1
  21. package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
  22. package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
  23. package/dist/runtime/nuxt.plugin.client.js +237 -50
  24. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  25. package/dist/runtime/nuxt.plugin.client.mjs +237 -50
  26. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  27. package/dist/svelte.d.mts +2 -2
  28. package/dist/svelte.d.ts +2 -2
  29. package/dist/svelte.js +237 -46
  30. package/dist/svelte.js.map +1 -1
  31. package/dist/svelte.mjs +237 -46
  32. package/dist/svelte.mjs.map +1 -1
  33. package/dist/{types-DmCSegdY.d.mts → types-CDMBvvjl.d.mts} +2 -0
  34. package/dist/{types-DmCSegdY.d.ts → types-CDMBvvjl.d.ts} +2 -0
  35. package/dist/vite.js +15 -5
  36. package/dist/vite.js.map +1 -1
  37. package/dist/vite.mjs +15 -5
  38. package/dist/vite.mjs.map +1 -1
  39. package/dist/vue.d.mts +2 -2
  40. package/dist/vue.d.ts +2 -2
  41. package/dist/vue.js +237 -46
  42. package/dist/vue.js.map +1 -1
  43. package/dist/vue.mjs +237 -46
  44. package/dist/vue.mjs.map +1 -1
  45. package/package.json +1 -1
package/dist/svelte.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk, S as StorageAPI } from './client-C0DPNG62.mjs';
1
+ import { H as HaexVaultSdk, S as StorageAPI } from './client-GeColu97.mjs';
2
2
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
3
3
  import { Readable } from 'svelte/store';
4
- import { A as ApplicationContext, a as ExtensionInfo, H as HaexHubConfig } from './types-DmCSegdY.mjs';
4
+ import { A as ApplicationContext, a as ExtensionInfo, H as HaexHubConfig } from './types-CDMBvvjl.mjs';
5
5
 
6
6
  /**
7
7
  * Initialize the HaexVault SDK for Svelte
package/dist/svelte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk, S as StorageAPI } from './client-B_B6rLIw.js';
1
+ import { H as HaexVaultSdk, S as StorageAPI } from './client-z1jTcuQE.js';
2
2
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
3
3
  import { Readable } from 'svelte/store';
4
- import { A as ApplicationContext, a as ExtensionInfo, H as HaexHubConfig } from './types-DmCSegdY.js';
4
+ import { A as ApplicationContext, a as ExtensionInfo, H as HaexHubConfig } from './types-CDMBvvjl.js';
5
5
 
6
6
  /**
7
7
  * Initialize the HaexVault SDK for Svelte
package/dist/svelte.js CHANGED
@@ -650,6 +650,40 @@ var SHELL_COMMANDS = {
650
650
  close: "extension_shell_close"
651
651
  };
652
652
 
653
+ // src/commands/passwords.ts
654
+ var PASSWORD_COMMANDS = {
655
+ /** List items (no secrets) within the extension's tag scope */
656
+ list: "extension_password_list",
657
+ /** Read full item including secrets, by id */
658
+ read: "extension_password_read",
659
+ /** Create item — must include >=1 tag in scope */
660
+ create: "extension_password_create",
661
+ /** Update item — keeps >=1 tag in scope */
662
+ update: "extension_password_update",
663
+ /** Delete item — must be in scope */
664
+ delete: "extension_password_delete"
665
+ };
666
+
667
+ // src/commands/mail.ts
668
+ var MAIL_COMMANDS = {
669
+ /** LIST mailboxes + optional STATUS counts */
670
+ listMailboxes: "extension_mail_list_mailboxes",
671
+ /** Lightweight envelope fetch for list views */
672
+ fetchEnvelopes: "extension_mail_fetch_envelopes",
673
+ /** Full message fetch (envelope + body + attachment metadata) */
674
+ fetchMessage: "extension_mail_fetch_message",
675
+ /** Set or unset IMAP flags on a UID set */
676
+ setFlags: "extension_mail_set_flags",
677
+ /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
678
+ moveMessages: "extension_mail_move_messages",
679
+ /** APPEND a base64-encoded RFC822 message into a mailbox */
680
+ appendMessage: "extension_mail_append_message",
681
+ /** SMTP send. Returns the assigned Message-ID. */
682
+ sendMessage: "extension_mail_send_message",
683
+ /** Build RFC822 bytes without sending (for Drafts via APPEND) */
684
+ buildRfc822: "extension_mail_build_rfc822"
685
+ };
686
+
653
687
  // src/api/storage.ts
654
688
  var StorageAPI = class {
655
689
  constructor(client) {
@@ -673,6 +707,12 @@ var StorageAPI = class {
673
707
  };
674
708
 
675
709
  // src/api/database.ts
710
+ function quoteIdent(identifier) {
711
+ if (identifier.startsWith('"') && identifier.endsWith('"')) {
712
+ return identifier;
713
+ }
714
+ return `"${identifier.replace(/"/g, '""')}"`;
715
+ }
676
716
  var DatabaseAPI = class {
677
717
  constructor(client) {
678
718
  this.client = client;
@@ -703,11 +743,11 @@ var DatabaseAPI = class {
703
743
  });
704
744
  }
705
745
  async createTable(tableName, columns) {
706
- const query = `CREATE TABLE IF NOT EXISTS ${tableName} (${columns})`;
746
+ const query = `CREATE TABLE IF NOT EXISTS ${quoteIdent(tableName)} (${columns})`;
707
747
  await this.execute(query);
708
748
  }
709
749
  async dropTable(tableName) {
710
- const query = `DROP TABLE IF EXISTS ${tableName}`;
750
+ const query = `DROP TABLE IF EXISTS ${quoteIdent(tableName)}`;
711
751
  await this.execute(query);
712
752
  }
713
753
  /**
@@ -736,18 +776,17 @@ var DatabaseAPI = class {
736
776
  async insert(tableName, data) {
737
777
  const keys = Object.keys(data);
738
778
  const values = Object.values(data);
779
+ const quotedCols = keys.map(quoteIdent).join(", ");
739
780
  const placeholders = keys.map(() => "?").join(", ");
740
- const query = `INSERT INTO ${tableName} (${keys.join(
741
- ", "
742
- )}) VALUES (${placeholders})`;
781
+ const query = `INSERT INTO ${quoteIdent(tableName)} (${quotedCols}) VALUES (${placeholders})`;
743
782
  const result = await this.execute(query, values);
744
783
  return result.lastInsertId ?? -1;
745
784
  }
746
785
  async update(tableName, data, where, whereParams) {
747
786
  const keys = Object.keys(data);
748
787
  const values = Object.values(data);
749
- const setClause = keys.map((key) => `${key} = ?`).join(", ");
750
- const query = `UPDATE ${tableName} SET ${setClause} WHERE ${where}`;
788
+ const setClause = keys.map((key) => `${quoteIdent(key)} = ?`).join(", ");
789
+ const query = `UPDATE ${quoteIdent(tableName)} SET ${setClause} WHERE ${where}`;
751
790
  const result = await this.execute(query, [
752
791
  ...values,
753
792
  ...whereParams || []
@@ -755,12 +794,12 @@ var DatabaseAPI = class {
755
794
  return result.rowsAffected;
756
795
  }
757
796
  async delete(tableName, where, whereParams) {
758
- const query = `DELETE FROM ${tableName} WHERE ${where}`;
797
+ const query = `DELETE FROM ${quoteIdent(tableName)} WHERE ${where}`;
759
798
  const result = await this.execute(query, whereParams);
760
799
  return result.rowsAffected;
761
800
  }
762
801
  async count(tableName, where, whereParams) {
763
- const query = where ? `SELECT COUNT(*) as count FROM ${tableName} WHERE ${where}` : `SELECT COUNT(*) as count FROM ${tableName}`;
802
+ const query = where ? `SELECT COUNT(*) as count FROM ${quoteIdent(tableName)} WHERE ${where}` : `SELECT COUNT(*) as count FROM ${quoteIdent(tableName)}`;
764
803
  const result = await this.queryOne(query, whereParams);
765
804
  return result?.count ?? 0;
766
805
  }
@@ -1582,6 +1621,140 @@ var ShellAPI = class {
1582
1621
  }
1583
1622
  };
1584
1623
 
1624
+ // src/api/passwords.ts
1625
+ var PasswordsAPI = class {
1626
+ constructor(client) {
1627
+ this.client = client;
1628
+ }
1629
+ /** List items in scope — summaries only, no secrets. */
1630
+ async listAsync() {
1631
+ return this.client.request(
1632
+ PASSWORD_COMMANDS.list,
1633
+ {}
1634
+ );
1635
+ }
1636
+ /** Read a single item by id with full secrets. */
1637
+ async readAsync(itemId) {
1638
+ return this.client.request(PASSWORD_COMMANDS.read, {
1639
+ itemId
1640
+ });
1641
+ }
1642
+ /**
1643
+ * Create a new password item. `input.tags` must contain at least one
1644
+ * tag within the extension's permission scope, otherwise the write
1645
+ * is rejected as a security violation.
1646
+ *
1647
+ * Returns the new item id.
1648
+ */
1649
+ async createAsync(input) {
1650
+ return this.client.request(PASSWORD_COMMANDS.create, { input });
1651
+ }
1652
+ /**
1653
+ * Update an existing item. The item must already be in scope, and
1654
+ * the new tag set must keep at least one tag in scope (extensions
1655
+ * cannot orphan an item out of their own reach).
1656
+ */
1657
+ async updateAsync(itemId, input) {
1658
+ return this.client.request(PASSWORD_COMMANDS.update, {
1659
+ itemId,
1660
+ input
1661
+ });
1662
+ }
1663
+ /** Delete an item by id. Item must be in scope. */
1664
+ async deleteAsync(itemId) {
1665
+ return this.client.request(PASSWORD_COMMANDS.delete, { itemId });
1666
+ }
1667
+ };
1668
+
1669
+ // src/api/mail.ts
1670
+ var MailAPI = class {
1671
+ constructor(client) {
1672
+ this.client = client;
1673
+ }
1674
+ /**
1675
+ * LIST mailboxes for an IMAP account. Pass `includeStatus=true` for
1676
+ * EXISTS/UNSEEN/UIDVALIDITY/UIDNEXT per box (one extra round-trip
1677
+ * per mailbox — fine for typical accounts, expensive for large
1678
+ * trees).
1679
+ */
1680
+ async listMailboxesAsync(imap, options = {}) {
1681
+ return this.client.request(MAIL_COMMANDS.listMailboxes, {
1682
+ imap,
1683
+ reference: options.reference,
1684
+ pattern: options.pattern,
1685
+ includeStatus: options.includeStatus
1686
+ });
1687
+ }
1688
+ /** Fetch lightweight envelopes for a mailbox + range (for list views). */
1689
+ async fetchEnvelopesAsync(imap, mailbox, range) {
1690
+ return this.client.request(
1691
+ MAIL_COMMANDS.fetchEnvelopes,
1692
+ { imap, mailbox, range }
1693
+ );
1694
+ }
1695
+ /** Fetch a full message (envelope + body + attachment metadata) by UID. */
1696
+ async fetchMessageAsync(imap, mailbox, uid) {
1697
+ return this.client.request(MAIL_COMMANDS.fetchMessage, {
1698
+ imap,
1699
+ mailbox,
1700
+ uid
1701
+ });
1702
+ }
1703
+ /**
1704
+ * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
1705
+ * mark messages as read; `add=false` removes the flag(s).
1706
+ */
1707
+ async setFlagsAsync(imap, mailbox, uids, flags, add) {
1708
+ return this.client.request(MAIL_COMMANDS.setFlags, {
1709
+ imap,
1710
+ mailbox,
1711
+ uids,
1712
+ flags,
1713
+ add
1714
+ });
1715
+ }
1716
+ /** Move messages between mailboxes. Falls back to COPY+EXPUNGE on servers without MOVE. */
1717
+ async moveMessagesAsync(imap, sourceMailbox, destinationMailbox, uids) {
1718
+ return this.client.request(MAIL_COMMANDS.moveMessages, {
1719
+ imap,
1720
+ sourceMailbox,
1721
+ destinationMailbox,
1722
+ uids
1723
+ });
1724
+ }
1725
+ /**
1726
+ * APPEND a base64-encoded RFC822 message into a mailbox. Combine
1727
+ * with `buildRfc822Async` to save drafts, or with the bytes returned
1728
+ * after `sendMessageAsync` to mirror the sent copy into "Sent".
1729
+ */
1730
+ async appendMessageAsync(imap, mailbox, rfc822Base64, flags) {
1731
+ return this.client.request(MAIL_COMMANDS.appendMessage, {
1732
+ imap,
1733
+ mailbox,
1734
+ rfc822Base64,
1735
+ flags
1736
+ });
1737
+ }
1738
+ /** Send a message via SMTP. Returns the assigned Message-ID (no angle brackets). */
1739
+ async sendMessageAsync(smtp, message) {
1740
+ return this.client.request(MAIL_COMMANDS.sendMessage, {
1741
+ smtp,
1742
+ message
1743
+ });
1744
+ }
1745
+ /**
1746
+ * Build RFC822 bytes for a message without sending — useful for
1747
+ * drafts that get APPENDed to a "Drafts" folder. Permission-wise
1748
+ * this is a fetch operation (no SMTP host involved).
1749
+ */
1750
+ async buildRfc822Async(imapHost, message) {
1751
+ return this.client.request(MAIL_COMMANDS.buildRfc822, {
1752
+ imapHost,
1753
+ message
1754
+ });
1755
+ }
1756
+ };
1757
+
1585
1758
  // src/client/tableName.ts
1586
1759
  function validatePublicKey(publicKey) {
1587
1760
  if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
@@ -1669,6 +1842,10 @@ function parseTableName(fullTableName) {
1669
1842
 
1670
1843
  // src/client/init.ts
1671
1844
  var PORT_HANDSHAKE_TIMEOUT_MS = 1e4;
1845
+ function getCurrentWebviewLabel() {
1846
+ const internals = window.__TAURI_INTERNALS__;
1847
+ return internals?.metadata?.currentWebview?.label;
1848
+ }
1672
1849
  function isInIframe() {
1673
1850
  return window.self !== window.top;
1674
1851
  }
@@ -1697,6 +1874,13 @@ async function initNativeMode(ctx, log, onEvent, onContextChange) {
1697
1874
  }
1698
1875
  async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1699
1876
  const { listen } = getTauriEvent();
1877
+ const webviewLabel = getCurrentWebviewLabel();
1878
+ const listenOptions = webviewLabel ? { target: webviewLabel } : void 0;
1879
+ if (!webviewLabel) {
1880
+ log(
1881
+ "WARNING: could not read __TAURI_INTERNALS__.metadata.currentWebview.label \u2014 registering listeners without a target. Label-scoped emits from the host will not be delivered until the metadata is available."
1882
+ );
1883
+ }
1700
1884
  log("Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
1701
1885
  try {
1702
1886
  await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
@@ -1714,7 +1898,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1714
1898
  } else {
1715
1899
  log("Event received but no context in payload:", event);
1716
1900
  }
1717
- });
1901
+ }, listenOptions);
1718
1902
  log("Context change listener registered successfully");
1719
1903
  } catch (error) {
1720
1904
  log("Failed to setup context change listener:", error);
@@ -1732,7 +1916,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1732
1916
  } else {
1733
1917
  log("External request event has no payload!");
1734
1918
  }
1735
- });
1919
+ }, listenOptions);
1736
1920
  log("External request listener registered successfully");
1737
1921
  } catch (error) {
1738
1922
  log("Failed to setup external request listener:", error);
@@ -1750,7 +1934,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1750
1934
  } else {
1751
1935
  log("AI action request event has no payload!");
1752
1936
  }
1753
- });
1937
+ }, listenOptions);
1754
1938
  log("AI action request listener registered successfully");
1755
1939
  } catch (error) {
1756
1940
  log("Failed to setup AI action request listener:", error);
@@ -1769,7 +1953,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1769
1953
  timestamp: Date.now()
1770
1954
  });
1771
1955
  }
1772
- });
1956
+ }, listenOptions);
1773
1957
  log("File change listener registered successfully");
1774
1958
  } catch (error) {
1775
1959
  log("Failed to setup file change listener:", error);
@@ -1786,14 +1970,14 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1786
1970
  timestamp: Date.now()
1787
1971
  });
1788
1972
  }
1789
- });
1973
+ }, listenOptions);
1790
1974
  log("Sync tables updated listener registered successfully");
1791
1975
  } catch (error) {
1792
1976
  log("Failed to setup sync tables updated listener:", error);
1793
1977
  }
1794
1978
  log("Setting up LocalSend event listeners");
1795
1979
  try {
1796
- await setupLocalSendEventListeners(log, onEvent);
1980
+ await setupLocalSendEventListeners(log, onEvent, listenOptions);
1797
1981
  log("LocalSend event listeners setup complete");
1798
1982
  } catch (error) {
1799
1983
  log("Failed to setup LocalSend event listeners:", error);
@@ -1810,7 +1994,7 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1810
1994
  data: payload.data
1811
1995
  });
1812
1996
  }
1813
- });
1997
+ }, listenOptions);
1814
1998
  log("Shell output listener registered");
1815
1999
  await listen(SHELL_EVENTS.EXIT, (event) => {
1816
2000
  if (event.payload) {
@@ -1822,13 +2006,13 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
1822
2006
  exitCode: payload.exitCode
1823
2007
  });
1824
2008
  }
1825
- });
2009
+ }, listenOptions);
1826
2010
  log("Shell exit listener registered");
1827
2011
  } catch (error) {
1828
2012
  log("Failed to setup Shell event listeners:", error);
1829
2013
  }
1830
2014
  }
1831
- async function setupLocalSendEventListeners(log, onEvent) {
2015
+ async function setupLocalSendEventListeners(log, onEvent, listenOptions) {
1832
2016
  const { listen } = getTauriEvent();
1833
2017
  try {
1834
2018
  await listen(LOCALSEND_EVENTS.deviceDiscovered, (event) => {
@@ -1840,7 +2024,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1840
2024
  timestamp: Date.now()
1841
2025
  });
1842
2026
  }
1843
- });
2027
+ }, listenOptions);
1844
2028
  log("LocalSend device discovered listener registered");
1845
2029
  } catch (error) {
1846
2030
  log("Failed to setup LocalSend device discovered listener:", error);
@@ -1855,7 +2039,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1855
2039
  timestamp: Date.now()
1856
2040
  });
1857
2041
  }
1858
- });
2042
+ }, listenOptions);
1859
2043
  log("LocalSend device lost listener registered");
1860
2044
  } catch (error) {
1861
2045
  log("Failed to setup LocalSend device lost listener:", error);
@@ -1870,7 +2054,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1870
2054
  timestamp: Date.now()
1871
2055
  });
1872
2056
  }
1873
- });
2057
+ }, listenOptions);
1874
2058
  log("LocalSend transfer request listener registered");
1875
2059
  } catch (error) {
1876
2060
  log("Failed to setup LocalSend transfer request listener:", error);
@@ -1885,7 +2069,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1885
2069
  timestamp: Date.now()
1886
2070
  });
1887
2071
  }
1888
- });
2072
+ }, listenOptions);
1889
2073
  log("LocalSend transfer progress listener registered");
1890
2074
  } catch (error) {
1891
2075
  log("Failed to setup LocalSend transfer progress listener:", error);
@@ -1900,7 +2084,7 @@ async function setupLocalSendEventListeners(log, onEvent) {
1900
2084
  timestamp: Date.now()
1901
2085
  });
1902
2086
  }
1903
- });
2087
+ }, listenOptions);
1904
2088
  log("LocalSend transfer complete listener registered");
1905
2089
  } catch (error) {
1906
2090
  log("Failed to setup LocalSend transfer complete listener:", error);
@@ -1915,13 +2099,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
1915
2099
  timestamp: Date.now()
1916
2100
  });
1917
2101
  }
1918
- });
2102
+ }, listenOptions);
1919
2103
  log("LocalSend transfer failed listener registered");
1920
2104
  } catch (error) {
1921
2105
  log("Failed to setup LocalSend transfer failed listener:", error);
1922
2106
  }
1923
2107
  }
1924
- async function initIframeMode(ctx, log, messageHandler, request) {
2108
+ async function initIframeMode(ctx, log, messageHandler) {
1925
2109
  if (!isInIframe()) {
1926
2110
  throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
1927
2111
  }
@@ -1938,15 +2122,12 @@ async function initIframeMode(ctx, log, messageHandler, request) {
1938
2122
  publicKey: ctx.config.manifest.publicKey,
1939
2123
  name: ctx.config.manifest.name,
1940
2124
  version: ctx.config.manifest.version,
1941
- displayName: ctx.config.manifest.name
2125
+ displayName: ctx.config.manifest.displayName ?? ctx.config.manifest.name
1942
2126
  };
1943
2127
  log("Extension info loaded from manifest:", ctx.state.extensionInfo);
1944
2128
  }
1945
2129
  sendDebugInfo(ctx.config);
1946
- const context2 = await request(EXTENSION_COMMANDS.getContext);
1947
- ctx.state.context = context2;
1948
- log("Application context received:", context2);
1949
- return { context: context2, port };
2130
+ return port;
1950
2131
  }
1951
2132
  function waitForHostPortAsync(log) {
1952
2133
  return new Promise((resolve, reject) => {
@@ -2129,11 +2310,10 @@ function processEvent(event, log, eventListeners, onContextChanged, onExternalRe
2129
2310
  emitEvent(event, log, eventListeners);
2130
2311
  }
2131
2312
  function emitEvent(event, log, eventListeners) {
2132
- console.log("[HaexVault SDK] emitEvent called with:", event.type, event);
2133
- console.log("[HaexVault SDK] Registered event types:", Array.from(eventListeners.keys()));
2134
- log("Event received:", event);
2313
+ log("emitEvent called with:", event.type, event);
2314
+ log("Registered event types:", Array.from(eventListeners.keys()));
2135
2315
  const listeners = eventListeners.get(event.type);
2136
- console.log("[HaexVault SDK] Listeners for", event.type, ":", listeners?.size ?? 0);
2316
+ log("Listeners for", event.type, ":", listeners?.size ?? 0);
2137
2317
  if (listeners) {
2138
2318
  listeners.forEach((callback) => callback(event));
2139
2319
  }
@@ -2230,9 +2410,9 @@ function registerExternalHandler(action, handler, handlers, log) {
2230
2410
  };
2231
2411
  }
2232
2412
  async function handleExternalRequest(request, handlers, respond, log) {
2233
- console.log("[SDK Debug] handleExternalRequest called!");
2234
- console.log("[SDK Debug] Request:", JSON.stringify(request, null, 2));
2235
- console.log("[SDK Debug] Available handlers:", Array.from(handlers.keys()));
2413
+ log("handleExternalRequest called");
2414
+ log("Request:", request);
2415
+ log("Available handlers:", Array.from(handlers.keys()));
2236
2416
  log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
2237
2417
  const handler = handlers.get(request.action);
2238
2418
  if (!handler) {
@@ -2258,7 +2438,6 @@ async function handleExternalRequest(request, handlers, respond, log) {
2258
2438
  }
2259
2439
  }
2260
2440
  async function respondToExternalRequest(response, request) {
2261
- console.log("[SDK Debug] respondToExternalRequest called with:", JSON.stringify(response, null, 2));
2262
2441
  await request(EXTERNAL_BRIDGE_COMMANDS.respond, response);
2263
2442
  }
2264
2443
 
@@ -2316,11 +2495,17 @@ var HaexVaultSdk = class {
2316
2495
  this.localsend = new LocalSendAPI(this);
2317
2496
  this.spaces = new SpacesAPI(this);
2318
2497
  this.shell = new ShellAPI(this);
2498
+ this.passwords = new PasswordsAPI(this);
2499
+ this.mail = new MailAPI(this);
2319
2500
  installConsoleForwarding(this.config.debug);
2320
- this.readyPromise = new Promise((resolve) => {
2501
+ this.readyPromise = new Promise((resolve, reject) => {
2321
2502
  this.resolveReady = resolve;
2503
+ this.rejectReady = reject;
2504
+ });
2505
+ this.init().catch((error) => {
2506
+ this.log("Init failed:", error);
2507
+ this.rejectReady(error);
2322
2508
  });
2323
- this.init();
2324
2509
  }
2325
2510
  // ==========================================================================
2326
2511
  // Lifecycle
@@ -2348,9 +2533,14 @@ var HaexVaultSdk = class {
2348
2533
  return this.setupPromise;
2349
2534
  }
2350
2535
  destroy() {
2351
- if (this.messageHandler) {
2352
- window.removeEventListener("message", this.messageHandler);
2536
+ if (this.messageHandler && this.hostPort) {
2537
+ this.hostPort.removeEventListener("message", this.messageHandler);
2353
2538
  }
2539
+ if (this.hostPort) {
2540
+ this.hostPort.close();
2541
+ this.hostPort = null;
2542
+ }
2543
+ this.messageHandler = null;
2354
2544
  this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
2355
2545
  this.pendingRequests.clear();
2356
2546
  this.eventListeners.clear();
@@ -2540,7 +2730,7 @@ var HaexVaultSdk = class {
2540
2730
  () => this._extensionInfo,
2541
2731
  this.handleEvent.bind(this)
2542
2732
  );
2543
- const { context: context2, port } = await initIframeMode(
2733
+ const port = await initIframeMode(
2544
2734
  {
2545
2735
  config: this.config,
2546
2736
  state: {
@@ -2569,8 +2759,7 @@ var HaexVaultSdk = class {
2569
2759
  }
2570
2760
  },
2571
2761
  this.log.bind(this),
2572
- this.messageHandler,
2573
- this.request.bind(this)
2762
+ this.messageHandler
2574
2763
  );
2575
2764
  this.hostPort = port;
2576
2765
  if (this.config.manifest) {
@@ -2578,10 +2767,12 @@ var HaexVaultSdk = class {
2578
2767
  publicKey: this.config.manifest.publicKey,
2579
2768
  name: this.config.manifest.name,
2580
2769
  version: this.config.manifest.version,
2581
- displayName: this.config.manifest.name
2770
+ displayName: this.config.manifest.displayName ?? this.config.manifest.name
2582
2771
  };
2583
2772
  this.notifySubscribersInternal();
2584
2773
  }
2774
+ const context2 = await this.request(EXTENSION_COMMANDS.getContext);
2775
+ this.log("Application context received:", context2);
2585
2776
  this._context = context2;
2586
2777
  this.isNativeWindow = false;
2587
2778
  this.initialized = true;