@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.
- package/dist/cli/index.js +14375 -1652
- package/dist/connectors/airtable-oauth.js +282 -46
- package/dist/connectors/airtable.js +319 -51
- package/dist/connectors/amplitude.js +322 -47
- package/dist/connectors/anthropic.js +135 -47
- package/dist/connectors/asana.js +327 -49
- package/dist/connectors/attio.js +302 -49
- package/dist/connectors/aws-billing.js +287 -46
- package/dist/connectors/azure-sql.js +421 -102
- package/dist/connectors/backlog-api-key.js +317 -47
- package/dist/connectors/clickup.js +338 -49
- package/dist/connectors/cosmosdb.js +305 -50
- package/dist/connectors/customerio.js +319 -47
- package/dist/connectors/dbt.js +340 -47
- package/dist/connectors/freshdesk.js +342 -53
- package/dist/connectors/freshsales.js +333 -52
- package/dist/connectors/freshservice.js +361 -53
- package/dist/connectors/gamma.js +327 -52
- package/dist/connectors/gemini.js +134 -47
- package/dist/connectors/github.js +386 -49
- package/dist/connectors/gmail-oauth.js +204 -7
- package/dist/connectors/gmail.js +350 -47
- package/dist/connectors/google-ads.js +288 -46
- package/dist/connectors/google-analytics-oauth.js +310 -46
- package/dist/connectors/google-analytics.js +547 -87
- package/dist/connectors/google-audit-log.js +438 -47
- package/dist/connectors/google-calendar-oauth.js +259 -46
- package/dist/connectors/google-calendar.js +359 -47
- package/dist/connectors/google-docs.js +220 -6
- package/dist/connectors/google-drive.js +262 -5
- package/dist/connectors/google-search-console-oauth.js +256 -46
- package/dist/connectors/google-sheets.js +272 -47
- package/dist/connectors/google-slides.js +205 -6
- package/dist/connectors/grafana.js +332 -49
- package/dist/connectors/hubspot-oauth.js +208 -5
- package/dist/connectors/hubspot.js +306 -49
- package/dist/connectors/influxdb.js +416 -51
- package/dist/connectors/intercom-oauth.js +210 -5
- package/dist/connectors/intercom.js +302 -49
- package/dist/connectors/jdbc.js +762 -110
- package/dist/connectors/jira-api-key.js +326 -47
- package/dist/connectors/kintone-api-token.js +281 -47
- package/dist/connectors/kintone.js +328 -47
- package/dist/connectors/linear.js +330 -49
- package/dist/connectors/linkedin-ads.js +268 -50
- package/dist/connectors/mailchimp-oauth.js +268 -46
- package/dist/connectors/mailchimp.js +320 -49
- package/dist/connectors/meta-ads-oauth.js +273 -48
- package/dist/connectors/meta-ads.js +285 -50
- package/dist/connectors/mixpanel.js +338 -47
- package/dist/connectors/monday.js +360 -49
- package/dist/connectors/mongodb.js +319 -57
- package/dist/connectors/notion-oauth.js +231 -5
- package/dist/connectors/notion.js +323 -51
- package/dist/connectors/openai.js +134 -47
- package/dist/connectors/oracle.js +454 -103
- package/dist/connectors/outlook-oauth.js +204 -5
- package/dist/connectors/powerbi-oauth.js +498 -5
- package/dist/connectors/salesforce.js +384 -49
- package/dist/connectors/semrush.js +609 -49
- package/dist/connectors/sentry.js +289 -50
- package/dist/connectors/shopify-oauth.js +187 -5
- package/dist/connectors/shopify.js +357 -47
- package/dist/connectors/sqlserver.js +415 -102
- package/dist/connectors/stripe-api-key.js +269 -46
- package/dist/connectors/stripe-oauth.js +202 -5
- package/dist/connectors/supabase.js +303 -48
- package/dist/connectors/tableau.js +536 -163
- package/dist/connectors/tiktok-ads.js +279 -48
- package/dist/connectors/wix-store.js +320 -49
- package/dist/connectors/zendesk-oauth.js +239 -5
- package/dist/connectors/zendesk.js +358 -47
- package/dist/index.d.ts +149 -1
- package/dist/index.js +15057 -2117
- package/dist/main.js +15005 -2073
- package/dist/vite-plugin.js +14752 -2019
- 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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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/freshsales/parameters.ts
|
|
57
|
+
init_parameter_definition();
|
|
46
58
|
var parameters = {
|
|
47
59
|
bundleAlias: new ParameterDefinition({
|
|
48
60
|
slug: "bundle-alias",
|
|
@@ -299,6 +311,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
299
311
|
tools;
|
|
300
312
|
query;
|
|
301
313
|
checkConnection;
|
|
314
|
+
/**
|
|
315
|
+
* SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
|
|
316
|
+
* implement this expose a step-by-step exploration flow (database/schema/
|
|
317
|
+
* table/etc. discovery) that the dashboard backend drives via the
|
|
318
|
+
* `/connections/:connectionId/setup` endpoint. Implement by delegating to
|
|
319
|
+
* `runSetupFlow` from `setup-flow.ts`.
|
|
320
|
+
*/
|
|
321
|
+
setup;
|
|
322
|
+
/**
|
|
323
|
+
* Opt-out of the default "verify before save" behavior on connection
|
|
324
|
+
* creation. The backend invokes `checkConnection` synchronously while
|
|
325
|
+
* creating the connection and aborts (no row inserted) if it fails — this
|
|
326
|
+
* flag disables that for connectors where the check cannot succeed pre-save:
|
|
327
|
+
*
|
|
328
|
+
* - `squadbase-db` populates `connection-url` only after Neon provisioning
|
|
329
|
+
* - OAuth connectors require an OAuth-aware proxyFetch keyed by the
|
|
330
|
+
* connectionId, which doesn't exist until the row is saved
|
|
331
|
+
*
|
|
332
|
+
* Exceptions are the explicit position; new credential-input connectors get
|
|
333
|
+
* the default verify-on-create behavior without opt-in.
|
|
334
|
+
*/
|
|
335
|
+
skipConnectionCheckOnCreate;
|
|
302
336
|
constructor(config) {
|
|
303
337
|
this.slug = config.slug;
|
|
304
338
|
this.authType = config.authType;
|
|
@@ -315,6 +349,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
315
349
|
this.tools = config.tools;
|
|
316
350
|
this.query = config.query;
|
|
317
351
|
this.checkConnection = config.checkConnection;
|
|
352
|
+
this.setup = config.setup;
|
|
353
|
+
this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
|
|
318
354
|
}
|
|
319
355
|
get connectorKey() {
|
|
320
356
|
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
@@ -379,6 +415,76 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
379
415
|
}
|
|
380
416
|
};
|
|
381
417
|
|
|
418
|
+
// ../connectors/src/setup-flow.ts
|
|
419
|
+
async function runSetupFlow(flow, params, ctx, config) {
|
|
420
|
+
const runtime = {
|
|
421
|
+
params,
|
|
422
|
+
language: ctx.language,
|
|
423
|
+
config
|
|
424
|
+
};
|
|
425
|
+
let state = flow.initialState();
|
|
426
|
+
let answerIdx = 0;
|
|
427
|
+
const pendingParameterUpdates = [];
|
|
428
|
+
for (const step of flow.steps) {
|
|
429
|
+
const ans = ctx.answers[answerIdx];
|
|
430
|
+
if (ans && ans.questionSlug === step.slug) {
|
|
431
|
+
state = step.applyAnswer(state, ans.answer);
|
|
432
|
+
if (step.toParameterUpdates) {
|
|
433
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
434
|
+
}
|
|
435
|
+
answerIdx += 1;
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
439
|
+
if (step.type === "text") {
|
|
440
|
+
if (step.fetchOptions) {
|
|
441
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
442
|
+
if (options2.length === 0) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
type: "nextQuestion",
|
|
448
|
+
questionSlug: step.slug,
|
|
449
|
+
question: step.question[ctx.language],
|
|
450
|
+
questionType: "text",
|
|
451
|
+
allowFreeText: resolvedAllowFreeText,
|
|
452
|
+
...pendingParameterUpdates.length > 0 && {
|
|
453
|
+
parameterUpdates: pendingParameterUpdates
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
458
|
+
if (options.length === 0) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
type: "nextQuestion",
|
|
463
|
+
questionSlug: step.slug,
|
|
464
|
+
question: step.question[ctx.language],
|
|
465
|
+
questionType: step.type,
|
|
466
|
+
options,
|
|
467
|
+
allowFreeText: resolvedAllowFreeText,
|
|
468
|
+
...pendingParameterUpdates.length > 0 && {
|
|
469
|
+
parameterUpdates: pendingParameterUpdates
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
474
|
+
return {
|
|
475
|
+
type: "fulfilled",
|
|
476
|
+
dataInvestigationResult,
|
|
477
|
+
...pendingParameterUpdates.length > 0 && {
|
|
478
|
+
parameterUpdates: pendingParameterUpdates
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
async function resolveSetupSelection(params) {
|
|
483
|
+
const { selected, allSentinel, fetchAll, limit } = params;
|
|
484
|
+
const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
|
|
485
|
+
return resolved.slice(0, limit);
|
|
486
|
+
}
|
|
487
|
+
|
|
382
488
|
// ../connectors/src/auth-types.ts
|
|
383
489
|
var AUTH_TYPES = {
|
|
384
490
|
OAUTH: "oauth",
|
|
@@ -415,15 +521,134 @@ var freshsalesOnboarding = new ConnectorOnboarding({
|
|
|
415
521
|
}
|
|
416
522
|
});
|
|
417
523
|
|
|
418
|
-
// ../connectors/src/connectors/freshsales/
|
|
419
|
-
import { z } from "zod";
|
|
524
|
+
// ../connectors/src/connectors/freshsales/utils.ts
|
|
420
525
|
var BASE_PATH_SEGMENT = "/crm/sales/api";
|
|
421
|
-
var REQUEST_TIMEOUT_MS = 6e4;
|
|
422
526
|
function buildBaseUrl2(bundleAlias) {
|
|
423
527
|
const trimmed = bundleAlias.trim().replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
424
528
|
const subdomain = trimmed.split(".")[0];
|
|
425
529
|
return `https://${subdomain}.myfreshworks.com${BASE_PATH_SEGMENT}`;
|
|
426
530
|
}
|
|
531
|
+
async function apiFetch(params, path2, init) {
|
|
532
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
533
|
+
const bundle = params[parameters.bundleAlias.slug];
|
|
534
|
+
if (!apiKey || !bundle) {
|
|
535
|
+
throw new Error(
|
|
536
|
+
"freshsales: missing required parameter(s) (api-key, bundle-alias)"
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
const baseUrl = buildBaseUrl2(bundle);
|
|
540
|
+
const url = `${baseUrl}${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
541
|
+
const headers = new Headers(init?.headers);
|
|
542
|
+
headers.set("Authorization", `Token token=${apiKey}`);
|
|
543
|
+
headers.set("Accept", "application/json");
|
|
544
|
+
return fetch(url, { ...init, headers });
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ../connectors/src/connectors/freshsales/setup-flow.ts
|
|
548
|
+
var FRESHSALES_SETUP_MAX_ENTITIES = 5;
|
|
549
|
+
var FRESHSALES_ENTITIES = [
|
|
550
|
+
{
|
|
551
|
+
value: "contacts",
|
|
552
|
+
label: "Contacts",
|
|
553
|
+
filtersPath: "/contacts/filters",
|
|
554
|
+
recordsPath: (id) => `/contacts/view/${id}?per_page=1`
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
value: "accounts",
|
|
558
|
+
label: "Sales accounts",
|
|
559
|
+
filtersPath: "/sales_accounts/filters",
|
|
560
|
+
recordsPath: (id) => `/sales_accounts/view/${id}?per_page=1`
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
value: "deals",
|
|
564
|
+
label: "Deals",
|
|
565
|
+
filtersPath: "/deals/filters",
|
|
566
|
+
recordsPath: (id) => `/deals/view/${id}?per_page=1`
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
value: "leads",
|
|
570
|
+
label: "Leads",
|
|
571
|
+
filtersPath: "/leads/filters",
|
|
572
|
+
recordsPath: (id) => `/leads/view/${id}?per_page=1`
|
|
573
|
+
}
|
|
574
|
+
];
|
|
575
|
+
async function fetchEntityCount(params, entry) {
|
|
576
|
+
const filtersRes = await apiFetch(params, entry.filtersPath);
|
|
577
|
+
if (!filtersRes.ok) return null;
|
|
578
|
+
const filtersData = await filtersRes.json();
|
|
579
|
+
const firstView = filtersData.filters?.[0]?.id;
|
|
580
|
+
if (firstView == null) return null;
|
|
581
|
+
const recordsRes = await apiFetch(
|
|
582
|
+
params,
|
|
583
|
+
entry.recordsPath(String(firstView))
|
|
584
|
+
);
|
|
585
|
+
if (!recordsRes.ok) return null;
|
|
586
|
+
const recordsData = await recordsRes.json();
|
|
587
|
+
return recordsData.meta?.total ?? null;
|
|
588
|
+
}
|
|
589
|
+
var freshsalesSetupFlow = {
|
|
590
|
+
initialState: () => ({}),
|
|
591
|
+
steps: [
|
|
592
|
+
{
|
|
593
|
+
slug: "entities",
|
|
594
|
+
type: "multiSelect",
|
|
595
|
+
question: {
|
|
596
|
+
ja: "\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3067\u6982\u89B3\u3057\u305F\u3044Freshsales\u30A8\u30F3\u30C6\u30A3\u30C6\u30A3\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
|
|
597
|
+
en: "Select the Freshsales entities to include in setup (multi-select allowed)"
|
|
598
|
+
},
|
|
599
|
+
async fetchOptions(_state, _rt) {
|
|
600
|
+
return FRESHSALES_ENTITIES.map((e) => ({
|
|
601
|
+
value: e.value,
|
|
602
|
+
label: e.label
|
|
603
|
+
}));
|
|
604
|
+
},
|
|
605
|
+
applyAnswer: (state, answer) => ({ ...state, entities: answer })
|
|
606
|
+
}
|
|
607
|
+
],
|
|
608
|
+
async finalize(state, rt) {
|
|
609
|
+
if (!state.entities) {
|
|
610
|
+
throw new Error("Freshsales setup: incomplete state on finalize");
|
|
611
|
+
}
|
|
612
|
+
const targetEntities = await resolveSetupSelection({
|
|
613
|
+
selected: state.entities,
|
|
614
|
+
allSentinel: "__ALL__",
|
|
615
|
+
fetchAll: async () => FRESHSALES_ENTITIES.map((e) => e.value),
|
|
616
|
+
limit: FRESHSALES_SETUP_MAX_ENTITIES
|
|
617
|
+
});
|
|
618
|
+
const entityByValue = new Map(FRESHSALES_ENTITIES.map((e) => [e.value, e]));
|
|
619
|
+
const sections = [
|
|
620
|
+
"## Freshsales",
|
|
621
|
+
"",
|
|
622
|
+
"### Selected entities",
|
|
623
|
+
"",
|
|
624
|
+
"| Entity | Count (default view) |",
|
|
625
|
+
"|--------|----------------------|"
|
|
626
|
+
];
|
|
627
|
+
for (const value of targetEntities) {
|
|
628
|
+
const entity = entityByValue.get(value);
|
|
629
|
+
if (!entity) {
|
|
630
|
+
sections.push(`| ${value} | _unknown_ |`);
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
const count = await fetchEntityCount(rt.params, entity);
|
|
634
|
+
sections.push(
|
|
635
|
+
`| ${entity.label} (${entity.value}) | ${count == null ? "-" : count} |`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
sections.push("");
|
|
639
|
+
return sections.join("\n");
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// ../connectors/src/connectors/freshsales/tools/request.ts
|
|
644
|
+
import { z } from "zod";
|
|
645
|
+
var BASE_PATH_SEGMENT2 = "/crm/sales/api";
|
|
646
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
647
|
+
function buildBaseUrl3(bundleAlias) {
|
|
648
|
+
const trimmed = bundleAlias.trim().replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
649
|
+
const subdomain = trimmed.split(".")[0];
|
|
650
|
+
return `https://${subdomain}.myfreshworks.com${BASE_PATH_SEGMENT2}`;
|
|
651
|
+
}
|
|
427
652
|
var inputSchema = z.object({
|
|
428
653
|
toolUseIntent: z.string().optional().describe(
|
|
429
654
|
"Brief description of what you intend to accomplish with this tool call"
|
|
@@ -499,8 +724,8 @@ Includes: most GET endpoints accept \`?include=\` with a comma-separated list (\
|
|
|
499
724
|
try {
|
|
500
725
|
const apiKey = parameters.apiKey.getValue(connection2);
|
|
501
726
|
const bundle = parameters.bundleAlias.getValue(connection2);
|
|
502
|
-
const baseUrl =
|
|
503
|
-
const normalizedPath = normalizeRequestPath(path2,
|
|
727
|
+
const baseUrl = buildBaseUrl3(bundle);
|
|
728
|
+
const normalizedPath = normalizeRequestPath(path2, BASE_PATH_SEGMENT2);
|
|
504
729
|
const url = `${baseUrl}${normalizedPath}`;
|
|
505
730
|
const controller = new AbortController();
|
|
506
731
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
@@ -715,7 +940,43 @@ export default async function handler(c: Context) {
|
|
|
715
940
|
- GET \`/selector/lifecycle_stages\` \u2014 \u30E9\u30A4\u30D5\u30B5\u30A4\u30AF\u30EB\u30B9\u30C6\u30FC\u30B8
|
|
716
941
|
- GET \`/selector/territories\` / \`/selector/business_types\` / \`/selector/industry_types\` / \`/selector/contact_statuses\` / \`/selector/sales_activity_types\``
|
|
717
942
|
},
|
|
718
|
-
tools
|
|
943
|
+
tools,
|
|
944
|
+
setup: (params, ctx, config) => runSetupFlow(freshsalesSetupFlow, params, ctx, config),
|
|
945
|
+
async checkConnection(params, _config) {
|
|
946
|
+
const bundleAlias = params[parameters.bundleAlias.slug];
|
|
947
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
948
|
+
if (!bundleAlias || !apiKey) {
|
|
949
|
+
return {
|
|
950
|
+
success: false,
|
|
951
|
+
error: `Missing required parameter(s): ${parameters.bundleAlias.slug}, ${parameters.apiKey.slug}`
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
try {
|
|
955
|
+
const res = await fetch(
|
|
956
|
+
`https://${bundleAlias}.myfreshworks.com/crm/sales/api/selector/owners`,
|
|
957
|
+
{
|
|
958
|
+
method: "GET",
|
|
959
|
+
headers: {
|
|
960
|
+
Authorization: `Token token=${apiKey}`,
|
|
961
|
+
Accept: "application/json"
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
);
|
|
965
|
+
if (!res.ok) {
|
|
966
|
+
const errText = await res.text().catch(() => res.statusText);
|
|
967
|
+
return {
|
|
968
|
+
success: false,
|
|
969
|
+
error: `Freshsales API failed: HTTP ${res.status} ${errText}`
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
return { success: true };
|
|
973
|
+
} catch (error) {
|
|
974
|
+
return {
|
|
975
|
+
success: false,
|
|
976
|
+
error: error instanceof Error ? error.message : String(error)
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
}
|
|
719
980
|
});
|
|
720
981
|
|
|
721
982
|
// src/connectors/create-connector-sdk.ts
|
|
@@ -744,6 +1005,7 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
744
1005
|
import { getContext } from "hono/context-storage";
|
|
745
1006
|
import { getCookie } from "hono/cookie";
|
|
746
1007
|
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
1008
|
+
var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
|
|
747
1009
|
function normalizeHeaders(input) {
|
|
748
1010
|
const out = {};
|
|
749
1011
|
if (!input) return out;
|
|
@@ -752,6 +1014,11 @@ function normalizeHeaders(input) {
|
|
|
752
1014
|
});
|
|
753
1015
|
return out;
|
|
754
1016
|
}
|
|
1017
|
+
function extractInputUrl(input) {
|
|
1018
|
+
if (typeof input === "string") return input;
|
|
1019
|
+
if (input instanceof URL) return input.href;
|
|
1020
|
+
return input.url;
|
|
1021
|
+
}
|
|
755
1022
|
function createSandboxProxyFetch(connectionId) {
|
|
756
1023
|
return async (input, init) => {
|
|
757
1024
|
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
@@ -761,10 +1028,17 @@ function createSandboxProxyFetch(connectionId) {
|
|
|
761
1028
|
"Connection proxy is not configured. Please check your deployment settings."
|
|
762
1029
|
);
|
|
763
1030
|
}
|
|
764
|
-
const originalUrl =
|
|
1031
|
+
const originalUrl = extractInputUrl(input);
|
|
1032
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
1033
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
1034
|
+
const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
1035
|
+
return fetch(sessionUrl, {
|
|
1036
|
+
method: "POST",
|
|
1037
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
765
1040
|
const originalMethod = init?.method ?? "GET";
|
|
766
1041
|
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
767
|
-
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
768
1042
|
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
769
1043
|
return fetch(proxyUrl, {
|
|
770
1044
|
method: "POST",
|
|
@@ -790,10 +1064,9 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
790
1064
|
}
|
|
791
1065
|
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
792
1066
|
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
1067
|
+
const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
793
1068
|
return async (input, init) => {
|
|
794
|
-
const originalUrl =
|
|
795
|
-
const originalMethod = init?.method ?? "GET";
|
|
796
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
1069
|
+
const originalUrl = extractInputUrl(input);
|
|
797
1070
|
const c = getContext();
|
|
798
1071
|
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
799
1072
|
if (!appSession) {
|
|
@@ -801,6 +1074,14 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
801
1074
|
"No authentication method available for connection proxy."
|
|
802
1075
|
);
|
|
803
1076
|
}
|
|
1077
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
1078
|
+
return fetch(sessionUrl, {
|
|
1079
|
+
method: "POST",
|
|
1080
|
+
headers: { Authorization: `Bearer ${appSession}` }
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
const originalMethod = init?.method ?? "GET";
|
|
1084
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
804
1085
|
return fetch(proxyUrl, {
|
|
805
1086
|
method: "POST",
|
|
806
1087
|
headers: {
|