@squadbase/vite-server 0.1.3-dev.9 → 0.1.3
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 +14229 -29321
- 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 +43 -6
- 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 +4476 -3949
- package/dist/main.js +4474 -3948
- package/dist/vite-plugin.js +4474 -3948
- 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,631 @@
|
|
|
1
|
+
// ../connectors/src/connectors/google-docs/sdk/index.ts
|
|
2
|
+
var DOCS_BASE_URL = "https://docs.googleapis.com/v1/documents";
|
|
3
|
+
function createClient(_params, fetchFn = fetch) {
|
|
4
|
+
function request(path2, init) {
|
|
5
|
+
const url = `${DOCS_BASE_URL}${path2 === "" || path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
6
|
+
return fetchFn(url, init);
|
|
7
|
+
}
|
|
8
|
+
async function getDocument(documentId) {
|
|
9
|
+
const url = `${DOCS_BASE_URL}/${documentId}`;
|
|
10
|
+
const response = await fetchFn(url);
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
const body = await response.text();
|
|
13
|
+
throw new Error(
|
|
14
|
+
`google-docs: getDocument failed (${response.status}): ${body}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return await response.json();
|
|
18
|
+
}
|
|
19
|
+
async function batchUpdate(documentId, requests) {
|
|
20
|
+
const url = `${DOCS_BASE_URL}/${documentId}:batchUpdate`;
|
|
21
|
+
const response = await fetchFn(url, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { "Content-Type": "application/json" },
|
|
24
|
+
body: JSON.stringify({ requests })
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
const body = await response.text();
|
|
28
|
+
throw new Error(
|
|
29
|
+
`google-docs: batchUpdate failed (${response.status}): ${body}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return await response.json();
|
|
33
|
+
}
|
|
34
|
+
async function createDocument(title) {
|
|
35
|
+
const url = DOCS_BASE_URL;
|
|
36
|
+
const response = await fetchFn(url, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: { "Content-Type": "application/json" },
|
|
39
|
+
body: JSON.stringify({ title })
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const body = await response.text();
|
|
43
|
+
throw new Error(
|
|
44
|
+
`google-docs: createDocument failed (${response.status}): ${body}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return await response.json();
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
request,
|
|
51
|
+
getDocument,
|
|
52
|
+
batchUpdate,
|
|
53
|
+
createDocument
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ../connectors/src/connector-onboarding.ts
|
|
58
|
+
var ConnectorOnboarding = class {
|
|
59
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
60
|
+
connectionSetupInstructions;
|
|
61
|
+
/** Phase 2: Data overview instructions */
|
|
62
|
+
dataOverviewInstructions;
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
65
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
66
|
+
}
|
|
67
|
+
getConnectionSetupPrompt(language) {
|
|
68
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
69
|
+
}
|
|
70
|
+
getDataOverviewInstructions(language) {
|
|
71
|
+
return this.dataOverviewInstructions[language];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ../connectors/src/connector-tool.ts
|
|
76
|
+
var ConnectorTool = class {
|
|
77
|
+
name;
|
|
78
|
+
description;
|
|
79
|
+
inputSchema;
|
|
80
|
+
outputSchema;
|
|
81
|
+
_execute;
|
|
82
|
+
constructor(config) {
|
|
83
|
+
this.name = config.name;
|
|
84
|
+
this.description = config.description;
|
|
85
|
+
this.inputSchema = config.inputSchema;
|
|
86
|
+
this.outputSchema = config.outputSchema;
|
|
87
|
+
this._execute = config.execute;
|
|
88
|
+
}
|
|
89
|
+
createTool(connections, config) {
|
|
90
|
+
return {
|
|
91
|
+
description: this.description,
|
|
92
|
+
inputSchema: this.inputSchema,
|
|
93
|
+
outputSchema: this.outputSchema,
|
|
94
|
+
execute: (input) => this._execute(input, connections, config)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// ../connectors/src/connector-plugin.ts
|
|
100
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
101
|
+
slug;
|
|
102
|
+
authType;
|
|
103
|
+
name;
|
|
104
|
+
description;
|
|
105
|
+
iconUrl;
|
|
106
|
+
parameters;
|
|
107
|
+
releaseFlag;
|
|
108
|
+
proxyPolicy;
|
|
109
|
+
experimentalAttributes;
|
|
110
|
+
onboarding;
|
|
111
|
+
systemPrompt;
|
|
112
|
+
tools;
|
|
113
|
+
query;
|
|
114
|
+
checkConnection;
|
|
115
|
+
constructor(config) {
|
|
116
|
+
this.slug = config.slug;
|
|
117
|
+
this.authType = config.authType;
|
|
118
|
+
this.name = config.name;
|
|
119
|
+
this.description = config.description;
|
|
120
|
+
this.iconUrl = config.iconUrl;
|
|
121
|
+
this.parameters = config.parameters;
|
|
122
|
+
this.releaseFlag = config.releaseFlag;
|
|
123
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
124
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
125
|
+
this.onboarding = config.onboarding;
|
|
126
|
+
this.systemPrompt = config.systemPrompt;
|
|
127
|
+
this.tools = config.tools;
|
|
128
|
+
this.query = config.query;
|
|
129
|
+
this.checkConnection = config.checkConnection;
|
|
130
|
+
}
|
|
131
|
+
get connectorKey() {
|
|
132
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Create tools for connections that belong to this connector.
|
|
136
|
+
* Filters connections by connectorKey internally.
|
|
137
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
138
|
+
*/
|
|
139
|
+
createTools(connections, config, opts) {
|
|
140
|
+
const myConnections = connections.filter(
|
|
141
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
142
|
+
);
|
|
143
|
+
const result = {};
|
|
144
|
+
for (const t of Object.values(this.tools)) {
|
|
145
|
+
const tool = t.createTool(myConnections, config);
|
|
146
|
+
const originalToModelOutput = tool.toModelOutput;
|
|
147
|
+
result[`${this.connectorKey}_${t.name}`] = {
|
|
148
|
+
...tool,
|
|
149
|
+
toModelOutput: async (options) => {
|
|
150
|
+
if (!originalToModelOutput) {
|
|
151
|
+
return opts.truncateOutput(options.output);
|
|
152
|
+
}
|
|
153
|
+
const modelOutput = await originalToModelOutput(options);
|
|
154
|
+
if (modelOutput.type === "text" || modelOutput.type === "json") {
|
|
155
|
+
return opts.truncateOutput(modelOutput.value);
|
|
156
|
+
}
|
|
157
|
+
return modelOutput;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
static deriveKey(slug, authType) {
|
|
164
|
+
if (authType) return `${slug}-${authType}`;
|
|
165
|
+
const LEGACY_NULL_AUTH_TYPE_MAP = {
|
|
166
|
+
// user-password
|
|
167
|
+
"postgresql": "user-password",
|
|
168
|
+
"mysql": "user-password",
|
|
169
|
+
"clickhouse": "user-password",
|
|
170
|
+
"kintone": "user-password",
|
|
171
|
+
"squadbase-db": "user-password",
|
|
172
|
+
// service-account
|
|
173
|
+
"snowflake": "service-account",
|
|
174
|
+
"bigquery": "service-account",
|
|
175
|
+
"google-analytics": "service-account",
|
|
176
|
+
"google-calendar": "service-account",
|
|
177
|
+
"aws-athena": "service-account",
|
|
178
|
+
"redshift": "service-account",
|
|
179
|
+
// api-key
|
|
180
|
+
"databricks": "api-key",
|
|
181
|
+
"dbt": "api-key",
|
|
182
|
+
"airtable": "api-key",
|
|
183
|
+
"openai": "api-key",
|
|
184
|
+
"gemini": "api-key",
|
|
185
|
+
"anthropic": "api-key",
|
|
186
|
+
"wix-store": "api-key"
|
|
187
|
+
};
|
|
188
|
+
const fallbackAuthType = LEGACY_NULL_AUTH_TYPE_MAP[slug];
|
|
189
|
+
if (fallbackAuthType) return `${slug}-${fallbackAuthType}`;
|
|
190
|
+
return slug;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// ../connectors/src/auth-types.ts
|
|
195
|
+
var AUTH_TYPES = {
|
|
196
|
+
OAUTH: "oauth",
|
|
197
|
+
API_KEY: "api-key",
|
|
198
|
+
JWT: "jwt",
|
|
199
|
+
SERVICE_ACCOUNT: "service-account",
|
|
200
|
+
PAT: "pat",
|
|
201
|
+
USER_PASSWORD: "user-password"
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// ../connectors/src/connectors/google-docs/setup.ts
|
|
205
|
+
var googleDocsOnboarding = new ConnectorOnboarding({
|
|
206
|
+
dataOverviewInstructions: {
|
|
207
|
+
en: `1. Create a new document with google-docs-oauth_request (POST with body { title: "..." }) or use an existing document ID.
|
|
208
|
+
2. Call google-docs-oauth_request with GET /{documentId} to fetch the document's content and metadata.`,
|
|
209
|
+
ja: `1. google-docs-oauth_request \u3092 POST\uFF08Body: { title: "..." }\uFF09\u3067\u547C\u3073\u51FA\u3057\u3066\u65B0\u3057\u3044\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u4F5C\u6210\u3059\u308B\u304B\u3001\u65E2\u5B58\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8ID\u3092\u5229\u7528\u3057\u307E\u3059\u3002
|
|
210
|
+
2. google-docs-oauth_request \u3067 GET /{documentId} \u3092\u547C\u3073\u51FA\u3057\u3001\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u5185\u5BB9\u3068\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002`
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// ../connectors/src/connectors/google-docs/parameters.ts
|
|
215
|
+
var parameters = {};
|
|
216
|
+
|
|
217
|
+
// ../connectors/src/connectors/google-docs/tools/request.ts
|
|
218
|
+
import { z } from "zod";
|
|
219
|
+
var DOCS_BASE_URL2 = "https://docs.googleapis.com/v1/documents";
|
|
220
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
221
|
+
var cachedToken = null;
|
|
222
|
+
async function getProxyToken(config) {
|
|
223
|
+
if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
|
|
224
|
+
return cachedToken.token;
|
|
225
|
+
}
|
|
226
|
+
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
227
|
+
const res = await fetch(url, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
headers: {
|
|
230
|
+
"Content-Type": "application/json",
|
|
231
|
+
"x-api-key": config.appApiKey,
|
|
232
|
+
"project-id": config.projectId
|
|
233
|
+
},
|
|
234
|
+
body: JSON.stringify({
|
|
235
|
+
sandboxId: config.sandboxId,
|
|
236
|
+
issuedBy: "coding-agent"
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
if (!res.ok) {
|
|
240
|
+
const errorText = await res.text().catch(() => res.statusText);
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Failed to get proxy token: HTTP ${res.status} ${errorText}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const data = await res.json();
|
|
246
|
+
cachedToken = {
|
|
247
|
+
token: data.token,
|
|
248
|
+
expiresAt: new Date(data.expiresAt).getTime()
|
|
249
|
+
};
|
|
250
|
+
return data.token;
|
|
251
|
+
}
|
|
252
|
+
var inputSchema = z.object({
|
|
253
|
+
toolUseIntent: z.string().optional().describe(
|
|
254
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
255
|
+
),
|
|
256
|
+
connectionId: z.string().describe("ID of the Google Docs connection to use"),
|
|
257
|
+
method: z.enum(["GET", "POST"]).describe("HTTP method"),
|
|
258
|
+
path: z.string().describe(
|
|
259
|
+
"API path appended to https://docs.googleapis.com/v1/documents (e.g., '', '/{documentId}', '/{documentId}:batchUpdate')."
|
|
260
|
+
),
|
|
261
|
+
body: z.record(z.string(), z.unknown()).optional().describe("JSON request body for POST requests"),
|
|
262
|
+
queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL")
|
|
263
|
+
});
|
|
264
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
265
|
+
z.object({
|
|
266
|
+
success: z.literal(true),
|
|
267
|
+
status: z.number(),
|
|
268
|
+
data: z.record(z.string(), z.unknown())
|
|
269
|
+
}),
|
|
270
|
+
z.object({
|
|
271
|
+
success: z.literal(false),
|
|
272
|
+
error: z.string()
|
|
273
|
+
})
|
|
274
|
+
]);
|
|
275
|
+
var requestTool = new ConnectorTool({
|
|
276
|
+
name: "request",
|
|
277
|
+
description: `Send authenticated requests to the Google Docs API v1.
|
|
278
|
+
Supports GET (read) and POST (create/update) methods.
|
|
279
|
+
Authentication is handled automatically via OAuth proxy.`,
|
|
280
|
+
inputSchema,
|
|
281
|
+
outputSchema,
|
|
282
|
+
async execute({ connectionId, method, path: path2, body, queryParams }, connections, config) {
|
|
283
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
284
|
+
if (!connection2) {
|
|
285
|
+
return {
|
|
286
|
+
success: false,
|
|
287
|
+
error: `Connection ${connectionId} not found`
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
console.log(
|
|
291
|
+
`[connector-request] google-docs/${connection2.name}: ${method} ${path2}`
|
|
292
|
+
);
|
|
293
|
+
try {
|
|
294
|
+
let url = `${DOCS_BASE_URL2}${path2 === "" || path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
295
|
+
if (queryParams) {
|
|
296
|
+
const searchParams = new URLSearchParams(queryParams);
|
|
297
|
+
url += `?${searchParams.toString()}`;
|
|
298
|
+
}
|
|
299
|
+
const token = await getProxyToken(config.oauthProxy);
|
|
300
|
+
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
301
|
+
const controller = new AbortController();
|
|
302
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
303
|
+
try {
|
|
304
|
+
const response = await fetch(proxyUrl, {
|
|
305
|
+
method: "POST",
|
|
306
|
+
headers: {
|
|
307
|
+
"Content-Type": "application/json",
|
|
308
|
+
Authorization: `Bearer ${token}`
|
|
309
|
+
},
|
|
310
|
+
body: JSON.stringify({
|
|
311
|
+
url,
|
|
312
|
+
method,
|
|
313
|
+
...body != null ? { body: JSON.stringify(body) } : {}
|
|
314
|
+
}),
|
|
315
|
+
signal: controller.signal
|
|
316
|
+
});
|
|
317
|
+
const data = await response.json();
|
|
318
|
+
if (!response.ok) {
|
|
319
|
+
const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
|
|
320
|
+
return { success: false, error: errorMessage };
|
|
321
|
+
}
|
|
322
|
+
return { success: true, status: response.status, data };
|
|
323
|
+
} finally {
|
|
324
|
+
clearTimeout(timeout);
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {
|
|
327
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
328
|
+
return { success: false, error: msg };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ../connectors/src/connectors/google-docs/index.ts
|
|
334
|
+
var tools = { request: requestTool };
|
|
335
|
+
var googleDocsConnector = new ConnectorPlugin({
|
|
336
|
+
slug: "google-docs",
|
|
337
|
+
authType: AUTH_TYPES.OAUTH,
|
|
338
|
+
name: "Google Docs",
|
|
339
|
+
description: "Connect to Google Docs for document data access and creation using OAuth.",
|
|
340
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/6vvcGJisvXjOumeTvswjzf/e9bb39e453cc0b71a20f26019b23b0d2/google_docs.png",
|
|
341
|
+
parameters,
|
|
342
|
+
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
343
|
+
onboarding: googleDocsOnboarding,
|
|
344
|
+
proxyPolicy: {
|
|
345
|
+
allowlist: [
|
|
346
|
+
{
|
|
347
|
+
host: "docs.googleapis.com",
|
|
348
|
+
methods: ["GET", "POST"]
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
},
|
|
352
|
+
systemPrompt: {
|
|
353
|
+
en: `### Tools (setup-time only)
|
|
354
|
+
|
|
355
|
+
- \`google-docs-oauth_request\`: Call the Google Docs API directly during setup / data overview. Supports read and write operations. Use it to get document content, create new documents, and modify document content via batchUpdate. Authentication is configured automatically via OAuth.
|
|
356
|
+
|
|
357
|
+
> **Important**: The \`google-docs-oauth_request\` tool is only available at setup time. Inside server-logic handlers, use the SDK (\`connection(id).createDocument\`, 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.
|
|
358
|
+
|
|
359
|
+
### Google Docs API Reference
|
|
360
|
+
|
|
361
|
+
#### Read Endpoints
|
|
362
|
+
- GET \`/{documentId}\` \u2014 Get the document's content and metadata (title, body, revisionId, styles)
|
|
363
|
+
|
|
364
|
+
#### Write Endpoints
|
|
365
|
+
- POST \`\` (empty path, with body) \u2014 Create a new document. Body: \`{ "title": "My Document" }\`
|
|
366
|
+
- POST \`/{documentId}:batchUpdate\` \u2014 Apply multiple updates to a document. Body: \`{ "requests": [...] }\`
|
|
367
|
+
|
|
368
|
+
#### Common batchUpdate Request Types
|
|
369
|
+
- \`insertText\` \u2014 Insert text at a location: \`{ "insertText": { "location": { "index": 1 }, "text": "Hello" } }\`
|
|
370
|
+
- \`deleteContentRange\` \u2014 Delete a range of content: \`{ "deleteContentRange": { "range": { "startIndex": 1, "endIndex": 5 } } }\`
|
|
371
|
+
- \`replaceAllText\` \u2014 Find & replace text: \`{ "replaceAllText": { "containsText": { "text": "old" }, "replaceText": "new" } }\`
|
|
372
|
+
- \`updateTextStyle\` \u2014 Style text (bold, color, font): \`{ "updateTextStyle": { "range": { "startIndex": 1, "endIndex": 5 }, "textStyle": { "bold": true }, "fields": "bold" } }\`
|
|
373
|
+
- \`updateParagraphStyle\` \u2014 Update paragraph style (alignment, indentation, etc.)
|
|
374
|
+
- \`insertTable\` \u2014 Insert a table: \`{ "insertTable": { "location": { "index": 1 }, "rows": 3, "columns": 2 } }\`
|
|
375
|
+
- \`insertInlineImage\` \u2014 Insert an image: \`{ "insertInlineImage": { "location": { "index": 1 }, "uri": "https://..." } }\`
|
|
376
|
+
- \`createParagraphBullets\` / \`deleteParagraphBullets\` \u2014 Add or remove bullets
|
|
377
|
+
|
|
378
|
+
### Tips
|
|
379
|
+
- Indexes in the Docs API are 1-based and reference the document body positions (including newlines)
|
|
380
|
+
- To explore a document, first GET the document to get its body structure and element indexes
|
|
381
|
+
- batchUpdate requests are applied in order \u2014 use this for complex multi-step modifications
|
|
382
|
+
- Sharing (permissions) cannot be done via this connector; only the OAuth user has access to the created documents
|
|
383
|
+
|
|
384
|
+
### Business Logic
|
|
385
|
+
|
|
386
|
+
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.
|
|
387
|
+
|
|
388
|
+
SDK surface (client created via \`connection(connectionId)\`):
|
|
389
|
+
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://docs.googleapis.com/v1/documents\`).
|
|
390
|
+
- \`client.getDocument(documentId)\` \u2014 fetch document content and metadata.
|
|
391
|
+
- \`client.createDocument(title)\` \u2014 create a new document.
|
|
392
|
+
- \`client.batchUpdate(documentId, requests)\` \u2014 apply one or more requests (insertText / updateTextStyle / etc.).
|
|
393
|
+
|
|
394
|
+
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.
|
|
395
|
+
|
|
396
|
+
#### Example
|
|
397
|
+
|
|
398
|
+
\`\`\`ts
|
|
399
|
+
import { connection } from "@squadbase/vite-server/connectors/google-docs";
|
|
400
|
+
|
|
401
|
+
const docs = connection("<connectionId>");
|
|
402
|
+
|
|
403
|
+
// Create a new document
|
|
404
|
+
const newDoc = await docs.createDocument("Quarterly Report");
|
|
405
|
+
const documentId = newDoc.documentId;
|
|
406
|
+
|
|
407
|
+
// Get document metadata and content
|
|
408
|
+
const document = await docs.getDocument(documentId);
|
|
409
|
+
console.log(document.title);
|
|
410
|
+
|
|
411
|
+
// Insert text and style it
|
|
412
|
+
await docs.batchUpdate(documentId, [
|
|
413
|
+
{ insertText: { location: { index: 1 }, text: "Hello, World!" } },
|
|
414
|
+
{ updateTextStyle: {
|
|
415
|
+
range: { startIndex: 1, endIndex: 13 },
|
|
416
|
+
textStyle: { bold: true },
|
|
417
|
+
fields: "bold",
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
]);
|
|
421
|
+
\`\`\``,
|
|
422
|
+
ja: `### \u30C4\u30FC\u30EB\uFF08\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u6642\u306E\u307F\uFF09
|
|
423
|
+
|
|
424
|
+
- \`google-docs-oauth_request\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3084\u30C7\u30FC\u30BF\u6982\u8981\u628A\u63E1\u6642\u306B Google Docs API \u3092\u76F4\u63A5\u53E9\u304F\u30C4\u30FC\u30EB\u3067\u3059\u3002\u8AAD\u307F\u53D6\u308A\u3068\u66F8\u304D\u8FBC\u307F\u306E\u4E21\u65B9\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u307E\u3059\u3002\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u5185\u5BB9\u306E\u53D6\u5F97\u3001\u65B0\u3057\u3044\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u4F5C\u6210\u3001batchUpdate \u306B\u3088\u308B\u5185\u5BB9\u5909\u66F4\u306A\u3069\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002OAuth \u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
425
|
+
|
|
426
|
+
> **\u91CD\u8981**: \`google-docs-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).createDocument\` \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
|
|
427
|
+
|
|
428
|
+
### Google Docs API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
429
|
+
|
|
430
|
+
#### \u8AAD\u307F\u53D6\u308A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
|
|
431
|
+
- GET \`/{documentId}\` \u2014 \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u5185\u5BB9\u3068\u30E1\u30BF\u30C7\u30FC\u30BF\uFF08\u30BF\u30A4\u30C8\u30EB\u3001body\u3001revisionId\u3001\u30B9\u30BF\u30A4\u30EB\uFF09\u3092\u53D6\u5F97
|
|
432
|
+
|
|
433
|
+
#### \u66F8\u304D\u8FBC\u307F\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
|
|
434
|
+
- POST \`\`\uFF08\u7A7A\u30D1\u30B9\u3001\u30DC\u30C7\u30A3\u4ED8\u304D\uFF09\u2014 \u65B0\u3057\u3044\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u4F5C\u6210\u3002Body: \`{ "title": "\u30DE\u30A4\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8" }\`
|
|
435
|
+
- POST \`/{documentId}:batchUpdate\` \u2014 \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u8907\u6570\u306E\u66F4\u65B0\u3092\u9069\u7528\u3002Body: \`{ "requests": [...] }\`
|
|
436
|
+
|
|
437
|
+
#### \u4E3B\u306A batchUpdate \u30EA\u30AF\u30A8\u30B9\u30C8\u30BF\u30A4\u30D7
|
|
438
|
+
- \`insertText\` \u2014 \u6307\u5B9A\u4F4D\u7F6E\u306B\u30C6\u30AD\u30B9\u30C8\u3092\u633F\u5165: \`{ "insertText": { "location": { "index": 1 }, "text": "Hello" } }\`
|
|
439
|
+
- \`deleteContentRange\` \u2014 \u7BC4\u56F2\u306E\u5185\u5BB9\u3092\u524A\u9664: \`{ "deleteContentRange": { "range": { "startIndex": 1, "endIndex": 5 } } }\`
|
|
440
|
+
- \`replaceAllText\` \u2014 \u30C6\u30AD\u30B9\u30C8\u306E\u691C\u7D22\u3068\u7F6E\u63DB: \`{ "replaceAllText": { "containsText": { "text": "\u53E4\u3044" }, "replaceText": "\u65B0\u3057\u3044" } }\`
|
|
441
|
+
- \`updateTextStyle\` \u2014 \u30C6\u30AD\u30B9\u30C8\u306E\u30B9\u30BF\u30A4\u30EB\u8A2D\u5B9A\uFF08\u592A\u5B57\u3001\u8272\u3001\u30D5\u30A9\u30F3\u30C8\uFF09: \`{ "updateTextStyle": { "range": { "startIndex": 1, "endIndex": 5 }, "textStyle": { "bold": true }, "fields": "bold" } }\`
|
|
442
|
+
- \`updateParagraphStyle\` \u2014 \u6BB5\u843D\u30B9\u30BF\u30A4\u30EB\u3092\u66F4\u65B0\uFF08\u914D\u7F6E\u3001\u30A4\u30F3\u30C7\u30F3\u30C8\u7B49\uFF09
|
|
443
|
+
- \`insertTable\` \u2014 \u30C6\u30FC\u30D6\u30EB\u3092\u633F\u5165: \`{ "insertTable": { "location": { "index": 1 }, "rows": 3, "columns": 2 } }\`
|
|
444
|
+
- \`insertInlineImage\` \u2014 \u753B\u50CF\u3092\u633F\u5165: \`{ "insertInlineImage": { "location": { "index": 1 }, "uri": "https://..." } }\`
|
|
445
|
+
- \`createParagraphBullets\` / \`deleteParagraphBullets\` \u2014 \u7B87\u6761\u66F8\u304D\u306E\u8FFD\u52A0\u30FB\u524A\u9664
|
|
446
|
+
|
|
447
|
+
### \u30D2\u30F3\u30C8
|
|
448
|
+
- Docs API \u306E\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u306F 1-based \u3067\u3001\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u672C\u6587\u306E\u4F4D\u7F6E\uFF08\u6539\u884C\u3082\u542B\u3080\uFF09\u3092\u53C2\u7167\u3057\u307E\u3059
|
|
449
|
+
- \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u63A2\u7D22\u3059\u308B\u306B\u306F\u3001\u307E\u305A GET \u3067\u53D6\u5F97\u3057\u3066\u672C\u6587\u69CB\u9020\u3068\u8981\u7D20\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u3092\u78BA\u8A8D\u3057\u307E\u3059
|
|
450
|
+
- batchUpdate \u30EA\u30AF\u30A8\u30B9\u30C8\u306F\u9806\u756A\u306B\u9069\u7528\u3055\u308C\u307E\u3059 \u2014 \u8907\u96D1\u306A\u8907\u6570\u30B9\u30C6\u30C3\u30D7\u306E\u5909\u66F4\u306B\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044
|
|
451
|
+
- \u5171\u6709\uFF08permissions\uFF09\u306F\u3053\u306E\u30B3\u30CD\u30AF\u30BF\u7D4C\u7531\u3067\u306F\u884C\u3048\u307E\u305B\u3093\u3002\u4F5C\u6210\u3057\u305F\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3078\u306F\u63A5\u7D9A\u3057\u305FOAuth\u30E6\u30FC\u30B6\u30FC\u306E\u307F\u304C\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u3067\u3059
|
|
452
|
+
|
|
453
|
+
### Business Logic
|
|
454
|
+
|
|
455
|
+
\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
|
|
456
|
+
|
|
457
|
+
SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
|
|
458
|
+
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304D fetch\uFF08\`path\` \u306F \`https://docs.googleapis.com/v1/documents\` \u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\uFF09\u3002
|
|
459
|
+
- \`client.getDocument(documentId)\` \u2014 \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u5185\u5BB9\u3068\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3002
|
|
460
|
+
- \`client.createDocument(title)\` \u2014 \u65B0\u3057\u3044\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u4F5C\u6210\u3002
|
|
461
|
+
- \`client.batchUpdate(documentId, requests)\` \u2014 insertText / updateTextStyle \u306A\u3069\u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u307E\u3068\u3081\u3066\u9069\u7528\u3002
|
|
462
|
+
|
|
463
|
+
\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
|
|
464
|
+
|
|
465
|
+
#### Example
|
|
466
|
+
|
|
467
|
+
\`\`\`ts
|
|
468
|
+
import { connection } from "@squadbase/vite-server/connectors/google-docs";
|
|
469
|
+
|
|
470
|
+
const docs = connection("<connectionId>");
|
|
471
|
+
|
|
472
|
+
// \u65B0\u3057\u3044\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u4F5C\u6210
|
|
473
|
+
const newDoc = await docs.createDocument("\u56DB\u534A\u671F\u30EC\u30DD\u30FC\u30C8");
|
|
474
|
+
const documentId = newDoc.documentId;
|
|
475
|
+
|
|
476
|
+
// \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3068\u5185\u5BB9\u3092\u53D6\u5F97
|
|
477
|
+
const document = await docs.getDocument(documentId);
|
|
478
|
+
console.log(document.title);
|
|
479
|
+
|
|
480
|
+
// \u30C6\u30AD\u30B9\u30C8\u3092\u633F\u5165\u3057\u3066\u30B9\u30BF\u30A4\u30EB\u3092\u9069\u7528
|
|
481
|
+
await docs.batchUpdate(documentId, [
|
|
482
|
+
{ insertText: { location: { index: 1 }, text: "Hello, World!" } },
|
|
483
|
+
{ updateTextStyle: {
|
|
484
|
+
range: { startIndex: 1, endIndex: 13 },
|
|
485
|
+
textStyle: { bold: true },
|
|
486
|
+
fields: "bold",
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
]);
|
|
490
|
+
\`\`\``
|
|
491
|
+
},
|
|
492
|
+
tools
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// src/connectors/create-connector-sdk.ts
|
|
496
|
+
import { readFileSync } from "fs";
|
|
497
|
+
import path from "path";
|
|
498
|
+
|
|
499
|
+
// src/connector-client/env.ts
|
|
500
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
501
|
+
const envVarName = entry.envVars[key];
|
|
502
|
+
if (!envVarName) {
|
|
503
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
504
|
+
}
|
|
505
|
+
const value = process.env[envVarName];
|
|
506
|
+
if (!value) {
|
|
507
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
508
|
+
}
|
|
509
|
+
return value;
|
|
510
|
+
}
|
|
511
|
+
function resolveEnvVarOptional(entry, key) {
|
|
512
|
+
const envVarName = entry.envVars[key];
|
|
513
|
+
if (!envVarName) return void 0;
|
|
514
|
+
return process.env[envVarName] || void 0;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/connector-client/proxy-fetch.ts
|
|
518
|
+
import { getContext } from "hono/context-storage";
|
|
519
|
+
import { getCookie } from "hono/cookie";
|
|
520
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
521
|
+
function createSandboxProxyFetch(connectionId) {
|
|
522
|
+
return async (input, init) => {
|
|
523
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
524
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
525
|
+
if (!token || !sandboxId) {
|
|
526
|
+
throw new Error(
|
|
527
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
531
|
+
const originalMethod = init?.method ?? "GET";
|
|
532
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
533
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
534
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
535
|
+
return fetch(proxyUrl, {
|
|
536
|
+
method: "POST",
|
|
537
|
+
headers: {
|
|
538
|
+
"Content-Type": "application/json",
|
|
539
|
+
Authorization: `Bearer ${token}`
|
|
540
|
+
},
|
|
541
|
+
body: JSON.stringify({
|
|
542
|
+
url: originalUrl,
|
|
543
|
+
method: originalMethod,
|
|
544
|
+
body: originalBody
|
|
545
|
+
})
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
550
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
551
|
+
if (!projectId) {
|
|
552
|
+
throw new Error(
|
|
553
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
557
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
558
|
+
return async (input, init) => {
|
|
559
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
560
|
+
const originalMethod = init?.method ?? "GET";
|
|
561
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
562
|
+
const c = getContext();
|
|
563
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
564
|
+
if (!appSession) {
|
|
565
|
+
throw new Error(
|
|
566
|
+
"No authentication method available for connection proxy."
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
return fetch(proxyUrl, {
|
|
570
|
+
method: "POST",
|
|
571
|
+
headers: {
|
|
572
|
+
"Content-Type": "application/json",
|
|
573
|
+
Authorization: `Bearer ${appSession}`
|
|
574
|
+
},
|
|
575
|
+
body: JSON.stringify({
|
|
576
|
+
url: originalUrl,
|
|
577
|
+
method: originalMethod,
|
|
578
|
+
body: originalBody
|
|
579
|
+
})
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function createProxyFetch(connectionId) {
|
|
584
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
585
|
+
return createSandboxProxyFetch(connectionId);
|
|
586
|
+
}
|
|
587
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// src/connectors/create-connector-sdk.ts
|
|
591
|
+
function loadConnectionsSync() {
|
|
592
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
593
|
+
try {
|
|
594
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
595
|
+
return JSON.parse(raw);
|
|
596
|
+
} catch {
|
|
597
|
+
return {};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
601
|
+
return (connectionId) => {
|
|
602
|
+
const connections = loadConnectionsSync();
|
|
603
|
+
const entry = connections[connectionId];
|
|
604
|
+
if (!entry) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
const params = {};
|
|
615
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
616
|
+
if (param.required) {
|
|
617
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
618
|
+
} else {
|
|
619
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
620
|
+
if (val !== void 0) params[param.slug] = val;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/connectors/entries/google-docs.ts
|
|
628
|
+
var connection = createConnectorSdk(googleDocsConnector, createClient);
|
|
629
|
+
export {
|
|
630
|
+
connection
|
|
631
|
+
};
|