@revoengine/cli 1.0.15 → 1.0.17

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 (51) hide show
  1. package/README.md +70 -12
  2. package/dist/src/cli.js +6 -2
  3. package/dist/src/client.d.ts +29 -3
  4. package/dist/src/client.js +92 -2
  5. package/dist/src/commands/component.js +2 -4
  6. package/dist/src/commands/index.d.ts +1 -0
  7. package/dist/src/commands/index.js +1 -0
  8. package/dist/src/commands/migrate.js +83 -20
  9. package/dist/src/commands/service-accounts.d.ts +2 -0
  10. package/dist/src/commands/service-accounts.js +149 -0
  11. package/dist/src/commands/terminal-browser.d.ts +29 -2
  12. package/dist/src/commands/terminal-browser.js +144 -35
  13. package/dist/src/commands/terminal-file.d.ts +21 -0
  14. package/dist/src/commands/terminal-file.js +160 -0
  15. package/dist/src/commands/terminal-operational-log.js +2 -2
  16. package/dist/src/commands/terminal-policy.d.ts +5 -2
  17. package/dist/src/commands/terminal-policy.js +10 -4
  18. package/dist/src/commands/terminal-reconnect-grace.js +1 -1
  19. package/dist/src/commands/terminal-sandbox.js +7 -0
  20. package/dist/src/commands/terminal-secure-browser.d.ts +1 -0
  21. package/dist/src/commands/terminal-secure-browser.js +2 -1
  22. package/dist/src/commands/terminal-service.js +4 -4
  23. package/dist/src/commands/terminal.d.ts +12 -0
  24. package/dist/src/commands/terminal.js +134 -45
  25. package/dist/src/component-lock.d.ts +4 -0
  26. package/dist/src/component-lock.js +21 -2
  27. package/dist/src/metadata-backfill.js +50 -1
  28. package/dist/src/migration.d.ts +20 -5
  29. package/dist/src/migration.js +200 -75
  30. package/dist/src/resource-inventory.d.ts +3 -2
  31. package/dist/src/resource-inventory.js +6 -1
  32. package/dist/src/resource-syncs/account-principal.d.ts +22 -0
  33. package/dist/src/resource-syncs/account-principal.js +86 -0
  34. package/dist/src/resource-syncs/group-sync.d.ts +10 -0
  35. package/dist/src/resource-syncs/group-sync.js +92 -20
  36. package/dist/src/resource-syncs/identity-migration.d.ts +19 -0
  37. package/dist/src/resource-syncs/identity-migration.js +108 -0
  38. package/dist/src/resource-syncs/job-template-sync.d.ts +4 -0
  39. package/dist/src/resource-syncs/job-template-sync.js +55 -12
  40. package/dist/src/resource-syncs/service-account-sync.d.ts +98 -0
  41. package/dist/src/resource-syncs/service-account-sync.js +620 -0
  42. package/dist/src/sync-output.js +10 -5
  43. package/dist/src/tracked-resources.d.ts +1 -1
  44. package/dist/src/tracked-resources.js +5 -1
  45. package/dist/src/types.d.ts +12 -0
  46. package/dist/src/ui.js +6 -3
  47. package/dist/src/workspace-diff.d.ts +1 -0
  48. package/dist/src/workspace-diff.js +4 -1
  49. package/dist/src/workspace-prune.d.ts +40 -0
  50. package/dist/src/workspace-prune.js +363 -0
  51. package/package.json +2 -2
@@ -1,6 +1,10 @@
1
1
  export const TRACK_ALL_RESOURCES = 'all';
2
- export const TRACKABLE_RESOURCE_TYPES = ['component', 'endpoint', 'group', 'role-group', 'job-template', 'schedule', 'event', 'database-table', 'database-view'];
2
+ export const TRACKABLE_RESOURCE_TYPES = ['component', 'endpoint', 'group', 'role-group', 'job-template', 'schedule', 'event', 'database-table', 'database-view', 'service-account'];
3
3
  const RESOURCE_ALIASES = {
4
+ 'service-account': 'service-account',
5
+ 'service-accounts': 'service-account',
6
+ serviceaccount: 'service-account',
7
+ serviceaccounts: 'service-account',
4
8
  all: TRACK_ALL_RESOURCES,
5
9
  '*': TRACK_ALL_RESOURCES,
6
10
  component: 'component',
@@ -159,6 +159,18 @@ export type EndpointRecord = {
159
159
  deletedBy?: string | null;
160
160
  [key: string]: unknown;
161
161
  };
162
+ export type ServiceAccountRecord = {
163
+ category?: string | null;
164
+ userId?: string;
165
+ name?: string;
166
+ serviceAccount?: boolean;
167
+ ownerId?: string;
168
+ ownerType?: string;
169
+ version?: number;
170
+ deletedAt?: string | null;
171
+ metadata?: Record<string, unknown>;
172
+ [key: string]: unknown;
173
+ };
162
174
  export type RoleGroupRecord = {
163
175
  roleGroupId?: string;
164
176
  id?: string;
package/dist/src/ui.js CHANGED
@@ -147,6 +147,9 @@ function renderCommandCatalog() {
147
147
  commandRow('revo endpoints push --all [--project <name>] [--yes] [--force]', 'Deploy and verify managed endpoints'),
148
148
  '',
149
149
  paintHeader('Access'),
150
+ commandRow('revo service-accounts pull --all [--project <name>] [--force]', 'Pull portable service-account definitions'),
151
+ commandRow('revo service-accounts plan --all [--project <name>] [--json] [--strict]', 'Plan accounts, owners and manual credential setup'),
152
+ commandRow('revo service-accounts push --all [--project <name>] [--yes] [--force]', 'Push service accounts; secrets remain target-local'),
150
153
  commandRow('revo role-groups pull --all [--project <name>] [--force]', 'Pull managed role groups into the configured workspace'),
151
154
  commandRow('revo role-groups plan --all [--project <name>] [--json] [--strict]', 'Preview workspace, lock, and live target state'),
152
155
  commandRow('revo role-groups push --all [--project <name>] [--yes] [--force]', 'Push role groups with live stable-key and lock checks'),
@@ -172,9 +175,9 @@ function renderCommandCatalog() {
172
175
  commandRow('revo metadata apply [--project <name>] --yes [--skip-partitions]', 'Populate missing stable-key metadata'),
173
176
  commandRow('revo pull --all|--resources <list> --yes [--skip-groups] [--force] [--json]', 'Build the repository workspace from the configured runtime source'),
174
177
  commandRow('revo diff [--json]', 'Show only workspace-to-target resource differences without writes'),
175
- commandRow('revo plan [--force] [--strict] [--json] [--hints]', 'Plan deployment of tracked workspace resources to the configured runtime target without writes'),
176
- commandRow('revo deploy --yes [--force] [--json]', 'Deploy tracked workspace resources to the configured runtime target in dependency order'),
177
- commandRow('revo migrate plan --from <env> --to <env> [--resources <list>] [--skip-groups] [--force] [--json] [--hints]', 'Preview nine phases through Groups and Role Groups'),
178
+ commandRow('revo plan [--prune] [--out file] [--force] [--strict] [--json] [--hints]', 'Plan tracked workspace upserts and optional Stable Key deletions without writes'),
179
+ commandRow('revo deploy [--yes] [--prune] [--reviewed-plan file] [--force] [--json]', 'Review, confirm, deploy and prune tracked resources in dependency order'),
180
+ commandRow('revo migrate plan --from <env> --to <env> [--resources <list>] [--skip-groups] [--force] [--json] [--hints]', 'Preview ten resource families and identity dependencies'),
178
181
  commandRow('revo migrate run --from <env> --to <env> [--resources <list>] [--skip-groups] --yes [--force] [--json]', 'Pull, plan, migrate, and verify resources in dependency order'),
179
182
  commandRow('revo migrate verify --from <env> --to <env> [--resources <list>] [--json]', 'Verify target resources against a fresh temporary source pull'),
180
183
  commandRow('revo search <CODE|SIMPLE> <term>', 'Search code references or all platform content'),
@@ -21,5 +21,6 @@ export type WorkspaceDiff = {
21
21
  from: 'workspace';
22
22
  to: string;
23
23
  changes: WorkspaceDiffChange[];
24
+ notices?: string[];
24
25
  };
25
26
  export declare function buildWorkspaceDiff(plan: MigrationPlan): WorkspaceDiff;
@@ -9,6 +9,7 @@ function resourceItems(plan, resource) {
9
9
  case 'schedule': return plan.schedules?.items || [];
10
10
  case 'event': return plan.events?.items || [];
11
11
  case 'group': return plan.groups?.items || [];
12
+ case 'service-account': return plan.serviceAccounts?.items || [];
12
13
  case 'role-group': return plan.roleGroups?.items || [];
13
14
  }
14
15
  }
@@ -71,5 +72,7 @@ export function buildWorkspaceDiff(plan) {
71
72
  });
72
73
  }
73
74
  }
74
- return { schemaVersion: 1, command: 'diff', from: 'workspace', to: plan.to, changes };
75
+ const notices = (plan.warnings || []).filter((warning) => /^(Service account|Source Service Account)/i.test(warning));
76
+ return { schemaVersion: 1, command: 'diff', from: 'workspace', to: plan.to, changes,
77
+ ...(notices.length ? { notices } : {}) };
75
78
  }
@@ -0,0 +1,40 @@
1
+ import type { RevoClient } from './client.ts';
2
+ import { type ResourceRecord } from './resource-inventory.ts';
3
+ import type { WorkspaceSyncResult } from './sync-output.ts';
4
+ import type { TrackableResourceType } from './tracked-resources.ts';
5
+ export type WorkspacePruneItem = {
6
+ resource: TrackableResourceType;
7
+ stableKey: string;
8
+ targetId: string;
9
+ name: string;
10
+ version: number | null;
11
+ targetHash: string;
12
+ };
13
+ export type WorkspacePrunePlan = {
14
+ items: WorkspacePruneItem[];
15
+ blockers: string[];
16
+ };
17
+ type Inventory = Partial<Record<TrackableResourceType, ResourceRecord[]>>;
18
+ type LocalManifests = Partial<Record<TrackableResourceType, Map<string, Record<string, unknown>>>>;
19
+ export declare function readPruneManifests(cwd: string, resources: readonly TrackableResourceType[]): LocalManifests;
20
+ export declare function planWorkspacePrune(input: {
21
+ resources: readonly TrackableResourceType[];
22
+ inventory: Inventory;
23
+ local: LocalManifests;
24
+ stableKeyName: string;
25
+ actorId?: string;
26
+ }): WorkspacePrunePlan;
27
+ export declare function buildWorkspacePrunePlan(input: {
28
+ cwd: string;
29
+ client: RevoClient;
30
+ resources: readonly TrackableResourceType[];
31
+ }): Promise<WorkspacePrunePlan>;
32
+ export declare function samePrunePlan(left: WorkspacePrunePlan, right: WorkspacePrunePlan): boolean;
33
+ export declare function applyWorkspacePrune(input: {
34
+ cwd: string;
35
+ client: RevoClient;
36
+ resources: readonly TrackableResourceType[];
37
+ envName: string;
38
+ plan: WorkspacePrunePlan;
39
+ }): Promise<WorkspaceSyncResult[]>;
40
+ export {};
@@ -0,0 +1,363 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { hashStable, readComponentLock, removeComponentLockBaseline, writeComponentLock } from "./component-lock.js";
4
+ import { readProjectStableKeyName } from "./project.js";
5
+ import { readResourceInventory, resourceIdOf } from "./resource-inventory.js";
6
+ import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey } from "./resource-metadata.js";
7
+ import { findManifestFiles, isRecord, requireProjectLayout } from "./resource-syncs/util.js";
8
+ const manifests = {
9
+ component: ['Components', 'component.json'],
10
+ 'job-template': ['JobTemplates', 'job-template.json'],
11
+ endpoint: ['Endpoints', 'endpoint.json'],
12
+ schedule: ['Schedules', 'schedule.json'],
13
+ event: ['Events', 'event.json'],
14
+ 'database-table': ['DatabaseTables', 'database-table.json'],
15
+ 'database-view': ['DatabaseViews', 'database-view.json'],
16
+ group: ['Groups', 'group.json'],
17
+ 'role-group': ['RoleGroups', 'role-group.json'],
18
+ 'service-account': ['ServiceAccounts', 'service-account.json'],
19
+ };
20
+ const deletionOrder = [
21
+ 'event', 'schedule', 'endpoint', 'job-template', 'component',
22
+ 'database-view', 'database-table', 'role-group', 'service-account', 'group',
23
+ ];
24
+ function key(resource, identity) {
25
+ return `${resource}:${normalizeStableKeyValue(identity)}`;
26
+ }
27
+ function active(record) {
28
+ return !record.deletedAt && !record.deletedBy;
29
+ }
30
+ export function readPruneManifests(cwd, resources) {
31
+ const { workspaceRoot } = requireProjectLayout(cwd, 'Workspace prune');
32
+ const stableKeyName = readProjectStableKeyName(cwd);
33
+ const result = {};
34
+ for (const resource of resources) {
35
+ const [directory, file] = manifests[resource];
36
+ const files = findManifestFiles(path.join(workspaceRoot, directory), file);
37
+ if (resource === 'database-table') {
38
+ files.push(...findManifestFiles(path.join(workspaceRoot, 'DatabaseSchemas'), 'database-schema.json'));
39
+ }
40
+ const entries = new Map();
41
+ for (const filename of files) {
42
+ const manifest = JSON.parse(fs.readFileSync(filename, 'utf8'));
43
+ if (!isRecord(manifest))
44
+ throw new Error(`Invalid prune manifest: ${filename}.`);
45
+ const stableKey = resource === 'component'
46
+ ? readConfiguredResourceMetadataStableKey(manifest, stableKeyName)
47
+ : typeof manifest.stableKey === 'string' ? manifest.stableKey : null;
48
+ if (!stableKey)
49
+ continue;
50
+ const identity = normalizeStableKeyValue(stableKey);
51
+ if (!identity)
52
+ throw new Error(`Empty Stable Key in ${filename}.`);
53
+ if (entries.has(identity))
54
+ throw new Error(`Duplicate local ${resource} Stable Key "${stableKey}"; prune blocked.`);
55
+ entries.set(identity, manifest);
56
+ }
57
+ result[resource] = entries;
58
+ }
59
+ return result;
60
+ }
61
+ function localReferences(resource, manifest) {
62
+ const refs = [];
63
+ const add = (family, value) => {
64
+ if (typeof value === 'string' && value)
65
+ refs.push({ resource: family, identity: value });
66
+ };
67
+ if (resource === 'job-template' && isRecord(manifest.component))
68
+ add('component', manifest.component.stableKey);
69
+ if (resource === 'endpoint') {
70
+ for (const binding of [manifest.execution, manifest.schema]) {
71
+ if (isRecord(binding))
72
+ add('component', binding.stableKey);
73
+ }
74
+ }
75
+ if ((resource === 'event' || resource === 'schedule') && isRecord(manifest.target)) {
76
+ add('job-template', manifest.target.jobTemplateStableKey);
77
+ add('database-view', manifest.target.databaseViewStableKey);
78
+ }
79
+ if (resource === 'database-view' && Array.isArray(manifest.sources)) {
80
+ for (const source of manifest.sources)
81
+ if (isRecord(source))
82
+ add('database-table', source.databaseStableKey);
83
+ }
84
+ if (resource === 'database-table')
85
+ add('database-table', manifest.parentStableKey);
86
+ if (isRecord(manifest.owner)) {
87
+ if (manifest.owner.type === 'group')
88
+ add('group', manifest.owner.stableKey);
89
+ if (manifest.owner.type === 'service-account')
90
+ add('service-account', manifest.owner.stableKey);
91
+ }
92
+ if (isRecord(manifest.executionPrincipal))
93
+ add('service-account', manifest.executionPrincipal.stableKey);
94
+ return refs;
95
+ }
96
+ function remoteReferences(resource, record, tables) {
97
+ const refs = [];
98
+ const add = (family, value) => {
99
+ if (typeof value === 'string' && value)
100
+ refs.push({ resource: family, identity: value });
101
+ };
102
+ if (resource === 'job-template' || resource === 'endpoint')
103
+ add('component', record.componentId);
104
+ if (resource === 'endpoint' && isRecord(record.options))
105
+ add('component', record.options.componentSchemaId);
106
+ if (resource === 'job-template')
107
+ add('service-account', record.triggerUser);
108
+ if (resource === 'schedule' || resource === 'event') {
109
+ add(record.targetType === 'JOB_TEMPLATE' ? 'job-template' : 'database-view', record.targetId);
110
+ }
111
+ if (resource === 'database-view' && Array.isArray(record.sourceDatabaseIds)) {
112
+ for (const id of record.sourceDatabaseIds)
113
+ add('database-table', id);
114
+ }
115
+ if (resource === 'database-table') {
116
+ add('database-table', record.parentDatabaseId || record.parentId);
117
+ if (isRecord(record.parent))
118
+ add('database-table', record.parent.databaseId || record.parent.id);
119
+ const name = typeof record.parent === 'string' ? record.parent : isRecord(record.parent) ? record.parent.name : undefined;
120
+ if (typeof name === 'string') {
121
+ // The API can return a partition parent by physical name rather than ID.
122
+ // Include every matching parent; ambiguity must not hide a dependency.
123
+ for (const table of tables)
124
+ if (table.name === name)
125
+ add('database-table', resourceIdOf(table));
126
+ }
127
+ }
128
+ if (record.ownerType === 'GROUP')
129
+ add('group', record.ownerId);
130
+ if (record.ownerType === 'USER')
131
+ add('service-account', record.ownerId);
132
+ return refs;
133
+ }
134
+ function resourceHash(record) {
135
+ // Definition/version changes fence deletion. Audit timestamps, counts and activity
136
+ // can change while upserts run without changing the definition being reviewed.
137
+ const { lastUpdateAt, lastUpdateBy, createdAt, createdBy, memberCount, ...definition } = record;
138
+ return hashStable(definition);
139
+ }
140
+ export function planWorkspacePrune(input) {
141
+ const blockers = [];
142
+ const candidates = new Map();
143
+ const byId = new Map();
144
+ for (const [family, records] of Object.entries(input.inventory)) {
145
+ const resource = family;
146
+ const keys = new Set();
147
+ for (const record of records || []) {
148
+ if (!active(record))
149
+ continue;
150
+ const id = resourceIdOf(record);
151
+ if (!id)
152
+ throw new Error(`Invalid ${resource} inventory: missing target ID.`);
153
+ if (byId.has(key(resource, id)))
154
+ throw new Error(`Repeated ${resource} target ID "${id}".`);
155
+ const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
156
+ byId.set(key(resource, id), { resource, record, stableKey });
157
+ if (!stableKey)
158
+ continue;
159
+ const identity = normalizeStableKeyValue(stableKey);
160
+ if (keys.has(identity))
161
+ blockers.push(`Duplicate target ${resource} Stable Key "${stableKey}"; prune blocked.`);
162
+ keys.add(identity);
163
+ if (!input.resources.includes(resource) || input.local[resource]?.has(identity))
164
+ continue;
165
+ if (resource === 'service-account' && (record.serviceAccount !== true || id === input.actorId)) {
166
+ blockers.push(`Cannot prune the authenticated account or a human account "${stableKey}".`);
167
+ }
168
+ if (resource === 'service-account' && !input.actorId)
169
+ blockers.push('Cannot determine authenticated account identity; service-account prune blocked.');
170
+ if (record.systemManaged === true || record.system === true) {
171
+ blockers.push(`Cannot prune system-managed ${resource} "${stableKey}".`);
172
+ }
173
+ if (resource === 'component' && [...(input.local.component?.values() || [])].some((manifest) => manifest.componentId === id || manifest.id === id)) {
174
+ blockers.push(`Local component still has target ID "${id}"; prune blocked.`);
175
+ }
176
+ candidates.set(key(resource, id), {
177
+ resource, stableKey, targetId: id, name: String(record.name || stableKey),
178
+ version: typeof record.version === 'number' ? record.version : null,
179
+ targetHash: resourceHash(record),
180
+ });
181
+ }
182
+ }
183
+ const removedKeys = new Set([...candidates.values()].map((item) => key(item.resource, item.stableKey)));
184
+ for (const [family, entries] of Object.entries(input.local)) {
185
+ for (const [identity, manifest] of entries || []) {
186
+ for (const reference of localReferences(family, manifest)) {
187
+ if (removedKeys.has(key(reference.resource, reference.identity))) {
188
+ blockers.push(`Retained ${family} "${identity}" references ${reference.resource} "${reference.identity}" planned for deletion.`);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ const dependencies = new Map();
194
+ for (const [idKey, target] of byId) {
195
+ for (const reference of remoteReferences(target.resource, target.record, input.inventory['database-table'] || [])) {
196
+ const referenced = key(reference.resource, reference.identity);
197
+ if (!candidates.has(referenced))
198
+ continue;
199
+ if (candidates.has(idKey)) {
200
+ const dependents = dependencies.get(referenced) || new Set();
201
+ dependents.add(idKey);
202
+ dependencies.set(referenced, dependents);
203
+ }
204
+ else {
205
+ const desired = target.stableKey ? input.local[target.resource]?.get(normalizeStableKeyValue(target.stableKey)) : undefined;
206
+ const removed = candidates.get(referenced);
207
+ // A managed retained consumer can release the old reference during upsert.
208
+ // An unmanaged or out-of-scope consumer must never be removed implicitly.
209
+ const preservesReference = desired && (((target.resource === 'group' || target.resource === 'service-account') && !isRecord(desired.owner))
210
+ || (target.resource === 'job-template' && removed.resource === 'service-account' && !isRecord(desired.executionPrincipal)));
211
+ if (!desired || preservesReference || localReferences(target.resource, desired).some((ref) => key(ref.resource, ref.identity) === key(removed.resource, removed.stableKey))) {
212
+ blockers.push(`${removed.resource} "${removed.stableKey}" is still referenced by retained ${target.resource} "${target.stableKey || resourceIdOf(target.record)}".`);
213
+ }
214
+ }
215
+ }
216
+ }
217
+ const items = [];
218
+ const remaining = new Map(candidates);
219
+ while (remaining.size) {
220
+ const next = [...remaining.entries()]
221
+ .filter(([idKey]) => ![...(dependencies.get(idKey) || [])].some((dependent) => remaining.has(dependent)))
222
+ .sort(([, left], [, right]) => deletionOrder.indexOf(left.resource) - deletionOrder.indexOf(right.resource)
223
+ || left.stableKey.localeCompare(right.stableKey))[0];
224
+ if (!next) {
225
+ blockers.push('Deletion dependency cycle; prune blocked.');
226
+ break;
227
+ }
228
+ items.push(next[1]);
229
+ remaining.delete(next[0]);
230
+ }
231
+ return { items, blockers: [...new Set(blockers)].sort() };
232
+ }
233
+ export async function buildWorkspacePrunePlan(input) {
234
+ const resources = new Set(input.resources);
235
+ // Include unmanaged and out-of-scope consumers in dependency checks.
236
+ if (resources.has('component')) {
237
+ resources.add('job-template');
238
+ resources.add('endpoint');
239
+ }
240
+ if (resources.has('job-template')) {
241
+ resources.add('event');
242
+ resources.add('schedule');
243
+ }
244
+ if (resources.has('database-table')) {
245
+ resources.add('database-view');
246
+ }
247
+ if (resources.has('database-view')) {
248
+ resources.add('event');
249
+ resources.add('schedule');
250
+ }
251
+ if (resources.has('group') || resources.has('service-account')) {
252
+ resources.add('group');
253
+ resources.add('service-account');
254
+ resources.add('job-template');
255
+ }
256
+ const local = readPruneManifests(input.cwd, input.resources);
257
+ const inventory = {};
258
+ for (const resource of resources) {
259
+ const records = [];
260
+ if (resource === 'service-account') {
261
+ // Human owners also block Group/Account deletion. Keep the client sanitization
262
+ // and sensitive-account trace redaction; never inventory credentials.
263
+ const { serviceAccounts } = await input.client.listAllServiceAccounts({ includeHumans: true });
264
+ for (const account of serviceAccounts) {
265
+ const id = resourceIdOf(account);
266
+ const detail = await input.client.getAccount(id);
267
+ if (!id || resourceIdOf(detail) !== id)
268
+ throw new Error('Incomplete account ownership inventory; prune blocked.');
269
+ records.push(detail);
270
+ }
271
+ inventory[resource] = records;
272
+ continue;
273
+ }
274
+ for await (const entry of readResourceInventory(input.client, resource)) {
275
+ if (!entry.resource || resourceIdOf(entry.resource) !== entry.listedId)
276
+ throw new Error(`Incomplete ${resource} inventory; prune blocked.`);
277
+ records.push(entry.resource);
278
+ }
279
+ inventory[resource] = records;
280
+ }
281
+ const me = resources.has('service-account') ? await input.client.me() : undefined;
282
+ const profile = isRecord(me) && isRecord(me.data) ? me.data : me;
283
+ const actorId = isRecord(profile) && isRecord(profile.user) ? String(profile.user.userId || '')
284
+ : isRecord(profile) ? String(profile.userId || '') : undefined;
285
+ return planWorkspacePrune({ resources: input.resources, local, inventory, stableKeyName: readProjectStableKeyName(input.cwd), actorId });
286
+ }
287
+ export function samePrunePlan(left, right) {
288
+ return hashStable(left) === hashStable(right);
289
+ }
290
+ function clearPruneBaseline(cwd, envName, item) {
291
+ const { projectRoot } = requireProjectLayout(cwd, 'Workspace prune');
292
+ const lock = readComponentLock(projectRoot);
293
+ if (item.resource === 'component') {
294
+ const identity = { mode: 'stableKey', metadataProperty: readProjectStableKeyName(cwd) };
295
+ const match = Object.entries(lock.components).find(([entryKey, value]) => normalizeStableKeyValue(value.stableKey || entryKey) === normalizeStableKeyValue(item.stableKey));
296
+ if (match?.[1].environments?.[envName]?.remoteComponentId === item.targetId) {
297
+ removeComponentLockBaseline(projectRoot, identity, match[0], item.targetId, envName);
298
+ }
299
+ return;
300
+ }
301
+ const fields = {
302
+ 'job-template': 'jobTemplates', endpoint: 'endpoints', schedule: 'schedules', event: 'events',
303
+ 'database-table': 'databaseSchemas', 'database-view': 'databaseViews', group: 'groups',
304
+ 'role-group': 'roleGroups', 'service-account': 'serviceAccounts',
305
+ };
306
+ const entries = lock[fields[item.resource]];
307
+ const entry = Object.values(entries).find((value) => normalizeStableKeyValue(value.stableKey) === normalizeStableKeyValue(item.stableKey));
308
+ if (entry?.environments[envName]) {
309
+ if (item.resource === 'database-table' && 'parentStableKey' in entry && entry.parentStableKey) {
310
+ lock.databaseSchemas[entry.stableKey].environments[envName] = {
311
+ remoteHash: entry.environments[envName].remoteHash,
312
+ tombstone: { deletedAt: new Date().toISOString(), parentStableKey: entry.parentStableKey },
313
+ };
314
+ }
315
+ else
316
+ delete entry.environments[envName];
317
+ writeComponentLock(projectRoot, lock);
318
+ }
319
+ }
320
+ export async function applyWorkspacePrune(input) {
321
+ if (input.plan.blockers.length)
322
+ throw new Error('Workspace prune plan is blocked.');
323
+ const results = [];
324
+ for (const item of input.plan.items) {
325
+ let accepted = false;
326
+ try {
327
+ if (readPruneManifests(input.cwd, input.resources)[item.resource]?.has(normalizeStableKeyValue(item.stableKey))) {
328
+ throw new Error('local manifest reappeared after planning');
329
+ }
330
+ // These owning APIs can affect a table subtree or deactivate view automations.
331
+ // Recheck the complete remaining graph before invoking a cascading lifecycle.
332
+ if (item.resource === 'database-table' || item.resource === 'database-view') {
333
+ const fresh = await buildWorkspacePrunePlan(input);
334
+ if (!samePrunePlan({ ...input.plan, items: input.plan.items.slice(results.length) }, fresh)) {
335
+ throw new Error('remaining deletion dependencies changed after planning');
336
+ }
337
+ }
338
+ let current;
339
+ for await (const entry of readResourceInventory(input.client, item.resource)) {
340
+ if (resourceIdOf(entry.resource) === item.targetId && active(entry.resource))
341
+ current = entry.resource;
342
+ }
343
+ if (!current || readConfiguredResourceMetadataStableKey(current, readProjectStableKeyName(input.cwd)) !== item.stableKey
344
+ || resourceHash(current) !== item.targetHash)
345
+ throw new Error('target changed after deletion was reviewed');
346
+ await input.client.deleteWorkspaceResource(item.resource, item.targetId);
347
+ accepted = true;
348
+ for await (const entry of readResourceInventory(input.client, item.resource)) {
349
+ if (resourceIdOf(entry.resource) === item.targetId && active(entry.resource))
350
+ throw new Error('delete did not remove the resource from the active catalog');
351
+ }
352
+ clearPruneBaseline(input.cwd, input.envName, item);
353
+ results.push({ status: 'pruned', targetPath: `${item.resource}:${item.stableKey}` });
354
+ }
355
+ catch (error) {
356
+ results.push({ status: accepted ? 'write-unverified' : 'failed', targetPath: `${item.resource}:${item.stableKey}`,
357
+ reason: error instanceof Error ? error.message : String(error) });
358
+ // Never continue into deletion of dependencies after a failed consumer delete.
359
+ break;
360
+ }
361
+ }
362
+ return results;
363
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revoengine/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "CLI package for the RevoEngine Platform API",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -11,7 +11,7 @@
11
11
  "scripts": {
12
12
  "build": "npm run clean && tsc -p tsconfig.build.json",
13
13
  "clean": "node --input-type=module -e \"import fs from 'node:fs'; fs.rmSync('dist', { recursive: true, force: true });\"",
14
- "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
14
+ "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/resource-syncs/account-principal.ts'); await import('./src/resource-syncs/identity-migration.ts'); await import('./src/resource-syncs/service-account-sync.ts'); await import('./src/commands/service-accounts.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/workspace-prune.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
15
15
  "dev": "node ./scripts/dev.ts",
16
16
  "prepack": "npm run build",
17
17
  "test": "node --test ./test/*.test.ts",