@getdial/cli 0.6.0 → 0.8.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/dist/cli.js +136 -63
- package/dist/commands/call/get.js +37 -0
- package/dist/commands/call/list.js +42 -0
- package/dist/commands/{call.js → call/send.js} +13 -13
- package/dist/commands/doctor.js +22 -22
- package/dist/commands/listen/index.js +2 -2
- package/dist/commands/local-target/add-cmd.js +27 -0
- package/dist/commands/local-target/add-url.js +29 -0
- package/dist/commands/local-target/list.js +16 -0
- package/dist/commands/local-target/remove.js +14 -0
- package/dist/commands/message/list.js +42 -0
- package/dist/commands/{send.js → message/send.js} +6 -6
- package/dist/commands/{numbers → number}/list.js +6 -7
- package/dist/commands/{numbers/provision.js → number/purchase.js} +5 -7
- package/dist/commands/onboard.js +53 -24
- package/dist/commands/signup.js +5 -5
- package/dist/commands/wait-for.js +3 -3
- package/dist/lib/fanout.js +131 -0
- package/dist/lib/local-targets.js +122 -0
- package/dist/lib/paths.js +1 -0
- package/dist/lib/pubnub.js +6 -2
- package/dist/lib/skill-install.js +100 -0
- package/dist/lib/state.js +6 -6
- package/package.json +5 -2
- package/skill.tar.gz +0 -0
- package/dist/commands/test-2fa/run.js +0 -84
- package/dist/commands/test-2fa/start.js +0 -38
- package/dist/commands/test-2fa/verify.js +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getdial/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Dial CLI — install, sign up, and run the local listen service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
+
"skill.tar.gz",
|
|
16
17
|
"README.md"
|
|
17
18
|
],
|
|
18
19
|
"scripts": {
|
|
19
20
|
"build": "tsc -p .",
|
|
20
21
|
"test": "node --import tsx --test",
|
|
21
|
-
"clean": "rm -rf dist"
|
|
22
|
+
"clean": "rm -rf dist skill.tar.gz",
|
|
23
|
+
"build:skill": "tar -czf skill.tar.gz skill",
|
|
24
|
+
"prepack": "npm run build && npm run build:skill"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"commander": "^14.0.3",
|
package/skill.tar.gz
ADDED
|
Binary file
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { readAuth } from "../../lib/state.js";
|
|
2
|
-
import { apiPost } from "../../lib/api.js";
|
|
3
|
-
import { paths } from "../../lib/paths.js";
|
|
4
|
-
import { supervisorStatus } from "../../lib/supervisor/index.js";
|
|
5
|
-
import { currentSize, tailUntilMatch } from "../../lib/log-tail.js";
|
|
6
|
-
import { parseRegexArg } from "../../lib/event-filter.js";
|
|
7
|
-
export async function runTest2faRun(opts) {
|
|
8
|
-
const auth = readAuth();
|
|
9
|
-
if (!auth) {
|
|
10
|
-
return fail(opts.json, "not_signed_in", "Not signed in. Run `dial signup` and `dial onboard` first.", 1);
|
|
11
|
-
}
|
|
12
|
-
const supervisor = supervisorStatus();
|
|
13
|
-
if (!supervisor.installed || !supervisor.running) {
|
|
14
|
-
return fail(opts.json, "listen_not_running", `Listen daemon is not running (installed=${supervisor.installed}, running=${supervisor.running}). Run \`dial listen install\`.`, 3);
|
|
15
|
-
}
|
|
16
|
-
const numberId = opts.numberId ?? auth.phone_number_id;
|
|
17
|
-
if (!numberId) {
|
|
18
|
-
return fail(opts.json, "no_number", "No default phone_number_id in auth. Pass --number-id <id>.", 1);
|
|
19
|
-
}
|
|
20
|
-
// Start listening BEFORE triggering the send so we don't miss the event.
|
|
21
|
-
const logFile = paths().listenLog;
|
|
22
|
-
const startOffset = currentSize(logFile);
|
|
23
|
-
const startedAt = Date.now();
|
|
24
|
-
const startRes = await apiPost("/api/v1/test/2fa", { phone_number_id: numberId }, auth.api_key);
|
|
25
|
-
if (!startRes.ok) {
|
|
26
|
-
return fail(opts.json, "start_failed", startRes.error, 2, { status: startRes.status });
|
|
27
|
-
}
|
|
28
|
-
// The test backend sends "Your Dial verification code is NNNNNN" — match the body.
|
|
29
|
-
const spec = {
|
|
30
|
-
eventType: "message.received",
|
|
31
|
-
fields: [{ name: "channel", value: "sms" }],
|
|
32
|
-
regexes: [parseRegexArg("body=/Your Dial verification code is \\d{6}/")],
|
|
33
|
-
};
|
|
34
|
-
const hit = await tailUntilMatch(logFile, spec, startOffset, opts.timeoutSeconds * 1000);
|
|
35
|
-
if (!hit) {
|
|
36
|
-
return fail(opts.json, "sms_timeout", `Timed out after ${opts.timeoutSeconds}s waiting for the SMS event in the listen log.`, 2, { session_id: startRes.data.session_id });
|
|
37
|
-
}
|
|
38
|
-
const body = String(hit.obj.body ?? "");
|
|
39
|
-
const codeMatch = /\b\d{6}\b/.exec(body);
|
|
40
|
-
if (!codeMatch) {
|
|
41
|
-
return fail(opts.json, "no_code_in_body", `Could not extract 6-digit code from SMS body: ${body}`, 2, {
|
|
42
|
-
session_id: startRes.data.session_id,
|
|
43
|
-
body,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const code = codeMatch[0];
|
|
47
|
-
const verifyRes = await apiPost(`/api/v1/test/2fa/${encodeURIComponent(startRes.data.session_id)}/verify`, { code }, auth.api_key);
|
|
48
|
-
if (!verifyRes.ok) {
|
|
49
|
-
return fail(opts.json, "verify_failed", verifyRes.error, 2, {
|
|
50
|
-
status: verifyRes.status,
|
|
51
|
-
session_id: startRes.data.session_id,
|
|
52
|
-
code,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const totalMs = Date.now() - startedAt;
|
|
56
|
-
if (opts.json) {
|
|
57
|
-
console.log(JSON.stringify({
|
|
58
|
-
ok: true,
|
|
59
|
-
verified: verifyRes.data.verified,
|
|
60
|
-
session_id: startRes.data.session_id,
|
|
61
|
-
code,
|
|
62
|
-
number_id: numberId,
|
|
63
|
-
total_ms: totalMs,
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
else if (verifyRes.data.verified) {
|
|
67
|
-
console.log(`verified.`);
|
|
68
|
-
console.log(` session: ${startRes.data.session_id}`);
|
|
69
|
-
console.log(` code: ${code}`);
|
|
70
|
-
console.log(` total time: ${totalMs}ms`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.error(`Backend rejected the extracted code "${code}" (verified=false).`);
|
|
74
|
-
return 2;
|
|
75
|
-
}
|
|
76
|
-
return 0;
|
|
77
|
-
}
|
|
78
|
-
function fail(json, code, message, exitCode, extra) {
|
|
79
|
-
if (json)
|
|
80
|
-
console.log(JSON.stringify({ ok: false, code, message, ...extra }));
|
|
81
|
-
else
|
|
82
|
-
console.error(message);
|
|
83
|
-
return exitCode;
|
|
84
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readAuth } from "../../lib/state.js";
|
|
2
|
-
import { apiPost } from "../../lib/api.js";
|
|
3
|
-
export async function runTest2faStart(opts) {
|
|
4
|
-
const auth = readAuth();
|
|
5
|
-
if (!auth) {
|
|
6
|
-
fail(opts.json, "not_signed_in", "Not signed in. Run `dial signup` and `dial onboard` first.");
|
|
7
|
-
return 1;
|
|
8
|
-
}
|
|
9
|
-
const numberId = opts.numberId ?? auth.phone_number_id;
|
|
10
|
-
if (!numberId) {
|
|
11
|
-
fail(opts.json, "no_number", "No default phone_number_id in auth. Pass --number-id <id>.");
|
|
12
|
-
return 1;
|
|
13
|
-
}
|
|
14
|
-
const res = await apiPost("/api/v1/test/2fa", { phone_number_id: numberId }, auth.api_key);
|
|
15
|
-
if (!res.ok) {
|
|
16
|
-
fail(opts.json, "start_failed", res.error, { status: res.status });
|
|
17
|
-
return 2;
|
|
18
|
-
}
|
|
19
|
-
if (opts.json) {
|
|
20
|
-
console.log(JSON.stringify({ ok: true, session_id: res.data.session_id, otp_message: res.data.otp_message, number_id: numberId }));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
console.log(`test 2fa session started.`);
|
|
24
|
-
console.log(` session: ${res.data.session_id}`);
|
|
25
|
-
console.log(` expected SMS: ${res.data.otp_message}`);
|
|
26
|
-
console.log(` to number: ${numberId}`);
|
|
27
|
-
console.log(``);
|
|
28
|
-
console.log(`Wait for it with: dial wait-for message.received -f channel=sms --json`);
|
|
29
|
-
console.log(`Or run the whole loop: dial test-2fa run`);
|
|
30
|
-
}
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
function fail(json, code, message, extra) {
|
|
34
|
-
if (json)
|
|
35
|
-
console.log(JSON.stringify({ ok: false, code, message, ...extra }));
|
|
36
|
-
else
|
|
37
|
-
console.error(message);
|
|
38
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { readAuth } from "../../lib/state.js";
|
|
2
|
-
import { apiPost } from "../../lib/api.js";
|
|
3
|
-
export async function runTest2faVerify(opts) {
|
|
4
|
-
const auth = readAuth();
|
|
5
|
-
if (!auth) {
|
|
6
|
-
fail(opts.json, "not_signed_in", "Not signed in. Run `dial signup` and `dial onboard` first.");
|
|
7
|
-
return 1;
|
|
8
|
-
}
|
|
9
|
-
const res = await apiPost(`/api/v1/test/2fa/${encodeURIComponent(opts.sessionId)}/verify`, { code: opts.code }, auth.api_key);
|
|
10
|
-
if (!res.ok) {
|
|
11
|
-
fail(opts.json, "verify_failed", res.error, { status: res.status });
|
|
12
|
-
return 2;
|
|
13
|
-
}
|
|
14
|
-
if (opts.json) {
|
|
15
|
-
console.log(JSON.stringify({ ok: true, verified: res.data.verified, session_id: opts.sessionId }));
|
|
16
|
-
}
|
|
17
|
-
else if (res.data.verified) {
|
|
18
|
-
console.log("verified.");
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
console.log("not verified.");
|
|
22
|
-
return 2;
|
|
23
|
-
}
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
26
|
-
function fail(json, code, message, extra) {
|
|
27
|
-
if (json)
|
|
28
|
-
console.log(JSON.stringify({ ok: false, code, message, ...extra }));
|
|
29
|
-
else
|
|
30
|
-
console.error(message);
|
|
31
|
-
}
|