@squadbase/vite-server 0.1.3-dev.7 → 0.1.3-dev.9

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.
Files changed (48) hide show
  1. package/dist/cli/index.js +1532 -1335
  2. package/dist/connectors/airtable-oauth.js +74 -1
  3. package/dist/connectors/airtable.js +74 -1
  4. package/dist/connectors/amplitude.js +74 -1
  5. package/dist/connectors/anthropic.js +74 -1
  6. package/dist/connectors/asana.js +74 -1
  7. package/dist/connectors/attio.js +74 -1
  8. package/dist/connectors/customerio.js +74 -1
  9. package/dist/connectors/dbt.js +74 -1
  10. package/dist/connectors/gemini.js +74 -1
  11. package/dist/connectors/gmail-oauth.js +74 -1
  12. package/dist/connectors/gmail.js +74 -1
  13. package/dist/connectors/google-ads-oauth.js +74 -1
  14. package/dist/connectors/google-ads.js +74 -1
  15. package/dist/connectors/google-analytics-oauth.js +87 -6
  16. package/dist/connectors/google-analytics.js +117 -46
  17. package/dist/connectors/google-calendar-oauth.js +74 -1
  18. package/dist/connectors/google-calendar.d.ts +1 -8
  19. package/dist/connectors/google-calendar.js +316 -64
  20. package/dist/connectors/google-sheets-oauth.js +85 -18
  21. package/dist/connectors/google-sheets.js +75 -2
  22. package/dist/connectors/grafana.js +74 -1
  23. package/dist/connectors/hubspot-oauth.js +74 -1
  24. package/dist/connectors/hubspot.js +74 -1
  25. package/dist/connectors/intercom-oauth.js +74 -1
  26. package/dist/connectors/intercom.js +74 -1
  27. package/dist/connectors/jira-api-key.js +74 -1
  28. package/dist/connectors/kintone-api-token.js +74 -1
  29. package/dist/connectors/kintone.js +74 -1
  30. package/dist/connectors/linkedin-ads-oauth.js +74 -1
  31. package/dist/connectors/linkedin-ads.js +74 -1
  32. package/dist/connectors/mailchimp-oauth.js +74 -1
  33. package/dist/connectors/mailchimp.js +74 -1
  34. package/dist/connectors/notion-oauth.js +74 -1
  35. package/dist/connectors/notion.js +74 -1
  36. package/dist/connectors/openai.js +74 -1
  37. package/dist/connectors/shopify-oauth.js +74 -1
  38. package/dist/connectors/shopify.js +74 -1
  39. package/dist/connectors/stripe-api-key.js +74 -1
  40. package/dist/connectors/stripe-oauth.js +74 -1
  41. package/dist/connectors/wix-store.js +74 -1
  42. package/dist/connectors/zendesk-oauth.js +74 -1
  43. package/dist/connectors/zendesk.js +74 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.js +1568 -1335
  46. package/dist/main.js +1567 -1333
  47. package/dist/vite-plugin.js +1483 -1286
  48. package/package.json +1 -1
@@ -409,6 +409,79 @@ function resolveEnvVarOptional(entry, key) {
409
409
  return process.env[envVarName] || void 0;
410
410
  }
411
411
 
412
+ // src/connector-client/proxy-fetch.ts
413
+ import { getContext } from "hono/context-storage";
414
+ import { getCookie } from "hono/cookie";
415
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
416
+ function createSandboxProxyFetch(connectionId) {
417
+ return async (input, init) => {
418
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
419
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
420
+ if (!token || !sandboxId) {
421
+ throw new Error(
422
+ "Connection proxy is not configured. Please check your deployment settings."
423
+ );
424
+ }
425
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
426
+ const originalMethod = init?.method ?? "GET";
427
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
428
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
429
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
430
+ return fetch(proxyUrl, {
431
+ method: "POST",
432
+ headers: {
433
+ "Content-Type": "application/json",
434
+ Authorization: `Bearer ${token}`
435
+ },
436
+ body: JSON.stringify({
437
+ url: originalUrl,
438
+ method: originalMethod,
439
+ body: originalBody
440
+ })
441
+ });
442
+ };
443
+ }
444
+ function createDeployedAppProxyFetch(connectionId) {
445
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
446
+ if (!projectId) {
447
+ throw new Error(
448
+ "Connection proxy is not configured. Please check your deployment settings."
449
+ );
450
+ }
451
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
452
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
453
+ return async (input, init) => {
454
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
455
+ const originalMethod = init?.method ?? "GET";
456
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
457
+ const c = getContext();
458
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
459
+ if (!appSession) {
460
+ throw new Error(
461
+ "No authentication method available for connection proxy."
462
+ );
463
+ }
464
+ return fetch(proxyUrl, {
465
+ method: "POST",
466
+ headers: {
467
+ "Content-Type": "application/json",
468
+ Authorization: `Bearer ${appSession}`
469
+ },
470
+ body: JSON.stringify({
471
+ url: originalUrl,
472
+ method: originalMethod,
473
+ body: originalBody
474
+ })
475
+ });
476
+ };
477
+ }
478
+ function createProxyFetch(connectionId) {
479
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
480
+ return createSandboxProxyFetch(connectionId);
481
+ }
482
+ return createDeployedAppProxyFetch(connectionId);
483
+ }
484
+
412
485
  // src/connectors/create-connector-sdk.ts
413
486
  function loadConnectionsSync() {
414
487
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -442,7 +515,7 @@ function createConnectorSdk(plugin, createClient2) {
442
515
  if (val !== void 0) params[param.slug] = val;
443
516
  }
444
517
  }
445
- return createClient2(params);
518
+ return createClient2(params, createProxyFetch(connectionId));
446
519
  };
447
520
  }
448
521
 
@@ -508,6 +508,79 @@ function resolveEnvVarOptional(entry, key) {
508
508
  return process.env[envVarName] || void 0;
509
509
  }
510
510
 
511
+ // src/connector-client/proxy-fetch.ts
512
+ import { getContext } from "hono/context-storage";
513
+ import { getCookie } from "hono/cookie";
514
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
515
+ function createSandboxProxyFetch(connectionId) {
516
+ return async (input, init) => {
517
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
518
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
519
+ if (!token || !sandboxId) {
520
+ throw new Error(
521
+ "Connection proxy is not configured. Please check your deployment settings."
522
+ );
523
+ }
524
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
525
+ const originalMethod = init?.method ?? "GET";
526
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
527
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
528
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
529
+ return fetch(proxyUrl, {
530
+ method: "POST",
531
+ headers: {
532
+ "Content-Type": "application/json",
533
+ Authorization: `Bearer ${token}`
534
+ },
535
+ body: JSON.stringify({
536
+ url: originalUrl,
537
+ method: originalMethod,
538
+ body: originalBody
539
+ })
540
+ });
541
+ };
542
+ }
543
+ function createDeployedAppProxyFetch(connectionId) {
544
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
545
+ if (!projectId) {
546
+ throw new Error(
547
+ "Connection proxy is not configured. Please check your deployment settings."
548
+ );
549
+ }
550
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
551
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
552
+ return async (input, init) => {
553
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
554
+ const originalMethod = init?.method ?? "GET";
555
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
556
+ const c = getContext();
557
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
558
+ if (!appSession) {
559
+ throw new Error(
560
+ "No authentication method available for connection proxy."
561
+ );
562
+ }
563
+ return fetch(proxyUrl, {
564
+ method: "POST",
565
+ headers: {
566
+ "Content-Type": "application/json",
567
+ Authorization: `Bearer ${appSession}`
568
+ },
569
+ body: JSON.stringify({
570
+ url: originalUrl,
571
+ method: originalMethod,
572
+ body: originalBody
573
+ })
574
+ });
575
+ };
576
+ }
577
+ function createProxyFetch(connectionId) {
578
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
579
+ return createSandboxProxyFetch(connectionId);
580
+ }
581
+ return createDeployedAppProxyFetch(connectionId);
582
+ }
583
+
511
584
  // src/connectors/create-connector-sdk.ts
512
585
  function loadConnectionsSync() {
513
586
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -541,7 +614,7 @@ function createConnectorSdk(plugin, createClient2) {
541
614
  if (val !== void 0) params[param.slug] = val;
542
615
  }
543
616
  }
544
- return createClient2(params);
617
+ return createClient2(params, createProxyFetch(connectionId));
545
618
  };
546
619
  }
547
620
 
@@ -731,6 +731,79 @@ function resolveEnvVarOptional(entry, key) {
731
731
  return process.env[envVarName] || void 0;
732
732
  }
733
733
 
734
+ // src/connector-client/proxy-fetch.ts
735
+ import { getContext } from "hono/context-storage";
736
+ import { getCookie } from "hono/cookie";
737
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
738
+ function createSandboxProxyFetch(connectionId) {
739
+ return async (input, init) => {
740
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
741
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
742
+ if (!token || !sandboxId) {
743
+ throw new Error(
744
+ "Connection proxy is not configured. Please check your deployment settings."
745
+ );
746
+ }
747
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
748
+ const originalMethod = init?.method ?? "GET";
749
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
750
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
751
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
752
+ return fetch(proxyUrl, {
753
+ method: "POST",
754
+ headers: {
755
+ "Content-Type": "application/json",
756
+ Authorization: `Bearer ${token}`
757
+ },
758
+ body: JSON.stringify({
759
+ url: originalUrl,
760
+ method: originalMethod,
761
+ body: originalBody
762
+ })
763
+ });
764
+ };
765
+ }
766
+ function createDeployedAppProxyFetch(connectionId) {
767
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
768
+ if (!projectId) {
769
+ throw new Error(
770
+ "Connection proxy is not configured. Please check your deployment settings."
771
+ );
772
+ }
773
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
774
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
775
+ return async (input, init) => {
776
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
777
+ const originalMethod = init?.method ?? "GET";
778
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
779
+ const c = getContext();
780
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
781
+ if (!appSession) {
782
+ throw new Error(
783
+ "No authentication method available for connection proxy."
784
+ );
785
+ }
786
+ return fetch(proxyUrl, {
787
+ method: "POST",
788
+ headers: {
789
+ "Content-Type": "application/json",
790
+ Authorization: `Bearer ${appSession}`
791
+ },
792
+ body: JSON.stringify({
793
+ url: originalUrl,
794
+ method: originalMethod,
795
+ body: originalBody
796
+ })
797
+ });
798
+ };
799
+ }
800
+ function createProxyFetch(connectionId) {
801
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
802
+ return createSandboxProxyFetch(connectionId);
803
+ }
804
+ return createDeployedAppProxyFetch(connectionId);
805
+ }
806
+
734
807
  // src/connectors/create-connector-sdk.ts
735
808
  function loadConnectionsSync() {
736
809
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -764,7 +837,7 @@ function createConnectorSdk(plugin, createClient2) {
764
837
  if (val !== void 0) params[param.slug] = val;
765
838
  }
766
839
  }
767
- return createClient2(params);
840
+ return createClient2(params, createProxyFetch(connectionId));
768
841
  };
769
842
  }
770
843
 
@@ -748,6 +748,79 @@ function resolveEnvVarOptional(entry, key) {
748
748
  return process.env[envVarName] || void 0;
749
749
  }
750
750
 
751
+ // src/connector-client/proxy-fetch.ts
752
+ import { getContext } from "hono/context-storage";
753
+ import { getCookie } from "hono/cookie";
754
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
755
+ function createSandboxProxyFetch(connectionId) {
756
+ return async (input, init) => {
757
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
758
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
759
+ if (!token || !sandboxId) {
760
+ throw new Error(
761
+ "Connection proxy is not configured. Please check your deployment settings."
762
+ );
763
+ }
764
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
765
+ const originalMethod = init?.method ?? "GET";
766
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
767
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
768
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
769
+ return fetch(proxyUrl, {
770
+ method: "POST",
771
+ headers: {
772
+ "Content-Type": "application/json",
773
+ Authorization: `Bearer ${token}`
774
+ },
775
+ body: JSON.stringify({
776
+ url: originalUrl,
777
+ method: originalMethod,
778
+ body: originalBody
779
+ })
780
+ });
781
+ };
782
+ }
783
+ function createDeployedAppProxyFetch(connectionId) {
784
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
785
+ if (!projectId) {
786
+ throw new Error(
787
+ "Connection proxy is not configured. Please check your deployment settings."
788
+ );
789
+ }
790
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
791
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
792
+ return async (input, init) => {
793
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
794
+ const originalMethod = init?.method ?? "GET";
795
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
796
+ const c = getContext();
797
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
798
+ if (!appSession) {
799
+ throw new Error(
800
+ "No authentication method available for connection proxy."
801
+ );
802
+ }
803
+ return fetch(proxyUrl, {
804
+ method: "POST",
805
+ headers: {
806
+ "Content-Type": "application/json",
807
+ Authorization: `Bearer ${appSession}`
808
+ },
809
+ body: JSON.stringify({
810
+ url: originalUrl,
811
+ method: originalMethod,
812
+ body: originalBody
813
+ })
814
+ });
815
+ };
816
+ }
817
+ function createProxyFetch(connectionId) {
818
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
819
+ return createSandboxProxyFetch(connectionId);
820
+ }
821
+ return createDeployedAppProxyFetch(connectionId);
822
+ }
823
+
751
824
  // src/connectors/create-connector-sdk.ts
752
825
  function loadConnectionsSync() {
753
826
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -781,7 +854,7 @@ function createConnectorSdk(plugin, createClient2) {
781
854
  if (val !== void 0) params[param.slug] = val;
782
855
  }
783
856
  }
784
- return createClient2(params);
857
+ return createClient2(params, createProxyFetch(connectionId));
785
858
  };
786
859
  }
787
860
 
@@ -496,6 +496,79 @@ function resolveEnvVarOptional(entry, key) {
496
496
  return process.env[envVarName] || void 0;
497
497
  }
498
498
 
499
+ // src/connector-client/proxy-fetch.ts
500
+ import { getContext } from "hono/context-storage";
501
+ import { getCookie } from "hono/cookie";
502
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
503
+ function createSandboxProxyFetch(connectionId) {
504
+ return async (input, init) => {
505
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
506
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
507
+ if (!token || !sandboxId) {
508
+ throw new Error(
509
+ "Connection proxy is not configured. Please check your deployment settings."
510
+ );
511
+ }
512
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
513
+ const originalMethod = init?.method ?? "GET";
514
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
515
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
516
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
517
+ return fetch(proxyUrl, {
518
+ method: "POST",
519
+ headers: {
520
+ "Content-Type": "application/json",
521
+ Authorization: `Bearer ${token}`
522
+ },
523
+ body: JSON.stringify({
524
+ url: originalUrl,
525
+ method: originalMethod,
526
+ body: originalBody
527
+ })
528
+ });
529
+ };
530
+ }
531
+ function createDeployedAppProxyFetch(connectionId) {
532
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
533
+ if (!projectId) {
534
+ throw new Error(
535
+ "Connection proxy is not configured. Please check your deployment settings."
536
+ );
537
+ }
538
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
539
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
540
+ return async (input, init) => {
541
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
542
+ const originalMethod = init?.method ?? "GET";
543
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
544
+ const c = getContext();
545
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
546
+ if (!appSession) {
547
+ throw new Error(
548
+ "No authentication method available for connection proxy."
549
+ );
550
+ }
551
+ return fetch(proxyUrl, {
552
+ method: "POST",
553
+ headers: {
554
+ "Content-Type": "application/json",
555
+ Authorization: `Bearer ${appSession}`
556
+ },
557
+ body: JSON.stringify({
558
+ url: originalUrl,
559
+ method: originalMethod,
560
+ body: originalBody
561
+ })
562
+ });
563
+ };
564
+ }
565
+ function createProxyFetch(connectionId) {
566
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
567
+ return createSandboxProxyFetch(connectionId);
568
+ }
569
+ return createDeployedAppProxyFetch(connectionId);
570
+ }
571
+
499
572
  // src/connectors/create-connector-sdk.ts
500
573
  function loadConnectionsSync() {
501
574
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -529,7 +602,7 @@ function createConnectorSdk(plugin, createClient2) {
529
602
  if (val !== void 0) params[param.slug] = val;
530
603
  }
531
604
  }
532
- return createClient2(params);
605
+ return createClient2(params, createProxyFetch(connectionId));
533
606
  };
534
607
  }
535
608
 
@@ -612,6 +612,79 @@ function resolveEnvVarOptional(entry, key) {
612
612
  return process.env[envVarName] || void 0;
613
613
  }
614
614
 
615
+ // src/connector-client/proxy-fetch.ts
616
+ import { getContext } from "hono/context-storage";
617
+ import { getCookie } from "hono/cookie";
618
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
619
+ function createSandboxProxyFetch(connectionId) {
620
+ return async (input, init) => {
621
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
622
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
623
+ if (!token || !sandboxId) {
624
+ throw new Error(
625
+ "Connection proxy is not configured. Please check your deployment settings."
626
+ );
627
+ }
628
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
629
+ const originalMethod = init?.method ?? "GET";
630
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
631
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
632
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
633
+ return fetch(proxyUrl, {
634
+ method: "POST",
635
+ headers: {
636
+ "Content-Type": "application/json",
637
+ Authorization: `Bearer ${token}`
638
+ },
639
+ body: JSON.stringify({
640
+ url: originalUrl,
641
+ method: originalMethod,
642
+ body: originalBody
643
+ })
644
+ });
645
+ };
646
+ }
647
+ function createDeployedAppProxyFetch(connectionId) {
648
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
649
+ if (!projectId) {
650
+ throw new Error(
651
+ "Connection proxy is not configured. Please check your deployment settings."
652
+ );
653
+ }
654
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
655
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
656
+ return async (input, init) => {
657
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
658
+ const originalMethod = init?.method ?? "GET";
659
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
660
+ const c = getContext();
661
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
662
+ if (!appSession) {
663
+ throw new Error(
664
+ "No authentication method available for connection proxy."
665
+ );
666
+ }
667
+ return fetch(proxyUrl, {
668
+ method: "POST",
669
+ headers: {
670
+ "Content-Type": "application/json",
671
+ Authorization: `Bearer ${appSession}`
672
+ },
673
+ body: JSON.stringify({
674
+ url: originalUrl,
675
+ method: originalMethod,
676
+ body: originalBody
677
+ })
678
+ });
679
+ };
680
+ }
681
+ function createProxyFetch(connectionId) {
682
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
683
+ return createSandboxProxyFetch(connectionId);
684
+ }
685
+ return createDeployedAppProxyFetch(connectionId);
686
+ }
687
+
615
688
  // src/connectors/create-connector-sdk.ts
616
689
  function loadConnectionsSync() {
617
690
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -645,7 +718,7 @@ function createConnectorSdk(plugin, createClient2) {
645
718
  if (val !== void 0) params[param.slug] = val;
646
719
  }
647
720
  }
648
- return createClient2(params);
721
+ return createClient2(params, createProxyFetch(connectionId));
649
722
  };
650
723
  }
651
724
 
@@ -450,6 +450,79 @@ function resolveEnvVarOptional(entry, key) {
450
450
  return process.env[envVarName] || void 0;
451
451
  }
452
452
 
453
+ // src/connector-client/proxy-fetch.ts
454
+ import { getContext } from "hono/context-storage";
455
+ import { getCookie } from "hono/cookie";
456
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
457
+ function createSandboxProxyFetch(connectionId) {
458
+ return async (input, init) => {
459
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
460
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
461
+ if (!token || !sandboxId) {
462
+ throw new Error(
463
+ "Connection proxy is not configured. Please check your deployment settings."
464
+ );
465
+ }
466
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
467
+ const originalMethod = init?.method ?? "GET";
468
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
469
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
470
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
471
+ return fetch(proxyUrl, {
472
+ method: "POST",
473
+ headers: {
474
+ "Content-Type": "application/json",
475
+ Authorization: `Bearer ${token}`
476
+ },
477
+ body: JSON.stringify({
478
+ url: originalUrl,
479
+ method: originalMethod,
480
+ body: originalBody
481
+ })
482
+ });
483
+ };
484
+ }
485
+ function createDeployedAppProxyFetch(connectionId) {
486
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
487
+ if (!projectId) {
488
+ throw new Error(
489
+ "Connection proxy is not configured. Please check your deployment settings."
490
+ );
491
+ }
492
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
493
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
494
+ return async (input, init) => {
495
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
496
+ const originalMethod = init?.method ?? "GET";
497
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
498
+ const c = getContext();
499
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
500
+ if (!appSession) {
501
+ throw new Error(
502
+ "No authentication method available for connection proxy."
503
+ );
504
+ }
505
+ return fetch(proxyUrl, {
506
+ method: "POST",
507
+ headers: {
508
+ "Content-Type": "application/json",
509
+ Authorization: `Bearer ${appSession}`
510
+ },
511
+ body: JSON.stringify({
512
+ url: originalUrl,
513
+ method: originalMethod,
514
+ body: originalBody
515
+ })
516
+ });
517
+ };
518
+ }
519
+ function createProxyFetch(connectionId) {
520
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
521
+ return createSandboxProxyFetch(connectionId);
522
+ }
523
+ return createDeployedAppProxyFetch(connectionId);
524
+ }
525
+
453
526
  // src/connectors/create-connector-sdk.ts
454
527
  function loadConnectionsSync() {
455
528
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -483,7 +556,7 @@ function createConnectorSdk(plugin, createClient2) {
483
556
  if (val !== void 0) params[param.slug] = val;
484
557
  }
485
558
  }
486
- return createClient2(params);
559
+ return createClient2(params, createProxyFetch(connectionId));
487
560
  };
488
561
  }
489
562