@squadbase/vite-server 0.1.3-dev.15 → 0.1.3-dev.16

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 (59) hide show
  1. package/dist/cli/index.js +2105 -2700
  2. package/dist/connectors/airtable-oauth.js +16 -5
  3. package/dist/connectors/airtable.js +16 -5
  4. package/dist/connectors/amplitude.js +16 -5
  5. package/dist/connectors/anthropic.js +16 -5
  6. package/dist/connectors/asana.js +16 -5
  7. package/dist/connectors/attio.js +16 -5
  8. package/dist/connectors/backlog-api-key.js +16 -5
  9. package/dist/connectors/customerio.js +16 -5
  10. package/dist/connectors/dbt.js +16 -5
  11. package/dist/connectors/gamma.js +16 -5
  12. package/dist/connectors/gemini.js +16 -5
  13. package/dist/connectors/gmail-oauth.js +16 -5
  14. package/dist/connectors/gmail.js +68 -34
  15. package/dist/connectors/google-ads.js +16 -5
  16. package/dist/connectors/google-analytics-oauth.js +16 -5
  17. package/dist/connectors/google-analytics.js +16 -5
  18. package/dist/connectors/google-calendar-oauth.js +16 -5
  19. package/dist/connectors/google-calendar.js +71 -48
  20. package/dist/connectors/{google-drive-oauth.d.ts → google-docs.d.ts} +1 -1
  21. package/dist/connectors/google-docs.js +585 -0
  22. package/dist/connectors/google-drive.d.ts +1 -1
  23. package/dist/connectors/google-drive.js +391 -327
  24. package/dist/connectors/google-sheets.d.ts +1 -1
  25. package/dist/connectors/google-sheets.js +210 -280
  26. package/dist/connectors/google-slides.d.ts +1 -1
  27. package/dist/connectors/google-slides.js +198 -335
  28. package/dist/connectors/grafana.js +16 -5
  29. package/dist/connectors/hubspot-oauth.js +16 -5
  30. package/dist/connectors/hubspot.js +16 -5
  31. package/dist/connectors/intercom-oauth.js +16 -5
  32. package/dist/connectors/intercom.js +16 -5
  33. package/dist/connectors/jira-api-key.js +16 -5
  34. package/dist/connectors/kintone-api-token.js +133 -59
  35. package/dist/connectors/kintone.js +16 -5
  36. package/dist/connectors/linkedin-ads.js +16 -5
  37. package/dist/connectors/mailchimp-oauth.js +16 -5
  38. package/dist/connectors/mailchimp.js +16 -5
  39. package/dist/connectors/mixpanel.js +16 -5
  40. package/dist/connectors/notion-oauth.js +16 -5
  41. package/dist/connectors/notion.js +16 -5
  42. package/dist/connectors/openai.js +16 -5
  43. package/dist/connectors/sentry.js +16 -5
  44. package/dist/connectors/shopify-oauth.js +16 -5
  45. package/dist/connectors/shopify.js +16 -5
  46. package/dist/connectors/stripe-api-key.js +16 -5
  47. package/dist/connectors/stripe-oauth.js +16 -5
  48. package/dist/connectors/wix-store.js +16 -5
  49. package/dist/connectors/zendesk-oauth.js +16 -5
  50. package/dist/connectors/zendesk.js +16 -5
  51. package/dist/index.js +2100 -2695
  52. package/dist/main.js +2100 -2695
  53. package/dist/vite-plugin.js +2100 -2695
  54. package/package.json +7 -15
  55. package/dist/connectors/google-drive-oauth.js +0 -879
  56. package/dist/connectors/google-sheets-oauth.d.ts +0 -5
  57. package/dist/connectors/google-sheets-oauth.js +0 -821
  58. package/dist/connectors/google-slides-oauth.d.ts +0 -5
  59. package/dist/connectors/google-slides-oauth.js +0 -742
@@ -1,821 +0,0 @@
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
-
40
- // ../connectors/src/parameter-definition.ts
41
- var ParameterDefinition = class {
42
- slug;
43
- name;
44
- description;
45
- envVarBaseKey;
46
- type;
47
- secret;
48
- required;
49
- constructor(config) {
50
- this.slug = config.slug;
51
- this.name = config.name;
52
- this.description = config.description;
53
- this.envVarBaseKey = config.envVarBaseKey;
54
- this.type = config.type;
55
- this.secret = config.secret;
56
- this.required = config.required;
57
- }
58
- /**
59
- * Get the parameter value from a ConnectorConnectionObject.
60
- */
61
- getValue(connection2) {
62
- const param = connection2.parameters.find(
63
- (p) => p.parameterSlug === this.slug
64
- );
65
- if (!param || param.value == null) {
66
- throw new Error(
67
- `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
68
- );
69
- }
70
- return param.value;
71
- }
72
- /**
73
- * Try to get the parameter value. Returns undefined if not found (for optional params).
74
- */
75
- tryGetValue(connection2) {
76
- const param = connection2.parameters.find(
77
- (p) => p.parameterSlug === this.slug
78
- );
79
- if (!param || param.value == null) return void 0;
80
- return param.value;
81
- }
82
- };
83
-
84
- // ../connectors/src/connectors/google-sheets-oauth/parameters.ts
85
- var parameters = {
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",
91
- type: "text",
92
- secret: false,
93
- required: false
94
- })
95
- };
96
-
97
- // ../connectors/src/connectors/google-sheets-oauth/sdk/index.ts
98
- init_utils2();
99
- var SHEETS_BASE_URL = "https://sheets.googleapis.com/v4/spreadsheets";
100
- function createClient(params, fetchFn = fetch) {
101
- const spreadsheetUrl = params[parameters.spreadsheetUrl.slug];
102
- const defaultSpreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
103
- function resolveSpreadsheetId(override) {
104
- const id = override ?? defaultSpreadsheetId;
105
- if (!id) {
106
- throw new Error(
107
- "google-sheets: spreadsheetId is required. Either configure a default or pass it explicitly."
108
- );
109
- }
110
- return id;
111
- }
112
- function request(path2, init) {
113
- const resolvedPath = defaultSpreadsheetId ? path2.replace(/\{spreadsheetId\}/g, defaultSpreadsheetId) : path2;
114
- const url = `${SHEETS_BASE_URL}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
115
- return fetchFn(url, init);
116
- }
117
- async function getSpreadsheet(spreadsheetId) {
118
- const id = resolveSpreadsheetId(spreadsheetId);
119
- const url = `${SHEETS_BASE_URL}/${id}?fields=spreadsheetId,properties,sheets.properties`;
120
- const response = await fetchFn(url);
121
- if (!response.ok) {
122
- const body = await response.text();
123
- throw new Error(
124
- `google-sheets: getSpreadsheet failed (${response.status}): ${body}`
125
- );
126
- }
127
- return await response.json();
128
- }
129
- async function getValues(range, spreadsheetId) {
130
- const id = resolveSpreadsheetId(spreadsheetId);
131
- const url = `${SHEETS_BASE_URL}/${id}/values/${encodeURIComponent(range)}`;
132
- const response = await fetchFn(url);
133
- if (!response.ok) {
134
- const body = await response.text();
135
- throw new Error(
136
- `google-sheets: getValues failed (${response.status}): ${body}`
137
- );
138
- }
139
- return await response.json();
140
- }
141
- async function batchGetValues(ranges, spreadsheetId) {
142
- const id = resolveSpreadsheetId(spreadsheetId);
143
- const searchParams = new URLSearchParams();
144
- for (const range of ranges) {
145
- searchParams.append("ranges", range);
146
- }
147
- const url = `${SHEETS_BASE_URL}/${id}/values:batchGet?${searchParams.toString()}`;
148
- const response = await fetchFn(url);
149
- if (!response.ok) {
150
- const body = await response.text();
151
- throw new Error(
152
- `google-sheets: batchGetValues failed (${response.status}): ${body}`
153
- );
154
- }
155
- return await response.json();
156
- }
157
- async function updateValues(range, values, spreadsheetId) {
158
- const id = resolveSpreadsheetId(spreadsheetId);
159
- const url = `${SHEETS_BASE_URL}/${id}/values/${encodeURIComponent(range)}?valueInputOption=USER_ENTERED`;
160
- const response = await fetchFn(url, {
161
- method: "PUT",
162
- headers: { "Content-Type": "application/json" },
163
- body: JSON.stringify({ range, majorDimension: "ROWS", values })
164
- });
165
- if (!response.ok) {
166
- const body = await response.text();
167
- throw new Error(
168
- `google-sheets: updateValues failed (${response.status}): ${body}`
169
- );
170
- }
171
- return await response.json();
172
- }
173
- async function appendValues(range, values, spreadsheetId) {
174
- const id = resolveSpreadsheetId(spreadsheetId);
175
- const url = `${SHEETS_BASE_URL}/${id}/values/${encodeURIComponent(range)}:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS`;
176
- const response = await fetchFn(url, {
177
- method: "POST",
178
- headers: { "Content-Type": "application/json" },
179
- body: JSON.stringify({ range, majorDimension: "ROWS", values })
180
- });
181
- if (!response.ok) {
182
- const body = await response.text();
183
- throw new Error(
184
- `google-sheets: appendValues failed (${response.status}): ${body}`
185
- );
186
- }
187
- return await response.json();
188
- }
189
- async function createSpreadsheet(title, sheetTitles) {
190
- const sheets = sheetTitles && sheetTitles.length > 0 ? sheetTitles.map((t) => ({ properties: { title: t } })) : void 0;
191
- const url = `${SHEETS_BASE_URL}`;
192
- const response = await fetchFn(url, {
193
- method: "POST",
194
- headers: { "Content-Type": "application/json" },
195
- body: JSON.stringify({
196
- properties: { title },
197
- ...sheets ? { sheets } : {}
198
- })
199
- });
200
- if (!response.ok) {
201
- const body = await response.text();
202
- throw new Error(
203
- `google-sheets: createSpreadsheet failed (${response.status}): ${body}`
204
- );
205
- }
206
- return await response.json();
207
- }
208
- return {
209
- request,
210
- getSpreadsheet,
211
- getValues,
212
- batchGetValues,
213
- updateValues,
214
- appendValues,
215
- createSpreadsheet
216
- };
217
- }
218
-
219
- // ../connectors/src/connector-onboarding.ts
220
- var ConnectorOnboarding = class {
221
- /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
222
- connectionSetupInstructions;
223
- /** Phase 2: Data overview instructions */
224
- dataOverviewInstructions;
225
- constructor(config) {
226
- this.connectionSetupInstructions = config.connectionSetupInstructions;
227
- this.dataOverviewInstructions = config.dataOverviewInstructions;
228
- }
229
- getConnectionSetupPrompt(language) {
230
- return this.connectionSetupInstructions?.[language] ?? null;
231
- }
232
- getDataOverviewInstructions(language) {
233
- return this.dataOverviewInstructions[language];
234
- }
235
- };
236
-
237
- // ../connectors/src/connector-tool.ts
238
- var ConnectorTool = class {
239
- name;
240
- description;
241
- inputSchema;
242
- outputSchema;
243
- _execute;
244
- constructor(config) {
245
- this.name = config.name;
246
- this.description = config.description;
247
- this.inputSchema = config.inputSchema;
248
- this.outputSchema = config.outputSchema;
249
- this._execute = config.execute;
250
- }
251
- createTool(connections, config) {
252
- return {
253
- description: this.description,
254
- inputSchema: this.inputSchema,
255
- outputSchema: this.outputSchema,
256
- execute: (input) => this._execute(input, connections, config)
257
- };
258
- }
259
- };
260
-
261
- // ../connectors/src/connector-plugin.ts
262
- var ConnectorPlugin = class _ConnectorPlugin {
263
- slug;
264
- authType;
265
- name;
266
- description;
267
- iconUrl;
268
- parameters;
269
- releaseFlag;
270
- proxyPolicy;
271
- experimentalAttributes;
272
- onboarding;
273
- systemPrompt;
274
- tools;
275
- query;
276
- checkConnection;
277
- constructor(config) {
278
- this.slug = config.slug;
279
- this.authType = config.authType;
280
- this.name = config.name;
281
- this.description = config.description;
282
- this.iconUrl = config.iconUrl;
283
- this.parameters = config.parameters;
284
- this.releaseFlag = config.releaseFlag;
285
- this.proxyPolicy = config.proxyPolicy;
286
- this.experimentalAttributes = config.experimentalAttributes;
287
- this.onboarding = config.onboarding;
288
- this.systemPrompt = config.systemPrompt;
289
- this.tools = config.tools;
290
- this.query = config.query;
291
- this.checkConnection = config.checkConnection;
292
- }
293
- get connectorKey() {
294
- return _ConnectorPlugin.deriveKey(this.slug, this.authType);
295
- }
296
- /**
297
- * Create tools for connections that belong to this connector.
298
- * Filters connections by connectorKey internally.
299
- * Returns tools keyed as `${connectorKey}_${toolName}`.
300
- */
301
- createTools(connections, config) {
302
- const myConnections = connections.filter(
303
- (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
304
- );
305
- const result = {};
306
- for (const t of Object.values(this.tools)) {
307
- result[`${this.connectorKey}_${t.name}`] = t.createTool(
308
- myConnections,
309
- config
310
- );
311
- }
312
- return result;
313
- }
314
- static deriveKey(slug, authType) {
315
- return authType ? `${slug}-${authType}` : slug;
316
- }
317
- };
318
-
319
- // ../connectors/src/auth-types.ts
320
- var AUTH_TYPES = {
321
- OAUTH: "oauth",
322
- API_KEY: "api-key",
323
- JWT: "jwt",
324
- SERVICE_ACCOUNT: "service-account",
325
- PAT: "pat",
326
- USER_PASSWORD: "user-password"
327
- };
328
-
329
- // ../connectors/src/connectors/google-sheets-oauth/tools/request.ts
330
- import { z } from "zod";
331
- init_utils2();
332
- var SHEETS_BASE_URL2 = "https://sheets.googleapis.com/v4/spreadsheets";
333
- var DRIVE_BASE_URL = "https://www.googleapis.com/drive/v3/files";
334
- var REQUEST_TIMEOUT_MS = 6e4;
335
- var cachedToken = null;
336
- async function getProxyToken(config) {
337
- if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
338
- return cachedToken.token;
339
- }
340
- const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
341
- const res = await fetch(url, {
342
- method: "POST",
343
- headers: {
344
- "Content-Type": "application/json",
345
- "x-api-key": config.appApiKey,
346
- "project-id": config.projectId
347
- },
348
- body: JSON.stringify({
349
- sandboxId: config.sandboxId,
350
- issuedBy: "coding-agent"
351
- })
352
- });
353
- if (!res.ok) {
354
- const errorText = await res.text().catch(() => res.statusText);
355
- throw new Error(
356
- `Failed to get proxy token: HTTP ${res.status} ${errorText}`
357
- );
358
- }
359
- const data = await res.json();
360
- cachedToken = {
361
- token: data.token,
362
- expiresAt: new Date(data.expiresAt).getTime()
363
- };
364
- return data.token;
365
- }
366
- var inputSchema = z.object({
367
- toolUseIntent: z.string().optional().describe(
368
- "Brief description of what you intend to accomplish with this tool call"
369
- ),
370
- connectionId: z.string().describe("ID of the Google Sheets OAuth connection to use"),
371
- method: z.enum(["GET", "POST", "PUT"]).describe("HTTP method"),
372
- path: z.string().describe(
373
- "API path appended to https://sheets.googleapis.com/v4/spreadsheets (e.g., '/{spreadsheetId}', '/{spreadsheetId}/values/Sheet1!A1:D10'). Use 'drive://files' prefix for Google Drive API calls (e.g., creating new spreadsheets). {spreadsheetId} is automatically replaced if a default is configured."
374
- ),
375
- body: z.record(z.string(), z.unknown()).optional().describe("JSON request body for POST/PUT requests"),
376
- queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL")
377
- });
378
- var outputSchema = z.discriminatedUnion("success", [
379
- z.object({
380
- success: z.literal(true),
381
- status: z.number(),
382
- data: z.record(z.string(), z.unknown())
383
- }),
384
- z.object({
385
- success: z.literal(false),
386
- error: z.string()
387
- })
388
- ]);
389
- var requestTool = new ConnectorTool({
390
- name: "request",
391
- description: `Send authenticated requests to the Google Sheets API v4.
392
- Supports GET (read), POST (create/append), and PUT (update) methods.
393
- Authentication is handled automatically via OAuth proxy.
394
- {spreadsheetId} in the path is automatically replaced with the connection's default spreadsheet ID if configured.`,
395
- inputSchema,
396
- outputSchema,
397
- async execute({ connectionId, method, path: path2, body, queryParams }, connections, config) {
398
- const connection2 = connections.find((c) => c.id === connectionId);
399
- if (!connection2) {
400
- return {
401
- success: false,
402
- error: `Connection ${connectionId} not found`
403
- };
404
- }
405
- console.log(
406
- `[connector-request] google-sheets-oauth/${connection2.name}: ${method} ${path2}`
407
- );
408
- try {
409
- const spreadsheetUrl = parameters.spreadsheetUrl.tryGetValue(connection2);
410
- const spreadsheetId = spreadsheetUrl ? extractSpreadsheetId(spreadsheetUrl) : void 0;
411
- let url;
412
- if (path2.startsWith("drive://")) {
413
- const drivePath = path2.slice("drive://".length);
414
- url = `${DRIVE_BASE_URL}${drivePath.startsWith("/") ? "" : "/"}${drivePath}`;
415
- } else {
416
- const resolvedPath = spreadsheetId ? path2.replace(/\{spreadsheetId\}/g, spreadsheetId) : path2;
417
- url = `${SHEETS_BASE_URL2}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
418
- }
419
- if (queryParams) {
420
- const searchParams = new URLSearchParams(queryParams);
421
- url += `?${searchParams.toString()}`;
422
- }
423
- const token = await getProxyToken(config.oauthProxy);
424
- const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
425
- const controller = new AbortController();
426
- const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
427
- try {
428
- const response = await fetch(proxyUrl, {
429
- method: "POST",
430
- headers: {
431
- "Content-Type": "application/json",
432
- Authorization: `Bearer ${token}`
433
- },
434
- body: JSON.stringify({
435
- url,
436
- method,
437
- ...body != null ? { body: JSON.stringify(body) } : {}
438
- }),
439
- signal: controller.signal
440
- });
441
- const data = await response.json();
442
- if (!response.ok) {
443
- const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
444
- return { success: false, error: errorMessage };
445
- }
446
- return { success: true, status: response.status, data };
447
- } finally {
448
- clearTimeout(timeout);
449
- }
450
- } catch (err) {
451
- const msg = err instanceof Error ? err.message : String(err);
452
- return { success: false, error: msg };
453
- }
454
- }
455
- });
456
-
457
- // ../connectors/src/connectors/google-sheets-oauth/setup.ts
458
- var requestToolName = `google-sheets-oauth_${requestTool.name}`;
459
- var googleSheetsOnboarding = new ConnectorOnboarding({
460
- connectionSetupInstructions: {
461
- 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
462
-
463
- 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:
464
- - \`method\`: \`"GET"\`
465
- - \`path\`: \`"/{spreadsheetId}?fields=spreadsheetId,properties.title,sheets.properties.title"\`
466
- 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
467
- 3. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
468
- - \`spreadsheet\`: \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30BF\u30A4\u30C8\u30EB
469
- - \`sheets\`: \u30B7\u30FC\u30C8\u540D\u4E00\u89A7\uFF08\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
470
- - \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
471
-
472
- #### \u5236\u7D04
473
- - **\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
474
- - \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
475
- - \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`,
476
- 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.
477
-
478
- 1. Call \`${requestToolName}\` to fetch spreadsheet metadata:
479
- - \`method\`: \`"GET"\`
480
- - \`path\`: \`"/{spreadsheetId}?fields=spreadsheetId,properties.title,sheets.properties.title"\`
481
- 2. If an error is returned, ask the user to check the spreadsheet sharing settings
482
- 3. Call \`updateConnectionContext\`:
483
- - \`spreadsheet\`: The spreadsheet title
484
- - \`sheets\`: Sheet names (comma-separated)
485
- - \`note\`: Brief description of the setup
486
-
487
- #### Constraints
488
- - **Do NOT read sheet data during setup**. Only the metadata request specified in the steps above is allowed
489
- - Do NOT ask the user for the spreadsheet URL \u2014 it is already stored as a connection parameter
490
- - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
491
- },
492
- dataOverviewInstructions: {
493
- en: `1. Call google-sheets-oauth_request with GET /{spreadsheetId} to get spreadsheet metadata (sheet names and properties)
494
- 2. Call google-sheets-oauth_request with GET /{spreadsheetId}/values/{sheetName}!A1:Z5 to sample data from key sheets`,
495
- ja: `1. google-sheets-oauth_request \u3067 GET /{spreadsheetId} \u3092\u547C\u3073\u51FA\u3057\u3001\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\uFF08\u30B7\u30FC\u30C8\u540D\u3068\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09\u3092\u53D6\u5F97
496
- 2. google-sheets-oauth_request \u3067 GET /{spreadsheetId}/values/{sheetName}!A1:Z5 \u3092\u547C\u3073\u51FA\u3057\u3001\u4E3B\u8981\u30B7\u30FC\u30C8\u306E\u30C7\u30FC\u30BF\u3092\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0`
497
- }
498
- });
499
-
500
- // ../connectors/src/connectors/google-sheets-oauth/index.ts
501
- var tools = { request: requestTool };
502
- var googleSheetsOauthConnector = new ConnectorPlugin({
503
- slug: "google-sheets",
504
- authType: AUTH_TYPES.OAUTH,
505
- name: "Google Sheets",
506
- description: "Connect to Google Sheets for spreadsheet data access and creation using OAuth.",
507
- iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/1UPQuggyiZmbb26CuaSr2h/032770e8739b183fa00b7625f024e536/google-sheets.svg",
508
- parameters,
509
- releaseFlag: { dev1: true, dev2: false, prod: false },
510
- onboarding: googleSheetsOnboarding,
511
- proxyPolicy: {
512
- allowlist: [
513
- {
514
- host: "sheets.googleapis.com",
515
- methods: ["GET", "POST", "PUT"]
516
- },
517
- {
518
- host: "www.googleapis.com",
519
- methods: ["POST"],
520
- pathPrefix: "/drive/v3/files"
521
- }
522
- ]
523
- },
524
- systemPrompt: {
525
- en: `### Tools
526
-
527
- - \`google-sheets-oauth_request\`: The way to call the Google Sheets API. Supports read and write operations. Use it to get/update spreadsheet metadata, cell values, create new spreadsheets, and more. Authentication is configured automatically via OAuth. The {spreadsheetId} placeholder in paths is automatically replaced with the configured default spreadsheet ID.
528
-
529
- ### Google Sheets API Reference
530
-
531
- #### Read Endpoints
532
- - GET \`/{spreadsheetId}\` \u2014 Get spreadsheet metadata (title, sheets, properties)
533
- - GET \`/{spreadsheetId}/values/{range}\` \u2014 Get cell values for a range
534
- - GET \`/{spreadsheetId}/values:batchGet?ranges={range1}&ranges={range2}\` \u2014 Get values for multiple ranges
535
-
536
- #### Write Endpoints
537
- - POST \`\` (empty path, with body) \u2014 Create a new spreadsheet. Body: \`{ "properties": { "title": "My Sheet" }, "sheets": [{ "properties": { "title": "Sheet1" } }] }\`
538
- - PUT \`/{spreadsheetId}/values/{range}?valueInputOption=USER_ENTERED\` \u2014 Update cell values for a range. Body: \`{ "range": "Sheet1!A1:B2", "majorDimension": "ROWS", "values": [["a","b"],["c","d"]] }\`
539
- - POST \`/{spreadsheetId}/values/{range}:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS\` \u2014 Append rows after the last row. Body: \`{ "range": "Sheet1!A1", "majorDimension": "ROWS", "values": [["a","b"]] }\`
540
- - POST \`/{spreadsheetId}:batchUpdate\` \u2014 Apply multiple updates (formatting, add sheets, merge cells, etc.). Body: \`{ "requests": [...] }\`
541
-
542
- ### Range Notation (A1 notation)
543
- - \`Sheet1!A1:D10\` \u2014 Specific range on Sheet1
544
- - \`Sheet1!A:A\` \u2014 Entire column A on Sheet1
545
- - \`Sheet1!1:3\` \u2014 Rows 1 to 3 on Sheet1
546
- - \`Sheet1\` \u2014 All data on Sheet1
547
- - \`A1:D10\` \u2014 Range on the first sheet (when only one sheet exists)
548
-
549
- ### Tips
550
- - Use \`{spreadsheetId}\` placeholder in paths \u2014 it is automatically replaced with the configured default spreadsheet ID
551
- - To explore a spreadsheet, first get metadata to see available sheet names
552
- - Use \`valueRenderOption=FORMATTED_VALUE\` query param to get display values
553
- - Use \`valueRenderOption=UNFORMATTED_VALUE\` for raw numeric values
554
- - Use \`majorDimension=COLUMNS\` to get data organized by columns instead of rows
555
- - For write operations, always use \`valueInputOption=USER_ENTERED\` so values are parsed as if typed by a user (dates, numbers, formulas are auto-detected)
556
-
557
- ### Business Logic
558
-
559
- The business logic type for this connector is "typescript". Write handler code using the connector SDK shown below. Do NOT access credentials directly from environment variables.
560
-
561
- #### Example
562
-
563
- \`\`\`ts
564
- import { connection } from "@squadbase/vite-server/connectors/google-sheets-oauth";
565
-
566
- const sheets = connection("<connectionId>");
567
-
568
- // Get spreadsheet metadata
569
- const metadata = await sheets.getSpreadsheet();
570
- console.log(metadata.properties.title, metadata.sheets.map(s => s.properties.title));
571
-
572
- // Get cell values
573
- const values = await sheets.getValues("Sheet1!A1:D10");
574
- console.log(values.values); // 2D array
575
-
576
- // Get multiple ranges at once
577
- const batch = await sheets.batchGetValues(["Sheet1!A1:B5", "Sheet2!A1:C3"]);
578
- batch.valueRanges.forEach(vr => console.log(vr.range, vr.values));
579
-
580
- // Update cell values
581
- await sheets.updateValues("Sheet1!A1:B2", [["Name", "Score"], ["Alice", "100"]]);
582
-
583
- // Append rows
584
- await sheets.appendValues("Sheet1!A1", [["Bob", "95"], ["Charlie", "88"]]);
585
-
586
- // Create a new spreadsheet
587
- const newSheet = await sheets.createSpreadsheet("Sales Report", ["Q1", "Q2", "Q3", "Q4"]);
588
- console.log(newSheet.spreadsheetId, newSheet.spreadsheetUrl);
589
- \`\`\``,
590
- ja: `### \u30C4\u30FC\u30EB
591
-
592
- - \`google-sheets-oauth_request\`: Google Sheets API\u3092\u547C\u3073\u51FA\u3059\u624B\u6BB5\u3067\u3059\u3002\u8AAD\u307F\u53D6\u308A\u3068\u66F8\u304D\u8FBC\u307F\u306E\u4E21\u65B9\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u307E\u3059\u3002\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u30FB\u30BB\u30EB\u5024\u306E\u53D6\u5F97/\u66F4\u65B0\u3001\u65B0\u3057\u3044\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u4F5C\u6210\u306A\u3069\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{spreadsheetId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002
593
-
594
- ### Google Sheets API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
595
-
596
- #### \u8AAD\u307F\u53D6\u308A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
597
- - GET \`/{spreadsheetId}\` \u2014 \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\uFF08\u30BF\u30A4\u30C8\u30EB\u3001\u30B7\u30FC\u30C8\u3001\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09
598
- - GET \`/{spreadsheetId}/values/{range}\` \u2014 \u7BC4\u56F2\u306E\u30BB\u30EB\u5024\u3092\u53D6\u5F97
599
- - GET \`/{spreadsheetId}/values:batchGet?ranges={range1}&ranges={range2}\` \u2014 \u8907\u6570\u7BC4\u56F2\u306E\u5024\u3092\u53D6\u5F97
600
-
601
- #### \u66F8\u304D\u8FBC\u307F\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
602
- - POST \`\`\uFF08\u7A7A\u30D1\u30B9\u3001\u30DC\u30C7\u30A3\u4ED8\u304D\uFF09\u2014 \u65B0\u3057\u3044\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u3092\u4F5C\u6210\u3002Body: \`{ "properties": { "title": "\u30DE\u30A4\u30B7\u30FC\u30C8" }, "sheets": [{ "properties": { "title": "Sheet1" } }] }\`
603
- - PUT \`/{spreadsheetId}/values/{range}?valueInputOption=USER_ENTERED\` \u2014 \u7BC4\u56F2\u306E\u30BB\u30EB\u5024\u3092\u66F4\u65B0\u3002Body: \`{ "range": "Sheet1!A1:B2", "majorDimension": "ROWS", "values": [["a","b"],["c","d"]] }\`
604
- - POST \`/{spreadsheetId}/values/{range}:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS\` \u2014 \u6700\u7D42\u884C\u306E\u5F8C\u306B\u884C\u3092\u8FFD\u52A0\u3002Body: \`{ "range": "Sheet1!A1", "majorDimension": "ROWS", "values": [["a","b"]] }\`
605
- - POST \`/{spreadsheetId}:batchUpdate\` \u2014 \u8907\u6570\u306E\u66F4\u65B0\u3092\u9069\u7528\uFF08\u66F8\u5F0F\u8A2D\u5B9A\u3001\u30B7\u30FC\u30C8\u8FFD\u52A0\u3001\u30BB\u30EB\u7D50\u5408\u306A\u3069\uFF09\u3002Body: \`{ "requests": [...] }\`
606
-
607
- ### \u7BC4\u56F2\u306E\u8868\u8A18\u6CD5\uFF08A1\u8868\u8A18\u6CD5\uFF09
608
- - \`Sheet1!A1:D10\` \u2014 Sheet1\u4E0A\u306E\u7279\u5B9A\u7BC4\u56F2
609
- - \`Sheet1!A:A\` \u2014 Sheet1\u306EA\u5217\u5168\u4F53
610
- - \`Sheet1!1:3\` \u2014 Sheet1\u306E1\u884C\u76EE\u304B\u30893\u884C\u76EE
611
- - \`Sheet1\` \u2014 Sheet1\u306E\u5168\u30C7\u30FC\u30BF
612
- - \`A1:D10\` \u2014 \u6700\u521D\u306E\u30B7\u30FC\u30C8\u306E\u7BC4\u56F2\uFF08\u30B7\u30FC\u30C8\u304C1\u3064\u306E\u307F\u306E\u5834\u5408\uFF09
613
-
614
- ### \u30D2\u30F3\u30C8
615
- - \u30D1\u30B9\u306B \`{spreadsheetId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u3092\u4F7F\u7528 \u2014 \u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059
616
- - \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u3092\u63A2\u7D22\u3059\u308B\u306B\u306F\u3001\u307E\u305A\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u3066\u5229\u7528\u53EF\u80FD\u306A\u30B7\u30FC\u30C8\u540D\u3092\u78BA\u8A8D\u3057\u307E\u3059
617
- - \u8868\u793A\u5024\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`valueRenderOption=FORMATTED_VALUE\` \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u4F7F\u7528\u3057\u307E\u3059
618
- - \u751F\u306E\u6570\u5024\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`valueRenderOption=UNFORMATTED_VALUE\` \u3092\u4F7F\u7528\u3057\u307E\u3059
619
- - \u5217\u3054\u3068\u306B\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`majorDimension=COLUMNS\` \u3092\u4F7F\u7528\u3057\u307E\u3059
620
- - \u66F8\u304D\u8FBC\u307F\u64CD\u4F5C\u3067\u306F\u5E38\u306B \`valueInputOption=USER_ENTERED\` \u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u5024\u304C\u30E6\u30FC\u30B6\u30FC\u5165\u529B\u306E\u3088\u3046\u306B\u89E3\u6790\u3055\u308C\u307E\u3059\uFF08\u65E5\u4ED8\u3001\u6570\u5024\u3001\u6570\u5F0F\u304C\u81EA\u52D5\u691C\u51FA\uFF09
621
-
622
- ### Business Logic
623
-
624
- \u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u4EE5\u4E0B\u306B\u793A\u3059\u30B3\u30CD\u30AF\u30BFSDK\u3092\u4F7F\u7528\u3057\u3066\u30CF\u30F3\u30C9\u30E9\u30B3\u30FC\u30C9\u3092\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u76F4\u63A5\u8A8D\u8A3C\u60C5\u5831\u306B\u30A2\u30AF\u30BB\u30B9\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
625
-
626
- #### Example
627
-
628
- \`\`\`ts
629
- import { connection } from "@squadbase/vite-server/connectors/google-sheets-oauth";
630
-
631
- const sheets = connection("<connectionId>");
632
-
633
- // \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97
634
- const metadata = await sheets.getSpreadsheet();
635
- console.log(metadata.properties.title, metadata.sheets.map(s => s.properties.title));
636
-
637
- // \u30BB\u30EB\u5024\u3092\u53D6\u5F97
638
- const values = await sheets.getValues("Sheet1!A1:D10");
639
- console.log(values.values); // 2D array
640
-
641
- // \u8907\u6570\u7BC4\u56F2\u306E\u5024\u3092\u4E00\u5EA6\u306B\u53D6\u5F97
642
- const batch = await sheets.batchGetValues(["Sheet1!A1:B5", "Sheet2!A1:C3"]);
643
- batch.valueRanges.forEach(vr => console.log(vr.range, vr.values));
644
-
645
- // \u30BB\u30EB\u5024\u3092\u66F4\u65B0
646
- await sheets.updateValues("Sheet1!A1:B2", [["\u540D\u524D", "\u30B9\u30B3\u30A2"], ["Alice", "100"]]);
647
-
648
- // \u884C\u3092\u8FFD\u52A0
649
- await sheets.appendValues("Sheet1!A1", [["Bob", "95"], ["Charlie", "88"]]);
650
-
651
- // \u65B0\u3057\u3044\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u3092\u4F5C\u6210
652
- const newSheet = await sheets.createSpreadsheet("\u58F2\u4E0A\u30EC\u30DD\u30FC\u30C8", ["Q1", "Q2", "Q3", "Q4"]);
653
- console.log(newSheet.spreadsheetId, newSheet.spreadsheetUrl);
654
- \`\`\``
655
- },
656
- tools,
657
- async checkConnection(params, config) {
658
- const { proxyFetch } = config;
659
- const spreadsheetUrl = params[parameters.spreadsheetUrl.slug];
660
- if (!spreadsheetUrl) {
661
- return { success: true };
662
- }
663
- const { extractSpreadsheetId: extractSpreadsheetId2 } = await Promise.resolve().then(() => (init_utils2(), utils_exports));
664
- const spreadsheetId = extractSpreadsheetId2(spreadsheetUrl);
665
- const url = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}?fields=spreadsheetId,properties.title`;
666
- try {
667
- const res = await proxyFetch(url, { method: "GET" });
668
- if (!res.ok) {
669
- const errorText = await res.text().catch(() => res.statusText);
670
- return {
671
- success: false,
672
- error: `Google Sheets API failed: HTTP ${res.status} ${errorText}`
673
- };
674
- }
675
- return { success: true };
676
- } catch (error) {
677
- return {
678
- success: false,
679
- error: error instanceof Error ? error.message : String(error)
680
- };
681
- }
682
- }
683
- });
684
-
685
- // src/connectors/create-connector-sdk.ts
686
- import { readFileSync } from "fs";
687
- import path from "path";
688
-
689
- // src/connector-client/env.ts
690
- function resolveEnvVar(entry, key, connectionId) {
691
- const envVarName = entry.envVars[key];
692
- if (!envVarName) {
693
- throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
694
- }
695
- const value = process.env[envVarName];
696
- if (!value) {
697
- throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
698
- }
699
- return value;
700
- }
701
- function resolveEnvVarOptional(entry, key) {
702
- const envVarName = entry.envVars[key];
703
- if (!envVarName) return void 0;
704
- return process.env[envVarName] || void 0;
705
- }
706
-
707
- // src/connector-client/proxy-fetch.ts
708
- import { getContext } from "hono/context-storage";
709
- import { getCookie } from "hono/cookie";
710
- var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
711
- function createSandboxProxyFetch(connectionId) {
712
- return async (input, init) => {
713
- const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
714
- const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
715
- if (!token || !sandboxId) {
716
- throw new Error(
717
- "Connection proxy is not configured. Please check your deployment settings."
718
- );
719
- }
720
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
721
- const originalMethod = init?.method ?? "GET";
722
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
723
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
724
- const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
725
- return fetch(proxyUrl, {
726
- method: "POST",
727
- headers: {
728
- "Content-Type": "application/json",
729
- Authorization: `Bearer ${token}`
730
- },
731
- body: JSON.stringify({
732
- url: originalUrl,
733
- method: originalMethod,
734
- body: originalBody
735
- })
736
- });
737
- };
738
- }
739
- function createDeployedAppProxyFetch(connectionId) {
740
- const projectId = process.env["SQUADBASE_PROJECT_ID"];
741
- if (!projectId) {
742
- throw new Error(
743
- "Connection proxy is not configured. Please check your deployment settings."
744
- );
745
- }
746
- const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
747
- const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
748
- return async (input, init) => {
749
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
750
- const originalMethod = init?.method ?? "GET";
751
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
752
- const c = getContext();
753
- const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
754
- if (!appSession) {
755
- throw new Error(
756
- "No authentication method available for connection proxy."
757
- );
758
- }
759
- return fetch(proxyUrl, {
760
- method: "POST",
761
- headers: {
762
- "Content-Type": "application/json",
763
- Authorization: `Bearer ${appSession}`
764
- },
765
- body: JSON.stringify({
766
- url: originalUrl,
767
- method: originalMethod,
768
- body: originalBody
769
- })
770
- });
771
- };
772
- }
773
- function createProxyFetch(connectionId) {
774
- if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
775
- return createSandboxProxyFetch(connectionId);
776
- }
777
- return createDeployedAppProxyFetch(connectionId);
778
- }
779
-
780
- // src/connectors/create-connector-sdk.ts
781
- function loadConnectionsSync() {
782
- const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
783
- try {
784
- const raw = readFileSync(filePath, "utf-8");
785
- return JSON.parse(raw);
786
- } catch {
787
- return {};
788
- }
789
- }
790
- function createConnectorSdk(plugin, createClient2) {
791
- return (connectionId) => {
792
- const connections = loadConnectionsSync();
793
- const entry = connections[connectionId];
794
- if (!entry) {
795
- throw new Error(
796
- `Connection "${connectionId}" not found in .squadbase/connections.json`
797
- );
798
- }
799
- if (entry.connector.slug !== plugin.slug) {
800
- throw new Error(
801
- `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
802
- );
803
- }
804
- const params = {};
805
- for (const param of Object.values(plugin.parameters)) {
806
- if (param.required) {
807
- params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
808
- } else {
809
- const val = resolveEnvVarOptional(entry, param.slug);
810
- if (val !== void 0) params[param.slug] = val;
811
- }
812
- }
813
- return createClient2(params, createProxyFetch(connectionId));
814
- };
815
- }
816
-
817
- // src/connectors/entries/google-sheets-oauth.ts
818
- var connection = createConnectorSdk(googleSheetsOauthConnector, createClient);
819
- export {
820
- connection
821
- };