@kelviq/cli 0.4.1 → 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/README.md +147 -5
- package/dist/cli-ui/secret-prompt.d.ts +53 -0
- package/dist/cli-ui/secret-prompt.js +119 -0
- package/dist/cli-ui/secret-prompt.js.map +1 -0
- package/dist/cli.js +6 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/env.js +2 -2
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/import/index.d.ts +15 -0
- package/dist/commands/import/index.js +120 -0
- package/dist/commands/import/index.js.map +1 -0
- package/dist/commands/import/lemon-squeezy.d.ts +2 -0
- package/dist/commands/import/lemon-squeezy.js +90 -0
- package/dist/commands/import/lemon-squeezy.js.map +1 -0
- package/dist/commands/import/redact.d.ts +10 -0
- package/dist/commands/import/redact.js +73 -0
- package/dist/commands/import/redact.js.map +1 -0
- package/dist/commands/import/runner.d.ts +40 -0
- package/dist/commands/import/runner.js +510 -0
- package/dist/commands/import/runner.js.map +1 -0
- package/dist/commands/import/source.d.ts +122 -0
- package/dist/commands/import/source.js +29 -0
- package/dist/commands/import/source.js.map +1 -0
- package/dist/commands/login.js +6 -104
- package/dist/commands/login.js.map +1 -1
- package/dist/core/config.d.ts +2 -0
- package/dist/core/config.js +4 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/env-file.d.ts +7 -2
- package/dist/core/env-file.js +22 -7
- package/dist/core/env-file.js.map +1 -1
- package/dist/core/errors.d.ts +23 -1
- package/dist/core/errors.js +83 -31
- package/dist/core/errors.js.map +1 -1
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.js +6 -3
- package/dist/core/http.js.map +1 -1
- package/dist/core/import-env.d.ts +8 -0
- package/dist/core/import-env.js +18 -0
- package/dist/core/import-env.js.map +1 -0
- package/dist/generated/openapi.json +1359 -109
- package/dist/sync/to-config.js +21 -1
- package/dist/sync/to-config.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** The source platform's API key: read from an environment variable or a masked prompt, never from a flag. */
|
|
2
|
+
export interface ImportCredentials {
|
|
3
|
+
/** Variable holding the key. Must be listed in core/import-env.ts so env files may set it. */
|
|
4
|
+
envVar: string;
|
|
5
|
+
/** What the key is called in the prompt and in messages, e.g. `Lemon Squeezy API key`. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Request body field the key is sent in. */
|
|
8
|
+
bodyField: string;
|
|
9
|
+
/** The key's name without the platform, lower case, e.g. `api key`: its row in the summary, and how an API message about it is recognised. */
|
|
10
|
+
shortLabel: string;
|
|
11
|
+
/** One line printed before the masked prompt saying where to create a key. */
|
|
12
|
+
createHint: string;
|
|
13
|
+
}
|
|
14
|
+
/** Which account, store or workspace on the source platform to import, when one key can reach several. */
|
|
15
|
+
export interface ImportLocator {
|
|
16
|
+
/** Commander flag with its value placeholder, e.g. `--store <id>`. */
|
|
17
|
+
flag: string;
|
|
18
|
+
/** Help text for the flag. */
|
|
19
|
+
description: string;
|
|
20
|
+
/** Variable used when the flag is absent. Must be listed in core/import-env.ts. */
|
|
21
|
+
envVar: string;
|
|
22
|
+
/** Request body field the value is sent in. */
|
|
23
|
+
bodyField: string;
|
|
24
|
+
/** Name of the thing in the summary and in messages, e.g. `store`. */
|
|
25
|
+
noun: string;
|
|
26
|
+
/** The question asked in an interactive session when neither the flag nor the variable is set, ending in `: `. */
|
|
27
|
+
prompt: string;
|
|
28
|
+
/** Field of the `202` response carrying its display name, when the API returns one. */
|
|
29
|
+
nameField?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Returns what is wrong with the value, or `undefined` when it is
|
|
32
|
+
* acceptable. The text follows the flag or variable name (`--store must
|
|
33
|
+
* be ...`) and must not quote the value: a variable set to the wrong thing
|
|
34
|
+
* can hold a key.
|
|
35
|
+
*/
|
|
36
|
+
validate(value: string): string | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** A flag only this source has. */
|
|
39
|
+
export interface ImportExtraFlag {
|
|
40
|
+
/** Commander flag, with a value placeholder when it takes one, e.g. `--orders <all|one-time|subscription>`. */
|
|
41
|
+
flag: string;
|
|
42
|
+
/** Help text for the flag. */
|
|
43
|
+
description: string;
|
|
44
|
+
/** Request body field the parsed value is sent in. */
|
|
45
|
+
bodyField: string;
|
|
46
|
+
/** Turns the flag's value (`true` for a flag without a placeholder) into the body value, or names what is wrong with it (quote the value only through `describeValue`). Called only when the flag was passed. */
|
|
47
|
+
parse(raw: string | boolean): {
|
|
48
|
+
value: unknown;
|
|
49
|
+
} | {
|
|
50
|
+
error: string;
|
|
51
|
+
};
|
|
52
|
+
/** Line in the pre-run summary. `text` receives the body value, or `undefined` when the flag was not passed; returning `undefined` prints nothing. */
|
|
53
|
+
summary?: {
|
|
54
|
+
label: string;
|
|
55
|
+
text(value: unknown): string | undefined;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface ImportSource {
|
|
59
|
+
/** Subcommand name, and `source` in the `--json` document, e.g. `lemon-squeezy`. */
|
|
60
|
+
id: string;
|
|
61
|
+
/** Display name, e.g. `Lemon Squeezy`. */
|
|
62
|
+
label: string;
|
|
63
|
+
/** Endpoint path beneath the API host that queues the import. */
|
|
64
|
+
path: string;
|
|
65
|
+
credentials: ImportCredentials;
|
|
66
|
+
locator?: ImportLocator;
|
|
67
|
+
/** Step names accepted by `--only` and `--skip`, in the order the import runs them. */
|
|
68
|
+
steps: readonly string[];
|
|
69
|
+
/** A comma-separated step list shown as the example of how to write one, e.g. `orders,renewals`. */
|
|
70
|
+
stepListExample: string;
|
|
71
|
+
/** Shown on stderr while the request is in flight: what the API is doing before it answers. */
|
|
72
|
+
progress: string;
|
|
73
|
+
/** What the user should know before starting, as extra rows of the pre-run summary. */
|
|
74
|
+
notes: readonly {
|
|
75
|
+
label: string;
|
|
76
|
+
text: string;
|
|
77
|
+
}[];
|
|
78
|
+
extraFlags: readonly ImportExtraFlag[];
|
|
79
|
+
/** How the API's field names read to the user in an error: a flag or a variable. Covers this source's own fields; the common ones are known to the runner. */
|
|
80
|
+
fieldLabels: Readonly<Record<string, string>>;
|
|
81
|
+
}
|
|
82
|
+
/** Flags every source accepts, plus whatever the source declares (keyed by commander's camelCased option name). */
|
|
83
|
+
export interface ImportOptions {
|
|
84
|
+
dryRun?: boolean;
|
|
85
|
+
only?: string;
|
|
86
|
+
skip?: string;
|
|
87
|
+
/** `false` (`--no-publish-plans`) imports plans as drafts. Left out or `true`, each imported plan is published. */
|
|
88
|
+
publishPlans?: boolean;
|
|
89
|
+
/** `false` (`--no-publish-discounts`) leaves imported discount codes switched off. Left out or `true`, they work at checkout. */
|
|
90
|
+
publishDiscounts?: boolean;
|
|
91
|
+
reportEmail?: string;
|
|
92
|
+
prod?: boolean;
|
|
93
|
+
yes?: boolean;
|
|
94
|
+
json?: boolean;
|
|
95
|
+
[sourceOption: string]: string | boolean | undefined;
|
|
96
|
+
}
|
|
97
|
+
export interface ImportIO {
|
|
98
|
+
stdin: NodeJS.ReadableStream;
|
|
99
|
+
/** The result: the closing report, or the one `--json` document. */
|
|
100
|
+
stdout: NodeJS.WritableStream;
|
|
101
|
+
/** Everything else: prompts, the pre-run summary, progress, errors. */
|
|
102
|
+
stderr: NodeJS.WritableStream;
|
|
103
|
+
isTTY: boolean;
|
|
104
|
+
env?: NodeJS.ProcessEnv;
|
|
105
|
+
configDir?: string;
|
|
106
|
+
/** Variables that were taken from an env file, with the file each came from; one that is absent came from the shell. */
|
|
107
|
+
envFileVars?: Readonly<Record<string, string>>;
|
|
108
|
+
/** Overrides how long the request may take; tests only. */
|
|
109
|
+
requestTimeoutMs?: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* How a rejected value is shown in a validation message: quoted when it is a
|
|
113
|
+
* short lower-case word (a mistyped step or choice), and as `an unrecognised
|
|
114
|
+
* value` otherwise. Anything longer or stranger could be a key that landed in
|
|
115
|
+
* the wrong flag or variable, and must not be printed.
|
|
116
|
+
*/
|
|
117
|
+
export declare function describeValue(value: string): string;
|
|
118
|
+
export declare function isEchoable(value: string): boolean;
|
|
119
|
+
/** `--dry-run` → `dryRun`, `--store <id>` → `store`: the key commander stores a flag's value under. */
|
|
120
|
+
export declare function optionKey(flag: string): string;
|
|
121
|
+
/** The flag without its value placeholder: `--store <id>` → `--store`. */
|
|
122
|
+
export declare function flagName(flag: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// What one import source declares. Everything common to every import (the
|
|
2
|
+
// flags `--dry-run`, `--only`, `--skip`, `--no-publish-plans`,
|
|
3
|
+
// `--no-publish-discounts`, `--report-email`, `--prod`, `--yes`, `--json`, the
|
|
4
|
+
// confirmation gate, the request, the output) lives in runner.ts; a source is
|
|
5
|
+
// only the data below, including every sentence that names the platform or
|
|
6
|
+
// one of its screens. Adding a source is one file of this shape, an entry in
|
|
7
|
+
// index.ts's list, and its variables in core/import-env.ts.
|
|
8
|
+
/**
|
|
9
|
+
* How a rejected value is shown in a validation message: quoted when it is a
|
|
10
|
+
* short lower-case word (a mistyped step or choice), and as `an unrecognised
|
|
11
|
+
* value` otherwise. Anything longer or stranger could be a key that landed in
|
|
12
|
+
* the wrong flag or variable, and must not be printed.
|
|
13
|
+
*/
|
|
14
|
+
export function describeValue(value) {
|
|
15
|
+
return isEchoable(value) ? `"${value}"` : 'an unrecognised value';
|
|
16
|
+
}
|
|
17
|
+
export function isEchoable(value) {
|
|
18
|
+
return /^[a-z_-]{1,20}$/.test(value);
|
|
19
|
+
}
|
|
20
|
+
/** `--dry-run` → `dryRun`, `--store <id>` → `store`: the key commander stores a flag's value under. */
|
|
21
|
+
export function optionKey(flag) {
|
|
22
|
+
const name = flag.trim().split(/[\s,]+/)[0]?.replace(/^--/, '') ?? '';
|
|
23
|
+
return name.replace(/-([a-z0-9])/g, (_match, char) => char.toUpperCase());
|
|
24
|
+
}
|
|
25
|
+
/** The flag without its value placeholder: `--store <id>` → `--store`. */
|
|
26
|
+
export function flagName(flag) {
|
|
27
|
+
return flag.trim().split(/\s+/)[0] ?? flag;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/commands/import/source.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+DAA+D;AAC/D,+EAA+E;AAC/E,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,4DAA4D;AA+G5D;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,uBAAuB,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IACtE,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AACpF,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC7C,CAAC"}
|
package/dist/commands/login.js
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
import { spawn } from 'node:child_process';
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
|
-
import { createInterface } from 'node:readline';
|
|
13
|
-
import { Writable } from 'node:stream';
|
|
14
12
|
import { LOGIN_HINT, printHint } from '../cli-ui/hints.js';
|
|
13
|
+
import { promptForKey } from '../cli-ui/secret-prompt.js';
|
|
15
14
|
import { writeUserConfig } from '../core/config.js';
|
|
16
15
|
/**
|
|
17
16
|
* Dashboard API-keys URL, deep-linked to the environment mode matching the
|
|
@@ -37,7 +36,11 @@ export async function runLogin(prod, io) {
|
|
|
37
36
|
write(`Opening the dashboard so you can copy a key. If your browser doesn't open, visit:\n ${url}\n`);
|
|
38
37
|
(io.openUrl ?? openBrowserBestEffort)(url);
|
|
39
38
|
const pasted = await promptForKey(`Paste your ${envName} Server API key: `, io);
|
|
40
|
-
|
|
39
|
+
if (pasted.cancelled) {
|
|
40
|
+
write('Cancelled; no key was stored.\n');
|
|
41
|
+
return { exitCode: 130 };
|
|
42
|
+
}
|
|
43
|
+
const key = pasted.value.trim();
|
|
41
44
|
if (!key) {
|
|
42
45
|
write('No key entered; nothing was saved.\n');
|
|
43
46
|
return { exitCode: 1 };
|
|
@@ -64,107 +67,6 @@ export function registerLoginCommand(program) {
|
|
|
64
67
|
process.exitCode = result.exitCode;
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
|
-
async function promptForKey(promptText, io) {
|
|
68
|
-
return io.isTTY ? readLineMasked(promptText, io) : readLinePlain(promptText, io);
|
|
69
|
-
}
|
|
70
|
-
/** Non-TTY (piped) path: read one line as-is. This is the path exercised by tests. */
|
|
71
|
-
function readLinePlain(promptText, io) {
|
|
72
|
-
return new Promise((resolve) => {
|
|
73
|
-
io.stdout.write(promptText);
|
|
74
|
-
const rl = createInterface({ input: io.stdin, terminal: false });
|
|
75
|
-
let resolved = false;
|
|
76
|
-
const finish = (line) => {
|
|
77
|
-
if (resolved)
|
|
78
|
-
return;
|
|
79
|
-
resolved = true;
|
|
80
|
-
rl.close();
|
|
81
|
-
resolve(line);
|
|
82
|
-
};
|
|
83
|
-
rl.once('line', finish);
|
|
84
|
-
rl.once('close', () => finish(''));
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* TTY path: reads a line while masking echo. `readline`'s own rendering
|
|
89
|
-
* (which would include the real characters, e.g. on a backspace-triggered
|
|
90
|
-
* line refresh) is fully suppressed via a muted output stream, exactly as
|
|
91
|
-
* before. In its place, one `*` is written per accepted character, driven
|
|
92
|
-
* by `readline`'s public `keypress` event — not a hand-rolled raw-mode
|
|
93
|
-
* reader; `readline` still owns all line editing and remains the sole
|
|
94
|
-
* source of truth for the captured value, this only decides what gets
|
|
95
|
-
* echoed. A pasted chunk arrives as one keypress per character (no
|
|
96
|
-
* raw-mode/TTY needed for that — `keypress` decoding runs on any input
|
|
97
|
-
* stream once `terminal: true` is set), so an 80-character paste renders as
|
|
98
|
-
* 80 separate `*` writes. Backspace erases one `*` in place (`\b \b`); it
|
|
99
|
-
* never reveals a character even if the visual count and the true
|
|
100
|
-
* in-progress line briefly disagree (e.g. a backspace at the very start,
|
|
101
|
-
* before any character has been echoed, is simply a no-op here — the
|
|
102
|
-
* underlying readline state is unaffected either way). Best-effort — if a
|
|
103
|
-
* given terminal doesn't cooperate, the user still gets a working (visible)
|
|
104
|
-
* prompt via the underlying readline behavior, never a crash.
|
|
105
|
-
*/
|
|
106
|
-
function readLineMasked(promptText, io) {
|
|
107
|
-
return new Promise((resolve) => {
|
|
108
|
-
const muted = new MutedWritable(io.stdout);
|
|
109
|
-
const rl = createInterface({ input: io.stdin, output: muted, terminal: true });
|
|
110
|
-
io.stdout.write(promptText);
|
|
111
|
-
muted.muted = true;
|
|
112
|
-
let echoed = 0;
|
|
113
|
-
// `done` guards against a real EventEmitter quirk: the Enter keystroke's
|
|
114
|
-
// own `keypress` event (str: '\n'/'\r', key.name: 'enter'/'return') is
|
|
115
|
-
// delivered to listeners in registration order, and `readline`'s own
|
|
116
|
-
// internal listener (registered first, inside createInterface above)
|
|
117
|
-
// synchronously finishes the line and invokes the `question` callback
|
|
118
|
-
// below — including our `removeListener` call — *before* this listener
|
|
119
|
-
// (registered second) gets its turn for that same emit() cycle. Node
|
|
120
|
-
// still calls already-snapshotted listeners for an in-flight emit even
|
|
121
|
-
// if one of them removed a later listener mid-cycle, so without this
|
|
122
|
-
// flag the Enter keystroke would slip through as one extra echoed
|
|
123
|
-
// character. The explicit name check below is a second, independent
|
|
124
|
-
// layer: Enter must never be treated as a typed character regardless of
|
|
125
|
-
// this timing detail.
|
|
126
|
-
let done = false;
|
|
127
|
-
const onKeypress = (str, key) => {
|
|
128
|
-
if (done)
|
|
129
|
-
return;
|
|
130
|
-
if (key?.name === 'return' || key?.name === 'enter')
|
|
131
|
-
return;
|
|
132
|
-
if (key?.name === 'backspace') {
|
|
133
|
-
if (echoed > 0) {
|
|
134
|
-
io.stdout.write('\b \b');
|
|
135
|
-
echoed -= 1;
|
|
136
|
-
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (str && str.length > 0) {
|
|
140
|
-
io.stdout.write('*'.repeat(str.length));
|
|
141
|
-
echoed += str.length;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
io.stdin.on('keypress', onKeypress);
|
|
145
|
-
rl.question('', (answer) => {
|
|
146
|
-
done = true;
|
|
147
|
-
io.stdin.removeListener('keypress', onKeypress);
|
|
148
|
-
muted.muted = false;
|
|
149
|
-
io.stdout.write('\n');
|
|
150
|
-
rl.close();
|
|
151
|
-
resolve(answer);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
class MutedWritable extends Writable {
|
|
156
|
-
target;
|
|
157
|
-
muted = false;
|
|
158
|
-
constructor(target) {
|
|
159
|
-
super();
|
|
160
|
-
this.target = target;
|
|
161
|
-
}
|
|
162
|
-
_write(chunk, _encoding, callback) {
|
|
163
|
-
if (!this.muted)
|
|
164
|
-
this.target.write(chunk);
|
|
165
|
-
callback();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
70
|
/**
|
|
169
71
|
* Best-effort browser open: spawn the platform opener, detached, with
|
|
170
72
|
* stdio ignored, and swallow every failure (missing binary, headless box,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,mEAAmE;AACnE,2EAA2E;AAC3E,6BAA6B;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,mEAAmE;AACnE,2EAA2E;AAC3E,6BAA6B;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,SAAS,UAAU,CAAC,IAAa;IAC/B,OAAO,iDAAiD,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACtF,CAAC;AAiBD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAa,EAAE,EAAW;IACvD,MAAM,OAAO,GAA6B,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS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,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,4BAA4B;IAC9B,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,SAAkB;IAC3C,IAAI,SAAS;QAAE,OAAO,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IAChD,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface UserConfigFile {
|
|
|
23
23
|
prodServerApiKey?: string;
|
|
24
24
|
sandboxServerApiKey?: string;
|
|
25
25
|
}
|
|
26
|
+
/** The API host an environment uses when no `KELVIQ_*_BASE_URL` variable points it elsewhere. */
|
|
27
|
+
export declare function defaultBaseUrl(envName: EnvName): string;
|
|
26
28
|
/**
|
|
27
29
|
* Loads the layered CLI config: env vars win over the user config file.
|
|
28
30
|
* Command-line flag overrides are applied by callers on top of this result
|
package/dist/core/config.js
CHANGED
|
@@ -54,6 +54,10 @@ function parseKelviqEnv(raw) {
|
|
|
54
54
|
return 'sandbox';
|
|
55
55
|
return raw === 'sandbox' || raw === 'production' ? raw : undefined;
|
|
56
56
|
}
|
|
57
|
+
/** The API host an environment uses when no `KELVIQ_*_BASE_URL` variable points it elsewhere. */
|
|
58
|
+
export function defaultBaseUrl(envName) {
|
|
59
|
+
return envName === 'production' ? DEFAULT_BASE_URL : DEFAULT_SANDBOX_BASE_URL;
|
|
60
|
+
}
|
|
57
61
|
/**
|
|
58
62
|
* Loads the layered CLI config: env vars win over the user config file.
|
|
59
63
|
* Command-line flag overrides are applied by callers on top of this result
|
package/dist/core/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,kEAAkE;AAClE,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AACxE,sEAAsE;AACtE,sBAAsB;AACtB,EAAE;AACF,+DAA+D;AAC/D,+DAA+D;AAC/D,mEAAmE;AACnE,uEAAuE;AACvE,0EAA0E;AAC1E,uDAAuD;AACvD,yEAAyE;AACzE,4EAA4E;AAC5E,kBAAkB;AAClB,6EAA6E;AAC7E,6EAA6E;AAC7E,yDAAyD;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AA8BjD,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AACzD,MAAM,wBAAwB,GAAG,sCAAsC,CAAC;AACxE,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAC9D,MAAM,wBAAwB,GAAG,2CAA2C,CAAC;AAC7E,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC,SAAS,gBAAgB,CAAC,GAAsB;IAC9C,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,OAAO,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;AAC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c,aAAa,CAAC,GAAG,EAAE;gBACnC,CAAC,CAAC,oCAAoC,aAAa,CAAC,GAAG,EAAE,CAAC;YAC5D,iEAAiE;YACjE,MAAM,GAAG,GACP,aAAa,CAAC,GAAG,KAAK,YAAY;gBAChC,CAAC,CAAC,qFAAqF;gBACvF,CAAC,CAAC,uDAAuD,CAAC;YAC9D,QAAQ,GAAG,oDAAoD,aAAa,CAAC,GAAG,KAAK,GAAG,KAAK,GAAG,EAAE,CAAC;QACrG,CAAC;QACD,KAAK,CACH,WAAW,OAAO,mBAAmB,KAAK,cAAc,QAAQ,GAAG;YACjE,6CAA6C,OAAO,KAAK,QAAQ,GAAG;YACpE,6DAA6D,IAAI,GAAG,CACvE,CAAC;QA1Bc,YAAO,GAAP,OAAO,CAAS;QAEhB,kBAAa,GAAb,aAAa,CAAoB;QAyBjD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACZ;IAA5B,YAA4B,KAAa;QACvC,KAAK,CAAC,uBAAuB,KAAK,mCAAmC,CAAC,CAAC;QAD7C,UAAK,GAAL,KAAK,CAAQ;QAEvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
package/dist/core/env-file.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const DEFAULT_ENV_FILES: readonly string[];
|
|
2
|
+
/** Whether an env file may set `key`: the CLI's own `KELVIQ_*` names, plus the variables the import sources declare. */
|
|
3
|
+
export declare function isEnvFileVariable(key: string): boolean;
|
|
2
4
|
/** Parses dotenv text: `KEY=value`, optional `export ` prefix, `#` comments, single/double quotes, `\n` escapes inside double quotes. */
|
|
3
5
|
export declare function parseEnvFile(text: string): Record<string, string>;
|
|
4
6
|
export interface EnvFileLoadResult {
|
|
@@ -16,9 +18,12 @@ export interface ApplyEnvFilesOptions {
|
|
|
16
18
|
}
|
|
17
19
|
/** What the most recent `applyEnvFiles` call did — `kelviq env` reports it. */
|
|
18
20
|
export declare function lastEnvFileLoad(): EnvFileLoadResult;
|
|
21
|
+
/** Which env file each variable of the most recent `applyEnvFiles` call was taken from, as the file was named (`.env.local`, or the `--env-file` path as given). A variable that came from the shell is absent. */
|
|
22
|
+
export declare function lastEnvFileOrigins(): Readonly<Record<string, string>>;
|
|
19
23
|
/**
|
|
20
|
-
* Applies
|
|
21
|
-
* variable that is already set. Throws when an
|
|
24
|
+
* Applies the pairs `isEnvFileVariable` accepts from the env files into
|
|
25
|
+
* `env`, never overriding a variable that is already set. Throws when an
|
|
26
|
+
* explicit file is missing.
|
|
22
27
|
*/
|
|
23
28
|
export declare function applyEnvFiles(env: NodeJS.ProcessEnv, options: ApplyEnvFilesOptions): EnvFileLoadResult;
|
|
24
29
|
/**
|
package/dist/core/env-file.js
CHANGED
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
// `.env.local` / `.env` works without `set -a; . ./.env.local; set +a`.
|
|
3
3
|
//
|
|
4
4
|
// Rules: variables already present in the environment always win (a file
|
|
5
|
-
// never overrides the shell); only `KELVIQ_*` keys
|
|
6
|
-
//
|
|
5
|
+
// never overrides the shell); only `KELVIQ_*` keys and the variables the
|
|
6
|
+
// import sources declare (core/import-env.ts) are applied, since those are
|
|
7
|
+
// the only ones the CLI reads; `.env.local` is read before `.env` so the
|
|
7
8
|
// local override file wins, matching the convention of the frameworks that
|
|
8
9
|
// use that pair. Explicit `--env-file` paths must exist; the default pair is
|
|
9
10
|
// skipped silently when absent. Nothing is ever printed from a file.
|
|
10
11
|
import { existsSync, readFileSync } from 'node:fs';
|
|
11
12
|
import { resolve } from 'node:path';
|
|
13
|
+
import { IMPORT_ENV_ALLOW_LIST } from './import-env.js';
|
|
12
14
|
export const DEFAULT_ENV_FILES = ['.env.local', '.env'];
|
|
13
15
|
const KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16
|
+
/** Whether an env file may set `key`: the CLI's own `KELVIQ_*` names, plus the variables the import sources declare. */
|
|
17
|
+
export function isEnvFileVariable(key) {
|
|
18
|
+
return key.startsWith('KELVIQ_') || IMPORT_ENV_ALLOW_LIST.includes(key);
|
|
19
|
+
}
|
|
14
20
|
/** Parses dotenv text: `KEY=value`, optional `export ` prefix, `#` comments, single/double quotes, `\n` escapes inside double quotes. */
|
|
15
21
|
export function parseEnvFile(text) {
|
|
16
22
|
const out = {};
|
|
@@ -43,20 +49,27 @@ export function parseEnvFile(text) {
|
|
|
43
49
|
return out;
|
|
44
50
|
}
|
|
45
51
|
let lastLoad = { loaded: [], applied: [] };
|
|
52
|
+
let lastOrigins = {};
|
|
46
53
|
/** What the most recent `applyEnvFiles` call did — `kelviq env` reports it. */
|
|
47
54
|
export function lastEnvFileLoad() {
|
|
48
55
|
return lastLoad;
|
|
49
56
|
}
|
|
57
|
+
/** Which env file each variable of the most recent `applyEnvFiles` call was taken from, as the file was named (`.env.local`, or the `--env-file` path as given). A variable that came from the shell is absent. */
|
|
58
|
+
export function lastEnvFileOrigins() {
|
|
59
|
+
return lastOrigins;
|
|
60
|
+
}
|
|
50
61
|
/**
|
|
51
|
-
* Applies
|
|
52
|
-
* variable that is already set. Throws when an
|
|
62
|
+
* Applies the pairs `isEnvFileVariable` accepts from the env files into
|
|
63
|
+
* `env`, never overriding a variable that is already set. Throws when an
|
|
64
|
+
* explicit file is missing.
|
|
53
65
|
*/
|
|
54
66
|
export function applyEnvFiles(env, options) {
|
|
55
67
|
const explicit = options.explicit ?? [];
|
|
56
68
|
const candidates = explicit.length > 0
|
|
57
|
-
? explicit.map((p) => ({ path: resolve(options.cwd, p), required: true }))
|
|
58
|
-
: (options.defaults ?? DEFAULT_ENV_FILES).map((p) => ({ path: resolve(options.cwd, p), required: false }));
|
|
69
|
+
? explicit.map((p) => ({ name: p, path: resolve(options.cwd, p), required: true }))
|
|
70
|
+
: (options.defaults ?? DEFAULT_ENV_FILES).map((p) => ({ name: p, path: resolve(options.cwd, p), required: false }));
|
|
59
71
|
const result = { loaded: [], applied: [] };
|
|
72
|
+
const origins = {};
|
|
60
73
|
for (const candidate of candidates) {
|
|
61
74
|
if (!existsSync(candidate.path)) {
|
|
62
75
|
if (candidate.required)
|
|
@@ -66,16 +79,18 @@ export function applyEnvFiles(env, options) {
|
|
|
66
79
|
const parsed = parseEnvFile(readFileSync(candidate.path, 'utf8'));
|
|
67
80
|
result.loaded.push(candidate.path);
|
|
68
81
|
for (const [key, value] of Object.entries(parsed)) {
|
|
69
|
-
if (!key
|
|
82
|
+
if (!isEnvFileVariable(key))
|
|
70
83
|
continue;
|
|
71
84
|
const existing = env[key];
|
|
72
85
|
if (existing !== undefined && existing.trim() !== '')
|
|
73
86
|
continue;
|
|
74
87
|
env[key] = value;
|
|
75
88
|
result.applied.push(key);
|
|
89
|
+
origins[key] = candidate.name;
|
|
76
90
|
}
|
|
77
91
|
}
|
|
78
92
|
lastLoad = result;
|
|
93
|
+
lastOrigins = origins;
|
|
79
94
|
return result;
|
|
80
95
|
}
|
|
81
96
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../src/core/env-file.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,yEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../src/core/env-file.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,qEAAqE;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,Y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E,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,SAAS,mBAAmB,CAAC,IAAY,EAAE,OAAe;IACxD,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Normalized error shape returned to CLI callers.
|
|
3
3
|
*
|
|
4
|
-
* Kelviq returns
|
|
4
|
+
* Kelviq returns these error shapes in the wild:
|
|
5
5
|
* - { status, message } (ErrorResponse)
|
|
6
6
|
* - { detail } (DetailErrorResponse)
|
|
7
|
+
* - { error } (a single message string)
|
|
8
|
+
* - { nonFieldErrors: [...] } (validation, not tied to a field)
|
|
9
|
+
* - { field: [...], list: { "0": [...] } } (validation, keyed by field;
|
|
10
|
+
* list items keyed by position)
|
|
11
|
+
* - { list: [{}, { field: [...] }] } (validation of a list of objects)
|
|
12
|
+
* - [ "...", "..." ] (validation, a bare list of messages)
|
|
13
|
+
* - an HTML page or plain text (a proxy or an unhandled failure)
|
|
7
14
|
* Plus the usual network / serialization failures. We collapse all of these
|
|
8
15
|
* into KelviqAPIError so command implementations don't have to branch.
|
|
9
16
|
*/
|
|
@@ -16,5 +23,20 @@ export interface KelviqAPIError {
|
|
|
16
23
|
};
|
|
17
24
|
}
|
|
18
25
|
export declare function isKelviqAPIError(value: unknown): value is KelviqAPIError;
|
|
26
|
+
/** One validation failure: `path` is the field name followed by any nested keys or list positions (`['only', '0']`, `['prices', '0', 'amount']`). A `nonFieldErrors` list takes its parent's path, so it is empty at the top level. */
|
|
27
|
+
export interface FieldError {
|
|
28
|
+
path: string[];
|
|
29
|
+
messages: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads a validation error body into a flat list, in the order the server
|
|
33
|
+
* sent it. Only strings inside arrays count as messages. Plain objects are
|
|
34
|
+
* descended into by key, and objects inside an array by their position
|
|
35
|
+
* (`prices[0].amount`), so a body that is not a validation error yields `[]`.
|
|
36
|
+
* A top-level array of strings is a list of messages with no field.
|
|
37
|
+
*/
|
|
38
|
+
export declare function collectFieldErrors(body: unknown, path?: string[]): FieldError[];
|
|
39
|
+
/** `only[0]` for `['only', '0']`, `address.city` for `['address', 'city']`, `prices[0].amount` for `['prices', '0', 'amount']`. */
|
|
40
|
+
export declare function fieldErrorPath(path: string[]): string;
|
|
19
41
|
export declare function fromHttpResponse(httpStatus: number, body: unknown): KelviqAPIError;
|
|
20
42
|
export declare function fromException(err: unknown): KelviqAPIError;
|