@squadbase/vite-server 0.1.3-dev.7 → 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 +1532 -1335
- 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 -46
- package/dist/connectors/google-calendar-oauth.js +74 -1
- package/dist/connectors/google-calendar.d.ts +1 -8
- package/dist/connectors/google-calendar.js +316 -64
- package/dist/connectors/google-sheets-oauth.js +85 -18
- package/dist/connectors/google-sheets.js +75 -2
- package/dist/connectors/grafana.js +74 -1
- 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 +1484 -1288
- package/dist/main.js +1483 -1286
- package/dist/vite-plugin.js +1483 -1286
- package/package.json +1 -1
|
@@ -85,7 +85,7 @@ var parameters = {
|
|
|
85
85
|
envVarBaseKey: "GOOGLE_SHEETS_SPREADSHEET_URL",
|
|
86
86
|
type: "text",
|
|
87
87
|
secret: false,
|
|
88
|
-
required:
|
|
88
|
+
required: true
|
|
89
89
|
})
|
|
90
90
|
};
|
|
91
91
|
|
|
@@ -590,6 +590,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
590
590
|
return process.env[envVarName] || void 0;
|
|
591
591
|
}
|
|
592
592
|
|
|
593
|
+
// src/connector-client/proxy-fetch.ts
|
|
594
|
+
import { getContext } from "hono/context-storage";
|
|
595
|
+
import { getCookie } from "hono/cookie";
|
|
596
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
597
|
+
function createSandboxProxyFetch(connectionId) {
|
|
598
|
+
return async (input, init) => {
|
|
599
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
600
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
601
|
+
if (!token || !sandboxId) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
607
|
+
const originalMethod = init?.method ?? "GET";
|
|
608
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
609
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
610
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
611
|
+
return fetch(proxyUrl, {
|
|
612
|
+
method: "POST",
|
|
613
|
+
headers: {
|
|
614
|
+
"Content-Type": "application/json",
|
|
615
|
+
Authorization: `Bearer ${token}`
|
|
616
|
+
},
|
|
617
|
+
body: JSON.stringify({
|
|
618
|
+
url: originalUrl,
|
|
619
|
+
method: originalMethod,
|
|
620
|
+
body: originalBody
|
|
621
|
+
})
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
626
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
627
|
+
if (!projectId) {
|
|
628
|
+
throw new Error(
|
|
629
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
633
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
634
|
+
return async (input, init) => {
|
|
635
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
636
|
+
const originalMethod = init?.method ?? "GET";
|
|
637
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
638
|
+
const c = getContext();
|
|
639
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
640
|
+
if (!appSession) {
|
|
641
|
+
throw new Error(
|
|
642
|
+
"No authentication method available for connection proxy."
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
return fetch(proxyUrl, {
|
|
646
|
+
method: "POST",
|
|
647
|
+
headers: {
|
|
648
|
+
"Content-Type": "application/json",
|
|
649
|
+
Authorization: `Bearer ${appSession}`
|
|
650
|
+
},
|
|
651
|
+
body: JSON.stringify({
|
|
652
|
+
url: originalUrl,
|
|
653
|
+
method: originalMethod,
|
|
654
|
+
body: originalBody
|
|
655
|
+
})
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function createProxyFetch(connectionId) {
|
|
660
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
661
|
+
return createSandboxProxyFetch(connectionId);
|
|
662
|
+
}
|
|
663
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
664
|
+
}
|
|
665
|
+
|
|
593
666
|
// src/connectors/create-connector-sdk.ts
|
|
594
667
|
function loadConnectionsSync() {
|
|
595
668
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -623,7 +696,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
623
696
|
if (val !== void 0) params[param.slug] = val;
|
|
624
697
|
}
|
|
625
698
|
}
|
|
626
|
-
return createClient2(params);
|
|
699
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
627
700
|
};
|
|
628
701
|
}
|
|
629
702
|
|
|
@@ -521,6 +521,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
521
521
|
return process.env[envVarName] || void 0;
|
|
522
522
|
}
|
|
523
523
|
|
|
524
|
+
// src/connector-client/proxy-fetch.ts
|
|
525
|
+
import { getContext } from "hono/context-storage";
|
|
526
|
+
import { getCookie } from "hono/cookie";
|
|
527
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
528
|
+
function createSandboxProxyFetch(connectionId) {
|
|
529
|
+
return async (input, init) => {
|
|
530
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
531
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
532
|
+
if (!token || !sandboxId) {
|
|
533
|
+
throw new Error(
|
|
534
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
538
|
+
const originalMethod = init?.method ?? "GET";
|
|
539
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
540
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
541
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
542
|
+
return fetch(proxyUrl, {
|
|
543
|
+
method: "POST",
|
|
544
|
+
headers: {
|
|
545
|
+
"Content-Type": "application/json",
|
|
546
|
+
Authorization: `Bearer ${token}`
|
|
547
|
+
},
|
|
548
|
+
body: JSON.stringify({
|
|
549
|
+
url: originalUrl,
|
|
550
|
+
method: originalMethod,
|
|
551
|
+
body: originalBody
|
|
552
|
+
})
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
557
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
558
|
+
if (!projectId) {
|
|
559
|
+
throw new Error(
|
|
560
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
564
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
565
|
+
return async (input, init) => {
|
|
566
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
567
|
+
const originalMethod = init?.method ?? "GET";
|
|
568
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
569
|
+
const c = getContext();
|
|
570
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
571
|
+
if (!appSession) {
|
|
572
|
+
throw new Error(
|
|
573
|
+
"No authentication method available for connection proxy."
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
return fetch(proxyUrl, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
headers: {
|
|
579
|
+
"Content-Type": "application/json",
|
|
580
|
+
Authorization: `Bearer ${appSession}`
|
|
581
|
+
},
|
|
582
|
+
body: JSON.stringify({
|
|
583
|
+
url: originalUrl,
|
|
584
|
+
method: originalMethod,
|
|
585
|
+
body: originalBody
|
|
586
|
+
})
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function createProxyFetch(connectionId) {
|
|
591
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
592
|
+
return createSandboxProxyFetch(connectionId);
|
|
593
|
+
}
|
|
594
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
595
|
+
}
|
|
596
|
+
|
|
524
597
|
// src/connectors/create-connector-sdk.ts
|
|
525
598
|
function loadConnectionsSync() {
|
|
526
599
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -554,7 +627,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
554
627
|
if (val !== void 0) params[param.slug] = val;
|
|
555
628
|
}
|
|
556
629
|
}
|
|
557
|
-
return createClient2(params);
|
|
630
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
558
631
|
};
|
|
559
632
|
}
|
|
560
633
|
|
|
@@ -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
|
|