@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,283 @@
1
+ // Command-layer pieces shared verbatim between `push` (src/commands/push.ts)
2
+ // and `promote` (src/commands/promote.ts, CLI plan 009). DESIGN-push.md §10
3
+ // requires promote's diff/apply behavior to be "inherited verbatim" from
4
+ // push, and its confirmation copy to match — the safest way to guarantee
5
+ // that is one shared module, not two hand-synced copies. Nothing here is
6
+ // reconciliation logic (that stays in src/sync/*, per §10's last paragraph);
7
+ // this is prompt/report/orchestration plumbing only.
8
+ import { createInterface } from 'node:readline';
9
+ import { style } from '../cli-ui/style.js';
10
+ import { applyPublishStep, publishRequestBody, publishSetFromApplyResult } from '../sync/publish.js';
11
+ import { applyPrunePlan } from '../sync/prune.js';
12
+ /**
13
+ * Keyed by the stdin stream itself so one command run — push.ts's write
14
+ * confirmation and this module's own publish confirmation both thread the
15
+ * SAME `io.stdin` — shares one underlying readline interface, with lines
16
+ * that arrive before anyone's asking BUFFERED rather than dropped.
17
+ *
18
+ * This matters starting with CLI plan 009: a `--publish` run can prompt
19
+ * TWICE per invocation (write confirmation, then publish confirmation) —
20
+ * the first time this module has ever needed more than one prompt per run.
21
+ * A naive create-a-fresh-interface-per-prompt implementation loses the
22
+ * second line when a piped/pasted multi-line stdin delivers both answers in
23
+ * the same underlying stream chunk: readline emits 'line' for every
24
+ * complete line found in that chunk SYNCHRONOUSLY, all before the first
25
+ * prompt's async continuation gets a chance to attach a listener for the
26
+ * second — so the second line fires into an empty room and is lost. A
27
+ * permanent 'line' listener (attached once, here) plus a queue closes that
28
+ * race: unclaimed lines wait in `queue` instead of evaporating.
29
+ */
30
+ const promptStreams = new WeakMap();
31
+ function getPromptStream(io) {
32
+ const existing = promptStreams.get(io.stdin);
33
+ if (existing)
34
+ return existing;
35
+ const state = {
36
+ rl: createInterface({ input: io.stdin, terminal: false }),
37
+ queue: [],
38
+ waiters: [],
39
+ closed: false,
40
+ };
41
+ state.rl.on('line', (line) => {
42
+ const waiter = state.waiters.shift();
43
+ if (waiter)
44
+ waiter(line);
45
+ else
46
+ state.queue.push(line);
47
+ });
48
+ state.rl.on('close', () => {
49
+ state.closed = true;
50
+ while (state.waiters.length > 0)
51
+ state.waiters.shift()?.('');
52
+ });
53
+ promptStreams.set(io.stdin, state);
54
+ return state;
55
+ }
56
+ /** 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. */
57
+ export function promptLine(promptText, io) {
58
+ io.stdout.write(promptText);
59
+ const state = getPromptStream(io);
60
+ if (state.queue.length > 0)
61
+ return Promise.resolve(state.queue.shift());
62
+ if (state.closed)
63
+ return Promise.resolve('');
64
+ return new Promise((resolvePromise) => {
65
+ state.waiters.push(resolvePromise);
66
+ });
67
+ }
68
+ /** Default No: only an explicit y/yes (case-insensitive) counts as confirmation. */
69
+ export async function confirm(promptText, io) {
70
+ const answer = (await promptLine(promptText, io)).trim().toLowerCase();
71
+ return answer === 'y' || answer === 'yes';
72
+ }
73
+ /**
74
+ * Releases the shared readline interface for `io.stdin` (see
75
+ * `promptStreams`). Callers (`runPush`/`runPromote`) call this exactly once,
76
+ * unconditionally, at the very end of a run (success or failure) — a real
77
+ * TTY's readline interface otherwise keeps listening on stdin, which can
78
+ * keep the process's event loop alive instead of letting it exit. A no-op
79
+ * when no prompt was ever issued this run (nothing to release).
80
+ */
81
+ export function closePrompt(io) {
82
+ const state = promptStreams.get(io.stdin);
83
+ if (!state)
84
+ return;
85
+ state.rl.close();
86
+ promptStreams.delete(io.stdin);
87
+ }
88
+ /**
89
+ * DESIGN-push.md §3: feature drift is a hard error, never an op — the raw
90
+ * (unstyled) lines push and promote both print, verbatim, before aborting
91
+ * (never a write). Exported separately from `renderFeatureDriftAbort` below
92
+ * (CLI plan 015) so the `--json` error document's single `error` string
93
+ * (src/sync/push-plan-json.ts) can reuse the exact same wording without ever
94
+ * routing through `style.err` — JSON mode must never risk an ANSI escape
95
+ * landing inside a JSON string value.
96
+ */
97
+ export function featureDriftAbortLines(plan) {
98
+ const lines = [];
99
+ if (plan.featureDrift.length > 0) {
100
+ lines.push('Feature drift detected: feature attributes are immutable via the API by design; ' +
101
+ 'edit the feature in the dashboard (name/description) and run `kelviq pull` to re-sync.');
102
+ for (const drift of plan.featureDrift) {
103
+ lines.push(` - "${drift.identifier}": ${drift.fields.join(', ')}`);
104
+ }
105
+ }
106
+ if (plan.errors.length > 0) {
107
+ lines.push('Errors:');
108
+ for (const e of plan.errors)
109
+ lines.push(` - ${e}`);
110
+ }
111
+ return lines;
112
+ }
113
+ /** Text-mode rendering of `featureDriftAbortLines` — styled red, one line per entry. */
114
+ export function renderFeatureDriftAbort(plan) {
115
+ return featureDriftAbortLines(plan).map((line) => style.err(line));
116
+ }
117
+ export function renderApplyReport(result) {
118
+ const applied = result.operations.filter((op) => op.status === 'applied');
119
+ if (result.ok) {
120
+ return `Push complete. Applied ${applied.length} operation${applied.length === 1 ? '' : 's'}.`;
121
+ }
122
+ const failedOps = result.operations.filter((op) => op.status === 'failed');
123
+ const notAttempted = result.operations.filter((op) => op.status === 'not-attempted');
124
+ const lines = ['Push failed partway through — no rollback; the report below is exactly what landed.', ''];
125
+ lines.push(`Applied (${applied.length}):`);
126
+ for (const op of applied)
127
+ lines.push(` - ${op.description}`);
128
+ lines.push('', `Failed (${failedOps.length}):`);
129
+ for (const op of failedOps)
130
+ lines.push(` - ${op.description}: ${op.error}`);
131
+ lines.push('', `Not attempted (${notAttempted.length}):`);
132
+ for (const op of notAttempted)
133
+ lines.push(` - ${op.description}`);
134
+ return lines.join('\n');
135
+ }
136
+ export function renderPublishReport(result) {
137
+ const published = result.operations.filter((op) => op.status === 'published');
138
+ if (result.ok) {
139
+ return `Published ${published.length} plan${published.length === 1 ? '' : 's'}.`;
140
+ }
141
+ const failedOps = result.operations.filter((op) => op.status === 'failed');
142
+ const notAttempted = result.operations.filter((op) => op.status === 'not-attempted');
143
+ const lines = [
144
+ 'Publish failed partway through — no rollback; the plans below already landed as drafts before publishing started.',
145
+ '',
146
+ ];
147
+ lines.push(`Published (${published.length}):`);
148
+ for (const op of published)
149
+ lines.push(` - ${op.planIdentifier}`);
150
+ lines.push('', `Failed (${failedOps.length}):`);
151
+ for (const op of failedOps)
152
+ lines.push(` - ${op.planIdentifier}: ${op.error}`);
153
+ lines.push('', `Not attempted (${notAttempted.length}):`);
154
+ for (const op of notAttempted)
155
+ lines.push(` - ${op.planIdentifier}`);
156
+ return lines.join('\n');
157
+ }
158
+ /** CLI plan 010: the `--prune` archive report — same applied/failed/not-attempted shape as `renderApplyReport`/`renderPublishReport`. */
159
+ export function renderPruneReport(result) {
160
+ const applied = result.operations.filter((op) => op.status === 'applied');
161
+ if (result.ok) {
162
+ return `Pruned ${applied.length} resource${applied.length === 1 ? '' : 's'}.`;
163
+ }
164
+ const failedOps = result.operations.filter((op) => op.status === 'failed');
165
+ const notAttempted = result.operations.filter((op) => op.status === 'not-attempted');
166
+ const lines = ['Prune failed partway through — no rollback; the report below is exactly what landed.', ''];
167
+ lines.push(`Archived (${applied.length}):`);
168
+ for (const op of applied)
169
+ lines.push(` - ${op.description}`);
170
+ lines.push('', `Failed (${failedOps.length}):`);
171
+ for (const op of failedOps)
172
+ lines.push(` - ${op.description}: ${op.error}`);
173
+ lines.push('', `Not attempted (${notAttempted.length}):`);
174
+ for (const op of notAttempted)
175
+ lines.push(` - ${op.description}`);
176
+ return lines.join('\n');
177
+ }
178
+ /**
179
+ * The `--publish` confirmation + write step (DESIGN-push.md §4, CLI plan 009
180
+ * Step 1), run strictly last and only after the caller has already confirmed
181
+ * `applyResult.ok` — a failed push/promote never reaches here. Returns
182
+ * `{ ok: true }` when there was nothing to publish (either `--publish` was
183
+ * never passed, or this run touched no plan) — the caller treats that the
184
+ * same as success. This is the ONE place either command asks about
185
+ * publishing, so the confirmation copy (safety-critical UX per plan 009's
186
+ * maintenance notes) can never drift between push and promote.
187
+ */
188
+ export async function runPublishStep(http, applyResult, options, envName, io) {
189
+ if (!options.publish)
190
+ return { ok: true };
191
+ const write = (s) => io.stdout.write(s);
192
+ const writeErr = (s) => io.stderr.write(s);
193
+ const planIdentifiers = publishSetFromApplyResult(applyResult);
194
+ if (planIdentifiers.length === 0) {
195
+ write('\nNothing to publish this run (no plan was created, updated, or had its prices replaced).\n');
196
+ return { ok: true };
197
+ }
198
+ const body = publishRequestBody(options);
199
+ write('\nPlans to publish:\n');
200
+ for (const identifier of planIdentifiers)
201
+ write(` - ${identifier}\n`);
202
+ if (body.updateFeatures) {
203
+ write("\nExisting customers will be migrated to the new plan's feature entitlements.\n");
204
+ }
205
+ if (body.updatePricing) {
206
+ write("Existing customers will be migrated to the new plan's pricing.\n");
207
+ }
208
+ if (!options.yes) {
209
+ if (!io.isTTY) {
210
+ writeErr('Refusing to publish without confirmation in a non-interactive session. Pass --yes to proceed.\n');
211
+ return { ok: false };
212
+ }
213
+ const n = planIdentifiers.length;
214
+ const countPhrase = style.bold(`${n} plan${n === 1 ? '' : 's'}`);
215
+ const confirmed = await confirm(`\nPublish ${countPhrase} to ${envName}? ${style.dim('[y/N]')} `, io);
216
+ if (!confirmed) {
217
+ write('Publish skipped; the writes above already landed as drafts.\n');
218
+ return { ok: false };
219
+ }
220
+ }
221
+ write('\n');
222
+ const result = await applyPublishStep(http, planIdentifiers, body, { stdout: io.stdout });
223
+ write('\n' + renderPublishReport(result) + '\n');
224
+ return { ok: result.ok };
225
+ }
226
+ const PROD_PRUNE_CONFIRM_WORD = 'production';
227
+ /**
228
+ * DESIGN-push.md §5 / CLI plan 010: the prod-prune gate. `--prune` against
229
+ * production requires ONE of:
230
+ * - the explicit `--allow-prod-prune` flag — deliberate, unambiguous
231
+ * consent, honored in both TTY and non-TTY sessions; or
232
+ * - (TTY only) typing the environment name at a DEDICATED prompt — never
233
+ * the y/N write-confirmation gate, which only mentions the archive count
234
+ * (see push.ts/promote.ts).
235
+ * Non-interactive without the flag is refused, naming it. `--yes` is never
236
+ * consulted here — `options` deliberately has no `yes` field — so there is
237
+ * no code path where `--yes` alone satisfies this gate, per DESIGN-push.md
238
+ * §5's explicit rule. A no-op (`{ ok: true }`) when `--prune` wasn't passed,
239
+ * the target isn't production, or there's nothing to archive this run — the
240
+ * gate only exists to guard an actual production archive.
241
+ */
242
+ export async function gateProdPrune(isProdTarget, archiveCount, options, io) {
243
+ if (!options.prune || archiveCount === 0 || !isProdTarget)
244
+ return { ok: true };
245
+ if (options.allowProdPrune)
246
+ return { ok: true };
247
+ const write = (s) => io.stdout.write(s);
248
+ const writeErr = (s) => io.stderr.write(s);
249
+ const suffix = archiveCount === 1 ? '' : 's';
250
+ if (!io.isTTY) {
251
+ writeErr(`Refusing to prune production without confirmation in a non-interactive session (this run would archive ${archiveCount} resource${suffix} in production). Pass --allow-prod-prune to proceed.\n`);
252
+ return { ok: false };
253
+ }
254
+ const countPhrase = style.bold(`${archiveCount} resource${suffix}`);
255
+ const typed = await promptLine(`\nThis will archive ${countPhrase} in ${style.archive('PRODUCTION')}. Type "${PROD_PRUNE_CONFIRM_WORD}" to confirm: `, io);
256
+ if (typed.trim() !== PROD_PRUNE_CONFIRM_WORD) {
257
+ write(`Aborted; production prune requires typing "${PROD_PRUNE_CONFIRM_WORD}" exactly. No changes were made.\n`);
258
+ return { ok: false };
259
+ }
260
+ return { ok: true };
261
+ }
262
+ /**
263
+ * The `--prune` archive step (DESIGN-push.md §5, CLI plan 010), run
264
+ * strictly LAST — after `applyPushPlan` and, when requested, the publish
265
+ * step have both already succeeded. All required confirmation (the general
266
+ * write confirmation, mentioning the archive count, plus `gateProdPrune`
267
+ * above when the target is production) has already happened by the time
268
+ * this runs; this function only applies and reports. Returns `{ ok: true }`
269
+ * when `--prune` wasn't requested, or the computed `PrunePlan` has nothing
270
+ * to archive.
271
+ */
272
+ export async function runPruneStep(http, prunePlan, prune, io) {
273
+ if (!prune)
274
+ return { ok: true };
275
+ if (prunePlan.archive.plans.length === 0 && prunePlan.archive.features.length === 0)
276
+ return { ok: true };
277
+ const write = (s) => io.stdout.write(s);
278
+ write('\n');
279
+ const result = await applyPrunePlan(http, prunePlan, { stdout: io.stdout });
280
+ write('\n' + renderPruneReport(result) + '\n');
281
+ return { ok: result.ok };
282
+ }
283
+ //# sourceMappingURL=push-shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-shared.js","sourceRoot":"","sources":["../../src/commands/push-shared.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,6EAA6E;AAC7E,qDAAqD;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAErG,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAgBlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,aAAa,GAAG,IAAI,OAAO,EAA4C,CAAC;AAE9E,SAAS,eAAe,CAAC,EAAY;IACnC,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,QAAQ;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1
+ import { Command } from 'commander';
2
+ export interface PushOptions {
3
+ prod?: boolean;
4
+ dryRun?: boolean;
5
+ yes?: boolean;
6
+ publish?: boolean;
7
+ migrateFeatures?: boolean;
8
+ migratePricing?: boolean;
9
+ /** CLI plan 010: archive remote-only plans/features that carry the `managed-by: kelviq-cli` marker (DESIGN-push.md §5/§6). Never touches products. */
10
+ prune?: boolean;
11
+ /** 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. */
12
+ allowProdPrune?: boolean;
13
+ /** CLI plan 014: renders every warning line exactly as it appears in `PushPlan.warnings`, bypassing price-drop aggregation. */
14
+ verbose?: boolean;
15
+ /** 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. */
16
+ json?: boolean;
17
+ }
18
+ export interface PushIO {
19
+ stdin: NodeJS.ReadableStream;
20
+ stdout: NodeJS.WritableStream;
21
+ stderr: NodeJS.WritableStream;
22
+ /** Whether stdin is an interactive terminal — governs the non-TTY-without-`--yes` refusal. */
23
+ isTTY: boolean;
24
+ /** Injectable for tests; defaults to process.env. */
25
+ env?: NodeJS.ProcessEnv;
26
+ /** Injectable for tests; defaults to the real user config directory. */
27
+ configDir?: string;
28
+ }
29
+ /**
30
+ * Runs the full push flow described in the module comment. Every failure —
31
+ * a load error, a missing key, a fetch failure — normalizes to a single
32
+ * `push failed: <message>` line on stderr, same contract as pull.ts.
33
+ * Feature-drift/error aborts, the dry-run stop, the empty-plan
34
+ * short-circuit, and the non-TTY-without-`--yes` refusal are NOT that catch
35
+ * block — they're expected, documented exits with their own messages.
36
+ *
37
+ * CLI plan 009: the `--migrate-features`/`--migrate-pricing` gate
38
+ * (`validatePublishFlags`) runs FIRST, before any I/O — a flag misuse never
39
+ * gets as far as loading the config file or resolving an environment.
40
+ */
41
+ export declare function runPush(configPath: string | undefined, options: PushOptions, io: PushIO): Promise<number>;
42
+ export declare function registerPushCommand(program: Command): void;
@@ -0,0 +1,268 @@
1
+ // `kelviq push` — deploys a `kelviq.config.ts` to a Kelviq environment
2
+ // (DESIGN-push.md, CLI plan 008; `--publish`/migration flags added by CLI
3
+ // plan 009; `--prune`/`--allow-prod-prune` added by CLI plan 010). Flow
4
+ // (DESIGN-push.md §7/§8, verbatim order, extended by plan 010's §5):
5
+ // 1. Load the config file, resolve the target environment.
6
+ // 2. Fetch remote state fresh (never cached) immediately before diffing.
7
+ // 3. Build the push plan (src/sync/diff.ts). Feature drift or unresolved
8
+ // references abort here, before any write. Also compute the prune
9
+ // plan (src/sync/prune.ts) — unconditionally, cheap, no HTTP.
10
+ // 4. Render the plan-of-record diff (src/sync/render-plan.ts) — including
11
+ // the `--publish` dry-run preview and, with `--prune`, the archive +
12
+ // skipped-unmanaged sections. `--dry-run` stops here with zero writes.
13
+ // 5. An empty plan AND empty prune plan (nothing to write or archive)
14
+ // short-circuits: no confirmation.
15
+ // 6. The prod-prune gate (src/commands/push-shared.ts's `gateProdPrune`):
16
+ // a no-op unless this run would archive something in production;
17
+ // otherwise a dedicated typed-name prompt (TTY) or `--allow-prod-prune`
18
+ // (non-TTY) — checked BEFORE the general confirmation, never satisfied
19
+ // by `--yes` alone.
20
+ // 7. Confirm: interactive TTY prompt (default No, mentioning the archive
21
+ // count when `--prune` is active), or `--yes` for headless/CI use —
22
+ // never both skipped.
23
+ // 8. Apply (src/sync/apply.ts), in DESIGN-push.md §8's fixed order, and
24
+ // print the resulting report.
25
+ // 9. `--publish` (§4/§8, strictly last, only if step 8 fully succeeded):
26
+ // a SEPARATE confirmation naming the plans and the migration
27
+ // consequence, then the publish writes (src/sync/publish.ts). See
28
+ // src/commands/push-shared.ts's `runPublishStep` — the exact same
29
+ // function `promote` (CLI plan 009) uses for its own publish step.
30
+ // 10. `--prune` archive step (CLI plan 010, strictly last, only if step 9
31
+ // fully succeeded): src/commands/push-shared.ts's `runPruneStep`,
32
+ // applying src/sync/prune.ts's `applyPrunePlan` — plans then features,
33
+ // never products.
34
+ //
35
+ // Orchestration only, same house rule as pull.ts: src/sync/* stays
36
+ // (mostly) pure — apply.ts/publish.ts/prune.ts are the exceptions, printing
37
+ // their own per-operation progress lines — and this command owns the rest
38
+ // of stdout/stderr.
39
+ import { resolve } from 'node:path';
40
+ import { authHintLine, messageCarriesAuthStatus } from '../cli-ui/auth-hint.js';
41
+ import { createSpinner } from '../cli-ui/spinner.js';
42
+ import { loadCliConfig, resolveEnv } from '../core/config.js';
43
+ import { KelviqHttpClient } from '../core/http.js';
44
+ import { loadConfigFile } from '../config-format/load.js';
45
+ import { applyPushPlan } from '../sync/apply.js';
46
+ import { buildPushPlan } from '../sync/diff.js';
47
+ import { fetchCatalog } from '../sync/fetch-catalog.js';
48
+ import { isPushPlanEmpty, plural, renderPushPlan } from '../sync/render-plan.js';
49
+ import { publishRequestBody, publishSetFromPushPlan, validatePublishFlags } from '../sync/publish.js';
50
+ import { buildPushJsonDocument, buildPushJsonErrorDocument, validateJsonFlags, writeJsonDocument } from '../sync/push-plan-json.js';
51
+ import { computePrunePlan, pruneArchiveCount } from '../sync/prune.js';
52
+ import { closePrompt, confirm, featureDriftAbortLines, gateProdPrune, renderApplyReport, renderFeatureDriftAbort, runPublishStep, runPruneStep, } from './push-shared.js';
53
+ const DEFAULT_CONFIG_PATH = 'kelviq.config.ts';
54
+ /**
55
+ * Runs the full push flow described in the module comment. Every failure —
56
+ * a load error, a missing key, a fetch failure — normalizes to a single
57
+ * `push failed: <message>` line on stderr, same contract as pull.ts.
58
+ * Feature-drift/error aborts, the dry-run stop, the empty-plan
59
+ * short-circuit, and the non-TTY-without-`--yes` refusal are NOT that catch
60
+ * block — they're expected, documented exits with their own messages.
61
+ *
62
+ * CLI plan 009: the `--migrate-features`/`--migrate-pricing` gate
63
+ * (`validatePublishFlags`) runs FIRST, before any I/O — a flag misuse never
64
+ * gets as far as loading the config file or resolving an environment.
65
+ */
66
+ export async function runPush(configPath, options, io) {
67
+ const write = (s) => io.stdout.write(s);
68
+ const writeErr = (s) => io.stderr.write(s);
69
+ // CLI plan 015: --json is checked alongside the other pre-I/O flag gates —
70
+ // it never mixes with prompts/writes, so a misuse (--json without
71
+ // --dry-run) is refused before the config file is even read.
72
+ const jsonFlagError = validateJsonFlags(options);
73
+ if (jsonFlagError) {
74
+ writeErr(`${jsonFlagError}\n`);
75
+ return 1;
76
+ }
77
+ const flagError = validatePublishFlags(options);
78
+ if (flagError) {
79
+ writeErr(`${flagError}\n`);
80
+ return 1;
81
+ }
82
+ const targetPath = resolve(configPath ?? DEFAULT_CONFIG_PATH);
83
+ try {
84
+ const { config: desired, warnings: loadWarnings } = await loadConfigFile(targetPath);
85
+ // CLI plan 015: JSON mode keeps stderr free of non-fatal narrative — these
86
+ // config-authoring warnings aren't part of the `--json` contract (only
87
+ // `PushPlan.warnings` is; see push-plan-json.ts's module comment).
88
+ if (!options.json) {
89
+ for (const w of loadWarnings)
90
+ writeErr(`warning: ${w}\n`);
91
+ }
92
+ const cliConfig = loadCliConfig(io.env ?? process.env, io.configDir);
93
+ const resolved = resolveEnv(cliConfig, Boolean(options.prod));
94
+ const http = new KelviqHttpClient({
95
+ serverApiKey: resolved.key,
96
+ baseUrl: resolved.baseUrl,
97
+ edgeUrl: cliConfig.edgeUrl,
98
+ userAgent: cliConfig.userAgent,
99
+ });
100
+ let raw;
101
+ if (options.json) {
102
+ // CLI plan 015: JSON mode forces the spinner off entirely (not just
103
+ // its animated frames) — stderr carries nothing but a fatal error.
104
+ raw = await fetchCatalog(http);
105
+ }
106
+ else {
107
+ const spinner = createSpinner(io.stderr);
108
+ spinner.start(`Fetching ${resolved.envName} catalog...`);
109
+ try {
110
+ raw = await fetchCatalog(http);
111
+ }
112
+ catch (err) {
113
+ // No `spinner.fail(...)` message here: the catch block below already
114
+ // normalizes every failure to exactly one `push failed: ...` line —
115
+ // an extra stderr line here would break that single-line contract
116
+ // (see test/pull.test.ts's equivalent invariant test).
117
+ spinner.stop();
118
+ throw err;
119
+ }
120
+ spinner.succeed(`Fetched ${resolved.envName} catalog (${plural(raw.products.length, 'product')}, ${plural(raw.features.length, 'feature')}, ${plural(raw.plans.length, 'plan')})`);
121
+ }
122
+ const plan = buildPushPlan(desired, raw);
123
+ // DESIGN-push.md §3: feature drift is a hard error, never an op — abort
124
+ // before any write, and before even rendering a diff (there's nothing
125
+ // trustworthy to render around an aborted plan).
126
+ if (plan.featureDrift.length > 0 || plan.errors.length > 0) {
127
+ if (options.json) {
128
+ writeJsonDocument(io.stdout, buildPushJsonErrorDocument(featureDriftAbortLines(plan).join('\n'), plan.featureDrift));
129
+ }
130
+ else {
131
+ for (const line of renderFeatureDriftAbort(plan))
132
+ writeErr(`${line}\n`);
133
+ }
134
+ return 1;
135
+ }
136
+ // CLI plan 010: computed unconditionally (pure, cheap — no HTTP) so the
137
+ // marker-gated partition exists whether or not `--prune` was passed;
138
+ // only rendered/applied below when it was.
139
+ const prunePlan = computePrunePlan(plan, raw);
140
+ // CLI plan 009: `--dry-run --publish` previews the publish set (computed
141
+ // straight from the plan, since nothing has been applied yet) alongside
142
+ // the normal diff — still zero writes. Only rendered for an ACTUAL dry
143
+ // run: a real `--publish` run prints its own (real) "Plans to publish"
144
+ // section later, from runPublishStep — showing this "would publish, dry
145
+ // run" preview ahead of an about-to-happen real publish would read as
146
+ // contradictory (caught live: 2026-07-21, see push.ts's git history).
147
+ const publishPreview = options.publish && options.dryRun
148
+ ? { planIdentifiers: publishSetFromPushPlan(plan), ...publishRequestBody(options) }
149
+ : undefined;
150
+ // CLI plan 010: the archive/skipped sections only render when `--prune`
151
+ // was passed — the no-`--prune` render path stays byte-for-byte
152
+ // unchanged (see render-plan.ts's RenderPushPlanOptions.prune comment).
153
+ const prunePreview = options.prune
154
+ ? {
155
+ archivePlans: prunePlan.archive.plans.map((op) => op.identifier),
156
+ archiveFeatures: prunePlan.archive.features.map((op) => op.identifier),
157
+ skippedPlans: prunePlan.skipped.plans,
158
+ skippedFeatures: prunePlan.skipped.features,
159
+ }
160
+ : undefined;
161
+ if (options.json) {
162
+ // `--json` implies `--dry-run` (validated above) — render the public
163
+ // contract document and stop; never reaches confirm/apply/publish/
164
+ // prune below (json never mixes with prompts/writes).
165
+ writeJsonDocument(io.stdout, buildPushJsonDocument({
166
+ envName: resolved.envName,
167
+ direction: 'push',
168
+ plan,
169
+ prunePlan,
170
+ prunePassed: Boolean(options.prune),
171
+ publishPreview,
172
+ }));
173
+ return 0;
174
+ }
175
+ write('\n' + renderPushPlan(plan, { envName: resolved.envName, verbose: options.verbose, publishPreview, prune: prunePreview }) + '\n');
176
+ if (options.dryRun) {
177
+ return 0;
178
+ }
179
+ const archiveCount = options.prune ? pruneArchiveCount(prunePlan) : 0;
180
+ if (isPushPlanEmpty(plan) && archiveCount === 0) {
181
+ return 0;
182
+ }
183
+ // CLI plan 010: the prod-prune gate is checked FIRST — a refusal here
184
+ // means no prompt (and no write) happens at all, regardless of --yes
185
+ // (DESIGN-push.md §5: "--yes alone does not unlock pruning production").
186
+ // A no-op unless this run would actually archive something in production.
187
+ const prodGate = await gateProdPrune(resolved.envName === 'production', archiveCount, options, io);
188
+ if (!prodGate.ok)
189
+ return 1;
190
+ if (!options.yes) {
191
+ if (!io.isTTY) {
192
+ writeErr('Refusing to apply changes without confirmation in a non-interactive session. Pass --yes to proceed.\n');
193
+ return 1;
194
+ }
195
+ // CLI plan 010: the confirmation prompt names the archive count
196
+ // explicitly once --prune is in play (DESIGN-push.md §7/§10 note) —
197
+ // 0 archives (the default, no-`--prune` case) keeps this prompt
198
+ // identical to before this plan.
199
+ const archiveSuffix = archiveCount > 0 ? ` (including ${archiveCount} archive${archiveCount === 1 ? '' : 's'})` : '';
200
+ const confirmed = await confirm(`\nApply these changes to ${resolved.envName}${archiveSuffix}? [y/N] `, io);
201
+ if (!confirmed) {
202
+ write('Aborted; no changes were made.\n');
203
+ return 1;
204
+ }
205
+ }
206
+ write('\n');
207
+ const result = await applyPushPlan(http, plan, { stdout: io.stdout });
208
+ write('\n' + renderApplyReport(result) + '\n');
209
+ if (!result.ok)
210
+ return 1;
211
+ // CLI plan 009 §4/§8: publish runs strictly last, only after every prior
212
+ // write succeeded, behind its OWN confirmation (separate from the one
213
+ // above) — see push-shared.ts's runPublishStep for the exact copy.
214
+ const publishOutcome = await runPublishStep(http, result, options, resolved.envName, io);
215
+ if (!publishOutcome.ok)
216
+ return 1;
217
+ // CLI plan 010: prune runs strictly LAST — after publish — and only
218
+ // when both prior steps succeeded (see push-shared.ts's runPruneStep;
219
+ // a no-op when `--prune` wasn't passed or nothing was marked to archive).
220
+ const pruneOutcome = await runPruneStep(http, prunePlan, options.prune, io);
221
+ return pruneOutcome.ok ? 0 : 1;
222
+ }
223
+ catch (err) {
224
+ const message = err instanceof Error ? err.message : String(err);
225
+ const fullMessage = `push failed: ${message}`;
226
+ if (options.json) {
227
+ writeJsonDocument(io.stdout, buildPushJsonErrorDocument(fullMessage));
228
+ }
229
+ else {
230
+ writeErr(`${fullMessage}\n`);
231
+ if (messageCarriesAuthStatus(message))
232
+ writeErr(`${authHintLine()}\n`);
233
+ }
234
+ return 1;
235
+ }
236
+ finally {
237
+ // Releases the shared readline interface (see push-shared.ts's
238
+ // `promptStreams`) if one was ever created this run — a no-op for
239
+ // --dry-run/--yes/non-TTY-refusal paths that never prompted.
240
+ closePrompt(io);
241
+ }
242
+ }
243
+ export function registerPushCommand(program) {
244
+ program
245
+ .command('push')
246
+ .description('Push a kelviq.config.ts file to a Kelviq environment: diff, confirm, and apply drafts-only writes.')
247
+ .argument('[config]', 'Path to the config file', DEFAULT_CONFIG_PATH)
248
+ .option('--prod', 'Push to the production environment instead of sandbox', false)
249
+ .option('--dry-run', 'Print the plan-of-record diff and exit without writing anything', false)
250
+ .option('--yes', 'Skip the interactive confirmation prompt(s) (required in non-interactive sessions)', false)
251
+ .option('--publish', 'Publish plans this run created, updated, or price-replaced (drafts otherwise) — requires its own confirmation', false)
252
+ .option('--migrate-features', 'With --publish: migrate existing customers to the published plan\'s feature entitlements', false)
253
+ .option('--migrate-pricing', 'With --publish: migrate existing customers to the published plan\'s pricing', false)
254
+ .option('--prune', 'Archive remote-only plans/features that carry the kelviq-cli managed-by marker (never products; runs after publish)', false)
255
+ .option('--allow-prod-prune', 'Required (in place of the interactive typed confirmation) to --prune against production in a non-interactive session', false)
256
+ .option('--verbose', 'List every individual dropped price field instead of the aggregated per-plan summary', false)
257
+ .option('--json', 'Machine-readable output (the public --dry-run --json contract) — valid only together with --dry-run', false)
258
+ .action(async (configPath, opts) => {
259
+ const exitCode = await runPush(configPath, opts, {
260
+ stdin: process.stdin,
261
+ stdout: process.stdout,
262
+ stderr: process.stderr,
263
+ isTTY: Boolean(process.stdin.isTTY),
264
+ });
265
+ process.exitCode = exitCode;
266
+ });
267
+ }
268
+ //# sourceMappingURL=push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.js","sourceRoot":"","sources":["../../src/commands/push.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,wEAAwE;AACxE,qEAAqE;AACrE,6DAA6D;AAC7D,2EAA2E;AAC3E,2EAA2E;AAC3E,uEAAuE;AACvE,mEAAmE;AACnE,4EAA4E;AAC5E,0EAA0E;AAC1E,4EAA4E;AAC5E,wEAAwE;AACxE,wCAAwC;AACxC,4EAA4E;AAC5E,sEAAsE;AACtE,6EAA6E;AAC7E,4EAA4E;AAC5E,yBAAyB;AACzB,2EAA2E;AAC3E,yEAAyE;AACzE,2BAA2B;AAC3B,0EAA0E;AAC1E,mCAAmC;AACnC,2EAA2E;AAC3E,kEAAkE;AAClE,uEAAuE;AACvE,uEAAuE;AACvE,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,6EAA6E;AAC7E,wBAAwB;AACxB,EAAE;AACF,mEAAmE;AACnE,4EAA4E;AAC5E,0EAA0E;AAC1E,oBAAoB;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAA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,CAAC,WAAW,EAAE,sFAAsF,EAAE,KAAK,CAAC;SAClH,MAAM,CAAC,QAAQ,EAAE,qGAAqG,EAAE,KAAK,CAAC;SAC9H,MAAM,CAAC,KAAK,EAAE,UAA8B,EAAE,IAAiB,EAAE,EAAE;QAClE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE;YAC/C,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,10 @@
1
+ import type { z } from 'zod';
2
+ import { featureDefSchema, planDefSchema, productDefSchema, type FeatureDef, type PlanDef, type ProductDef } from './schema.js';
3
+ export type Kind = 'product' | 'feature' | 'plan';
4
+ /** A parsed def plus a non-enumerable `__kind` tag identifying which builder produced it. */
5
+ export type Branded<T, K extends Kind> = T & {
6
+ readonly __kind: K;
7
+ };
8
+ export declare function product(def: z.input<typeof productDefSchema>): Branded<ProductDef, 'product'>;
9
+ export declare function feature(def: z.input<typeof featureDefSchema>): Branded<FeatureDef, 'feature'>;
10
+ export declare function plan(def: z.input<typeof planDefSchema>): Branded<PlanDef, 'plan'>;