@squadbase/vite-server 0.1.3-dev.6 → 0.1.3-dev.8
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 +1858 -1340
- package/dist/connectors/airtable-oauth.js +74 -1
- package/dist/connectors/airtable.js +74 -1
- package/dist/connectors/amplitude.js +74 -1
- package/dist/connectors/anthropic.js +74 -1
- package/dist/connectors/asana.js +74 -1
- package/dist/connectors/attio.js +74 -1
- package/dist/connectors/customerio.js +74 -1
- package/dist/connectors/dbt.js +74 -1
- package/dist/connectors/gemini.js +74 -1
- package/dist/connectors/gmail-oauth.js +74 -1
- package/dist/connectors/gmail.js +74 -1
- package/dist/connectors/google-ads-oauth.js +74 -1
- package/dist/connectors/google-ads.js +74 -1
- package/dist/connectors/google-analytics-oauth.js +87 -6
- package/dist/connectors/google-analytics.js +117 -52
- package/dist/connectors/google-calendar-oauth.js +75 -2
- package/dist/connectors/google-calendar.d.ts +1 -8
- package/dist/connectors/google-calendar.js +363 -60
- package/dist/connectors/google-sheets-oauth.js +141 -31
- package/dist/connectors/google-sheets.js +108 -9
- package/dist/connectors/grafana.d.ts +5 -0
- package/dist/connectors/grafana.js +638 -0
- package/dist/connectors/hubspot-oauth.js +74 -1
- package/dist/connectors/hubspot.js +74 -1
- package/dist/connectors/intercom-oauth.js +74 -1
- package/dist/connectors/intercom.js +74 -1
- package/dist/connectors/jira-api-key.js +74 -1
- package/dist/connectors/kintone-api-token.js +74 -1
- package/dist/connectors/kintone.js +74 -1
- package/dist/connectors/linkedin-ads-oauth.js +74 -1
- package/dist/connectors/linkedin-ads.js +74 -1
- package/dist/connectors/mailchimp-oauth.js +74 -1
- package/dist/connectors/mailchimp.js +74 -1
- package/dist/connectors/notion-oauth.js +74 -1
- package/dist/connectors/notion.js +74 -1
- package/dist/connectors/openai.js +74 -1
- package/dist/connectors/shopify-oauth.js +74 -1
- package/dist/connectors/shopify.js +74 -1
- package/dist/connectors/stripe-api-key.js +74 -1
- package/dist/connectors/stripe-oauth.js +74 -1
- package/dist/connectors/wix-store.js +74 -1
- package/dist/connectors/zendesk-oauth.js +74 -1
- package/dist/connectors/zendesk.js +74 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1808 -1291
- package/dist/main.js +1807 -1289
- package/dist/vite-plugin.js +1807 -1289
- package/package.json +5 -1
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../connectors/src/connectors/google-sheets/utils.ts
|
|
12
|
+
function extractSpreadsheetId(urlOrId) {
|
|
13
|
+
const trimmed = urlOrId.trim();
|
|
14
|
+
const match = trimmed.match(SPREADSHEET_URL_PATTERN);
|
|
15
|
+
if (match) {
|
|
16
|
+
return match[1];
|
|
17
|
+
}
|
|
18
|
+
return trimmed;
|
|
19
|
+
}
|
|
20
|
+
var SPREADSHEET_URL_PATTERN;
|
|
21
|
+
var init_utils = __esm({
|
|
22
|
+
"../connectors/src/connectors/google-sheets/utils.ts"() {
|
|
23
|
+
"use strict";
|
|
24
|
+
SPREADSHEET_URL_PATTERN = /docs\.google\.com\/spreadsheets\/d\/([a-zA-Z0-9_-]+)/;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// ../connectors/src/connectors/google-sheets-oauth/utils.ts
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
extractSpreadsheetId: () => extractSpreadsheetId
|
|
32
|
+
});
|
|
33
|
+
var init_utils2 = __esm({
|
|
34
|
+
"../connectors/src/connectors/google-sheets-oauth/utils.ts"() {
|
|
35
|
+
"use strict";
|
|
36
|
+
init_utils();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
1
40
|
// ../connectors/src/parameter-definition.ts
|
|
2
41
|
var ParameterDefinition = class {
|
|
3
42
|
slug;
|
|
@@ -44,21 +83,23 @@ var ParameterDefinition = class {
|
|
|
44
83
|
|
|
45
84
|
// ../connectors/src/connectors/google-sheets-oauth/parameters.ts
|
|
46
85
|
var parameters = {
|
|
47
|
-
|
|
48
|
-
slug: "spreadsheet-
|
|
49
|
-
name: "
|
|
50
|
-
description: "The
|
|
51
|
-
envVarBaseKey: "
|
|
86
|
+
spreadsheetUrl: new ParameterDefinition({
|
|
87
|
+
slug: "spreadsheet-url",
|
|
88
|
+
name: "Google Spreadsheet URL",
|
|
89
|
+
description: "The URL of the Google Spreadsheet (e.g., https://docs.google.com/spreadsheets/d/xxxxx/edit). The spreadsheet ID is automatically extracted from the URL.",
|
|
90
|
+
envVarBaseKey: "GOOGLE_SHEETS_OAUTH_SPREADSHEET_URL",
|
|
52
91
|
type: "text",
|
|
53
92
|
secret: false,
|
|
54
|
-
required:
|
|
93
|
+
required: true
|
|
55
94
|
})
|
|
56
95
|
};
|
|
57
96
|
|
|
58
97
|
// ../connectors/src/connectors/google-sheets-oauth/sdk/index.ts
|
|
98
|
+
init_utils2();
|
|
59
99
|
var BASE_URL = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
60
100
|
function createClient(params, fetchFn = fetch) {
|
|
61
|
-
const
|
|
101
|
+
const spreadsheetUrl = params[parameters.spreadsheetUrl.slug];
|
|
102
|
+
const defaultSpreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
|
|
62
103
|
function resolveSpreadsheetId(override) {
|
|
63
104
|
const id = override ?? defaultSpreadsheetId;
|
|
64
105
|
if (!id) {
|
|
@@ -233,6 +274,7 @@ var AUTH_TYPES = {
|
|
|
233
274
|
|
|
234
275
|
// ../connectors/src/connectors/google-sheets-oauth/tools/request.ts
|
|
235
276
|
import { z } from "zod";
|
|
277
|
+
init_utils2();
|
|
236
278
|
var BASE_URL2 = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
237
279
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
238
280
|
var cachedToken = null;
|
|
@@ -307,7 +349,8 @@ Authentication is handled automatically via OAuth proxy.
|
|
|
307
349
|
`[connector-request] google-sheets-oauth/${connection2.name}: ${method} ${path2}`
|
|
308
350
|
);
|
|
309
351
|
try {
|
|
310
|
-
const
|
|
352
|
+
const spreadsheetUrl = parameters.spreadsheetUrl.tryGetValue(connection2);
|
|
353
|
+
const spreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
|
|
311
354
|
const resolvedPath = spreadsheetId ? path2.replace(/\{spreadsheetId\}/g, spreadsheetId) : path2;
|
|
312
355
|
let url = `${BASE_URL2}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
|
|
313
356
|
if (queryParams) {
|
|
@@ -351,43 +394,35 @@ Authentication is handled automatically via OAuth proxy.
|
|
|
351
394
|
var requestToolName = `google-sheets-oauth_${requestTool.name}`;
|
|
352
395
|
var googleSheetsOnboarding = new ConnectorOnboarding({
|
|
353
396
|
connectionSetupInstructions: {
|
|
354
|
-
ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Sheets\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
355
|
-
|
|
356
|
-
1. \
|
|
357
|
-
2. \u30E6\u30FC\u30B6\u30FC\u304CURL\u307E\u305F\u306F\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID\u3092\u63D0\u4F9B\u3057\u305F\u3089\u3001URL\u304B\u3089ID\u3092\u62BD\u51FA\u3059\u308B\uFF08\`/d/\` \u3068 \`/edit\` \u306E\u9593\u306E\u6587\u5B57\u5217\uFF09
|
|
358
|
-
3. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
|
|
359
|
-
- \`parameterSlug\`: \`"spreadsheet-id"\`
|
|
360
|
-
- \`value\`: \u62BD\u51FA\u3057\u305F\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID
|
|
361
|
-
4. \`${requestToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3059\u308B:
|
|
397
|
+
ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Sheets\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8URL\u306F\u63A5\u7D9A\u30D1\u30E9\u30E1\u30FC\u30BF\u3068\u3057\u3066\u65E2\u306B\u767B\u9332\u6E08\u307F\u3067\u3059\u3002\u30E6\u30FC\u30B6\u30FC\u306B\u805E\u304D\u8FD4\u3055\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
|
|
398
|
+
|
|
399
|
+
1. \`${requestToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3059\u308B:
|
|
362
400
|
- \`method\`: \`"GET"\`
|
|
363
401
|
- \`path\`: \`"/{spreadsheetId}?fields=spreadsheetId,properties.title,sheets.properties.title"\`
|
|
364
|
-
|
|
365
|
-
|
|
402
|
+
2. \u30A8\u30E9\u30FC\u304C\u8FD4\u3055\u308C\u305F\u5834\u5408\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u5171\u6709\u8A2D\u5B9A\u3092\u78BA\u8A8D\u3059\u308B\u3088\u3046\u4F1D\u3048\u308B
|
|
403
|
+
3. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
|
|
366
404
|
- \`spreadsheet\`: \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30BF\u30A4\u30C8\u30EB
|
|
367
405
|
- \`sheets\`: \u30B7\u30FC\u30C8\u540D\u4E00\u89A7\uFF08\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
|
|
368
406
|
- \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
|
|
369
407
|
|
|
370
408
|
#### \u5236\u7D04
|
|
371
409
|
- **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30B7\u30FC\u30C8\u306E\u30C7\u30FC\u30BF\u3092\u8AAD\u307F\u53D6\u3089\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u30EA\u30AF\u30A8\u30B9\u30C8\u306E\u307F
|
|
410
|
+
- \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8URL\u3092\u30E6\u30FC\u30B6\u30FC\u306B\u805E\u304D\u8FD4\u3055\u306A\u3044\u3053\u3068\uFF08\u767B\u9332\u6E08\u307F\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u305D\u306E\u307E\u307E\u4F7F\u7528\u3059\u308B\uFF09
|
|
372
411
|
- \u30C4\u30FC\u30EB\u9593\u306F1\u6587\u3060\u3051\u66F8\u3044\u3066\u5373\u6B21\u306E\u30C4\u30FC\u30EB\u547C\u3073\u51FA\u3057\u3002\u4E0D\u8981\u306A\u8AAC\u660E\u306F\u7701\u7565\u3057\u3001\u52B9\u7387\u7684\u306B\u9032\u3081\u308B`,
|
|
373
|
-
en: `Follow these steps to set up the Google Sheets connection.
|
|
374
|
-
|
|
375
|
-
1.
|
|
376
|
-
2. When the user provides a URL or spreadsheet ID, extract the ID from the URL (the string between \`/d/\` and \`/edit\`)
|
|
377
|
-
3. Call \`updateConnectionParameters\`:
|
|
378
|
-
- \`parameterSlug\`: \`"spreadsheet-id"\`
|
|
379
|
-
- \`value\`: The extracted spreadsheet ID
|
|
380
|
-
4. Call \`${requestToolName}\` to fetch spreadsheet metadata:
|
|
412
|
+
en: `Follow these steps to set up the Google Sheets connection. The spreadsheet URL is already registered as a connection parameter \u2014 do NOT ask the user for it again.
|
|
413
|
+
|
|
414
|
+
1. Call \`${requestToolName}\` to fetch spreadsheet metadata:
|
|
381
415
|
- \`method\`: \`"GET"\`
|
|
382
416
|
- \`path\`: \`"/{spreadsheetId}?fields=spreadsheetId,properties.title,sheets.properties.title"\`
|
|
383
|
-
|
|
384
|
-
|
|
417
|
+
2. If an error is returned, ask the user to check the spreadsheet sharing settings
|
|
418
|
+
3. Call \`updateConnectionContext\`:
|
|
385
419
|
- \`spreadsheet\`: The spreadsheet title
|
|
386
420
|
- \`sheets\`: Sheet names (comma-separated)
|
|
387
421
|
- \`note\`: Brief description of the setup
|
|
388
422
|
|
|
389
423
|
#### Constraints
|
|
390
424
|
- **Do NOT read sheet data during setup**. Only the metadata request specified in the steps above is allowed
|
|
425
|
+
- Do NOT ask the user for the spreadsheet URL \u2014 it is already stored as a connection parameter
|
|
391
426
|
- Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
|
|
392
427
|
},
|
|
393
428
|
dataOverviewInstructions: {
|
|
@@ -518,10 +553,12 @@ batch.valueRanges.forEach(vr => console.log(vr.range, vr.values));
|
|
|
518
553
|
tools,
|
|
519
554
|
async checkConnection(params, config) {
|
|
520
555
|
const { proxyFetch } = config;
|
|
521
|
-
const
|
|
522
|
-
if (!
|
|
556
|
+
const spreadsheetUrl = params[parameters.spreadsheetUrl.slug];
|
|
557
|
+
if (!spreadsheetUrl) {
|
|
523
558
|
return { success: true };
|
|
524
559
|
}
|
|
560
|
+
const { extractSpreadsheetId: extractSpreadsheetId2 } = await Promise.resolve().then(() => (init_utils2(), utils_exports));
|
|
561
|
+
const spreadsheetId = extractSpreadsheetId2(spreadsheetUrl);
|
|
525
562
|
const url = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}?fields=spreadsheetId,properties.title`;
|
|
526
563
|
try {
|
|
527
564
|
const res = await proxyFetch(url, { method: "GET" });
|
|
@@ -564,6 +601,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
564
601
|
return process.env[envVarName] || void 0;
|
|
565
602
|
}
|
|
566
603
|
|
|
604
|
+
// src/connector-client/proxy-fetch.ts
|
|
605
|
+
import { getContext } from "hono/context-storage";
|
|
606
|
+
import { getCookie } from "hono/cookie";
|
|
607
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
608
|
+
function createSandboxProxyFetch(connectionId) {
|
|
609
|
+
return async (input, init) => {
|
|
610
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
611
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
612
|
+
if (!token || !sandboxId) {
|
|
613
|
+
throw new Error(
|
|
614
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
618
|
+
const originalMethod = init?.method ?? "GET";
|
|
619
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
620
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
621
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
622
|
+
return fetch(proxyUrl, {
|
|
623
|
+
method: "POST",
|
|
624
|
+
headers: {
|
|
625
|
+
"Content-Type": "application/json",
|
|
626
|
+
Authorization: `Bearer ${token}`
|
|
627
|
+
},
|
|
628
|
+
body: JSON.stringify({
|
|
629
|
+
url: originalUrl,
|
|
630
|
+
method: originalMethod,
|
|
631
|
+
body: originalBody
|
|
632
|
+
})
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
637
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
638
|
+
if (!projectId) {
|
|
639
|
+
throw new Error(
|
|
640
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
644
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
645
|
+
return async (input, init) => {
|
|
646
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
647
|
+
const originalMethod = init?.method ?? "GET";
|
|
648
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
649
|
+
const c = getContext();
|
|
650
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
651
|
+
if (!appSession) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
"No authentication method available for connection proxy."
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
return fetch(proxyUrl, {
|
|
657
|
+
method: "POST",
|
|
658
|
+
headers: {
|
|
659
|
+
"Content-Type": "application/json",
|
|
660
|
+
Authorization: `Bearer ${appSession}`
|
|
661
|
+
},
|
|
662
|
+
body: JSON.stringify({
|
|
663
|
+
url: originalUrl,
|
|
664
|
+
method: originalMethod,
|
|
665
|
+
body: originalBody
|
|
666
|
+
})
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function createProxyFetch(connectionId) {
|
|
671
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
672
|
+
return createSandboxProxyFetch(connectionId);
|
|
673
|
+
}
|
|
674
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
675
|
+
}
|
|
676
|
+
|
|
567
677
|
// src/connectors/create-connector-sdk.ts
|
|
568
678
|
function loadConnectionsSync() {
|
|
569
679
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -597,7 +707,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
597
707
|
if (val !== void 0) params[param.slug] = val;
|
|
598
708
|
}
|
|
599
709
|
}
|
|
600
|
-
return createClient2(params);
|
|
710
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
601
711
|
};
|
|
602
712
|
}
|
|
603
713
|
|
|
@@ -1,3 +1,25 @@
|
|
|
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
|
+
|
|
6
|
+
// ../connectors/src/connectors/google-sheets/utils.ts
|
|
7
|
+
function extractSpreadsheetId(urlOrId) {
|
|
8
|
+
const trimmed = urlOrId.trim();
|
|
9
|
+
const match = trimmed.match(SPREADSHEET_URL_PATTERN);
|
|
10
|
+
if (match) {
|
|
11
|
+
return match[1];
|
|
12
|
+
}
|
|
13
|
+
return trimmed;
|
|
14
|
+
}
|
|
15
|
+
var SPREADSHEET_URL_PATTERN;
|
|
16
|
+
var init_utils = __esm({
|
|
17
|
+
"../connectors/src/connectors/google-sheets/utils.ts"() {
|
|
18
|
+
"use strict";
|
|
19
|
+
SPREADSHEET_URL_PATTERN = /docs\.google\.com\/spreadsheets\/d\/([a-zA-Z0-9_-]+)/;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
1
23
|
// ../connectors/src/parameter-definition.ts
|
|
2
24
|
var ParameterDefinition = class {
|
|
3
25
|
slug;
|
|
@@ -56,18 +78,19 @@ var parameters = {
|
|
|
56
78
|
secret: true,
|
|
57
79
|
required: true
|
|
58
80
|
}),
|
|
59
|
-
|
|
60
|
-
slug: "spreadsheet-
|
|
61
|
-
name: "
|
|
62
|
-
description: "The
|
|
63
|
-
envVarBaseKey: "
|
|
81
|
+
spreadsheetUrl: new ParameterDefinition({
|
|
82
|
+
slug: "spreadsheet-url",
|
|
83
|
+
name: "Google Spreadsheet URL",
|
|
84
|
+
description: "The URL of the Google Spreadsheet (e.g., https://docs.google.com/spreadsheets/d/xxxxx/edit). The spreadsheet ID is automatically extracted from the URL.",
|
|
85
|
+
envVarBaseKey: "GOOGLE_SHEETS_SPREADSHEET_URL",
|
|
64
86
|
type: "text",
|
|
65
87
|
secret: false,
|
|
66
|
-
required:
|
|
88
|
+
required: true
|
|
67
89
|
})
|
|
68
90
|
};
|
|
69
91
|
|
|
70
92
|
// ../connectors/src/connectors/google-sheets/sdk/index.ts
|
|
93
|
+
init_utils();
|
|
71
94
|
var TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
72
95
|
var BASE_URL = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
73
96
|
var SCOPE = "https://www.googleapis.com/auth/spreadsheets.readonly";
|
|
@@ -95,7 +118,8 @@ function buildJwt(clientEmail, privateKey, nowSec) {
|
|
|
95
118
|
}
|
|
96
119
|
function createClient(params) {
|
|
97
120
|
const serviceAccountKeyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
|
|
98
|
-
const
|
|
121
|
+
const spreadsheetUrl = params[parameters.spreadsheetUrl.slug];
|
|
122
|
+
const defaultSpreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
|
|
99
123
|
if (!serviceAccountKeyJsonBase64) {
|
|
100
124
|
throw new Error(
|
|
101
125
|
`google-sheets: missing required parameter: ${parameters.serviceAccountKeyJsonBase64.slug}`
|
|
@@ -335,6 +359,7 @@ var googleSheetsOnboarding = new ConnectorOnboarding({
|
|
|
335
359
|
|
|
336
360
|
// ../connectors/src/connectors/google-sheets/tools/request.ts
|
|
337
361
|
import { z } from "zod";
|
|
362
|
+
init_utils();
|
|
338
363
|
var BASE_URL2 = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
339
364
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
340
365
|
var inputSchema = z.object({
|
|
@@ -380,7 +405,8 @@ Authentication is handled automatically using a service account.
|
|
|
380
405
|
try {
|
|
381
406
|
const { GoogleAuth } = await import("google-auth-library");
|
|
382
407
|
const keyJsonBase64 = parameters.serviceAccountKeyJsonBase64.getValue(connection2);
|
|
383
|
-
const
|
|
408
|
+
const spreadsheetUrl = parameters.spreadsheetUrl.tryGetValue(connection2);
|
|
409
|
+
const spreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
|
|
384
410
|
const credentials = JSON.parse(
|
|
385
411
|
Buffer.from(keyJsonBase64, "base64").toString("utf-8")
|
|
386
412
|
);
|
|
@@ -564,6 +590,79 @@ function resolveEnvVarOptional(entry, key) {
|
|
|
564
590
|
return process.env[envVarName] || void 0;
|
|
565
591
|
}
|
|
566
592
|
|
|
593
|
+
// src/connector-client/proxy-fetch.ts
|
|
594
|
+
import { getContext } from "hono/context-storage";
|
|
595
|
+
import { getCookie } from "hono/cookie";
|
|
596
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
597
|
+
function createSandboxProxyFetch(connectionId) {
|
|
598
|
+
return async (input, init) => {
|
|
599
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
600
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
601
|
+
if (!token || !sandboxId) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
607
|
+
const originalMethod = init?.method ?? "GET";
|
|
608
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
609
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
610
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
611
|
+
return fetch(proxyUrl, {
|
|
612
|
+
method: "POST",
|
|
613
|
+
headers: {
|
|
614
|
+
"Content-Type": "application/json",
|
|
615
|
+
Authorization: `Bearer ${token}`
|
|
616
|
+
},
|
|
617
|
+
body: JSON.stringify({
|
|
618
|
+
url: originalUrl,
|
|
619
|
+
method: originalMethod,
|
|
620
|
+
body: originalBody
|
|
621
|
+
})
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
626
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
627
|
+
if (!projectId) {
|
|
628
|
+
throw new Error(
|
|
629
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
633
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
634
|
+
return async (input, init) => {
|
|
635
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
636
|
+
const originalMethod = init?.method ?? "GET";
|
|
637
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
638
|
+
const c = getContext();
|
|
639
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
640
|
+
if (!appSession) {
|
|
641
|
+
throw new Error(
|
|
642
|
+
"No authentication method available for connection proxy."
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
return fetch(proxyUrl, {
|
|
646
|
+
method: "POST",
|
|
647
|
+
headers: {
|
|
648
|
+
"Content-Type": "application/json",
|
|
649
|
+
Authorization: `Bearer ${appSession}`
|
|
650
|
+
},
|
|
651
|
+
body: JSON.stringify({
|
|
652
|
+
url: originalUrl,
|
|
653
|
+
method: originalMethod,
|
|
654
|
+
body: originalBody
|
|
655
|
+
})
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function createProxyFetch(connectionId) {
|
|
660
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
661
|
+
return createSandboxProxyFetch(connectionId);
|
|
662
|
+
}
|
|
663
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
664
|
+
}
|
|
665
|
+
|
|
567
666
|
// src/connectors/create-connector-sdk.ts
|
|
568
667
|
function loadConnectionsSync() {
|
|
569
668
|
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
@@ -597,7 +696,7 @@ function createConnectorSdk(plugin, createClient2) {
|
|
|
597
696
|
if (val !== void 0) params[param.slug] = val;
|
|
598
697
|
}
|
|
599
698
|
}
|
|
600
|
-
return createClient2(params);
|
|
699
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
601
700
|
};
|
|
602
701
|
}
|
|
603
702
|
|