@haex-space/vault-sdk 3.1.0 → 3.2.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.
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 +212 -24
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +209 -25
  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 +205 -23
  18. package/dist/react.js.map +1 -1
  19. package/dist/react.mjs +205 -23
  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 +205 -27
  24. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  25. package/dist/runtime/nuxt.plugin.client.mjs +205 -27
  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 +205 -23
  30. package/dist/svelte.js.map +1 -1
  31. package/dist/svelte.mjs +205 -23
  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 +205 -23
  42. package/dist/vue.js.map +1 -1
  43. package/dist/vue.mjs +205 -23
  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() === "") {
@@ -1938,7 +2111,7 @@ async function initIframeMode(ctx, log, messageHandler, request) {
1938
2111
  publicKey: ctx.config.manifest.publicKey,
1939
2112
  name: ctx.config.manifest.name,
1940
2113
  version: ctx.config.manifest.version,
1941
- displayName: ctx.config.manifest.name
2114
+ displayName: ctx.config.manifest.displayName ?? ctx.config.manifest.name
1942
2115
  };
1943
2116
  log("Extension info loaded from manifest:", ctx.state.extensionInfo);
1944
2117
  }
@@ -2129,11 +2302,10 @@ function processEvent(event, log, eventListeners, onContextChanged, onExternalRe
2129
2302
  emitEvent(event, log, eventListeners);
2130
2303
  }
2131
2304
  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);
2305
+ log("emitEvent called with:", event.type, event);
2306
+ log("Registered event types:", Array.from(eventListeners.keys()));
2135
2307
  const listeners = eventListeners.get(event.type);
2136
- console.log("[HaexVault SDK] Listeners for", event.type, ":", listeners?.size ?? 0);
2308
+ log("Listeners for", event.type, ":", listeners?.size ?? 0);
2137
2309
  if (listeners) {
2138
2310
  listeners.forEach((callback) => callback(event));
2139
2311
  }
@@ -2230,9 +2402,9 @@ function registerExternalHandler(action, handler, handlers, log) {
2230
2402
  };
2231
2403
  }
2232
2404
  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()));
2405
+ log("handleExternalRequest called");
2406
+ log("Request:", request);
2407
+ log("Available handlers:", Array.from(handlers.keys()));
2236
2408
  log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
2237
2409
  const handler = handlers.get(request.action);
2238
2410
  if (!handler) {
@@ -2258,7 +2430,6 @@ async function handleExternalRequest(request, handlers, respond, log) {
2258
2430
  }
2259
2431
  }
2260
2432
  async function respondToExternalRequest(response, request) {
2261
- console.log("[SDK Debug] respondToExternalRequest called with:", JSON.stringify(response, null, 2));
2262
2433
  await request(EXTERNAL_BRIDGE_COMMANDS.respond, response);
2263
2434
  }
2264
2435
 
@@ -2316,11 +2487,17 @@ var HaexVaultSdk = class {
2316
2487
  this.localsend = new LocalSendAPI(this);
2317
2488
  this.spaces = new SpacesAPI(this);
2318
2489
  this.shell = new ShellAPI(this);
2490
+ this.passwords = new PasswordsAPI(this);
2491
+ this.mail = new MailAPI(this);
2319
2492
  installConsoleForwarding(this.config.debug);
2320
- this.readyPromise = new Promise((resolve) => {
2493
+ this.readyPromise = new Promise((resolve, reject) => {
2321
2494
  this.resolveReady = resolve;
2495
+ this.rejectReady = reject;
2496
+ });
2497
+ this.init().catch((error) => {
2498
+ this.log("Init failed:", error);
2499
+ this.rejectReady(error);
2322
2500
  });
2323
- this.init();
2324
2501
  }
2325
2502
  // ==========================================================================
2326
2503
  // Lifecycle
@@ -2348,9 +2525,14 @@ var HaexVaultSdk = class {
2348
2525
  return this.setupPromise;
2349
2526
  }
2350
2527
  destroy() {
2351
- if (this.messageHandler) {
2352
- window.removeEventListener("message", this.messageHandler);
2528
+ if (this.messageHandler && this.hostPort) {
2529
+ this.hostPort.removeEventListener("message", this.messageHandler);
2530
+ }
2531
+ if (this.hostPort) {
2532
+ this.hostPort.close();
2533
+ this.hostPort = null;
2353
2534
  }
2535
+ this.messageHandler = null;
2354
2536
  this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
2355
2537
  this.pendingRequests.clear();
2356
2538
  this.eventListeners.clear();
@@ -2578,7 +2760,7 @@ var HaexVaultSdk = class {
2578
2760
  publicKey: this.config.manifest.publicKey,
2579
2761
  name: this.config.manifest.name,
2580
2762
  version: this.config.manifest.version,
2581
- displayName: this.config.manifest.name
2763
+ displayName: this.config.manifest.displayName ?? this.config.manifest.name
2582
2764
  };
2583
2765
  this.notifySubscribersInternal();
2584
2766
  }