@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
@@ -780,6 +780,79 @@ function resolveEnvVarOptional(entry, key) {
780
780
  return process.env[envVarName] || void 0;
781
781
  }
782
782
 
783
+ // src/connector-client/proxy-fetch.ts
784
+ import { getContext } from "hono/context-storage";
785
+ import { getCookie } from "hono/cookie";
786
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
787
+ function createSandboxProxyFetch(connectionId) {
788
+ return async (input, init) => {
789
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
790
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
791
+ if (!token || !sandboxId) {
792
+ throw new Error(
793
+ "Connection proxy is not configured. Please check your deployment settings."
794
+ );
795
+ }
796
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
797
+ const originalMethod = init?.method ?? "GET";
798
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
799
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
800
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
801
+ return fetch(proxyUrl, {
802
+ method: "POST",
803
+ headers: {
804
+ "Content-Type": "application/json",
805
+ Authorization: `Bearer ${token}`
806
+ },
807
+ body: JSON.stringify({
808
+ url: originalUrl,
809
+ method: originalMethod,
810
+ body: originalBody
811
+ })
812
+ });
813
+ };
814
+ }
815
+ function createDeployedAppProxyFetch(connectionId) {
816
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
817
+ if (!projectId) {
818
+ throw new Error(
819
+ "Connection proxy is not configured. Please check your deployment settings."
820
+ );
821
+ }
822
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
823
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
824
+ return async (input, init) => {
825
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
826
+ const originalMethod = init?.method ?? "GET";
827
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
828
+ const c = getContext();
829
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
830
+ if (!appSession) {
831
+ throw new Error(
832
+ "No authentication method available for connection proxy."
833
+ );
834
+ }
835
+ return fetch(proxyUrl, {
836
+ method: "POST",
837
+ headers: {
838
+ "Content-Type": "application/json",
839
+ Authorization: `Bearer ${appSession}`
840
+ },
841
+ body: JSON.stringify({
842
+ url: originalUrl,
843
+ method: originalMethod,
844
+ body: originalBody
845
+ })
846
+ });
847
+ };
848
+ }
849
+ function createProxyFetch(connectionId) {
850
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
851
+ return createSandboxProxyFetch(connectionId);
852
+ }
853
+ return createDeployedAppProxyFetch(connectionId);
854
+ }
855
+
783
856
  // src/connectors/create-connector-sdk.ts
784
857
  function loadConnectionsSync() {
785
858
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -813,7 +886,7 @@ function createConnectorSdk(plugin, createClient2) {
813
886
  if (val !== void 0) params[param.slug] = val;
814
887
  }
815
888
  }
816
- return createClient2(params);
889
+ return createClient2(params, createProxyFetch(connectionId));
817
890
  };
818
891
  }
819
892
 
@@ -211,6 +211,79 @@ function resolveEnvVarOptional(entry, key) {
211
211
  return process.env[envVarName] || void 0;
212
212
  }
213
213
 
214
+ // src/connector-client/proxy-fetch.ts
215
+ import { getContext } from "hono/context-storage";
216
+ import { getCookie } from "hono/cookie";
217
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
218
+ function createSandboxProxyFetch(connectionId) {
219
+ return async (input, init) => {
220
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
221
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
222
+ if (!token || !sandboxId) {
223
+ throw new Error(
224
+ "Connection proxy is not configured. Please check your deployment settings."
225
+ );
226
+ }
227
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
228
+ const originalMethod = init?.method ?? "GET";
229
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
230
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
231
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
232
+ return fetch(proxyUrl, {
233
+ method: "POST",
234
+ headers: {
235
+ "Content-Type": "application/json",
236
+ Authorization: `Bearer ${token}`
237
+ },
238
+ body: JSON.stringify({
239
+ url: originalUrl,
240
+ method: originalMethod,
241
+ body: originalBody
242
+ })
243
+ });
244
+ };
245
+ }
246
+ function createDeployedAppProxyFetch(connectionId) {
247
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
248
+ if (!projectId) {
249
+ throw new Error(
250
+ "Connection proxy is not configured. Please check your deployment settings."
251
+ );
252
+ }
253
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
254
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
255
+ return async (input, init) => {
256
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
257
+ const originalMethod = init?.method ?? "GET";
258
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
259
+ const c = getContext();
260
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
261
+ if (!appSession) {
262
+ throw new Error(
263
+ "No authentication method available for connection proxy."
264
+ );
265
+ }
266
+ return fetch(proxyUrl, {
267
+ method: "POST",
268
+ headers: {
269
+ "Content-Type": "application/json",
270
+ Authorization: `Bearer ${appSession}`
271
+ },
272
+ body: JSON.stringify({
273
+ url: originalUrl,
274
+ method: originalMethod,
275
+ body: originalBody
276
+ })
277
+ });
278
+ };
279
+ }
280
+ function createProxyFetch(connectionId) {
281
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
282
+ return createSandboxProxyFetch(connectionId);
283
+ }
284
+ return createDeployedAppProxyFetch(connectionId);
285
+ }
286
+
214
287
  // src/connectors/create-connector-sdk.ts
215
288
  function loadConnectionsSync() {
216
289
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -244,7 +317,7 @@ function createConnectorSdk(plugin, createClient2) {
244
317
  if (val !== void 0) params[param.slug] = val;
245
318
  }
246
319
  }
247
- return createClient2(params);
320
+ return createClient2(params, createProxyFetch(connectionId));
248
321
  };
249
322
  }
250
323
 
@@ -596,6 +596,79 @@ function resolveEnvVarOptional(entry, key) {
596
596
  return process.env[envVarName] || void 0;
597
597
  }
598
598
 
599
+ // src/connector-client/proxy-fetch.ts
600
+ import { getContext } from "hono/context-storage";
601
+ import { getCookie } from "hono/cookie";
602
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
603
+ function createSandboxProxyFetch(connectionId) {
604
+ return async (input, init) => {
605
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
606
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
607
+ if (!token || !sandboxId) {
608
+ throw new Error(
609
+ "Connection proxy is not configured. Please check your deployment settings."
610
+ );
611
+ }
612
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
613
+ const originalMethod = init?.method ?? "GET";
614
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
615
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
616
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
617
+ return fetch(proxyUrl, {
618
+ method: "POST",
619
+ headers: {
620
+ "Content-Type": "application/json",
621
+ Authorization: `Bearer ${token}`
622
+ },
623
+ body: JSON.stringify({
624
+ url: originalUrl,
625
+ method: originalMethod,
626
+ body: originalBody
627
+ })
628
+ });
629
+ };
630
+ }
631
+ function createDeployedAppProxyFetch(connectionId) {
632
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
633
+ if (!projectId) {
634
+ throw new Error(
635
+ "Connection proxy is not configured. Please check your deployment settings."
636
+ );
637
+ }
638
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
639
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
640
+ return async (input, init) => {
641
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
642
+ const originalMethod = init?.method ?? "GET";
643
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
644
+ const c = getContext();
645
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
646
+ if (!appSession) {
647
+ throw new Error(
648
+ "No authentication method available for connection proxy."
649
+ );
650
+ }
651
+ return fetch(proxyUrl, {
652
+ method: "POST",
653
+ headers: {
654
+ "Content-Type": "application/json",
655
+ Authorization: `Bearer ${appSession}`
656
+ },
657
+ body: JSON.stringify({
658
+ url: originalUrl,
659
+ method: originalMethod,
660
+ body: originalBody
661
+ })
662
+ });
663
+ };
664
+ }
665
+ function createProxyFetch(connectionId) {
666
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
667
+ return createSandboxProxyFetch(connectionId);
668
+ }
669
+ return createDeployedAppProxyFetch(connectionId);
670
+ }
671
+
599
672
  // src/connectors/create-connector-sdk.ts
600
673
  function loadConnectionsSync() {
601
674
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -629,7 +702,7 @@ function createConnectorSdk(plugin, createClient2) {
629
702
  if (val !== void 0) params[param.slug] = val;
630
703
  }
631
704
  }
632
- return createClient2(params);
705
+ return createClient2(params, createProxyFetch(connectionId));
633
706
  };
634
707
  }
635
708
 
@@ -758,6 +758,79 @@ function resolveEnvVarOptional(entry, key) {
758
758
  return process.env[envVarName] || void 0;
759
759
  }
760
760
 
761
+ // src/connector-client/proxy-fetch.ts
762
+ import { getContext } from "hono/context-storage";
763
+ import { getCookie } from "hono/cookie";
764
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
765
+ function createSandboxProxyFetch(connectionId) {
766
+ return async (input, init) => {
767
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
768
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
769
+ if (!token || !sandboxId) {
770
+ throw new Error(
771
+ "Connection proxy is not configured. Please check your deployment settings."
772
+ );
773
+ }
774
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
775
+ const originalMethod = init?.method ?? "GET";
776
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
777
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
778
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
779
+ return fetch(proxyUrl, {
780
+ method: "POST",
781
+ headers: {
782
+ "Content-Type": "application/json",
783
+ Authorization: `Bearer ${token}`
784
+ },
785
+ body: JSON.stringify({
786
+ url: originalUrl,
787
+ method: originalMethod,
788
+ body: originalBody
789
+ })
790
+ });
791
+ };
792
+ }
793
+ function createDeployedAppProxyFetch(connectionId) {
794
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
795
+ if (!projectId) {
796
+ throw new Error(
797
+ "Connection proxy is not configured. Please check your deployment settings."
798
+ );
799
+ }
800
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
801
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
802
+ return async (input, init) => {
803
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
804
+ const originalMethod = init?.method ?? "GET";
805
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
806
+ const c = getContext();
807
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
808
+ if (!appSession) {
809
+ throw new Error(
810
+ "No authentication method available for connection proxy."
811
+ );
812
+ }
813
+ return fetch(proxyUrl, {
814
+ method: "POST",
815
+ headers: {
816
+ "Content-Type": "application/json",
817
+ Authorization: `Bearer ${appSession}`
818
+ },
819
+ body: JSON.stringify({
820
+ url: originalUrl,
821
+ method: originalMethod,
822
+ body: originalBody
823
+ })
824
+ });
825
+ };
826
+ }
827
+ function createProxyFetch(connectionId) {
828
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
829
+ return createSandboxProxyFetch(connectionId);
830
+ }
831
+ return createDeployedAppProxyFetch(connectionId);
832
+ }
833
+
761
834
  // src/connectors/create-connector-sdk.ts
762
835
  function loadConnectionsSync() {
763
836
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -791,7 +864,7 @@ function createConnectorSdk(plugin, createClient2) {
791
864
  if (val !== void 0) params[param.slug] = val;
792
865
  }
793
866
  }
794
- return createClient2(params);
867
+ return createClient2(params, createProxyFetch(connectionId));
795
868
  };
796
869
  }
797
870
 
@@ -773,6 +773,79 @@ function resolveEnvVarOptional(entry, key) {
773
773
  return process.env[envVarName] || void 0;
774
774
  }
775
775
 
776
+ // src/connector-client/proxy-fetch.ts
777
+ import { getContext } from "hono/context-storage";
778
+ import { getCookie } from "hono/cookie";
779
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
780
+ function createSandboxProxyFetch(connectionId) {
781
+ return async (input, init) => {
782
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
783
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
784
+ if (!token || !sandboxId) {
785
+ throw new Error(
786
+ "Connection proxy is not configured. Please check your deployment settings."
787
+ );
788
+ }
789
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
790
+ const originalMethod = init?.method ?? "GET";
791
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
792
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
793
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
794
+ return fetch(proxyUrl, {
795
+ method: "POST",
796
+ headers: {
797
+ "Content-Type": "application/json",
798
+ Authorization: `Bearer ${token}`
799
+ },
800
+ body: JSON.stringify({
801
+ url: originalUrl,
802
+ method: originalMethod,
803
+ body: originalBody
804
+ })
805
+ });
806
+ };
807
+ }
808
+ function createDeployedAppProxyFetch(connectionId) {
809
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
810
+ if (!projectId) {
811
+ throw new Error(
812
+ "Connection proxy is not configured. Please check your deployment settings."
813
+ );
814
+ }
815
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
816
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
817
+ return async (input, init) => {
818
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
819
+ const originalMethod = init?.method ?? "GET";
820
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
821
+ const c = getContext();
822
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
823
+ if (!appSession) {
824
+ throw new Error(
825
+ "No authentication method available for connection proxy."
826
+ );
827
+ }
828
+ return fetch(proxyUrl, {
829
+ method: "POST",
830
+ headers: {
831
+ "Content-Type": "application/json",
832
+ Authorization: `Bearer ${appSession}`
833
+ },
834
+ body: JSON.stringify({
835
+ url: originalUrl,
836
+ method: originalMethod,
837
+ body: originalBody
838
+ })
839
+ });
840
+ };
841
+ }
842
+ function createProxyFetch(connectionId) {
843
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
844
+ return createSandboxProxyFetch(connectionId);
845
+ }
846
+ return createDeployedAppProxyFetch(connectionId);
847
+ }
848
+
776
849
  // src/connectors/create-connector-sdk.ts
777
850
  function loadConnectionsSync() {
778
851
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -806,7 +879,7 @@ function createConnectorSdk(plugin, createClient2) {
806
879
  if (val !== void 0) params[param.slug] = val;
807
880
  }
808
881
  }
809
- return createClient2(params);
882
+ return createClient2(params, createProxyFetch(connectionId));
810
883
  };
811
884
  }
812
885
 
@@ -750,6 +750,79 @@ function resolveEnvVarOptional(entry, key) {
750
750
  return process.env[envVarName] || void 0;
751
751
  }
752
752
 
753
+ // src/connector-client/proxy-fetch.ts
754
+ import { getContext } from "hono/context-storage";
755
+ import { getCookie } from "hono/cookie";
756
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
757
+ function createSandboxProxyFetch(connectionId) {
758
+ return async (input, init) => {
759
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
760
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
761
+ if (!token || !sandboxId) {
762
+ throw new Error(
763
+ "Connection proxy is not configured. Please check your deployment settings."
764
+ );
765
+ }
766
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
767
+ const originalMethod = init?.method ?? "GET";
768
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
769
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
770
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
771
+ return fetch(proxyUrl, {
772
+ method: "POST",
773
+ headers: {
774
+ "Content-Type": "application/json",
775
+ Authorization: `Bearer ${token}`
776
+ },
777
+ body: JSON.stringify({
778
+ url: originalUrl,
779
+ method: originalMethod,
780
+ body: originalBody
781
+ })
782
+ });
783
+ };
784
+ }
785
+ function createDeployedAppProxyFetch(connectionId) {
786
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
787
+ if (!projectId) {
788
+ throw new Error(
789
+ "Connection proxy is not configured. Please check your deployment settings."
790
+ );
791
+ }
792
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
793
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
794
+ return async (input, init) => {
795
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
796
+ const originalMethod = init?.method ?? "GET";
797
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
798
+ const c = getContext();
799
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
800
+ if (!appSession) {
801
+ throw new Error(
802
+ "No authentication method available for connection proxy."
803
+ );
804
+ }
805
+ return fetch(proxyUrl, {
806
+ method: "POST",
807
+ headers: {
808
+ "Content-Type": "application/json",
809
+ Authorization: `Bearer ${appSession}`
810
+ },
811
+ body: JSON.stringify({
812
+ url: originalUrl,
813
+ method: originalMethod,
814
+ body: originalBody
815
+ })
816
+ });
817
+ };
818
+ }
819
+ function createProxyFetch(connectionId) {
820
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
821
+ return createSandboxProxyFetch(connectionId);
822
+ }
823
+ return createDeployedAppProxyFetch(connectionId);
824
+ }
825
+
753
826
  // src/connectors/create-connector-sdk.ts
754
827
  function loadConnectionsSync() {
755
828
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -783,7 +856,7 @@ function createConnectorSdk(plugin, createClient2) {
783
856
  if (val !== void 0) params[param.slug] = val;
784
857
  }
785
858
  }
786
- return createClient2(params);
859
+ return createClient2(params, createProxyFetch(connectionId));
787
860
  };
788
861
  }
789
862
 
@@ -57,7 +57,7 @@ var parameters = {
57
57
 
58
58
  // ../connectors/src/connectors/google-analytics-oauth/sdk/index.ts
59
59
  var BASE_URL = "https://analyticsdata.googleapis.com/v1beta/";
60
- function createClient(params, fetchFn = fetch) {
60
+ function createClient(params, fetchFn) {
61
61
  const propertyId = params[parameters.propertyId.slug];
62
62
  function resolvePropertyId() {
63
63
  if (!propertyId) {
@@ -483,12 +483,15 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
483
483
  ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Analytics (OAuth) \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
484
484
 
485
485
  1. \`${listAccountsToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001OAuth\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGoogle Analytics\u30A2\u30AB\u30A6\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
486
- 2. \u300C\u4F7F\u7528\u3059\u308B\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u300D\u3068\u30E6\u30FC\u30B6\u30FC\u306B\u4F1D\u3048\u305F\u4E0A\u3067\u3001\`askUserQuestion\` \u3092\u547C\u3073\u51FA\u3059:
487
- - \`options\`: \u30A2\u30AB\u30A6\u30F3\u30C8\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u8868\u793A\u540D (name)\` \u306E\u5F62\u5F0F
486
+ 2. \u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u9078\u629E:
487
+ - \u30A2\u30AB\u30A6\u30F3\u30C8\u304C **2\u4EF6\u4EE5\u4E0A**: \u300C\u4F7F\u7528\u3059\u308B\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u300D\u3068\u30E6\u30FC\u30B6\u30FC\u306B\u4F1D\u3048\u305F\u4E0A\u3067\u3001\`askUserQuestion\` \u3092\u547C\u3073\u51FA\u3059\uFF08\`options\`: \u5404 option \u306E \`label\` \u306F \`\u8868\u793A\u540D (name)\` \u306E\u5F62\u5F0F\uFF09
488
+ - \u30A2\u30AB\u30A6\u30F3\u30C8\u304C **1\u4EF6\u306E\u307F**: \`askUserQuestion\` \u306F\u30B9\u30AD\u30C3\u30D7\u3057\u3001\u305D\u306E\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u9078\u629E\u6E08\u307F\u3068\u3057\u3066\u6B21\u3078\u9032\u3080
489
+ - \u30A2\u30AB\u30A6\u30F3\u30C8\u304C **0\u4EF6**: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u4E2D\u65AD\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30A2\u30AB\u30A6\u30F3\u30C8\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B
488
490
  3. \`${listPropertiesToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u9078\u629E\u3055\u308C\u305F\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
489
491
  4. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
490
492
  - \`parameterSlug\`: \`"property-id"\`
491
493
  - \`options\`: \u30D7\u30ED\u30D1\u30C6\u30A3\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u8868\u793A\u540D (id: \u30D7\u30ED\u30D1\u30C6\u30A3ID)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F\u30D7\u30ED\u30D1\u30C6\u30A3ID
494
+ - \u30D7\u30ED\u30D1\u30C6\u30A3\u304C **0\u4EF6** \u306E\u5834\u5408\u306F\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u4E2D\u65AD\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B
492
495
  5. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30D7\u30ED\u30D1\u30C6\u30A3\u306E \`label\` \u304C\u30E1\u30C3\u30BB\u30FC\u30B8\u3068\u3057\u3066\u5C4A\u304F\u306E\u3067\u3001\u6B21\u306E\u30B9\u30C6\u30C3\u30D7\u306B\u9032\u3080
493
496
  6. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
494
497
  - \`property\`: \u9078\u629E\u3055\u308C\u305F\u30D7\u30ED\u30D1\u30C6\u30A3\u306E\u8868\u793A\u540D
@@ -497,16 +500,20 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
497
500
 
498
501
  #### \u5236\u7D04
499
502
  - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30EC\u30DD\u30FC\u30C8\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u306E\u307F
503
+ - \`askUserQuestion\` \u306E \`options\` \u306F\u6700\u4F4E2\u4EF6\u5FC5\u8981\u3002\u5019\u88DC\u304C1\u4EF6\u4EE5\u4E0B\u306E\u5834\u5408\u306F\u5FC5\u305A\u30B9\u30AD\u30C3\u30D7\u3059\u308B\u3053\u3068
500
504
  - \u30C4\u30FC\u30EB\u9593\u306F1\u6587\u3060\u3051\u66F8\u3044\u3066\u5373\u6B21\u306E\u30C4\u30FC\u30EB\u547C\u3073\u51FA\u3057\u3002\u4E0D\u8981\u306A\u8AAC\u660E\u306F\u7701\u7565\u3057\u3001\u52B9\u7387\u7684\u306B\u9032\u3081\u308B`,
501
505
  en: `Follow these steps to set up the Google Analytics (OAuth) connection.
502
506
 
503
507
  1. Call \`${listAccountsToolName}\` to get the list of Google Analytics accounts accessible with the OAuth credentials
504
- 2. Tell the user "Please select an account.", then call \`askUserQuestion\`:
505
- - \`options\`: The account list. Each option's \`label\` should be \`Display Name (name)\`
508
+ 2. Select an account:
509
+ - **2 or more accounts**: Tell the user "Please select an account.", then call \`askUserQuestion\` (\`options\`: each option's \`label\` should be \`Display Name (name)\`)
510
+ - **Only 1 account**: Skip \`askUserQuestion\` and proceed using that account as the selection
511
+ - **0 accounts**: Abort setup and inform the user that no accessible accounts are available
506
512
  3. Call \`${listPropertiesToolName}\` to get the list of properties for the selected account
507
513
  4. Call \`updateConnectionParameters\`:
508
514
  - \`parameterSlug\`: \`"property-id"\`
509
515
  - \`options\`: The property list. Each option's \`label\` should be \`Display Name (id: propertyId)\`, \`value\` should be the property ID
516
+ - If **0 properties** are returned, abort setup and inform the user that no accessible properties are available
510
517
  5. The \`label\` of the user's selected property will arrive as a message. Proceed to the next step
511
518
  6. Call \`updateConnectionContext\`:
512
519
  - \`property\`: The selected property's display name
@@ -515,6 +522,7 @@ var googleAnalyticsOauthOnboarding = new ConnectorOnboarding({
515
522
 
516
523
  #### Constraints
517
524
  - **Do NOT fetch report data during setup**. Only the metadata requests specified in the steps above are allowed
525
+ - \`askUserQuestion\` requires at least 2 \`options\`. Always skip it when there is 1 or fewer candidates
518
526
  - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
519
527
  },
520
528
  dataOverviewInstructions: {
@@ -847,6 +855,79 @@ function resolveEnvVarOptional(entry, key) {
847
855
  return process.env[envVarName] || void 0;
848
856
  }
849
857
 
858
+ // src/connector-client/proxy-fetch.ts
859
+ import { getContext } from "hono/context-storage";
860
+ import { getCookie } from "hono/cookie";
861
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
862
+ function createSandboxProxyFetch(connectionId) {
863
+ return async (input, init) => {
864
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
865
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
866
+ if (!token || !sandboxId) {
867
+ throw new Error(
868
+ "Connection proxy is not configured. Please check your deployment settings."
869
+ );
870
+ }
871
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
872
+ const originalMethod = init?.method ?? "GET";
873
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
874
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
875
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
876
+ return fetch(proxyUrl, {
877
+ method: "POST",
878
+ headers: {
879
+ "Content-Type": "application/json",
880
+ Authorization: `Bearer ${token}`
881
+ },
882
+ body: JSON.stringify({
883
+ url: originalUrl,
884
+ method: originalMethod,
885
+ body: originalBody
886
+ })
887
+ });
888
+ };
889
+ }
890
+ function createDeployedAppProxyFetch(connectionId) {
891
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
892
+ if (!projectId) {
893
+ throw new Error(
894
+ "Connection proxy is not configured. Please check your deployment settings."
895
+ );
896
+ }
897
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
898
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
899
+ return async (input, init) => {
900
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
901
+ const originalMethod = init?.method ?? "GET";
902
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
903
+ const c = getContext();
904
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
905
+ if (!appSession) {
906
+ throw new Error(
907
+ "No authentication method available for connection proxy."
908
+ );
909
+ }
910
+ return fetch(proxyUrl, {
911
+ method: "POST",
912
+ headers: {
913
+ "Content-Type": "application/json",
914
+ Authorization: `Bearer ${appSession}`
915
+ },
916
+ body: JSON.stringify({
917
+ url: originalUrl,
918
+ method: originalMethod,
919
+ body: originalBody
920
+ })
921
+ });
922
+ };
923
+ }
924
+ function createProxyFetch(connectionId) {
925
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
926
+ return createSandboxProxyFetch(connectionId);
927
+ }
928
+ return createDeployedAppProxyFetch(connectionId);
929
+ }
930
+
850
931
  // src/connectors/create-connector-sdk.ts
851
932
  function loadConnectionsSync() {
852
933
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -880,7 +961,7 @@ function createConnectorSdk(plugin, createClient2) {
880
961
  if (val !== void 0) params[param.slug] = val;
881
962
  }
882
963
  }
883
- return createClient2(params);
964
+ return createClient2(params, createProxyFetch(connectionId));
884
965
  };
885
966
  }
886
967