@haex-space/vault-sdk 3.0.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.
- package/dist/{client-dpJHb3FP.d.ts → client-GeColu97.d.mts} +270 -2
- package/dist/{client-BXtzUBWv.d.mts → client-z1jTcuQE.d.ts} +270 -2
- package/dist/index.d.mts +93 -6
- package/dist/index.d.ts +93 -6
- package/dist/index.js +301 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -46
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/nuxt.js +34 -7
- package/dist/nuxt.js.map +1 -1
- package/dist/nuxt.mjs +34 -7
- package/dist/nuxt.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +294 -44
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +294 -44
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
- package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
- package/dist/runtime/nuxt.plugin.client.js +294 -48
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +294 -48
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +294 -44
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +294 -44
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-DmCSegdY.d.mts → types-CDMBvvjl.d.mts} +2 -0
- package/dist/{types-DmCSegdY.d.ts → types-CDMBvvjl.d.ts} +2 -0
- package/dist/vite.js +33 -6
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +33 -6
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +294 -44
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +294 -44
- package/dist/vue.mjs.map +1 -1
- package/package.json +2 -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-
|
|
4
|
-
import { A as ApplicationContext } from '../types-
|
|
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-
|
|
4
|
-
import { A as ApplicationContext } from '../types-
|
|
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} (${
|
|
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,12 +1263,163 @@ 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 */
|
|
1230
1403
|
DEBUG: "haexspace:debug",
|
|
1231
1404
|
/** Console forwarding from extension iframe */
|
|
1232
|
-
CONSOLE_FORWARD: "console.forward"
|
|
1405
|
+
CONSOLE_FORWARD: "console.forward",
|
|
1406
|
+
/**
|
|
1407
|
+
* Sent from main window to iframe on the shared window listener, carrying
|
|
1408
|
+
* one `MessagePort` in `event.ports[0]`. Once received, the SDK switches
|
|
1409
|
+
* to port-based messaging and never reads the window listener again.
|
|
1410
|
+
*
|
|
1411
|
+
* Payload: `{ type: PORT_INIT }` — no data. The port itself is the payload.
|
|
1412
|
+
*/
|
|
1413
|
+
PORT_INIT: "haexspace:port:init",
|
|
1414
|
+
/**
|
|
1415
|
+
* Sent from SDK to main window *over the MessagePort* after the port is
|
|
1416
|
+
* installed. Main uses this to mark the iframe as ready and flush any
|
|
1417
|
+
* events buffered during the handshake window. Only valid on the port —
|
|
1418
|
+
* a READY sent over window.postMessage is ignored.
|
|
1419
|
+
*
|
|
1420
|
+
* Payload: `{ type: PORT_READY }` — no data.
|
|
1421
|
+
*/
|
|
1422
|
+
PORT_READY: "haexspace:port:ready"
|
|
1233
1423
|
};
|
|
1234
1424
|
|
|
1235
1425
|
// src/polyfills/consoleForwarding.ts
|
|
@@ -1384,6 +1574,7 @@ function parseTableName(fullTableName) {
|
|
|
1384
1574
|
}
|
|
1385
1575
|
|
|
1386
1576
|
// src/client/init.ts
|
|
1577
|
+
var PORT_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
1387
1578
|
function isInIframe() {
|
|
1388
1579
|
return window.self !== window.top;
|
|
1389
1580
|
}
|
|
@@ -1640,17 +1831,20 @@ async function initIframeMode(ctx, log, messageHandler, request) {
|
|
|
1640
1831
|
if (!isInIframe()) {
|
|
1641
1832
|
throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1642
1833
|
}
|
|
1834
|
+
const port = await waitForHostPortAsync(log);
|
|
1643
1835
|
ctx.handlers.messageHandler = messageHandler;
|
|
1644
|
-
|
|
1836
|
+
port.addEventListener("message", messageHandler);
|
|
1837
|
+
port.start();
|
|
1838
|
+
port.postMessage({ type: HAEXSPACE_MESSAGE_TYPES.PORT_READY });
|
|
1645
1839
|
ctx.state.isNativeWindow = false;
|
|
1646
1840
|
ctx.state.initialized = true;
|
|
1647
|
-
log("HaexVault SDK initialized in iframe mode");
|
|
1841
|
+
log("HaexVault SDK initialized in iframe mode (MessagePort transport)");
|
|
1648
1842
|
if (ctx.config.manifest) {
|
|
1649
1843
|
ctx.state.extensionInfo = {
|
|
1650
1844
|
publicKey: ctx.config.manifest.publicKey,
|
|
1651
1845
|
name: ctx.config.manifest.name,
|
|
1652
1846
|
version: ctx.config.manifest.version,
|
|
1653
|
-
displayName: ctx.config.manifest.name
|
|
1847
|
+
displayName: ctx.config.manifest.displayName ?? ctx.config.manifest.name
|
|
1654
1848
|
};
|
|
1655
1849
|
log("Extension info loaded from manifest:", ctx.state.extensionInfo);
|
|
1656
1850
|
}
|
|
@@ -1658,7 +1852,42 @@ async function initIframeMode(ctx, log, messageHandler, request) {
|
|
|
1658
1852
|
const context = await request(EXTENSION_COMMANDS.getContext);
|
|
1659
1853
|
ctx.state.context = context;
|
|
1660
1854
|
log("Application context received:", context);
|
|
1661
|
-
return { context };
|
|
1855
|
+
return { context, port };
|
|
1856
|
+
}
|
|
1857
|
+
function waitForHostPortAsync(log) {
|
|
1858
|
+
return new Promise((resolve, reject) => {
|
|
1859
|
+
let settled = false;
|
|
1860
|
+
const cleanup = () => {
|
|
1861
|
+
window.removeEventListener("message", handler);
|
|
1862
|
+
};
|
|
1863
|
+
const timeoutId = setTimeout(() => {
|
|
1864
|
+
if (settled) return;
|
|
1865
|
+
settled = true;
|
|
1866
|
+
cleanup();
|
|
1867
|
+
reject(
|
|
1868
|
+
new HaexVaultSdkError(
|
|
1869
|
+
"TIMEOUT" /* TIMEOUT */,
|
|
1870
|
+
"errors.port_handshake_timeout",
|
|
1871
|
+
{ timeout: PORT_HANDSHAKE_TIMEOUT_MS }
|
|
1872
|
+
)
|
|
1873
|
+
);
|
|
1874
|
+
}, PORT_HANDSHAKE_TIMEOUT_MS);
|
|
1875
|
+
const handler = (event) => {
|
|
1876
|
+
const type = event.data?.type;
|
|
1877
|
+
if (type !== HAEXSPACE_MESSAGE_TYPES.PORT_INIT) return;
|
|
1878
|
+
const port = event.ports[0];
|
|
1879
|
+
if (!port) {
|
|
1880
|
+
log("PORT_INIT received but event.ports is empty \u2014 ignoring");
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
if (settled) return;
|
|
1884
|
+
settled = true;
|
|
1885
|
+
clearTimeout(timeoutId);
|
|
1886
|
+
cleanup();
|
|
1887
|
+
resolve(port);
|
|
1888
|
+
};
|
|
1889
|
+
window.addEventListener("message", handler);
|
|
1890
|
+
});
|
|
1662
1891
|
}
|
|
1663
1892
|
function sendDebugInfo(config) {
|
|
1664
1893
|
if (!config.debug) return;
|
|
@@ -1682,7 +1911,15 @@ postMessage error: ${e}`);
|
|
|
1682
1911
|
function generateRequestId(counter) {
|
|
1683
1912
|
return `req_${counter}`;
|
|
1684
1913
|
}
|
|
1685
|
-
function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests) {
|
|
1914
|
+
function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port) {
|
|
1915
|
+
if (!port) {
|
|
1916
|
+
return Promise.reject(
|
|
1917
|
+
new HaexVaultSdkError(
|
|
1918
|
+
"EXTENSION_NOT_INITIALIZED" /* EXTENSION_NOT_INITIALIZED */,
|
|
1919
|
+
"errors.port_not_connected"
|
|
1920
|
+
)
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1686
1923
|
const request = {
|
|
1687
1924
|
method,
|
|
1688
1925
|
params,
|
|
@@ -1698,17 +1935,16 @@ function sendPostMessage(method, params, requestId, config, extensionInfo, pendi
|
|
|
1698
1935
|
);
|
|
1699
1936
|
}, config.timeout);
|
|
1700
1937
|
pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1701
|
-
const targetOrigin = "*";
|
|
1702
1938
|
if (config.debug) {
|
|
1703
1939
|
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1704
1940
|
console.log("[SDK Debug] Request ID:", requestId);
|
|
1705
1941
|
console.log("[SDK Debug] Method:", request.method);
|
|
1706
1942
|
console.log("[SDK Debug] Params:", request.params);
|
|
1707
|
-
console.log("[SDK Debug]
|
|
1943
|
+
console.log("[SDK Debug] Transport: MessagePort");
|
|
1708
1944
|
console.log("[SDK Debug] Extension info:", extensionInfo);
|
|
1709
1945
|
console.log("[SDK Debug] ========================================");
|
|
1710
1946
|
}
|
|
1711
|
-
|
|
1947
|
+
port.postMessage({ id: requestId, ...request });
|
|
1712
1948
|
});
|
|
1713
1949
|
}
|
|
1714
1950
|
async function sendInvoke(method, params, config, _log) {
|
|
@@ -1727,11 +1963,6 @@ function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
|
|
|
1727
1963
|
return (event) => {
|
|
1728
1964
|
if (config.debug) {
|
|
1729
1965
|
console.log("[SDK Debug] ========== Message Received ==========");
|
|
1730
|
-
console.log("[SDK Debug] Event origin:", event.origin);
|
|
1731
|
-
console.log(
|
|
1732
|
-
"[SDK Debug] Event source:",
|
|
1733
|
-
event.source === window.parent ? "parent window" : "unknown"
|
|
1734
|
-
);
|
|
1735
1966
|
console.log("[SDK Debug] Event data:", event.data);
|
|
1736
1967
|
console.log("[SDK Debug] Extension info loaded:", !!extensionInfo());
|
|
1737
1968
|
console.log(
|
|
@@ -1739,12 +1970,6 @@ function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
|
|
|
1739
1970
|
pendingRequests.size
|
|
1740
1971
|
);
|
|
1741
1972
|
}
|
|
1742
|
-
if (event.source !== window.parent) {
|
|
1743
|
-
if (config.debug) {
|
|
1744
|
-
console.error("[SDK Debug] \u274C REJECTED: Message not from parent window!");
|
|
1745
|
-
}
|
|
1746
|
-
return;
|
|
1747
|
-
}
|
|
1748
1973
|
const data = event.data;
|
|
1749
1974
|
if ("id" in data && pendingRequests.has(data.id)) {
|
|
1750
1975
|
if (config.debug) {
|
|
@@ -1810,11 +2035,10 @@ function processEvent(event, log, eventListeners, onContextChanged, onExternalRe
|
|
|
1810
2035
|
emitEvent(event, log, eventListeners);
|
|
1811
2036
|
}
|
|
1812
2037
|
function emitEvent(event, log, eventListeners) {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
log("Event received:", event);
|
|
2038
|
+
log("emitEvent called with:", event.type, event);
|
|
2039
|
+
log("Registered event types:", Array.from(eventListeners.keys()));
|
|
1816
2040
|
const listeners = eventListeners.get(event.type);
|
|
1817
|
-
|
|
2041
|
+
log("Listeners for", event.type, ":", listeners?.size ?? 0);
|
|
1818
2042
|
if (listeners) {
|
|
1819
2043
|
listeners.forEach((callback) => callback(event));
|
|
1820
2044
|
}
|
|
@@ -1911,9 +2135,9 @@ function registerExternalHandler(action, handler, handlers, log) {
|
|
|
1911
2135
|
};
|
|
1912
2136
|
}
|
|
1913
2137
|
async function handleExternalRequest(request, handlers, respond, log) {
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2138
|
+
log("handleExternalRequest called");
|
|
2139
|
+
log("Request:", request);
|
|
2140
|
+
log("Available handlers:", Array.from(handlers.keys()));
|
|
1917
2141
|
log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
|
|
1918
2142
|
const handler = handlers.get(request.action);
|
|
1919
2143
|
if (!handler) {
|
|
@@ -1939,7 +2163,6 @@ async function handleExternalRequest(request, handlers, respond, log) {
|
|
|
1939
2163
|
}
|
|
1940
2164
|
}
|
|
1941
2165
|
async function respondToExternalRequest(response, request) {
|
|
1942
|
-
console.log("[SDK Debug] respondToExternalRequest called with:", JSON.stringify(response, null, 2));
|
|
1943
2166
|
await request(EXTERNAL_BRIDGE_COMMANDS.respond, response);
|
|
1944
2167
|
}
|
|
1945
2168
|
|
|
@@ -1966,6 +2189,13 @@ var HaexVaultSdk = class {
|
|
|
1966
2189
|
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
1967
2190
|
// Handlers
|
|
1968
2191
|
this.messageHandler = null;
|
|
2192
|
+
/**
|
|
2193
|
+
* MessagePort obtained from the main window during iframe-mode handshake.
|
|
2194
|
+
* `null` until `initIframe()` completes successfully. Every outbound
|
|
2195
|
+
* request in iframe mode flows through this port; `sendPostMessage` rejects
|
|
2196
|
+
* if called before the handshake finishes.
|
|
2197
|
+
*/
|
|
2198
|
+
this.hostPort = null;
|
|
1969
2199
|
this.setupPromise = null;
|
|
1970
2200
|
this.setupHook = null;
|
|
1971
2201
|
// Public APIs
|
|
@@ -1990,11 +2220,17 @@ var HaexVaultSdk = class {
|
|
|
1990
2220
|
this.localsend = new LocalSendAPI(this);
|
|
1991
2221
|
this.spaces = new SpacesAPI(this);
|
|
1992
2222
|
this.shell = new ShellAPI(this);
|
|
2223
|
+
this.passwords = new PasswordsAPI(this);
|
|
2224
|
+
this.mail = new MailAPI(this);
|
|
1993
2225
|
installConsoleForwarding(this.config.debug);
|
|
1994
|
-
this.readyPromise = new Promise((resolve) => {
|
|
2226
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
1995
2227
|
this.resolveReady = resolve;
|
|
2228
|
+
this.rejectReady = reject;
|
|
2229
|
+
});
|
|
2230
|
+
this.init().catch((error) => {
|
|
2231
|
+
this.log("Init failed:", error);
|
|
2232
|
+
this.rejectReady(error);
|
|
1996
2233
|
});
|
|
1997
|
-
this.init();
|
|
1998
2234
|
}
|
|
1999
2235
|
// ==========================================================================
|
|
2000
2236
|
// Lifecycle
|
|
@@ -2022,9 +2258,14 @@ var HaexVaultSdk = class {
|
|
|
2022
2258
|
return this.setupPromise;
|
|
2023
2259
|
}
|
|
2024
2260
|
destroy() {
|
|
2025
|
-
if (this.messageHandler) {
|
|
2026
|
-
|
|
2261
|
+
if (this.messageHandler && this.hostPort) {
|
|
2262
|
+
this.hostPort.removeEventListener("message", this.messageHandler);
|
|
2027
2263
|
}
|
|
2264
|
+
if (this.hostPort) {
|
|
2265
|
+
this.hostPort.close();
|
|
2266
|
+
this.hostPort = null;
|
|
2267
|
+
}
|
|
2268
|
+
this.messageHandler = null;
|
|
2028
2269
|
this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
|
|
2029
2270
|
this.pendingRequests.clear();
|
|
2030
2271
|
this.eventListeners.clear();
|
|
@@ -2139,7 +2380,15 @@ var HaexVaultSdk = class {
|
|
|
2139
2380
|
return sendInvoke(method, paramsWithCredentials, this.config, this.log.bind(this));
|
|
2140
2381
|
}
|
|
2141
2382
|
const requestId = generateRequestId(++this.requestCounter);
|
|
2142
|
-
return sendPostMessage(
|
|
2383
|
+
return sendPostMessage(
|
|
2384
|
+
method,
|
|
2385
|
+
resolvedParams,
|
|
2386
|
+
requestId,
|
|
2387
|
+
this.config,
|
|
2388
|
+
this._extensionInfo,
|
|
2389
|
+
this.pendingRequests,
|
|
2390
|
+
this.hostPort
|
|
2391
|
+
);
|
|
2143
2392
|
}
|
|
2144
2393
|
// ==========================================================================
|
|
2145
2394
|
// Private: Initialization
|
|
@@ -2206,7 +2455,7 @@ var HaexVaultSdk = class {
|
|
|
2206
2455
|
() => this._extensionInfo,
|
|
2207
2456
|
this.handleEvent.bind(this)
|
|
2208
2457
|
);
|
|
2209
|
-
const { context } = await initIframeMode(
|
|
2458
|
+
const { context, port } = await initIframeMode(
|
|
2210
2459
|
{
|
|
2211
2460
|
config: this.config,
|
|
2212
2461
|
state: {
|
|
@@ -2238,12 +2487,13 @@ var HaexVaultSdk = class {
|
|
|
2238
2487
|
this.messageHandler,
|
|
2239
2488
|
this.request.bind(this)
|
|
2240
2489
|
);
|
|
2490
|
+
this.hostPort = port;
|
|
2241
2491
|
if (this.config.manifest) {
|
|
2242
2492
|
this._extensionInfo = {
|
|
2243
2493
|
publicKey: this.config.manifest.publicKey,
|
|
2244
2494
|
name: this.config.manifest.name,
|
|
2245
2495
|
version: this.config.manifest.version,
|
|
2246
|
-
displayName: this.config.manifest.name
|
|
2496
|
+
displayName: this.config.manifest.displayName ?? this.config.manifest.name
|
|
2247
2497
|
};
|
|
2248
2498
|
this.notifySubscribersInternal();
|
|
2249
2499
|
}
|
|
@@ -2325,22 +2575,18 @@ var nuxt_plugin_client_default = app.defineNuxtPlugin(async (nuxtApp) => {
|
|
|
2325
2575
|
context: client.context
|
|
2326
2576
|
});
|
|
2327
2577
|
await client.ready();
|
|
2328
|
-
console.log("[Nuxt Plugin] Client ready, context:", client.context);
|
|
2329
2578
|
state.value = {
|
|
2330
2579
|
isReady: true,
|
|
2331
2580
|
isSetupComplete: false,
|
|
2332
2581
|
context: client.context
|
|
2333
2582
|
};
|
|
2334
|
-
console.log("[Nuxt Plugin] Initial state set:", state.value);
|
|
2335
2583
|
client.subscribe(() => {
|
|
2336
|
-
console.log("[Nuxt Plugin] Client context updated:", client.context);
|
|
2337
2584
|
const isSetupComplete = client.setupCompleted;
|
|
2338
2585
|
state.value = {
|
|
2339
2586
|
...state.value,
|
|
2340
2587
|
context: client.context,
|
|
2341
2588
|
isSetupComplete
|
|
2342
2589
|
};
|
|
2343
|
-
console.log("[Nuxt Plugin] State updated:", state.value);
|
|
2344
2590
|
});
|
|
2345
2591
|
const haexVaultPlugin = {
|
|
2346
2592
|
client,
|