@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,879 +0,0 @@
1
- // ../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;
42
- }
43
- };
44
-
45
- // ../connectors/src/connectors/google-drive-oauth/utils.ts
46
- var FOLDER_URL_PATTERN = /drive\.google\.com\/drive\/folders\/([a-zA-Z0-9_-]+)/;
47
- function extractFolderId(urlOrId) {
48
- const trimmed = urlOrId.trim();
49
- const match = trimmed.match(FOLDER_URL_PATTERN);
50
- if (match) {
51
- return match[1];
52
- }
53
- return trimmed;
54
- }
55
-
56
- // ../connectors/src/connectors/google-drive-oauth/parameters.ts
57
- var parameters = {
58
- folderId: new ParameterDefinition({
59
- slug: "folder-id",
60
- name: "Google Drive Folder ID",
61
- description: "The ID of a default Google Drive folder to scope operations to (e.g., from the folder URL: https://drive.google.com/drive/folders/{folderId}). Optional \u2014 if not set, operations target the root of My Drive.",
62
- envVarBaseKey: "GOOGLE_DRIVE_OAUTH_FOLDER_ID",
63
- type: "text",
64
- secret: false,
65
- required: false
66
- })
67
- };
68
-
69
- // ../connectors/src/connectors/google-drive-oauth/sdk/index.ts
70
- var BASE_URL = "https://www.googleapis.com/drive/v3";
71
- var DEFAULT_FILE_FIELDS = "id,name,mimeType,parents,webViewLink,webContentLink,createdTime,modifiedTime,size,starred,trashed,shared,owners";
72
- function createClient(params, fetchFn = fetch) {
73
- const folderIdRaw = params[parameters.folderId.slug];
74
- const defaultFolderId = folderIdRaw ? extractFolderId(folderIdRaw) : void 0;
75
- function request(path2, init) {
76
- const url = `${BASE_URL}${path2.startsWith("/") ? "" : "/"}${path2}`;
77
- return fetchFn(url, init);
78
- }
79
- async function listFiles(options) {
80
- const searchParams = new URLSearchParams();
81
- let query = options?.query ?? "";
82
- if (defaultFolderId && !query.includes("in parents")) {
83
- const folderClause = `'${defaultFolderId}' in parents`;
84
- query = query ? `${folderClause} and (${query})` : folderClause;
85
- }
86
- if (query) searchParams.set("q", query);
87
- if (options?.pageSize) searchParams.set("pageSize", String(options.pageSize));
88
- if (options?.pageToken) searchParams.set("pageToken", options.pageToken);
89
- if (options?.orderBy) searchParams.set("orderBy", options.orderBy);
90
- searchParams.set("fields", options?.fields ?? `nextPageToken,files(${DEFAULT_FILE_FIELDS})`);
91
- const url = `${BASE_URL}/files?${searchParams.toString()}`;
92
- const response = await fetchFn(url);
93
- if (!response.ok) {
94
- const body = await response.text();
95
- throw new Error(
96
- `google-drive: listFiles failed (${response.status}): ${body}`
97
- );
98
- }
99
- return await response.json();
100
- }
101
- async function getFile(fileId, fields) {
102
- const url = `${BASE_URL}/files/${fileId}?fields=${fields ?? DEFAULT_FILE_FIELDS}`;
103
- const response = await fetchFn(url);
104
- if (!response.ok) {
105
- const body = await response.text();
106
- throw new Error(
107
- `google-drive: getFile failed (${response.status}): ${body}`
108
- );
109
- }
110
- return await response.json();
111
- }
112
- async function createFile(options) {
113
- const metadata = { name: options.name };
114
- if (options.mimeType) metadata.mimeType = options.mimeType;
115
- if (options.description) metadata.description = options.description;
116
- if (options.parents) {
117
- metadata.parents = options.parents;
118
- } else if (defaultFolderId) {
119
- metadata.parents = [defaultFolderId];
120
- }
121
- const url = `${BASE_URL}/files?fields=${DEFAULT_FILE_FIELDS}`;
122
- const response = await fetchFn(url, {
123
- method: "POST",
124
- headers: { "Content-Type": "application/json" },
125
- body: JSON.stringify(metadata)
126
- });
127
- if (!response.ok) {
128
- const body = await response.text();
129
- throw new Error(
130
- `google-drive: createFile failed (${response.status}): ${body}`
131
- );
132
- }
133
- return await response.json();
134
- }
135
- async function updateFile(fileId, metadata, addParents, removeParents) {
136
- const searchParams = new URLSearchParams();
137
- searchParams.set("fields", DEFAULT_FILE_FIELDS);
138
- if (addParents) searchParams.set("addParents", addParents);
139
- if (removeParents) searchParams.set("removeParents", removeParents);
140
- const url = `${BASE_URL}/files/${fileId}?${searchParams.toString()}`;
141
- const response = await fetchFn(url, {
142
- method: "PATCH",
143
- headers: { "Content-Type": "application/json" },
144
- body: JSON.stringify(metadata)
145
- });
146
- if (!response.ok) {
147
- const body = await response.text();
148
- throw new Error(
149
- `google-drive: updateFile failed (${response.status}): ${body}`
150
- );
151
- }
152
- return await response.json();
153
- }
154
- async function copyFile(fileId, name, parents) {
155
- const metadata = {};
156
- if (name) metadata.name = name;
157
- if (parents) metadata.parents = parents;
158
- const url = `${BASE_URL}/files/${fileId}/copy?fields=${DEFAULT_FILE_FIELDS}`;
159
- const response = await fetchFn(url, {
160
- method: "POST",
161
- headers: { "Content-Type": "application/json" },
162
- body: JSON.stringify(metadata)
163
- });
164
- if (!response.ok) {
165
- const body = await response.text();
166
- throw new Error(
167
- `google-drive: copyFile failed (${response.status}): ${body}`
168
- );
169
- }
170
- return await response.json();
171
- }
172
- async function listPermissions(fileId) {
173
- const url = `${BASE_URL}/files/${fileId}/permissions?fields=permissions(id,type,role,emailAddress,displayName)`;
174
- const response = await fetchFn(url);
175
- if (!response.ok) {
176
- const body = await response.text();
177
- throw new Error(
178
- `google-drive: listPermissions failed (${response.status}): ${body}`
179
- );
180
- }
181
- return await response.json();
182
- }
183
- async function shareFile(fileId, type, role, emailAddress) {
184
- const permission = { type, role };
185
- if (emailAddress) permission.emailAddress = emailAddress;
186
- const url = `${BASE_URL}/files/${fileId}/permissions`;
187
- const response = await fetchFn(url, {
188
- method: "POST",
189
- headers: { "Content-Type": "application/json" },
190
- body: JSON.stringify(permission)
191
- });
192
- if (!response.ok) {
193
- const body = await response.text();
194
- throw new Error(
195
- `google-drive: shareFile failed (${response.status}): ${body}`
196
- );
197
- }
198
- return await response.json();
199
- }
200
- function downloadFile(fileId) {
201
- const url = `${BASE_URL}/files/${fileId}?alt=media`;
202
- return fetchFn(url);
203
- }
204
- function exportFile(fileId, mimeType) {
205
- const url = `${BASE_URL}/files/${fileId}/export?mimeType=${encodeURIComponent(mimeType)}`;
206
- return fetchFn(url);
207
- }
208
- return {
209
- request,
210
- listFiles,
211
- getFile,
212
- createFile,
213
- updateFile,
214
- copyFile,
215
- listPermissions,
216
- shareFile,
217
- downloadFile,
218
- exportFile
219
- };
220
- }
221
-
222
- // ../connectors/src/connector-onboarding.ts
223
- var ConnectorOnboarding = class {
224
- /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
225
- connectionSetupInstructions;
226
- /** Phase 2: Data overview instructions */
227
- dataOverviewInstructions;
228
- constructor(config) {
229
- this.connectionSetupInstructions = config.connectionSetupInstructions;
230
- this.dataOverviewInstructions = config.dataOverviewInstructions;
231
- }
232
- getConnectionSetupPrompt(language) {
233
- return this.connectionSetupInstructions?.[language] ?? null;
234
- }
235
- getDataOverviewInstructions(language) {
236
- return this.dataOverviewInstructions[language];
237
- }
238
- };
239
-
240
- // ../connectors/src/connector-tool.ts
241
- var ConnectorTool = class {
242
- name;
243
- description;
244
- inputSchema;
245
- outputSchema;
246
- _execute;
247
- constructor(config) {
248
- this.name = config.name;
249
- this.description = config.description;
250
- this.inputSchema = config.inputSchema;
251
- this.outputSchema = config.outputSchema;
252
- this._execute = config.execute;
253
- }
254
- createTool(connections, config) {
255
- return {
256
- description: this.description,
257
- inputSchema: this.inputSchema,
258
- outputSchema: this.outputSchema,
259
- execute: (input) => this._execute(input, connections, config)
260
- };
261
- }
262
- };
263
-
264
- // ../connectors/src/connector-plugin.ts
265
- var ConnectorPlugin = class _ConnectorPlugin {
266
- slug;
267
- authType;
268
- name;
269
- description;
270
- iconUrl;
271
- parameters;
272
- releaseFlag;
273
- proxyPolicy;
274
- experimentalAttributes;
275
- onboarding;
276
- systemPrompt;
277
- tools;
278
- query;
279
- checkConnection;
280
- constructor(config) {
281
- this.slug = config.slug;
282
- this.authType = config.authType;
283
- this.name = config.name;
284
- this.description = config.description;
285
- this.iconUrl = config.iconUrl;
286
- this.parameters = config.parameters;
287
- this.releaseFlag = config.releaseFlag;
288
- this.proxyPolicy = config.proxyPolicy;
289
- this.experimentalAttributes = config.experimentalAttributes;
290
- this.onboarding = config.onboarding;
291
- this.systemPrompt = config.systemPrompt;
292
- this.tools = config.tools;
293
- this.query = config.query;
294
- this.checkConnection = config.checkConnection;
295
- }
296
- get connectorKey() {
297
- return _ConnectorPlugin.deriveKey(this.slug, this.authType);
298
- }
299
- /**
300
- * Create tools for connections that belong to this connector.
301
- * Filters connections by connectorKey internally.
302
- * Returns tools keyed as `${connectorKey}_${toolName}`.
303
- */
304
- createTools(connections, config) {
305
- const myConnections = connections.filter(
306
- (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
307
- );
308
- const result = {};
309
- for (const t of Object.values(this.tools)) {
310
- result[`${this.connectorKey}_${t.name}`] = t.createTool(
311
- myConnections,
312
- config
313
- );
314
- }
315
- return result;
316
- }
317
- static deriveKey(slug, authType) {
318
- return authType ? `${slug}-${authType}` : slug;
319
- }
320
- };
321
-
322
- // ../connectors/src/auth-types.ts
323
- var AUTH_TYPES = {
324
- OAUTH: "oauth",
325
- API_KEY: "api-key",
326
- JWT: "jwt",
327
- SERVICE_ACCOUNT: "service-account",
328
- PAT: "pat",
329
- USER_PASSWORD: "user-password"
330
- };
331
-
332
- // ../connectors/src/connectors/google-drive-oauth/setup.ts
333
- var googleDriveOnboarding = new ConnectorOnboarding({
334
- dataOverviewInstructions: {
335
- en: `1. Call google-drive-oauth_request with GET /files?pageSize=20&fields=files(id,name,mimeType,modifiedTime)&orderBy=modifiedTime desc to list recent files
336
- 2. Call google-drive-oauth_request with GET /about?fields=user,storageQuota to get account info and storage usage`,
337
- ja: `1. google-drive-oauth_request \u3067 GET /files?pageSize=20&fields=files(id,name,mimeType,modifiedTime)&orderBy=modifiedTime desc \u3092\u547C\u3073\u51FA\u3057\u3001\u6700\u8FD1\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u8868\u793A
338
- 2. google-drive-oauth_request \u3067 GET /about?fields=user,storageQuota \u3092\u547C\u3073\u51FA\u3057\u3001\u30A2\u30AB\u30A6\u30F3\u30C8\u60C5\u5831\u3068\u30B9\u30C8\u30EC\u30FC\u30B8\u4F7F\u7528\u91CF\u3092\u53D6\u5F97`
339
- }
340
- });
341
-
342
- // ../connectors/src/connectors/google-drive-oauth/tools/request.ts
343
- import { z } from "zod";
344
- var BASE_URL2 = "https://www.googleapis.com/drive/v3";
345
- var REQUEST_TIMEOUT_MS = 6e4;
346
- var cachedToken = null;
347
- async function getProxyToken(config) {
348
- if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
349
- return cachedToken.token;
350
- }
351
- const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
352
- const res = await fetch(url, {
353
- method: "POST",
354
- headers: {
355
- "Content-Type": "application/json",
356
- "x-api-key": config.appApiKey,
357
- "project-id": config.projectId
358
- },
359
- body: JSON.stringify({
360
- sandboxId: config.sandboxId,
361
- issuedBy: "coding-agent"
362
- })
363
- });
364
- if (!res.ok) {
365
- const errorText = await res.text().catch(() => res.statusText);
366
- throw new Error(
367
- `Failed to get proxy token: HTTP ${res.status} ${errorText}`
368
- );
369
- }
370
- const data = await res.json();
371
- cachedToken = {
372
- token: data.token,
373
- expiresAt: new Date(data.expiresAt).getTime()
374
- };
375
- return data.token;
376
- }
377
- var inputSchema = z.object({
378
- toolUseIntent: z.string().optional().describe(
379
- "Brief description of what you intend to accomplish with this tool call"
380
- ),
381
- connectionId: z.string().describe("ID of the Google Drive OAuth connection to use"),
382
- method: z.enum(["GET", "POST", "PATCH"]).describe("HTTP method"),
383
- path: z.string().describe(
384
- "API path appended to https://www.googleapis.com/drive/v3 (e.g., '/files', '/files/{fileId}', '/files/{fileId}/permissions')."
385
- ),
386
- body: z.record(z.string(), z.unknown()).optional().describe("JSON request body for POST/PATCH requests"),
387
- queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL")
388
- });
389
- var outputSchema = z.discriminatedUnion("success", [
390
- z.object({
391
- success: z.literal(true),
392
- status: z.number(),
393
- data: z.record(z.string(), z.unknown())
394
- }),
395
- z.object({
396
- success: z.literal(false),
397
- error: z.string()
398
- })
399
- ]);
400
- var requestTool = new ConnectorTool({
401
- name: "request",
402
- description: `Send authenticated requests to the Google Drive API v3.
403
- Supports GET (read/list/download), POST (create/copy), and PATCH (update) methods.
404
- Authentication is handled automatically via OAuth proxy.`,
405
- inputSchema,
406
- outputSchema,
407
- async execute({ connectionId, method, path: path2, body, queryParams }, connections, config) {
408
- const connection2 = connections.find((c) => c.id === connectionId);
409
- if (!connection2) {
410
- return {
411
- success: false,
412
- error: `Connection ${connectionId} not found`
413
- };
414
- }
415
- console.log(
416
- `[connector-request] google-drive-oauth/${connection2.name}: ${method} ${path2}`
417
- );
418
- try {
419
- let url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
420
- if (queryParams) {
421
- const searchParams = new URLSearchParams(queryParams);
422
- url += `?${searchParams.toString()}`;
423
- }
424
- const token = await getProxyToken(config.oauthProxy);
425
- const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
426
- const controller = new AbortController();
427
- const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
428
- try {
429
- const response = await fetch(proxyUrl, {
430
- method: "POST",
431
- headers: {
432
- "Content-Type": "application/json",
433
- Authorization: `Bearer ${token}`
434
- },
435
- body: JSON.stringify({
436
- url,
437
- method,
438
- ...body != null ? { body: JSON.stringify(body) } : {}
439
- }),
440
- signal: controller.signal
441
- });
442
- const data = await response.json();
443
- if (!response.ok) {
444
- const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
445
- return { success: false, error: errorMessage };
446
- }
447
- return { success: true, status: response.status, data };
448
- } finally {
449
- clearTimeout(timeout);
450
- }
451
- } catch (err) {
452
- const msg = err instanceof Error ? err.message : String(err);
453
- return { success: false, error: msg };
454
- }
455
- }
456
- });
457
-
458
- // ../connectors/src/connectors/google-drive-oauth/index.ts
459
- var tools = { request: requestTool };
460
- var googleDriveOauthConnector = new ConnectorPlugin({
461
- slug: "google-drive",
462
- authType: AUTH_TYPES.OAUTH,
463
- name: "Google Drive",
464
- description: "Connect to Google Drive for file management, sharing, and collaboration using OAuth.",
465
- iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/4GJX5yQTogUgar1buWxXbv/4b43a65353319c508111489f834d22c4/google_drive.png",
466
- parameters,
467
- releaseFlag: { dev1: true, dev2: false, prod: false },
468
- onboarding: googleDriveOnboarding,
469
- proxyPolicy: {
470
- allowlist: [
471
- {
472
- host: "www.googleapis.com",
473
- pathPrefix: "/drive/",
474
- methods: ["GET", "POST", "PATCH"]
475
- }
476
- ]
477
- },
478
- systemPrompt: {
479
- en: `### Tools
480
-
481
- - \`google-drive-oauth_request\`: Send authenticated requests to the Google Drive API v3. Supports GET, POST, and PATCH methods. Authentication is configured automatically via OAuth.
482
-
483
- ### Google Drive API Reference
484
-
485
- #### Files
486
- - GET \`/files\` \u2014 List files. Key query params: \`q\` (search query), \`pageSize\`, \`pageToken\`, \`orderBy\`, \`fields\`
487
- - GET \`/files/{fileId}\` \u2014 Get file metadata. Use \`fields\` param to select specific fields
488
- - GET \`/files/{fileId}?alt=media\` \u2014 Download file content (for non-Google-Workspace files)
489
- - POST \`/files\` \u2014 Create a new file or folder (metadata only). Body: \`{ "name": "My File", "mimeType": "...", "parents": ["folderId"] }\`
490
- - PATCH \`/files/{fileId}\` \u2014 Update file metadata (rename, move, star). Body: \`{ "name": "New Name" }\`. Use \`addParents\`/\`removeParents\` query params to move
491
- - POST \`/files/{fileId}/copy\` \u2014 Copy a file. Body: \`{ "name": "Copy of File", "parents": ["folderId"] }\`
492
-
493
- #### Download & Export
494
- - GET \`/files/{fileId}?alt=media\` \u2014 Download file content (PDFs, images, text files, etc.)
495
- - GET \`/files/{fileId}/export?mimeType={mimeType}\` \u2014 Export a Google Workspace file (Docs, Sheets, Slides) to another format
496
-
497
- #### Permissions (Sharing)
498
- - GET \`/files/{fileId}/permissions\` \u2014 List permissions on a file
499
- - POST \`/files/{fileId}/permissions\` \u2014 Share a file. Body: \`{ "type": "user", "role": "writer", "emailAddress": "user@example.com" }\`
500
-
501
- #### Account Info
502
- - GET \`/about?fields=user,storageQuota\` \u2014 Get account info and storage usage
503
-
504
- ### Search Query Syntax (\`q\` parameter)
505
- - \`name = 'My Document'\` \u2014 Exact name match
506
- - \`name contains 'report'\` \u2014 Name contains text
507
- - \`mimeType = 'application/vnd.google-apps.folder'\` \u2014 Folders only
508
- - \`mimeType = 'application/vnd.google-apps.spreadsheet'\` \u2014 Google Sheets only
509
- - \`mimeType = 'application/vnd.google-apps.presentation'\` \u2014 Google Slides only
510
- - \`mimeType = 'application/vnd.google-apps.document'\` \u2014 Google Docs only
511
- - \`'folderId' in parents\` \u2014 Files in a specific folder
512
- - \`trashed = false\` \u2014 Exclude trashed files
513
- - \`starred = true\` \u2014 Starred files
514
- - \`sharedWithMe\` \u2014 Files shared with the user
515
- - \`modifiedTime > '2024-01-01T00:00:00'\` \u2014 Modified after date
516
- - Combine with \`and\`/\`or\`/\`not\`: \`mimeType = 'application/vnd.google-apps.folder' and name contains 'project'\`
517
-
518
- ### Common MIME Types
519
- | Type | MIME Type |
520
- |------|-----------|
521
- | Folder | \`application/vnd.google-apps.folder\` |
522
- | Google Docs | \`application/vnd.google-apps.document\` |
523
- | Google Sheets | \`application/vnd.google-apps.spreadsheet\` |
524
- | Google Slides | \`application/vnd.google-apps.presentation\` |
525
- | PDF | \`application/pdf\` |
526
-
527
- ### Export MIME Types (for Google Workspace files)
528
- | Source | Export Format | MIME Type |
529
- |--------|--------------|-----------|
530
- | Docs | PDF | \`application/pdf\` |
531
- | Docs | Word | \`application/vnd.openxmlformats-officedocument.wordprocessingml.document\` |
532
- | Docs | Plain Text | \`text/plain\` |
533
- | Sheets | PDF | \`application/pdf\` |
534
- | Sheets | Excel | \`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\` |
535
- | Sheets | CSV | \`text/csv\` |
536
- | Slides | PDF | \`application/pdf\` |
537
- | Slides | PowerPoint | \`application/vnd.openxmlformats-officedocument.presentationml.presentation\` |
538
-
539
- ### Tips
540
- - Always use \`fields\` parameter to limit response data and improve performance
541
- - Use \`orderBy=modifiedTime desc\` to get most recently modified files first
542
- - To create a folder, use mimeType \`application/vnd.google-apps.folder\`
543
- - To move a file, use PATCH with \`addParents\` and \`removeParents\` query params
544
- - Files in "My Drive" have no parent specified; use \`'root' in parents\` to list root files
545
-
546
- ### Business Logic
547
-
548
- 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.
549
-
550
- #### Example
551
-
552
- \`\`\`ts
553
- import { connection } from "@squadbase/vite-server/connectors/google-drive-oauth";
554
-
555
- const drive = connection("<connectionId>");
556
-
557
- // List recent files
558
- const result = await drive.listFiles({ pageSize: 20, orderBy: "modifiedTime desc" });
559
- result.files.forEach(f => console.log(f.name, f.mimeType));
560
-
561
- // Search for spreadsheets
562
- const sheets = await drive.listFiles({
563
- query: "mimeType = 'application/vnd.google-apps.spreadsheet' and name contains 'report'"
564
- });
565
-
566
- // Get file metadata
567
- const file = await drive.getFile("fileId123");
568
- console.log(file.name, file.webViewLink);
569
-
570
- // Create a folder
571
- const folder = await drive.createFile({
572
- name: "Reports",
573
- mimeType: "application/vnd.google-apps.folder",
574
- });
575
-
576
- // Create a Google Sheets file inside the folder
577
- const sheet = await drive.createFile({
578
- name: "Q1 Report",
579
- mimeType: "application/vnd.google-apps.spreadsheet",
580
- parents: [folder.id],
581
- });
582
-
583
- // Download file content (non-Google-Workspace files)
584
- const content = await drive.downloadFile("fileId123");
585
- const text = await content.text(); // or content.arrayBuffer() for binary
586
-
587
- // Export a Google Docs file as PDF
588
- const pdf = await drive.exportFile("docFileId", "application/pdf");
589
-
590
- // Share a file
591
- await drive.shareFile("fileId123", "user", "writer", "colleague@example.com");
592
-
593
- // Copy a file
594
- const copy = await drive.copyFile("fileId123", "Backup Copy");
595
-
596
- // Move a file to a different folder
597
- await drive.updateFile("fileId123", {}, "newFolderId", "oldFolderId");
598
- \`\`\``,
599
- ja: `### \u30C4\u30FC\u30EB
600
-
601
- - \`google-drive-oauth_request\`: Google Drive API v3\u3078\u306E\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002GET, POST, PATCH\u30E1\u30BD\u30C3\u30C9\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
602
-
603
- ### Google Drive API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
604
-
605
- #### \u30D5\u30A1\u30A4\u30EB
606
- - GET \`/files\` \u2014 \u30D5\u30A1\u30A4\u30EB\u4E00\u89A7\u3002\u4E3B\u8981\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF: \`q\`\uFF08\u691C\u7D22\u30AF\u30A8\u30EA\uFF09, \`pageSize\`, \`pageToken\`, \`orderBy\`, \`fields\`
607
- - GET \`/files/{fileId}\` \u2014 \u30D5\u30A1\u30A4\u30EB\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3002\`fields\`\u30D1\u30E9\u30E1\u30FC\u30BF\u3067\u7279\u5B9A\u306E\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u9078\u629E
608
- - GET \`/files/{fileId}?alt=media\` \u2014 \u30D5\u30A1\u30A4\u30EB\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\uFF08\u975EGoogle Workspace\u30D5\u30A1\u30A4\u30EB\u5411\u3051\uFF09
609
- - POST \`/files\` \u2014 \u65B0\u3057\u3044\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30D5\u30A9\u30EB\u30C0\u3092\u4F5C\u6210\uFF08\u30E1\u30BF\u30C7\u30FC\u30BF\u306E\u307F\uFF09\u3002Body: \`{ "name": "\u30DE\u30A4\u30D5\u30A1\u30A4\u30EB", "mimeType": "...", "parents": ["folderId"] }\`
610
- - PATCH \`/files/{fileId}\` \u2014 \u30D5\u30A1\u30A4\u30EB\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u66F4\u65B0\uFF08\u540D\u524D\u5909\u66F4\u3001\u79FB\u52D5\u3001\u30B9\u30BF\u30FC\uFF09\u3002Body: \`{ "name": "\u65B0\u3057\u3044\u540D\u524D" }\`\u3002\`addParents\`/\`removeParents\`\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u3067\u79FB\u52D5
611
- - POST \`/files/{fileId}/copy\` \u2014 \u30D5\u30A1\u30A4\u30EB\u3092\u30B3\u30D4\u30FC\u3002Body: \`{ "name": "\u30B3\u30D4\u30FC", "parents": ["folderId"] }\`
612
-
613
- #### \u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 & \u30A8\u30AF\u30B9\u30DD\u30FC\u30C8
614
- - GET \`/files/{fileId}?alt=media\` \u2014 \u30D5\u30A1\u30A4\u30EB\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\uFF08PDF\u3001\u753B\u50CF\u3001\u30C6\u30AD\u30B9\u30C8\u30D5\u30A1\u30A4\u30EB\u7B49\uFF09
615
- - GET \`/files/{fileId}/export?mimeType={mimeType}\` \u2014 Google Workspace\u30D5\u30A1\u30A4\u30EB\uFF08Docs, Sheets, Slides\uFF09\u3092\u5225\u306E\u5F62\u5F0F\u306B\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8
616
-
617
- #### \u30D1\u30FC\u30DF\u30C3\u30B7\u30E7\u30F3\uFF08\u5171\u6709\uFF09
618
- - GET \`/files/{fileId}/permissions\` \u2014 \u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30FC\u30DF\u30C3\u30B7\u30E7\u30F3\u4E00\u89A7
619
- - POST \`/files/{fileId}/permissions\` \u2014 \u30D5\u30A1\u30A4\u30EB\u3092\u5171\u6709\u3002Body: \`{ "type": "user", "role": "writer", "emailAddress": "user@example.com" }\`
620
-
621
- #### \u30A2\u30AB\u30A6\u30F3\u30C8\u60C5\u5831
622
- - GET \`/about?fields=user,storageQuota\` \u2014 \u30A2\u30AB\u30A6\u30F3\u30C8\u60C5\u5831\u3068\u30B9\u30C8\u30EC\u30FC\u30B8\u4F7F\u7528\u91CF\u3092\u53D6\u5F97
623
-
624
- ### \u691C\u7D22\u30AF\u30A8\u30EA\u69CB\u6587\uFF08\`q\` \u30D1\u30E9\u30E1\u30FC\u30BF\uFF09
625
- - \`name = '\u30DE\u30A4\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8'\` \u2014 \u540D\u524D\u306E\u5B8C\u5168\u4E00\u81F4
626
- - \`name contains '\u30EC\u30DD\u30FC\u30C8'\` \u2014 \u540D\u524D\u306B\u30C6\u30AD\u30B9\u30C8\u3092\u542B\u3080
627
- - \`mimeType = 'application/vnd.google-apps.folder'\` \u2014 \u30D5\u30A9\u30EB\u30C0\u306E\u307F
628
- - \`mimeType = 'application/vnd.google-apps.spreadsheet'\` \u2014 Google Sheets\u306E\u307F
629
- - \`mimeType = 'application/vnd.google-apps.presentation'\` \u2014 Google Slides\u306E\u307F
630
- - \`mimeType = 'application/vnd.google-apps.document'\` \u2014 Google Docs\u306E\u307F
631
- - \`'folderId' in parents\` \u2014 \u7279\u5B9A\u306E\u30D5\u30A9\u30EB\u30C0\u5185\u306E\u30D5\u30A1\u30A4\u30EB
632
- - \`trashed = false\` \u2014 \u30B4\u30DF\u7BB1\u3092\u9664\u5916
633
- - \`starred = true\` \u2014 \u30B9\u30BF\u30FC\u4ED8\u304D\u30D5\u30A1\u30A4\u30EB
634
- - \`sharedWithMe\` \u2014 \u5171\u6709\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB
635
- - \`modifiedTime > '2024-01-01T00:00:00'\` \u2014 \u6307\u5B9A\u65E5\u4EE5\u964D\u306B\u66F4\u65B0
636
- - \`and\`/\`or\`/\`not\`\u3067\u7D44\u307F\u5408\u308F\u305B: \`mimeType = 'application/vnd.google-apps.folder' and name contains 'project'\`
637
-
638
- ### \u4E3B\u8981\u306A MIME \u30BF\u30A4\u30D7
639
- | \u30BF\u30A4\u30D7 | MIME Type |
640
- |--------|-----------|
641
- | \u30D5\u30A9\u30EB\u30C0 | \`application/vnd.google-apps.folder\` |
642
- | Google Docs | \`application/vnd.google-apps.document\` |
643
- | Google Sheets | \`application/vnd.google-apps.spreadsheet\` |
644
- | Google Slides | \`application/vnd.google-apps.presentation\` |
645
- | PDF | \`application/pdf\` |
646
-
647
- ### \u30A8\u30AF\u30B9\u30DD\u30FC\u30C8 MIME \u30BF\u30A4\u30D7\uFF08Google Workspace\u30D5\u30A1\u30A4\u30EB\u7528\uFF09
648
- | \u30BD\u30FC\u30B9 | \u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u5F62\u5F0F | MIME Type |
649
- |--------|----------------|-----------|
650
- | Docs | PDF | \`application/pdf\` |
651
- | Docs | Word | \`application/vnd.openxmlformats-officedocument.wordprocessingml.document\` |
652
- | Docs | \u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8 | \`text/plain\` |
653
- | Sheets | PDF | \`application/pdf\` |
654
- | Sheets | Excel | \`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\` |
655
- | Sheets | CSV | \`text/csv\` |
656
- | Slides | PDF | \`application/pdf\` |
657
- | Slides | PowerPoint | \`application/vnd.openxmlformats-officedocument.presentationml.presentation\` |
658
-
659
- ### \u30D2\u30F3\u30C8
660
- - \`fields\`\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u4F7F\u7528\u3057\u3066\u30EC\u30B9\u30DD\u30F3\u30B9\u30C7\u30FC\u30BF\u3092\u5236\u9650\u3057\u3001\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u3092\u5411\u4E0A\u3055\u305B\u3066\u304F\u3060\u3055\u3044
661
- - \`orderBy=modifiedTime desc\`\u3067\u6700\u8FD1\u66F4\u65B0\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u5148\u306B\u53D6\u5F97
662
- - \u30D5\u30A9\u30EB\u30C0\u3092\u4F5C\u6210\u3059\u308B\u306B\u306FmimeType\u306B\`application/vnd.google-apps.folder\`\u3092\u4F7F\u7528
663
- - \u30D5\u30A1\u30A4\u30EB\u3092\u79FB\u52D5\u3059\u308B\u306B\u306FPATCH\u3067\`addParents\`\u3068\`removeParents\`\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u4F7F\u7528
664
- - \u300C\u30DE\u30A4\u30C9\u30E9\u30A4\u30D6\u300D\u306E\u30EB\u30FC\u30C8\u30D5\u30A1\u30A4\u30EB\u306F\`'root' in parents\`\u3067\u4E00\u89A7\u8868\u793A
665
-
666
- ### Business Logic
667
-
668
- \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
669
-
670
- #### Example
671
-
672
- \`\`\`ts
673
- import { connection } from "@squadbase/vite-server/connectors/google-drive-oauth";
674
-
675
- const drive = connection("<connectionId>");
676
-
677
- // \u6700\u8FD1\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u8868\u793A
678
- const result = await drive.listFiles({ pageSize: 20, orderBy: "modifiedTime desc" });
679
- result.files.forEach(f => console.log(f.name, f.mimeType));
680
-
681
- // \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u3092\u691C\u7D22
682
- const sheets = await drive.listFiles({
683
- query: "mimeType = 'application/vnd.google-apps.spreadsheet' and name contains '\u30EC\u30DD\u30FC\u30C8'"
684
- });
685
-
686
- // \u30D5\u30A1\u30A4\u30EB\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97
687
- const file = await drive.getFile("fileId123");
688
- console.log(file.name, file.webViewLink);
689
-
690
- // \u30D5\u30A9\u30EB\u30C0\u3092\u4F5C\u6210
691
- const folder = await drive.createFile({
692
- name: "\u30EC\u30DD\u30FC\u30C8",
693
- mimeType: "application/vnd.google-apps.folder",
694
- });
695
-
696
- // \u30D5\u30A9\u30EB\u30C0\u5185\u306BGoogle Sheets\u30D5\u30A1\u30A4\u30EB\u3092\u4F5C\u6210
697
- const sheet = await drive.createFile({
698
- name: "Q1\u30EC\u30DD\u30FC\u30C8",
699
- mimeType: "application/vnd.google-apps.spreadsheet",
700
- parents: [folder.id],
701
- });
702
-
703
- // \u30D5\u30A1\u30A4\u30EB\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\uFF08\u975EGoogle Workspace\u30D5\u30A1\u30A4\u30EB\uFF09
704
- const content = await drive.downloadFile("fileId123");
705
- const text = await content.text(); // \u30D0\u30A4\u30CA\u30EA\u306E\u5834\u5408\u306F content.arrayBuffer()
706
-
707
- // Google Docs\u30D5\u30A1\u30A4\u30EB\u3092PDF\u3068\u3057\u3066\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8
708
- const pdf = await drive.exportFile("docFileId", "application/pdf");
709
-
710
- // \u30D5\u30A1\u30A4\u30EB\u3092\u5171\u6709
711
- await drive.shareFile("fileId123", "user", "writer", "colleague@example.com");
712
-
713
- // \u30D5\u30A1\u30A4\u30EB\u3092\u30B3\u30D4\u30FC
714
- const copy = await drive.copyFile("fileId123", "\u30D0\u30C3\u30AF\u30A2\u30C3\u30D7\u30B3\u30D4\u30FC");
715
-
716
- // \u30D5\u30A1\u30A4\u30EB\u3092\u5225\u306E\u30D5\u30A9\u30EB\u30C0\u306B\u79FB\u52D5
717
- await drive.updateFile("fileId123", {}, "newFolderId", "oldFolderId");
718
- \`\`\``
719
- },
720
- tools,
721
- async checkConnection(_params, config) {
722
- const { proxyFetch } = config;
723
- const url = "https://www.googleapis.com/drive/v3/about?fields=user";
724
- try {
725
- const res = await proxyFetch(url, { method: "GET" });
726
- if (!res.ok) {
727
- const errorText = await res.text().catch(() => res.statusText);
728
- return {
729
- success: false,
730
- error: `Google Drive API failed: HTTP ${res.status} ${errorText}`
731
- };
732
- }
733
- return { success: true };
734
- } catch (error) {
735
- return {
736
- success: false,
737
- error: error instanceof Error ? error.message : String(error)
738
- };
739
- }
740
- }
741
- });
742
-
743
- // src/connectors/create-connector-sdk.ts
744
- import { readFileSync } from "fs";
745
- import path from "path";
746
-
747
- // src/connector-client/env.ts
748
- function resolveEnvVar(entry, key, connectionId) {
749
- const envVarName = entry.envVars[key];
750
- if (!envVarName) {
751
- throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
752
- }
753
- const value = process.env[envVarName];
754
- if (!value) {
755
- throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
756
- }
757
- return value;
758
- }
759
- function resolveEnvVarOptional(entry, key) {
760
- const envVarName = entry.envVars[key];
761
- if (!envVarName) return void 0;
762
- return process.env[envVarName] || void 0;
763
- }
764
-
765
- // src/connector-client/proxy-fetch.ts
766
- import { getContext } from "hono/context-storage";
767
- import { getCookie } from "hono/cookie";
768
- var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
769
- function createSandboxProxyFetch(connectionId) {
770
- return async (input, init) => {
771
- const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
772
- const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
773
- if (!token || !sandboxId) {
774
- throw new Error(
775
- "Connection proxy is not configured. Please check your deployment settings."
776
- );
777
- }
778
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
779
- const originalMethod = init?.method ?? "GET";
780
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
781
- const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
782
- const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
783
- return fetch(proxyUrl, {
784
- method: "POST",
785
- headers: {
786
- "Content-Type": "application/json",
787
- Authorization: `Bearer ${token}`
788
- },
789
- body: JSON.stringify({
790
- url: originalUrl,
791
- method: originalMethod,
792
- body: originalBody
793
- })
794
- });
795
- };
796
- }
797
- function createDeployedAppProxyFetch(connectionId) {
798
- const projectId = process.env["SQUADBASE_PROJECT_ID"];
799
- if (!projectId) {
800
- throw new Error(
801
- "Connection proxy is not configured. Please check your deployment settings."
802
- );
803
- }
804
- const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
805
- const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
806
- return async (input, init) => {
807
- const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
808
- const originalMethod = init?.method ?? "GET";
809
- const originalBody = init?.body ? JSON.parse(init.body) : void 0;
810
- const c = getContext();
811
- const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
812
- if (!appSession) {
813
- throw new Error(
814
- "No authentication method available for connection proxy."
815
- );
816
- }
817
- return fetch(proxyUrl, {
818
- method: "POST",
819
- headers: {
820
- "Content-Type": "application/json",
821
- Authorization: `Bearer ${appSession}`
822
- },
823
- body: JSON.stringify({
824
- url: originalUrl,
825
- method: originalMethod,
826
- body: originalBody
827
- })
828
- });
829
- };
830
- }
831
- function createProxyFetch(connectionId) {
832
- if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
833
- return createSandboxProxyFetch(connectionId);
834
- }
835
- return createDeployedAppProxyFetch(connectionId);
836
- }
837
-
838
- // src/connectors/create-connector-sdk.ts
839
- function loadConnectionsSync() {
840
- const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
841
- try {
842
- const raw = readFileSync(filePath, "utf-8");
843
- return JSON.parse(raw);
844
- } catch {
845
- return {};
846
- }
847
- }
848
- function createConnectorSdk(plugin, createClient2) {
849
- return (connectionId) => {
850
- const connections = loadConnectionsSync();
851
- const entry = connections[connectionId];
852
- if (!entry) {
853
- throw new Error(
854
- `Connection "${connectionId}" not found in .squadbase/connections.json`
855
- );
856
- }
857
- if (entry.connector.slug !== plugin.slug) {
858
- throw new Error(
859
- `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
860
- );
861
- }
862
- const params = {};
863
- for (const param of Object.values(plugin.parameters)) {
864
- if (param.required) {
865
- params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
866
- } else {
867
- const val = resolveEnvVarOptional(entry, param.slug);
868
- if (val !== void 0) params[param.slug] = val;
869
- }
870
- }
871
- return createClient2(params, createProxyFetch(connectionId));
872
- };
873
- }
874
-
875
- // src/connectors/entries/google-drive-oauth.ts
876
- var connection = createConnectorSdk(googleDriveOauthConnector, createClient);
877
- export {
878
- connection
879
- };