@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,37 @@
1
+ import type { PriceDef } from '../config-format/schema.js';
2
+ /** Same pending mechanism as `PendingProductRef` (src/sync/diff.ts), for `chargeCatalogPrice[].feature`/`PlanFeaturesCreateRequest`'s `feature` (both UUIDs in the real request). */
3
+ export interface PendingFeatureRef {
4
+ readonly pendingFeatureIdentifier: string;
5
+ }
6
+ export type FeatureRefValue = string | PendingFeatureRef;
7
+ export declare const PLAN_PRICE_CREATE_REQUEST_FIELDS: readonly string[];
8
+ export declare const PLAN_CHARGE_CATALOG_PRICE_FIELDS: readonly string[];
9
+ export declare const PLAN_CHARGE_FIELDS: readonly string[];
10
+ export interface FilterPriceResult {
11
+ /**
12
+ * Allowlisted keys only, `chargeCatalogPrice[].feature` resolved to a UUID
13
+ * (or left null/absent when the source was null/absent). Ready to send
14
+ * inside a `PlanPriceBulkRequest.prices[]` entry AS LONG AS it contains no
15
+ * `PendingFeatureRef` placeholders — a `chargeCatalogPrice[].feature` that
16
+ * names a same-run pending feature is `{ pendingFeatureIdentifier }`, not
17
+ * a UUID, until the caller (CLI plan 008) resolves it against that
18
+ * feature's create response.
19
+ */
20
+ filtered: Record<string, unknown>;
21
+ /** Human-readable dropped-key paths, e.g. `chargeCatalogPrice[0].charges[1].stripePriceId`. */
22
+ dropped: string[];
23
+ /** Unresolvable `chargeCatalogPrice[].feature` references — never a silent drop. */
24
+ errors: string[];
25
+ }
26
+ /**
27
+ * Filters a config-space `PriceDef` down to a `PlanPriceCreateRequest`-shaped
28
+ * body: allowlist at every level (top-level price → `chargeCatalogPrice[]` →
29
+ * `charges[]`), with `chargeCatalogPrice[].feature` translated to a UUID via
30
+ * `featureUuidByIdentifier` (identifier -> UUID, built from the *current*
31
+ * remote features — see src/sync/diff.ts) or, for a feature `desired` also
32
+ * creates this run, a `PendingFeatureRef` placeholder (`pendingFeatureIdentifiers`
33
+ * — the same identifiers driving this run's feature-create ops). Never
34
+ * throws — unresolvable features land in `errors`, stripped keys land in
35
+ * `dropped`; the caller decides what to do with either.
36
+ */
37
+ export declare function filterPriceForRequest(price: PriceDef, featureUuidByIdentifier: Map<string, string>, pendingFeatureIdentifiers: ReadonlySet<string>): FilterPriceResult;
@@ -0,0 +1,195 @@
1
+ // Sourced from src/generated/openapi.json:
2
+ // components.schemas.PlanPriceCreateRequest.properties
3
+ // Hardcoded (not read at runtime) — the drift-guard test in
4
+ // test/sync-price-filter.test.ts asserts this list against a fresh read of
5
+ // the spec, so a `npm run snapshot` that changes the request schema fails a
6
+ // test instead of silently going stale. Re-verify here if that test fails.
7
+ export const PLAN_PRICE_CREATE_REQUEST_FIELDS = [
8
+ 'priceType',
9
+ 'currency',
10
+ 'freeTrial',
11
+ 'trialPeriod',
12
+ 'enabled',
13
+ 'taxBehavior',
14
+ 'chargeCatalogPrice',
15
+ ];
16
+ // Sourced from src/generated/openapi.json:
17
+ // components.schemas.PlanChargeCatalogPrice.properties
18
+ export const PLAN_CHARGE_CATALOG_PRICE_FIELDS = [
19
+ 'feature',
20
+ 'priceModel',
21
+ 'reset',
22
+ 'resetTime',
23
+ 'hasUnlimitedUsage',
24
+ 'paymentType',
25
+ 'rollover',
26
+ 'usageAlerts',
27
+ 'charges',
28
+ ];
29
+ // Sourced from src/generated/openapi.json:
30
+ // components.schemas.PlanCharge.properties
31
+ export const PLAN_CHARGE_FIELDS = ['chargePeriod', 'priceData', 'tiers', 'advanced'];
32
+ function isPlainObject(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
34
+ }
35
+ /**
36
+ * Resolves a value known to be an *identifier* (a bare string, or an
37
+ * embedded object's `identifier` field) against the current remote map,
38
+ * falling back to a `PendingFeatureRef` when the identifier matches no
39
+ * remote feature but does match one `desired` creates this run. Returns
40
+ * `undefined` when neither — the caller is responsible for the `errors`
41
+ * entry.
42
+ */
43
+ function resolveAsIdentifier(identifier, featureUuidByIdentifier, pendingFeatureIdentifiers) {
44
+ const uuid = featureUuidByIdentifier.get(identifier);
45
+ if (uuid)
46
+ return uuid;
47
+ if (pendingFeatureIdentifiers.has(identifier))
48
+ return { pendingFeatureIdentifier: identifier };
49
+ return undefined;
50
+ }
51
+ /**
52
+ * Resolves a value known to be a *UUID* (a bare string that isn't a known
53
+ * identifier, or an embedded object's `id` field) against the set of
54
+ * currently remote feature UUIDs. No pending fallback: a UUID can't be
55
+ * mapped to a pending feature's not-yet-assigned UUID (DESIGN-push.md §2 —
56
+ * this is the same "foreign UUID" rejection the map-based identifier
57
+ * lookup already implied before pending existed).
58
+ */
59
+ function resolveAsUuid(uuid, knownFeatureUuids) {
60
+ return knownFeatureUuids.has(uuid) ? uuid : undefined;
61
+ }
62
+ /**
63
+ * Resolves a `chargeCatalogPrice[].feature` reference to a UUID or a
64
+ * `PendingFeatureRef`. Accepts (DESIGN-push.md §2): an identifier string
65
+ * (map lookup, then pending); a raw UUID string (accepted iff it's one of
66
+ * the map's values — no pending fallback); an embedded object (unwrapped
67
+ * via `identifier` — map then pending — or, failing that, `id` — map only,
68
+ * mirroring `resolveFeatureIdentifier` in src/sync/to-config.ts); or
69
+ * null/absent (passed through unchanged — the request schema's `feature` is
70
+ * nullable). Anything else appends a message to `errors` naming `path` and
71
+ * returns `undefined` — the caller omits the key rather than sending a
72
+ * guess.
73
+ */
74
+ function resolveChargeFeature(value, featureUuidByIdentifier, knownFeatureUuids, pendingFeatureIdentifiers, path, errors) {
75
+ if (value === null || value === undefined)
76
+ return value;
77
+ if (typeof value === 'string') {
78
+ // A bare string's shape (identifier vs UUID) is ambiguous — try
79
+ // identifier resolution (existing or pending) first, then UUID.
80
+ const byIdentifier = resolveAsIdentifier(value, featureUuidByIdentifier, pendingFeatureIdentifiers);
81
+ if (byIdentifier !== undefined)
82
+ return byIdentifier;
83
+ const byUuid = resolveAsUuid(value, knownFeatureUuids);
84
+ if (byUuid !== undefined)
85
+ return byUuid;
86
+ errors.push(`${path}: unresolvable feature reference "${value}" (not a known identifier or UUID)`);
87
+ return undefined;
88
+ }
89
+ if (isPlainObject(value)) {
90
+ if (typeof value.identifier === 'string') {
91
+ const resolved = resolveAsIdentifier(value.identifier, featureUuidByIdentifier, pendingFeatureIdentifiers);
92
+ if (resolved !== undefined)
93
+ return resolved;
94
+ errors.push(`${path}: unresolvable feature reference "${value.identifier}" (not a known identifier or UUID)`);
95
+ return undefined;
96
+ }
97
+ if (typeof value.id === 'string') {
98
+ const resolved = resolveAsUuid(value.id, knownFeatureUuids);
99
+ if (resolved !== undefined)
100
+ return resolved;
101
+ errors.push(`${path}: unresolvable feature reference "${value.id}" (not a known identifier or UUID)`);
102
+ return undefined;
103
+ }
104
+ errors.push(`${path}: embedded feature object has neither "identifier" nor "id"`);
105
+ return undefined;
106
+ }
107
+ errors.push(`${path}: unexpected feature reference type (${typeof value})`);
108
+ return undefined;
109
+ }
110
+ function filterCharge(value, path, dropped, errors) {
111
+ if (!isPlainObject(value)) {
112
+ errors.push(`${path}: expected an object, got ${value === null ? 'null' : typeof value}`);
113
+ return {};
114
+ }
115
+ const filtered = {};
116
+ for (const [key, fieldValue] of Object.entries(value)) {
117
+ if (PLAN_CHARGE_FIELDS.includes(key)) {
118
+ filtered[key] = fieldValue;
119
+ }
120
+ else {
121
+ dropped.push(`${path}.${key}`);
122
+ }
123
+ }
124
+ return filtered;
125
+ }
126
+ function filterChargeCatalogPriceEntry(value, path, featureUuidByIdentifier, knownFeatureUuids, pendingFeatureIdentifiers, dropped, errors) {
127
+ if (!isPlainObject(value)) {
128
+ errors.push(`${path}: expected an object, got ${value === null ? 'null' : typeof value}`);
129
+ return {};
130
+ }
131
+ const filtered = {};
132
+ for (const [key, fieldValue] of Object.entries(value)) {
133
+ if (!PLAN_CHARGE_CATALOG_PRICE_FIELDS.includes(key)) {
134
+ dropped.push(`${path}.${key}`);
135
+ continue;
136
+ }
137
+ if (key === 'feature') {
138
+ const resolved = resolveChargeFeature(fieldValue, featureUuidByIdentifier, knownFeatureUuids, pendingFeatureIdentifiers, `${path}.feature`, errors);
139
+ // Omit the key entirely on an unresolved reference rather than guessing
140
+ // null (null is a valid, *meaningful* request value — "plan-level
141
+ // charge" — so it must never stand in for "couldn't resolve this").
142
+ if (resolved !== undefined)
143
+ filtered.feature = resolved;
144
+ continue;
145
+ }
146
+ if (key === 'charges') {
147
+ if (!Array.isArray(fieldValue)) {
148
+ errors.push(`${path}.charges: expected an array, got ${typeof fieldValue}`);
149
+ filtered.charges = [];
150
+ }
151
+ else {
152
+ filtered.charges = fieldValue.map((charge, i) => filterCharge(charge, `${path}.charges[${i}]`, dropped, errors));
153
+ }
154
+ continue;
155
+ }
156
+ filtered[key] = fieldValue;
157
+ }
158
+ return filtered;
159
+ }
160
+ /**
161
+ * Filters a config-space `PriceDef` down to a `PlanPriceCreateRequest`-shaped
162
+ * body: allowlist at every level (top-level price → `chargeCatalogPrice[]` →
163
+ * `charges[]`), with `chargeCatalogPrice[].feature` translated to a UUID via
164
+ * `featureUuidByIdentifier` (identifier -> UUID, built from the *current*
165
+ * remote features — see src/sync/diff.ts) or, for a feature `desired` also
166
+ * creates this run, a `PendingFeatureRef` placeholder (`pendingFeatureIdentifiers`
167
+ * — the same identifiers driving this run's feature-create ops). Never
168
+ * throws — unresolvable features land in `errors`, stripped keys land in
169
+ * `dropped`; the caller decides what to do with either.
170
+ */
171
+ export function filterPriceForRequest(price, featureUuidByIdentifier, pendingFeatureIdentifiers) {
172
+ const dropped = [];
173
+ const errors = [];
174
+ const knownFeatureUuids = new Set(featureUuidByIdentifier.values());
175
+ const filtered = {};
176
+ for (const [key, value] of Object.entries(price)) {
177
+ if (!PLAN_PRICE_CREATE_REQUEST_FIELDS.includes(key)) {
178
+ dropped.push(key);
179
+ continue;
180
+ }
181
+ if (key === 'chargeCatalogPrice') {
182
+ if (!Array.isArray(value)) {
183
+ errors.push(`chargeCatalogPrice: expected an array, got ${typeof value}`);
184
+ filtered.chargeCatalogPrice = [];
185
+ }
186
+ else {
187
+ filtered.chargeCatalogPrice = value.map((entry, i) => filterChargeCatalogPriceEntry(entry, `chargeCatalogPrice[${i}]`, featureUuidByIdentifier, knownFeatureUuids, pendingFeatureIdentifiers, dropped, errors));
188
+ }
189
+ continue;
190
+ }
191
+ filtered[key] = value;
192
+ }
193
+ return { filtered, dropped, errors };
194
+ }
195
+ //# sourceMappingURL=price-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-filter.js","sourceRoot":"","sources":["../../src/sync/price-filter.ts"],"names":[],"mappings":"AA8CA,2CAA2C;AAC3C,yDAAyD;AACzD,4DAA4D;AAC5D,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gCAAgC,GAAsB;IACjE,WAAW;IACX,UAAU;IACV,WAAW;IACX,aAAa;IACb,SAAS;IACT,aAAa;IACb,oBAAoB;CACrB,CAAC;AAEF,2CAA2C;AAC3C,yDAAyD;AACzD,MAAM,CAAC,MAAM,gCAAgC,GAAsB;IACjE,SAAS;IACT,YAAY;IACZ,OAAO;IACP,WAAW;IACX,mBAAmB;IACnB,aAAa;IACb,UAAU;IACV,aAAa;IACb,SAAS;CACV,CAAC;AAEF,2CAA2C;AAC3C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAmBxG,SAAS,aAAa,CAAC,KAAc;I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QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACpD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,GAAG,KAAK,oBAAoB,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,8CAA8C,OAAO,KAAK,EAAE,CAAC,CAAC;gBAC1E,QAAQ,CAAC,kBAAkB,GAAG,EAAE,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,kBAAkB,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CACnD,6BAA6B,CAC3B,KAAK,EACL,sBAAsB,CAAC,GAAG,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,EACzB,OAAO,EACP,MAAM,CACP,CACF,CAAC;YACJ,CAAC;YACD,SAAS;QACX,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { KelviqHttpClient } from '../core/http.js';
2
+ import type { PushPlan } from './diff.js';
3
+ import type { RawCatalog } from './fetch-catalog.js';
4
+ /** Why a candidate was NOT included in `PrunePlan.archive` — always a human-readable sentence, never a silent drop. */
5
+ export interface SkippedResource {
6
+ identifier: string;
7
+ reason: string;
8
+ }
9
+ export interface ArchivePlanOp {
10
+ kind: 'plan-archive';
11
+ identifier: string;
12
+ }
13
+ /** `DELETE /catalog/features/{pk}/` — features are archived by UUID, not identifier (unlike plans); `pk` is read from the raw catalog, never guessed. */
14
+ export interface ArchiveFeatureOp {
15
+ kind: 'feature-archive';
16
+ identifier: string;
17
+ pk: string;
18
+ }
19
+ export interface PrunePlan {
20
+ /** Execution order matches §5: plans first, then features. */
21
+ archive: {
22
+ plans: ArchivePlanOp[];
23
+ features: ArchiveFeatureOp[];
24
+ };
25
+ /** Remote-only plans/features that matched config history but carry no (or a different) `managed-by: kelviq-cli` marker — never archived, listed with a reason instead. */
26
+ skipped: {
27
+ plans: SkippedResource[];
28
+ features: SkippedResource[];
29
+ };
30
+ }
31
+ /**
32
+ * Partitions `plan.unmanagedRemote.plans`/`.features` into prunable
33
+ * (marker present) and skipped (marker absent/different) — pure data, no
34
+ * HTTP. `raw` is needed only to resolve a prunable feature's UUID (`pk`) for
35
+ * the archive endpoint; `diff.ts`'s `UnmanagedRemoteFeature` carries only the
36
+ * identifier and the marker boolean, by design (see diff.ts's own module
37
+ * comment on keeping diff computation identifier-space-only).
38
+ *
39
+ * Products are read from neither `plan.unmanagedRemote.products` nor `raw` —
40
+ * they have no path into `PrunePlan` at all (§5: products are never pruned,
41
+ * any mechanism, marker or not).
42
+ */
43
+ export declare function computePrunePlan(plan: PushPlan, raw: RawCatalog): PrunePlan;
44
+ /** True iff there is nothing to archive — the prune-equivalent of render-plan.ts's `isPushPlanEmpty`. Ignores `skipped` (informational, never a write), same convention. */
45
+ export declare function isPrunePlanEmpty(prunePlan: PrunePlan): boolean;
46
+ /** Total resource count `PrunePlan.archive` would archive — what the prod-prune gate and the write confirmation both need to render an accurate count. */
47
+ export declare function pruneArchiveCount(prunePlan: PrunePlan): number;
48
+ export type PruneOperationStatus = 'applied' | 'failed' | 'not-attempted';
49
+ export interface PruneOperationRecord {
50
+ kind: 'plan-archive' | 'feature-archive';
51
+ identifier: string;
52
+ description: string;
53
+ status: PruneOperationStatus;
54
+ /** Present only when `status === 'failed'`. */
55
+ error?: string;
56
+ }
57
+ export interface PruneApplyResult {
58
+ /** Every archive operation the plan contained, in execution order (plans then features), whether or not it was attempted. */
59
+ operations: PruneOperationRecord[];
60
+ /** True iff every operation applied (vacuously true for a plan with zero archive operations). */
61
+ ok: boolean;
62
+ }
63
+ /** Same `{ stdout }` shape apply.ts's `ApplyIO`/publish.ts's `PublishIO` use. */
64
+ export interface PruneApplyIO {
65
+ stdout: NodeJS.WritableStream;
66
+ }
67
+ /**
68
+ * Archives every operation in `prunePlan.archive`, plans first then features
69
+ * (§5 — so a pruned feature is never still attached to a soon-to-be-pruned
70
+ * plan), stopping on first failure with the same applied/failed/
71
+ * not-attempted partition `apply.ts`/`publish.ts` use. Never throws: an
72
+ * unexpected error from a single call is captured as that operation's `error`
73
+ * rather than escaping. Callers (push.ts/promote.ts) run this strictly LAST —
74
+ * after `applyPushPlan` and, when requested, the publish step — and only
75
+ * when both of those already succeeded.
76
+ */
77
+ export declare function applyPrunePlan(http: KelviqHttpClient, prunePlan: PrunePlan, io: PruneApplyIO): Promise<PruneApplyResult>;
@@ -0,0 +1,112 @@
1
+ import { style } from '../cli-ui/style.js';
2
+ const NO_MARKER_REASON = 'no kelviq-cli marker on the remote metadata (created outside this CLI, by another tool, or before marker support) — never pruned';
3
+ /**
4
+ * Partitions `plan.unmanagedRemote.plans`/`.features` into prunable
5
+ * (marker present) and skipped (marker absent/different) — pure data, no
6
+ * HTTP. `raw` is needed only to resolve a prunable feature's UUID (`pk`) for
7
+ * the archive endpoint; `diff.ts`'s `UnmanagedRemoteFeature` carries only the
8
+ * identifier and the marker boolean, by design (see diff.ts's own module
9
+ * comment on keeping diff computation identifier-space-only).
10
+ *
11
+ * Products are read from neither `plan.unmanagedRemote.products` nor `raw` —
12
+ * they have no path into `PrunePlan` at all (§5: products are never pruned,
13
+ * any mechanism, marker or not).
14
+ */
15
+ export function computePrunePlan(plan, raw) {
16
+ const featurePkByIdentifier = new Map(raw.features.map((f) => [f.identifier, f.id]));
17
+ const archivePlans = [];
18
+ const skippedPlans = [];
19
+ for (const p of plan.unmanagedRemote.plans) {
20
+ if (p.managedByMarker) {
21
+ archivePlans.push({ kind: 'plan-archive', identifier: p.identifier });
22
+ }
23
+ else {
24
+ skippedPlans.push({ identifier: p.identifier, reason: NO_MARKER_REASON });
25
+ }
26
+ }
27
+ const archiveFeatures = [];
28
+ const skippedFeatures = [];
29
+ for (const f of plan.unmanagedRemote.features) {
30
+ if (!f.managedByMarker) {
31
+ skippedFeatures.push({ identifier: f.identifier, reason: NO_MARKER_REASON });
32
+ continue;
33
+ }
34
+ const pk = featurePkByIdentifier.get(f.identifier);
35
+ if (!pk) {
36
+ // Defensive, not a reachable path in practice: `f.identifier` came from
37
+ // `toConfigDefs(raw)`, itself built from `raw.features` — the same
38
+ // list `featurePkByIdentifier` indexes. Refuse rather than guess.
39
+ skippedFeatures.push({
40
+ identifier: f.identifier,
41
+ reason: 'carries the managed-by marker but its UUID could not be resolved from the raw catalog — refusing to archive without a resolvable id',
42
+ });
43
+ continue;
44
+ }
45
+ archiveFeatures.push({ kind: 'feature-archive', identifier: f.identifier, pk });
46
+ }
47
+ return {
48
+ archive: { plans: archivePlans, features: archiveFeatures },
49
+ skipped: { plans: skippedPlans, features: skippedFeatures },
50
+ };
51
+ }
52
+ /** True iff there is nothing to archive — the prune-equivalent of render-plan.ts's `isPushPlanEmpty`. Ignores `skipped` (informational, never a write), same convention. */
53
+ export function isPrunePlanEmpty(prunePlan) {
54
+ return prunePlan.archive.plans.length === 0 && prunePlan.archive.features.length === 0;
55
+ }
56
+ /** Total resource count `PrunePlan.archive` would archive — what the prod-prune gate and the write confirmation both need to render an accurate count. */
57
+ export function pruneArchiveCount(prunePlan) {
58
+ return prunePlan.archive.plans.length + prunePlan.archive.features.length;
59
+ }
60
+ /**
61
+ * Archives every operation in `prunePlan.archive`, plans first then features
62
+ * (§5 — so a pruned feature is never still attached to a soon-to-be-pruned
63
+ * plan), stopping on first failure with the same applied/failed/
64
+ * not-attempted partition `apply.ts`/`publish.ts` use. Never throws: an
65
+ * unexpected error from a single call is captured as that operation's `error`
66
+ * rather than escaping. Callers (push.ts/promote.ts) run this strictly LAST —
67
+ * after `applyPushPlan` and, when requested, the publish step — and only
68
+ * when both of those already succeeded.
69
+ */
70
+ export async function applyPrunePlan(http, prunePlan, io) {
71
+ const operations = [];
72
+ let failed = false;
73
+ const write = (s) => io.stdout.write(s);
74
+ async function run(kind, identifier, description, exec) {
75
+ if (failed) {
76
+ operations.push({ kind, identifier, description, status: 'not-attempted' });
77
+ return;
78
+ }
79
+ write(`-> ${description}\n`);
80
+ let outcome;
81
+ try {
82
+ outcome = await exec();
83
+ }
84
+ catch (err) {
85
+ outcome = { ok: false, error: err instanceof Error ? err.message : String(err) };
86
+ }
87
+ if (outcome.ok) {
88
+ operations.push({ kind, identifier, description, status: 'applied' });
89
+ write(` ${style.ok('ok')}\n`);
90
+ }
91
+ else {
92
+ const error = outcome.error ?? 'unknown error';
93
+ operations.push({ kind, identifier, description, status: 'failed', error });
94
+ write(` ${style.fail(`FAILED: ${error}`)}\n`);
95
+ failed = true;
96
+ }
97
+ }
98
+ for (const op of prunePlan.archive.plans) {
99
+ await run('plan-archive', op.identifier, `archive plan "${op.identifier}"`, async () => {
100
+ const result = await http.request({ method: 'DELETE', path: `/catalog/plans/${encodeURIComponent(op.identifier)}/`, auth: 'server' });
101
+ return result.ok ? { ok: true } : { ok: false, error: result.error.message };
102
+ });
103
+ }
104
+ for (const op of prunePlan.archive.features) {
105
+ await run('feature-archive', op.identifier, `archive feature "${op.identifier}"`, async () => {
106
+ const result = await http.request({ method: 'DELETE', path: `/catalog/features/${encodeURIComponent(op.pk)}/`, auth: 'server' });
107
+ return result.ok ? { ok: true } : { ok: false, error: result.error.message };
108
+ });
109
+ }
110
+ return { operations, ok: !failed };
111
+ }
112
+ //# sourceMappingURL=prune.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.js","sourceRoot":"","sources":["../../src/sync/prune.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAmC3C,MAAM,gBAAgB,GACpB,kIAAkI,CAAC;AAErI;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,GAAe;IAC9D,MAAM,qBAAq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kB,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACtI,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC;IACD,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,GAAG,CAAC,iBAAiB,EAAE,EAAE,CAAC,UAAU,EAAE,oBAAoB,EAAE,CAAC,UAAU,GAAG,EAAE,KAAK,IAAI,EAAE;YAC3F,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,qBAAqB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACjI,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;AACrC,CAAC"}
@@ -0,0 +1,75 @@
1
+ import type { KelviqHttpClient } from '../core/http.js';
2
+ import type { ApplyResult } from './apply.js';
3
+ import type { PushPlan } from './diff.js';
4
+ export interface PublishFlagOptions {
5
+ publish?: boolean;
6
+ migrateFeatures?: boolean;
7
+ migratePricing?: boolean;
8
+ }
9
+ /**
10
+ * Gates the migration flags per DESIGN-push.md §4: `--migrate-features` /
11
+ * `--migrate-pricing` REQUIRE `--publish`. Returns a human-readable error
12
+ * naming the offending flag when violated; `undefined` for every valid
13
+ * combination (no flags at all; a bare `--publish`; `--publish` plus either
14
+ * or both migration flags).
15
+ */
16
+ export declare function validatePublishFlags(options: PublishFlagOptions): string | undefined;
17
+ /**
18
+ * The exact `PlanPublishRequest` body DESIGN-push.md §4 mandates: both
19
+ * booleans default `false`, and can only become `true` when their own flag
20
+ * was passed AND `--publish` itself was passed — the `Boolean(options.publish)
21
+ * && ...` structure is deliberate belt-and-suspenders: even if a future
22
+ * caller invoked this without first running `validatePublishFlags`, the
23
+ * booleans still can't go `true` off a migration flag alone.
24
+ */
25
+ export declare function publishRequestBody(options: PublishFlagOptions): {
26
+ updateFeatures: boolean;
27
+ updatePricing: boolean;
28
+ };
29
+ /**
30
+ * `--dry-run --publish` preview: the plans a real run of `plan` WOULD
31
+ * create, patch, or price-replace — computed straight from the `PushPlan`
32
+ * (nothing has been applied yet), in §8 dependency order, deduped to first
33
+ * occurrence (a plan that's both created/patched AND price-replaced this run
34
+ * keeps its earlier position).
35
+ */
36
+ export declare function publishSetFromPushPlan(plan: PushPlan): string[];
37
+ /**
38
+ * The real publish set for a completed run: plans this run actually
39
+ * created, patched, or price-replaced — i.e. `ApplyResult` operations of
40
+ * kind `plan-create`/`plan-patch`/`price-bulk-replace` whose `status` is
41
+ * `'applied'` (a `not-attempted`/`failed` op never touched anything, so it
42
+ * never belongs in the publish set — consistent with runPush/runPromote only
43
+ * calling this after confirming `applyResult.ok`). Order is
44
+ * `ApplyResult.operations`'s own order (itself §8 dependency order), deduped
45
+ * to first occurrence.
46
+ */
47
+ export declare function publishSetFromApplyResult(result: ApplyResult): string[];
48
+ export interface PublishOperationRecord {
49
+ planIdentifier: string;
50
+ status: 'published' | 'failed' | 'not-attempted';
51
+ /** Present only when `status === 'failed'`. */
52
+ error?: string;
53
+ }
54
+ export interface PublishResult {
55
+ /** Every plan identifier the step was asked to publish, in order, whether or not the publish call was attempted. */
56
+ operations: PublishOperationRecord[];
57
+ /** True iff every publish call succeeded (vacuously true for an empty publish set). */
58
+ ok: boolean;
59
+ }
60
+ /** Same `{ stdout }` shape apply.ts's `ApplyIO` uses — publish reuses it rather than declaring a parallel type. */
61
+ export interface PublishIO {
62
+ stdout: NodeJS.WritableStream;
63
+ }
64
+ /**
65
+ * Publishes every plan in `planIdentifiers`, in order, via
66
+ * `POST /catalog/plans/{identifier}/publish/` — same fixed-order,
67
+ * stop-on-first-failure contract as `applyPushPlan` (DESIGN-push.md §8):
68
+ * once one publish call fails, every remaining plan is recorded
69
+ * `not-attempted` rather than attempted. Never throws: an unexpected error
70
+ * from a single call is captured as that plan's `error`.
71
+ */
72
+ export declare function applyPublishStep(http: KelviqHttpClient, planIdentifiers: string[], body: {
73
+ updateFeatures: boolean;
74
+ updatePricing: boolean;
75
+ }, io: PublishIO): Promise<PublishResult>;
@@ -0,0 +1,126 @@
1
+ import { style } from '../cli-ui/style.js';
2
+ /**
3
+ * Gates the migration flags per DESIGN-push.md §4: `--migrate-features` /
4
+ * `--migrate-pricing` REQUIRE `--publish`. Returns a human-readable error
5
+ * naming the offending flag when violated; `undefined` for every valid
6
+ * combination (no flags at all; a bare `--publish`; `--publish` plus either
7
+ * or both migration flags).
8
+ */
9
+ export function validatePublishFlags(options) {
10
+ if (options.publish)
11
+ return undefined;
12
+ if (options.migrateFeatures)
13
+ return '--migrate-features requires --publish.';
14
+ if (options.migratePricing)
15
+ return '--migrate-pricing requires --publish.';
16
+ return undefined;
17
+ }
18
+ /**
19
+ * The exact `PlanPublishRequest` body DESIGN-push.md §4 mandates: both
20
+ * booleans default `false`, and can only become `true` when their own flag
21
+ * was passed AND `--publish` itself was passed — the `Boolean(options.publish)
22
+ * && ...` structure is deliberate belt-and-suspenders: even if a future
23
+ * caller invoked this without first running `validatePublishFlags`, the
24
+ * booleans still can't go `true` off a migration flag alone.
25
+ */
26
+ export function publishRequestBody(options) {
27
+ const published = Boolean(options.publish);
28
+ return {
29
+ updateFeatures: published && Boolean(options.migrateFeatures),
30
+ updatePricing: published && Boolean(options.migratePricing),
31
+ };
32
+ }
33
+ function addOnce(order, seen, identifier) {
34
+ if (seen.has(identifier))
35
+ return;
36
+ seen.add(identifier);
37
+ order.push(identifier);
38
+ }
39
+ /**
40
+ * `--dry-run --publish` preview: the plans a real run of `plan` WOULD
41
+ * create, patch, or price-replace — computed straight from the `PushPlan`
42
+ * (nothing has been applied yet), in §8 dependency order, deduped to first
43
+ * occurrence (a plan that's both created/patched AND price-replaced this run
44
+ * keeps its earlier position).
45
+ */
46
+ export function publishSetFromPushPlan(plan) {
47
+ const seen = new Set();
48
+ const order = [];
49
+ for (const op of plan.plans.create)
50
+ addOnce(order, seen, op.identifier);
51
+ for (const op of plan.plans.patch)
52
+ addOnce(order, seen, op.identifier);
53
+ for (const op of plan.prices.bulkReplace)
54
+ addOnce(order, seen, op.planIdentifier);
55
+ return order;
56
+ }
57
+ const PUBLISH_RELEVANT_KINDS = new Set(['plan-create', 'plan-patch', 'price-bulk-replace']);
58
+ /**
59
+ * The real publish set for a completed run: plans this run actually
60
+ * created, patched, or price-replaced — i.e. `ApplyResult` operations of
61
+ * kind `plan-create`/`plan-patch`/`price-bulk-replace` whose `status` is
62
+ * `'applied'` (a `not-attempted`/`failed` op never touched anything, so it
63
+ * never belongs in the publish set — consistent with runPush/runPromote only
64
+ * calling this after confirming `applyResult.ok`). Order is
65
+ * `ApplyResult.operations`'s own order (itself §8 dependency order), deduped
66
+ * to first occurrence.
67
+ */
68
+ export function publishSetFromApplyResult(result) {
69
+ const seen = new Set();
70
+ const order = [];
71
+ for (const op of result.operations) {
72
+ if (op.status !== 'applied')
73
+ continue;
74
+ if (!PUBLISH_RELEVANT_KINDS.has(op.kind))
75
+ continue;
76
+ if (!op.planIdentifier)
77
+ continue;
78
+ addOnce(order, seen, op.planIdentifier);
79
+ }
80
+ return order;
81
+ }
82
+ /**
83
+ * Publishes every plan in `planIdentifiers`, in order, via
84
+ * `POST /catalog/plans/{identifier}/publish/` — same fixed-order,
85
+ * stop-on-first-failure contract as `applyPushPlan` (DESIGN-push.md §8):
86
+ * once one publish call fails, every remaining plan is recorded
87
+ * `not-attempted` rather than attempted. Never throws: an unexpected error
88
+ * from a single call is captured as that plan's `error`.
89
+ */
90
+ export async function applyPublishStep(http, planIdentifiers, body, io) {
91
+ const operations = [];
92
+ let failed = false;
93
+ const write = (s) => io.stdout.write(s);
94
+ for (const identifier of planIdentifiers) {
95
+ if (failed) {
96
+ operations.push({ planIdentifier: identifier, status: 'not-attempted' });
97
+ continue;
98
+ }
99
+ write(`-> publish plan "${identifier}"\n`);
100
+ let outcome;
101
+ try {
102
+ const result = await http.request({
103
+ method: 'POST',
104
+ path: `/catalog/plans/${encodeURIComponent(identifier)}/publish/`,
105
+ body,
106
+ auth: 'server',
107
+ });
108
+ outcome = result.ok ? { ok: true } : { ok: false, error: result.error.message };
109
+ }
110
+ catch (err) {
111
+ outcome = { ok: false, error: err instanceof Error ? err.message : String(err) };
112
+ }
113
+ if (outcome.ok) {
114
+ operations.push({ planIdentifier: identifier, status: 'published' });
115
+ write(` ${style.ok('ok')}\n`);
116
+ }
117
+ else {
118
+ const error = outcome.error ?? 'unknown error';
119
+ operations.push({ planIdentifier: identifier, status: 'failed', error });
120
+ write(` ${style.fail(`FAILED: ${error}`)}\n`);
121
+ failed = true;
122
+ }
123
+ }
124
+ return { operations, ok: !failed };
125
+ }
126
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/sync/publish.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAU3C;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC9D,IAAI,OAAO,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACtC,IAAI,OAAO,CAAC,eAAe;QAAE,OAAO,wCAAwC,CAAC;IAC7E,IAAI,OAAO,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