@shuffleio/shuffle-mcps 0.0.39 → 0.0.45

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.
@@ -2,7 +2,7 @@ import {
2
2
  fetchApps,
3
3
  fetchAppsViaApiConfig,
4
4
  invalidateAppsCache
5
- } from "./chunk-DCHKGFML.mjs";
5
+ } from "./chunk-5LZ5IZ2O.mjs";
6
6
  export {
7
7
  fetchApps,
8
8
  fetchAppsViaApiConfig,
@@ -50,7 +50,7 @@ var keyFor = (input, init) => {
50
50
  return null;
51
51
  }
52
52
  };
53
- var withStoredApiKey = (input, init) => {
53
+ var withStoredAuth = (input, init) => {
54
54
  if (typeof window === "undefined") return init;
55
55
  let urlStr;
56
56
  if (typeof input === "string") urlStr = input;
@@ -59,17 +59,35 @@ var withStoredApiKey = (input, init) => {
59
59
  else return init;
60
60
  try {
61
61
  const url = new URL(urlStr, window.location.href);
62
- const isKnownShuffleOrigin = allowedOrigins.has(url.origin) || url.origin === window.location.origin || url.hostname === "shuffler.io" || url.hostname.endsWith(".shuffler.io") || url.hostname === "tunnel.schemaless.org";
62
+ const isKnownShuffleOrigin = allowedOrigins.has(url.origin) || url.origin === window.location.origin || url.hostname === "shuffler.io" || url.hostname.endsWith(".shuffler.io") || url.hostname === "tunnel.schemaless.org" || url.hostname === "shuffle.security" || url.hostname.endsWith(".shuffle.security");
63
63
  if (!url.pathname.startsWith("/api/") || !isKnownShuffleOrigin) return init;
64
- const apiKey = window.localStorage.getItem("shuffle_api_key");
65
- if (!apiKey) return init;
64
+ if (url.pathname === "/api/v1/login" || url.pathname === "/api/v1/users/register") return init;
65
+ const sessionToken = window.localStorage.getItem("session_token");
66
+ const token = sessionToken && sessionToken.trim().length > 0 ? sessionToken.trim() : null;
66
67
  const requestHeaders = typeof Request !== "undefined" && input instanceof Request ? input.headers : void 0;
67
68
  const headers = new Headers(requestHeaders);
68
69
  if (init?.headers) {
69
70
  new Headers(init.headers).forEach((value, name) => headers.set(name, value));
70
71
  }
71
- if (!headers.has("Authorization")) headers.set("Authorization", `Bearer ${apiKey}`);
72
- return { ...init, headers };
72
+ if (token && !headers.has("Authorization")) {
73
+ headers.set("Authorization", `Bearer ${token}`);
74
+ }
75
+ if (!headers.has("Org-Id")) {
76
+ try {
77
+ const raw = window.localStorage.getItem("shuffle_user_info");
78
+ if (raw) {
79
+ const parsed = JSON.parse(raw);
80
+ const orgId = parsed?.active_org?.id;
81
+ if (orgId) headers.set("Org-Id", orgId);
82
+ }
83
+ } catch {
84
+ }
85
+ }
86
+ return {
87
+ ...init,
88
+ credentials: init?.credentials || "include",
89
+ headers
90
+ };
73
91
  } catch {
74
92
  return init;
75
93
  }
@@ -99,7 +117,7 @@ var installFetchBreaker = () => {
99
117
  installed = true;
100
118
  const original = window.fetch.bind(window);
101
119
  window.fetch = (async (input, init) => {
102
- const authenticatedInit = withStoredApiKey(input, init);
120
+ const authenticatedInit = withStoredAuth(input, init);
103
121
  const key = keyFor(input, authenticatedInit);
104
122
  if (!key) return original(input, authenticatedInit);
105
123
  const entry = getEntry(key);
@@ -175,6 +193,84 @@ var installFetchBreaker = () => {
175
193
  });
176
194
  };
177
195
 
196
+ // ../lib/shuffleUrls.ts
197
+ var readEnv = (key) => {
198
+ try {
199
+ const meta = new Function("try { return import.meta } catch { return undefined }")();
200
+ const val = meta?.env?.[key];
201
+ if (val && typeof val === "string" && val.trim().length > 0) {
202
+ return val.trim();
203
+ }
204
+ } catch {
205
+ }
206
+ if (typeof window !== "undefined") {
207
+ const win = window;
208
+ const runtimeConfig = win.__SHUFFLE_CONFIG__ || win._env_ || win.__ENV__;
209
+ if (runtimeConfig && typeof runtimeConfig === "object") {
210
+ const val = runtimeConfig[key] || runtimeConfig[key.replace(/^VITE_/, "")];
211
+ if (val && typeof val === "string" && val.trim().length > 0) {
212
+ return val.trim();
213
+ }
214
+ }
215
+ }
216
+ try {
217
+ if (typeof process !== "undefined" && process.env) {
218
+ const val = process.env[key] || process.env[key.replace(/^VITE_/, "")];
219
+ if (val && typeof val === "string" && val.trim().length > 0) {
220
+ return val.trim();
221
+ }
222
+ }
223
+ } catch {
224
+ }
225
+ return void 0;
226
+ };
227
+ var isManagedDomain = () => {
228
+ if (typeof window === "undefined") return false;
229
+ const hostname = window.location.hostname.toLowerCase();
230
+ return hostname.includes("lovable") || hostname.includes("shuffler.io") || hostname.includes("shutdown.no") || hostname.includes("shuffle.security");
231
+ };
232
+ var getShuffleCoreBaseUrl = () => {
233
+ const envUrl = readEnv("VITE_SHUFFLE_CORE_URL") || readEnv("SHUFFLE_CORE_URL") || readEnv("VITE_SHUFFLE_AUTOMATION_URL") || readEnv("VITE_SHUFFLE_URL");
234
+ if (envUrl) {
235
+ return envUrl.replace(/\/+$/, "");
236
+ }
237
+ if (typeof window !== "undefined") {
238
+ try {
239
+ const savedCore = localStorage.getItem("shuffle_core_url");
240
+ if (savedCore && savedCore.trim().length > 0) {
241
+ return savedCore.trim().replace(/\/+$/, "");
242
+ }
243
+ const customHost = localStorage.getItem("shuffle_custom_host_url");
244
+ if (customHost && customHost.trim().length > 0) {
245
+ const cleaned = customHost.trim().replace(/\/+$/, "");
246
+ if (cleaned.includes(":5001")) {
247
+ return cleaned.replace(":5001", ":3001");
248
+ }
249
+ return cleaned;
250
+ }
251
+ } catch {
252
+ }
253
+ }
254
+ if (typeof window !== "undefined") {
255
+ const hostname = window.location.hostname;
256
+ const isManaged = isManagedDomain();
257
+ if (isManaged) {
258
+ return "https://shuffler.io";
259
+ }
260
+ if (window.location.port === "3001") {
261
+ return window.location.origin;
262
+ }
263
+ return `${window.location.protocol}//${hostname}:3001`;
264
+ }
265
+ return "https://shuffler.io";
266
+ };
267
+ var getShuffleCoreUrl = (path) => {
268
+ const base = getShuffleCoreBaseUrl();
269
+ if (!path) return base;
270
+ const cleanPath = path.startsWith("/") ? path : `/${path}`;
271
+ return `${base}${cleanPath}`;
272
+ };
273
+
178
274
  // ../lib/platform.ts
179
275
  var getPlatform = () => {
180
276
  if (typeof window === "undefined") return "web";
@@ -232,7 +328,8 @@ if (typeof window !== "undefined") {
232
328
  // api.ts
233
329
  installFetchBreaker();
234
330
  var DEV_BACKEND = "https://tunnel.schemaless.org";
235
- var PROD_BACKEND = "https://shuffler.io";
331
+ var PROD_BACKEND = "https://uk.shuffler.io";
332
+ var SHUFFLE_AUTOMATION_URL = getShuffleCoreUrl("/new-dashboard");
236
333
  var CLOUD_DOMAINS = ["shuffle.security", "www.shuffle.security", "security.shuffler.io", "shutdown.no", "www.shutdown.no"];
237
334
  var getEnvVar = (key) => {
238
335
  try {
@@ -274,7 +371,11 @@ var readCachedRegion = () => {
274
371
  const raw = localStorage.getItem(REGION_STORAGE_KEY);
275
372
  if (!raw) return { url: null, orgId: null };
276
373
  const parsed = JSON.parse(raw);
277
- return { url: parsed?.url || null, orgId: parsed?.orgId || null };
374
+ const url = parsed?.url ? parsed.url.replace(/\/+$/, "") : null;
375
+ if (url === "https://shuffler.io" || url === PROD_BACKEND) {
376
+ return { url: null, orgId: parsed?.orgId || null };
377
+ }
378
+ return { url, orgId: parsed?.orgId || null };
278
379
  } catch {
279
380
  return { url: null, orgId: null };
280
381
  }
@@ -284,8 +385,20 @@ var _regionUrl = cached.url;
284
385
  var readCachedCustomHost = () => {
285
386
  if (typeof window === "undefined") return null;
286
387
  try {
388
+ const mode = localStorage.getItem("shuffle_selected_server_mode");
389
+ if (mode && mode !== "self-hosted") return null;
287
390
  const raw = localStorage.getItem("shuffle_custom_host_url");
288
- return raw ? raw.trim().replace(/\/+$/, "") : null;
391
+ const cleaned = raw ? raw.trim().replace(/\/+$/, "") : null;
392
+ if (!cleaned) return null;
393
+ if (cleaned === DEV_BACKEND && !isDevEnvironment() && mode !== "self-hosted") {
394
+ try {
395
+ localStorage.removeItem("shuffle_custom_host_url");
396
+ localStorage.removeItem("shuffle_selected_server_mode");
397
+ } catch {
398
+ }
399
+ return null;
400
+ }
401
+ return cleaned;
289
402
  } catch {
290
403
  return null;
291
404
  }
@@ -336,7 +449,8 @@ var setRegionUrl = (regionUrl, orgId) => {
336
449
  _trackedOrgId = orgId || null;
337
450
  if (regionUrl && isShufflerSubdomain(regionUrl)) {
338
451
  const normalized = regionUrl.replace(/\/+$/, "");
339
- if (normalized !== PROD_BACKEND) {
452
+ const isDefaultCloud = normalized === PROD_BACKEND || normalized === "https://shuffler.io";
453
+ if (!isDefaultCloud) {
340
454
  _regionUrl = normalized;
341
455
  persistRegion(_regionUrl, _trackedOrgId);
342
456
  console.log(`[API] Region URL set to: ${_regionUrl}`);
@@ -389,6 +503,38 @@ if (typeof window !== "undefined") {
389
503
  }
390
504
  var getHostBaseUrl = () => _hostBaseUrl;
391
505
  var getTrackedOrgId = () => _trackedOrgId;
506
+ var LEGACY_API_KEY_STORAGE_KEY = "shuffle_api_key";
507
+ var clearAuthTokens = () => {
508
+ try {
509
+ localStorage.removeItem("session_token");
510
+ localStorage.removeItem(LEGACY_API_KEY_STORAGE_KEY);
511
+ } catch {
512
+ }
513
+ };
514
+ var getSessionToken = () => {
515
+ try {
516
+ if (typeof localStorage === "undefined") return null;
517
+ if (localStorage.getItem(LEGACY_API_KEY_STORAGE_KEY) !== null) {
518
+ localStorage.removeItem(LEGACY_API_KEY_STORAGE_KEY);
519
+ }
520
+ const stored = localStorage.getItem("session_token");
521
+ if (stored && stored.trim().length > 0 && stored !== "null" && stored !== "undefined") {
522
+ return stored.trim();
523
+ }
524
+ return null;
525
+ } catch {
526
+ return null;
527
+ }
528
+ };
529
+ var setSessionToken = (token) => {
530
+ clearAuthTokens();
531
+ if (token && token.trim().length > 0) {
532
+ try {
533
+ localStorage.setItem("session_token", token.trim());
534
+ } catch {
535
+ }
536
+ }
537
+ };
392
538
  var API_CONFIG = {
393
539
  // Shuffle backend URL — host override beats region URL beats default.
394
540
  get baseUrl() {
@@ -401,17 +547,16 @@ var API_CONFIG = {
401
547
  },
402
548
  // API version
403
549
  version: "v1",
404
- // Get API key from localStorage (for local development)
550
+ /**
551
+ * DEPRECATED alias for the single session token. There is no separate
552
+ * API-key auth any more: exactly one session token may exist at a time.
553
+ */
405
554
  get apiKey() {
406
- return localStorage.getItem("shuffle_api_key");
555
+ return getSessionToken();
407
556
  },
408
- // Set API key in localStorage
557
+ /** DEPRECATED: writes/clears the single session token. */
409
558
  setApiKey(key) {
410
- if (key) {
411
- localStorage.setItem("shuffle_api_key", key);
412
- } else {
413
- localStorage.removeItem("shuffle_api_key");
414
- }
559
+ setSessionToken(key);
415
560
  }
416
561
  };
417
562
  var getApiUrl = (endpoint) => {
@@ -430,11 +575,21 @@ var shuffleFetch = (url, init) => {
430
575
  };
431
576
  var getAuthHeader = (overrideOrgId) => {
432
577
  const headers = {};
433
- const apiKey = API_CONFIG.apiKey;
434
- if (apiKey) {
435
- headers["Authorization"] = `Bearer ${apiKey}`;
578
+ const token = getSessionToken();
579
+ if (token) {
580
+ headers["Authorization"] = `Bearer ${token}`;
581
+ }
582
+ let orgId = overrideOrgId ?? _trackedOrgId;
583
+ if (!orgId && typeof localStorage !== "undefined") {
584
+ try {
585
+ const raw = localStorage.getItem("shuffle_user_info");
586
+ if (raw) {
587
+ const parsed = JSON.parse(raw);
588
+ orgId = parsed?.active_org?.id || parsed?.org_id || null;
589
+ }
590
+ } catch {
591
+ }
436
592
  }
437
- const orgId = overrideOrgId ?? _trackedOrgId;
438
593
  if (orgId) {
439
594
  headers["Org-Id"] = orgId;
440
595
  }
@@ -442,8 +597,10 @@ var getAuthHeader = (overrideOrgId) => {
442
597
  };
443
598
  var hasShuffleAuth = () => {
444
599
  try {
445
- if (API_CONFIG.apiKey) return true;
446
- return !!(localStorage.getItem("session_token") || localStorage.getItem("shuffle_user_info"));
600
+ if (getSessionToken()) return true;
601
+ const info = localStorage.getItem("shuffle_user_info");
602
+ if (info && info.trim().length > 0 && info !== "null" && info !== "undefined") return true;
603
+ return false;
447
604
  } catch {
448
605
  return false;
449
606
  }
@@ -455,7 +612,9 @@ var ERROR_TTL_MS = 3e4;
455
612
  var cache = /* @__PURE__ */ new Map();
456
613
  var cacheKey = (o) => `${o.baseUrl}|${o.path || "/api/v1/apps"}|${o.apiKey || ""}|${o.orgId || ""}`;
457
614
  var doFetch = async (o) => {
458
- const headers = {};
615
+ const headers = {
616
+ ...getAuthHeader(o.orgId || void 0)
617
+ };
459
618
  if (o.apiKey) headers["Authorization"] = `Bearer ${o.apiKey}`;
460
619
  if (o.orgId) headers["Org-Id"] = o.orgId;
461
620
  const response = await fetch(`${o.baseUrl}${o.path || "/api/v1/apps"}`, {