mindcache 3.5.1 → 3.5.3

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.mjs CHANGED
@@ -184,6 +184,7 @@ var init_CloudAdapter = __esm({
184
184
  if (!config.baseUrl) {
185
185
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
186
186
  }
187
+ this.validateConfig(config);
187
188
  this.setupNetworkDetection();
188
189
  }
189
190
  ws = null;
@@ -199,6 +200,43 @@ var init_CloudAdapter = __esm({
199
200
  handleOnline = null;
200
201
  handleOffline = null;
201
202
  _synced = false;
203
+ /**
204
+ * Validate configuration and warn about common mistakes
205
+ */
206
+ validateConfig(config) {
207
+ const baseUrl = config.baseUrl;
208
+ if (!baseUrl) {
209
+ return;
210
+ }
211
+ console.log("\u2601\uFE0F MindCache Cloud Config:", {
212
+ baseUrl,
213
+ instanceId: config.instanceId,
214
+ hasTokenProvider: !!config.tokenProvider,
215
+ hasApiKey: !!config.apiKey
216
+ });
217
+ try {
218
+ const url = new URL(baseUrl);
219
+ if (url.hostname === "mindcache.dev") {
220
+ console.error(
221
+ '\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)."
222
+ );
223
+ }
224
+ if (url.protocol === "ws:" || url.protocol === "wss:") {
225
+ console.warn(
226
+ "\u26A0\uFE0F MindCache Cloud: baseUrl uses WebSocket protocol (" + url.protocol + "). Consider using http:// or https:// - CloudAdapter will handle the WebSocket upgrade automatically."
227
+ );
228
+ }
229
+ if (url.hostname === "localhost" && url.port !== "8787" && url.port !== "3000") {
230
+ console.warn(
231
+ "\u26A0\uFE0F MindCache Cloud: localhost URL detected with non-standard port " + url.port + ". Default MindCache dev server runs on port 8787."
232
+ );
233
+ }
234
+ const wsUrl = baseUrl.replace("https://", "wss://").replace("http://", "ws://");
235
+ console.log("\u2601\uFE0F WebSocket will connect to:", wsUrl + "/sync/" + config.instanceId);
236
+ } catch (e) {
237
+ console.error("\u26A0\uFE0F MindCache Cloud: Invalid baseUrl format:", baseUrl);
238
+ }
239
+ }
202
240
  /** Browser network status - instantly updated via navigator.onLine */
203
241
  get isOnline() {
204
242
  return this._isOnline;
@@ -2622,9 +2660,8 @@ init_CloudAdapter();
2622
2660
  init_CloudAdapter();
2623
2661
 
2624
2662
  // src/cloud/OAuthClient.ts
2625
- var DEFAULT_AUTH_URL = "https://api.mindcache.dev/oauth/authorize";
2626
- var DEFAULT_TOKEN_URL = "https://api.mindcache.dev/oauth/token";
2627
- var DEFAULT_USERINFO_URL = "https://api.mindcache.dev/oauth/userinfo";
2663
+ var DEFAULT_API_URL = "https://api.mindcache.dev";
2664
+ var DEFAULT_USERINFO_URL = DEFAULT_API_URL + "/oauth/userinfo";
2628
2665
  var TOKEN_REFRESH_BUFFER = 5 * 60 * 1e3;
2629
2666
  function generateRandomString(length2) {
2630
2667
  const array = new Uint8Array(length2);
@@ -2660,19 +2697,58 @@ var OAuthClient = class {
2660
2697
  url.hash = "";
2661
2698
  redirectUri = url.toString();
2662
2699
  }
2700
+ const baseUrl = config.baseUrl || config.apiUrl || DEFAULT_API_URL;
2701
+ const authUrl = config.authUrl || baseUrl + "/oauth/authorize";
2702
+ const tokenUrl = config.tokenUrl || baseUrl + "/oauth/token";
2703
+ const apiUrl = config.apiUrl || baseUrl;
2663
2704
  this.config = {
2664
2705
  clientId: config.clientId,
2665
2706
  redirectUri: redirectUri || "",
2666
2707
  scopes: config.scopes || ["read", "write"],
2667
- authUrl: config.authUrl || DEFAULT_AUTH_URL,
2668
- tokenUrl: config.tokenUrl || DEFAULT_TOKEN_URL,
2669
- apiUrl: config.apiUrl || (config.tokenUrl || DEFAULT_TOKEN_URL).replace("/oauth/token", ""),
2708
+ baseUrl,
2709
+ authUrl,
2710
+ tokenUrl,
2711
+ apiUrl,
2670
2712
  usePKCE: config.usePKCE !== false,
2671
2713
  // Default true
2672
2714
  storagePrefix: config.storagePrefix || "mindcache_oauth"
2673
2715
  };
2716
+ console.log("\u{1F510} MindCache OAuth Config:", {
2717
+ baseUrl: this.config.baseUrl,
2718
+ authUrl: this.config.authUrl,
2719
+ tokenUrl: this.config.tokenUrl,
2720
+ apiUrl: this.config.apiUrl,
2721
+ clientId: this.config.clientId.substring(0, 20) + "..."
2722
+ });
2723
+ this.validateApi();
2674
2724
  this.loadTokens();
2675
2725
  }
2726
+ /**
2727
+ * Validate the API is reachable and warn about common misconfigurations
2728
+ */
2729
+ async validateApi() {
2730
+ try {
2731
+ const response = await fetch(`${this.config.apiUrl}/oauth/apps/info`, {
2732
+ method: "GET",
2733
+ headers: { "Accept": "application/json" }
2734
+ });
2735
+ if (response.status === 404) {
2736
+ console.error(
2737
+ "\u274C MindCache OAuth ERROR: API not found at " + this.config.apiUrl + '\n The server returned 404. Common causes:\n - Wrong domain: Use "api.mindcache.dev" not "mindcache.dev"\n - Wrong port: Local dev server is usually on port 8787\n - Server not running: Make sure the MindCache server is started'
2738
+ );
2739
+ } else if (!response.ok) {
2740
+ console.warn(
2741
+ "\u26A0\uFE0F MindCache OAuth: API responded with status " + response.status + "\n URL: " + this.config.apiUrl
2742
+ );
2743
+ } else {
2744
+ console.log("\u2705 MindCache OAuth: API is reachable at " + this.config.apiUrl);
2745
+ }
2746
+ } catch (error) {
2747
+ console.error(
2748
+ "\u274C MindCache OAuth ERROR: Cannot reach API at " + this.config.apiUrl + "\n Error: " + (error instanceof Error ? error.message : String(error)) + "\n Check your network connection and baseUrl configuration."
2749
+ );
2750
+ }
2751
+ }
2676
2752
  /**
2677
2753
  * Check if user is authenticated
2678
2754
  */