@squadbase/vite-server 0.1.3-dev.6 → 0.1.3-dev.8

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 (49) hide show
  1. package/dist/cli/index.js +1858 -1340
  2. package/dist/connectors/airtable-oauth.js +74 -1
  3. package/dist/connectors/airtable.js +74 -1
  4. package/dist/connectors/amplitude.js +74 -1
  5. package/dist/connectors/anthropic.js +74 -1
  6. package/dist/connectors/asana.js +74 -1
  7. package/dist/connectors/attio.js +74 -1
  8. package/dist/connectors/customerio.js +74 -1
  9. package/dist/connectors/dbt.js +74 -1
  10. package/dist/connectors/gemini.js +74 -1
  11. package/dist/connectors/gmail-oauth.js +74 -1
  12. package/dist/connectors/gmail.js +74 -1
  13. package/dist/connectors/google-ads-oauth.js +74 -1
  14. package/dist/connectors/google-ads.js +74 -1
  15. package/dist/connectors/google-analytics-oauth.js +87 -6
  16. package/dist/connectors/google-analytics.js +117 -52
  17. package/dist/connectors/google-calendar-oauth.js +75 -2
  18. package/dist/connectors/google-calendar.d.ts +1 -8
  19. package/dist/connectors/google-calendar.js +363 -60
  20. package/dist/connectors/google-sheets-oauth.js +141 -31
  21. package/dist/connectors/google-sheets.js +108 -9
  22. package/dist/connectors/grafana.d.ts +5 -0
  23. package/dist/connectors/grafana.js +638 -0
  24. package/dist/connectors/hubspot-oauth.js +74 -1
  25. package/dist/connectors/hubspot.js +74 -1
  26. package/dist/connectors/intercom-oauth.js +74 -1
  27. package/dist/connectors/intercom.js +74 -1
  28. package/dist/connectors/jira-api-key.js +74 -1
  29. package/dist/connectors/kintone-api-token.js +74 -1
  30. package/dist/connectors/kintone.js +74 -1
  31. package/dist/connectors/linkedin-ads-oauth.js +74 -1
  32. package/dist/connectors/linkedin-ads.js +74 -1
  33. package/dist/connectors/mailchimp-oauth.js +74 -1
  34. package/dist/connectors/mailchimp.js +74 -1
  35. package/dist/connectors/notion-oauth.js +74 -1
  36. package/dist/connectors/notion.js +74 -1
  37. package/dist/connectors/openai.js +74 -1
  38. package/dist/connectors/shopify-oauth.js +74 -1
  39. package/dist/connectors/shopify.js +74 -1
  40. package/dist/connectors/stripe-api-key.js +74 -1
  41. package/dist/connectors/stripe-oauth.js +74 -1
  42. package/dist/connectors/wix-store.js +74 -1
  43. package/dist/connectors/zendesk-oauth.js +74 -1
  44. package/dist/connectors/zendesk.js +74 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.js +1808 -1291
  47. package/dist/main.js +1807 -1289
  48. package/dist/vite-plugin.js +1807 -1289
  49. package/package.json +5 -1
@@ -56,6 +56,15 @@ var parameters = {
56
56
  secret: true,
57
57
  required: true
58
58
  }),
59
+ impersonateEmail: new ParameterDefinition({
60
+ slug: "impersonate-email",
61
+ name: "User Email Address(es)",
62
+ description: "The email address(es) of the Google Workspace user(s) whose calendar will be accessed via Domain-wide Delegation. Multiple addresses can be provided as a comma-separated list (e.g., 'user1@example.com, user2@example.com') to aggregate accessible calendars across users during setup. After setup completes, this value is overwritten with the owner email of the selected calendar.",
63
+ envVarBaseKey: "GOOGLE_CALENDAR_IMPERSONATE_EMAIL",
64
+ type: "text",
65
+ secret: false,
66
+ required: true
67
+ }),
59
68
  calendarId: new ParameterDefinition({
60
69
  slug: "calendar-id",
61
70
  name: "Default Calendar ID",
@@ -95,14 +104,20 @@ function buildJwt(clientEmail, privateKey, nowSec, subject) {
95
104
  const signature = base64url(sign.sign(privateKey));
96
105
  return `${signingInput}.${signature}`;
97
106
  }
98
- function createClient(params, options) {
107
+ function createClient(params) {
99
108
  const serviceAccountKeyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
109
+ const impersonateEmail = params[parameters.impersonateEmail.slug];
100
110
  const defaultCalendarId = params[parameters.calendarId.slug] ?? "primary";
101
111
  if (!serviceAccountKeyJsonBase64) {
102
112
  throw new Error(
103
113
  `google-calendar: missing required parameter: ${parameters.serviceAccountKeyJsonBase64.slug}`
104
114
  );
105
115
  }
116
+ if (!impersonateEmail) {
117
+ throw new Error(
118
+ `google-calendar: missing required parameter: ${parameters.impersonateEmail.slug}`
119
+ );
120
+ }
106
121
  let serviceAccountKey;
107
122
  try {
108
123
  const decoded = Buffer.from(
@@ -120,10 +135,10 @@ function createClient(params, options) {
120
135
  "google-calendar: service account key JSON must contain client_email and private_key"
121
136
  );
122
137
  }
123
- const subject = options?.subject;
138
+ const subject = impersonateEmail;
124
139
  let cachedToken = null;
125
140
  let tokenExpiresAt = 0;
126
- async function getAccessToken() {
141
+ async function getAccessToken2() {
127
142
  const nowSec = Math.floor(Date.now() / 1e3);
128
143
  if (cachedToken && nowSec < tokenExpiresAt - 60) {
129
144
  return cachedToken;
@@ -158,7 +173,7 @@ function createClient(params, options) {
158
173
  }
159
174
  return {
160
175
  async request(path2, init) {
161
- const accessToken = await getAccessToken();
176
+ const accessToken = await getAccessToken2();
162
177
  const resolvedPath = path2.replace(
163
178
  /\{calendarId\}/g,
164
179
  defaultCalendarId
@@ -181,18 +196,18 @@ function createClient(params, options) {
181
196
  const data = await response.json();
182
197
  return data.items ?? [];
183
198
  },
184
- async listEvents(options2, calendarId) {
199
+ async listEvents(options, calendarId) {
185
200
  const cid = resolveCalendarId(calendarId);
186
201
  const searchParams = new URLSearchParams();
187
- if (options2?.timeMin) searchParams.set("timeMin", options2.timeMin);
188
- if (options2?.timeMax) searchParams.set("timeMax", options2.timeMax);
189
- if (options2?.maxResults)
190
- searchParams.set("maxResults", String(options2.maxResults));
191
- if (options2?.q) searchParams.set("q", options2.q);
192
- if (options2?.singleEvents != null)
193
- searchParams.set("singleEvents", String(options2.singleEvents));
194
- if (options2?.orderBy) searchParams.set("orderBy", options2.orderBy);
195
- if (options2?.pageToken) searchParams.set("pageToken", options2.pageToken);
202
+ if (options?.timeMin) searchParams.set("timeMin", options.timeMin);
203
+ if (options?.timeMax) searchParams.set("timeMax", options.timeMax);
204
+ if (options?.maxResults)
205
+ searchParams.set("maxResults", String(options.maxResults));
206
+ if (options?.q) searchParams.set("q", options.q);
207
+ if (options?.singleEvents != null)
208
+ searchParams.set("singleEvents", String(options.singleEvents));
209
+ if (options?.orderBy) searchParams.set("orderBy", options.orderBy);
210
+ if (options?.pageToken) searchParams.set("pageToken", options.pageToken);
196
211
  const qs = searchParams.toString();
197
212
  const path2 = `/calendars/${encodeURIComponent(cid)}/events${qs ? `?${qs}` : ""}`;
198
213
  const response = await this.request(path2, { method: "GET" });
@@ -329,8 +344,224 @@ var AUTH_TYPES = {
329
344
  USER_PASSWORD: "user-password"
330
345
  };
331
346
 
347
+ // ../connectors/src/connectors/google-calendar/tools/list-calendars.ts
348
+ import * as crypto2 from "crypto";
349
+ import { z } from "zod";
350
+ var TOKEN_URL2 = "https://oauth2.googleapis.com/token";
351
+ var BASE_URL2 = "https://www.googleapis.com/calendar/v3";
352
+ var SCOPE2 = "https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/calendar.events.readonly";
353
+ var REQUEST_TIMEOUT_MS = 6e4;
354
+ function base64url2(input) {
355
+ const buf = typeof input === "string" ? Buffer.from(input) : input;
356
+ return buf.toString("base64url");
357
+ }
358
+ function buildJwt2(clientEmail, privateKey, nowSec, subject) {
359
+ const header = base64url2(JSON.stringify({ alg: "RS256", typ: "JWT" }));
360
+ const payload = base64url2(
361
+ JSON.stringify({
362
+ iss: clientEmail,
363
+ sub: subject,
364
+ scope: SCOPE2,
365
+ aud: TOKEN_URL2,
366
+ iat: nowSec,
367
+ exp: nowSec + 3600
368
+ })
369
+ );
370
+ const signingInput = `${header}.${payload}`;
371
+ const sign = crypto2.createSign("RSA-SHA256");
372
+ sign.update(signingInput);
373
+ sign.end();
374
+ const signature = base64url2(sign.sign(privateKey));
375
+ return `${signingInput}.${signature}`;
376
+ }
377
+ async function getAccessToken(serviceAccount, subject) {
378
+ const nowSec = Math.floor(Date.now() / 1e3);
379
+ const jwt = buildJwt2(
380
+ serviceAccount.client_email,
381
+ serviceAccount.private_key,
382
+ nowSec,
383
+ subject
384
+ );
385
+ const response = await fetch(TOKEN_URL2, {
386
+ method: "POST",
387
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
388
+ body: new URLSearchParams({
389
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
390
+ assertion: jwt
391
+ })
392
+ });
393
+ if (!response.ok) {
394
+ const text = await response.text();
395
+ throw new Error(
396
+ `token exchange failed for ${subject} (${response.status}): ${text}`
397
+ );
398
+ }
399
+ const data = await response.json();
400
+ return data.access_token;
401
+ }
402
+ var inputSchema = z.object({
403
+ toolUseIntent: z.string().optional().describe(
404
+ "Brief description of what you intend to accomplish with this tool call"
405
+ ),
406
+ connectionId: z.string().describe("ID of the Google Calendar connection to use")
407
+ });
408
+ var outputSchema = z.discriminatedUnion("success", [
409
+ z.object({
410
+ success: z.literal(true),
411
+ calendars: z.array(
412
+ z.object({
413
+ impersonateEmail: z.string(),
414
+ id: z.string(),
415
+ summary: z.string(),
416
+ primary: z.boolean().optional(),
417
+ accessRole: z.string()
418
+ })
419
+ ),
420
+ errors: z.array(
421
+ z.object({
422
+ impersonateEmail: z.string(),
423
+ error: z.string()
424
+ })
425
+ )
426
+ }),
427
+ z.object({
428
+ success: z.literal(false),
429
+ error: z.string()
430
+ })
431
+ ]);
432
+ var listCalendarsTool = new ConnectorTool({
433
+ name: "listCalendars",
434
+ description: "List Google Calendars accessible via Domain-wide Delegation by impersonating the Google Workspace user(s) configured on the connection's `impersonate-email` parameter (comma-separated list supported). Use during setup to aggregate calendars across the configured emails.",
435
+ inputSchema,
436
+ outputSchema,
437
+ async execute({ connectionId }, connections) {
438
+ const connection2 = connections.find((c) => c.id === connectionId);
439
+ if (!connection2) {
440
+ return {
441
+ success: false,
442
+ error: `Connection ${connectionId} not found`
443
+ };
444
+ }
445
+ const impersonateEmailRaw = parameters.impersonateEmail.getValue(connection2);
446
+ const emails = impersonateEmailRaw.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
447
+ if (emails.length === 0) {
448
+ return {
449
+ success: false,
450
+ error: "impersonate-email parameter is empty"
451
+ };
452
+ }
453
+ console.log(
454
+ `[connector-request] google-calendar/${connection2.name}: listCalendars for ${emails.join(",")}`
455
+ );
456
+ let serviceAccount;
457
+ try {
458
+ const keyJsonBase64 = parameters.serviceAccountKeyJsonBase64.getValue(connection2);
459
+ const decoded = Buffer.from(keyJsonBase64, "base64").toString("utf-8");
460
+ serviceAccount = JSON.parse(decoded);
461
+ } catch (err) {
462
+ const msg = err instanceof Error ? err.message : String(err);
463
+ return {
464
+ success: false,
465
+ error: `failed to decode service account key: ${msg}`
466
+ };
467
+ }
468
+ if (!serviceAccount.client_email || !serviceAccount.private_key) {
469
+ return {
470
+ success: false,
471
+ error: "service account key JSON must contain client_email and private_key"
472
+ };
473
+ }
474
+ const aggregated = [];
475
+ const errors = [];
476
+ for (const email of emails) {
477
+ const controller = new AbortController();
478
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
479
+ try {
480
+ const token = await getAccessToken(serviceAccount, email);
481
+ const response = await fetch(`${BASE_URL2}/users/me/calendarList`, {
482
+ method: "GET",
483
+ headers: { Authorization: `Bearer ${token}` },
484
+ signal: controller.signal
485
+ });
486
+ const data = await response.json();
487
+ if (!response.ok) {
488
+ const errorObj = data?.error;
489
+ errors.push({
490
+ impersonateEmail: email,
491
+ error: errorObj?.message ?? `HTTP ${response.status} ${response.statusText}`
492
+ });
493
+ continue;
494
+ }
495
+ const items = data.items ?? [];
496
+ for (const c of items) {
497
+ aggregated.push({
498
+ impersonateEmail: email,
499
+ id: c.id,
500
+ summary: c.summary,
501
+ primary: c.primary,
502
+ accessRole: c.accessRole
503
+ });
504
+ }
505
+ } catch (err) {
506
+ const msg = err instanceof Error ? err.message : String(err);
507
+ errors.push({ impersonateEmail: email, error: msg });
508
+ } finally {
509
+ clearTimeout(timeout);
510
+ }
511
+ }
512
+ return {
513
+ success: true,
514
+ calendars: aggregated,
515
+ errors
516
+ };
517
+ }
518
+ });
519
+
332
520
  // ../connectors/src/connectors/google-calendar/setup.ts
521
+ var listCalendarsToolName = `google-calendar_${listCalendarsTool.name}`;
333
522
  var googleCalendarOnboarding = new ConnectorOnboarding({
523
+ connectionSetupInstructions: {
524
+ ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Calendar\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
525
+
526
+ 1. \`${listCalendarsToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E \`impersonate-email\` \u30D1\u30E9\u30E1\u30FC\u30BF\u306B\u8A2D\u5B9A\u3055\u308C\u305F\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\uFF08\u30AB\u30F3\u30DE\u533A\u5207\u308A\u5BFE\u5FDC\uFF09\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30AB\u30EC\u30F3\u30C0\u30FC\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
527
+ 2. \u8FD4\u5374\u3055\u308C\u305F \`calendars\` \u914D\u5217\uFF08\u5404\u8981\u7D20: \`{ impersonateEmail, id, summary, primary, accessRole }\`\uFF09\u3092\u5143\u306B\u3001\u300C\u4F7F\u7528\u3059\u308B\u30AB\u30EC\u30F3\u30C0\u30FC\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:
528
+ - \`parameterSlug\`: \`"calendar-id"\`
529
+ - \`options\`: \u30AB\u30EC\u30F3\u30C0\u30FC\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u30AB\u30EC\u30F3\u30C0\u30FC\u540D (owner: impersonateEmail)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F\u30AB\u30EC\u30F3\u30C0\u30FCID
530
+ - \`errors\` \u306B\u5931\u6557\u3057\u305F\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u304C\u3042\u308B\u5834\u5408\u306F\u3001\u305D\u306E\u65E8\u3092\u77ED\u304F\u4F1D\u3048\u308B
531
+ 3. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30AB\u30EC\u30F3\u30C0\u30FC\u306E \`label\` \u304C\u30E1\u30C3\u30BB\u30FC\u30B8\u3068\u3057\u3066\u5C4A\u304F\u3002\u305D\u306E label \u304B\u3089 owner \u306E\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u62BD\u51FA\u3057\u3001\`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
532
+ - \`parameterSlug\`: \`"impersonate-email"\`
533
+ - \`options\`: \`[{ value: <ownerEmail>, label: <ownerEmail> }]\`\uFF08\u9078\u629E\u6E08\u307F\u30AB\u30EC\u30F3\u30C0\u30FC\u306E owner email \u3092\u5358\u4E00\u30AA\u30D7\u30B7\u30E7\u30F3\u3068\u3057\u3066\u6E21\u3059\uFF09
534
+ 4. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u5BFE\u8C61\u60C5\u5831\u3092\u8A18\u9332\u3059\u308B:
535
+ - \`user\`: \u8A2D\u5B9A\u3057\u305F\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9
536
+ - \`calendar\`: \u9078\u629E\u3055\u308C\u305F\u30AB\u30EC\u30F3\u30C0\u30FC\u540D
537
+ - \`calendarId\`: \u9078\u629E\u3055\u308C\u305F\u30AB\u30EC\u30F3\u30C0\u30FCID
538
+ - \`note\`: \u300CDomain-wide Delegation\u3067 {email} \u306E {calendar} \u306B\u30A2\u30AF\u30BB\u30B9\u300D\u306A\u3069\u306E\u8AAC\u660E
539
+
540
+ #### \u5236\u7D04
541
+ - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30E6\u30FC\u30B6\u30FC\u3078\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u7B49\u306E\u5165\u529B\u3092\u6C42\u3081\u306A\u3044\u3053\u3068**\u3002\u5FC5\u8981\u306A\u5024\u306F\u63A5\u7D9A\u4F5C\u6210\u6642\u306E\u30D1\u30E9\u30E1\u30FC\u30BF\uFF08\`impersonate-email\`\uFF09\u304B\u3089\u53D6\u5F97\u3059\u308B
542
+ - **\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u30C9\u30E1\u30A4\u30F3\u5168\u4F53\u306E\u59D4\u4EFB\u8A2D\u5B9A\u304C\u5FC5\u8981\u3067\u3059**\u3002\`${listCalendarsToolName}\` \u306E \`errors\` \u306B\u6A29\u9650\u30A8\u30E9\u30FC\u304C\u51FA\u308B\u5834\u5408\u3001Google Workspace\u7BA1\u7406\u8005\u306BDomain-wide Delegation\u306E\u8A2D\u5B9A\u78BA\u8A8D\u3092\u4FC3\u3057\u3066\u304F\u3060\u3055\u3044
543
+ - \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`,
544
+ en: `Follow these steps to set up the Google Calendar connection.
545
+
546
+ 1. Call \`${listCalendarsToolName}\` to list calendars accessible via the email address(es) configured in the connection's \`impersonate-email\` parameter (comma-separated list supported)
547
+ 2. Using the returned \`calendars\` array (each item: \`{ impersonateEmail, id, summary, primary, accessRole }\`), tell the user "Please select a calendar.", then call \`updateConnectionParameters\`:
548
+ - \`parameterSlug\`: \`"calendar-id"\`
549
+ - \`options\`: The calendar list. Each option's \`label\` should be \`Calendar Name (owner: impersonateEmail)\`, \`value\` should be the calendar ID
550
+ - If \`errors\` contains failing email addresses, briefly mention them
551
+ 3. The \`label\` of the user's selected calendar will arrive as a message. Extract the owner email from that label and call \`updateConnectionParameters\`:
552
+ - \`parameterSlug\`: \`"impersonate-email"\`
553
+ - \`options\`: \`[{ value: <ownerEmail>, label: <ownerEmail> }]\` (pass the selected calendar's owner email as a single option)
554
+ 4. Call \`updateConnectionContext\` to record the target:
555
+ - \`user\`: The configured email address
556
+ - \`calendar\`: The selected calendar's name
557
+ - \`calendarId\`: The selected calendar ID
558
+ - \`note\`: A description such as "Accessing {email}'s {calendar} via Domain-wide Delegation"
559
+
560
+ #### Constraints
561
+ - **Do NOT prompt the user for any input (e.g., email addresses) during setup**. The required values come from the connection parameters (\`impersonate-email\`) filled in at connection creation time
562
+ - **Domain-wide Delegation must be configured on the service account**. If \`${listCalendarsToolName}\` returns permission errors in the \`errors\` field, ask the user to verify the Domain-wide Delegation setup with their Google Workspace administrator
563
+ - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
564
+ },
334
565
  dataOverviewInstructions: {
335
566
  en: `1. Call google-calendar_request with GET /calendars/{calendarId} to get the default calendar's metadata
336
567
  2. Call google-calendar_request with GET /users/me/calendarList to list all accessible calendars
@@ -342,33 +573,33 @@ var googleCalendarOnboarding = new ConnectorOnboarding({
342
573
  });
343
574
 
344
575
  // ../connectors/src/connectors/google-calendar/tools/request.ts
345
- import { z } from "zod";
346
- var BASE_URL2 = "https://www.googleapis.com/calendar/v3";
347
- var REQUEST_TIMEOUT_MS = 6e4;
348
- var inputSchema = z.object({
349
- toolUseIntent: z.string().optional().describe(
576
+ import { z as z2 } from "zod";
577
+ var BASE_URL3 = "https://www.googleapis.com/calendar/v3";
578
+ var REQUEST_TIMEOUT_MS2 = 6e4;
579
+ var inputSchema2 = z2.object({
580
+ toolUseIntent: z2.string().optional().describe(
350
581
  "Brief description of what you intend to accomplish with this tool call"
351
582
  ),
352
- connectionId: z.string().describe("ID of the Google Calendar connection to use"),
353
- method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).describe("HTTP method"),
354
- path: z.string().describe(
583
+ connectionId: z2.string().describe("ID of the Google Calendar connection to use"),
584
+ method: z2.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).describe("HTTP method"),
585
+ path: z2.string().describe(
355
586
  "API path appended to https://www.googleapis.com/calendar/v3 (e.g., '/calendars/{calendarId}/events'). {calendarId} is automatically replaced."
356
587
  ),
357
- queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL"),
358
- body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON) for POST/PUT/PATCH methods"),
359
- subject: z.string().optional().describe(
360
- "Email address of the user to impersonate via Domain-wide Delegation. When set, the service account acts on behalf of this user."
588
+ queryParams: z2.record(z2.string(), z2.string()).optional().describe("Query parameters to append to the URL"),
589
+ body: z2.record(z2.string(), z2.unknown()).optional().describe("Request body (JSON) for POST/PUT/PATCH methods"),
590
+ subject: z2.string().optional().describe(
591
+ "Override the email address of the user to impersonate via Domain-wide Delegation. If omitted, the connection's configured user email is used."
361
592
  )
362
593
  });
363
- var outputSchema = z.discriminatedUnion("success", [
364
- z.object({
365
- success: z.literal(true),
366
- status: z.number(),
367
- data: z.record(z.string(), z.unknown())
594
+ var outputSchema2 = z2.discriminatedUnion("success", [
595
+ z2.object({
596
+ success: z2.literal(true),
597
+ status: z2.number(),
598
+ data: z2.record(z2.string(), z2.unknown())
368
599
  }),
369
- z.object({
370
- success: z.literal(false),
371
- error: z.string()
600
+ z2.object({
601
+ success: z2.literal(false),
602
+ error: z2.string()
372
603
  })
373
604
  ]);
374
605
  var requestTool = new ConnectorTool({
@@ -376,8 +607,8 @@ var requestTool = new ConnectorTool({
376
607
  description: `Send authenticated requests to the Google Calendar API v3.
377
608
  Authentication is handled automatically using a service account.
378
609
  {calendarId} in the path is automatically replaced with the connection's default calendar ID.`,
379
- inputSchema,
380
- outputSchema,
610
+ inputSchema: inputSchema2,
611
+ outputSchema: outputSchema2,
381
612
  async execute({ connectionId, method, path: path2, queryParams, body, subject }, connections) {
382
613
  const connection2 = connections.find((c) => c.id === connectionId);
383
614
  if (!connection2) {
@@ -392,7 +623,15 @@ Authentication is handled automatically using a service account.
392
623
  try {
393
624
  const { GoogleAuth } = await import("google-auth-library");
394
625
  const keyJsonBase64 = parameters.serviceAccountKeyJsonBase64.getValue(connection2);
626
+ const impersonateEmail = parameters.impersonateEmail.tryGetValue(connection2);
395
627
  const calendarId = parameters.calendarId.tryGetValue(connection2) ?? "primary";
628
+ const resolvedSubject = subject ?? impersonateEmail;
629
+ if (!resolvedSubject) {
630
+ return {
631
+ success: false,
632
+ error: `Missing required parameter: ${parameters.impersonateEmail.slug}. Configure the user email for this connection.`
633
+ };
634
+ }
396
635
  const credentials = JSON.parse(
397
636
  Buffer.from(keyJsonBase64, "base64").toString("utf-8")
398
637
  );
@@ -402,7 +641,7 @@ Authentication is handled automatically using a service account.
402
641
  "https://www.googleapis.com/auth/calendar.readonly",
403
642
  "https://www.googleapis.com/auth/calendar.events.readonly"
404
643
  ],
405
- ...subject ? { clientOptions: { subject } } : {}
644
+ clientOptions: { subject: resolvedSubject }
406
645
  });
407
646
  const token = await auth.getAccessToken();
408
647
  if (!token) {
@@ -412,13 +651,13 @@ Authentication is handled automatically using a service account.
412
651
  };
413
652
  }
414
653
  const resolvedPath = path2.replace(/\{calendarId\}/g, calendarId);
415
- let url = `${BASE_URL2}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
654
+ let url = `${BASE_URL3}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
416
655
  if (queryParams) {
417
656
  const searchParams = new URLSearchParams(queryParams);
418
657
  url += `?${searchParams.toString()}`;
419
658
  }
420
659
  const controller = new AbortController();
421
- const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
660
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
422
661
  try {
423
662
  const response = await fetch(url, {
424
663
  method,
@@ -456,26 +695,26 @@ Authentication is handled automatically using a service account.
456
695
  });
457
696
 
458
697
  // ../connectors/src/connectors/google-calendar/index.ts
459
- var tools = { request: requestTool };
698
+ var tools = { request: requestTool, listCalendars: listCalendarsTool };
460
699
  var googleCalendarConnector = new ConnectorPlugin({
461
700
  slug: "google-calendar",
462
701
  authType: AUTH_TYPES.SERVICE_ACCOUNT,
463
702
  name: "Google Calendar",
464
703
  description: "Connect to Google Calendar for calendar and event data access using a service account.",
465
- iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/5D9eTiMxiL7MaezWXyAaLG/dbcf25e1d51ab877548b3d77e4b02c6d/google-calendar.svg",
704
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/2YsqoBEpdELmfDeFcyGHyE/4494c633b5ae15e562cb739cd85442c1/google-calendar.png",
466
705
  parameters,
467
706
  releaseFlag: { dev1: true, dev2: true, prod: true },
468
707
  onboarding: googleCalendarOnboarding,
469
708
  systemPrompt: {
470
709
  en: `### Tools
471
710
 
472
- - \`google-calendar_request\`: The only way to call the Google Calendar API. Use it to list calendars, get events, and manage calendar data. Authentication is handled automatically using a service account. The {calendarId} placeholder in paths is automatically replaced with the configured default calendar ID. Supports Domain-wide Delegation via the optional \`subject\` parameter to impersonate a user.
711
+ - \`google-calendar_request\`: The only way to call the Google Calendar API. Use it to list calendars, get events, and manage calendar data. Authentication is handled automatically using a service account with Domain-wide Delegation \u2014 the service account impersonates the user configured on the connection (\`impersonate-email\` parameter). The {calendarId} placeholder in paths is automatically replaced with the configured default calendar ID. Pass an optional \`subject\` only if you need to override the configured user for a specific request.
473
712
 
474
713
  ### Business Logic
475
714
 
476
715
  The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
477
716
 
478
- SDK methods (client created via \`connection(connectionId)\` or \`connection(connectionId, { subject })\`):
717
+ SDK methods (client created via \`connection(connectionId)\` \u2014 the connection's \`impersonate-email\` parameter is used automatically for Domain-wide Delegation):
479
718
  - \`client.listCalendars()\` \u2014 list all accessible calendars
480
719
  - \`client.listEvents(options?, calendarId?)\` \u2014 list events with optional filters
481
720
  - \`client.getEvent(eventId, calendarId?)\` \u2014 get a single event by ID
@@ -483,10 +722,10 @@ SDK methods (client created via \`connection(connectionId)\` or \`connection(con
483
722
 
484
723
  #### Domain-wide Delegation
485
724
 
486
- To access a user's calendar via Domain-wide Delegation, pass \`subject\` (the user's email) as the second argument to \`connection()\`:
725
+ The target user email is configured on the connection (\`impersonate-email\` parameter), so \`connection()\` automatically uses it. Pass \`subject\` only to override it:
487
726
 
488
727
  \`\`\`ts
489
- const calendar = connection("<connectionId>", { subject: "user@example.com" });
728
+ const calendar = connection("<connectionId>", { subject: "other-user@example.com" });
490
729
  \`\`\`
491
730
 
492
731
  \`\`\`ts
@@ -540,13 +779,13 @@ export default async function handler(c: Context) {
540
779
  - The default calendar ID is "primary" if not configured`,
541
780
  ja: `### \u30C4\u30FC\u30EB
542
781
 
543
- - \`google-calendar_request\`: Google Calendar API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30AB\u30EC\u30F3\u30C0\u30FC\u306E\u4E00\u89A7\u53D6\u5F97\u3001\u30A4\u30D9\u30F3\u30C8\u306E\u53D6\u5F97\u3001\u30AB\u30EC\u30F3\u30C0\u30FC\u30C7\u30FC\u30BF\u306E\u7BA1\u7406\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u306F\u81EA\u52D5\u7684\u306B\u51E6\u7406\u3055\u308C\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{calendarId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30AB\u30EC\u30F3\u30C0\u30FCID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002Domain-wide Delegation\u3092\u4F7F\u7528\u3059\u308B\u5834\u5408\u3001\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\`subject\`\u30D1\u30E9\u30E1\u30FC\u30BF\u3067\u30E6\u30FC\u30B6\u30FC\u3092\u507D\u88C5\u3067\u304D\u307E\u3059\u3002
782
+ - \`google-calendar_request\`: Google Calendar API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30AB\u30EC\u30F3\u30C0\u30FC\u306E\u4E00\u89A7\u53D6\u5F97\u3001\u30A4\u30D9\u30F3\u30C8\u306E\u53D6\u5F97\u3001\u30AB\u30EC\u30F3\u30C0\u30FC\u30C7\u30FC\u30BF\u306E\u7BA1\u7406\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\uFF0BDomain-wide Delegation\u3067\u8A8D\u8A3C\u304C\u81EA\u52D5\u7684\u306B\u51E6\u7406\u3055\u308C\u3001\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306B\u8A2D\u5B9A\u3055\u308C\u305F\u30E6\u30FC\u30B6\u30FC\uFF08\`impersonate-email\`\u30D1\u30E9\u30E1\u30FC\u30BF\uFF09\u3068\u3057\u3066\u52D5\u4F5C\u3057\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{calendarId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30AB\u30EC\u30F3\u30C0\u30FCID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002\u7279\u5B9A\u30EA\u30AF\u30A8\u30B9\u30C8\u3067\u8A2D\u5B9A\u30E6\u30FC\u30B6\u30FC\u3092\u4E0A\u66F8\u304D\u3057\u305F\u3044\u5834\u5408\u306E\u307F\u3001\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\`subject\`\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002
544
783
 
545
784
  ### Business Logic
546
785
 
547
786
  \u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u30CF\u30F3\u30C9\u30E9\u5185\u3067\u306F\u30B3\u30CD\u30AF\u30BFSDK\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u8A8D\u8A3C\u60C5\u5831\u3092\u8AAD\u307F\u53D6\u3089\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
548
787
 
549
- SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u307E\u305F\u306F \`connection(connectionId, { subject })\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
788
+ SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8 \u2014 \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\`impersonate-email\`\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u81EA\u52D5\u7684\u306BDomain-wide Delegation\u306Esubject\u3068\u3057\u3066\u4F7F\u308F\u308C\u307E\u3059):
550
789
  - \`client.listCalendars()\` \u2014 \u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u5168\u30AB\u30EC\u30F3\u30C0\u30FC\u306E\u4E00\u89A7\u53D6\u5F97
551
790
  - \`client.listEvents(options?, calendarId?)\` \u2014 \u30D5\u30A3\u30EB\u30BF\u30FC\u4ED8\u304D\u30A4\u30D9\u30F3\u30C8\u4E00\u89A7\u53D6\u5F97
552
791
  - \`client.getEvent(eventId, calendarId?)\` \u2014 ID\u306B\u3088\u308B\u5358\u4E00\u30A4\u30D9\u30F3\u30C8\u53D6\u5F97
@@ -554,10 +793,10 @@ SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u307E\u305F\u306F \`c
554
793
 
555
794
  #### Domain-wide Delegation
556
795
 
557
- Domain-wide Delegation\u3067\u30E6\u30FC\u30B6\u30FC\u306E\u30AB\u30EC\u30F3\u30C0\u30FC\u306B\u30A2\u30AF\u30BB\u30B9\u3059\u308B\u306B\u306F\u3001\`connection()\`\u306E\u7B2C2\u5F15\u6570\u306B\`subject\`\uFF08\u30E6\u30FC\u30B6\u30FC\u306E\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\uFF09\u3092\u6E21\u3057\u307E\u3059\uFF1A
796
+ \u5BFE\u8C61\u30E6\u30FC\u30B6\u30FC\u306E\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u306F\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\uFF08\`impersonate-email\`\u30D1\u30E9\u30E1\u30FC\u30BF\uFF09\u306B\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u305F\u3081\u3001\`connection()\`\u306F\u81EA\u52D5\u7684\u306B\u305D\u308C\u3092\u4F7F\u3044\u307E\u3059\u3002\u4E0A\u66F8\u304D\u3057\u305F\u3044\u5834\u5408\u306E\u307F\`subject\`\u3092\u6E21\u3057\u307E\u3059\uFF1A
558
797
 
559
798
  \`\`\`ts
560
- const calendar = connection("<connectionId>", { subject: "user@example.com" });
799
+ const calendar = connection("<connectionId>", { subject: "other-user@example.com" });
561
800
  \`\`\`
562
801
 
563
802
  \`\`\`ts
@@ -635,6 +874,79 @@ function resolveEnvVarOptional(entry, key) {
635
874
  return process.env[envVarName] || void 0;
636
875
  }
637
876
 
877
+ // src/connector-client/proxy-fetch.ts
878
+ import { getContext } from "hono/context-storage";
879
+ import { getCookie } from "hono/cookie";
880
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
881
+ function createSandboxProxyFetch(connectionId) {
882
+ return async (input, init) => {
883
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
884
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
885
+ if (!token || !sandboxId) {
886
+ throw new Error(
887
+ "Connection proxy is not configured. Please check your deployment settings."
888
+ );
889
+ }
890
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
891
+ const originalMethod = init?.method ?? "GET";
892
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
893
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
894
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
895
+ return fetch(proxyUrl, {
896
+ method: "POST",
897
+ headers: {
898
+ "Content-Type": "application/json",
899
+ Authorization: `Bearer ${token}`
900
+ },
901
+ body: JSON.stringify({
902
+ url: originalUrl,
903
+ method: originalMethod,
904
+ body: originalBody
905
+ })
906
+ });
907
+ };
908
+ }
909
+ function createDeployedAppProxyFetch(connectionId) {
910
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
911
+ if (!projectId) {
912
+ throw new Error(
913
+ "Connection proxy is not configured. Please check your deployment settings."
914
+ );
915
+ }
916
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
917
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
918
+ return async (input, init) => {
919
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
920
+ const originalMethod = init?.method ?? "GET";
921
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
922
+ const c = getContext();
923
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
924
+ if (!appSession) {
925
+ throw new Error(
926
+ "No authentication method available for connection proxy."
927
+ );
928
+ }
929
+ return fetch(proxyUrl, {
930
+ method: "POST",
931
+ headers: {
932
+ "Content-Type": "application/json",
933
+ Authorization: `Bearer ${appSession}`
934
+ },
935
+ body: JSON.stringify({
936
+ url: originalUrl,
937
+ method: originalMethod,
938
+ body: originalBody
939
+ })
940
+ });
941
+ };
942
+ }
943
+ function createProxyFetch(connectionId) {
944
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
945
+ return createSandboxProxyFetch(connectionId);
946
+ }
947
+ return createDeployedAppProxyFetch(connectionId);
948
+ }
949
+
638
950
  // src/connectors/create-connector-sdk.ts
639
951
  function loadConnectionsSync() {
640
952
  const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
@@ -668,21 +980,12 @@ function createConnectorSdk(plugin, createClient2) {
668
980
  if (val !== void 0) params[param.slug] = val;
669
981
  }
670
982
  }
671
- return createClient2(params);
983
+ return createClient2(params, createProxyFetch(connectionId));
672
984
  };
673
985
  }
674
986
 
675
987
  // src/connectors/entries/google-calendar.ts
676
- var baseConnection = createConnectorSdk(googleCalendarConnector, createClient);
677
- var connection = (connectionId, options) => {
678
- if (options) {
679
- return createConnectorSdk(
680
- googleCalendarConnector,
681
- (params) => createClient(params, options)
682
- )(connectionId);
683
- }
684
- return baseConnection(connectionId);
685
- };
988
+ var connection = createConnectorSdk(googleCalendarConnector, createClient);
686
989
  export {
687
990
  connection
688
991
  };