mindcache 3.5.0 → 3.5.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.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-CM7nyJaG.mjs';
2
- export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, h as ContextRules, n as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, k as HistoryOptions, K as KeyAttributes, j as KeyEntry, f as KeyType, L as Listener, l as MindCacheCloudOptions, m as MindCacheIndexedDBOptions, i as STM, j as STMEntry, g as SystemTag, o as SystemTagHelpers } from './CloudAdapter-CM7nyJaG.mjs';
1
+ import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-DK4YecbV.mjs';
2
+ export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, h as ContextRules, n as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, k as HistoryOptions, K as KeyAttributes, j as KeyEntry, f as KeyType, L as Listener, l as MindCacheCloudOptions, m as MindCacheIndexedDBOptions, i as STM, j as STMEntry, g as SystemTag, o as SystemTagHelpers } from './CloudAdapter-DK4YecbV.mjs';
3
3
  export { IndexedDBAdapter, IndexedDBConfig } from './server.mjs';
4
4
  import 'yjs';
5
5
 
@@ -20,6 +20,8 @@ interface OAuthConfig {
20
20
  authUrl?: string;
21
21
  /** MindCache token URL (default: production) */
22
22
  tokenUrl?: string;
23
+ /** MindCache API URL for WebSocket token exchange (default: production) */
24
+ apiUrl?: string;
23
25
  /** Use PKCE for security (default: true) */
24
26
  usePKCE?: boolean;
25
27
  /** Storage key prefix (default: 'mindcache_oauth') */
@@ -109,10 +111,16 @@ declare class OAuthClient {
109
111
  */
110
112
  private clearAuth;
111
113
  /**
112
- * Token provider function for MindCache cloud config
113
- * Use this with MindCacheCloudOptions.tokenProvider
114
- */
114
+ * Token provider for MindCache cloud config
115
+ * This fetches a WebSocket token (short-lived) using the OAuth access token
116
+ * Use this with MindCacheCloudOptions.tokenProvider
117
+ */
115
118
  tokenProvider: () => Promise<string>;
119
+ /**
120
+ * Get raw OAuth access token (for API calls, not WebSocket)
121
+ * Use getAccessToken() for most cases
122
+ */
123
+ accessTokenProvider: () => Promise<string>;
116
124
  private getStorage;
117
125
  private setStorage;
118
126
  private removeStorage;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-CM7nyJaG.js';
2
- export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, h as ContextRules, n as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, k as HistoryOptions, K as KeyAttributes, j as KeyEntry, f as KeyType, L as Listener, l as MindCacheCloudOptions, m as MindCacheIndexedDBOptions, i as STM, j as STMEntry, g as SystemTag, o as SystemTagHelpers } from './CloudAdapter-CM7nyJaG.js';
1
+ import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-DK4YecbV.js';
2
+ export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, h as ContextRules, n as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, k as HistoryOptions, K as KeyAttributes, j as KeyEntry, f as KeyType, L as Listener, l as MindCacheCloudOptions, m as MindCacheIndexedDBOptions, i as STM, j as STMEntry, g as SystemTag, o as SystemTagHelpers } from './CloudAdapter-DK4YecbV.js';
3
3
  export { IndexedDBAdapter, IndexedDBConfig } from './server.js';
4
4
  import 'yjs';
5
5
 
@@ -20,6 +20,8 @@ interface OAuthConfig {
20
20
  authUrl?: string;
21
21
  /** MindCache token URL (default: production) */
22
22
  tokenUrl?: string;
23
+ /** MindCache API URL for WebSocket token exchange (default: production) */
24
+ apiUrl?: string;
23
25
  /** Use PKCE for security (default: true) */
24
26
  usePKCE?: boolean;
25
27
  /** Storage key prefix (default: 'mindcache_oauth') */
@@ -109,10 +111,16 @@ declare class OAuthClient {
109
111
  */
110
112
  private clearAuth;
111
113
  /**
112
- * Token provider function for MindCache cloud config
113
- * Use this with MindCacheCloudOptions.tokenProvider
114
- */
114
+ * Token provider for MindCache cloud config
115
+ * This fetches a WebSocket token (short-lived) using the OAuth access token
116
+ * Use this with MindCacheCloudOptions.tokenProvider
117
+ */
115
118
  tokenProvider: () => Promise<string>;
119
+ /**
120
+ * Get raw OAuth access token (for API calls, not WebSocket)
121
+ * Use getAccessToken() for most cases
122
+ */
123
+ accessTokenProvider: () => Promise<string>;
116
124
  private getStorage;
117
125
  private setStorage;
118
126
  private removeStorage;
package/dist/index.js CHANGED
@@ -212,6 +212,7 @@ var init_CloudAdapter = __esm({
212
212
  if (!config.baseUrl) {
213
213
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
214
214
  }
215
+ this.validateConfig(config);
215
216
  this.setupNetworkDetection();
216
217
  }
217
218
  ws = null;
@@ -227,6 +228,43 @@ var init_CloudAdapter = __esm({
227
228
  handleOnline = null;
228
229
  handleOffline = null;
229
230
  _synced = false;
231
+ /**
232
+ * Validate configuration and warn about common mistakes
233
+ */
234
+ validateConfig(config) {
235
+ const baseUrl = config.baseUrl;
236
+ if (!baseUrl) {
237
+ return;
238
+ }
239
+ console.log("\u2601\uFE0F MindCache Cloud Config:", {
240
+ baseUrl,
241
+ instanceId: config.instanceId,
242
+ hasTokenProvider: !!config.tokenProvider,
243
+ hasApiKey: !!config.apiKey
244
+ });
245
+ try {
246
+ const url = new URL(baseUrl);
247
+ if (url.hostname === "mindcache.dev") {
248
+ console.error(
249
+ '\u26A0\uFE0F MindCache Cloud WARNING: baseUrl is set to "mindcache.dev" but the API is at "api.mindcache.dev".\n Current: ' + baseUrl + "\n Expected: https://api.mindcache.dev\n This will cause WebSocket connection failures (404 errors)."
250
+ );
251
+ }
252
+ if (url.protocol === "ws:" || url.protocol === "wss:") {
253
+ console.warn(
254
+ "\u26A0\uFE0F MindCache Cloud: baseUrl uses WebSocket protocol (" + url.protocol + "). Consider using http:// or https:// - CloudAdapter will handle the WebSocket upgrade automatically."
255
+ );
256
+ }
257
+ if (url.hostname === "localhost" && url.port !== "8787" && url.port !== "3000") {
258
+ console.warn(
259
+ "\u26A0\uFE0F MindCache Cloud: localhost URL detected with non-standard port " + url.port + ". Default MindCache dev server runs on port 8787."
260
+ );
261
+ }
262
+ const wsUrl = baseUrl.replace("https://", "wss://").replace("http://", "ws://");
263
+ console.log("\u2601\uFE0F WebSocket will connect to:", wsUrl + "/sync/" + config.instanceId);
264
+ } catch (e) {
265
+ console.error("\u26A0\uFE0F MindCache Cloud: Invalid baseUrl format:", baseUrl);
266
+ }
267
+ }
230
268
  /** Browser network status - instantly updated via navigator.onLine */
231
269
  get isOnline() {
232
270
  return this._isOnline;
@@ -395,10 +433,12 @@ var init_CloudAdapter = __esm({
395
433
  try {
396
434
  if (typeof event.data === "string") {
397
435
  const msg = JSON.parse(event.data);
436
+ console.log("\u2601\uFE0F CloudAdapter: Received JSON message:", msg.type, msg);
398
437
  if (msg.type === "auth_success") {
399
438
  this._state = "connected";
400
439
  this.reconnectAttempts = 0;
401
440
  this.emit("connected");
441
+ console.log("\u2601\uFE0F Connected to MindCache cloud");
402
442
  } else if (msg.type === "auth_error" || msg.type === "error") {
403
443
  this._state = "error";
404
444
  this.emit("error", new Error(msg.error));
@@ -406,6 +446,7 @@ var init_CloudAdapter = __esm({
406
446
  console.debug("MindCache Cloud: Received message type:", msg.type, msg);
407
447
  }
408
448
  } else {
449
+ console.log("\u2601\uFE0F CloudAdapter: Received binary message, length:", event.data.byteLength);
409
450
  const encoder = encoding__namespace.createEncoder();
410
451
  const decoder = decoding__namespace.createDecoder(new Uint8Array(event.data));
411
452
  if (this.mindcache) {
@@ -416,6 +457,7 @@ var init_CloudAdapter = __esm({
416
457
  if (!this._synced && (messageType === 1 || messageType === 2)) {
417
458
  this._synced = true;
418
459
  this.emit("synced");
460
+ console.log("\u2601\uFE0F Synced with cloud");
419
461
  }
420
462
  }
421
463
  }
@@ -2690,6 +2732,7 @@ var OAuthClient = class {
2690
2732
  scopes: config.scopes || ["read", "write"],
2691
2733
  authUrl: config.authUrl || DEFAULT_AUTH_URL,
2692
2734
  tokenUrl: config.tokenUrl || DEFAULT_TOKEN_URL,
2735
+ apiUrl: config.apiUrl || (config.tokenUrl || DEFAULT_TOKEN_URL).replace("/oauth/token", ""),
2693
2736
  usePKCE: config.usePKCE !== false,
2694
2737
  // Default true
2695
2738
  storagePrefix: config.storagePrefix || "mindcache_oauth"
@@ -2914,10 +2957,39 @@ var OAuthClient = class {
2914
2957
  this.removeStorage("tokens");
2915
2958
  }
2916
2959
  /**
2917
- * Token provider function for MindCache cloud config
2918
- * Use this with MindCacheCloudOptions.tokenProvider
2919
- */
2960
+ * Token provider for MindCache cloud config
2961
+ * This fetches a WebSocket token (short-lived) using the OAuth access token
2962
+ * Use this with MindCacheCloudOptions.tokenProvider
2963
+ */
2920
2964
  tokenProvider = async () => {
2965
+ const accessToken = await this.getAccessToken();
2966
+ const instanceId = this.getInstanceId();
2967
+ if (!instanceId) {
2968
+ throw new Error("No instance ID available. Complete OAuth flow first.");
2969
+ }
2970
+ const response = await fetch(`${this.config.apiUrl}/api/ws-token`, {
2971
+ method: "POST",
2972
+ headers: {
2973
+ "Content-Type": "application/json",
2974
+ "Authorization": `Bearer ${accessToken}`
2975
+ },
2976
+ body: JSON.stringify({
2977
+ instanceId,
2978
+ permission: "write"
2979
+ })
2980
+ });
2981
+ if (!response.ok) {
2982
+ const data2 = await response.json().catch(() => ({}));
2983
+ throw new Error(data2.error || "Failed to get WebSocket token");
2984
+ }
2985
+ const data = await response.json();
2986
+ return data.token;
2987
+ };
2988
+ /**
2989
+ * Get raw OAuth access token (for API calls, not WebSocket)
2990
+ * Use getAccessToken() for most cases
2991
+ */
2992
+ accessTokenProvider = async () => {
2921
2993
  return this.getAccessToken();
2922
2994
  };
2923
2995
  // Storage helpers