@revoengine/cli 1.0.17 → 1.0.19

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.
@@ -328,6 +328,33 @@ export async function buildJobTemplatesPlan(input) {
328
328
  localByKey.set(entry.manifest.stableKey, [...(localByKey.get(entry.manifest.stableKey) || []), entry]);
329
329
  }
330
330
  const targetRecordsByKey = new Map();
331
+ const targetRecordsByName = new Map();
332
+ for (const record of targetRecords) {
333
+ if (typeof record.name !== 'string')
334
+ continue;
335
+ const matches = targetRecordsByName.get(record.name) || [];
336
+ matches.push(record);
337
+ targetRecordsByName.set(record.name, matches);
338
+ }
339
+ const nameCollisionKeys = new Set();
340
+ const localNames = new Map();
341
+ for (const [stableKey, entries] of localByKey) {
342
+ const desired = entries[0].manifest;
343
+ const previous = localNames.get(desired.name);
344
+ if (previous && previous !== stableKey) {
345
+ blockers.push(`Duplicate local job-template name "${desired.name}" for "${previous}" and "${stableKey}".`);
346
+ nameCollisionKeys.add(previous);
347
+ nameCollisionKeys.add(stableKey);
348
+ }
349
+ localNames.set(desired.name, stableKey);
350
+ for (const record of targetRecordsByName.get(desired.name) || []) {
351
+ if (readConfiguredResourceMetadataStableKey(record, input.stableKeyName) === stableKey
352
+ || input.pruneBeforeUpsertIds?.includes(jobTemplateIdOf(record)))
353
+ continue;
354
+ blockers.push(`Job-template name "${desired.name}" is already used by target "${jobTemplateIdOf(record)}" with a different or missing Stable Key; review its identity or an explicit workspace prune.`);
355
+ nameCollisionKeys.add(stableKey);
356
+ }
357
+ }
331
358
  for (const record of targetRecords) {
332
359
  const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
333
360
  if (!stableKey) {
@@ -387,6 +414,10 @@ export async function buildJobTemplatesPlan(input) {
387
414
  continue;
388
415
  }
389
416
  const desired = entries[0].manifest;
417
+ if (nameCollisionKeys.has(stableKeyIdentity)) {
418
+ items.push({ status: 'collision', stableKey: desired.stableKey, name: desired.name, reason: 'job-template name is already in use' });
419
+ continue;
420
+ }
390
421
  const lockEntry = lockEntriesByKey.get(stableKeyIdentity);
391
422
  if (!desired.executionPrincipal && (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded')) {
392
423
  warnings.push(`Job template "${desired.stableKey}": execution principal excluded; manual target execution principal configuration is required.`);
@@ -21,9 +21,26 @@ export async function serviceAccountManifestFromRecord(client, record, stableKey
21
21
  stableKey,
22
22
  name: String(record.name || ''),
23
23
  metadata: { [stableKeyName]: stableKey },
24
- owner: await readPortableOwner(client, record, stableKeyName),
24
+ owner: await readManagementPrincipal(client, record, stableKeyName),
25
25
  };
26
26
  }
27
+ async function readManagementPrincipal(client, record, stableKeyName) {
28
+ // The manifest's portable owner now represents one management ACL principal.
29
+ // Self access is target-local and never creates a dependency on the account itself.
30
+ if (!record.access)
31
+ return readPortableOwner(client, record, stableKeyName);
32
+ const { restricted, users, groups } = record.access;
33
+ if (typeof restricted !== 'boolean' || !Array.isArray(users) || !Array.isArray(groups)) {
34
+ throw new Error('Invalid service-account management access response.');
35
+ }
36
+ const managers = users.filter(user => user.userId !== record.userId);
37
+ if (!restricted || managers.length + groups.length !== 1) {
38
+ return { type: 'unresolved', reason: 'unrestricted or multiple management principals require target-local configuration' };
39
+ }
40
+ return readPortableOwner(client, groups.length
41
+ ? { ownerType: 'GROUP', ownerId: groups[0].groupId }
42
+ : { ownerType: 'USER', ownerId: managers[0].userId }, stableKeyName);
43
+ }
27
44
  export function hashPortableServiceAccount(manifest) {
28
45
  return hashStable({ kind: manifest.kind, stableKey: manifest.stableKey, name: manifest.name, metadata: manifest.metadata,
29
46
  ...(['group', 'service-account'].includes(manifest.owner.type) ? { owner: manifest.owner } : {}) });
@@ -427,15 +444,33 @@ export async function pullServiceAccountsToWorkspace(input) {
427
444
  skipped,
428
445
  };
429
446
  }
447
+ async function managementAccessPayload(client, manifest, stableKeyName, target) {
448
+ if (target?.access) {
449
+ const managers = target.access.users.filter(user => user.userId !== target.userId);
450
+ if (!target.access.restricted || managers.length + target.access.groups.length !== 1) {
451
+ throw new Error('Target management ACL requires target-local configuration; portable owner cannot replace unrestricted or multiple principals.');
452
+ }
453
+ }
454
+ const principal = await resolvePortableOwner(client, manifest.owner, stableKeyName);
455
+ // Preserve an existing self grant without transferring its source UUID.
456
+ const users = target?.userId && target.access?.users.some(user => user.userId === target.userId)
457
+ ? [{ id: target.userId }] : [];
458
+ const groups = [];
459
+ (principal.ownerType === 'USER' ? users : groups).push({ id: principal.ownerId });
460
+ return { restricted: true, users, groups };
461
+ }
430
462
  async function buildCreatePayload(client, manifest, stableKeyName) {
431
- return { name: manifest.name, metadata: manifest.metadata, ...await resolvePortableOwner(client, manifest.owner, stableKeyName) };
463
+ return { name: manifest.name, metadata: manifest.metadata, access: await managementAccessPayload(client, manifest, stableKeyName) };
432
464
  }
433
465
  async function buildBaseUpdatePayload(client, manifest, target, stableKeyName) {
434
466
  if (!Number.isInteger(target.version)) {
435
467
  throw new Error('target service-account version is required');
436
468
  }
469
+ const ownerChanged = ['group', 'service-account'].includes(manifest.owner.type)
470
+ && hashStable(manifest.owner) !== hashStable(await readManagementPrincipal(client, target, stableKeyName));
437
471
  return { name: manifest.name, metadata: { ...sanitizeUserMetadata(target.metadata), ...manifest.metadata }, version: target.version,
438
- ...(['group', 'service-account'].includes(manifest.owner.type) ? await resolvePortableOwner(client, manifest.owner, stableKeyName) : {}) };
472
+ ...(ownerChanged
473
+ ? { access: await managementAccessPayload(client, manifest, stableKeyName, target) } : {}) };
439
474
  }
440
475
  function updateEnvironmentBaseline(input) {
441
476
  const { projectRoot } = requireProjectLayout(input.cwd, 'Service-account');
@@ -159,11 +159,28 @@ export type EndpointRecord = {
159
159
  deletedBy?: string | null;
160
160
  [key: string]: unknown;
161
161
  };
162
+ export type ServiceAccountAccessRecord = {
163
+ restricted: boolean;
164
+ users: Array<{
165
+ userId: string;
166
+ mail?: string;
167
+ name?: string;
168
+ }>;
169
+ groups: Array<{
170
+ groupId: string;
171
+ name?: string;
172
+ }>;
173
+ };
162
174
  export type ServiceAccountRecord = {
163
175
  category?: string | null;
164
176
  userId?: string;
165
177
  name?: string;
166
178
  serviceAccount?: boolean;
179
+ access?: ServiceAccountAccessRecord;
180
+ memberships?: {
181
+ groups: string[];
182
+ roleGroups: string[];
183
+ };
167
184
  ownerId?: string;
168
185
  ownerType?: string;
169
186
  version?: number;
package/dist/src/ui.js CHANGED
@@ -130,7 +130,7 @@ function renderCommandCatalog() {
130
130
  commandRow('revo component pull --all [--project <name>] [--yes] [--force]', 'Pull every available component safely'),
131
131
  commandRow('revo component push <identity...> [--project <name>]', 'Push by configured stable key or component ID'),
132
132
  commandRow('revo component push --all [--project <name>] [--yes] [--force] [--prune] [--changed --base <ref>]', 'Push local components with lock checks'),
133
- commandRow('revo component debug <componentId> [BODY] [--stream] [--raw-debug]', 'Debug one local component against sandbox'),
133
+ commandRow('revo component debug <componentId> [BODY] [--read-only=true|false] [--stream]', 'Run one local component in sandbox'),
134
134
  '',
135
135
  paintHeader('Databases'),
136
136
  commandRow('revo database-tables pull --all [--project <name>] [--force] [--strict]', 'Pull portable Database Tables and partitions'),
@@ -9,6 +9,7 @@ export type WorkspacePruneItem = {
9
9
  name: string;
10
10
  version: number | null;
11
11
  targetHash: string;
12
+ beforeUpserts?: true;
12
13
  };
13
14
  export type WorkspacePrunePlan = {
14
15
  items: WorkspacePruneItem[];
@@ -36,5 +37,6 @@ export declare function applyWorkspacePrune(input: {
36
37
  resources: readonly TrackableResourceType[];
37
38
  envName: string;
38
39
  plan: WorkspacePrunePlan;
40
+ beforeUpsertsOnly?: boolean;
39
41
  }): Promise<WorkspaceSyncResult[]>;
40
42
  export {};
@@ -95,9 +95,9 @@ function localReferences(resource, manifest) {
95
95
  }
96
96
  function remoteReferences(resource, record, tables) {
97
97
  const refs = [];
98
- const add = (family, value) => {
98
+ const add = (family, value, targetLocal = false) => {
99
99
  if (typeof value === 'string' && value)
100
- refs.push({ resource: family, identity: value });
100
+ refs.push({ resource: family, identity: value, targetLocal });
101
101
  };
102
102
  if (resource === 'job-template' || resource === 'endpoint')
103
103
  add('component', record.componentId);
@@ -125,6 +125,26 @@ function remoteReferences(resource, record, tables) {
125
125
  add('database-table', resourceIdOf(table));
126
126
  }
127
127
  }
128
+ if (resource === 'service-account') {
129
+ if (isRecord(record.access)) {
130
+ const users = Array.isArray(record.access.users) ? record.access.users.filter(user => isRecord(user) && user.userId !== record.userId) : [];
131
+ const groups = Array.isArray(record.access.groups) ? record.access.groups : [];
132
+ const targetLocal = record.access.restricted !== true || users.length + groups.length !== 1;
133
+ for (const user of users)
134
+ if (isRecord(user))
135
+ add('service-account', user.userId, targetLocal);
136
+ for (const group of groups)
137
+ if (isRecord(group))
138
+ add('group', group.groupId, targetLocal);
139
+ }
140
+ if (isRecord(record.memberships)) {
141
+ for (const [family, values] of [['group', record.memberships.groups], ['role-group', record.memberships.roleGroups]]) {
142
+ if (Array.isArray(values))
143
+ for (const value of values)
144
+ add(family, value, true);
145
+ }
146
+ }
147
+ }
128
148
  if (record.ownerType === 'GROUP')
129
149
  add('group', record.ownerId);
130
150
  if (record.ownerType === 'USER')
@@ -191,11 +211,15 @@ export function planWorkspacePrune(input) {
191
211
  }
192
212
  }
193
213
  const dependencies = new Map();
214
+ const consumers = new Map();
194
215
  for (const [idKey, target] of byId) {
195
216
  for (const reference of remoteReferences(target.resource, target.record, input.inventory['database-table'] || [])) {
196
217
  const referenced = key(reference.resource, reference.identity);
197
218
  if (!candidates.has(referenced))
198
219
  continue;
220
+ const usages = consumers.get(referenced) || new Set();
221
+ usages.add(idKey);
222
+ consumers.set(referenced, usages);
199
223
  if (candidates.has(idKey)) {
200
224
  const dependents = dependencies.get(referenced) || new Set();
201
225
  dependents.add(idKey);
@@ -206,7 +230,10 @@ export function planWorkspacePrune(input) {
206
230
  const removed = candidates.get(referenced);
207
231
  // A managed retained consumer can release the old reference during upsert.
208
232
  // 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))
233
+ const preservesReference = desired && (reference.targetLocal
234
+ ||
235
+ ((target.resource === 'group' || target.resource === 'service-account')
236
+ && (!isRecord(desired.owner) || !['group', 'service-account'].includes(String(desired.owner.type))))
210
237
  || (target.resource === 'job-template' && removed.resource === 'service-account' && !isRecord(desired.executionPrincipal)));
211
238
  if (!desired || preservesReference || localReferences(target.resource, desired).some((ref) => key(ref.resource, ref.identity) === key(removed.resource, removed.stableKey))) {
212
239
  blockers.push(`${removed.resource} "${removed.stableKey}" is still referenced by retained ${target.resource} "${target.stableKey || resourceIdOf(target.record)}".`);
@@ -214,6 +241,46 @@ export function planWorkspacePrune(input) {
214
241
  }
215
242
  }
216
243
  }
244
+ // Names are unique independently of Stable Key. Release only reviewed name
245
+ // conflicts and their obsolete consumers before upserts; retained consumers
246
+ // cannot detach during this phase, even if their desired manifest moves later.
247
+ const beforeUpserts = new Set();
248
+ const templatesByName = new Map();
249
+ for (const [idKey, target] of byId) {
250
+ if (target.resource !== 'job-template' || typeof target.record.name !== 'string')
251
+ continue;
252
+ const matches = templatesByName.get(target.record.name) || [];
253
+ matches.push(idKey);
254
+ templatesByName.set(target.record.name, matches);
255
+ }
256
+ for (const manifest of input.local['job-template']?.values() || []) {
257
+ if (typeof manifest.name !== 'string')
258
+ continue;
259
+ for (const idKey of templatesByName.get(manifest.name) || []) {
260
+ const target = byId.get(idKey);
261
+ if (target.stableKey === manifest.stableKey)
262
+ continue;
263
+ if (candidates.has(idKey))
264
+ beforeUpserts.add(idKey);
265
+ else
266
+ blockers.push(`Job-template name "${manifest.name}" is already used by retained or unmanaged target "${resourceIdOf(target.record)}".`);
267
+ }
268
+ }
269
+ const pending = [...beforeUpserts];
270
+ for (const idKey of pending) {
271
+ for (const consumer of consumers.get(idKey) || []) {
272
+ if (!candidates.has(consumer)) {
273
+ const target = byId.get(consumer);
274
+ blockers.push(`Cannot delete ${candidates.get(idKey).resource} "${candidates.get(idKey).stableKey}" before upserts: retained ${target.resource} "${target.stableKey || resourceIdOf(target.record)}" still references it.`);
275
+ }
276
+ else if (!beforeUpserts.has(consumer)) {
277
+ beforeUpserts.add(consumer);
278
+ pending.push(consumer);
279
+ }
280
+ }
281
+ }
282
+ for (const idKey of beforeUpserts)
283
+ candidates.get(idKey).beforeUpserts = true;
217
284
  const items = [];
218
285
  const remaining = new Map(candidates);
219
286
  while (remaining.size) {
@@ -321,17 +388,25 @@ export async function applyWorkspacePrune(input) {
321
388
  if (input.plan.blockers.length)
322
389
  throw new Error('Workspace prune plan is blocked.');
323
390
  const results = [];
324
- for (const item of input.plan.items) {
391
+ const deleted = new Set();
392
+ for (const item of input.plan.items.filter((item) => !input.beforeUpsertsOnly || item.beforeUpserts)) {
325
393
  let accepted = false;
326
394
  try {
327
395
  if (readPruneManifests(input.cwd, input.resources)[item.resource]?.has(normalizeStableKeyValue(item.stableKey))) {
328
396
  throw new Error('local manifest reappeared after planning');
329
397
  }
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)) {
398
+ // Early template replacement needs its event/schedule graph, including
399
+ // unmanaged and out-of-scope consumers. Avoid reloading unrelated tables,
400
+ // identities and components for every early delete. Cascades still fence
401
+ // the complete remaining plan.
402
+ if (input.beforeUpsertsOnly || item.resource === 'database-table' || item.resource === 'database-view') {
403
+ const resources = input.beforeUpsertsOnly
404
+ ? input.resources.filter((resource) => resource === 'job-template' || resource === 'event' || resource === 'schedule')
405
+ : input.resources;
406
+ const fresh = await buildWorkspacePrunePlan({ ...input, resources });
407
+ const remaining = input.plan.items.filter((candidate) => resources.includes(candidate.resource)
408
+ && !deleted.has(key(candidate.resource, candidate.targetId)));
409
+ if (!samePrunePlan({ ...input.plan, items: remaining }, fresh)) {
335
410
  throw new Error('remaining deletion dependencies changed after planning');
336
411
  }
337
412
  }
@@ -350,6 +425,7 @@ export async function applyWorkspacePrune(input) {
350
425
  throw new Error('delete did not remove the resource from the active catalog');
351
426
  }
352
427
  clearPruneBaseline(input.cwd, input.envName, item);
428
+ deleted.add(key(item.resource, item.targetId));
353
429
  results.push({ status: 'pruned', targetPath: `${item.resource}:${item.stableKey}` });
354
430
  }
355
431
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revoengine/cli",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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/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')\"",
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-actions.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",