@steve228uk/nhs-cli 0.0.1 → 0.1.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/AGENTS.md +26 -0
- package/CONTRIBUTING.md +11 -0
- package/INSTALL.md +88 -0
- package/README.md +140 -3
- package/SECURITY.md +9 -0
- package/bin/nhs-prescriptions.mjs +11 -0
- package/bin/nhs.mjs +3 -0
- package/docs/android-network-inspection.md +99 -0
- package/docs/api-observation-template.md +42 -0
- package/docs/api-research.md +128 -0
- package/docs/architecture.md +27 -0
- package/docs/authentication.md +45 -0
- package/docs/cli.md +35 -0
- package/docs/releasing.md +65 -0
- package/docs/validation.md +39 -0
- package/package.json +44 -7
- package/skills/nhs/SKILL.md +74 -0
- package/src/auth.mjs +282 -0
- package/src/cli.mjs +189 -0
- package/src/config.mjs +29 -0
- package/src/credentials.mjs +19 -0
- package/src/domains.mjs +184 -0
- package/src/errors.mjs +31 -0
- package/src/otp.mjs +46 -0
- package/src/output.mjs +32 -0
- package/src/storage.mjs +211 -0
- package/src/transport.mjs +116 -0
- package/src/types.mjs +13 -0
- package/src/ui.mjs +52 -0
package/src/ui.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { text, password, isCancel, intro, outro, cancel, log } from '@clack/prompts';
|
|
2
|
+
import { NhsError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prompts use the terminal on stderr; passwords alone are masked.
|
|
6
|
+
* @param {string} message
|
|
7
|
+
* @param {{secret?: boolean, validate?: (value: string | undefined) => string | undefined, input?: typeof process.stdin, output?: typeof process.stderr}} options
|
|
8
|
+
*/
|
|
9
|
+
export async function promptInput(message, { secret = false, validate = undefined, input = process.stdin, output = process.stderr } = {}) {
|
|
10
|
+
if (!input.isTTY || !output.isTTY) throw new NhsError('auth_required', 'Interactive authentication requires a terminal. Run nhs auth login in a terminal.');
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const closed = () => controller.abort();
|
|
13
|
+
input.once('end', closed);
|
|
14
|
+
input.once('close', closed);
|
|
15
|
+
try {
|
|
16
|
+
const value = await (secret ? password : text)({ message, input, output, validate, signal: controller.signal });
|
|
17
|
+
if (isCancel(value)) throw new NhsError('auth_cancelled', 'Authentication was cancelled.');
|
|
18
|
+
return /** @type {string} */ (value);
|
|
19
|
+
} finally {
|
|
20
|
+
input.off('end', closed);
|
|
21
|
+
input.off('close', closed);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const phases = {
|
|
26
|
+
session: 'Checking saved NHS session',
|
|
27
|
+
credentials: 'Signing in to NHS login',
|
|
28
|
+
authorization: 'Connecting securely to NHS login',
|
|
29
|
+
otp: 'NHS has sent a security code to your phone',
|
|
30
|
+
verify: 'Verifying your security code',
|
|
31
|
+
create: 'Creating and securely saving your NHS session',
|
|
32
|
+
gp: 'Connecting to your GP services',
|
|
33
|
+
};
|
|
34
|
+
/** Only fixed phase labels enter progress output, never authentication values. */
|
|
35
|
+
export function createUi({ enabled = false, output = process.stderr } = {}) {
|
|
36
|
+
let started = false;
|
|
37
|
+
return {
|
|
38
|
+
phase(phase) {
|
|
39
|
+
if (!enabled || !Object.hasOwn(phases, phase)) return;
|
|
40
|
+
if (!started) { intro('NHS CLI · unofficial NHS App client', { output }); started = true; }
|
|
41
|
+
log.step(phases[phase], { output });
|
|
42
|
+
},
|
|
43
|
+
finish(login = false) {
|
|
44
|
+
if (started) outro(login ? 'Signed in. Your login is securely saved.' : 'NHS session ready.', { output });
|
|
45
|
+
started = false;
|
|
46
|
+
},
|
|
47
|
+
fail() {
|
|
48
|
+
if (started) cancel('Could not complete this command.', { output });
|
|
49
|
+
started = false;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|