@williamthorsen/toolbelt.secrets 0.4.3 โ†’ 0.6.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.
@@ -0,0 +1,259 @@
1
+ [
2
+ {
3
+ "version": "0.6.0",
4
+ "date": "2026-10-25",
5
+ "sections": [
6
+ {
7
+ "title": "๐ŸŽ‰ Features",
8
+ "audience": "all",
9
+ "items": [
10
+ {
11
+ "description": "Adds the structured changelog `.meta/changelog.json` to each package's npm tarball, beside `CHANGELOG.md`. (#398)",
12
+ "hash": "2ce82cd51b7b78270274ae9318c2bc726eb09cf0",
13
+ "entry": 1
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "title": "โ™ป๏ธ Refactoring",
19
+ "audience": "dev",
20
+ "items": [
21
+ {
22
+ "description": "Replaces hand-rolled error descriptions, `instanceof Error` checks on caught values, record guards, directory ascents, and first-letter capitalization in package source with `describeError`, `isError`, `isRecord`, `isRecordOrArray`, `listDirectoryChain`, and `capitalize`, and declares each helper's package from another workspace as a `workspace:*` runtime dependency of the package that adopts it. (#400)",
23
+ "hash": "dc681ce947df9aebf203f9457b10bc8afd2adec1",
24
+ "entry": 1
25
+ }
26
+ ]
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ "version": "0.5.0",
32
+ "date": "2026-10-11",
33
+ "sections": [
34
+ {
35
+ "title": "๐Ÿชฆ Removed",
36
+ "audience": "all",
37
+ "items": [
38
+ {
39
+ "description": "Removes the `tb-secret` executable from `@williamthorsen/toolbelt.secrets`, along with its `bin` declaration and its README section, and links the README to `thor-secret` in `@williamthorsen/secret-tools`. (#384)",
40
+ "breaking": true,
41
+ "migration": "Install `@williamthorsen/secret-tools` and replace each `tb-secret` invocation with `thor-secret`, because the new package installs the command under that name and not as `tb-secret`.",
42
+ "hash": "2fff83f8875b13aa4aa1f69a6a30a10dc472044c",
43
+ "entry": 1
44
+ }
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "version": "0.4.3",
51
+ "date": "2026-10-11",
52
+ "sections": [
53
+ {
54
+ "title": "โ™ป๏ธ Refactoring",
55
+ "audience": "dev",
56
+ "items": [
57
+ {
58
+ "description": "Replaces the private `readStreamText` copies in the `tb-jira` and `tb-secret` bins with imports from `@williamthorsen/toolbelt.cli/candidate`. (#381)",
59
+ "hash": "e9511be999d62720e414b2405287d7fd47300c0b",
60
+ "entry": 2
61
+ }
62
+ ]
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "version": "0.4.2",
68
+ "date": "2026-10-09",
69
+ "sections": [
70
+ {
71
+ "title": "๐Ÿ“ฆ Dependencies",
72
+ "audience": "dev",
73
+ "items": [{ "description": "Bumped `@williamthorsen/toolbelt.cli` to 0.4.0" }]
74
+ }
75
+ ]
76
+ },
77
+ {
78
+ "version": "0.4.1",
79
+ "date": "2026-10-07",
80
+ "sections": [
81
+ {
82
+ "title": "๐Ÿ“ฆ Dependencies",
83
+ "audience": "dev",
84
+ "items": [{ "description": "Bumped `@williamthorsen/toolbelt.cli` to 0.3.0" }]
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ "version": "0.4.0",
90
+ "date": "2026-10-06",
91
+ "sections": [
92
+ {
93
+ "title": "๐ŸŽ‰ Features",
94
+ "audience": "all",
95
+ "items": [
96
+ {
97
+ "description": "Moves the argument parsing, dispatch, and help of `tb-git`, `tb-jira`, `tb-node`, and `tb-secret` to `@williamthorsen/toolbelt.cli`, which generates each command's help from its schema and reports a usage error as `Error: <message>`, followed by a `Did you mean` line for a mistyped command and a pointer to that command's `--help`. (#365)",
98
+ "hash": "d9924a0c93f279691b21b98f2567ce157a2cfff4",
99
+ "entry": 1
100
+ },
101
+ {
102
+ "description": "Adds `-V` to `tb-git`, `tb-jira`, `tb-node`, and `tb-secret` as a short form of `--version`. (#365)",
103
+ "hash": "d9924a0c93f279691b21b98f2567ce157a2cfff4",
104
+ "entry": 2
105
+ }
106
+ ]
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ "version": "0.3.1",
112
+ "date": "2026-10-02",
113
+ "sections": [
114
+ {
115
+ "title": "๐Ÿงช Tests",
116
+ "audience": "dev",
117
+ "items": [
118
+ {
119
+ "description": "Corrects test titles and one test input that misstated what their tests check, among them an `asNonEmptyArray` title that called a mutable array immutable and a `setDifference` test named for arrays that passed `Set` instances. (#353)",
120
+ "hash": "a63031711563d43c6909609fad4feccfe497e5d1",
121
+ "entry": 4
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ "title": "๐Ÿ“š Documentation",
127
+ "audience": "dev",
128
+ "items": [
129
+ {
130
+ "description": "Audits the comments in every authored TypeScript, JavaScript, shell, and YAML source and every `tsconfig*.json` against the comment discipline, cutting comments that paraphrase the code or narrate history, rewriting doc descriptions in the third-person indicative, and adding descriptions to the functions, methods, and classes that had none. (#353)",
131
+ "hash": "a63031711563d43c6909609fad4feccfe497e5d1",
132
+ "entry": 1
133
+ },
134
+ {
135
+ "description": "Revises READMEs, doc comments, and test names across the repository to follow the current `plain-speech` and writing-preference rules. (#354)",
136
+ "hash": "b4e08eede95e052f4c27db2640ed6515df14baf4",
137
+ "entry": 1
138
+ },
139
+ {
140
+ "description": "Rewords the help text and messages printed by `tb-jira`, `tb-node`, and `tb-secret`, and the advice and skip reasons reported by the adoption kits, to follow the same writing conventions. (#354)",
141
+ "hash": "b4e08eede95e052f4c27db2640ed6515df14baf4",
142
+ "entry": 2
143
+ }
144
+ ]
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "version": "0.3.0",
150
+ "date": "2026-09-15",
151
+ "sections": [
152
+ {
153
+ "title": "๐ŸŽ‰ Features",
154
+ "audience": "all",
155
+ "items": [
156
+ {
157
+ "description": "Move createTempTree from toolbelt.filesystem to toolbelt.testing (#313)",
158
+ "body": "- Moves `CreateTempTreeOptions` and the `TempTree` handle to `@williamthorsen/toolbelt.testing/candidate` along with `createTempTree`.\n\nMigration: Import `createTempTree`, `CreateTempTreeOptions`, and `TempTree` from `@williamthorsen/toolbelt.testing/candidate`, and declare `@williamthorsen/toolbelt.testing` in the manifest that declared `@williamthorsen/toolbelt.filesystem` for them.",
159
+ "breaking": true,
160
+ "migration": "Import `createTempTree`, `CreateTempTreeOptions`, and `TempTree` from `@williamthorsen/toolbelt.testing/candidate`, and declare `@williamthorsen/toolbelt.testing` in the manifest that declared `@williamthorsen/toolbelt.filesystem` for them.",
161
+ "hash": "857dc50b69084af6de51cb557c0e54e0083e375d"
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "title": "โš™๏ธ Tooling",
167
+ "audience": "dev",
168
+ "items": [
169
+ {
170
+ "description": "Remove the stale repo-local cliff.toml and normalize changelog titles (#327)",
171
+ "body": "- Stops `release-kit prepare` from printing a \"skipped due to grouping error(s)\" warning for each releasable workspace by letting it resolve the git-cliff template bundled with release-kit, previously overridden by the root `cliff.toml`.\n- Excludes commits without a ticket prefix from future changelog entries.\n- Renames the section titles in every `packages/*/.meta/changelog.json`, except `Dependency updates`, to the headings of release-kit's work-type taxonomy, such as \"๐ŸŽ‰ Features\" and \"๐Ÿ—๏ธ Internal features\", and regenerates each `CHANGELOG.md` so that release-kit orders existing and new sections by the same rule.\n- Causes the next `release-kit prepare` to plan patch releases of `dstructs`, `hof`, and `sets`, which had no other commits since their last release, because the changelog commit touches every workspace.",
172
+ "hash": "2b3c4fe7a08f210adb66f4a4f5bfedc011908d36"
173
+ }
174
+ ]
175
+ },
176
+ {
177
+ "title": "๐Ÿ“š Documentation",
178
+ "audience": "dev",
179
+ "items": [
180
+ {
181
+ "description": "Align prose with plain-speech doctrine and writing conventions (#306)",
182
+ "body": "- Copy-edits prose across the repo: comments, test names, package READMEs, and `AGENTS.md`.\n- Rewrites a few user-facing strings as well, among them `configure-project`'s help text and the errors from `parseProjectSpec`, `securityCommands`, and `hashString`.",
183
+ "hash": "ab9c5a84a25e5084986733ecc79b88be9b9c7ef1"
184
+ }
185
+ ]
186
+ }
187
+ ]
188
+ },
189
+ {
190
+ "version": "0.2.0",
191
+ "date": "2026-09-06",
192
+ "sections": [
193
+ {
194
+ "title": "๐ŸŽ‰ Features",
195
+ "audience": "all",
196
+ "items": [
197
+ {
198
+ "description": "Add createKeychainStore and tb-secret to toolbelt.secrets (#276)",
199
+ "body": "Adds the first exports to `@williamthorsen/toolbelt.secrets`: `createKeychainStore`, which stores and reads secrets in the macOS keychain with no external dependency. Also adds `tb-secret`, a command that exposes the same store to a shell caller.\n\nSupports macOS only.",
200
+ "hash": "2e8d6aaecfcad938b39774f78c822b22f764572d"
201
+ },
202
+ {
203
+ "description": "Ship the tb-jira CLI and document toolbelt.atlassian (#295)",
204
+ "body": "- Adds the `tb-jira` binary to `@williamthorsen/toolbelt.atlassian`: Its `configure-project` subcommand reconciles a Jira project's statuses, workflow transitions, and board features against a spec file owned by the consuming repo, and `--dry-run` prints the plan and writes nothing.\n- Adds a `tb-jira auth` subcommand, which stores, replaces, and removes the Jira API token in the keychain and reports which source would supply it without printing the token.\n- Adds `resolveJiraSite`, `findJiraTokenSource`, and `JiraTransportError` to `@williamthorsen/toolbelt.atlassian/candidate`, so library code can resolve the site, name which link of the token chain would answer without reading the token, and tell a request that Jira rejected from one that never reached Jira.\n- Adds `promptSecret` and `UnstorableSecretError` to `@williamthorsen/toolbelt.secrets/candidate`, so a caller outside that package can prompt for a secret without echoing it and can tell a token refused by the keychain from a keychain that could not be reached.",
205
+ "hash": "b1f8c42d2b0d9ae3b691beb7141c301dbe363ba6"
206
+ }
207
+ ]
208
+ },
209
+ {
210
+ "title": "๐Ÿ› Bug fixes",
211
+ "audience": "all",
212
+ "items": [
213
+ {
214
+ "description": "Stop truncating a secret longer than 128 characters (#278)",
215
+ "body": "Fixes an issue where `tb-secret set` and `setSecret` stored the first 128 bytes of a longer secret and reported success, so an API token of ordinary length was silently corrupted. Secrets of up to ~2,000 bytes can now be stored; an empty secret or a secret that exceeds the limit is refused.\n\nAt a terminal, `tb-secret set` now prompts for the secret twice. An abandoned prompt reports that nothing was stored.\n\nSeparately, a write can now target a named keychain: `createKeychainStore` returns a writable store for any keychain, and `tb-secret set` now has a `--keychain` option.",
216
+ "hash": "05f80928ad6aea69844bfcfa539a1cd22a004420"
217
+ },
218
+ {
219
+ "description": "Point every package bin at a committed wrapper (#296)",
220
+ "body": "- Points the `tb-git`, `tb-jira`, and `tb-secret` commands at committed wrappers under each package's `bin/`, so the target exists when the package manager links the command rather than only after a build.",
221
+ "hash": "920491782b81e31b9e3e626bf9a26d37dd99ea82"
222
+ },
223
+ {
224
+ "description": "Fix piped-stdin reads and unhandled EPIPE in the CLIs (#301)",
225
+ "body": "- Fixes an issue where `tb-secret set` and `tb-jira auth set` failed with `EAGAIN: resource temporarily unavailable` when the producer of a piped credential delayed its first byte, as `tb-secret get`, `op read`, and `gh auth token` all do.\n- Stops `tb-secret`, `tb-jira`, and `tb-git` from crashing with an unhandled `EPIPE` when the reader on their stdout or stderr exits first, so that `tb-secret get | head -1` ends quietly, as a program that ignores `SIGPIPE` does.",
226
+ "hash": "76bb91faf6da82e1d41f27e67b5055693f4c9168"
227
+ }
228
+ ]
229
+ },
230
+ {
231
+ "title": "๐Ÿ—๏ธ Internal features",
232
+ "audience": "dev",
233
+ "items": [
234
+ {
235
+ "description": "Scaffold toolbelt.secrets for credential storage (#275)",
236
+ "body": "Scaffolds `packages/secrets`, an empty workspace for storing and retrieving secrets in the OS credential store, publishing to npm as `@williamthorsen/toolbelt.secrets`.",
237
+ "hash": "d625019170c68217cdd55b8092f0dd88da8df73f"
238
+ }
239
+ ]
240
+ },
241
+ {
242
+ "title": "๐Ÿ“š Documentation",
243
+ "audience": "dev",
244
+ "items": [
245
+ {
246
+ "description": "Repair the repository's prose and record every rejection's ground (#290)",
247
+ "body": "Applies one repo-wide `revise-prose` sweep across the repository's READMEs, `AGENTS.md`, source comments, doc descriptions, and test names.",
248
+ "hash": "e04e58fb6172a585a9207d363f96c9e481031baf"
249
+ },
250
+ {
251
+ "description": "Restore relativizers across atlassian, secrets, and the workflows (#304)",
252
+ "body": "- Revises documentation and comments to align with plain-speech doctrine and writing conventions.",
253
+ "hash": "78a36fb425be681c8f373fba87a687114b3f3943"
254
+ }
255
+ ]
256
+ }
257
+ ]
258
+ }
259
+ ]
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.6.0 โ€” 2026-10-25
6
+
7
+ ### ๐ŸŽ‰ Features
8
+
9
+ - Adds the structured changelog `.meta/changelog.json` to each package's npm tarball, beside `CHANGELOG.md`. (#398)
10
+
11
+ ### โ™ป๏ธ Refactoring
12
+
13
+ - Replaces hand-rolled error descriptions, `instanceof Error` checks on caught values, record guards, directory ascents, and first-letter capitalization in package source with `describeError`, `isError`, `isRecord`, `isRecordOrArray`, `listDirectoryChain`, and `capitalize`, and declares each helper's package from another workspace as a `workspace:*` runtime dependency of the package that adopts it. (#400)
14
+
15
+ ## 0.5.0 โ€” 2026-10-11
16
+
17
+ ### ๐Ÿชฆ Removed
18
+
19
+ - ๐Ÿšจ **Breaking:** Removes the `tb-secret` executable from `@williamthorsen/toolbelt.secrets`, along with its `bin` declaration and its README section, and links the README to `thor-secret` in `@williamthorsen/secret-tools`. (#384)
20
+
5
21
  ## 0.4.3 โ€” 2026-10-11
6
22
 
7
23
  ### โ™ป๏ธ Refactoring
package/README.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  Utilities for storing and retrieving secrets in the OS credential store.
4
4
 
5
- <!-- section:release-notes --><!-- /section:release-notes -->
5
+ <!-- section:release-notes -->
6
+ ## Release notes โ€” v0.6.0 (2026-10-25)
7
+
8
+ ### ๐ŸŽ‰ Features
9
+
10
+ - Adds the structured changelog `.meta/changelog.json` to each package's npm tarball, beside `CHANGELOG.md`. (#398)
11
+ <!-- /section:release-notes -->
6
12
 
7
13
  ## Installation
8
14
 
@@ -24,55 +30,7 @@ An item created here is local to the Mac that created it. `security` offers no i
24
30
 
25
31
  ## CLI
26
32
 
27
- The package includes a `tb-secret` command exposing the store to a shell caller.
28
-
29
- ```sh
30
- pnpm add --global @williamthorsen/toolbelt.secrets # puts tb-secret on PATH
31
- npx @williamthorsen/toolbelt.secrets get my-token # or run it without installing
32
- ```
33
-
34
- `tb-secret --help`, each subcommand's `--help`, and `tb-secret --version` (or `-V`) report the surface and the installed version.
35
-
36
- | Subcommand | Effect |
37
- | ---------------------------- | ---------------------------------------------------- |
38
- | `tb-secret delete <service>` | Removes a secret |
39
- | `tb-secret get <service>` | Prints a secret |
40
- | `tb-secret has <service>` | Reports whether a secret is stored, printing nothing |
41
- | `tb-secret set <service>` | Stores a secret |
42
-
43
- | Option | Effect |
44
- | ----------------------- | ------------------------------------------------------- |
45
- | `-a, --account <name>` | Account of the secret (default: the empty account) |
46
- | `-k, --keychain <path>` | Keychain to act on, rather than the default search list |
47
-
48
- At a terminal, `set` prompts for the secret twice and echoes nothing; piped, it reads stdin and drops one trailing newline, since `echo` adds one. The secret passes through this process either way.
49
-
50
- ```sh
51
- tb-secret set atlassian-api-token --account me@example.com # prompts, echoing nothing
52
-
53
- pbpaste | tb-secret set atlassian-api-token # or pipe it
54
-
55
- export ATLASSIAN_API_TOKEN=$(tb-secret get atlassian-api-token --account me@example.com)
56
- ```
57
-
58
- ### Exit codes
59
-
60
- | Code | Meaning |
61
- | ---- | ------------------------------------------------------------- |
62
- | `0` | The command succeeded |
63
- | `1` | No secret is stored under that service and account |
64
- | `2` | Usage or validation error, with the message on stderr |
65
- | `3` | The keychain could not be reached, with the message on stderr |
66
-
67
- An absent secret is `1` and a keychain that could not be reached is `3`, so a script can tell one from the other.
68
-
69
- ```sh
70
- if token=$(tb-secret get atlassian-api-token); then
71
- curl --user "me@example.com:$token" https://example.atlassian.net/rest/api/3/myself
72
- elif [ $? -eq 1 ]; then
73
- echo 'No token stored. Run `tb-secret set atlassian-api-token`.' >&2
74
- fi
75
- ```
33
+ For these functions on the command line, use `thor-secret` from [`@williamthorsen/secret-tools`](https://www.npmjs.com/package/@williamthorsen/secret-tools).
76
34
 
77
35
  ## `createKeychainStore`
78
36
 
@@ -1,3 +1,4 @@
1
+ import { describeError } from '@williamthorsen/toolbelt.errors';
1
2
  import { assertStorableSecret } from "./assertStorableSecret.js";
2
3
  import { parseSecurityPassword } from "./parseSecurityPassword.js";
3
4
  import { buildDeleteArgs, buildFindArgs, buildHasArgs, composeSetLine } from "./securityCommands.js";
@@ -16,7 +17,7 @@ export function buildKeychainStore(run, keychain) {
16
17
  return findSecret(query);
17
18
  }
18
19
  catch (error) {
19
- const detail = error instanceof Error ? error.message : String(error);
20
+ const detail = describeError(error);
20
21
  throw new Error(`The secret was written but could not be read back to verify it. ${detail}`, { cause: error });
21
22
  }
22
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.secrets",
3
- "version": "0.4.3",
3
+ "version": "0.6.0",
4
4
  "description": "Utilities for storing and retrieving secrets in the OS credential store",
5
5
  "keywords": [
6
6
  "credentials",
@@ -39,19 +39,16 @@
39
39
  "import": "./dist/esm/1-proposed/index.js"
40
40
  }
41
41
  },
42
- "bin": {
43
- "tb-secret": "./bin/tb-secret.js"
44
- },
45
42
  "files": [
46
- "bin/*",
47
43
  "CHANGELOG.md",
44
+ ".meta/changelog.json",
48
45
  "dist/*"
49
46
  ],
50
47
  "dependencies": {
51
- "@williamthorsen/toolbelt.cli": "0.5.0"
48
+ "@williamthorsen/toolbelt.errors": "0.9.0"
52
49
  },
53
50
  "devDependencies": {
54
- "@williamthorsen/toolbelt.testing": "0.6.3"
51
+ "@williamthorsen/toolbelt.testing": "0.8.0"
55
52
  },
56
53
  "engines": {
57
54
  "node": ">=24.0.0"
package/bin/tb-secret.js DELETED
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Imports only node builtins: A top-level import resolves before the gate below runs, so an unresolvable
4
- // dependency would replace this file's build-first message with ERR_MODULE_NOT_FOUND.
5
- import { existsSync } from 'node:fs';
6
-
7
- // Thin wrapper so that pnpm can link the bin at install time, before `dist/` exists. The real entry point loads
8
- // at runtime from the build output.
9
- const entryPoint = new URL('../dist/esm/bin/tb-secret.js', import.meta.url);
10
-
11
- // Gate on the entry file itself: Because Node raises ERR_MODULE_NOT_FOUND for any unresolved module in the
12
- // graph, keying the build-first message off the error code would also fire when the build is present and one
13
- // of its imports is missing.
14
- if (!existsSync(entryPoint)) {
15
- process.stderr.write(
16
- 'tb-secret: build output not found. In a source checkout, run `nmr build`; otherwise reinstall the package.\n',
17
- );
18
- process.exit(1);
19
- }
20
-
21
- try {
22
- await import(entryPoint.href);
23
- } catch (error) {
24
- const message = error instanceof Error ? error.message : String(error);
25
- process.stderr.write(`tb-secret: failed to load: ${message}\n`);
26
- process.exit(1);
27
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Finds the manifest of the package owning a directory, ascending to the first `package.json` declaring a
3
- * `name`. One declaring none is a marker manifest, such as the `{"type": "commonjs"}` file left in `dist/`
4
- * by a dual-format build, and the ascent passes over it, so the function returns the owning package's
5
- * manifest rather than the nearest one. Throws when no ancestor declares a name.
6
- *
7
- * @internal
8
- */
9
- export declare function findOwningManifest(startDir: string): OwningManifest;
10
- export interface OwningManifest {
11
- readonly manifest: {
12
- readonly version?: unknown;
13
- };
14
- readonly manifestPath: string;
15
- }
@@ -1,24 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- export function findOwningManifest(startDir) {
4
- let dir = startDir;
5
- for (;;) {
6
- const manifestPath = path.join(dir, 'package.json');
7
- if (fs.existsSync(manifestPath)) {
8
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
9
- if (isNamedManifest(manifest))
10
- return { manifest, manifestPath };
11
- }
12
- const parent = path.dirname(dir);
13
- if (parent === dir)
14
- throw new Error(`No package manifest declaring a name at or above ${startDir}.`);
15
- dir = parent;
16
- }
17
- }
18
- function isNamedManifest(value) {
19
- return (typeof value === 'object' &&
20
- value !== null &&
21
- !Array.isArray(value) &&
22
- 'name' in value &&
23
- typeof value.name === 'string');
24
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Reads the version declared by the package owning a directory, defaulting to this module's own, which is
3
- * this package whether it runs from source under the test runner or from the build output once installed.
4
- * Throws when the owning manifest declares no string version.
5
- *
6
- * @internal
7
- */
8
- export declare function resolveSelfVersion(fromDir?: string): string;
@@ -1,8 +0,0 @@
1
- import { findOwningManifest } from "./findOwningManifest.js";
2
- export function resolveSelfVersion(fromDir = import.meta.dirname) {
3
- const { manifest, manifestPath } = findOwningManifest(fromDir);
4
- if (typeof manifest.version !== 'string') {
5
- throw new TypeError(`No version declared in the package manifest at ${manifestPath}.`);
6
- }
7
- return manifest.version;
8
- }
@@ -1,23 +0,0 @@
1
- import type { WritableSecretStore } from '../3-candidate/SecretStore.js';
2
- /**
3
- * Runs the `tb-secret` command line, returning what to write and exit with rather than doing either, so that
4
- * the whole surface is exercisable without a process. Every failure is reported through the result: Nothing throws.
5
- *
6
- * @internal
7
- */
8
- export declare function runTbSecret(args: string[], effects: TbSecretEffects): Promise<TbSecretResult>;
9
- /** The effects deferred to the entry point, which keeps the runner free of I/O. */
10
- export interface TbSecretEffects {
11
- readonly createStore: (keychain: string | undefined) => WritableSecretStore;
12
- readonly isStdinTty: () => boolean;
13
- /** Reads a secret from the terminal, echoing nothing and asking twice. */
14
- readonly promptSecret: () => Promise<string>;
15
- readonly readStdin: () => Promise<string>;
16
- readonly resolveVersion: () => string;
17
- }
18
- /** What the caller should write to each stream and exit with. */
19
- export interface TbSecretResult {
20
- readonly exitCode: number;
21
- readonly stderr: string;
22
- readonly stdout: string;
23
- }
@@ -1,165 +0,0 @@
1
- import { createCli, runCli, UsageError } from '@williamthorsen/toolbelt.cli/candidate';
2
- import { UnstorableSecretError } from "../3-candidate/UnstorableSecretError.js";
3
- const EXIT_OK = 0;
4
- const EXIT_NO_RESULT = 1;
5
- const EXIT_KEYSTORE = 3;
6
- const { defineCommand, defineGroup } = createCli();
7
- const SERVICE_OPERAND = { name: 'service', description: 'The service that names the secret' };
8
- const SECRET_FLAGS = {
9
- account: {
10
- type: 'string',
11
- description: 'Account holding the secret (default: the empty account)',
12
- short: 'a',
13
- valueHint: 'name',
14
- },
15
- keychain: {
16
- type: 'string',
17
- description: 'Keychain to act on, rather than the default search list',
18
- short: 'k',
19
- valueHint: 'path',
20
- },
21
- };
22
- const ROOT = defineGroup({
23
- summary: 'Store and read secrets in the macOS keychain. Requires macOS.',
24
- epilog: `A secret is named by a service and an optional account, so one service can hold a secret per account. An item
25
- is local to this Mac: \`security\` offers no iCloud Keychain synchronization.
26
-
27
- Exit codes:
28
- 0 The command succeeded
29
- 1 No secret is stored under that service and account
30
- 2 Usage or validation error
31
- 3 The keychain could not be reached`,
32
- commands: {
33
- delete: defineCommand({
34
- summary: 'Remove a secret',
35
- description: 'Remove a secret, exiting 1 when none is stored.',
36
- flags: SECRET_FLAGS,
37
- operands: [SERVICE_OPERAND],
38
- run: ({ context, flags, operands, stderr }) => reportFailures(stderr, () => {
39
- const query = buildQuery(operands.service, flags.account);
40
- const removed = callKeystore(() => context.createStore(flags.keychain).deleteSecret(query));
41
- return removed ? EXIT_OK : EXIT_NO_RESULT;
42
- }),
43
- }),
44
- get: defineCommand({
45
- summary: 'Print a secret',
46
- description: 'Print a secret, exiting 1 when none is stored.',
47
- flags: SECRET_FLAGS,
48
- operands: [SERVICE_OPERAND],
49
- run: ({ context, flags, operands, stderr, stdout }) => reportFailures(stderr, () => {
50
- const query = buildQuery(operands.service, flags.account);
51
- const secret = callKeystore(() => context.createStore(flags.keychain).findSecret(query));
52
- if (secret === undefined)
53
- return EXIT_NO_RESULT;
54
- stdout.write(`${secret}\n`);
55
- return EXIT_OK;
56
- }),
57
- }),
58
- has: defineCommand({
59
- summary: 'Report whether a secret is stored, printing nothing',
60
- description: `Exit 0 when a secret is stored and 1 when none is, printing nothing either way. The secret itself is never
61
- read, so this raises no keychain access prompt.`,
62
- flags: SECRET_FLAGS,
63
- operands: [SERVICE_OPERAND],
64
- run: ({ context, flags, operands, stderr }) => reportFailures(stderr, () => {
65
- const query = buildQuery(operands.service, flags.account);
66
- const stored = callKeystore(() => context.createStore(flags.keychain).hasSecret(query));
67
- return stored ? EXIT_OK : EXIT_NO_RESULT;
68
- }),
69
- }),
70
- set: defineCommand({
71
- summary: 'Store a secret',
72
- description: 'Store a secret, replacing one already stored under the same service and account.',
73
- epilog: `At a terminal the secret is prompted for twice and echoed nowhere; piped, it is read from stdin and one
74
- trailing newline is dropped, since \`echo\` adds one. Either way it is passed to \`security\` inside a command
75
- sent on stdin, so it never enters an argument vector that any local process could read.
76
-
77
- The stored secret is read back and compared before this command reports success. Replacing an item that
78
- another program created can therefore raise a keychain access prompt, since verifying the write reads the
79
- secret.
80
-
81
- A secret can be about 2,000 bytes long. The exact ceiling depends on the service, account, and keychain, which
82
- share one 4,095-byte command line with it; a secret that would not fit is refused rather than stored in part.`,
83
- flags: SECRET_FLAGS,
84
- operands: [SERVICE_OPERAND],
85
- run: ({ context, flags, operands, stderr }) => reportFailures(stderr, () => runSet(operands.service, flags, context)),
86
- }),
87
- },
88
- });
89
- export async function runTbSecret(args, effects) {
90
- const stdout = createTextBuffer();
91
- const stderr = createTextBuffer();
92
- const exitCode = await runCli(args, ROOT, {
93
- name: 'tb-secret',
94
- context: effects,
95
- version: () => resolveVersion(effects),
96
- stdout,
97
- stderr,
98
- });
99
- return { exitCode, stderr: stderr.text, stdout: stdout.text };
100
- }
101
- class KeystoreError extends Error {
102
- }
103
- function buildQuery(service, account) {
104
- if (service === '')
105
- throw new Error('The service name is empty.');
106
- return { account, service };
107
- }
108
- function callKeystore(operation) {
109
- try {
110
- return operation();
111
- }
112
- catch (error) {
113
- if (error instanceof UnstorableSecretError)
114
- throw error;
115
- throw new KeystoreError(describeError(error));
116
- }
117
- }
118
- function createTextBuffer() {
119
- let text = '';
120
- return {
121
- get text() {
122
- return text;
123
- },
124
- write(chunk) {
125
- text += chunk;
126
- },
127
- };
128
- }
129
- function describeError(error) {
130
- return error instanceof Error ? error.message : String(error);
131
- }
132
- async function reportFailures(stderr, body) {
133
- try {
134
- return await body();
135
- }
136
- catch (error) {
137
- if (error instanceof UsageError)
138
- throw error;
139
- if (error instanceof KeystoreError) {
140
- stderr.write(`${error.message}\n`);
141
- return EXIT_KEYSTORE;
142
- }
143
- throw new UsageError(describeError(error), { cause: error });
144
- }
145
- }
146
- function resolveVersion(effects) {
147
- try {
148
- return effects.resolveVersion();
149
- }
150
- catch (error) {
151
- throw new UsageError(describeError(error), { cause: error });
152
- }
153
- }
154
- async function runSet(service, flags, effects) {
155
- const query = buildQuery(service, flags.account);
156
- const store = callKeystore(() => effects.createStore(flags.keychain));
157
- const secret = effects.isStdinTty()
158
- ? await effects.promptSecret()
159
- : stripOneTrailingNewline(await effects.readStdin());
160
- callKeystore(() => store.setSecret(query, secret));
161
- return EXIT_OK;
162
- }
163
- function stripOneTrailingNewline(input) {
164
- return input.replace(/\r?\n$/, '');
165
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,23 +0,0 @@
1
- import { readStreamText } from '@williamthorsen/toolbelt.cli/candidate';
2
- import { createKeychainStore } from "../3-candidate/createKeychainStore.js";
3
- import { promptSecret } from "../3-candidate/promptSecret.js";
4
- import { resolveSelfVersion } from "./resolveSelfVersion.js";
5
- import { runTbSecret } from "./runTbSecret.js";
6
- for (const stream of [process.stdout, process.stderr]) {
7
- stream.on('error', (error) => {
8
- if (error.code !== 'EPIPE')
9
- throw error;
10
- });
11
- }
12
- const { exitCode, stderr, stdout } = await runTbSecret(process.argv.slice(2), {
13
- createStore: (keychain) => (keychain === undefined ? createKeychainStore() : createKeychainStore({ keychain })),
14
- isStdinTty: () => process.stdin.isTTY,
15
- promptSecret: () => promptSecret(process.stdin, process.stderr),
16
- readStdin: () => readStreamText(process.stdin),
17
- resolveVersion: () => resolveSelfVersion(),
18
- });
19
- if (stdout !== '')
20
- process.stdout.write(stdout);
21
- if (stderr !== '')
22
- process.stderr.write(stderr);
23
- process.exitCode = exitCode;