@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.
Files changed (77) hide show
  1. package/dist/cli/index.js +14375 -1652
  2. package/dist/connectors/airtable-oauth.js +282 -46
  3. package/dist/connectors/airtable.js +319 -51
  4. package/dist/connectors/amplitude.js +322 -47
  5. package/dist/connectors/anthropic.js +135 -47
  6. package/dist/connectors/asana.js +327 -49
  7. package/dist/connectors/attio.js +302 -49
  8. package/dist/connectors/aws-billing.js +287 -46
  9. package/dist/connectors/azure-sql.js +421 -102
  10. package/dist/connectors/backlog-api-key.js +317 -47
  11. package/dist/connectors/clickup.js +338 -49
  12. package/dist/connectors/cosmosdb.js +305 -50
  13. package/dist/connectors/customerio.js +319 -47
  14. package/dist/connectors/dbt.js +340 -47
  15. package/dist/connectors/freshdesk.js +342 -53
  16. package/dist/connectors/freshsales.js +333 -52
  17. package/dist/connectors/freshservice.js +361 -53
  18. package/dist/connectors/gamma.js +327 -52
  19. package/dist/connectors/gemini.js +134 -47
  20. package/dist/connectors/github.js +386 -49
  21. package/dist/connectors/gmail-oauth.js +204 -7
  22. package/dist/connectors/gmail.js +350 -47
  23. package/dist/connectors/google-ads.js +288 -46
  24. package/dist/connectors/google-analytics-oauth.js +310 -46
  25. package/dist/connectors/google-analytics.js +547 -87
  26. package/dist/connectors/google-audit-log.js +438 -47
  27. package/dist/connectors/google-calendar-oauth.js +259 -46
  28. package/dist/connectors/google-calendar.js +359 -47
  29. package/dist/connectors/google-docs.js +220 -6
  30. package/dist/connectors/google-drive.js +262 -5
  31. package/dist/connectors/google-search-console-oauth.js +256 -46
  32. package/dist/connectors/google-sheets.js +272 -47
  33. package/dist/connectors/google-slides.js +205 -6
  34. package/dist/connectors/grafana.js +332 -49
  35. package/dist/connectors/hubspot-oauth.js +208 -5
  36. package/dist/connectors/hubspot.js +306 -49
  37. package/dist/connectors/influxdb.js +416 -51
  38. package/dist/connectors/intercom-oauth.js +210 -5
  39. package/dist/connectors/intercom.js +302 -49
  40. package/dist/connectors/jdbc.js +762 -110
  41. package/dist/connectors/jira-api-key.js +326 -47
  42. package/dist/connectors/kintone-api-token.js +281 -47
  43. package/dist/connectors/kintone.js +328 -47
  44. package/dist/connectors/linear.js +330 -49
  45. package/dist/connectors/linkedin-ads.js +268 -50
  46. package/dist/connectors/mailchimp-oauth.js +268 -46
  47. package/dist/connectors/mailchimp.js +320 -49
  48. package/dist/connectors/meta-ads-oauth.js +273 -48
  49. package/dist/connectors/meta-ads.js +285 -50
  50. package/dist/connectors/mixpanel.js +338 -47
  51. package/dist/connectors/monday.js +360 -49
  52. package/dist/connectors/mongodb.js +319 -57
  53. package/dist/connectors/notion-oauth.js +231 -5
  54. package/dist/connectors/notion.js +323 -51
  55. package/dist/connectors/openai.js +134 -47
  56. package/dist/connectors/oracle.js +454 -103
  57. package/dist/connectors/outlook-oauth.js +204 -5
  58. package/dist/connectors/powerbi-oauth.js +498 -5
  59. package/dist/connectors/salesforce.js +384 -49
  60. package/dist/connectors/semrush.js +609 -49
  61. package/dist/connectors/sentry.js +289 -50
  62. package/dist/connectors/shopify-oauth.js +187 -5
  63. package/dist/connectors/shopify.js +357 -47
  64. package/dist/connectors/sqlserver.js +415 -102
  65. package/dist/connectors/stripe-api-key.js +269 -46
  66. package/dist/connectors/stripe-oauth.js +202 -5
  67. package/dist/connectors/supabase.js +303 -48
  68. package/dist/connectors/tableau.js +536 -163
  69. package/dist/connectors/tiktok-ads.js +279 -48
  70. package/dist/connectors/wix-store.js +320 -49
  71. package/dist/connectors/zendesk-oauth.js +239 -5
  72. package/dist/connectors/zendesk.js +358 -47
  73. package/dist/index.d.ts +149 -1
  74. package/dist/index.js +15057 -2117
  75. package/dist/main.js +15005 -2073
  76. package/dist/vite-plugin.js +14752 -2019
  77. 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 = class {
3
- slug;
4
- name;
5
- description;
6
- envVarBaseKey;
7
- type;
8
- secret;
9
- required;
10
- constructor(config) {
11
- this.slug = config.slug;
12
- this.name = config.name;
13
- this.description = config.description;
14
- this.envVarBaseKey = config.envVarBaseKey;
15
- this.type = config.type;
16
- this.secret = config.secret;
17
- this.required = config.required;
18
- }
19
- /**
20
- * Get the parameter value from a ConnectorConnectionObject.
21
- */
22
- getValue(connection2) {
23
- const param = connection2.parameters.find(
24
- (p) => p.parameterSlug === this.slug
25
- );
26
- if (!param || param.value == null) {
27
- throw new Error(
28
- `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
29
- );
30
- }
31
- return param.value;
32
- }
33
- /**
34
- * Try to get the parameter value. Returns undefined if not found (for optional params).
35
- */
36
- tryGetValue(connection2) {
37
- const param = connection2.parameters.find(
38
- (p) => p.parameterSlug === this.slug
39
- );
40
- if (!param || param.value == null) return void 0;
41
- return param.value;
7
+ var ParameterDefinition;
8
+ var init_parameter_definition = __esm({
9
+ "../connectors/src/parameter-definition.ts"() {
10
+ "use strict";
11
+ ParameterDefinition = class {
12
+ slug;
13
+ name;
14
+ description;
15
+ envVarBaseKey;
16
+ type;
17
+ secret;
18
+ required;
19
+ constructor(config) {
20
+ this.slug = config.slug;
21
+ this.name = config.name;
22
+ this.description = config.description;
23
+ this.envVarBaseKey = config.envVarBaseKey;
24
+ this.type = config.type;
25
+ this.secret = config.secret;
26
+ this.required = config.required;
27
+ }
28
+ /**
29
+ * Get the parameter value from a ConnectorConnectionObject.
30
+ */
31
+ getValue(connection2) {
32
+ const param = connection2.parameters.find(
33
+ (p) => p.parameterSlug === this.slug
34
+ );
35
+ if (!param || param.value == null) {
36
+ throw new Error(
37
+ `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
38
+ );
39
+ }
40
+ return param.value;
41
+ }
42
+ /**
43
+ * Try to get the parameter value. Returns undefined if not found (for optional params).
44
+ */
45
+ tryGetValue(connection2) {
46
+ const param = connection2.parameters.find(
47
+ (p) => p.parameterSlug === this.slug
48
+ );
49
+ if (!param || param.value == null) return void 0;
50
+ return param.value;
51
+ }
52
+ };
42
53
  }
43
- };
54
+ });
44
55
 
45
56
  // ../connectors/src/connectors/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,76 @@ 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
+ const pendingParameterUpdates = [];
369
+ for (const step of flow.steps) {
370
+ const ans = ctx.answers[answerIdx];
371
+ if (ans && ans.questionSlug === step.slug) {
372
+ state = step.applyAnswer(state, ans.answer);
373
+ if (step.toParameterUpdates) {
374
+ pendingParameterUpdates.push(...step.toParameterUpdates(state));
375
+ }
376
+ answerIdx += 1;
377
+ continue;
378
+ }
379
+ const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
380
+ if (step.type === "text") {
381
+ if (step.fetchOptions) {
382
+ const options2 = await step.fetchOptions(state, runtime);
383
+ if (options2.length === 0) {
384
+ continue;
385
+ }
386
+ }
387
+ return {
388
+ type: "nextQuestion",
389
+ questionSlug: step.slug,
390
+ question: step.question[ctx.language],
391
+ questionType: "text",
392
+ allowFreeText: resolvedAllowFreeText,
393
+ ...pendingParameterUpdates.length > 0 && {
394
+ parameterUpdates: pendingParameterUpdates
395
+ }
396
+ };
397
+ }
398
+ const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
399
+ if (options.length === 0) {
400
+ continue;
401
+ }
402
+ return {
403
+ type: "nextQuestion",
404
+ questionSlug: step.slug,
405
+ question: step.question[ctx.language],
406
+ questionType: step.type,
407
+ options,
408
+ allowFreeText: resolvedAllowFreeText,
409
+ ...pendingParameterUpdates.length > 0 && {
410
+ parameterUpdates: pendingParameterUpdates
411
+ }
412
+ };
413
+ }
414
+ const dataInvestigationResult = await flow.finalize(state, runtime);
415
+ return {
416
+ type: "fulfilled",
417
+ dataInvestigationResult,
418
+ ...pendingParameterUpdates.length > 0 && {
419
+ parameterUpdates: pendingParameterUpdates
420
+ }
421
+ };
422
+ }
423
+ async function resolveSetupSelection(params) {
424
+ const { selected, allSentinel, fetchAll, limit } = params;
425
+ const resolved = selected.includes(allSentinel) ? await fetchAll() : selected.filter((v) => v !== allSentinel);
426
+ return resolved.slice(0, limit);
427
+ }
428
+
323
429
  // ../connectors/src/auth-types.ts
324
430
  var AUTH_TYPES = {
325
431
  OAUTH: "oauth",
@@ -344,6 +450,150 @@ var zendeskOnboarding = new ConnectorOnboarding({
344
450
  }
345
451
  });
346
452
 
453
+ // ../connectors/src/connectors/zendesk/utils.ts
454
+ function normalizeSubdomain(raw) {
455
+ return raw.trim().replace(/^https?:\/\//i, "").replace(/\.zendesk\.com.*$/, "").replace(/\/+$/, "").split(".")[0];
456
+ }
457
+ function basicAuthHeader(email, apiToken) {
458
+ return `Basic ${Buffer.from(`${email}/token:${apiToken}`).toString("base64")}`;
459
+ }
460
+ async function apiFetch(params, path2, init) {
461
+ const subdomain = params[parameters.subdomain.slug];
462
+ const email = params[parameters.email.slug];
463
+ const apiToken = params[parameters.apiToken.slug];
464
+ if (!subdomain || !email || !apiToken) {
465
+ throw new Error(
466
+ "zendesk: missing required parameter(s) (subdomain, email, api-token)"
467
+ );
468
+ }
469
+ const url = `https://${normalizeSubdomain(subdomain)}.zendesk.com${path2.startsWith("/") ? "" : "/"}${path2}`;
470
+ const headers = new Headers(init?.headers);
471
+ headers.set("Authorization", basicAuthHeader(email, apiToken));
472
+ headers.set("Accept", "application/json");
473
+ return fetch(url, { ...init, headers });
474
+ }
475
+
476
+ // ../connectors/src/connectors/zendesk/setup-flow.ts
477
+ var ZENDESK_SETUP_MAX_ENTITIES = 5;
478
+ var ZENDESK_ENTITIES = [
479
+ {
480
+ value: "tickets",
481
+ label: "Tickets",
482
+ countPath: "/api/v2/tickets.json?page[size]=1",
483
+ countField: "count"
484
+ },
485
+ {
486
+ value: "users",
487
+ label: "Users",
488
+ countPath: "/api/v2/users.json?page[size]=1",
489
+ countField: "count"
490
+ },
491
+ {
492
+ value: "organizations",
493
+ label: "Organizations",
494
+ countPath: "/api/v2/organizations.json?page[size]=1",
495
+ countField: "count"
496
+ },
497
+ {
498
+ value: "groups",
499
+ label: "Groups",
500
+ countPath: "/api/v2/groups.json?page[size]=1",
501
+ countField: "count"
502
+ },
503
+ {
504
+ value: "articles",
505
+ label: "Help Center articles",
506
+ countPath: "/api/v2/help_center/articles.json?page[size]=1",
507
+ countField: "count"
508
+ }
509
+ ];
510
+ async function listBrands(params) {
511
+ const res = await apiFetch(params, "/api/v2/brands.json");
512
+ if (!res.ok) return [];
513
+ const data = await res.json();
514
+ return data.brands ?? [];
515
+ }
516
+ async function fetchCount(params, path2, countField) {
517
+ const res = await apiFetch(params, path2);
518
+ if (!res.ok) return null;
519
+ const data = await res.json();
520
+ const raw = data[countField];
521
+ if (typeof raw === "number") return raw;
522
+ if (typeof data["count"] === "number") return data["count"];
523
+ return null;
524
+ }
525
+ var zendeskSetupFlow = {
526
+ initialState: () => ({}),
527
+ steps: [
528
+ {
529
+ slug: "brand",
530
+ type: "select",
531
+ question: {
532
+ 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",
533
+ en: "Select the Zendesk brand to use for setup"
534
+ },
535
+ async fetchOptions(_state, rt) {
536
+ const brands = await listBrands(rt.params);
537
+ const active = brands.filter((b) => b.active !== false && b.name);
538
+ if (active.length < 2) return [];
539
+ return active.map((b) => ({
540
+ value: String(b.subdomain ?? b.id ?? b.name),
541
+ label: String(b.name)
542
+ }));
543
+ },
544
+ applyAnswer: (state, answer) => ({ ...state, brand: answer[0] })
545
+ },
546
+ {
547
+ slug: "entities",
548
+ type: "multiSelect",
549
+ question: {
550
+ 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",
551
+ en: "Select the entities to include in setup (multi-select allowed)"
552
+ },
553
+ async fetchOptions(_state, _rt) {
554
+ return ZENDESK_ENTITIES.map((e) => ({ value: e.value, label: e.label }));
555
+ },
556
+ applyAnswer: (state, answer) => ({ ...state, entities: answer })
557
+ }
558
+ ],
559
+ async finalize(state, rt) {
560
+ if (!state.entities) {
561
+ throw new Error("Zendesk setup: incomplete state on finalize");
562
+ }
563
+ const targetEntities = await resolveSetupSelection({
564
+ selected: state.entities,
565
+ allSentinel: "__ALL__",
566
+ fetchAll: async () => ZENDESK_ENTITIES.map((e) => e.value),
567
+ limit: ZENDESK_SETUP_MAX_ENTITIES
568
+ });
569
+ const entityByValue = new Map(ZENDESK_ENTITIES.map((e) => [e.value, e]));
570
+ const sections = ["## Zendesk", ""];
571
+ if (state.brand) {
572
+ sections.push(`### Brand: ${state.brand}`, "");
573
+ }
574
+ sections.push("### Selected entities", "");
575
+ sections.push("| Entity | Count |");
576
+ sections.push("|--------|-------|");
577
+ for (const value of targetEntities) {
578
+ const entity = entityByValue.get(value);
579
+ if (!entity) {
580
+ sections.push(`| ${value} | _unknown_ |`);
581
+ continue;
582
+ }
583
+ const count = await fetchCount(
584
+ rt.params,
585
+ entity.countPath,
586
+ entity.countField
587
+ );
588
+ sections.push(
589
+ `| ${entity.label} (${entity.value}) | ${count == null ? "-" : count} |`
590
+ );
591
+ }
592
+ sections.push("");
593
+ return sections.join("\n");
594
+ }
595
+ };
596
+
347
597
  // ../connectors/src/connectors/zendesk/tools/request.ts
348
598
  import { z } from "zod";
349
599
  var REQUEST_TIMEOUT_MS = 6e4;
@@ -612,7 +862,48 @@ export default async function handler(c: Context) {
612
862
  - \`type:user role:agent\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30E6\u30FC\u30B6\u30FC
613
863
  - \`type:organization {name}\` \u2014 \u540D\u524D\u304C\u4E00\u81F4\u3059\u308B\u7D44\u7E54`
614
864
  },
615
- tools
865
+ tools,
866
+ setup: (params, ctx, config) => runSetupFlow(zendeskSetupFlow, params, ctx, config),
867
+ async checkConnection(params, _config) {
868
+ const subdomain = params[parameters.subdomain.slug];
869
+ const email = params[parameters.email.slug];
870
+ const apiToken = params[parameters.apiToken.slug];
871
+ if (!subdomain || !email || !apiToken) {
872
+ return {
873
+ success: false,
874
+ error: `Missing required parameter(s): ${parameters.subdomain.slug}, ${parameters.email.slug}, ${parameters.apiToken.slug}`
875
+ };
876
+ }
877
+ try {
878
+ const credentials = Buffer.from(
879
+ `${email}/token:${apiToken}`,
880
+ "utf-8"
881
+ ).toString("base64");
882
+ const res = await fetch(
883
+ `https://${subdomain}.zendesk.com/api/v2/users/me.json`,
884
+ {
885
+ method: "GET",
886
+ headers: {
887
+ Authorization: `Basic ${credentials}`,
888
+ Accept: "application/json"
889
+ }
890
+ }
891
+ );
892
+ if (!res.ok) {
893
+ const errText = await res.text().catch(() => res.statusText);
894
+ return {
895
+ success: false,
896
+ error: `Zendesk API failed: HTTP ${res.status} ${errText}`
897
+ };
898
+ }
899
+ return { success: true };
900
+ } catch (error) {
901
+ return {
902
+ success: false,
903
+ error: error instanceof Error ? error.message : String(error)
904
+ };
905
+ }
906
+ }
616
907
  });
617
908
 
618
909
  // src/connectors/create-connector-sdk.ts
@@ -641,6 +932,7 @@ function resolveEnvVarOptional(entry, key) {
641
932
  import { getContext } from "hono/context-storage";
642
933
  import { getCookie } from "hono/cookie";
643
934
  var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
935
+ var TABLEAU_SESSION_SENTINEL_URL = "squadbase://tableau-session/";
644
936
  function normalizeHeaders(input) {
645
937
  const out = {};
646
938
  if (!input) return out;
@@ -649,6 +941,11 @@ function normalizeHeaders(input) {
649
941
  });
650
942
  return out;
651
943
  }
944
+ function extractInputUrl(input) {
945
+ if (typeof input === "string") return input;
946
+ if (input instanceof URL) return input.href;
947
+ return input.url;
948
+ }
652
949
  function createSandboxProxyFetch(connectionId) {
653
950
  return async (input, init) => {
654
951
  const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
@@ -658,10 +955,17 @@ function createSandboxProxyFetch(connectionId) {
658
955
  "Connection proxy is not configured. Please check your deployment settings."
659
956
  );
660
957
  }
661
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
958
+ const originalUrl = extractInputUrl(input);
959
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
960
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
961
+ const sessionUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
962
+ return fetch(sessionUrl, {
963
+ method: "POST",
964
+ headers: { Authorization: `Bearer ${token}` }
965
+ });
966
+ }
662
967
  const originalMethod = init?.method ?? "GET";
663
968
  const originalBody = init?.body ? JSON.parse(init.body) : void 0;
664
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
665
969
  const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
666
970
  return fetch(proxyUrl, {
667
971
  method: "POST",
@@ -687,10 +991,9 @@ function createDeployedAppProxyFetch(connectionId) {
687
991
  }
688
992
  const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
689
993
  const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
994
+ const sessionUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/tableau-session`;
690
995
  return async (input, init) => {
691
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
692
- const originalMethod = init?.method ?? "GET";
693
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
996
+ const originalUrl = extractInputUrl(input);
694
997
  const c = getContext();
695
998
  const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
696
999
  if (!appSession) {
@@ -698,6 +1001,14 @@ function createDeployedAppProxyFetch(connectionId) {
698
1001
  "No authentication method available for connection proxy."
699
1002
  );
700
1003
  }
1004
+ if (originalUrl === TABLEAU_SESSION_SENTINEL_URL) {
1005
+ return fetch(sessionUrl, {
1006
+ method: "POST",
1007
+ headers: { Authorization: `Bearer ${appSession}` }
1008
+ });
1009
+ }
1010
+ const originalMethod = init?.method ?? "GET";
1011
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
701
1012
  return fetch(proxyUrl, {
702
1013
  method: "POST",
703
1014
  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 };