@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
@@ -67,6 +67,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
67
67
  tools;
68
68
  query;
69
69
  checkConnection;
70
+ /**
71
+ * SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
72
+ * implement this expose a step-by-step exploration flow (database/schema/
73
+ * table/etc. discovery) that the dashboard backend drives via the
74
+ * `/connections/:connectionId/setup` endpoint. Implement by delegating to
75
+ * `runSetupFlow` from `setup-flow.ts`.
76
+ */
77
+ setup;
78
+ /**
79
+ * Opt-out of the default "verify before save" behavior on connection
80
+ * creation. The backend invokes `checkConnection` synchronously while
81
+ * creating the connection and aborts (no row inserted) if it fails — this
82
+ * flag disables that for connectors where the check cannot succeed pre-save:
83
+ *
84
+ * - `squadbase-db` populates `connection-url` only after Neon provisioning
85
+ * - OAuth connectors require an OAuth-aware proxyFetch keyed by the
86
+ * connectionId, which doesn't exist until the row is saved
87
+ *
88
+ * Exceptions are the explicit position; new credential-input connectors get
89
+ * the default verify-on-create behavior without opt-in.
90
+ */
91
+ skipConnectionCheckOnCreate;
70
92
  constructor(config) {
71
93
  this.slug = config.slug;
72
94
  this.authType = config.authType;
@@ -83,6 +105,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
83
105
  this.tools = config.tools;
84
106
  this.query = config.query;
85
107
  this.checkConnection = config.checkConnection;
108
+ this.setup = config.setup;
109
+ this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
86
110
  }
87
111
  get connectorKey() {
88
112
  return _ConnectorPlugin.deriveKey(this.slug, this.authType);
@@ -147,6 +171,51 @@ var ConnectorPlugin = class _ConnectorPlugin {
147
171
  }
148
172
  };
149
173
 
174
+ // ../connectors/src/setup-flow.ts
175
+ async function runSetupFlow(flow, params, ctx, config) {
176
+ const runtime = {
177
+ params,
178
+ language: ctx.language,
179
+ config
180
+ };
181
+ let state = flow.initialState();
182
+ let answerIdx = 0;
183
+ for (const step of flow.steps) {
184
+ const ans = ctx.answers[answerIdx];
185
+ if (ans && ans.questionSlug === step.slug) {
186
+ state = step.applyAnswer(state, ans.answer);
187
+ answerIdx += 1;
188
+ continue;
189
+ }
190
+ if (step.type === "text") {
191
+ return {
192
+ type: "nextQuestion",
193
+ questionSlug: step.slug,
194
+ question: step.question[ctx.language],
195
+ questionType: "text"
196
+ };
197
+ }
198
+ const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
199
+ if (options.length === 0) {
200
+ continue;
201
+ }
202
+ return {
203
+ type: "nextQuestion",
204
+ questionSlug: step.slug,
205
+ question: step.question[ctx.language],
206
+ questionType: step.type,
207
+ options
208
+ };
209
+ }
210
+ const dataInvestigationResult = await flow.finalize(state, runtime);
211
+ return { type: "fulfilled", dataInvestigationResult };
212
+ }
213
+ async function resolveSetupSelection(params) {
214
+ const { selected, allSentinel, fetchAll, limit } = params;
215
+ const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
216
+ return resolved.slice(0, limit);
217
+ }
218
+
150
219
  // ../connectors/src/auth-types.ts
151
220
  var AUTH_TYPES = {
152
221
  OAUTH: "oauth",
@@ -307,6 +376,93 @@ var hubspotOnboarding = new ConnectorOnboarding({
307
376
  }
308
377
  });
309
378
 
379
+ // ../connectors/src/connectors/hubspot-oauth/utils.ts
380
+ var BASE_URL3 = "https://api.hubapi.com";
381
+ function apiFetch(proxyFetch, path2, init) {
382
+ const url = `${BASE_URL3}${path2.startsWith("/") ? "" : "/"}${path2}`;
383
+ return proxyFetch(url, init);
384
+ }
385
+
386
+ // ../connectors/src/connectors/hubspot-oauth/setup-flow.ts
387
+ var HUBSPOT_SETUP_MAX_OBJECT_TYPES = 10;
388
+ var HUBSPOT_SETUP_MAX_PROPERTIES = 50;
389
+ var HUBSPOT_OBJECT_TYPES = [
390
+ { value: "contacts", label: "Contacts" },
391
+ { value: "companies", label: "Companies" },
392
+ { value: "deals", label: "Deals" },
393
+ { value: "tickets", label: "Tickets" },
394
+ { value: "products", label: "Products" },
395
+ { value: "notes", label: "Notes" },
396
+ { value: "calls", label: "Calls" },
397
+ { value: "emails", label: "Emails" },
398
+ { value: "meetings", label: "Meetings" },
399
+ { value: "tasks", label: "Tasks" }
400
+ ];
401
+ async function listProperties(proxyFetch, objectType) {
402
+ const res = await apiFetch(proxyFetch, `/crm/v3/properties/${objectType}`);
403
+ if (!res.ok) {
404
+ const body = await res.text().catch(() => res.statusText);
405
+ throw new Error(
406
+ `hubspot-oauth: listProperties(${objectType}) failed (${res.status}): ${body}`
407
+ );
408
+ }
409
+ const data = await res.json();
410
+ return data.results ?? [];
411
+ }
412
+ var hubspotOauthSetupFlow = {
413
+ initialState: () => ({}),
414
+ steps: [
415
+ {
416
+ slug: "objectTypes",
417
+ type: "multiSelect",
418
+ question: {
419
+ ja: "\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3067\u6982\u89B3\u3057\u305F\u3044CRM\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
420
+ en: "Select the CRM object types to include in setup (multi-select allowed)"
421
+ },
422
+ async fetchOptions(_state, _rt) {
423
+ return HUBSPOT_OBJECT_TYPES.map((o) => ({
424
+ value: o.value,
425
+ label: o.label
426
+ }));
427
+ },
428
+ applyAnswer: (state, answer) => ({ ...state, objectTypes: answer })
429
+ }
430
+ ],
431
+ async finalize(state, rt) {
432
+ if (!state.objectTypes) {
433
+ throw new Error("HubSpot setup: incomplete state on finalize");
434
+ }
435
+ const targetObjectTypes = await resolveSetupSelection({
436
+ selected: state.objectTypes,
437
+ allSentinel: "__ALL__",
438
+ fetchAll: async () => HUBSPOT_OBJECT_TYPES.map((o) => o.value),
439
+ limit: HUBSPOT_SETUP_MAX_OBJECT_TYPES
440
+ });
441
+ const sections = ["## HubSpot", ""];
442
+ for (const objectType of targetObjectTypes) {
443
+ sections.push(`### Object: ${objectType}`, "");
444
+ const props = await listProperties(rt.config.proxyFetch, objectType);
445
+ const limited = props.slice(0, HUBSPOT_SETUP_MAX_PROPERTIES);
446
+ sections.push("| Property | Type | Label |");
447
+ sections.push("|----------|------|-------|");
448
+ for (const p of limited) {
449
+ const name = (p.name ?? "").replace(/\|/g, "\\|");
450
+ const type = (p.type ?? "").replace(/\|/g, "\\|");
451
+ const label = (p.label ?? "").replace(/\|/g, "\\|");
452
+ sections.push(`| ${name} | ${type} | ${label || "-"} |`);
453
+ }
454
+ if (props.length > HUBSPOT_SETUP_MAX_PROPERTIES) {
455
+ sections.push(
456
+ "",
457
+ `_Showing first ${HUBSPOT_SETUP_MAX_PROPERTIES} of ${props.length} properties._`
458
+ );
459
+ }
460
+ sections.push("");
461
+ }
462
+ return sections.join("\n");
463
+ }
464
+ };
465
+
310
466
  // ../connectors/src/connectors/hubspot-oauth/parameters.ts
311
467
  var parameters = {};
312
468
 
@@ -315,6 +471,7 @@ var tools = { request: requestTool };
315
471
  var hubspotOauthConnector = new ConnectorPlugin({
316
472
  slug: "hubspot",
317
473
  authType: AUTH_TYPES.OAUTH,
474
+ skipConnectionCheckOnCreate: true,
318
475
  name: "HubSpot",
319
476
  description: "Connect to HubSpot CRM for contacts, deals, companies, and marketing data using OAuth.",
320
477
  iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/5UcSkKkzhUMA4RsM45ynuo/43b967e36915ca0fc5d277684b204320/hubspot.svg",
@@ -423,6 +580,7 @@ const data = await res.json();
423
580
  \`\`\``
424
581
  },
425
582
  tools,
583
+ setup: (params, ctx, config) => runSetupFlow(hubspotOauthSetupFlow, params, ctx, config),
426
584
  async checkConnection(_params, config) {
427
585
  const { proxyFetch } = config;
428
586
  try {
@@ -473,6 +631,7 @@ function resolveEnvVarOptional(entry, key) {
473
631
  import { getContext } from "hono/context-storage";
474
632
  import { getCookie } from "hono/cookie";
475
633
  var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
634
+ var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
476
635
  function normalizeHeaders(input) {
477
636
  const out = {};
478
637
  if (!input) return out;
@@ -481,6 +640,11 @@ function normalizeHeaders(input) {
481
640
  });
482
641
  return out;
483
642
  }
643
+ function extractInputUrl(input) {
644
+ if (typeof input === "string") return input;
645
+ if (input instanceof URL) return input.href;
646
+ return input.url;
647
+ }
484
648
  function createSandboxProxyFetch(connectionId) {
485
649
  return async (input, init) => {
486
650
  const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
@@ -490,10 +654,17 @@ function createSandboxProxyFetch(connectionId) {
490
654
  "Connection proxy is not configured. Please check your deployment settings."
491
655
  );
492
656
  }
493
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
657
+ const originalUrl = extractInputUrl(input);
658
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
659
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
660
+ const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
661
+ return fetch(sessionUrl, {
662
+ method: "POST",
663
+ headers: { Authorization: `Bearer ${token}` }
664
+ });
665
+ }
494
666
  const originalMethod = init?.method ?? "GET";
495
667
  const originalBody = init?.body ? JSON.parse(init.body) : void 0;
496
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
497
668
  const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
498
669
  return fetch(proxyUrl, {
499
670
  method: "POST",
@@ -519,10 +690,9 @@ function createDeployedAppProxyFetch(connectionId) {
519
690
  }
520
691
  const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
521
692
  const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
693
+ const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
522
694
  return async (input, init) => {
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;
695
+ const originalUrl = extractInputUrl(input);
526
696
  const c = getContext();
527
697
  const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
528
698
  if (!appSession) {
@@ -530,6 +700,14 @@ function createDeployedAppProxyFetch(connectionId) {
530
700
  "No authentication method available for connection proxy."
531
701
  );
532
702
  }
703
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
704
+ return fetch(sessionUrl, {
705
+ method: "POST",
706
+ headers: { Authorization: `Bearer ${appSession}` }
707
+ });
708
+ }
709
+ const originalMethod = init?.method ?? "GET";
710
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
533
711
  return fetch(proxyUrl, {
534
712
  method: "POST",
535
713
  headers: {
@@ -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/hubspot/parameters.ts
57
+ init_parameter_definition();
46
58
  var parameters = {
47
59
  apiKey: new ParameterDefinition({
48
60
  slug: "api-key",
@@ -196,6 +208,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
196
208
  tools;
197
209
  query;
198
210
  checkConnection;
211
+ /**
212
+ * SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
213
+ * implement this expose a step-by-step exploration flow (database/schema/
214
+ * table/etc. discovery) that the dashboard backend drives via the
215
+ * `/connections/:connectionId/setup` endpoint. Implement by delegating to
216
+ * `runSetupFlow` from `setup-flow.ts`.
217
+ */
218
+ setup;
219
+ /**
220
+ * Opt-out of the default "verify before save" behavior on connection
221
+ * creation. The backend invokes `checkConnection` synchronously while
222
+ * creating the connection and aborts (no row inserted) if it fails — this
223
+ * flag disables that for connectors where the check cannot succeed pre-save:
224
+ *
225
+ * - `squadbase-db` populates `connection-url` only after Neon provisioning
226
+ * - OAuth connectors require an OAuth-aware proxyFetch keyed by the
227
+ * connectionId, which doesn't exist until the row is saved
228
+ *
229
+ * Exceptions are the explicit position; new credential-input connectors get
230
+ * the default verify-on-create behavior without opt-in.
231
+ */
232
+ skipConnectionCheckOnCreate;
199
233
  constructor(config) {
200
234
  this.slug = config.slug;
201
235
  this.authType = config.authType;
@@ -212,6 +246,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
212
246
  this.tools = config.tools;
213
247
  this.query = config.query;
214
248
  this.checkConnection = config.checkConnection;
249
+ this.setup = config.setup;
250
+ this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
215
251
  }
216
252
  get connectorKey() {
217
253
  return _ConnectorPlugin.deriveKey(this.slug, this.authType);
@@ -276,6 +312,51 @@ var ConnectorPlugin = class _ConnectorPlugin {
276
312
  }
277
313
  };
278
314
 
315
+ // ../connectors/src/setup-flow.ts
316
+ async function runSetupFlow(flow, params, ctx, config) {
317
+ const runtime = {
318
+ params,
319
+ language: ctx.language,
320
+ config
321
+ };
322
+ let state = flow.initialState();
323
+ let answerIdx = 0;
324
+ for (const step of flow.steps) {
325
+ const ans = ctx.answers[answerIdx];
326
+ if (ans && ans.questionSlug === step.slug) {
327
+ state = step.applyAnswer(state, ans.answer);
328
+ answerIdx += 1;
329
+ continue;
330
+ }
331
+ if (step.type === "text") {
332
+ return {
333
+ type: "nextQuestion",
334
+ questionSlug: step.slug,
335
+ question: step.question[ctx.language],
336
+ questionType: "text"
337
+ };
338
+ }
339
+ const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
340
+ if (options.length === 0) {
341
+ continue;
342
+ }
343
+ return {
344
+ type: "nextQuestion",
345
+ questionSlug: step.slug,
346
+ question: step.question[ctx.language],
347
+ questionType: step.type,
348
+ options
349
+ };
350
+ }
351
+ const dataInvestigationResult = await flow.finalize(state, runtime);
352
+ return { type: "fulfilled", dataInvestigationResult };
353
+ }
354
+ async function resolveSetupSelection(params) {
355
+ const { selected, allSentinel, fetchAll, limit } = params;
356
+ const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
357
+ return resolved.slice(0, limit);
358
+ }
359
+
279
360
  // ../connectors/src/auth-types.ts
280
361
  var AUTH_TYPES = {
281
362
  OAUTH: "oauth",
@@ -298,9 +379,105 @@ var hubspotOnboarding = new ConnectorOnboarding({
298
379
  }
299
380
  });
300
381
 
382
+ // ../connectors/src/connectors/hubspot/utils.ts
383
+ var BASE_URL2 = "https://api.hubapi.com";
384
+ async function apiFetch(params, path2, init) {
385
+ const apiKey = params[parameters.apiKey.slug];
386
+ if (!apiKey) {
387
+ throw new Error("hubspot: missing required parameter: api-key");
388
+ }
389
+ const url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
390
+ const headers = new Headers(init?.headers);
391
+ headers.set("Authorization", `Bearer ${apiKey}`);
392
+ headers.set("Accept", "application/json");
393
+ return fetch(url, { ...init, headers });
394
+ }
395
+
396
+ // ../connectors/src/connectors/hubspot/setup-flow.ts
397
+ var HUBSPOT_SETUP_MAX_OBJECT_TYPES = 10;
398
+ var HUBSPOT_SETUP_MAX_PROPERTIES = 50;
399
+ var HUBSPOT_OBJECT_TYPES = [
400
+ { value: "contacts", label: "Contacts" },
401
+ { value: "companies", label: "Companies" },
402
+ { value: "deals", label: "Deals" },
403
+ { value: "tickets", label: "Tickets" },
404
+ { value: "products", label: "Products" },
405
+ { value: "notes", label: "Notes" },
406
+ { value: "calls", label: "Calls" },
407
+ { value: "emails", label: "Emails" },
408
+ { value: "meetings", label: "Meetings" },
409
+ { value: "tasks", label: "Tasks" }
410
+ ];
411
+ async function listProperties(params, objectType) {
412
+ const res = await apiFetch(params, `/crm/v3/properties/${objectType}`);
413
+ if (!res.ok) {
414
+ const body = await res.text().catch(() => res.statusText);
415
+ throw new Error(
416
+ `hubspot: listProperties(${objectType}) failed (${res.status}): ${body}`
417
+ );
418
+ }
419
+ const data = await res.json();
420
+ return data.results ?? [];
421
+ }
422
+ var hubspotSetupFlow = {
423
+ initialState: () => ({}),
424
+ steps: [
425
+ {
426
+ slug: "objectTypes",
427
+ type: "multiSelect",
428
+ question: {
429
+ ja: "\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3067\u6982\u89B3\u3057\u305F\u3044CRM\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
430
+ en: "Select the CRM object types to include in setup (multi-select allowed)"
431
+ },
432
+ async fetchOptions(_state, _rt) {
433
+ return HUBSPOT_OBJECT_TYPES.map((o) => ({
434
+ value: o.value,
435
+ label: o.label
436
+ }));
437
+ },
438
+ applyAnswer: (state, answer) => ({ ...state, objectTypes: answer })
439
+ }
440
+ ],
441
+ async finalize(state, rt) {
442
+ if (!state.objectTypes) {
443
+ throw new Error("HubSpot setup: incomplete state on finalize");
444
+ }
445
+ const targetObjectTypes = await resolveSetupSelection({
446
+ selected: state.objectTypes,
447
+ // No "all" sentinel — the list is fixed and small, so explicit selection
448
+ // is the only path. resolveSetupSelection still enforces the cap.
449
+ allSentinel: "__ALL__",
450
+ fetchAll: async () => HUBSPOT_OBJECT_TYPES.map((o) => o.value),
451
+ limit: HUBSPOT_SETUP_MAX_OBJECT_TYPES
452
+ });
453
+ const sections = ["## HubSpot", ""];
454
+ for (const objectType of targetObjectTypes) {
455
+ sections.push(`### Object: ${objectType}`, "");
456
+ const props = await listProperties(rt.params, objectType);
457
+ const limited = props.slice(0, HUBSPOT_SETUP_MAX_PROPERTIES);
458
+ sections.push("| Property | Type | Label |");
459
+ sections.push("|----------|------|-------|");
460
+ for (const p of limited) {
461
+ const name = (p.name ?? "").replace(/\|/g, "\\|");
462
+ const type = (p.type ?? "").replace(/\|/g, "\\|");
463
+ const label = (p.label ?? "").replace(/\|/g, "\\|");
464
+ sections.push(`| ${name} | ${type} | ${label || "-"} |`);
465
+ }
466
+ if (props.length > HUBSPOT_SETUP_MAX_PROPERTIES) {
467
+ sections.push(
468
+ "",
469
+ `_Showing first ${HUBSPOT_SETUP_MAX_PROPERTIES} of ${props.length} properties._`
470
+ );
471
+ }
472
+ sections.push("");
473
+ }
474
+ return sections.join("\n");
475
+ }
476
+ };
477
+
301
478
  // ../connectors/src/connectors/hubspot/tools/request.ts
302
479
  import { z } from "zod";
303
- var BASE_URL2 = "https://api.hubapi.com";
480
+ var BASE_URL3 = "https://api.hubapi.com";
304
481
  var REQUEST_TIMEOUT_MS = 6e4;
305
482
  var inputSchema = z.object({
306
483
  toolUseIntent: z.string().optional().describe(
@@ -347,7 +524,7 @@ Use the search endpoint (POST /crm/v3/objects/{objectType}/search) for complex q
347
524
  );
348
525
  try {
349
526
  const apiKey = parameters.apiKey.getValue(connection2);
350
- const url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
527
+ const url = `${BASE_URL3}${path2.startsWith("/") ? "" : "/"}${path2}`;
351
528
  const controller = new AbortController();
352
529
  const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
353
530
  try {
@@ -522,7 +699,42 @@ export default async function handler(c: Context) {
522
699
  - \`limit\` \u2014 \u30DA\u30FC\u30B8\u3042\u305F\u308A\u306E\u6700\u5927\u7D50\u679C\u6570\uFF08\u6700\u5927100\uFF09
523
700
  - \`after\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u30AA\u30D5\u30BB\u30C3\u30C8`
524
701
  },
525
- tools
702
+ tools,
703
+ setup: (params, ctx, config) => runSetupFlow(hubspotSetupFlow, params, ctx, config),
704
+ async checkConnection(params, _config) {
705
+ const apiKey = params[parameters.apiKey.slug];
706
+ if (!apiKey) {
707
+ return {
708
+ success: false,
709
+ error: `Missing required parameter: ${parameters.apiKey.slug}`
710
+ };
711
+ }
712
+ try {
713
+ const res = await fetch(
714
+ "https://api.hubapi.com/account-info/v3/details",
715
+ {
716
+ method: "GET",
717
+ headers: {
718
+ Authorization: `Bearer ${apiKey}`,
719
+ Accept: "application/json"
720
+ }
721
+ }
722
+ );
723
+ if (!res.ok) {
724
+ const errText = await res.text().catch(() => res.statusText);
725
+ return {
726
+ success: false,
727
+ error: `HubSpot API failed: HTTP ${res.status} ${errText}`
728
+ };
729
+ }
730
+ return { success: true };
731
+ } catch (error) {
732
+ return {
733
+ success: false,
734
+ error: error instanceof Error ? error.message : String(error)
735
+ };
736
+ }
737
+ }
526
738
  });
527
739
 
528
740
  // src/connectors/create-connector-sdk.ts
@@ -551,6 +763,7 @@ function resolveEnvVarOptional(entry, key) {
551
763
  import { getContext } from "hono/context-storage";
552
764
  import { getCookie } from "hono/cookie";
553
765
  var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
766
+ var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
554
767
  function normalizeHeaders(input) {
555
768
  const out = {};
556
769
  if (!input) return out;
@@ -559,6 +772,11 @@ function normalizeHeaders(input) {
559
772
  });
560
773
  return out;
561
774
  }
775
+ function extractInputUrl(input) {
776
+ if (typeof input === "string") return input;
777
+ if (input instanceof URL) return input.href;
778
+ return input.url;
779
+ }
562
780
  function createSandboxProxyFetch(connectionId) {
563
781
  return async (input, init) => {
564
782
  const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
@@ -568,10 +786,17 @@ function createSandboxProxyFetch(connectionId) {
568
786
  "Connection proxy is not configured. Please check your deployment settings."
569
787
  );
570
788
  }
571
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
789
+ const originalUrl = extractInputUrl(input);
790
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
791
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
792
+ const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
793
+ return fetch(sessionUrl, {
794
+ method: "POST",
795
+ headers: { Authorization: `Bearer ${token}` }
796
+ });
797
+ }
572
798
  const originalMethod = init?.method ?? "GET";
573
799
  const originalBody = init?.body ? JSON.parse(init.body) : void 0;
574
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
575
800
  const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
576
801
  return fetch(proxyUrl, {
577
802
  method: "POST",
@@ -597,10 +822,9 @@ function createDeployedAppProxyFetch(connectionId) {
597
822
  }
598
823
  const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
599
824
  const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
825
+ const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
600
826
  return async (input, init) => {
601
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
602
- const originalMethod = init?.method ?? "GET";
603
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
827
+ const originalUrl = extractInputUrl(input);
604
828
  const c = getContext();
605
829
  const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
606
830
  if (!appSession) {
@@ -608,6 +832,14 @@ function createDeployedAppProxyFetch(connectionId) {
608
832
  "No authentication method available for connection proxy."
609
833
  );
610
834
  }
835
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
836
+ return fetch(sessionUrl, {
837
+ method: "POST",
838
+ headers: { Authorization: `Bearer ${appSession}` }
839
+ });
840
+ }
841
+ const originalMethod = init?.method ?? "GET";
842
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
611
843
  return fetch(proxyUrl, {
612
844
  method: "POST",
613
845
  headers: {