@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.
Files changed (99) hide show
  1. package/README.md +313 -0
  2. package/dist/cli-ui/auth-hint.d.ts +6 -0
  3. package/dist/cli-ui/auth-hint.js +34 -0
  4. package/dist/cli-ui/auth-hint.js.map +1 -0
  5. package/dist/cli-ui/hints.d.ts +5 -0
  6. package/dist/cli-ui/hints.js +19 -0
  7. package/dist/cli-ui/hints.js.map +1 -0
  8. package/dist/cli-ui/spinner.d.ts +7 -0
  9. package/dist/cli-ui/spinner.js +61 -0
  10. package/dist/cli-ui/spinner.js.map +1 -0
  11. package/dist/cli-ui/style.d.ts +47 -0
  12. package/dist/cli-ui/style.js +71 -0
  13. package/dist/cli-ui/style.js.map +1 -0
  14. package/dist/cli-ui/tty.d.ts +1 -0
  15. package/dist/cli-ui/tty.js +13 -0
  16. package/dist/cli-ui/tty.js.map +1 -0
  17. package/dist/cli.d.ts +2 -0
  18. package/dist/cli.js +51 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/commands/env.d.ts +34 -0
  21. package/dist/commands/env.js +52 -0
  22. package/dist/commands/env.js.map +1 -0
  23. package/dist/commands/init.d.ts +15 -0
  24. package/dist/commands/init.js +70 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/login.d.ts +22 -0
  27. package/dist/commands/login.js +205 -0
  28. package/dist/commands/login.js.map +1 -0
  29. package/dist/commands/logout.d.ts +13 -0
  30. package/dist/commands/logout.js +39 -0
  31. package/dist/commands/logout.js.map +1 -0
  32. package/dist/commands/promote.d.ts +42 -0
  33. package/dist/commands/promote.js +243 -0
  34. package/dist/commands/promote.js.map +1 -0
  35. package/dist/commands/pull.d.ts +31 -0
  36. package/dist/commands/pull.js +108 -0
  37. package/dist/commands/pull.js.map +1 -0
  38. package/dist/commands/push-shared.d.ts +97 -0
  39. package/dist/commands/push-shared.js +283 -0
  40. package/dist/commands/push-shared.js.map +1 -0
  41. package/dist/commands/push.d.ts +42 -0
  42. package/dist/commands/push.js +268 -0
  43. package/dist/commands/push.js.map +1 -0
  44. package/dist/config-format/builders.d.ts +10 -0
  45. package/dist/config-format/builders.js +46 -0
  46. package/dist/config-format/builders.js.map +1 -0
  47. package/dist/config-format/index.d.ts +4 -0
  48. package/dist/config-format/index.js +9 -0
  49. package/dist/config-format/index.js.map +1 -0
  50. package/dist/config-format/load.d.ts +23 -0
  51. package/dist/config-format/load.js +82 -0
  52. package/dist/config-format/load.js.map +1 -0
  53. package/dist/config-format/schema.d.ts +423 -0
  54. package/dist/config-format/schema.js +105 -0
  55. package/dist/config-format/schema.js.map +1 -0
  56. package/dist/core/config.d.ts +48 -0
  57. package/dist/core/config.js +128 -0
  58. package/dist/core/config.js.map +1 -0
  59. package/dist/core/errors.d.ts +20 -0
  60. package/dist/core/errors.js +58 -0
  61. package/dist/core/errors.js.map +1 -0
  62. package/dist/core/http.d.ts +39 -0
  63. package/dist/core/http.js +104 -0
  64. package/dist/core/http.js.map +1 -0
  65. package/dist/core/version.d.ts +1 -0
  66. package/dist/core/version.js +14 -0
  67. package/dist/core/version.js.map +1 -0
  68. package/dist/generated/openapi.json +6635 -0
  69. package/dist/sync/apply.d.ts +38 -0
  70. package/dist/sync/apply.js +234 -0
  71. package/dist/sync/apply.js.map +1 -0
  72. package/dist/sync/diff.d.ts +186 -0
  73. package/dist/sync/diff.js +402 -0
  74. package/dist/sync/diff.js.map +1 -0
  75. package/dist/sync/fetch-catalog.d.ts +105 -0
  76. package/dist/sync/fetch-catalog.js +100 -0
  77. package/dist/sync/fetch-catalog.js.map +1 -0
  78. package/dist/sync/price-filter.d.ts +37 -0
  79. package/dist/sync/price-filter.js +195 -0
  80. package/dist/sync/price-filter.js.map +1 -0
  81. package/dist/sync/prune.d.ts +77 -0
  82. package/dist/sync/prune.js +112 -0
  83. package/dist/sync/prune.js.map +1 -0
  84. package/dist/sync/publish.d.ts +75 -0
  85. package/dist/sync/publish.js +126 -0
  86. package/dist/sync/publish.js.map +1 -0
  87. package/dist/sync/push-plan-json.d.ts +79 -0
  88. package/dist/sync/push-plan-json.js +70 -0
  89. package/dist/sync/push-plan-json.js.map +1 -0
  90. package/dist/sync/render-plan.d.ts +83 -0
  91. package/dist/sync/render-plan.js +358 -0
  92. package/dist/sync/render-plan.js.map +1 -0
  93. package/dist/sync/serialize.d.ts +18 -0
  94. package/dist/sync/serialize.js +108 -0
  95. package/dist/sync/serialize.js.map +1 -0
  96. package/dist/sync/to-config.d.ts +9 -0
  97. package/dist/sync/to-config.js +191 -0
  98. package/dist/sync/to-config.js.map +1 -0
  99. package/package.json +68 -0
@@ -0,0 +1,243 @@
1
+ import { authHintLine, messageCarriesAuthStatus } from '../cli-ui/auth-hint.js';
2
+ import { createSpinner } from '../cli-ui/spinner.js';
3
+ import { loadCliConfig, resolveEnv } from '../core/config.js';
4
+ import { KelviqHttpClient } from '../core/http.js';
5
+ import { applyPushPlan } from '../sync/apply.js';
6
+ import { buildPushPlan } from '../sync/diff.js';
7
+ import { fetchCatalog } from '../sync/fetch-catalog.js';
8
+ import { toConfigDefs } from '../sync/to-config.js';
9
+ import { isPushPlanEmpty, plural, renderPushPlan } from '../sync/render-plan.js';
10
+ import { publishRequestBody, publishSetFromPushPlan, validatePublishFlags } from '../sync/publish.js';
11
+ import { buildPushJsonDocument, buildPushJsonErrorDocument, validateJsonFlags, writeJsonDocument } from '../sync/push-plan-json.js';
12
+ import { computePrunePlan, pruneArchiveCount } from '../sync/prune.js';
13
+ import { closePrompt, confirm, featureDriftAbortLines, gateProdPrune, renderApplyReport, renderFeatureDriftAbort, runPublishStep, runPruneStep, } from './push-shared.js';
14
+ /** §10: "The renderer's environment label must make the direction unmistakable." */
15
+ const PROMOTE_ENV_LABEL = 'promote: sandbox → production';
16
+ /** The publish step always targets production for promote — never the composite direction label (publish only ever acts on what was just written to the target). */
17
+ const PUBLISH_ENV_LABEL = 'production';
18
+ /**
19
+ * Runs the full promote flow described in the module comment. Every
20
+ * failure — a missing key for either environment, a fetch failure —
21
+ * normalizes to a single `promote failed: <message>` line on stderr, same
22
+ * contract as push.ts/pull.ts. Feature-drift/error aborts, the dry-run stop,
23
+ * the empty-plan short-circuit, and the non-TTY-without-`--yes` refusal are
24
+ * NOT that catch block — they're expected, documented exits with their own
25
+ * messages.
26
+ *
27
+ * Reads no config file and writes none — `desired` is the freshly fetched
28
+ * SANDBOX catalog translated in-memory via `toConfigDefs`, never
29
+ * `loadConfigFile`.
30
+ */
31
+ export async function runPromote(options, io) {
32
+ const write = (s) => io.stdout.write(s);
33
+ const writeErr = (s) => io.stderr.write(s);
34
+ // CLI plan 015: --json is checked alongside the other pre-I/O flag gates —
35
+ // it never mixes with prompts/writes, so a misuse (--json without
36
+ // --dry-run) is refused before either environment is even resolved.
37
+ const jsonFlagError = validateJsonFlags(options);
38
+ if (jsonFlagError) {
39
+ writeErr(`${jsonFlagError}\n`);
40
+ return 1;
41
+ }
42
+ const flagError = validatePublishFlags(options);
43
+ if (flagError) {
44
+ writeErr(`${flagError}\n`);
45
+ return 1;
46
+ }
47
+ try {
48
+ const cliConfig = loadCliConfig(io.env ?? process.env, io.configDir);
49
+ // §10: promote needs BOTH keys — sandbox to read, production to write.
50
+ // resolveEnv throws its standard MissingKeyError (naming the env var)
51
+ // for whichever is missing; sandbox is checked first since it's the
52
+ // source read that happens first.
53
+ const sandboxEnv = resolveEnv(cliConfig, false);
54
+ const prodEnv = resolveEnv(cliConfig, true);
55
+ const sandboxHttp = new KelviqHttpClient({
56
+ serverApiKey: sandboxEnv.key,
57
+ baseUrl: sandboxEnv.baseUrl,
58
+ edgeUrl: cliConfig.edgeUrl,
59
+ userAgent: cliConfig.userAgent,
60
+ });
61
+ const prodHttp = new KelviqHttpClient({
62
+ serverApiKey: prodEnv.key,
63
+ baseUrl: prodEnv.baseUrl,
64
+ edgeUrl: cliConfig.edgeUrl,
65
+ userAgent: cliConfig.userAgent,
66
+ });
67
+ let sandboxRaw;
68
+ if (options.json) {
69
+ // CLI plan 015: JSON mode forces the spinner off entirely (not just
70
+ // its animated frames) — stderr carries nothing but a fatal error.
71
+ sandboxRaw = await fetchCatalog(sandboxHttp);
72
+ }
73
+ else {
74
+ const sandboxSpinner = createSpinner(io.stderr);
75
+ sandboxSpinner.start('Fetching sandbox catalog...');
76
+ try {
77
+ sandboxRaw = await fetchCatalog(sandboxHttp);
78
+ }
79
+ catch (err) {
80
+ // No `.fail(...)` message: the catch block below already normalizes
81
+ // every failure to exactly one `promote failed: ...` line.
82
+ sandboxSpinner.stop();
83
+ throw err;
84
+ }
85
+ sandboxSpinner.succeed(`Fetched sandbox catalog (${plural(sandboxRaw.products.length, 'product')}, ${plural(sandboxRaw.features.length, 'feature')}, ${plural(sandboxRaw.plans.length, 'plan')})`);
86
+ }
87
+ const { products, features, plans, warnings: desiredWarnings } = toConfigDefs(sandboxRaw);
88
+ // CLI plan 015: JSON mode keeps stderr free of non-fatal narrative — these
89
+ // translation warnings aren't part of the `--json` contract (only
90
+ // `PushPlan.warnings` is; see push-plan-json.ts's module comment).
91
+ if (!options.json) {
92
+ for (const w of desiredWarnings)
93
+ writeErr(`warning: ${w}\n`);
94
+ }
95
+ const desired = { products, features, plans };
96
+ let prodRaw;
97
+ if (options.json) {
98
+ prodRaw = await fetchCatalog(prodHttp);
99
+ }
100
+ else {
101
+ const prodSpinner = createSpinner(io.stderr);
102
+ prodSpinner.start('Fetching production catalog...');
103
+ try {
104
+ prodRaw = await fetchCatalog(prodHttp);
105
+ }
106
+ catch (err) {
107
+ prodSpinner.stop();
108
+ throw err;
109
+ }
110
+ prodSpinner.succeed(`Fetched production catalog (${plural(prodRaw.products.length, 'product')}, ${plural(prodRaw.features.length, 'feature')}, ${plural(prodRaw.plans.length, 'plan')})`);
111
+ }
112
+ const plan = buildPushPlan(desired, prodRaw);
113
+ // DESIGN-push.md §3 (via §10, unchanged): feature drift is a hard error
114
+ // — same abort message push.ts uses, verbatim (push-shared.ts is the
115
+ // single source so the two commands can't drift in wording).
116
+ if (plan.featureDrift.length > 0 || plan.errors.length > 0) {
117
+ if (options.json) {
118
+ writeJsonDocument(io.stdout, buildPushJsonErrorDocument(featureDriftAbortLines(plan).join('\n'), plan.featureDrift));
119
+ }
120
+ else {
121
+ for (const line of renderFeatureDriftAbort(plan))
122
+ writeErr(`${line}\n`);
123
+ }
124
+ return 1;
125
+ }
126
+ // CLI plan 010: computed unconditionally (pure, cheap — no HTTP), same
127
+ // as push.ts.
128
+ const prunePlan = computePrunePlan(plan, prodRaw);
129
+ // Only rendered for an ACTUAL dry run — see push.ts's identical comment
130
+ // (same fix, same reason, caught live 2026-07-21).
131
+ const publishPreview = options.publish && options.dryRun
132
+ ? { planIdentifiers: publishSetFromPushPlan(plan), ...publishRequestBody(options) }
133
+ : undefined;
134
+ const prunePreview = options.prune
135
+ ? {
136
+ archivePlans: prunePlan.archive.plans.map((op) => op.identifier),
137
+ archiveFeatures: prunePlan.archive.features.map((op) => op.identifier),
138
+ skippedPlans: prunePlan.skipped.plans,
139
+ skippedFeatures: prunePlan.skipped.features,
140
+ }
141
+ : undefined;
142
+ if (options.json) {
143
+ // `--json` implies `--dry-run` (validated above) — render the public
144
+ // contract document and stop; never reaches confirm/apply/publish/
145
+ // prune below (json never mixes with prompts/writes). `direction` is
146
+ // always `promote` here — the composite "sandbox → production" label
147
+ // is a text-render-only concern (`PROMOTE_ENV_LABEL`); the JSON
148
+ // contract's `environment` field is always the target, `production`.
149
+ writeJsonDocument(io.stdout, buildPushJsonDocument({
150
+ envName: 'production',
151
+ direction: 'promote',
152
+ plan,
153
+ prunePlan,
154
+ prunePassed: Boolean(options.prune),
155
+ publishPreview,
156
+ }));
157
+ return 0;
158
+ }
159
+ write('\n' +
160
+ renderPushPlan(plan, { envName: PROMOTE_ENV_LABEL, directional: true, verbose: options.verbose, publishPreview, prune: prunePreview }) +
161
+ '\n');
162
+ if (options.dryRun) {
163
+ return 0;
164
+ }
165
+ const archiveCount = options.prune ? pruneArchiveCount(prunePlan) : 0;
166
+ if (isPushPlanEmpty(plan) && archiveCount === 0) {
167
+ return 0;
168
+ }
169
+ // CLI plan 010: promote always targets production, so `--prune` always
170
+ // crosses this gate (per DESIGN-push.md §5's note, quoted in this
171
+ // module's own header comment) — checked first, before the general
172
+ // confirmation, and never satisfied by `--yes` alone.
173
+ const prodGate = await gateProdPrune(true, archiveCount, options, io);
174
+ if (!prodGate.ok)
175
+ return 1;
176
+ if (!options.yes) {
177
+ if (!io.isTTY) {
178
+ writeErr('Refusing to apply changes without confirmation in a non-interactive session. Pass --yes to proceed.\n');
179
+ return 1;
180
+ }
181
+ const archiveSuffix = archiveCount > 0 ? ` (including ${archiveCount} archive${archiveCount === 1 ? '' : 's'})` : '';
182
+ const confirmed = await confirm(`\nApply these changes to ${PUBLISH_ENV_LABEL}${archiveSuffix}? [y/N] `, io);
183
+ if (!confirmed) {
184
+ write('Aborted; no changes were made.\n');
185
+ return 1;
186
+ }
187
+ }
188
+ write('\n');
189
+ const result = await applyPushPlan(prodHttp, plan, { stdout: io.stdout });
190
+ write('\n' + renderApplyReport(result) + '\n');
191
+ if (!result.ok)
192
+ return 1;
193
+ const publishOutcome = await runPublishStep(prodHttp, result, options, PUBLISH_ENV_LABEL, io);
194
+ if (!publishOutcome.ok)
195
+ return 1;
196
+ // CLI plan 010: prune runs strictly LAST — after publish — against
197
+ // PRODUCTION (`prodHttp`), same ordering/gating contract as push.ts.
198
+ const pruneOutcome = await runPruneStep(prodHttp, prunePlan, options.prune, io);
199
+ return pruneOutcome.ok ? 0 : 1;
200
+ }
201
+ catch (err) {
202
+ const message = err instanceof Error ? err.message : String(err);
203
+ const fullMessage = `promote failed: ${message}`;
204
+ if (options.json) {
205
+ writeJsonDocument(io.stdout, buildPushJsonErrorDocument(fullMessage));
206
+ }
207
+ else {
208
+ writeErr(`${fullMessage}\n`);
209
+ if (messageCarriesAuthStatus(message))
210
+ writeErr(`${authHintLine()}\n`);
211
+ }
212
+ return 1;
213
+ }
214
+ finally {
215
+ // Releases the shared readline interface (see push-shared.ts's
216
+ // `promptStreams`) if one was ever created this run.
217
+ closePrompt(io);
218
+ }
219
+ }
220
+ export function registerPromoteCommand(program) {
221
+ program
222
+ .command('promote')
223
+ .description('Move sandbox changes to production: diff sandbox against prod, confirm, and apply drafts-only writes. Reads/writes no local config file.')
224
+ .option('--dry-run', 'Print the plan-of-record diff and exit without writing anything', false)
225
+ .option('--yes', 'Skip the interactive confirmation prompt(s) (required in non-interactive sessions)', false)
226
+ .option('--publish', 'Publish plans this run created, updated, or price-replaced (drafts otherwise) — requires its own confirmation', false)
227
+ .option('--migrate-features', 'With --publish: migrate existing customers to the published plan\'s feature entitlements', false)
228
+ .option('--migrate-pricing', 'With --publish: migrate existing customers to the published plan\'s pricing', false)
229
+ .option('--prune', 'Archive remote-only plans/features in production that carry the kelviq-cli managed-by marker (never products; runs after publish)', false)
230
+ .option('--allow-prod-prune', 'Required (in place of the interactive typed confirmation) to --prune in a non-interactive session — promote always targets production', false)
231
+ .option('--verbose', 'List every individual dropped price field instead of the aggregated per-plan summary', false)
232
+ .option('--json', 'Machine-readable output (the public --dry-run --json contract) — valid only together with --dry-run', false)
233
+ .action(async (opts) => {
234
+ const exitCode = await runPromote(opts, {
235
+ stdin: process.stdin,
236
+ stdout: process.stdout,
237
+ stderr: process.stderr,
238
+ isTTY: Boolean(process.stdin.isTTY),
239
+ });
240
+ process.exitCode = exitCode;
241
+ });
242
+ }
243
+ //# sourceMappingURL=promote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote.js","sourceRoot":"","sources":["../../src/commands/promote.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,i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ACvJ,MAAM,CAAC,WAAW,EAAE,iEAAiE,EAAE,KAAK,CAAC;SAC7F,MAAM,CAAC,OAAO,EAAE,oFAAoF,EAAE,KAAK,CAAC;SAC5G,MAAM,CAAC,WAAW,EAAE,+GAA+G,EAAE,KAAK,CAAC;SAC3I,MAAM,CAAC,oBAAoB,EAAE,0FAA0F,EAAE,KAAK,CAAC;SAC/H,MAAM,CAAC,mBAAmB,EAAE,6EAA6E,EAAE,KAAK,CAAC;SACjH,MAAM,CAAC,SAAS,EAAE,mIAAmI,EAAE,KAAK,CAAC;SAC7J,MAAM,CAAC,oBAAoB,EAAE,uIAAuI,EAAE,KAAK,CAAC;SAC5K,MAAM,CAAC,WAAW,EAAE,sFAAsF,EAAE,KAAK,CAAC;SAClH,MAAM,CAAC,QAAQ,EAAE,qGAAqG,EAAE,KAAK,CAAC;SAC9H,MAAM,CAAC,KAAK,EAAE,IAAoB,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE;YACtC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;SACpC,CAAC,CAAC;QACH,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { Command } from 'commander';
2
+ export interface PullOptions {
3
+ prod?: boolean;
4
+ output?: string;
5
+ force?: boolean;
6
+ }
7
+ export interface PullIO {
8
+ stdout: NodeJS.WritableStream;
9
+ stderr: NodeJS.WritableStream;
10
+ /** Injectable for tests; defaults to process.env. */
11
+ env?: NodeJS.ProcessEnv;
12
+ /** Injectable for tests; defaults to the real user config directory. */
13
+ configDir?: string;
14
+ }
15
+ /**
16
+ * Resolves the environment, fetches the remote catalog, translates it into
17
+ * config defs, serializes it, and writes it to `options.output` (default
18
+ * `kelviq.config.ts`). Returns a non-zero exit code (and writes nothing) if
19
+ * the target already exists without `--force`, if no API key is configured
20
+ * for the requested environment, or if anything else in the run fails.
21
+ *
22
+ * Everything from environment resolution through the file write is one try
23
+ * block: this is a user-facing CLI command, so no error — a MissingKeyError,
24
+ * a fetch failure, a translation bug surfacing as a builder validation
25
+ * throw, an fs error — is ever allowed to escape as a raw stack trace. Every
26
+ * failure is normalized to a single `pull failed: <message>` line on
27
+ * stderr; a MissingKeyError's own actionable message (env var name,
28
+ * dashboard URL) passes through unchanged as that `<message>`.
29
+ */
30
+ export declare function runPull(options: PullOptions, io: PullIO): Promise<number>;
31
+ export declare function registerPullCommand(program: Command): void;
@@ -0,0 +1,108 @@
1
+ // `kelviq pull` — fetches the remote catalog (products, features, plans,
2
+ // plus per-plan prices/entitlements) and writes it to a `kelviq.config.ts`
3
+ // file. The on-ramp for pricing-as-code: point the CLI at an existing
4
+ // Kelviq org and get a config describing its catalog instead of
5
+ // hand-transcribing from the dashboard.
6
+ //
7
+ // No diff/merge: writing over an existing file requires `--force` (smart
8
+ // merge is a future release — see CLI plan 005 scope). Orchestration only —
9
+ // fetch/translate/serialize (src/sync/) stay pure and don't print; this
10
+ // command owns all stdout/stderr output.
11
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
12
+ import { dirname, resolve } from 'node:path';
13
+ import { authHintLine, messageCarriesAuthStatus } from '../cli-ui/auth-hint.js';
14
+ import { PULL_HINT, printHint } from '../cli-ui/hints.js';
15
+ import { createSpinner } from '../cli-ui/spinner.js';
16
+ import { loadCliConfig, resolveEnv } from '../core/config.js';
17
+ import { KelviqHttpClient } from '../core/http.js';
18
+ import { fetchCatalog } from '../sync/fetch-catalog.js';
19
+ import { plural } from '../sync/render-plan.js';
20
+ import { serializeConfig } from '../sync/serialize.js';
21
+ import { toConfigDefs } from '../sync/to-config.js';
22
+ const DEFAULT_OUTPUT = 'kelviq.config.ts';
23
+ /**
24
+ * Resolves the environment, fetches the remote catalog, translates it into
25
+ * config defs, serializes it, and writes it to `options.output` (default
26
+ * `kelviq.config.ts`). Returns a non-zero exit code (and writes nothing) if
27
+ * the target already exists without `--force`, if no API key is configured
28
+ * for the requested environment, or if anything else in the run fails.
29
+ *
30
+ * Everything from environment resolution through the file write is one try
31
+ * block: this is a user-facing CLI command, so no error — a MissingKeyError,
32
+ * a fetch failure, a translation bug surfacing as a builder validation
33
+ * throw, an fs error — is ever allowed to escape as a raw stack trace. Every
34
+ * failure is normalized to a single `pull failed: <message>` line on
35
+ * stderr; a MissingKeyError's own actionable message (env var name,
36
+ * dashboard URL) passes through unchanged as that `<message>`.
37
+ */
38
+ export async function runPull(options, io) {
39
+ const write = (s) => io.stdout.write(s);
40
+ const writeErr = (s) => io.stderr.write(s);
41
+ const targetPath = resolve(options.output ?? DEFAULT_OUTPUT);
42
+ if (existsSync(targetPath) && !options.force) {
43
+ write(`${targetPath} already exists. Use --force to overwrite it ` +
44
+ `(smart merge with an existing config is planned for a future release).\n`);
45
+ return 1;
46
+ }
47
+ try {
48
+ const config = loadCliConfig(io.env ?? process.env, io.configDir);
49
+ const resolved = resolveEnv(config, Boolean(options.prod));
50
+ const http = new KelviqHttpClient({
51
+ serverApiKey: resolved.key,
52
+ baseUrl: resolved.baseUrl,
53
+ edgeUrl: config.edgeUrl,
54
+ userAgent: config.userAgent,
55
+ });
56
+ const spinner = createSpinner(io.stderr);
57
+ spinner.start(`Fetching ${resolved.envName} catalog...`);
58
+ let raw;
59
+ try {
60
+ raw = await fetchCatalog(http);
61
+ }
62
+ catch (err) {
63
+ // No `spinner.fail(...)` message here: the catch block below already
64
+ // normalizes every failure to exactly one `pull failed: ...` line —
65
+ // an extra stderr line here would break that single-line contract
66
+ // (see this file's own "normalizes any internal failure" test).
67
+ spinner.stop();
68
+ throw err;
69
+ }
70
+ spinner.succeed(`Fetched ${resolved.envName} catalog (${plural(raw.products.length, 'product')}, ${plural(raw.features.length, 'feature')}, ${plural(raw.plans.length, 'plan')})`);
71
+ const { products, features, plans, warnings: translateWarnings } = toConfigDefs(raw);
72
+ const { code, warnings: serializeWarnings } = serializeConfig({ products, features, plans });
73
+ const warnings = [...translateWarnings, ...serializeWarnings];
74
+ mkdirSync(dirname(targetPath), { recursive: true });
75
+ writeFileSync(targetPath, code);
76
+ write(`Wrote ${targetPath}\n`);
77
+ write(` products: ${products.length}\n`);
78
+ write(` features: ${features.length}\n`);
79
+ write(` plans: ${plans.length}\n`);
80
+ if (warnings.length > 0) {
81
+ write(`\nWarnings (${warnings.length}):\n`);
82
+ for (const w of warnings)
83
+ write(` - ${w}\n`);
84
+ }
85
+ printHint(io.stdout, PULL_HINT);
86
+ return 0;
87
+ }
88
+ catch (err) {
89
+ const message = err instanceof Error ? err.message : String(err);
90
+ writeErr(`pull failed: ${message}\n`);
91
+ if (messageCarriesAuthStatus(message))
92
+ writeErr(`${authHintLine()}\n`);
93
+ return 1;
94
+ }
95
+ }
96
+ export function registerPullCommand(program) {
97
+ program
98
+ .command('pull')
99
+ .description('Fetch the remote catalog and write it to a kelviq.config.ts file.')
100
+ .option('--prod', 'Pull from the production environment instead of sandbox', false)
101
+ .option('-o, --output <path>', 'Path to write the config file', DEFAULT_OUTPUT)
102
+ .option('--force', 'Overwrite the output file if it already exists', false)
103
+ .action(async (opts) => {
104
+ const exitCode = await runPull(opts, { stdout: process.stdout, stderr: process.stderr });
105
+ process.exitCode = exitCode;
106
+ });
107
+ }
108
+ //# sourceMappingURL=pull.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull.js","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,sEAAsE;AACtE,gEAAgE;AAChE,wCAAwC;AACxC,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,wEAAwE;AACxE,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,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B;IAClD,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mEAAmE,CAAC;SAChF,MAAM,CAAC,QAAQ,EAAE,yDAAyD,EAAE,KAAK,CAAC;SAClF,MAAM,CAAC,qBAAqB,EAAE,+BAA+B,EAAE,cAAc,CAAC;SAC9E,MAAM,CAAC,SAAS,EAAE,gDAAgD,EAAE,KAAK,CAAC;SAC1E,MAAM,CAAC,KAAK,EAAE,IAAiB,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACzF,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,97 @@
1
+ import type { KelviqHttpClient } from '../core/http.js';
2
+ import type { ApplyResult } from '../sync/apply.js';
3
+ import type { PushPlan } from '../sync/diff.js';
4
+ import type { PublishFlagOptions, PublishResult } from '../sync/publish.js';
5
+ import type { PruneApplyResult, PrunePlan } from '../sync/prune.js';
6
+ export interface PromptIO {
7
+ stdin: NodeJS.ReadableStream;
8
+ stdout: NodeJS.WritableStream;
9
+ }
10
+ /** Reads one line from stdin, no echo suppression — a y/N answer isn't a secret, unlike login.ts's key prompt. Works identically for a real TTY (cooked-mode echo is the terminal driver's job, not readline's) and a piped/test stream. See `promptStreams`'s comment for why lines are queued rather than read via a fresh listener each call. */
11
+ export declare function promptLine(promptText: string, io: PromptIO): Promise<string>;
12
+ /** Default No: only an explicit y/yes (case-insensitive) counts as confirmation. */
13
+ export declare function confirm(promptText: string, io: PromptIO): Promise<boolean>;
14
+ /**
15
+ * Releases the shared readline interface for `io.stdin` (see
16
+ * `promptStreams`). Callers (`runPush`/`runPromote`) call this exactly once,
17
+ * unconditionally, at the very end of a run (success or failure) — a real
18
+ * TTY's readline interface otherwise keeps listening on stdin, which can
19
+ * keep the process's event loop alive instead of letting it exit. A no-op
20
+ * when no prompt was ever issued this run (nothing to release).
21
+ */
22
+ export declare function closePrompt(io: PromptIO): void;
23
+ /**
24
+ * DESIGN-push.md §3: feature drift is a hard error, never an op — the raw
25
+ * (unstyled) lines push and promote both print, verbatim, before aborting
26
+ * (never a write). Exported separately from `renderFeatureDriftAbort` below
27
+ * (CLI plan 015) so the `--json` error document's single `error` string
28
+ * (src/sync/push-plan-json.ts) can reuse the exact same wording without ever
29
+ * routing through `style.err` — JSON mode must never risk an ANSI escape
30
+ * landing inside a JSON string value.
31
+ */
32
+ export declare function featureDriftAbortLines(plan: PushPlan): string[];
33
+ /** Text-mode rendering of `featureDriftAbortLines` — styled red, one line per entry. */
34
+ export declare function renderFeatureDriftAbort(plan: PushPlan): string[];
35
+ export declare function renderApplyReport(result: ApplyResult): string;
36
+ export declare function renderPublishReport(result: PublishResult): string;
37
+ /** CLI plan 010: the `--prune` archive report — same applied/failed/not-attempted shape as `renderApplyReport`/`renderPublishReport`. */
38
+ export declare function renderPruneReport(result: PruneApplyResult): string;
39
+ export interface PublishStepIO {
40
+ stdin: NodeJS.ReadableStream;
41
+ stdout: NodeJS.WritableStream;
42
+ stderr: NodeJS.WritableStream;
43
+ isTTY: boolean;
44
+ }
45
+ /**
46
+ * The `--publish` confirmation + write step (DESIGN-push.md §4, CLI plan 009
47
+ * Step 1), run strictly last and only after the caller has already confirmed
48
+ * `applyResult.ok` — a failed push/promote never reaches here. Returns
49
+ * `{ ok: true }` when there was nothing to publish (either `--publish` was
50
+ * never passed, or this run touched no plan) — the caller treats that the
51
+ * same as success. This is the ONE place either command asks about
52
+ * publishing, so the confirmation copy (safety-critical UX per plan 009's
53
+ * maintenance notes) can never drift between push and promote.
54
+ */
55
+ export declare function runPublishStep(http: KelviqHttpClient, applyResult: ApplyResult, options: PublishFlagOptions & {
56
+ yes?: boolean;
57
+ }, envName: string, io: PublishStepIO): Promise<{
58
+ ok: boolean;
59
+ }>;
60
+ export interface ProdPruneGateOptions {
61
+ prune?: boolean;
62
+ allowProdPrune?: boolean;
63
+ }
64
+ /**
65
+ * DESIGN-push.md §5 / CLI plan 010: the prod-prune gate. `--prune` against
66
+ * production requires ONE of:
67
+ * - the explicit `--allow-prod-prune` flag — deliberate, unambiguous
68
+ * consent, honored in both TTY and non-TTY sessions; or
69
+ * - (TTY only) typing the environment name at a DEDICATED prompt — never
70
+ * the y/N write-confirmation gate, which only mentions the archive count
71
+ * (see push.ts/promote.ts).
72
+ * Non-interactive without the flag is refused, naming it. `--yes` is never
73
+ * consulted here — `options` deliberately has no `yes` field — so there is
74
+ * no code path where `--yes` alone satisfies this gate, per DESIGN-push.md
75
+ * §5's explicit rule. A no-op (`{ ok: true }`) when `--prune` wasn't passed,
76
+ * the target isn't production, or there's nothing to archive this run — the
77
+ * gate only exists to guard an actual production archive.
78
+ */
79
+ export declare function gateProdPrune(isProdTarget: boolean, archiveCount: number, options: ProdPruneGateOptions, io: PublishStepIO): Promise<{
80
+ ok: boolean;
81
+ }>;
82
+ export interface PruneStepIO {
83
+ stdout: NodeJS.WritableStream;
84
+ }
85
+ /**
86
+ * The `--prune` archive step (DESIGN-push.md §5, CLI plan 010), run
87
+ * strictly LAST — after `applyPushPlan` and, when requested, the publish
88
+ * step have both already succeeded. All required confirmation (the general
89
+ * write confirmation, mentioning the archive count, plus `gateProdPrune`
90
+ * above when the target is production) has already happened by the time
91
+ * this runs; this function only applies and reports. Returns `{ ok: true }`
92
+ * when `--prune` wasn't requested, or the computed `PrunePlan` has nothing
93
+ * to archive.
94
+ */
95
+ export declare function runPruneStep(http: KelviqHttpClient, prunePlan: PrunePlan, prune: boolean | undefined, io: PruneStepIO): Promise<{
96
+ ok: boolean;
97
+ }>;