@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/wix-store/parameters.ts
|
|
57
|
+
init_parameter_definition();
|
|
46
58
|
var parameters = {
|
|
47
59
|
accountId: new ParameterDefinition({
|
|
48
60
|
slug: "account-id",
|
|
@@ -258,6 +270,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
258
270
|
tools;
|
|
259
271
|
query;
|
|
260
272
|
checkConnection;
|
|
273
|
+
/**
|
|
274
|
+
* SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
|
|
275
|
+
* implement this expose a step-by-step exploration flow (database/schema/
|
|
276
|
+
* table/etc. discovery) that the dashboard backend drives via the
|
|
277
|
+
* `/connections/:connectionId/setup` endpoint. Implement by delegating to
|
|
278
|
+
* `runSetupFlow` from `setup-flow.ts`.
|
|
279
|
+
*/
|
|
280
|
+
setup;
|
|
281
|
+
/**
|
|
282
|
+
* Opt-out of the default "verify before save" behavior on connection
|
|
283
|
+
* creation. The backend invokes `checkConnection` synchronously while
|
|
284
|
+
* creating the connection and aborts (no row inserted) if it fails — this
|
|
285
|
+
* flag disables that for connectors where the check cannot succeed pre-save:
|
|
286
|
+
*
|
|
287
|
+
* - `squadbase-db` populates `connection-url` only after Neon provisioning
|
|
288
|
+
* - OAuth connectors require an OAuth-aware proxyFetch keyed by the
|
|
289
|
+
* connectionId, which doesn't exist until the row is saved
|
|
290
|
+
*
|
|
291
|
+
* Exceptions are the explicit position; new credential-input connectors get
|
|
292
|
+
* the default verify-on-create behavior without opt-in.
|
|
293
|
+
*/
|
|
294
|
+
skipConnectionCheckOnCreate;
|
|
261
295
|
constructor(config) {
|
|
262
296
|
this.slug = config.slug;
|
|
263
297
|
this.authType = config.authType;
|
|
@@ -274,6 +308,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
274
308
|
this.tools = config.tools;
|
|
275
309
|
this.query = config.query;
|
|
276
310
|
this.checkConnection = config.checkConnection;
|
|
311
|
+
this.setup = config.setup;
|
|
312
|
+
this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
|
|
277
313
|
}
|
|
278
314
|
get connectorKey() {
|
|
279
315
|
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
@@ -338,6 +374,71 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
338
374
|
}
|
|
339
375
|
};
|
|
340
376
|
|
|
377
|
+
// ../connectors/src/setup-flow.ts
|
|
378
|
+
async function runSetupFlow(flow, params, ctx, config) {
|
|
379
|
+
const runtime = {
|
|
380
|
+
params,
|
|
381
|
+
language: ctx.language,
|
|
382
|
+
config
|
|
383
|
+
};
|
|
384
|
+
let state = flow.initialState();
|
|
385
|
+
let answerIdx = 0;
|
|
386
|
+
const pendingParameterUpdates = [];
|
|
387
|
+
for (const step of flow.steps) {
|
|
388
|
+
const ans = ctx.answers[answerIdx];
|
|
389
|
+
if (ans && ans.questionSlug === step.slug) {
|
|
390
|
+
state = step.applyAnswer(state, ans.answer);
|
|
391
|
+
if (step.toParameterUpdates) {
|
|
392
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
393
|
+
}
|
|
394
|
+
answerIdx += 1;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
398
|
+
if (step.type === "text") {
|
|
399
|
+
if (step.fetchOptions) {
|
|
400
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
401
|
+
if (options2.length === 0) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
type: "nextQuestion",
|
|
407
|
+
questionSlug: step.slug,
|
|
408
|
+
question: step.question[ctx.language],
|
|
409
|
+
questionType: "text",
|
|
410
|
+
allowFreeText: resolvedAllowFreeText,
|
|
411
|
+
...pendingParameterUpdates.length > 0 && {
|
|
412
|
+
parameterUpdates: pendingParameterUpdates
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
417
|
+
if (options.length === 0) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
type: "nextQuestion",
|
|
422
|
+
questionSlug: step.slug,
|
|
423
|
+
question: step.question[ctx.language],
|
|
424
|
+
questionType: step.type,
|
|
425
|
+
options,
|
|
426
|
+
allowFreeText: resolvedAllowFreeText,
|
|
427
|
+
...pendingParameterUpdates.length > 0 && {
|
|
428
|
+
parameterUpdates: pendingParameterUpdates
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
433
|
+
return {
|
|
434
|
+
type: "fulfilled",
|
|
435
|
+
dataInvestigationResult,
|
|
436
|
+
...pendingParameterUpdates.length > 0 && {
|
|
437
|
+
parameterUpdates: pendingParameterUpdates
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
341
442
|
// ../connectors/src/auth-types.ts
|
|
342
443
|
var AUTH_TYPES = {
|
|
343
444
|
OAUTH: "oauth",
|
|
@@ -360,9 +461,120 @@ var wixStoreOnboarding = new ConnectorOnboarding({
|
|
|
360
461
|
}
|
|
361
462
|
});
|
|
362
463
|
|
|
464
|
+
// ../connectors/src/connectors/wix-store/utils.ts
|
|
465
|
+
var BASE_URL = "https://www.wixapis.com";
|
|
466
|
+
async function apiFetch(params, path2, init) {
|
|
467
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
468
|
+
const siteId = params[parameters.siteId.slug];
|
|
469
|
+
if (!apiKey || !siteId) {
|
|
470
|
+
throw new Error(
|
|
471
|
+
"wix-store: missing required parameters: api-key and site-id"
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const url = `${BASE_URL}${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
475
|
+
const headers = new Headers(init?.headers);
|
|
476
|
+
headers.set("Authorization", apiKey);
|
|
477
|
+
headers.set("wix-site-id", siteId);
|
|
478
|
+
if (!headers.has("Content-Type")) {
|
|
479
|
+
headers.set("Content-Type", "application/json");
|
|
480
|
+
}
|
|
481
|
+
return fetch(url, { ...init, headers });
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// ../connectors/src/connectors/wix-store/setup-flow.ts
|
|
485
|
+
var WIX_STORE_SETUP_MAX_ENTITIES = 10;
|
|
486
|
+
var ENTITY_LABELS = {
|
|
487
|
+
products: { en: "Products", ja: "Products (\u5546\u54C1)" },
|
|
488
|
+
orders: { en: "Orders", ja: "Orders (\u6CE8\u6587)" },
|
|
489
|
+
collections: { en: "Collections", ja: "Collections (\u30B3\u30EC\u30AF\u30B7\u30E7\u30F3)" },
|
|
490
|
+
inventory: { en: "Inventory items", ja: "Inventory items (\u5728\u5EAB)" }
|
|
491
|
+
};
|
|
492
|
+
var ENTITY_VALUES = [
|
|
493
|
+
"products",
|
|
494
|
+
"orders",
|
|
495
|
+
"collections",
|
|
496
|
+
"inventory"
|
|
497
|
+
];
|
|
498
|
+
var QUERY_SPECS = {
|
|
499
|
+
products: {
|
|
500
|
+
path: "/stores/v1/products/query",
|
|
501
|
+
body: { query: { paging: { limit: 1, offset: 0 } } },
|
|
502
|
+
totalField: "totalResults"
|
|
503
|
+
},
|
|
504
|
+
orders: {
|
|
505
|
+
path: "/ecom/v1/orders/search",
|
|
506
|
+
body: { search: { cursorPaging: { limit: 1 } } },
|
|
507
|
+
totalField: "pagingMetadata.total"
|
|
508
|
+
},
|
|
509
|
+
collections: {
|
|
510
|
+
path: "/stores/v1/collections/query",
|
|
511
|
+
body: { query: { paging: { limit: 1 } } },
|
|
512
|
+
totalField: "totalResults"
|
|
513
|
+
},
|
|
514
|
+
inventory: {
|
|
515
|
+
path: "/stores/v2/inventoryItems/query",
|
|
516
|
+
body: { query: { paging: { limit: 1 } } },
|
|
517
|
+
totalField: "totalResults"
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
function lookupNumeric(data, path2) {
|
|
521
|
+
const parts = path2.split(".");
|
|
522
|
+
let cur = data;
|
|
523
|
+
for (const p of parts) {
|
|
524
|
+
if (!cur || typeof cur !== "object") return void 0;
|
|
525
|
+
cur = cur[p];
|
|
526
|
+
}
|
|
527
|
+
return typeof cur === "number" ? cur : void 0;
|
|
528
|
+
}
|
|
529
|
+
var wixStoreSetupFlow = {
|
|
530
|
+
initialState: () => ({}),
|
|
531
|
+
steps: [
|
|
532
|
+
{
|
|
533
|
+
slug: "entities",
|
|
534
|
+
type: "multiSelect",
|
|
535
|
+
question: {
|
|
536
|
+
ja: "\u5BFE\u8C61\u306E\u30A8\u30F3\u30C6\u30A3\u30C6\u30A3\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
|
|
537
|
+
en: "Select target entities (multi-select allowed)"
|
|
538
|
+
},
|
|
539
|
+
async fetchOptions(_state, rt) {
|
|
540
|
+
return ENTITY_VALUES.map((value) => ({
|
|
541
|
+
value,
|
|
542
|
+
label: ENTITY_LABELS[value][rt.language]
|
|
543
|
+
}));
|
|
544
|
+
},
|
|
545
|
+
applyAnswer: (state, answer) => ({ ...state, entities: answer })
|
|
546
|
+
}
|
|
547
|
+
],
|
|
548
|
+
async finalize(state, rt) {
|
|
549
|
+
if (!state.entities) {
|
|
550
|
+
throw new Error("Wix Store setup: incomplete state on finalize");
|
|
551
|
+
}
|
|
552
|
+
const selected = state.entities.filter((e) => ENTITY_VALUES.includes(e)).slice(0, WIX_STORE_SETUP_MAX_ENTITIES);
|
|
553
|
+
const sections = ["## Wix Store", ""];
|
|
554
|
+
for (const entity of selected) {
|
|
555
|
+
const spec = QUERY_SPECS[entity];
|
|
556
|
+
let count = "available";
|
|
557
|
+
const res = await apiFetch(rt.params, spec.path, {
|
|
558
|
+
method: "POST",
|
|
559
|
+
body: JSON.stringify(spec.body)
|
|
560
|
+
});
|
|
561
|
+
if (res.ok) {
|
|
562
|
+
const data = await res.json();
|
|
563
|
+
const total = lookupNumeric(data, spec.totalField);
|
|
564
|
+
if (typeof total === "number") count = String(total);
|
|
565
|
+
} else {
|
|
566
|
+
count = "unavailable";
|
|
567
|
+
}
|
|
568
|
+
sections.push(`### ${ENTITY_LABELS[entity].en}`, "");
|
|
569
|
+
sections.push(`Count: ${count}`, "");
|
|
570
|
+
}
|
|
571
|
+
return sections.join("\n");
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
363
575
|
// ../connectors/src/connectors/wix-store/tools/request.ts
|
|
364
576
|
import { z } from "zod";
|
|
365
|
-
var
|
|
577
|
+
var BASE_URL2 = "https://www.wixapis.com/";
|
|
366
578
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
367
579
|
var inputSchema = z.object({
|
|
368
580
|
toolUseIntent: z.string().optional().describe("Brief description of what you intend to accomplish with this tool call"),
|
|
@@ -397,7 +609,7 @@ Authentication is handled automatically using the API Key and Site ID.`,
|
|
|
397
609
|
try {
|
|
398
610
|
const apiKey = parameters.apiKey.getValue(connection2);
|
|
399
611
|
const siteId = parameters.siteId.getValue(connection2);
|
|
400
|
-
const url = `${
|
|
612
|
+
const url = `${BASE_URL2}${path2}`;
|
|
401
613
|
const controller = new AbortController();
|
|
402
614
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
403
615
|
try {
|
|
@@ -592,7 +804,46 @@ export default async function handler(c: Context) {
|
|
|
592
804
|
- \`POST stores/v2/inventoryItems/query\`
|
|
593
805
|
- Body: \`{ "query": { "paging": { "limit": 50 } } }\``
|
|
594
806
|
},
|
|
595
|
-
tools
|
|
807
|
+
tools,
|
|
808
|
+
setup: (params, ctx, config) => runSetupFlow(wixStoreSetupFlow, params, ctx, config),
|
|
809
|
+
async checkConnection(params, _config) {
|
|
810
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
811
|
+
const siteId = params[parameters.siteId.slug];
|
|
812
|
+
if (!apiKey || !siteId) {
|
|
813
|
+
return {
|
|
814
|
+
success: false,
|
|
815
|
+
error: "Missing required parameters: api-key and site-id"
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
try {
|
|
819
|
+
const res = await fetch(
|
|
820
|
+
"https://www.wixapis.com/stores/v1/products/query",
|
|
821
|
+
{
|
|
822
|
+
method: "POST",
|
|
823
|
+
headers: {
|
|
824
|
+
Authorization: apiKey,
|
|
825
|
+
"wix-site-id": siteId,
|
|
826
|
+
"Content-Type": "application/json",
|
|
827
|
+
Accept: "application/json"
|
|
828
|
+
},
|
|
829
|
+
body: JSON.stringify({ query: { paging: { limit: 1, offset: 0 } } })
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
if (!res.ok) {
|
|
833
|
+
const errorText = await res.text().catch(() => res.statusText);
|
|
834
|
+
return {
|
|
835
|
+
success: false,
|
|
836
|
+
error: `Wix Store API failed: HTTP ${res.status} ${errorText}`
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
return { success: true };
|
|
840
|
+
} catch (error) {
|
|
841
|
+
return {
|
|
842
|
+
success: false,
|
|
843
|
+
error: error instanceof Error ? error.message : String(error)
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
}
|
|
596
847
|
});
|
|
597
848
|
|
|
598
849
|
// src/connectors/create-connector-sdk.ts
|
|
@@ -621,6 +872,7 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
621
872
|
import { getContext } from "hono/context-storage";
|
|
622
873
|
import { getCookie } from "hono/cookie";
|
|
623
874
|
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
875
|
+
var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
|
|
624
876
|
function normalizeHeaders(input) {
|
|
625
877
|
const out = {};
|
|
626
878
|
if (!input) return out;
|
|
@@ -629,6 +881,11 @@ function normalizeHeaders(input) {
|
|
|
629
881
|
});
|
|
630
882
|
return out;
|
|
631
883
|
}
|
|
884
|
+
function extractInputUrl(input) {
|
|
885
|
+
if (typeof input === "string") return input;
|
|
886
|
+
if (input instanceof URL) return input.href;
|
|
887
|
+
return input.url;
|
|
888
|
+
}
|
|
632
889
|
function createSandboxProxyFetch(connectionId) {
|
|
633
890
|
return async (input, init) => {
|
|
634
891
|
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
@@ -638,10 +895,17 @@ function createSandboxProxyFetch(connectionId) {
|
|
|
638
895
|
"Connection proxy is not configured. Please check your deployment settings."
|
|
639
896
|
);
|
|
640
897
|
}
|
|
641
|
-
const originalUrl =
|
|
898
|
+
const originalUrl = extractInputUrl(input);
|
|
899
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
900
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
901
|
+
const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
902
|
+
return fetch(sessionUrl, {
|
|
903
|
+
method: "POST",
|
|
904
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
905
|
+
});
|
|
906
|
+
}
|
|
642
907
|
const originalMethod = init?.method ?? "GET";
|
|
643
908
|
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
644
|
-
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
645
909
|
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
646
910
|
return fetch(proxyUrl, {
|
|
647
911
|
method: "POST",
|
|
@@ -667,10 +931,9 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
667
931
|
}
|
|
668
932
|
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
669
933
|
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
934
|
+
const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
670
935
|
return async (input, init) => {
|
|
671
|
-
const originalUrl =
|
|
672
|
-
const originalMethod = init?.method ?? "GET";
|
|
673
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
936
|
+
const originalUrl = extractInputUrl(input);
|
|
674
937
|
const c = getContext();
|
|
675
938
|
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
676
939
|
if (!appSession) {
|
|
@@ -678,6 +941,14 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
678
941
|
"No authentication method available for connection proxy."
|
|
679
942
|
);
|
|
680
943
|
}
|
|
944
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
945
|
+
return fetch(sessionUrl, {
|
|
946
|
+
method: "POST",
|
|
947
|
+
headers: { Authorization: `Bearer ${appSession}` }
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
const originalMethod = init?.method ?? "GET";
|
|
951
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
681
952
|
return fetch(proxyUrl, {
|
|
682
953
|
method: "POST",
|
|
683
954
|
headers: {
|