@haex-space/vault-sdk 2.2.7 → 2.3.1

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/index.d.ts CHANGED
@@ -6,14 +6,14 @@ export { H as HaextensionConfig } from './config-D_HXjsEV.js';
6
6
  import 'drizzle-orm/sqlite-proxy';
7
7
 
8
8
  /**
9
- * localStorage Polyfill for HaexHub Extensions
9
+ * localStorage Polyfill for HaexSpace Extensions
10
10
  *
11
11
  * Provides an in-memory fallback when localStorage is blocked
12
12
  * due to custom protocol restrictions (haex-extension://)
13
13
  */
14
14
  declare function installLocalStoragePolyfill(): void;
15
15
  /**
16
- * sessionStorage Polyfill for HaexHub Extensions
16
+ * sessionStorage Polyfill for HaexSpace Extensions
17
17
  *
18
18
  * Provides a no-op implementation as session state doesn't work
19
19
  * reliably in custom protocol contexts
@@ -21,7 +21,7 @@ declare function installLocalStoragePolyfill(): void;
21
21
  declare function installSessionStoragePolyfill(): void;
22
22
 
23
23
  /**
24
- * Cookie Polyfill for HaexHub Extensions
24
+ * Cookie Polyfill for HaexSpace Extensions
25
25
  *
26
26
  * Provides an in-memory cookie implementation when cookies are blocked
27
27
  * due to custom protocol restrictions (haex-extension://)
@@ -29,7 +29,7 @@ declare function installSessionStoragePolyfill(): void;
29
29
  declare function installCookiePolyfill(): void;
30
30
 
31
31
  /**
32
- * History API Polyfill for HaexHub Extensions
32
+ * History API Polyfill for HaexSpace Extensions
33
33
  *
34
34
  * Works around SecurityError when using pushState/replaceState
35
35
  * in custom protocol contexts (haex-extension://)
@@ -54,7 +54,7 @@ declare global {
54
54
  declare function installBaseTag(): void;
55
55
 
56
56
  /**
57
- * HaexHub Extension Polyfills
57
+ * HaexSpace Extension Polyfills
58
58
  *
59
59
  * Auto-initializing polyfills for localStorage, cookies, and history API
60
60
  * that work around restrictions in custom protocol contexts (haex-extension://)
@@ -69,13 +69,13 @@ declare function installBaseTag(): void;
69
69
  * You can also install them manually:
70
70
  *
71
71
  * ```typescript
72
- * import { installPolyfills } from '@haexhub/sdk/polyfills';
72
+ * import { installPolyfills } from '@haex-space/vault-sdk/polyfills';
73
73
  * installPolyfills();
74
74
  * ```
75
75
  */
76
76
 
77
77
  /**
78
- * Install all HaexHub polyfills
78
+ * Install all HaexSpace polyfills
79
79
  *
80
80
  * This function is called automatically when the SDK is imported.
81
81
  * You usually don't need to call this manually.
@@ -121,6 +121,21 @@ declare const HAEXTENSION_METHODS: {
121
121
  type DeepValues<T> = T extends object ? T[keyof T] extends string ? T[keyof T] : T[keyof T] extends object ? DeepValues<T[keyof T]> : never : never;
122
122
  type HaextensionMethod = DeepValues<typeof HAEXTENSION_METHODS>;
123
123
 
124
+ /**
125
+ * Central message type definitions for HaexSpace SDK
126
+ *
127
+ * Message Naming Schema: haexspace:{subject}
128
+ *
129
+ * These are used for internal communication between extensions and HaexSpace
130
+ */
131
+ declare const HAEXSPACE_MESSAGE_TYPES: {
132
+ /** Debug message for development/troubleshooting */
133
+ readonly DEBUG: "haexspace:debug";
134
+ /** Console forwarding from extension iframe */
135
+ readonly CONSOLE_FORWARD: "console.forward";
136
+ };
137
+ type HaexspaceMessageType = (typeof HAEXSPACE_MESSAGE_TYPES)[keyof typeof HAEXSPACE_MESSAGE_TYPES];
138
+
124
139
  declare function createHaexVaultClient(config?: HaexHubConfig): HaexVaultClient;
125
140
 
126
- export { HAEXTENSION_METHODS, HaexHubConfig, HaexVaultClient, type HaextensionMethod, createHaexVaultClient, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill };
141
+ export { HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_METHODS, HaexHubConfig, HaexVaultClient, type HaexspaceMessageType, type HaextensionMethod, createHaexVaultClient, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ function installLocalStoragePolyfill() {
7
7
  if (typeof window === "undefined") {
8
8
  return;
9
9
  }
10
- console.log("[HaexHub] Storage Polyfill loading immediately");
10
+ console.log("[HaexSpace] Storage Polyfill loading immediately");
11
11
  let localStorageWorks = false;
12
12
  try {
13
13
  const testKey = "__ls_test__";
@@ -15,7 +15,7 @@ function installLocalStoragePolyfill() {
15
15
  localStorage.removeItem(testKey);
16
16
  localStorageWorks = true;
17
17
  } catch (e) {
18
- console.warn("[HaexHub] localStorage blocked \u2013 using in-memory fallback");
18
+ console.warn("[HaexSpace] localStorage blocked \u2013 using in-memory fallback");
19
19
  }
20
20
  if (!localStorageWorks) {
21
21
  const lsStorage = /* @__PURE__ */ new Map();
@@ -48,7 +48,7 @@ function installLocalStoragePolyfill() {
48
48
  } catch (e) {
49
49
  window.localStorage = localStoragePoly;
50
50
  }
51
- console.log("[HaexHub] localStorage replaced with in-memory polyfill");
51
+ console.log("[HaexSpace] localStorage replaced with in-memory polyfill");
52
52
  }
53
53
  }
54
54
  function installSessionStoragePolyfill() {
@@ -93,7 +93,7 @@ function installSessionStoragePolyfill() {
93
93
  key: () => null
94
94
  };
95
95
  }
96
- console.log("[HaexHub] sessionStorage polyfill installed");
96
+ console.log("[HaexSpace] sessionStorage polyfill installed");
97
97
  }
98
98
 
99
99
  // src/polyfills/cookies.ts
@@ -106,7 +106,7 @@ function installCookiePolyfill() {
106
106
  document.cookie = "__cookie_test__=1";
107
107
  cookiesWork = document.cookie.indexOf("__cookie_test__") !== -1;
108
108
  } catch (e) {
109
- console.warn("[HaexHub] Cookies blocked \u2013 using in-memory fallback");
109
+ console.warn("[HaexSpace] Cookies blocked \u2013 using in-memory fallback");
110
110
  }
111
111
  if (!cookiesWork) {
112
112
  const cookieStore = /* @__PURE__ */ new Map();
@@ -152,7 +152,7 @@ function installCookiePolyfill() {
152
152
  },
153
153
  configurable: true
154
154
  });
155
- console.log("[HaexHub] Cookie polyfill installed");
155
+ console.log("[HaexSpace] Cookie polyfill installed");
156
156
  }
157
157
  }
158
158
 
@@ -162,16 +162,16 @@ function installHistoryPolyfill() {
162
162
  return;
163
163
  }
164
164
  const install = () => {
165
- console.log("[HaexHub] History Patch loading");
165
+ console.log("[HaexSpace] History Patch loading");
166
166
  const originalPushState = history.pushState;
167
167
  const originalReplaceState = history.replaceState;
168
168
  let skipNextPush = false;
169
169
  let skipNextReplace = false;
170
170
  history.pushState = function(state, title, url) {
171
- console.log("[HaexHub] pushState called:", url, "skip:", skipNextPush);
171
+ console.log("[HaexSpace] pushState called:", url, "skip:", skipNextPush);
172
172
  if (skipNextPush) {
173
173
  skipNextPush = false;
174
- console.log("[HaexHub] pushState skipped");
174
+ console.log("[HaexSpace] pushState skipped");
175
175
  return;
176
176
  }
177
177
  try {
@@ -181,7 +181,7 @@ function installHistoryPolyfill() {
181
181
  const urlString = url.toString();
182
182
  let hashUrl = urlString.replace(/^\/#/, "");
183
183
  hashUrl = hashUrl.startsWith("#") ? hashUrl : "#" + hashUrl;
184
- console.log("[HaexHub] SecurityError - setting hash to:", hashUrl);
184
+ console.log("[HaexSpace] SecurityError - setting hash to:", hashUrl);
185
185
  skipNextPush = true;
186
186
  window.location.hash = hashUrl.replace(/^#/, "");
187
187
  return;
@@ -190,10 +190,10 @@ function installHistoryPolyfill() {
190
190
  }
191
191
  };
192
192
  history.replaceState = function(state, title, url) {
193
- console.log("[HaexHub] replaceState called:", url, "skip:", skipNextReplace);
193
+ console.log("[HaexSpace] replaceState called:", url, "skip:", skipNextReplace);
194
194
  if (skipNextReplace) {
195
195
  skipNextReplace = false;
196
- console.log("[HaexHub] replaceState skipped");
196
+ console.log("[HaexSpace] replaceState skipped");
197
197
  return;
198
198
  }
199
199
  try {
@@ -203,7 +203,7 @@ function installHistoryPolyfill() {
203
203
  const urlString = url.toString();
204
204
  let hashUrl = urlString.replace(/^\/#/, "");
205
205
  hashUrl = hashUrl.startsWith("#") ? hashUrl : "#" + hashUrl;
206
- console.log("[HaexHub] SecurityError - setting hash to:", hashUrl);
206
+ console.log("[HaexSpace] SecurityError - setting hash to:", hashUrl);
207
207
  skipNextReplace = true;
208
208
  window.location.hash = hashUrl.replace(/^#/, "");
209
209
  return;
@@ -211,7 +211,7 @@ function installHistoryPolyfill() {
211
211
  throw e;
212
212
  }
213
213
  };
214
- console.log("[HaexHub] History API patched");
214
+ console.log("[HaexSpace] History API patched");
215
215
  };
216
216
  if (document.readyState === "loading") {
217
217
  document.addEventListener("DOMContentLoaded", install, { once: true });
@@ -220,22 +220,30 @@ function installHistoryPolyfill() {
220
220
  }
221
221
  }
222
222
 
223
+ // src/messages.ts
224
+ var HAEXSPACE_MESSAGE_TYPES = {
225
+ /** Debug message for development/troubleshooting */
226
+ DEBUG: "haexspace:debug",
227
+ /** Console forwarding from extension iframe */
228
+ CONSOLE_FORWARD: "console.forward"
229
+ };
230
+
223
231
  // src/polyfills/debug.ts
224
232
  function installDebugDiagnostics() {
225
233
  if (typeof window === "undefined") {
226
234
  return;
227
235
  }
228
236
  const hasParent = window.parent && window.parent !== window;
229
- console.log("[HaexHub] hasParent:", hasParent);
237
+ console.log("[HaexSpace] hasParent:", hasParent);
230
238
  if (hasParent) {
231
- console.log("[HaexHub] Attempting to send debug message to parent...");
239
+ console.log("[HaexSpace] Attempting to send debug message to parent...");
232
240
  window.parent.postMessage({
233
- type: "haexhub:debug",
241
+ type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
234
242
  data: `[Polyfills] window.parent test: exists=${!!window.parent}, different=${hasParent}, selfIsTop=${window.self === window.top}`
235
243
  }, "*");
236
- console.log("[HaexHub] Debug message sent!");
244
+ console.log("[HaexSpace] Debug message sent!");
237
245
  } else {
238
- console.log("[HaexHub] No parent window or parent === window");
246
+ console.log("[HaexSpace] No parent window or parent === window");
239
247
  }
240
248
  }
241
249
 
@@ -245,27 +253,27 @@ function installBaseTag() {
245
253
  return;
246
254
  }
247
255
  if (window.__HAEXHUB_BASE_TAG_INSTALLING__) {
248
- console.log("[HaexHub] Base tag installation already in progress, skipping");
256
+ console.log("[HaexSpace] Base tag installation already in progress, skipping");
249
257
  return;
250
258
  }
251
- console.log("[HaexHub] Base tag installation starting");
259
+ console.log("[HaexSpace] Base tag installation starting");
252
260
  if (window.self === window.top) {
253
- console.log("[HaexHub] Not in iframe, skipping base tag");
261
+ console.log("[HaexSpace] Not in iframe, skipping base tag");
254
262
  return;
255
263
  }
256
264
  const existingBaseTag = document.querySelector("base#haexhub-base");
257
265
  if (existingBaseTag && existingBaseTag.href && existingBaseTag.href !== window.location.origin + "/") {
258
- console.log("[HaexHub] Base tag already configured, skipping");
266
+ console.log("[HaexSpace] Base tag already configured, skipping");
259
267
  return;
260
268
  }
261
269
  window.__HAEXHUB_BASE_TAG_INSTALLING__ = true;
262
270
  const pathname = window.location.pathname;
263
271
  const lastSlashIndex = pathname.lastIndexOf("/");
264
272
  const basePath = lastSlashIndex !== -1 ? pathname.substring(0, lastSlashIndex + 1) : "/";
265
- console.log("[HaexHub] Extracted base path from location:", basePath);
273
+ console.log("[HaexSpace] Extracted base path from location:", basePath);
266
274
  if (existingBaseTag) {
267
275
  existingBaseTag.href = basePath;
268
- console.log(`[HaexHub] Base tag updated: ${existingBaseTag.href}`);
276
+ console.log(`[HaexSpace] Base tag updated: ${existingBaseTag.href}`);
269
277
  } else {
270
278
  const baseTag = document.createElement("base");
271
279
  baseTag.id = "haexhub-base";
@@ -273,9 +281,9 @@ function installBaseTag() {
273
281
  const head = document.head || document.querySelector("head");
274
282
  if (head) {
275
283
  head.insertBefore(baseTag, head.firstChild);
276
- console.log(`[HaexHub] Base tag created: ${baseTag.href}`);
284
+ console.log(`[HaexSpace] Base tag created: ${baseTag.href}`);
277
285
  } else {
278
- console.warn("[HaexHub] No <head> found, cannot inject base tag");
286
+ console.warn("[HaexSpace] No <head> found, cannot inject base tag");
279
287
  }
280
288
  }
281
289
  }
@@ -311,7 +319,7 @@ function interceptConsole(level) {
311
319
  const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
312
320
  window.parent.postMessage(
313
321
  {
314
- type: "console.forward",
322
+ type: HAEXSPACE_MESSAGE_TYPES.CONSOLE_FORWARD,
315
323
  data: {
316
324
  timestamp,
317
325
  level,
@@ -322,7 +330,7 @@ function interceptConsole(level) {
322
330
  "*"
323
331
  );
324
332
  } catch (error) {
325
- originalConsole.error("[HaexHub] Failed to forward console message:", error);
333
+ originalConsole.error("[HaexSpace] Failed to forward console message:", error);
326
334
  }
327
335
  }
328
336
  };
@@ -335,7 +343,7 @@ function installConsoleForwarding(debug = false) {
335
343
  return;
336
344
  }
337
345
  if (!debug) {
338
- console.log("[HaexHub] Console forwarding disabled (not in debug mode)");
346
+ console.log("[HaexSpace] Console forwarding disabled (not in debug mode)");
339
347
  return;
340
348
  }
341
349
  interceptConsole("log");
@@ -343,7 +351,7 @@ function installConsoleForwarding(debug = false) {
343
351
  interceptConsole("warn");
344
352
  interceptConsole("error");
345
353
  interceptConsole("debug");
346
- console.log("[HaexHub] Console forwarding installed");
354
+ console.log("[HaexSpace] Console forwarding installed");
347
355
  }
348
356
 
349
357
  // src/polyfills/index.ts
@@ -355,7 +363,7 @@ function installPolyfills() {
355
363
  installSessionStoragePolyfill();
356
364
  installCookiePolyfill();
357
365
  installHistoryPolyfill();
358
- console.log("[HaexHub] All polyfills loaded successfully");
366
+ console.log("[HaexSpace] All polyfills loaded successfully");
359
367
  installDebugDiagnostics();
360
368
  }
361
369
  if (typeof window !== "undefined") {
@@ -880,13 +888,13 @@ var HaexVaultClient = class {
880
888
  async runSetupAsync() {
881
889
  if (!this.setupHook) return;
882
890
  try {
883
- this.log("[HaexHub] Running setup hook...");
891
+ this.log("[HaexSpace] Running setup hook...");
884
892
  await this.setupHook();
885
893
  this._setupCompleted = true;
886
- this.log("[HaexHub] Setup completed successfully");
894
+ this.log("[HaexSpace] Setup completed successfully");
887
895
  this.notifySubscribers();
888
896
  } catch (error) {
889
- this.log("[HaexHub] Setup failed:", error);
897
+ this.log("[HaexSpace] Setup failed:", error);
890
898
  throw error;
891
899
  }
892
900
  }
@@ -1215,26 +1223,26 @@ var HaexVaultClient = class {
1215
1223
  this.log("Application context:", this._context);
1216
1224
  this.notifySubscribers();
1217
1225
  const { listen } = window.__TAURI__.event;
1218
- console.log("[HaexHub SDK] Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
1226
+ console.log("[HaexSpace SDK] Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
1219
1227
  try {
1220
1228
  await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
1221
- console.log("[HaexHub SDK] Received Tauri event:", HAEXTENSION_EVENTS.CONTEXT_CHANGED, event);
1229
+ console.log("[HaexSpace SDK] Received Tauri event:", HAEXTENSION_EVENTS.CONTEXT_CHANGED, event);
1222
1230
  this.log("Received context change event:", event);
1223
1231
  if (event.payload?.context) {
1224
1232
  this._context = event.payload.context;
1225
- console.log("[HaexHub SDK] Updated context to:", this._context);
1233
+ console.log("[HaexSpace SDK] Updated context to:", this._context);
1226
1234
  this.handleEvent({
1227
1235
  type: HAEXTENSION_EVENTS.CONTEXT_CHANGED,
1228
1236
  data: { context: this._context },
1229
1237
  timestamp: Date.now()
1230
1238
  });
1231
1239
  } else {
1232
- console.warn("[HaexHub SDK] Event received but no context in payload:", event);
1240
+ console.warn("[HaexSpace SDK] Event received but no context in payload:", event);
1233
1241
  }
1234
1242
  });
1235
- console.log("[HaexHub SDK] Context change listener registered successfully");
1243
+ console.log("[HaexSpace SDK] Context change listener registered successfully");
1236
1244
  } catch (error) {
1237
- console.error("[HaexHub SDK] Failed to setup context change listener:", error);
1245
+ console.error("[HaexSpace SDK] Failed to setup context change listener:", error);
1238
1246
  this.log("Failed to setup context change listener:", error);
1239
1247
  }
1240
1248
  this.resolveReady();
@@ -1251,7 +1259,7 @@ var HaexVaultClient = class {
1251
1259
  window.addEventListener("message", this.messageHandler);
1252
1260
  this.isNativeWindow = false;
1253
1261
  this.initialized = true;
1254
- this.log("HaexHub SDK initialized in iframe mode");
1262
+ this.log("HaexSpace SDK initialized in iframe mode");
1255
1263
  try {
1256
1264
  if (this.config.manifest) {
1257
1265
  this._extensionInfo = {
@@ -1270,7 +1278,7 @@ window.parent === window: ${window.parent === window}
1270
1278
  window.self === window.top: ${window.self === window.top}`;
1271
1279
  try {
1272
1280
  window.parent.postMessage({
1273
- type: "haexhub:debug",
1281
+ type: HAEXSPACE_MESSAGE_TYPES.DEBUG,
1274
1282
  data: debugInfo
1275
1283
  }, "*");
1276
1284
  } catch (e) {
@@ -1419,7 +1427,7 @@ postMessage error: ${e}`);
1419
1427
  }
1420
1428
  log(...args) {
1421
1429
  if (this.config.debug) {
1422
- console.log("[HaexHub SDK]", ...args);
1430
+ console.log("[HaexSpace SDK]", ...args);
1423
1431
  }
1424
1432
  }
1425
1433
  };
@@ -1433,6 +1441,7 @@ exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
1433
1441
  exports.DatabaseAPI = DatabaseAPI;
1434
1442
  exports.ErrorCode = ErrorCode;
1435
1443
  exports.FilesystemAPI = FilesystemAPI;
1444
+ exports.HAEXSPACE_MESSAGE_TYPES = HAEXSPACE_MESSAGE_TYPES;
1436
1445
  exports.HAEXTENSION_EVENTS = HAEXTENSION_EVENTS;
1437
1446
  exports.HAEXTENSION_METHODS = HAEXTENSION_METHODS;
1438
1447
  exports.HaexHubError = HaexHubError;