@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
package/dist/react.js
CHANGED
|
@@ -269,7 +269,24 @@ var HAEXSPACE_MESSAGE_TYPES = {
|
|
|
269
269
|
/** Debug message for development/troubleshooting */
|
|
270
270
|
DEBUG: "haexspace:debug",
|
|
271
271
|
/** Console forwarding from extension iframe */
|
|
272
|
-
CONSOLE_FORWARD: "console.forward"
|
|
272
|
+
CONSOLE_FORWARD: "console.forward",
|
|
273
|
+
/**
|
|
274
|
+
* Sent from main window to iframe on the shared window listener, carrying
|
|
275
|
+
* one `MessagePort` in `event.ports[0]`. Once received, the SDK switches
|
|
276
|
+
* to port-based messaging and never reads the window listener again.
|
|
277
|
+
*
|
|
278
|
+
* Payload: `{ type: PORT_INIT }` — no data. The port itself is the payload.
|
|
279
|
+
*/
|
|
280
|
+
PORT_INIT: "haexspace:port:init",
|
|
281
|
+
/**
|
|
282
|
+
* Sent from SDK to main window *over the MessagePort* after the port is
|
|
283
|
+
* installed. Main uses this to mark the iframe as ready and flush any
|
|
284
|
+
* events buffered during the handshake window. Only valid on the port —
|
|
285
|
+
* a READY sent over window.postMessage is ignored.
|
|
286
|
+
*
|
|
287
|
+
* Payload: `{ type: PORT_READY }` — no data.
|
|
288
|
+
*/
|
|
289
|
+
PORT_READY: "haexspace:port:ready"
|
|
273
290
|
};
|
|
274
291
|
|
|
275
292
|
// src/polyfills/debug.ts
|
|
@@ -633,6 +650,40 @@ var SHELL_COMMANDS = {
|
|
|
633
650
|
close: "extension_shell_close"
|
|
634
651
|
};
|
|
635
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
|
+
|
|
636
687
|
// src/api/storage.ts
|
|
637
688
|
var StorageAPI = class {
|
|
638
689
|
constructor(client) {
|
|
@@ -656,6 +707,12 @@ var StorageAPI = class {
|
|
|
656
707
|
};
|
|
657
708
|
|
|
658
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
|
+
}
|
|
659
716
|
var DatabaseAPI = class {
|
|
660
717
|
constructor(client) {
|
|
661
718
|
this.client = client;
|
|
@@ -686,11 +743,11 @@ var DatabaseAPI = class {
|
|
|
686
743
|
});
|
|
687
744
|
}
|
|
688
745
|
async createTable(tableName, columns) {
|
|
689
|
-
const query = `CREATE TABLE IF NOT EXISTS ${tableName} (${columns})`;
|
|
746
|
+
const query = `CREATE TABLE IF NOT EXISTS ${quoteIdent(tableName)} (${columns})`;
|
|
690
747
|
await this.execute(query);
|
|
691
748
|
}
|
|
692
749
|
async dropTable(tableName) {
|
|
693
|
-
const query = `DROP TABLE IF EXISTS ${tableName}`;
|
|
750
|
+
const query = `DROP TABLE IF EXISTS ${quoteIdent(tableName)}`;
|
|
694
751
|
await this.execute(query);
|
|
695
752
|
}
|
|
696
753
|
/**
|
|
@@ -719,18 +776,17 @@ var DatabaseAPI = class {
|
|
|
719
776
|
async insert(tableName, data) {
|
|
720
777
|
const keys = Object.keys(data);
|
|
721
778
|
const values = Object.values(data);
|
|
779
|
+
const quotedCols = keys.map(quoteIdent).join(", ");
|
|
722
780
|
const placeholders = keys.map(() => "?").join(", ");
|
|
723
|
-
const query = `INSERT INTO ${tableName} (${
|
|
724
|
-
", "
|
|
725
|
-
)}) VALUES (${placeholders})`;
|
|
781
|
+
const query = `INSERT INTO ${quoteIdent(tableName)} (${quotedCols}) VALUES (${placeholders})`;
|
|
726
782
|
const result = await this.execute(query, values);
|
|
727
783
|
return result.lastInsertId ?? -1;
|
|
728
784
|
}
|
|
729
785
|
async update(tableName, data, where, whereParams) {
|
|
730
786
|
const keys = Object.keys(data);
|
|
731
787
|
const values = Object.values(data);
|
|
732
|
-
const setClause = keys.map((key) => `${key} = ?`).join(", ");
|
|
733
|
-
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}`;
|
|
734
790
|
const result = await this.execute(query, [
|
|
735
791
|
...values,
|
|
736
792
|
...whereParams || []
|
|
@@ -738,12 +794,12 @@ var DatabaseAPI = class {
|
|
|
738
794
|
return result.rowsAffected;
|
|
739
795
|
}
|
|
740
796
|
async delete(tableName, where, whereParams) {
|
|
741
|
-
const query = `DELETE FROM ${tableName} WHERE ${where}`;
|
|
797
|
+
const query = `DELETE FROM ${quoteIdent(tableName)} WHERE ${where}`;
|
|
742
798
|
const result = await this.execute(query, whereParams);
|
|
743
799
|
return result.rowsAffected;
|
|
744
800
|
}
|
|
745
801
|
async count(tableName, where, whereParams) {
|
|
746
|
-
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)}`;
|
|
747
803
|
const result = await this.queryOne(query, whereParams);
|
|
748
804
|
return result?.count ?? 0;
|
|
749
805
|
}
|
|
@@ -1565,6 +1621,140 @@ var ShellAPI = class {
|
|
|
1565
1621
|
}
|
|
1566
1622
|
};
|
|
1567
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
|
+
|
|
1568
1758
|
// src/client/tableName.ts
|
|
1569
1759
|
function validatePublicKey(publicKey) {
|
|
1570
1760
|
if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
|
|
@@ -1651,6 +1841,7 @@ function parseTableName(fullTableName) {
|
|
|
1651
1841
|
}
|
|
1652
1842
|
|
|
1653
1843
|
// src/client/init.ts
|
|
1844
|
+
var PORT_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
1654
1845
|
function isInIframe() {
|
|
1655
1846
|
return window.self !== window.top;
|
|
1656
1847
|
}
|
|
@@ -1907,17 +2098,20 @@ async function initIframeMode(ctx, log, messageHandler, request) {
|
|
|
1907
2098
|
if (!isInIframe()) {
|
|
1908
2099
|
throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1909
2100
|
}
|
|
2101
|
+
const port = await waitForHostPortAsync(log);
|
|
1910
2102
|
ctx.handlers.messageHandler = messageHandler;
|
|
1911
|
-
|
|
2103
|
+
port.addEventListener("message", messageHandler);
|
|
2104
|
+
port.start();
|
|
2105
|
+
port.postMessage({ type: HAEXSPACE_MESSAGE_TYPES.PORT_READY });
|
|
1912
2106
|
ctx.state.isNativeWindow = false;
|
|
1913
2107
|
ctx.state.initialized = true;
|
|
1914
|
-
log("HaexVault SDK initialized in iframe mode");
|
|
2108
|
+
log("HaexVault SDK initialized in iframe mode (MessagePort transport)");
|
|
1915
2109
|
if (ctx.config.manifest) {
|
|
1916
2110
|
ctx.state.extensionInfo = {
|
|
1917
2111
|
publicKey: ctx.config.manifest.publicKey,
|
|
1918
2112
|
name: ctx.config.manifest.name,
|
|
1919
2113
|
version: ctx.config.manifest.version,
|
|
1920
|
-
displayName: ctx.config.manifest.name
|
|
2114
|
+
displayName: ctx.config.manifest.displayName ?? ctx.config.manifest.name
|
|
1921
2115
|
};
|
|
1922
2116
|
log("Extension info loaded from manifest:", ctx.state.extensionInfo);
|
|
1923
2117
|
}
|
|
@@ -1925,7 +2119,42 @@ async function initIframeMode(ctx, log, messageHandler, request) {
|
|
|
1925
2119
|
const context = await request(EXTENSION_COMMANDS.getContext);
|
|
1926
2120
|
ctx.state.context = context;
|
|
1927
2121
|
log("Application context received:", context);
|
|
1928
|
-
return { context };
|
|
2122
|
+
return { context, port };
|
|
2123
|
+
}
|
|
2124
|
+
function waitForHostPortAsync(log) {
|
|
2125
|
+
return new Promise((resolve, reject) => {
|
|
2126
|
+
let settled = false;
|
|
2127
|
+
const cleanup = () => {
|
|
2128
|
+
window.removeEventListener("message", handler);
|
|
2129
|
+
};
|
|
2130
|
+
const timeoutId = setTimeout(() => {
|
|
2131
|
+
if (settled) return;
|
|
2132
|
+
settled = true;
|
|
2133
|
+
cleanup();
|
|
2134
|
+
reject(
|
|
2135
|
+
new HaexVaultSdkError(
|
|
2136
|
+
"TIMEOUT" /* TIMEOUT */,
|
|
2137
|
+
"errors.port_handshake_timeout",
|
|
2138
|
+
{ timeout: PORT_HANDSHAKE_TIMEOUT_MS }
|
|
2139
|
+
)
|
|
2140
|
+
);
|
|
2141
|
+
}, PORT_HANDSHAKE_TIMEOUT_MS);
|
|
2142
|
+
const handler = (event) => {
|
|
2143
|
+
const type = event.data?.type;
|
|
2144
|
+
if (type !== HAEXSPACE_MESSAGE_TYPES.PORT_INIT) return;
|
|
2145
|
+
const port = event.ports[0];
|
|
2146
|
+
if (!port) {
|
|
2147
|
+
log("PORT_INIT received but event.ports is empty \u2014 ignoring");
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
if (settled) return;
|
|
2151
|
+
settled = true;
|
|
2152
|
+
clearTimeout(timeoutId);
|
|
2153
|
+
cleanup();
|
|
2154
|
+
resolve(port);
|
|
2155
|
+
};
|
|
2156
|
+
window.addEventListener("message", handler);
|
|
2157
|
+
});
|
|
1929
2158
|
}
|
|
1930
2159
|
function sendDebugInfo(config) {
|
|
1931
2160
|
if (!config.debug) return;
|
|
@@ -1949,7 +2178,15 @@ postMessage error: ${e}`);
|
|
|
1949
2178
|
function generateRequestId(counter) {
|
|
1950
2179
|
return `req_${counter}`;
|
|
1951
2180
|
}
|
|
1952
|
-
function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests) {
|
|
2181
|
+
function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port) {
|
|
2182
|
+
if (!port) {
|
|
2183
|
+
return Promise.reject(
|
|
2184
|
+
new HaexVaultSdkError(
|
|
2185
|
+
"EXTENSION_NOT_INITIALIZED" /* EXTENSION_NOT_INITIALIZED */,
|
|
2186
|
+
"errors.port_not_connected"
|
|
2187
|
+
)
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
1953
2190
|
const request = {
|
|
1954
2191
|
method,
|
|
1955
2192
|
params,
|
|
@@ -1965,17 +2202,16 @@ function sendPostMessage(method, params, requestId, config, extensionInfo, pendi
|
|
|
1965
2202
|
);
|
|
1966
2203
|
}, config.timeout);
|
|
1967
2204
|
pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1968
|
-
const targetOrigin = "*";
|
|
1969
2205
|
if (config.debug) {
|
|
1970
2206
|
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1971
2207
|
console.log("[SDK Debug] Request ID:", requestId);
|
|
1972
2208
|
console.log("[SDK Debug] Method:", request.method);
|
|
1973
2209
|
console.log("[SDK Debug] Params:", request.params);
|
|
1974
|
-
console.log("[SDK Debug]
|
|
2210
|
+
console.log("[SDK Debug] Transport: MessagePort");
|
|
1975
2211
|
console.log("[SDK Debug] Extension info:", extensionInfo);
|
|
1976
2212
|
console.log("[SDK Debug] ========================================");
|
|
1977
2213
|
}
|
|
1978
|
-
|
|
2214
|
+
port.postMessage({ id: requestId, ...request });
|
|
1979
2215
|
});
|
|
1980
2216
|
}
|
|
1981
2217
|
async function sendInvoke(method, params, config, _log) {
|
|
@@ -1994,11 +2230,6 @@ function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
|
|
|
1994
2230
|
return (event) => {
|
|
1995
2231
|
if (config.debug) {
|
|
1996
2232
|
console.log("[SDK Debug] ========== Message Received ==========");
|
|
1997
|
-
console.log("[SDK Debug] Event origin:", event.origin);
|
|
1998
|
-
console.log(
|
|
1999
|
-
"[SDK Debug] Event source:",
|
|
2000
|
-
event.source === window.parent ? "parent window" : "unknown"
|
|
2001
|
-
);
|
|
2002
2233
|
console.log("[SDK Debug] Event data:", event.data);
|
|
2003
2234
|
console.log("[SDK Debug] Extension info loaded:", !!extensionInfo());
|
|
2004
2235
|
console.log(
|
|
@@ -2006,12 +2237,6 @@ function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
|
|
|
2006
2237
|
pendingRequests.size
|
|
2007
2238
|
);
|
|
2008
2239
|
}
|
|
2009
|
-
if (event.source !== window.parent) {
|
|
2010
|
-
if (config.debug) {
|
|
2011
|
-
console.error("[SDK Debug] \u274C REJECTED: Message not from parent window!");
|
|
2012
|
-
}
|
|
2013
|
-
return;
|
|
2014
|
-
}
|
|
2015
2240
|
const data = event.data;
|
|
2016
2241
|
if ("id" in data && pendingRequests.has(data.id)) {
|
|
2017
2242
|
if (config.debug) {
|
|
@@ -2077,11 +2302,10 @@ function processEvent(event, log, eventListeners, onContextChanged, onExternalRe
|
|
|
2077
2302
|
emitEvent(event, log, eventListeners);
|
|
2078
2303
|
}
|
|
2079
2304
|
function emitEvent(event, log, eventListeners) {
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
log("Event received:", event);
|
|
2305
|
+
log("emitEvent called with:", event.type, event);
|
|
2306
|
+
log("Registered event types:", Array.from(eventListeners.keys()));
|
|
2083
2307
|
const listeners = eventListeners.get(event.type);
|
|
2084
|
-
|
|
2308
|
+
log("Listeners for", event.type, ":", listeners?.size ?? 0);
|
|
2085
2309
|
if (listeners) {
|
|
2086
2310
|
listeners.forEach((callback) => callback(event));
|
|
2087
2311
|
}
|
|
@@ -2178,9 +2402,9 @@ function registerExternalHandler(action, handler, handlers, log) {
|
|
|
2178
2402
|
};
|
|
2179
2403
|
}
|
|
2180
2404
|
async function handleExternalRequest(request, handlers, respond, log) {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2405
|
+
log("handleExternalRequest called");
|
|
2406
|
+
log("Request:", request);
|
|
2407
|
+
log("Available handlers:", Array.from(handlers.keys()));
|
|
2184
2408
|
log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
|
|
2185
2409
|
const handler = handlers.get(request.action);
|
|
2186
2410
|
if (!handler) {
|
|
@@ -2206,7 +2430,6 @@ async function handleExternalRequest(request, handlers, respond, log) {
|
|
|
2206
2430
|
}
|
|
2207
2431
|
}
|
|
2208
2432
|
async function respondToExternalRequest(response, request) {
|
|
2209
|
-
console.log("[SDK Debug] respondToExternalRequest called with:", JSON.stringify(response, null, 2));
|
|
2210
2433
|
await request(EXTERNAL_BRIDGE_COMMANDS.respond, response);
|
|
2211
2434
|
}
|
|
2212
2435
|
|
|
@@ -2233,6 +2456,13 @@ var HaexVaultSdk = class {
|
|
|
2233
2456
|
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
2234
2457
|
// Handlers
|
|
2235
2458
|
this.messageHandler = null;
|
|
2459
|
+
/**
|
|
2460
|
+
* MessagePort obtained from the main window during iframe-mode handshake.
|
|
2461
|
+
* `null` until `initIframe()` completes successfully. Every outbound
|
|
2462
|
+
* request in iframe mode flows through this port; `sendPostMessage` rejects
|
|
2463
|
+
* if called before the handshake finishes.
|
|
2464
|
+
*/
|
|
2465
|
+
this.hostPort = null;
|
|
2236
2466
|
this.setupPromise = null;
|
|
2237
2467
|
this.setupHook = null;
|
|
2238
2468
|
// Public APIs
|
|
@@ -2257,11 +2487,17 @@ var HaexVaultSdk = class {
|
|
|
2257
2487
|
this.localsend = new LocalSendAPI(this);
|
|
2258
2488
|
this.spaces = new SpacesAPI(this);
|
|
2259
2489
|
this.shell = new ShellAPI(this);
|
|
2490
|
+
this.passwords = new PasswordsAPI(this);
|
|
2491
|
+
this.mail = new MailAPI(this);
|
|
2260
2492
|
installConsoleForwarding(this.config.debug);
|
|
2261
|
-
this.readyPromise = new Promise((resolve) => {
|
|
2493
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
2262
2494
|
this.resolveReady = resolve;
|
|
2495
|
+
this.rejectReady = reject;
|
|
2496
|
+
});
|
|
2497
|
+
this.init().catch((error) => {
|
|
2498
|
+
this.log("Init failed:", error);
|
|
2499
|
+
this.rejectReady(error);
|
|
2263
2500
|
});
|
|
2264
|
-
this.init();
|
|
2265
2501
|
}
|
|
2266
2502
|
// ==========================================================================
|
|
2267
2503
|
// Lifecycle
|
|
@@ -2289,9 +2525,14 @@ var HaexVaultSdk = class {
|
|
|
2289
2525
|
return this.setupPromise;
|
|
2290
2526
|
}
|
|
2291
2527
|
destroy() {
|
|
2292
|
-
if (this.messageHandler) {
|
|
2293
|
-
|
|
2528
|
+
if (this.messageHandler && this.hostPort) {
|
|
2529
|
+
this.hostPort.removeEventListener("message", this.messageHandler);
|
|
2294
2530
|
}
|
|
2531
|
+
if (this.hostPort) {
|
|
2532
|
+
this.hostPort.close();
|
|
2533
|
+
this.hostPort = null;
|
|
2534
|
+
}
|
|
2535
|
+
this.messageHandler = null;
|
|
2295
2536
|
this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
|
|
2296
2537
|
this.pendingRequests.clear();
|
|
2297
2538
|
this.eventListeners.clear();
|
|
@@ -2406,7 +2647,15 @@ var HaexVaultSdk = class {
|
|
|
2406
2647
|
return sendInvoke(method, paramsWithCredentials, this.config, this.log.bind(this));
|
|
2407
2648
|
}
|
|
2408
2649
|
const requestId = generateRequestId(++this.requestCounter);
|
|
2409
|
-
return sendPostMessage(
|
|
2650
|
+
return sendPostMessage(
|
|
2651
|
+
method,
|
|
2652
|
+
resolvedParams,
|
|
2653
|
+
requestId,
|
|
2654
|
+
this.config,
|
|
2655
|
+
this._extensionInfo,
|
|
2656
|
+
this.pendingRequests,
|
|
2657
|
+
this.hostPort
|
|
2658
|
+
);
|
|
2410
2659
|
}
|
|
2411
2660
|
// ==========================================================================
|
|
2412
2661
|
// Private: Initialization
|
|
@@ -2473,7 +2722,7 @@ var HaexVaultSdk = class {
|
|
|
2473
2722
|
() => this._extensionInfo,
|
|
2474
2723
|
this.handleEvent.bind(this)
|
|
2475
2724
|
);
|
|
2476
|
-
const { context } = await initIframeMode(
|
|
2725
|
+
const { context, port } = await initIframeMode(
|
|
2477
2726
|
{
|
|
2478
2727
|
config: this.config,
|
|
2479
2728
|
state: {
|
|
@@ -2505,12 +2754,13 @@ var HaexVaultSdk = class {
|
|
|
2505
2754
|
this.messageHandler,
|
|
2506
2755
|
this.request.bind(this)
|
|
2507
2756
|
);
|
|
2757
|
+
this.hostPort = port;
|
|
2508
2758
|
if (this.config.manifest) {
|
|
2509
2759
|
this._extensionInfo = {
|
|
2510
2760
|
publicKey: this.config.manifest.publicKey,
|
|
2511
2761
|
name: this.config.manifest.name,
|
|
2512
2762
|
version: this.config.manifest.version,
|
|
2513
|
-
displayName: this.config.manifest.name
|
|
2763
|
+
displayName: this.config.manifest.displayName ?? this.config.manifest.name
|
|
2514
2764
|
};
|
|
2515
2765
|
this.notifySubscribersInternal();
|
|
2516
2766
|
}
|