@haex-space/vault-sdk 3.7.0 → 4.0.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 (51) hide show
  1. package/README.md +51 -19
  2. package/dist/cli/index.js +437 -355
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/cli/index.mjs +428 -339
  5. package/dist/cli/index.mjs.map +1 -1
  6. package/dist/{client-DH4Km77u.d.ts → client-C6pEREPM.d.ts} +48 -3
  7. package/dist/{client-Dn4AbXbT.d.mts → client-GdCi-m2s.d.mts} +48 -3
  8. package/dist/haex_bundle_bg.wasm +0 -0
  9. package/dist/index.d.mts +11 -59
  10. package/dist/index.d.ts +11 -59
  11. package/dist/index.js +130 -105
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +149 -123
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/node.d.mts +53 -2
  16. package/dist/node.d.ts +53 -2
  17. package/dist/node.js +319 -2
  18. package/dist/node.js.map +1 -1
  19. package/dist/node.mjs +320 -5
  20. package/dist/node.mjs.map +1 -1
  21. package/dist/nuxt.js +7 -5
  22. package/dist/nuxt.js.map +1 -1
  23. package/dist/nuxt.mjs +3 -2
  24. package/dist/nuxt.mjs.map +1 -1
  25. package/dist/react.d.mts +2 -2
  26. package/dist/react.d.ts +2 -2
  27. package/dist/react.js +137 -7
  28. package/dist/react.js.map +1 -1
  29. package/dist/react.mjs +157 -27
  30. package/dist/react.mjs.map +1 -1
  31. package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
  32. package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
  33. package/dist/runtime/nuxt.plugin.client.js +45 -7
  34. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  35. package/dist/runtime/nuxt.plugin.client.mjs +45 -7
  36. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  37. package/dist/svelte.d.mts +2 -2
  38. package/dist/svelte.d.ts +2 -2
  39. package/dist/svelte.js +137 -7
  40. package/dist/svelte.js.map +1 -1
  41. package/dist/svelte.mjs +157 -27
  42. package/dist/svelte.mjs.map +1 -1
  43. package/dist/{types-DQZCRfC-.d.mts → types-Ba4G6ZpC.d.mts} +10 -2
  44. package/dist/{types-DQZCRfC-.d.ts → types-Ba4G6ZpC.d.ts} +10 -2
  45. package/dist/vue.d.mts +2 -2
  46. package/dist/vue.d.ts +2 -2
  47. package/dist/vue.js +137 -7
  48. package/dist/vue.js.map +1 -1
  49. package/dist/vue.mjs +157 -27
  50. package/dist/vue.mjs.map +1 -1
  51. package/package.json +8 -6
@@ -180,7 +180,12 @@ var EXTENSION_COMMANDS = {
180
180
  /** Get extension info (manifest, id, etc.) */
181
181
  getInfo: "extension_get_info",
182
182
  /** Get application context (theme, locale, etc.) */
183
- getContext: "extension_context_get"};
183
+ getContext: "extension_context_get",
184
+ /** Ask the host to mark (or unmark) this extension's own tab as wanting attention */
185
+ tabAttention: "extension_tab_attention",
186
+ /** Ask the user to confirm, in a dialog the host draws over this extension's tab */
187
+ dialogConfirm: "extension_dialog_confirm"
188
+ };
184
189
 
185
190
  // src/commands/remoteStorage.ts
186
191
  var REMOTE_STORAGE_COMMANDS = {
@@ -1515,6 +1520,32 @@ var NotificationsAPI = class {
1515
1520
  }
1516
1521
  };
1517
1522
 
1523
+ // src/api/tab.ts
1524
+ var TabAPI = class {
1525
+ constructor(client) {
1526
+ this.client = client;
1527
+ }
1528
+ /**
1529
+ * Mark the tab as wanting the user's attention (`true`), e.g. for unread
1530
+ * content, or clear the mark (`false`).
1531
+ */
1532
+ async requestAttention(active) {
1533
+ await this.client.request(EXTENSION_COMMANDS.tabAttention, { active });
1534
+ }
1535
+ };
1536
+
1537
+ // src/api/dialog.ts
1538
+ var DialogAPI = class {
1539
+ constructor(client) {
1540
+ this.client = client;
1541
+ }
1542
+ /** Asks the user; resolves `true` for confirm, `false` for cancel or when the dialog is closed. */
1543
+ async confirm(options) {
1544
+ const answer = await this.client.request(EXTENSION_COMMANDS.dialogConfirm, { ...options }, { timeout: null });
1545
+ return answer === true;
1546
+ }
1547
+ };
1548
+
1518
1549
  // src/messages.ts
1519
1550
  var HAEXSPACE_MESSAGE_TYPES = {
1520
1551
  /** Debug message for development/troubleshooting */
@@ -1840,6 +1871,10 @@ function waitForHostPortAsync(log) {
1840
1871
  const handler = (event) => {
1841
1872
  const type = event.data?.type;
1842
1873
  if (type !== HAEXSPACE_MESSAGE_TYPES.PORT_INIT) return;
1874
+ if (event.source !== window.parent) {
1875
+ log("PORT_INIT from a window other than the parent \u2014 ignoring");
1876
+ return;
1877
+ }
1843
1878
  const port = event.ports[0];
1844
1879
  if (!port) {
1845
1880
  log("PORT_INIT received but event.ports is empty \u2014 ignoring");
@@ -1876,7 +1911,7 @@ postMessage error: ${e}`);
1876
1911
  function generateRequestId(counter) {
1877
1912
  return `req_${counter}`;
1878
1913
  }
1879
- function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port) {
1914
+ function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests, port, timeoutMs = config.timeout) {
1880
1915
  if (!port) {
1881
1916
  return Promise.reject(
1882
1917
  new HaexVaultSdkError(
@@ -1891,14 +1926,14 @@ function sendPostMessage(method, params, requestId, config, extensionInfo, pendi
1891
1926
  timestamp: Date.now()
1892
1927
  };
1893
1928
  return new Promise((resolve, reject) => {
1894
- const timeout = setTimeout(() => {
1929
+ const timeout = timeoutMs === null ? void 0 : setTimeout(() => {
1895
1930
  pendingRequests.delete(requestId);
1896
1931
  reject(
1897
1932
  new HaexVaultSdkError("TIMEOUT" /* TIMEOUT */, "errors.timeout", {
1898
- timeout: config.timeout
1933
+ timeout: timeoutMs
1899
1934
  })
1900
1935
  );
1901
- }, config.timeout);
1936
+ }, timeoutMs);
1902
1937
  pendingRequests.set(requestId, { resolve, reject, timeout });
1903
1938
  if (config.debug) {
1904
1939
  console.log("[SDK Debug] ========== Sending Request ==========");
@@ -2251,6 +2286,8 @@ var HaexVaultSdk = class {
2251
2286
  this.passwords = new PasswordsAPI(this);
2252
2287
  this.mail = new MailAPI(this);
2253
2288
  this.notifications = new NotificationsAPI(this);
2289
+ this.tab = new TabAPI(this);
2290
+ this.dialog = new DialogAPI(this);
2254
2291
  installConsoleForwarding(this.config.debug);
2255
2292
  this.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, (event) => {
2256
2293
  const data = event.data;
@@ -2406,7 +2443,7 @@ var HaexVaultSdk = class {
2406
2443
  // ==========================================================================
2407
2444
  // Communication
2408
2445
  // ==========================================================================
2409
- async request(method, params) {
2446
+ async request(method, params, options) {
2410
2447
  const resolvedParams = params ?? {};
2411
2448
  const send = () => {
2412
2449
  if (this.isNativeWindow && hasTauri()) {
@@ -2425,7 +2462,8 @@ var HaexVaultSdk = class {
2425
2462
  this.config,
2426
2463
  this._extensionInfo,
2427
2464
  this.pendingRequests,
2428
- this.hostPort
2465
+ this.hostPort,
2466
+ options?.timeout
2429
2467
  );
2430
2468
  };
2431
2469
  return withPermissionRetry(send, this.permissionWaiters, this.log.bind(this));