@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
@@ -1,7 +1,7 @@
1
1
  import * as nuxt_app from 'nuxt/app';
2
2
  import { ShallowRef } from 'vue';
3
- import { H as HaexVaultSdk } from '../client-C0DPNG62.mjs';
4
- import { A as ApplicationContext } from '../types-DmCSegdY.mjs';
3
+ import { H as HaexVaultSdk } from '../client-GeColu97.mjs';
4
+ import { A as ApplicationContext } from '../types-CDMBvvjl.mjs';
5
5
  import 'drizzle-orm/sqlite-proxy';
6
6
 
7
7
  declare const _default: nuxt_app.Plugin<{
@@ -1,7 +1,7 @@
1
1
  import * as nuxt_app from 'nuxt/app';
2
2
  import { ShallowRef } from 'vue';
3
- import { H as HaexVaultSdk } from '../client-B_B6rLIw.js';
4
- import { A as ApplicationContext } from '../types-DmCSegdY.js';
3
+ import { H as HaexVaultSdk } from '../client-z1jTcuQE.js';
4
+ import { A as ApplicationContext } from '../types-CDMBvvjl.js';
5
5
  import 'drizzle-orm/sqlite-proxy';
6
6
 
7
7
  declare const _default: nuxt_app.Plugin<{
@@ -267,6 +267,40 @@ var SHELL_COMMANDS = {
267
267
  close: "extension_shell_close"
268
268
  };
269
269
 
270
+ // src/commands/passwords.ts
271
+ var PASSWORD_COMMANDS = {
272
+ /** List items (no secrets) within the extension's tag scope */
273
+ list: "extension_password_list",
274
+ /** Read full item including secrets, by id */
275
+ read: "extension_password_read",
276
+ /** Create item — must include >=1 tag in scope */
277
+ create: "extension_password_create",
278
+ /** Update item — keeps >=1 tag in scope */
279
+ update: "extension_password_update",
280
+ /** Delete item — must be in scope */
281
+ delete: "extension_password_delete"
282
+ };
283
+
284
+ // src/commands/mail.ts
285
+ var MAIL_COMMANDS = {
286
+ /** LIST mailboxes + optional STATUS counts */
287
+ listMailboxes: "extension_mail_list_mailboxes",
288
+ /** Lightweight envelope fetch for list views */
289
+ fetchEnvelopes: "extension_mail_fetch_envelopes",
290
+ /** Full message fetch (envelope + body + attachment metadata) */
291
+ fetchMessage: "extension_mail_fetch_message",
292
+ /** Set or unset IMAP flags on a UID set */
293
+ setFlags: "extension_mail_set_flags",
294
+ /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
295
+ moveMessages: "extension_mail_move_messages",
296
+ /** APPEND a base64-encoded RFC822 message into a mailbox */
297
+ appendMessage: "extension_mail_append_message",
298
+ /** SMTP send. Returns the assigned Message-ID. */
299
+ sendMessage: "extension_mail_send_message",
300
+ /** Build RFC822 bytes without sending (for Drafts via APPEND) */
301
+ buildRfc822: "extension_mail_build_rfc822"
302
+ };
303
+
270
304
  // src/api/storage.ts
271
305
  var StorageAPI = class {
272
306
  constructor(client) {
@@ -290,6 +324,12 @@ var StorageAPI = class {
290
324
  };
291
325
 
292
326
  // src/api/database.ts
327
+ function quoteIdent(identifier) {
328
+ if (identifier.startsWith('"') && identifier.endsWith('"')) {
329
+ return identifier;
330
+ }
331
+ return `"${identifier.replace(/"/g, '""')}"`;
332
+ }
293
333
  var DatabaseAPI = class {
294
334
  constructor(client) {
295
335
  this.client = client;
@@ -320,11 +360,11 @@ var DatabaseAPI = class {
320
360
  });
321
361
  }
322
362
  async createTable(tableName, columns) {
323
- const query = `CREATE TABLE IF NOT EXISTS ${tableName} (${columns})`;
363
+ const query = `CREATE TABLE IF NOT EXISTS ${quoteIdent(tableName)} (${columns})`;
324
364
  await this.execute(query);
325
365
  }
326
366
  async dropTable(tableName) {
327
- const query = `DROP TABLE IF EXISTS ${tableName}`;
367
+ const query = `DROP TABLE IF EXISTS ${quoteIdent(tableName)}`;
328
368
  await this.execute(query);
329
369
  }
330
370
  /**
@@ -353,18 +393,17 @@ var DatabaseAPI = class {
353
393
  async insert(tableName, data) {
354
394
  const keys = Object.keys(data);
355
395
  const values = Object.values(data);
396
+ const quotedCols = keys.map(quoteIdent).join(", ");
356
397
  const placeholders = keys.map(() => "?").join(", ");
357
- const query = `INSERT INTO ${tableName} (${keys.join(
358
- ", "
359
- )}) VALUES (${placeholders})`;
398
+ const query = `INSERT INTO ${quoteIdent(tableName)} (${quotedCols}) VALUES (${placeholders})`;
360
399
  const result = await this.execute(query, values);
361
400
  return result.lastInsertId ?? -1;
362
401
  }
363
402
  async update(tableName, data, where, whereParams) {
364
403
  const keys = Object.keys(data);
365
404
  const values = Object.values(data);
366
- const setClause = keys.map((key) => `${key} = ?`).join(", ");
367
- const query = `UPDATE ${tableName} SET ${setClause} WHERE ${where}`;
405
+ const setClause = keys.map((key) => `${quoteIdent(key)} = ?`).join(", ");
406
+ const query = `UPDATE ${quoteIdent(tableName)} SET ${setClause} WHERE ${where}`;
368
407
  const result = await this.execute(query, [
369
408
  ...values,
370
409
  ...whereParams || []
@@ -372,12 +411,12 @@ var DatabaseAPI = class {
372
411
  return result.rowsAffected;
373
412
  }
374
413
  async delete(tableName, where, whereParams) {
375
- const query = `DELETE FROM ${tableName} WHERE ${where}`;
414
+ const query = `DELETE FROM ${quoteIdent(tableName)} WHERE ${where}`;
376
415
  const result = await this.execute(query, whereParams);
377
416
  return result.rowsAffected;
378
417
  }
379
418
  async count(tableName, where, whereParams) {
380
- const query = where ? `SELECT COUNT(*) as count FROM ${tableName} WHERE ${where}` : `SELECT COUNT(*) as count FROM ${tableName}`;
419
+ const query = where ? `SELECT COUNT(*) as count FROM ${quoteIdent(tableName)} WHERE ${where}` : `SELECT COUNT(*) as count FROM ${quoteIdent(tableName)}`;
381
420
  const result = await this.queryOne(query, whereParams);
382
421
  return result?.count ?? 0;
383
422
  }
@@ -1224,6 +1263,140 @@ var ShellAPI = class {
1224
1263
  }
1225
1264
  };
1226
1265
 
1266
+ // src/api/passwords.ts
1267
+ var PasswordsAPI = class {
1268
+ constructor(client) {
1269
+ this.client = client;
1270
+ }
1271
+ /** List items in scope — summaries only, no secrets. */
1272
+ async listAsync() {
1273
+ return this.client.request(
1274
+ PASSWORD_COMMANDS.list,
1275
+ {}
1276
+ );
1277
+ }
1278
+ /** Read a single item by id with full secrets. */
1279
+ async readAsync(itemId) {
1280
+ return this.client.request(PASSWORD_COMMANDS.read, {
1281
+ itemId
1282
+ });
1283
+ }
1284
+ /**
1285
+ * Create a new password item. `input.tags` must contain at least one
1286
+ * tag within the extension's permission scope, otherwise the write
1287
+ * is rejected as a security violation.
1288
+ *
1289
+ * Returns the new item id.
1290
+ */
1291
+ async createAsync(input) {
1292
+ return this.client.request(PASSWORD_COMMANDS.create, { input });
1293
+ }
1294
+ /**
1295
+ * Update an existing item. The item must already be in scope, and
1296
+ * the new tag set must keep at least one tag in scope (extensions
1297
+ * cannot orphan an item out of their own reach).
1298
+ */
1299
+ async updateAsync(itemId, input) {
1300
+ return this.client.request(PASSWORD_COMMANDS.update, {
1301
+ itemId,
1302
+ input
1303
+ });
1304
+ }
1305
+ /** Delete an item by id. Item must be in scope. */
1306
+ async deleteAsync(itemId) {
1307
+ return this.client.request(PASSWORD_COMMANDS.delete, { itemId });
1308
+ }
1309
+ };
1310
+
1311
+ // src/api/mail.ts
1312
+ var MailAPI = class {
1313
+ constructor(client) {
1314
+ this.client = client;
1315
+ }
1316
+ /**
1317
+ * LIST mailboxes for an IMAP account. Pass `includeStatus=true` for
1318
+ * EXISTS/UNSEEN/UIDVALIDITY/UIDNEXT per box (one extra round-trip
1319
+ * per mailbox — fine for typical accounts, expensive for large
1320
+ * trees).
1321
+ */
1322
+ async listMailboxesAsync(imap, options = {}) {
1323
+ return this.client.request(MAIL_COMMANDS.listMailboxes, {
1324
+ imap,
1325
+ reference: options.reference,
1326
+ pattern: options.pattern,
1327
+ includeStatus: options.includeStatus
1328
+ });
1329
+ }
1330
+ /** Fetch lightweight envelopes for a mailbox + range (for list views). */
1331
+ async fetchEnvelopesAsync(imap, mailbox, range) {
1332
+ return this.client.request(
1333
+ MAIL_COMMANDS.fetchEnvelopes,
1334
+ { imap, mailbox, range }
1335
+ );
1336
+ }
1337
+ /** Fetch a full message (envelope + body + attachment metadata) by UID. */
1338
+ async fetchMessageAsync(imap, mailbox, uid) {
1339
+ return this.client.request(MAIL_COMMANDS.fetchMessage, {
1340
+ imap,
1341
+ mailbox,
1342
+ uid
1343
+ });
1344
+ }
1345
+ /**
1346
+ * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
1347
+ * mark messages as read; `add=false` removes the flag(s).
1348
+ */
1349
+ async setFlagsAsync(imap, mailbox, uids, flags, add) {
1350
+ return this.client.request(MAIL_COMMANDS.setFlags, {
1351
+ imap,
1352
+ mailbox,
1353
+ uids,
1354
+ flags,
1355
+ add
1356
+ });
1357
+ }
1358
+ /** Move messages between mailboxes. Falls back to COPY+EXPUNGE on servers without MOVE. */
1359
+ async moveMessagesAsync(imap, sourceMailbox, destinationMailbox, uids) {
1360
+ return this.client.request(MAIL_COMMANDS.moveMessages, {
1361
+ imap,
1362
+ sourceMailbox,
1363
+ destinationMailbox,
1364
+ uids
1365
+ });
1366
+ }
1367
+ /**
1368
+ * APPEND a base64-encoded RFC822 message into a mailbox. Combine
1369
+ * with `buildRfc822Async` to save drafts, or with the bytes returned
1370
+ * after `sendMessageAsync` to mirror the sent copy into "Sent".
1371
+ */
1372
+ async appendMessageAsync(imap, mailbox, rfc822Base64, flags) {
1373
+ return this.client.request(MAIL_COMMANDS.appendMessage, {
1374
+ imap,
1375
+ mailbox,
1376
+ rfc822Base64,
1377
+ flags
1378
+ });
1379
+ }
1380
+ /** Send a message via SMTP. Returns the assigned Message-ID (no angle brackets). */
1381
+ async sendMessageAsync(smtp, message) {
1382
+ return this.client.request(MAIL_COMMANDS.sendMessage, {
1383
+ smtp,
1384
+ message
1385
+ });
1386
+ }
1387
+ /**
1388
+ * Build RFC822 bytes for a message without sending — useful for
1389
+ * drafts that get APPENDed to a "Drafts" folder. Permission-wise
1390
+ * this is a fetch operation (no SMTP host involved).
1391
+ */
1392
+ async buildRfc822Async(imapHost, message) {
1393
+ return this.client.request(MAIL_COMMANDS.buildRfc822, {
1394
+ imapHost,
1395
+ message
1396
+ });
1397
+ }
1398
+ };
1399
+
1227
1400
  // src/messages.ts
1228
1401
  var HAEXSPACE_MESSAGE_TYPES = {
1229
1402
  /** Debug message for development/troubleshooting */
@@ -1671,7 +1844,7 @@ async function initIframeMode(ctx, log, messageHandler, request) {
1671
1844
  publicKey: ctx.config.manifest.publicKey,
1672
1845
  name: ctx.config.manifest.name,
1673
1846
  version: ctx.config.manifest.version,
1674
- displayName: ctx.config.manifest.name
1847
+ displayName: ctx.config.manifest.displayName ?? ctx.config.manifest.name
1675
1848
  };
1676
1849
  log("Extension info loaded from manifest:", ctx.state.extensionInfo);
1677
1850
  }
@@ -1862,11 +2035,10 @@ function processEvent(event, log, eventListeners, onContextChanged, onExternalRe
1862
2035
  emitEvent(event, log, eventListeners);
1863
2036
  }
1864
2037
  function emitEvent(event, log, eventListeners) {
1865
- console.log("[HaexVault SDK] emitEvent called with:", event.type, event);
1866
- console.log("[HaexVault SDK] Registered event types:", Array.from(eventListeners.keys()));
1867
- log("Event received:", event);
2038
+ log("emitEvent called with:", event.type, event);
2039
+ log("Registered event types:", Array.from(eventListeners.keys()));
1868
2040
  const listeners = eventListeners.get(event.type);
1869
- console.log("[HaexVault SDK] Listeners for", event.type, ":", listeners?.size ?? 0);
2041
+ log("Listeners for", event.type, ":", listeners?.size ?? 0);
1870
2042
  if (listeners) {
1871
2043
  listeners.forEach((callback) => callback(event));
1872
2044
  }
@@ -1963,9 +2135,9 @@ function registerExternalHandler(action, handler, handlers, log) {
1963
2135
  };
1964
2136
  }
1965
2137
  async function handleExternalRequest(request, handlers, respond, log) {
1966
- console.log("[SDK Debug] handleExternalRequest called!");
1967
- console.log("[SDK Debug] Request:", JSON.stringify(request, null, 2));
1968
- console.log("[SDK Debug] Available handlers:", Array.from(handlers.keys()));
2138
+ log("handleExternalRequest called");
2139
+ log("Request:", request);
2140
+ log("Available handlers:", Array.from(handlers.keys()));
1969
2141
  log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
1970
2142
  const handler = handlers.get(request.action);
1971
2143
  if (!handler) {
@@ -1991,7 +2163,6 @@ async function handleExternalRequest(request, handlers, respond, log) {
1991
2163
  }
1992
2164
  }
1993
2165
  async function respondToExternalRequest(response, request) {
1994
- console.log("[SDK Debug] respondToExternalRequest called with:", JSON.stringify(response, null, 2));
1995
2166
  await request(EXTERNAL_BRIDGE_COMMANDS.respond, response);
1996
2167
  }
1997
2168
 
@@ -2049,11 +2220,17 @@ var HaexVaultSdk = class {
2049
2220
  this.localsend = new LocalSendAPI(this);
2050
2221
  this.spaces = new SpacesAPI(this);
2051
2222
  this.shell = new ShellAPI(this);
2223
+ this.passwords = new PasswordsAPI(this);
2224
+ this.mail = new MailAPI(this);
2052
2225
  installConsoleForwarding(this.config.debug);
2053
- this.readyPromise = new Promise((resolve) => {
2226
+ this.readyPromise = new Promise((resolve, reject) => {
2054
2227
  this.resolveReady = resolve;
2228
+ this.rejectReady = reject;
2229
+ });
2230
+ this.init().catch((error) => {
2231
+ this.log("Init failed:", error);
2232
+ this.rejectReady(error);
2055
2233
  });
2056
- this.init();
2057
2234
  }
2058
2235
  // ==========================================================================
2059
2236
  // Lifecycle
@@ -2081,9 +2258,14 @@ var HaexVaultSdk = class {
2081
2258
  return this.setupPromise;
2082
2259
  }
2083
2260
  destroy() {
2084
- if (this.messageHandler) {
2085
- window.removeEventListener("message", this.messageHandler);
2261
+ if (this.messageHandler && this.hostPort) {
2262
+ this.hostPort.removeEventListener("message", this.messageHandler);
2263
+ }
2264
+ if (this.hostPort) {
2265
+ this.hostPort.close();
2266
+ this.hostPort = null;
2086
2267
  }
2268
+ this.messageHandler = null;
2087
2269
  this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
2088
2270
  this.pendingRequests.clear();
2089
2271
  this.eventListeners.clear();
@@ -2311,7 +2493,7 @@ var HaexVaultSdk = class {
2311
2493
  publicKey: this.config.manifest.publicKey,
2312
2494
  name: this.config.manifest.name,
2313
2495
  version: this.config.manifest.version,
2314
- displayName: this.config.manifest.name
2496
+ displayName: this.config.manifest.displayName ?? this.config.manifest.name
2315
2497
  };
2316
2498
  this.notifySubscribersInternal();
2317
2499
  }
@@ -2393,22 +2575,18 @@ var nuxt_plugin_client_default = app.defineNuxtPlugin(async (nuxtApp) => {
2393
2575
  context: client.context
2394
2576
  });
2395
2577
  await client.ready();
2396
- console.log("[Nuxt Plugin] Client ready, context:", client.context);
2397
2578
  state.value = {
2398
2579
  isReady: true,
2399
2580
  isSetupComplete: false,
2400
2581
  context: client.context
2401
2582
  };
2402
- console.log("[Nuxt Plugin] Initial state set:", state.value);
2403
2583
  client.subscribe(() => {
2404
- console.log("[Nuxt Plugin] Client context updated:", client.context);
2405
2584
  const isSetupComplete = client.setupCompleted;
2406
2585
  state.value = {
2407
2586
  ...state.value,
2408
2587
  context: client.context,
2409
2588
  isSetupComplete
2410
2589
  };
2411
- console.log("[Nuxt Plugin] State updated:", state.value);
2412
2590
  });
2413
2591
  const haexVaultPlugin = {
2414
2592
  client,