@ancha-labs/cli 0.1.3 → 0.1.4

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.
@@ -1,22 +1,44 @@
1
1
  // Reference companion, never configure as the agent under test.
2
- // Dependency-free Node >=24; these are native API requests to the local twins.
2
+ // Dependency-free Node >=24; these are native API requests to the local twins: one read per tool the scene has.
3
+ const env = process.env;
4
+ const bearer = token => ({ Authorization: `Bearer ${token}` });
5
+ const basic = (user, password = '') => ({ Authorization: `Basic ${Buffer.from(`${user}:${password}`).toString('base64')}` });
6
+ const json = { 'Content-Type': 'application/json' };
7
+ // [the tool's URL variable, path, headers, and a JSON body for a POST]
3
8
  const calls = [
4
- ['SLACK_API_URL', 'conversations.list', { Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}` }],
5
- ['GITHUB_API_URL', 'repos/acme/starter', { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` }],
6
- ['DATADOG_API_URL', 'api/v1/dashboard', { 'DD-API-KEY': process.env.DD_API_KEY, 'DD-APPLICATION-KEY': process.env.DD_APP_KEY }],
7
- ['PAGERDUTY_API_URL', 'services', { Authorization: `Token token=${process.env.PAGERDUTY_API_TOKEN}`, Accept: 'application/vnd.pagerduty+json;version=2' }],
9
+ ['SLACK_API_URL', 'conversations.list', bearer(env.SLACK_BOT_TOKEN)],
10
+ ['GITHUB_API_URL', 'repos/acme/starter', bearer(env.GITHUB_TOKEN)],
11
+ ['DATADOG_API_URL', 'api/v1/dashboard', { 'DD-API-KEY': env.DD_API_KEY, 'DD-APPLICATION-KEY': env.DD_APP_KEY }],
12
+ ['PAGERDUTY_API_URL', 'services', { Authorization: `Token token=${env.PAGERDUTY_API_TOKEN}`, Accept: 'application/vnd.pagerduty+json;version=2' }],
13
+ ['SALESFORCE_INSTANCE_URL', 'services/data/v67.0/query?q=SELECT+Id+FROM+Account+LIMIT+1', bearer(env.SALESFORCE_ACCESS_TOKEN)],
14
+ ['GOOGLE_ADS_API_URL', 'v26/customers:listAccessibleCustomers', bearer(env.GOOGLE_ADS_ACCESS_TOKEN)],
15
+ ['GMAIL_API_URL', 'gmail/v1/users/me/labels', bearer(env.GMAIL_ACCESS_TOKEN)],
16
+ ['GOOGLE_DRIVE_API_URL', 'drive/v3/files?pageSize=1', bearer(env.GOOGLE_DRIVE_ACCESS_TOKEN)],
17
+ ['GOOGLE_CALENDAR_API_URL', 'calendar/v3/users/me/calendarList', bearer(env.GOOGLE_CALENDAR_ACCESS_TOKEN)],
18
+ ['LINEAR_API_URL', '', { Authorization: env.LINEAR_API_KEY, ...json }, { query: '{ viewer { id } }' }],
19
+ ['OKTA_ORG_URL', 'api/v1/users?limit=1', { Authorization: `SSWS ${env.OKTA_API_TOKEN}` }],
20
+ ['STRIPE_API_URL', 'v1/customers?limit=1', bearer(env.STRIPE_SECRET_KEY)],
21
+ ['CLERK_API_URL', 'v1/users?limit=1', bearer(env.CLERK_SECRET_KEY)],
22
+ ['NOTION_API_URL', 'v1/search', { ...bearer(env.NOTION_TOKEN), 'Notion-Version': '2025-09-03', ...json }, { page_size: 1 }],
23
+ ['DROPBOX_API_URL', '2/users/get_current_account', { ...bearer(env.DROPBOX_ACCESS_TOKEN), ...json }, null],
24
+ ['RESEND_BASE_URL', 'emails', bearer(env.RESEND_API_KEY)],
25
+ ['MICROSOFT_GRAPH_API_URL', 'v1.0/me/drive/root/children', { authorization: `Bearer ${env.MICROSOFT_GRAPH_ACCESS_TOKEN}` }],
26
+ ['SHOPIFY_API_URL', `admin/api/${env.SHOPIFY_API_VERSION}/graphql.json`, { 'X-Shopify-Access-Token': env.SHOPIFY_ACCESS_TOKEN, ...json }, { query: '{ shop { name } }' }],
27
+ ['LOB_API_URL', 'letters?limit=1', basic(env.LOB_API_KEY)],
28
+ ['INTERCOM_API_URL', 'conversations?per_page=1', { ...bearer(env.INTERCOM_ACCESS_TOKEN), Accept: 'application/json' }],
29
+ ['TWILIO_API_URL', `2010-04-01/Accounts/${env.TWILIO_ACCOUNT_SID}/Messages.json?PageSize=1`, basic(env.TWILIO_ACCOUNT_SID, env.TWILIO_AUTH_TOKEN)],
8
30
  ];
9
- for (const [variable, path, headers] of calls) {
10
- const base = process.env[variable];
31
+ for (const [variable, path, headers, body] of calls) {
32
+ const base = env[variable];
11
33
  if (!base) continue;
12
- const url = new URL(`${base.replace(/\/+$/, '')}/${path}`);
34
+ const url = new URL(path ? `${base.replace(/\/+$/, '')}/${path}` : base);
13
35
  // A twin URL is loopback (local server) or carries this environment's /e/<id>/ path (hosted server);
14
36
  // a real API has neither, so the reference companion can never reach one.
15
- const envId = process.env.ANCHA_ENV_ID;
37
+ const envId = env.ANCHA_ENV_ID;
16
38
  const twin = ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname) || (envId && url.pathname.includes(`/e/${envId}/`));
17
39
  if (!twin) throw new Error('reference companions only call Ancha twins: a loopback URL or this environment\'s /e/<id>/ path');
18
- const response = await fetch(url, { headers, signal: AbortSignal.timeout(3000) });
40
+ const response = await fetch(url, { method: body === undefined ? 'GET' : 'POST', headers, ...(body !== undefined && { body: JSON.stringify(body) }), signal: AbortSignal.timeout(3000) });
19
41
  if (!response.ok) throw new Error(`${variable}: HTTP ${response.status}`);
20
- const body = await response.json();
21
- if (body.ok === false) throw new Error(`${variable}: native API error`);
42
+ const result = await response.json();
43
+ if (result.ok === false) throw new Error(`${variable}: native API error`);
22
44
  }
@@ -2,5 +2,25 @@
2
2
  "slack": "Slack: list conversations through the native Web API.",
3
3
  "github": "GitHub: read the acme/starter repository through the native API.",
4
4
  "datadog": "Datadog: list dashboards through the native API.",
5
- "pagerduty": "PagerDuty: list services through the native REST API."
5
+ "pagerduty": "PagerDuty: list services through the native REST API.",
6
+ "salesforce": "Salesforce: query accounts through the native REST API.",
7
+ "google-ads": "Google Ads: list the accessible customers through the native API.",
8
+ "gmail": "Gmail: list the mailbox's labels through the native API.",
9
+ "google-drive": "Google Drive: list files through the native API.",
10
+ "google-calendar": "Google Calendar: list calendars through the native API.",
11
+ "amazon-s3": "Amazon S3: list buckets through the native API.",
12
+ "linear": "Linear: read the viewer through the native GraphQL API.",
13
+ "okta": "Okta: list users through the native Management API.",
14
+ "stripe": "Stripe: list customers through the native API.",
15
+ "clerk": "Clerk: list users through the native Backend API.",
16
+ "notion": "Notion: search the pages shared with the integration through the native API.",
17
+ "dropbox": "Dropbox: read the current account through the native API.",
18
+ "resend": "Resend: list sent emails through the native API.",
19
+ "microsoft-word": "Microsoft Word: list the files in the OneDrive root through Microsoft Graph.",
20
+ "shopify": "Shopify: read the shop through the native Admin GraphQL API.",
21
+ "lob": "Lob: list letters through the native API.",
22
+ "paypal": "PayPal: list subscriptions through the native REST API.",
23
+ "kalshi": "Kalshi: read the portfolio balance through the native Trade API.",
24
+ "intercom": "Intercom: list conversations through the native API.",
25
+ "twilio": "Twilio: list messages through the native REST API."
6
26
  }