mindcache 3.5.2 → 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
@@ -2660,9 +2660,8 @@ init_CloudAdapter();
2660
2660
  init_CloudAdapter();
2661
2661
 
2662
2662
  // src/cloud/OAuthClient.ts
2663
- var DEFAULT_AUTH_URL = "https://api.mindcache.dev/oauth/authorize";
2664
- var DEFAULT_TOKEN_URL = "https://api.mindcache.dev/oauth/token";
2665
- 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";
2666
2665
  var TOKEN_REFRESH_BUFFER = 5 * 60 * 1e3;
2667
2666
  function generateRandomString(length2) {
2668
2667
  const array = new Uint8Array(length2);
@@ -2698,19 +2697,58 @@ var OAuthClient = class {
2698
2697
  url.hash = "";
2699
2698
  redirectUri = url.toString();
2700
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;
2701
2704
  this.config = {
2702
2705
  clientId: config.clientId,
2703
2706
  redirectUri: redirectUri || "",
2704
2707
  scopes: config.scopes || ["read", "write"],
2705
- authUrl: config.authUrl || DEFAULT_AUTH_URL,
2706
- tokenUrl: config.tokenUrl || DEFAULT_TOKEN_URL,
2707
- apiUrl: config.apiUrl || (config.tokenUrl || DEFAULT_TOKEN_URL).replace("/oauth/token", ""),
2708
+ baseUrl,
2709
+ authUrl,
2710
+ tokenUrl,
2711
+ apiUrl,
2708
2712
  usePKCE: config.usePKCE !== false,
2709
2713
  // Default true
2710
2714
  storagePrefix: config.storagePrefix || "mindcache_oauth"
2711
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();
2712
2724
  this.loadTokens();
2713
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
+ }
2714
2752
  /**
2715
2753
  * Check if user is authenticated
2716
2754
  */