-
Notifications
You must be signed in to change notification settings - Fork 4
/
client-tester.js
executable file
·53 lines (46 loc) · 1.04 KB
/
client-tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
import PortierClient from "./dist/index.js";
import { createInterface } from "node:readline";
if (process.argv.length !== 3) {
console.error("Broker required");
process.exit(1);
}
const client = new PortierClient({
broker: process.argv[2],
redirectUri: "http://imaginary-client.test/fake-verify-route",
});
const rl = createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
const wrap = (fn) => {
fn().then(
(res) => {
console.log(`ok\t${res}`);
},
(err) => {
console.log(`err\t${err.message}`);
},
);
};
rl.on("line", (line) => {
const cmd = line.split("\t");
switch (cmd[0]) {
case "echo":
wrap(async () => cmd[1]);
break;
case "auth":
wrap(async () => client.authenticate(cmd[1], cmd[2]));
break;
case "verify":
wrap(async () => client.verify(cmd[1]));
break;
default:
console.error(`invalid command: ${cmd[0]}`);
process.exit(1);
}
});
process.stdin.on("end", () => {
client.destroy();
});