@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/semrush/parameters.ts
|
|
57
|
+
init_parameter_definition();
|
|
46
58
|
var parameters = {
|
|
47
59
|
apiKey: new ParameterDefinition({
|
|
48
60
|
slug: "api-key",
|
|
@@ -236,6 +248,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
236
248
|
tools;
|
|
237
249
|
query;
|
|
238
250
|
checkConnection;
|
|
251
|
+
/**
|
|
252
|
+
* SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
|
|
253
|
+
* implement this expose a step-by-step exploration flow (database/schema/
|
|
254
|
+
* table/etc. discovery) that the dashboard backend drives via the
|
|
255
|
+
* `/connections/:connectionId/setup` endpoint. Implement by delegating to
|
|
256
|
+
* `runSetupFlow` from `setup-flow.ts`.
|
|
257
|
+
*/
|
|
258
|
+
setup;
|
|
259
|
+
/**
|
|
260
|
+
* Opt-out of the default "verify before save" behavior on connection
|
|
261
|
+
* creation. The backend invokes `checkConnection` synchronously while
|
|
262
|
+
* creating the connection and aborts (no row inserted) if it fails — this
|
|
263
|
+
* flag disables that for connectors where the check cannot succeed pre-save:
|
|
264
|
+
*
|
|
265
|
+
* - `squadbase-db` populates `connection-url` only after Neon provisioning
|
|
266
|
+
* - OAuth connectors require an OAuth-aware proxyFetch keyed by the
|
|
267
|
+
* connectionId, which doesn't exist until the row is saved
|
|
268
|
+
*
|
|
269
|
+
* Exceptions are the explicit position; new credential-input connectors get
|
|
270
|
+
* the default verify-on-create behavior without opt-in.
|
|
271
|
+
*/
|
|
272
|
+
skipConnectionCheckOnCreate;
|
|
239
273
|
constructor(config) {
|
|
240
274
|
this.slug = config.slug;
|
|
241
275
|
this.authType = config.authType;
|
|
@@ -252,6 +286,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
252
286
|
this.tools = config.tools;
|
|
253
287
|
this.query = config.query;
|
|
254
288
|
this.checkConnection = config.checkConnection;
|
|
289
|
+
this.setup = config.setup;
|
|
290
|
+
this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
|
|
255
291
|
}
|
|
256
292
|
get connectorKey() {
|
|
257
293
|
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
@@ -316,6 +352,76 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
316
352
|
}
|
|
317
353
|
};
|
|
318
354
|
|
|
355
|
+
// ../connectors/src/setup-flow.ts
|
|
356
|
+
async function runSetupFlow(flow, params, ctx, config) {
|
|
357
|
+
const runtime = {
|
|
358
|
+
params,
|
|
359
|
+
language: ctx.language,
|
|
360
|
+
config
|
|
361
|
+
};
|
|
362
|
+
let state = flow.initialState();
|
|
363
|
+
let answerIdx = 0;
|
|
364
|
+
const pendingParameterUpdates = [];
|
|
365
|
+
for (const step of flow.steps) {
|
|
366
|
+
const ans = ctx.answers[answerIdx];
|
|
367
|
+
if (ans && ans.questionSlug === step.slug) {
|
|
368
|
+
state = step.applyAnswer(state, ans.answer);
|
|
369
|
+
if (step.toParameterUpdates) {
|
|
370
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
371
|
+
}
|
|
372
|
+
answerIdx += 1;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
376
|
+
if (step.type === "text") {
|
|
377
|
+
if (step.fetchOptions) {
|
|
378
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
379
|
+
if (options2.length === 0) {
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
type: "nextQuestion",
|
|
385
|
+
questionSlug: step.slug,
|
|
386
|
+
question: step.question[ctx.language],
|
|
387
|
+
questionType: "text",
|
|
388
|
+
allowFreeText: resolvedAllowFreeText,
|
|
389
|
+
...pendingParameterUpdates.length > 0 && {
|
|
390
|
+
parameterUpdates: pendingParameterUpdates
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
395
|
+
if (options.length === 0) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
type: "nextQuestion",
|
|
400
|
+
questionSlug: step.slug,
|
|
401
|
+
question: step.question[ctx.language],
|
|
402
|
+
questionType: step.type,
|
|
403
|
+
options,
|
|
404
|
+
allowFreeText: resolvedAllowFreeText,
|
|
405
|
+
...pendingParameterUpdates.length > 0 && {
|
|
406
|
+
parameterUpdates: pendingParameterUpdates
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
411
|
+
return {
|
|
412
|
+
type: "fulfilled",
|
|
413
|
+
dataInvestigationResult,
|
|
414
|
+
...pendingParameterUpdates.length > 0 && {
|
|
415
|
+
parameterUpdates: pendingParameterUpdates
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
async function resolveSetupSelection(params) {
|
|
420
|
+
const { selected, allSentinel, fetchAll, limit } = params;
|
|
421
|
+
const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
|
|
422
|
+
return resolved.slice(0, limit);
|
|
423
|
+
}
|
|
424
|
+
|
|
319
425
|
// ../connectors/src/auth-types.ts
|
|
320
426
|
var AUTH_TYPES = {
|
|
321
427
|
OAUTH: "oauth",
|
|
@@ -511,6 +617,439 @@ var semrushOnboarding = new ConnectorOnboarding({
|
|
|
511
617
|
}
|
|
512
618
|
});
|
|
513
619
|
|
|
620
|
+
// ../connectors/src/connectors/semrush/utils.ts
|
|
621
|
+
var BASE_URL3 = "https://api.semrush.com";
|
|
622
|
+
var PROJECTS_BASE_URL = `${BASE_URL3}/management/v1`;
|
|
623
|
+
function projectsApiFetch(params, path2, init) {
|
|
624
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
625
|
+
if (!apiKey) {
|
|
626
|
+
throw new Error(
|
|
627
|
+
`semrush: missing required parameter: ${parameters.apiKey.slug}`
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
const trimmedPath = path2.startsWith("/") ? path2 : `/${path2}`;
|
|
631
|
+
const url = new URL(`${PROJECTS_BASE_URL}${trimmedPath}`);
|
|
632
|
+
if (!url.searchParams.has("key")) {
|
|
633
|
+
url.searchParams.set("key", apiKey);
|
|
634
|
+
}
|
|
635
|
+
const headers = new Headers(init?.headers);
|
|
636
|
+
if (!headers.has("Accept")) headers.set("Accept", "application/json");
|
|
637
|
+
return fetch(url.toString(), { ...init, headers });
|
|
638
|
+
}
|
|
639
|
+
async function reportFetch(params, query) {
|
|
640
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
641
|
+
if (!apiKey) {
|
|
642
|
+
throw new Error(
|
|
643
|
+
`semrush: missing required parameter: ${parameters.apiKey.slug}`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const url = new URL(`${BASE_URL3}/`);
|
|
647
|
+
for (const [k, v] of Object.entries(query)) {
|
|
648
|
+
url.searchParams.set(k, v);
|
|
649
|
+
}
|
|
650
|
+
url.searchParams.set("key", apiKey);
|
|
651
|
+
const res = await fetch(url.toString());
|
|
652
|
+
const text = await res.text();
|
|
653
|
+
if (text.startsWith("ERROR ")) throw new Error(text.trim());
|
|
654
|
+
return parseSemicolonCsv(text);
|
|
655
|
+
}
|
|
656
|
+
async function backlinksFetch(params, query) {
|
|
657
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
658
|
+
if (!apiKey) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
`semrush: missing required parameter: ${parameters.apiKey.slug}`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const url = new URL(`${BASE_URL3}/analytics/v1/`);
|
|
664
|
+
for (const [k, v] of Object.entries(query)) {
|
|
665
|
+
url.searchParams.set(k, v);
|
|
666
|
+
}
|
|
667
|
+
url.searchParams.set("key", apiKey);
|
|
668
|
+
const res = await fetch(url.toString());
|
|
669
|
+
const text = await res.text();
|
|
670
|
+
if (text.startsWith("ERROR ")) throw new Error(text.trim());
|
|
671
|
+
return parseSemicolonCsv(text);
|
|
672
|
+
}
|
|
673
|
+
function parseSemicolonCsv(raw) {
|
|
674
|
+
const lines = raw.trim().split("\n").filter(Boolean);
|
|
675
|
+
if (lines.length === 0) return { columns: [], rows: [] };
|
|
676
|
+
const columns = lines[0].split(";");
|
|
677
|
+
const rows = lines.slice(1).map((line) => {
|
|
678
|
+
const values = line.split(";");
|
|
679
|
+
const row = {};
|
|
680
|
+
for (let i = 0; i < columns.length; i++) {
|
|
681
|
+
row[columns[i]] = values[i] ?? "";
|
|
682
|
+
}
|
|
683
|
+
return row;
|
|
684
|
+
});
|
|
685
|
+
return { columns, rows };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// ../connectors/src/connectors/semrush/setup-flow.ts
|
|
689
|
+
var ALL_PROJECTS = "__ALL_PROJECTS__";
|
|
690
|
+
var SEMRUSH_SETUP_MAX_PROJECTS = 10;
|
|
691
|
+
var SEMRUSH_DATABASES = [
|
|
692
|
+
{ value: "us", label: "United States" },
|
|
693
|
+
{ value: "uk", label: "United Kingdom" },
|
|
694
|
+
{ value: "ca", label: "Canada" },
|
|
695
|
+
{ value: "au", label: "Australia" },
|
|
696
|
+
{ value: "de", label: "Germany" },
|
|
697
|
+
{ value: "fr", label: "France" },
|
|
698
|
+
{ value: "es", label: "Spain" },
|
|
699
|
+
{ value: "it", label: "Italy" },
|
|
700
|
+
{ value: "br", label: "Brazil" },
|
|
701
|
+
{ value: "jp", label: "Japan" },
|
|
702
|
+
{ value: "in", label: "India" },
|
|
703
|
+
{ value: "ru", label: "Russia" },
|
|
704
|
+
{ value: "nl", label: "Netherlands" },
|
|
705
|
+
{ value: "se", label: "Sweden" },
|
|
706
|
+
{ value: "mx", label: "Mexico" },
|
|
707
|
+
{ value: "kr", label: "South Korea" },
|
|
708
|
+
{ value: "sg", label: "Singapore" },
|
|
709
|
+
{ value: "hk", label: "Hong Kong" },
|
|
710
|
+
{ value: "tw", label: "Taiwan" }
|
|
711
|
+
];
|
|
712
|
+
var REPORT_TYPE_LABELS = {
|
|
713
|
+
domain_overview: {
|
|
714
|
+
en: "Domain Overview (rank, traffic, keyword count)",
|
|
715
|
+
ja: "Domain Overview (\u30E9\u30F3\u30AF\u30FB\u30C8\u30E9\u30D5\u30A3\u30C3\u30AF\u30FB\u30AD\u30FC\u30EF\u30FC\u30C9\u6570)"
|
|
716
|
+
},
|
|
717
|
+
organic_search: {
|
|
718
|
+
en: "Organic Search (top organic keywords)",
|
|
719
|
+
ja: "Organic Search (\u4E0A\u4F4D\u30AA\u30FC\u30AC\u30CB\u30C3\u30AF\u30AD\u30FC\u30EF\u30FC\u30C9)"
|
|
720
|
+
},
|
|
721
|
+
paid_search: {
|
|
722
|
+
en: "Paid Search (top paid keywords)",
|
|
723
|
+
ja: "Paid Search (\u4E0A\u4F4D\u6709\u6599\u30AD\u30FC\u30EF\u30FC\u30C9)"
|
|
724
|
+
},
|
|
725
|
+
backlinks: {
|
|
726
|
+
en: "Backlinks (referring domains, backlink count)",
|
|
727
|
+
ja: "Backlinks (\u53C2\u7167\u30C9\u30E1\u30A4\u30F3\u30FB\u88AB\u30EA\u30F3\u30AF\u6570)"
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
var REPORT_TYPE_VALUES = [
|
|
731
|
+
"domain_overview",
|
|
732
|
+
"organic_search",
|
|
733
|
+
"paid_search",
|
|
734
|
+
"backlinks"
|
|
735
|
+
];
|
|
736
|
+
function projectId(p) {
|
|
737
|
+
const raw = p.project_id ?? p.id;
|
|
738
|
+
return raw == null ? "" : String(raw);
|
|
739
|
+
}
|
|
740
|
+
function projectName(p) {
|
|
741
|
+
return p.project_name ?? p.name ?? p.domain ?? p.url ?? projectId(p);
|
|
742
|
+
}
|
|
743
|
+
function projectDomain(p) {
|
|
744
|
+
return p.domain ?? p.domain_unicode ?? p.url ?? "";
|
|
745
|
+
}
|
|
746
|
+
function projectCreatedAt(p) {
|
|
747
|
+
return p.created_at ?? p.date_created ?? "";
|
|
748
|
+
}
|
|
749
|
+
async function fetchProjects(params) {
|
|
750
|
+
let res;
|
|
751
|
+
try {
|
|
752
|
+
res = await projectsApiFetch(params, "/projects");
|
|
753
|
+
} catch (err) {
|
|
754
|
+
return {
|
|
755
|
+
ok: false,
|
|
756
|
+
error: err instanceof Error ? err.message : String(err)
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
if (!res.ok) {
|
|
760
|
+
const body2 = await res.text().catch(() => res.statusText);
|
|
761
|
+
return {
|
|
762
|
+
ok: false,
|
|
763
|
+
error: `HTTP ${res.status} ${body2 || res.statusText}`
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
let body;
|
|
767
|
+
try {
|
|
768
|
+
body = await res.json();
|
|
769
|
+
} catch (err) {
|
|
770
|
+
return {
|
|
771
|
+
ok: false,
|
|
772
|
+
error: err instanceof Error ? err.message : String(err)
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
const projects = Array.isArray(body) ? body : Array.isArray(body?.projects) ? body.projects : Array.isArray(body?.data) ? body.data : [];
|
|
776
|
+
return { ok: true, projects };
|
|
777
|
+
}
|
|
778
|
+
function formatNumber(n) {
|
|
779
|
+
return n.toLocaleString("en-US");
|
|
780
|
+
}
|
|
781
|
+
async function fetchDomainOverview(params, domain, database) {
|
|
782
|
+
const sections = [];
|
|
783
|
+
try {
|
|
784
|
+
const report = await reportFetch(params, {
|
|
785
|
+
type: "domain_ranks",
|
|
786
|
+
domain,
|
|
787
|
+
database
|
|
788
|
+
});
|
|
789
|
+
if (report.rows.length === 0) {
|
|
790
|
+
sections.push("_No data found for this domain._", "");
|
|
791
|
+
return sections;
|
|
792
|
+
}
|
|
793
|
+
const row = report.rows[0];
|
|
794
|
+
sections.push("| Metric | Value |");
|
|
795
|
+
sections.push("|--------|-------|");
|
|
796
|
+
sections.push(
|
|
797
|
+
`| Rank | ${row["Rank"] ?? "-"} |`,
|
|
798
|
+
`| Organic Keywords | ${formatNumber(Number(row["Organic Keywords"]) || 0)} |`,
|
|
799
|
+
`| Organic Traffic | ${formatNumber(Number(row["Organic Traffic"]) || 0)} |`,
|
|
800
|
+
`| Organic Cost | $${formatNumber(Number(row["Organic Cost"]) || 0)} |`,
|
|
801
|
+
`| Adwords Keywords | ${formatNumber(Number(row["Adwords Keywords"]) || 0)} |`,
|
|
802
|
+
`| Adwords Traffic | ${formatNumber(Number(row["Adwords Traffic"]) || 0)} |`,
|
|
803
|
+
`| Adwords Cost | $${formatNumber(Number(row["Adwords Cost"]) || 0)} |`
|
|
804
|
+
);
|
|
805
|
+
sections.push("");
|
|
806
|
+
} catch (err) {
|
|
807
|
+
sections.push(
|
|
808
|
+
`_Error: ${err instanceof Error ? err.message : String(err)}_`,
|
|
809
|
+
""
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
return sections;
|
|
813
|
+
}
|
|
814
|
+
async function fetchOrganicSearch(params, domain, database) {
|
|
815
|
+
return fetchKeywordReport(params, "domain_organic", domain, database);
|
|
816
|
+
}
|
|
817
|
+
async function fetchPaidSearch(params, domain, database) {
|
|
818
|
+
return fetchKeywordReport(params, "domain_adwords", domain, database);
|
|
819
|
+
}
|
|
820
|
+
async function fetchKeywordReport(params, type, domain, database) {
|
|
821
|
+
const sections = [];
|
|
822
|
+
try {
|
|
823
|
+
const report = await reportFetch(params, {
|
|
824
|
+
type,
|
|
825
|
+
domain,
|
|
826
|
+
database,
|
|
827
|
+
display_limit: "5"
|
|
828
|
+
});
|
|
829
|
+
if (report.rows.length === 0) {
|
|
830
|
+
sections.push("_No data found._", "");
|
|
831
|
+
return sections;
|
|
832
|
+
}
|
|
833
|
+
sections.push(...renderCsvTable(report, 5));
|
|
834
|
+
sections.push("");
|
|
835
|
+
} catch (err) {
|
|
836
|
+
sections.push(
|
|
837
|
+
`_Error: ${err instanceof Error ? err.message : String(err)}_`,
|
|
838
|
+
""
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
return sections;
|
|
842
|
+
}
|
|
843
|
+
async function fetchBacklinks(params, domain) {
|
|
844
|
+
const sections = [];
|
|
845
|
+
try {
|
|
846
|
+
const report = await backlinksFetch(params, {
|
|
847
|
+
type: "backlinks_overview",
|
|
848
|
+
target: domain,
|
|
849
|
+
target_type: "root_domain"
|
|
850
|
+
});
|
|
851
|
+
if (report.rows.length === 0) {
|
|
852
|
+
sections.push("_No backlink data found._", "");
|
|
853
|
+
return sections;
|
|
854
|
+
}
|
|
855
|
+
const row = report.rows[0];
|
|
856
|
+
sections.push("| Metric | Value |");
|
|
857
|
+
sections.push("|--------|-------|");
|
|
858
|
+
for (const col of report.columns) {
|
|
859
|
+
sections.push(`| ${col} | ${formatNumber(Number(row[col]) || 0)} |`);
|
|
860
|
+
}
|
|
861
|
+
sections.push("");
|
|
862
|
+
} catch (err) {
|
|
863
|
+
sections.push(
|
|
864
|
+
`_Error: ${err instanceof Error ? err.message : String(err)}_`,
|
|
865
|
+
""
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
return sections;
|
|
869
|
+
}
|
|
870
|
+
function renderCsvTable(report, maxRows) {
|
|
871
|
+
const cols = report.columns;
|
|
872
|
+
const rows = report.rows.slice(0, maxRows);
|
|
873
|
+
const lines = [];
|
|
874
|
+
lines.push(`| ${cols.join(" | ")} |`);
|
|
875
|
+
lines.push(`|${cols.map(() => "---").join("|")}|`);
|
|
876
|
+
for (const row of rows) {
|
|
877
|
+
const cells = cols.map((c) => (row[c] ?? "").replace(/\|/g, "\\|"));
|
|
878
|
+
lines.push(`| ${cells.join(" | ")} |`);
|
|
879
|
+
}
|
|
880
|
+
return lines;
|
|
881
|
+
}
|
|
882
|
+
var semrushSetupFlow = {
|
|
883
|
+
initialState: () => ({}),
|
|
884
|
+
steps: [
|
|
885
|
+
{
|
|
886
|
+
slug: "domain",
|
|
887
|
+
type: "select",
|
|
888
|
+
allowFreeText: true,
|
|
889
|
+
question: {
|
|
890
|
+
ja: "\u5206\u6790\u5BFE\u8C61\u306E\u30C9\u30E1\u30A4\u30F3\u3092\u9078\u629E\u307E\u305F\u306F\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
891
|
+
en: "Select or enter the domain to analyze"
|
|
892
|
+
},
|
|
893
|
+
async fetchOptions(_state, rt) {
|
|
894
|
+
const result = await fetchProjects(rt.params);
|
|
895
|
+
if (!result.ok || result.projects.length === 0) return [];
|
|
896
|
+
const seen = /* @__PURE__ */ new Set();
|
|
897
|
+
const options = [];
|
|
898
|
+
for (const p of result.projects) {
|
|
899
|
+
const d = projectDomain(p);
|
|
900
|
+
if (d && !seen.has(d)) {
|
|
901
|
+
seen.add(d);
|
|
902
|
+
options.push({
|
|
903
|
+
value: d,
|
|
904
|
+
label: `${d} (${projectName(p)})`
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return options;
|
|
909
|
+
},
|
|
910
|
+
applyAnswer: (state, answer) => ({ ...state, domain: answer[0] })
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
slug: "database",
|
|
914
|
+
type: "select",
|
|
915
|
+
allowFreeText: false,
|
|
916
|
+
question: {
|
|
917
|
+
ja: "\u30EA\u30FC\u30B8\u30E7\u30F3\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u5BFE\u8C61\u30C9\u30E1\u30A4\u30F3\u306E\u4E3B\u8981\u5E02\u5834\uFF09",
|
|
918
|
+
en: "Select the region (primary market for the target domain)"
|
|
919
|
+
},
|
|
920
|
+
async fetchOptions() {
|
|
921
|
+
return SEMRUSH_DATABASES.map((db) => ({
|
|
922
|
+
value: db.value,
|
|
923
|
+
label: `${db.label} (${db.value})`
|
|
924
|
+
}));
|
|
925
|
+
},
|
|
926
|
+
applyAnswer: (state, answer) => ({ ...state, database: answer[0] })
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
slug: "reportTypes",
|
|
930
|
+
type: "multiSelect",
|
|
931
|
+
question: {
|
|
932
|
+
ja: "\u63A2\u7D22\u3059\u308B\u30EC\u30DD\u30FC\u30C8\u7A2E\u5225\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
|
|
933
|
+
en: "Select report types to explore (multi-select allowed)"
|
|
934
|
+
},
|
|
935
|
+
async fetchOptions(_state, rt) {
|
|
936
|
+
return REPORT_TYPE_VALUES.map((value) => ({
|
|
937
|
+
value,
|
|
938
|
+
label: REPORT_TYPE_LABELS[value][rt.language]
|
|
939
|
+
}));
|
|
940
|
+
},
|
|
941
|
+
applyAnswer: (state, answer) => ({ ...state, reportTypes: answer })
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
slug: "projects",
|
|
945
|
+
type: "multiSelect",
|
|
946
|
+
question: {
|
|
947
|
+
ja: "\u5BFE\u8C61\u306E Semrush \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
|
|
948
|
+
en: "Select target Semrush projects (multi-select allowed)"
|
|
949
|
+
},
|
|
950
|
+
async fetchOptions(_state, rt) {
|
|
951
|
+
const result = await fetchProjects(rt.params);
|
|
952
|
+
if (!result.ok || result.projects.length === 0) {
|
|
953
|
+
return [];
|
|
954
|
+
}
|
|
955
|
+
const options = result.projects.map((p) => {
|
|
956
|
+
const id = projectId(p);
|
|
957
|
+
if (!id) return null;
|
|
958
|
+
return { value: id, label: projectName(p) };
|
|
959
|
+
}).filter(
|
|
960
|
+
(opt) => opt !== null
|
|
961
|
+
);
|
|
962
|
+
if (options.length === 0) return [];
|
|
963
|
+
return [
|
|
964
|
+
{
|
|
965
|
+
value: ALL_PROJECTS,
|
|
966
|
+
label: rt.language === "ja" ? "\u3059\u3079\u3066\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8" : "All projects"
|
|
967
|
+
},
|
|
968
|
+
...options
|
|
969
|
+
];
|
|
970
|
+
},
|
|
971
|
+
applyAnswer: (state, answer) => ({ ...state, projects: answer })
|
|
972
|
+
}
|
|
973
|
+
],
|
|
974
|
+
async finalize(state, rt) {
|
|
975
|
+
if (!state.domain || !state.database || !state.reportTypes) {
|
|
976
|
+
throw new Error("Semrush setup: incomplete state on finalize");
|
|
977
|
+
}
|
|
978
|
+
const domain = state.domain;
|
|
979
|
+
const database = state.database;
|
|
980
|
+
const selected = state.reportTypes.filter(
|
|
981
|
+
(r) => REPORT_TYPE_VALUES.includes(r)
|
|
982
|
+
);
|
|
983
|
+
const sections = [
|
|
984
|
+
"## Semrush",
|
|
985
|
+
"",
|
|
986
|
+
`**Domain:** ${domain}`,
|
|
987
|
+
`**Region:** ${database}`,
|
|
988
|
+
""
|
|
989
|
+
];
|
|
990
|
+
for (const reportType of selected) {
|
|
991
|
+
sections.push(
|
|
992
|
+
`### ${REPORT_TYPE_LABELS[reportType].en}`,
|
|
993
|
+
""
|
|
994
|
+
);
|
|
995
|
+
switch (reportType) {
|
|
996
|
+
case "domain_overview":
|
|
997
|
+
sections.push(
|
|
998
|
+
...await fetchDomainOverview(rt.params, domain, database)
|
|
999
|
+
);
|
|
1000
|
+
break;
|
|
1001
|
+
case "organic_search":
|
|
1002
|
+
sections.push(
|
|
1003
|
+
...await fetchOrganicSearch(rt.params, domain, database)
|
|
1004
|
+
);
|
|
1005
|
+
break;
|
|
1006
|
+
case "paid_search":
|
|
1007
|
+
sections.push(
|
|
1008
|
+
...await fetchPaidSearch(rt.params, domain, database)
|
|
1009
|
+
);
|
|
1010
|
+
break;
|
|
1011
|
+
case "backlinks":
|
|
1012
|
+
sections.push(...await fetchBacklinks(rt.params, domain));
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
if (state.projects?.length) {
|
|
1017
|
+
const result = await fetchProjects(rt.params);
|
|
1018
|
+
if (result.ok) {
|
|
1019
|
+
const projectByIdMap = /* @__PURE__ */ new Map();
|
|
1020
|
+
for (const p of result.projects) {
|
|
1021
|
+
const id = projectId(p);
|
|
1022
|
+
if (id) projectByIdMap.set(id, p);
|
|
1023
|
+
}
|
|
1024
|
+
const targetIds = await resolveSetupSelection({
|
|
1025
|
+
selected: state.projects,
|
|
1026
|
+
allSentinel: ALL_PROJECTS,
|
|
1027
|
+
fetchAll: async () => result.projects.map((p) => projectId(p)).filter((id) => id),
|
|
1028
|
+
limit: SEMRUSH_SETUP_MAX_PROJECTS
|
|
1029
|
+
});
|
|
1030
|
+
if (targetIds.length > 0) {
|
|
1031
|
+
sections.push("### Projects", "");
|
|
1032
|
+
sections.push("| Project | Domain | Created |");
|
|
1033
|
+
sections.push("|---------|--------|---------|");
|
|
1034
|
+
for (const id of targetIds) {
|
|
1035
|
+
const p = projectByIdMap.get(id);
|
|
1036
|
+
if (!p) {
|
|
1037
|
+
sections.push(`| ${id} | - | - |`);
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
const name = projectName(p).replace(/\|/g, "\\|");
|
|
1041
|
+
const dom = projectDomain(p).replace(/\|/g, "\\|") || "-";
|
|
1042
|
+
const created = projectCreatedAt(p) || "-";
|
|
1043
|
+
sections.push(`| ${name} | ${dom} | ${created} |`);
|
|
1044
|
+
}
|
|
1045
|
+
sections.push("");
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return sections.join("\n");
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
|
|
514
1053
|
// ../connectors/src/connectors/semrush/index.ts
|
|
515
1054
|
var tools = { request: requestTool };
|
|
516
1055
|
var semrushConnector = new ConnectorPlugin({
|
|
@@ -732,6 +1271,7 @@ API \u30E6\u30CB\u30C3\u30C8\u6B8B\u91CF\u306E\u78BA\u8A8D\uFF08\u7121\u6599\u30
|
|
|
732
1271
|
- \u5C65\u6B74\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8\u306E\u65E5\u4ED8\u306F\u5FC5\u305A\u6708\u306E15\u65E5\uFF08\`YYYYMM15\`\uFF09`
|
|
733
1272
|
},
|
|
734
1273
|
tools,
|
|
1274
|
+
setup: (params, ctx, config) => runSetupFlow(semrushSetupFlow, params, ctx, config),
|
|
735
1275
|
async checkConnection(params) {
|
|
736
1276
|
try {
|
|
737
1277
|
const apiKey = params["api-key"];
|
|
@@ -790,6 +1330,7 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
790
1330
|
import { getContext } from "hono/context-storage";
|
|
791
1331
|
import { getCookie } from "hono/cookie";
|
|
792
1332
|
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
1333
|
+
var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
|
|
793
1334
|
function normalizeHeaders(input) {
|
|
794
1335
|
const out = {};
|
|
795
1336
|
if (!input) return out;
|
|
@@ -798,6 +1339,11 @@ function normalizeHeaders(input) {
|
|
|
798
1339
|
});
|
|
799
1340
|
return out;
|
|
800
1341
|
}
|
|
1342
|
+
function extractInputUrl(input) {
|
|
1343
|
+
if (typeof input === "string") return input;
|
|
1344
|
+
if (input instanceof URL) return input.href;
|
|
1345
|
+
return input.url;
|
|
1346
|
+
}
|
|
801
1347
|
function createSandboxProxyFetch(connectionId) {
|
|
802
1348
|
return async (input, init) => {
|
|
803
1349
|
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
@@ -807,10 +1353,17 @@ function createSandboxProxyFetch(connectionId) {
|
|
|
807
1353
|
"Connection proxy is not configured. Please check your deployment settings."
|
|
808
1354
|
);
|
|
809
1355
|
}
|
|
810
|
-
const originalUrl =
|
|
1356
|
+
const originalUrl = extractInputUrl(input);
|
|
1357
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
1358
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
1359
|
+
const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
1360
|
+
return fetch(sessionUrl, {
|
|
1361
|
+
method: "POST",
|
|
1362
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
811
1365
|
const originalMethod = init?.method ?? "GET";
|
|
812
1366
|
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
813
|
-
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
814
1367
|
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
815
1368
|
return fetch(proxyUrl, {
|
|
816
1369
|
method: "POST",
|
|
@@ -828,18 +1381,17 @@ function createSandboxProxyFetch(connectionId) {
|
|
|
828
1381
|
};
|
|
829
1382
|
}
|
|
830
1383
|
function createDeployedAppProxyFetch(connectionId) {
|
|
831
|
-
const
|
|
832
|
-
if (!
|
|
1384
|
+
const projectId2 = process.env["SQUADBASE_PROJECT_ID"];
|
|
1385
|
+
if (!projectId2) {
|
|
833
1386
|
throw new Error(
|
|
834
1387
|
"Connection proxy is not configured. Please check your deployment settings."
|
|
835
1388
|
);
|
|
836
1389
|
}
|
|
837
1390
|
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
838
|
-
const proxyUrl = `https://${
|
|
1391
|
+
const proxyUrl = `https://${projectId2}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
1392
|
+
const sessionUrl = `https://${projectId2}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
839
1393
|
return async (input, init) => {
|
|
840
|
-
const originalUrl =
|
|
841
|
-
const originalMethod = init?.method ?? "GET";
|
|
842
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
1394
|
+
const originalUrl = extractInputUrl(input);
|
|
843
1395
|
const c = getContext();
|
|
844
1396
|
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
845
1397
|
if (!appSession) {
|
|
@@ -847,6 +1399,14 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
847
1399
|
"No authentication method available for connection proxy."
|
|
848
1400
|
);
|
|
849
1401
|
}
|
|
1402
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
1403
|
+
return fetch(sessionUrl, {
|
|
1404
|
+
method: "POST",
|
|
1405
|
+
headers: { Authorization: `Bearer ${appSession}` }
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
const originalMethod = init?.method ?? "GET";
|
|
1409
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
850
1410
|
return fetch(proxyUrl, {
|
|
851
1411
|
method: "POST",
|
|
852
1412
|
headers: {
|