@williamthorsen/toolbelt.secrets 0.4.2 â 0.5.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/CHANGELOG.md +12 -0
- package/README.md +8 -50
- package/package.json +1 -8
- package/bin/tb-secret.js +0 -27
- package/dist/esm/bin/findOwningManifest.d.ts +0 -15
- package/dist/esm/bin/findOwningManifest.js +0 -24
- package/dist/esm/bin/readStreamText.d.ts +0 -7
- package/dist/esm/bin/readStreamText.js +0 -7
- package/dist/esm/bin/resolveSelfVersion.d.ts +0 -8
- package/dist/esm/bin/resolveSelfVersion.js +0 -8
- package/dist/esm/bin/runTbSecret.d.ts +0 -23
- package/dist/esm/bin/runTbSecret.js +0 -165
- package/dist/esm/bin/tb-secret.d.ts +0 -1
- package/dist/esm/bin/tb-secret.js +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.5.0 â 2026-10-11
|
|
6
|
+
|
|
7
|
+
### đĒĻ Removed
|
|
8
|
+
|
|
9
|
+
- đ¨ **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)
|
|
10
|
+
|
|
11
|
+
## 0.4.3 â 2026-10-11
|
|
12
|
+
|
|
13
|
+
### âģī¸ Refactoring
|
|
14
|
+
|
|
15
|
+
- Replaces the private `readStreamText` copies in the `tb-jira` and `tb-secret` bins with imports from `@williamthorsen/toolbelt.cli/candidate`. (#381)
|
|
16
|
+
|
|
5
17
|
## 0.4.2 â 2026-10-09
|
|
6
18
|
|
|
7
19
|
### đĻ Dependencies
|
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
|
|
5
|
+
<!-- section:release-notes -->
|
|
6
|
+
## Release notes â v0.5.0 (2026-10-11)
|
|
7
|
+
|
|
8
|
+
### đĒĻ Removed
|
|
9
|
+
|
|
10
|
+
- đ¨ **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)
|
|
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
|
-
|
|
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/toolbelt.secrets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Utilities for storing and retrieving secrets in the OS credential store",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"credentials",
|
|
@@ -39,17 +39,10 @@
|
|
|
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",
|
|
48
44
|
"dist/*"
|
|
49
45
|
],
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@williamthorsen/toolbelt.cli": "0.4.0"
|
|
52
|
-
},
|
|
53
46
|
"devDependencies": {
|
|
54
47
|
"@williamthorsen/toolbelt.testing": "0.6.3"
|
|
55
48
|
},
|
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,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads a stream to end as text, awaiting a producer that has not yet written. A synchronous read of a
|
|
3
|
-
* non-blocking pipe fails with `EAGAIN` rather than waiting, and a piped secret arrives on such a pipe.
|
|
4
|
-
*
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare function readStreamText(stream: NodeJS.ReadableStream): Promise<string>;
|
|
@@ -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 { createKeychainStore } from "../3-candidate/createKeychainStore.js";
|
|
2
|
-
import { promptSecret } from "../3-candidate/promptSecret.js";
|
|
3
|
-
import { readStreamText } from "./readStreamText.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;
|