@kelviq/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +313 -0
- package/dist/cli-ui/auth-hint.d.ts +6 -0
- package/dist/cli-ui/auth-hint.js +34 -0
- package/dist/cli-ui/auth-hint.js.map +1 -0
- package/dist/cli-ui/hints.d.ts +5 -0
- package/dist/cli-ui/hints.js +19 -0
- package/dist/cli-ui/hints.js.map +1 -0
- package/dist/cli-ui/spinner.d.ts +7 -0
- package/dist/cli-ui/spinner.js +61 -0
- package/dist/cli-ui/spinner.js.map +1 -0
- package/dist/cli-ui/style.d.ts +47 -0
- package/dist/cli-ui/style.js +71 -0
- package/dist/cli-ui/style.js.map +1 -0
- package/dist/cli-ui/tty.d.ts +1 -0
- package/dist/cli-ui/tty.js +13 -0
- package/dist/cli-ui/tty.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/env.d.ts +34 -0
- package/dist/commands/env.js +52 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/init.d.ts +15 -0
- package/dist/commands/init.js +70 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/login.d.ts +22 -0
- package/dist/commands/login.js +205 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +13 -0
- package/dist/commands/logout.js +39 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/promote.d.ts +42 -0
- package/dist/commands/promote.js +243 -0
- package/dist/commands/promote.js.map +1 -0
- package/dist/commands/pull.d.ts +31 -0
- package/dist/commands/pull.js +108 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push-shared.d.ts +97 -0
- package/dist/commands/push-shared.js +283 -0
- package/dist/commands/push-shared.js.map +1 -0
- package/dist/commands/push.d.ts +42 -0
- package/dist/commands/push.js +268 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/config-format/builders.d.ts +10 -0
- package/dist/config-format/builders.js +46 -0
- package/dist/config-format/builders.js.map +1 -0
- package/dist/config-format/index.d.ts +4 -0
- package/dist/config-format/index.js +9 -0
- package/dist/config-format/index.js.map +1 -0
- package/dist/config-format/load.d.ts +23 -0
- package/dist/config-format/load.js +82 -0
- package/dist/config-format/load.js.map +1 -0
- package/dist/config-format/schema.d.ts +423 -0
- package/dist/config-format/schema.js +105 -0
- package/dist/config-format/schema.js.map +1 -0
- package/dist/core/config.d.ts +48 -0
- package/dist/core/config.js +128 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/http.d.ts +39 -0
- package/dist/core/http.js +104 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +14 -0
- package/dist/core/version.js.map +1 -0
- package/dist/generated/openapi.json +6635 -0
- package/dist/sync/apply.d.ts +38 -0
- package/dist/sync/apply.js +234 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/diff.d.ts +186 -0
- package/dist/sync/diff.js +402 -0
- package/dist/sync/diff.js.map +1 -0
- package/dist/sync/fetch-catalog.d.ts +105 -0
- package/dist/sync/fetch-catalog.js +100 -0
- package/dist/sync/fetch-catalog.js.map +1 -0
- package/dist/sync/price-filter.d.ts +37 -0
- package/dist/sync/price-filter.js +195 -0
- package/dist/sync/price-filter.js.map +1 -0
- package/dist/sync/prune.d.ts +77 -0
- package/dist/sync/prune.js +112 -0
- package/dist/sync/prune.js.map +1 -0
- package/dist/sync/publish.d.ts +75 -0
- package/dist/sync/publish.js +126 -0
- package/dist/sync/publish.js.map +1 -0
- package/dist/sync/push-plan-json.d.ts +79 -0
- package/dist/sync/push-plan-json.js +70 -0
- package/dist/sync/push-plan-json.js.map +1 -0
- package/dist/sync/render-plan.d.ts +83 -0
- package/dist/sync/render-plan.js +358 -0
- package/dist/sync/render-plan.js.map +1 -0
- package/dist/sync/serialize.d.ts +18 -0
- package/dist/sync/serialize.js +108 -0
- package/dist/sync/serialize.js.map +1 -0
- package/dist/sync/to-config.d.ts +9 -0
- package/dist/sync/to-config.js +191 -0
- package/dist/sync/to-config.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { filterPriceForRequest } from './price-filter.js';
|
|
2
|
+
import { toConfigDefs } from './to-config.js';
|
|
3
|
+
const MANAGED_BY_KEY = 'managed-by';
|
|
4
|
+
const MANAGED_BY_VALUE = 'kelviq-cli';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Canonicalization — undefined/absent compare equal, object key order is
|
|
7
|
+
// irrelevant. Array order still matters generically; entitlements and prices
|
|
8
|
+
// get their own order-insensitive comparisons below because they're
|
|
9
|
+
// logically sets/multisets, not ordered lists.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
function canonicalize(value) {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(canonicalize);
|
|
14
|
+
if (value !== null && typeof value === 'object') {
|
|
15
|
+
const record = value;
|
|
16
|
+
const sorted = {};
|
|
17
|
+
for (const key of Object.keys(record).sort()) {
|
|
18
|
+
const fieldValue = record[key];
|
|
19
|
+
if (fieldValue === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
sorted[key] = canonicalize(fieldValue);
|
|
22
|
+
}
|
|
23
|
+
return sorted;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function canonicalKey(value) {
|
|
28
|
+
return JSON.stringify(canonicalize(value));
|
|
29
|
+
}
|
|
30
|
+
function canonicalEqual(a, b) {
|
|
31
|
+
return canonicalKey(a) === canonicalKey(b);
|
|
32
|
+
}
|
|
33
|
+
/** Order-insensitive (and duplicate-count-sensitive) array equality over already-filtered price bodies. */
|
|
34
|
+
function pricesEqualAsMultiset(a, b) {
|
|
35
|
+
if (a.length !== b.length)
|
|
36
|
+
return false;
|
|
37
|
+
const aKeys = a.map(canonicalKey).sort();
|
|
38
|
+
const bKeys = b.map(canonicalKey).sort();
|
|
39
|
+
return aKeys.every((key, i) => key === bKeys[i]);
|
|
40
|
+
}
|
|
41
|
+
function hasManagedByMarker(metadata) {
|
|
42
|
+
return metadata?.[MANAGED_BY_KEY] === MANAGED_BY_VALUE;
|
|
43
|
+
}
|
|
44
|
+
/** Strips the marker key before comparing metadata — see CLI plan 007 final report for why plans get the same treatment as features here even though DESIGN-push.md's wording is explicit only for features: without it, a hand-authored config that never mentions `metadata` would show spurious drift/patches forever against a marker the config author never declared. */
|
|
45
|
+
function stripMarker(metadata) {
|
|
46
|
+
if (!metadata)
|
|
47
|
+
return {};
|
|
48
|
+
const { [MANAGED_BY_KEY]: _marker, ...rest } = metadata;
|
|
49
|
+
return rest;
|
|
50
|
+
}
|
|
51
|
+
/** Merges the marker in, always winning over a config-declared `managed-by` key (DESIGN-push.md §6: "merged into — never replacing — whatever metadata the config author declares", with the marker itself the one exception). */
|
|
52
|
+
function mergeMarker(metadata) {
|
|
53
|
+
return { ...(metadata ?? {}), [MANAGED_BY_KEY]: MANAGED_BY_VALUE };
|
|
54
|
+
}
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Products
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
function diffProductFields(desired, remote) {
|
|
59
|
+
const body = {};
|
|
60
|
+
const changedFields = [];
|
|
61
|
+
const previous = {};
|
|
62
|
+
if (desired.name !== remote.name) {
|
|
63
|
+
body.name = desired.name;
|
|
64
|
+
previous.name = remote.name;
|
|
65
|
+
changedFields.push('name');
|
|
66
|
+
}
|
|
67
|
+
if (desired.taxCode !== remote.taxCode) {
|
|
68
|
+
body.taxCode = desired.taxCode;
|
|
69
|
+
previous.taxCode = remote.taxCode;
|
|
70
|
+
changedFields.push('taxCode');
|
|
71
|
+
}
|
|
72
|
+
// Optional field: absence in config means "no opinion", not "clear it" —
|
|
73
|
+
// same convention as prices/entitlements (DESIGN-push.md §3: omitting an
|
|
74
|
+
// array signals "don't touch"), applied here to keep a pulled config's
|
|
75
|
+
// absent-vs-present optional fields from producing phantom patches.
|
|
76
|
+
if (desired.description !== undefined && desired.description !== remote.description) {
|
|
77
|
+
body.description = desired.description;
|
|
78
|
+
previous.description = remote.description;
|
|
79
|
+
changedFields.push('description');
|
|
80
|
+
}
|
|
81
|
+
return { body, changedFields, previous };
|
|
82
|
+
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Features
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
function diffFeatureFields(desired, remote) {
|
|
87
|
+
const changed = [];
|
|
88
|
+
if (desired.name !== remote.name)
|
|
89
|
+
changed.push('name');
|
|
90
|
+
if (desired.type !== remote.type)
|
|
91
|
+
changed.push('type');
|
|
92
|
+
if (desired.description !== undefined && desired.description !== remote.description)
|
|
93
|
+
changed.push('description');
|
|
94
|
+
if (desired.featureDetails !== undefined && !canonicalEqual(desired.featureDetails, remote.featureDetails)) {
|
|
95
|
+
changed.push('featureDetails');
|
|
96
|
+
}
|
|
97
|
+
if (desired.meter !== undefined && !canonicalEqual(desired.meter, remote.meter)) {
|
|
98
|
+
changed.push('meter');
|
|
99
|
+
}
|
|
100
|
+
if (desired.metadata !== undefined) {
|
|
101
|
+
const desiredMeta = stripMarker(desired.metadata);
|
|
102
|
+
const remoteMeta = stripMarker(remote.metadata);
|
|
103
|
+
if (!canonicalEqual(desiredMeta, remoteMeta))
|
|
104
|
+
changed.push('metadata');
|
|
105
|
+
}
|
|
106
|
+
return changed;
|
|
107
|
+
}
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Plans
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
function diffPlanFields(desired, remote) {
|
|
112
|
+
const body = {};
|
|
113
|
+
const changedFields = [];
|
|
114
|
+
const previous = {};
|
|
115
|
+
if (desired.name !== remote.name) {
|
|
116
|
+
body.name = desired.name;
|
|
117
|
+
previous.name = remote.name;
|
|
118
|
+
changedFields.push('name');
|
|
119
|
+
}
|
|
120
|
+
if (desired.description !== undefined && desired.description !== remote.description) {
|
|
121
|
+
body.description = desired.description;
|
|
122
|
+
previous.description = remote.description;
|
|
123
|
+
changedFields.push('description');
|
|
124
|
+
}
|
|
125
|
+
if (desired.isVisible !== undefined && desired.isVisible !== remote.isVisible) {
|
|
126
|
+
body.isVisible = desired.isVisible;
|
|
127
|
+
previous.isVisible = remote.isVisible;
|
|
128
|
+
changedFields.push('isVisible');
|
|
129
|
+
}
|
|
130
|
+
if (desired.metadata !== undefined) {
|
|
131
|
+
const desiredMeta = stripMarker(desired.metadata);
|
|
132
|
+
const remoteMeta = stripMarker(remote.metadata);
|
|
133
|
+
if (!canonicalEqual(desiredMeta, remoteMeta)) {
|
|
134
|
+
body.metadata = mergeMarker(desired.metadata);
|
|
135
|
+
// Verbatim remote metadata — NOT re-merged with the marker, unlike
|
|
136
|
+
// `body.metadata` above (see `PlanPatchOp.previous`'s own comment).
|
|
137
|
+
previous.metadata = remote.metadata ?? {};
|
|
138
|
+
changedFields.push('metadata');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { body, changedFields, previous };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Resolves `planDef.product` to what a `PlanCreateRequest.product` body
|
|
145
|
+
* field can hold: a real UUID (found in the current remote product map), a
|
|
146
|
+
* `PendingProductRef` (the product isn't remote yet, but `desired` also
|
|
147
|
+
* creates it this run), or `undefined` (dangling reference — recorded in
|
|
148
|
+
* `errors`, never silently accepted).
|
|
149
|
+
*/
|
|
150
|
+
function resolveProductRef(productIdentifier, productUuidByIdentifier, desiredProductIds, planIdentifier, errors) {
|
|
151
|
+
const uuid = productUuidByIdentifier.get(productIdentifier);
|
|
152
|
+
if (uuid)
|
|
153
|
+
return uuid;
|
|
154
|
+
if (desiredProductIds.has(productIdentifier)) {
|
|
155
|
+
return { pendingProductIdentifier: productIdentifier };
|
|
156
|
+
}
|
|
157
|
+
errors.push(`Plan "${planIdentifier}" references product "${productIdentifier}", which doesn't exist remotely and isn't declared in this config.`);
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
/** Same resolution shape as `resolveProductRef`, for entitlement-add's `feature` (a UUID in the real request). */
|
|
161
|
+
function resolveFeatureRef(featureIdentifier, featureUuidByIdentifier, desiredFeatureIds, planIdentifier, errors) {
|
|
162
|
+
const uuid = featureUuidByIdentifier.get(featureIdentifier);
|
|
163
|
+
if (uuid)
|
|
164
|
+
return uuid;
|
|
165
|
+
if (desiredFeatureIds.has(featureIdentifier)) {
|
|
166
|
+
return { pendingFeatureIdentifier: featureIdentifier };
|
|
167
|
+
}
|
|
168
|
+
errors.push(`Plan "${planIdentifier}" has an entitlement referencing feature "${featureIdentifier}", which doesn't exist remotely and isn't declared in this config.`);
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
/** Everything but `feature` — what `PlanFeaturesCreateRequest`/`PlanFeaturePatchRequest` call `details`. `EntitlementDef` stores these flattened (see to-config.ts's `toEntitlementDefs`), not nested. */
|
|
172
|
+
function entitlementDetails(entitlement) {
|
|
173
|
+
const { feature: _feature, ...details } = entitlement;
|
|
174
|
+
return details;
|
|
175
|
+
}
|
|
176
|
+
/** Converges remote entitlements toward `desiredEntitlements`, keyed by feature identifier (order-insensitive — DESIGN-push.md §3). */
|
|
177
|
+
function diffEntitlements(planIdentifier, desiredEntitlements, remoteEntitlements, featureUuidByIdentifier, desiredFeatureIds, errors) {
|
|
178
|
+
const add = [];
|
|
179
|
+
const update = [];
|
|
180
|
+
const del = [];
|
|
181
|
+
const desiredByFeature = new Map(desiredEntitlements.map((e) => [e.feature, e]));
|
|
182
|
+
const remoteByFeature = new Map(remoteEntitlements.map((e) => [e.feature, e]));
|
|
183
|
+
for (const [featureIdentifier, desiredEntitlement] of desiredByFeature) {
|
|
184
|
+
const remoteEntitlement = remoteByFeature.get(featureIdentifier);
|
|
185
|
+
const details = entitlementDetails(desiredEntitlement);
|
|
186
|
+
if (!remoteEntitlement) {
|
|
187
|
+
const featureRef = resolveFeatureRef(featureIdentifier, featureUuidByIdentifier, desiredFeatureIds, planIdentifier, errors);
|
|
188
|
+
if (featureRef === undefined)
|
|
189
|
+
continue;
|
|
190
|
+
add.push({ kind: 'entitlement-add', planIdentifier, featureIdentifier, feature: featureRef, details });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (!canonicalEqual(details, entitlementDetails(remoteEntitlement))) {
|
|
194
|
+
update.push({
|
|
195
|
+
kind: 'entitlement-update',
|
|
196
|
+
planIdentifier,
|
|
197
|
+
featureIdentifier,
|
|
198
|
+
details,
|
|
199
|
+
previousDetails: entitlementDetails(remoteEntitlement),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const featureIdentifier of remoteByFeature.keys()) {
|
|
204
|
+
if (!desiredByFeature.has(featureIdentifier)) {
|
|
205
|
+
del.push({ kind: 'entitlement-delete', planIdentifier, featureIdentifier });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { add, update, delete: del };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A plan's `prices` array (when the key is present) is authoritative for the
|
|
212
|
+
* *entire* remote price set for that plan (DESIGN-push.md §3) — compared as
|
|
213
|
+
* a canonicalized, filtered multiset. Both sides run through
|
|
214
|
+
* `filterPriceForRequest` (with the same `featureUuidByIdentifier` and
|
|
215
|
+
* `pendingFeatureIdentifiers`) before comparing so a pulled config (which
|
|
216
|
+
* carries server-owned junk verbatim) diffs clean against the very catalog
|
|
217
|
+
* it came from. Returns `undefined` when `desiredPlan.prices` is absent
|
|
218
|
+
* ("don't touch pricing here") or when the filtered sets are already equal.
|
|
219
|
+
*
|
|
220
|
+
* No special-casing is needed for a `PendingFeatureRef` on the desired side:
|
|
221
|
+
* `{ pendingFeatureIdentifier }` and a resolved UUID string canonicalize to
|
|
222
|
+
* different JSON, so a price needing a same-run pending feature always
|
|
223
|
+
* differs from the remote side (which can never itself resolve to a pending
|
|
224
|
+
* ref — a feature that's remote isn't pending) and correctly forces a
|
|
225
|
+
* bulk-replace op.
|
|
226
|
+
*/
|
|
227
|
+
function diffPrices(planIdentifier, desiredPlan, remotePlan, featureUuidByIdentifier, pendingFeatureIdentifiers, warnings, errors) {
|
|
228
|
+
if (desiredPlan.prices === undefined)
|
|
229
|
+
return undefined;
|
|
230
|
+
const desiredFiltered = desiredPlan.prices.map((price) => filterPriceForRequest(price, featureUuidByIdentifier, pendingFeatureIdentifiers));
|
|
231
|
+
const remoteFiltered = (remotePlan?.prices ?? []).map((price) => filterPriceForRequest(price, featureUuidByIdentifier, pendingFeatureIdentifiers));
|
|
232
|
+
for (const result of desiredFiltered) {
|
|
233
|
+
errors.push(...result.errors.map((message) => `Plan "${planIdentifier}" price: ${message}`));
|
|
234
|
+
}
|
|
235
|
+
const desiredBodies = desiredFiltered.map((r) => r.filtered);
|
|
236
|
+
const remoteBodies = remoteFiltered.map((r) => r.filtered);
|
|
237
|
+
if (pricesEqualAsMultiset(desiredBodies, remoteBodies))
|
|
238
|
+
return undefined;
|
|
239
|
+
// Only warn about dropped fields for the side that's actually about to be
|
|
240
|
+
// sent — the remote side's dropped paths just describe pull-side noise
|
|
241
|
+
// already implied by the diff, not something this push run does.
|
|
242
|
+
for (const result of desiredFiltered) {
|
|
243
|
+
warnings.push(...result.dropped.map((path) => `Plan "${planIdentifier}" price: dropped "${path}" (server-owned field, not sent).`));
|
|
244
|
+
}
|
|
245
|
+
return { kind: 'price-bulk-replace', planIdentifier, prices: desiredBodies, remotePriceCount: remoteBodies.length };
|
|
246
|
+
}
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// Main entry point
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
export function buildPushPlan(desired, remote) {
|
|
251
|
+
const warnings = [];
|
|
252
|
+
const errors = [];
|
|
253
|
+
// Forward maps (DESIGN-push.md §2 step 1) — the mirror index over the same
|
|
254
|
+
// fetch `toConfigDefs` inverts (uuid -> identifier). `remote.products`/
|
|
255
|
+
// `remote.features` are already flat API objects (id + identifier as plain
|
|
256
|
+
// fields) — the embedded-object drift to-config.ts resolves only affects
|
|
257
|
+
// `ApiPlan.product`/entitlement `feature` references, not these lists.
|
|
258
|
+
const productUuidByIdentifier = new Map(remote.products.map((p) => [p.identifier, p.id]));
|
|
259
|
+
const featureUuidByIdentifier = new Map(remote.features.map((f) => [f.identifier, f.id]));
|
|
260
|
+
const remoteConfig = toConfigDefs(remote);
|
|
261
|
+
warnings.push(...remoteConfig.warnings);
|
|
262
|
+
const desiredProductIds = new Set(desired.products.map((p) => p.identifier));
|
|
263
|
+
const desiredFeatureIds = new Set(desired.features.map((f) => f.identifier));
|
|
264
|
+
const desiredPlanIds = new Set(desired.plans.map((p) => p.identifier));
|
|
265
|
+
const remoteProductsByIdentifier = new Map(remoteConfig.products.map((p) => [p.identifier, p]));
|
|
266
|
+
const remoteFeaturesByIdentifier = new Map(remoteConfig.features.map((f) => [f.identifier, f]));
|
|
267
|
+
const remotePlansByIdentifier = new Map(remoteConfig.plans.map((p) => [p.identifier, p]));
|
|
268
|
+
// --- Products ---
|
|
269
|
+
const productCreate = [];
|
|
270
|
+
const productPatch = [];
|
|
271
|
+
for (const productDef of desired.products) {
|
|
272
|
+
const existing = remoteProductsByIdentifier.get(productDef.identifier);
|
|
273
|
+
if (!existing) {
|
|
274
|
+
productCreate.push({
|
|
275
|
+
kind: 'product-create',
|
|
276
|
+
identifier: productDef.identifier,
|
|
277
|
+
body: {
|
|
278
|
+
identifier: productDef.identifier,
|
|
279
|
+
name: productDef.name,
|
|
280
|
+
taxCode: productDef.taxCode,
|
|
281
|
+
...(productDef.description !== undefined ? { description: productDef.description } : {}),
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const { body, changedFields, previous } = diffProductFields(productDef, existing);
|
|
287
|
+
if (changedFields.length === 0)
|
|
288
|
+
continue;
|
|
289
|
+
const pk = productUuidByIdentifier.get(productDef.identifier);
|
|
290
|
+
if (!pk) {
|
|
291
|
+
// Unreachable in practice — `existing` and `pk` are both sourced from
|
|
292
|
+
// `remote.products` — kept as a defensive guard, not a real code path.
|
|
293
|
+
errors.push(`Product "${productDef.identifier}" matched remotely by identifier but its UUID couldn't be resolved.`);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
productPatch.push({ kind: 'product-patch', identifier: productDef.identifier, pk, body, previous });
|
|
297
|
+
}
|
|
298
|
+
// --- Features ---
|
|
299
|
+
const featureCreate = [];
|
|
300
|
+
const featureDrift = [];
|
|
301
|
+
for (const featureDef of desired.features) {
|
|
302
|
+
const existing = remoteFeaturesByIdentifier.get(featureDef.identifier);
|
|
303
|
+
if (!existing) {
|
|
304
|
+
featureCreate.push({
|
|
305
|
+
kind: 'feature-create',
|
|
306
|
+
identifier: featureDef.identifier,
|
|
307
|
+
body: {
|
|
308
|
+
identifier: featureDef.identifier,
|
|
309
|
+
name: featureDef.name,
|
|
310
|
+
featureType: featureDef.type,
|
|
311
|
+
...(featureDef.description !== undefined ? { description: featureDef.description } : {}),
|
|
312
|
+
...(featureDef.featureDetails !== undefined ? { featureDetails: featureDef.featureDetails } : {}),
|
|
313
|
+
...(featureDef.meter !== undefined ? { meter: featureDef.meter } : {}),
|
|
314
|
+
metadata: mergeMarker(featureDef.metadata),
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const changedFields = diffFeatureFields(featureDef, existing);
|
|
320
|
+
if (changedFields.length > 0) {
|
|
321
|
+
featureDrift.push({ identifier: featureDef.identifier, fields: changedFields });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// Identifiers of features `desired` creates this run — the same set
|
|
325
|
+
// driving `featureCreate` above. Threaded into price filtering so
|
|
326
|
+
// `chargeCatalogPrice[].feature` referencing one of these resolves to a
|
|
327
|
+
// `PendingFeatureRef` instead of an unresolvable error (see
|
|
328
|
+
// src/sync/price-filter.ts's module comment for why this matters for
|
|
329
|
+
// `promote`, DESIGN-push.md §10).
|
|
330
|
+
const pendingFeatureIdentifiers = new Set(featureCreate.map((op) => op.identifier));
|
|
331
|
+
// --- Plans (+ entitlements + prices, which depend on the product/feature maps above) ---
|
|
332
|
+
const planCreate = [];
|
|
333
|
+
const planPatch = [];
|
|
334
|
+
const entitlementAdd = [];
|
|
335
|
+
const entitlementUpdate = [];
|
|
336
|
+
const entitlementDelete = [];
|
|
337
|
+
const priceBulkReplace = [];
|
|
338
|
+
for (const planDef of desired.plans) {
|
|
339
|
+
const existing = remotePlansByIdentifier.get(planDef.identifier);
|
|
340
|
+
let planIsUsable = true;
|
|
341
|
+
if (!existing) {
|
|
342
|
+
const productRef = resolveProductRef(planDef.product, productUuidByIdentifier, desiredProductIds, planDef.identifier, errors);
|
|
343
|
+
if (productRef === undefined) {
|
|
344
|
+
planIsUsable = false;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
planCreate.push({
|
|
348
|
+
kind: 'plan-create',
|
|
349
|
+
identifier: planDef.identifier,
|
|
350
|
+
body: {
|
|
351
|
+
identifier: planDef.identifier,
|
|
352
|
+
name: planDef.name,
|
|
353
|
+
product: productRef,
|
|
354
|
+
...(planDef.description !== undefined ? { description: planDef.description } : {}),
|
|
355
|
+
...(planDef.isVisible !== undefined ? { isVisible: planDef.isVisible } : {}),
|
|
356
|
+
metadata: mergeMarker(planDef.metadata),
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
const { body, changedFields, previous } = diffPlanFields(planDef, existing);
|
|
363
|
+
if (changedFields.length > 0) {
|
|
364
|
+
planPatch.push({ kind: 'plan-patch', identifier: planDef.identifier, body, previous });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// A plan that couldn't be resolved to a usable create op has nothing to
|
|
368
|
+
// attach entitlements/prices to — the dangling-product error above is
|
|
369
|
+
// already the actionable signal.
|
|
370
|
+
if (!planIsUsable)
|
|
371
|
+
continue;
|
|
372
|
+
const entitlementDiff = diffEntitlements(planDef.identifier, planDef.entitlements ?? [], existing?.entitlements ?? [], featureUuidByIdentifier, desiredFeatureIds, errors);
|
|
373
|
+
entitlementAdd.push(...entitlementDiff.add);
|
|
374
|
+
entitlementUpdate.push(...entitlementDiff.update);
|
|
375
|
+
entitlementDelete.push(...entitlementDiff.delete);
|
|
376
|
+
const priceOp = diffPrices(planDef.identifier, planDef, existing, featureUuidByIdentifier, pendingFeatureIdentifiers, warnings, errors);
|
|
377
|
+
if (priceOp)
|
|
378
|
+
priceBulkReplace.push(priceOp);
|
|
379
|
+
}
|
|
380
|
+
// --- Unmanaged remote (DESIGN-push.md §6) ---
|
|
381
|
+
const unmanagedProducts = remoteConfig.products
|
|
382
|
+
.filter((p) => !desiredProductIds.has(p.identifier))
|
|
383
|
+
.map((p) => ({ identifier: p.identifier }));
|
|
384
|
+
const unmanagedFeatures = remoteConfig.features
|
|
385
|
+
.filter((f) => !desiredFeatureIds.has(f.identifier))
|
|
386
|
+
.map((f) => ({ identifier: f.identifier, managedByMarker: hasManagedByMarker(f.metadata) }));
|
|
387
|
+
const unmanagedPlans = remoteConfig.plans
|
|
388
|
+
.filter((p) => !desiredPlanIds.has(p.identifier))
|
|
389
|
+
.map((p) => ({ identifier: p.identifier, managedByMarker: hasManagedByMarker(p.metadata) }));
|
|
390
|
+
return {
|
|
391
|
+
products: { create: productCreate, patch: productPatch },
|
|
392
|
+
features: { create: featureCreate },
|
|
393
|
+
plans: { create: planCreate, patch: planPatch },
|
|
394
|
+
entitlements: { add: entitlementAdd, update: entitlementUpdate, delete: entitlementDelete },
|
|
395
|
+
prices: { bulkReplace: priceBulkReplace },
|
|
396
|
+
featureDrift,
|
|
397
|
+
unmanagedRemote: { products: unmanagedProducts, features: unmanagedFeatures, plans: unmanagedPlans },
|
|
398
|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,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE;QACpG,QAAQ;QACR,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { KelviqHttpClient } from '../core/http.js';
|
|
2
|
+
import type { FeatureType, PriceType, TaxBehavior, TaxCode } from '../config-format/schema.js';
|
|
3
|
+
export interface ApiProduct {
|
|
4
|
+
id: string;
|
|
5
|
+
identifier: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
taxCode: TaxCode;
|
|
9
|
+
createdBy?: string;
|
|
10
|
+
modifiedOn?: string;
|
|
11
|
+
images?: unknown[];
|
|
12
|
+
}
|
|
13
|
+
export interface ApiFeature {
|
|
14
|
+
id: string;
|
|
15
|
+
identifier: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
featureType: FeatureType;
|
|
19
|
+
featureDetails?: Record<string, unknown>;
|
|
20
|
+
meter?: Record<string, unknown>;
|
|
21
|
+
details?: Record<string, unknown>;
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
isArchived?: boolean;
|
|
24
|
+
modifiedOn?: string;
|
|
25
|
+
}
|
|
26
|
+
/** The `feature` field embedded in a PlanFeatureEntitlement — a (possibly
|
|
27
|
+
* partial) CatalogFeature object, not a bare UUID. */
|
|
28
|
+
export interface ApiEmbeddedFeature {
|
|
29
|
+
id?: string;
|
|
30
|
+
identifier?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Live-observed drift (2026-07-10): GET /catalog/plans/ results[].product is
|
|
35
|
+
* a FULL EMBEDDED PRODUCT OBJECT in production — keys observed include id,
|
|
36
|
+
* identifier, name, description, instanceType, createdBy, modifiedOn,
|
|
37
|
+
* billingMethod, images, taxCode, files — not the bare product UUID string
|
|
38
|
+
* src/generated/openapi.json documents. Mirrors ApiEmbeddedFeature's shape
|
|
39
|
+
* (possibly-partial object with id/identifier) so ./to-config.ts can resolve
|
|
40
|
+
* either shape the same way features already are.
|
|
41
|
+
*/
|
|
42
|
+
export interface ApiEmbeddedProduct {
|
|
43
|
+
id?: string;
|
|
44
|
+
identifier?: string;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface ApiPlanLink {
|
|
48
|
+
name: string;
|
|
49
|
+
url: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ApiPlan {
|
|
52
|
+
identifier: string;
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
/** Parent product: a bare UUID string per spec, or a full embedded
|
|
56
|
+
* product object in practice — see ApiEmbeddedProduct. Plan responses
|
|
57
|
+
* also carry an undocumented `basePlan` key, ignored here since fields
|
|
58
|
+
* are mapped explicitly rather than passed through. */
|
|
59
|
+
product: string | ApiEmbeddedProduct;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
version?: number;
|
|
62
|
+
isLatest?: boolean;
|
|
63
|
+
modifiedOn?: string;
|
|
64
|
+
createdOn?: string;
|
|
65
|
+
details?: Record<string, unknown>;
|
|
66
|
+
isVisible?: boolean;
|
|
67
|
+
isImported?: boolean;
|
|
68
|
+
countries?: string[];
|
|
69
|
+
license?: Record<string, unknown> | null;
|
|
70
|
+
links?: ApiPlanLink[];
|
|
71
|
+
files?: unknown[];
|
|
72
|
+
ordering?: number | null;
|
|
73
|
+
}
|
|
74
|
+
export interface ApiPlanPrice {
|
|
75
|
+
id: string;
|
|
76
|
+
priceType: PriceType;
|
|
77
|
+
currency?: string;
|
|
78
|
+
freeTrial?: boolean;
|
|
79
|
+
trialPeriod?: number;
|
|
80
|
+
enabled?: boolean;
|
|
81
|
+
taxBehavior?: TaxBehavior;
|
|
82
|
+
chargeCatalogPrice?: Array<Record<string, unknown>>;
|
|
83
|
+
}
|
|
84
|
+
export interface ApiPlanFeatureEntitlement {
|
|
85
|
+
feature: ApiEmbeddedFeature;
|
|
86
|
+
details?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
export interface RawCatalog {
|
|
89
|
+
products: ApiProduct[];
|
|
90
|
+
features: ApiFeature[];
|
|
91
|
+
plans: ApiPlan[];
|
|
92
|
+
/** Keyed by plan identifier. */
|
|
93
|
+
planPrices: Record<string, ApiPlanPrice[]>;
|
|
94
|
+
/** Keyed by plan identifier. */
|
|
95
|
+
planEntitlements: Record<string, ApiPlanFeatureEntitlement[]>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Fetches the full remote catalog: all products, all features, all plans
|
|
99
|
+
* (every version — dedupe to the latest is ./to-config.ts's job), then for
|
|
100
|
+
* each distinct plan identifier its prices and entitlements.
|
|
101
|
+
*
|
|
102
|
+
* // TODO: parallelize the per-plan fetch loop below — sequential is fine for
|
|
103
|
+
* v0's expected catalog sizes.
|
|
104
|
+
*/
|
|
105
|
+
export declare function fetchCatalog(http: KelviqHttpClient): Promise<RawCatalog>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Safety cap on pagination follow-throughs — guards against a malformed API
|
|
2
|
+
* response whose `next` never resolves to null from looping forever. */
|
|
3
|
+
const MAX_PAGES = 1000;
|
|
4
|
+
function isPaginatedEnvelope(data) {
|
|
5
|
+
return typeof data === 'object' && data !== null && Array.isArray(data.results);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* GETs `path` and follows `next` (the full pagination envelope's absolute
|
|
9
|
+
* URL) until it's null, accumulating results across every page. `next`'s
|
|
10
|
+
* query string (which carries the page number and any original filters
|
|
11
|
+
* forward) is re-applied to `path` on each hop rather than parsing `next`'s
|
|
12
|
+
* host/pathname — this works regardless of what host the API reports `next`
|
|
13
|
+
* on, and keeps the http client's own host selection (`base` vs `edge`) in
|
|
14
|
+
* control throughout.
|
|
15
|
+
*
|
|
16
|
+
* Response shape is classified per-request rather than assumed, because not
|
|
17
|
+
* every endpoint actually matches the spec's documented envelope (see the
|
|
18
|
+
* module comment above) — a bare array and the `{ results, next, ... }`
|
|
19
|
+
* envelope are both accepted; anything else is a clean error, never a raw
|
|
20
|
+
* TypeError from indexing a shape that isn't there.
|
|
21
|
+
*/
|
|
22
|
+
async function fetchAllPages(http, opts) {
|
|
23
|
+
const results = [];
|
|
24
|
+
let query = opts.query;
|
|
25
|
+
let nextUrl;
|
|
26
|
+
let page = 0;
|
|
27
|
+
do {
|
|
28
|
+
page += 1;
|
|
29
|
+
if (page > MAX_PAGES) {
|
|
30
|
+
throw new Error(`Failed to fetch ${opts.label}: exceeded ${MAX_PAGES} pages while following pagination.`);
|
|
31
|
+
}
|
|
32
|
+
const result = await http.request({
|
|
33
|
+
method: 'GET',
|
|
34
|
+
path: opts.path,
|
|
35
|
+
query,
|
|
36
|
+
auth: 'server',
|
|
37
|
+
});
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
throw new Error(`Failed to fetch ${opts.label}: ${result.error.message} (${result.error.status})`);
|
|
40
|
+
}
|
|
41
|
+
const data = result.data;
|
|
42
|
+
if (Array.isArray(data)) {
|
|
43
|
+
// Live-observed drift (2026-07-10): GET /catalog/plans/{identifier}/features/
|
|
44
|
+
// returns a bare JSON array in production (`[]` when empty), not the
|
|
45
|
+
// PaginatedPlanFeatureEntitlements envelope src/generated/openapi.json
|
|
46
|
+
// documents. A bare array is a single, complete page — there's no
|
|
47
|
+
// `next` to follow. This branch stays alongside the envelope branch
|
|
48
|
+
// below (rather than replacing it) so a future spec/reality
|
|
49
|
+
// reconciliation on either side keeps working.
|
|
50
|
+
results.push(...data);
|
|
51
|
+
nextUrl = null;
|
|
52
|
+
}
|
|
53
|
+
else if (isPaginatedEnvelope(data)) {
|
|
54
|
+
results.push(...data.results);
|
|
55
|
+
nextUrl = data.next;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error(`Failed to fetch ${opts.label}: unexpected response shape (expected a list or a paginated envelope).`);
|
|
59
|
+
}
|
|
60
|
+
if (nextUrl) {
|
|
61
|
+
query = Object.fromEntries(new URL(nextUrl).searchParams.entries());
|
|
62
|
+
}
|
|
63
|
+
} while (nextUrl);
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Fetches the full remote catalog: all products, all features, all plans
|
|
68
|
+
* (every version — dedupe to the latest is ./to-config.ts's job), then for
|
|
69
|
+
* each distinct plan identifier its prices and entitlements.
|
|
70
|
+
*
|
|
71
|
+
* // TODO: parallelize the per-plan fetch loop below — sequential is fine for
|
|
72
|
+
* v0's expected catalog sizes.
|
|
73
|
+
*/
|
|
74
|
+
export async function fetchCatalog(http) {
|
|
75
|
+
const products = await fetchAllPages(http, { path: '/catalog/products/', label: 'products' });
|
|
76
|
+
const features = await fetchAllPages(http, { path: '/catalog/features/', label: 'features' });
|
|
77
|
+
const plans = await fetchAllPages(http, { path: '/catalog/plans/', label: 'plans' });
|
|
78
|
+
const planPrices = {};
|
|
79
|
+
const planEntitlements = {};
|
|
80
|
+
// Prices/entitlements are addressed by plan *identifier*, so multiple
|
|
81
|
+
// versions of the same plan (see isLatest dedupe in ./to-config.ts) would
|
|
82
|
+
// hit the exact same sub-resource URL — fetch each identifier once.
|
|
83
|
+
const fetchedIdentifiers = new Set();
|
|
84
|
+
for (const p of plans) {
|
|
85
|
+
if (fetchedIdentifiers.has(p.identifier))
|
|
86
|
+
continue;
|
|
87
|
+
fetchedIdentifiers.add(p.identifier);
|
|
88
|
+
const encodedIdentifier = encodeURIComponent(p.identifier);
|
|
89
|
+
planPrices[p.identifier] = await fetchAllPages(http, {
|
|
90
|
+
path: `/catalog/plans/${encodedIdentifier}/prices/`,
|
|
91
|
+
label: `prices for plan "${p.identifier}"`,
|
|
92
|
+
});
|
|
93
|
+
planEntitlements[p.identifier] = await fetchAllPages(http, {
|
|
94
|
+
path: `/catalog/plans/${encodedIdentifier}/features/`,
|
|
95
|
+
label: `entitlements for plan "${p.identifier}"`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return { products, features, plans, planPrices, planEntitlements };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=fetch-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-catalog.js","sourceRoot":"","sources":["../../src/sync/fetch-catalog.ts"],"names":[],"mappings":"AAoBA;wEACwE;AACxE,MAAM,SAAS,GAAG,IAAI,CAAC;AAgHvB,SAAS,mBAAmB,CAAI,IAAa;IAC3C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAA8B,CAAC,OAAO,CAAC,CAAC;AAC7G,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,aAAa,CAC1B,IAAsB,EACtB,IAIC;IAED,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACvB,IAAI,OAAsB,CAAC;IAC3B,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,GAAG,CAAC;QACF,IAAI,IAAI,CAAC,CAAC;QACV,IAAI,IAAI,GAAG,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,KAAK,cAAc,SAAS,oCAAoC,CAAC,CAAC;QAC5G,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAA6B;YAC5D,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK;YACL,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACrG,CAAC;QAED,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