@noisybrood/cli 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,84 @@
1
- # Temporary Holding Version
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset=".github/banner-dark.png">
3
+ <img alt="Noisy Brood: The command line" src=".github/banner-light.png">
4
+ </picture>
2
5
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
6
+ # The command line
7
+
8
+ [![npm](https://img.shields.io/npm/v/@noisybrood/cli)](https://www.npmjs.com/package/@noisybrood/cli)
9
+ [![The check, on the latest copy](https://github.com/Noisy-Brood/brood-cli/actions/workflows/check.yml/badge.svg)](https://github.com/Noisy-Brood/brood-cli/actions/workflows/check.yml)
10
+ [![Licence: Apache-2.0](https://img.shields.io/badge/licence-Apache--2.0-blue)](LICENSE)
11
+
12
+ `brood` answers questions about your mailbox from Noisy Brood's index: who
13
+ writes to you, how often, who has gone quiet, and what Brood has decided about
14
+ each. It never reads a message. The index holds no subject, no body and no
15
+ attachment, so there is nothing of what anyone wrote for it to show you.
16
+
17
+ It changes your mailbox in three ways only: `brood hush` and `brood unhush`,
18
+ which file a sender's mail and bring it back, and `brood keep add`, which adds
19
+ addresses and domains to the list of senders Brood never files. Each needs you
20
+ to have signed in with that permission.
21
+
22
+ ## Install
23
+
24
+ It needs Node 24 or later.
25
+
26
+ ```
27
+ npm install --global @noisybrood/cli@0.2.0
28
+ ```
29
+
30
+ Name the version. Each one published is fixed once it is on npm, and carries
31
+ a provenance attestation, shown on its npm page, saying it was built here,
32
+ from this repository's source.
33
+
34
+ ## Sign in
35
+
36
+ ```
37
+ brood login
38
+ ```
39
+
40
+ It shows a code and an address. Open the address in a browser where you are
41
+ signed in to Noisy Brood, and approve the code. Nothing is typed into the
42
+ terminal but the command. `brood login --read-only` asks for a session that
43
+ can only read.
44
+
45
+ The session is kept in your keychain: macOS's, or on Linux the desktop's
46
+ Secret Service. Where there is none, it goes in `~/.config/brood/credentials.json`
47
+ (or under `XDG_CONFIG_HOME`), readable only by you. `brood logout` ends it at
48
+ Brood before forgetting it. To shut it out at once, revoke it on your account page.
49
+
50
+ ## Ask
51
+
52
+ ```
53
+ brood senders who wrote, most first
54
+ brood senders stripe.com one sender
55
+ brood quiet senders that have gone silent
56
+ brood week one finished week, beside the week before
57
+ brood classifications what Brood has decided, and its state
58
+ brood help everything else
59
+ ```
60
+
61
+ Every command that reads your index takes `--json`, which prints the answer
62
+ as the API gives it.
63
+ Before an answer, brood says any mailbox it could not read whole, so a quiet
64
+ answer is never taken for a quiet mailbox.
65
+
66
+ ## Reading the comments
67
+
68
+ The code's comments refer to internal design documents and issues, such as
69
+ `DD10 §6` or `#1367`. Those are private. You do not need them to read the code
70
+ or run its tests.
71
+
72
+ ## This repository
73
+
74
+ This repository is where brood is built and published, copied one way from a
75
+ private one. brood is written and reviewed there, and copied here with the
76
+ parts of Noisy Brood's own packages it compiles in whenever it changes.
77
+ Nothing here is edited by hand, and it takes no pull requests. A tag starts
78
+ the publish workflow, which builds the package here and stages it on npm
79
+ with provenance, holding no npm token, and a maintainer approves each version
80
+ with a second factor before it is published.
81
+
82
+ Questions and ideas are welcome in
83
+ [Discussions](https://github.com/Noisy-Brood/brood-cli/discussions), and bugs as
84
+ issues. A security problem is never either: see [SECURITY.md](SECURITY.md).
@@ -0,0 +1,58 @@
1
+ import { APP_ORIGIN } from "./origin.js";
2
+ /**
3
+ * What a client of the API needs, and nothing of how the app answers (#1408):
4
+ * where to call and sign in, each operation's arguments and answer, and the
5
+ * problems a client branches on. The CLI imports this alone, so its public
6
+ * mirror carries it alone; the operations' descriptions, the arguments'
7
+ * narrowing and when each problem is answered are the app's half of this
8
+ * package, which re-exports this.
9
+ */
10
+ export * from "./values.js";
11
+ /** Where every operation is called, by POST with its arguments in the body (DD21 §2, §3). */
12
+ export const API_BASE = `${APP_ORIGIN}/api/v1`;
13
+ /**
14
+ * Where a client signs in (DD21 §4): Clerk's OAuth server for the production
15
+ * instance, and each client's id there. A client id is not a secret: a public
16
+ * client is known by it alone, and ships it (#1354).
17
+ */
18
+ export const SIGN_IN = {
19
+ issuer: "https://clerk.app.noisybrood.com",
20
+ clients: { cli: "P029s9c7VAQInceB" },
21
+ };
22
+ /** The codes a problem carries, which clients branch on (DD21 §8, RFC 9457). */
23
+ export const PROBLEM_CODES = [
24
+ "invalid_argument",
25
+ "unauthenticated",
26
+ "credential_revoked",
27
+ "insufficient_scope",
28
+ "plan_required",
29
+ "not_found",
30
+ "mailbox_unreachable",
31
+ "never_quiet",
32
+ "in_progress",
33
+ "rate_limited",
34
+ "internal",
35
+ ];
36
+ /**
37
+ * Each problem's status and title (DD21 §8, RFC 9457), which a client shows
38
+ * and branches on.
39
+ */
40
+ export const PROBLEM_TITLES = {
41
+ invalid_argument: { status: 400, title: "An argument is not valid" },
42
+ unauthenticated: { status: 401, title: "Not signed in" },
43
+ credential_revoked: { status: 401, title: "This credential was revoked" },
44
+ insufficient_scope: { status: 403, title: "This credential may not do that" },
45
+ plan_required: { status: 403, title: "This needs Pro" },
46
+ not_found: { status: 404, title: "Not found" },
47
+ mailbox_unreachable: {
48
+ status: 409,
49
+ title: "Brood cannot reach this mailbox",
50
+ },
51
+ never_quiet: {
52
+ status: 409,
53
+ title: "Your never-quiet list keeps this in view",
54
+ },
55
+ in_progress: { status: 409, title: "Brood is still undoing this" },
56
+ rate_limited: { status: 429, title: "Too many calls" },
57
+ internal: { status: 500, title: "Something went wrong" },
58
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The app's origin: where the API answers, and where every surface that links
3
+ * into the app or posts to it builds its address from. A file of its own,
4
+ * with no imports, so the pitch site's middleware and the checks can read it
5
+ * without the rest of the API.
6
+ */
7
+ export const APP_ORIGIN = "https://app.noisybrood.com";
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The values the API's answers and arguments take, as lists, so the types
3
+ * derive from them and the reference names them from them (#1344): one
4
+ * home for each, with no value typed twice.
5
+ */
6
+ /** A classification's states, as the engine's list holds them, which a test keeps equal. */
7
+ export const CLASSIFICATION_STATES = [
8
+ "proposed",
9
+ "active",
10
+ "quieted",
11
+ "declined",
12
+ ];
13
+ /** Why the engine proposed or moved a classification, as the engine's list holds them. */
14
+ export const CLASSIFICATION_REASONS = [
15
+ "volume",
16
+ "subdomain_split",
17
+ "customer",
18
+ "silence",
19
+ "correction_streak",
20
+ "reproposed",
21
+ "filter_missing",
22
+ "restored",
23
+ "kept_out",
24
+ "adopted",
25
+ "by_hand",
26
+ ];
27
+ /** How a week sounded beside the one before; `first` with none to compare. */
28
+ export const TONES = ["quieter", "louder", "much the same", "first"];
29
+ /** How a week sounded, as a reader is told it, with no number in it: the app's week page and `brood week` both say it. */
30
+ export const TONE_TITLES = {
31
+ quieter: "A quieter week.",
32
+ louder: "A louder week.",
33
+ "much the same": "A week much like the one before.",
34
+ first: "The first week Brood can tell you about.",
35
+ };
36
+ /** What a sender is, as the app tags it. */
37
+ export const SENDER_TAGS = [
38
+ "customer",
39
+ "filed",
40
+ "quieted",
41
+ "correspondence",
42
+ "mailing",
43
+ ];
44
+ /** How much of a sender is meant: everything under its root domain, or the one address. */
45
+ export const SENDER_SCOPES = ["domain", "address"];
46
+ /** What a classification covers: a domain and everything under it, or one address. */
47
+ export const SUBJECT_KINDS = ["domain", "sender"];
48
+ /** How a classification is shown in a mailbox. */
49
+ export const SHOWN = ["active", "quieted", "left"];
50
+ /** Which way a message went. */
51
+ export const DIRECTIONS = ["inbound", "outbound"];
52
+ /** How the person was addressed on a message. */
53
+ export const ADDRESSED = ["to", "cc", "neither"];
54
+ /**
55
+ * What an entry on the never-quiet list names: one sender's address, a domain
56
+ * and everything under it, a pattern on an address's local part, or an
57
+ * address copied on a message, which keeps that mail alone in view (#663).
58
+ */
59
+ export const KEPT_KINDS = ["address", "domain", "pattern", "copied"];
60
+ /**
61
+ * What became of one line given to `keep`, or would, as the never-quiet
62
+ * list's paste says it in the app, which a test keeps equal: kept, there
63
+ * already, said twice, not in force since a filter could not change, or
64
+ * refused for what it is.
65
+ */
66
+ export const KEEP_OUTCOMES = [
67
+ "added",
68
+ "already_listed",
69
+ "repeated",
70
+ "not_in_force",
71
+ "invalid_address",
72
+ "invalid_domain",
73
+ "invalid_pattern",
74
+ "unrenderable",
75
+ ];
76
+ /**
77
+ * What became of one line given to `add_customers`, or would, as the
78
+ * Customers page's paste says it, which a test keeps equal: a customer, one
79
+ * already, a domain that names no organisation, one that cannot be read, a
80
+ * site's address, or a line Brood failed on.
81
+ */
82
+ export const CUSTOMER_OUTCOMES = [
83
+ "added",
84
+ "already",
85
+ "shared",
86
+ "invalid",
87
+ "address",
88
+ "failed",
89
+ ];
90
+ /** A list of values as the reference writes them: each as code, `or` before the last. */
91
+ export const listed = (values) => values.length < 2
92
+ ? values.map((v) => `\`${v}\``).join("")
93
+ : `${values
94
+ .slice(0, -1)
95
+ .map((v) => `\`${v}\``)
96
+ .join(", ")} or \`${values.at(-1)}\``;
@@ -0,0 +1,4 @@
1
+ // The figures the CLI uses, as Brood's figures hold them.
2
+ export const API_PAGE_MAX = 200;
3
+ export const API_STRETCH_DAYS = 30;
4
+ export const PORTRAIT_DAYS = 90;
@@ -0,0 +1,2 @@
1
+ // The dark scheme's colours the CLI uses, as Brood's tokens hold them.
2
+ export const DARK_BARN = "#d4786b";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The wren, as coordinates: the mark's one source, beside the colours it is
3
+ * inked in, so the sites' component and the app's draw the same bird (DD13 §6:
4
+ * the app shares tokens, never components).
5
+ *
6
+ * Drawn on a 100×100 field, facing right, tail cocked — the posture is the
7
+ * diagnostic thing about a wren and the silhouette has to carry it at 24px,
8
+ * where nothing else survives.
9
+ */
10
+ /** The closed outline: beak, crown, back, tail, belly, breast. */
11
+ export const BODY = `M94 43 L76 40
12
+ C71 25 54 20 44 31 C39 36 36 42 34 48
13
+ L12 20 L9 30 L3 26 L27 64
14
+ C29 78 44 85 58 81 C72 77 80 62 78 48 Z`;
15
+ /** The eye, punched through the body as a hole. Never a second colour. */
16
+ export const EYE = { cx: 68, cy: 35, r: 3.2 };
17
+ /** The folded wing, as an open curve punched through the body. */
18
+ export const WING = `M42 52 C52 61 60 67 66 67`;
19
+ /**
20
+ * The weight of the wing and the eye's detail strokes, in user units on the
21
+ * 100-unit field, so it is a fixed share of the mark at any size: the wing
22
+ * holds its weight at 22px in the app's rail and at 72px on a title slide
23
+ * alike. One number for every renderer, so no two draw a different bird.
24
+ */
25
+ export const DETAIL_WEIGHT = 3.2;
26
+ /** The field everything above is drawn on. */
27
+ export const VIEWBOX = "0 0 100 100";
28
+ /** A path on one line, as an SVG file carries it. */
29
+ const oneLine = (d) => d.replace(/\s+/g, " ").trim();
30
+ /**
31
+ * The mark as a file of its own: the body, with the eye and the wing
32
+ * punched through to whatever is behind, so it needs no ground. `paint`
33
+ * inks the body: a colour, or a stylesheet setting `.wren`'s fill, as the
34
+ * favicon's does to follow the system's scheme. `comment` heads the file.
35
+ * `ground`, when given, sets the bird on a square of that colour with
36
+ * `margin` units of room on each side, for a place that shows an icon on a
37
+ * ground it chooses, such as a dark screen.
38
+ */
39
+ export function wrenSvg(paint, comment, ground) {
40
+ const style = "style" in paint ? `\n <style>\n${paint.style}\n </style>` : "";
41
+ const ink = "fill" in paint ? `fill="${paint.fill}"` : `class="wren"`;
42
+ const m = ground?.margin ?? 0;
43
+ const field = `x="${-m}" y="${-m}" width="${100 + 2 * m}" height="${100 + 2 * m}"`;
44
+ const viewBox = ground
45
+ ? `${-m} ${-m} ${100 + 2 * m} ${100 + 2 * m}`
46
+ : VIEWBOX;
47
+ const square = ground ? `\n <rect ${field} fill="${ground.fill}"/>` : "";
48
+ return `<!-- ${comment} -->
49
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}">${style}${square}
50
+ <mask id="wren">
51
+ <rect ${ground ? field : 'width="100" height="100"'} fill="white"/>
52
+ <circle cx="${EYE.cx}" cy="${EYE.cy}" r="${EYE.r}" fill="black"/>
53
+ <path d="${oneLine(WING)}" fill="none" stroke="black" stroke-width="${DETAIL_WEIGHT}" stroke-linecap="round"/>
54
+ </mask>
55
+ <path ${ink} d="${oneLine(BODY)}" mask="url(#wren)"/>
56
+ </svg>
57
+ `;
58
+ }
package/dist/brood.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { text } from "node:stream/consumers";
5
+ import { keychainFor } from "./keychain.js";
6
+ import { run } from "./main.js";
7
+ process.exitCode = await run({
8
+ fetch: (url, init) => fetch(url, init),
9
+ env: process.env,
10
+ now: () => Date.now(),
11
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
12
+ out: (line) => process.stdout.write(`${line}\n`),
13
+ err: (line) => process.stderr.write(`${line}\n`),
14
+ tty: process.stdout.isTTY === true,
15
+ input: () => text(process.stdin),
16
+ read: (path) => readFile(path, "utf8"),
17
+ // Asked on standard error, so an answer piped elsewhere holds none of it.
18
+ ask: process.stdin.isTTY && process.stderr.isTTY
19
+ ? async (question) => {
20
+ const terminal = createInterface({
21
+ input: process.stdin,
22
+ output: process.stderr,
23
+ });
24
+ try {
25
+ return await terminal.question(question);
26
+ }
27
+ finally {
28
+ terminal.close();
29
+ }
30
+ }
31
+ : null,
32
+ keychain: keychainFor(process.platform),
33
+ }, process.argv.slice(2));
package/dist/client.js ADDED
@@ -0,0 +1,100 @@
1
+ import { API_BASE, PROBLEM_CODES, PROBLEM_TITLES, } from "./brood/api/src/client.js";
2
+ import { clean, cleaned, isRecord, Refused, Refusal } from "./io.js";
3
+ import { freshCredentials, refresh } from "./sign-in.js";
4
+ import { VERSION } from "./version.js";
5
+ const isProblem = (v) => isRecord(v) &&
6
+ typeof v.status === "number" &&
7
+ typeof v.title === "string" &&
8
+ PROBLEM_CODES.some((c) => c === v.code);
9
+ const isEnvelope = (v) => isRecord(v) &&
10
+ isRecord(v.data) &&
11
+ Array.isArray(v.accounts) &&
12
+ v.accounts.every((a) => isRecord(a) &&
13
+ typeof a.id === "string" &&
14
+ isRecord(a.sync) &&
15
+ typeof a.sync.phase === "string" &&
16
+ typeof a.whole === "boolean") &&
17
+ typeof v.complete === "boolean" &&
18
+ (v.next === undefined || typeof v.next === "string");
19
+ /** A problem as the person reads it: what happened, and what to do. */
20
+ function refusalOf(problem, retryAfter) {
21
+ switch (problem.code) {
22
+ case "credential_revoked":
23
+ return new Refusal("brood was revoked on your account page, or went unused too long. Allow it again there to carry on.");
24
+ case "insufficient_scope":
25
+ return new Refusal("This session may only read. Run brood logout, then brood login without --read-only.");
26
+ case "rate_limited":
27
+ // The day's rule changes have a reason the server gives; the minute's
28
+ // limit has only its wait.
29
+ return new Refusal(problem.detail
30
+ ? `${PROBLEM_TITLES.rate_limited.title}. ${problem.detail}`
31
+ : retryAfter
32
+ ? `${PROBLEM_TITLES.rate_limited.title}. Try again in ${clean(retryAfter)} seconds.`
33
+ : `${PROBLEM_TITLES.rate_limited.title}. Try again in a minute.`);
34
+ case "invalid_argument":
35
+ return new Refusal(`${PROBLEM_TITLES.invalid_argument.title}: ${problem.detail ?? "the request"}.`);
36
+ default:
37
+ return new Refusal(problem.detail
38
+ ? `${PROBLEM_TITLES[problem.code].title}. ${problem.detail}`
39
+ : `${PROBLEM_TITLES[problem.code].title}.`);
40
+ }
41
+ }
42
+ async function send(io, operation, args, credentials) {
43
+ let response;
44
+ try {
45
+ response = await io.fetch(`${API_BASE}/${operation}`, {
46
+ method: "POST",
47
+ headers: {
48
+ authorization: `Bearer ${credentials.access_token}`,
49
+ "content-type": "application/json",
50
+ // DD21 §11: so the gate can refuse a version known to be broken.
51
+ "user-agent": `brood-cli/${VERSION}`,
52
+ },
53
+ body: JSON.stringify(args),
54
+ });
55
+ }
56
+ catch {
57
+ throw new Refusal("Could not reach Brood. Check the connection and try again.");
58
+ }
59
+ let body;
60
+ try {
61
+ // Cleaned as it arrives: a sender writes its own address, name and
62
+ // domain, so no printer can be the one that forgot (DD21 §8).
63
+ body = cleaned(await response.json());
64
+ }
65
+ catch {
66
+ body = null;
67
+ }
68
+ return {
69
+ status: response.status,
70
+ body,
71
+ retryAfter: response.headers.get("retry-after"),
72
+ };
73
+ }
74
+ /**
75
+ * Calls one operation as the signed-in person. A token Brood refuses as
76
+ * unauthenticated is refreshed once and the call made again, since an
77
+ * access token can lapse between the check and the call.
78
+ */
79
+ export async function call(io, operation, args) {
80
+ // Arguments may be read from the session, as logging out's refresh token
81
+ // is: after a refresh, it must be the new one that is ended.
82
+ const of = (c) => (typeof args === "function" ? args(c) : args);
83
+ let held = await freshCredentials(io);
84
+ let answer = await send(io, operation, of(held), held);
85
+ if (answer.status === 401 &&
86
+ isProblem(answer.body) &&
87
+ answer.body.code === "unauthenticated") {
88
+ held = await refresh(io, held);
89
+ answer = await send(io, operation, of(held), held);
90
+ }
91
+ if (isProblem(answer.body))
92
+ throw new Refused(refusalOf(answer.body, answer.retryAfter).message, answer.body.code);
93
+ if (answer.status !== 200 || !isEnvelope(answer.body))
94
+ throw new Refusal("Brood's answer could not be read. Try again shortly.");
95
+ // The envelope's shape is checked above, and its data taken as the
96
+ // operation's answer as packages/api types it: the app is built against the
97
+ // same types, and v1 grows only by addition (DD21 §11), so a field this
98
+ // client reads is one the API still sends.
99
+ return answer.body;
100
+ }