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