@decocms/mesh-sdk 1.1.0 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/mesh-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "SDK for building external apps that integrate with Mesh MCP servers",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -600,12 +600,25 @@ export interface McpAuthStatus {
600
600
  isServerError?: boolean;
601
601
  }
602
602
 
603
+ /**
604
+ * Get the current origin for URL resolution.
605
+ * Returns window.location.origin in browser, undefined on server.
606
+ */
607
+ function getCurrentOrigin(): string | undefined {
608
+ if (typeof window !== "undefined" && window.location?.origin) {
609
+ return window.location.origin;
610
+ }
611
+ return undefined;
612
+ }
613
+
603
614
  /**
604
615
  * Extract connection ID from MCP proxy URL
605
616
  */
606
617
  function extractConnectionIdFromUrl(url: string): string | null {
607
618
  try {
608
- const urlObj = new URL(url);
619
+ // Use current origin as base for relative URLs (browser only)
620
+ const base = getCurrentOrigin();
621
+ const urlObj = base ? new URL(url, base) : new URL(url);
609
622
  const match = urlObj.pathname.match(/^\/mcp\/([^/]+)/);
610
623
  return match?.[1] ?? null;
611
624
  } catch {
@@ -682,8 +695,11 @@ export async function isConnectionAuthenticated({
682
695
 
683
696
  // Extract connection ID for OAuth token status check
684
697
  const connectionId = extractConnectionIdFromUrl(url);
685
- // Determine base URL for API calls (meshUrl > URL origin > window.location.origin)
686
- const apiBaseUrl = meshUrl ?? new URL(url).origin;
698
+ // Determine base URL for API calls (meshUrl > URL origin > current origin)
699
+ // Use current origin as base for relative URLs (browser only)
700
+ const base = getCurrentOrigin();
701
+ const apiBaseUrl =
702
+ meshUrl ?? (base ? new URL(url, base).origin : new URL(url).origin);
687
703
 
688
704
  if (response.ok) {
689
705
  // Check if we have an OAuth token stored for this connection