@squadbase/vite-server 0.1.9-dev.87dd3f7 → 0.1.9-dev.a120137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cli/index.js +73157 -60061
  2. package/dist/connectors/asana.js +15 -2
  3. package/dist/connectors/aws-billing.d.ts +5 -0
  4. package/dist/connectors/aws-billing.js +29843 -0
  5. package/dist/connectors/azure-sql.d.ts +5 -0
  6. package/dist/connectors/azure-sql.js +657 -0
  7. package/dist/connectors/clickup.d.ts +5 -0
  8. package/dist/connectors/clickup.js +850 -0
  9. package/dist/connectors/freshdesk.d.ts +5 -0
  10. package/dist/connectors/freshdesk.js +842 -0
  11. package/dist/connectors/freshsales.d.ts +5 -0
  12. package/dist/connectors/freshsales.js +867 -0
  13. package/dist/connectors/freshservice.d.ts +5 -0
  14. package/dist/connectors/freshservice.js +813 -0
  15. package/dist/connectors/github.d.ts +5 -0
  16. package/dist/connectors/github.js +963 -0
  17. package/dist/connectors/gmail-oauth.js +15 -2
  18. package/dist/connectors/gmail.js +23 -14
  19. package/dist/connectors/google-audit-log.js +25 -14
  20. package/dist/connectors/google-calendar-oauth.js +18 -2
  21. package/dist/connectors/google-calendar.js +40 -26
  22. package/dist/connectors/google-docs.js +18 -2
  23. package/dist/connectors/google-drive.js +15 -2
  24. package/dist/connectors/google-search-console-oauth.d.ts +5 -0
  25. package/dist/connectors/google-search-console-oauth.js +923 -0
  26. package/dist/connectors/google-sheets.js +18 -2
  27. package/dist/connectors/google-slides.js +18 -2
  28. package/dist/connectors/jdbc.d.ts +5 -0
  29. package/dist/connectors/jdbc.js +21097 -0
  30. package/dist/connectors/monday.d.ts +5 -0
  31. package/dist/connectors/monday.js +853 -0
  32. package/dist/connectors/oracle.d.ts +5 -0
  33. package/dist/connectors/oracle.js +665 -0
  34. package/dist/connectors/semrush.d.ts +5 -0
  35. package/dist/connectors/semrush.js +812 -0
  36. package/dist/connectors/sqlserver.d.ts +5 -0
  37. package/dist/connectors/sqlserver.js +656 -0
  38. package/dist/connectors/supabase.d.ts +5 -0
  39. package/dist/connectors/supabase.js +582 -0
  40. package/dist/connectors/tiktok-ads.js +15 -2
  41. package/dist/index.js +73218 -60122
  42. package/dist/main.js +73212 -60116
  43. package/dist/vite-plugin.js +73118 -60022
  44. package/package.json +60 -2
@@ -0,0 +1,923 @@
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(request, siteUrl) {
89
+ const url = resolveSiteUrl(siteUrl);
90
+ const path2 = `/sites/${encodeURIComponent(url)}/searchAnalytics/query`;
91
+ const response = await this.request(path2, {
92
+ method: "POST",
93
+ headers: { "Content-Type": "application/json" },
94
+ body: JSON.stringify(request)
95
+ });
96
+ if (!response.ok) {
97
+ const text = await response.text();
98
+ throw new Error(
99
+ `google-search-console-oauth: querySearchAnalytics failed (${response.status}): ${text}`
100
+ );
101
+ }
102
+ return await response.json();
103
+ },
104
+ async listSitemaps(siteUrl) {
105
+ const url = resolveSiteUrl(siteUrl);
106
+ const path2 = `/sites/${encodeURIComponent(url)}/sitemaps`;
107
+ const response = await this.request(path2, { method: "GET" });
108
+ if (!response.ok) {
109
+ const text = await response.text();
110
+ throw new Error(
111
+ `google-search-console-oauth: listSitemaps failed (${response.status}): ${text}`
112
+ );
113
+ }
114
+ const data = await response.json();
115
+ return data.sitemap ?? [];
116
+ }
117
+ };
118
+ }
119
+
120
+ // ../connectors/src/connector-onboarding.ts
121
+ var ConnectorOnboarding = class {
122
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
123
+ connectionSetupInstructions;
124
+ /** Phase 2: Data overview instructions */
125
+ dataOverviewInstructions;
126
+ constructor(config) {
127
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
128
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
129
+ }
130
+ getConnectionSetupPrompt(language) {
131
+ return this.connectionSetupInstructions?.[language] ?? null;
132
+ }
133
+ getDataOverviewInstructions(language) {
134
+ return this.dataOverviewInstructions[language];
135
+ }
136
+ };
137
+
138
+ // ../connectors/src/connector-tool.ts
139
+ var ConnectorTool = class {
140
+ name;
141
+ description;
142
+ inputSchema;
143
+ outputSchema;
144
+ _execute;
145
+ constructor(config) {
146
+ this.name = config.name;
147
+ this.description = config.description;
148
+ this.inputSchema = config.inputSchema;
149
+ this.outputSchema = config.outputSchema;
150
+ this._execute = config.execute;
151
+ }
152
+ createTool(connections, config) {
153
+ return {
154
+ description: this.description,
155
+ inputSchema: this.inputSchema,
156
+ outputSchema: this.outputSchema,
157
+ execute: (input) => this._execute(input, connections, config)
158
+ };
159
+ }
160
+ };
161
+
162
+ // ../connectors/src/connector-plugin.ts
163
+ var ConnectorPlugin = class _ConnectorPlugin {
164
+ slug;
165
+ authType;
166
+ name;
167
+ description;
168
+ iconUrl;
169
+ parameters;
170
+ releaseFlag;
171
+ proxyPolicy;
172
+ experimentalAttributes;
173
+ categories;
174
+ onboarding;
175
+ systemPrompt;
176
+ tools;
177
+ query;
178
+ checkConnection;
179
+ constructor(config) {
180
+ this.slug = config.slug;
181
+ this.authType = config.authType;
182
+ this.name = config.name;
183
+ this.description = config.description;
184
+ this.iconUrl = config.iconUrl;
185
+ this.parameters = config.parameters;
186
+ this.releaseFlag = config.releaseFlag;
187
+ this.proxyPolicy = config.proxyPolicy;
188
+ this.experimentalAttributes = config.experimentalAttributes;
189
+ this.categories = config.categories ?? [];
190
+ this.onboarding = config.onboarding;
191
+ this.systemPrompt = config.systemPrompt;
192
+ this.tools = config.tools;
193
+ this.query = config.query;
194
+ this.checkConnection = config.checkConnection;
195
+ }
196
+ get connectorKey() {
197
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
198
+ }
199
+ /**
200
+ * Create tools for connections that belong to this connector.
201
+ * Filters connections by connectorKey internally.
202
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
203
+ */
204
+ createTools(connections, config, opts) {
205
+ const myConnections = connections.filter(
206
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
207
+ );
208
+ const result = {};
209
+ for (const t of Object.values(this.tools)) {
210
+ const tool = t.createTool(myConnections, config);
211
+ const originalToModelOutput = tool.toModelOutput;
212
+ result[`${this.connectorKey}_${t.name}`] = {
213
+ ...tool,
214
+ toModelOutput: async (options) => {
215
+ if (!originalToModelOutput) {
216
+ return opts.truncateOutput(options.output);
217
+ }
218
+ const modelOutput = await originalToModelOutput(options);
219
+ if (modelOutput.type === "text" || modelOutput.type === "json") {
220
+ return opts.truncateOutput(modelOutput.value);
221
+ }
222
+ return modelOutput;
223
+ }
224
+ };
225
+ }
226
+ return result;
227
+ }
228
+ static deriveKey(slug, authType) {
229
+ if (authType) return `${slug}-${authType}`;
230
+ const LEGACY_NULL_AUTH_TYPE_MAP = {
231
+ // user-password
232
+ "postgresql": "user-password",
233
+ "mysql": "user-password",
234
+ "clickhouse": "user-password",
235
+ "kintone": "user-password",
236
+ "squadbase-db": "user-password",
237
+ // service-account
238
+ "snowflake": "service-account",
239
+ "bigquery": "service-account",
240
+ "google-analytics": "service-account",
241
+ "google-calendar": "service-account",
242
+ "aws-athena": "service-account",
243
+ "redshift": "service-account",
244
+ // api-key
245
+ "databricks": "api-key",
246
+ "dbt": "api-key",
247
+ "airtable": "api-key",
248
+ "openai": "api-key",
249
+ "gemini": "api-key",
250
+ "anthropic": "api-key",
251
+ "wix-store": "api-key"
252
+ };
253
+ const fallbackAuthType = LEGACY_NULL_AUTH_TYPE_MAP[slug];
254
+ if (fallbackAuthType) return `${slug}-${fallbackAuthType}`;
255
+ return slug;
256
+ }
257
+ };
258
+
259
+ // ../connectors/src/auth-types.ts
260
+ var AUTH_TYPES = {
261
+ OAUTH: "oauth",
262
+ API_KEY: "api-key",
263
+ JWT: "jwt",
264
+ SERVICE_ACCOUNT: "service-account",
265
+ PAT: "pat",
266
+ USER_PASSWORD: "user-password"
267
+ };
268
+
269
+ // ../connectors/src/lib/normalize-path.ts
270
+ function normalizeRequestPath(path2, basePathSegment) {
271
+ let p = path2.trim();
272
+ if (!p.startsWith("/")) p = "/" + p;
273
+ if (p === basePathSegment || p.startsWith(basePathSegment + "/")) {
274
+ p = p.slice(basePathSegment.length) || "/";
275
+ }
276
+ return p;
277
+ }
278
+
279
+ // ../connectors/src/connectors/google-search-console-oauth/tools/list-sites.ts
280
+ import { z } from "zod";
281
+ var BASE_URL2 = "https://searchconsole.googleapis.com/webmasters/v3";
282
+ var REQUEST_TIMEOUT_MS = 6e4;
283
+ var cachedToken = null;
284
+ async function getProxyToken(config) {
285
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
286
+ return cachedToken.token;
287
+ }
288
+ const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
289
+ const res = await fetch(url, {
290
+ method: "POST",
291
+ headers: {
292
+ "Content-Type": "application/json",
293
+ "x-api-key": config.appApiKey,
294
+ "project-id": config.projectId
295
+ },
296
+ body: JSON.stringify({
297
+ sandboxId: config.sandboxId,
298
+ issuedBy: "coding-agent"
299
+ })
300
+ });
301
+ if (!res.ok) {
302
+ const errorText = await res.text().catch(() => res.statusText);
303
+ throw new Error(
304
+ `Failed to get proxy token: HTTP ${res.status} ${errorText}`
305
+ );
306
+ }
307
+ const data = await res.json();
308
+ cachedToken = {
309
+ token: data.token,
310
+ expiresAt: new Date(data.expiresAt).getTime()
311
+ };
312
+ return data.token;
313
+ }
314
+ var inputSchema = z.object({
315
+ toolUseIntent: z.string().optional().describe(
316
+ "Brief description of what you intend to accomplish with this tool call"
317
+ ),
318
+ connectionId: z.string().describe("ID of the Google Search Console OAuth connection to use")
319
+ });
320
+ var outputSchema = z.discriminatedUnion("success", [
321
+ z.object({
322
+ success: z.literal(true),
323
+ sites: z.array(
324
+ z.object({
325
+ siteUrl: z.string(),
326
+ permissionLevel: z.string()
327
+ })
328
+ )
329
+ }),
330
+ z.object({
331
+ success: z.literal(false),
332
+ error: z.string()
333
+ })
334
+ ]);
335
+ var listSitesTool = new ConnectorTool({
336
+ name: "listSites",
337
+ 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.",
338
+ inputSchema,
339
+ outputSchema,
340
+ async execute({ connectionId }, connections, config) {
341
+ const connection2 = connections.find((c) => c.id === connectionId);
342
+ if (!connection2) {
343
+ return {
344
+ success: false,
345
+ error: `Connection ${connectionId} not found`
346
+ };
347
+ }
348
+ console.log(
349
+ `[connector-request] google-search-console-oauth/${connection2.name}: listSites`
350
+ );
351
+ try {
352
+ const url = `${BASE_URL2}/sites`;
353
+ const token = await getProxyToken(config.oauthProxy);
354
+ const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
355
+ const controller = new AbortController();
356
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
357
+ try {
358
+ const response = await fetch(proxyUrl, {
359
+ method: "POST",
360
+ headers: {
361
+ "Content-Type": "application/json",
362
+ Authorization: `Bearer ${token}`
363
+ },
364
+ body: JSON.stringify({
365
+ url,
366
+ method: "GET"
367
+ }),
368
+ signal: controller.signal
369
+ });
370
+ const data = await response.json();
371
+ if (!response.ok) {
372
+ const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
373
+ return { success: false, error: errorMessage };
374
+ }
375
+ const siteEntry = data.siteEntry ?? [];
376
+ return {
377
+ success: true,
378
+ sites: siteEntry.map((s) => ({
379
+ siteUrl: s.siteUrl ?? "",
380
+ permissionLevel: s.permissionLevel ?? ""
381
+ }))
382
+ };
383
+ } finally {
384
+ clearTimeout(timeout);
385
+ }
386
+ } catch (err) {
387
+ const msg = err instanceof Error ? err.message : String(err);
388
+ return { success: false, error: msg };
389
+ }
390
+ }
391
+ });
392
+
393
+ // ../connectors/src/connectors/google-search-console-oauth/setup.ts
394
+ var listSitesToolName = `google-search-console-oauth_${listSitesTool.name}`;
395
+ var googleSearchConsoleOauthOnboarding = new ConnectorOnboarding({
396
+ connectionSetupInstructions: {
397
+ 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
398
+
399
+ 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
400
+ 2. \u30B5\u30A4\u30C8\u306E\u9078\u629E:
401
+ - \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:
402
+ - \`parameterSlug\`: \`"site-url"\`
403
+ - \`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\`
404
+ - \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
405
+ - \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
406
+ 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
407
+
408
+ #### \u5236\u7D04
409
+ - **\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
410
+ - \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`,
411
+ en: `Follow these steps to set up the Google Search Console (OAuth) connection.
412
+
413
+ 1. Call \`${listSitesToolName}\` to get the list of sites accessible with the OAuth credentials
414
+ 2. Select a site:
415
+ - **2 or more sites**: Tell the user "Please select a site.", then call \`updateConnectionParameters\`:
416
+ - \`parameterSlug\`: \`"site-url"\`
417
+ - \`options\`: The site list. Each option's \`label\` should be \`siteUrl (permission: permissionLevel)\`, \`value\` should be the \`siteUrl\`
418
+ - **Only 1 site**: Call \`updateConnectionParameters\` directly with that site URL as \`value\`
419
+ - **0 sites**: Abort setup and inform the user that no accessible sites are available (advise them to verify ownership in Search Console and retry)
420
+ 3. The \`label\` of the user's selected site will arrive as a message. Proceed to the next step
421
+
422
+ #### Constraints
423
+ - **Do NOT fetch Search Analytics data during setup**. Only the metadata requests specified in the steps above are allowed
424
+ - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
425
+ },
426
+ dataOverviewInstructions: {
427
+ en: `1. Call google-search-console-oauth_request with GET /sites/{siteUrl} to fetch metadata for the configured site
428
+ 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`,
429
+ 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
430
+ 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`
431
+ }
432
+ });
433
+
434
+ // ../connectors/src/connectors/google-search-console-oauth/tools/request.ts
435
+ import { z as z2 } from "zod";
436
+ var BASE_HOST = "https://searchconsole.googleapis.com";
437
+ var BASE_PATH_SEGMENT = "/webmasters/v3";
438
+ var BASE_URL3 = `${BASE_HOST}${BASE_PATH_SEGMENT}`;
439
+ var REQUEST_TIMEOUT_MS2 = 6e4;
440
+ var cachedToken2 = null;
441
+ async function getProxyToken2(config) {
442
+ if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
443
+ return cachedToken2.token;
444
+ }
445
+ const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
446
+ const res = await fetch(url, {
447
+ method: "POST",
448
+ headers: {
449
+ "Content-Type": "application/json",
450
+ "x-api-key": config.appApiKey,
451
+ "project-id": config.projectId
452
+ },
453
+ body: JSON.stringify({
454
+ sandboxId: config.sandboxId,
455
+ issuedBy: "coding-agent"
456
+ })
457
+ });
458
+ if (!res.ok) {
459
+ const errorText = await res.text().catch(() => res.statusText);
460
+ throw new Error(
461
+ `Failed to get proxy token: HTTP ${res.status} ${errorText}`
462
+ );
463
+ }
464
+ const data = await res.json();
465
+ cachedToken2 = {
466
+ token: data.token,
467
+ expiresAt: new Date(data.expiresAt).getTime()
468
+ };
469
+ return data.token;
470
+ }
471
+ var inputSchema2 = z2.object({
472
+ toolUseIntent: z2.string().optional().describe(
473
+ "Brief description of what you intend to accomplish with this tool call"
474
+ ),
475
+ connectionId: z2.string().describe("ID of the Google Search Console OAuth connection to use"),
476
+ method: z2.enum(["GET", "POST", "PUT", "DELETE"]).describe(
477
+ "HTTP method. Use POST for searchAnalytics queries and sitemap submission, GET for listing/inspecting resources, PUT for sitemap upsert, DELETE for sitemap removal."
478
+ ),
479
+ path: z2.string().describe(
480
+ "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."
481
+ ),
482
+ queryParams: z2.record(z2.string(), z2.string()).optional().describe("Query parameters to append to the URL"),
483
+ body: z2.record(z2.string(), z2.unknown()).optional().describe("Request body (JSON) for POST/PUT methods")
484
+ });
485
+ var outputSchema2 = z2.discriminatedUnion("success", [
486
+ z2.object({
487
+ success: z2.literal(true),
488
+ status: z2.number(),
489
+ data: z2.record(z2.string(), z2.unknown())
490
+ }),
491
+ z2.object({
492
+ success: z2.literal(false),
493
+ error: z2.string()
494
+ })
495
+ ]);
496
+ var requestTool = new ConnectorTool({
497
+ name: "request",
498
+ description: `Send authenticated requests to the Google Search Console API (Webmasters v3).
499
+ Use this tool to query Search Analytics data (clicks, impressions, CTR, position), list/inspect sitemaps, and read site metadata.
500
+ Authentication is handled automatically via OAuth proxy.
501
+ {siteUrl} in the path is automatically replaced with the connection's default site URL and URL-encoded.
502
+ 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.`,
503
+ inputSchema: inputSchema2,
504
+ outputSchema: outputSchema2,
505
+ async execute({ connectionId, method, path: path2, queryParams, body }, connections, config) {
506
+ const connection2 = connections.find((c) => c.id === connectionId);
507
+ if (!connection2) {
508
+ return {
509
+ success: false,
510
+ error: `Connection ${connectionId} not found`
511
+ };
512
+ }
513
+ console.log(
514
+ `[connector-request] google-search-console-oauth/${connection2.name}: ${method} ${path2}`
515
+ );
516
+ try {
517
+ const siteUrl = parameters.siteUrl.tryGetValue(connection2);
518
+ const resolvedPath = siteUrl ? path2.replace(/\{siteUrl\}/g, encodeURIComponent(siteUrl)) : path2;
519
+ const normalizedPath = normalizeRequestPath(
520
+ resolvedPath,
521
+ BASE_PATH_SEGMENT
522
+ );
523
+ let url = `${BASE_URL3}${normalizedPath}`;
524
+ if (queryParams) {
525
+ const searchParams = new URLSearchParams(queryParams);
526
+ url += `?${searchParams.toString()}`;
527
+ }
528
+ const token = await getProxyToken2(config.oauthProxy);
529
+ const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
530
+ const controller = new AbortController();
531
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
532
+ try {
533
+ const response = await fetch(proxyUrl, {
534
+ method: "POST",
535
+ headers: {
536
+ "Content-Type": "application/json",
537
+ Authorization: `Bearer ${token}`
538
+ },
539
+ body: JSON.stringify({
540
+ url,
541
+ method,
542
+ ...body && ["POST", "PUT"].includes(method) ? {
543
+ headers: { "Content-Type": "application/json" },
544
+ body: JSON.stringify(body)
545
+ } : {}
546
+ }),
547
+ signal: controller.signal
548
+ });
549
+ const data = await response.json();
550
+ if (!response.ok) {
551
+ const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
552
+ return { success: false, error: errorMessage };
553
+ }
554
+ return { success: true, status: response.status, data };
555
+ } finally {
556
+ clearTimeout(timeout);
557
+ }
558
+ } catch (err) {
559
+ const msg = err instanceof Error ? err.message : String(err);
560
+ return { success: false, error: msg };
561
+ }
562
+ }
563
+ });
564
+
565
+ // ../connectors/src/connectors/google-search-console-oauth/index.ts
566
+ var tools = {
567
+ request: requestTool,
568
+ listSites: listSitesTool
569
+ };
570
+ var googleSearchConsoleOauthConnector = new ConnectorPlugin({
571
+ slug: "google-search-console",
572
+ authType: AUTH_TYPES.OAUTH,
573
+ name: "Google Search Console",
574
+ description: "Connect to Google Search Console for search performance, indexing, and sitemap data using OAuth.",
575
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/3rPusKosno7i1emOCmskTp/9ed092a4dc95efb74e34e83098ef3905/google-search-console-icon.webp",
576
+ parameters,
577
+ releaseFlag: { dev1: true, dev2: false, prod: false },
578
+ categories: ["marketing"],
579
+ onboarding: googleSearchConsoleOauthOnboarding,
580
+ proxyPolicy: {
581
+ allowlist: [
582
+ {
583
+ host: "searchconsole.googleapis.com",
584
+ methods: ["GET", "POST", "PUT", "DELETE"]
585
+ }
586
+ ]
587
+ },
588
+ systemPrompt: {
589
+ en: `### Tools
590
+
591
+ - \`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.
592
+ - \`google-search-console-oauth_listSites\`: List accessible Search Console sites. Use during setup to discover available properties.
593
+
594
+ ### Search Console API Reference
595
+
596
+ #### Available Endpoints
597
+ - GET \`/sites\` \u2014 List sites accessible by the authenticated user
598
+ - GET \`/sites/{siteUrl}\` \u2014 Get a single site's metadata and permission level
599
+ - POST \`/sites/{siteUrl}/searchAnalytics/query\` \u2014 Query search performance data (clicks, impressions, CTR, position)
600
+ - GET \`/sites/{siteUrl}/sitemaps\` \u2014 List sitemaps submitted for a site
601
+ - GET \`/sites/{siteUrl}/sitemaps/{feedpath}\` \u2014 Get a single sitemap
602
+
603
+ #### searchAnalytics/query \u2014 Body
604
+ \`\`\`json
605
+ {
606
+ "startDate": "2024-01-01",
607
+ "endDate": "2024-01-31",
608
+ "dimensions": ["query", "page"],
609
+ "type": "web",
610
+ "rowLimit": 1000,
611
+ "startRow": 0
612
+ }
613
+ \`\`\`
614
+
615
+ #### Common Dimensions
616
+ \`query\`, \`page\`, \`country\`, \`device\`, \`date\`, \`searchAppearance\`
617
+
618
+ #### Common Metrics (returned automatically)
619
+ \`clicks\`, \`impressions\`, \`ctr\`, \`position\`
620
+
621
+ #### type values
622
+ \`web\` (default), \`image\`, \`video\`, \`news\`, \`discover\`, \`googleNews\`
623
+
624
+ #### siteUrl formats
625
+ - URL-prefix property: \`https://www.example.com/\` (must include protocol and trailing slash)
626
+ - Domain property: \`sc-domain:example.com\`
627
+
628
+ In paths, use the \`{siteUrl}\` placeholder \u2014 it is automatically URL-encoded with the connection's configured site.
629
+
630
+ #### Date format
631
+ \`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.
632
+
633
+ ### Business Logic
634
+
635
+ 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.
636
+
637
+ SDK surface (client created via \`connection(connectionId)\`):
638
+ - \`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).
639
+ - \`client.listSites()\` \u2014 list sites accessible by the OAuth user.
640
+ - \`client.querySearchAnalytics(request, siteUrl?)\` \u2014 query Search Analytics performance data.
641
+ - \`client.listSitemaps(siteUrl?)\` \u2014 list sitemaps submitted for a site.
642
+
643
+ 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.
644
+
645
+ #### Example
646
+
647
+ \`\`\`ts
648
+ import { connection } from "@squadbase/vite-server/connectors/google-search-console-oauth";
649
+
650
+ const gsc = connection("<connectionId>");
651
+
652
+ // List all accessible sites
653
+ const sites = await gsc.listSites();
654
+ console.log(sites.map(s => \`\${s.siteUrl} (\${s.permissionLevel})\`));
655
+
656
+ // Top queries for the last 28 days
657
+ const { rows } = await gsc.querySearchAnalytics({
658
+ startDate: "2024-01-01",
659
+ endDate: "2024-01-28",
660
+ dimensions: ["query"],
661
+ rowLimit: 100,
662
+ });
663
+ rows?.forEach(r => console.log(r.keys?.[0], r.clicks, r.impressions));
664
+
665
+ // List sitemaps
666
+ const sitemaps = await gsc.listSitemaps();
667
+ sitemaps.forEach(s => console.log(s.path, s.lastSubmitted));
668
+ \`\`\``,
669
+ ja: `### \u30C4\u30FC\u30EB
670
+
671
+ - \`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
672
+ - \`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
673
+
674
+ ### Search Console API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
675
+
676
+ #### \u5229\u7528\u53EF\u80FD\u306A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
677
+ - GET \`/sites\` \u2014 \u8A8D\u8A3C\u30E6\u30FC\u30B6\u30FC\u304C\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u5168\u30B5\u30A4\u30C8\u306E\u4E00\u89A7
678
+ - GET \`/sites/{siteUrl}\` \u2014 \u5358\u4E00\u30B5\u30A4\u30C8\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3068\u6A29\u9650\u3092\u53D6\u5F97
679
+ - 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
680
+ - GET \`/sites/{siteUrl}/sitemaps\` \u2014 \u30B5\u30A4\u30C8\u306B\u63D0\u51FA\u6E08\u307F\u306E\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u4E00\u89A7
681
+ - GET \`/sites/{siteUrl}/sitemaps/{feedpath}\` \u2014 \u5358\u4E00\u30B5\u30A4\u30C8\u30DE\u30C3\u30D7\u306E\u53D6\u5F97
682
+
683
+ #### searchAnalytics/query \u2014 Body\u4F8B
684
+ \`\`\`json
685
+ {
686
+ "startDate": "2024-01-01",
687
+ "endDate": "2024-01-31",
688
+ "dimensions": ["query", "page"],
689
+ "type": "web",
690
+ "rowLimit": 1000,
691
+ "startRow": 0
692
+ }
693
+ \`\`\`
694
+
695
+ #### \u4E3B\u8981\u306A\u30C7\u30A3\u30E1\u30F3\u30B7\u30E7\u30F3
696
+ \`query\`, \`page\`, \`country\`, \`device\`, \`date\`, \`searchAppearance\`
697
+
698
+ #### \u4E3B\u8981\u306A\u30E1\u30C8\u30EA\u30AF\u30B9\uFF08\u81EA\u52D5\u7684\u306B\u8FD4\u5374\u3055\u308C\u308B\uFF09
699
+ \`clicks\`, \`impressions\`, \`ctr\`, \`position\`
700
+
701
+ #### type \u306E\u5024
702
+ \`web\`\uFF08\u30C7\u30D5\u30A9\u30EB\u30C8\uFF09, \`image\`, \`video\`, \`news\`, \`discover\`, \`googleNews\`
703
+
704
+ #### siteUrl \u306E\u5F62\u5F0F
705
+ - 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
706
+ - \u30C9\u30E1\u30A4\u30F3\u30D7\u30ED\u30D1\u30C6\u30A3: \`sc-domain:example.com\`
707
+
708
+ \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
709
+
710
+ #### \u65E5\u4ED8\u5F62\u5F0F
711
+ \`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
712
+
713
+ ### Business Logic
714
+
715
+ \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
716
+
717
+ SDK\uFF08\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\uFF09:
718
+ - \`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
719
+ - \`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
720
+ - \`client.querySearchAnalytics(request, siteUrl?)\` \u2014 \u691C\u7D22\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3002
721
+ - \`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
722
+
723
+ \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
724
+
725
+ #### Example
726
+
727
+ \`\`\`ts
728
+ import { connection } from "@squadbase/vite-server/connectors/google-search-console-oauth";
729
+
730
+ const gsc = connection("<connectionId>");
731
+
732
+ // List all accessible sites
733
+ const sites = await gsc.listSites();
734
+ console.log(sites.map(s => \`\${s.siteUrl} (\${s.permissionLevel})\`));
735
+
736
+ // Top queries for the last 28 days
737
+ const { rows } = await gsc.querySearchAnalytics({
738
+ startDate: "2024-01-01",
739
+ endDate: "2024-01-28",
740
+ dimensions: ["query"],
741
+ rowLimit: 100,
742
+ });
743
+ rows?.forEach(r => console.log(r.keys?.[0], r.clicks, r.impressions));
744
+
745
+ // List sitemaps
746
+ const sitemaps = await gsc.listSitemaps();
747
+ sitemaps.forEach(s => console.log(s.path, s.lastSubmitted));
748
+ \`\`\``
749
+ },
750
+ tools,
751
+ async checkConnection(params, config) {
752
+ const { proxyFetch } = config;
753
+ const siteUrl = params[parameters.siteUrl.slug];
754
+ const url = siteUrl ? `https://searchconsole.googleapis.com/webmasters/v3/sites/${encodeURIComponent(siteUrl)}` : `https://searchconsole.googleapis.com/webmasters/v3/sites`;
755
+ try {
756
+ const res = await proxyFetch(url, { method: "GET" });
757
+ if (!res.ok) {
758
+ const errorText = await res.text().catch(() => res.statusText);
759
+ return {
760
+ success: false,
761
+ error: `Google Search Console API failed: HTTP ${res.status} ${errorText}`
762
+ };
763
+ }
764
+ return { success: true };
765
+ } catch (error) {
766
+ return {
767
+ success: false,
768
+ error: error instanceof Error ? error.message : String(error)
769
+ };
770
+ }
771
+ }
772
+ });
773
+
774
+ // src/connectors/create-connector-sdk.ts
775
+ import { readFileSync } from "fs";
776
+ import path from "path";
777
+
778
+ // src/connector-client/env.ts
779
+ function resolveEnvVar(entry, key, connectionId) {
780
+ const envVarName = entry.envVars[key];
781
+ if (!envVarName) {
782
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
783
+ }
784
+ const value = process.env[envVarName];
785
+ if (!value) {
786
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
787
+ }
788
+ return value;
789
+ }
790
+ function resolveEnvVarOptional(entry, key) {
791
+ const envVarName = entry.envVars[key];
792
+ if (!envVarName) return void 0;
793
+ return process.env[envVarName] || void 0;
794
+ }
795
+
796
+ // src/connector-client/proxy-fetch.ts
797
+ import { getContext } from "hono/context-storage";
798
+ import { getCookie } from "hono/cookie";
799
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
800
+ function normalizeHeaders(input) {
801
+ const out = {};
802
+ if (!input) return out;
803
+ new Headers(input).forEach((value, key) => {
804
+ out[key] = value;
805
+ });
806
+ return out;
807
+ }
808
+ function createSandboxProxyFetch(connectionId) {
809
+ return async (input, init) => {
810
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
811
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
812
+ if (!token || !sandboxId) {
813
+ throw new Error(
814
+ "Connection proxy is not configured. Please check your deployment settings."
815
+ );
816
+ }
817
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
818
+ const originalMethod = init?.method ?? "GET";
819
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
820
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
821
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
822
+ return fetch(proxyUrl, {
823
+ method: "POST",
824
+ headers: {
825
+ "Content-Type": "application/json",
826
+ Authorization: `Bearer ${token}`
827
+ },
828
+ body: JSON.stringify({
829
+ url: originalUrl,
830
+ method: originalMethod,
831
+ headers: normalizeHeaders(init?.headers),
832
+ body: originalBody
833
+ })
834
+ });
835
+ };
836
+ }
837
+ function createDeployedAppProxyFetch(connectionId) {
838
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
839
+ if (!projectId) {
840
+ throw new Error(
841
+ "Connection proxy is not configured. Please check your deployment settings."
842
+ );
843
+ }
844
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
845
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
846
+ return async (input, init) => {
847
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
848
+ const originalMethod = init?.method ?? "GET";
849
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
850
+ const c = getContext();
851
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
852
+ if (!appSession) {
853
+ throw new Error(
854
+ "No authentication method available for connection proxy."
855
+ );
856
+ }
857
+ return fetch(proxyUrl, {
858
+ method: "POST",
859
+ headers: {
860
+ "Content-Type": "application/json",
861
+ Authorization: `Bearer ${appSession}`
862
+ },
863
+ body: JSON.stringify({
864
+ url: originalUrl,
865
+ method: originalMethod,
866
+ headers: normalizeHeaders(init?.headers),
867
+ body: originalBody
868
+ })
869
+ });
870
+ };
871
+ }
872
+ function createProxyFetch(connectionId) {
873
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
874
+ return createSandboxProxyFetch(connectionId);
875
+ }
876
+ return createDeployedAppProxyFetch(connectionId);
877
+ }
878
+
879
+ // src/connectors/create-connector-sdk.ts
880
+ function loadConnectionsSync() {
881
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
882
+ try {
883
+ const raw = readFileSync(filePath, "utf-8");
884
+ return JSON.parse(raw);
885
+ } catch {
886
+ return {};
887
+ }
888
+ }
889
+ function createConnectorSdk(plugin, createClient2) {
890
+ return (connectionId) => {
891
+ const connections = loadConnectionsSync();
892
+ const entry = connections[connectionId];
893
+ if (!entry) {
894
+ throw new Error(
895
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
896
+ );
897
+ }
898
+ if (entry.connector.slug !== plugin.slug) {
899
+ throw new Error(
900
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
901
+ );
902
+ }
903
+ const params = {};
904
+ for (const param of Object.values(plugin.parameters)) {
905
+ if (param.required) {
906
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
907
+ } else {
908
+ const val = resolveEnvVarOptional(entry, param.slug);
909
+ if (val !== void 0) params[param.slug] = val;
910
+ }
911
+ }
912
+ return createClient2(params, createProxyFetch(connectionId));
913
+ };
914
+ }
915
+
916
+ // src/connectors/entries/google-search-console-oauth.ts
917
+ var connection = createConnectorSdk(
918
+ googleSearchConsoleOauthConnector,
919
+ createClient
920
+ );
921
+ export {
922
+ connection
923
+ };