@haex-space/vault-sdk 2.3.8 → 2.3.10

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.
@@ -17,6 +17,8 @@ declare const HAEXTENSION_EVENTS: {
17
17
  readonly CONTEXT_CHANGED: "haextension:context:changed";
18
18
  /** Search request from HaexHub */
19
19
  readonly SEARCH_REQUEST: "haextension:search:request";
20
+ /** External request from authorized client (browser extension, CLI, server, etc.) */
21
+ readonly EXTERNAL_REQUEST: "haextension:external:request";
20
22
  };
21
23
  type HaextensionEvent = typeof HAEXTENSION_EVENTS[keyof typeof HAEXTENSION_EVENTS];
22
24
 
@@ -150,6 +152,44 @@ interface SearchRequestEvent extends HaexHubEvent {
150
152
  requestId: string;
151
153
  };
152
154
  }
155
+ /**
156
+ * External request from an authorized client (browser extension, CLI, server, etc.)
157
+ * These requests come through the WebSocket bridge and are routed to the appropriate extension.
158
+ */
159
+ interface ExternalRequestEvent extends HaexHubEvent {
160
+ type: typeof HAEXTENSION_EVENTS.EXTERNAL_REQUEST;
161
+ data: ExternalRequest;
162
+ }
163
+ /**
164
+ * External request payload
165
+ */
166
+ interface ExternalRequest {
167
+ /** Unique request ID for response correlation */
168
+ requestId: string;
169
+ /** Client's public key (Base64 SPKI format, used as identifier) */
170
+ publicKey: string;
171
+ /** Action/method to perform (extension-specific) */
172
+ action: string;
173
+ /** Request payload (extension-specific) */
174
+ payload: Record<string, unknown>;
175
+ }
176
+ /**
177
+ * External request response (sent back to the client)
178
+ */
179
+ interface ExternalResponse {
180
+ /** Request ID for correlation */
181
+ requestId: string;
182
+ /** Whether the request was successful */
183
+ success: boolean;
184
+ /** Response data (if successful) */
185
+ data?: unknown;
186
+ /** Error message (if failed) */
187
+ error?: string;
188
+ }
189
+ /**
190
+ * Handler function type for external requests
191
+ */
192
+ type ExternalRequestHandler = (request: ExternalRequest) => Promise<ExternalResponse> | ExternalResponse;
153
193
  type EventCallback = (event: HaexHubEvent) => void;
154
194
  interface ExtensionManifest {
155
195
  name: string;
@@ -235,4 +275,4 @@ declare class HaexHubError extends Error {
235
275
  };
236
276
  }
237
277
 
238
- export { type ApplicationContext as A, type ContextChangedEvent as C, type DatabaseQueryResult as D, type ExtensionManifest as E, type HaexHubConfig as H, type Migration as M, type PermissionResponse as P, type SearchResult as S, TABLE_SEPARATOR as T, type WebRequestOptions as W, type ExtensionInfo as a, type MigrationResult as b, type WebResponse as c, type DatabasePermissionRequest as d, type EventCallback as e, type HaexHubRequest as f, type HaexHubResponse as g, type HaexHubEvent as h, type DatabasePermission as i, type DatabaseQueryParams as j, type DatabaseExecuteParams as k, type DatabaseTableInfo as l, type DatabaseColumnInfo as m, type SearchQuery as n, type SearchRequestEvent as o, PermissionStatus as p, ErrorCode as q, DEFAULT_TIMEOUT as r, getTableName as s, HaexHubError as t, HAEXTENSION_EVENTS as u, type HaextensionEvent as v };
278
+ export { type ApplicationContext as A, type ContextChangedEvent as C, type DatabaseQueryResult as D, type ExtensionManifest as E, type HaexHubConfig as H, type Migration as M, type PermissionResponse as P, type SearchResult as S, TABLE_SEPARATOR as T, type WebRequestOptions as W, type ExtensionInfo as a, type MigrationResult as b, type WebResponse as c, type DatabasePermissionRequest as d, type ExternalRequestHandler as e, type ExternalResponse as f, type EventCallback as g, type HaexHubRequest as h, type HaexHubResponse as i, type HaexHubEvent as j, type DatabasePermission as k, type DatabaseQueryParams as l, type DatabaseExecuteParams as m, type DatabaseTableInfo as n, type DatabaseColumnInfo as o, type SearchQuery as p, type SearchRequestEvent as q, type ExternalRequestEvent as r, type ExternalRequest as s, PermissionStatus as t, ErrorCode as u, DEFAULT_TIMEOUT as v, getTableName as w, HaexHubError as x, HAEXTENSION_EVENTS as y, type HaextensionEvent as z };
@@ -17,6 +17,8 @@ declare const HAEXTENSION_EVENTS: {
17
17
  readonly CONTEXT_CHANGED: "haextension:context:changed";
18
18
  /** Search request from HaexHub */
19
19
  readonly SEARCH_REQUEST: "haextension:search:request";
20
+ /** External request from authorized client (browser extension, CLI, server, etc.) */
21
+ readonly EXTERNAL_REQUEST: "haextension:external:request";
20
22
  };
21
23
  type HaextensionEvent = typeof HAEXTENSION_EVENTS[keyof typeof HAEXTENSION_EVENTS];
22
24
 
@@ -150,6 +152,44 @@ interface SearchRequestEvent extends HaexHubEvent {
150
152
  requestId: string;
151
153
  };
152
154
  }
155
+ /**
156
+ * External request from an authorized client (browser extension, CLI, server, etc.)
157
+ * These requests come through the WebSocket bridge and are routed to the appropriate extension.
158
+ */
159
+ interface ExternalRequestEvent extends HaexHubEvent {
160
+ type: typeof HAEXTENSION_EVENTS.EXTERNAL_REQUEST;
161
+ data: ExternalRequest;
162
+ }
163
+ /**
164
+ * External request payload
165
+ */
166
+ interface ExternalRequest {
167
+ /** Unique request ID for response correlation */
168
+ requestId: string;
169
+ /** Client's public key (Base64 SPKI format, used as identifier) */
170
+ publicKey: string;
171
+ /** Action/method to perform (extension-specific) */
172
+ action: string;
173
+ /** Request payload (extension-specific) */
174
+ payload: Record<string, unknown>;
175
+ }
176
+ /**
177
+ * External request response (sent back to the client)
178
+ */
179
+ interface ExternalResponse {
180
+ /** Request ID for correlation */
181
+ requestId: string;
182
+ /** Whether the request was successful */
183
+ success: boolean;
184
+ /** Response data (if successful) */
185
+ data?: unknown;
186
+ /** Error message (if failed) */
187
+ error?: string;
188
+ }
189
+ /**
190
+ * Handler function type for external requests
191
+ */
192
+ type ExternalRequestHandler = (request: ExternalRequest) => Promise<ExternalResponse> | ExternalResponse;
153
193
  type EventCallback = (event: HaexHubEvent) => void;
154
194
  interface ExtensionManifest {
155
195
  name: string;
@@ -235,4 +275,4 @@ declare class HaexHubError extends Error {
235
275
  };
236
276
  }
237
277
 
238
- export { type ApplicationContext as A, type ContextChangedEvent as C, type DatabaseQueryResult as D, type ExtensionManifest as E, type HaexHubConfig as H, type Migration as M, type PermissionResponse as P, type SearchResult as S, TABLE_SEPARATOR as T, type WebRequestOptions as W, type ExtensionInfo as a, type MigrationResult as b, type WebResponse as c, type DatabasePermissionRequest as d, type EventCallback as e, type HaexHubRequest as f, type HaexHubResponse as g, type HaexHubEvent as h, type DatabasePermission as i, type DatabaseQueryParams as j, type DatabaseExecuteParams as k, type DatabaseTableInfo as l, type DatabaseColumnInfo as m, type SearchQuery as n, type SearchRequestEvent as o, PermissionStatus as p, ErrorCode as q, DEFAULT_TIMEOUT as r, getTableName as s, HaexHubError as t, HAEXTENSION_EVENTS as u, type HaextensionEvent as v };
278
+ export { type ApplicationContext as A, type ContextChangedEvent as C, type DatabaseQueryResult as D, type ExtensionManifest as E, type HaexHubConfig as H, type Migration as M, type PermissionResponse as P, type SearchResult as S, TABLE_SEPARATOR as T, type WebRequestOptions as W, type ExtensionInfo as a, type MigrationResult as b, type WebResponse as c, type DatabasePermissionRequest as d, type ExternalRequestHandler as e, type ExternalResponse as f, type EventCallback as g, type HaexHubRequest as h, type HaexHubResponse as i, type HaexHubEvent as j, type DatabasePermission as k, type DatabaseQueryParams as l, type DatabaseExecuteParams as m, type DatabaseTableInfo as n, type DatabaseColumnInfo as o, type SearchQuery as p, type SearchRequestEvent as q, type ExternalRequestEvent as r, type ExternalRequest as s, PermissionStatus as t, ErrorCode as u, DEFAULT_TIMEOUT as v, getTableName as w, HaexHubError as x, HAEXTENSION_EVENTS as y, type HaextensionEvent as z };
package/dist/vue.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultClient, S as StorageAPI } from './client-BIiJwbdW.mjs';
1
+ import { H as HaexVaultClient, S as StorageAPI } from './client-BdeVsDdi.mjs';
2
2
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
3
3
  import { Ref } from 'vue';
4
- import { H as HaexHubConfig } from './types-FE9ewl3r.mjs';
4
+ import { H as HaexHubConfig } from './types-DBF83o_W.mjs';
5
5
 
6
6
  /**
7
7
  * Vue 3 composable for HaexHub SDK
package/dist/vue.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultClient, S as StorageAPI } from './client-D4hDL-PR.js';
1
+ import { H as HaexVaultClient, S as StorageAPI } from './client-Ctv_qXuk.js';
2
2
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
3
3
  import { Ref } from 'vue';
4
- import { H as HaexHubConfig } from './types-FE9ewl3r.js';
4
+ import { H as HaexHubConfig } from './types-DBF83o_W.js';
5
5
 
6
6
  /**
7
7
  * Vue 3 composable for HaexHub SDK
package/dist/vue.js CHANGED
@@ -337,7 +337,9 @@ var HAEXTENSION_EVENTS = {
337
337
  /** Context (theme, locale, platform) has changed */
338
338
  CONTEXT_CHANGED: "haextension:context:changed",
339
339
  /** Search request from HaexHub */
340
- SEARCH_REQUEST: "haextension:search:request"
340
+ SEARCH_REQUEST: "haextension:search:request",
341
+ /** External request from authorized client (browser extension, CLI, server, etc.) */
342
+ EXTERNAL_REQUEST: "haextension:external:request"
341
343
  };
342
344
 
343
345
  // src/methods.ts
@@ -757,6 +759,7 @@ var HaexVaultClient = class {
757
759
  constructor(config = {}) {
758
760
  this.pendingRequests = /* @__PURE__ */ new Map();
759
761
  this.eventListeners = /* @__PURE__ */ new Map();
762
+ this.externalRequestHandlers = /* @__PURE__ */ new Map();
760
763
  this.messageHandler = null;
761
764
  this.initialized = false;
762
765
  this.requestCounter = 0;
@@ -1019,6 +1022,40 @@ var HaexVaultClient = class {
1019
1022
  results
1020
1023
  });
1021
1024
  }
1025
+ /**
1026
+ * Register a handler for external requests (from browser extensions, CLI, servers, etc.)
1027
+ *
1028
+ * @param action - The action/method name to handle (e.g., "get-logins", "get-totp")
1029
+ * @param handler - Function that processes the request and returns a response
1030
+ * @returns Unsubscribe function to remove the handler
1031
+ *
1032
+ * @example
1033
+ * ```typescript
1034
+ * client.onExternalRequest("get-logins", async (request) => {
1035
+ * const entries = await getMatchingEntries(request.payload.url);
1036
+ * return {
1037
+ * requestId: request.requestId,
1038
+ * success: true,
1039
+ * data: { entries }
1040
+ * };
1041
+ * });
1042
+ * ```
1043
+ */
1044
+ onExternalRequest(action, handler) {
1045
+ this.externalRequestHandlers.set(action, handler);
1046
+ this.log(`[ExternalRequest] Registered handler for action: ${action}`);
1047
+ return () => {
1048
+ this.externalRequestHandlers.delete(action);
1049
+ this.log(`[ExternalRequest] Unregistered handler for action: ${action}`);
1050
+ };
1051
+ }
1052
+ /**
1053
+ * Send a response to an external request back to haex-vault
1054
+ * This is called internally after a handler processes a request
1055
+ */
1056
+ async respondToExternalRequest(response) {
1057
+ await this.request("external.respond", response);
1058
+ }
1022
1059
  async request(method, params = {}) {
1023
1060
  if (this.isNativeWindow && typeof window.__TAURI__ !== "undefined") {
1024
1061
  return this.invoke(method, params);
@@ -1116,6 +1153,13 @@ var HaexVaultClient = class {
1116
1153
  extensionVersion: params.extensionVersion,
1117
1154
  migrations: params.migrations
1118
1155
  });
1156
+ case "external.respond":
1157
+ return invoke("webview_extension_external_respond", {
1158
+ requestId: params.requestId,
1159
+ success: params.success,
1160
+ data: params.data,
1161
+ error: params.error
1162
+ });
1119
1163
  default:
1120
1164
  throw new HaexHubError(
1121
1165
  "METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */,
@@ -1184,6 +1228,22 @@ var HaexVaultClient = class {
1184
1228
  console.error("[HaexSpace SDK] Failed to setup context change listener:", error);
1185
1229
  this.log("Failed to setup context change listener:", error);
1186
1230
  }
1231
+ try {
1232
+ await listen(HAEXTENSION_EVENTS.EXTERNAL_REQUEST, (event) => {
1233
+ this.log("Received external request event:", event);
1234
+ if (event.payload) {
1235
+ this.handleEvent({
1236
+ type: HAEXTENSION_EVENTS.EXTERNAL_REQUEST,
1237
+ data: event.payload,
1238
+ timestamp: Date.now()
1239
+ });
1240
+ }
1241
+ });
1242
+ console.log("[HaexSpace SDK] External request listener registered successfully");
1243
+ } catch (error) {
1244
+ console.error("[HaexSpace SDK] Failed to setup external request listener:", error);
1245
+ this.log("Failed to setup external request listener:", error);
1246
+ }
1187
1247
  this.resolveReady();
1188
1248
  return;
1189
1249
  }
@@ -1305,8 +1365,38 @@ postMessage error: ${e}`);
1305
1365
  this.log("Context updated:", this._context);
1306
1366
  this.notifySubscribers();
1307
1367
  }
1368
+ if (event.type === HAEXTENSION_EVENTS.EXTERNAL_REQUEST) {
1369
+ const externalEvent = event;
1370
+ this.handleExternalRequest(externalEvent.data);
1371
+ return;
1372
+ }
1308
1373
  this.emitEvent(event);
1309
1374
  }
1375
+ async handleExternalRequest(request) {
1376
+ this.log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
1377
+ const handler = this.externalRequestHandlers.get(request.action);
1378
+ if (!handler) {
1379
+ this.log(`[ExternalRequest] No handler for action: ${request.action}`);
1380
+ await this.respondToExternalRequest({
1381
+ requestId: request.requestId,
1382
+ success: false,
1383
+ error: `No handler registered for action: ${request.action}`
1384
+ });
1385
+ return;
1386
+ }
1387
+ try {
1388
+ const response = await handler(request);
1389
+ await this.respondToExternalRequest(response);
1390
+ this.log(`[ExternalRequest] Response sent for: ${request.action}`);
1391
+ } catch (error) {
1392
+ this.log(`[ExternalRequest] Handler error:`, error);
1393
+ await this.respondToExternalRequest({
1394
+ requestId: request.requestId,
1395
+ success: false,
1396
+ error: error instanceof Error ? error.message : String(error)
1397
+ });
1398
+ }
1399
+ }
1310
1400
  emitEvent(event) {
1311
1401
  this.log("Event received:", event);
1312
1402
  const listeners = this.eventListeners.get(event.type);