@vatio-ai/cli 0.59.0 → 0.61.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.
- package/bin/vatio.mjs +8 -1
- package/lib/api-client.mjs +48 -0
- package/lib/commands/auth.mjs +50 -31
- package/lib/commands/deploy.mjs +3 -3
- package/lib/commands/env.mjs +0 -1
- package/lib/commands/webhooks.mjs +142 -0
- package/lib/commands/workspace-admin.mjs +60 -3
- package/lib/config.mjs +18 -0
- package/lib/device-auth.mjs +4 -4
- package/lib/help.mjs +12 -1
- package/lib/support.mjs +7 -5
- package/lib/telemetry.mjs +3 -0
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -12,7 +12,8 @@ import { login, logout } from "../lib/commands/auth.mjs";
|
|
|
12
12
|
import { configCommand, doctor, init, version } from "../lib/commands/misc.mjs";
|
|
13
13
|
import { diff, publish, push, rollback, status } from "../lib/commands/deploy.mjs";
|
|
14
14
|
import { env } from "../lib/commands/env.mjs";
|
|
15
|
-
import { secrets, tokens } from "../lib/commands/workspace-admin.mjs";
|
|
15
|
+
import { keys, secrets, tokens } from "../lib/commands/workspace-admin.mjs";
|
|
16
|
+
import { templates, webhooks } from "../lib/commands/webhooks.mjs";
|
|
16
17
|
import { auth } from "../lib/commands/identity-key.mjs";
|
|
17
18
|
import { chat } from "../lib/commands/chat.mjs";
|
|
18
19
|
import { kb } from "../lib/commands/knowledge.mjs";
|
|
@@ -83,6 +84,12 @@ async function run(command, args) {
|
|
|
83
84
|
return await diff(config, args);
|
|
84
85
|
case "tokens":
|
|
85
86
|
return await tokens(config, args);
|
|
87
|
+
case "keys":
|
|
88
|
+
return await keys(config, args);
|
|
89
|
+
case "templates":
|
|
90
|
+
return await templates(config, args);
|
|
91
|
+
case "webhooks":
|
|
92
|
+
return await webhooks(config, args);
|
|
86
93
|
case "auth":
|
|
87
94
|
return await auth(config, args);
|
|
88
95
|
case "chat":
|
package/lib/api-client.mjs
CHANGED
|
@@ -171,6 +171,54 @@ export class ApiClient extends HttpClient {
|
|
|
171
171
|
return this.patch("/business", fields);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
// --- server keys ----------------------------------------------------
|
|
175
|
+
|
|
176
|
+
listServerKeys() {
|
|
177
|
+
return this.get("/server_keys");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
createServerKey({ environment, label = null }) {
|
|
181
|
+
const body = { environment };
|
|
182
|
+
if (String(label ?? "").trim() !== "") body.label = String(label).trim();
|
|
183
|
+
return this.post("/server_keys", body);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
revokeServerKey({ prefix }) {
|
|
187
|
+
return this.delete(`/server_keys/${encode(prefix)}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// --- templates, webhooks ---------------------------------------------
|
|
191
|
+
|
|
192
|
+
listTemplates({ environment }) {
|
|
193
|
+
return this.get("/templates", { environment });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
listWebhookEndpoints() {
|
|
197
|
+
return this.get("/webhook_endpoints");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
createWebhookEndpoint({ environment, url, events = [], label = null }) {
|
|
201
|
+
const body = { environment, url, events };
|
|
202
|
+
if (String(label ?? "").trim() !== "") body.label = String(label).trim();
|
|
203
|
+
return this.post("/webhook_endpoints", body);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
updateWebhookEndpoint({ id, ...attrs }) {
|
|
207
|
+
return this.patch(`/webhook_endpoints/${encode(id)}`, attrs);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
deleteWebhookEndpoint({ id }) {
|
|
211
|
+
return this.delete(`/webhook_endpoints/${encode(id)}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
testWebhookEndpoint({ id }) {
|
|
215
|
+
return this.post(`/webhook_endpoints/${encode(id)}/test`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
listWebhookDeliveries({ id }) {
|
|
219
|
+
return this.get(`/webhook_endpoints/${encode(id)}/deliveries`);
|
|
220
|
+
}
|
|
221
|
+
|
|
174
222
|
// --- chats ----------------------------------------------------------
|
|
175
223
|
|
|
176
224
|
createChat({ environment }) {
|
package/lib/commands/auth.mjs
CHANGED
|
@@ -1,64 +1,83 @@
|
|
|
1
|
-
// login / logout, and the device-code dance they share with `
|
|
1
|
+
// login / logout, and the device-code dance they share with `push`.
|
|
2
2
|
|
|
3
|
-
import { DeviceAuthClient, ExpiredError, PendingError } from "../device-auth.mjs";
|
|
3
|
+
import { DeniedError, DeviceAuthClient, ExpiredError, PendingError } from "../device-auth.mjs";
|
|
4
4
|
import { DEFAULT_BASE_URL } from "../config.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { fail, openBrowser, sleep, takeValue } from "../support.mjs";
|
|
6
6
|
|
|
7
|
-
// A token is minted by a human
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
7
|
+
// A token is minted by a human signing in on the page this opens -- email,
|
|
8
|
+
// Google or GitHub -- never by the CLI alone, which is why it asks nothing
|
|
9
|
+
// itself: a coding agent running it has no one to ask. The code in flight is
|
|
10
|
+
// kept in the config file, so an agent whose shell gave up waiting picks the
|
|
11
|
+
// same page back up on its next run instead of starting over.
|
|
12
|
+
export async function deviceLogin({ config, baseUrl, message, workspace = null }) {
|
|
11
13
|
const resolved = String(baseUrl || process.env.VATIO_BASE_URL || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
12
14
|
const client = new DeviceAuthClient({ baseUrl: resolved });
|
|
13
15
|
|
|
14
16
|
console.log(message);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const deviceCode = auth.device_code;
|
|
19
|
-
const userCode = auth.user_code;
|
|
20
|
-
const verificationUri = auth.verification_uri_complete ?? auth.verification_uri;
|
|
21
|
-
const interval = Number(auth.interval ?? 5);
|
|
22
|
-
const expiresIn = Number(auth.expires_in ?? 900);
|
|
23
|
-
if (!deviceCode || !verificationUri) fail("The platform did not return a device code");
|
|
17
|
+
let pending = config.pendingLogin();
|
|
18
|
+
const resumed = pending && pending.base_url === resolved && pending.expires_at > Date.now();
|
|
19
|
+
if (!resumed) pending = await startLogin({ config, client, resolved, workspace });
|
|
24
20
|
|
|
25
21
|
console.log("");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.log(`Code: ${userCode}`);
|
|
32
|
-
openBrowser(verificationUri);
|
|
33
|
-
}
|
|
22
|
+
console.log(resumed ? "Still waiting for you to sign in here:" : "Sign in to Vatio here:");
|
|
23
|
+
console.log(` ${pending.url}`);
|
|
24
|
+
console.log(`This terminal is ${pending.user_code} — check the page shows the same code.`);
|
|
25
|
+
console.log("(A coding agent running this: if no browser opened, show this link to the person you work for.)");
|
|
26
|
+
if (!resumed) openBrowser(pending.url);
|
|
34
27
|
console.log("");
|
|
35
|
-
console.log("Waiting…");
|
|
28
|
+
console.log("Waiting… (if this gets cut off, run the same command again once you have signed in)");
|
|
36
29
|
|
|
37
|
-
const deadline = Date.now() + expiresIn * 1000;
|
|
38
30
|
for (;;) {
|
|
39
|
-
if (Date.now() >
|
|
31
|
+
if (Date.now() > pending.expires_at) {
|
|
32
|
+
config.clearPendingLogin();
|
|
33
|
+
fail("The link expired. Run the command again to get a new one.");
|
|
34
|
+
}
|
|
40
35
|
try {
|
|
41
|
-
const result = await client.poll({ deviceCode });
|
|
36
|
+
const result = await client.poll({ deviceCode: pending.device_code });
|
|
37
|
+
config.clearPendingLogin();
|
|
42
38
|
return {
|
|
43
39
|
token: result.token,
|
|
44
40
|
baseUrl: String(result.base_url ?? "").trim() || resolved
|
|
45
41
|
};
|
|
46
42
|
} catch (error) {
|
|
47
43
|
if (error instanceof PendingError) {
|
|
48
|
-
await sleep(interval * 1000);
|
|
44
|
+
await sleep(pending.interval * 1000);
|
|
49
45
|
continue;
|
|
50
46
|
}
|
|
51
|
-
if (error instanceof ExpiredError
|
|
47
|
+
if (error instanceof ExpiredError || error instanceof DeniedError) {
|
|
48
|
+
config.clearPendingLogin();
|
|
49
|
+
fail(error instanceof DeniedError
|
|
50
|
+
? "The sign-in was turned down in the browser. Run the command again to get a new link."
|
|
51
|
+
: "The link expired. Run the command again to get a new one.");
|
|
52
|
+
}
|
|
52
53
|
throw error;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
async function startLogin({ config, client, resolved, workspace }) {
|
|
59
|
+
const auth = await client.start({ workspace });
|
|
60
|
+
const url = auth.verification_uri_complete ?? auth.verification_uri;
|
|
61
|
+
if (!auth.device_code || !url) fail("The platform did not return a device code");
|
|
62
|
+
|
|
63
|
+
const pending = {
|
|
64
|
+
base_url: resolved,
|
|
65
|
+
url,
|
|
66
|
+
device_code: auth.device_code,
|
|
67
|
+
user_code: auth.user_code,
|
|
68
|
+
interval: Number(auth.interval ?? 5),
|
|
69
|
+
expires_at: Date.now() + Number(auth.expires_in ?? 900) * 1000
|
|
70
|
+
};
|
|
71
|
+
config.writePendingLogin(pending);
|
|
72
|
+
return pending;
|
|
73
|
+
}
|
|
74
|
+
|
|
57
75
|
export async function login(config, args) {
|
|
58
76
|
const baseUrl = takeValue(args, "--base-url");
|
|
59
77
|
const { token, baseUrl: resolved } = await deviceLogin({
|
|
78
|
+
config,
|
|
60
79
|
baseUrl,
|
|
61
|
-
message: "
|
|
80
|
+
message: "Signing this machine in to Vatio…"
|
|
62
81
|
});
|
|
63
82
|
|
|
64
83
|
config.writeAuth({ baseUrl: resolved, token });
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -23,10 +23,10 @@ import { detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../supp
|
|
|
23
23
|
|
|
24
24
|
// The first command that makes something exist on a server, so the first one
|
|
25
25
|
// that needs to know whose it is.
|
|
26
|
-
export async function ensureAuthorized(config) {
|
|
26
|
+
export async function ensureAuthorized(config, { workspace = null } = {}) {
|
|
27
27
|
if (config.resolveToken()) return;
|
|
28
28
|
|
|
29
|
-
const auth = await deviceLogin({ message: "Before I can push this, I need to know whose it is." });
|
|
29
|
+
const auth = await deviceLogin({ config, workspace, message: "Before I can push this, I need to know whose it is." });
|
|
30
30
|
config.writeAuth({ baseUrl: auth.baseUrl, token: auth.token });
|
|
31
31
|
console.log(`Token saved to ${config.configPath}`);
|
|
32
32
|
console.log("");
|
|
@@ -90,7 +90,7 @@ export async function push(config, args) {
|
|
|
90
90
|
const environment = takeEnv(args, { fallback: null, cwd: config.workspaceRoot });
|
|
91
91
|
const workspace = config.resolveWorkspaceRequired();
|
|
92
92
|
|
|
93
|
-
await ensureAuthorized(config);
|
|
93
|
+
await ensureAuthorized(config, { workspace });
|
|
94
94
|
|
|
95
95
|
// The remote has to exist before the workspace can be checked: the slug is in
|
|
96
96
|
// the URL of the call that checks it. It is created unnamed; the display name
|
package/lib/commands/env.mjs
CHANGED
|
@@ -52,7 +52,6 @@ async function show(client, workspace, name) {
|
|
|
52
52
|
? ` deployment: #${row.deployment_id}${row.git_sha ? ` (${row.git_sha.slice(0, 7)})` : ""}`
|
|
53
53
|
: " deployment: none yet — `vatio push`");
|
|
54
54
|
if (row.share_url) console.log(` try it: ${row.share_url}`);
|
|
55
|
-
if (row.page_url) console.log(` page with the bubble: ${row.page_url}`);
|
|
56
55
|
if (row.knowledge_url) console.log(` knowledge diff: ${row.knowledge_url}`);
|
|
57
56
|
|
|
58
57
|
if (row.token) {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// `vatio templates` / `vatio webhooks` — what a developer sets up so their
|
|
2
|
+
// backend can send WhatsApp messages through the server API: the templates
|
|
3
|
+
// the number can send, and where Vatio reports what happened. Sending itself
|
|
4
|
+
// is the backend's job, with a server key, not the CLI's.
|
|
5
|
+
|
|
6
|
+
import { deployClient } from "./deploy.mjs";
|
|
7
|
+
import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
8
|
+
|
|
9
|
+
const WAIT_INTERVAL_MS = 2_000;
|
|
10
|
+
|
|
11
|
+
// Repeatable: `--event message.sent --event message.replied`.
|
|
12
|
+
function takeAll(args, name) {
|
|
13
|
+
const values = [];
|
|
14
|
+
for (let value = takeValue(args, name); value !== null; value = takeValue(args, name)) values.push(value);
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function templates(config, args) {
|
|
19
|
+
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
20
|
+
const json = takeFlag(args, "--json");
|
|
21
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
22
|
+
const client = deployClient(config, workspace);
|
|
23
|
+
const sub = args.shift() ?? "list";
|
|
24
|
+
if (sub !== "list") fail("Usage: vatio templates list [--env live] [--json]");
|
|
25
|
+
|
|
26
|
+
const payload = await client.listTemplates({ environment });
|
|
27
|
+
const list = Array.isArray(payload.templates) ? payload.templates : [];
|
|
28
|
+
if (json) {
|
|
29
|
+
console.log(JSON.stringify(list, null, 2));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (list.length === 0) {
|
|
33
|
+
console.log(environment === "live"
|
|
34
|
+
? "No templates on this workspace's WhatsApp number. Create them on the console's Channels → WhatsApp page."
|
|
35
|
+
: "Templates belong to the workspace's own number; the preview number has none of yours. Use --env live.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log(`Templates on the workspace's number (${list.length}):`);
|
|
39
|
+
for (const template of list) {
|
|
40
|
+
const status = template.status === "APPROVED" ? paint("green", template.status) : paint("cyan", template.status);
|
|
41
|
+
const count = template.parameter_count ?? "?";
|
|
42
|
+
console.log(` ${template.name} (${template.language}) ${template.category} ${status} ${count} param${count === 1 ? "" : "s"}`);
|
|
43
|
+
if (template.body) console.log(` ${template.body.replace(/\n/g, "\n ")}`);
|
|
44
|
+
if (template.status === "APPROVED") console.log(` "template": ${JSON.stringify(template.example)}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function webhooks(config, args) {
|
|
49
|
+
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
50
|
+
const label = takeValue(args, "--label");
|
|
51
|
+
const events = takeAll(args, "--event");
|
|
52
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
53
|
+
const client = deployClient(config, workspace);
|
|
54
|
+
const sub = args.shift() ?? "list";
|
|
55
|
+
|
|
56
|
+
if (sub === "list") {
|
|
57
|
+
const payload = await client.listWebhookEndpoints();
|
|
58
|
+
const list = Array.isArray(payload.webhook_endpoints) ? payload.webhook_endpoints : [];
|
|
59
|
+
if (list.length === 0) {
|
|
60
|
+
console.log(`No webhook endpoints on workspace ${workspace}`);
|
|
61
|
+
console.log(" Add one: vatio webhooks create https://your-app.com/vatio/webhooks --env live");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.log(`Webhook endpoints on workspace ${workspace} (${list.length}):`);
|
|
65
|
+
for (const endpoint of list) {
|
|
66
|
+
const state = endpoint.enabled ? paint("green", "enabled") : paint("red", "disabled");
|
|
67
|
+
console.log(` #${endpoint.id} ${endpoint.environment} ${endpoint.url} ${state}`);
|
|
68
|
+
console.log(` events: ${endpoint.events.length > 0 ? endpoint.events.join(", ") : "all"}` +
|
|
69
|
+
(endpoint.consecutive_failures > 0 ? ` failing: ${endpoint.consecutive_failures} in a row` : ""));
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (sub === "create") {
|
|
74
|
+
const url = args.shift();
|
|
75
|
+
if (!url) fail("Usage: vatio webhooks create URL [--event NAME]... [--label NAME] [--env NAME]");
|
|
76
|
+
const payload = await client.createWebhookEndpoint({ environment, url, events, label });
|
|
77
|
+
console.log(`Created webhook endpoint #${payload.id} for ${environment}: ${payload.url}`);
|
|
78
|
+
console.log(` events: ${payload.events.length > 0 ? payload.events.join(", ") : "all"}`);
|
|
79
|
+
console.log("");
|
|
80
|
+
// Vatio signs every delivery with it; it is not shown again.
|
|
81
|
+
console.log(` ${payload.secret}`);
|
|
82
|
+
console.log("");
|
|
83
|
+
console.log("Copy the signing secret now — it is not shown again. Check it with: vatio webhooks test " + payload.id);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (sub === "test") {
|
|
87
|
+
const id = args.shift();
|
|
88
|
+
if (!id) fail("Usage: vatio webhooks test ID");
|
|
89
|
+
const delivery = await client.testWebhookEndpoint({ id });
|
|
90
|
+
console.log(`Sent a ping (${delivery.id}). Waiting for your endpoint…`);
|
|
91
|
+
const deadline = Date.now() + 30_000;
|
|
92
|
+
for (;;) {
|
|
93
|
+
await sleep(WAIT_INTERVAL_MS);
|
|
94
|
+
const { deliveries = [] } = await client.listWebhookDeliveries({ id });
|
|
95
|
+
const current = deliveries.find((entry) => entry.id === delivery.id);
|
|
96
|
+
if (current && (current.status === "delivered" || current.attempts > 0)) {
|
|
97
|
+
printDelivery(current);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (Date.now() > deadline) {
|
|
101
|
+
console.log("No answer yet. Check later with: vatio webhooks deliveries " + id);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (sub === "deliveries") {
|
|
107
|
+
const id = args.shift();
|
|
108
|
+
if (!id) fail("Usage: vatio webhooks deliveries ID");
|
|
109
|
+
const { deliveries = [] } = await client.listWebhookDeliveries({ id });
|
|
110
|
+
if (deliveries.length === 0) {
|
|
111
|
+
console.log("No deliveries yet.");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
for (const delivery of deliveries) printDelivery(delivery);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (sub === "enable") {
|
|
118
|
+
const id = args.shift();
|
|
119
|
+
if (!id) fail("Usage: vatio webhooks enable ID");
|
|
120
|
+
await client.updateWebhookEndpoint({ id, enabled: true });
|
|
121
|
+
console.log(`Enabled webhook endpoint #${id}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (sub === "rm" || sub === "remove" || sub === "delete") {
|
|
125
|
+
const id = args.shift();
|
|
126
|
+
if (!id) fail("Usage: vatio webhooks rm ID");
|
|
127
|
+
await client.deleteWebhookEndpoint({ id });
|
|
128
|
+
console.log(`Removed webhook endpoint #${id}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fail("Usage: vatio webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID [--env NAME]");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function printDelivery(delivery) {
|
|
136
|
+
const status = delivery.status === "delivered"
|
|
137
|
+
? paint("green", "delivered")
|
|
138
|
+
: delivery.status === "failed" ? paint("red", "failed") : paint("cyan", "retrying");
|
|
139
|
+
const http = delivery.response_status ? ` HTTP ${delivery.response_status}` : "";
|
|
140
|
+
const error = delivery.last_error ? ` — ${delivery.last_error}` : "";
|
|
141
|
+
console.log(` ${delivery.id} ${delivery.event} ${status}${http} attempts ${delivery.attempts} ${delivery.created_at}${error}`);
|
|
142
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// secrets / tokens — the
|
|
2
|
-
// deliberately does not carry. A secret is a credential, and so
|
|
3
|
-
// publishable token (with the origins it accepts)
|
|
1
|
+
// secrets / tokens / keys — the things a workspace has that its manifest
|
|
2
|
+
// deliberately does not carry. A secret is a credential, and so are a
|
|
3
|
+
// publishable token (with the origins it accepts) and a server key; none of
|
|
4
|
+
// them is in vatio.yml.
|
|
4
5
|
|
|
5
6
|
import { deployClient } from "./deploy.mjs";
|
|
6
7
|
import { askSecret, branchDefault, fail, paint, takeValue } from "../support.mjs";
|
|
@@ -137,6 +138,62 @@ export async function tokens(config, args) {
|
|
|
137
138
|
);
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
// Server keys: what the developer's own backend calls the server API with --
|
|
142
|
+
// today, to have the agent write to a contact first. Unlike a publishable
|
|
143
|
+
// token it is a secret, and unlike the CLI's own token it belongs to the
|
|
144
|
+
// workspace, so it outlives whoever created it.
|
|
145
|
+
export async function keys(config, args) {
|
|
146
|
+
const environment = environmentOption(args, "live", config.workspaceRoot);
|
|
147
|
+
const label = takeValue(args, "--label") ?? takeValue(args, "-l");
|
|
148
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
149
|
+
const client = deployClient(config, workspace);
|
|
150
|
+
const sub = args.shift() ?? "list";
|
|
151
|
+
|
|
152
|
+
if (sub === "list") {
|
|
153
|
+
const payload = await client.listServerKeys();
|
|
154
|
+
const list = asArray(payload.server_keys);
|
|
155
|
+
if (list.length === 0) {
|
|
156
|
+
console.log(`No server keys on workspace ${workspace}`);
|
|
157
|
+
console.log(" Create one: vatio keys create --env live --label backend");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
console.log(`Server keys on workspace ${workspace} (${list.length}):`);
|
|
161
|
+
for (const key of list) {
|
|
162
|
+
const parts = [key.prefix, key.environment];
|
|
163
|
+
if (key.label) parts.push(key.label);
|
|
164
|
+
parts.push(key.last_used_at ? `last used ${key.last_used_at}` : "never used");
|
|
165
|
+
console.log(` ${parts.join(" ")}`);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (sub === "create") {
|
|
170
|
+
const payload = await client.createServerKey({ environment, label });
|
|
171
|
+
console.log(`Created a server key for ${environment} on workspace ${workspace}`);
|
|
172
|
+
console.log("");
|
|
173
|
+
// The platform keeps only a digest: this is the one time the key exists
|
|
174
|
+
// anywhere it can be copied from.
|
|
175
|
+
console.log(` ${payload.key}`);
|
|
176
|
+
console.log("");
|
|
177
|
+
console.log("Copy it now — it is not shown again. Keep it on your server, never in a page or an app:");
|
|
178
|
+
console.log("");
|
|
179
|
+
console.log(` VATIO_SERVER_KEY=${payload.key}`);
|
|
180
|
+
console.log("");
|
|
181
|
+
console.log("Try it (lists the templates your number can send):");
|
|
182
|
+
console.log(` curl ${config.resolveBaseUrl()}/api/server/v1/${workspace}/templates \\`);
|
|
183
|
+
console.log(' -H "Authorization: Bearer $VATIO_SERVER_KEY"');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (sub === "revoke") {
|
|
187
|
+
const prefix = args.shift();
|
|
188
|
+
if (!prefix) fail("Usage: vatio keys revoke PREFIX");
|
|
189
|
+
await client.revokeServerKey({ prefix });
|
|
190
|
+
console.log(`Revoked ${prefix} on workspace ${workspace}`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
fail("Usage: vatio keys list|create [--env live|preview|NAME] [--label NAME]|revoke PREFIX");
|
|
195
|
+
}
|
|
196
|
+
|
|
140
197
|
// An empty list is not "anywhere": only Vatio's own pages can use the token.
|
|
141
198
|
function originsLine(origins) {
|
|
142
199
|
const list = asArray(origins);
|
package/lib/config.mjs
CHANGED
|
@@ -156,6 +156,24 @@ export class Config {
|
|
|
156
156
|
return this.save(data);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
pendingLogin() {
|
|
160
|
+
const pending = this.load().pending_login;
|
|
161
|
+
return pending && typeof pending === "object" && pending.device_code ? pending : null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
writePendingLogin(pending) {
|
|
165
|
+
const data = this.load();
|
|
166
|
+
data.pending_login = pending;
|
|
167
|
+
return this.save(data);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
clearPendingLogin() {
|
|
171
|
+
const data = this.load();
|
|
172
|
+
if (!Object.hasOwn(data, "pending_login")) return data;
|
|
173
|
+
delete data.pending_login;
|
|
174
|
+
return this.save(data);
|
|
175
|
+
}
|
|
176
|
+
|
|
159
177
|
displayHash() {
|
|
160
178
|
const out = {};
|
|
161
179
|
const base = this.resolveBaseUrl();
|
package/lib/device-auth.mjs
CHANGED
|
@@ -17,11 +17,11 @@ export class DeviceAuthClient {
|
|
|
17
17
|
this.baseUrl = String(baseUrl ?? "").replace(/\/$/, "");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
start({
|
|
20
|
+
// A `workspace` lets the page the developer signs in on wait for that push
|
|
21
|
+
// and land on its test screen.
|
|
22
|
+
start({ workspace } = {}) {
|
|
23
23
|
const body = {};
|
|
24
|
-
if (
|
|
24
|
+
if (workspace) body.workspace = workspace;
|
|
25
25
|
return this.#post("/api/developer/v1/device_authorizations", body);
|
|
26
26
|
}
|
|
27
27
|
|
package/lib/help.mjs
CHANGED
|
@@ -19,7 +19,8 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
19
19
|
|
|
20
20
|
Getting started:
|
|
21
21
|
init [SLUG] [--name NAME] Create vatio.yml here, and the remote to match
|
|
22
|
-
login [--base-url URL]
|
|
22
|
+
login [--base-url URL] Sign this machine in from the browser: email link,
|
|
23
|
+
Google or GitHub. Creates the account if needed
|
|
23
24
|
logout Forget the token
|
|
24
25
|
doctor Node, config, workspace and token status
|
|
25
26
|
version What this CLI is
|
|
@@ -28,6 +29,7 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
28
29
|
|
|
29
30
|
Deploy:
|
|
30
31
|
push [--env NAME] Validate the workspace, then update a preview
|
|
32
|
+
(the first one signs in like \`login\`)
|
|
31
33
|
publish [--env NAME] Promote an environment to live, with its knowledge
|
|
32
34
|
changes. Without --env or a branch, the latest
|
|
33
35
|
push. Refused when GitHub is connected: merge
|
|
@@ -90,8 +92,17 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
90
92
|
tokens list|create [--env NAME] [--label NAME] [--origin URL]...|revoke PREFIX
|
|
91
93
|
tokens origins PREFIX URL...
|
|
92
94
|
The origins a token is accepted from (replaces the list)
|
|
95
|
+
keys list|create [--env NAME] [--label NAME]|revoke PREFIX
|
|
96
|
+
Server keys, for your backend to call the server API
|
|
93
97
|
auth --new-key Keypair that signs the JWT saying who a visitor is
|
|
94
98
|
|
|
99
|
+
Sending from your backend (WhatsApp, with a server key):
|
|
100
|
+
templates list [--env live] [--json]
|
|
101
|
+
The number's templates, parameter counts, and the
|
|
102
|
+
"template" object to send
|
|
103
|
+
webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID
|
|
104
|
+
Where Vatio tells your backend what happened
|
|
105
|
+
|
|
95
106
|
Channels:
|
|
96
107
|
whatsapp Set up in the console; prints the link
|
|
97
108
|
instagram Set up in the console; prints the link
|
package/lib/support.mjs
CHANGED
|
@@ -100,6 +100,12 @@ export function detectGitSha(cwd) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
export function sleep(ms) {
|
|
104
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Works without a terminal too: a coding agent running on the developer's own
|
|
108
|
+
// machine still opens their browser.
|
|
103
109
|
export function openBrowser(url) {
|
|
104
110
|
if (!url) return;
|
|
105
111
|
const command =
|
|
@@ -114,12 +120,8 @@ export function openBrowser(url) {
|
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
export function sleep(ms) {
|
|
118
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
123
|
// Returns "" with nothing attached to stdin, so an agent running `vatio push`
|
|
122
|
-
// in a pipeline
|
|
124
|
+
// in a pipeline never hangs on a prompt.
|
|
123
125
|
export async function ask(question) {
|
|
124
126
|
if (!process.stdin.isTTY) return "";
|
|
125
127
|
|
package/lib/telemetry.mjs
CHANGED
|
@@ -31,6 +31,9 @@ const SUBCOMMANDS = {
|
|
|
31
31
|
business: ["show", "set", "hours"],
|
|
32
32
|
secrets: ["list", "set", "rm"],
|
|
33
33
|
tokens: ["list", "create", "revoke", "origins"],
|
|
34
|
+
keys: ["list", "create", "revoke"],
|
|
35
|
+
templates: ["list"],
|
|
36
|
+
webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
|
|
34
37
|
config: ["show", "get", "set", "unset"]
|
|
35
38
|
};
|
|
36
39
|
|