@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,3 +1,4 @@
1
+ import { type IdentityProjection } from './account-principal.ts';
1
2
  import { type FieldChange } from '../diff-details.ts';
2
3
  import type { RevoClient } from '../client.ts';
3
4
  import type { GroupRecord } from '../types.ts';
@@ -5,6 +6,10 @@ export declare const GROUPS_DIRECTORY = "Groups";
5
6
  export declare const GROUP_MANIFEST_FILE = "group.json";
6
7
  export type GroupManifest = {
7
8
  kind: 'group';
9
+ owner?: {
10
+ type: 'service-account';
11
+ stableKey: string;
12
+ };
8
13
  stableKey: string;
9
14
  name: string;
10
15
  category?: string | null;
@@ -42,6 +47,8 @@ export type GroupPlanItem = {
42
47
  currentHash?: string;
43
48
  baselineHash?: string;
44
49
  ownerStableKey?: string;
50
+ ownerKind?: 'group' | 'service-account';
51
+ manual?: string[];
45
52
  };
46
53
  export type GroupsPlan = {
47
54
  resourceType: 'group';
@@ -72,6 +79,8 @@ export declare function buildGroupsPlan(input: {
72
79
  cwd: string;
73
80
  envName: string;
74
81
  stableKeyName: string;
82
+ projectedIdentities?: IdentityProjection;
83
+ onlyStableKeys?: string[];
75
84
  }): Promise<GroupsPlan>;
76
85
  export declare function pullGroupsToWorkspace(input: {
77
86
  client: RevoClient;
@@ -87,6 +96,7 @@ export declare function pushGroups(input: {
87
96
  envName: string;
88
97
  stableKeyName: string;
89
98
  force?: boolean;
99
+ onlyStableKeys?: string[];
90
100
  }): Promise<{
91
101
  plan: GroupsPlan;
92
102
  results: GroupPushResult[];
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path';
2
+ import { accountPrincipal, serviceAccountMatches, ownerIsAvailable } from "./account-principal.js";
2
3
  import { describeFieldChanges, formatDiffValue } from "../diff-details.js";
3
4
  import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
4
5
  import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "../resource-metadata.js";
@@ -68,7 +69,7 @@ export function hashPortableGroup(manifest) {
68
69
  });
69
70
  }
70
71
  function diffGroups(desired, target) {
71
- return ['name', 'category', 'description', 'metadata']
72
+ return ['name', 'category', 'description', 'metadata', 'owner']
72
73
  .filter((field) => {
73
74
  const desiredValue = field === 'category'
74
75
  ? desired.category ?? null
@@ -127,6 +128,13 @@ function validateManifest(manifest, stableKeyName) {
127
128
  if (manifest.description !== undefined && typeof manifest.description !== 'string') {
128
129
  errors.push('description must be a string or omitted');
129
130
  }
131
+ if (manifest.owner !== undefined && (!isRecord(manifest.owner)
132
+ || Object.keys(manifest.owner).some((key) => key !== 'type' && key !== 'stableKey')
133
+ || manifest.owner.type !== 'service-account'
134
+ || typeof manifest.owner.stableKey !== 'string'
135
+ || !manifest.owner.stableKey.trim())) {
136
+ errors.push('owner must contain a Service Account stableKey');
137
+ }
130
138
  if (isRecord(manifest.metadata) && Object.keys(manifest.metadata).some((key) => key.startsWith('__'))) {
131
139
  errors.push('metadata must not contain backend-reserved keys');
132
140
  }
@@ -153,13 +161,14 @@ function emptyPlanCounts() {
153
161
  delete: 0,
154
162
  };
155
163
  }
156
- function sourceOwnerPolicy(input) {
164
+ async function sourceOwnerPolicy(input) {
157
165
  const ownerType = typeof input.record.ownerType === 'string'
158
166
  ? input.record.ownerType.trim().toUpperCase()
159
167
  : '';
160
168
  const ownerId = typeof input.record.ownerId === 'string' ? input.record.ownerId.trim() : '';
161
169
  if (ownerType === 'USER' && ownerId) {
162
- return { type: 'manual-user' };
170
+ const principal = await accountPrincipal(input.client, ownerId, input.stableKeyName);
171
+ return principal ? { type: 'service-account', stableKey: principal.stableKey } : { type: 'manual-user' };
163
172
  }
164
173
  if (ownerType === 'GROUP' && ownerId) {
165
174
  const owner = input.recordsById.get(ownerId);
@@ -185,6 +194,9 @@ function resolveCreateDependencies(input) {
185
194
  .filter((item) => item.status === 'manual-owner' && item.stableKey)
186
195
  .map((item) => item.stableKey));
187
196
  for (const item of createByKey.values()) {
197
+ if (item.ownerKind === 'service-account') {
198
+ continue;
199
+ }
188
200
  const ownerStableKey = item.ownerStableKey || '';
189
201
  const targetOwners = input.remoteByKey.get(ownerStableKey) || [];
190
202
  if (targetOwners.length === 1) {
@@ -256,7 +268,7 @@ function consumeCollisionCandidates(input) {
256
268
  }
257
269
  }
258
270
  export async function buildGroupsPlan(input) {
259
- const localEntries = readWorkspaceGroups(input.cwd);
271
+ const localEntries = readWorkspaceGroups(input.cwd).filter((entry) => !input.onlyStableKeys || input.onlyStableKeys.includes(entry.manifest.stableKey));
260
272
  const records = await loadRemoteGroups(input.client);
261
273
  const { projectRoot } = requireProjectLayout(input.cwd, 'Group');
262
274
  const lock = readComponentLock(projectRoot);
@@ -283,6 +295,14 @@ export async function buildGroupsPlan(input) {
283
295
  const unmanaged = [];
284
296
  for (const record of records) {
285
297
  const manifest = groupManifestFromRecord(record, input.stableKeyName);
298
+ if (manifest && localEntries.some((entry) => entry.manifest.stableKey === manifest.stableKey && Boolean(entry.manifest.owner))) {
299
+ if (record.ownerType === 'USER' && record.ownerId) {
300
+ const principal = await accountPrincipal(input.client, record.ownerId, input.stableKeyName);
301
+ if (principal) {
302
+ manifest.owner = { type: 'service-account', stableKey: principal.stableKey };
303
+ }
304
+ }
305
+ }
286
306
  if (!manifest) {
287
307
  unmanaged.push(record);
288
308
  continue;
@@ -327,7 +347,7 @@ export async function buildGroupsPlan(input) {
327
347
  }
328
348
  const lockEntry = lockByStableKey.get(desired.stableKey);
329
349
  if (matches.length === 0) {
330
- const owner = lockEntry?.owner;
350
+ const owner = desired.owner || lockEntry?.owner;
331
351
  if (!owner) {
332
352
  blockers.push(`Cannot create Group "${desired.stableKey}": missing portable source owner policy; pull from source first.`);
333
353
  items.push({
@@ -358,12 +378,18 @@ export async function buildGroupsPlan(input) {
358
378
  });
359
379
  }
360
380
  else {
381
+ if (owner.type === 'service-account' && !await ownerIsAvailable(input.client, owner, input.stableKeyName, input.projectedIdentities)) {
382
+ blockers.push(`Group "${desired.stableKey}" service-account owner is missing or ambiguous.`);
383
+ items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'service-account owner is missing or ambiguous' });
384
+ continue;
385
+ }
361
386
  items.push({
362
387
  status: 'create',
363
388
  stableKey: desired.stableKey,
364
389
  name: desired.name,
365
390
  desiredHash,
366
391
  ownerStableKey: owner.stableKey,
392
+ ownerKind: owner.type,
367
393
  });
368
394
  }
369
395
  continue;
@@ -388,7 +414,18 @@ export async function buildGroupsPlan(input) {
388
414
  }
389
415
  let ownerChanged = false;
390
416
  let ownerStableKey;
391
- if (lockEntry?.owner?.type === 'group') {
417
+ const desiredOwner = desired.owner || lockEntry?.owner;
418
+ if (desiredOwner?.type === 'service-account') {
419
+ ownerStableKey = desiredOwner.stableKey;
420
+ const matches = await serviceAccountMatches(input.client, ownerStableKey, input.stableKeyName);
421
+ if (matches.length > 1 || (matches.length === 0 && !(input.projectedIdentities?.serviceAccounts || []).includes(ownerStableKey))) {
422
+ blockers.push(`Group "${desired.stableKey}" service-account owner is missing or ambiguous.`);
423
+ items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'service-account owner is missing or ambiguous' });
424
+ continue;
425
+ }
426
+ ownerChanged = target.record.ownerType !== 'USER' || matches.length === 0 || target.record.ownerId !== matches[0].userId;
427
+ }
428
+ if (lockEntry?.owner?.type === 'group' && !desired.owner) {
392
429
  ownerStableKey = lockEntry.owner.stableKey;
393
430
  const ownerMatches = remoteByKey.get(ownerStableKey) || [];
394
431
  if (ownerMatches.length > 1) {
@@ -428,7 +465,7 @@ export async function buildGroupsPlan(input) {
428
465
  name: desired.name,
429
466
  desiredHash,
430
467
  currentHash: target.hash,
431
- ...(ownerStableKey ? { ownerStableKey } : {}),
468
+ ...(ownerStableKey ? { ownerStableKey, ownerKind: desiredOwner?.type === 'service-account' ? 'service-account' : 'group' } : {}),
432
469
  ...(changedFields.length > 0 ? {
433
470
  changedFields,
434
471
  fieldChanges: [
@@ -463,7 +500,9 @@ export async function buildGroupsPlan(input) {
463
500
  items.push({ status: 'conflict', ...common, baselineHash, reason: 'desired and target changed since lock baseline' });
464
501
  }
465
502
  }
466
- resolveCreateDependencies({ items, remoteByKey, blockers });
503
+ if (!input.projectedIdentities) {
504
+ resolveCreateDependencies({ items, remoteByKey, blockers });
505
+ }
467
506
  for (const [stableKey, matches] of remoteByKey) {
468
507
  if (consumedRemoteKeys.has(stableKey) || localByKey.has(stableKey)) {
469
508
  continue;
@@ -507,6 +546,12 @@ export async function buildGroupsPlan(input) {
507
546
  };
508
547
  items.sort((left, right) => rank[left.status] - rank[right.status]
509
548
  || (left.stableKey || left.name).localeCompare(right.stableKey || right.name));
549
+ for (const item of items) {
550
+ if (lockByStableKey.get(item.stableKey || '')?.owner?.type === 'manual-user') {
551
+ item.manual = ['Configure the human owner manually on target'];
552
+ warnings.add(`Group "${item.stableKey}": human owner requires manual target configuration.`);
553
+ }
554
+ }
510
555
  const counts = emptyPlanCounts();
511
556
  for (const item of items) {
512
557
  counts[item.status] += 1;
@@ -520,7 +565,7 @@ export async function buildGroupsPlan(input) {
520
565
  warnings: [...warnings].sort((left, right) => left.localeCompare(right)),
521
566
  exclusions: [
522
567
  'members/users are always skipped',
523
- 'USER owners, leader, avatar, UUID and version are target-local and never persisted',
568
+ 'Human USER owners, leader, avatar, UUID and version are target-local and never persisted',
524
569
  'GROUP owner dependencies are persisted only as stableKey references',
525
570
  ],
526
571
  };
@@ -554,7 +599,10 @@ export async function pullGroupsToWorkspace(input) {
554
599
  if (memberCount > 0) {
555
600
  notices.push({ stableKey: manifest.stableKey, reason: `source members excluded: ${memberCount}` });
556
601
  }
557
- const owner = sourceOwnerPolicy({ record, recordsById, stableKeyName: input.stableKeyName });
602
+ const owner = await sourceOwnerPolicy({ client: input.client, record, recordsById, stableKeyName: input.stableKeyName });
603
+ if (owner.type === 'service-account') {
604
+ manifest.owner = owner;
605
+ }
558
606
  if (owner.type === 'manual-user') {
559
607
  notices.push({ stableKey: manifest.stableKey, reason: 'source USER owner excluded; target creation is manual' });
560
608
  }
@@ -670,18 +718,18 @@ export async function pullGroupsToWorkspace(input) {
670
718
  notices,
671
719
  };
672
720
  }
673
- function buildCreatePayload(manifest, ownerId) {
721
+ function buildCreatePayload(manifest, ownerId, ownerType = 'GROUP') {
674
722
  return {
675
723
  name: manifest.name,
676
724
  ...(manifest.category === undefined ? {} : { category: manifest.category }),
677
725
  ...(manifest.description === undefined ? {} : { desc: manifest.description }),
678
726
  metadata: sanitizeUserMetadata(manifest.metadata),
679
- ownerType: 'GROUP',
727
+ ownerType,
680
728
  ownerId,
681
729
  members: [],
682
730
  };
683
731
  }
684
- function buildUpdatePayload(manifest, target, ownerId) {
732
+ function buildUpdatePayload(manifest, target, ownerId, ownerType = 'GROUP') {
685
733
  if (!Number.isInteger(target.version)) {
686
734
  throw new Error('target Group version is required');
687
735
  }
@@ -695,7 +743,7 @@ function buildUpdatePayload(manifest, target, ownerId) {
695
743
  : { desc: manifest.description ?? '' }),
696
744
  metadata: sanitizeUserMetadata(manifest.metadata),
697
745
  version: target.version,
698
- ...(ownerId ? { ownerType: 'GROUP', ownerId } : {}),
746
+ ...(ownerId ? { ownerType, ownerId } : {}),
699
747
  };
700
748
  }
701
749
  function updateEnvironmentBaseline(input) {
@@ -730,6 +778,12 @@ function updateEnvironmentBaseline(input) {
730
778
  function localManifestByStableKey(cwd) {
731
779
  return new Map(readWorkspaceGroups(cwd).map((entry) => [entry.manifest.stableKey, entry]));
732
780
  }
781
+ async function liveOwnerMatches(client, stableKeyName, item) {
782
+ if (item.ownerKind === 'service-account') {
783
+ return (await serviceAccountMatches(client, item.ownerStableKey || '', stableKeyName)).map((account) => ({ groupId: account.userId }));
784
+ }
785
+ return liveTargetByStableKey(client, stableKeyName, item.ownerStableKey || '');
786
+ }
733
787
  async function liveTargetByStableKey(client, stableKeyName, stableKey) {
734
788
  const records = await loadRemoteGroups(client);
735
789
  return records.filter((record) => stableKeyOf(record, stableKeyName) === stableKey);
@@ -791,7 +845,7 @@ export async function pushGroups(input) {
791
845
  let progressed = false;
792
846
  for (const [stableKey, item] of [...pendingCreates.entries()]
793
847
  .sort(([left], [right]) => left.localeCompare(right))) {
794
- const ownerMatches = await liveTargetByStableKey(input.client, input.stableKeyName, item.ownerStableKey || '');
848
+ const ownerMatches = await liveOwnerMatches(input.client, input.stableKeyName, item);
795
849
  if (ownerMatches.length === 0) {
796
850
  continue;
797
851
  }
@@ -819,17 +873,23 @@ export async function pushGroups(input) {
819
873
  }
820
874
  try {
821
875
  await assertCreateStillSafe(input.client, input.stableKeyName, local.manifest);
822
- const created = unwrapData(await input.client.createGroup(buildCreatePayload(local.manifest, ownerId)));
876
+ const created = unwrapData(await input.client.createGroup(buildCreatePayload(local.manifest, ownerId, item.ownerKind === 'service-account' ? 'USER' : 'GROUP')));
823
877
  const createdId = groupIdOf(created);
824
878
  if (!createdId) {
825
879
  throw new Error('create response did not include groupId');
826
880
  }
827
881
  const verified = unwrapData(await input.client.getGroup(createdId));
828
882
  const verifiedManifest = groupManifestFromRecord(verified, input.stableKeyName);
883
+ if (verifiedManifest && local.manifest.owner && verified.ownerType === 'USER' && verified.ownerId) {
884
+ const principal = await accountPrincipal(input.client, verified.ownerId, input.stableKeyName);
885
+ if (principal) {
886
+ verifiedManifest.owner = { type: 'service-account', stableKey: principal.stableKey };
887
+ }
888
+ }
829
889
  if (!verifiedManifest || hashPortableGroup(verifiedManifest) !== liveDesiredHash) {
830
890
  throw new Error('created Group did not match desired portable hash');
831
891
  }
832
- if (String(verified.ownerType || '').toUpperCase() !== 'GROUP' || verified.ownerId !== ownerId) {
892
+ if (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' ? 'USER' : 'GROUP') || verified.ownerId !== ownerId) {
833
893
  throw new Error('created Group did not retain the resolved target owner');
834
894
  }
835
895
  updateEnvironmentBaseline({ cwd: input.cwd, envName: input.envName, stableKey, remoteHash: liveDesiredHash });
@@ -878,12 +938,18 @@ export async function pushGroups(input) {
878
938
  }
879
939
  const target = unwrapData(await input.client.getGroup(targetId));
880
940
  const targetManifest = groupManifestFromRecord(target, input.stableKeyName);
941
+ if (targetManifest && local.manifest.owner && target.ownerType === 'USER' && target.ownerId) {
942
+ const principal = await accountPrincipal(input.client, target.ownerId, input.stableKeyName);
943
+ if (principal) {
944
+ targetManifest.owner = { type: 'service-account', stableKey: principal.stableKey };
945
+ }
946
+ }
881
947
  if (!targetManifest || hashPortableGroup(targetManifest) !== item.currentHash) {
882
948
  throw new Error('target changed after planning');
883
949
  }
884
950
  let desiredOwnerId;
885
951
  if (item.ownerStableKey) {
886
- const ownerMatches = await liveTargetByStableKey(input.client, input.stableKeyName, item.ownerStableKey);
952
+ const ownerMatches = await liveOwnerMatches(input.client, input.stableKeyName, item);
887
953
  if (ownerMatches.length !== 1) {
888
954
  throw new Error(`expected one live target owner Group, found ${ownerMatches.length}`);
889
955
  }
@@ -892,13 +958,19 @@ export async function pushGroups(input) {
892
958
  throw new Error('live target owner Group did not include groupId');
893
959
  }
894
960
  }
895
- await input.client.updateGroup(targetId, buildUpdatePayload(local.manifest, target, desiredOwnerId));
961
+ await input.client.updateGroup(targetId, buildUpdatePayload(local.manifest, target, desiredOwnerId, item.ownerKind === 'service-account' ? 'USER' : 'GROUP'));
896
962
  const verified = unwrapData(await input.client.getGroup(targetId));
897
963
  const verifiedManifest = groupManifestFromRecord(verified, input.stableKeyName);
964
+ if (verifiedManifest && local.manifest.owner && verified.ownerType === 'USER' && verified.ownerId) {
965
+ const principal = await accountPrincipal(input.client, verified.ownerId, input.stableKeyName);
966
+ if (principal) {
967
+ verifiedManifest.owner = { type: 'service-account', stableKey: principal.stableKey };
968
+ }
969
+ }
898
970
  if (!verifiedManifest || hashPortableGroup(verifiedManifest) !== liveDesiredHash) {
899
971
  throw new Error('updated Group did not match desired portable hash');
900
972
  }
901
- if (desiredOwnerId && (String(verified.ownerType || '').toUpperCase() !== 'GROUP'
973
+ if (desiredOwnerId && (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' ? 'USER' : 'GROUP')
902
974
  || verified.ownerId !== desiredOwnerId)) {
903
975
  throw new Error('updated Group did not retain the resolved target owner');
904
976
  }
@@ -0,0 +1,19 @@
1
+ import type { RevoClient } from '../client.ts';
2
+ import { type GroupOwnerPolicy } from '../component-lock.ts';
3
+ import type { IdentityProjection } from './account-principal.ts';
4
+ type IdentityNode = {
5
+ resource: 'group' | 'service-account';
6
+ stableKey: string;
7
+ owner?: GroupOwnerPolicy;
8
+ };
9
+ export declare function planIdentityMigration(input: {
10
+ client: RevoClient;
11
+ cwd: string;
12
+ stableKeyName: string;
13
+ resources: string[];
14
+ }): Promise<{
15
+ ordered: IdentityNode[];
16
+ projection: IdentityProjection;
17
+ blockers: string[];
18
+ } | undefined>;
19
+ export {};
@@ -0,0 +1,108 @@
1
+ import { readComponentLock } from "../component-lock.js";
2
+ import { readConfiguredResourceMetadataStableKey } from "../resource-metadata.js";
3
+ import { readWorkspaceGroups } from "./group-sync.js";
4
+ import { readWorkspaceServiceAccounts } from "./service-account-sync.js";
5
+ import { requireProjectLayout, unwrapData } from "./util.js";
6
+ export async function planIdentityMigration(input) {
7
+ const { projectRoot } = requireProjectLayout(input.cwd, 'Identity migration');
8
+ const lock = readComponentLock(projectRoot);
9
+ const groupEntries = input.resources.includes('group') ? readWorkspaceGroups(input.cwd) : [];
10
+ const accountEntries = input.resources.includes('service-account') ? readWorkspaceServiceAccounts(input.cwd) : [];
11
+ if (!input.resources.includes('service-account') && !groupEntries.some((entry) => entry.manifest.owner)) {
12
+ return undefined;
13
+ }
14
+ const nodes = [
15
+ ...accountEntries.map(({ manifest }) => ({ resource: 'service-account', stableKey: manifest.stableKey, owner: manifest.owner })),
16
+ ...groupEntries.map(({ manifest }) => ({ resource: 'group', stableKey: manifest.stableKey, owner: manifest.owner || lock.groups[manifest.stableKey]?.owner })),
17
+ ];
18
+ const id = (node) => `${node.resource}:${node.stableKey}`;
19
+ const liveCounts = new Map();
20
+ const { serviceAccounts } = await input.client.listAllServiceAccounts();
21
+ for (const summary of serviceAccounts) {
22
+ const record = await input.client.getServiceAccount(String(summary.userId || ''));
23
+ const key = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
24
+ if (key) {
25
+ const k = id({ resource: 'service-account', stableKey: key });
26
+ liveCounts.set(k, (liveCounts.get(k) || 0) + 1);
27
+ }
28
+ }
29
+ if (nodes.some((node) => node.resource === 'group' || node.owner?.type === 'group')) {
30
+ const { groups } = await input.client.listAllGroups();
31
+ for (const summary of groups) {
32
+ const record = unwrapData(await input.client.getGroup(String(summary.groupId || summary.id || '')));
33
+ const key = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
34
+ if (key && !record.deletedAt) {
35
+ const k = id({
36
+ resource: 'group',
37
+ stableKey: key
38
+ });
39
+ liveCounts.set(k, (liveCounts.get(k) || 0) + 1);
40
+ }
41
+ }
42
+ }
43
+ const blockers = [];
44
+ const byId = new Map();
45
+ for (const node of nodes) {
46
+ const key = id(node);
47
+ if (byId.has(key)) {
48
+ blockers.push(`Duplicate desired identity "${key}".`);
49
+ }
50
+ byId.set(key, node);
51
+ }
52
+ const ordered = [];
53
+ const state = new Map();
54
+ const visit = (node, trail) => {
55
+ const key = id(node);
56
+ if (state.get(key) === 'ready') {
57
+ return true;
58
+ }
59
+ if (state.get(key) === 'manual' || state.get(key) === 'blocked') {
60
+ return false;
61
+ }
62
+ if (state.get(key) === 'visiting') {
63
+ blockers.push(`Circular identity owner dependency: ${[...trail, key].join(' -> ')}.`);
64
+ state.set(key, 'blocked');
65
+ return false;
66
+ }
67
+ if ((liveCounts.get(key) || 0) > 1) {
68
+ blockers.push(`Duplicate target identity "${key}".`);
69
+ state.set(key, 'blocked');
70
+ return false;
71
+ }
72
+ state.set(key, 'visiting');
73
+ const owner = node.owner;
74
+ if (owner?.type === 'group' || owner?.type === 'service-account') {
75
+ const dependency = id({ resource: owner.type, stableKey: owner.stableKey });
76
+ const count = liveCounts.get(dependency) || 0;
77
+ if (count > 1) {
78
+ blockers.push(`Ambiguous owner "${dependency}" for "${key}".`);
79
+ state.set(key, 'blocked');
80
+ return false;
81
+ }
82
+ if (count === 0) {
83
+ const parent = byId.get(dependency);
84
+ if (!parent || !visit(parent, [...trail, key])) {
85
+ blockers.push(`Owner "${dependency}" is unavailable for "${key}"; configure it manually or include its resource family.`);
86
+ state.set(key, 'blocked');
87
+ return false;
88
+ }
89
+ }
90
+ }
91
+ else if (!liveCounts.get(key)) {
92
+ // A human owner has no portable mapping; creation stays manual.
93
+ state.set(key, 'manual');
94
+ return false;
95
+ }
96
+ state.set(key, 'ready');
97
+ ordered.push(node);
98
+ return true;
99
+ };
100
+ for (const node of nodes) {
101
+ visit(node, []);
102
+ }
103
+ const projection = {
104
+ serviceAccounts: ordered.filter((node) => node.resource === 'service-account').map((node) => node.stableKey),
105
+ groups: ordered.filter((node) => node.resource === 'group').map((node) => node.stableKey),
106
+ };
107
+ return { ordered, projection, blockers: [...new Set(blockers)] };
108
+ }
@@ -1,3 +1,4 @@
1
+ import { type ExecutionPrincipal } from './account-principal.ts';
1
2
  import { type FieldChange } from '../diff-details.ts';
2
3
  import type { RevoClient } from '../client.ts';
3
4
  export declare const JOB_TEMPLATES_DIRECTORY = "JobTemplates";
@@ -12,6 +13,7 @@ export type JobTemplateManifest = {
12
13
  component: {
13
14
  stableKey: string;
14
15
  };
16
+ executionPrincipal?: ExecutionPrincipal;
15
17
  timeout?: number;
16
18
  options?: unknown;
17
19
  inputs?: unknown;
@@ -64,6 +66,7 @@ export type JobTemplatePlanItem = {
64
66
  desiredHash?: string;
65
67
  currentHash?: string;
66
68
  baselineHash?: string;
69
+ manual?: string[];
67
70
  componentStableKey?: string;
68
71
  componentDesiredHash?: string;
69
72
  dependencyReadiness?: JobTemplateDependencyReadiness;
@@ -85,6 +88,7 @@ export declare function buildJobTemplatesPlan(input: {
85
88
  envName: string;
86
89
  stableKeyName: string;
87
90
  projectedComponents?: ProjectedComponentDependency[];
91
+ projectedServiceAccounts?: string[];
88
92
  }): Promise<JobTemplatesPlan>;
89
93
  export declare function pullJobTemplatesToWorkspace(input: {
90
94
  client: RevoClient;