@squadbase/vite-server 0.1.3-dev.0 → 0.1.3-dev.1
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 +13282 -4299
- package/dist/connectors/asana.d.ts +5 -0
- package/dist/connectors/asana.js +661 -0
- package/dist/connectors/customerio.d.ts +5 -0
- package/dist/connectors/customerio.js +633 -0
- package/dist/connectors/gmail-oauth.d.ts +5 -0
- package/dist/connectors/gmail-oauth.js +639 -0
- package/dist/connectors/google-ads.d.ts +5 -0
- package/dist/connectors/google-ads.js +784 -0
- package/dist/connectors/google-sheets.d.ts +5 -0
- package/dist/connectors/google-sheets.js +598 -0
- package/dist/connectors/hubspot.js +14 -5
- package/dist/connectors/intercom-oauth.d.ts +5 -0
- package/dist/connectors/intercom-oauth.js +510 -0
- package/dist/connectors/intercom.d.ts +5 -0
- package/dist/connectors/intercom.js +627 -0
- package/dist/connectors/jira-api-key.d.ts +5 -0
- package/dist/connectors/jira-api-key.js +523 -0
- package/dist/connectors/linkedin-ads-oauth.d.ts +5 -0
- package/dist/connectors/linkedin-ads-oauth.js +774 -0
- package/dist/connectors/linkedin-ads.d.ts +5 -0
- package/dist/connectors/linkedin-ads.js +782 -0
- package/dist/connectors/mailchimp-oauth.d.ts +5 -0
- package/dist/connectors/mailchimp-oauth.js +539 -0
- package/dist/connectors/mailchimp.d.ts +5 -0
- package/dist/connectors/mailchimp.js +646 -0
- package/dist/connectors/zendesk-oauth.d.ts +5 -0
- package/dist/connectors/zendesk-oauth.js +505 -0
- package/dist/connectors/zendesk.d.ts +5 -0
- package/dist/connectors/zendesk.js +631 -0
- package/dist/index.js +13238 -4255
- package/dist/main.js +13240 -4257
- package/dist/vite-plugin.js +13240 -4257
- package/package.json +42 -2
|
@@ -0,0 +1,598 @@
|
|
|
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-sheets/sdk/index.ts
|
|
46
|
+
import * as crypto from "crypto";
|
|
47
|
+
|
|
48
|
+
// ../connectors/src/connectors/google-sheets/parameters.ts
|
|
49
|
+
var parameters = {
|
|
50
|
+
serviceAccountKeyJsonBase64: new ParameterDefinition({
|
|
51
|
+
slug: "service-account-key-json-base64",
|
|
52
|
+
name: "Google Cloud Service Account JSON",
|
|
53
|
+
description: "The service account JSON key used to authenticate with Google Cloud Platform. Ensure that the service account has the necessary permissions to access Google Sheets.",
|
|
54
|
+
envVarBaseKey: "GOOGLE_SHEETS_SERVICE_ACCOUNT_JSON_BASE64",
|
|
55
|
+
type: "base64EncodedJson",
|
|
56
|
+
secret: true,
|
|
57
|
+
required: true
|
|
58
|
+
}),
|
|
59
|
+
spreadsheetId: new ParameterDefinition({
|
|
60
|
+
slug: "spreadsheet-id",
|
|
61
|
+
name: "Default Spreadsheet ID",
|
|
62
|
+
description: "The ID of the default Google Spreadsheet. Can be found in the spreadsheet URL: https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit",
|
|
63
|
+
envVarBaseKey: "GOOGLE_SHEETS_SPREADSHEET_ID",
|
|
64
|
+
type: "text",
|
|
65
|
+
secret: false,
|
|
66
|
+
required: false
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// ../connectors/src/connectors/google-sheets/sdk/index.ts
|
|
71
|
+
var TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
72
|
+
var BASE_URL = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
73
|
+
var SCOPE = "https://www.googleapis.com/auth/spreadsheets.readonly";
|
|
74
|
+
function base64url(input) {
|
|
75
|
+
const buf = typeof input === "string" ? Buffer.from(input) : input;
|
|
76
|
+
return buf.toString("base64url");
|
|
77
|
+
}
|
|
78
|
+
function buildJwt(clientEmail, privateKey, nowSec) {
|
|
79
|
+
const header = base64url(JSON.stringify({ alg: "RS256", typ: "JWT" }));
|
|
80
|
+
const payload = base64url(
|
|
81
|
+
JSON.stringify({
|
|
82
|
+
iss: clientEmail,
|
|
83
|
+
scope: SCOPE,
|
|
84
|
+
aud: TOKEN_URL,
|
|
85
|
+
iat: nowSec,
|
|
86
|
+
exp: nowSec + 3600
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
const signingInput = `${header}.${payload}`;
|
|
90
|
+
const sign = crypto.createSign("RSA-SHA256");
|
|
91
|
+
sign.update(signingInput);
|
|
92
|
+
sign.end();
|
|
93
|
+
const signature = base64url(sign.sign(privateKey));
|
|
94
|
+
return `${signingInput}.${signature}`;
|
|
95
|
+
}
|
|
96
|
+
function createClient(params) {
|
|
97
|
+
const serviceAccountKeyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
|
|
98
|
+
const defaultSpreadsheetId = params[parameters.spreadsheetId.slug];
|
|
99
|
+
if (!serviceAccountKeyJsonBase64) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`google-sheets: missing required parameter: ${parameters.serviceAccountKeyJsonBase64.slug}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
let serviceAccountKey;
|
|
105
|
+
try {
|
|
106
|
+
const decoded = Buffer.from(
|
|
107
|
+
serviceAccountKeyJsonBase64,
|
|
108
|
+
"base64"
|
|
109
|
+
).toString("utf-8");
|
|
110
|
+
serviceAccountKey = JSON.parse(decoded);
|
|
111
|
+
} catch {
|
|
112
|
+
throw new Error(
|
|
113
|
+
"google-sheets: failed to decode service account key JSON from base64"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (!serviceAccountKey.client_email || !serviceAccountKey.private_key) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"google-sheets: service account key JSON must contain client_email and private_key"
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
let cachedToken = null;
|
|
122
|
+
let tokenExpiresAt = 0;
|
|
123
|
+
async function getAccessToken() {
|
|
124
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
125
|
+
if (cachedToken && nowSec < tokenExpiresAt - 60) {
|
|
126
|
+
return cachedToken;
|
|
127
|
+
}
|
|
128
|
+
const jwt = buildJwt(
|
|
129
|
+
serviceAccountKey.client_email,
|
|
130
|
+
serviceAccountKey.private_key,
|
|
131
|
+
nowSec
|
|
132
|
+
);
|
|
133
|
+
const response = await fetch(TOKEN_URL, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
136
|
+
body: new URLSearchParams({
|
|
137
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
138
|
+
assertion: jwt
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
if (!response.ok) {
|
|
142
|
+
const text = await response.text();
|
|
143
|
+
throw new Error(
|
|
144
|
+
`google-sheets: token exchange failed (${response.status}): ${text}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
const data = await response.json();
|
|
148
|
+
cachedToken = data.access_token;
|
|
149
|
+
tokenExpiresAt = nowSec + data.expires_in;
|
|
150
|
+
return cachedToken;
|
|
151
|
+
}
|
|
152
|
+
function resolveSpreadsheetId(override) {
|
|
153
|
+
const id = override ?? defaultSpreadsheetId;
|
|
154
|
+
if (!id) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
"google-sheets: spreadsheetId is required. Either configure a default or pass it explicitly."
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return id;
|
|
160
|
+
}
|
|
161
|
+
async function authenticatedFetch(url, init) {
|
|
162
|
+
const accessToken = await getAccessToken();
|
|
163
|
+
const headers = new Headers(init?.headers);
|
|
164
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
165
|
+
return fetch(url, { ...init, headers });
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
async request(path2, init) {
|
|
169
|
+
const resolvedPath = defaultSpreadsheetId ? path2.replace(/\{spreadsheetId\}/g, defaultSpreadsheetId) : path2;
|
|
170
|
+
const url = `${BASE_URL}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
|
|
171
|
+
return authenticatedFetch(url, init);
|
|
172
|
+
},
|
|
173
|
+
async getSpreadsheet(spreadsheetId) {
|
|
174
|
+
const id = resolveSpreadsheetId(spreadsheetId);
|
|
175
|
+
const url = `${BASE_URL}/${id}?fields=spreadsheetId,properties,sheets.properties`;
|
|
176
|
+
const response = await authenticatedFetch(url);
|
|
177
|
+
if (!response.ok) {
|
|
178
|
+
const body = await response.text();
|
|
179
|
+
throw new Error(
|
|
180
|
+
`google-sheets: getSpreadsheet failed (${response.status}): ${body}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return await response.json();
|
|
184
|
+
},
|
|
185
|
+
async getValues(range, spreadsheetId) {
|
|
186
|
+
const id = resolveSpreadsheetId(spreadsheetId);
|
|
187
|
+
const url = `${BASE_URL}/${id}/values/${encodeURIComponent(range)}`;
|
|
188
|
+
const response = await authenticatedFetch(url);
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
const body = await response.text();
|
|
191
|
+
throw new Error(
|
|
192
|
+
`google-sheets: getValues failed (${response.status}): ${body}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return await response.json();
|
|
196
|
+
},
|
|
197
|
+
async batchGetValues(ranges, spreadsheetId) {
|
|
198
|
+
const id = resolveSpreadsheetId(spreadsheetId);
|
|
199
|
+
const searchParams = new URLSearchParams();
|
|
200
|
+
for (const range of ranges) {
|
|
201
|
+
searchParams.append("ranges", range);
|
|
202
|
+
}
|
|
203
|
+
const url = `${BASE_URL}/${id}/values:batchGet?${searchParams.toString()}`;
|
|
204
|
+
const response = await authenticatedFetch(url);
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
const body = await response.text();
|
|
207
|
+
throw new Error(
|
|
208
|
+
`google-sheets: batchGetValues failed (${response.status}): ${body}`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return await response.json();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ../connectors/src/connector-onboarding.ts
|
|
217
|
+
var ConnectorOnboarding = class {
|
|
218
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
219
|
+
connectionSetupInstructions;
|
|
220
|
+
/** Phase 2: Data overview instructions */
|
|
221
|
+
dataOverviewInstructions;
|
|
222
|
+
constructor(config) {
|
|
223
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
224
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
225
|
+
}
|
|
226
|
+
getConnectionSetupPrompt(language) {
|
|
227
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
228
|
+
}
|
|
229
|
+
getDataOverviewInstructions(language) {
|
|
230
|
+
return this.dataOverviewInstructions[language];
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// ../connectors/src/connector-tool.ts
|
|
235
|
+
var ConnectorTool = class {
|
|
236
|
+
name;
|
|
237
|
+
description;
|
|
238
|
+
inputSchema;
|
|
239
|
+
outputSchema;
|
|
240
|
+
_execute;
|
|
241
|
+
constructor(config) {
|
|
242
|
+
this.name = config.name;
|
|
243
|
+
this.description = config.description;
|
|
244
|
+
this.inputSchema = config.inputSchema;
|
|
245
|
+
this.outputSchema = config.outputSchema;
|
|
246
|
+
this._execute = config.execute;
|
|
247
|
+
}
|
|
248
|
+
createTool(connections, config) {
|
|
249
|
+
return {
|
|
250
|
+
description: this.description,
|
|
251
|
+
inputSchema: this.inputSchema,
|
|
252
|
+
outputSchema: this.outputSchema,
|
|
253
|
+
execute: (input) => this._execute(input, connections, config)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// ../connectors/src/connector-plugin.ts
|
|
259
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
260
|
+
slug;
|
|
261
|
+
authType;
|
|
262
|
+
name;
|
|
263
|
+
description;
|
|
264
|
+
iconUrl;
|
|
265
|
+
parameters;
|
|
266
|
+
releaseFlag;
|
|
267
|
+
proxyPolicy;
|
|
268
|
+
experimentalAttributes;
|
|
269
|
+
onboarding;
|
|
270
|
+
systemPrompt;
|
|
271
|
+
tools;
|
|
272
|
+
query;
|
|
273
|
+
checkConnection;
|
|
274
|
+
constructor(config) {
|
|
275
|
+
this.slug = config.slug;
|
|
276
|
+
this.authType = config.authType;
|
|
277
|
+
this.name = config.name;
|
|
278
|
+
this.description = config.description;
|
|
279
|
+
this.iconUrl = config.iconUrl;
|
|
280
|
+
this.parameters = config.parameters;
|
|
281
|
+
this.releaseFlag = config.releaseFlag;
|
|
282
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
283
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
284
|
+
this.onboarding = config.onboarding;
|
|
285
|
+
this.systemPrompt = config.systemPrompt;
|
|
286
|
+
this.tools = config.tools;
|
|
287
|
+
this.query = config.query;
|
|
288
|
+
this.checkConnection = config.checkConnection;
|
|
289
|
+
}
|
|
290
|
+
get connectorKey() {
|
|
291
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create tools for connections that belong to this connector.
|
|
295
|
+
* Filters connections by connectorKey internally.
|
|
296
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
297
|
+
*/
|
|
298
|
+
createTools(connections, config) {
|
|
299
|
+
const myConnections = connections.filter(
|
|
300
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
301
|
+
);
|
|
302
|
+
const result = {};
|
|
303
|
+
for (const t of Object.values(this.tools)) {
|
|
304
|
+
result[`${this.connectorKey}_${t.name}`] = t.createTool(
|
|
305
|
+
myConnections,
|
|
306
|
+
config
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
static deriveKey(slug, authType) {
|
|
312
|
+
return authType ? `${slug}-${authType}` : slug;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// ../connectors/src/connectors/google-sheets/setup.ts
|
|
317
|
+
var googleSheetsOnboarding = new ConnectorOnboarding({
|
|
318
|
+
dataOverviewInstructions: {
|
|
319
|
+
en: `1. Call google-sheets_request with GET /{spreadsheetId} to get spreadsheet metadata (sheet names and properties)
|
|
320
|
+
2. Call google-sheets_request with GET /{spreadsheetId}/values/{sheetName}!A1:Z5 to sample data from key sheets`,
|
|
321
|
+
ja: `1. google-sheets_request \u3067 GET /{spreadsheetId} \u3092\u547C\u3073\u51FA\u3057\u3001\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\uFF08\u30B7\u30FC\u30C8\u540D\u3068\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09\u3092\u53D6\u5F97
|
|
322
|
+
2. google-sheets_request \u3067 GET /{spreadsheetId}/values/{sheetName}!A1:Z5 \u3092\u547C\u3073\u51FA\u3057\u3001\u4E3B\u8981\u30B7\u30FC\u30C8\u306E\u30C7\u30FC\u30BF\u3092\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0`
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ../connectors/src/connectors/google-sheets/tools/request.ts
|
|
327
|
+
import { z } from "zod";
|
|
328
|
+
var BASE_URL2 = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
329
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
330
|
+
var inputSchema = z.object({
|
|
331
|
+
toolUseIntent: z.string().optional().describe(
|
|
332
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
333
|
+
),
|
|
334
|
+
connectionId: z.string().describe("ID of the Google Sheets connection to use"),
|
|
335
|
+
method: z.enum(["GET"]).describe("HTTP method (read-only, GET only)"),
|
|
336
|
+
path: z.string().describe(
|
|
337
|
+
"API path appended to https://sheets.googleapis.com/v4/spreadsheets (e.g., '/{spreadsheetId}', '/{spreadsheetId}/values/Sheet1!A1:D10'). {spreadsheetId} is automatically replaced if a default is configured."
|
|
338
|
+
),
|
|
339
|
+
queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL")
|
|
340
|
+
});
|
|
341
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
342
|
+
z.object({
|
|
343
|
+
success: z.literal(true),
|
|
344
|
+
status: z.number(),
|
|
345
|
+
data: z.record(z.string(), z.unknown())
|
|
346
|
+
}),
|
|
347
|
+
z.object({
|
|
348
|
+
success: z.literal(false),
|
|
349
|
+
error: z.string()
|
|
350
|
+
})
|
|
351
|
+
]);
|
|
352
|
+
var requestTool = new ConnectorTool({
|
|
353
|
+
name: "request",
|
|
354
|
+
description: `Send authenticated GET requests to the Google Sheets API v4.
|
|
355
|
+
Authentication is handled automatically using a service account.
|
|
356
|
+
{spreadsheetId} in the path is automatically replaced with the connection's default spreadsheet ID if configured.`,
|
|
357
|
+
inputSchema,
|
|
358
|
+
outputSchema,
|
|
359
|
+
async execute({ connectionId, method, path: path2, queryParams }, connections) {
|
|
360
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
361
|
+
if (!connection2) {
|
|
362
|
+
return {
|
|
363
|
+
success: false,
|
|
364
|
+
error: `Connection ${connectionId} not found`
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
console.log(
|
|
368
|
+
`[connector-request] google-sheets/${connection2.name}: ${method} ${path2}`
|
|
369
|
+
);
|
|
370
|
+
try {
|
|
371
|
+
const { GoogleAuth } = await import("google-auth-library");
|
|
372
|
+
const keyJsonBase64 = parameters.serviceAccountKeyJsonBase64.getValue(connection2);
|
|
373
|
+
const spreadsheetId = parameters.spreadsheetId.tryGetValue(connection2);
|
|
374
|
+
const credentials = JSON.parse(
|
|
375
|
+
Buffer.from(keyJsonBase64, "base64").toString("utf-8")
|
|
376
|
+
);
|
|
377
|
+
const auth = new GoogleAuth({
|
|
378
|
+
credentials,
|
|
379
|
+
scopes: ["https://www.googleapis.com/auth/spreadsheets.readonly"]
|
|
380
|
+
});
|
|
381
|
+
const token = await auth.getAccessToken();
|
|
382
|
+
if (!token) {
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
error: "Failed to obtain access token"
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const resolvedPath = spreadsheetId ? path2.replace(/\{spreadsheetId\}/g, spreadsheetId) : path2;
|
|
389
|
+
let url = `${BASE_URL2}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
|
|
390
|
+
if (queryParams) {
|
|
391
|
+
const searchParams = new URLSearchParams(queryParams);
|
|
392
|
+
url += `?${searchParams.toString()}`;
|
|
393
|
+
}
|
|
394
|
+
const controller = new AbortController();
|
|
395
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
396
|
+
try {
|
|
397
|
+
const response = await fetch(url, {
|
|
398
|
+
method,
|
|
399
|
+
headers: {
|
|
400
|
+
Authorization: `Bearer ${token}`
|
|
401
|
+
},
|
|
402
|
+
signal: controller.signal
|
|
403
|
+
});
|
|
404
|
+
const data = await response.json();
|
|
405
|
+
if (!response.ok) {
|
|
406
|
+
const errorObj = data?.error;
|
|
407
|
+
return {
|
|
408
|
+
success: false,
|
|
409
|
+
error: errorObj?.message ?? `HTTP ${response.status} ${response.statusText}`
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return { success: true, status: response.status, data };
|
|
413
|
+
} finally {
|
|
414
|
+
clearTimeout(timeout);
|
|
415
|
+
}
|
|
416
|
+
} catch (err) {
|
|
417
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
418
|
+
return { success: false, error: msg };
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// ../connectors/src/connectors/google-sheets/index.ts
|
|
424
|
+
var tools = { request: requestTool };
|
|
425
|
+
var googleSheetsConnector = new ConnectorPlugin({
|
|
426
|
+
slug: "google-sheets",
|
|
427
|
+
authType: null,
|
|
428
|
+
name: "Google Sheets",
|
|
429
|
+
description: "Connect to Google Sheets for spreadsheet data access using a service account.",
|
|
430
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/1UPQuggyiZmbb26CuaSr2h/032770e8739b183fa00b7625f024e536/google-sheets.svg",
|
|
431
|
+
parameters,
|
|
432
|
+
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
433
|
+
onboarding: googleSheetsOnboarding,
|
|
434
|
+
systemPrompt: {
|
|
435
|
+
en: `### Tools
|
|
436
|
+
|
|
437
|
+
- \`google-sheets_request\`: The only way to call the Google Sheets API (read-only). Use it to get spreadsheet metadata, cell values, and batch values. Authentication is configured automatically via service account. The {spreadsheetId} placeholder in paths is automatically replaced with the configured default spreadsheet ID.
|
|
438
|
+
|
|
439
|
+
### Google Sheets API Reference
|
|
440
|
+
|
|
441
|
+
#### Available Endpoints
|
|
442
|
+
- GET \`/{spreadsheetId}\` \u2014 Get spreadsheet metadata (title, sheets, properties)
|
|
443
|
+
- GET \`/{spreadsheetId}/values/{range}\` \u2014 Get cell values for a range
|
|
444
|
+
- GET \`/{spreadsheetId}/values:batchGet?ranges={range1}&ranges={range2}\` \u2014 Get values for multiple ranges
|
|
445
|
+
|
|
446
|
+
### Range Notation (A1 notation)
|
|
447
|
+
- \`Sheet1!A1:D10\` \u2014 Specific range on Sheet1
|
|
448
|
+
- \`Sheet1!A:A\` \u2014 Entire column A on Sheet1
|
|
449
|
+
- \`Sheet1!1:3\` \u2014 Rows 1 to 3 on Sheet1
|
|
450
|
+
- \`Sheet1\` \u2014 All data on Sheet1
|
|
451
|
+
- \`A1:D10\` \u2014 Range on the first sheet (when only one sheet exists)
|
|
452
|
+
|
|
453
|
+
### Tips
|
|
454
|
+
- Use \`{spreadsheetId}\` placeholder in paths \u2014 it is automatically replaced with the configured default spreadsheet ID
|
|
455
|
+
- To explore a spreadsheet, first get metadata to see available sheet names
|
|
456
|
+
- Use \`valueRenderOption=FORMATTED_VALUE\` query param to get display values
|
|
457
|
+
- Use \`valueRenderOption=UNFORMATTED_VALUE\` for raw numeric values
|
|
458
|
+
- Use \`majorDimension=COLUMNS\` to get data organized by columns instead of rows
|
|
459
|
+
|
|
460
|
+
### Business Logic
|
|
461
|
+
|
|
462
|
+
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.
|
|
463
|
+
|
|
464
|
+
#### Example
|
|
465
|
+
|
|
466
|
+
\`\`\`ts
|
|
467
|
+
import { connection } from "@squadbase/vite-server/connectors/google-sheets";
|
|
468
|
+
|
|
469
|
+
const sheets = connection("<connectionId>");
|
|
470
|
+
|
|
471
|
+
// Get spreadsheet metadata
|
|
472
|
+
const metadata = await sheets.getSpreadsheet();
|
|
473
|
+
console.log(metadata.properties.title, metadata.sheets.map(s => s.properties.title));
|
|
474
|
+
|
|
475
|
+
// Get cell values
|
|
476
|
+
const values = await sheets.getValues("Sheet1!A1:D10");
|
|
477
|
+
console.log(values.values); // 2D array
|
|
478
|
+
|
|
479
|
+
// Get multiple ranges at once
|
|
480
|
+
const batch = await sheets.batchGetValues(["Sheet1!A1:B5", "Sheet2!A1:C3"]);
|
|
481
|
+
batch.valueRanges.forEach(vr => console.log(vr.range, vr.values));
|
|
482
|
+
\`\`\``,
|
|
483
|
+
ja: `### \u30C4\u30FC\u30EB
|
|
484
|
+
|
|
485
|
+
- \`google-sheets_request\`: Google Sheets API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\uFF08\u8AAD\u307F\u53D6\u308A\u5C02\u7528\uFF09\u3002\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3001\u30BB\u30EB\u5024\u3001\u30D0\u30C3\u30C1\u5024\u306E\u53D6\u5F97\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{spreadsheetId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002
|
|
486
|
+
|
|
487
|
+
### Google Sheets API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
488
|
+
|
|
489
|
+
#### \u5229\u7528\u53EF\u80FD\u306A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
|
|
490
|
+
- GET \`/{spreadsheetId}\` \u2014 \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\uFF08\u30BF\u30A4\u30C8\u30EB\u3001\u30B7\u30FC\u30C8\u3001\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09
|
|
491
|
+
- GET \`/{spreadsheetId}/values/{range}\` \u2014 \u7BC4\u56F2\u306E\u30BB\u30EB\u5024\u3092\u53D6\u5F97
|
|
492
|
+
- GET \`/{spreadsheetId}/values:batchGet?ranges={range1}&ranges={range2}\` \u2014 \u8907\u6570\u7BC4\u56F2\u306E\u5024\u3092\u53D6\u5F97
|
|
493
|
+
|
|
494
|
+
### \u7BC4\u56F2\u306E\u8868\u8A18\u6CD5\uFF08A1\u8868\u8A18\u6CD5\uFF09
|
|
495
|
+
- \`Sheet1!A1:D10\` \u2014 Sheet1\u4E0A\u306E\u7279\u5B9A\u7BC4\u56F2
|
|
496
|
+
- \`Sheet1!A:A\` \u2014 Sheet1\u306EA\u5217\u5168\u4F53
|
|
497
|
+
- \`Sheet1!1:3\` \u2014 Sheet1\u306E1\u884C\u76EE\u304B\u30893\u884C\u76EE
|
|
498
|
+
- \`Sheet1\` \u2014 Sheet1\u306E\u5168\u30C7\u30FC\u30BF
|
|
499
|
+
- \`A1:D10\` \u2014 \u6700\u521D\u306E\u30B7\u30FC\u30C8\u306E\u7BC4\u56F2\uFF08\u30B7\u30FC\u30C8\u304C1\u3064\u306E\u307F\u306E\u5834\u5408\uFF09
|
|
500
|
+
|
|
501
|
+
### \u30D2\u30F3\u30C8
|
|
502
|
+
- \u30D1\u30B9\u306B \`{spreadsheetId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u3092\u4F7F\u7528 \u2014 \u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8ID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059
|
|
503
|
+
- \u30B9\u30D7\u30EC\u30C3\u30C9\u30B7\u30FC\u30C8\u3092\u63A2\u7D22\u3059\u308B\u306B\u306F\u3001\u307E\u305A\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u3066\u5229\u7528\u53EF\u80FD\u306A\u30B7\u30FC\u30C8\u540D\u3092\u78BA\u8A8D\u3057\u307E\u3059
|
|
504
|
+
- \u8868\u793A\u5024\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`valueRenderOption=FORMATTED_VALUE\` \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u4F7F\u7528\u3057\u307E\u3059
|
|
505
|
+
- \u751F\u306E\u6570\u5024\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`valueRenderOption=UNFORMATTED_VALUE\` \u3092\u4F7F\u7528\u3057\u307E\u3059
|
|
506
|
+
- \u5217\u3054\u3068\u306B\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3059\u308B\u306B\u306F \`majorDimension=COLUMNS\` \u3092\u4F7F\u7528\u3057\u307E\u3059
|
|
507
|
+
|
|
508
|
+
### Business Logic
|
|
509
|
+
|
|
510
|
+
\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
|
|
511
|
+
|
|
512
|
+
#### Example
|
|
513
|
+
|
|
514
|
+
\`\`\`ts
|
|
515
|
+
import { connection } from "@squadbase/vite-server/connectors/google-sheets";
|
|
516
|
+
|
|
517
|
+
const sheets = connection("<connectionId>");
|
|
518
|
+
|
|
519
|
+
// Get spreadsheet metadata
|
|
520
|
+
const metadata = await sheets.getSpreadsheet();
|
|
521
|
+
console.log(metadata.properties.title, metadata.sheets.map(s => s.properties.title));
|
|
522
|
+
|
|
523
|
+
// Get cell values
|
|
524
|
+
const values = await sheets.getValues("Sheet1!A1:D10");
|
|
525
|
+
console.log(values.values); // 2D array
|
|
526
|
+
|
|
527
|
+
// Get multiple ranges at once
|
|
528
|
+
const batch = await sheets.batchGetValues(["Sheet1!A1:B5", "Sheet2!A1:C3"]);
|
|
529
|
+
batch.valueRanges.forEach(vr => console.log(vr.range, vr.values));
|
|
530
|
+
\`\`\``
|
|
531
|
+
},
|
|
532
|
+
tools
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// src/connectors/create-connector-sdk.ts
|
|
536
|
+
import { readFileSync } from "fs";
|
|
537
|
+
import path from "path";
|
|
538
|
+
|
|
539
|
+
// src/connector-client/env.ts
|
|
540
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
541
|
+
const envVarName = entry.envVars[key];
|
|
542
|
+
if (!envVarName) {
|
|
543
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
544
|
+
}
|
|
545
|
+
const value = process.env[envVarName];
|
|
546
|
+
if (!value) {
|
|
547
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
548
|
+
}
|
|
549
|
+
return value;
|
|
550
|
+
}
|
|
551
|
+
function resolveEnvVarOptional(entry, key) {
|
|
552
|
+
const envVarName = entry.envVars[key];
|
|
553
|
+
if (!envVarName) return void 0;
|
|
554
|
+
return process.env[envVarName] || void 0;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/connectors/create-connector-sdk.ts
|
|
558
|
+
function loadConnectionsSync() {
|
|
559
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
560
|
+
try {
|
|
561
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
562
|
+
return JSON.parse(raw);
|
|
563
|
+
} catch {
|
|
564
|
+
return {};
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
568
|
+
return (connectionId) => {
|
|
569
|
+
const connections = loadConnectionsSync();
|
|
570
|
+
const entry = connections[connectionId];
|
|
571
|
+
if (!entry) {
|
|
572
|
+
throw new Error(
|
|
573
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
const params = {};
|
|
582
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
583
|
+
if (param.required) {
|
|
584
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
585
|
+
} else {
|
|
586
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
587
|
+
if (val !== void 0) params[param.slug] = val;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return createClient2(params);
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/connectors/entries/google-sheets.ts
|
|
595
|
+
var connection = createConnectorSdk(googleSheetsConnector, createClient);
|
|
596
|
+
export {
|
|
597
|
+
connection
|
|
598
|
+
};
|
|
@@ -46,8 +46,8 @@ var ParameterDefinition = class {
|
|
|
46
46
|
var parameters = {
|
|
47
47
|
apiKey: new ParameterDefinition({
|
|
48
48
|
slug: "api-key",
|
|
49
|
-
name: "
|
|
50
|
-
description: "
|
|
49
|
+
name: "Personal Access Key",
|
|
50
|
+
description: "Your HubSpot Personal Access Key for authentication (starts with pat-).",
|
|
51
51
|
envVarBaseKey: "HUBSPOT_API_KEY",
|
|
52
52
|
type: "text",
|
|
53
53
|
secret: true,
|
|
@@ -237,6 +237,15 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
+
// ../connectors/src/auth-types.ts
|
|
241
|
+
var AUTH_TYPES = {
|
|
242
|
+
OAUTH: "oauth",
|
|
243
|
+
API_KEY: "api-key",
|
|
244
|
+
JWT: "jwt",
|
|
245
|
+
SERVICE_ACCOUNT: "service-account",
|
|
246
|
+
PAT: "pat"
|
|
247
|
+
};
|
|
248
|
+
|
|
240
249
|
// ../connectors/src/connectors/hubspot/setup.ts
|
|
241
250
|
var hubspotOnboarding = new ConnectorOnboarding({
|
|
242
251
|
dataOverviewInstructions: {
|
|
@@ -280,7 +289,7 @@ var outputSchema = z.discriminatedUnion("success", [
|
|
|
280
289
|
var requestTool = new ConnectorTool({
|
|
281
290
|
name: "request",
|
|
282
291
|
description: `Send authenticated requests to the HubSpot API.
|
|
283
|
-
Authentication is handled automatically using the
|
|
292
|
+
Authentication is handled automatically using the Personal Access Key (Bearer token).
|
|
284
293
|
Use this tool for all HubSpot API interactions: querying contacts, deals, companies, tickets, and other CRM objects.
|
|
285
294
|
Use the search endpoint (POST /crm/v3/objects/{objectType}/search) for complex queries with filters.`,
|
|
286
295
|
inputSchema,
|
|
@@ -331,9 +340,9 @@ Use the search endpoint (POST /crm/v3/objects/{objectType}/search) for complex q
|
|
|
331
340
|
var tools = { request: requestTool };
|
|
332
341
|
var hubspotConnector = new ConnectorPlugin({
|
|
333
342
|
slug: "hubspot",
|
|
334
|
-
authType:
|
|
343
|
+
authType: AUTH_TYPES.PAT,
|
|
335
344
|
name: "HubSpot",
|
|
336
|
-
description: "Connect to HubSpot CRM for contacts, deals, companies, and marketing data using a
|
|
345
|
+
description: "Connect to HubSpot CRM for contacts, deals, companies, and marketing data using a Personal Access Key.",
|
|
337
346
|
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/5UcSkKkzhUMA4RsM45ynuo/43b967e36915ca0fc5d277684b204320/hubspot.svg",
|
|
338
347
|
parameters,
|
|
339
348
|
releaseFlag: { dev1: true, dev2: false, prod: false },
|