@squadbase/vite-server 0.1.12-dev.a9ac647 → 0.1.17-dev.24af54e

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 +12374 -883
  2. package/dist/connectors/airtable-oauth.js +257 -46
  3. package/dist/connectors/airtable.js +294 -51
  4. package/dist/connectors/amplitude.js +297 -47
  5. package/dist/connectors/anthropic.js +135 -47
  6. package/dist/connectors/asana.js +302 -49
  7. package/dist/connectors/attio.js +277 -49
  8. package/dist/connectors/aws-billing.js +262 -46
  9. package/dist/connectors/azure-sql.js +396 -102
  10. package/dist/connectors/backlog-api-key.js +292 -47
  11. package/dist/connectors/clickup.js +313 -49
  12. package/dist/connectors/cosmosdb.js +280 -50
  13. package/dist/connectors/customerio.js +294 -47
  14. package/dist/connectors/dbt.js +315 -47
  15. package/dist/connectors/freshdesk.js +317 -53
  16. package/dist/connectors/freshsales.js +308 -52
  17. package/dist/connectors/freshservice.js +336 -53
  18. package/dist/connectors/gamma.js +302 -52
  19. package/dist/connectors/gemini.js +134 -47
  20. package/dist/connectors/github.js +361 -49
  21. package/dist/connectors/gmail-oauth.js +179 -7
  22. package/dist/connectors/gmail.js +325 -47
  23. package/dist/connectors/google-ads.js +263 -46
  24. package/dist/connectors/google-analytics-oauth.js +285 -46
  25. package/dist/connectors/google-analytics.js +387 -49
  26. package/dist/connectors/google-audit-log.js +413 -47
  27. package/dist/connectors/google-calendar-oauth.js +234 -46
  28. package/dist/connectors/google-calendar.js +334 -47
  29. package/dist/connectors/google-docs.js +195 -6
  30. package/dist/connectors/google-drive.js +237 -5
  31. package/dist/connectors/google-search-console-oauth.js +231 -46
  32. package/dist/connectors/google-sheets.js +247 -47
  33. package/dist/connectors/google-slides.js +180 -6
  34. package/dist/connectors/grafana.js +307 -49
  35. package/dist/connectors/hubspot-oauth.js +183 -5
  36. package/dist/connectors/hubspot.js +281 -49
  37. package/dist/connectors/influxdb.js +391 -51
  38. package/dist/connectors/intercom-oauth.js +185 -5
  39. package/dist/connectors/intercom.js +277 -49
  40. package/dist/connectors/jdbc.js +737 -110
  41. package/dist/connectors/jira-api-key.js +301 -47
  42. package/dist/connectors/kintone-api-token.js +256 -47
  43. package/dist/connectors/kintone.js +303 -47
  44. package/dist/connectors/linear.js +305 -49
  45. package/dist/connectors/linkedin-ads.js +243 -50
  46. package/dist/connectors/mailchimp-oauth.js +243 -46
  47. package/dist/connectors/mailchimp.js +295 -49
  48. package/dist/connectors/meta-ads-oauth.js +248 -48
  49. package/dist/connectors/meta-ads.js +260 -50
  50. package/dist/connectors/mixpanel.js +313 -47
  51. package/dist/connectors/monday.js +335 -49
  52. package/dist/connectors/mongodb.js +294 -57
  53. package/dist/connectors/notion-oauth.js +206 -5
  54. package/dist/connectors/notion.js +298 -51
  55. package/dist/connectors/openai.js +134 -47
  56. package/dist/connectors/oracle.js +414 -103
  57. package/dist/connectors/outlook-oauth.js +179 -5
  58. package/dist/connectors/powerbi-oauth.js +226 -5
  59. package/dist/connectors/salesforce.js +359 -49
  60. package/dist/connectors/semrush.js +289 -49
  61. package/dist/connectors/sentry.js +264 -50
  62. package/dist/connectors/shopify-oauth.js +162 -5
  63. package/dist/connectors/shopify.js +332 -47
  64. package/dist/connectors/sqlserver.js +390 -102
  65. package/dist/connectors/stripe-api-key.js +244 -46
  66. package/dist/connectors/stripe-oauth.js +177 -5
  67. package/dist/connectors/supabase.js +278 -48
  68. package/dist/connectors/tableau.js +389 -184
  69. package/dist/connectors/tiktok-ads.js +254 -48
  70. package/dist/connectors/wix-store.js +295 -49
  71. package/dist/connectors/zendesk-oauth.js +214 -5
  72. package/dist/connectors/zendesk.js +333 -47
  73. package/dist/index.d.ts +149 -1
  74. package/dist/index.js +13677 -1969
  75. package/dist/main.js +13627 -1927
  76. package/dist/vite-plugin.js +12391 -890
  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/gmail/parameters.ts
57
+ init_parameter_definition();
46
58
  var parameters = {
47
59
  serviceAccountKeyJsonBase64: new ParameterDefinition({
48
60
  slug: "service-account-key-json-base64",
@@ -165,6 +177,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
165
177
  tools;
166
178
  query;
167
179
  checkConnection;
180
+ /**
181
+ * SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
182
+ * implement this expose a step-by-step exploration flow (database/schema/
183
+ * table/etc. discovery) that the dashboard backend drives via the
184
+ * `/connections/:connectionId/setup` endpoint. Implement by delegating to
185
+ * `runSetupFlow` from `setup-flow.ts`.
186
+ */
187
+ setup;
188
+ /**
189
+ * Opt-out of the default "verify before save" behavior on connection
190
+ * creation. The backend invokes `checkConnection` synchronously while
191
+ * creating the connection and aborts (no row inserted) if it fails — this
192
+ * flag disables that for connectors where the check cannot succeed pre-save:
193
+ *
194
+ * - `squadbase-db` populates `connection-url` only after Neon provisioning
195
+ * - OAuth connectors require an OAuth-aware proxyFetch keyed by the
196
+ * connectionId, which doesn't exist until the row is saved
197
+ *
198
+ * Exceptions are the explicit position; new credential-input connectors get
199
+ * the default verify-on-create behavior without opt-in.
200
+ */
201
+ skipConnectionCheckOnCreate;
168
202
  constructor(config) {
169
203
  this.slug = config.slug;
170
204
  this.authType = config.authType;
@@ -181,6 +215,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
181
215
  this.tools = config.tools;
182
216
  this.query = config.query;
183
217
  this.checkConnection = config.checkConnection;
218
+ this.setup = config.setup;
219
+ this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
184
220
  }
185
221
  get connectorKey() {
186
222
  return _ConnectorPlugin.deriveKey(this.slug, this.authType);
@@ -245,6 +281,51 @@ var ConnectorPlugin = class _ConnectorPlugin {
245
281
  }
246
282
  };
247
283
 
284
+ // ../connectors/src/setup-flow.ts
285
+ async function runSetupFlow(flow, params, ctx, config) {
286
+ const runtime = {
287
+ params,
288
+ language: ctx.language,
289
+ config
290
+ };
291
+ let state = flow.initialState();
292
+ let answerIdx = 0;
293
+ for (const step of flow.steps) {
294
+ const ans = ctx.answers[answerIdx];
295
+ if (ans && ans.questionSlug === step.slug) {
296
+ state = step.applyAnswer(state, ans.answer);
297
+ answerIdx += 1;
298
+ continue;
299
+ }
300
+ if (step.type === "text") {
301
+ return {
302
+ type: "nextQuestion",
303
+ questionSlug: step.slug,
304
+ question: step.question[ctx.language],
305
+ questionType: "text"
306
+ };
307
+ }
308
+ const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
309
+ if (options.length === 0) {
310
+ continue;
311
+ }
312
+ return {
313
+ type: "nextQuestion",
314
+ questionSlug: step.slug,
315
+ question: step.question[ctx.language],
316
+ questionType: step.type,
317
+ options
318
+ };
319
+ }
320
+ const dataInvestigationResult = await flow.finalize(state, runtime);
321
+ return { type: "fulfilled", dataInvestigationResult };
322
+ }
323
+ async function resolveSetupSelection(params) {
324
+ const { selected, allSentinel, fetchAll, limit } = params;
325
+ const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
326
+ return resolved.slice(0, limit);
327
+ }
328
+
248
329
  // ../connectors/src/auth-types.ts
249
330
  var AUTH_TYPES = {
250
331
  OAUTH: "oauth",
@@ -469,6 +550,135 @@ var gmailOnboarding = new ConnectorOnboarding({
469
550
  }
470
551
  });
471
552
 
553
+ // ../connectors/src/connectors/gmail/utils.ts
554
+ function decodeServiceAccount2(keyJsonBase64) {
555
+ const decoded = Buffer.from(keyJsonBase64, "base64").toString("utf-8");
556
+ return JSON.parse(decoded);
557
+ }
558
+ async function getDelegatedAccessToken(params, subject, scopes) {
559
+ const keyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
560
+ if (!keyJsonBase64) {
561
+ throw new Error("Gmail setup: service account key is missing");
562
+ }
563
+ const sa = decodeServiceAccount2(keyJsonBase64);
564
+ const { GoogleAuth } = await import("google-auth-library");
565
+ const auth = new GoogleAuth({
566
+ credentials: { client_email: sa.client_email, private_key: sa.private_key },
567
+ scopes,
568
+ clientOptions: { subject }
569
+ });
570
+ const token = await auth.getAccessToken();
571
+ if (!token) {
572
+ throw new Error("Gmail setup: failed to obtain access token");
573
+ }
574
+ return token;
575
+ }
576
+ var READONLY_SCOPES2 = ["https://www.googleapis.com/auth/gmail.readonly"];
577
+ async function gmailApiFetch(params, subject, url) {
578
+ const token = await getDelegatedAccessToken(params, subject, READONLY_SCOPES2);
579
+ const res = await fetch(url, {
580
+ method: "GET",
581
+ headers: { Authorization: `Bearer ${token}` }
582
+ });
583
+ if (!res.ok) {
584
+ const text = await res.text().catch(() => res.statusText);
585
+ throw new Error(`Gmail API ${url} failed: HTTP ${res.status} ${text}`);
586
+ }
587
+ return await res.json();
588
+ }
589
+
590
+ // ../connectors/src/connectors/gmail/setup-flow.ts
591
+ var ALL_LABELS = "__ALL_LABELS__";
592
+ var GMAIL_SETUP_MAX_LABELS = 20;
593
+ async function listLabels(params, subject) {
594
+ const url = "https://gmail.googleapis.com/gmail/v1/users/me/labels";
595
+ const data = await gmailApiFetch(
596
+ params,
597
+ subject,
598
+ url
599
+ );
600
+ return data.labels ?? [];
601
+ }
602
+ var gmailSetupFlow = {
603
+ initialState: () => ({}),
604
+ steps: [
605
+ {
606
+ slug: "subject",
607
+ type: "text",
608
+ question: {
609
+ ja: "\u5BFE\u8C61\u3068\u3059\u308B Workspace \u30E6\u30FC\u30B6\u30FC\u306E\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08Domain-wide Delegation \u3067\u4EE3\u7406\u30A2\u30AF\u30BB\u30B9\u3057\u307E\u3059\uFF09",
610
+ en: "Enter the Workspace user email to impersonate via Domain-wide Delegation"
611
+ },
612
+ applyAnswer: (state, answer) => ({ ...state, subject: answer[0] })
613
+ },
614
+ {
615
+ slug: "labels",
616
+ type: "multiSelect",
617
+ question: {
618
+ ja: "\u5BFE\u8C61\u306E\u30E9\u30D9\u30EB\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
619
+ en: "Select target labels (multi-select allowed)"
620
+ },
621
+ async fetchOptions(state, rt) {
622
+ if (!state.subject) return [];
623
+ const labels = await listLabels(rt.params, state.subject);
624
+ return [
625
+ {
626
+ value: ALL_LABELS,
627
+ label: rt.language === "ja" ? "\u3059\u3079\u3066\u306E\u30E9\u30D9\u30EB" : "All labels"
628
+ },
629
+ ...labels.map((l) => ({ value: l.id, label: l.name }))
630
+ ];
631
+ },
632
+ applyAnswer: (state, answer) => ({ ...state, labels: answer })
633
+ }
634
+ ],
635
+ async finalize(state, rt) {
636
+ if (!state.subject || !state.labels) {
637
+ throw new Error("Gmail setup: incomplete state on finalize");
638
+ }
639
+ const subject = state.subject;
640
+ const labels = await listLabels(rt.params, subject);
641
+ const byId = new Map(labels.map((l) => [l.id, l]));
642
+ const targetIds = await resolveSetupSelection({
643
+ selected: state.labels,
644
+ allSentinel: ALL_LABELS,
645
+ fetchAll: async () => labels.map((l) => l.id),
646
+ limit: GMAIL_SETUP_MAX_LABELS
647
+ });
648
+ const sections = [
649
+ "## Gmail",
650
+ "",
651
+ `### Subject: ${subject}`,
652
+ ""
653
+ ];
654
+ if (targetIds.length === 0) {
655
+ sections.push(
656
+ rt.language === "ja" ? "\u5BFE\u8C61\u306E\u30E9\u30D9\u30EB\u304C\u9078\u629E\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002" : "No labels selected."
657
+ );
658
+ return sections.join("\n");
659
+ }
660
+ sections.push("| Label | Visibility | Messages | Unread |");
661
+ sections.push("|-------|-----------|----------|--------|");
662
+ for (const id of targetIds) {
663
+ const url = `https://gmail.googleapis.com/gmail/v1/users/me/labels/${encodeURIComponent(
664
+ id
665
+ )}`;
666
+ const detail = await gmailApiFetch(
667
+ rt.params,
668
+ subject,
669
+ url
670
+ );
671
+ const name = detail.name ?? byId.get(id)?.name ?? id;
672
+ const vis = detail.labelListVisibility ?? "-";
673
+ const total = detail.messagesTotal ?? "-";
674
+ const unread = detail.messagesUnread ?? "-";
675
+ sections.push(`| ${name} | ${vis} | ${total} | ${unread} |`);
676
+ }
677
+ sections.push("");
678
+ return sections.join("\n");
679
+ }
680
+ };
681
+
472
682
  // ../connectors/src/connectors/gmail/index.ts
473
683
  var tools = { request_with_delegation: requestWithDelegationTool };
474
684
  var gmailConnector = new ConnectorPlugin({
@@ -669,7 +879,55 @@ for (const msg of messages.messages ?? []) {
669
879
  }
670
880
  \`\`\``
671
881
  },
672
- tools
882
+ tools,
883
+ setup: (params, ctx, config) => runSetupFlow(gmailSetupFlow, params, ctx, config),
884
+ async checkConnection(params, _config) {
885
+ const keyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
886
+ if (!keyJsonBase64) {
887
+ return {
888
+ success: false,
889
+ error: "gmail: missing service account key"
890
+ };
891
+ }
892
+ let sa;
893
+ try {
894
+ const decoded = Buffer.from(keyJsonBase64, "base64").toString("utf-8");
895
+ sa = JSON.parse(decoded);
896
+ } catch (err) {
897
+ const msg = err instanceof Error ? err.message : String(err);
898
+ return {
899
+ success: false,
900
+ error: `gmail: failed to parse service account JSON: ${msg}`
901
+ };
902
+ }
903
+ if (!sa.client_email || !sa.private_key) {
904
+ return {
905
+ success: false,
906
+ error: "gmail: service account JSON must contain client_email and private_key"
907
+ };
908
+ }
909
+ try {
910
+ const { GoogleAuth } = await import("google-auth-library");
911
+ const auth = new GoogleAuth({
912
+ credentials: {
913
+ client_email: sa.client_email,
914
+ private_key: sa.private_key
915
+ },
916
+ scopes: ["https://www.googleapis.com/auth/gmail.readonly"]
917
+ });
918
+ const token = await auth.getAccessToken();
919
+ if (!token) {
920
+ return {
921
+ success: false,
922
+ error: "gmail: failed to obtain access token"
923
+ };
924
+ }
925
+ return { success: true };
926
+ } catch (err) {
927
+ const msg = err instanceof Error ? err.message : String(err);
928
+ return { success: false, error: msg };
929
+ }
930
+ }
673
931
  });
674
932
 
675
933
  // src/connectors/create-connector-sdk.ts
@@ -698,6 +956,7 @@ function resolveEnvVarOptional(entry, key) {
698
956
  import { getContext } from "hono/context-storage";
699
957
  import { getCookie } from "hono/cookie";
700
958
  var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
959
+ var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
701
960
  function normalizeHeaders(input) {
702
961
  const out = {};
703
962
  if (!input) return out;
@@ -706,6 +965,11 @@ function normalizeHeaders(input) {
706
965
  });
707
966
  return out;
708
967
  }
968
+ function extractInputUrl(input) {
969
+ if (typeof input === "string") return input;
970
+ if (input instanceof URL) return input.href;
971
+ return input.url;
972
+ }
709
973
  function createSandboxProxyFetch(connectionId) {
710
974
  return async (input, init) => {
711
975
  const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
@@ -715,10 +979,17 @@ function createSandboxProxyFetch(connectionId) {
715
979
  "Connection proxy is not configured. Please check your deployment settings."
716
980
  );
717
981
  }
718
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
982
+ const originalUrl = extractInputUrl(input);
983
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
984
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
985
+ const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
986
+ return fetch(sessionUrl, {
987
+ method: "POST",
988
+ headers: { Authorization: `Bearer ${token}` }
989
+ });
990
+ }
719
991
  const originalMethod = init?.method ?? "GET";
720
992
  const originalBody = init?.body ? JSON.parse(init.body) : void 0;
721
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
722
993
  const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
723
994
  return fetch(proxyUrl, {
724
995
  method: "POST",
@@ -744,10 +1015,9 @@ function createDeployedAppProxyFetch(connectionId) {
744
1015
  }
745
1016
  const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
746
1017
  const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
1018
+ const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
747
1019
  return async (input, init) => {
748
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
749
- const originalMethod = init?.method ?? "GET";
750
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
1020
+ const originalUrl = extractInputUrl(input);
751
1021
  const c = getContext();
752
1022
  const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
753
1023
  if (!appSession) {
@@ -755,6 +1025,14 @@ function createDeployedAppProxyFetch(connectionId) {
755
1025
  "No authentication method available for connection proxy."
756
1026
  );
757
1027
  }
1028
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
1029
+ return fetch(sessionUrl, {
1030
+ method: "POST",
1031
+ headers: { Authorization: `Bearer ${appSession}` }
1032
+ });
1033
+ }
1034
+ const originalMethod = init?.method ?? "GET";
1035
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
758
1036
  return fetch(proxyUrl, {
759
1037
  method: "POST",
760
1038
  headers: {