@unhingged/vizu-core 0.1.1 → 0.1.2

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.cts CHANGED
@@ -498,6 +498,14 @@ declare class CloudStorageAdapter implements StorageAdapter {
498
498
  * state.
499
499
  */
500
500
  preflightAuth(): Promise<void>;
501
+ /**
502
+ * Synchronous accessor for the currently cached bearer token, used
503
+ * by sibling modules that need to authenticate against the same
504
+ * backend (live-collab cross-origin polling). Returns null when no
505
+ * valid token is cached — callers fall back to credentials:'include'
506
+ * for same-origin or just disable themselves.
507
+ */
508
+ getCachedAuthToken(): string | null;
501
509
  load(_namespace: string): Promise<VizuComment[]>;
502
510
  addComment(_namespace: string, comment: VizuComment): Promise<void>;
503
511
  updateComment(_namespace: string, id: string, patch: Partial<VizuComment>): Promise<VizuComment | null>;
package/dist/index.d.ts CHANGED
@@ -498,6 +498,14 @@ declare class CloudStorageAdapter implements StorageAdapter {
498
498
  * state.
499
499
  */
500
500
  preflightAuth(): Promise<void>;
501
+ /**
502
+ * Synchronous accessor for the currently cached bearer token, used
503
+ * by sibling modules that need to authenticate against the same
504
+ * backend (live-collab cross-origin polling). Returns null when no
505
+ * valid token is cached — callers fall back to credentials:'include'
506
+ * for same-origin or just disable themselves.
507
+ */
508
+ getCachedAuthToken(): string | null;
501
509
  load(_namespace: string): Promise<VizuComment[]>;
502
510
  addComment(_namespace: string, comment: VizuComment): Promise<void>;
503
511
  updateComment(_namespace: string, id: string, patch: Partial<VizuComment>): Promise<VizuComment | null>;
package/dist/index.js CHANGED
@@ -365,6 +365,18 @@ var CloudStorageAdapter = class {
365
365
  async preflightAuth() {
366
366
  await this.resolveToken();
367
367
  }
368
+ /**
369
+ * Synchronous accessor for the currently cached bearer token, used
370
+ * by sibling modules that need to authenticate against the same
371
+ * backend (live-collab cross-origin polling). Returns null when no
372
+ * valid token is cached — callers fall back to credentials:'include'
373
+ * for same-origin or just disable themselves.
374
+ */
375
+ getCachedAuthToken() {
376
+ if (!this.cachedToken) return null;
377
+ if (this.isExpired(this.cachedToken)) return null;
378
+ return this.cachedToken.token;
379
+ }
368
380
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
369
381
  async load(_namespace) {
370
382
  const out = [];
@@ -537,7 +549,7 @@ var CloudStorageAdapter = class {
537
549
  }
538
550
  }
539
551
  sessionKey() {
540
- return `vizu:cloud-token:${this.workspace}`;
552
+ return `vizu:cloud-token:v2:${this.workspace}`;
541
553
  }
542
554
  /**
543
555
  * Resolve a valid token, opening the popup if needed.
@@ -2845,14 +2857,27 @@ var Vizu = class {
2845
2857
  if (options.actions) this.actions = [...options.actions];
2846
2858
  if (options.onCommentAdded) this.bus.on("comment:added", (p) => options.onCommentAdded(p.comment));
2847
2859
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
2848
- if (options.liveblocks && options.cloud) {
2849
- const live = options.liveblocks;
2860
+ if (options.cloud) {
2850
2861
  const cloud = options.cloud;
2851
- void import("./live-collab-IRUNFAPE.js").then(({ LiveCollab }) => {
2862
+ const apiUrl = (cloud.apiUrl ?? "https://vizu.unhingged.com").replace(/\/$/, "");
2863
+ void import("./live-collab-BVLNJ5QI.js").then(({ LiveCollab }) => {
2852
2864
  this.liveCollab = new LiveCollab({
2853
- publicKey: live.publicKey,
2854
- authEndpoint: live.authEndpoint,
2855
- workspaceSlug: cloud.workspace
2865
+ workspaceSlug: cloud.workspace,
2866
+ apiUrl,
2867
+ getAuthHeader: async () => {
2868
+ if (typeof window === "undefined") return null;
2869
+ try {
2870
+ if (new URL(apiUrl).origin === window.location.origin) return null;
2871
+ } catch {
2872
+ return null;
2873
+ }
2874
+ const adapter = this.storage;
2875
+ if (adapter instanceof CloudStorageAdapter) {
2876
+ const token = adapter.getCachedAuthToken();
2877
+ if (token) return { Authorization: `Bearer ${token}` };
2878
+ }
2879
+ return null;
2880
+ }
2856
2881
  });
2857
2882
  void this.liveCollab.start();
2858
2883
  });