@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/index.js
CHANGED
|
@@ -380,67 +380,6 @@ var HAEXTENSION_EVENTS = {
|
|
|
380
380
|
EXTERNAL_REQUEST: "haextension:external:request"
|
|
381
381
|
};
|
|
382
382
|
|
|
383
|
-
// src/methods.ts
|
|
384
|
-
var HAEXTENSION_METHODS = {
|
|
385
|
-
context: {
|
|
386
|
-
get: "haextension:context:get"
|
|
387
|
-
},
|
|
388
|
-
database: {
|
|
389
|
-
query: "haextension:database:query",
|
|
390
|
-
execute: "haextension:database:execute",
|
|
391
|
-
transaction: "haextension:database:transaction",
|
|
392
|
-
registerMigrations: "haextension:database:register-migrations"
|
|
393
|
-
},
|
|
394
|
-
filesystem: {
|
|
395
|
-
saveFile: "haextension:filesystem:save-file",
|
|
396
|
-
openFile: "haextension:filesystem:open-file",
|
|
397
|
-
showImage: "haextension:filesystem:show-image",
|
|
398
|
-
sync: {
|
|
399
|
-
// Spaces
|
|
400
|
-
listSpaces: "haextension:filesystem:sync:list-spaces",
|
|
401
|
-
createSpace: "haextension:filesystem:sync:create-space",
|
|
402
|
-
deleteSpace: "haextension:filesystem:sync:delete-space",
|
|
403
|
-
// Files
|
|
404
|
-
listFiles: "haextension:filesystem:sync:list-files",
|
|
405
|
-
getFile: "haextension:filesystem:sync:get-file",
|
|
406
|
-
uploadFile: "haextension:filesystem:sync:upload-file",
|
|
407
|
-
downloadFile: "haextension:filesystem:sync:download-file",
|
|
408
|
-
deleteFile: "haextension:filesystem:sync:delete-file",
|
|
409
|
-
// Backends
|
|
410
|
-
listBackends: "haextension:filesystem:sync:list-backends",
|
|
411
|
-
addBackend: "haextension:filesystem:sync:add-backend",
|
|
412
|
-
removeBackend: "haextension:filesystem:sync:remove-backend",
|
|
413
|
-
testBackend: "haextension:filesystem:sync:test-backend",
|
|
414
|
-
// Sync Rules
|
|
415
|
-
listSyncRules: "haextension:filesystem:sync:list-sync-rules",
|
|
416
|
-
addSyncRule: "haextension:filesystem:sync:add-sync-rule",
|
|
417
|
-
removeSyncRule: "haextension:filesystem:sync:remove-sync-rule",
|
|
418
|
-
// Sync Operations
|
|
419
|
-
getSyncStatus: "haextension:filesystem:sync:get-sync-status",
|
|
420
|
-
triggerSync: "haextension:filesystem:sync:trigger-sync",
|
|
421
|
-
pauseSync: "haextension:filesystem:sync:pause-sync",
|
|
422
|
-
resumeSync: "haextension:filesystem:sync:resume-sync",
|
|
423
|
-
// Conflict Resolution
|
|
424
|
-
resolveConflict: "haextension:filesystem:sync:resolve-conflict",
|
|
425
|
-
// UI Helpers
|
|
426
|
-
selectFolder: "haextension:filesystem:sync:select-folder"
|
|
427
|
-
}
|
|
428
|
-
},
|
|
429
|
-
storage: {
|
|
430
|
-
getItem: "haextension:storage:get-item",
|
|
431
|
-
setItem: "haextension:storage:set-item",
|
|
432
|
-
removeItem: "haextension:storage:remove-item",
|
|
433
|
-
clear: "haextension:storage:clear",
|
|
434
|
-
keys: "haextension:storage:keys"
|
|
435
|
-
},
|
|
436
|
-
web: {
|
|
437
|
-
fetch: "haextension:web:fetch"
|
|
438
|
-
},
|
|
439
|
-
application: {
|
|
440
|
-
open: "haextension:application:open"
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
383
|
// src/types.ts
|
|
445
384
|
var DEFAULT_TIMEOUT = 3e4;
|
|
446
385
|
var TABLE_SEPARATOR = "__";
|
|
@@ -470,13 +409,13 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
|
470
409
|
ErrorCode2["WEB_ERROR"] = "WEB_ERROR";
|
|
471
410
|
return ErrorCode2;
|
|
472
411
|
})(ErrorCode || {});
|
|
473
|
-
var
|
|
412
|
+
var HaexVaultSdkError = class extends Error {
|
|
474
413
|
constructor(code, messageKey, details) {
|
|
475
414
|
super(messageKey);
|
|
476
415
|
this.code = code;
|
|
477
416
|
this.messageKey = messageKey;
|
|
478
417
|
this.details = details;
|
|
479
|
-
this.name = "
|
|
418
|
+
this.name = "HaexVaultSdkError";
|
|
480
419
|
}
|
|
481
420
|
/**
|
|
482
421
|
* Get localized error message
|
|
@@ -504,6 +443,67 @@ var HaexHubError = class extends Error {
|
|
|
504
443
|
}
|
|
505
444
|
};
|
|
506
445
|
|
|
446
|
+
// src/methods.ts
|
|
447
|
+
var HAEXTENSION_METHODS = {
|
|
448
|
+
context: {
|
|
449
|
+
get: "haextension:context:get"
|
|
450
|
+
},
|
|
451
|
+
database: {
|
|
452
|
+
query: "haextension:database:query",
|
|
453
|
+
execute: "haextension:database:execute",
|
|
454
|
+
transaction: "haextension:database:transaction",
|
|
455
|
+
registerMigrations: "haextension:database:register-migrations"
|
|
456
|
+
},
|
|
457
|
+
filesystem: {
|
|
458
|
+
saveFile: "haextension:filesystem:save-file",
|
|
459
|
+
openFile: "haextension:filesystem:open-file",
|
|
460
|
+
showImage: "haextension:filesystem:show-image",
|
|
461
|
+
sync: {
|
|
462
|
+
// Spaces
|
|
463
|
+
listSpaces: "haextension:filesystem:sync:list-spaces",
|
|
464
|
+
createSpace: "haextension:filesystem:sync:create-space",
|
|
465
|
+
deleteSpace: "haextension:filesystem:sync:delete-space",
|
|
466
|
+
// Files
|
|
467
|
+
listFiles: "haextension:filesystem:sync:list-files",
|
|
468
|
+
getFile: "haextension:filesystem:sync:get-file",
|
|
469
|
+
uploadFile: "haextension:filesystem:sync:upload-file",
|
|
470
|
+
downloadFile: "haextension:filesystem:sync:download-file",
|
|
471
|
+
deleteFile: "haextension:filesystem:sync:delete-file",
|
|
472
|
+
// Backends
|
|
473
|
+
listBackends: "haextension:filesystem:sync:list-backends",
|
|
474
|
+
addBackend: "haextension:filesystem:sync:add-backend",
|
|
475
|
+
removeBackend: "haextension:filesystem:sync:remove-backend",
|
|
476
|
+
testBackend: "haextension:filesystem:sync:test-backend",
|
|
477
|
+
// Sync Rules
|
|
478
|
+
listSyncRules: "haextension:filesystem:sync:list-sync-rules",
|
|
479
|
+
addSyncRule: "haextension:filesystem:sync:add-sync-rule",
|
|
480
|
+
removeSyncRule: "haextension:filesystem:sync:remove-sync-rule",
|
|
481
|
+
// Sync Operations
|
|
482
|
+
getSyncStatus: "haextension:filesystem:sync:get-sync-status",
|
|
483
|
+
triggerSync: "haextension:filesystem:sync:trigger-sync",
|
|
484
|
+
pauseSync: "haextension:filesystem:sync:pause-sync",
|
|
485
|
+
resumeSync: "haextension:filesystem:sync:resume-sync",
|
|
486
|
+
// Conflict Resolution
|
|
487
|
+
resolveConflict: "haextension:filesystem:sync:resolve-conflict",
|
|
488
|
+
// UI Helpers
|
|
489
|
+
selectFolder: "haextension:filesystem:sync:select-folder"
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
storage: {
|
|
493
|
+
getItem: "haextension:storage:get-item",
|
|
494
|
+
setItem: "haextension:storage:set-item",
|
|
495
|
+
removeItem: "haextension:storage:remove-item",
|
|
496
|
+
clear: "haextension:storage:clear",
|
|
497
|
+
keys: "haextension:storage:keys"
|
|
498
|
+
},
|
|
499
|
+
web: {
|
|
500
|
+
fetch: "haextension:web:fetch"
|
|
501
|
+
},
|
|
502
|
+
application: {
|
|
503
|
+
open: "haextension:application:open"
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
507
|
// src/api/storage.ts
|
|
508
508
|
var StorageAPI = class {
|
|
509
509
|
constructor(client) {
|
|
@@ -1046,548 +1046,547 @@ var PermissionsAPI = class {
|
|
|
1046
1046
|
return response.status === "granted";
|
|
1047
1047
|
}
|
|
1048
1048
|
};
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
this._context = null;
|
|
1059
|
-
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
1060
|
-
this.isNativeWindow = false;
|
|
1061
|
-
// Wird im Konstruktor initialisiert
|
|
1062
|
-
this.setupPromise = null;
|
|
1063
|
-
this.setupHook = null;
|
|
1064
|
-
this._setupCompleted = false;
|
|
1065
|
-
this.orm = null;
|
|
1066
|
-
this.config = {
|
|
1067
|
-
debug: config.debug ?? false,
|
|
1068
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
1069
|
-
manifest: config.manifest
|
|
1070
|
-
};
|
|
1071
|
-
this.storage = new StorageAPI(this);
|
|
1072
|
-
this.database = new DatabaseAPI(this);
|
|
1073
|
-
this.filesystem = new FilesystemAPI(this);
|
|
1074
|
-
this.web = new WebAPI(this);
|
|
1075
|
-
this.permissions = new PermissionsAPI(this);
|
|
1076
|
-
installConsoleForwarding(this.config.debug);
|
|
1077
|
-
this.readyPromise = new Promise((resolve) => {
|
|
1078
|
-
this.resolveReady = resolve;
|
|
1079
|
-
});
|
|
1080
|
-
this.init();
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* Gibt ein Promise zurück, das aufgelöst wird, sobald der Client
|
|
1084
|
-
* initialisiert ist und Extension-Infos empfangen hat.
|
|
1085
|
-
*/
|
|
1086
|
-
async ready() {
|
|
1087
|
-
return this.readyPromise;
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Gibt zurück, ob das Setup bereits abgeschlossen wurde.
|
|
1091
|
-
*/
|
|
1092
|
-
get setupCompleted() {
|
|
1093
|
-
return this._setupCompleted;
|
|
1049
|
+
|
|
1050
|
+
// src/client/tableName.ts
|
|
1051
|
+
function validatePublicKey(publicKey) {
|
|
1052
|
+
if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
|
|
1053
|
+
throw new HaexVaultSdkError(
|
|
1054
|
+
"INVALID_PUBLIC_KEY" /* INVALID_PUBLIC_KEY */,
|
|
1055
|
+
"errors.invalid_public_key",
|
|
1056
|
+
{ publicKey }
|
|
1057
|
+
);
|
|
1094
1058
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
}
|
|
1104
|
-
this.setupHook = setupFn;
|
|
1059
|
+
}
|
|
1060
|
+
function validateExtensionName(extensionName) {
|
|
1061
|
+
if (!extensionName || !/^[a-z][a-z0-9-]*$/i.test(extensionName)) {
|
|
1062
|
+
throw new HaexVaultSdkError(
|
|
1063
|
+
"INVALID_EXTENSION_NAME" /* INVALID_EXTENSION_NAME */,
|
|
1064
|
+
"errors.invalid_extension_name",
|
|
1065
|
+
{ extensionName }
|
|
1066
|
+
);
|
|
1105
1067
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
await this.readyPromise;
|
|
1113
|
-
if (!this.setupHook || this.setupCompleted) {
|
|
1114
|
-
return;
|
|
1115
|
-
}
|
|
1116
|
-
if (!this.setupPromise) {
|
|
1117
|
-
this.setupPromise = this.runSetupAsync();
|
|
1118
|
-
}
|
|
1119
|
-
return this.setupPromise;
|
|
1068
|
+
if (extensionName.includes(TABLE_SEPARATOR)) {
|
|
1069
|
+
throw new HaexVaultSdkError(
|
|
1070
|
+
"INVALID_EXTENSION_NAME" /* INVALID_EXTENSION_NAME */,
|
|
1071
|
+
"errors.extension_name_contains_separator",
|
|
1072
|
+
{ extensionName, separator: TABLE_SEPARATOR }
|
|
1073
|
+
);
|
|
1120
1074
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
this.notifySubscribers();
|
|
1129
|
-
} catch (error) {
|
|
1130
|
-
this.log("[HaexSpace] Setup failed:", error);
|
|
1131
|
-
throw error;
|
|
1132
|
-
}
|
|
1075
|
+
}
|
|
1076
|
+
function validateTableName(tableName) {
|
|
1077
|
+
if (!tableName || typeof tableName !== "string") {
|
|
1078
|
+
throw new HaexVaultSdkError(
|
|
1079
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1080
|
+
"errors.table_name_empty"
|
|
1081
|
+
);
|
|
1133
1082
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
*/
|
|
1140
|
-
initializeDatabase(schema) {
|
|
1141
|
-
if (!this._extensionInfo) {
|
|
1142
|
-
throw new HaexHubError(
|
|
1143
|
-
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1144
|
-
"errors.client_not_ready"
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
const dbInstance = sqliteProxy.drizzle(
|
|
1148
|
-
async (sql, params, method) => {
|
|
1149
|
-
try {
|
|
1150
|
-
if (method === "run" || method === "all") {
|
|
1151
|
-
const result2 = await this.request(
|
|
1152
|
-
HAEXTENSION_METHODS.database.execute,
|
|
1153
|
-
{
|
|
1154
|
-
query: sql,
|
|
1155
|
-
params
|
|
1156
|
-
}
|
|
1157
|
-
);
|
|
1158
|
-
if (method === "all") {
|
|
1159
|
-
return { rows: result2.rows || [] };
|
|
1160
|
-
}
|
|
1161
|
-
if (result2.rows && Array.isArray(result2.rows) && result2.rows.length > 0) {
|
|
1162
|
-
return { rows: result2.rows };
|
|
1163
|
-
}
|
|
1164
|
-
return result2;
|
|
1165
|
-
}
|
|
1166
|
-
const result = await this.request(HAEXTENSION_METHODS.database.query, {
|
|
1167
|
-
query: sql,
|
|
1168
|
-
params
|
|
1169
|
-
});
|
|
1170
|
-
const rows = result.rows;
|
|
1171
|
-
if (method === "get") {
|
|
1172
|
-
return { rows: rows.length > 0 ? rows.at(0) : void 0 };
|
|
1173
|
-
}
|
|
1174
|
-
return { rows };
|
|
1175
|
-
} catch (error) {
|
|
1176
|
-
this.log("Database operation failed:", error);
|
|
1177
|
-
throw error;
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
{
|
|
1181
|
-
schema,
|
|
1182
|
-
logger: false
|
|
1183
|
-
}
|
|
1083
|
+
if (tableName.includes(TABLE_SEPARATOR)) {
|
|
1084
|
+
throw new HaexVaultSdkError(
|
|
1085
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1086
|
+
"errors.table_name_contains_separator",
|
|
1087
|
+
{ tableName, separator: TABLE_SEPARATOR }
|
|
1184
1088
|
);
|
|
1185
|
-
this.orm = dbInstance;
|
|
1186
|
-
return dbInstance;
|
|
1187
1089
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1090
|
+
if (!/^[a-z][a-z0-9-_]*$/i.test(tableName)) {
|
|
1091
|
+
throw new HaexVaultSdkError(
|
|
1092
|
+
"INVALID_TABLE_NAME" /* INVALID_TABLE_NAME */,
|
|
1093
|
+
"errors.table_name_format",
|
|
1094
|
+
{ tableName }
|
|
1095
|
+
);
|
|
1190
1096
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1097
|
+
}
|
|
1098
|
+
function getExtensionTableName(extensionInfo, tableName) {
|
|
1099
|
+
if (!extensionInfo) {
|
|
1100
|
+
throw new HaexVaultSdkError(
|
|
1101
|
+
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1102
|
+
"errors.extension_info_unavailable"
|
|
1103
|
+
);
|
|
1193
1104
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1105
|
+
validateTableName(tableName);
|
|
1106
|
+
const { publicKey, name } = extensionInfo;
|
|
1107
|
+
return `"${getTableName(publicKey, name, tableName)}"`;
|
|
1108
|
+
}
|
|
1109
|
+
function getDependencyTableName(publicKey, extensionName, tableName) {
|
|
1110
|
+
validatePublicKey(publicKey);
|
|
1111
|
+
validateExtensionName(extensionName);
|
|
1112
|
+
validateTableName(tableName);
|
|
1113
|
+
return `"${getTableName(publicKey, extensionName, tableName)}"`;
|
|
1114
|
+
}
|
|
1115
|
+
function parseTableName(fullTableName) {
|
|
1116
|
+
let cleanTableName = fullTableName;
|
|
1117
|
+
if (cleanTableName.startsWith('"') && cleanTableName.endsWith('"')) {
|
|
1118
|
+
cleanTableName = cleanTableName.slice(1, -1);
|
|
1199
1119
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1120
|
+
const parts = cleanTableName.split(TABLE_SEPARATOR);
|
|
1121
|
+
if (parts.length !== 3) {
|
|
1122
|
+
return null;
|
|
1202
1123
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1124
|
+
const [publicKey, extensionName, tableName] = parts;
|
|
1125
|
+
if (!publicKey || !extensionName || !tableName) {
|
|
1126
|
+
return null;
|
|
1205
1127
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1128
|
+
return {
|
|
1129
|
+
publicKey,
|
|
1130
|
+
extensionName,
|
|
1131
|
+
tableName
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// src/client/init.ts
|
|
1136
|
+
function isInIframe() {
|
|
1137
|
+
return window.self !== window.top;
|
|
1138
|
+
}
|
|
1139
|
+
function hasTauri() {
|
|
1140
|
+
return typeof window.__TAURI__ !== "undefined";
|
|
1141
|
+
}
|
|
1142
|
+
function getTauriCore() {
|
|
1143
|
+
return window.__TAURI__.core;
|
|
1144
|
+
}
|
|
1145
|
+
function getTauriEvent() {
|
|
1146
|
+
return window.__TAURI__.event;
|
|
1147
|
+
}
|
|
1148
|
+
async function initNativeMode(ctx, log, onEvent, onContextChange) {
|
|
1149
|
+
const { invoke } = getTauriCore();
|
|
1150
|
+
const extensionInfo = await invoke("webview_extension_get_info");
|
|
1151
|
+
const context = await invoke("webview_extension_context_get");
|
|
1152
|
+
ctx.state.isNativeWindow = true;
|
|
1153
|
+
ctx.state.initialized = true;
|
|
1154
|
+
ctx.state.extensionInfo = extensionInfo;
|
|
1155
|
+
ctx.state.context = context;
|
|
1156
|
+
log("HaexVault SDK initialized in native WebViewWindow mode");
|
|
1157
|
+
log("Extension info:", extensionInfo);
|
|
1158
|
+
log("Application context:", context);
|
|
1159
|
+
await setupTauriEventListeners(ctx, log, onEvent, onContextChange);
|
|
1160
|
+
return { extensionInfo, context };
|
|
1161
|
+
}
|
|
1162
|
+
async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
1163
|
+
const { listen } = getTauriEvent();
|
|
1164
|
+
console.log("[HaexVault SDK] Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
|
|
1165
|
+
try {
|
|
1166
|
+
await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
|
|
1167
|
+
console.log("[HaexVault SDK] Received Tauri event:", HAEXTENSION_EVENTS.CONTEXT_CHANGED, event);
|
|
1168
|
+
log("Received context change event:", event);
|
|
1169
|
+
const payload = event.payload;
|
|
1170
|
+
if (payload?.context) {
|
|
1171
|
+
ctx.state.context = payload.context;
|
|
1172
|
+
console.log("[HaexVault SDK] Updated context to:", ctx.state.context);
|
|
1173
|
+
onContextChange(payload.context);
|
|
1174
|
+
onEvent({
|
|
1175
|
+
type: HAEXTENSION_EVENTS.CONTEXT_CHANGED,
|
|
1176
|
+
data: { context: ctx.state.context },
|
|
1177
|
+
timestamp: Date.now()
|
|
1178
|
+
});
|
|
1179
|
+
} else {
|
|
1180
|
+
console.warn("[HaexVault SDK] Event received but no context in payload:", event);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
console.log("[HaexVault SDK] Context change listener registered successfully");
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
console.error("[HaexVault SDK] Failed to setup context change listener:", error);
|
|
1186
|
+
log("Failed to setup context change listener:", error);
|
|
1216
1187
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1188
|
+
try {
|
|
1189
|
+
await listen(HAEXTENSION_EVENTS.EXTERNAL_REQUEST, (event) => {
|
|
1190
|
+
log("Received external request event:", event);
|
|
1191
|
+
if (event.payload) {
|
|
1192
|
+
onEvent({
|
|
1193
|
+
type: HAEXTENSION_EVENTS.EXTERNAL_REQUEST,
|
|
1194
|
+
data: event.payload,
|
|
1195
|
+
timestamp: Date.now()
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
console.log("[HaexVault SDK] External request listener registered successfully");
|
|
1200
|
+
} catch (error) {
|
|
1201
|
+
console.error("[HaexVault SDK] Failed to setup external request listener:", error);
|
|
1202
|
+
log("Failed to setup external request listener:", error);
|
|
1222
1203
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
tableName
|
|
1204
|
+
}
|
|
1205
|
+
async function initIframeMode(ctx, log, messageHandler, request) {
|
|
1206
|
+
if (!isInIframe()) {
|
|
1207
|
+
throw new HaexVaultSdkError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1208
|
+
}
|
|
1209
|
+
ctx.handlers.messageHandler = messageHandler;
|
|
1210
|
+
window.addEventListener("message", messageHandler);
|
|
1211
|
+
ctx.state.isNativeWindow = false;
|
|
1212
|
+
ctx.state.initialized = true;
|
|
1213
|
+
log("HaexVault SDK initialized in iframe mode");
|
|
1214
|
+
if (ctx.config.manifest) {
|
|
1215
|
+
ctx.state.extensionInfo = {
|
|
1216
|
+
publicKey: ctx.config.manifest.publicKey,
|
|
1217
|
+
name: ctx.config.manifest.name,
|
|
1218
|
+
version: ctx.config.manifest.version,
|
|
1219
|
+
displayName: ctx.config.manifest.name
|
|
1240
1220
|
};
|
|
1221
|
+
log("Extension info loaded from manifest:", ctx.state.extensionInfo);
|
|
1241
1222
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
* Execute a raw SQL statement (INSERT, UPDATE, DELETE, CREATE, etc.)
|
|
1264
|
-
* Returns rowsAffected and lastInsertId
|
|
1265
|
-
*/
|
|
1266
|
-
async execute(sql, params = []) {
|
|
1267
|
-
const result = await this.request(
|
|
1268
|
-
HAEXTENSION_METHODS.database.execute,
|
|
1269
|
-
{ query: sql, params }
|
|
1270
|
-
);
|
|
1271
|
-
return {
|
|
1272
|
-
rowsAffected: result.rowsAffected,
|
|
1273
|
-
lastInsertId: result.lastInsertId
|
|
1274
|
-
};
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* Registers and applies extension migrations with HaexVault
|
|
1278
|
-
*
|
|
1279
|
-
* HaexVault will:
|
|
1280
|
-
* 1. Validate all SQL statements (ensure only extension's own tables are accessed)
|
|
1281
|
-
* 2. Store migrations with applied_at = NULL
|
|
1282
|
-
* 3. Query pending migrations sorted by name
|
|
1283
|
-
* 4. Apply pending migrations and set up CRDT triggers
|
|
1284
|
-
* 5. Mark successful migrations with applied_at timestamp
|
|
1285
|
-
*
|
|
1286
|
-
* @param extensionVersion - The version of the extension
|
|
1287
|
-
* @param migrations - Array of migration objects with name and SQL content
|
|
1288
|
-
* @returns Promise with migration result (applied count, already applied count, applied migration names)
|
|
1289
|
-
*/
|
|
1290
|
-
async registerMigrationsAsync(extensionVersion, migrations) {
|
|
1291
|
-
return this.database.registerMigrationsAsync(extensionVersion, migrations);
|
|
1292
|
-
}
|
|
1293
|
-
async requestDatabasePermission(request) {
|
|
1294
|
-
return this.request("permissions.database.request", {
|
|
1295
|
-
resource: request.resource,
|
|
1296
|
-
operation: request.operation,
|
|
1297
|
-
reason: request.reason
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1300
|
-
async checkDatabasePermission(resource, operation) {
|
|
1301
|
-
const response = await this.request(
|
|
1302
|
-
"permissions.database.check",
|
|
1303
|
-
{
|
|
1304
|
-
resource,
|
|
1305
|
-
operation
|
|
1306
|
-
}
|
|
1307
|
-
);
|
|
1308
|
-
return response.status === "granted";
|
|
1309
|
-
}
|
|
1310
|
-
async respondToSearch(requestId, results) {
|
|
1311
|
-
await this.request("search.respond", {
|
|
1312
|
-
requestId,
|
|
1313
|
-
results
|
|
1314
|
-
});
|
|
1223
|
+
sendDebugInfo(ctx.config);
|
|
1224
|
+
const context = await request(HAEXTENSION_METHODS.context.get);
|
|
1225
|
+
ctx.state.context = context;
|
|
1226
|
+
log("Application context received:", context);
|
|
1227
|
+
return { context };
|
|
1228
|
+
}
|
|
1229
|
+
function sendDebugInfo(config) {
|
|
1230
|
+
if (!config.debug) return;
|
|
1231
|
+
if (typeof window === "undefined" || !window.parent) return;
|
|
1232
|
+
const debugInfo = `SDK Debug:
|
|
1233
|
+
window.parent exists: ${!!window.parent}
|
|
1234
|
+
window.parent === window: ${window.parent === window}
|
|
1235
|
+
window.self === window.top: ${window.self === window.top}`;
|
|
1236
|
+
try {
|
|
1237
|
+
window.parent.postMessage({
|
|
1238
|
+
type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
|
|
1239
|
+
data: debugInfo
|
|
1240
|
+
}, "*");
|
|
1241
|
+
} catch (e) {
|
|
1242
|
+
alert(debugInfo + `
|
|
1243
|
+
postMessage error: ${e}`);
|
|
1315
1244
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// src/commands.ts
|
|
1248
|
+
var TAURI_COMMANDS = {
|
|
1249
|
+
database: {
|
|
1250
|
+
query: "webview_extension_db_query",
|
|
1251
|
+
execute: "webview_extension_db_execute",
|
|
1252
|
+
registerMigrations: "webview_extension_db_register_migrations"
|
|
1253
|
+
},
|
|
1254
|
+
permissions: {
|
|
1255
|
+
checkWeb: "webview_extension_check_web_permission",
|
|
1256
|
+
checkDatabase: "webview_extension_check_database_permission",
|
|
1257
|
+
checkFilesystem: "webview_extension_check_filesystem_permission"
|
|
1258
|
+
},
|
|
1259
|
+
web: {
|
|
1260
|
+
open: "webview_extension_web_open",
|
|
1261
|
+
fetch: "webview_extension_web_request"
|
|
1262
|
+
},
|
|
1263
|
+
filesystem: {
|
|
1264
|
+
saveFile: "webview_extension_fs_save_file",
|
|
1265
|
+
openFile: "webview_extension_fs_open_file",
|
|
1266
|
+
showImage: "webview_extension_fs_show_image"
|
|
1267
|
+
},
|
|
1268
|
+
external: {
|
|
1269
|
+
respond: "webview_extension_external_respond"
|
|
1270
|
+
},
|
|
1271
|
+
extension: {
|
|
1272
|
+
getInfo: "webview_extension_get_info",
|
|
1273
|
+
getContext: "webview_extension_context_get"
|
|
1274
|
+
},
|
|
1275
|
+
filesync: {
|
|
1276
|
+
// Spaces
|
|
1277
|
+
listSpaces: "filesync_list_spaces",
|
|
1278
|
+
createSpace: "filesync_create_space",
|
|
1279
|
+
deleteSpace: "filesync_delete_space",
|
|
1280
|
+
// Files
|
|
1281
|
+
listFiles: "filesync_list_files",
|
|
1282
|
+
getFile: "filesync_get_file",
|
|
1283
|
+
uploadFile: "filesync_upload_file",
|
|
1284
|
+
downloadFile: "filesync_download_file",
|
|
1285
|
+
deleteFile: "filesync_delete_file",
|
|
1286
|
+
// Backends
|
|
1287
|
+
listBackends: "filesync_list_backends",
|
|
1288
|
+
addBackend: "filesync_add_backend",
|
|
1289
|
+
removeBackend: "filesync_remove_backend",
|
|
1290
|
+
testBackend: "filesync_test_backend",
|
|
1291
|
+
// Sync Rules
|
|
1292
|
+
listSyncRules: "filesync_list_sync_rules",
|
|
1293
|
+
addSyncRule: "filesync_add_sync_rule",
|
|
1294
|
+
removeSyncRule: "filesync_remove_sync_rule",
|
|
1295
|
+
// Sync Operations
|
|
1296
|
+
getSyncStatus: "filesync_get_sync_status",
|
|
1297
|
+
triggerSync: "filesync_trigger_sync",
|
|
1298
|
+
pauseSync: "filesync_pause_sync",
|
|
1299
|
+
resumeSync: "filesync_resume_sync",
|
|
1300
|
+
// Conflict Resolution
|
|
1301
|
+
resolveConflict: "filesync_resolve_conflict",
|
|
1302
|
+
// UI Helpers
|
|
1303
|
+
selectFolder: "filesync_select_folder"
|
|
1342
1304
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
// src/transport/handlers/database.ts
|
|
1308
|
+
var databaseHandlers = {
|
|
1309
|
+
[HAEXTENSION_METHODS.database.query]: {
|
|
1310
|
+
command: TAURI_COMMANDS.database.query,
|
|
1311
|
+
args: (p) => ({
|
|
1312
|
+
query: p.query,
|
|
1313
|
+
params: p.params || []
|
|
1314
|
+
})
|
|
1315
|
+
},
|
|
1316
|
+
[HAEXTENSION_METHODS.database.execute]: {
|
|
1317
|
+
command: TAURI_COMMANDS.database.execute,
|
|
1318
|
+
args: (p) => ({
|
|
1319
|
+
query: p.query,
|
|
1320
|
+
params: p.params || []
|
|
1321
|
+
})
|
|
1322
|
+
},
|
|
1323
|
+
[HAEXTENSION_METHODS.database.registerMigrations]: {
|
|
1324
|
+
command: TAURI_COMMANDS.database.registerMigrations,
|
|
1325
|
+
args: (p) => ({
|
|
1326
|
+
extensionVersion: p.extensionVersion,
|
|
1327
|
+
migrations: p.migrations
|
|
1328
|
+
})
|
|
1349
1329
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
this.pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1374
|
-
const targetOrigin = "*";
|
|
1375
|
-
if (this.config.debug) {
|
|
1376
|
-
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1377
|
-
console.log("[SDK Debug] Request ID:", requestId);
|
|
1378
|
-
console.log("[SDK Debug] Method:", request.method);
|
|
1379
|
-
console.log("[SDK Debug] Params:", request.params);
|
|
1380
|
-
console.log("[SDK Debug] Target origin:", targetOrigin);
|
|
1381
|
-
console.log("[SDK Debug] Extension info:", this._extensionInfo);
|
|
1382
|
-
console.log("[SDK Debug] ========================================");
|
|
1383
|
-
}
|
|
1384
|
-
window.parent.postMessage({ id: requestId, ...request }, targetOrigin);
|
|
1385
|
-
});
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
// src/transport/handlers/permissions.ts
|
|
1333
|
+
var permissionsHandlers = {
|
|
1334
|
+
"permissions.web.check": {
|
|
1335
|
+
command: TAURI_COMMANDS.permissions.checkWeb,
|
|
1336
|
+
args: (p) => ({
|
|
1337
|
+
url: p.url
|
|
1338
|
+
})
|
|
1339
|
+
},
|
|
1340
|
+
"permissions.database.check": {
|
|
1341
|
+
command: TAURI_COMMANDS.permissions.checkDatabase,
|
|
1342
|
+
args: (p) => ({
|
|
1343
|
+
resource: p.resource,
|
|
1344
|
+
operation: p.operation
|
|
1345
|
+
})
|
|
1346
|
+
},
|
|
1347
|
+
"permissions.filesystem.check": {
|
|
1348
|
+
command: TAURI_COMMANDS.permissions.checkFilesystem,
|
|
1349
|
+
args: (p) => ({
|
|
1350
|
+
path: p.path,
|
|
1351
|
+
actionStr: p.action
|
|
1352
|
+
})
|
|
1386
1353
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
});
|
|
1406
|
-
case "permissions.web.check":
|
|
1407
|
-
return invoke("webview_extension_check_web_permission", {
|
|
1408
|
-
url: params.url
|
|
1409
|
-
});
|
|
1410
|
-
case "permissions.database.check":
|
|
1411
|
-
return invoke("webview_extension_check_database_permission", {
|
|
1412
|
-
resource: params.resource,
|
|
1413
|
-
operation: params.operation
|
|
1414
|
-
});
|
|
1415
|
-
case "permissions.filesystem.check":
|
|
1416
|
-
return invoke("webview_extension_check_filesystem_permission", {
|
|
1417
|
-
path: params.path,
|
|
1418
|
-
actionStr: params.action
|
|
1419
|
-
});
|
|
1420
|
-
case HAEXTENSION_METHODS.application.open:
|
|
1421
|
-
return invoke("webview_extension_web_open", {
|
|
1422
|
-
url: params.url
|
|
1423
|
-
});
|
|
1424
|
-
case HAEXTENSION_METHODS.web.fetch:
|
|
1425
|
-
return invoke("webview_extension_web_request", {
|
|
1426
|
-
url: params.url,
|
|
1427
|
-
method: params.method,
|
|
1428
|
-
headers: params.headers,
|
|
1429
|
-
body: params.body
|
|
1430
|
-
});
|
|
1431
|
-
case HAEXTENSION_METHODS.filesystem.saveFile:
|
|
1432
|
-
return invoke("webview_extension_fs_save_file", {
|
|
1433
|
-
data: params.data,
|
|
1434
|
-
defaultPath: params.defaultPath,
|
|
1435
|
-
title: params.title,
|
|
1436
|
-
filters: params.filters
|
|
1437
|
-
});
|
|
1438
|
-
case HAEXTENSION_METHODS.filesystem.openFile:
|
|
1439
|
-
return invoke("webview_extension_fs_open_file", {
|
|
1440
|
-
data: params.data,
|
|
1441
|
-
fileName: params.fileName
|
|
1442
|
-
});
|
|
1443
|
-
case HAEXTENSION_METHODS.database.registerMigrations:
|
|
1444
|
-
return invoke("webview_extension_db_register_migrations", {
|
|
1445
|
-
extensionVersion: params.extensionVersion,
|
|
1446
|
-
migrations: params.migrations
|
|
1447
|
-
});
|
|
1448
|
-
case "external.respond":
|
|
1449
|
-
return invoke("webview_extension_external_respond", {
|
|
1450
|
-
requestId: params.requestId,
|
|
1451
|
-
success: params.success,
|
|
1452
|
-
data: params.data,
|
|
1453
|
-
error: params.error
|
|
1454
|
-
});
|
|
1455
|
-
default:
|
|
1456
|
-
throw new HaexHubError(
|
|
1457
|
-
"METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */,
|
|
1458
|
-
"errors.method_not_found",
|
|
1459
|
-
{ method }
|
|
1460
|
-
);
|
|
1461
|
-
}
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
// src/transport/handlers/web.ts
|
|
1357
|
+
var webHandlers = {
|
|
1358
|
+
[HAEXTENSION_METHODS.application.open]: {
|
|
1359
|
+
command: TAURI_COMMANDS.web.open,
|
|
1360
|
+
args: (p) => ({
|
|
1361
|
+
url: p.url
|
|
1362
|
+
})
|
|
1363
|
+
},
|
|
1364
|
+
[HAEXTENSION_METHODS.web.fetch]: {
|
|
1365
|
+
command: TAURI_COMMANDS.web.fetch,
|
|
1366
|
+
args: (p) => ({
|
|
1367
|
+
url: p.url,
|
|
1368
|
+
method: p.method,
|
|
1369
|
+
headers: p.headers,
|
|
1370
|
+
body: p.body
|
|
1371
|
+
})
|
|
1462
1372
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
// src/transport/handlers/filesystem.ts
|
|
1376
|
+
var filesystemHandlers = {
|
|
1377
|
+
[HAEXTENSION_METHODS.filesystem.saveFile]: {
|
|
1378
|
+
command: TAURI_COMMANDS.filesystem.saveFile,
|
|
1379
|
+
args: (p) => ({
|
|
1380
|
+
data: p.data,
|
|
1381
|
+
defaultPath: p.defaultPath,
|
|
1382
|
+
title: p.title,
|
|
1383
|
+
filters: p.filters
|
|
1384
|
+
})
|
|
1385
|
+
},
|
|
1386
|
+
[HAEXTENSION_METHODS.filesystem.openFile]: {
|
|
1387
|
+
command: TAURI_COMMANDS.filesystem.openFile,
|
|
1388
|
+
args: (p) => ({
|
|
1389
|
+
data: p.data,
|
|
1390
|
+
fileName: p.fileName
|
|
1391
|
+
})
|
|
1392
|
+
},
|
|
1393
|
+
[HAEXTENSION_METHODS.filesystem.showImage]: {
|
|
1394
|
+
command: TAURI_COMMANDS.filesystem.showImage,
|
|
1395
|
+
args: (p) => ({
|
|
1396
|
+
dataUrl: p.dataUrl
|
|
1397
|
+
})
|
|
1468
1398
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1401
|
+
// src/transport/handlers/external.ts
|
|
1402
|
+
var externalHandlers = {
|
|
1403
|
+
"external.respond": {
|
|
1404
|
+
command: TAURI_COMMANDS.external.respond,
|
|
1405
|
+
args: (p) => ({
|
|
1406
|
+
requestId: p.requestId,
|
|
1407
|
+
success: p.success,
|
|
1408
|
+
data: p.data,
|
|
1409
|
+
error: p.error
|
|
1410
|
+
})
|
|
1474
1411
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1412
|
+
};
|
|
1413
|
+
|
|
1414
|
+
// src/transport/handlers/filesync.ts
|
|
1415
|
+
var filesyncHandlers = {
|
|
1416
|
+
// ==========================================================================
|
|
1417
|
+
// Spaces
|
|
1418
|
+
// ==========================================================================
|
|
1419
|
+
[HAEXTENSION_METHODS.filesystem.sync.listSpaces]: {
|
|
1420
|
+
command: TAURI_COMMANDS.filesync.listSpaces,
|
|
1421
|
+
args: () => ({})
|
|
1422
|
+
},
|
|
1423
|
+
[HAEXTENSION_METHODS.filesystem.sync.createSpace]: {
|
|
1424
|
+
command: TAURI_COMMANDS.filesync.createSpace,
|
|
1425
|
+
args: (p) => ({ request: p })
|
|
1426
|
+
},
|
|
1427
|
+
[HAEXTENSION_METHODS.filesystem.sync.deleteSpace]: {
|
|
1428
|
+
command: TAURI_COMMANDS.filesync.deleteSpace,
|
|
1429
|
+
args: (p) => ({ spaceId: p.spaceId })
|
|
1430
|
+
},
|
|
1431
|
+
// ==========================================================================
|
|
1432
|
+
// Files
|
|
1433
|
+
// ==========================================================================
|
|
1434
|
+
[HAEXTENSION_METHODS.filesystem.sync.listFiles]: {
|
|
1435
|
+
command: TAURI_COMMANDS.filesync.listFiles,
|
|
1436
|
+
args: (p) => ({ request: p })
|
|
1437
|
+
},
|
|
1438
|
+
[HAEXTENSION_METHODS.filesystem.sync.getFile]: {
|
|
1439
|
+
command: TAURI_COMMANDS.filesync.getFile,
|
|
1440
|
+
args: (p) => ({ fileId: p.fileId })
|
|
1441
|
+
},
|
|
1442
|
+
[HAEXTENSION_METHODS.filesystem.sync.uploadFile]: {
|
|
1443
|
+
command: TAURI_COMMANDS.filesync.uploadFile,
|
|
1444
|
+
args: (p) => ({ request: p })
|
|
1445
|
+
},
|
|
1446
|
+
[HAEXTENSION_METHODS.filesystem.sync.downloadFile]: {
|
|
1447
|
+
command: TAURI_COMMANDS.filesync.downloadFile,
|
|
1448
|
+
args: (p) => ({ request: p })
|
|
1449
|
+
},
|
|
1450
|
+
[HAEXTENSION_METHODS.filesystem.sync.deleteFile]: {
|
|
1451
|
+
command: TAURI_COMMANDS.filesync.deleteFile,
|
|
1452
|
+
args: (p) => ({ fileId: p.fileId })
|
|
1453
|
+
},
|
|
1454
|
+
// ==========================================================================
|
|
1455
|
+
// Backends
|
|
1456
|
+
// ==========================================================================
|
|
1457
|
+
[HAEXTENSION_METHODS.filesystem.sync.listBackends]: {
|
|
1458
|
+
command: TAURI_COMMANDS.filesync.listBackends,
|
|
1459
|
+
args: () => ({})
|
|
1460
|
+
},
|
|
1461
|
+
[HAEXTENSION_METHODS.filesystem.sync.addBackend]: {
|
|
1462
|
+
command: TAURI_COMMANDS.filesync.addBackend,
|
|
1463
|
+
args: (p) => ({ request: p })
|
|
1464
|
+
},
|
|
1465
|
+
[HAEXTENSION_METHODS.filesystem.sync.removeBackend]: {
|
|
1466
|
+
command: TAURI_COMMANDS.filesync.removeBackend,
|
|
1467
|
+
args: (p) => ({ backendId: p.backendId })
|
|
1468
|
+
},
|
|
1469
|
+
[HAEXTENSION_METHODS.filesystem.sync.testBackend]: {
|
|
1470
|
+
command: TAURI_COMMANDS.filesync.testBackend,
|
|
1471
|
+
args: (p) => ({ backendId: p.backendId })
|
|
1472
|
+
},
|
|
1473
|
+
// ==========================================================================
|
|
1474
|
+
// Sync Rules
|
|
1475
|
+
// ==========================================================================
|
|
1476
|
+
[HAEXTENSION_METHODS.filesystem.sync.listSyncRules]: {
|
|
1477
|
+
command: TAURI_COMMANDS.filesync.listSyncRules,
|
|
1478
|
+
args: () => ({})
|
|
1479
|
+
},
|
|
1480
|
+
[HAEXTENSION_METHODS.filesystem.sync.addSyncRule]: {
|
|
1481
|
+
command: TAURI_COMMANDS.filesync.addSyncRule,
|
|
1482
|
+
args: (p) => ({ request: p })
|
|
1483
|
+
},
|
|
1484
|
+
[HAEXTENSION_METHODS.filesystem.sync.removeSyncRule]: {
|
|
1485
|
+
command: TAURI_COMMANDS.filesync.removeSyncRule,
|
|
1486
|
+
args: (p) => ({ ruleId: p.ruleId })
|
|
1487
|
+
},
|
|
1488
|
+
// ==========================================================================
|
|
1489
|
+
// Sync Operations
|
|
1490
|
+
// ==========================================================================
|
|
1491
|
+
[HAEXTENSION_METHODS.filesystem.sync.getSyncStatus]: {
|
|
1492
|
+
command: TAURI_COMMANDS.filesync.getSyncStatus,
|
|
1493
|
+
args: () => ({})
|
|
1494
|
+
},
|
|
1495
|
+
[HAEXTENSION_METHODS.filesystem.sync.triggerSync]: {
|
|
1496
|
+
command: TAURI_COMMANDS.filesync.triggerSync,
|
|
1497
|
+
args: () => ({})
|
|
1498
|
+
},
|
|
1499
|
+
[HAEXTENSION_METHODS.filesystem.sync.pauseSync]: {
|
|
1500
|
+
command: TAURI_COMMANDS.filesync.pauseSync,
|
|
1501
|
+
args: () => ({})
|
|
1502
|
+
},
|
|
1503
|
+
[HAEXTENSION_METHODS.filesystem.sync.resumeSync]: {
|
|
1504
|
+
command: TAURI_COMMANDS.filesync.resumeSync,
|
|
1505
|
+
args: () => ({})
|
|
1506
|
+
},
|
|
1507
|
+
// ==========================================================================
|
|
1508
|
+
// Conflict Resolution
|
|
1509
|
+
// ==========================================================================
|
|
1510
|
+
[HAEXTENSION_METHODS.filesystem.sync.resolveConflict]: {
|
|
1511
|
+
command: TAURI_COMMANDS.filesync.resolveConflict,
|
|
1512
|
+
args: (p) => ({ request: p })
|
|
1513
|
+
},
|
|
1514
|
+
// ==========================================================================
|
|
1515
|
+
// UI Helpers
|
|
1516
|
+
// ==========================================================================
|
|
1517
|
+
[HAEXTENSION_METHODS.filesystem.sync.selectFolder]: {
|
|
1518
|
+
command: TAURI_COMMANDS.filesync.selectFolder,
|
|
1519
|
+
args: () => ({})
|
|
1484
1520
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
if (event.payload) {
|
|
1527
|
-
this.handleEvent({
|
|
1528
|
-
type: HAEXTENSION_EVENTS.EXTERNAL_REQUEST,
|
|
1529
|
-
data: event.payload,
|
|
1530
|
-
timestamp: Date.now()
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
});
|
|
1534
|
-
console.log("[HaexSpace SDK] External request listener registered successfully");
|
|
1535
|
-
} catch (error) {
|
|
1536
|
-
console.error("[HaexSpace SDK] Failed to setup external request listener:", error);
|
|
1537
|
-
this.log("Failed to setup external request listener:", error);
|
|
1538
|
-
}
|
|
1539
|
-
this.resolveReady();
|
|
1540
|
-
return;
|
|
1541
|
-
}
|
|
1542
|
-
} catch (error) {
|
|
1543
|
-
this.log("Tauri commands failed, falling back to iframe mode", error);
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
if (window.self === window.top) {
|
|
1547
|
-
throw new HaexHubError("NOT_IN_IFRAME" /* NOT_IN_IFRAME */, "errors.not_in_iframe");
|
|
1548
|
-
}
|
|
1549
|
-
this.messageHandler = this.handleMessage.bind(this);
|
|
1550
|
-
window.addEventListener("message", this.messageHandler);
|
|
1551
|
-
this.isNativeWindow = false;
|
|
1552
|
-
this.initialized = true;
|
|
1553
|
-
this.log("HaexSpace SDK initialized in iframe mode");
|
|
1554
|
-
try {
|
|
1555
|
-
if (this.config.manifest) {
|
|
1556
|
-
this._extensionInfo = {
|
|
1557
|
-
publicKey: this.config.manifest.publicKey,
|
|
1558
|
-
name: this.config.manifest.name,
|
|
1559
|
-
version: this.config.manifest.version,
|
|
1560
|
-
displayName: this.config.manifest.name
|
|
1561
|
-
};
|
|
1562
|
-
this.log("Extension info loaded from manifest:", this._extensionInfo);
|
|
1563
|
-
this.notifySubscribers();
|
|
1564
|
-
}
|
|
1565
|
-
if (typeof window !== "undefined" && window.parent) {
|
|
1566
|
-
const debugInfo = `SDK Debug:
|
|
1567
|
-
window.parent exists: ${!!window.parent}
|
|
1568
|
-
window.parent === window: ${window.parent === window}
|
|
1569
|
-
window.self === window.top: ${window.self === window.top}`;
|
|
1570
|
-
try {
|
|
1571
|
-
window.parent.postMessage({
|
|
1572
|
-
type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
|
|
1573
|
-
data: debugInfo
|
|
1574
|
-
}, "*");
|
|
1575
|
-
} catch (e) {
|
|
1576
|
-
alert(debugInfo + `
|
|
1577
|
-
postMessage error: ${e}`);
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
this._context = await this.request(HAEXTENSION_METHODS.context.get);
|
|
1581
|
-
this.log("Application context received:", this._context);
|
|
1582
|
-
this.notifySubscribers();
|
|
1583
|
-
this.resolveReady();
|
|
1584
|
-
} catch (error) {
|
|
1585
|
-
this.log("Failed to load extension info or context:", error);
|
|
1586
|
-
throw error;
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// src/transport/handlers/index.ts
|
|
1524
|
+
var allHandlers = {
|
|
1525
|
+
...databaseHandlers,
|
|
1526
|
+
...permissionsHandlers,
|
|
1527
|
+
...webHandlers,
|
|
1528
|
+
...filesystemHandlers,
|
|
1529
|
+
...externalHandlers,
|
|
1530
|
+
...filesyncHandlers
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
// src/client/transport.ts
|
|
1534
|
+
function generateRequestId(counter) {
|
|
1535
|
+
return `req_${counter}`;
|
|
1536
|
+
}
|
|
1537
|
+
function sendPostMessage(method, params, requestId, config, extensionInfo, pendingRequests) {
|
|
1538
|
+
const request = {
|
|
1539
|
+
method,
|
|
1540
|
+
params,
|
|
1541
|
+
timestamp: Date.now()
|
|
1542
|
+
};
|
|
1543
|
+
return new Promise((resolve, reject) => {
|
|
1544
|
+
const timeout = setTimeout(() => {
|
|
1545
|
+
pendingRequests.delete(requestId);
|
|
1546
|
+
reject(
|
|
1547
|
+
new HaexVaultSdkError("TIMEOUT" /* TIMEOUT */, "errors.timeout", {
|
|
1548
|
+
timeout: config.timeout
|
|
1549
|
+
})
|
|
1550
|
+
);
|
|
1551
|
+
}, config.timeout);
|
|
1552
|
+
pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
1553
|
+
const targetOrigin = "*";
|
|
1554
|
+
if (config.debug) {
|
|
1555
|
+
console.log("[SDK Debug] ========== Sending Request ==========");
|
|
1556
|
+
console.log("[SDK Debug] Request ID:", requestId);
|
|
1557
|
+
console.log("[SDK Debug] Method:", request.method);
|
|
1558
|
+
console.log("[SDK Debug] Params:", request.params);
|
|
1559
|
+
console.log("[SDK Debug] Target origin:", targetOrigin);
|
|
1560
|
+
console.log("[SDK Debug] Extension info:", extensionInfo);
|
|
1561
|
+
console.log("[SDK Debug] ========================================");
|
|
1587
1562
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1563
|
+
window.parent.postMessage({ id: requestId, ...request }, targetOrigin);
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
async function sendInvoke(method, params, config, log) {
|
|
1567
|
+
const { invoke } = window.__TAURI__.core;
|
|
1568
|
+
if (config.debug) {
|
|
1569
|
+
console.log("[SDK Debug] ========== Invoke Request ==========");
|
|
1570
|
+
console.log("[SDK Debug] Method:", method);
|
|
1571
|
+
console.log("[SDK Debug] Params:", params);
|
|
1572
|
+
console.log("[SDK Debug] =======================================");
|
|
1573
|
+
}
|
|
1574
|
+
const handler = allHandlers[method];
|
|
1575
|
+
if (handler) {
|
|
1576
|
+
const args = handler.args(params);
|
|
1577
|
+
return invoke(handler.command, args);
|
|
1578
|
+
}
|
|
1579
|
+
throw new HaexVaultSdkError(
|
|
1580
|
+
"METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */,
|
|
1581
|
+
"errors.method_not_found",
|
|
1582
|
+
{ method }
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// src/client/events.ts
|
|
1587
|
+
function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
|
|
1588
|
+
return (event) => {
|
|
1589
|
+
if (config.debug) {
|
|
1591
1590
|
console.log("[SDK Debug] ========== Message Received ==========");
|
|
1592
1591
|
console.log("[SDK Debug] Event origin:", event.origin);
|
|
1593
1592
|
console.log(
|
|
@@ -1595,160 +1594,534 @@ postMessage error: ${e}`);
|
|
|
1595
1594
|
event.source === window.parent ? "parent window" : "unknown"
|
|
1596
1595
|
);
|
|
1597
1596
|
console.log("[SDK Debug] Event data:", event.data);
|
|
1598
|
-
console.log("[SDK Debug] Extension info loaded:", !!
|
|
1597
|
+
console.log("[SDK Debug] Extension info loaded:", !!extensionInfo());
|
|
1599
1598
|
console.log(
|
|
1600
1599
|
"[SDK Debug] Pending requests count:",
|
|
1601
|
-
|
|
1600
|
+
pendingRequests.size
|
|
1602
1601
|
);
|
|
1603
1602
|
}
|
|
1604
1603
|
if (event.source !== window.parent) {
|
|
1605
|
-
if (
|
|
1604
|
+
if (config.debug) {
|
|
1606
1605
|
console.error("[SDK Debug] \u274C REJECTED: Message not from parent window!");
|
|
1607
1606
|
}
|
|
1608
1607
|
return;
|
|
1609
1608
|
}
|
|
1610
1609
|
const data = event.data;
|
|
1611
|
-
if ("id" in data &&
|
|
1612
|
-
if (
|
|
1610
|
+
if ("id" in data && pendingRequests.has(data.id)) {
|
|
1611
|
+
if (config.debug) {
|
|
1613
1612
|
console.log("[SDK Debug] \u2705 Found pending request for ID:", data.id);
|
|
1614
1613
|
}
|
|
1615
|
-
const pending =
|
|
1614
|
+
const pending = pendingRequests.get(data.id);
|
|
1616
1615
|
clearTimeout(pending.timeout);
|
|
1617
|
-
|
|
1616
|
+
pendingRequests.delete(data.id);
|
|
1618
1617
|
if (data.error) {
|
|
1619
|
-
if (
|
|
1618
|
+
if (config.debug) {
|
|
1620
1619
|
console.error("[SDK Debug] \u274C Request failed:", data.error);
|
|
1621
1620
|
}
|
|
1622
1621
|
pending.reject(data.error);
|
|
1623
1622
|
} else {
|
|
1624
|
-
if (
|
|
1623
|
+
if (config.debug) {
|
|
1625
1624
|
console.log("[SDK Debug] \u2705 Request succeeded:", data.result);
|
|
1626
1625
|
}
|
|
1627
1626
|
pending.resolve(data.result);
|
|
1628
1627
|
}
|
|
1629
1628
|
return;
|
|
1630
1629
|
}
|
|
1631
|
-
if ("id" in data && !
|
|
1632
|
-
if (
|
|
1630
|
+
if ("id" in data && !pendingRequests.has(data.id)) {
|
|
1631
|
+
if (config.debug) {
|
|
1633
1632
|
console.warn(
|
|
1634
1633
|
"[SDK Debug] \u26A0\uFE0F Received response for unknown request ID:",
|
|
1635
1634
|
data.id
|
|
1636
1635
|
);
|
|
1637
1636
|
console.warn(
|
|
1638
1637
|
"[SDK Debug] Known IDs:",
|
|
1639
|
-
Array.from(
|
|
1638
|
+
Array.from(pendingRequests.keys())
|
|
1640
1639
|
);
|
|
1641
1640
|
}
|
|
1642
1641
|
}
|
|
1643
1642
|
if ("type" in data && data.type) {
|
|
1644
|
-
if (
|
|
1643
|
+
if (config.debug) {
|
|
1645
1644
|
console.log("[SDK Debug] Event received:", data.type);
|
|
1646
1645
|
}
|
|
1647
|
-
|
|
1646
|
+
onEvent(data);
|
|
1648
1647
|
}
|
|
1649
|
-
if (
|
|
1648
|
+
if (config.debug) {
|
|
1650
1649
|
console.log("[SDK Debug] ========== End Message ==========");
|
|
1651
1650
|
}
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest) {
|
|
1654
|
+
if (event.type === HAEXTENSION_EVENTS.CONTEXT_CHANGED) {
|
|
1655
|
+
const contextEvent = event;
|
|
1656
|
+
onContextChanged(contextEvent.data.context);
|
|
1657
|
+
log("Context updated:", contextEvent.data.context);
|
|
1658
|
+
}
|
|
1659
|
+
if (event.type === HAEXTENSION_EVENTS.EXTERNAL_REQUEST) {
|
|
1660
|
+
const externalEvent = event;
|
|
1661
|
+
onExternalRequest(externalEvent);
|
|
1662
|
+
return;
|
|
1652
1663
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1664
|
+
emitEvent(event, log, eventListeners);
|
|
1665
|
+
}
|
|
1666
|
+
function emitEvent(event, log, eventListeners) {
|
|
1667
|
+
log("Event received:", event);
|
|
1668
|
+
const listeners = eventListeners.get(event.type);
|
|
1669
|
+
if (listeners) {
|
|
1670
|
+
listeners.forEach((callback) => callback(event));
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
function addEventListener(eventType, callback, eventListeners) {
|
|
1674
|
+
if (!eventListeners.has(eventType)) {
|
|
1675
|
+
eventListeners.set(eventType, /* @__PURE__ */ new Set());
|
|
1676
|
+
}
|
|
1677
|
+
eventListeners.get(eventType).add(callback);
|
|
1678
|
+
}
|
|
1679
|
+
function removeEventListener(eventType, callback, eventListeners) {
|
|
1680
|
+
const listeners = eventListeners.get(eventType);
|
|
1681
|
+
if (listeners) {
|
|
1682
|
+
listeners.delete(callback);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function notifySubscribers(subscribers) {
|
|
1686
|
+
subscribers.forEach((callback) => callback());
|
|
1687
|
+
}
|
|
1688
|
+
function createDrizzleInstance(schema, extensionInfo, request, log) {
|
|
1689
|
+
if (!extensionInfo) {
|
|
1690
|
+
throw new HaexVaultSdkError(
|
|
1691
|
+
"EXTENSION_INFO_UNAVAILABLE" /* EXTENSION_INFO_UNAVAILABLE */,
|
|
1692
|
+
"errors.client_not_ready"
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
return sqliteProxy.drizzle(
|
|
1696
|
+
async (sql, params, method) => {
|
|
1697
|
+
try {
|
|
1698
|
+
if (method === "run" || method === "all") {
|
|
1699
|
+
const result2 = await request(
|
|
1700
|
+
HAEXTENSION_METHODS.database.execute,
|
|
1701
|
+
{
|
|
1702
|
+
query: sql,
|
|
1703
|
+
params
|
|
1704
|
+
}
|
|
1705
|
+
);
|
|
1706
|
+
if (method === "all") {
|
|
1707
|
+
return { rows: result2.rows || [] };
|
|
1708
|
+
}
|
|
1709
|
+
if (result2.rows && Array.isArray(result2.rows) && result2.rows.length > 0) {
|
|
1710
|
+
return { rows: result2.rows };
|
|
1711
|
+
}
|
|
1712
|
+
return result2;
|
|
1713
|
+
}
|
|
1714
|
+
const result = await request(HAEXTENSION_METHODS.database.query, {
|
|
1715
|
+
query: sql,
|
|
1716
|
+
params
|
|
1717
|
+
});
|
|
1718
|
+
const rows = result.rows;
|
|
1719
|
+
if (method === "get") {
|
|
1720
|
+
return { rows: rows.length > 0 ? rows.at(0) : void 0 };
|
|
1721
|
+
}
|
|
1722
|
+
return { rows };
|
|
1723
|
+
} catch (error) {
|
|
1724
|
+
log("Database operation failed:", error);
|
|
1725
|
+
throw error;
|
|
1726
|
+
}
|
|
1727
|
+
},
|
|
1728
|
+
{
|
|
1729
|
+
schema,
|
|
1730
|
+
logger: false
|
|
1659
1731
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
async function queryRaw(sql, params, request, debug) {
|
|
1735
|
+
const result = await request(
|
|
1736
|
+
HAEXTENSION_METHODS.database.query,
|
|
1737
|
+
{ query: sql, params }
|
|
1738
|
+
);
|
|
1739
|
+
if (debug) {
|
|
1740
|
+
console.log("[SDK query()] Raw result:", JSON.stringify(result, null, 2));
|
|
1741
|
+
}
|
|
1742
|
+
return result.rows;
|
|
1743
|
+
}
|
|
1744
|
+
async function executeRaw(sql, params, request) {
|
|
1745
|
+
const result = await request(
|
|
1746
|
+
HAEXTENSION_METHODS.database.execute,
|
|
1747
|
+
{ query: sql, params }
|
|
1748
|
+
);
|
|
1749
|
+
return {
|
|
1750
|
+
rowsAffected: result.rowsAffected,
|
|
1751
|
+
lastInsertId: result.lastInsertId
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
// src/client/external.ts
|
|
1756
|
+
function registerExternalHandler(action, handler, handlers, log) {
|
|
1757
|
+
handlers.set(action, handler);
|
|
1758
|
+
log(`[ExternalRequest] Registered handler for action: ${action}`);
|
|
1759
|
+
return () => {
|
|
1760
|
+
handlers.delete(action);
|
|
1761
|
+
log(`[ExternalRequest] Unregistered handler for action: ${action}`);
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
async function handleExternalRequest(request, handlers, respond, log) {
|
|
1765
|
+
log(`[ExternalRequest] Received request: ${request.action} from ${request.publicKey.substring(0, 20)}...`);
|
|
1766
|
+
const handler = handlers.get(request.action);
|
|
1767
|
+
if (!handler) {
|
|
1768
|
+
log(`[ExternalRequest] No handler for action: ${request.action}`);
|
|
1769
|
+
await respond({
|
|
1770
|
+
requestId: request.requestId,
|
|
1771
|
+
success: false,
|
|
1772
|
+
error: `No handler registered for action: ${request.action}`
|
|
1773
|
+
});
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
try {
|
|
1777
|
+
const response = await handler(request);
|
|
1778
|
+
await respond(response);
|
|
1779
|
+
log(`[ExternalRequest] Response sent for: ${request.action}`);
|
|
1780
|
+
} catch (error) {
|
|
1781
|
+
log(`[ExternalRequest] Handler error:`, error);
|
|
1782
|
+
await respond({
|
|
1783
|
+
requestId: request.requestId,
|
|
1784
|
+
success: false,
|
|
1785
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
async function respondToExternalRequest(response, request) {
|
|
1790
|
+
await request("external.respond", response);
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
// src/client.ts
|
|
1794
|
+
var HaexVaultClient = class {
|
|
1795
|
+
constructor(config = {}) {
|
|
1796
|
+
// State
|
|
1797
|
+
this.initialized = false;
|
|
1798
|
+
this.isNativeWindow = false;
|
|
1799
|
+
this.requestCounter = 0;
|
|
1800
|
+
this._extensionInfo = null;
|
|
1801
|
+
this._context = null;
|
|
1802
|
+
this._setupCompleted = false;
|
|
1803
|
+
// Collections
|
|
1804
|
+
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
1805
|
+
this.eventListeners = /* @__PURE__ */ new Map();
|
|
1806
|
+
this.externalRequestHandlers = /* @__PURE__ */ new Map();
|
|
1807
|
+
this.reactiveSubscribers = /* @__PURE__ */ new Set();
|
|
1808
|
+
// Handlers
|
|
1809
|
+
this.messageHandler = null;
|
|
1810
|
+
this.setupPromise = null;
|
|
1811
|
+
this.setupHook = null;
|
|
1812
|
+
// Public APIs
|
|
1813
|
+
this.orm = null;
|
|
1814
|
+
this.config = {
|
|
1815
|
+
debug: config.debug ?? false,
|
|
1816
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
1817
|
+
manifest: config.manifest
|
|
1818
|
+
};
|
|
1819
|
+
this.storage = new StorageAPI(this);
|
|
1820
|
+
this.database = new DatabaseAPI(this);
|
|
1821
|
+
this.filesystem = new FilesystemAPI(this);
|
|
1822
|
+
this.web = new WebAPI(this);
|
|
1823
|
+
this.permissions = new PermissionsAPI(this);
|
|
1824
|
+
installConsoleForwarding(this.config.debug);
|
|
1825
|
+
this.readyPromise = new Promise((resolve) => {
|
|
1826
|
+
this.resolveReady = resolve;
|
|
1827
|
+
});
|
|
1828
|
+
this.init();
|
|
1829
|
+
}
|
|
1830
|
+
// ==========================================================================
|
|
1831
|
+
// Lifecycle
|
|
1832
|
+
// ==========================================================================
|
|
1833
|
+
async ready() {
|
|
1834
|
+
return this.readyPromise;
|
|
1835
|
+
}
|
|
1836
|
+
get setupCompleted() {
|
|
1837
|
+
return this._setupCompleted;
|
|
1838
|
+
}
|
|
1839
|
+
onSetup(setupFn) {
|
|
1840
|
+
if (this.setupHook) {
|
|
1841
|
+
throw new Error("Setup hook already registered");
|
|
1664
1842
|
}
|
|
1665
|
-
this.
|
|
1666
|
-
}
|
|
1667
|
-
async
|
|
1668
|
-
this.
|
|
1669
|
-
|
|
1670
|
-
if (!handler) {
|
|
1671
|
-
this.log(`[ExternalRequest] No handler for action: ${request.action}`);
|
|
1672
|
-
await this.respondToExternalRequest({
|
|
1673
|
-
requestId: request.requestId,
|
|
1674
|
-
success: false,
|
|
1675
|
-
error: `No handler registered for action: ${request.action}`
|
|
1676
|
-
});
|
|
1843
|
+
this.setupHook = setupFn;
|
|
1844
|
+
}
|
|
1845
|
+
async setupComplete() {
|
|
1846
|
+
await this.readyPromise;
|
|
1847
|
+
if (!this.setupHook || this.setupCompleted) {
|
|
1677
1848
|
return;
|
|
1678
1849
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
await this.respondToExternalRequest(response);
|
|
1682
|
-
this.log(`[ExternalRequest] Response sent for: ${request.action}`);
|
|
1683
|
-
} catch (error) {
|
|
1684
|
-
this.log(`[ExternalRequest] Handler error:`, error);
|
|
1685
|
-
await this.respondToExternalRequest({
|
|
1686
|
-
requestId: request.requestId,
|
|
1687
|
-
success: false,
|
|
1688
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1689
|
-
});
|
|
1850
|
+
if (!this.setupPromise) {
|
|
1851
|
+
this.setupPromise = this.runSetupAsync();
|
|
1690
1852
|
}
|
|
1853
|
+
return this.setupPromise;
|
|
1691
1854
|
}
|
|
1692
|
-
|
|
1693
|
-
this.
|
|
1694
|
-
|
|
1695
|
-
if (listeners) {
|
|
1696
|
-
listeners.forEach((callback) => callback(event));
|
|
1855
|
+
destroy() {
|
|
1856
|
+
if (this.messageHandler) {
|
|
1857
|
+
window.removeEventListener("message", this.messageHandler);
|
|
1697
1858
|
}
|
|
1859
|
+
this.pendingRequests.forEach(({ timeout }) => clearTimeout(timeout));
|
|
1860
|
+
this.pendingRequests.clear();
|
|
1861
|
+
this.eventListeners.clear();
|
|
1862
|
+
this.initialized = false;
|
|
1863
|
+
this.log("HaexVault SDK destroyed");
|
|
1698
1864
|
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1865
|
+
// ==========================================================================
|
|
1866
|
+
// Properties
|
|
1867
|
+
// ==========================================================================
|
|
1868
|
+
get extensionInfo() {
|
|
1869
|
+
return this._extensionInfo;
|
|
1701
1870
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
throw new HaexHubError(
|
|
1705
|
-
"INVALID_PUBLIC_KEY" /* INVALID_PUBLIC_KEY */,
|
|
1706
|
-
"errors.invalid_public_key",
|
|
1707
|
-
{ publicKey }
|
|
1708
|
-
);
|
|
1709
|
-
}
|
|
1871
|
+
get context() {
|
|
1872
|
+
return this._context;
|
|
1710
1873
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
);
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1874
|
+
// ==========================================================================
|
|
1875
|
+
// Subscriptions
|
|
1876
|
+
// ==========================================================================
|
|
1877
|
+
subscribe(callback) {
|
|
1878
|
+
this.reactiveSubscribers.add(callback);
|
|
1879
|
+
return () => {
|
|
1880
|
+
this.reactiveSubscribers.delete(callback);
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
// ==========================================================================
|
|
1884
|
+
// Table Name Utilities
|
|
1885
|
+
// ==========================================================================
|
|
1886
|
+
getTableName(tableName) {
|
|
1887
|
+
return getExtensionTableName(this._extensionInfo, tableName);
|
|
1888
|
+
}
|
|
1889
|
+
getDependencyTableName(publicKey, extensionName, tableName) {
|
|
1890
|
+
return getDependencyTableName(publicKey, extensionName, tableName);
|
|
1891
|
+
}
|
|
1892
|
+
parseTableName(fullTableName) {
|
|
1893
|
+
return parseTableName(fullTableName);
|
|
1894
|
+
}
|
|
1895
|
+
// ==========================================================================
|
|
1896
|
+
// Database
|
|
1897
|
+
// ==========================================================================
|
|
1898
|
+
initializeDatabase(schema) {
|
|
1899
|
+
const db = createDrizzleInstance(schema, this._extensionInfo, this.request.bind(this), this.log.bind(this));
|
|
1900
|
+
this.orm = db;
|
|
1901
|
+
return db;
|
|
1902
|
+
}
|
|
1903
|
+
async query(sql, params = []) {
|
|
1904
|
+
return queryRaw(sql, params, this.request.bind(this), this.config.debug);
|
|
1905
|
+
}
|
|
1906
|
+
async select(sql, params = []) {
|
|
1907
|
+
return this.query(sql, params);
|
|
1908
|
+
}
|
|
1909
|
+
async execute(sql, params = []) {
|
|
1910
|
+
return executeRaw(sql, params, this.request.bind(this));
|
|
1911
|
+
}
|
|
1912
|
+
async registerMigrationsAsync(extensionVersion, migrations) {
|
|
1913
|
+
return this.database.registerMigrationsAsync(extensionVersion, migrations);
|
|
1914
|
+
}
|
|
1915
|
+
// ==========================================================================
|
|
1916
|
+
// Dependencies
|
|
1917
|
+
// ==========================================================================
|
|
1918
|
+
async getDependencies() {
|
|
1919
|
+
return this.request("extensions.getDependencies");
|
|
1920
|
+
}
|
|
1921
|
+
// ==========================================================================
|
|
1922
|
+
// Permissions
|
|
1923
|
+
// ==========================================================================
|
|
1924
|
+
async requestDatabasePermission(request) {
|
|
1925
|
+
return this.request("permissions.database.request", {
|
|
1926
|
+
resource: request.resource,
|
|
1927
|
+
operation: request.operation,
|
|
1928
|
+
reason: request.reason
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
async checkDatabasePermission(resource, operation) {
|
|
1932
|
+
const response = await this.request("permissions.database.check", { resource, operation });
|
|
1933
|
+
return response.status === "granted";
|
|
1934
|
+
}
|
|
1935
|
+
// ==========================================================================
|
|
1936
|
+
// Search
|
|
1937
|
+
// ==========================================================================
|
|
1938
|
+
async respondToSearch(requestId, results) {
|
|
1939
|
+
await this.request("search.respond", { requestId, results });
|
|
1940
|
+
}
|
|
1941
|
+
// ==========================================================================
|
|
1942
|
+
// External Requests
|
|
1943
|
+
// ==========================================================================
|
|
1944
|
+
onExternalRequest(action, handler) {
|
|
1945
|
+
return registerExternalHandler(action, handler, this.externalRequestHandlers, this.log.bind(this));
|
|
1946
|
+
}
|
|
1947
|
+
async respondToExternalRequest(response) {
|
|
1948
|
+
await respondToExternalRequest(response, this.request.bind(this));
|
|
1949
|
+
}
|
|
1950
|
+
// ==========================================================================
|
|
1951
|
+
// Events
|
|
1952
|
+
// ==========================================================================
|
|
1953
|
+
on(eventType, callback) {
|
|
1954
|
+
addEventListener(eventType, callback, this.eventListeners);
|
|
1955
|
+
}
|
|
1956
|
+
off(eventType, callback) {
|
|
1957
|
+
removeEventListener(eventType, callback, this.eventListeners);
|
|
1958
|
+
}
|
|
1959
|
+
// ==========================================================================
|
|
1960
|
+
// Communication
|
|
1961
|
+
// ==========================================================================
|
|
1962
|
+
async request(method, params) {
|
|
1963
|
+
const resolvedParams = params ?? {};
|
|
1964
|
+
if (this.isNativeWindow && hasTauri()) {
|
|
1965
|
+
return sendInvoke(method, resolvedParams, this.config, this.log.bind(this));
|
|
1725
1966
|
}
|
|
1967
|
+
const requestId = generateRequestId(++this.requestCounter);
|
|
1968
|
+
return sendPostMessage(method, resolvedParams, requestId, this.config, this._extensionInfo, this.pendingRequests);
|
|
1726
1969
|
}
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1970
|
+
// ==========================================================================
|
|
1971
|
+
// Private: Initialization
|
|
1972
|
+
// ==========================================================================
|
|
1973
|
+
async init() {
|
|
1974
|
+
if (this.initialized) return;
|
|
1975
|
+
if (!isInIframe() && hasTauri()) {
|
|
1976
|
+
try {
|
|
1977
|
+
await this.initNative();
|
|
1978
|
+
return;
|
|
1979
|
+
} catch (error) {
|
|
1980
|
+
this.log("Tauri commands failed, falling back to iframe mode", error);
|
|
1981
|
+
}
|
|
1733
1982
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1983
|
+
await this.initIframe();
|
|
1984
|
+
}
|
|
1985
|
+
async initNative() {
|
|
1986
|
+
const { extensionInfo, context } = await initNativeMode(
|
|
1987
|
+
{
|
|
1988
|
+
config: this.config,
|
|
1989
|
+
state: {
|
|
1990
|
+
initialized: this.initialized,
|
|
1991
|
+
isNativeWindow: this.isNativeWindow,
|
|
1992
|
+
requestCounter: this.requestCounter,
|
|
1993
|
+
setupCompleted: this._setupCompleted,
|
|
1994
|
+
extensionInfo: this._extensionInfo,
|
|
1995
|
+
context: this._context,
|
|
1996
|
+
orm: this.orm
|
|
1997
|
+
},
|
|
1998
|
+
collections: {
|
|
1999
|
+
pendingRequests: this.pendingRequests,
|
|
2000
|
+
eventListeners: this.eventListeners,
|
|
2001
|
+
externalRequestHandlers: this.externalRequestHandlers,
|
|
2002
|
+
reactiveSubscribers: this.reactiveSubscribers
|
|
2003
|
+
},
|
|
2004
|
+
promises: {
|
|
2005
|
+
readyPromise: this.readyPromise,
|
|
2006
|
+
resolveReady: this.resolveReady,
|
|
2007
|
+
setupPromise: this.setupPromise,
|
|
2008
|
+
setupHook: this.setupHook
|
|
2009
|
+
},
|
|
2010
|
+
handlers: {
|
|
2011
|
+
messageHandler: this.messageHandler
|
|
2012
|
+
}
|
|
2013
|
+
},
|
|
2014
|
+
this.log.bind(this),
|
|
2015
|
+
this.handleEvent.bind(this),
|
|
2016
|
+
(ctx) => {
|
|
2017
|
+
this._context = ctx;
|
|
2018
|
+
this.notifySubscribersInternal();
|
|
2019
|
+
}
|
|
2020
|
+
);
|
|
2021
|
+
this._extensionInfo = extensionInfo;
|
|
2022
|
+
this._context = context;
|
|
2023
|
+
this.isNativeWindow = true;
|
|
2024
|
+
this.initialized = true;
|
|
2025
|
+
this.notifySubscribersInternal();
|
|
2026
|
+
this.resolveReady();
|
|
2027
|
+
}
|
|
2028
|
+
async initIframe() {
|
|
2029
|
+
this.messageHandler = createMessageHandler(
|
|
2030
|
+
this.config,
|
|
2031
|
+
this.pendingRequests,
|
|
2032
|
+
() => this._extensionInfo,
|
|
2033
|
+
this.handleEvent.bind(this)
|
|
2034
|
+
);
|
|
2035
|
+
const { context } = await initIframeMode(
|
|
2036
|
+
{
|
|
2037
|
+
config: this.config,
|
|
2038
|
+
state: {
|
|
2039
|
+
initialized: this.initialized,
|
|
2040
|
+
isNativeWindow: this.isNativeWindow,
|
|
2041
|
+
requestCounter: this.requestCounter,
|
|
2042
|
+
setupCompleted: this._setupCompleted,
|
|
2043
|
+
extensionInfo: this._extensionInfo,
|
|
2044
|
+
context: this._context,
|
|
2045
|
+
orm: this.orm
|
|
2046
|
+
},
|
|
2047
|
+
collections: {
|
|
2048
|
+
pendingRequests: this.pendingRequests,
|
|
2049
|
+
eventListeners: this.eventListeners,
|
|
2050
|
+
externalRequestHandlers: this.externalRequestHandlers,
|
|
2051
|
+
reactiveSubscribers: this.reactiveSubscribers
|
|
2052
|
+
},
|
|
2053
|
+
promises: {
|
|
2054
|
+
readyPromise: this.readyPromise,
|
|
2055
|
+
resolveReady: this.resolveReady,
|
|
2056
|
+
setupPromise: this.setupPromise,
|
|
2057
|
+
setupHook: this.setupHook
|
|
2058
|
+
},
|
|
2059
|
+
handlers: {
|
|
2060
|
+
messageHandler: this.messageHandler
|
|
2061
|
+
}
|
|
2062
|
+
},
|
|
2063
|
+
this.log.bind(this),
|
|
2064
|
+
this.messageHandler,
|
|
2065
|
+
this.request.bind(this)
|
|
2066
|
+
);
|
|
2067
|
+
if (this.config.manifest) {
|
|
2068
|
+
this._extensionInfo = {
|
|
2069
|
+
publicKey: this.config.manifest.publicKey,
|
|
2070
|
+
name: this.config.manifest.name,
|
|
2071
|
+
version: this.config.manifest.version,
|
|
2072
|
+
displayName: this.config.manifest.name
|
|
2073
|
+
};
|
|
2074
|
+
this.notifySubscribersInternal();
|
|
1740
2075
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
2076
|
+
this._context = context;
|
|
2077
|
+
this.isNativeWindow = false;
|
|
2078
|
+
this.initialized = true;
|
|
2079
|
+
this.notifySubscribersInternal();
|
|
2080
|
+
this.resolveReady();
|
|
2081
|
+
}
|
|
2082
|
+
// ==========================================================================
|
|
2083
|
+
// Private: Event Handling
|
|
2084
|
+
// ==========================================================================
|
|
2085
|
+
handleEvent(event) {
|
|
2086
|
+
processEvent(
|
|
2087
|
+
event,
|
|
2088
|
+
this.log.bind(this),
|
|
2089
|
+
this.eventListeners,
|
|
2090
|
+
(ctx) => {
|
|
2091
|
+
this._context = ctx;
|
|
2092
|
+
this.notifySubscribersInternal();
|
|
2093
|
+
},
|
|
2094
|
+
(extEvent) => this.handleExternalRequestInternal(extEvent.data)
|
|
2095
|
+
);
|
|
2096
|
+
}
|
|
2097
|
+
async handleExternalRequestInternal(request) {
|
|
2098
|
+
await handleExternalRequest(request, this.externalRequestHandlers, this.respondToExternalRequest.bind(this), this.log.bind(this));
|
|
2099
|
+
}
|
|
2100
|
+
// ==========================================================================
|
|
2101
|
+
// Private: Setup
|
|
2102
|
+
// ==========================================================================
|
|
2103
|
+
async runSetupAsync() {
|
|
2104
|
+
if (!this.setupHook) return;
|
|
2105
|
+
try {
|
|
2106
|
+
this.log("[HaexVault] Running setup hook...");
|
|
2107
|
+
await this.setupHook();
|
|
2108
|
+
this._setupCompleted = true;
|
|
2109
|
+
this.log("[HaexVault] Setup completed successfully");
|
|
2110
|
+
this.notifySubscribersInternal();
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
this.log("[HaexVault] Setup failed:", error);
|
|
2113
|
+
throw error;
|
|
1747
2114
|
}
|
|
1748
2115
|
}
|
|
2116
|
+
// ==========================================================================
|
|
2117
|
+
// Private: Utilities
|
|
2118
|
+
// ==========================================================================
|
|
2119
|
+
notifySubscribersInternal() {
|
|
2120
|
+
notifySubscribers(this.reactiveSubscribers);
|
|
2121
|
+
}
|
|
1749
2122
|
log(...args) {
|
|
1750
2123
|
if (this.config.debug) {
|
|
1751
|
-
console.log("[
|
|
2124
|
+
console.log("[HaexVault SDK]", ...args);
|
|
1752
2125
|
}
|
|
1753
2126
|
}
|
|
1754
2127
|
};
|
|
@@ -1980,6 +2353,42 @@ async function encryptCrdtData(data, vaultKey) {
|
|
|
1980
2353
|
nonce: arrayBufferToBase64(nonce)
|
|
1981
2354
|
};
|
|
1982
2355
|
}
|
|
2356
|
+
async function wrapKey(keyToWrap, wrappingKey) {
|
|
2357
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
2358
|
+
"raw",
|
|
2359
|
+
new Uint8Array(wrappingKey),
|
|
2360
|
+
{ name: ALGORITHM },
|
|
2361
|
+
false,
|
|
2362
|
+
["encrypt"]
|
|
2363
|
+
);
|
|
2364
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2365
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
2366
|
+
{ name: ALGORITHM, iv: nonce },
|
|
2367
|
+
cryptoKey,
|
|
2368
|
+
new Uint8Array(keyToWrap)
|
|
2369
|
+
);
|
|
2370
|
+
const result = new Uint8Array(12 + ciphertext.byteLength);
|
|
2371
|
+
result.set(nonce, 0);
|
|
2372
|
+
result.set(new Uint8Array(ciphertext), 12);
|
|
2373
|
+
return result;
|
|
2374
|
+
}
|
|
2375
|
+
async function unwrapKey(wrappedKey, wrappingKey) {
|
|
2376
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
2377
|
+
"raw",
|
|
2378
|
+
new Uint8Array(wrappingKey),
|
|
2379
|
+
{ name: ALGORITHM },
|
|
2380
|
+
false,
|
|
2381
|
+
["decrypt"]
|
|
2382
|
+
);
|
|
2383
|
+
const nonce = wrappedKey.slice(0, 12);
|
|
2384
|
+
const ciphertext = wrappedKey.slice(12);
|
|
2385
|
+
const plaintext = await crypto.subtle.decrypt(
|
|
2386
|
+
{ name: ALGORITHM, iv: nonce },
|
|
2387
|
+
cryptoKey,
|
|
2388
|
+
ciphertext
|
|
2389
|
+
);
|
|
2390
|
+
return new Uint8Array(plaintext);
|
|
2391
|
+
}
|
|
1983
2392
|
async function decryptCrdtData(encryptedData, nonce, vaultKey) {
|
|
1984
2393
|
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
1985
2394
|
const cryptoKey = await crypto.subtle.importKey(
|
|
@@ -2044,11 +2453,12 @@ exports.FilesystemAPI = FilesystemAPI;
|
|
|
2044
2453
|
exports.HAEXSPACE_MESSAGE_TYPES = HAEXSPACE_MESSAGE_TYPES;
|
|
2045
2454
|
exports.HAEXTENSION_EVENTS = HAEXTENSION_EVENTS;
|
|
2046
2455
|
exports.HAEXTENSION_METHODS = HAEXTENSION_METHODS;
|
|
2047
|
-
exports.HaexHubError = HaexHubError;
|
|
2048
2456
|
exports.HaexVaultClient = HaexVaultClient;
|
|
2457
|
+
exports.HaexVaultSdkError = HaexVaultSdkError;
|
|
2049
2458
|
exports.PermissionStatus = PermissionStatus;
|
|
2050
2459
|
exports.PermissionsAPI = PermissionsAPI;
|
|
2051
2460
|
exports.TABLE_SEPARATOR = TABLE_SEPARATOR;
|
|
2461
|
+
exports.TAURI_COMMANDS = TAURI_COMMANDS;
|
|
2052
2462
|
exports.WebAPI = WebAPI;
|
|
2053
2463
|
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
2054
2464
|
exports.base64ToArrayBuffer = base64ToArrayBuffer;
|
|
@@ -2071,6 +2481,8 @@ exports.installLocalStoragePolyfill = installLocalStoragePolyfill;
|
|
|
2071
2481
|
exports.installPolyfills = installPolyfills;
|
|
2072
2482
|
exports.installSessionStoragePolyfill = installSessionStoragePolyfill;
|
|
2073
2483
|
exports.sortObjectKeysRecursively = sortObjectKeysRecursively;
|
|
2484
|
+
exports.unwrapKey = unwrapKey;
|
|
2074
2485
|
exports.verifyExtensionSignature = verifyExtensionSignature;
|
|
2486
|
+
exports.wrapKey = wrapKey;
|
|
2075
2487
|
//# sourceMappingURL=index.js.map
|
|
2076
2488
|
//# sourceMappingURL=index.js.map
|