@beryl-so/cli 0.17.0 → 0.21.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,145 +0,0 @@
1
- import { extractCode } from "../email-extract.js";
2
- import { dim, green } from "../output.js";
3
- import { arg, flagBool, flagNum, flagStr } from "./util.js";
4
- export const inboxCommands = [
5
- {
6
- name: "inbox create",
7
- summary: "Mint an email inbox that Beryl receives mail for",
8
- groupSummary: "Email inboxes for testing flows that send mail — signups, OTPs, receipts.",
9
- description: "Creates a receiving address under Beryl's inbound email domain and returns it. " +
10
- "Use it wherever a test needs a real, readable mailbox — e.g. as the --email for " +
11
- "`beryl signup`, then read the code back with `beryl inbox read --extract-code`. " +
12
- "Pass --permanent to mint the workspace's single permanent mailbox (no TTL).",
13
- scope: "workspace",
14
- flags: [
15
- {
16
- name: "permanent",
17
- type: "boolean",
18
- description: "Mint the workspace's permanent mailbox (no TTL); one per workspace",
19
- },
20
- {
21
- name: "ttl-hours",
22
- type: "number",
23
- description: "Hours before the inbox expires and stops receiving (1-168, default 24; ignored with --permanent)",
24
- },
25
- { name: "project", type: "string", description: "Attach the inbox to a project id" },
26
- ],
27
- examples: [
28
- "beryl inbox create --json",
29
- "beryl inbox create --ttl-hours 2",
30
- "beryl inbox create --permanent",
31
- ],
32
- async run(ctx, input) {
33
- const ws = await ctx.requireWorkspace(input);
34
- const inbox = (await ctx.client.post(`/workspaces/${ws}/inboxes`, {
35
- ttl_hours: flagBool(input, "permanent") ? null : (flagNum(input, "ttl-hours") ?? 24),
36
- project_id: flagStr(input, "project") ?? null,
37
- }));
38
- return {
39
- data: inbox,
40
- human: `${green("Created")} inbox ${inbox.id}\n\n ${inbox.address}\n\n` +
41
- dim(`Read it with: beryl inbox read ${inbox.id}`),
42
- };
43
- },
44
- },
45
- {
46
- name: "inbox list",
47
- summary: "List the workspace's inboxes, newest first",
48
- description: "Every inbox the workspace has minted with `beryl inbox create`. Expired inboxes " +
49
- "stop receiving and are hard-deleted by a background sweep, so they drop off " +
50
- "this list shortly after their TTL. Pass --permanent for just the permanent mailbox.",
51
- scope: "workspace",
52
- flags: [
53
- {
54
- name: "permanent",
55
- type: "boolean",
56
- description: "Only the workspace's permanent mailbox (no TTL, not run/project scoped)",
57
- },
58
- ],
59
- async run(ctx, input) {
60
- const ws = await ctx.requireWorkspace(input);
61
- const query = flagBool(input, "permanent") ? { permanent: true } : undefined;
62
- return { data: await ctx.client.get(`/workspaces/${ws}/inboxes`, query) };
63
- },
64
- },
65
- {
66
- name: "inbox delete",
67
- summary: "Delete an inbox and every email it has received",
68
- scope: "workspace",
69
- args: [{ name: "inbox-id", description: "Inbox id from `beryl inbox create`", required: true }],
70
- flags: [{ name: "force", type: "boolean", description: "Skip the confirmation prompt" }],
71
- async run(ctx, input) {
72
- const ws = await ctx.requireWorkspace(input);
73
- const id = arg(input, "inbox-id");
74
- await ctx.confirm(`Delete inbox ${id} and its emails?`, flagBool(input, "force"));
75
- await ctx.client.del(`/workspaces/${ws}/inboxes/${id}`);
76
- return { human: "Deleted." };
77
- },
78
- },
79
- {
80
- name: "inbox read",
81
- summary: "Read the latest email from an inbox (waits for one to arrive)",
82
- description: "Waits up to --timeout-s for a matching email and returns it (one blocking request; " +
83
- "the server caps the wait at 50s — re-run to keep waiting). With --extract-code, " +
84
- "also pulls the one-time code (4-8 digits) out of the body/subject — handy for " +
85
- "completing `beryl login --email <addr> --code <code>` unattended. Exits non-zero " +
86
- "if nothing arrives before the timeout.",
87
- scope: "workspace",
88
- args: [{ name: "inbox-id", description: "Inbox id from `beryl inbox create`", required: true }],
89
- flags: [
90
- {
91
- name: "timeout-s",
92
- type: "number",
93
- description: "Seconds to wait for a matching email (0 = don't wait; max 50, default 30)",
94
- },
95
- { name: "since", type: "string", description: "Only emails received after this ISO timestamp" },
96
- { name: "from-contains", type: "string", description: "Only emails whose sender contains this" },
97
- {
98
- name: "subject-contains",
99
- type: "string",
100
- description: "Only emails whose subject contains this",
101
- },
102
- {
103
- name: "extract-code",
104
- type: "boolean",
105
- description: "Also return the one-time code found in the email as `code`",
106
- },
107
- ],
108
- examples: [
109
- "beryl inbox read ibx_123 --timeout-s 45 --json",
110
- "beryl inbox read ibx_123 --subject-contains code --extract-code --json",
111
- ],
112
- async run(ctx, input) {
113
- const ws = await ctx.requireWorkspace(input);
114
- const email = (await ctx.client.get(`/workspaces/${ws}/inboxes/${arg(input, "inbox-id")}/emails/latest`, {
115
- timeout_s: flagNum(input, "timeout-s"),
116
- since: flagStr(input, "since"),
117
- from_contains: flagStr(input, "from-contains"),
118
- subject_contains: flagStr(input, "subject-contains"),
119
- }));
120
- if (!flagBool(input, "extract-code"))
121
- return { data: email };
122
- return { data: { ...email, code: extractCode(email) } };
123
- },
124
- },
125
- {
126
- name: "inbox emails",
127
- summary: "List the emails an inbox has received",
128
- scope: "workspace",
129
- args: [{ name: "inbox-id", description: "Inbox id from `beryl inbox create`", required: true }],
130
- flags: [
131
- { name: "since", type: "string", description: "Only emails received after this ISO timestamp" },
132
- {
133
- name: "limit",
134
- type: "number",
135
- description: "Return only the most recent N emails (newest first)",
136
- },
137
- ],
138
- async run(ctx, input) {
139
- const ws = await ctx.requireWorkspace(input);
140
- return {
141
- data: await ctx.client.get(`/workspaces/${ws}/inboxes/${arg(input, "inbox-id")}/emails`, { since: flagStr(input, "since"), limit: flagNum(input, "limit") }),
142
- };
143
- },
144
- },
145
- ];