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/{CloudAdapter-CM7nyJaG.d.mts → CloudAdapter-DK4YecbV.d.mts} +4 -0
- package/dist/{CloudAdapter-CM7nyJaG.d.ts → CloudAdapter-DK4YecbV.d.ts} +4 -0
- package/dist/cloud/index.d.mts +2 -2
- package/dist/cloud/index.d.ts +2 -2
- package/dist/cloud/index.js +42 -0
- package/dist/cloud/index.js.map +1 -1
- package/dist/cloud/index.mjs +42 -0
- package/dist/cloud/index.mjs.map +1 -1
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -3
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +42 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +42 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -367,10 +405,12 @@ var init_CloudAdapter = __esm({
|
|
|
367
405
|
try {
|
|
368
406
|
if (typeof event.data === "string") {
|
|
369
407
|
const msg = JSON.parse(event.data);
|
|
408
|
+
console.log("\u2601\uFE0F CloudAdapter: Received JSON message:", msg.type, msg);
|
|
370
409
|
if (msg.type === "auth_success") {
|
|
371
410
|
this._state = "connected";
|
|
372
411
|
this.reconnectAttempts = 0;
|
|
373
412
|
this.emit("connected");
|
|
413
|
+
console.log("\u2601\uFE0F Connected to MindCache cloud");
|
|
374
414
|
} else if (msg.type === "auth_error" || msg.type === "error") {
|
|
375
415
|
this._state = "error";
|
|
376
416
|
this.emit("error", new Error(msg.error));
|
|
@@ -378,6 +418,7 @@ var init_CloudAdapter = __esm({
|
|
|
378
418
|
console.debug("MindCache Cloud: Received message type:", msg.type, msg);
|
|
379
419
|
}
|
|
380
420
|
} else {
|
|
421
|
+
console.log("\u2601\uFE0F CloudAdapter: Received binary message, length:", event.data.byteLength);
|
|
381
422
|
const encoder = encoding.createEncoder();
|
|
382
423
|
const decoder = decoding.createDecoder(new Uint8Array(event.data));
|
|
383
424
|
if (this.mindcache) {
|
|
@@ -388,6 +429,7 @@ var init_CloudAdapter = __esm({
|
|
|
388
429
|
if (!this._synced && (messageType === 1 || messageType === 2)) {
|
|
389
430
|
this._synced = true;
|
|
390
431
|
this.emit("synced");
|
|
432
|
+
console.log("\u2601\uFE0F Synced with cloud");
|
|
391
433
|
}
|
|
392
434
|
}
|
|
393
435
|
}
|
|
@@ -2662,6 +2704,7 @@ var OAuthClient = class {
|
|
|
2662
2704
|
scopes: config.scopes || ["read", "write"],
|
|
2663
2705
|
authUrl: config.authUrl || DEFAULT_AUTH_URL,
|
|
2664
2706
|
tokenUrl: config.tokenUrl || DEFAULT_TOKEN_URL,
|
|
2707
|
+
apiUrl: config.apiUrl || (config.tokenUrl || DEFAULT_TOKEN_URL).replace("/oauth/token", ""),
|
|
2665
2708
|
usePKCE: config.usePKCE !== false,
|
|
2666
2709
|
// Default true
|
|
2667
2710
|
storagePrefix: config.storagePrefix || "mindcache_oauth"
|
|
@@ -2886,10 +2929,39 @@ var OAuthClient = class {
|
|
|
2886
2929
|
this.removeStorage("tokens");
|
|
2887
2930
|
}
|
|
2888
2931
|
/**
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2932
|
+
* Token provider for MindCache cloud config
|
|
2933
|
+
* This fetches a WebSocket token (short-lived) using the OAuth access token
|
|
2934
|
+
* Use this with MindCacheCloudOptions.tokenProvider
|
|
2935
|
+
*/
|
|
2892
2936
|
tokenProvider = async () => {
|
|
2937
|
+
const accessToken = await this.getAccessToken();
|
|
2938
|
+
const instanceId = this.getInstanceId();
|
|
2939
|
+
if (!instanceId) {
|
|
2940
|
+
throw new Error("No instance ID available. Complete OAuth flow first.");
|
|
2941
|
+
}
|
|
2942
|
+
const response = await fetch(`${this.config.apiUrl}/api/ws-token`, {
|
|
2943
|
+
method: "POST",
|
|
2944
|
+
headers: {
|
|
2945
|
+
"Content-Type": "application/json",
|
|
2946
|
+
"Authorization": `Bearer ${accessToken}`
|
|
2947
|
+
},
|
|
2948
|
+
body: JSON.stringify({
|
|
2949
|
+
instanceId,
|
|
2950
|
+
permission: "write"
|
|
2951
|
+
})
|
|
2952
|
+
});
|
|
2953
|
+
if (!response.ok) {
|
|
2954
|
+
const data2 = await response.json().catch(() => ({}));
|
|
2955
|
+
throw new Error(data2.error || "Failed to get WebSocket token");
|
|
2956
|
+
}
|
|
2957
|
+
const data = await response.json();
|
|
2958
|
+
return data.token;
|
|
2959
|
+
};
|
|
2960
|
+
/**
|
|
2961
|
+
* Get raw OAuth access token (for API calls, not WebSocket)
|
|
2962
|
+
* Use getAccessToken() for most cases
|
|
2963
|
+
*/
|
|
2964
|
+
accessTokenProvider = async () => {
|
|
2893
2965
|
return this.getAccessToken();
|
|
2894
2966
|
};
|
|
2895
2967
|
// Storage helpers
|