@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
|
@@ -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
|
|
|
@@ -507,6 +507,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
507
507
|
return process.env[envVarName] || void 0;
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
// src/connector-client/proxy-fetch.ts
|
|
511
|
+
import { getContext } from "hono/context-storage";
|
|
512
|
+
import { getCookie } from "hono/cookie";
|
|
513
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
514
|
+
function createSandboxProxyFetch(connectionId) {
|
|
515
|
+
return async (input, init) => {
|
|
516
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
517
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
518
|
+
if (!token || !sandboxId) {
|
|
519
|
+
throw new Error(
|
|
520
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
524
|
+
const originalMethod = init?.method ?? "GET";
|
|
525
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
526
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
527
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
528
|
+
return fetch(proxyUrl, {
|
|
529
|
+
method: "POST",
|
|
530
|
+
headers: {
|
|
531
|
+
"Content-Type": "application/json",
|
|
532
|
+
Authorization: `Bearer ${token}`
|
|
533
|
+
},
|
|
534
|
+
body: JSON.stringify({
|
|
535
|
+
url: originalUrl,
|
|
536
|
+
method: originalMethod,
|
|
537
|
+
body: originalBody
|
|
538
|
+
})
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
543
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
544
|
+
if (!projectId) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
550
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
551
|
+
return async (input, init) => {
|
|
552
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
553
|
+
const originalMethod = init?.method ?? "GET";
|
|
554
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
555
|
+
const c = getContext();
|
|
556
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
557
|
+
if (!appSession) {
|
|
558
|
+
throw new Error(
|
|
559
|
+
"No authentication method available for connection proxy."
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
return fetch(proxyUrl, {
|
|
563
|
+
method: "POST",
|
|
564
|
+
headers: {
|
|
565
|
+
"Content-Type": "application/json",
|
|
566
|
+
Authorization: `Bearer ${appSession}`
|
|
567
|
+
},
|
|
568
|
+
body: JSON.stringify({
|
|
569
|
+
url: originalUrl,
|
|
570
|
+
method: originalMethod,
|
|
571
|
+
body: originalBody
|
|
572
|
+
})
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
function createProxyFetch(connectionId) {
|
|
577
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
578
|
+
return createSandboxProxyFetch(connectionId);
|
|
579
|
+
}
|
|
580
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
581
|
+
}
|
|
582
|
+
|
|
510
583
|
// src/connectors/create-connector-sdk.ts
|
|
511
584
|
function loadConnectionsSync() {
|
|
512
585
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -540,7 +613,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
540
613
|
if (val !== void 0) params[param.slug] = val;
|
|
541
614
|
}
|
|
542
615
|
}
|
|
543
|
-
return createClient2(params);
|
|
616
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
544
617
|
};
|
|
545
618
|
}
|
|
546
619
|
|
|
@@ -467,6 +467,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
467
467
|
return process.env[envVarName] || void 0;
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
+
// src/connector-client/proxy-fetch.ts
|
|
471
|
+
import { getContext } from "hono/context-storage";
|
|
472
|
+
import { getCookie } from "hono/cookie";
|
|
473
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
474
|
+
function createSandboxProxyFetch(connectionId) {
|
|
475
|
+
return async (input, init) => {
|
|
476
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
477
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
478
|
+
if (!token || !sandboxId) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
484
|
+
const originalMethod = init?.method ?? "GET";
|
|
485
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
486
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
487
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
488
|
+
return fetch(proxyUrl, {
|
|
489
|
+
method: "POST",
|
|
490
|
+
headers: {
|
|
491
|
+
"Content-Type": "application/json",
|
|
492
|
+
Authorization: `Bearer ${token}`
|
|
493
|
+
},
|
|
494
|
+
body: JSON.stringify({
|
|
495
|
+
url: originalUrl,
|
|
496
|
+
method: originalMethod,
|
|
497
|
+
body: originalBody
|
|
498
|
+
})
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
503
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
504
|
+
if (!projectId) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
510
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
511
|
+
return async (input, init) => {
|
|
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 c = getContext();
|
|
516
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
517
|
+
if (!appSession) {
|
|
518
|
+
throw new Error(
|
|
519
|
+
"No authentication method available for connection proxy."
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
return fetch(proxyUrl, {
|
|
523
|
+
method: "POST",
|
|
524
|
+
headers: {
|
|
525
|
+
"Content-Type": "application/json",
|
|
526
|
+
Authorization: `Bearer ${appSession}`
|
|
527
|
+
},
|
|
528
|
+
body: JSON.stringify({
|
|
529
|
+
url: originalUrl,
|
|
530
|
+
method: originalMethod,
|
|
531
|
+
body: originalBody
|
|
532
|
+
})
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function createProxyFetch(connectionId) {
|
|
537
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
538
|
+
return createSandboxProxyFetch(connectionId);
|
|
539
|
+
}
|
|
540
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
541
|
+
}
|
|
542
|
+
|
|
470
543
|
// src/connectors/create-connector-sdk.ts
|
|
471
544
|
function loadConnectionsSync() {
|
|
472
545
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -500,7 +573,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
500
573
|
if (val !== void 0) params[param.slug] = val;
|
|
501
574
|
}
|
|
502
575
|
}
|
|
503
|
-
return createClient2(params);
|
|
576
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
504
577
|
};
|
|
505
578
|
}
|
|
506
579
|
|
|
@@ -593,6 +593,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
593
593
|
return process.env[envVarName] || void 0;
|
|
594
594
|
}
|
|
595
595
|
|
|
596
|
+
// src/connector-client/proxy-fetch.ts
|
|
597
|
+
import { getContext } from "hono/context-storage";
|
|
598
|
+
import { getCookie } from "hono/cookie";
|
|
599
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
600
|
+
function createSandboxProxyFetch(connectionId) {
|
|
601
|
+
return async (input, init) => {
|
|
602
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
603
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
604
|
+
if (!token || !sandboxId) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
610
|
+
const originalMethod = init?.method ?? "GET";
|
|
611
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
612
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
613
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
614
|
+
return fetch(proxyUrl, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: {
|
|
617
|
+
"Content-Type": "application/json",
|
|
618
|
+
Authorization: `Bearer ${token}`
|
|
619
|
+
},
|
|
620
|
+
body: JSON.stringify({
|
|
621
|
+
url: originalUrl,
|
|
622
|
+
method: originalMethod,
|
|
623
|
+
body: originalBody
|
|
624
|
+
})
|
|
625
|
+
});
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
629
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
630
|
+
if (!projectId) {
|
|
631
|
+
throw new Error(
|
|
632
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
636
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
637
|
+
return async (input, init) => {
|
|
638
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
639
|
+
const originalMethod = init?.method ?? "GET";
|
|
640
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
641
|
+
const c = getContext();
|
|
642
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
643
|
+
if (!appSession) {
|
|
644
|
+
throw new Error(
|
|
645
|
+
"No authentication method available for connection proxy."
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
return fetch(proxyUrl, {
|
|
649
|
+
method: "POST",
|
|
650
|
+
headers: {
|
|
651
|
+
"Content-Type": "application/json",
|
|
652
|
+
Authorization: `Bearer ${appSession}`
|
|
653
|
+
},
|
|
654
|
+
body: JSON.stringify({
|
|
655
|
+
url: originalUrl,
|
|
656
|
+
method: originalMethod,
|
|
657
|
+
body: originalBody
|
|
658
|
+
})
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function createProxyFetch(connectionId) {
|
|
663
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
664
|
+
return createSandboxProxyFetch(connectionId);
|
|
665
|
+
}
|
|
666
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
667
|
+
}
|
|
668
|
+
|
|
596
669
|
// src/connectors/create-connector-sdk.ts
|
|
597
670
|
function loadConnectionsSync() {
|
|
598
671
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -626,7 +699,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
626
699
|
if (val !== void 0) params[param.slug] = val;
|
|
627
700
|
}
|
|
628
701
|
}
|
|
629
|
-
return createClient2(params);
|
|
702
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
630
703
|
};
|
|
631
704
|
}
|
|
632
705
|
|
|
@@ -481,6 +481,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
481
481
|
return process.env[envVarName] || void 0;
|
|
482
482
|
}
|
|
483
483
|
|
|
484
|
+
// src/connector-client/proxy-fetch.ts
|
|
485
|
+
import { getContext } from "hono/context-storage";
|
|
486
|
+
import { getCookie } from "hono/cookie";
|
|
487
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
488
|
+
function createSandboxProxyFetch(connectionId) {
|
|
489
|
+
return async (input, init) => {
|
|
490
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
491
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
492
|
+
if (!token || !sandboxId) {
|
|
493
|
+
throw new Error(
|
|
494
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
498
|
+
const originalMethod = init?.method ?? "GET";
|
|
499
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
500
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
501
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
502
|
+
return fetch(proxyUrl, {
|
|
503
|
+
method: "POST",
|
|
504
|
+
headers: {
|
|
505
|
+
"Content-Type": "application/json",
|
|
506
|
+
Authorization: `Bearer ${token}`
|
|
507
|
+
},
|
|
508
|
+
body: JSON.stringify({
|
|
509
|
+
url: originalUrl,
|
|
510
|
+
method: originalMethod,
|
|
511
|
+
body: originalBody
|
|
512
|
+
})
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
517
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
518
|
+
if (!projectId) {
|
|
519
|
+
throw new Error(
|
|
520
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
524
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
525
|
+
return async (input, init) => {
|
|
526
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
527
|
+
const originalMethod = init?.method ?? "GET";
|
|
528
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
529
|
+
const c = getContext();
|
|
530
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
531
|
+
if (!appSession) {
|
|
532
|
+
throw new Error(
|
|
533
|
+
"No authentication method available for connection proxy."
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
return fetch(proxyUrl, {
|
|
537
|
+
method: "POST",
|
|
538
|
+
headers: {
|
|
539
|
+
"Content-Type": "application/json",
|
|
540
|
+
Authorization: `Bearer ${appSession}`
|
|
541
|
+
},
|
|
542
|
+
body: JSON.stringify({
|
|
543
|
+
url: originalUrl,
|
|
544
|
+
method: originalMethod,
|
|
545
|
+
body: originalBody
|
|
546
|
+
})
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function createProxyFetch(connectionId) {
|
|
551
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
552
|
+
return createSandboxProxyFetch(connectionId);
|
|
553
|
+
}
|
|
554
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
555
|
+
}
|
|
556
|
+
|
|
484
557
|
// src/connectors/create-connector-sdk.ts
|
|
485
558
|
function loadConnectionsSync() {
|
|
486
559
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -514,7 +587,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
514
587
|
if (val !== void 0) params[param.slug] = val;
|
|
515
588
|
}
|
|
516
589
|
}
|
|
517
|
-
return createClient2(params);
|
|
590
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
518
591
|
};
|
|
519
592
|
}
|
|
520
593
|
|
|
@@ -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
|
|