@vatio-ai/cli 0.132.0 → 0.134.0

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,159 @@
1
+ // The owner's side of the workspace, as the inbox's Security, Activity and
2
+ // Plan pages have it: how it is protected, what happened in it, letting Vatio
3
+ // in, handing it over, deleting it, and its plan. The same API the MCP's
4
+ // workspace tools call. What outlives a support grant needs a fresh code from
5
+ // the owner's second factor (--code), as `vatio team invite` does.
6
+
7
+ import { deployClient, workspacesClient } from "./deploy.mjs";
8
+ import { withSecondFactor } from "./team.mjs";
9
+ import { ask, fail, paint, takeFlag, takeValue } from "../support.mjs";
10
+
11
+ const print = (answer) => console.log(JSON.stringify(answer, null, 2));
12
+
13
+ const SECURITY_USAGE = "Usage: vatio security [show] [--json]\n" +
14
+ " vatio security set [--require-2fa on|off] [--retention-days N]";
15
+
16
+ export async function security(config, args) {
17
+ const json = takeFlag(args, "--json");
18
+ const client = deployClient(config, config.resolveWorkspaceRequired());
19
+ const sub = args.shift() ?? "show";
20
+ if (sub === "show") {
21
+ if (args.length) fail(SECURITY_USAGE);
22
+ return showSecurity(await client.get("/security"), json);
23
+ }
24
+ if (sub === "set") {
25
+ const require2fa = takeValue(args, "--require-2fa");
26
+ const retention = takeValue(args, "--retention-days");
27
+ if (args.length || (require2fa === null && retention === null)) fail(SECURITY_USAGE);
28
+ if (require2fa !== null && !["on", "off"].includes(require2fa)) fail(SECURITY_USAGE);
29
+ const body = {};
30
+ if (require2fa !== null) body.require_two_factor = require2fa === "on";
31
+ if (retention !== null) body.retention_days = Number(retention);
32
+ return showSecurity(await client.patch("/security", body), json);
33
+ }
34
+ fail(SECURITY_USAGE);
35
+ }
36
+
37
+ function showSecurity(answer, json) {
38
+ if (json) return print(answer);
39
+ console.log(`Two-step verification for everyone: ${answer.require_two_factor ? "required" : "not required"}`);
40
+ console.log(`Conversations kept: ${answer.retention_days ? `${answer.retention_days} days` : "until deleted"}`);
41
+ if (answer.members_without_two_factor) {
42
+ console.log(`${answer.members_without_two_factor} on the team have no second factor yet.`);
43
+ }
44
+ }
45
+
46
+ const ACTIVITY_USAGE = "Usage: vatio activity [--category NAME] [--page N] [--json]";
47
+
48
+ export async function activity(config, args) {
49
+ const json = takeFlag(args, "--json");
50
+ const category = takeValue(args, "--category");
51
+ const page = takeValue(args, "--page");
52
+ if (args.length) fail(ACTIVITY_USAGE);
53
+ const client = deployClient(config, config.resolveWorkspaceRequired());
54
+ const answer = await client.get("/activity", { category, page });
55
+ if (json) return print(answer);
56
+ for (const event of answer.data ?? []) {
57
+ console.log(`${String(event.at ?? event.created_at ?? "").slice(0, 16).replace("T", " ")} ${event.who ?? event.who_label ?? "Vatio"} ${event.label ?? event.action}`);
58
+ }
59
+ if ((answer.data ?? []).length === 0) console.log("Nothing yet.");
60
+ if (answer.meta?.next_page) console.log(`More: vatio activity --page ${answer.meta.next_page}`);
61
+ }
62
+
63
+ const SUPPORT_USAGE = "Usage: vatio support-access [show] [--json]\n" +
64
+ " vatio support-access open 24h|72h|7d\n" +
65
+ " vatio support-access close";
66
+
67
+ export async function supportAccess(config, args) {
68
+ const json = takeFlag(args, "--json");
69
+ const client = deployClient(config, config.resolveWorkspaceRequired());
70
+ const sub = args.shift() ?? "show";
71
+ let answer;
72
+ if (sub === "show") answer = await client.get("/support_access");
73
+ else if (sub === "open") {
74
+ const duration = args.shift();
75
+ if (!duration || args.length) fail(SUPPORT_USAGE);
76
+ answer = await client.post("/support_access", { duration });
77
+ } else if (sub === "close") answer = await client.delete("/support_access");
78
+ else fail(SUPPORT_USAGE);
79
+ if (json) return print(answer);
80
+ const active = answer.active ?? [];
81
+ if (active.length === 0) return console.log("Vatio staff cannot open this workspace.");
82
+ for (const grant of active) console.log(`Open until ${grant.expires_at} (${grant.kind ?? "granted"})`);
83
+ }
84
+
85
+ const TRANSFER_USAGE = "Usage: vatio transfer [show] [--json]\n" +
86
+ " vatio transfer offer EMAIL [--code CODE | --recovery-code CODE]\n" +
87
+ " vatio transfer cancel\n" +
88
+ " vatio transfer accept SLUG [--code CODE | --recovery-code CODE]\n" +
89
+ " vatio transfer decline SLUG";
90
+
91
+ export async function transfer(config, args) {
92
+ const json = takeFlag(args, "--json");
93
+ const code = takeValue(args, "--code");
94
+ const recoveryCode = takeValue(args, "--recovery-code");
95
+ const sub = args.shift() ?? "show";
96
+ if (sub === "accept" || sub === "decline") {
97
+ const slug = args.shift();
98
+ if (!slug || args.length) fail(TRANSFER_USAGE);
99
+ const account = workspacesClient(config);
100
+ if (sub === "decline") {
101
+ await account.post(`/api/v1/transfers/${encodeURIComponent(slug)}/decline`, {});
102
+ return console.log(`Declined ${slug}: it stays with its owner.`);
103
+ }
104
+ await withSecondFactor((body) => account.post(`/api/v1/transfers/${encodeURIComponent(slug)}/accept`, body),
105
+ { code, recovery_code: recoveryCode });
106
+ return console.log(`${paint("green", "✓")} ${slug} is yours now.`);
107
+ }
108
+
109
+ const client = deployClient(config, config.resolveWorkspaceRequired());
110
+ let answer;
111
+ if (sub === "show") answer = await client.get("/transfer");
112
+ else if (sub === "offer") {
113
+ const email = args.shift();
114
+ if (!email || args.length) fail(TRANSFER_USAGE);
115
+ answer = await withSecondFactor((body) => client.post("/transfer", body), { email, code, recovery_code: recoveryCode });
116
+ } else if (sub === "cancel") answer = await client.delete("/transfer");
117
+ else fail(TRANSFER_USAGE);
118
+ if (json) return print(answer);
119
+ if (answer?.pending) return console.log(`Offered to ${answer.pending.email ?? answer.pending.to ?? "someone"} until ${answer.pending.expires_at}.`);
120
+ console.log(answer?.transferable === false ? "This workspace cannot be transferred." : "No offer open.");
121
+ }
122
+
123
+ const WORKSPACE_USAGE = "Usage: vatio workspace delete SLUG [--yes] [--code CODE | --recovery-code CODE]";
124
+
125
+ export async function workspace(config, args) {
126
+ const yes = takeFlag(args, "--yes");
127
+ const code = takeValue(args, "--code");
128
+ const recoveryCode = takeValue(args, "--recovery-code");
129
+ const sub = args.shift();
130
+ const slug = args.shift();
131
+ if (sub !== "delete" || !slug || args.length) fail(WORKSPACE_USAGE);
132
+ if (slug !== config.resolveWorkspaceRequired()) {
133
+ fail(`${slug} is not the workspace this command is on (${config.resolveWorkspaceRequired()}): name the same one.`);
134
+ }
135
+ if (!yes) {
136
+ if (!process.stdin.isTTY) fail("Deleting a workspace cannot be undone, so without a terminal it needs --yes.");
137
+ const answer = await ask(`${paint("green", "?")} Delete ${slug} for everyone? Type its slug: `);
138
+ if (answer.trim() !== slug) fail("Nothing changed.");
139
+ }
140
+ const client = deployClient(config, slug);
141
+ await withSecondFactor((query) => client.delete(`/workspace${toQuery(query)}`), { code, recovery_code: recoveryCode });
142
+ console.log(`Deleted ${slug}.`);
143
+ }
144
+
145
+ function toQuery(values) {
146
+ const search = new URLSearchParams(Object.entries(values).filter(([, value]) => value));
147
+ const text = search.toString();
148
+ return text ? `?${text}` : "";
149
+ }
150
+
151
+ export async function plan(config, args) {
152
+ const json = takeFlag(args, "--json");
153
+ if (args.length) fail("Usage: vatio plan [--json]");
154
+ const answer = await deployClient(config, config.resolveWorkspaceRequired()).get("/plan");
155
+ if (json) return print(answer);
156
+ console.log(`Plan: ${answer.plan}`);
157
+ console.log(`Conversations this period: ${answer.conversations} of ${answer.included}${answer.over ? " (over)" : ""}`);
158
+ if (answer.period) console.log(`Period: ${answer.period.from} → ${answer.period.to}`);
159
+ }
@@ -0,0 +1,104 @@
1
+ // What the inbox shows about how the agent reaches people and how it is
2
+ // doing: the web widget's look, the Analytics page, the testers on Vatio's
3
+ // shared number and account, and a person stepping into a conversation. The
4
+ // same API the MCP's tools for them call.
5
+
6
+ import { deployClient } from "./deploy.mjs";
7
+ import { fail, paint, takeFlag, takeValue } from "../support.mjs";
8
+
9
+ const print = (answer) => console.log(JSON.stringify(answer, null, 2));
10
+
11
+ const WIDGET_USAGE = "Usage: vatio widget [show] [--json]\n" +
12
+ " vatio widget set [--title T] [--greeting G] [--suggestion S]... [--position left|right]\n" +
13
+ " [--scheme auto|light|dark] [--reply-style stream|paced] [--locale en|es|pt]\n" +
14
+ " A field given replaces that one; the rest stays. Name, about, color and logo are `vatio business set`.";
15
+
16
+ const WIDGET_FLAGS = { "--title": "title", "--greeting": "greeting", "--position": "position", "--scheme": "scheme",
17
+ "--reply-style": "reply_style" };
18
+
19
+ export async function widget(config, args) {
20
+ const json = takeFlag(args, "--json");
21
+ const client = deployClient(config, config.resolveWorkspaceRequired());
22
+ const sub = args.shift() ?? "show";
23
+ if (sub === "show") {
24
+ if (args.length) fail(WIDGET_USAGE);
25
+ return showWidget(await client.get("/widget"), json);
26
+ }
27
+ if (sub !== "set") fail(WIDGET_USAGE);
28
+
29
+ const current = await client.get("/widget");
30
+ const settings = { ...(current.settings && !Array.isArray(current.settings) ? current.settings : {}) };
31
+ for (const [flag, key] of Object.entries(WIDGET_FLAGS)) {
32
+ const value = takeValue(args, flag);
33
+ if (value !== null) settings[key] = value;
34
+ }
35
+ const suggestions = [];
36
+ for (let value = takeValue(args, "--suggestion"); value !== null; value = takeValue(args, "--suggestion")) suggestions.push(value);
37
+ if (suggestions.length) settings.suggestions = suggestions;
38
+ const locale = takeValue(args, "--locale");
39
+ if (args.length) fail(WIDGET_USAGE);
40
+ showWidget(await client.patch("/widget", { settings, locale: locale ?? current.locale }), json);
41
+ }
42
+
43
+ function showWidget(answer, json) {
44
+ if (json) return print(answer);
45
+ const settings = answer.settings && !Array.isArray(answer.settings) ? answer.settings : {};
46
+ const keys = Object.keys(settings);
47
+ console.log(keys.length ? keys.map((key) => `${key.padEnd(12)} ${JSON.stringify(settings[key])}`).join("\n") : "Vatio's defaults.");
48
+ if (answer.locale) console.log(`${"locale".padEnd(12)} ${answer.locale}`);
49
+ console.log("");
50
+ console.log(answer.snippet);
51
+ }
52
+
53
+ export async function analytics(config, args) {
54
+ const json = takeFlag(args, "--json");
55
+ const days = takeValue(args, "--days");
56
+ if (args.length) fail("Usage: vatio analytics [--days N] [--json]");
57
+ const answer = await deployClient(config, config.resolveWorkspaceRequired()).get("/analytics", { days });
58
+ if (json) return print(answer);
59
+ const change = (block) => (block?.previous_total ? ` (${block.previous_total} the ${answer.days} days before)` : "");
60
+ console.log(`Last ${answer.days} days, your customers:`);
61
+ console.log(` conversations ${answer.conversations?.total ?? 0}${change(answer.conversations)}`);
62
+ console.log(` messages ${answer.messages?.total ?? 0}${change(answer.messages)}`);
63
+ if (answer.saved_replies) console.log(` replies Vatio saved ${answer.saved_replies.total ?? 0}`);
64
+ if (answer.after_hours) console.log(` conversations after hours ${answer.after_hours.after_hours ?? 0}`);
65
+ if (answer.asked_team) console.log(` questions to the team ${answer.asked_team.questions ?? 0} (${answer.asked_team.answered ?? 0} answered)`);
66
+ if (answer.flags) console.log(` reports ${answer.flags.opened ?? 0} opened, ${answer.flags.resolved ?? 0} resolved`);
67
+ }
68
+
69
+ const TESTERS_USAGE = "Usage: vatio testers [web|whatsapp|instagram] [--json]\n" +
70
+ " vatio testers rm whatsapp|instagram ID";
71
+
72
+ export async function testers(config, args) {
73
+ const json = takeFlag(args, "--json");
74
+ const client = deployClient(config, config.resolveWorkspaceRequired());
75
+ const sub = args.shift() ?? "whatsapp";
76
+ if (sub === "rm" || sub === "remove") {
77
+ const channel = args.shift();
78
+ const id = args.shift();
79
+ if (!["whatsapp", "instagram"].includes(channel) || !id || args.length) fail(TESTERS_USAGE);
80
+ await client.delete(`/test/${channel === "instagram" ? "instagram_accounts" : "whatsapp_numbers"}/${encodeURIComponent(id)}`);
81
+ return console.log(`${paint("green", "✓")} Removed ${channel} tester ${id}.`);
82
+ }
83
+ if (!["web", "whatsapp", "instagram"].includes(sub) || args.length) fail(TESTERS_USAGE);
84
+ print(await client.get("/test", { channel: sub }));
85
+ if (!json) console.log("\nThe inbox's Try the agent shows the same, with the code that adds a tester.");
86
+ }
87
+
88
+ // `vatio chat reply ID "text"` and `vatio chat release ID`: a person on the
89
+ // team stepping into a customer's conversation, and handing it back.
90
+ export async function conversation(config, sub, args) {
91
+ const json = takeFlag(args, "--json");
92
+ const id = args.shift();
93
+ if (!id) fail(`Usage: vatio chat ${sub} CHAT_ID${sub === "reply" ? ' "TEXT"' : ""}`);
94
+ const client = deployClient(config, config.resolveWorkspaceRequired());
95
+ if (sub === "release") {
96
+ const answer = await client.post(`/conversations/${encodeURIComponent(id)}/release`, {});
97
+ return json ? print(answer) : console.log(`${paint("green", "✓")} The agent answers conversation ${id} again.`);
98
+ }
99
+ const content = args.join(" ").trim();
100
+ if (!content) fail('Usage: vatio chat reply CHAT_ID "TEXT"');
101
+ const answer = await client.post(`/conversations/${encodeURIComponent(id)}/messages`, { content });
102
+ if (json) return print(answer);
103
+ console.log(`${paint("green", "✓")} Sent in conversation ${id}. The agent stays out of it until \`vatio chat release ${id}\`.`);
104
+ }
@@ -309,7 +309,7 @@ export async function shareSession(config, args) {
309
309
 
310
310
  let response;
311
311
  try {
312
- response = await fetch(`${config.resolveBaseUrl()}/api/developer/v1/cli/transcripts`, {
312
+ response = await fetch(`${config.resolveBaseUrl()}/api/v1/cli/transcripts`, {
313
313
  method: "POST",
314
314
  headers: { ...chosenHeaders(), Authorization: `Bearer ${config.resolveToken()}`, Accept: "application/json" },
315
315
  body: form,
@@ -1,16 +1,17 @@
1
- // team — who is in the workspace, and inviting someone: what the inbox's Team
2
- // page does, for a coding agent that is asked to "add Ana as a supervisor". The
3
- // owner's alone, like the page. Removing a member and changing a role stay in
4
- // the inbox, where the owner confirms it is them.
1
+ // team — who is in the workspace, and as what: what the inbox's Team page does,
2
+ // for a coding agent that is asked to "add Ana as a supervisor". The owner's
3
+ // alone, like the page. A person is named by their email; the platform keys
4
+ // them by membership, which the list gives.
5
5
 
6
6
  import { deployClient } from "./deploy.mjs";
7
+ import { errorCode } from "../http.mjs";
7
8
  import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
8
9
 
9
10
  // The answers that say something the generic 401 and 403 lines would hide.
10
11
  const SAYS_WHY = new Set(["owner_only", "reauthentication_required", "invalid_confirmation"]);
11
12
 
12
13
  function explain(error) {
13
- const code = error?.body?.error?.code;
14
+ const code = errorCode(error);
14
15
  if (SAYS_WHY.has(code)) fail(error.message);
15
16
  throw error;
16
17
  }
@@ -18,6 +19,9 @@ function explain(error) {
18
19
  const ROLES = ["viewer", "supervisor", "developer"];
19
20
  const USAGE = `Usage: vatio team [list] [--json]\n` +
20
21
  ` vatio team invite EMAIL --role ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
22
+ ` vatio team role EMAIL ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
23
+ " vatio team rm EMAIL [--json]\n" +
24
+ " vatio team resend EMAIL [--json]\n" +
21
25
  " With a second factor on your account, --code is the 6-digit code from your authenticator app.\n" +
22
26
  " vatio team questions [--to EMAIL...|--none] [--template NAME [--language CODE]|--no-template] [--json]";
23
27
 
@@ -50,9 +54,42 @@ export async function team(config, args) {
50
54
  return print(answer, workspace, json);
51
55
  }
52
56
 
57
+ if (sub === "role" || sub === "rm" || sub === "remove" || sub === "resend") {
58
+ const code = takeValue(args, "--code");
59
+ const recoveryCode = takeValue(args, "--recovery-code");
60
+ const email = args.shift();
61
+ const role = sub === "role" ? args.shift() : null;
62
+ if (!email || args.length > 0 || (sub === "role" && !ROLES.includes(role))) fail(USAGE);
63
+ const member = await memberByEmail(client, email);
64
+ let answer;
65
+ if (sub === "role") {
66
+ answer = await withSecondFactor((confirmed) => client.updateMember(member.id, confirmed),
67
+ { role, code, recovery_code: recoveryCode }).catch(explain);
68
+ } else if (sub === "resend") {
69
+ answer = await client.resendMember(member.id).catch(explain);
70
+ } else {
71
+ answer = await client.removeMember(member.id).catch(explain);
72
+ }
73
+ if (!json) {
74
+ const done = { role: `${member.email} is now ${role}`, resend: `Sent ${member.email} the invitation again`,
75
+ rm: `Removed ${member.email}: they no longer reach this workspace`, remove: `Removed ${member.email}` }[sub];
76
+ console.log(`${paint("green", "✓")} ${done}.`);
77
+ console.log("");
78
+ }
79
+ return print(answer, workspace, json);
80
+ }
81
+
53
82
  fail(USAGE);
54
83
  }
55
84
 
85
+ async function memberByEmail(client, email) {
86
+ const wanted = email.trim().toLowerCase();
87
+ const list = await client.members().catch(explain);
88
+ const member = (list.data ?? []).find((row) => String(row.email).toLowerCase() === wanted);
89
+ if (!member) fail(`${wanted} is not on this workspace's team (vatio team list).`);
90
+ return member;
91
+ }
92
+
56
93
  function print(answer, workspace, json) {
57
94
  if (json) return console.log(JSON.stringify(answer, null, 2));
58
95
  const members = answer.data ?? [];
@@ -75,7 +112,7 @@ export async function withSecondFactor(send, body) {
75
112
  try {
76
113
  return await send(confirmed);
77
114
  } catch (error) {
78
- const needsCode = error?.status === 403 && error?.body?.error?.code === "reauthentication_required";
115
+ const needsCode = error?.status === 403 && errorCode(error) === "reauthentication_required";
79
116
  if (!needsCode || confirmed.code || confirmed.recovery_code) throw error;
80
117
  if (!process.stdin.isTTY || !/--code/.test(error.message)) throw error;
81
118
  const code = await askSecret(`${paint("green", "?")} Code from your authenticator app: `);
@@ -7,7 +7,7 @@
7
7
  import { readFileSync } from "node:fs";
8
8
 
9
9
  import { deployClient } from "./deploy.mjs";
10
- import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
10
+ import { fail, paint, sleep, takeFlag, takeSide, takeValue } from "../support.mjs";
11
11
 
12
12
  const WAIT_INTERVAL_MS = 2_000;
13
13
 
@@ -18,7 +18,7 @@ function takeAll(args, name) {
18
18
  return values;
19
19
  }
20
20
 
21
- const LIST_USAGE = "vatio whatsapp templates list [--env live] [--json]";
21
+ const LIST_USAGE = "vatio whatsapp templates list [--test-number] [--json]";
22
22
  const CREATE_USAGE = "vatio whatsapp templates create NAME --language CODE --body TEXT [--example VALUE]... " +
23
23
  "[--category utility|marketing] [--footer TEXT] [--button-url 'TEXT|URL']... [--button-example VALUE]... " +
24
24
  "[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]... [--json]\n" +
@@ -42,7 +42,7 @@ export async function templates(config, args) {
42
42
  args.shift();
43
43
  return deleteTemplate(config, args, json);
44
44
  }
45
- const environment = takeEnv(args, { fallback: "live" });
45
+ const environment = takeSide(args, "--test-number");
46
46
  const workspace = config.resolveWorkspaceRequired();
47
47
  const client = deployClient(config, workspace);
48
48
  const sub = args.shift() ?? "list";
@@ -58,7 +58,7 @@ export async function templates(config, args) {
58
58
  if (list.length === 0) {
59
59
  if (live && payload.whatsapp_connected === false) {
60
60
  console.log("This workspace has no WhatsApp number of its own yet. The templates you create stay on Vatio's " +
61
- "test number until you connect one, and then Vatio moves them to it: vatio whatsapp templates list --env preview");
61
+ "test number until you connect one, and then Vatio moves them to it: vatio whatsapp templates list --test-number");
62
62
  } else if (!live && payload.whatsapp_connected === true) {
63
63
  console.log("This workspace has its own WhatsApp number, so its templates are there: vatio whatsapp templates list");
64
64
  } else {
@@ -141,10 +141,10 @@ function printCreated(template, json, count) {
141
141
  `${own ? "your own number" : "Vatio's test number"}: ${template.category}, ` +
142
142
  `${count} param${count === 1 ? "" : "s"}, ${paint("cyan", template.status)}.`);
143
143
  console.log("Meta usually decides within minutes, at most 24 hours. Check with: vatio whatsapp templates list" +
144
- (own ? "" : " --env preview"));
144
+ (own ? "" : " --test-number"));
145
145
  console.log(own
146
146
  ? "Once APPROVED, your backend sends it with a live key outside the 24-hour window with:"
147
- : "Once APPROVED, a preview key sends it on Vatio's test number, to your team's verified WhatsApps and your " +
147
+ : "Once APPROVED, a test secret key sends it on Vatio's test number, to your team's verified WhatsApps and your " +
148
148
  "customer phones, outside the 24-hour window with:");
149
149
  console.log(` "template": ${JSON.stringify(template.example)}`);
150
150
  if (!own) {
@@ -201,7 +201,7 @@ async function deleteTemplate(config, args, json) {
201
201
  }
202
202
 
203
203
  export async function webhooks(config, args) {
204
- const environment = takeEnv(args, { fallback: "live" });
204
+ const environment = takeSide(args, "--test");
205
205
  const label = takeValue(args, "--label");
206
206
  const events = takeAll(args, "--event");
207
207
  const workspace = config.resolveWorkspaceRequired();
@@ -210,16 +210,16 @@ export async function webhooks(config, args) {
210
210
 
211
211
  if (sub === "list") {
212
212
  const payload = await client.listWebhookEndpoints();
213
- const list = Array.isArray(payload.webhook_endpoints) ? payload.webhook_endpoints : [];
213
+ const list = Array.isArray(payload.webhooks) ? payload.webhooks : [];
214
214
  if (list.length === 0) {
215
215
  console.log(`No webhook endpoints on workspace ${workspace}`);
216
- console.log(" Add one: vatio webhooks create https://your-app.com/vatio/webhooks --env live");
216
+ console.log(" Add one: vatio webhooks create https://your-app.com/vatio/webhooks");
217
217
  return;
218
218
  }
219
219
  console.log(`Webhook endpoints on workspace ${workspace} (${list.length}):`);
220
220
  for (const endpoint of list) {
221
221
  const state = endpoint.enabled ? paint("green", "enabled") : paint("red", "disabled");
222
- console.log(` #${endpoint.id} ${endpoint.environment} ${endpoint.url} ${state}`);
222
+ console.log(` #${endpoint.id} ${endpoint.environment === "preview" ? "test" : endpoint.environment} ${endpoint.url} ${state}`);
223
223
  console.log(` events: ${endpoint.events.length > 0 ? endpoint.events.join(", ") : "all"}` +
224
224
  (endpoint.consecutive_failures > 0 ? ` failing: ${endpoint.consecutive_failures} in a row` : ""));
225
225
  }
@@ -227,9 +227,9 @@ export async function webhooks(config, args) {
227
227
  }
228
228
  if (sub === "create") {
229
229
  const url = args.shift();
230
- if (!url) fail("Usage: vatio webhooks create URL [--event NAME]... [--label NAME] [--env NAME]");
230
+ if (!url) fail("Usage: vatio webhooks create URL [--event NAME]... [--label NAME] [--test]");
231
231
  const payload = await client.createWebhookEndpoint({ environment, url, events, label });
232
- console.log(`Created webhook endpoint #${payload.id} for ${environment}: ${payload.url}`);
232
+ console.log(`Created ${environment === "preview" ? "a test" : "a live"} webhook endpoint #${payload.id}: ${payload.url}`);
233
233
  console.log(` events: ${payload.events.length > 0 ? payload.events.join(", ") : "all"}`);
234
234
  console.log("");
235
235
  // Vatio signs every delivery with it; it is not shown again.
@@ -284,7 +284,7 @@ export async function webhooks(config, args) {
284
284
  return;
285
285
  }
286
286
 
287
- fail("Usage: vatio webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID [--env NAME]");
287
+ fail("Usage: vatio webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID [--test]");
288
288
  }
289
289
 
290
290
  function printDelivery(delivery) {
@@ -6,6 +6,7 @@ import { existsSync, readFileSync, realpathSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
 
8
8
  import { deployClient } from "./deploy.mjs";
9
+ import { errorCode } from "../http.mjs";
9
10
  import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
10
11
 
11
12
  // The platform says which names exist (preview and live); this only keeps
@@ -99,7 +100,7 @@ async function listSecrets(client, workspace, environment) {
99
100
 
100
101
  function secretScope({ environment, tests }) {
101
102
  if (tests) return "tests";
102
- return environment ? `only ${environment}` : "every environment";
103
+ return environment ? `only the ${environment === "preview" ? "team's" : "customers'"} version, from before` : "everywhere";
103
104
  }
104
105
 
105
106
  function takeRepeated(args, flag) {
@@ -115,7 +116,7 @@ const KINDS = ["publishable", "secret"];
115
116
  // this list is only for the help text. `team` is never given by default.
116
117
  const SCOPES = ["messages", "instagram", "chats", "team"];
117
118
  const KEYS_USAGE =
118
- "Usage: vatio keys list [--json]|create publishable|secret [--env live|preview] [--label NAME] " +
119
+ "Usage: vatio keys list [--json]|create publishable|secret [--test] [--label NAME] " +
119
120
  "[--scope NAME]... [--code CODE | --recovery-code CODE] [--json]|revoke PREFIX";
120
121
 
121
122
  // A publishable key used to take a list of the sites it worked from. It works
@@ -132,7 +133,8 @@ const NO_ORIGINS = "A publishable key works from any site, so there are no origi
132
133
  // it. A secret key carries scopes; without --scope it gets every one but
133
134
  // `team`.
134
135
  export async function keys(config, args) {
135
- const environment = environmentOption(args, "live");
136
+ const test = takeFlag(args, "--test");
137
+ const environment = environmentOption(args, test ? "preview" : "live");
136
138
  const label = takeValue(args, "--label") ?? takeValue(args, "-l");
137
139
  if (takeRepeated(args, "--origin").length > 0) fail(`--origin was removed. ${NO_ORIGINS}`);
138
140
  const scopes = takeRepeated(args, "--scope");
@@ -152,13 +154,13 @@ export async function keys(config, args) {
152
154
  }
153
155
  if (list.length === 0) {
154
156
  console.log(`No API keys on workspace ${workspace}`);
155
- console.log(" Create one: vatio keys create publishable --env live --label website");
156
- console.log(" vatio keys create secret --env live --label backend");
157
+ console.log(" Create one: vatio keys create publishable --label website");
158
+ console.log(" vatio keys create secret --label backend (--test for one that reaches only your team)");
157
159
  return;
158
160
  }
159
161
  console.log(`API keys on workspace ${workspace} (${list.length}):`);
160
162
  for (const key of list) {
161
- const parts = [key.kind, key.prefix, key.environment];
163
+ const parts = [key.kind, key.prefix, key.environment === "preview" ? "test" : key.environment];
162
164
  if (key.label) parts.push(key.label);
163
165
  if (key.managed) parts.push(`managed${key.managed_kind ? ` (${key.managed_kind})` : ""}`);
164
166
  parts.push(key.last_used_at ? `last used ${key.last_used_at}` : "never used");
@@ -174,7 +176,7 @@ export async function keys(config, args) {
174
176
  if (sub === "create") {
175
177
  const kind = args.shift();
176
178
  if (!KINDS.includes(kind)) {
177
- fail("Say which kind: vatio keys create publishable|secret [--env NAME] [--label NAME] [--scope NAME]...");
179
+ fail("Say which kind: vatio keys create publishable|secret [--test] [--label NAME] [--scope NAME]...");
178
180
  }
179
181
  if (kind === "publishable" && scopes.length > 0) {
180
182
  fail(`--scope only applies to a secret key (${SCOPES.join(", ")}).`);
@@ -193,7 +195,7 @@ export async function keys(config, args) {
193
195
  console.log(JSON.stringify({ ...payload, workspace }, null, 2));
194
196
  return;
195
197
  }
196
- console.log(`Created a ${kind} key for ${environment} on workspace ${workspace}`);
198
+ console.log(`Created a ${environment === "preview" ? "test " : ""}${kind} key on workspace ${workspace}`);
197
199
  if (kind === "publishable") console.log(" works from any site");
198
200
  if (kind === "secret") console.log(` scopes: ${asArray(payload.api_key?.scopes).join(", ")}`);
199
201
  console.log("");
@@ -243,7 +245,7 @@ async function createKey(client, { code, recoveryCode, ...fields }) {
243
245
  try {
244
246
  return await client.createApiKey({ ...fields, confirmation }).catch(explainKeyError);
245
247
  } catch (error) {
246
- const needsCode = error?.status === 403 && error?.body?.error?.code === "reauthentication_required";
248
+ const needsCode = error?.status === 403 && errorCode(error) === "reauthentication_required";
247
249
  // explainKeyError let it through only when the terminal can answer it.
248
250
  if (!needsCode || code || recoveryCode) throw error;
249
251
  const typed = await askSecret(`${paint("green", "?")} Code from your authenticator app: `);
package/lib/config.mjs CHANGED
@@ -290,7 +290,7 @@ export class Config {
290
290
  const base = this.resolveBaseUrl();
291
291
  const workspace = this.resolveWorkspace();
292
292
  if (!base || !workspace) return null;
293
- return `${base}/api/developer/v1/${workspace}`;
293
+ return `${base}/api/v1/${workspace}`;
294
294
  }
295
295
 
296
296
  writeAuth({ baseUrl, token }) {
@@ -1,4 +1,4 @@
1
- // Device-code auth (/api/developer/v1/device_authorizations): the CLI asks for a code, the
1
+ // Device-code auth (/api/v1/device_authorizations): the CLI asks for a code, the
2
2
  // developer approves it in a browser, the CLI polls until a token comes back.
3
3
  // The port of cli/lib/device_auth_client.rb.
4
4
  //
@@ -23,11 +23,11 @@ export class DeviceAuthClient {
23
23
  start({ workspace } = {}) {
24
24
  const body = {};
25
25
  if (workspace) body.workspace = workspace;
26
- return this.#post("/api/developer/v1/device_authorizations", body);
26
+ return this.#post("/api/v1/device_authorizations", body);
27
27
  }
28
28
 
29
29
  poll({ deviceCode }) {
30
- return this.#post("/api/developer/v1/device_authorizations/token", { device_code: deviceCode });
30
+ return this.#post("/api/v1/device_authorizations/token", { device_code: deviceCode });
31
31
  }
32
32
 
33
33
  async #post(path, body) {