@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
@@ -546,6 +546,79 @@ function resolveEnvVarOptional(entry, key) {
546
546
  return process.env[envVarName] || void 0;
547
547
  }
548
548
 
549
+ // src/connector-client/proxy-fetch.ts
550
+ import { getContext } from "hono/context-storage";
551
+ import { getCookie } from "hono/cookie";
552
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
553
+ function createSandboxProxyFetch(connectionId) {
554
+ return async (input, init) => {
555
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
556
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
557
+ if (!token || !sandboxId) {
558
+ throw new Error(
559
+ "Connection proxy is not configured. Please check your deployment settings."
560
+ );
561
+ }
562
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
563
+ const originalMethod = init?.method ?? "GET";
564
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
565
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
566
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
567
+ return fetch(proxyUrl, {
568
+ method: "POST",
569
+ headers: {
570
+ "Content-Type": "application/json",
571
+ Authorization: `Bearer ${token}`
572
+ },
573
+ body: JSON.stringify({
574
+ url: originalUrl,
575
+ method: originalMethod,
576
+ body: originalBody
577
+ })
578
+ });
579
+ };
580
+ }
581
+ function createDeployedAppProxyFetch(connectionId) {
582
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
583
+ if (!projectId) {
584
+ throw new Error(
585
+ "Connection proxy is not configured. Please check your deployment settings."
586
+ );
587
+ }
588
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
589
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
590
+ return async (input, init) => {
591
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
592
+ const originalMethod = init?.method ?? "GET";
593
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
594
+ const c = getContext();
595
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
596
+ if (!appSession) {
597
+ throw new Error(
598
+ "No authentication method available for connection proxy."
599
+ );
600
+ }
601
+ return fetch(proxyUrl, {
602
+ method: "POST",
603
+ headers: {
604
+ "Content-Type": "application/json",
605
+ Authorization: `Bearer ${appSession}`
606
+ },
607
+ body: JSON.stringify({
608
+ url: originalUrl,
609
+ method: originalMethod,
610
+ body: originalBody
611
+ })
612
+ });
613
+ };
614
+ }
615
+ function createProxyFetch(connectionId) {
616
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
617
+ return createSandboxProxyFetch(connectionId);
618
+ }
619
+ return createDeployedAppProxyFetch(connectionId);
620
+ }
621
+
549
622
  // src/connectors/create-connector-sdk.ts
550
623
  function loadConnectionsSync() {
551
624
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -579,7 +652,7 @@ function createConnectorSdk(plugin, createClient2) {
579
652
  if (val !== void 0) params[param.slug] = val;
580
653
  }
581
654
  }
582
- return createClient2(params);
655
+ return createClient2(params, createProxyFetch(connectionId));
583
656
  };
584
657
  }
585
658
 
@@ -217,6 +217,79 @@ function resolveEnvVarOptional(entry, key) {
217
217
  return process.env[envVarName] || void 0;
218
218
  }
219
219
 
220
+ // src/connector-client/proxy-fetch.ts
221
+ import { getContext } from "hono/context-storage";
222
+ import { getCookie } from "hono/cookie";
223
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
224
+ function createSandboxProxyFetch(connectionId) {
225
+ return async (input, init) => {
226
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
227
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
228
+ if (!token || !sandboxId) {
229
+ throw new Error(
230
+ "Connection proxy is not configured. Please check your deployment settings."
231
+ );
232
+ }
233
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
234
+ const originalMethod = init?.method ?? "GET";
235
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
236
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
237
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
238
+ return fetch(proxyUrl, {
239
+ method: "POST",
240
+ headers: {
241
+ "Content-Type": "application/json",
242
+ Authorization: `Bearer ${token}`
243
+ },
244
+ body: JSON.stringify({
245
+ url: originalUrl,
246
+ method: originalMethod,
247
+ body: originalBody
248
+ })
249
+ });
250
+ };
251
+ }
252
+ function createDeployedAppProxyFetch(connectionId) {
253
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
254
+ if (!projectId) {
255
+ throw new Error(
256
+ "Connection proxy is not configured. Please check your deployment settings."
257
+ );
258
+ }
259
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
260
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
261
+ return async (input, init) => {
262
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
263
+ const originalMethod = init?.method ?? "GET";
264
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
265
+ const c = getContext();
266
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
267
+ if (!appSession) {
268
+ throw new Error(
269
+ "No authentication method available for connection proxy."
270
+ );
271
+ }
272
+ return fetch(proxyUrl, {
273
+ method: "POST",
274
+ headers: {
275
+ "Content-Type": "application/json",
276
+ Authorization: `Bearer ${appSession}`
277
+ },
278
+ body: JSON.stringify({
279
+ url: originalUrl,
280
+ method: originalMethod,
281
+ body: originalBody
282
+ })
283
+ });
284
+ };
285
+ }
286
+ function createProxyFetch(connectionId) {
287
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
288
+ return createSandboxProxyFetch(connectionId);
289
+ }
290
+ return createDeployedAppProxyFetch(connectionId);
291
+ }
292
+
220
293
  // src/connectors/create-connector-sdk.ts
221
294
  function loadConnectionsSync() {
222
295
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -250,7 +323,7 @@ function createConnectorSdk(plugin, createClient2) {
250
323
  if (val !== void 0) params[param.slug] = val;
251
324
  }
252
325
  }
253
- return createClient2(params);
326
+ return createClient2(params, createProxyFetch(connectionId));
254
327
  };
255
328
  }
256
329
 
@@ -435,6 +435,79 @@ function resolveEnvVarOptional(entry, key) {
435
435
  return process.env[envVarName] || void 0;
436
436
  }
437
437
 
438
+ // src/connector-client/proxy-fetch.ts
439
+ import { getContext } from "hono/context-storage";
440
+ import { getCookie } from "hono/cookie";
441
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
442
+ function createSandboxProxyFetch(connectionId) {
443
+ return async (input, init) => {
444
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
445
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
446
+ if (!token || !sandboxId) {
447
+ throw new Error(
448
+ "Connection proxy is not configured. Please check your deployment settings."
449
+ );
450
+ }
451
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
452
+ const originalMethod = init?.method ?? "GET";
453
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
454
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
455
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
456
+ return fetch(proxyUrl, {
457
+ method: "POST",
458
+ headers: {
459
+ "Content-Type": "application/json",
460
+ Authorization: `Bearer ${token}`
461
+ },
462
+ body: JSON.stringify({
463
+ url: originalUrl,
464
+ method: originalMethod,
465
+ body: originalBody
466
+ })
467
+ });
468
+ };
469
+ }
470
+ function createDeployedAppProxyFetch(connectionId) {
471
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
472
+ if (!projectId) {
473
+ throw new Error(
474
+ "Connection proxy is not configured. Please check your deployment settings."
475
+ );
476
+ }
477
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
478
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
479
+ return async (input, init) => {
480
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
481
+ const originalMethod = init?.method ?? "GET";
482
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
483
+ const c = getContext();
484
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
485
+ if (!appSession) {
486
+ throw new Error(
487
+ "No authentication method available for connection proxy."
488
+ );
489
+ }
490
+ return fetch(proxyUrl, {
491
+ method: "POST",
492
+ headers: {
493
+ "Content-Type": "application/json",
494
+ Authorization: `Bearer ${appSession}`
495
+ },
496
+ body: JSON.stringify({
497
+ url: originalUrl,
498
+ method: originalMethod,
499
+ body: originalBody
500
+ })
501
+ });
502
+ };
503
+ }
504
+ function createProxyFetch(connectionId) {
505
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
506
+ return createSandboxProxyFetch(connectionId);
507
+ }
508
+ return createDeployedAppProxyFetch(connectionId);
509
+ }
510
+
438
511
  // src/connectors/create-connector-sdk.ts
439
512
  function loadConnectionsSync() {
440
513
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -468,7 +541,7 @@ function createConnectorSdk(plugin, createClient2) {
468
541
  if (val !== void 0) params[param.slug] = val;
469
542
  }
470
543
  }
471
- return createClient2(params);
544
+ return createClient2(params, createProxyFetch(connectionId));
472
545
  };
473
546
  }
474
547
 
@@ -688,6 +688,79 @@ function resolveEnvVarOptional(entry, key) {
688
688
  return process.env[envVarName] || void 0;
689
689
  }
690
690
 
691
+ // src/connector-client/proxy-fetch.ts
692
+ import { getContext } from "hono/context-storage";
693
+ import { getCookie } from "hono/cookie";
694
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
695
+ function createSandboxProxyFetch(connectionId) {
696
+ return async (input, init) => {
697
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
698
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
699
+ if (!token || !sandboxId) {
700
+ throw new Error(
701
+ "Connection proxy is not configured. Please check your deployment settings."
702
+ );
703
+ }
704
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
705
+ const originalMethod = init?.method ?? "GET";
706
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
707
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
708
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
709
+ return fetch(proxyUrl, {
710
+ method: "POST",
711
+ headers: {
712
+ "Content-Type": "application/json",
713
+ Authorization: `Bearer ${token}`
714
+ },
715
+ body: JSON.stringify({
716
+ url: originalUrl,
717
+ method: originalMethod,
718
+ body: originalBody
719
+ })
720
+ });
721
+ };
722
+ }
723
+ function createDeployedAppProxyFetch(connectionId) {
724
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
725
+ if (!projectId) {
726
+ throw new Error(
727
+ "Connection proxy is not configured. Please check your deployment settings."
728
+ );
729
+ }
730
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
731
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
732
+ return async (input, init) => {
733
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
734
+ const originalMethod = init?.method ?? "GET";
735
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
736
+ const c = getContext();
737
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
738
+ if (!appSession) {
739
+ throw new Error(
740
+ "No authentication method available for connection proxy."
741
+ );
742
+ }
743
+ return fetch(proxyUrl, {
744
+ method: "POST",
745
+ headers: {
746
+ "Content-Type": "application/json",
747
+ Authorization: `Bearer ${appSession}`
748
+ },
749
+ body: JSON.stringify({
750
+ url: originalUrl,
751
+ method: originalMethod,
752
+ body: originalBody
753
+ })
754
+ });
755
+ };
756
+ }
757
+ function createProxyFetch(connectionId) {
758
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
759
+ return createSandboxProxyFetch(connectionId);
760
+ }
761
+ return createDeployedAppProxyFetch(connectionId);
762
+ }
763
+
691
764
  // src/connectors/create-connector-sdk.ts
692
765
  function loadConnectionsSync() {
693
766
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -721,7 +794,7 @@ function createConnectorSdk(plugin, createClient2) {
721
794
  if (val !== void 0) params[param.slug] = val;
722
795
  }
723
796
  }
724
- return createClient2(params);
797
+ return createClient2(params, createProxyFetch(connectionId));
725
798
  };
726
799
  }
727
800
 
@@ -483,6 +483,79 @@ function resolveEnvVarOptional(entry, key) {
483
483
  return process.env[envVarName] || void 0;
484
484
  }
485
485
 
486
+ // src/connector-client/proxy-fetch.ts
487
+ import { getContext } from "hono/context-storage";
488
+ import { getCookie } from "hono/cookie";
489
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
490
+ function createSandboxProxyFetch(connectionId) {
491
+ return async (input, init) => {
492
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
493
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
494
+ if (!token || !sandboxId) {
495
+ throw new Error(
496
+ "Connection proxy is not configured. Please check your deployment settings."
497
+ );
498
+ }
499
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
500
+ const originalMethod = init?.method ?? "GET";
501
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
502
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
503
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
504
+ return fetch(proxyUrl, {
505
+ method: "POST",
506
+ headers: {
507
+ "Content-Type": "application/json",
508
+ Authorization: `Bearer ${token}`
509
+ },
510
+ body: JSON.stringify({
511
+ url: originalUrl,
512
+ method: originalMethod,
513
+ body: originalBody
514
+ })
515
+ });
516
+ };
517
+ }
518
+ function createDeployedAppProxyFetch(connectionId) {
519
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
520
+ if (!projectId) {
521
+ throw new Error(
522
+ "Connection proxy is not configured. Please check your deployment settings."
523
+ );
524
+ }
525
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
526
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
527
+ return async (input, init) => {
528
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
529
+ const originalMethod = init?.method ?? "GET";
530
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
531
+ const c = getContext();
532
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
533
+ if (!appSession) {
534
+ throw new Error(
535
+ "No authentication method available for connection proxy."
536
+ );
537
+ }
538
+ return fetch(proxyUrl, {
539
+ method: "POST",
540
+ headers: {
541
+ "Content-Type": "application/json",
542
+ Authorization: `Bearer ${appSession}`
543
+ },
544
+ body: JSON.stringify({
545
+ url: originalUrl,
546
+ method: originalMethod,
547
+ body: originalBody
548
+ })
549
+ });
550
+ };
551
+ }
552
+ function createProxyFetch(connectionId) {
553
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
554
+ return createSandboxProxyFetch(connectionId);
555
+ }
556
+ return createDeployedAppProxyFetch(connectionId);
557
+ }
558
+
486
559
  // src/connectors/create-connector-sdk.ts
487
560
  function loadConnectionsSync() {
488
561
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -516,7 +589,7 @@ function createConnectorSdk(plugin, createClient2) {
516
589
  if (val !== void 0) params[param.slug] = val;
517
590
  }
518
591
  }
519
- return createClient2(params);
592
+ return createClient2(params, createProxyFetch(connectionId));
520
593
  };
521
594
  }
522
595
 
@@ -442,6 +442,79 @@ function resolveEnvVarOptional(entry, key) {
442
442
  return process.env[envVarName] || void 0;
443
443
  }
444
444
 
445
+ // src/connector-client/proxy-fetch.ts
446
+ import { getContext } from "hono/context-storage";
447
+ import { getCookie } from "hono/cookie";
448
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
449
+ function createSandboxProxyFetch(connectionId) {
450
+ return async (input, init) => {
451
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
452
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
453
+ if (!token || !sandboxId) {
454
+ throw new Error(
455
+ "Connection proxy is not configured. Please check your deployment settings."
456
+ );
457
+ }
458
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
459
+ const originalMethod = init?.method ?? "GET";
460
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
461
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
462
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
463
+ return fetch(proxyUrl, {
464
+ method: "POST",
465
+ headers: {
466
+ "Content-Type": "application/json",
467
+ Authorization: `Bearer ${token}`
468
+ },
469
+ body: JSON.stringify({
470
+ url: originalUrl,
471
+ method: originalMethod,
472
+ body: originalBody
473
+ })
474
+ });
475
+ };
476
+ }
477
+ function createDeployedAppProxyFetch(connectionId) {
478
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
479
+ if (!projectId) {
480
+ throw new Error(
481
+ "Connection proxy is not configured. Please check your deployment settings."
482
+ );
483
+ }
484
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
485
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
486
+ return async (input, init) => {
487
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
488
+ const originalMethod = init?.method ?? "GET";
489
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
490
+ const c = getContext();
491
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
492
+ if (!appSession) {
493
+ throw new Error(
494
+ "No authentication method available for connection proxy."
495
+ );
496
+ }
497
+ return fetch(proxyUrl, {
498
+ method: "POST",
499
+ headers: {
500
+ "Content-Type": "application/json",
501
+ Authorization: `Bearer ${appSession}`
502
+ },
503
+ body: JSON.stringify({
504
+ url: originalUrl,
505
+ method: originalMethod,
506
+ body: originalBody
507
+ })
508
+ });
509
+ };
510
+ }
511
+ function createProxyFetch(connectionId) {
512
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
513
+ return createSandboxProxyFetch(connectionId);
514
+ }
515
+ return createDeployedAppProxyFetch(connectionId);
516
+ }
517
+
445
518
  // src/connectors/create-connector-sdk.ts
446
519
  function loadConnectionsSync() {
447
520
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -475,7 +548,7 @@ function createConnectorSdk(plugin, createClient2) {
475
548
  if (val !== void 0) params[param.slug] = val;
476
549
  }
477
550
  }
478
- return createClient2(params);
551
+ return createClient2(params, createProxyFetch(connectionId));
479
552
  };
480
553
  }
481
554
 
@@ -577,6 +577,79 @@ function resolveEnvVarOptional(entry, key) {
577
577
  return process.env[envVarName] || void 0;
578
578
  }
579
579
 
580
+ // src/connector-client/proxy-fetch.ts
581
+ import { getContext } from "hono/context-storage";
582
+ import { getCookie } from "hono/cookie";
583
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
584
+ function createSandboxProxyFetch(connectionId) {
585
+ return async (input, init) => {
586
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
587
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
588
+ if (!token || !sandboxId) {
589
+ throw new Error(
590
+ "Connection proxy is not configured. Please check your deployment settings."
591
+ );
592
+ }
593
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
594
+ const originalMethod = init?.method ?? "GET";
595
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
596
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
597
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
598
+ return fetch(proxyUrl, {
599
+ method: "POST",
600
+ headers: {
601
+ "Content-Type": "application/json",
602
+ Authorization: `Bearer ${token}`
603
+ },
604
+ body: JSON.stringify({
605
+ url: originalUrl,
606
+ method: originalMethod,
607
+ body: originalBody
608
+ })
609
+ });
610
+ };
611
+ }
612
+ function createDeployedAppProxyFetch(connectionId) {
613
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
614
+ if (!projectId) {
615
+ throw new Error(
616
+ "Connection proxy is not configured. Please check your deployment settings."
617
+ );
618
+ }
619
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
620
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
621
+ return async (input, init) => {
622
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
623
+ const originalMethod = init?.method ?? "GET";
624
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
625
+ const c = getContext();
626
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
627
+ if (!appSession) {
628
+ throw new Error(
629
+ "No authentication method available for connection proxy."
630
+ );
631
+ }
632
+ return fetch(proxyUrl, {
633
+ method: "POST",
634
+ headers: {
635
+ "Content-Type": "application/json",
636
+ Authorization: `Bearer ${appSession}`
637
+ },
638
+ body: JSON.stringify({
639
+ url: originalUrl,
640
+ method: originalMethod,
641
+ body: originalBody
642
+ })
643
+ });
644
+ };
645
+ }
646
+ function createProxyFetch(connectionId) {
647
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
648
+ return createSandboxProxyFetch(connectionId);
649
+ }
650
+ return createDeployedAppProxyFetch(connectionId);
651
+ }
652
+
580
653
  // src/connectors/create-connector-sdk.ts
581
654
  function loadConnectionsSync() {
582
655
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -610,7 +683,7 @@ function createConnectorSdk(plugin, createClient2) {
610
683
  if (val !== void 0) params[param.slug] = val;
611
684
  }
612
685
  }
613
- return createClient2(params);
686
+ return createClient2(params, createProxyFetch(connectionId));
614
687
  };
615
688
  }
616
689