@squadbase/vite-server 0.1.12-dev.a9ac647 → 0.1.17-dev.3b633bb

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 (77) hide show
  1. package/dist/cli/index.js +14375 -1652
  2. package/dist/connectors/airtable-oauth.js +282 -46
  3. package/dist/connectors/airtable.js +319 -51
  4. package/dist/connectors/amplitude.js +322 -47
  5. package/dist/connectors/anthropic.js +135 -47
  6. package/dist/connectors/asana.js +327 -49
  7. package/dist/connectors/attio.js +302 -49
  8. package/dist/connectors/aws-billing.js +287 -46
  9. package/dist/connectors/azure-sql.js +421 -102
  10. package/dist/connectors/backlog-api-key.js +317 -47
  11. package/dist/connectors/clickup.js +338 -49
  12. package/dist/connectors/cosmosdb.js +305 -50
  13. package/dist/connectors/customerio.js +319 -47
  14. package/dist/connectors/dbt.js +340 -47
  15. package/dist/connectors/freshdesk.js +342 -53
  16. package/dist/connectors/freshsales.js +333 -52
  17. package/dist/connectors/freshservice.js +361 -53
  18. package/dist/connectors/gamma.js +327 -52
  19. package/dist/connectors/gemini.js +134 -47
  20. package/dist/connectors/github.js +386 -49
  21. package/dist/connectors/gmail-oauth.js +204 -7
  22. package/dist/connectors/gmail.js +350 -47
  23. package/dist/connectors/google-ads.js +288 -46
  24. package/dist/connectors/google-analytics-oauth.js +310 -46
  25. package/dist/connectors/google-analytics.js +547 -87
  26. package/dist/connectors/google-audit-log.js +438 -47
  27. package/dist/connectors/google-calendar-oauth.js +259 -46
  28. package/dist/connectors/google-calendar.js +359 -47
  29. package/dist/connectors/google-docs.js +220 -6
  30. package/dist/connectors/google-drive.js +262 -5
  31. package/dist/connectors/google-search-console-oauth.js +256 -46
  32. package/dist/connectors/google-sheets.js +272 -47
  33. package/dist/connectors/google-slides.js +205 -6
  34. package/dist/connectors/grafana.js +332 -49
  35. package/dist/connectors/hubspot-oauth.js +208 -5
  36. package/dist/connectors/hubspot.js +306 -49
  37. package/dist/connectors/influxdb.js +416 -51
  38. package/dist/connectors/intercom-oauth.js +210 -5
  39. package/dist/connectors/intercom.js +302 -49
  40. package/dist/connectors/jdbc.js +762 -110
  41. package/dist/connectors/jira-api-key.js +326 -47
  42. package/dist/connectors/kintone-api-token.js +281 -47
  43. package/dist/connectors/kintone.js +328 -47
  44. package/dist/connectors/linear.js +330 -49
  45. package/dist/connectors/linkedin-ads.js +268 -50
  46. package/dist/connectors/mailchimp-oauth.js +268 -46
  47. package/dist/connectors/mailchimp.js +320 -49
  48. package/dist/connectors/meta-ads-oauth.js +273 -48
  49. package/dist/connectors/meta-ads.js +285 -50
  50. package/dist/connectors/mixpanel.js +338 -47
  51. package/dist/connectors/monday.js +360 -49
  52. package/dist/connectors/mongodb.js +319 -57
  53. package/dist/connectors/notion-oauth.js +231 -5
  54. package/dist/connectors/notion.js +323 -51
  55. package/dist/connectors/openai.js +134 -47
  56. package/dist/connectors/oracle.js +454 -103
  57. package/dist/connectors/outlook-oauth.js +204 -5
  58. package/dist/connectors/powerbi-oauth.js +498 -5
  59. package/dist/connectors/salesforce.js +384 -49
  60. package/dist/connectors/semrush.js +609 -49
  61. package/dist/connectors/sentry.js +289 -50
  62. package/dist/connectors/shopify-oauth.js +187 -5
  63. package/dist/connectors/shopify.js +357 -47
  64. package/dist/connectors/sqlserver.js +415 -102
  65. package/dist/connectors/stripe-api-key.js +269 -46
  66. package/dist/connectors/stripe-oauth.js +202 -5
  67. package/dist/connectors/supabase.js +303 -48
  68. package/dist/connectors/tableau.js +536 -163
  69. package/dist/connectors/tiktok-ads.js +279 -48
  70. package/dist/connectors/wix-store.js +320 -49
  71. package/dist/connectors/zendesk-oauth.js +239 -5
  72. package/dist/connectors/zendesk.js +358 -47
  73. package/dist/index.d.ts +149 -1
  74. package/dist/index.js +15057 -2117
  75. package/dist/main.js +15005 -2073
  76. package/dist/vite-plugin.js +14752 -2019
  77. package/package.json +1 -1
@@ -1,48 +1,60 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __esm = (fn, res) => function __init() {
3
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ };
5
+
1
6
  // ../connectors/src/parameter-definition.ts
2
- var ParameterDefinition = class {
3
- slug;
4
- name;
5
- description;
6
- envVarBaseKey;
7
- type;
8
- secret;
9
- required;
10
- constructor(config) {
11
- this.slug = config.slug;
12
- this.name = config.name;
13
- this.description = config.description;
14
- this.envVarBaseKey = config.envVarBaseKey;
15
- this.type = config.type;
16
- this.secret = config.secret;
17
- this.required = config.required;
18
- }
19
- /**
20
- * Get the parameter value from a ConnectorConnectionObject.
21
- */
22
- getValue(connection2) {
23
- const param = connection2.parameters.find(
24
- (p) => p.parameterSlug === this.slug
25
- );
26
- if (!param || param.value == null) {
27
- throw new Error(
28
- `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
29
- );
30
- }
31
- return param.value;
32
- }
33
- /**
34
- * Try to get the parameter value. Returns undefined if not found (for optional params).
35
- */
36
- tryGetValue(connection2) {
37
- const param = connection2.parameters.find(
38
- (p) => p.parameterSlug === this.slug
39
- );
40
- if (!param || param.value == null) return void 0;
41
- return param.value;
7
+ var ParameterDefinition;
8
+ var init_parameter_definition = __esm({
9
+ "../connectors/src/parameter-definition.ts"() {
10
+ "use strict";
11
+ ParameterDefinition = class {
12
+ slug;
13
+ name;
14
+ description;
15
+ envVarBaseKey;
16
+ type;
17
+ secret;
18
+ required;
19
+ constructor(config) {
20
+ this.slug = config.slug;
21
+ this.name = config.name;
22
+ this.description = config.description;
23
+ this.envVarBaseKey = config.envVarBaseKey;
24
+ this.type = config.type;
25
+ this.secret = config.secret;
26
+ this.required = config.required;
27
+ }
28
+ /**
29
+ * Get the parameter value from a ConnectorConnectionObject.
30
+ */
31
+ getValue(connection2) {
32
+ const param = connection2.parameters.find(
33
+ (p) => p.parameterSlug === this.slug
34
+ );
35
+ if (!param || param.value == null) {
36
+ throw new Error(
37
+ `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
38
+ );
39
+ }
40
+ return param.value;
41
+ }
42
+ /**
43
+ * Try to get the parameter value. Returns undefined if not found (for optional params).
44
+ */
45
+ tryGetValue(connection2) {
46
+ const param = connection2.parameters.find(
47
+ (p) => p.parameterSlug === this.slug
48
+ );
49
+ if (!param || param.value == null) return void 0;
50
+ return param.value;
51
+ }
52
+ };
42
53
  }
43
- };
54
+ });
44
55
 
45
56
  // ../connectors/src/connectors/github/parameters.ts
57
+ init_parameter_definition();
46
58
  var parameters = {
47
59
  personalAccessToken: new ParameterDefinition({
48
60
  slug: "personal-access-token",
@@ -343,6 +355,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
343
355
  tools;
344
356
  query;
345
357
  checkConnection;
358
+ /**
359
+ * SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
360
+ * implement this expose a step-by-step exploration flow (database/schema/
361
+ * table/etc. discovery) that the dashboard backend drives via the
362
+ * `/connections/:connectionId/setup` endpoint. Implement by delegating to
363
+ * `runSetupFlow` from `setup-flow.ts`.
364
+ */
365
+ setup;
366
+ /**
367
+ * Opt-out of the default "verify before save" behavior on connection
368
+ * creation. The backend invokes `checkConnection` synchronously while
369
+ * creating the connection and aborts (no row inserted) if it fails — this
370
+ * flag disables that for connectors where the check cannot succeed pre-save:
371
+ *
372
+ * - `squadbase-db` populates `connection-url` only after Neon provisioning
373
+ * - OAuth connectors require an OAuth-aware proxyFetch keyed by the
374
+ * connectionId, which doesn't exist until the row is saved
375
+ *
376
+ * Exceptions are the explicit position; new credential-input connectors get
377
+ * the default verify-on-create behavior without opt-in.
378
+ */
379
+ skipConnectionCheckOnCreate;
346
380
  constructor(config) {
347
381
  this.slug = config.slug;
348
382
  this.authType = config.authType;
@@ -359,6 +393,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
359
393
  this.tools = config.tools;
360
394
  this.query = config.query;
361
395
  this.checkConnection = config.checkConnection;
396
+ this.setup = config.setup;
397
+ this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
362
398
  }
363
399
  get connectorKey() {
364
400
  return _ConnectorPlugin.deriveKey(this.slug, this.authType);
@@ -423,6 +459,76 @@ var ConnectorPlugin = class _ConnectorPlugin {
423
459
  }
424
460
  };
425
461
 
462
+ // ../connectors/src/setup-flow.ts
463
+ async function runSetupFlow(flow, params, ctx, config) {
464
+ const runtime = {
465
+ params,
466
+ language: ctx.language,
467
+ config
468
+ };
469
+ let state = flow.initialState();
470
+ let answerIdx = 0;
471
+ const pendingParameterUpdates = [];
472
+ for (const step of flow.steps) {
473
+ const ans = ctx.answers[answerIdx];
474
+ if (ans && ans.questionSlug === step.slug) {
475
+ state = step.applyAnswer(state, ans.answer);
476
+ if (step.toParameterUpdates) {
477
+ pendingParameterUpdates.push(...step.toParameterUpdates(state));
478
+ }
479
+ answerIdx += 1;
480
+ continue;
481
+ }
482
+ const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
483
+ if (step.type === "text") {
484
+ if (step.fetchOptions) {
485
+ const options2 = await step.fetchOptions(state, runtime);
486
+ if (options2.length === 0) {
487
+ continue;
488
+ }
489
+ }
490
+ return {
491
+ type: "nextQuestion",
492
+ questionSlug: step.slug,
493
+ question: step.question[ctx.language],
494
+ questionType: "text",
495
+ allowFreeText: resolvedAllowFreeText,
496
+ ...pendingParameterUpdates.length > 0 && {
497
+ parameterUpdates: pendingParameterUpdates
498
+ }
499
+ };
500
+ }
501
+ const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
502
+ if (options.length === 0) {
503
+ continue;
504
+ }
505
+ return {
506
+ type: "nextQuestion",
507
+ questionSlug: step.slug,
508
+ question: step.question[ctx.language],
509
+ questionType: step.type,
510
+ options,
511
+ allowFreeText: resolvedAllowFreeText,
512
+ ...pendingParameterUpdates.length > 0 && {
513
+ parameterUpdates: pendingParameterUpdates
514
+ }
515
+ };
516
+ }
517
+ const dataInvestigationResult = await flow.finalize(state, runtime);
518
+ return {
519
+ type: "fulfilled",
520
+ dataInvestigationResult,
521
+ ...pendingParameterUpdates.length > 0 && {
522
+ parameterUpdates: pendingParameterUpdates
523
+ }
524
+ };
525
+ }
526
+ async function resolveSetupSelection(params) {
527
+ const { selected, allSentinel, fetchAll, limit } = params;
528
+ const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
529
+ return resolved.slice(0, limit);
530
+ }
531
+
426
532
  // ../connectors/src/auth-types.ts
427
533
  var AUTH_TYPES = {
428
534
  OAUTH: "oauth",
@@ -455,10 +561,185 @@ var githubOnboarding = new ConnectorOnboarding({
455
561
  }
456
562
  });
457
563
 
564
+ // ../connectors/src/connectors/github/utils.ts
565
+ function resolveBaseUrl(connectionBaseUrl) {
566
+ const trimmed = connectionBaseUrl?.trim();
567
+ return trimmed && trimmed.replace(/\/+$/, "") || DEFAULT_BASE_URL;
568
+ }
569
+ async function apiFetch(params, path2, init) {
570
+ const token = params[parameters.personalAccessToken.slug];
571
+ if (!token) {
572
+ throw new Error(
573
+ "github: missing required parameter: personal-access-token"
574
+ );
575
+ }
576
+ const baseUrl = resolveBaseUrl(params[parameters.baseUrl.slug]);
577
+ const trimmedPath = path2.replace(/^\/+/, "/");
578
+ const url = `${baseUrl}${trimmedPath.startsWith("/") ? "" : "/"}${trimmedPath}`;
579
+ const headers = new Headers(init?.headers);
580
+ headers.set("Authorization", `Bearer ${token}`);
581
+ if (!headers.has("Accept")) {
582
+ headers.set("Accept", "application/vnd.github+json");
583
+ }
584
+ if (!headers.has("X-GitHub-Api-Version")) {
585
+ headers.set("X-GitHub-Api-Version", "2022-11-28");
586
+ }
587
+ if (!headers.has("User-Agent")) {
588
+ headers.set("User-Agent", "squadbase-connectors-github");
589
+ }
590
+ return fetch(url, { ...init, headers });
591
+ }
592
+
593
+ // ../connectors/src/connectors/github/setup-flow.ts
594
+ var ALL_REPOS = "__ALL_REPOS__";
595
+ var GITHUB_SETUP_MAX_REPOS = 20;
596
+ var USER_OWNER = "__USER__";
597
+ async function getAuthenticatedUser(params) {
598
+ const res = await apiFetch(params, "/user");
599
+ if (!res.ok) return null;
600
+ return await res.json();
601
+ }
602
+ async function listOrgs(params) {
603
+ const res = await apiFetch(params, "/user/orgs?per_page=100");
604
+ if (!res.ok) {
605
+ const body = await res.text().catch(() => res.statusText);
606
+ throw new Error(`github: listOrgs failed (${res.status}): ${body}`);
607
+ }
608
+ return await res.json();
609
+ }
610
+ async function listReposPaged(params, pathBase) {
611
+ const all = [];
612
+ let page = 1;
613
+ const perPage = 100;
614
+ while (all.length < 500) {
615
+ const sep = pathBase.includes("?") ? "&" : "?";
616
+ const res = await apiFetch(
617
+ params,
618
+ `${pathBase}${sep}per_page=${perPage}&page=${page}`
619
+ );
620
+ if (!res.ok) {
621
+ const body = await res.text().catch(() => res.statusText);
622
+ throw new Error(`github: listRepos failed (${res.status}): ${body}`);
623
+ }
624
+ const batch = await res.json();
625
+ if (!Array.isArray(batch) || batch.length === 0) break;
626
+ all.push(...batch);
627
+ if (batch.length < perPage) break;
628
+ page += 1;
629
+ }
630
+ return all;
631
+ }
632
+ async function listOrgRepos(params, org) {
633
+ return listReposPaged(
634
+ params,
635
+ `/orgs/${encodeURIComponent(org)}/repos?sort=updated`
636
+ );
637
+ }
638
+ async function listUserRepos(params) {
639
+ return listReposPaged(params, `/user/repos?sort=updated&affiliation=owner`);
640
+ }
641
+ async function getRepoLanguages(params, fullName) {
642
+ const res = await apiFetch(params, `/repos/${fullName}/languages`);
643
+ if (!res.ok) return {};
644
+ return await res.json();
645
+ }
646
+ var githubSetupFlow = {
647
+ initialState: () => ({}),
648
+ steps: [
649
+ {
650
+ slug: "owner",
651
+ type: "select",
652
+ question: {
653
+ ja: "\u5BFE\u8C61\u306E\u30AA\u30FC\u30CA\u30FC\uFF08\u7D44\u7E54\u307E\u305F\u306F\u81EA\u5206\u81EA\u8EAB\uFF09\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044",
654
+ en: "Select the owner (organization or yourself)"
655
+ },
656
+ async fetchOptions(_state, rt) {
657
+ const [user, orgs] = await Promise.all([
658
+ getAuthenticatedUser(rt.params).catch(() => null),
659
+ listOrgs(rt.params).catch(() => [])
660
+ ]);
661
+ const options = [];
662
+ if (user?.login) {
663
+ options.push({
664
+ value: USER_OWNER,
665
+ label: rt.language === "ja" ? `\u81EA\u5206 (${user.login})` : `Myself (${user.login})`
666
+ });
667
+ }
668
+ for (const org of orgs) {
669
+ if (org.login) {
670
+ options.push({ value: org.login, label: org.login });
671
+ }
672
+ }
673
+ return options;
674
+ },
675
+ applyAnswer: (state, answer) => ({ ...state, owner: answer[0] })
676
+ },
677
+ {
678
+ slug: "repos",
679
+ type: "multiSelect",
680
+ question: {
681
+ ja: "\u5BFE\u8C61\u306E\u30EA\u30DD\u30B8\u30C8\u30EA\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
682
+ en: "Select target repositories (multi-select allowed)"
683
+ },
684
+ async fetchOptions(state, rt) {
685
+ if (!state.owner) return [];
686
+ const repos = state.owner === USER_OWNER ? await listUserRepos(rt.params) : await listOrgRepos(rt.params, state.owner);
687
+ const repoOptions = repos.filter((r) => r.full_name).map((r) => ({ value: r.full_name, label: r.full_name }));
688
+ return [
689
+ {
690
+ value: ALL_REPOS,
691
+ label: rt.language === "ja" ? "\u3059\u3079\u3066\u306E\u30EA\u30DD\u30B8\u30C8\u30EA" : "All repositories"
692
+ },
693
+ ...repoOptions
694
+ ];
695
+ },
696
+ applyAnswer: (state, answer) => ({ ...state, repos: answer })
697
+ }
698
+ ],
699
+ async finalize(state, rt) {
700
+ if (!state.owner || !state.repos) {
701
+ throw new Error("GitHub setup: incomplete state on finalize");
702
+ }
703
+ const repos = state.owner === USER_OWNER ? await listUserRepos(rt.params) : await listOrgRepos(rt.params, state.owner);
704
+ const repoByFullName = new Map(repos.map((r) => [r.full_name, r]));
705
+ const targetFullNames = await resolveSetupSelection({
706
+ selected: state.repos,
707
+ allSentinel: ALL_REPOS,
708
+ fetchAll: async () => repos.map((r) => r.full_name).filter((n) => n),
709
+ limit: GITHUB_SETUP_MAX_REPOS
710
+ });
711
+ const ownerLabel = state.owner === USER_OWNER ? "self" : state.owner;
712
+ const sections = [
713
+ "## GitHub",
714
+ "",
715
+ `### Owner: ${ownerLabel}`,
716
+ ""
717
+ ];
718
+ for (const fullName of targetFullNames) {
719
+ const repo = repoByFullName.get(fullName);
720
+ if (!repo) {
721
+ sections.push(`#### Repository: ${fullName}`, "", "_Not found._", "");
722
+ continue;
723
+ }
724
+ sections.push(`#### Repository: ${repo.full_name}`, "");
725
+ sections.push(`- Description: ${repo.description ?? "-"}`);
726
+ sections.push(`- Default branch: ${repo.default_branch ?? "-"}`);
727
+ sections.push(`- Visibility: ${repo.private ? "private" : "public"}`);
728
+ const languages = await getRepoLanguages(rt.params, repo.full_name);
729
+ const names = Object.keys(languages);
730
+ sections.push(
731
+ `- Languages: ${names.length > 0 ? names.join(", ") : "-"}`
732
+ );
733
+ sections.push("");
734
+ }
735
+ return sections.join("\n");
736
+ }
737
+ };
738
+
458
739
  // ../connectors/src/connectors/github/tools/request.ts
459
740
  import { z } from "zod";
460
741
  var REQUEST_TIMEOUT_MS = 6e4;
461
- function resolveBaseUrl(connectionBaseUrl) {
742
+ function resolveBaseUrl2(connectionBaseUrl) {
462
743
  const trimmed = connectionBaseUrl?.trim();
463
744
  return trimmed && trimmed.replace(/\/+$/, "") || DEFAULT_BASE_URL;
464
745
  }
@@ -544,7 +825,7 @@ Rate limits: 5,000 req/hr on REST endpoints, 30 req/min on /search/*. Inspect \`
544
825
  );
545
826
  try {
546
827
  const token = parameters.personalAccessToken.getValue(connection2);
547
- const baseUrl = resolveBaseUrl(parameters.baseUrl.tryGetValue(connection2));
828
+ const baseUrl = resolveBaseUrl2(parameters.baseUrl.tryGetValue(connection2));
548
829
  const trimmedPath = path2.trim().replace(/^\/+/, "/");
549
830
  const url = `${baseUrl}${trimmedPath.startsWith("/") ? "" : "/"}${trimmedPath}`;
550
831
  const controller = new AbortController();
@@ -811,7 +1092,43 @@ export default async function handler(c: Context) {
811
1092
  **\u30AF\u30A9\u30FC\u30BF**
812
1093
  - GET \`/rate_limit\` \u2014 REST / GraphQL / search \u306E\u6B8B\u30EC\u30FC\u30C8\u78BA\u8A8D`
813
1094
  },
814
- tools
1095
+ tools,
1096
+ setup: (params, ctx, config) => runSetupFlow(githubSetupFlow, params, ctx, config),
1097
+ async checkConnection(params, _config) {
1098
+ const token = params[parameters.personalAccessToken.slug];
1099
+ if (!token) {
1100
+ return {
1101
+ success: false,
1102
+ error: `Missing required parameter: ${parameters.personalAccessToken.slug}`
1103
+ };
1104
+ }
1105
+ const rawBaseUrl = params[parameters.baseUrl.slug]?.trim();
1106
+ const baseUrl = rawBaseUrl && rawBaseUrl.replace(/\/+$/, "") || DEFAULT_BASE_URL;
1107
+ try {
1108
+ const res = await fetch(`${baseUrl}/user`, {
1109
+ method: "GET",
1110
+ headers: {
1111
+ Authorization: `Bearer ${token}`,
1112
+ Accept: "application/vnd.github+json",
1113
+ "X-GitHub-Api-Version": "2022-11-28",
1114
+ "User-Agent": "squadbase-connector"
1115
+ }
1116
+ });
1117
+ if (!res.ok) {
1118
+ const errorText = await res.text().catch(() => res.statusText);
1119
+ return {
1120
+ success: false,
1121
+ error: `GitHub API failed: HTTP ${res.status} ${errorText}`
1122
+ };
1123
+ }
1124
+ return { success: true };
1125
+ } catch (error) {
1126
+ return {
1127
+ success: false,
1128
+ error: error instanceof Error ? error.message : String(error)
1129
+ };
1130
+ }
1131
+ }
815
1132
  });
816
1133
 
817
1134
  // src/connectors/create-connector-sdk.ts
@@ -840,6 +1157,7 @@ function resolveEnvVarOptional(entry, key) {
840
1157
  import { getContext } from "hono/context-storage";
841
1158
  import { getCookie } from "hono/cookie";
842
1159
  var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
1160
+ var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
843
1161
  function normalizeHeaders(input) {
844
1162
  const out = {};
845
1163
  if (!input) return out;
@@ -848,6 +1166,11 @@ function normalizeHeaders(input) {
848
1166
  });
849
1167
  return out;
850
1168
  }
1169
+ function extractInputUrl(input) {
1170
+ if (typeof input === "string") return input;
1171
+ if (input instanceof URL) return input.href;
1172
+ return input.url;
1173
+ }
851
1174
  function createSandboxProxyFetch(connectionId) {
852
1175
  return async (input, init) => {
853
1176
  const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
@@ -857,10 +1180,17 @@ function createSandboxProxyFetch(connectionId) {
857
1180
  "Connection proxy is not configured. Please check your deployment settings."
858
1181
  );
859
1182
  }
860
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1183
+ const originalUrl = extractInputUrl(input);
1184
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
1185
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
1186
+ const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
1187
+ return fetch(sessionUrl, {
1188
+ method: "POST",
1189
+ headers: { Authorization: `Bearer ${token}` }
1190
+ });
1191
+ }
861
1192
  const originalMethod = init?.method ?? "GET";
862
1193
  const originalBody = init?.body ? JSON.parse(init.body) : void 0;
863
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
864
1194
  const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
865
1195
  return fetch(proxyUrl, {
866
1196
  method: "POST",
@@ -886,10 +1216,9 @@ function createDeployedAppProxyFetch(connectionId) {
886
1216
  }
887
1217
  const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
888
1218
  const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
1219
+ const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
889
1220
  return async (input, init) => {
890
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
891
- const originalMethod = init?.method ?? "GET";
892
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
1221
+ const originalUrl = extractInputUrl(input);
893
1222
  const c = getContext();
894
1223
  const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
895
1224
  if (!appSession) {
@@ -897,6 +1226,14 @@ function createDeployedAppProxyFetch(connectionId) {
897
1226
  "No authentication method available for connection proxy."
898
1227
  );
899
1228
  }
1229
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
1230
+ return fetch(sessionUrl, {
1231
+ method: "POST",
1232
+ headers: { Authorization: `Bearer ${appSession}` }
1233
+ });
1234
+ }
1235
+ const originalMethod = init?.method ?? "GET";
1236
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
900
1237
  return fetch(proxyUrl, {
901
1238
  method: "POST",
902
1239
  headers: {