@squadbase/vite-server 0.1.3-dev.6 → 0.1.3-dev.8
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/dist/cli/index.js +1858 -1340
- package/dist/connectors/airtable-oauth.js +74 -1
- package/dist/connectors/airtable.js +74 -1
- package/dist/connectors/amplitude.js +74 -1
- package/dist/connectors/anthropic.js +74 -1
- package/dist/connectors/asana.js +74 -1
- package/dist/connectors/attio.js +74 -1
- package/dist/connectors/customerio.js +74 -1
- package/dist/connectors/dbt.js +74 -1
- package/dist/connectors/gemini.js +74 -1
- package/dist/connectors/gmail-oauth.js +74 -1
- package/dist/connectors/gmail.js +74 -1
- package/dist/connectors/google-ads-oauth.js +74 -1
- package/dist/connectors/google-ads.js +74 -1
- package/dist/connectors/google-analytics-oauth.js +87 -6
- package/dist/connectors/google-analytics.js +117 -52
- package/dist/connectors/google-calendar-oauth.js +75 -2
- package/dist/connectors/google-calendar.d.ts +1 -8
- package/dist/connectors/google-calendar.js +363 -60
- package/dist/connectors/google-sheets-oauth.js +141 -31
- package/dist/connectors/google-sheets.js +108 -9
- package/dist/connectors/grafana.d.ts +5 -0
- package/dist/connectors/grafana.js +638 -0
- package/dist/connectors/hubspot-oauth.js +74 -1
- package/dist/connectors/hubspot.js +74 -1
- package/dist/connectors/intercom-oauth.js +74 -1
- package/dist/connectors/intercom.js +74 -1
- package/dist/connectors/jira-api-key.js +74 -1
- package/dist/connectors/kintone-api-token.js +74 -1
- package/dist/connectors/kintone.js +74 -1
- package/dist/connectors/linkedin-ads-oauth.js +74 -1
- package/dist/connectors/linkedin-ads.js +74 -1
- package/dist/connectors/mailchimp-oauth.js +74 -1
- package/dist/connectors/mailchimp.js +74 -1
- package/dist/connectors/notion-oauth.js +74 -1
- package/dist/connectors/notion.js +74 -1
- package/dist/connectors/openai.js +74 -1
- package/dist/connectors/shopify-oauth.js +74 -1
- package/dist/connectors/shopify.js +74 -1
- package/dist/connectors/stripe-api-key.js +74 -1
- package/dist/connectors/stripe-oauth.js +74 -1
- package/dist/connectors/wix-store.js +74 -1
- package/dist/connectors/zendesk-oauth.js +74 -1
- package/dist/connectors/zendesk.js +74 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1808 -1291
- package/dist/main.js +1807 -1289
- package/dist/vite-plugin.js +1807 -1289
- package/package.json +5 -1
|
@@ -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
|
|
|
@@ -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
|
|