@kelviq/cli 0.1.1
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 +313 -0
- package/dist/cli-ui/auth-hint.d.ts +6 -0
- package/dist/cli-ui/auth-hint.js +34 -0
- package/dist/cli-ui/auth-hint.js.map +1 -0
- package/dist/cli-ui/hints.d.ts +5 -0
- package/dist/cli-ui/hints.js +19 -0
- package/dist/cli-ui/hints.js.map +1 -0
- package/dist/cli-ui/spinner.d.ts +7 -0
- package/dist/cli-ui/spinner.js +61 -0
- package/dist/cli-ui/spinner.js.map +1 -0
- package/dist/cli-ui/style.d.ts +47 -0
- package/dist/cli-ui/style.js +71 -0
- package/dist/cli-ui/style.js.map +1 -0
- package/dist/cli-ui/tty.d.ts +1 -0
- package/dist/cli-ui/tty.js +13 -0
- package/dist/cli-ui/tty.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/env.d.ts +34 -0
- package/dist/commands/env.js +52 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/init.d.ts +15 -0
- package/dist/commands/init.js +70 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/login.d.ts +22 -0
- package/dist/commands/login.js +205 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +13 -0
- package/dist/commands/logout.js +39 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/promote.d.ts +42 -0
- package/dist/commands/promote.js +243 -0
- package/dist/commands/promote.js.map +1 -0
- package/dist/commands/pull.d.ts +31 -0
- package/dist/commands/pull.js +108 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push-shared.d.ts +97 -0
- package/dist/commands/push-shared.js +283 -0
- package/dist/commands/push-shared.js.map +1 -0
- package/dist/commands/push.d.ts +42 -0
- package/dist/commands/push.js +268 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/config-format/builders.d.ts +10 -0
- package/dist/config-format/builders.js +46 -0
- package/dist/config-format/builders.js.map +1 -0
- package/dist/config-format/index.d.ts +4 -0
- package/dist/config-format/index.js +9 -0
- package/dist/config-format/index.js.map +1 -0
- package/dist/config-format/load.d.ts +23 -0
- package/dist/config-format/load.js +82 -0
- package/dist/config-format/load.js.map +1 -0
- package/dist/config-format/schema.d.ts +423 -0
- package/dist/config-format/schema.js +105 -0
- package/dist/config-format/schema.js.map +1 -0
- package/dist/core/config.d.ts +48 -0
- package/dist/core/config.js +128 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/http.d.ts +39 -0
- package/dist/core/http.js +104 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +14 -0
- package/dist/core/version.js.map +1 -0
- package/dist/generated/openapi.json +6635 -0
- package/dist/sync/apply.d.ts +38 -0
- package/dist/sync/apply.js +234 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/diff.d.ts +186 -0
- package/dist/sync/diff.js +402 -0
- package/dist/sync/diff.js.map +1 -0
- package/dist/sync/fetch-catalog.d.ts +105 -0
- package/dist/sync/fetch-catalog.js +100 -0
- package/dist/sync/fetch-catalog.js.map +1 -0
- package/dist/sync/price-filter.d.ts +37 -0
- package/dist/sync/price-filter.js +195 -0
- package/dist/sync/price-filter.js.map +1 -0
- package/dist/sync/prune.d.ts +77 -0
- package/dist/sync/prune.js +112 -0
- package/dist/sync/prune.js.map +1 -0
- package/dist/sync/publish.d.ts +75 -0
- package/dist/sync/publish.js +126 -0
- package/dist/sync/publish.js.map +1 -0
- package/dist/sync/push-plan-json.d.ts +79 -0
- package/dist/sync/push-plan-json.js +70 -0
- package/dist/sync/push-plan-json.js.map +1 -0
- package/dist/sync/render-plan.d.ts +83 -0
- package/dist/sync/render-plan.js +358 -0
- package/dist/sync/render-plan.js.map +1 -0
- package/dist/sync/serialize.d.ts +18 -0
- package/dist/sync/serialize.js +108 -0
- package/dist/sync/serialize.js.map +1 -0
- package/dist/sync/to-config.d.ts +9 -0
- package/dist/sync/to-config.js +191 -0
- package/dist/sync/to-config.js.map +1 -0
- package/package.json +68 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { initStyle } from './cli-ui/style.js';
|
|
4
|
+
import { registerEnvCommand } from './commands/env.js';
|
|
5
|
+
import { registerInitCommand } from './commands/init.js';
|
|
6
|
+
import { registerLoginCommand } from './commands/login.js';
|
|
7
|
+
import { registerLogoutCommand } from './commands/logout.js';
|
|
8
|
+
import { registerPromoteCommand } from './commands/promote.js';
|
|
9
|
+
import { registerPullCommand } from './commands/pull.js';
|
|
10
|
+
import { registerPushCommand } from './commands/push.js';
|
|
11
|
+
import { getPackageVersion } from './core/version.js';
|
|
12
|
+
const program = new Command();
|
|
13
|
+
program
|
|
14
|
+
.name('kelviq')
|
|
15
|
+
.description('Kelviq CLI — pricing-as-code and API tools for Kelviq.')
|
|
16
|
+
.version(getPackageVersion())
|
|
17
|
+
// CLI plan 014: must be typed before the subcommand name (e.g. `kelviq
|
|
18
|
+
// --no-color push`) — a root-level option, same as `--version`/`--help`.
|
|
19
|
+
.option('--no-color', 'Disable colored output');
|
|
20
|
+
// CLI plan 014: the ONE place style.ts's singleton is initialized — after
|
|
21
|
+
// commander has parsed `--no-color` but before any command's action runs.
|
|
22
|
+
// `optsWithGlobals()` reads the flag off the root program regardless of
|
|
23
|
+
// which command instance the hook fires for.
|
|
24
|
+
//
|
|
25
|
+
// CLI plan 015: `--json` (env/push/promote) forces styling off unconditionally
|
|
26
|
+
// — even under `FORCE_COLOR` — since an ANSI escape landing inside a JSON
|
|
27
|
+
// string value would violate the "one JSON document, nothing else" stdout
|
|
28
|
+
// contract. Passing an empty `env` bypasses FORCE_COLOR/NO_COLOR entirely;
|
|
29
|
+
// `stream: { isTTY: false }` bypasses the TTY branch too.
|
|
30
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
31
|
+
const opts = actionCommand.optsWithGlobals();
|
|
32
|
+
if (opts.json) {
|
|
33
|
+
initStyle({ noColorFlag: true, stream: { isTTY: false }, env: {} });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
initStyle({
|
|
37
|
+
noColorFlag: opts.color === false,
|
|
38
|
+
stream: process.stdout,
|
|
39
|
+
env: process.env,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
registerLoginCommand(program);
|
|
44
|
+
registerLogoutCommand(program);
|
|
45
|
+
registerEnvCommand(program);
|
|
46
|
+
registerInitCommand(program);
|
|
47
|
+
registerPullCommand(program);
|
|
48
|
+
registerPushCommand(program);
|
|
49
|
+
registerPromoteCommand(program);
|
|
50
|
+
program.parseAsync(process.argv);
|
|
51
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MA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,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface EnvIO {
|
|
3
|
+
stdout: NodeJS.WritableStream;
|
|
4
|
+
/** Injectable for tests; defaults to the real user config directory. */
|
|
5
|
+
configDir?: string;
|
|
6
|
+
/** Injectable for tests; defaults to process.env. */
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
}
|
|
9
|
+
export interface EnvOptions {
|
|
10
|
+
/** CLI plan 015: machine-readable output — `{ environment, sandboxUrl, prodUrl, sandboxKey, prodKey }`, `sandboxKey`/`prodKey` always `"set"`/`"missing"`, never a key value. */
|
|
11
|
+
json?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** CLI plan 015: the exact `kelviq env --json` document — field names verbatim (public, versioned contract; see README). `environment` is always the literal `"sandbox"`, matching the text report's own "sandbox (default...)" line — `env` has no `--prod` flag of its own, it always reports both keys' status together. */
|
|
14
|
+
export interface EnvJsonDocument {
|
|
15
|
+
environment: 'sandbox';
|
|
16
|
+
sandboxUrl: string;
|
|
17
|
+
prodUrl: string;
|
|
18
|
+
sandboxKey: 'set' | 'missing';
|
|
19
|
+
prodKey: 'set' | 'missing';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Builds and prints the environment report — plain text by default, or (CLI
|
|
23
|
+
* plan 015) the `EnvJsonDocument` above with `options.json`. Returns the
|
|
24
|
+
* exact text written so callers (and tests) can assert on it without
|
|
25
|
+
* re-parsing stdout.
|
|
26
|
+
*
|
|
27
|
+
* Key rows show only `set` / `missing` — loadCliConfig doesn't expose
|
|
28
|
+
* whether a value came from an env var or the config file, so this
|
|
29
|
+
* intentionally doesn't claim a source (see CLI plan 003 environment facts;
|
|
30
|
+
* a provenance-aware version would require widening core/config.ts). Never
|
|
31
|
+
* writes any part of a key's value, in either mode.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runEnvReport(io: EnvIO, options?: EnvOptions): string;
|
|
34
|
+
export declare function registerEnvCommand(program: Command): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { style } from '../cli-ui/style.js';
|
|
2
|
+
import { loadCliConfig } from '../core/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builds and prints the environment report — plain text by default, or (CLI
|
|
5
|
+
* plan 015) the `EnvJsonDocument` above with `options.json`. Returns the
|
|
6
|
+
* exact text written so callers (and tests) can assert on it without
|
|
7
|
+
* re-parsing stdout.
|
|
8
|
+
*
|
|
9
|
+
* Key rows show only `set` / `missing` — loadCliConfig doesn't expose
|
|
10
|
+
* whether a value came from an env var or the config file, so this
|
|
11
|
+
* intentionally doesn't claim a source (see CLI plan 003 environment facts;
|
|
12
|
+
* a provenance-aware version would require widening core/config.ts). Never
|
|
13
|
+
* writes any part of a key's value, in either mode.
|
|
14
|
+
*/
|
|
15
|
+
export function runEnvReport(io, options = {}) {
|
|
16
|
+
const config = loadCliConfig(io.env ?? process.env, io.configDir);
|
|
17
|
+
if (options.json) {
|
|
18
|
+
const doc = {
|
|
19
|
+
environment: 'sandbox',
|
|
20
|
+
sandboxUrl: config.sandboxBaseUrl,
|
|
21
|
+
prodUrl: config.baseUrl,
|
|
22
|
+
sandboxKey: config.sandboxServerApiKey ? 'set' : 'missing',
|
|
23
|
+
prodKey: config.prodServerApiKey ? 'set' : 'missing',
|
|
24
|
+
};
|
|
25
|
+
const report = `${JSON.stringify(doc)}\n`;
|
|
26
|
+
io.stdout.write(report);
|
|
27
|
+
return report;
|
|
28
|
+
}
|
|
29
|
+
const sandboxStatus = config.sandboxServerApiKey ? style.ok('set') : style.fail('missing');
|
|
30
|
+
const prodStatus = config.prodServerApiKey ? style.ok('set') : style.fail('missing');
|
|
31
|
+
const lines = [
|
|
32
|
+
'Environment : sandbox (default — use --prod to target production)',
|
|
33
|
+
`Sandbox URL : ${config.sandboxBaseUrl}`,
|
|
34
|
+
`Prod URL : ${config.baseUrl}`,
|
|
35
|
+
`Sandbox key : ${sandboxStatus}`,
|
|
36
|
+
`Prod key : ${prodStatus}`,
|
|
37
|
+
'Org : unknown — Kelviq has no key-introspection endpoint yet',
|
|
38
|
+
];
|
|
39
|
+
const report = lines.join('\n') + '\n';
|
|
40
|
+
io.stdout.write(report);
|
|
41
|
+
return report;
|
|
42
|
+
}
|
|
43
|
+
export function registerEnvCommand(program) {
|
|
44
|
+
program
|
|
45
|
+
.command('env')
|
|
46
|
+
.description('Show which Kelviq environment and API keys are configured.')
|
|
47
|
+
.option('--json', 'Machine-readable output (never includes key material)', false)
|
|
48
|
+
.action((opts) => {
|
|
49
|
+
runEnvReport({ stdout: process.stdout }, opts);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAwBlD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,EAAS,EAAE,UAAsB,EAAE;IAC9D,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAElE,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,GAAoB;YAC3B,WAAW,EAAE,SAAS;YACtB,UAAU,EAAE,MAAM,CAAC,cAAc;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YAC1D,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACrD,CAAC;QACF,MAA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} from 'commander';
|
|
2
|
+
export interface InitOptions {
|
|
3
|
+
output?: string;
|
|
4
|
+
force?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface InitIO {
|
|
7
|
+
stdout: NodeJS.WritableStream;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Writes the starter config to `options.output` (default `kelviq.config.ts`
|
|
11
|
+
* in the current directory). Returns a non-zero exit code and writes nothing
|
|
12
|
+
* if the target already exists and `--force` wasn't passed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runInit(options: InitOptions, io: InitIO): number;
|
|
15
|
+
export declare function registerInitCommand(program: Command): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// `kelviq init` — writes a starter `kelviq.config.ts` file (pricing-as-code;
|
|
2
|
+
// see src/config-format/). Refuses to clobber an existing file unless
|
|
3
|
+
// `--force` is passed.
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, resolve } from 'node:path';
|
|
6
|
+
import { INIT_HINT, printHint } from '../cli-ui/hints.js';
|
|
7
|
+
const DEFAULT_OUTPUT = 'kelviq.config.ts';
|
|
8
|
+
// A commented, compiling example — see CLI plan 004 Step 4. Imports from the
|
|
9
|
+
// published `@kelviq/cli/config` subpath (src/config-format/index.ts,
|
|
10
|
+
// exported via package.json's "./config" export).
|
|
11
|
+
const STARTER_CONFIG = `// kelviq.config.ts — pricing-as-code for Kelviq.
|
|
12
|
+
// Defines products, features, and plans as typed, versioned TypeScript.
|
|
13
|
+
// Sync this file with your Kelviq account using \`kelviq pull\` / \`kelviq push\`.
|
|
14
|
+
import { product, feature, plan } from '@kelviq/cli/config';
|
|
15
|
+
|
|
16
|
+
export const app = product({
|
|
17
|
+
identifier: 'my-app',
|
|
18
|
+
name: 'My App',
|
|
19
|
+
taxCode: 'saas',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const seats = feature({
|
|
23
|
+
identifier: 'seats',
|
|
24
|
+
name: 'Seats',
|
|
25
|
+
type: 'CUSTOMIZABLE',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const pro = plan({
|
|
29
|
+
identifier: 'pro',
|
|
30
|
+
name: 'Pro',
|
|
31
|
+
product: 'my-app',
|
|
32
|
+
entitlements: [{ feature: 'seats', value: 5 }],
|
|
33
|
+
prices: [
|
|
34
|
+
{
|
|
35
|
+
priceType: 'PAID',
|
|
36
|
+
currency: 'USD',
|
|
37
|
+
// Full charge shape: see Kelviq docs → api-reference/plans/update-plan-prices
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
`;
|
|
42
|
+
/**
|
|
43
|
+
* Writes the starter config to `options.output` (default `kelviq.config.ts`
|
|
44
|
+
* in the current directory). Returns a non-zero exit code and writes nothing
|
|
45
|
+
* if the target already exists and `--force` wasn't passed.
|
|
46
|
+
*/
|
|
47
|
+
export function runInit(options, io) {
|
|
48
|
+
const targetPath = resolve(options.output ?? DEFAULT_OUTPUT);
|
|
49
|
+
if (existsSync(targetPath) && !options.force) {
|
|
50
|
+
io.stdout.write(`${targetPath} already exists. Use --force to overwrite.\n`);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
54
|
+
writeFileSync(targetPath, STARTER_CONFIG);
|
|
55
|
+
io.stdout.write(`Wrote starter config to ${targetPath}\n`);
|
|
56
|
+
printHint(io.stdout, INIT_HINT);
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
export function registerInitCommand(program) {
|
|
60
|
+
program
|
|
61
|
+
.command('init')
|
|
62
|
+
.description('Generate a starter kelviq.config.ts file for pricing-as-code.')
|
|
63
|
+
.option('-o, --output <path>', 'Path to write the config file', DEFAULT_OUTPUT)
|
|
64
|
+
.option('--force', 'Overwrite the file if it already exists', false)
|
|
65
|
+
.action((opts) => {
|
|
66
|
+
const exitCode = runInit(opts, { stdout: process.stdout });
|
|
67
|
+
process.exitC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AmB,CAAC,OAAgB;IAClD,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,+DAA+D,CAAC;SAC5E,MAAM,CAAC,qBAAqB,EAAE,+BAA+B,EAAE,cAAc,CAAC;SAC9E,MAAM,CAAC,SAAS,EAAE,yCAAyC,EAAE,KAAK,CAAC;SACnE,MAAM,CAAC,CAAC,IAAiB,EAAE,EAAE;QAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface LoginIO {
|
|
3
|
+
stdin: NodeJS.ReadableStream;
|
|
4
|
+
stdout: NodeJS.WritableStream;
|
|
5
|
+
/** Whether stdin is an interactive terminal (masks input) vs piped (plain read). */
|
|
6
|
+
isTTY: boolean;
|
|
7
|
+
/** Injectable for tests; defaults to the real user config directory. */
|
|
8
|
+
configDir?: string;
|
|
9
|
+
/** Injectable for tests; defaults to the real best-effort browser opener. */
|
|
10
|
+
openUrl?: (url: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface LoginResult {
|
|
13
|
+
exitCode: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Prints the key page URL, tries to open it, prompts for the key on stdin
|
|
17
|
+
* (masked with asterisk feedback when interactive), and stores it via
|
|
18
|
+
* writeUserConfig. The raw pasted characters are never echoed or logged —
|
|
19
|
+
* only their count, in the post-capture receipt line.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runLogin(prod: boolean, io: LoginIO): Promise<LoginResult>;
|
|
22
|
+
export declare function registerLoginCommand(program: Command): void;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// `kelviq login` — paste-key auth (see plans-cli/003 for why: browser-handoff
|
|
2
|
+
// pairing needs backend endpoints that don't exist yet, and a CLI must never
|
|
3
|
+
// collect Kelviq account credentials directly).
|
|
4
|
+
//
|
|
5
|
+
// The action is split into an exported `runLogin` that takes injected IO so
|
|
6
|
+
// tests can drive it without spawning a process or a real TTY; the
|
|
7
|
+
// commander wiring in `registerLoginCommand` is the only part that touches
|
|
8
|
+
// real process.stdin/stdout.
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { createInterface } from 'node:readline';
|
|
13
|
+
import { Writable } from 'node:stream';
|
|
14
|
+
import { LOGIN_HINT, printHint } from '../cli-ui/hints.js';
|
|
15
|
+
import { writeUserConfig } from '../core/config.js';
|
|
16
|
+
/**
|
|
17
|
+
* Dashboard API-keys URL, deep-linked to the environment mode matching the
|
|
18
|
+
* login target. Naming asymmetry: the CLI/API call it "production", but the
|
|
19
|
+
* dashboard's query param calls it `live` — that spelling stays confined to
|
|
20
|
+
* the URL and never leaks into CLI wording.
|
|
21
|
+
*/
|
|
22
|
+
function keyPageUrl(prod) {
|
|
23
|
+
return `https://app.kelviq.com/settings/api-keys?mode=${prod ? 'live' : 'sandbox'}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Prints the key page URL, tries to open it, prompts for the key on stdin
|
|
27
|
+
* (masked with asterisk feedback when interactive), and stores it via
|
|
28
|
+
* writeUserConfig. The raw pasted characters are never echoed or logged —
|
|
29
|
+
* only their count, in the post-capture receipt line.
|
|
30
|
+
*/
|
|
31
|
+
export async function runLogin(prod, io) {
|
|
32
|
+
const envName = prod ? 'production' : 'sandbox';
|
|
33
|
+
const slot = prod ? 'prodServerApiKey' : 'sandboxServerApiKey';
|
|
34
|
+
const write = (s) => io.stdout.write(s);
|
|
35
|
+
const url = keyPageUrl(prod);
|
|
36
|
+
write(`Logging in to the ${envName} environment.\n`);
|
|
37
|
+
write(`Opening the dashboard so you can copy a key. If your browser doesn't open, visit:\n ${url}\n`);
|
|
38
|
+
(io.openUrl ?? openBrowserBestEffort)(url);
|
|
39
|
+
const pasted = await promptForKey(`Paste your ${envName} Server API key: `, io);
|
|
40
|
+
const key = pasted.trim();
|
|
41
|
+
if (!key) {
|
|
42
|
+
write('No key entered; nothing was saved.\n');
|
|
43
|
+
return { exitCode: 1 };
|
|
44
|
+
}
|
|
45
|
+
// Receipt of capture: count only (matches what gets stored below), never
|
|
46
|
+
// any other property of the key — no prefix, no substring.
|
|
47
|
+
write(`Received a ${key.length}-character key.\n`);
|
|
48
|
+
writeUserConfig({ [slot]: key }, io.configDir);
|
|
49
|
+
write(`Saved ${envName} key to ${displayConfigPath(io.configDir)}\n`);
|
|
50
|
+
printHint(io.stdout, LOGIN_HINT);
|
|
51
|
+
return { exitCode: 0 };
|
|
52
|
+
}
|
|
53
|
+
export function registerLoginCommand(program) {
|
|
54
|
+
program
|
|
55
|
+
.command('login')
|
|
56
|
+
.description('Paste a Kelviq Server API key from the dashboard and store it locally.')
|
|
57
|
+
.option('--prod', 'Store the key for the production environment instead of sandbox', false)
|
|
58
|
+
.action(async (opts) => {
|
|
59
|
+
const result = await runLogin(opts.prod, {
|
|
60
|
+
stdin: process.stdin,
|
|
61
|
+
stdout: process.stdout,
|
|
62
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
63
|
+
});
|
|
64
|
+
process.exitCode = result.exitCode;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
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
|
+
/**
|
|
169
|
+
* Best-effort browser open: spawn the platform opener, detached, with
|
|
170
|
+
* stdio ignored, and swallow every failure (missing binary, headless box,
|
|
171
|
+
* etc). The printed URL is the actual contract; this is a convenience.
|
|
172
|
+
*/
|
|
173
|
+
function openBrowserBestEffort(url) {
|
|
174
|
+
try {
|
|
175
|
+
const platform = process.platform;
|
|
176
|
+
const [command, args] = platform === 'darwin'
|
|
177
|
+
? ['open', [url]]
|
|
178
|
+
: platform === 'win32'
|
|
179
|
+
? ['cmd', ['/c', 'start', '""', url]]
|
|
180
|
+
: ['xdg-open', [url]];
|
|
181
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
182
|
+
child.on('error', () => {
|
|
183
|
+
// Best-effort only; the printed URL above is the real contract.
|
|
184
|
+
});
|
|
185
|
+
child.unref();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// Best-effort only; ignore.
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Mirrors config.ts's private default-directory logic purely to print a
|
|
193
|
+
* path in the success message. config.ts intentionally doesn't export a
|
|
194
|
+
* path helper (see CLI plan 003 environment facts); duplicating this one
|
|
195
|
+
* read-only computation is simpler than widening core's public API for a
|
|
196
|
+
* cosmetic message.
|
|
197
|
+
*/
|
|
198
|
+
function displayConfigPath(configDir) {
|
|
199
|
+
if (configDir)
|
|
200
|
+
return join(configDir, 'config.json');
|
|
201
|
+
const xdg = process.env.XDG_CONFIG_HOME?.trim();
|
|
202
|
+
const base = xdg || join(homedir(), '.config');
|
|
203
|
+
return join(base, 'kelviq', 'config.json');
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot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;QAC9F,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACrB,gEAAgE;QAClE,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface LogoutOptions {
|
|
3
|
+
prod?: boolean;
|
|
4
|
+
all?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface LogoutIO {
|
|
7
|
+
stdout: NodeJS.WritableStream;
|
|
8
|
+
/** Injectable for tests; defaults to the real user config directory. */
|
|
9
|
+
configDir?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Removes the requested key slot(s), printing what actually changed. Always exits 0. */
|
|
12
|
+
export declare function runLogout(options: LogoutOptions, io: LogoutIO): number;
|
|
13
|
+
export declare function registerLogoutCommand(program: Command): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { deleteUserConfigKey, loadCliConfig } from '../core/config.js';
|
|
2
|
+
function envNameOf(slot) {
|
|
3
|
+
return slot === 'prodServerApiKey' ? 'production' : 'sandbox';
|
|
4
|
+
}
|
|
5
|
+
/** Removes the requested key slot(s), printing what actually changed. Always exits 0. */
|
|
6
|
+
export function runLogout(options, io) {
|
|
7
|
+
const targets = options.all
|
|
8
|
+
? ['sandboxServerApiKey', 'prodServerApiKey']
|
|
9
|
+
: options.prod
|
|
10
|
+
? ['prodServerApiKey']
|
|
11
|
+
: ['sandboxServerApiKey'];
|
|
12
|
+
// Read the file-only view (strip the two key-override env vars so a real
|
|
13
|
+
// KELVIQ_*_SERVER_API_KEY on the operator's machine can't make an absent
|
|
14
|
+
// file key look present) to report accurately whether each slot actually
|
|
15
|
+
// held a value before deleting it.
|
|
16
|
+
const checkEnv = { ...process.env };
|
|
17
|
+
delete checkEnv.KELVIQ_SERVER_API_KEY;
|
|
18
|
+
delete checkEnv.KELVIQ_SANDBOX_SERVER_API_KEY;
|
|
19
|
+
const before = loadCliConfig(checkEnv, io.configDir);
|
|
20
|
+
for (const slot of targets) {
|
|
21
|
+
const envName = envNameOf(slot);
|
|
22
|
+
const had = Boolean(before[slot]);
|
|
23
|
+
deleteUserConfigKey(slot, io.configDir);
|
|
24
|
+
io.stdout.write(had ? `Removed ${envName} key.\n` : `No ${envName} key was stored.\n`);
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
export function registerLogoutCommand(program) {
|
|
29
|
+
program
|
|
30
|
+
.command('logout')
|
|
31
|
+
.description('Remove stored Kelviq API key(s) from the local config file.')
|
|
32
|
+
.option('--prod', 'Remove the production key instead of sandbox', false)
|
|
33
|
+
.option('--all', 'Remove both sandbox and production keys', false)
|
|
34
|
+
.action((opts) => {
|
|
35
|
+
const exitCode = runLogout(opts, { stdout: process.stdout });
|
|
36
|
+
process.exitCode = exitCode;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAevE,SAAS,SAAS,CAAC,IAAU;IAC3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8C,EAAE,KAAK,CAAC;SACvE,MAAM,CAAC,OAAO,EAAE,yCAAyC,EAAE,KAAK,CAAC;SACjE,MAAM,CAAC,CAAC,IAAmB,EAAE,EAAE;QAC9B,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export interface PromoteOptions {
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
yes?: boolean;
|
|
5
|
+
publish?: boolean;
|
|
6
|
+
migrateFeatures?: boolean;
|
|
7
|
+
migratePricing?: boolean;
|
|
8
|
+
/** CLI plan 010: archive remote-only plans/features in production that carry the `managed-by: kelviq-cli` marker (DESIGN-push.md §5/§6). Never touches products. Promote always targets production, so passing this always crosses the prod-prune gate (see `gateProdPrune`). */
|
|
9
|
+
prune?: boolean;
|
|
10
|
+
/** CLI plan 010: satisfies the prod-prune gate in a non-interactive session (or skips the interactive typed-name prompt). `--yes` alone never substitutes for this. */
|
|
11
|
+
allowProdPrune?: boolean;
|
|
12
|
+
/** CLI plan 014: renders every warning line exactly as it appears in `PushPlan.warnings`, bypassing price-drop aggregation. */
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
/** CLI plan 015: machine-readable output — the public `--dry-run --json` contract (src/sync/push-plan-json.ts). Valid ONLY together with `--dryRun`; forces styling/spinner off and prints exactly one JSON document on stdout. */
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface PromoteIO {
|
|
18
|
+
stdin: NodeJS.ReadableStream;
|
|
19
|
+
stdout: NodeJS.WritableStream;
|
|
20
|
+
stderr: NodeJS.WritableStream;
|
|
21
|
+
/** Whether stdin is an interactive terminal — governs the non-TTY-without-`--yes` refusal. */
|
|
22
|
+
isTTY: boolean;
|
|
23
|
+
/** Injectable for tests; defaults to process.env. */
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
/** Injectable for tests; defaults to the real user config directory. */
|
|
26
|
+
configDir?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Runs the full promote flow described in the module comment. Every
|
|
30
|
+
* failure — a missing key for either environment, a fetch failure —
|
|
31
|
+
* normalizes to a single `promote failed: <message>` line on stderr, same
|
|
32
|
+
* contract as push.ts/pull.ts. Feature-drift/error aborts, the dry-run stop,
|
|
33
|
+
* the empty-plan short-circuit, and the non-TTY-without-`--yes` refusal are
|
|
34
|
+
* NOT that catch block — they're expected, documented exits with their own
|
|
35
|
+
* messages.
|
|
36
|
+
*
|
|
37
|
+
* Reads no config file and writes none — `desired` is the freshly fetched
|
|
38
|
+
* SANDBOX catalog translated in-memory via `toConfigDefs`, never
|
|
39
|
+
* `loadConfigFile`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runPromote(options: PromoteOptions, io: PromoteIO): Promise<number>;
|
|
42
|
+
export declare function registerPromoteCommand(program: Command): void;
|