@revoengine/cli 1.0.14 → 1.0.16

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 (58) hide show
  1. package/README.md +57 -21
  2. package/dist/src/cli.js +5 -1
  3. package/dist/src/client.d.ts +25 -14
  4. package/dist/src/client.js +67 -34
  5. package/dist/src/commands/component.js +1 -0
  6. package/dist/src/commands/env.js +1 -5
  7. package/dist/src/commands/index.d.ts +1 -0
  8. package/dist/src/commands/index.js +1 -0
  9. package/dist/src/commands/migrate.js +12 -2
  10. package/dist/src/commands/service-accounts.d.ts +2 -0
  11. package/dist/src/commands/service-accounts.js +149 -0
  12. package/dist/src/commands/terminal-browser.d.ts +29 -1
  13. package/dist/src/commands/terminal-browser.js +165 -34
  14. package/dist/src/commands/terminal-file.d.ts +21 -0
  15. package/dist/src/commands/terminal-file.js +160 -0
  16. package/dist/src/commands/terminal-operational-log.js +2 -2
  17. package/dist/src/commands/terminal-policy.d.ts +11 -2
  18. package/dist/src/commands/terminal-policy.js +27 -2
  19. package/dist/src/commands/terminal-pty.js +2 -0
  20. package/dist/src/commands/terminal-reconnect-grace.d.ts +19 -0
  21. package/dist/src/commands/terminal-reconnect-grace.js +59 -1
  22. package/dist/src/commands/terminal-sandbox.js +7 -0
  23. package/dist/src/commands/terminal-secure-browser.d.ts +1 -0
  24. package/dist/src/commands/terminal-secure-browser.js +2 -1
  25. package/dist/src/commands/terminal-service.d.ts +4 -3
  26. package/dist/src/commands/terminal-service.js +23 -19
  27. package/dist/src/commands/terminal.d.ts +29 -1
  28. package/dist/src/commands/terminal.js +508 -107
  29. package/dist/src/component-lock.d.ts +4 -0
  30. package/dist/src/component-lock.js +21 -2
  31. package/dist/src/config.d.ts +0 -3
  32. package/dist/src/config.js +0 -2
  33. package/dist/src/metadata-backfill.js +50 -1
  34. package/dist/src/migration.d.ts +10 -2
  35. package/dist/src/migration.js +159 -69
  36. package/dist/src/resource-inventory.d.ts +3 -2
  37. package/dist/src/resource-inventory.js +6 -1
  38. package/dist/src/resource-syncs/account-principal.d.ts +22 -0
  39. package/dist/src/resource-syncs/account-principal.js +86 -0
  40. package/dist/src/resource-syncs/database-view-sync.d.ts +0 -1
  41. package/dist/src/resource-syncs/database-view-sync.js +1 -12
  42. package/dist/src/resource-syncs/group-sync.d.ts +10 -0
  43. package/dist/src/resource-syncs/group-sync.js +92 -20
  44. package/dist/src/resource-syncs/identity-migration.d.ts +19 -0
  45. package/dist/src/resource-syncs/identity-migration.js +108 -0
  46. package/dist/src/resource-syncs/job-template-sync.d.ts +4 -0
  47. package/dist/src/resource-syncs/job-template-sync.js +55 -12
  48. package/dist/src/resource-syncs/service-account-sync.d.ts +98 -0
  49. package/dist/src/resource-syncs/service-account-sync.js +620 -0
  50. package/dist/src/sync-output.js +3 -0
  51. package/dist/src/tracked-resources.d.ts +1 -1
  52. package/dist/src/tracked-resources.js +5 -1
  53. package/dist/src/types.d.ts +12 -0
  54. package/dist/src/ui.js +4 -1
  55. package/dist/src/workspace-diff.d.ts +1 -0
  56. package/dist/src/workspace-diff.js +4 -1
  57. package/package.json +6 -5
  58. package/scripts/ensure-pty-helper.mjs +0 -9
@@ -44,6 +44,9 @@ export type GroupLockEntry = {
44
44
  export type GroupOwnerPolicy = {
45
45
  type: 'group';
46
46
  stableKey: string;
47
+ } | {
48
+ type: 'service-account';
49
+ stableKey: string;
47
50
  } | {
48
51
  type: 'manual-user';
49
52
  } | {
@@ -112,6 +115,7 @@ export type RevoLockFile = {
112
115
  components: Record<string, ComponentLockEntry>;
113
116
  groups: Record<string, GroupLockEntry>;
114
117
  roleGroups: Record<string, RoleGroupLockEntry>;
118
+ serviceAccounts: Record<string, RoleGroupLockEntry>;
115
119
  jobTemplates: Record<string, JobTemplateLockEntry>;
116
120
  schedules: Record<string, ScheduleLockEntry>;
117
121
  events: Record<string, EventLockEntry>;
@@ -155,6 +155,7 @@ export function readComponentLock(projectRoot) {
155
155
  components: {},
156
156
  groups: {},
157
157
  roleGroups: {},
158
+ serviceAccounts: {},
158
159
  jobTemplates: {},
159
160
  schedules: {},
160
161
  events: {},
@@ -212,8 +213,8 @@ export function readComponentLock(projectRoot) {
212
213
  stableKey: String(entry.stableKey),
213
214
  path: String(entry.path),
214
215
  sourceHash: String(entry.sourceHash),
215
- ...((isRecord(entry.owner) && entry.owner.type === 'group' && typeof entry.owner.stableKey === 'string')
216
- ? { owner: { type: 'group', stableKey: entry.owner.stableKey } }
216
+ ...((isRecord(entry.owner) && (entry.owner.type === 'group' || entry.owner.type === 'service-account') && typeof entry.owner.stableKey === 'string')
217
+ ? { owner: { type: entry.owner.type, stableKey: entry.owner.stableKey } }
217
218
  : (isRecord(entry.owner) && entry.owner.type === 'manual-user')
218
219
  ? { owner: { type: 'manual-user' } }
219
220
  : (isRecord(entry.owner) && entry.owner.type === 'unresolved' && typeof entry.owner.reason === 'string')
@@ -226,6 +227,23 @@ export function readComponentLock(projectRoot) {
226
227
  syncedAt: String(baseline.syncedAt),
227
228
  }])),
228
229
  }])),
230
+ serviceAccounts: Object.fromEntries(Object.entries(raw.serviceAccounts && typeof raw.serviceAccounts === 'object' ? raw.serviceAccounts : {})
231
+ .filter(([, entry]) => (typeof entry.stableKey === 'string'
232
+ && typeof entry.path === 'string'
233
+ && typeof entry.sourceHash === 'string'
234
+ && entry.environments
235
+ && typeof entry.environments === 'object'))
236
+ .map(([key, entry]) => [key, {
237
+ stableKey: String(entry.stableKey),
238
+ path: String(entry.path),
239
+ sourceHash: String(entry.sourceHash),
240
+ environments: Object.fromEntries(Object.entries(entry.environments)
241
+ .filter(([, baseline]) => typeof baseline.remoteHash === 'string' && typeof baseline.syncedAt === 'string')
242
+ .map(([envName, baseline]) => [envName, {
243
+ remoteHash: String(baseline.remoteHash),
244
+ syncedAt: String(baseline.syncedAt),
245
+ }])),
246
+ }])),
229
247
  roleGroups: Object.fromEntries(Object.entries(raw.roleGroups && typeof raw.roleGroups === 'object' ? raw.roleGroups : {})
230
248
  .filter(([, entry]) => (typeof entry.stableKey === 'string'
231
249
  && typeof entry.path === 'string'
@@ -379,6 +397,7 @@ export function writeComponentLock(projectRoot, lock) {
379
397
  components: sortedComponents,
380
398
  ...(Object.keys(sortedGroups).length > 0 ? { groups: sortedGroups } : {}),
381
399
  roleGroups: sortedRoleGroups,
400
+ ...(Object.keys(lock.serviceAccounts || {}).length ? { serviceAccounts: lock.serviceAccounts } : {}),
382
401
  jobTemplates: sortedJobTemplates,
383
402
  ...(Object.keys(sortedSchedules).length > 0 ? { schedules: sortedSchedules } : {}),
384
403
  ...(Object.keys(sortedEvents).length > 0 ? { events: sortedEvents } : {}),
@@ -4,7 +4,6 @@ export type RuntimeConfig = {
4
4
  baseUrl: string;
5
5
  instance: string;
6
6
  token: string;
7
- production?: true;
8
7
  };
9
8
  export type RuntimeConfigOptions = {
10
9
  baseUrl?: string;
@@ -16,7 +15,6 @@ export type StoredEnvironmentProfile = {
16
15
  baseUrl: string;
17
16
  token: string;
18
17
  instance?: string;
19
- production?: true;
20
18
  };
21
19
  type StoredConfig = Omit<RuntimeConfig, 'instance'> & {
22
20
  instance?: string;
@@ -69,7 +67,6 @@ export declare function readAuthValidationState(key?: string): AuthValidationSta
69
67
  export declare function saveAuthValidationState(state: AuthValidationState): void;
70
68
  export declare function clearAuthValidationState(key?: string): void;
71
69
  export declare function resolveRuntimeConfig(options?: RuntimeConfigOptions): {
72
- production?: true | undefined;
73
70
  baseUrl: string;
74
71
  instance: string;
75
72
  token: string;
@@ -185,7 +185,6 @@ function parseEnvironmentProfiles(value) {
185
185
  baseUrl: entry.baseUrl,
186
186
  token: entry.token,
187
187
  ...(typeof entry.instance === 'string' && isUuid(entry.instance) ? { instance: entry.instance } : {}),
188
- ...(entry.production === true ? { production: true } : {}),
189
188
  };
190
189
  }
191
190
  return Object.keys(environments).length > 0 ? environments : null;
@@ -475,7 +474,6 @@ export function resolveRuntimeConfig(options = {}) {
475
474
  baseUrl: options.baseUrl || profile.baseUrl || DEFAULT_BASE_URL,
476
475
  instance: options.instance ?? (profile.instance || ''),
477
476
  token: options.token || profile.token || '',
478
- ...(profile.production ? { production: true } : {}),
479
477
  };
480
478
  }
481
479
  const defaultStored = mergeWithLegacy(stored);
@@ -485,6 +485,32 @@ export async function buildMetadataBackfillPlan(input) {
485
485
  });
486
486
  }
487
487
  }
488
+ if (shouldTrackResource(trackedResources, 'service-account') && typeof client.listAllServiceAccounts === 'function') {
489
+ for await (const { listedId, resource: account } of readResourceInventory(client, 'service-account')) {
490
+ if (!listedId) {
491
+ continue;
492
+ }
493
+ const resourceId = resourceIdOf(account) || listedId;
494
+ const existingStableKey = readConfiguredResourceMetadataStableKey(account, stableKeyName);
495
+ const stableKey = existingStableKey && !force
496
+ ? undefined
497
+ : buildNamedResourceGeneratedStableKey(account);
498
+ const plannedStableKey = stableKey || existingStableKey || undefined;
499
+ items.push({
500
+ resourceType: 'service-account',
501
+ resourceId,
502
+ name: String(account.name || ''),
503
+ category: null,
504
+ action: rawConfiguredStableKey(account, stableKeyName).present && !existingStableKey ? 'blocked' : existingStableKey && !force ? 'skip' : 'update',
505
+ metadataField: 'metadata',
506
+ stableKeyName,
507
+ ...(plannedStableKey ? { stableKey: plannedStableKey } : {}),
508
+ reason: existingStableKey
509
+ ? (force ? 'stable key will be regenerated' : 'stable key already exists')
510
+ : 'stable key missing',
511
+ });
512
+ }
513
+ }
488
514
  if (shouldTrackResource(trackedResources, 'role-group') && typeof client.listAllRoleGroups === 'function') {
489
515
  for await (const { listedId, resource: roleGroup } of readResourceInventory(client, 'role-group')) {
490
516
  if (!listedId) {
@@ -714,7 +740,7 @@ export async function applyMetadataBackfillPlan(input) {
714
740
  const resourceTypes = new Set(plan.items.map((item) => item.resourceType));
715
741
  const readOrder = [
716
742
  'component', 'database-table', 'database-view', 'endpoint',
717
- 'role-group', 'group', 'job-template', 'schedule', 'event',
743
+ 'role-group', 'service-account', 'group', 'job-template', 'schedule', 'event',
718
744
  ];
719
745
  for (const resourceType of readOrder) {
720
746
  if (!resourceTypes.has(resourceType)) {
@@ -954,6 +980,29 @@ export async function applyMetadataBackfillPlan(input) {
954
980
  results.push({ resourceType: item.resourceType, resourceId: item.resourceId, stableKey, action: 'update' });
955
981
  continue;
956
982
  }
983
+ if (item.resourceType === 'service-account') {
984
+ const account = await client.getServiceAccount(item.resourceId);
985
+ const current = readConfiguredResourceMetadataStableKey(account, plan.stableKeyName);
986
+ if (current && !plan.force) {
987
+ results.push({ resourceType: item.resourceType, resourceId: item.resourceId, stableKey: current, action: 'skip' });
988
+ continue;
989
+ }
990
+ if (!current && rawConfiguredStableKey(account, plan.stableKeyName).present) {
991
+ throw new Error('Invalid service-account stableKey; refusing to overwrite it.');
992
+ }
993
+ const stableKey = item.stableKey || buildNamedResourceGeneratedStableKey(account);
994
+ if (!Number.isInteger(account.version)) {
995
+ throw new Error('Service-account version is required.');
996
+ }
997
+ await client.updateServiceAccount(item.resourceId, { version: account.version,
998
+ metadata: { ...sanitizeUserMetadata(account.metadata), [plan.stableKeyName]: stableKey } });
999
+ const verified = await client.getServiceAccount(item.resourceId);
1000
+ if (readConfiguredResourceMetadataStableKey(verified, plan.stableKeyName) !== stableKey) {
1001
+ throw new Error('Updated service account did not retain the planned stableKey.');
1002
+ }
1003
+ results.push({ resourceType: item.resourceType, resourceId: item.resourceId, stableKey, action: 'update' });
1004
+ continue;
1005
+ }
957
1006
  if (item.resourceType === 'role-group') {
958
1007
  const roleGroup = currentResources.get(`role-group:${item.resourceId}`);
959
1008
  if (!roleGroup)
@@ -1,3 +1,4 @@
1
+ import { type ServiceAccountsPlan, type ServiceAccountPullResult, type ServiceAccountPushResult } from './resource-syncs/service-account-sync.ts';
1
2
  import { RevoClient } from './client.ts';
2
3
  import { type ComponentPlan, type ComponentSyncResult } from './commands/component.ts';
3
4
  import { type DatabaseSchemaMigrationPolicy, type DatabaseSchemaPullResult, type DatabaseSchemaPushResult, type DatabaseSchemasPlan } from './resource-syncs/database-table-sync.ts';
@@ -8,10 +9,10 @@ import { type GroupPullResult, type GroupPushResult, type GroupsPlan } from './r
8
9
  import { type JobTemplatePullResult, type JobTemplatePushResult, type JobTemplatesPlan } from './resource-syncs/job-template-sync.ts';
9
10
  import { type SchedulePullResult, type SchedulePushResult, type SchedulesPlan } from './resource-syncs/schedule-sync.ts';
10
11
  import { type RoleGroupPullResult, type RoleGroupPushResult, type RoleGroupsPlan } from './resource-syncs/role-group-sync.ts';
11
- export type MigrationResource = 'database-table' | 'database-view' | 'component' | 'job-template' | 'endpoint' | 'schedule' | 'event' | 'group' | 'role-group';
12
+ export type MigrationResource = 'database-table' | 'database-view' | 'component' | 'job-template' | 'endpoint' | 'schedule' | 'event' | 'group' | 'role-group' | 'service-account';
12
13
  export type MigrationVerdict = 'ready' | 'ready-with-warnings' | 'blocked';
13
14
  export type MigrationOperations = Record<'noop' | 'create' | 'update' | 'adopt' | 'excluded' | 'blocked', number>;
14
- type MigrationPushResult = DatabaseSchemaPushResult | DatabaseViewPushResult | ComponentSyncResult | JobTemplatePushResult | EndpointPushResult | SchedulePushResult | EventPushResult | GroupPushResult | RoleGroupPushResult;
15
+ type MigrationPushResult = DatabaseSchemaPushResult | DatabaseViewPushResult | ComponentSyncResult | JobTemplatePushResult | EndpointPushResult | SchedulePushResult | EventPushResult | GroupPushResult | RoleGroupPushResult | ServiceAccountPushResult;
15
16
  export type MigrationPhasePlan = {
16
17
  order: number;
17
18
  resource: MigrationResource;
@@ -48,6 +49,10 @@ export type MigrationPlan = {
48
49
  operations: MigrationOperations;
49
50
  sourcePull: MigrationSourcePullSummary;
50
51
  phases: MigrationPhasePlan[];
52
+ identityOrder?: Array<{
53
+ resource: 'group' | 'service-account';
54
+ stableKey: string;
55
+ }>;
51
56
  databaseSchemas?: DatabaseSchemasPlan;
52
57
  databaseViews?: DatabaseViewsPlan;
53
58
  components?: ComponentPlan;
@@ -57,6 +62,7 @@ export type MigrationPlan = {
57
62
  events?: EventsPlan;
58
63
  groups?: GroupsPlan;
59
64
  roleGroups?: RoleGroupsPlan;
65
+ serviceAccounts?: ServiceAccountsPlan;
60
66
  warnings: string[];
61
67
  blockers: string[];
62
68
  };
@@ -80,6 +86,7 @@ export type MigrationRun = {
80
86
  events?: EventPullResult;
81
87
  groups?: GroupPullResult;
82
88
  roleGroups?: RoleGroupPullResult;
89
+ serviceAccounts?: ServiceAccountPullResult;
83
90
  };
84
91
  plan: MigrationPlan;
85
92
  results: MigrationPushResult[];
@@ -116,6 +123,7 @@ export type ResourcePullResults = {
116
123
  events?: EventPullResult;
117
124
  groups?: GroupPullResult;
118
125
  roleGroups?: RoleGroupPullResult;
126
+ serviceAccounts?: ServiceAccountPullResult;
119
127
  };
120
128
  export type ResourcePullInput = {
121
129
  cwd: string;
@@ -1,4 +1,6 @@
1
1
  import fs from 'node:fs';
2
+ import { planIdentityMigration } from "./resource-syncs/identity-migration.js";
3
+ import { SERVICE_ACCOUNTS_DIRECTORY, buildServiceAccountsPlan, pullServiceAccountsToWorkspace, pushServiceAccounts } from "./resource-syncs/service-account-sync.js";
2
4
  import os from 'node:os';
3
5
  import path from 'node:path';
4
6
  import { RevoClient } from "./client.js";
@@ -19,6 +21,7 @@ const RESOURCE_ORDER = [
19
21
  'database-table',
20
22
  'database-view',
21
23
  'component',
24
+ 'service-account',
22
25
  'job-template',
23
26
  'endpoint',
24
27
  'schedule',
@@ -59,7 +62,6 @@ function migrationPolicy(input) {
59
62
  function viewMigrationPolicy(input, deferPreview = false) {
60
63
  return {
61
64
  ...migrationPolicy(input),
62
- allowActiveScheduleDependencies: true,
63
65
  ...(deferPreview ? { deferPreview: true } : {}),
64
66
  };
65
67
  }
@@ -487,6 +489,24 @@ function summarizeGroupPhase(plan) {
487
489
  blockers,
488
490
  };
489
491
  }
492
+ function serviceAccountItemAction(item) {
493
+ if (item.status === 'manual-owner') {
494
+ return 'excluded';
495
+ }
496
+ return roleGroupItemAction({ ...item, status: item.status });
497
+ }
498
+ function summarizeServiceAccountPhase(plan) {
499
+ const operations = emptyOperations();
500
+ for (const item of plan.items) {
501
+ operations[serviceAccountItemAction(item)] += 1;
502
+ }
503
+ const warnings = [...plan.exclusions,
504
+ ...plan.items.filter((item) => item.status === 'manual-owner').map((item) => `Service account "${item.stableKey}": ${item.reason}.`),
505
+ ...plan.items.filter((item) => item.status === 'create').map((item) => `Service account "${item.stableKey}" will be created active with platform access; configure secrets separately on ${plan.env}.`),
506
+ ];
507
+ return { order: 4, resource: 'service-account', operations, warnings, blockers: plan.blockers,
508
+ needsChanges: operations.create + operations.update > 0, readyToMigrate: plan.blockers.length === 0, verdict: phaseVerdict(plan.blockers, warnings) };
509
+ }
490
510
  function summarizeRoleGroupPhase(plan) {
491
511
  const operations = emptyOperations();
492
512
  for (const item of plan.items) {
@@ -574,6 +594,9 @@ function summarizePulls(mode, pulls) {
574
594
  skipped: pulls.groups.skipped.length,
575
595
  };
576
596
  }
597
+ if (pulls.serviceAccounts) {
598
+ byResource['service-account'] = { pulled: pulls.serviceAccounts.pulled.length, pruned: pulls.serviceAccounts.pruned.length, skipped: pulls.serviceAccounts.skipped.length };
599
+ }
577
600
  if (pulls.roleGroups) {
578
601
  byResource['role-group'] = {
579
602
  pulled: pulls.roleGroups.pulled.length,
@@ -629,6 +652,17 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
629
652
  }
630
653
  }
631
654
  }
655
+ if (phase.resource === 'service-account' && plans.serviceAccounts) {
656
+ for (const item of plans.serviceAccounts.items) {
657
+ const action = serviceAccountItemAction(item);
658
+ if (action === 'create' || action === 'update') {
659
+ gates.push({
660
+ from: action,
661
+ message: `Service Account "${item.stableKey || item.name}" can change environment access and requires --force for repository deployment.`,
662
+ });
663
+ }
664
+ }
665
+ }
632
666
  if (phase.resource === 'role-group' && plans.roleGroups) {
633
667
  for (const item of plans.roleGroups.items) {
634
668
  const action = roleGroupItemAction(item);
@@ -674,82 +708,87 @@ function combinePlan(input) {
674
708
  ...(input.databaseSchemas ? [summarizeSchemaPhase(input.databaseSchemas)] : []),
675
709
  ...(input.databaseViews ? [summarizeViewPhase(input.databaseViews)] : []),
676
710
  ...(input.components ? [summarizeComponentPhase(input.components)] : []),
711
+ ...(input.serviceAccounts ? [summarizeServiceAccountPhase(input.serviceAccounts)] : []),
677
712
  ...(input.jobTemplates ? [summarizeJobTemplatePhase(input.jobTemplates)] : []),
678
713
  ...(input.endpoints ? [summarizeEndpointPhase(input.endpoints)] : []),
679
714
  ...(input.schedules ? [summarizeSchedulePhase(input.schedules)] : []),
680
715
  ...(input.events ? [summarizeEventPhase(input.events)] : []),
681
716
  ...(input.groups ? [summarizeGroupPhase(input.groups)] : []),
682
717
  ...(input.roleGroups ? [summarizeRoleGroupPhase(input.roleGroups)] : []),
683
- ].map((phase) => applyWorkspaceDeploymentPolicy(input.migrationInput, phase, input))
718
+ ].map((phase) => ({ ...phase, order: RESOURCE_ORDER.indexOf(phase.resource) + 1 })).map((phase) => applyWorkspaceDeploymentPolicy(input.migrationInput, phase, input))
684
719
  .map((phase) => {
685
- const pullWarnings = phase.resource === 'database-table'
686
- ? (input.pulls.databaseSchemas?.skipped || []).map((item) => `Source Database Table skipped: ${item.targetPath}: ${item.reason}.`)
687
- : phase.resource === 'database-view'
688
- ? (input.pulls.databaseViews?.skipped || []).map((item) => `Source Database View "${item.stableKey || item.name}" skipped: ${item.reason}.`)
689
- : phase.resource === 'component'
690
- ? (input.pulls.components || [])
691
- .filter((item) => item.status === 'skipped' && item.reason !== 'no changes')
692
- .map((item) => `Source Component skipped: ${item.targetPath}: ${item.reason || 'unknown reason'}.`)
693
- : phase.resource === 'job-template'
694
- ? [
695
- ...(input.pulls.jobTemplates?.skipped || [])
696
- .map((item) => `Source Job Template "${item.name}" skipped: ${item.reason}.`),
697
- ...(input.pulls.jobTemplates?.warnings || [])
698
- .map((item) => `Source Job Template "${item.stableKey}": ${item.reason}.`),
699
- ]
700
- : phase.resource === 'endpoint'
701
- ? (input.pulls.endpoints?.skipped || [])
702
- .map((item) => `Source Endpoint skipped: ${item.targetPath}: ${item.reason}.`)
703
- : phase.resource === 'schedule'
704
- ? [
705
- ...(input.pulls.schedules?.warnings || [])
706
- .map((item) => `Source Schedule "${item.stableKey}": ${item.reason}.`),
707
- ...(input.pulls.schedules?.pulled || [])
708
- .filter(({ manifest }) => manifest.activationCandidate === true)
709
- .map(({ manifest }) => `Source Schedule "${manifest.stableKey}" is an activation candidate; migration syncs its portable definition but does not automatically change target activation state.`),
710
- ]
711
- : phase.resource === 'event'
720
+ const pullWarnings = phase.resource === 'service-account'
721
+ ? (input.pulls.serviceAccounts?.skipped || []).map((item) => `Source Service Account "${item.name}" skipped: ${item.reason}.`)
722
+ : phase.resource === 'database-table'
723
+ ? (input.pulls.databaseSchemas?.skipped || []).map((item) => `Source Database Table skipped: ${item.targetPath}: ${item.reason}.`)
724
+ : phase.resource === 'database-view'
725
+ ? (input.pulls.databaseViews?.skipped || []).map((item) => `Source Database View "${item.stableKey || item.name}" skipped: ${item.reason}.`)
726
+ : phase.resource === 'component'
727
+ ? (input.pulls.components || [])
728
+ .filter((item) => item.status === 'skipped' && item.reason !== 'no changes')
729
+ .map((item) => `Source Component skipped: ${item.targetPath}: ${item.reason || 'unknown reason'}.`)
730
+ : phase.resource === 'job-template'
731
+ ? [
732
+ ...(input.pulls.jobTemplates?.skipped || [])
733
+ .map((item) => `Source Job Template "${item.name}" skipped: ${item.reason}.`),
734
+ ...(input.pulls.jobTemplates?.warnings || [])
735
+ .map((item) => `Source Job Template "${item.stableKey}": ${item.reason}.`),
736
+ ]
737
+ : phase.resource === 'endpoint'
738
+ ? (input.pulls.endpoints?.skipped || [])
739
+ .map((item) => `Source Endpoint skipped: ${item.targetPath}: ${item.reason}.`)
740
+ : phase.resource === 'schedule'
712
741
  ? [
713
- ...(input.pulls.events?.warnings || [])
714
- .map((item) => `Source Event "${item.stableKey}": ${item.reason}.`),
715
- ...(input.pulls.events?.pulled || [])
716
- .filter(({ manifest }) => manifest.active === true)
717
- .map(({ manifest }) => `Source Event "${manifest.stableKey}" is active; migration syncs its portable configuration but does not automatically change target activation state.`),
742
+ ...(input.pulls.schedules?.warnings || [])
743
+ .map((item) => `Source Schedule "${item.stableKey}": ${item.reason}.`),
744
+ ...(input.pulls.schedules?.pulled || [])
745
+ .filter(({ manifest }) => manifest.activationCandidate === true)
746
+ .map(({ manifest }) => `Source Schedule "${manifest.stableKey}" is an activation candidate; migration syncs its portable definition but does not automatically change target activation state.`),
718
747
  ]
719
- : phase.resource === 'group'
748
+ : phase.resource === 'event'
720
749
  ? [
721
- ...(input.pulls.groups?.skipped || [])
722
- .map((item) => `Source Group "${item.name}" skipped: ${item.reason}.`),
723
- ...(input.pulls.groups?.notices || [])
724
- .map((item) => `Source Group "${item.stableKey}": ${item.reason}.`),
750
+ ...(input.pulls.events?.warnings || [])
751
+ .map((item) => `Source Event "${item.stableKey}": ${item.reason}.`),
752
+ ...(input.pulls.events?.pulled || [])
753
+ .filter(({ manifest }) => manifest.active === true)
754
+ .map(({ manifest }) => `Source Event "${manifest.stableKey}" is active; migration syncs its portable configuration but does not automatically change target activation state.`),
725
755
  ]
726
- : (input.pulls.roleGroups?.skipped || [])
727
- .map((item) => `Source Role Group "${item.name}" skipped: ${item.reason}.`);
728
- const pruneWarnings = phase.resource === 'database-table'
729
- ? (input.pulls.databaseSchemas?.pruned || []).map((item) => `Pruned stale source workspace Database Table "${item.stableKey}".`)
730
- : phase.resource === 'database-view'
731
- ? (input.pulls.databaseViews?.pruned || []).map((item) => `Pruned stale source workspace Database View "${item.stableKey}".`)
732
- : phase.resource === 'component'
733
- ? (input.pulls.components || [])
734
- .filter((item) => item.status === 'pruned')
735
- .map((item) => `Pruned stale source workspace Component at "${item.targetPath}".`)
736
- : phase.resource === 'job-template'
737
- ? (input.pulls.jobTemplates?.pruned || [])
738
- .map((item) => `Pruned stale source workspace Job Template "${item.stableKey}".`)
739
- : phase.resource === 'endpoint'
740
- ? (input.pulls.endpoints?.pruned || [])
741
- .map((item) => `Pruned stale source workspace Endpoint "${item.stableKey}".`)
742
- : phase.resource === 'schedule'
743
- ? (input.pulls.schedules?.pruned || [])
744
- .map((item) => `Pruned stale source workspace Schedule "${item.stableKey}".`)
745
- : phase.resource === 'event'
746
- ? (input.pulls.events?.pruned || [])
747
- .map((item) => `Pruned stale source workspace Event "${item.stableKey}".`)
748
- : phase.resource === 'group'
749
- ? (input.pulls.groups?.pruned || [])
750
- .map((item) => `Pruned stale source workspace Group "${item.stableKey}".`)
751
- : (input.pulls.roleGroups?.pruned || [])
752
- .map((item) => `Pruned stale source workspace Role Group "${item.stableKey}".`);
756
+ : phase.resource === 'group'
757
+ ? [
758
+ ...(input.pulls.groups?.skipped || [])
759
+ .map((item) => `Source Group "${item.name}" skipped: ${item.reason}.`),
760
+ ...(input.pulls.groups?.notices || [])
761
+ .map((item) => `Source Group "${item.stableKey}": ${item.reason}.`),
762
+ ]
763
+ : (input.pulls.roleGroups?.skipped || [])
764
+ .map((item) => `Source Role Group "${item.name}" skipped: ${item.reason}.`);
765
+ const pruneWarnings = phase.resource === 'service-account'
766
+ ? (input.pulls.serviceAccounts?.pruned || []).map((item) => `Pruned stale source workspace Service Account "${item.stableKey}".`)
767
+ : phase.resource === 'database-table'
768
+ ? (input.pulls.databaseSchemas?.pruned || []).map((item) => `Pruned stale source workspace Database Table "${item.stableKey}".`)
769
+ : phase.resource === 'database-view'
770
+ ? (input.pulls.databaseViews?.pruned || []).map((item) => `Pruned stale source workspace Database View "${item.stableKey}".`)
771
+ : phase.resource === 'component'
772
+ ? (input.pulls.components || [])
773
+ .filter((item) => item.status === 'pruned')
774
+ .map((item) => `Pruned stale source workspace Component at "${item.targetPath}".`)
775
+ : phase.resource === 'job-template'
776
+ ? (input.pulls.jobTemplates?.pruned || [])
777
+ .map((item) => `Pruned stale source workspace Job Template "${item.stableKey}".`)
778
+ : phase.resource === 'endpoint'
779
+ ? (input.pulls.endpoints?.pruned || [])
780
+ .map((item) => `Pruned stale source workspace Endpoint "${item.stableKey}".`)
781
+ : phase.resource === 'schedule'
782
+ ? (input.pulls.schedules?.pruned || [])
783
+ .map((item) => `Pruned stale source workspace Schedule "${item.stableKey}".`)
784
+ : phase.resource === 'event'
785
+ ? (input.pulls.events?.pruned || [])
786
+ .map((item) => `Pruned stale source workspace Event "${item.stableKey}".`)
787
+ : phase.resource === 'group'
788
+ ? (input.pulls.groups?.pruned || [])
789
+ .map((item) => `Pruned stale source workspace Group "${item.stableKey}".`)
790
+ : (input.pulls.roleGroups?.pruned || [])
791
+ .map((item) => `Pruned stale source workspace Role Group "${item.stableKey}".`);
753
792
  const warnings = [...new Set([...phase.warnings, ...pullWarnings, ...pruneWarnings])];
754
793
  return { ...phase, warnings, verdict: phaseVerdict(phase.blockers, warnings) };
755
794
  });
@@ -783,6 +822,7 @@ function combinePlan(input) {
783
822
  ...(input.events ? { events: input.events } : {}),
784
823
  ...(input.groups ? { groups: input.groups } : {}),
785
824
  ...(input.roleGroups ? { roleGroups: input.roleGroups } : {}),
825
+ ...(input.serviceAccounts ? { serviceAccounts: input.serviceAccounts } : {}),
786
826
  warnings,
787
827
  blockers,
788
828
  };
@@ -817,6 +857,7 @@ function createTemporaryProject(input) {
817
857
  EVENTS_DIRECTORY,
818
858
  GROUPS_DIRECTORY,
819
859
  ROLE_GROUPS_DIRECTORY,
860
+ SERVICE_ACCOUNTS_DIRECTORY,
820
861
  ]) {
821
862
  const sourceDirectory = path.join(workspaceRoot, directory);
822
863
  if (fs.existsSync(sourceDirectory)) {
@@ -928,6 +969,10 @@ export async function pullResourcesToWorkspace(input) {
928
969
  pruneOrphans: input.pruneOrphans === true,
929
970
  }));
930
971
  }
972
+ if (resources.includes('service-account')) {
973
+ pulls.serviceAccounts = await runMigrationStage('source pull', 'service-account', input.sourceLabel, () => pullServiceAccountsToWorkspace({ client, cwd: input.cwd, envName: input.sourceKey, stableKeyName,
974
+ force: input.force === true, pruneOrphans: input.pruneOrphans === true }));
975
+ }
931
976
  if (resources.includes('job-template')) {
932
977
  pulls.jobTemplates = await runMigrationStage('source pull', 'job-template', input.sourceLabel, () => pullJobTemplatesToWorkspace({
933
978
  client,
@@ -1131,12 +1176,20 @@ async function planWorkspace(input) {
1131
1176
  operation: 'plan',
1132
1177
  }), undefined, input.detailedDiff === true))
1133
1178
  : undefined;
1179
+ const identities = await planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources });
1180
+ const serviceAccounts = resources.includes('service-account')
1181
+ ? await runMigrationStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
1182
+ projectedIdentities: identities?.projection })) : undefined;
1183
+ if (serviceAccounts && identities) {
1184
+ serviceAccounts.blockers.push(...identities.blockers);
1185
+ }
1134
1186
  const jobTemplates = resources.includes('job-template')
1135
1187
  ? await runMigrationStage('target plan', 'job-template', environmentLabel, () => buildJobTemplatesPlan({
1136
1188
  client,
1137
1189
  cwd: input.cwd,
1138
1190
  envName: environmentKey,
1139
1191
  stableKeyName,
1192
+ projectedServiceAccounts: identities?.projection.serviceAccounts,
1140
1193
  ...(input.projectDependencies === true && components
1141
1194
  ? { projectedComponents: projectedComponentDependencies(components) }
1142
1195
  : {}),
@@ -1184,8 +1237,12 @@ async function planWorkspace(input) {
1184
1237
  cwd: input.cwd,
1185
1238
  envName: environmentKey,
1186
1239
  stableKeyName,
1240
+ projectedIdentities: identities?.projection,
1187
1241
  }))
1188
1242
  : undefined;
1243
+ if (groups && identities && !serviceAccounts) {
1244
+ groups.blockers.push(...identities.blockers);
1245
+ }
1189
1246
  const roleGroups = resources.includes('role-group')
1190
1247
  ? await runMigrationStage('target plan', 'role-group', environmentLabel, () => buildRoleGroupsPlan({
1191
1248
  client,
@@ -1194,7 +1251,7 @@ async function planWorkspace(input) {
1194
1251
  stableKeyName,
1195
1252
  }))
1196
1253
  : undefined;
1197
- return combinePlan({
1254
+ const combined = combinePlan({
1198
1255
  migrationInput: input,
1199
1256
  sourcePullMode: input.sourcePullMode,
1200
1257
  pulls: input.pulls,
@@ -1207,7 +1264,12 @@ async function planWorkspace(input) {
1207
1264
  events,
1208
1265
  groups,
1209
1266
  roleGroups,
1267
+ serviceAccounts,
1210
1268
  });
1269
+ if (identities) {
1270
+ combined.identityOrder = identities.ordered.map(({ resource, stableKey }) => ({ resource, stableKey }));
1271
+ }
1272
+ return combined;
1211
1273
  }
1212
1274
  export async function buildMigrationPlan(input) {
1213
1275
  requireProject(input);
@@ -1323,6 +1385,7 @@ export async function runMigration(input) {
1323
1385
  events: initialPlan.events,
1324
1386
  groups: initialPlan.groups,
1325
1387
  roleGroups: initialPlan.roleGroups,
1388
+ serviceAccounts: initialPlan.serviceAccounts,
1326
1389
  });
1327
1390
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1328
1391
  }
@@ -1405,6 +1468,32 @@ export async function runMigration(input) {
1405
1468
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1406
1469
  }
1407
1470
  }
1471
+ const identityRun = await planIdentityMigration({ client: targetClient, cwd: input.cwd, stableKeyName, resources });
1472
+ if (identityRun) {
1473
+ if (identityRun.blockers.length > 0) {
1474
+ return { ...base, verdict: 'failed', results, phaseResults };
1475
+ }
1476
+ for (const node of identityRun.ordered) {
1477
+ const pushed = node.resource === 'service-account'
1478
+ ? await pushServiceAccounts({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] })
1479
+ : await pushGroups({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] });
1480
+ const relevant = pushed.results.filter((item) => item.stableKey === node.stableKey);
1481
+ phaseResults[node.resource] = [...(phaseResults[node.resource] || []), ...relevant];
1482
+ results.push(...relevant);
1483
+ if (!resultsAreComplete(relevant)) {
1484
+ return { ...base, verdict: 'failed', results, phaseResults };
1485
+ }
1486
+ }
1487
+ if (resources.includes('service-account')) {
1488
+ const pushed = await pushServiceAccounts({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true });
1489
+ const remaining = pushed.results.filter((item) => !(phaseResults['service-account'] || []).some((prior) => 'stableKey' in prior && prior.stableKey === item.stableKey));
1490
+ phaseResults['service-account'] = [...(phaseResults['service-account'] || []), ...remaining];
1491
+ results.push(...remaining);
1492
+ if (!resultsAreComplete(pushed.results)) {
1493
+ return { ...base, verdict: 'failed', results, phaseResults };
1494
+ }
1495
+ }
1496
+ }
1408
1497
  if (resources.includes('job-template')) {
1409
1498
  const liveJobTemplatePlan = await buildJobTemplatesPlan({
1410
1499
  client: targetClient,
@@ -1568,8 +1657,9 @@ export async function runMigration(input) {
1568
1657
  stableKeyName,
1569
1658
  force: true,
1570
1659
  });
1571
- phaseResults.group = pushed.results;
1572
- results.push(...pushed.results);
1660
+ const groupRemaining = pushed.results.filter((item) => !(phaseResults.group || []).some((prior) => 'stableKey' in prior && prior.stableKey === item.stableKey));
1661
+ phaseResults.group = [...(phaseResults.group || []), ...groupRemaining];
1662
+ results.push(...groupRemaining);
1573
1663
  if (!resultsAreComplete(pushed.results)) {
1574
1664
  const verification = await planWorkspace({
1575
1665
  ...input,
@@ -1,7 +1,8 @@
1
1
  import type { RevoClient } from './client.ts';
2
2
  import type { TrackableResourceType } from './tracked-resources.ts';
3
- import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ScheduleRecord } from './types.ts';
3
+ import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ScheduleRecord, ServiceAccountRecord } from './types.ts';
4
4
  type ResourceRecordMap = {
5
+ 'service-account': ServiceAccountRecord;
5
6
  component: ComponentRecord;
6
7
  'database-table': DatabaseSchemaRecord;
7
8
  'database-view': DatabaseViewRecord;
@@ -13,7 +14,7 @@ type ResourceRecordMap = {
13
14
  event: EventRecord;
14
15
  };
15
16
  export type ResourceRecord = ResourceRecordMap[TrackableResourceType];
16
- export type ResourceInventoryClient = Pick<RevoClient, 'listAllComponents' | 'getComponent' | 'listAllDatabaseSchemas' | 'listAllDatabaseViewsForSync' | 'listAllEndpoints' | 'getEndpoint' | 'listAllRoleGroups' | 'getRoleGroup' | 'listAllGroups' | 'getGroup' | 'listAllJobTemplates' | 'getJobTemplate' | 'listAllSchedules' | 'getSchedule' | 'listAllEvents' | 'getEvent'>;
17
+ export type ResourceInventoryClient = Pick<RevoClient, 'listAllServiceAccounts' | 'getServiceAccount' | 'listAllComponents' | 'getComponent' | 'listAllDatabaseSchemas' | 'listAllDatabaseViewsForSync' | 'listAllEndpoints' | 'getEndpoint' | 'listAllRoleGroups' | 'getRoleGroup' | 'listAllGroups' | 'getGroup' | 'listAllJobTemplates' | 'getJobTemplate' | 'listAllSchedules' | 'getSchedule' | 'listAllEvents' | 'getEvent'>;
17
18
  type InventoryOptions = {
18
19
  skipPartitions?: boolean;
19
20
  };