@haex-space/vault-sdk 2.3.15 → 2.4.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-ChH7wiuU.d.ts → client-BSdAg7D1.d.ts} +25 -95
- package/dist/{client-8eGxojZ1.d.mts → client-ClYpUDoI.d.mts} +25 -95
- package/dist/index.d.mts +75 -5
- package/dist/index.d.ts +75 -5
- package/dist/index.js +1090 -678
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1087 -678
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +1024 -655
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1024 -655
- 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 +1033 -664
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +1033 -664
- 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 +1026 -657
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +1026 -657
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-DBF83o_W.d.mts → types-CmPqOcLB.d.mts} +8 -8
- package/dist/{types-DBF83o_W.d.ts → types-CmPqOcLB.d.ts} +8 -8
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +1024 -655
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1024 -655
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/svelte.mjs
CHANGED
|
@@ -340,6 +340,46 @@ var HAEXTENSION_EVENTS = {
|
|
|
340
340
|
EXTERNAL_REQUEST: "haextension:external:request"
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
+
// src/types.ts
|
|
344
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
345
|
+
var TABLE_SEPARATOR = "__";
|
|
346
|
+
function getTableName(publicKey, extensionName, tableName) {
|
|
347
|
+
return `${publicKey}${TABLE_SEPARATOR}${extensionName}${TABLE_SEPARATOR}${tableName}`;
|
|
348
|
+
}
|
|
349
|
+
var HaexVaultSdkError = class extends Error {
|
|
350
|
+
constructor(code, messageKey, details) {
|
|
351
|
+
super(messageKey);
|
|
352
|
+
this.code = code;
|
|
353
|
+
this.messageKey = messageKey;
|
|
354
|
+
this.details = details;
|
|
355
|
+
this.name = "HaexVaultSdkError";
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get localized error message
|
|
359
|
+
* @param locale - Locale code (e.g., 'en', 'de')
|
|
360
|
+
* @param translations - Translation object
|
|
361
|
+
*/
|
|
362
|
+
getLocalizedMessage(locale = "en", translations) {
|
|
363
|
+
if (!translations || !translations[locale]) {
|
|
364
|
+
return this.messageKey;
|
|
365
|
+
}
|
|
366
|
+
let message = translations[locale][this.messageKey] || this.messageKey;
|
|
367
|
+
if (this.details) {
|
|
368
|
+
Object.entries(this.details).forEach(([key, value]) => {
|
|
369
|
+
message = message.replace(`{${key}}`, String(value));
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return message;
|
|
373
|
+
}
|
|
374
|
+
toJSON() {
|
|
375
|
+
return {
|
|
376
|
+
code: this.code,
|
|
377
|
+
message: this.messageKey,
|
|
378
|
+
details: this.details
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
343
383
|
// src/methods.ts
|
|
344
384
|
var HAEXTENSION_METHODS = {
|
|
345
385
|
context: {
|
|
@@ -401,46 +441,6 @@ var HAEXTENSION_METHODS = {
|
|
|
401
441
|
}
|
|
402
442
|
};
|
|
403
443
|
|
|
404
|
-
// src/types.ts
|
|
405
|
-
var DEFAULT_TIMEOUT = 3e4;
|
|
406
|
-
var TABLE_SEPARATOR = "__";
|
|
407
|
-
function getTableName(publicKey, extensionName, tableName) {
|
|
408
|
-
return `${publicKey}${TABLE_SEPARATOR}${extensionName}${TABLE_SEPARATOR}${tableName}`;
|
|
409
|
-
}
|
|
410
|
-
var HaexHubError = class extends Error {
|
|
411
|
-
constructor(code, messageKey, details) {
|
|
412
|
-
super(messageKey);
|
|
413
|
-
this.code = code;
|
|
414
|
-
this.messageKey = messageKey;
|
|
415
|
-
this.details = details;
|
|
416
|
-
this.name = "HaexHubError";
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Get localized error message
|
|
420
|
-
* @param locale - Locale code (e.g., 'en', 'de')
|
|
421
|
-
* @param translations - Translation object
|
|
422
|
-
*/
|
|
423
|
-
getLocalizedMessage(locale = "en", translations) {
|
|
424
|
-
if (!translations || !translations[locale]) {
|
|
425
|
-
return this.messageKey;
|
|
426
|
-
}
|
|
427
|
-
let message = translations[locale][this.messageKey] || this.messageKey;
|
|
428
|
-
if (this.details) {
|
|
429
|
-
Object.entries(this.details).forEach(([key, value]) => {
|
|
430
|
-
message = message.replace(`{${key}}`, String(value));
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
return message;
|
|
434
|
-
}
|
|
435
|
-
toJSON() {
|
|
436
|
-
return {
|
|
437
|
-
code: this.code,
|
|
438
|
-
message: this.messageKey,
|
|
439
|
-
details: this.details
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
444
|
// src/api/storage.ts
|
|
445
445
|
var StorageAPI = class {
|
|
446
446
|
constructor(client) {
|
|
@@ -983,548 +983,543 @@ var PermissionsAPI = class {
|
|
|
983
983
|
return response.status === "granted";
|
|
984
984
|
}
|
|
985
985
|
};
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
this._context = null;
|
|
996
|
-
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
997
|
-
this.isNativeWindow = false;
|
|
998
|
-
// Wird im Konstruktor initialisiert
|
|
999
|
-
this.setupPromise = null;
|
|
1000
|
-
this.setupHook = null;
|
|
1001
|
-
this._setupCompleted = false;
|
|
1002
|
-
this.orm = null;
|
|
1003
|
-
this.config = {
|
|
1004
|
-
debug: config.debug ?? false,
|
|
1005
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
1006
|
-
manifest: config.manifest
|
|
1007
|
-
};
|
|
1008
|
-
this.storage = new StorageAPI(this);
|
|
1009
|
-
this.database = new DatabaseAPI(this);
|
|
1010
|
-
this.filesystem = new FilesystemAPI(this);
|
|
1011
|
-
this.web = new WebAPI(this);
|
|
1012
|
-
this.permissions = new PermissionsAPI(this);
|
|
1013
|
-
installConsoleForwarding(this.config.debug);
|
|
1014
|
-
this.readyPromise = new Promise((resolve) => {
|
|
1015
|
-
this.resolveReady = resolve;
|
|
1016
|
-
});
|
|
1017
|
-
this.init();
|
|
986
|
+
|
|
987
|
+
// src/client/tableName.ts
|
|
988
|
+
function validatePublicKey(publicKey) {
|
|
989
|
+
if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
|
|
990
|
+
throw new HaexVaultSdkError(
|
|
991
|
+
"INVALID_PUBLIC_KEY" /* INVALID_PUBLIC_KEY */,
|
|
992
|
+
"errors.invalid_public_key",
|
|
993
|
+
{ publicKey }
|
|
994
|
+
);
|
|
1018
995
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
996
|
+
}
|
|
997
|
+
function validateExtensionName(extensionName) {
|
|
998
|
+
if (!extensionName || !/^[a-z][a-z0-9-]*$/i.test(extensionName)) {
|
|
999
|
+
throw new HaexVaultSdkError(
|
|
1000
|
+
"INVALID_EXTENSION_NAME" /* INVALID_EXTENSION_NAME */,
|
|
1001
|
+
"errors.invalid_extension_name",
|
|
1002
|
+
{ extensionName }
|
|
1003
|
+
);
|
|
1025
1004
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1005
|
+
if (extensionName.includes(TABLE_SEPARATOR)) {
|
|
1006
|
+
throw new HaexVaultSdkError(
|
|
1007
|
+
"INVALID_EXTENSION_NAME" /* INVALID_EXTENSION_NAME */,
|
|
1008
|
+
"errors.extension_name_contains_separator",
|
|
1009
|
+
{ extensionName, separator: TABLE_SEPARATOR }
|
|
1010
|
+
);
|
|
1031
1011
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
throw new Error("Setup hook already registered");
|
|
1040
|
-
}
|
|
1041
|
-
this.setupHook = setupFn;
|
|
1012
|
+
}
|
|
1013
|
+
function validateTableName(tableName) {
|
|
1014
|
+
if (!tableName || typeof tableName !== "string") {
|
|
1015
|
+
throw new HaexVaultSdkError(
|
|
1016
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1017
|
+
"errors.table_name_empty"
|
|
1018
|
+
);
|
|
1042
1019
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
await this.readyPromise;
|
|
1050
|
-
if (!this.setupHook || this.setupCompleted) {
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
|
-
if (!this.setupPromise) {
|
|
1054
|
-
this.setupPromise = this.runSetupAsync();
|
|
1055
|
-
}
|
|
1056
|
-
return this.setupPromise;
|
|
1020
|
+
if (tableName.includes(TABLE_SEPARATOR)) {
|
|
1021
|
+
throw new HaexVaultSdkError(
|
|
1022
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1023
|
+
"errors.table_name_contains_separator",
|
|
1024
|
+
{ tableName, separator: TABLE_SEPARATOR }
|
|
1025
|
+
);
|
|
1057
1026
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
this.log("[HaexSpace] Setup completed successfully");
|
|
1065
|
-
this.notifySubscribers();
|
|
1066
|
-
} catch (error) {
|
|
1067
|
-
this.log("[HaexSpace] Setup failed:", error);
|
|
1068
|
-
throw error;
|
|
1069
|
-
}
|
|
1027
|
+
if (!/^[a-z][a-z0-9-_]*$/i.test(tableName)) {
|
|
1028
|
+
throw new HaexVaultSdkError(
|
|
1029
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1030
|
+
"errors.table_name_format",
|
|
1031
|
+
{ tableName }
|
|
1032
|
+
);
|
|
1070
1033
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
initializeDatabase(schema) {
|
|
1078
|
-
if (!this._extensionInfo) {
|
|
1079
|
-
throw new HaexHubError(
|
|
1080
|
-
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1081
|
-
"errors.client_not_ready"
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
const dbInstance = drizzle(
|
|
1085
|
-
async (sql, params, method) => {
|
|
1086
|
-
try {
|
|
1087
|
-
if (method === "run" || method === "all") {
|
|
1088
|
-
const result2 = await this.request(
|
|
1089
|
-
HAEXTENSION_METHODS.database.execute,
|
|
1090
|
-
{
|
|
1091
|
-
query: sql,
|
|
1092
|
-
params
|
|
1093
|
-
}
|
|
1094
|
-
);
|
|
1095
|
-
if (method === "all") {
|
|
1096
|
-
return { rows: result2.rows || [] };
|
|
1097
|
-
}
|
|
1098
|
-
if (result2.rows && Array.isArray(result2.rows) && result2.rows.length > 0) {
|
|
1099
|
-
return { rows: result2.rows };
|
|
1100
|
-
}
|
|
1101
|
-
return result2;
|
|
1102
|
-
}
|
|
1103
|
-
const result = await this.request(HAEXTENSION_METHODS.database.query, {
|
|
1104
|
-
query: sql,
|
|
1105
|
-
params
|
|
1106
|
-
});
|
|
1107
|
-
const rows = result.rows;
|
|
1108
|
-
if (method === "get") {
|
|
1109
|
-
return { rows: rows.length > 0 ? rows.at(0) : void 0 };
|
|
1110
|
-
}
|
|
1111
|
-
return { rows };
|
|
1112
|
-
} catch (error) {
|
|
1113
|
-
this.log("Database operation failed:", error);
|
|
1114
|
-
throw error;
|
|
1115
|
-
}
|
|
1116
|
-
},
|
|
1117
|
-
{
|
|
1118
|
-
schema,
|
|
1119
|
-
logger: false
|
|
1120
|
-
}
|
|
1034
|
+
}
|
|
1035
|
+
function getExtensionTableName(extensionInfo2, tableName) {
|
|
1036
|
+
if (!extensionInfo2) {
|
|
1037
|
+
throw new HaexVaultSdkError(
|
|
1038
|
+
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1039
|
+
"errors.extension_info_unavailable"
|
|
1121
1040
|
);
|
|
1122
|
-
this.orm = dbInstance;
|
|
1123
|
-
return dbInstance;
|
|
1124
1041
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1042
|
+
validateTableName(tableName);
|
|
1043
|
+
const { publicKey, name } = extensionInfo2;
|
|
1044
|
+
return `"${getTableName(publicKey, name, tableName)}"`;
|
|
1045
|
+
}
|
|
1046
|
+
function getDependencyTableName(publicKey, extensionName, tableName) {
|
|
1047
|
+
validatePublicKey(publicKey);
|
|
1048
|
+
validateExtensionName(extensionName);
|
|
1049
|
+
validateTableName(tableName);
|
|
1050
|
+
return `"${getTableName(publicKey, extensionName, tableName)}"`;
|
|
1051
|
+
}
|
|
1052
|
+
function parseTableName(fullTableName) {
|
|
1053
|
+
let cleanTableName = fullTableName;
|
|
1054
|
+
if (cleanTableName.startsWith('"') && cleanTableName.endsWith('"')) {
|
|
1055
|
+
cleanTableName = cleanTableName.slice(1, -1);
|
|
1056
|
+
}
|
|
1057
|
+
const parts = cleanTableName.split(TABLE_SEPARATOR);
|
|
1058
|
+
if (parts.length !== 3) {
|
|
1059
|
+
return null;
|
|
1060
|
+
}
|
|
1061
|
+
const [publicKey, extensionName, tableName] = parts;
|
|
1062
|
+
if (!publicKey || !extensionName || !tableName) {
|
|
1063
|
+
return null;
|
|
1064
|
+
}
|
|
1065
|
+
return {
|
|
1066
|
+
publicKey,
|
|
1067
|
+
extensionName,
|
|
1068
|
+
tableName
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// src/client/init.ts
|
|
1073
|
+
function isInIframe() {
|
|
1074
|
+
return window.self !== window.top;
|
|
1075
|
+
}
|
|
1076
|
+
function hasTauri() {
|
|
1077
|
+
return typeof window.__TAURI__ !== "undefined";
|
|
1078
|
+
}
|
|
1079
|
+
function getTauriCore() {
|
|
1080
|
+
return window.__TAURI__.core;
|
|
1081
|
+
}
|
|
1082
|
+
function getTauriEvent() {
|
|
1083
|
+
return window.__TAURI__.event;
|
|
1084
|
+
}
|
|
1085
|
+
async function initNativeMode(ctx, log, onEvent, onContextChange) {
|
|
1086
|
+
const { invoke } = getTauriCore();
|
|
1087
|
+
const extensionInfo2 = await invoke("webview_extension_get_info");
|
|
1088
|
+
const context2 = await invoke("webview_extension_context_get");
|
|
1089
|
+
ctx.state.isNativeWindow = true;
|
|
1090
|
+
ctx.state.initialized = true;
|
|
1091
|
+
ctx.state.extensionInfo = extensionInfo2;
|
|
1092
|
+
ctx.state.context = context2;
|
|
1093
|
+
log("HaexVault SDK initialized in native WebViewWindow mode");
|
|
1094
|
+
log("Extension info:", extensionInfo2);
|
|
1095
|
+
log("Application context:", context2);
|
|
1096
|
+
await setupTauriEventListeners(ctx, log, onEvent, onContextChange);
|
|
1097
|
+
return { extensionInfo: extensionInfo2, context: context2 };
|
|
1098
|
+
}
|
|
1099
|
+
async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
1100
|
+
const { listen } = getTauriEvent();
|
|
1101
|
+
console.log("[HaexVault SDK] Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
|
|
1102
|
+
try {
|
|
1103
|
+
await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
|
|
1104
|
+
console.log("[HaexVault SDK] Received Tauri event:", HAEXTENSION_EVENTS.CONTEXT_CHANGED, event);
|
|
1105
|
+
log("Received context change event:", event);
|
|
1106
|
+
const payload = event.payload;
|
|
1107
|
+
if (payload?.context) {
|
|
1108
|
+
ctx.state.context = payload.context;
|
|
1109
|
+
console.log("[HaexVault SDK] Updated context to:", ctx.state.context);
|
|
1110
|
+
onContextChange(payload.context);
|
|
1111
|
+
onEvent({
|
|
1112
|
+
type: HAEXTENSION_EVENTS.CONTEXT_CHANGED,
|
|
1113
|
+
data: { context: ctx.state.context },
|
|
1114
|
+
timestamp: Date.now()
|
|
1115
|
+
});
|
|
1116
|
+
} else {
|
|
1117
|
+
console.warn("[HaexVault SDK] Event received but no context in payload:", event);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
console.log("[HaexVault SDK] Context change listener registered successfully");
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
console.error("[HaexVault SDK] Failed to setup context change listener:", error);
|
|
1123
|
+
log("Failed to setup context change listener:", error);
|
|
1127
1124
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1125
|
+
try {
|
|
1126
|
+
await listen(HAEXTENSION_EVENTS.EXTERNAL_REQUEST, (event) => {
|
|
1127
|
+
log("Received external request event:", event);
|
|
1128
|
+
if (event.payload) {
|
|
1129
|
+
onEvent({
|
|
1130
|
+
type: HAEXTENSION_EVENTS.EXTERNAL_REQUEST,
|
|
1131
|
+
data: event.payload,
|
|
1132
|
+
timestamp: Date.now()
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
console.log("[HaexVault SDK] External request listener registered successfully");
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
console.error("[HaexVault SDK] Failed to setup external request listener:", error);
|
|
1139
|
+
log("Failed to setup external request listener:", error);
|
|
1130
1140
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1141
|
+
}
|
|
1142
|
+
async function initIframeMode(ctx, log, messageHandler, request) {
|
|
1143
|
+
if (!isInIframe()) {
|
|
1144
|
+
throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1145
|
+
}
|
|
1146
|
+
ctx.handlers.messageHandler = messageHandler;
|
|
1147
|
+
window.addEventListener("message", messageHandler);
|
|
1148
|
+
ctx.state.isNativeWindow = false;
|
|
1149
|
+
ctx.state.initialized = true;
|
|
1150
|
+
log("HaexVault SDK initialized in iframe mode");
|
|
1151
|
+
if (ctx.config.manifest) {
|
|
1152
|
+
ctx.state.extensionInfo = {
|
|
1153
|
+
publicKey: ctx.config.manifest.publicKey,
|
|
1154
|
+
name: ctx.config.manifest.name,
|
|
1155
|
+
version: ctx.config.manifest.version,
|
|
1156
|
+
displayName: ctx.config.manifest.name
|
|
1135
1157
|
};
|
|
1158
|
+
log("Extension info loaded from manifest:", ctx.state.extensionInfo);
|
|
1136
1159
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1160
|
+
sendDebugInfo(ctx.config);
|
|
1161
|
+
const context2 = await request(HAEXTENSION_METHODS.context.get);
|
|
1162
|
+
ctx.state.context = context2;
|
|
1163
|
+
log("Application context received:", context2);
|
|
1164
|
+
return { context: context2 };
|
|
1165
|
+
}
|
|
1166
|
+
function sendDebugInfo(config) {
|
|
1167
|
+
if (!config.debug) return;
|
|
1168
|
+
if (typeof window === "undefined" || !window.parent) return;
|
|
1169
|
+
const debugInfo = `SDK Debug:
|
|
1170
|
+
window.parent exists: ${!!window.parent}
|
|
1171
|
+
window.parent === window: ${window.parent === window}
|
|
1172
|
+
window.self === window.top: ${window.self === window.top}`;
|
|
1173
|
+
try {
|
|
1174
|
+
window.parent.postMessage({
|
|
1175
|
+
type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
|
|
1176
|
+
data: debugInfo
|
|
1177
|
+
}, "*");
|
|
1178
|
+
} catch (e) {
|
|
1179
|
+
alert(debugInfo + `
|
|
1180
|
+
postMessage error: ${e}`);
|
|
1139
1181
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// src/commands.ts
|
|
1185
|
+
var TAURI_COMMANDS = {
|
|
1186
|
+
database: {
|
|
1187
|
+
query: "webview_extension_db_query",
|
|
1188
|
+
execute: "webview_extension_db_execute",
|
|
1189
|
+
registerMigrations: "webview_extension_db_register_migrations"
|
|
1190
|
+
},
|
|
1191
|
+
permissions: {
|
|
1192
|
+
checkWeb: "webview_extension_check_web_permission",
|
|
1193
|
+
checkDatabase: "webview_extension_check_database_permission",
|
|
1194
|
+
checkFilesystem: "webview_extension_check_filesystem_permission"
|
|
1195
|
+
},
|
|
1196
|
+
web: {
|
|
1197
|
+
open: "webview_extension_web_open",
|
|
1198
|
+
fetch: "webview_extension_web_request"
|
|
1199
|
+
},
|
|
1200
|
+
filesystem: {
|
|
1201
|
+
saveFile: "webview_extension_fs_save_file",
|
|
1202
|
+
openFile: "webview_extension_fs_open_file",
|
|
1203
|
+
showImage: "webview_extension_fs_show_image"
|
|
1204
|
+
},
|
|
1205
|
+
external: {
|
|
1206
|
+
respond: "webview_extension_external_respond"
|
|
1207
|
+
},
|
|
1208
|
+
filesync: {
|
|
1209
|
+
// Spaces
|
|
1210
|
+
listSpaces: "filesync_list_spaces",
|
|
1211
|
+
createSpace: "filesync_create_space",
|
|
1212
|
+
deleteSpace: "filesync_delete_space",
|
|
1213
|
+
// Files
|
|
1214
|
+
listFiles: "filesync_list_files",
|
|
1215
|
+
getFile: "filesync_get_file",
|
|
1216
|
+
uploadFile: "filesync_upload_file",
|
|
1217
|
+
downloadFile: "filesync_download_file",
|
|
1218
|
+
deleteFile: "filesync_delete_file",
|
|
1219
|
+
// Backends
|
|
1220
|
+
listBackends: "filesync_list_backends",
|
|
1221
|
+
addBackend: "filesync_add_backend",
|
|
1222
|
+
removeBackend: "filesync_remove_backend",
|
|
1223
|
+
testBackend: "filesync_test_backend",
|
|
1224
|
+
// Sync Rules
|
|
1225
|
+
listSyncRules: "filesync_list_sync_rules",
|
|
1226
|
+
addSyncRule: "filesync_add_sync_rule",
|
|
1227
|
+
removeSyncRule: "filesync_remove_sync_rule",
|
|
1228
|
+
// Sync Operations
|
|
1229
|
+
getSyncStatus: "filesync_get_sync_status",
|
|
1230
|
+
triggerSync: "filesync_trigger_sync",
|
|
1231
|
+
pauseSync: "filesync_pause_sync",
|
|
1232
|
+
resumeSync: "filesync_resume_sync",
|
|
1233
|
+
// Conflict Resolution
|
|
1234
|
+
resolveConflict: "filesync_resolve_conflict",
|
|
1235
|
+
// UI Helpers
|
|
1236
|
+
selectFolder: "filesync_select_folder"
|
|
1142
1237
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1238
|
+
};
|
|
1239
|
+
|
|
1240
|
+
// src/transport/handlers/database.ts
|
|
1241
|
+
var databaseHandlers = {
|
|
1242
|
+
[HAEXTENSION_METHODS.database.query]: {
|
|
1243
|
+
command: TAURI_COMMANDS.database.query,
|
|
1244
|
+
args: (p) => ({
|
|
1245
|
+
query: p.query,
|
|
1246
|
+
params: p.params || []
|
|
1247
|
+
})
|
|
1248
|
+
},
|
|
1249
|
+
[HAEXTENSION_METHODS.database.execute]: {
|
|
1250
|
+
command: TAURI_COMMANDS.database.execute,
|
|
1251
|
+
args: (p) => ({
|
|
1252
|
+
query: p.query,
|
|
1253
|
+
params: p.params || []
|
|
1254
|
+
})
|
|
1255
|
+
},
|
|
1256
|
+
[HAEXTENSION_METHODS.database.registerMigrations]: {
|
|
1257
|
+
command: TAURI_COMMANDS.database.registerMigrations,
|
|
1258
|
+
args: (p) => ({
|
|
1259
|
+
extensionVersion: p.extensionVersion,
|
|
1260
|
+
migrations: p.migrations
|
|
1261
|
+
})
|
|
1153
1262
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
// src/transport/handlers/permissions.ts
|
|
1266
|
+
var permissionsHandlers = {
|
|
1267
|
+
"permissions.web.check": {
|
|
1268
|
+
command: TAURI_COMMANDS.permissions.checkWeb,
|
|
1269
|
+
args: (p) => ({
|
|
1270
|
+
url: p.url
|
|
1271
|
+
})
|
|
1272
|
+
},
|
|
1273
|
+
"permissions.database.check": {
|
|
1274
|
+
command: TAURI_COMMANDS.permissions.checkDatabase,
|
|
1275
|
+
args: (p) => ({
|
|
1276
|
+
resource: p.resource,
|
|
1277
|
+
operation: p.operation
|
|
1278
|
+
})
|
|
1279
|
+
},
|
|
1280
|
+
"permissions.filesystem.check": {
|
|
1281
|
+
command: TAURI_COMMANDS.permissions.checkFilesystem,
|
|
1282
|
+
args: (p) => ({
|
|
1283
|
+
path: p.path,
|
|
1284
|
+
actionStr: p.action
|
|
1285
|
+
})
|
|
1159
1286
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
// src/transport/handlers/web.ts
|
|
1290
|
+
var webHandlers = {
|
|
1291
|
+
[HAEXTENSION_METHODS.application.open]: {
|
|
1292
|
+
command: TAURI_COMMANDS.web.open,
|
|
1293
|
+
args: (p) => ({
|
|
1294
|
+
url: p.url
|
|
1295
|
+
})
|
|
1296
|
+
},
|
|
1297
|
+
[HAEXTENSION_METHODS.web.fetch]: {
|
|
1298
|
+
command: TAURI_COMMANDS.web.fetch,
|
|
1299
|
+
args: (p) => ({
|
|
1300
|
+
url: p.url,
|
|
1301
|
+
method: p.method,
|
|
1302
|
+
headers: p.headers,
|
|
1303
|
+
body: p.body
|
|
1304
|
+
})
|
|
1178
1305
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
// src/transport/handlers/filesystem.ts
|
|
1309
|
+
var filesystemHandlers = {
|
|
1310
|
+
[HAEXTENSION_METHODS.filesystem.saveFile]: {
|
|
1311
|
+
command: TAURI_COMMANDS.filesystem.saveFile,
|
|
1312
|
+
args: (p) => ({
|
|
1313
|
+
data: p.data,
|
|
1314
|
+
defaultPath: p.defaultPath,
|
|
1315
|
+
title: p.title,
|
|
1316
|
+
filters: p.filters
|
|
1317
|
+
})
|
|
1318
|
+
},
|
|
1319
|
+
[HAEXTENSION_METHODS.filesystem.openFile]: {
|
|
1320
|
+
command: TAURI_COMMANDS.filesystem.openFile,
|
|
1321
|
+
args: (p) => ({
|
|
1322
|
+
data: p.data,
|
|
1323
|
+
fileName: p.fileName
|
|
1324
|
+
})
|
|
1325
|
+
},
|
|
1326
|
+
[HAEXTENSION_METHODS.filesystem.showImage]: {
|
|
1327
|
+
command: TAURI_COMMANDS.filesystem.showImage,
|
|
1328
|
+
args: (p) => ({
|
|
1329
|
+
dataUrl: p.dataUrl
|
|
1330
|
+
})
|
|
1192
1331
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
// src/transport/handlers/external.ts
|
|
1335
|
+
var externalHandlers = {
|
|
1336
|
+
"external.respond": {
|
|
1337
|
+
command: TAURI_COMMANDS.external.respond,
|
|
1338
|
+
args: (p) => ({
|
|
1339
|
+
requestId: p.requestId,
|
|
1340
|
+
success: p.success,
|
|
1341
|
+
data: p.data,
|
|
1342
|
+
error: p.error
|
|
1343
|
+
})
|
|
1198
1344
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
})
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
})
|
|
1308
|
-
);
|
|
1309
|
-
}, this.config.timeout);
|
|
1310
|
-
this.pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1311
|
-
const targetOrigin = "*";
|
|
1312
|
-
if (this.config.debug) {
|
|
1313
|
-
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1314
|
-
console.log("[SDK Debug] Request ID:", requestId);
|
|
1315
|
-
console.log("[SDK Debug] Method:", request.method);
|
|
1316
|
-
console.log("[SDK Debug] Params:", request.params);
|
|
1317
|
-
console.log("[SDK Debug] Target origin:", targetOrigin);
|
|
1318
|
-
console.log("[SDK Debug] Extension info:", this._extensionInfo);
|
|
1319
|
-
console.log("[SDK Debug] ========================================");
|
|
1320
|
-
}
|
|
1321
|
-
window.parent.postMessage({ id: requestId, ...request }, targetOrigin);
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
async invoke(method, params) {
|
|
1325
|
-
const { invoke } = window.__TAURI__.core;
|
|
1326
|
-
if (this.config.debug) {
|
|
1327
|
-
console.log("[SDK Debug] ========== Invoke Request ==========");
|
|
1328
|
-
console.log("[SDK Debug] Method:", method);
|
|
1329
|
-
console.log("[SDK Debug] Params:", params);
|
|
1330
|
-
console.log("[SDK Debug] =======================================");
|
|
1331
|
-
}
|
|
1332
|
-
switch (method) {
|
|
1333
|
-
case HAEXTENSION_METHODS.database.query:
|
|
1334
|
-
return invoke("webview_extension_db_query", {
|
|
1335
|
-
query: params.query,
|
|
1336
|
-
params: params.params || []
|
|
1337
|
-
});
|
|
1338
|
-
case HAEXTENSION_METHODS.database.execute:
|
|
1339
|
-
return invoke("webview_extension_db_execute", {
|
|
1340
|
-
query: params.query,
|
|
1341
|
-
params: params.params || []
|
|
1342
|
-
});
|
|
1343
|
-
case "permissions.web.check":
|
|
1344
|
-
return invoke("webview_extension_check_web_permission", {
|
|
1345
|
-
url: params.url
|
|
1346
|
-
});
|
|
1347
|
-
case "permissions.database.check":
|
|
1348
|
-
return invoke("webview_extension_check_database_permission", {
|
|
1349
|
-
resource: params.resource,
|
|
1350
|
-
operation: params.operation
|
|
1351
|
-
});
|
|
1352
|
-
case "permissions.filesystem.check":
|
|
1353
|
-
return invoke("webview_extension_check_filesystem_permission", {
|
|
1354
|
-
path: params.path,
|
|
1355
|
-
actionStr: params.action
|
|
1356
|
-
});
|
|
1357
|
-
case HAEXTENSION_METHODS.application.open:
|
|
1358
|
-
return invoke("webview_extension_web_open", {
|
|
1359
|
-
url: params.url
|
|
1360
|
-
});
|
|
1361
|
-
case HAEXTENSION_METHODS.web.fetch:
|
|
1362
|
-
return invoke("webview_extension_web_request", {
|
|
1363
|
-
url: params.url,
|
|
1364
|
-
method: params.method,
|
|
1365
|
-
headers: params.headers,
|
|
1366
|
-
body: params.body
|
|
1367
|
-
});
|
|
1368
|
-
case HAEXTENSION_METHODS.filesystem.saveFile:
|
|
1369
|
-
return invoke("webview_extension_fs_save_file", {
|
|
1370
|
-
data: params.data,
|
|
1371
|
-
defaultPath: params.defaultPath,
|
|
1372
|
-
title: params.title,
|
|
1373
|
-
filters: params.filters
|
|
1374
|
-
});
|
|
1375
|
-
case HAEXTENSION_METHODS.filesystem.openFile:
|
|
1376
|
-
return invoke("webview_extension_fs_open_file", {
|
|
1377
|
-
data: params.data,
|
|
1378
|
-
fileName: params.fileName
|
|
1379
|
-
});
|
|
1380
|
-
case HAEXTENSION_METHODS.database.registerMigrations:
|
|
1381
|
-
return invoke("webview_extension_db_register_migrations", {
|
|
1382
|
-
extensionVersion: params.extensionVersion,
|
|
1383
|
-
migrations: params.migrations
|
|
1384
|
-
});
|
|
1385
|
-
case "external.respond":
|
|
1386
|
-
return invoke("webview_extension_external_respond", {
|
|
1387
|
-
requestId: params.requestId,
|
|
1388
|
-
success: params.success,
|
|
1389
|
-
data: params.data,
|
|
1390
|
-
error: params.error
|
|
1391
|
-
});
|
|
1392
|
-
default:
|
|
1393
|
-
throw new HaexHubError(
|
|
1394
|
-
"METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */,
|
|
1395
|
-
"errors.method_not_found",
|
|
1396
|
-
{ method }
|
|
1397
|
-
);
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
on(eventType, callback) {
|
|
1401
|
-
if (!this.eventListeners.has(eventType)) {
|
|
1402
|
-
this.eventListeners.set(eventType, /* @__PURE__ */ new Set());
|
|
1403
|
-
}
|
|
1404
|
-
this.eventListeners.get(eventType).add(callback);
|
|
1405
|
-
}
|
|
1406
|
-
off(eventType, callback) {
|
|
1407
|
-
const listeners = this.eventListeners.get(eventType);
|
|
1408
|
-
if (listeners) {
|
|
1409
|
-
listeners.delete(callback);
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
destroy() {
|
|
1413
|
-
if (this.messageHandler) {
|
|
1414
|
-
window.removeEventListener("message", this.messageHandler);
|
|
1415
|
-
}
|
|
1416
|
-
this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
|
|
1417
|
-
this.pendingRequests.clear();
|
|
1418
|
-
this.eventListeners.clear();
|
|
1419
|
-
this.initialized = false;
|
|
1420
|
-
this.log("HaexHub SDK destroyed");
|
|
1345
|
+
};
|
|
1346
|
+
|
|
1347
|
+
// src/transport/handlers/filesync.ts
|
|
1348
|
+
var filesyncHandlers = {
|
|
1349
|
+
// ==========================================================================
|
|
1350
|
+
// Spaces
|
|
1351
|
+
// ==========================================================================
|
|
1352
|
+
[HAEXTENSION_METHODS.filesystem.sync.listSpaces]: {
|
|
1353
|
+
command: TAURI_COMMANDS.filesync.listSpaces,
|
|
1354
|
+
args: () => ({})
|
|
1355
|
+
},
|
|
1356
|
+
[HAEXTENSION_METHODS.filesystem.sync.createSpace]: {
|
|
1357
|
+
command: TAURI_COMMANDS.filesync.createSpace,
|
|
1358
|
+
args: (p) => ({ request: p })
|
|
1359
|
+
},
|
|
1360
|
+
[HAEXTENSION_METHODS.filesystem.sync.deleteSpace]: {
|
|
1361
|
+
command: TAURI_COMMANDS.filesync.deleteSpace,
|
|
1362
|
+
args: (p) => ({ spaceId: p.spaceId })
|
|
1363
|
+
},
|
|
1364
|
+
// ==========================================================================
|
|
1365
|
+
// Files
|
|
1366
|
+
// ==========================================================================
|
|
1367
|
+
[HAEXTENSION_METHODS.filesystem.sync.listFiles]: {
|
|
1368
|
+
command: TAURI_COMMANDS.filesync.listFiles,
|
|
1369
|
+
args: (p) => ({ request: p })
|
|
1370
|
+
},
|
|
1371
|
+
[HAEXTENSION_METHODS.filesystem.sync.getFile]: {
|
|
1372
|
+
command: TAURI_COMMANDS.filesync.getFile,
|
|
1373
|
+
args: (p) => ({ fileId: p.fileId })
|
|
1374
|
+
},
|
|
1375
|
+
[HAEXTENSION_METHODS.filesystem.sync.uploadFile]: {
|
|
1376
|
+
command: TAURI_COMMANDS.filesync.uploadFile,
|
|
1377
|
+
args: (p) => ({ request: p })
|
|
1378
|
+
},
|
|
1379
|
+
[HAEXTENSION_METHODS.filesystem.sync.downloadFile]: {
|
|
1380
|
+
command: TAURI_COMMANDS.filesync.downloadFile,
|
|
1381
|
+
args: (p) => ({ request: p })
|
|
1382
|
+
},
|
|
1383
|
+
[HAEXTENSION_METHODS.filesystem.sync.deleteFile]: {
|
|
1384
|
+
command: TAURI_COMMANDS.filesync.deleteFile,
|
|
1385
|
+
args: (p) => ({ fileId: p.fileId })
|
|
1386
|
+
},
|
|
1387
|
+
// ==========================================================================
|
|
1388
|
+
// Backends
|
|
1389
|
+
// ==========================================================================
|
|
1390
|
+
[HAEXTENSION_METHODS.filesystem.sync.listBackends]: {
|
|
1391
|
+
command: TAURI_COMMANDS.filesync.listBackends,
|
|
1392
|
+
args: () => ({})
|
|
1393
|
+
},
|
|
1394
|
+
[HAEXTENSION_METHODS.filesystem.sync.addBackend]: {
|
|
1395
|
+
command: TAURI_COMMANDS.filesync.addBackend,
|
|
1396
|
+
args: (p) => ({ request: p })
|
|
1397
|
+
},
|
|
1398
|
+
[HAEXTENSION_METHODS.filesystem.sync.removeBackend]: {
|
|
1399
|
+
command: TAURI_COMMANDS.filesync.removeBackend,
|
|
1400
|
+
args: (p) => ({ backendId: p.backendId })
|
|
1401
|
+
},
|
|
1402
|
+
[HAEXTENSION_METHODS.filesystem.sync.testBackend]: {
|
|
1403
|
+
command: TAURI_COMMANDS.filesync.testBackend,
|
|
1404
|
+
args: (p) => ({ backendId: p.backendId })
|
|
1405
|
+
},
|
|
1406
|
+
// ==========================================================================
|
|
1407
|
+
// Sync Rules
|
|
1408
|
+
// ==========================================================================
|
|
1409
|
+
[HAEXTENSION_METHODS.filesystem.sync.listSyncRules]: {
|
|
1410
|
+
command: TAURI_COMMANDS.filesync.listSyncRules,
|
|
1411
|
+
args: () => ({})
|
|
1412
|
+
},
|
|
1413
|
+
[HAEXTENSION_METHODS.filesystem.sync.addSyncRule]: {
|
|
1414
|
+
command: TAURI_COMMANDS.filesync.addSyncRule,
|
|
1415
|
+
args: (p) => ({ request: p })
|
|
1416
|
+
},
|
|
1417
|
+
[HAEXTENSION_METHODS.filesystem.sync.removeSyncRule]: {
|
|
1418
|
+
command: TAURI_COMMANDS.filesync.removeSyncRule,
|
|
1419
|
+
args: (p) => ({ ruleId: p.ruleId })
|
|
1420
|
+
},
|
|
1421
|
+
// ==========================================================================
|
|
1422
|
+
// Sync Operations
|
|
1423
|
+
// ==========================================================================
|
|
1424
|
+
[HAEXTENSION_METHODS.filesystem.sync.getSyncStatus]: {
|
|
1425
|
+
command: TAURI_COMMANDS.filesync.getSyncStatus,
|
|
1426
|
+
args: () => ({})
|
|
1427
|
+
},
|
|
1428
|
+
[HAEXTENSION_METHODS.filesystem.sync.triggerSync]: {
|
|
1429
|
+
command: TAURI_COMMANDS.filesync.triggerSync,
|
|
1430
|
+
args: () => ({})
|
|
1431
|
+
},
|
|
1432
|
+
[HAEXTENSION_METHODS.filesystem.sync.pauseSync]: {
|
|
1433
|
+
command: TAURI_COMMANDS.filesync.pauseSync,
|
|
1434
|
+
args: () => ({})
|
|
1435
|
+
},
|
|
1436
|
+
[HAEXTENSION_METHODS.filesystem.sync.resumeSync]: {
|
|
1437
|
+
command: TAURI_COMMANDS.filesync.resumeSync,
|
|
1438
|
+
args: () => ({})
|
|
1439
|
+
},
|
|
1440
|
+
// ==========================================================================
|
|
1441
|
+
// Conflict Resolution
|
|
1442
|
+
// ==========================================================================
|
|
1443
|
+
[HAEXTENSION_METHODS.filesystem.sync.resolveConflict]: {
|
|
1444
|
+
command: TAURI_COMMANDS.filesync.resolveConflict,
|
|
1445
|
+
args: (p) => ({ request: p })
|
|
1446
|
+
},
|
|
1447
|
+
// ==========================================================================
|
|
1448
|
+
// UI Helpers
|
|
1449
|
+
// ==========================================================================
|
|
1450
|
+
[HAEXTENSION_METHODS.filesystem.sync.selectFolder]: {
|
|
1451
|
+
command: TAURI_COMMANDS.filesync.selectFolder,
|
|
1452
|
+
args: () => ({})
|
|
1421
1453
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
if (event.payload) {
|
|
1464
|
-
this.handleEvent({
|
|
1465
|
-
type: HAEXTENSION_EVENTS.EXTERNAL_REQUEST,
|
|
1466
|
-
data: event.payload,
|
|
1467
|
-
timestamp: Date.now()
|
|
1468
|
-
});
|
|
1469
|
-
}
|
|
1470
|
-
});
|
|
1471
|
-
console.log("[HaexSpace SDK] External request listener registered successfully");
|
|
1472
|
-
} catch (error) {
|
|
1473
|
-
console.error("[HaexSpace SDK] Failed to setup external request listener:", error);
|
|
1474
|
-
this.log("Failed to setup external request listener:", error);
|
|
1475
|
-
}
|
|
1476
|
-
this.resolveReady();
|
|
1477
|
-
return;
|
|
1478
|
-
}
|
|
1479
|
-
} catch (error) {
|
|
1480
|
-
this.log("Tauri commands failed, falling back to iframe mode", error);
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
if (window.self === window.top) {
|
|
1484
|
-
throw new HaexHubError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1485
|
-
}
|
|
1486
|
-
this.messageHandler = this.handleMessage.bind(this);
|
|
1487
|
-
window.addEventListener("message", this.messageHandler);
|
|
1488
|
-
this.isNativeWindow = false;
|
|
1489
|
-
this.initialized = true;
|
|
1490
|
-
this.log("HaexSpace SDK initialized in iframe mode");
|
|
1491
|
-
try {
|
|
1492
|
-
if (this.config.manifest) {
|
|
1493
|
-
this._extensionInfo = {
|
|
1494
|
-
publicKey: this.config.manifest.publicKey,
|
|
1495
|
-
name: this.config.manifest.name,
|
|
1496
|
-
version: this.config.manifest.version,
|
|
1497
|
-
displayName: this.config.manifest.name
|
|
1498
|
-
};
|
|
1499
|
-
this.log("Extension info loaded from manifest:", this._extensionInfo);
|
|
1500
|
-
this.notifySubscribers();
|
|
1501
|
-
}
|
|
1502
|
-
if (typeof window !== "undefined" && window.parent) {
|
|
1503
|
-
const debugInfo = `SDK Debug:
|
|
1504
|
-
window.parent exists: ${!!window.parent}
|
|
1505
|
-
window.parent === window: ${window.parent === window}
|
|
1506
|
-
window.self === window.top: ${window.self === window.top}`;
|
|
1507
|
-
try {
|
|
1508
|
-
window.parent.postMessage({
|
|
1509
|
-
type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
|
|
1510
|
-
data: debugInfo
|
|
1511
|
-
}, "*");
|
|
1512
|
-
} catch (e) {
|
|
1513
|
-
alert(debugInfo + `
|
|
1514
|
-
postMessage error: ${e}`);
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
this._context = await this.request(HAEXTENSION_METHODS.context.get);
|
|
1518
|
-
this.log("Application context received:", this._context);
|
|
1519
|
-
this.notifySubscribers();
|
|
1520
|
-
this.resolveReady();
|
|
1521
|
-
} catch (error) {
|
|
1522
|
-
this.log("Failed to load extension info or context:", error);
|
|
1523
|
-
throw error;
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
// src/transport/handlers/index.ts
|
|
1457
|
+
var allHandlers = {
|
|
1458
|
+
...databaseHandlers,
|
|
1459
|
+
...permissionsHandlers,
|
|
1460
|
+
...webHandlers,
|
|
1461
|
+
...filesystemHandlers,
|
|
1462
|
+
...externalHandlers,
|
|
1463
|
+
...filesyncHandlers
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
// src/client/transport.ts
|
|
1467
|
+
function generateRequestId(counter) {
|
|
1468
|
+
return `req_${counter}`;
|
|
1469
|
+
}
|
|
1470
|
+
function sendPostMessage(method, params, requestId, config, extensionInfo2, pendingRequests) {
|
|
1471
|
+
const request = {
|
|
1472
|
+
method,
|
|
1473
|
+
params,
|
|
1474
|
+
timestamp: Date.now()
|
|
1475
|
+
};
|
|
1476
|
+
return new Promise((resolve, reject) => {
|
|
1477
|
+
const timeout = setTimeout(() => {
|
|
1478
|
+
pendingRequests.delete(requestId);
|
|
1479
|
+
reject(
|
|
1480
|
+
new HaexVaultSdkError("TIMEOUT" /* TIMEOUT */, "errors.timeout", {
|
|
1481
|
+
timeout: config.timeout
|
|
1482
|
+
})
|
|
1483
|
+
);
|
|
1484
|
+
}, config.timeout);
|
|
1485
|
+
pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1486
|
+
const targetOrigin = "*";
|
|
1487
|
+
if (config.debug) {
|
|
1488
|
+
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1489
|
+
console.log("[SDK Debug] Request ID:", requestId);
|
|
1490
|
+
console.log("[SDK Debug] Method:", request.method);
|
|
1491
|
+
console.log("[SDK Debug] Params:", request.params);
|
|
1492
|
+
console.log("[SDK Debug] Target origin:", targetOrigin);
|
|
1493
|
+
console.log("[SDK Debug] Extension info:", extensionInfo2);
|
|
1494
|
+
console.log("[SDK Debug] ========================================");
|
|
1524
1495
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1496
|
+
window.parent.postMessage({ id: requestId, ...request }, targetOrigin);
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
async function sendInvoke(method, params, config, log) {
|
|
1500
|
+
const { invoke } = window.__TAURI__.core;
|
|
1501
|
+
if (config.debug) {
|
|
1502
|
+
console.log("[SDK Debug] ========== Invoke Request ==========");
|
|
1503
|
+
console.log("[SDK Debug] Method:", method);
|
|
1504
|
+
console.log("[SDK Debug] Params:", params);
|
|
1505
|
+
console.log("[SDK Debug] =======================================");
|
|
1506
|
+
}
|
|
1507
|
+
const handler = allHandlers[method];
|
|
1508
|
+
if (handler) {
|
|
1509
|
+
const args = handler.args(params);
|
|
1510
|
+
return invoke(handler.command, args);
|
|
1511
|
+
}
|
|
1512
|
+
throw new HaexVaultSdkError(
|
|
1513
|
+
"METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */,
|
|
1514
|
+
"errors.method_not_found",
|
|
1515
|
+
{ method }
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
// src/client/events.ts
|
|
1520
|
+
function createMessageHandler(config, pendingRequests, extensionInfo2, onEvent) {
|
|
1521
|
+
return (event) => {
|
|
1522
|
+
if (config.debug) {
|
|
1528
1523
|
console.log("[SDK Debug] ========== Message Received ==========");
|
|
1529
1524
|
console.log("[SDK Debug] Event origin:", event.origin);
|
|
1530
1525
|
console.log(
|
|
@@ -1532,160 +1527,534 @@ postMessage error: ${e}`);
|
|
|
1532
1527
|
event.source === window.parent ? "parent window" : "unknown"
|
|
1533
1528
|
);
|
|
1534
1529
|
console.log("[SDK Debug] Event data:", event.data);
|
|
1535
|
-
console.log("[SDK Debug] Extension info loaded:", !!
|
|
1530
|
+
console.log("[SDK Debug] Extension info loaded:", !!extensionInfo2());
|
|
1536
1531
|
console.log(
|
|
1537
1532
|
"[SDK Debug] Pending requests count:",
|
|
1538
|
-
|
|
1533
|
+
pendingRequests.size
|
|
1539
1534
|
);
|
|
1540
1535
|
}
|
|
1541
1536
|
if (event.source !== window.parent) {
|
|
1542
|
-
if (
|
|
1537
|
+
if (config.debug) {
|
|
1543
1538
|
console.error("[SDK Debug] \u274C REJECTED: Message not from parent window!");
|
|
1544
1539
|
}
|
|
1545
1540
|
return;
|
|
1546
1541
|
}
|
|
1547
1542
|
const data = event.data;
|
|
1548
|
-
if ("id" in data &&
|
|
1549
|
-
if (
|
|
1543
|
+
if ("id" in data && pendingRequests.has(data.id)) {
|
|
1544
|
+
if (config.debug) {
|
|
1550
1545
|
console.log("[SDK Debug] \u2705 Found pending request for ID:", data.id);
|
|
1551
1546
|
}
|
|
1552
|
-
const pending =
|
|
1547
|
+
const pending = pendingRequests.get(data.id);
|
|
1553
1548
|
clearTimeout(pending.timeout);
|
|
1554
|
-
|
|
1549
|
+
pendingRequests.delete(data.id);
|
|
1555
1550
|
if (data.error) {
|
|
1556
|
-
if (
|
|
1551
|
+
if (config.debug) {
|
|
1557
1552
|
console.error("[SDK Debug] \u274C Request failed:", data.error);
|
|
1558
1553
|
}
|
|
1559
1554
|
pending.reject(data.error);
|
|
1560
1555
|
} else {
|
|
1561
|
-
if (
|
|
1556
|
+
if (config.debug) {
|
|
1562
1557
|
console.log("[SDK Debug] \u2705 Request succeeded:", data.result);
|
|
1563
1558
|
}
|
|
1564
1559
|
pending.resolve(data.result);
|
|
1565
1560
|
}
|
|
1566
1561
|
return;
|
|
1567
1562
|
}
|
|
1568
|
-
if ("id" in data && !
|
|
1569
|
-
if (
|
|
1563
|
+
if ("id" in data && !pendingRequests.has(data.id)) {
|
|
1564
|
+
if (config.debug) {
|
|
1570
1565
|
console.warn(
|
|
1571
1566
|
"[SDK Debug] \u26A0\uFE0F Received response for unknown request ID:",
|
|
1572
1567
|
data.id
|
|
1573
1568
|
);
|
|
1574
1569
|
console.warn(
|
|
1575
1570
|
"[SDK Debug] Known IDs:",
|
|
1576
|
-
Array.from(
|
|
1571
|
+
Array.from(pendingRequests.keys())
|
|
1577
1572
|
);
|
|
1578
1573
|
}
|
|
1579
1574
|
}
|
|
1580
1575
|
if ("type" in data && data.type) {
|
|
1581
|
-
if (
|
|
1576
|
+
if (config.debug) {
|
|
1582
1577
|
console.log("[SDK Debug] Event received:", data.type);
|
|
1583
1578
|
}
|
|
1584
|
-
|
|
1579
|
+
onEvent(data);
|
|
1585
1580
|
}
|
|
1586
|
-
if (
|
|
1581
|
+
if (config.debug) {
|
|
1587
1582
|
console.log("[SDK Debug] ========== End Message ==========");
|
|
1588
1583
|
}
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest) {
|
|
1587
|
+
if (event.type === HAEXTENSION_EVENTS.CONTEXT_CHANGED) {
|
|
1588
|
+
const contextEvent = event;
|
|
1589
|
+
onContextChanged(contextEvent.data.context);
|
|
1590
|
+
log("Context updated:", contextEvent.data.context);
|
|
1591
|
+
}
|
|
1592
|
+
if (event.type === HAEXTENSION_EVENTS.EXTERNAL_REQUEST) {
|
|
1593
|
+
const externalEvent = event;
|
|
1594
|
+
onExternalRequest(externalEvent);
|
|
1595
|
+
return;
|
|
1589
1596
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1597
|
+
emitEvent(event, log, eventListeners);
|
|
1598
|
+
}
|
|
1599
|
+
function emitEvent(event, log, eventListeners) {
|
|
1600
|
+
log("Event received:", event);
|
|
1601
|
+
const listeners = eventListeners.get(event.type);
|
|
1602
|
+
if (listeners) {
|
|
1603
|
+
listeners.forEach((callback) => callback(event));
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
function addEventListener(eventType, callback, eventListeners) {
|
|
1607
|
+
if (!eventListeners.has(eventType)) {
|
|
1608
|
+
eventListeners.set(eventType, /* @__PURE__ */ new Set());
|
|
1609
|
+
}
|
|
1610
|
+
eventListeners.get(eventType).add(callback);
|
|
1611
|
+
}
|
|
1612
|
+
function removeEventListener(eventType, callback, eventListeners) {
|
|
1613
|
+
const listeners = eventListeners.get(eventType);
|
|
1614
|
+
if (listeners) {
|
|
1615
|
+
listeners.delete(callback);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function notifySubscribers(subscribers) {
|
|
1619
|
+
subscribers.forEach((callback) => callback());
|
|
1620
|
+
}
|
|
1621
|
+
function createDrizzleInstance(schema, extensionInfo2, request, log) {
|
|
1622
|
+
if (!extensionInfo2) {
|
|
1623
|
+
throw new HaexVaultSdkError(
|
|
1624
|
+
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1625
|
+
"errors.client_not_ready"
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
return drizzle(
|
|
1629
|
+
async (sql, params, method) => {
|
|
1630
|
+
try {
|
|
1631
|
+
if (method === "run" || method === "all") {
|
|
1632
|
+
const result2 = await request(
|
|
1633
|
+
HAEXTENSION_METHODS.database.execute,
|
|
1634
|
+
{
|
|
1635
|
+
query: sql,
|
|
1636
|
+
params
|
|
1637
|
+
}
|
|
1638
|
+
);
|
|
1639
|
+
if (method === "all") {
|
|
1640
|
+
return { rows: result2.rows || [] };
|
|
1641
|
+
}
|
|
1642
|
+
if (result2.rows && Array.isArray(result2.rows) && result2.rows.length > 0) {
|
|
1643
|
+
return { rows: result2.rows };
|
|
1644
|
+
}
|
|
1645
|
+
return result2;
|
|
1646
|
+
}
|
|
1647
|
+
const result = await request(HAEXTENSION_METHODS.database.query, {
|
|
1648
|
+
query: sql,
|
|
1649
|
+
params
|
|
1650
|
+
});
|
|
1651
|
+
const rows = result.rows;
|
|
1652
|
+
if (method === "get") {
|
|
1653
|
+
return { rows: rows.length > 0 ? rows.at(0) : void 0 };
|
|
1654
|
+
}
|
|
1655
|
+
return { rows };
|
|
1656
|
+
} catch (error) {
|
|
1657
|
+
log("Database operation failed:", error);
|
|
1658
|
+
throw error;
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
{
|
|
1662
|
+
schema,
|
|
1663
|
+
logger: false
|
|
1596
1664
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
async function queryRaw(sql, params, request, debug) {
|
|
1668
|
+
const result = await request(
|
|
1669
|
+
HAEXTENSION_METHODS.database.query,
|
|
1670
|
+
{ query: sql, params }
|
|
1671
|
+
);
|
|
1672
|
+
if (debug) {
|
|
1673
|
+
console.log("[SDK query()] Raw result:", JSON.stringify(result, null, 2));
|
|
1674
|
+
}
|
|
1675
|
+
return result.rows;
|
|
1676
|
+
}
|
|
1677
|
+
async function executeRaw(sql, params, request) {
|
|
1678
|
+
const result = await request(
|
|
1679
|
+
HAEXTENSION_METHODS.database.execute,
|
|
1680
|
+
{ query: sql, params }
|
|
1681
|
+
);
|
|
1682
|
+
return {
|
|
1683
|
+
rowsAffected: result.rowsAffected,
|
|
1684
|
+
lastInsertId: result.lastInsertId
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
// src/client/external.ts
|
|
1689
|
+
function registerExternalHandler(action, handler, handlers, log) {
|
|
1690
|
+
handlers.set(action, handler);
|
|
1691
|
+
log(`[ExternalRequest] Registered handler for action: ${action}`);
|
|
1692
|
+
return () => {
|
|
1693
|
+
handlers.delete(action);
|
|
1694
|
+
log(`[ExternalRequest] Unregistered handler for action: ${action}`);
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
async function handleExternalRequest(request, handlers, respond, log) {
|
|
1698
|
+
log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
|
|
1699
|
+
const handler = handlers.get(request.action);
|
|
1700
|
+
if (!handler) {
|
|
1701
|
+
log(`[ExternalRequest] No handler for action: ${request.action}`);
|
|
1702
|
+
await respond({
|
|
1703
|
+
requestId: request.requestId,
|
|
1704
|
+
success: false,
|
|
1705
|
+
error: `No handler registered for action: ${request.action}`
|
|
1706
|
+
});
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
try {
|
|
1710
|
+
const response = await handler(request);
|
|
1711
|
+
await respond(response);
|
|
1712
|
+
log(`[ExternalRequest] Response sent for: ${request.action}`);
|
|
1713
|
+
} catch (error) {
|
|
1714
|
+
log(`[ExternalRequest] Handler error:`, error);
|
|
1715
|
+
await respond({
|
|
1716
|
+
requestId: request.requestId,
|
|
1717
|
+
success: false,
|
|
1718
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
async function respondToExternalRequest(response, request) {
|
|
1723
|
+
await request("external.respond", response);
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
// src/client.ts
|
|
1727
|
+
var HaexVaultClient = class {
|
|
1728
|
+
constructor(config = {}) {
|
|
1729
|
+
// State
|
|
1730
|
+
this.initialized = false;
|
|
1731
|
+
this.isNativeWindow = false;
|
|
1732
|
+
this.requestCounter = 0;
|
|
1733
|
+
this._extensionInfo = null;
|
|
1734
|
+
this._context = null;
|
|
1735
|
+
this._setupCompleted = false;
|
|
1736
|
+
// Collections
|
|
1737
|
+
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
1738
|
+
this.eventListeners = /* @__PURE__ */ new Map();
|
|
1739
|
+
this.externalRequestHandlers = /* @__PURE__ */ new Map();
|
|
1740
|
+
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
1741
|
+
// Handlers
|
|
1742
|
+
this.messageHandler = null;
|
|
1743
|
+
this.setupPromise = null;
|
|
1744
|
+
this.setupHook = null;
|
|
1745
|
+
// Public APIs
|
|
1746
|
+
this.orm = null;
|
|
1747
|
+
this.config = {
|
|
1748
|
+
debug: config.debug ?? false,
|
|
1749
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
1750
|
+
manifest: config.manifest
|
|
1751
|
+
};
|
|
1752
|
+
this.storage = new StorageAPI(this);
|
|
1753
|
+
this.database = new DatabaseAPI(this);
|
|
1754
|
+
this.filesystem = new FilesystemAPI(this);
|
|
1755
|
+
this.web = new WebAPI(this);
|
|
1756
|
+
this.permissions = new PermissionsAPI(this);
|
|
1757
|
+
installConsoleForwarding(this.config.debug);
|
|
1758
|
+
this.readyPromise = new Promise((resolve) => {
|
|
1759
|
+
this.resolveReady = resolve;
|
|
1760
|
+
});
|
|
1761
|
+
this.init();
|
|
1762
|
+
}
|
|
1763
|
+
// ==========================================================================
|
|
1764
|
+
// Lifecycle
|
|
1765
|
+
// ==========================================================================
|
|
1766
|
+
async ready() {
|
|
1767
|
+
return this.readyPromise;
|
|
1768
|
+
}
|
|
1769
|
+
get setupCompleted() {
|
|
1770
|
+
return this._setupCompleted;
|
|
1771
|
+
}
|
|
1772
|
+
onSetup(setupFn) {
|
|
1773
|
+
if (this.setupHook) {
|
|
1774
|
+
throw new Error("Setup hook already registered");
|
|
1601
1775
|
}
|
|
1602
|
-
this.
|
|
1603
|
-
}
|
|
1604
|
-
async
|
|
1605
|
-
this.
|
|
1606
|
-
|
|
1607
|
-
if (!handler) {
|
|
1608
|
-
this.log(`[ExternalRequest] No handler for action: ${request.action}`);
|
|
1609
|
-
await this.respondToExternalRequest({
|
|
1610
|
-
requestId: request.requestId,
|
|
1611
|
-
success: false,
|
|
1612
|
-
error: `No handler registered for action: ${request.action}`
|
|
1613
|
-
});
|
|
1776
|
+
this.setupHook = setupFn;
|
|
1777
|
+
}
|
|
1778
|
+
async setupComplete() {
|
|
1779
|
+
await this.readyPromise;
|
|
1780
|
+
if (!this.setupHook || this.setupCompleted) {
|
|
1614
1781
|
return;
|
|
1615
1782
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
await this.respondToExternalRequest(response);
|
|
1619
|
-
this.log(`[ExternalRequest] Response sent for: ${request.action}`);
|
|
1620
|
-
} catch (error) {
|
|
1621
|
-
this.log(`[ExternalRequest] Handler error:`, error);
|
|
1622
|
-
await this.respondToExternalRequest({
|
|
1623
|
-
requestId: request.requestId,
|
|
1624
|
-
success: false,
|
|
1625
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1626
|
-
});
|
|
1783
|
+
if (!this.setupPromise) {
|
|
1784
|
+
this.setupPromise = this.runSetupAsync();
|
|
1627
1785
|
}
|
|
1786
|
+
return this.setupPromise;
|
|
1628
1787
|
}
|
|
1629
|
-
|
|
1630
|
-
this.
|
|
1631
|
-
|
|
1632
|
-
if (listeners) {
|
|
1633
|
-
listeners.forEach((callback) => callback(event));
|
|
1788
|
+
destroy() {
|
|
1789
|
+
if (this.messageHandler) {
|
|
1790
|
+
window.removeEventListener("message", this.messageHandler);
|
|
1634
1791
|
}
|
|
1792
|
+
this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
|
|
1793
|
+
this.pendingRequests.clear();
|
|
1794
|
+
this.eventListeners.clear();
|
|
1795
|
+
this.initialized = false;
|
|
1796
|
+
this.log("HaexVault SDK destroyed");
|
|
1635
1797
|
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1798
|
+
// ==========================================================================
|
|
1799
|
+
// Properties
|
|
1800
|
+
// ==========================================================================
|
|
1801
|
+
get extensionInfo() {
|
|
1802
|
+
return this._extensionInfo;
|
|
1638
1803
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
throw new HaexHubError(
|
|
1642
|
-
"INVALID_PUBLIC_KEY" /* INVALID_PUBLIC_KEY */,
|
|
1643
|
-
"errors.invalid_public_key",
|
|
1644
|
-
{ publicKey }
|
|
1645
|
-
);
|
|
1646
|
-
}
|
|
1804
|
+
get context() {
|
|
1805
|
+
return this._context;
|
|
1647
1806
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
);
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1807
|
+
// ==========================================================================
|
|
1808
|
+
// Subscriptions
|
|
1809
|
+
// ==========================================================================
|
|
1810
|
+
subscribe(callback) {
|
|
1811
|
+
this.reactiveSubscribers.add(callback);
|
|
1812
|
+
return () => {
|
|
1813
|
+
this.reactiveSubscribers.delete(callback);
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
// ==========================================================================
|
|
1817
|
+
// Table Name Utilities
|
|
1818
|
+
// ==========================================================================
|
|
1819
|
+
getTableName(tableName) {
|
|
1820
|
+
return getExtensionTableName(this._extensionInfo, tableName);
|
|
1821
|
+
}
|
|
1822
|
+
getDependencyTableName(publicKey, extensionName, tableName) {
|
|
1823
|
+
return getDependencyTableName(publicKey, extensionName, tableName);
|
|
1824
|
+
}
|
|
1825
|
+
parseTableName(fullTableName) {
|
|
1826
|
+
return parseTableName(fullTableName);
|
|
1827
|
+
}
|
|
1828
|
+
// ==========================================================================
|
|
1829
|
+
// Database
|
|
1830
|
+
// ==========================================================================
|
|
1831
|
+
initializeDatabase(schema) {
|
|
1832
|
+
const db = createDrizzleInstance(schema, this._extensionInfo, this.request.bind(this), this.log.bind(this));
|
|
1833
|
+
this.orm = db;
|
|
1834
|
+
return db;
|
|
1835
|
+
}
|
|
1836
|
+
async query(sql, params = []) {
|
|
1837
|
+
return queryRaw(sql, params, this.request.bind(this), this.config.debug);
|
|
1838
|
+
}
|
|
1839
|
+
async select(sql, params = []) {
|
|
1840
|
+
return this.query(sql, params);
|
|
1841
|
+
}
|
|
1842
|
+
async execute(sql, params = []) {
|
|
1843
|
+
return executeRaw(sql, params, this.request.bind(this));
|
|
1844
|
+
}
|
|
1845
|
+
async registerMigrationsAsync(extensionVersion, migrations) {
|
|
1846
|
+
return this.database.registerMigrationsAsync(extensionVersion, migrations);
|
|
1847
|
+
}
|
|
1848
|
+
// ==========================================================================
|
|
1849
|
+
// Dependencies
|
|
1850
|
+
// ==========================================================================
|
|
1851
|
+
async getDependencies() {
|
|
1852
|
+
return this.request("extensions.getDependencies");
|
|
1853
|
+
}
|
|
1854
|
+
// ==========================================================================
|
|
1855
|
+
// Permissions
|
|
1856
|
+
// ==========================================================================
|
|
1857
|
+
async requestDatabasePermission(request) {
|
|
1858
|
+
return this.request("permissions.database.request", {
|
|
1859
|
+
resource: request.resource,
|
|
1860
|
+
operation: request.operation,
|
|
1861
|
+
reason: request.reason
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
async checkDatabasePermission(resource, operation) {
|
|
1865
|
+
const response = await this.request("permissions.database.check", { resource, operation });
|
|
1866
|
+
return response.status === "granted";
|
|
1867
|
+
}
|
|
1868
|
+
// ==========================================================================
|
|
1869
|
+
// Search
|
|
1870
|
+
// ==========================================================================
|
|
1871
|
+
async respondToSearch(requestId, results) {
|
|
1872
|
+
await this.request("search.respond", { requestId, results });
|
|
1873
|
+
}
|
|
1874
|
+
// ==========================================================================
|
|
1875
|
+
// External Requests
|
|
1876
|
+
// ==========================================================================
|
|
1877
|
+
onExternalRequest(action, handler) {
|
|
1878
|
+
return registerExternalHandler(action, handler, this.externalRequestHandlers, this.log.bind(this));
|
|
1879
|
+
}
|
|
1880
|
+
async respondToExternalRequest(response) {
|
|
1881
|
+
await respondToExternalRequest(response, this.request.bind(this));
|
|
1882
|
+
}
|
|
1883
|
+
// ==========================================================================
|
|
1884
|
+
// Events
|
|
1885
|
+
// ==========================================================================
|
|
1886
|
+
on(eventType, callback) {
|
|
1887
|
+
addEventListener(eventType, callback, this.eventListeners);
|
|
1888
|
+
}
|
|
1889
|
+
off(eventType, callback) {
|
|
1890
|
+
removeEventListener(eventType, callback, this.eventListeners);
|
|
1891
|
+
}
|
|
1892
|
+
// ==========================================================================
|
|
1893
|
+
// Communication
|
|
1894
|
+
// ==========================================================================
|
|
1895
|
+
async request(method, params) {
|
|
1896
|
+
const resolvedParams = params ?? {};
|
|
1897
|
+
if (this.isNativeWindow && hasTauri()) {
|
|
1898
|
+
return sendInvoke(method, resolvedParams, this.config, this.log.bind(this));
|
|
1662
1899
|
}
|
|
1900
|
+
const requestId = generateRequestId(++this.requestCounter);
|
|
1901
|
+
return sendPostMessage(method, resolvedParams, requestId, this.config, this._extensionInfo, this.pendingRequests);
|
|
1663
1902
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1903
|
+
// ==========================================================================
|
|
1904
|
+
// Private: Initialization
|
|
1905
|
+
// ==========================================================================
|
|
1906
|
+
async init() {
|
|
1907
|
+
if (this.initialized) return;
|
|
1908
|
+
if (!isInIframe() && hasTauri()) {
|
|
1909
|
+
try {
|
|
1910
|
+
await this.initNative();
|
|
1911
|
+
return;
|
|
1912
|
+
} catch (error) {
|
|
1913
|
+
this.log("Tauri commands failed, falling back to iframe mode", error);
|
|
1914
|
+
}
|
|
1670
1915
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1916
|
+
await this.initIframe();
|
|
1917
|
+
}
|
|
1918
|
+
async initNative() {
|
|
1919
|
+
const { extensionInfo: extensionInfo2, context: context2 } = await initNativeMode(
|
|
1920
|
+
{
|
|
1921
|
+
config: this.config,
|
|
1922
|
+
state: {
|
|
1923
|
+
initialized: this.initialized,
|
|
1924
|
+
isNativeWindow: this.isNativeWindow,
|
|
1925
|
+
requestCounter: this.requestCounter,
|
|
1926
|
+
setupCompleted: this._setupCompleted,
|
|
1927
|
+
extensionInfo: this._extensionInfo,
|
|
1928
|
+
context: this._context,
|
|
1929
|
+
orm: this.orm
|
|
1930
|
+
},
|
|
1931
|
+
collections: {
|
|
1932
|
+
pendingRequests: this.pendingRequests,
|
|
1933
|
+
eventListeners: this.eventListeners,
|
|
1934
|
+
externalRequestHandlers: this.externalRequestHandlers,
|
|
1935
|
+
reactiveSubscribers: this.reactiveSubscribers
|
|
1936
|
+
},
|
|
1937
|
+
promises: {
|
|
1938
|
+
readyPromise: this.readyPromise,
|
|
1939
|
+
resolveReady: this.resolveReady,
|
|
1940
|
+
setupPromise: this.setupPromise,
|
|
1941
|
+
setupHook: this.setupHook
|
|
1942
|
+
},
|
|
1943
|
+
handlers: {
|
|
1944
|
+
messageHandler: this.messageHandler
|
|
1945
|
+
}
|
|
1946
|
+
},
|
|
1947
|
+
this.log.bind(this),
|
|
1948
|
+
this.handleEvent.bind(this),
|
|
1949
|
+
(ctx) => {
|
|
1950
|
+
this._context = ctx;
|
|
1951
|
+
this.notifySubscribersInternal();
|
|
1952
|
+
}
|
|
1953
|
+
);
|
|
1954
|
+
this._extensionInfo = extensionInfo2;
|
|
1955
|
+
this._context = context2;
|
|
1956
|
+
this.isNativeWindow = true;
|
|
1957
|
+
this.initialized = true;
|
|
1958
|
+
this.notifySubscribersInternal();
|
|
1959
|
+
this.resolveReady();
|
|
1960
|
+
}
|
|
1961
|
+
async initIframe() {
|
|
1962
|
+
this.messageHandler = createMessageHandler(
|
|
1963
|
+
this.config,
|
|
1964
|
+
this.pendingRequests,
|
|
1965
|
+
() => this._extensionInfo,
|
|
1966
|
+
this.handleEvent.bind(this)
|
|
1967
|
+
);
|
|
1968
|
+
const { context: context2 } = await initIframeMode(
|
|
1969
|
+
{
|
|
1970
|
+
config: this.config,
|
|
1971
|
+
state: {
|
|
1972
|
+
initialized: this.initialized,
|
|
1973
|
+
isNativeWindow: this.isNativeWindow,
|
|
1974
|
+
requestCounter: this.requestCounter,
|
|
1975
|
+
setupCompleted: this._setupCompleted,
|
|
1976
|
+
extensionInfo: this._extensionInfo,
|
|
1977
|
+
context: this._context,
|
|
1978
|
+
orm: this.orm
|
|
1979
|
+
},
|
|
1980
|
+
collections: {
|
|
1981
|
+
pendingRequests: this.pendingRequests,
|
|
1982
|
+
eventListeners: this.eventListeners,
|
|
1983
|
+
externalRequestHandlers: this.externalRequestHandlers,
|
|
1984
|
+
reactiveSubscribers: this.reactiveSubscribers
|
|
1985
|
+
},
|
|
1986
|
+
promises: {
|
|
1987
|
+
readyPromise: this.readyPromise,
|
|
1988
|
+
resolveReady: this.resolveReady,
|
|
1989
|
+
setupPromise: this.setupPromise,
|
|
1990
|
+
setupHook: this.setupHook
|
|
1991
|
+
},
|
|
1992
|
+
handlers: {
|
|
1993
|
+
messageHandler: this.messageHandler
|
|
1994
|
+
}
|
|
1995
|
+
},
|
|
1996
|
+
this.log.bind(this),
|
|
1997
|
+
this.messageHandler,
|
|
1998
|
+
this.request.bind(this)
|
|
1999
|
+
);
|
|
2000
|
+
if (this.config.manifest) {
|
|
2001
|
+
this._extensionInfo = {
|
|
2002
|
+
publicKey: this.config.manifest.publicKey,
|
|
2003
|
+
name: this.config.manifest.name,
|
|
2004
|
+
version: this.config.manifest.version,
|
|
2005
|
+
displayName: this.config.manifest.name
|
|
2006
|
+
};
|
|
2007
|
+
this.notifySubscribersInternal();
|
|
1677
2008
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
2009
|
+
this._context = context2;
|
|
2010
|
+
this.isNativeWindow = false;
|
|
2011
|
+
this.initialized = true;
|
|
2012
|
+
this.notifySubscribersInternal();
|
|
2013
|
+
this.resolveReady();
|
|
2014
|
+
}
|
|
2015
|
+
// ==========================================================================
|
|
2016
|
+
// Private: Event Handling
|
|
2017
|
+
// ==========================================================================
|
|
2018
|
+
handleEvent(event) {
|
|
2019
|
+
processEvent(
|
|
2020
|
+
event,
|
|
2021
|
+
this.log.bind(this),
|
|
2022
|
+
this.eventListeners,
|
|
2023
|
+
(ctx) => {
|
|
2024
|
+
this._context = ctx;
|
|
2025
|
+
this.notifySubscribersInternal();
|
|
2026
|
+
},
|
|
2027
|
+
(extEvent) => this.handleExternalRequestInternal(extEvent.data)
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
async handleExternalRequestInternal(request) {
|
|
2031
|
+
await handleExternalRequest(request, this.externalRequestHandlers, this.respondToExternalRequest.bind(this), this.log.bind(this));
|
|
2032
|
+
}
|
|
2033
|
+
// ==========================================================================
|
|
2034
|
+
// Private: Setup
|
|
2035
|
+
// ==========================================================================
|
|
2036
|
+
async runSetupAsync() {
|
|
2037
|
+
if (!this.setupHook) return;
|
|
2038
|
+
try {
|
|
2039
|
+
this.log("[HaexVault] Running setup hook...");
|
|
2040
|
+
await this.setupHook();
|
|
2041
|
+
this._setupCompleted = true;
|
|
2042
|
+
this.log("[HaexVault] Setup completed successfully");
|
|
2043
|
+
this.notifySubscribersInternal();
|
|
2044
|
+
} catch (error) {
|
|
2045
|
+
this.log("[HaexVault] Setup failed:", error);
|
|
2046
|
+
throw error;
|
|
1684
2047
|
}
|
|
1685
2048
|
}
|
|
2049
|
+
// ==========================================================================
|
|
2050
|
+
// Private: Utilities
|
|
2051
|
+
// ==========================================================================
|
|
2052
|
+
notifySubscribersInternal() {
|
|
2053
|
+
notifySubscribers(this.reactiveSubscribers);
|
|
2054
|
+
}
|
|
1686
2055
|
log(...args) {
|
|
1687
2056
|
if (this.config.debug) {
|
|
1688
|
-
console.log("[
|
|
2057
|
+
console.log("[HaexVault SDK]", ...args);
|
|
1689
2058
|
}
|
|
1690
2059
|
}
|
|
1691
2060
|
};
|