@squadbase/vite-server 0.1.9-dev.d3c856d → 0.1.9-dev.e22f810

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.
@@ -0,0 +1,954 @@
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-search-console-oauth/parameters.ts
46
+ var parameters = {
47
+ siteUrl: new ParameterDefinition({
48
+ slug: "site-url",
49
+ name: "Default Site URL",
50
+ description: "The default Google Search Console site URL to use (e.g., 'https://example.com/' or a domain property like 'sc-domain:example.com'). Obtained from the listSites tool during setup.",
51
+ envVarBaseKey: "GOOGLE_SEARCH_CONSOLE_OAUTH_SITE_URL",
52
+ type: "text",
53
+ secret: false,
54
+ required: false
55
+ })
56
+ };
57
+
58
+ // ../connectors/src/connectors/google-search-console-oauth/sdk/index.ts
59
+ var BASE_URL = "https://searchconsole.googleapis.com/webmasters/v3";
60
+ function createClient(params, fetchFn = fetch) {
61
+ const defaultSiteUrl = params[parameters.siteUrl.slug];
62
+ function resolveSiteUrl(override) {
63
+ const url = override ?? defaultSiteUrl;
64
+ if (!url) {
65
+ throw new Error(
66
+ "google-search-console-oauth: siteUrl is required. Configure it via connection parameters or pass it as an argument."
67
+ );
68
+ }
69
+ return url;
70
+ }
71
+ return {
72
+ async request(path2, init) {
73
+ const resolvedPath = defaultSiteUrl ? path2.replace(/\{siteUrl\}/g, encodeURIComponent(defaultSiteUrl)) : path2;
74
+ const url = `${BASE_URL}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
75
+ return fetchFn(url, init);
76
+ },
77
+ async listSites() {
78
+ const response = await this.request("/sites", { method: "GET" });
79
+ if (!response.ok) {
80
+ const text = await response.text();
81
+ throw new Error(
82
+ `google-search-console-oauth: listSites failed (${response.status}): ${text}`
83
+ );
84
+ }
85
+ const data = await response.json();
86
+ return data.siteEntry ?? [];
87
+ },
88
+ async querySearchAnalytics(arg1, arg2) {
89
+ let siteUrlOverride;
90
+ let body;
91
+ if (typeof arg2 === "string") {
92
+ siteUrlOverride = arg2;
93
+ body = arg1;
94
+ } else {
95
+ const {
96
+ siteUrl: siteUrlField,
97
+ requestBody,
98
+ ...rest
99
+ } = arg1 ?? {};
100
+ siteUrlOverride = siteUrlField;
101
+ body = requestBody ?? rest;
102
+ }
103
+ if (!body || !body.startDate || !body.endDate) {
104
+ throw new Error(
105
+ "google-search-console-oauth: querySearchAnalytics requires startDate and endDate. Pass them either as `{ startDate, endDate, ... }` or wrapped in `{ requestBody: { startDate, endDate, ... } }`."
106
+ );
107
+ }
108
+ const url = resolveSiteUrl(siteUrlOverride);
109
+ const path2 = `/sites/${encodeURIComponent(url)}/searchAnalytics/query`;
110
+ const response = await this.request(path2, {
111
+ method: "POST",
112
+ headers: { "Content-Type": "application/json" },
113
+ body: JSON.stringify(body)
114
+ });
115
+ if (!response.ok) {
116
+ const text = await response.text();
117
+ throw new Error(
118
+ `google-search-console-oauth: querySearchAnalytics failed (${response.status}): ${text}`
119
+ );
120
+ }
121
+ return await response.json();
122
+ },
123
+ async listSitemaps(siteUrl) {
124
+ const url = resolveSiteUrl(siteUrl);
125
+ const path2 = `/sites/${encodeURIComponent(url)}/sitemaps`;
126
+ const response = await this.request(path2, { method: "GET" });
127
+ if (!response.ok) {
128
+ const text = await response.text();
129
+ throw new Error(
130
+ `google-search-console-oauth: listSitemaps failed (${response.status}): ${text}`
131
+ );
132
+ }
133
+ const data = await response.json();
134
+ return data.sitemap ?? [];
135
+ }
136
+ };
137
+ }
138
+
139
+ // ../connectors/src/connector-onboarding.ts
140
+ var ConnectorOnboarding = class {
141
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
142
+ connectionSetupInstructions;
143
+ /** Phase 2: Data overview instructions */
144
+ dataOverviewInstructions;
145
+ constructor(config) {
146
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
147
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
148
+ }
149
+ getConnectionSetupPrompt(language) {
150
+ return this.connectionSetupInstructions?.[language] ?? null;
151
+ }
152
+ getDataOverviewInstructions(language) {
153
+ return this.dataOverviewInstructions[language];
154
+ }
155
+ };
156
+
157
+ // ../connectors/src/connector-tool.ts
158
+ var ConnectorTool = class {
159
+ name;
160
+ description;
161
+ inputSchema;
162
+ outputSchema;
163
+ _execute;
164
+ constructor(config) {
165
+ this.name = config.name;
166
+ this.description = config.description;
167
+ this.inputSchema = config.inputSchema;
168
+ this.outputSchema = config.outputSchema;
169
+ this._execute = config.execute;
170
+ }
171
+ createTool(connections, config) {
172
+ return {
173
+ description: this.description,
174
+ inputSchema: this.inputSchema,
175
+ outputSchema: this.outputSchema,
176
+ execute: (input) => this._execute(input, connections, config)
177
+ };
178
+ }
179
+ };
180
+
181
+ // ../connectors/src/connector-plugin.ts
182
+ var ConnectorPlugin = class _ConnectorPlugin {
183
+ slug;
184
+ authType;
185
+ name;
186
+ description;
187
+ iconUrl;
188
+ parameters;
189
+ releaseFlag;
190
+ proxyPolicy;
191
+ experimentalAttributes;
192
+ categories;
193
+ onboarding;
194
+ systemPrompt;
195
+ tools;
196
+ query;
197
+ checkConnection;
198
+ constructor(config) {
199
+ this.slug = config.slug;
200
+ this.authType = config.authType;
201
+ this.name = config.name;
202
+ this.description = config.description;
203
+ this.iconUrl = config.iconUrl;
204
+ this.parameters = config.parameters;
205
+ this.releaseFlag = config.releaseFlag;
206
+ this.proxyPolicy = config.proxyPolicy;
207
+ this.experimentalAttributes = config.experimentalAttributes;
208
+ this.categories = config.categories ?? [];
209
+ this.onboarding = config.onboarding;
210
+ this.systemPrompt = config.systemPrompt;
211
+ this.tools = config.tools;
212
+ this.query = config.query;
213
+ this.checkConnection = config.checkConnection;
214
+ }
215
+ get connectorKey() {
216
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
217
+ }
218
+ /**
219
+ * Create tools for connections that belong to this connector.
220
+ * Filters connections by connectorKey internally.
221
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
222
+ */
223
+ createTools(connections, config, opts) {
224
+ const myConnections = connections.filter(
225
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
226
+ );
227
+ const result = {};
228
+ for (const t of Object.values(this.tools)) {
229
+ const tool = t.createTool(myConnections, config);
230
+ const originalToModelOutput = tool.toModelOutput;
231
+ result[`${this.connectorKey}_${t.name}`] = {
232
+ ...tool,
233
+ toModelOutput: async (options) => {
234
+ if (!originalToModelOutput) {
235
+ return opts.truncateOutput(options.output);
236
+ }
237
+ const modelOutput = await originalToModelOutput(options);
238
+ if (modelOutput.type === "text" || modelOutput.type === "json") {
239
+ return opts.truncateOutput(modelOutput.value);
240
+ }
241
+ return modelOutput;
242
+ }
243
+ };
244
+ }
245
+ return result;
246
+ }
247
+ static deriveKey(slug, authType) {
248
+ if (authType) return `${slug}-${authType}`;
249
+ const LEGACY_NULL_AUTH_TYPE_MAP = {
250
+ // user-password
251
+ "postgresql": "user-password",
252
+ "mysql": "user-password",
253
+ "clickhouse": "user-password",
254
+ "kintone": "user-password",
255
+ "squadbase-db": "user-password",
256
+ // service-account
257
+ "snowflake": "service-account",
258
+ "bigquery": "service-account",
259
+ "google-analytics": "service-account",
260
+ "google-calendar": "service-account",
261
+ "aws-athena": "service-account",
262
+ "redshift": "service-account",
263
+ // api-key
264
+ "databricks": "api-key",
265
+ "dbt": "api-key",
266
+ "airtable": "api-key",
267
+ "openai": "api-key",
268
+ "gemini": "api-key",
269
+ "anthropic": "api-key",
270
+ "wix-store": "api-key"
271
+ };
272
+ const fallbackAuthType = LEGACY_NULL_AUTH_TYPE_MAP[slug];
273
+ if (fallbackAuthType) return `${slug}-${fallbackAuthType}`;
274
+ return slug;
275
+ }
276
+ };
277
+
278
+ // ../connectors/src/auth-types.ts
279
+ var AUTH_TYPES = {
280
+ OAUTH: "oauth",
281
+ API_KEY: "api-key",
282
+ JWT: "jwt",
283
+ SERVICE_ACCOUNT: "service-account",
284
+ PAT: "pat",
285
+ USER_PASSWORD: "user-password"
286
+ };
287
+
288
+ // ../connectors/src/lib/normalize-path.ts
289
+ function normalizeRequestPath(path2, basePathSegment) {
290
+ let p = path2.trim();
291
+ if (!p.startsWith("/")) p = "/" + p;
292
+ if (p === basePathSegment || p.startsWith(basePathSegment + "/")) {
293
+ p = p.slice(basePathSegment.length) || "/";
294
+ }
295
+ return p;
296
+ }
297
+
298
+ // ../connectors/src/connectors/google-search-console-oauth/tools/list-sites.ts
299
+ import { z } from "zod";
300
+ var BASE_URL2 = "https://searchconsole.googleapis.com/webmasters/v3";
301
+ var REQUEST_TIMEOUT_MS = 6e4;
302
+ var cachedToken = null;
303
+ async function getProxyToken(config) {
304
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
305
+ return cachedToken.token;
306
+ }
307
+ const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
308
+ const res = await fetch(url, {
309
+ method: "POST",
310
+ headers: {
311
+ "Content-Type": "application/json",
312
+ "x-api-key": config.appApiKey,
313
+ "project-id": config.projectId
314
+ },
315
+ body: JSON.stringify({
316
+ sandboxId: config.sandboxId,
317
+ issuedBy: "coding-agent"
318
+ })
319
+ });
320
+ if (!res.ok) {
321
+ const errorText = await res.text().catch(() => res.statusText);
322
+ throw new Error(
323
+ `Failed to get proxy token: HTTP ${res.status} ${errorText}`
324
+ );
325
+ }
326
+ const data = await res.json();
327
+ cachedToken = {
328
+ token: data.token,
329
+ expiresAt: new Date(data.expiresAt).getTime()
330
+ };
331
+ return data.token;
332
+ }
333
+ var inputSchema = z.object({
334
+ toolUseIntent: z.string().optional().describe(
335
+ "Brief description of what you intend to accomplish with this tool call"
336
+ ),
337
+ connectionId: z.string().describe("ID of the Google Search Console OAuth connection to use")
338
+ });
339
+ var outputSchema = z.discriminatedUnion("success", [
340
+ z.object({
341
+ success: z.literal(true),
342
+ sites: z.array(
343
+ z.object({
344
+ siteUrl: z.string(),
345
+ permissionLevel: z.string()
346
+ })
347
+ )
348
+ }),
349
+ z.object({
350
+ success: z.literal(false),
351
+ error: z.string()
352
+ })
353
+ ]);
354
+ var listSitesTool = new ConnectorTool({
355
+ name: "listSites",
356
+ description: "List all Google Search Console sites accessible with the OAuth credentials. Returns each site's URL (URL-prefix property like 'https://example.com/' or domain property like 'sc-domain:example.com') and the user's permission level. Use during setup to discover available sites.",
357
+ inputSchema,
358
+ outputSchema,
359
+ async execute({ connectionId }, connections, config) {
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-search-console-oauth/${connection2.name}: listSites`
369
+ );
370
+ try {
371
+ const url = `${BASE_URL2}/sites`;
372
+ const token = await getProxyToken(config.oauthProxy);
373
+ const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
374
+ const controller = new AbortController();
375
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
376
+ try {
377
+ const response = await fetch(proxyUrl, {
378
+ method: "POST",
379
+ headers: {
380
+ "Content-Type": "application/json",
381
+ Authorization: `Bearer ${token}`
382
+ },
383
+ body: JSON.stringify({
384
+ url,
385
+ method: "GET"
386
+ }),
387
+ signal: controller.signal
388
+ });
389
+ const data = await response.json();
390
+ if (!response.ok) {
391
+ const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
392
+ return { success: false, error: errorMessage };
393
+ }
394
+ const siteEntry = data.siteEntry ?? [];
395
+ return {
396
+ success: true,
397
+ sites: siteEntry.map((s) => ({
398
+ siteUrl: s.siteUrl ?? "",
399
+ permissionLevel: s.permissionLevel ?? ""
400
+ }))
401
+ };
402
+ } finally {
403
+ clearTimeout(timeout);
404
+ }
405
+ } catch (err) {
406
+ const msg = err instanceof Error ? err.message : String(err);
407
+ return { success: false, error: msg };
408
+ }
409
+ }
410
+ });
411
+
412
+ // ../connectors/src/connectors/google-search-console-oauth/setup.ts
413
+ var listSitesToolName = `google-search-console-oauth_${listSitesTool.name}`;
414
+ var googleSearchConsoleOauthOnboarding = new ConnectorOnboarding({
415
+ connectionSetupInstructions: {
416
+ ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Search Console (OAuth) \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
417
+
418
+ 1. \`${listSitesToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001OAuth\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30B5\u30A4\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
419
+ 2. \u30B5\u30A4\u30C8\u306E\u9078\u629E:
420
+ - \u30B5\u30A4\u30C8\u304C **2\u4EF6\u4EE5\u4E0A**: \u300C\u4F7F\u7528\u3059\u308B\u30B5\u30A4\u30C8\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u300D\u3068\u30E6\u30FC\u30B6\u30FC\u306B\u4F1D\u3048\u305F\u4E0A\u3067\u3001\`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
421
+ - \`parameterSlug\`: \`"site-url"\`
422
+ - \`options\`: \u30B5\u30A4\u30C8\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u30B5\u30A4\u30C8URL (\u6A29\u9650: permissionLevel)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F \`siteUrl\`
423
+ - \u30B5\u30A4\u30C8\u304C **1\u4EF6\u306E\u307F**: \`updateConnectionParameters\` \u3067 \`value\` \u306B\u305D\u306E\u30B5\u30A4\u30C8URL\u3092\u76F4\u63A5\u6307\u5B9A\u3057\u3066\u4FDD\u5B58\u3059\u308B
424
+ - \u30B5\u30A4\u30C8\u304C **0\u4EF6**: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u4E2D\u65AD\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30B5\u30A4\u30C8\u304C\u306A\u3044\u65E8\u3092\u4F1D\u3048\u308B\uFF08Search Console\u3067\u30B5\u30A4\u30C8\u3092\u6240\u6709\u78BA\u8A8D\u3057\u3066\u304B\u3089\u518D\u8A66\u884C\u3059\u308B\u3088\u3046\u6848\u5185\uFF09
425
+ 3. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30B5\u30A4\u30C8\u306E \`label\` \u304C\u30E1\u30C3\u30BB\u30FC\u30B8\u3068\u3057\u3066\u5C4A\u304F\u306E\u3067\u3001\u6B21\u306E\u30B9\u30C6\u30C3\u30D7\u306B\u9032\u3080
426
+
427
+ #### \u5236\u7D04
428
+ - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306BSearch Analytics\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u306E\u307F
429
+ - \u30C4\u30FC\u30EB\u9593\u306F1\u6587\u3060\u3051\u66F8\u3044\u3066\u5373\u6B21\u306E\u30C4\u30FC\u30EB\u547C\u3073\u51FA\u3057\u3002\u4E0D\u8981\u306A\u8AAC\u660E\u306F\u7701\u7565\u3057\u3001\u52B9\u7387\u7684\u306B\u9032\u3081\u308B`,
430
+ en: `Follow these steps to set up the Google Search Console (OAuth) connection.
431
+
432
+ 1. Call \`${listSitesToolName}\` to get the list of sites accessible with the OAuth credentials
433
+ 2. Select a site:
434
+ - **2 or more sites**: Tell the user "Please select a site.", then call \`updateConnectionParameters\`:
435
+ - \`parameterSlug\`: \`"site-url"\`
436
+ - \`options\`: The site list. Each option's \`label\` should be \`siteUrl (permission: permissionLevel)\`, \`value\` should be the \`siteUrl\`
437
+ - **Only 1 site**: Call \`updateConnectionParameters\` directly with that site URL as \`value\`
438
+ - **0 sites**: Abort setup and inform the user that no accessible sites are available (advise them to verify ownership in Search Console and retry)
439
+ 3. The \`label\` of the user's selected site will arrive as a message. Proceed to the next step
440
+
441
+ #### Constraints
442
+ - **Do NOT fetch Search Analytics data during setup**. Only the metadata requests specified in the steps above are allowed
443
+ - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
444
+ },
445
+ dataOverviewInstructions: {
446
+ en: `1. Call google-search-console-oauth_request with GET /sites/{siteUrl} to fetch metadata for the configured site
447
+ 2. Call google-search-console-oauth_request with POST /sites/{siteUrl}/searchAnalytics/query and a small body \u2014 startDate/endDate covering the last 7 days, dimensions ["date"], rowLimit 7 \u2014 to verify that performance data is available`,
448
+ ja: `1. google-search-console-oauth_request \u3067 GET /sites/{siteUrl} \u3092\u547C\u3073\u51FA\u3057\u3001\u8A2D\u5B9A\u3055\u308C\u305F\u30B5\u30A4\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97
449
+ 2. google-search-console-oauth_request \u3067 POST /sites/{siteUrl}/searchAnalytics/query \u3092\u76F4\u8FD17\u65E5\u9593\u306E startDate/endDate\u3001dimensions ["date"]\u3001rowLimit 7 \u3067\u547C\u3073\u51FA\u3057\u3001\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u30C7\u30FC\u30BF\u306E\u53EF\u7528\u6027\u3092\u78BA\u8A8D`
450
+ }
451
+ });
452
+
453
+ // ../connectors/src/connectors/google-search-console-oauth/tools/request.ts
454
+ import { z as z2 } from "zod";
455
+ var BASE_HOST = "https://searchconsole.googleapis.com";
456
+ var BASE_PATH_SEGMENT = "/webmasters/v3";
457
+ var BASE_URL3 = `${BASE_HOST}${BASE_PATH_SEGMENT}`;
458
+ var REQUEST_TIMEOUT_MS2 = 6e4;
459
+ var cachedToken2 = null;
460
+ async function getProxyToken2(config) {
461
+ if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
462
+ return cachedToken2.token;
463
+ }
464
+ const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
465
+ const res = await fetch(url, {
466
+ method: "POST",
467
+ headers: {
468
+ "Content-Type": "application/json",
469
+ "x-api-key": config.appApiKey,
470
+ "project-id": config.projectId
471
+ },
472
+ body: JSON.stringify({
473
+ sandboxId: config.sandboxId,
474
+ issuedBy: "coding-agent"
475
+ })
476
+ });
477
+ if (!res.ok) {
478
+ const errorText = await res.text().catch(() => res.statusText);
479
+ throw new Error(
480
+ `Failed to get proxy token: HTTP ${res.status} ${errorText}`
481
+ );
482
+ }
483
+ const data = await res.json();
484
+ cachedToken2 = {
485
+ token: data.token,
486
+ expiresAt: new Date(data.expiresAt).getTime()
487
+ };
488
+ return data.token;
489
+ }
490
+ var inputSchema2 = z2.object({
491
+ toolUseIntent: z2.string().optional().describe(
492
+ "Brief description of what you intend to accomplish with this tool call"
493
+ ),
494
+ connectionId: z2.string().describe("ID of the Google Search Console OAuth connection to use"),
495
+ method: z2.enum(["GET", "POST", "PUT", "DELETE"]).describe(
496
+ "HTTP method. Use POST for searchAnalytics queries and sitemap submission, GET for listing/inspecting resources, PUT for sitemap upsert, DELETE for sitemap removal."
497
+ ),
498
+ path: z2.string().describe(
499
+ "API path appended to https://searchconsole.googleapis.com/webmasters/v3 (e.g., '/sites/{siteUrl}/searchAnalytics/query'). {siteUrl} is automatically replaced with the connection's default site URL and URL-encoded."
500
+ ),
501
+ queryParams: z2.record(z2.string(), z2.string()).optional().describe("Query parameters to append to the URL"),
502
+ body: z2.record(z2.string(), z2.unknown()).optional().describe("Request body (JSON) for POST/PUT methods")
503
+ });
504
+ var outputSchema2 = z2.discriminatedUnion("success", [
505
+ z2.object({
506
+ success: z2.literal(true),
507
+ status: z2.number(),
508
+ data: z2.record(z2.string(), z2.unknown())
509
+ }),
510
+ z2.object({
511
+ success: z2.literal(false),
512
+ error: z2.string()
513
+ })
514
+ ]);
515
+ var requestTool = new ConnectorTool({
516
+ name: "request",
517
+ description: `Send authenticated requests to the Google Search Console API (Webmasters v3).
518
+ Use this tool to query Search Analytics data (clicks, impressions, CTR, position), list/inspect sitemaps, and read site metadata.
519
+ Authentication is handled automatically via OAuth proxy.
520
+ {siteUrl} in the path is automatically replaced with the connection's default site URL and URL-encoded.
521
+ For URL Inspection API requests, use the absolute path '/v1/urlInspection/index:inspect' \u2014 the leading /webmasters/v3 prefix will be stripped if you accidentally include it.`,
522
+ inputSchema: inputSchema2,
523
+ outputSchema: outputSchema2,
524
+ async execute({ connectionId, method, path: path2, queryParams, body }, connections, config) {
525
+ const connection2 = connections.find((c) => c.id === connectionId);
526
+ if (!connection2) {
527
+ return {
528
+ success: false,
529
+ error: `Connection ${connectionId} not found`
530
+ };
531
+ }
532
+ console.log(
533
+ `[connector-request] google-search-console-oauth/${connection2.name}: ${method} ${path2}`
534
+ );
535
+ try {
536
+ const siteUrl = parameters.siteUrl.tryGetValue(connection2);
537
+ const resolvedPath = siteUrl ? path2.replace(/\{siteUrl\}/g, encodeURIComponent(siteUrl)) : path2;
538
+ const normalizedPath = normalizeRequestPath(
539
+ resolvedPath,
540
+ BASE_PATH_SEGMENT
541
+ );
542
+ let url = `${BASE_URL3}${normalizedPath}`;
543
+ if (queryParams) {
544
+ const searchParams = new URLSearchParams(queryParams);
545
+ url += `?${searchParams.toString()}`;
546
+ }
547
+ const token = await getProxyToken2(config.oauthProxy);
548
+ const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
549
+ const controller = new AbortController();
550
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
551
+ try {
552
+ const response = await fetch(proxyUrl, {
553
+ method: "POST",
554
+ headers: {
555
+ "Content-Type": "application/json",
556
+ Authorization: `Bearer ${token}`
557
+ },
558
+ body: JSON.stringify({
559
+ url,
560
+ method,
561
+ ...body && ["POST", "PUT"].includes(method) ? {
562
+ headers: { "Content-Type": "application/json" },
563
+ body: JSON.stringify(body)
564
+ } : {}
565
+ }),
566
+ signal: controller.signal
567
+ });
568
+ const data = await response.json();
569
+ if (!response.ok) {
570
+ const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
571
+ return { success: false, error: errorMessage };
572
+ }
573
+ return { success: true, status: response.status, data };
574
+ } finally {
575
+ clearTimeout(timeout);
576
+ }
577
+ } catch (err) {
578
+ const msg = err instanceof Error ? err.message : String(err);
579
+ return { success: false, error: msg };
580
+ }
581
+ }
582
+ });
583
+
584
+ // ../connectors/src/connectors/google-search-console-oauth/index.ts
585
+ var tools = {
586
+ request: requestTool,
587
+ listSites: listSitesTool
588
+ };
589
+ var googleSearchConsoleOauthConnector = new ConnectorPlugin({
590
+ slug: "google-search-console",
591
+ authType: AUTH_TYPES.OAUTH,
592
+ name: "Google Search Console",
593
+ description: "Connect to Google Search Console for search performance, indexing, and sitemap data using OAuth.",
594
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/3rPusKosno7i1emOCmskTp/9ed092a4dc95efb74e34e83098ef3905/google-search-console-icon.webp",
595
+ parameters,
596
+ releaseFlag: { dev1: true, dev2: true, prod: true },
597
+ categories: ["marketing"],
598
+ onboarding: googleSearchConsoleOauthOnboarding,
599
+ proxyPolicy: {
600
+ allowlist: [
601
+ {
602
+ host: "searchconsole.googleapis.com",
603
+ methods: ["GET", "POST", "PUT", "DELETE"]
604
+ }
605
+ ]
606
+ },
607
+ systemPrompt: {
608
+ en: `### Tools
609
+
610
+ - \`google-search-console-oauth_request\`: Send authenticated requests to the Google Search Console API (Webmasters v3). Use it for searchAnalytics queries, sitemap inspection, and site metadata. The {siteUrl} placeholder in paths is automatically replaced and URL-encoded. Authentication is configured automatically via OAuth.
611
+ - \`google-search-console-oauth_listSites\`: List accessible Search Console sites. Use during setup to discover available properties.
612
+
613
+ ### Search Console API Reference
614
+
615
+ #### Available Endpoints
616
+ - GET \`/sites\` \u2014 List sites accessible by the authenticated user
617
+ - GET \`/sites/{siteUrl}\` \u2014 Get a single site's metadata and permission level
618
+ - POST \`/sites/{siteUrl}/searchAnalytics/query\` \u2014 Query search performance data (clicks, impressions, CTR, position)
619
+ - GET \`/sites/{siteUrl}/sitemaps\` \u2014 List sitemaps submitted for a site
620
+ - GET \`/sites/{siteUrl}/sitemaps/{feedpath}\` \u2014 Get a single sitemap
621
+
622
+ #### searchAnalytics/query \u2014 Body
623
+ \`\`\`json
624
+ {
625
+ "startDate": "2024-01-01",
626
+ "endDate": "2024-01-31",
627
+ "dimensions": ["query", "page"],
628
+ "type": "web",
629
+ "rowLimit": 1000,
630
+ "startRow": 0
631
+ }
632
+ \`\`\`
633
+
634
+ #### Common Dimensions
635
+ \`query\`, \`page\`, \`country\`, \`device\`, \`date\`, \`searchAppearance\`
636
+
637
+ #### Common Metrics (returned automatically)
638
+ \`clicks\`, \`impressions\`, \`ctr\`, \`position\`
639
+
640
+ #### type values
641
+ \`web\` (default), \`image\`, \`video\`, \`news\`, \`discover\`, \`googleNews\`
642
+
643
+ #### siteUrl formats
644
+ - URL-prefix property: \`https://www.example.com/\` (must include protocol and trailing slash)
645
+ - Domain property: \`sc-domain:example.com\`
646
+
647
+ In paths, use the \`{siteUrl}\` placeholder \u2014 it is automatically URL-encoded with the connection's configured site.
648
+
649
+ #### Date format
650
+ \`YYYY-MM-DD\` (Pacific time zone). Search Console data has roughly a 2-day delay; query \`endDate\` no later than 2 days before today for stable results.
651
+
652
+ ### Business Logic
653
+
654
+ 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.
655
+
656
+ SDK surface (client created via \`connection(connectionId)\`):
657
+ - \`client.request(path, init?)\` \u2014 low-level authenticated fetch (\`path\` is appended to \`https://searchconsole.googleapis.com/webmasters/v3\`; \`{siteUrl}\` placeholders are auto-replaced and URL-encoded).
658
+ - \`client.listSites()\` \u2014 list sites accessible by the OAuth user.
659
+ - \`client.querySearchAnalytics(args)\` \u2014 query Search Analytics performance data. Pass a single object: \`{ startDate, endDate, dimensions?, rowLimit?, ... }\`. \`siteUrl\` may be set on the same object to override the connection default. The googleapis-style envelope \`{ siteUrl?, requestBody: { startDate, endDate, ... } }\` is also accepted. \`startDate\` and \`endDate\` (\`YYYY-MM-DD\`) are required.
660
+ - \`client.listSitemaps(siteUrl?)\` \u2014 list sitemaps submitted for a site.
661
+
662
+ 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.
663
+
664
+ #### Example
665
+
666
+ \`\`\`ts
667
+ import { connection } from "@squadbase/vite-server/connectors/google-search-console-oauth";
668
+
669
+ const gsc = connection("<connectionId>");
670
+
671
+ // List all accessible sites
672
+ const sites = await gsc.listSites();
673
+ console.log(sites.map(s => \`\${s.siteUrl} (\${s.permissionLevel})\`));
674
+
675
+ // Top queries for the last 28 days \u2014 flat shape (recommended)
676
+ const { rows } = await gsc.querySearchAnalytics({
677
+ startDate: "2024-01-01",
678
+ endDate: "2024-01-28",
679
+ dimensions: ["query"],
680
+ rowLimit: 100,
681
+ });
682
+ rows?.forEach(r => console.log(r.keys?.[0], r.clicks, r.impressions));
683
+
684
+ // Override the configured site (also accepts requestBody envelope)
685
+ await gsc.querySearchAnalytics({
686
+ siteUrl: "sc-domain:example.com",
687
+ requestBody: { startDate: "2024-01-01", endDate: "2024-01-28", dimensions: ["page"] },
688
+ });
689
+
690
+ // List sitemaps
691
+ const sitemaps = await gsc.listSitemaps();
692
+ sitemaps.forEach(s => console.log(s.path, s.lastSubmitted));
693
+ \`\`\``,
694
+ ja: `### \u30C4\u30FC\u30EB
695
+
696
+ - \`google-search-console-oauth_request\`: Google Search Console API (Webmasters v3) \u3078\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002searchAnalytics \u30AF\u30A8\u30EA\u3001\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u78BA\u8A8D\u3001\u30B5\u30A4\u30C8\u30E1\u30BF\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{siteUrl}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u81EA\u52D5\u7684\u306BURL\u30A8\u30F3\u30B3\u30FC\u30C9\u3055\u308C\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
697
+ - \`google-search-console-oauth_listSites\`: \u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306ASearch Console\u30B5\u30A4\u30C8\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u6642\u306B\u5229\u7528\u53EF\u80FD\u306A\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u78BA\u8A8D\u3059\u308B\u305F\u3081\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002
698
+
699
+ ### Search Console API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
700
+
701
+ #### \u5229\u7528\u53EF\u80FD\u306A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
702
+ - GET \`/sites\` \u2014 \u8A8D\u8A3C\u30E6\u30FC\u30B6\u30FC\u304C\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u5168\u30B5\u30A4\u30C8\u306E\u4E00\u89A7
703
+ - GET \`/sites/{siteUrl}\` \u2014 \u5358\u4E00\u30B5\u30A4\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3068\u6A29\u9650\u3092\u53D6\u5F97
704
+ - POST \`/sites/{siteUrl}/searchAnalytics/query\` \u2014 \u691C\u7D22\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u30C7\u30FC\u30BF\uFF08clicks, impressions, CTR, position\uFF09\u306E\u53D6\u5F97
705
+ - GET \`/sites/{siteUrl}/sitemaps\` \u2014 \u30B5\u30A4\u30C8\u306B\u63D0\u51FA\u6E08\u307F\u306E\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u4E00\u89A7
706
+ - GET \`/sites/{siteUrl}/sitemaps/{feedpath}\` \u2014 \u5358\u4E00\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u306E\u53D6\u5F97
707
+
708
+ #### searchAnalytics/query \u2014 Body\u4F8B
709
+ \`\`\`json
710
+ {
711
+ "startDate": "2024-01-01",
712
+ "endDate": "2024-01-31",
713
+ "dimensions": ["query", "page"],
714
+ "type": "web",
715
+ "rowLimit": 1000,
716
+ "startRow": 0
717
+ }
718
+ \`\`\`
719
+
720
+ #### \u4E3B\u8981\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3
721
+ \`query\`, \`page\`, \`country\`, \`device\`, \`date\`, \`searchAppearance\`
722
+
723
+ #### \u4E3B\u8981\u306A\u30E1\u30C8\u30EA\u30AF\u30B9\uFF08\u81EA\u52D5\u7684\u306B\u8FD4\u5374\u3055\u308C\u308B\uFF09
724
+ \`clicks\`, \`impressions\`, \`ctr\`, \`position\`
725
+
726
+ #### type \u306E\u5024
727
+ \`web\`\uFF08\u30C7\u30D5\u30A9\u30EB\u30C8\uFF09, \`image\`, \`video\`, \`news\`, \`discover\`, \`googleNews\`
728
+
729
+ #### siteUrl \u306E\u5F62\u5F0F
730
+ - URL\u30D7\u30EC\u30D5\u30A3\u30C3\u30AF\u30B9\u30D7\u30ED\u30D1\u30C6\u30A3: \`https://www.example.com/\`\uFF08\u30D7\u30ED\u30C8\u30B3\u30EB\u3068\u672B\u5C3E\u30B9\u30E9\u30C3\u30B7\u30E5\u304C\u5FC5\u9808\uFF09
731
+ - \u30C9\u30E1\u30A4\u30F3\u30D7\u30ED\u30D1\u30C6\u30A3: \`sc-domain:example.com\`
732
+
733
+ \u30D1\u30B9\u3067\u306F \`{siteUrl}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u8A2D\u5B9A\u3055\u308C\u305F\u30B5\u30A4\u30C8\u3067\u81EA\u52D5\u7684\u306BURL\u30A8\u30F3\u30B3\u30FC\u30C9\u3055\u308C\u307E\u3059\u3002
734
+
735
+ #### \u65E5\u4ED8\u5F62\u5F0F
736
+ \`YYYY-MM-DD\`\uFF08\u592A\u5E73\u6D0B\u6642\u9593\uFF09\u3002Search Console \u306E\u30C7\u30FC\u30BF\u306F\u7D042\u65E5\u306E\u9045\u5EF6\u304C\u3042\u308B\u305F\u3081\u3001\u5B89\u5B9A\u3057\u305F\u7D50\u679C\u3092\u5F97\u308B\u306B\u306F \`endDate\` \u3092\u672C\u65E5\u306E2\u65E5\u524D\u4EE5\u524D\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002
737
+
738
+ ### Business Logic
739
+
740
+ \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
741
+
742
+ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
743
+ - \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304D fetch\uFF08\`path\` \u306F \`https://searchconsole.googleapis.com/webmasters/v3\` \u306B\u8FFD\u52A0\u3055\u308C\u3001\`{siteUrl}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u306F\u81EA\u52D5\u7684\u306BURL\u30A8\u30F3\u30B3\u30FC\u30C9\u3055\u308C\u7F6E\u63DB\u3055\u308C\u307E\u3059\uFF09\u3002
744
+ - \`client.listSites()\` \u2014 OAuth \u30E6\u30FC\u30B6\u30FC\u304C\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30B5\u30A4\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3002
745
+ - \`client.querySearchAnalytics(args)\` \u2014 \u691C\u7D22\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3002\u5F15\u6570\u306F\u5358\u4E00\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067 \`{ startDate, endDate, dimensions?, rowLimit?, ... }\` \u3092\u6E21\u3057\u307E\u3059\u3002\`siteUrl\` \u3092\u540C\u3058\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B\u542B\u3081\u308B\u3068\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u3092\u4E0A\u66F8\u304D\u3067\u304D\u307E\u3059\u3002googleapis \u5F62\u5F0F\u306E \`{ siteUrl?, requestBody: { startDate, endDate, ... } }\` \u3082\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002\`startDate\` \u3068 \`endDate\`\uFF08\`YYYY-MM-DD\` \u5F62\u5F0F\uFF09\u306F\u5FC5\u9808\u3067\u3059\u3002
746
+ - \`client.listSitemaps(siteUrl?)\` \u2014 \u30B5\u30A4\u30C8\u306B\u63D0\u51FA\u6E08\u307F\u306E\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u4E00\u89A7\u3092\u53D6\u5F97\u3002
747
+
748
+ \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
749
+
750
+ #### Example
751
+
752
+ \`\`\`ts
753
+ import { connection } from "@squadbase/vite-server/connectors/google-search-console-oauth";
754
+
755
+ const gsc = connection("<connectionId>");
756
+
757
+ // List all accessible sites
758
+ const sites = await gsc.listSites();
759
+ console.log(sites.map(s => \`\${s.siteUrl} (\${s.permissionLevel})\`));
760
+
761
+ // Top queries for the last 28 days \u2014 \u30D5\u30E9\u30C3\u30C8\u5F62\u5F0F\uFF08\u63A8\u5968\uFF09
762
+ const { rows } = await gsc.querySearchAnalytics({
763
+ startDate: "2024-01-01",
764
+ endDate: "2024-01-28",
765
+ dimensions: ["query"],
766
+ rowLimit: 100,
767
+ });
768
+ rows?.forEach(r => console.log(r.keys?.[0], r.clicks, r.impressions));
769
+
770
+ // siteUrl \u3092\u4E0A\u66F8\u304D\u3059\u308B\u5834\u5408\uFF08requestBody \u30A8\u30F3\u30D9\u30ED\u30FC\u30D7\u3082\u53EF\uFF09
771
+ await gsc.querySearchAnalytics({
772
+ siteUrl: "sc-domain:example.com",
773
+ requestBody: { startDate: "2024-01-01", endDate: "2024-01-28", dimensions: ["page"] },
774
+ });
775
+
776
+ // List sitemaps
777
+ const sitemaps = await gsc.listSitemaps();
778
+ sitemaps.forEach(s => console.log(s.path, s.lastSubmitted));
779
+ \`\`\``
780
+ },
781
+ tools,
782
+ async checkConnection(params, config) {
783
+ const { proxyFetch } = config;
784
+ const siteUrl = params[parameters.siteUrl.slug];
785
+ const url = siteUrl ? `https://searchconsole.googleapis.com/webmasters/v3/sites/${encodeURIComponent(siteUrl)}` : `https://searchconsole.googleapis.com/webmasters/v3/sites`;
786
+ try {
787
+ const res = await proxyFetch(url, { method: "GET" });
788
+ if (!res.ok) {
789
+ const errorText = await res.text().catch(() => res.statusText);
790
+ return {
791
+ success: false,
792
+ error: `Google Search Console API failed: HTTP ${res.status} ${errorText}`
793
+ };
794
+ }
795
+ return { success: true };
796
+ } catch (error) {
797
+ return {
798
+ success: false,
799
+ error: error instanceof Error ? error.message : String(error)
800
+ };
801
+ }
802
+ }
803
+ });
804
+
805
+ // src/connectors/create-connector-sdk.ts
806
+ import { readFileSync } from "fs";
807
+ import path from "path";
808
+
809
+ // src/connector-client/env.ts
810
+ function resolveEnvVar(entry, key, connectionId) {
811
+ const envVarName = entry.envVars[key];
812
+ if (!envVarName) {
813
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
814
+ }
815
+ const value = process.env[envVarName];
816
+ if (!value) {
817
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
818
+ }
819
+ return value;
820
+ }
821
+ function resolveEnvVarOptional(entry, key) {
822
+ const envVarName = entry.envVars[key];
823
+ if (!envVarName) return void 0;
824
+ return process.env[envVarName] || void 0;
825
+ }
826
+
827
+ // src/connector-client/proxy-fetch.ts
828
+ import { getContext } from "hono/context-storage";
829
+ import { getCookie } from "hono/cookie";
830
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
831
+ function normalizeHeaders(input) {
832
+ const out = {};
833
+ if (!input) return out;
834
+ new Headers(input).forEach((value, key) => {
835
+ out[key] = value;
836
+ });
837
+ return out;
838
+ }
839
+ function createSandboxProxyFetch(connectionId) {
840
+ return async (input, init) => {
841
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
842
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
843
+ if (!token || !sandboxId) {
844
+ throw new Error(
845
+ "Connection proxy is not configured. Please check your deployment settings."
846
+ );
847
+ }
848
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
849
+ const originalMethod = init?.method ?? "GET";
850
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
851
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
852
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
853
+ return fetch(proxyUrl, {
854
+ method: "POST",
855
+ headers: {
856
+ "Content-Type": "application/json",
857
+ Authorization: `Bearer ${token}`
858
+ },
859
+ body: JSON.stringify({
860
+ url: originalUrl,
861
+ method: originalMethod,
862
+ headers: normalizeHeaders(init?.headers),
863
+ body: originalBody
864
+ })
865
+ });
866
+ };
867
+ }
868
+ function createDeployedAppProxyFetch(connectionId) {
869
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
870
+ if (!projectId) {
871
+ throw new Error(
872
+ "Connection proxy is not configured. Please check your deployment settings."
873
+ );
874
+ }
875
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
876
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
877
+ return async (input, init) => {
878
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
879
+ const originalMethod = init?.method ?? "GET";
880
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
881
+ const c = getContext();
882
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
883
+ if (!appSession) {
884
+ throw new Error(
885
+ "No authentication method available for connection proxy."
886
+ );
887
+ }
888
+ return fetch(proxyUrl, {
889
+ method: "POST",
890
+ headers: {
891
+ "Content-Type": "application/json",
892
+ Authorization: `Bearer ${appSession}`
893
+ },
894
+ body: JSON.stringify({
895
+ url: originalUrl,
896
+ method: originalMethod,
897
+ headers: normalizeHeaders(init?.headers),
898
+ body: originalBody
899
+ })
900
+ });
901
+ };
902
+ }
903
+ function createProxyFetch(connectionId) {
904
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
905
+ return createSandboxProxyFetch(connectionId);
906
+ }
907
+ return createDeployedAppProxyFetch(connectionId);
908
+ }
909
+
910
+ // src/connectors/create-connector-sdk.ts
911
+ function loadConnectionsSync() {
912
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
913
+ try {
914
+ const raw = readFileSync(filePath, "utf-8");
915
+ return JSON.parse(raw);
916
+ } catch {
917
+ return {};
918
+ }
919
+ }
920
+ function createConnectorSdk(plugin, createClient2) {
921
+ return (connectionId) => {
922
+ const connections = loadConnectionsSync();
923
+ const entry = connections[connectionId];
924
+ if (!entry) {
925
+ throw new Error(
926
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
927
+ );
928
+ }
929
+ if (entry.connector.slug !== plugin.slug) {
930
+ throw new Error(
931
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
932
+ );
933
+ }
934
+ const params = {};
935
+ for (const param of Object.values(plugin.parameters)) {
936
+ if (param.required) {
937
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
938
+ } else {
939
+ const val = resolveEnvVarOptional(entry, param.slug);
940
+ if (val !== void 0) params[param.slug] = val;
941
+ }
942
+ }
943
+ return createClient2(params, createProxyFetch(connectionId));
944
+ };
945
+ }
946
+
947
+ // src/connectors/entries/google-search-console-oauth.ts
948
+ var connection = createConnectorSdk(
949
+ googleSearchConsoleOauthConnector,
950
+ createClient
951
+ );
952
+ export {
953
+ connection
954
+ };