@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.
- package/dist/cli/index.js +12374 -883
- package/dist/connectors/airtable-oauth.js +257 -46
- package/dist/connectors/airtable.js +294 -51
- package/dist/connectors/amplitude.js +297 -47
- package/dist/connectors/anthropic.js +135 -47
- package/dist/connectors/asana.js +302 -49
- package/dist/connectors/attio.js +277 -49
- package/dist/connectors/aws-billing.js +262 -46
- package/dist/connectors/azure-sql.js +396 -102
- package/dist/connectors/backlog-api-key.js +292 -47
- package/dist/connectors/clickup.js +313 -49
- package/dist/connectors/cosmosdb.js +280 -50
- package/dist/connectors/customerio.js +294 -47
- package/dist/connectors/dbt.js +315 -47
- package/dist/connectors/freshdesk.js +317 -53
- package/dist/connectors/freshsales.js +308 -52
- package/dist/connectors/freshservice.js +336 -53
- package/dist/connectors/gamma.js +302 -52
- package/dist/connectors/gemini.js +134 -47
- package/dist/connectors/github.js +361 -49
- package/dist/connectors/gmail-oauth.js +179 -7
- package/dist/connectors/gmail.js +325 -47
- package/dist/connectors/google-ads.js +263 -46
- package/dist/connectors/google-analytics-oauth.js +285 -46
- package/dist/connectors/google-analytics.js +387 -49
- package/dist/connectors/google-audit-log.js +413 -47
- package/dist/connectors/google-calendar-oauth.js +234 -46
- package/dist/connectors/google-calendar.js +334 -47
- package/dist/connectors/google-docs.js +195 -6
- package/dist/connectors/google-drive.js +237 -5
- package/dist/connectors/google-search-console-oauth.js +231 -46
- package/dist/connectors/google-sheets.js +247 -47
- package/dist/connectors/google-slides.js +180 -6
- package/dist/connectors/grafana.js +307 -49
- package/dist/connectors/hubspot-oauth.js +183 -5
- package/dist/connectors/hubspot.js +281 -49
- package/dist/connectors/influxdb.js +391 -51
- package/dist/connectors/intercom-oauth.js +185 -5
- package/dist/connectors/intercom.js +277 -49
- package/dist/connectors/jdbc.js +737 -110
- package/dist/connectors/jira-api-key.js +301 -47
- package/dist/connectors/kintone-api-token.js +256 -47
- package/dist/connectors/kintone.js +303 -47
- package/dist/connectors/linear.js +305 -49
- package/dist/connectors/linkedin-ads.js +243 -50
- package/dist/connectors/mailchimp-oauth.js +243 -46
- package/dist/connectors/mailchimp.js +295 -49
- package/dist/connectors/meta-ads-oauth.js +248 -48
- package/dist/connectors/meta-ads.js +260 -50
- package/dist/connectors/mixpanel.js +313 -47
- package/dist/connectors/monday.js +335 -49
- package/dist/connectors/mongodb.js +294 -57
- package/dist/connectors/notion-oauth.js +206 -5
- package/dist/connectors/notion.js +298 -51
- package/dist/connectors/openai.js +134 -47
- package/dist/connectors/oracle.js +414 -103
- package/dist/connectors/outlook-oauth.js +179 -5
- package/dist/connectors/powerbi-oauth.js +226 -5
- package/dist/connectors/salesforce.js +359 -49
- package/dist/connectors/semrush.js +289 -49
- package/dist/connectors/sentry.js +264 -50
- package/dist/connectors/shopify-oauth.js +162 -5
- package/dist/connectors/shopify.js +332 -47
- package/dist/connectors/sqlserver.js +390 -102
- package/dist/connectors/stripe-api-key.js +244 -46
- package/dist/connectors/stripe-oauth.js +177 -5
- package/dist/connectors/supabase.js +278 -48
- package/dist/connectors/tableau.js +389 -184
- package/dist/connectors/tiktok-ads.js +254 -48
- package/dist/connectors/wix-store.js +295 -49
- package/dist/connectors/zendesk-oauth.js +214 -5
- package/dist/connectors/zendesk.js +333 -47
- package/dist/index.d.ts +149 -1
- package/dist/index.js +13677 -1969
- package/dist/main.js +13627 -1927
- package/dist/vite-plugin.js +12391 -890
- 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/zendesk/parameters.ts
|
|
57
|
+
init_parameter_definition();
|
|
46
58
|
var parameters = {
|
|
47
59
|
subdomain: new ParameterDefinition({
|
|
48
60
|
slug: "subdomain",
|
|
@@ -240,6 +252,28 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
240
252
|
tools;
|
|
241
253
|
query;
|
|
242
254
|
checkConnection;
|
|
255
|
+
/**
|
|
256
|
+
* SQPD-1212: Logic-based, rule-driven connection setup. Connectors that
|
|
257
|
+
* implement this expose a step-by-step exploration flow (database/schema/
|
|
258
|
+
* table/etc. discovery) that the dashboard backend drives via the
|
|
259
|
+
* `/connections/:connectionId/setup` endpoint. Implement by delegating to
|
|
260
|
+
* `runSetupFlow` from `setup-flow.ts`.
|
|
261
|
+
*/
|
|
262
|
+
setup;
|
|
263
|
+
/**
|
|
264
|
+
* Opt-out of the default "verify before save" behavior on connection
|
|
265
|
+
* creation. The backend invokes `checkConnection` synchronously while
|
|
266
|
+
* creating the connection and aborts (no row inserted) if it fails — this
|
|
267
|
+
* flag disables that for connectors where the check cannot succeed pre-save:
|
|
268
|
+
*
|
|
269
|
+
* - `squadbase-db` populates `connection-url` only after Neon provisioning
|
|
270
|
+
* - OAuth connectors require an OAuth-aware proxyFetch keyed by the
|
|
271
|
+
* connectionId, which doesn't exist until the row is saved
|
|
272
|
+
*
|
|
273
|
+
* Exceptions are the explicit position; new credential-input connectors get
|
|
274
|
+
* the default verify-on-create behavior without opt-in.
|
|
275
|
+
*/
|
|
276
|
+
skipConnectionCheckOnCreate;
|
|
243
277
|
constructor(config) {
|
|
244
278
|
this.slug = config.slug;
|
|
245
279
|
this.authType = config.authType;
|
|
@@ -256,6 +290,8 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
256
290
|
this.tools = config.tools;
|
|
257
291
|
this.query = config.query;
|
|
258
292
|
this.checkConnection = config.checkConnection;
|
|
293
|
+
this.setup = config.setup;
|
|
294
|
+
this.skipConnectionCheckOnCreate = config.skipConnectionCheckOnCreate;
|
|
259
295
|
}
|
|
260
296
|
get connectorKey() {
|
|
261
297
|
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
@@ -320,6 +356,51 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
320
356
|
}
|
|
321
357
|
};
|
|
322
358
|
|
|
359
|
+
// ../connectors/src/setup-flow.ts
|
|
360
|
+
async function runSetupFlow(flow, params, ctx, config) {
|
|
361
|
+
const runtime = {
|
|
362
|
+
params,
|
|
363
|
+
language: ctx.language,
|
|
364
|
+
config
|
|
365
|
+
};
|
|
366
|
+
let state = flow.initialState();
|
|
367
|
+
let answerIdx = 0;
|
|
368
|
+
for (const step of flow.steps) {
|
|
369
|
+
const ans = ctx.answers[answerIdx];
|
|
370
|
+
if (ans && ans.questionSlug === step.slug) {
|
|
371
|
+
state = step.applyAnswer(state, ans.answer);
|
|
372
|
+
answerIdx += 1;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (step.type === "text") {
|
|
376
|
+
return {
|
|
377
|
+
type: "nextQuestion",
|
|
378
|
+
questionSlug: step.slug,
|
|
379
|
+
question: step.question[ctx.language],
|
|
380
|
+
questionType: "text"
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
384
|
+
if (options.length === 0) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
type: "nextQuestion",
|
|
389
|
+
questionSlug: step.slug,
|
|
390
|
+
question: step.question[ctx.language],
|
|
391
|
+
questionType: step.type,
|
|
392
|
+
options
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
396
|
+
return { type: "fulfilled", dataInvestigationResult };
|
|
397
|
+
}
|
|
398
|
+
async function resolveSetupSelection(params) {
|
|
399
|
+
const { selected, allSentinel, fetchAll, limit } = params;
|
|
400
|
+
const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
|
|
401
|
+
return resolved.slice(0, limit);
|
|
402
|
+
}
|
|
403
|
+
|
|
323
404
|
// ../connectors/src/auth-types.ts
|
|
324
405
|
var AUTH_TYPES = {
|
|
325
406
|
OAUTH: "oauth",
|
|
@@ -344,6 +425,150 @@ var zendeskOnboarding = new ConnectorOnboarding({
|
|
|
344
425
|
}
|
|
345
426
|
});
|
|
346
427
|
|
|
428
|
+
// ../connectors/src/connectors/zendesk/utils.ts
|
|
429
|
+
function normalizeSubdomain(raw) {
|
|
430
|
+
return raw.trim().replace(/^https?:\/\//i, "").replace(/\.zendesk\.com.*$/, "").replace(/\/+$/, "").split(".")[0];
|
|
431
|
+
}
|
|
432
|
+
function basicAuthHeader(email, apiToken) {
|
|
433
|
+
return `Basic ${Buffer.from(`${email}/token:${apiToken}`).toString("base64")}`;
|
|
434
|
+
}
|
|
435
|
+
async function apiFetch(params, path2, init) {
|
|
436
|
+
const subdomain = params[parameters.subdomain.slug];
|
|
437
|
+
const email = params[parameters.email.slug];
|
|
438
|
+
const apiToken = params[parameters.apiToken.slug];
|
|
439
|
+
if (!subdomain || !email || !apiToken) {
|
|
440
|
+
throw new Error(
|
|
441
|
+
"zendesk: missing required parameter(s) (subdomain, email, api-token)"
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const url = `https://${normalizeSubdomain(subdomain)}.zendesk.com${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
445
|
+
const headers = new Headers(init?.headers);
|
|
446
|
+
headers.set("Authorization", basicAuthHeader(email, apiToken));
|
|
447
|
+
headers.set("Accept", "application/json");
|
|
448
|
+
return fetch(url, { ...init, headers });
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// ../connectors/src/connectors/zendesk/setup-flow.ts
|
|
452
|
+
var ZENDESK_SETUP_MAX_ENTITIES = 5;
|
|
453
|
+
var ZENDESK_ENTITIES = [
|
|
454
|
+
{
|
|
455
|
+
value: "tickets",
|
|
456
|
+
label: "Tickets",
|
|
457
|
+
countPath: "/api/v2/tickets.json?page[size]=1",
|
|
458
|
+
countField: "count"
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
value: "users",
|
|
462
|
+
label: "Users",
|
|
463
|
+
countPath: "/api/v2/users.json?page[size]=1",
|
|
464
|
+
countField: "count"
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
value: "organizations",
|
|
468
|
+
label: "Organizations",
|
|
469
|
+
countPath: "/api/v2/organizations.json?page[size]=1",
|
|
470
|
+
countField: "count"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
value: "groups",
|
|
474
|
+
label: "Groups",
|
|
475
|
+
countPath: "/api/v2/groups.json?page[size]=1",
|
|
476
|
+
countField: "count"
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
value: "articles",
|
|
480
|
+
label: "Help Center articles",
|
|
481
|
+
countPath: "/api/v2/help_center/articles.json?page[size]=1",
|
|
482
|
+
countField: "count"
|
|
483
|
+
}
|
|
484
|
+
];
|
|
485
|
+
async function listBrands(params) {
|
|
486
|
+
const res = await apiFetch(params, "/api/v2/brands.json");
|
|
487
|
+
if (!res.ok) return [];
|
|
488
|
+
const data = await res.json();
|
|
489
|
+
return data.brands ?? [];
|
|
490
|
+
}
|
|
491
|
+
async function fetchCount(params, path2, countField) {
|
|
492
|
+
const res = await apiFetch(params, path2);
|
|
493
|
+
if (!res.ok) return null;
|
|
494
|
+
const data = await res.json();
|
|
495
|
+
const raw = data[countField];
|
|
496
|
+
if (typeof raw === "number") return raw;
|
|
497
|
+
if (typeof data["count"] === "number") return data["count"];
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
var zendeskSetupFlow = {
|
|
501
|
+
initialState: () => ({}),
|
|
502
|
+
steps: [
|
|
503
|
+
{
|
|
504
|
+
slug: "brand",
|
|
505
|
+
type: "select",
|
|
506
|
+
question: {
|
|
507
|
+
ja: "\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3067\u5BFE\u8C61\u3068\u3059\u308BZendesk\u30D6\u30E9\u30F3\u30C9\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044",
|
|
508
|
+
en: "Select the Zendesk brand to use for setup"
|
|
509
|
+
},
|
|
510
|
+
async fetchOptions(_state, rt) {
|
|
511
|
+
const brands = await listBrands(rt.params);
|
|
512
|
+
const active = brands.filter((b) => b.active !== false && b.name);
|
|
513
|
+
if (active.length < 2) return [];
|
|
514
|
+
return active.map((b) => ({
|
|
515
|
+
value: String(b.subdomain ?? b.id ?? b.name),
|
|
516
|
+
label: String(b.name)
|
|
517
|
+
}));
|
|
518
|
+
},
|
|
519
|
+
applyAnswer: (state, answer) => ({ ...state, brand: answer[0] })
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
slug: "entities",
|
|
523
|
+
type: "multiSelect",
|
|
524
|
+
question: {
|
|
525
|
+
ja: "\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3067\u6982\u89B3\u3057\u305F\u3044\u30A8\u30F3\u30C6\u30A3\u30C6\u30A3\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u8907\u6570\u9078\u629E\u53EF\uFF09",
|
|
526
|
+
en: "Select the entities to include in setup (multi-select allowed)"
|
|
527
|
+
},
|
|
528
|
+
async fetchOptions(_state, _rt) {
|
|
529
|
+
return ZENDESK_ENTITIES.map((e) => ({ value: e.value, label: e.label }));
|
|
530
|
+
},
|
|
531
|
+
applyAnswer: (state, answer) => ({ ...state, entities: answer })
|
|
532
|
+
}
|
|
533
|
+
],
|
|
534
|
+
async finalize(state, rt) {
|
|
535
|
+
if (!state.entities) {
|
|
536
|
+
throw new Error("Zendesk setup: incomplete state on finalize");
|
|
537
|
+
}
|
|
538
|
+
const targetEntities = await resolveSetupSelection({
|
|
539
|
+
selected: state.entities,
|
|
540
|
+
allSentinel: "__ALL__",
|
|
541
|
+
fetchAll: async () => ZENDESK_ENTITIES.map((e) => e.value),
|
|
542
|
+
limit: ZENDESK_SETUP_MAX_ENTITIES
|
|
543
|
+
});
|
|
544
|
+
const entityByValue = new Map(ZENDESK_ENTITIES.map((e) => [e.value, e]));
|
|
545
|
+
const sections = ["## Zendesk", ""];
|
|
546
|
+
if (state.brand) {
|
|
547
|
+
sections.push(`### Brand: ${state.brand}`, "");
|
|
548
|
+
}
|
|
549
|
+
sections.push("### Selected entities", "");
|
|
550
|
+
sections.push("| Entity | Count |");
|
|
551
|
+
sections.push("|--------|-------|");
|
|
552
|
+
for (const value of targetEntities) {
|
|
553
|
+
const entity = entityByValue.get(value);
|
|
554
|
+
if (!entity) {
|
|
555
|
+
sections.push(`| ${value} | _unknown_ |`);
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const count = await fetchCount(
|
|
559
|
+
rt.params,
|
|
560
|
+
entity.countPath,
|
|
561
|
+
entity.countField
|
|
562
|
+
);
|
|
563
|
+
sections.push(
|
|
564
|
+
`| ${entity.label} (${entity.value}) | ${count == null ? "-" : count} |`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
sections.push("");
|
|
568
|
+
return sections.join("\n");
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
347
572
|
// ../connectors/src/connectors/zendesk/tools/request.ts
|
|
348
573
|
import { z } from "zod";
|
|
349
574
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
@@ -612,7 +837,48 @@ export default async function handler(c: Context) {
|
|
|
612
837
|
- \`type:user role:agent\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30E6\u30FC\u30B6\u30FC
|
|
613
838
|
- \`type:organization {name}\` \u2014 \u540D\u524D\u304C\u4E00\u81F4\u3059\u308B\u7D44\u7E54`
|
|
614
839
|
},
|
|
615
|
-
tools
|
|
840
|
+
tools,
|
|
841
|
+
setup: (params, ctx, config) => runSetupFlow(zendeskSetupFlow, params, ctx, config),
|
|
842
|
+
async checkConnection(params, _config) {
|
|
843
|
+
const subdomain = params[parameters.subdomain.slug];
|
|
844
|
+
const email = params[parameters.email.slug];
|
|
845
|
+
const apiToken = params[parameters.apiToken.slug];
|
|
846
|
+
if (!subdomain || !email || !apiToken) {
|
|
847
|
+
return {
|
|
848
|
+
success: false,
|
|
849
|
+
error: `Missing required parameter(s): ${parameters.subdomain.slug}, ${parameters.email.slug}, ${parameters.apiToken.slug}`
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
try {
|
|
853
|
+
const credentials = Buffer.from(
|
|
854
|
+
`${email}/token:${apiToken}`,
|
|
855
|
+
"utf-8"
|
|
856
|
+
).toString("base64");
|
|
857
|
+
const res = await fetch(
|
|
858
|
+
`https://${subdomain}.zendesk.com/api/v2/users/me.json`,
|
|
859
|
+
{
|
|
860
|
+
method: "GET",
|
|
861
|
+
headers: {
|
|
862
|
+
Authorization: `Basic ${credentials}`,
|
|
863
|
+
Accept: "application/json"
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
);
|
|
867
|
+
if (!res.ok) {
|
|
868
|
+
const errText = await res.text().catch(() => res.statusText);
|
|
869
|
+
return {
|
|
870
|
+
success: false,
|
|
871
|
+
error: `Zendesk API failed: HTTP ${res.status} ${errText}`
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
return { success: true };
|
|
875
|
+
} catch (error) {
|
|
876
|
+
return {
|
|
877
|
+
success: false,
|
|
878
|
+
error: error instanceof Error ? error.message : String(error)
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
}
|
|
616
882
|
});
|
|
617
883
|
|
|
618
884
|
// src/connectors/create-connector-sdk.ts
|
|
@@ -641,6 +907,7 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
641
907
|
import { getContext } from "hono/context-storage";
|
|
642
908
|
import { getCookie } from "hono/cookie";
|
|
643
909
|
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
910
|
+
var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
|
|
644
911
|
function normalizeHeaders(input) {
|
|
645
912
|
const out = {};
|
|
646
913
|
if (!input) return out;
|
|
@@ -649,6 +916,11 @@ function normalizeHeaders(input) {
|
|
|
649
916
|
});
|
|
650
917
|
return out;
|
|
651
918
|
}
|
|
919
|
+
function extractInputUrl(input) {
|
|
920
|
+
if (typeof input === "string") return input;
|
|
921
|
+
if (input instanceof URL) return input.href;
|
|
922
|
+
return input.url;
|
|
923
|
+
}
|
|
652
924
|
function createSandboxProxyFetch(connectionId) {
|
|
653
925
|
return async (input, init) => {
|
|
654
926
|
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
@@ -658,10 +930,17 @@ function createSandboxProxyFetch(connectionId) {
|
|
|
658
930
|
"Connection proxy is not configured. Please check your deployment settings."
|
|
659
931
|
);
|
|
660
932
|
}
|
|
661
|
-
const originalUrl =
|
|
933
|
+
const originalUrl = extractInputUrl(input);
|
|
934
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
935
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
936
|
+
const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
937
|
+
return fetch(sessionUrl, {
|
|
938
|
+
method: "POST",
|
|
939
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
940
|
+
});
|
|
941
|
+
}
|
|
662
942
|
const originalMethod = init?.method ?? "GET";
|
|
663
943
|
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
664
|
-
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
665
944
|
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
666
945
|
return fetch(proxyUrl, {
|
|
667
946
|
method: "POST",
|
|
@@ -687,10 +966,9 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
687
966
|
}
|
|
688
967
|
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
689
968
|
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
969
|
+
const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
|
|
690
970
|
return async (input, init) => {
|
|
691
|
-
const originalUrl =
|
|
692
|
-
const originalMethod = init?.method ?? "GET";
|
|
693
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
971
|
+
const originalUrl = extractInputUrl(input);
|
|
694
972
|
const c = getContext();
|
|
695
973
|
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
696
974
|
if (!appSession) {
|
|
@@ -698,6 +976,14 @@ function createDeployedAppProxyFetch(connectionId) {
|
|
|
698
976
|
"No authentication method available for connection proxy."
|
|
699
977
|
);
|
|
700
978
|
}
|
|
979
|
+
if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
|
|
980
|
+
return fetch(sessionUrl, {
|
|
981
|
+
method: "POST",
|
|
982
|
+
headers: { Authorization: `Bearer ${appSession}` }
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
const originalMethod = init?.method ?? "GET";
|
|
986
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
701
987
|
return fetch(proxyUrl, {
|
|
702
988
|
method: "POST",
|
|
703
989
|
headers: {
|
package/dist/index.d.ts
CHANGED
|
@@ -132,6 +132,154 @@ declare function connection(connectionId: string): {
|
|
|
132
132
|
fetch(url: string, options?: ConnectionFetchOptions): Promise<Response>;
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Project Storage (SQPD-1213) — HTTP transport for `@squadbase/vite-server`。
|
|
137
|
+
*
|
|
138
|
+
* 設計は `connector-client/proxy-fetch.ts` (IP allowlist 越えのコネクション proxy) と同じ
|
|
139
|
+
* 2 経路パターン。両経路とも user-function-proxy の `/_sqcore/storage/*` を叩く。
|
|
140
|
+
*
|
|
141
|
+
* - **Sandbox 内 vite-server (preview-app server-side / ユーザーアプリ server-side)**:
|
|
142
|
+
* URL = `https://${INTERNAL_SQUADBASE_SANDBOX_ID}.${SQUADBASE_PREVIEW_BASE_DOMAIN}/_sqcore/storage/*`
|
|
143
|
+
* 認証 = `Authorization: Bearer ${INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL}`
|
|
144
|
+
* default base domain: `preview.app.squadbase.dev`
|
|
145
|
+
*
|
|
146
|
+
* - **デプロイ済みアプリ**:
|
|
147
|
+
* URL = `https://${SQUADBASE_PROJECT_ID}.${SQUADBASE_APP_BASE_DOMAIN}/_sqcore/storage/*`
|
|
148
|
+
* 認証 = `__Host-squadbase-session` cookie を `Authorization: Bearer` に転送
|
|
149
|
+
* default base domain: `squadbase.app`
|
|
150
|
+
*
|
|
151
|
+
* 経路判定は `INTERNAL_SQUADBASE_SANDBOX_ID` の有無で行う。
|
|
152
|
+
* Coding-Agent から呼ぶ app-api 直経路は本 SDK では持たず、coding-agent 側で別実装する。
|
|
153
|
+
*/
|
|
154
|
+
type PresignedPutResult = {
|
|
155
|
+
url: string;
|
|
156
|
+
headers: Record<string, string>;
|
|
157
|
+
expiresAt: string;
|
|
158
|
+
};
|
|
159
|
+
type PresignedGetResult = {
|
|
160
|
+
url: string;
|
|
161
|
+
expiresAt: string;
|
|
162
|
+
};
|
|
163
|
+
type StorageMetadata = {
|
|
164
|
+
key: string;
|
|
165
|
+
size: number;
|
|
166
|
+
contentType: string;
|
|
167
|
+
createdAt: string;
|
|
168
|
+
createdBy: string;
|
|
169
|
+
source: "upload" | "agent" | "system";
|
|
170
|
+
};
|
|
171
|
+
type StorageListItem = {
|
|
172
|
+
key: string;
|
|
173
|
+
size: number;
|
|
174
|
+
lastModified: string;
|
|
175
|
+
};
|
|
176
|
+
type StorageListResult = {
|
|
177
|
+
objects: StorageListItem[];
|
|
178
|
+
nextCursor?: string;
|
|
179
|
+
};
|
|
180
|
+
type StorageUsageDelta = {
|
|
181
|
+
totalSizeBytes: number;
|
|
182
|
+
objectCount: number;
|
|
183
|
+
};
|
|
184
|
+
interface StorageTransport {
|
|
185
|
+
signPut(relativeKey: string, contentType: string, contentLength: number): Promise<PresignedPutResult>;
|
|
186
|
+
signGet(relativeKey: string): Promise<PresignedGetResult>;
|
|
187
|
+
notifyUploaded(relativeKey: string, size: number): Promise<StorageUsageDelta>;
|
|
188
|
+
list(prefix?: string, options?: {
|
|
189
|
+
limit?: number;
|
|
190
|
+
cursor?: string;
|
|
191
|
+
}): Promise<StorageListResult>;
|
|
192
|
+
head(relativeKey: string): Promise<StorageMetadata>;
|
|
193
|
+
delete(relativeKey: string): Promise<StorageUsageDelta>;
|
|
194
|
+
copy(srcRelativeKey: string, destRelativeKey: string, options?: {
|
|
195
|
+
overwrite?: boolean;
|
|
196
|
+
}): Promise<StorageUsageDelta>;
|
|
197
|
+
move(srcRelativeKey: string, destRelativeKey: string, options?: {
|
|
198
|
+
overwrite?: boolean;
|
|
199
|
+
}): Promise<StorageUsageDelta>;
|
|
200
|
+
}
|
|
201
|
+
declare class PresignedHttpsTransport implements StorageTransport {
|
|
202
|
+
signPut(key: string, contentType: string, contentLength: number): Promise<PresignedPutResult>;
|
|
203
|
+
signGet(key: string): Promise<PresignedGetResult>;
|
|
204
|
+
notifyUploaded(key: string, size: number): Promise<StorageUsageDelta>;
|
|
205
|
+
list(prefix?: string, options?: {
|
|
206
|
+
limit?: number;
|
|
207
|
+
cursor?: string;
|
|
208
|
+
}): Promise<StorageListResult>;
|
|
209
|
+
head(key: string): Promise<StorageMetadata>;
|
|
210
|
+
delete(key: string): Promise<StorageUsageDelta>;
|
|
211
|
+
copy(srcKey: string, destKey: string, options?: {
|
|
212
|
+
overwrite?: boolean;
|
|
213
|
+
}): Promise<StorageUsageDelta>;
|
|
214
|
+
move(srcKey: string, destKey: string, options?: {
|
|
215
|
+
overwrite?: boolean;
|
|
216
|
+
}): Promise<StorageUsageDelta>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Project Storage (SQPD-1213) — `storage.uploads.*` の SDK 実装。
|
|
221
|
+
*
|
|
222
|
+
* 二段ネスト命名 (`storage.uploads.*`) で `agent` / `system` 名前空間の将来追加に備える。
|
|
223
|
+
* slice1+2 (put/get/head/list/delete/uploaded callback) を提供し、copy/move は slice3 で追加。
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
type PutOptions = {
|
|
227
|
+
contentType?: string;
|
|
228
|
+
};
|
|
229
|
+
type ListOptions = {
|
|
230
|
+
limit?: number;
|
|
231
|
+
cursor?: string;
|
|
232
|
+
};
|
|
233
|
+
type GetResult = {
|
|
234
|
+
/** S3 から取得した body。Hono / Node fetch の Response.body 互換 (ReadableStream<Uint8Array> | null)。 */
|
|
235
|
+
body: ReadableStream<Uint8Array> | null;
|
|
236
|
+
/** head 相当のメタデータ */
|
|
237
|
+
metadata: StorageMetadata;
|
|
238
|
+
};
|
|
239
|
+
declare class StorageUploadsClient {
|
|
240
|
+
private readonly transport;
|
|
241
|
+
constructor(transport: StorageTransport);
|
|
242
|
+
put(key: string, data: Buffer | Uint8Array | ArrayBuffer | Blob, options?: PutOptions): Promise<StorageUsageDelta>;
|
|
243
|
+
get(key: string): Promise<GetResult>;
|
|
244
|
+
head(key: string): Promise<StorageMetadata>;
|
|
245
|
+
list(prefix?: string, options?: ListOptions): Promise<StorageListResult>;
|
|
246
|
+
delete(key: string): Promise<StorageUsageDelta>;
|
|
247
|
+
copy(srcKey: string, destKey: string, options?: {
|
|
248
|
+
overwrite?: boolean;
|
|
249
|
+
}): Promise<StorageUsageDelta>;
|
|
250
|
+
/**
|
|
251
|
+
* rename も本メソッドで表現する (内部的には copy + src 削除を backend で実施)。
|
|
252
|
+
*/
|
|
253
|
+
move(srcKey: string, destKey: string, options?: {
|
|
254
|
+
overwrite?: boolean;
|
|
255
|
+
}): Promise<StorageUsageDelta>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Project Storage (SQPD-1213) — public SDK entry。
|
|
260
|
+
*
|
|
261
|
+
* ユーザーアプリ (vite-server で動くサーバーロジック) から以下のように利用する:
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* import { storage } from "@squadbase/vite-server";
|
|
265
|
+
*
|
|
266
|
+
* await storage.uploads.put("reports/2026-05.csv", buffer, { contentType: "text/csv" });
|
|
267
|
+
* const { body, metadata } = await storage.uploads.get("reports/2026-05.csv");
|
|
268
|
+
* const { objects, nextCursor } = await storage.uploads.list("reports/");
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* `agent` / `system` 名前空間は将来追加 (現在は uploads のみ)。
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Project Storage の SDK 入口。
|
|
276
|
+
*
|
|
277
|
+
* 現状は `uploads` のみ。将来 `agent` / `system` を追加するときも公開 API を破壊しない。
|
|
278
|
+
*/
|
|
279
|
+
declare const storage: {
|
|
280
|
+
uploads: StorageUploadsClient;
|
|
281
|
+
};
|
|
282
|
+
|
|
135
283
|
declare const app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
136
284
|
|
|
137
|
-
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionFetchOptions, type ConnectionsMap, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type QueryFn, type WixStoreClient, connection, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getQuery, loadConnections };
|
|
285
|
+
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionFetchOptions, type ConnectionsMap, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type PresignedGetResult, PresignedHttpsTransport, type PresignedPutResult, type QueryFn, type GetResult as StorageGetResult, type StorageListItem, type ListOptions as StorageListOptions, type StorageListResult, type StorageMetadata, type PutOptions as StoragePutOptions, type StorageTransport, StorageUploadsClient, type StorageUsageDelta, type WixStoreClient, connection, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getQuery, loadConnections, storage };
|