sf-plugin-permission-sets 0.0.0-dev.20 → 0.0.0-dev.21

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 (71) hide show
  1. package/README.md +19 -16
  2. package/lib/adapters/connection-org-client.d.ts +7 -3
  3. package/lib/adapters/connection-org-client.js +173 -4
  4. package/lib/adapters/connection-org-client.js.map +1 -1
  5. package/lib/commands/ps/apply.d.ts +25 -0
  6. package/lib/commands/ps/apply.js +116 -0
  7. package/lib/commands/ps/apply.js.map +1 -0
  8. package/lib/commands/ps/check.d.ts +1 -1
  9. package/lib/commands/ps/check.js +1 -1
  10. package/lib/commands/ps/check.js.map +1 -1
  11. package/lib/commands/ps/export.d.ts +17 -0
  12. package/lib/commands/ps/export.js +29 -0
  13. package/lib/commands/ps/export.js.map +1 -0
  14. package/lib/commands/ps/plan.d.ts +21 -0
  15. package/lib/commands/ps/plan.js +74 -0
  16. package/lib/commands/ps/plan.js.map +1 -0
  17. package/lib/commands/ps/validate.d.ts +1 -1
  18. package/lib/commands/ps/validate.js +1 -1
  19. package/lib/commands/ps/validate.js.map +1 -1
  20. package/lib/core/diff.d.ts +8 -0
  21. package/lib/core/diff.js +35 -0
  22. package/lib/core/diff.js.map +1 -0
  23. package/lib/core/finding.d.ts +27 -0
  24. package/lib/core/finding.js +22 -0
  25. package/lib/core/finding.js.map +1 -0
  26. package/lib/core/load.js +2 -1
  27. package/lib/core/load.js.map +1 -1
  28. package/lib/core/model.d.ts +38 -7
  29. package/lib/core/normalize.d.ts +5 -1
  30. package/lib/core/normalize.js +6 -9
  31. package/lib/core/normalize.js.map +1 -1
  32. package/lib/core/parse.d.ts +1 -1
  33. package/lib/core/parse.js +3 -8
  34. package/lib/core/parse.js.map +1 -1
  35. package/lib/core/report.d.ts +6 -8
  36. package/lib/core/report.js +45 -11
  37. package/lib/core/report.js.map +1 -1
  38. package/lib/core/resolve.d.ts +6 -1
  39. package/lib/core/resolve.js +31 -12
  40. package/lib/core/resolve.js.map +1 -1
  41. package/lib/core/schema.d.ts +1 -1
  42. package/lib/core/schema.js +2 -6
  43. package/lib/core/schema.js.map +1 -1
  44. package/lib/core/serialize.d.ts +7 -0
  45. package/lib/core/serialize.js +27 -0
  46. package/lib/core/serialize.js.map +1 -0
  47. package/lib/services/adapters/org-client.d.ts +19 -0
  48. package/lib/services/adapters/org-client.js.map +1 -0
  49. package/lib/services/apply.d.ts +40 -0
  50. package/lib/services/apply.js +115 -0
  51. package/lib/services/apply.js.map +1 -0
  52. package/lib/services/check.d.ts +2 -1
  53. package/lib/services/check.js +1 -1
  54. package/lib/services/check.js.map +1 -1
  55. package/lib/services/export.d.ts +13 -0
  56. package/lib/services/export.js +25 -0
  57. package/lib/services/export.js.map +1 -0
  58. package/lib/services/plan.d.ts +35 -0
  59. package/lib/services/plan.js +70 -0
  60. package/lib/services/plan.js.map +1 -0
  61. package/lib/services/validate.d.ts +3 -2
  62. package/lib/services/validate.js +2 -2
  63. package/lib/services/validate.js.map +1 -1
  64. package/messages/ps.apply.md +81 -0
  65. package/messages/ps.export.md +25 -0
  66. package/messages/ps.plan.md +45 -0
  67. package/oclif.manifest.json +267 -1
  68. package/package.json +10 -7
  69. package/lib/services/org-client.d.ts +0 -11
  70. package/lib/services/org-client.js.map +0 -1
  71. /package/lib/services/{org-client.js → adapters/org-client.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { error } from './finding.js';
2
3
  const scopeList = z.array(z.string().min(1)).optional();
3
4
  export const userEntrySchema = z.strictObject({
4
5
  permissionSets: scopeList,
@@ -15,12 +16,7 @@ export function validateFile(data, file) {
15
16
  return { data: parsed.data, findings: [] };
16
17
  }
17
18
  return {
18
- findings: parsed.error.issues.map((issue) => ({
19
- level: 'error',
20
- code: 'SCHEMA',
21
- message: `${issue.path.join('.') || '(root)'}: ${issue.message}`,
22
- file,
23
- })),
19
+ findings: parsed.error.issues.map((issue) => error('SCHEMA', `${issue.path.join('.') || '(root)'}: ${issue.message}`, { file })),
24
20
  };
25
21
  }
26
22
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAExD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,YAAY,CAAC;IAC1C,cAAc,EAAE,SAAS;IACzB,mBAAmB,EAAE,SAAS;IAC9B,qBAAqB,EAAE,SAAS;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC;IACrC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC;CACtD,CAAC,CAAC;AAIH,wFAAwF;AACxF,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,IAAY;IACpD,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO;QACH,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC1C,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,EA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AC,CACrF;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { DesiredAssignment } from './model.js';
2
+ /**
3
+ * Emit canonical (assignee, kind, target) tuples back to a user-keyed YAML
4
+ * document: the inverse of normalize. Usernames and targets are sorted and
5
+ * de-duplicated so the output is deterministic, and empty scopes are omitted.
6
+ */
7
+ export declare function serializeAssignments(assignments: DesiredAssignment[]): string;
@@ -0,0 +1,27 @@
1
+ import { stringify } from 'yaml';
2
+ import { kindKeys } from './normalize.js';
3
+ /**
4
+ * Emit canonical (assignee, kind, target) tuples back to a user-keyed YAML
5
+ * document: the inverse of normalize. Usernames and targets are sorted and
6
+ * de-duplicated so the output is deterministic, and empty scopes are omitted.
7
+ */
8
+ export function serializeAssignments(assignments) {
9
+ const usernames = [...new Set(assignments.map((assignment) => assignment.assignee))].sort();
10
+ const users = {};
11
+ for (const username of usernames) {
12
+ const entry = {};
13
+ for (const [kind, key] of kindKeys) {
14
+ const targets = [
15
+ ...new Set(assignments
16
+ .filter((assignment) => assignment.assignee === username && assignment.kind === kind)
17
+ .map((assignment) => assignment.target)),
18
+ ].sort();
19
+ if (targets.length > 0) {
20
+ entry[key] = targets;
21
+ }
22
+ }
23
+ users[username] = entry;
24
+ }
25
+ return stringify({ users });
26
+ }
27
+ //# sourceMappingURL=serialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/core/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAgC;IACjE,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5F,MAAM,KAAK,GAAuB,EAAE,CAAC;IAErC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,KAAK,GAA+B,EAAE,CAAC;QAE7C,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG;gBACZ,GAAG,IAAI,GAAG,CACN,WAAW;qBACN,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,QAAQ,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC;qBACpF,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAC9C;aACJ,CAAC,IAAI,EAAE,CAAC;YAET,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;YACzB,CAAC;QACL,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ActualAssignment, AssignmentOutcome, DesiredAssignment, Kind, OrgTarget, OrgUser, ResolvedAddition, TargetRef } from '../../core/model.js';
2
+ /**
3
+ * Port: the org operations a service needs, in domain terms. Declared here, by the
4
+ * consumer, so services depend on the abstraction and the adapter implements it.
5
+ */
6
+ export interface OrgClient {
7
+ /** The users that exist in the org, among the given usernames. */
8
+ findUsers(usernames: string[]): Promise<OrgUser[]>;
9
+ /** The targets (with ids) that exist in the org, among the given names of one kind. */
10
+ findTargets(kind: Kind, names: string[]): Promise<OrgTarget[]>;
11
+ /** Every assignable permission set, group, and license assignment held by active users. */
12
+ listAssignments(): Promise<DesiredAssignment[]>;
13
+ /** The current assignments of the given managed targets, with their record ids. */
14
+ currentAssignments(targets: TargetRef[]): Promise<ActualAssignment[]>;
15
+ /** Insert the given assignments, reporting per-record success or failure. */
16
+ addAssignments(additions: ResolvedAddition[]): Promise<AssignmentOutcome[]>;
17
+ /** Delete the given assignments by record id, reporting per-record success or failure. */
18
+ removeAssignments(removals: ActualAssignment[]): Promise<AssignmentOutcome[]>;
19
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-client.js","sourceRoot":"","sources":["../../../src/services/adapters/org-client.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { AssignmentOutcome, Diff } from '../core/model.js';
2
+ import { Finding } from '../core/finding.js';
3
+ import { OrgClient } from './adapters/org-client.js';
4
+ export type ApplyMode = 'additive' | 'destructive' | 'sync';
5
+ export type ApplyInput = {
6
+ mode: ApplyMode;
7
+ maxDeletes: number;
8
+ dryRun: boolean;
9
+ };
10
+ /** How a run ended, so the command can report and set the exit code. */
11
+ export type ApplyStatus = 'applied' | 'dry-run' | 'declined' | 'max-deletes-exceeded' | 'invalid';
12
+ export type ApplyResult = {
13
+ files: string[];
14
+ findings: Finding[];
15
+ diff: Diff;
16
+ /** What the chosen mode did not act on (surfaced as drift). */
17
+ drift: {
18
+ adds: number;
19
+ removes: number;
20
+ };
21
+ outcomes: AssignmentOutcome[];
22
+ status: ApplyStatus;
23
+ failed: boolean;
24
+ };
25
+ /**
26
+ * Online apply: load the files, resolve every reference to an org id, diff against
27
+ * the org's current state, then add and/or remove per the mode. Deletions are
28
+ * capped by maxDeletes and gated by an injected confirmation.
29
+ */
30
+ export declare class ApplyService {
31
+ private readonly org;
32
+ private readonly files;
33
+ private readonly input;
34
+ private readonly confirmDeletions;
35
+ constructor(org: OrgClient, files: string[], input: ApplyInput, confirmDeletions: (count: number) => Promise<boolean>);
36
+ run(): Promise<ApplyResult>;
37
+ /** Look every declared reference up in the org, returning findings and the id maps. */
38
+ private resolve;
39
+ private execute;
40
+ }
@@ -0,0 +1,115 @@
1
+ import { loadFiles } from '../core/load.js';
2
+ import { diffAssignments } from '../core/diff.js';
3
+ import { kinds, distinctAssignees, distinctTargets, evaluateUsers, evaluateTargets, indexUsersById, indexTargetsById, } from '../core/resolve.js';
4
+ import { countFindings } from '../core/finding.js';
5
+ const emptyDiff = { toAdd: [], toRemove: [], unchanged: [] };
6
+ /** An aborted-before-any-change result, carrying the findings that explain why. */
7
+ function invalidResult(files, findings) {
8
+ return {
9
+ files,
10
+ findings,
11
+ diff: emptyDiff,
12
+ drift: { adds: 0, removes: 0 },
13
+ outcomes: [],
14
+ status: 'invalid',
15
+ failed: true,
16
+ };
17
+ }
18
+ /** The resolved ids of every declared target, to fetch their current memberships. */
19
+ function managedTargets(resolution) {
20
+ const refs = [];
21
+ for (const kind of kinds) {
22
+ for (const id of resolution.targetIds[kind].values()) {
23
+ refs.push({ kind, id });
24
+ }
25
+ }
26
+ return refs;
27
+ }
28
+ /**
29
+ * Online apply: load the files, resolve every reference to an org id, diff against
30
+ * the org's current state, then add and/or remove per the mode. Deletions are
31
+ * capped by maxDeletes and gated by an injected confirmation.
32
+ */
33
+ export class ApplyService {
34
+ org;
35
+ files;
36
+ input;
37
+ confirmDeletions;
38
+ constructor(org, files, input, confirmDeletions) {
39
+ this.org = org;
40
+ this.files = files;
41
+ this.input = input;
42
+ this.confirmDeletions = confirmDeletions;
43
+ }
44
+ async run() {
45
+ const loaded = await loadFiles(this.files);
46
+ if (countFindings(loaded.findings).errors > 0) {
47
+ return invalidResult(loaded.files, loaded.findings);
48
+ }
49
+ const resolution = await this.resolve(loaded.assignments);
50
+ const findings = [...loaded.findings, ...resolution.findings];
51
+ if (countFindings(findings).errors > 0) {
52
+ return invalidResult(loaded.files, findings);
53
+ }
54
+ const actual = await this.org.currentAssignments(managedTargets(resolution));
55
+ const diff = diffAssignments(loaded.assignments, actual);
56
+ const { mode, maxDeletes, dryRun } = this.input;
57
+ const additions = mode === 'destructive' ? [] : diff.toAdd;
58
+ const removals = mode === 'additive' ? [] : diff.toRemove;
59
+ const drift = {
60
+ adds: mode === 'destructive' ? diff.toAdd.length : 0,
61
+ removes: mode === 'additive' ? diff.toRemove.length : 0,
62
+ };
63
+ if (removals.length > maxDeletes) {
64
+ return {
65
+ files: loaded.files,
66
+ findings,
67
+ diff,
68
+ drift,
69
+ outcomes: [],
70
+ status: 'max-deletes-exceeded',
71
+ failed: true,
72
+ };
73
+ }
74
+ if (dryRun) {
75
+ return { files: loaded.files, findings, diff, drift, outcomes: [], status: 'dry-run', failed: false };
76
+ }
77
+ if (removals.length > 0) {
78
+ const confirmed = await this.confirmDeletions(removals.length);
79
+ if (!confirmed) {
80
+ return { files: loaded.files, findings, diff, drift, outcomes: [], status: 'declined', failed: false };
81
+ }
82
+ }
83
+ const outcomes = await this.execute(additions, removals, resolution);
84
+ const failed = outcomes.some((outcome) => !outcome.success);
85
+ return { files: loaded.files, findings, diff, drift, outcomes, status: 'applied', failed };
86
+ }
87
+ /** Look every declared reference up in the org, returning findings and the id maps. */
88
+ async resolve(assignments) {
89
+ const usernames = distinctAssignees(assignments);
90
+ const targetsByKind = kinds.map((kind) => ({ kind, targets: distinctTargets(assignments, kind) }));
91
+ const usersTask = usernames.length > 0 ? this.org.findUsers(usernames) : Promise.resolve([]);
92
+ const targetsTask = Promise.all(targetsByKind.map(({ kind, targets }) => (targets.length > 0 ? this.org.findTargets(kind, targets) : Promise.resolve([])).then((found) => ({ kind, targets, found }))));
93
+ const [foundUsers, perKind] = await Promise.all([usersTask, targetsTask]);
94
+ const findings = [...evaluateUsers(usernames, foundUsers)];
95
+ const targetIds = {};
96
+ for (const { kind, targets, found } of perKind) {
97
+ findings.push(...evaluateTargets(kind, targets, found.map((target) => target.name)));
98
+ targetIds[kind] = indexTargetsById(found);
99
+ }
100
+ return { findings, userIds: indexUsersById(foundUsers), targetIds };
101
+ }
102
+ async execute(additions, removals, resolution) {
103
+ const resolved = additions.map((addition) => ({
104
+ ...addition,
105
+ assigneeId: resolution.userIds.get(addition.assignee.toLowerCase()) ?? '',
106
+ targetId: resolution.targetIds[addition.kind].get(addition.target.toLowerCase()) ?? '',
107
+ }));
108
+ const [added, removed] = await Promise.all([
109
+ resolved.length > 0 ? this.org.addAssignments(resolved) : Promise.resolve([]),
110
+ removals.length > 0 ? this.org.removeAssignments(removals) : Promise.resolve([]),
111
+ ]);
112
+ return [...added, ...removed];
113
+ }
114
+ }
115
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/services/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACH,KAAK,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,EACd,gBAAgB,GACnB,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAW,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA+B5D,MAAM,SAAS,GAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAEnE,mFAAmF;AACnF,SAAS,aAAa,CAAC,KAAe,EAAE,QAAmB;IACvD,OAAO;QACH,KAAK;QACL,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;QAC9B,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,IAAI;KACf,CAAC;AACN,CAAC;AAED,qFAAqF;AACrF,SAAS,cAAc,CAAC,UAAsB;IAC1C,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,KAAK,MAAM,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACnD,IAAI,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,EAAE;SACzF,CAAC,CAAC,CAAC;QAEJ,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACvC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAsB,EAAE,CAAC;YAClG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAsB,EAAE,CAAC;SACxG,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC;IAClC,CAAC;CACJ"}
@@ -1,4 +1,5 @@
1
- import { DesiredAssignment, Finding } from '../core/model.js';
1
+ import { DesiredAssignment } from '../core/model.js';
2
+ import { Finding } from '../core/finding.js';
2
3
  export type CheckResult = {
3
4
  files: string[];
4
5
  assignments: DesiredAssignment[];
@@ -1,5 +1,5 @@
1
1
  import { loadFiles } from '../core/load.js';
2
- import { countFindings } from '../core/report.js';
2
+ import { countFindings } from '../core/finding.js';
3
3
  /** Offline check: load the files, validate them, and summarize the findings. */
4
4
  export class CheckService {
5
5
  files;
@@ -1 +1 @@
1
- {"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/services/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAYlD,gFAAgF;AAChF,MAAM,OAAO,YAAY;IACe;IAAkC;IAAtE,YAAoC,KAAe,EAAmB,MAAe;QAAjD,UAAK,GAAL,KAAK,CAAU;QAAmB,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAElF,KAAK,CAAC,GAAG;QACZ,MAAM,M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,MAAM;SACT,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,13 @@
1
+ import { OrgClient } from './adapters/org-client.js';
2
+ export type ExportResult = {
3
+ outputFile: string;
4
+ users: number;
5
+ assignments: number;
6
+ };
7
+ /** Online export: read the org's current assignments and write them as a YAML file. */
8
+ export declare class ExportService {
9
+ private readonly org;
10
+ private readonly outputFile;
11
+ constructor(org: OrgClient, outputFile: string);
12
+ run(): Promise<ExportResult>;
13
+ }
@@ -0,0 +1,25 @@
1
+ import { writeFile, mkdir } from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { serializeAssignments } from '../core/serialize.js';
4
+ /** Online export: read the org's current assignments and write them as a YAML file. */
5
+ export class ExportService {
6
+ org;
7
+ outputFile;
8
+ constructor(org, outputFile) {
9
+ this.org = org;
10
+ this.outputFile = outputFile;
11
+ }
12
+ async run() {
13
+ const assignments = await this.org.listAssignments();
14
+ const content = serializeAssignments(assignments);
15
+ await mkdir(dirname(this.outputFile), { recursive: true });
16
+ await writeFile(this.outputFile, content, 'utf8');
17
+ const assignees = new Set(assignments.map((assignment) => assignment.assignee));
18
+ return {
19
+ outputFile: this.outputFile,
20
+ users: assignees.size,
21
+ assignments: assignments.length,
22
+ };
23
+ }
24
+ }
25
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/services/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAS5D,uFAAuF;AACvF,MAAM,OAAO,aAAa;IACc;IAAiC;IAArE,YAAoC,GAAc,EAAmB,UAAkB;QAAnD,QAAG,GAAH,GAAG,CAAW;QAAmB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAEpF,KAAK,CAAC,GAAG;QACZ,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;QACrD,MAAM,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAElD,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAElD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEhF,OAAO;YACH,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,KAAK,EAAE,SAAS,CAAC,IAAI;YACrB,WAAW,EAAE,WAAW,CAAC,MAAM;SAClC,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,35 @@
1
+ import { Diff } from '../core/model.js';
2
+ import { Finding } from '../core/finding.js';
3
+ import { OrgClient } from './adapters/org-client.js';
4
+ export type PlanMode = 'additive' | 'destructive' | 'sync';
5
+ export type PlanInput = {
6
+ mode: PlanMode;
7
+ };
8
+ /** How a run ended, so the command can report and set the exit code. */
9
+ export type PlanStatus = 'planned' | 'invalid';
10
+ export type PlanResult = {
11
+ files: string[];
12
+ findings: Finding[];
13
+ diff: Diff;
14
+ /** What the chosen mode would not act on (surfaced as drift). */
15
+ drift: {
16
+ adds: number;
17
+ removes: number;
18
+ };
19
+ status: PlanStatus;
20
+ };
21
+ /**
22
+ * Read-only preview: load the files, resolve every reference to an org id, fetch the
23
+ * current state, and diff. The full diff (adds and would-be removes) is always returned
24
+ * regardless of mode; drift is whatever the chosen mode would not act on. Never changes
25
+ * the org. This is the apply pipeline stopping before any DML.
26
+ */
27
+ export declare class PlanService {
28
+ private readonly org;
29
+ private readonly files;
30
+ private readonly input;
31
+ constructor(org: OrgClient, files: string[], input: PlanInput);
32
+ run(): Promise<PlanResult>;
33
+ /** Look every declared reference up in the org, returning findings and the target id maps. */
34
+ private resolve;
35
+ }
@@ -0,0 +1,70 @@
1
+ import { loadFiles } from '../core/load.js';
2
+ import { diffAssignments } from '../core/diff.js';
3
+ import { kinds, distinctAssignees, distinctTargets, evaluateUsers, evaluateTargets, indexTargetsById, } from '../core/resolve.js';
4
+ import { countFindings } from '../core/finding.js';
5
+ const emptyDiff = { toAdd: [], toRemove: [], unchanged: [] };
6
+ /** An aborted-before-the-diff result, carrying the findings that explain why. */
7
+ function invalidResult(files, findings) {
8
+ return { files, findings, diff: emptyDiff, drift: { adds: 0, removes: 0 }, status: 'invalid' };
9
+ }
10
+ /**
11
+ * Read-only preview: load the files, resolve every reference to an org id, fetch the
12
+ * current state, and diff. The full diff (adds and would-be removes) is always returned
13
+ * regardless of mode; drift is whatever the chosen mode would not act on. Never changes
14
+ * the org. This is the apply pipeline stopping before any DML.
15
+ */
16
+ export class PlanService {
17
+ org;
18
+ files;
19
+ input;
20
+ constructor(org, files, input) {
21
+ this.org = org;
22
+ this.files = files;
23
+ this.input = input;
24
+ }
25
+ async run() {
26
+ const loaded = await loadFiles(this.files);
27
+ if (countFindings(loaded.findings).errors > 0) {
28
+ return invalidResult(loaded.files, loaded.findings);
29
+ }
30
+ const resolution = await this.resolve(loaded.assignments);
31
+ const findings = [...loaded.findings, ...resolution.findings];
32
+ if (countFindings(findings).errors > 0) {
33
+ return invalidResult(loaded.files, findings);
34
+ }
35
+ const actual = await this.org.currentAssignments(managedTargets(resolution));
36
+ const diff = diffAssignments(loaded.assignments, actual);
37
+ const { mode } = this.input;
38
+ const drift = {
39
+ adds: mode === 'destructive' ? diff.toAdd.length : 0,
40
+ removes: mode === 'additive' ? diff.toRemove.length : 0,
41
+ };
42
+ return { files: loaded.files, findings, diff, drift, status: 'planned' };
43
+ }
44
+ /** Look every declared reference up in the org, returning findings and the target id maps. */
45
+ async resolve(assignments) {
46
+ const usernames = distinctAssignees(assignments);
47
+ const targetsByKind = kinds.map((kind) => ({ kind, targets: distinctTargets(assignments, kind) }));
48
+ const usersTask = usernames.length > 0 ? this.org.findUsers(usernames) : Promise.resolve([]);
49
+ const targetsTask = Promise.all(targetsByKind.map(({ kind, targets }) => (targets.length > 0 ? this.org.findTargets(kind, targets) : Promise.resolve([])).then((found) => ({ kind, targets, found }))));
50
+ const [foundUsers, perKind] = await Promise.all([usersTask, targetsTask]);
51
+ const findings = [...evaluateUsers(usernames, foundUsers)];
52
+ const targetIds = {};
53
+ for (const { kind, targets, found } of perKind) {
54
+ findings.push(...evaluateTargets(kind, targets, found.map((target) => target.name)));
55
+ targetIds[kind] = indexTargetsById(found);
56
+ }
57
+ return { findings, targetIds };
58
+ }
59
+ }
60
+ /** The resolved ids of every declared target, to fetch their current memberships. */
61
+ function managedTargets(resolution) {
62
+ const refs = [];
63
+ for (const kind of kinds) {
64
+ for (const id of resolution.targetIds[kind].values()) {
65
+ refs.push({ kind, id });
66
+ }
67
+ }
68
+ return refs;
69
+ }
70
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/services/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACH,KAAK,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,eAAe,EACf,gBAAgB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAW,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA2B5D,MAAM,SAAS,GAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAEnE,iFAAiF;AACjF,SAAS,aAAa,CAAC,KAAe,EAAE,QAAmB;IACvD,OAAO,EAAE,KAAK,E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AAC,CACxC,CACJ,CACJ,CAAC;QAEF,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;QAE1E,MAAM,QAAQ,GAAc,CAAC,GAAG,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;QACtE,MAAM,SAAS,GAAG,EAAuC,CAAC;QAC1D,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC;YAC7C,QAAQ,CAAC,IAAI,CACT,GAAG,eAAe,CACd,IAAI,EACJ,OAAO,EACP,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CACrC,CACJ,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACnC,CAAC;CACJ;AAED,qFAAqF;AACrF,SAAS,cAAc,CAAC,UAAsB;IAC1C,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,KAAK,MAAM,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACnD,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5B,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -1,5 +1,6 @@
1
- import { DesiredAssignment, Finding } from '../core/model.js';
2
- import { OrgClient } from './org-client.js';
1
+ import { DesiredAssignment } from '../core/model.js';
2
+ import { Finding } from '../core/finding.js';
3
+ import { OrgClient } from './adapters/org-client.js';
3
4
  export type ValidateResult = {
4
5
  files: string[];
5
6
  assignments: DesiredAssignment[];
@@ -1,6 +1,6 @@
1
1
  import { loadFiles } from '../core/load.js';
2
- import { countFindings } from '../core/report.js';
3
2
  import { kinds, distinctAssignees, distinctTargets, evaluateUsers, evaluateTargets } from '../core/resolve.js';
3
+ import { countFindings } from '../core/finding.js';
4
4
  /** Online validate: run the offline load, then resolve every reference against the org. */
5
5
  export class ValidateService {
6
6
  org;
@@ -33,7 +33,7 @@ export class ValidateService {
33
33
  for (const kind of kinds) {
34
34
  const targets = distinctTargets(assignments, kind);
35
35
  if (targets.length > 0) {
36
- tasks.push(this.org.findTargets(kind, targets).then((found) => evaluateTargets(kind, targets, found)));
36
+ tasks.push(this.org.findTargets(kind, targets).then((found) => evaluateTargets(kind, targets, found.map((target) => target.name))));
37
37
  }
38
38
  }
39
39
  const results = await Promise.all(tasks);
@@ -1 +1 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/services/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAa/G,2FAA2F;AAC3F,MAAM,OAAO,eAAe;IACY;IAAiC;IAArE,YAAoC,GAAc,EAAmB,KAAe;QAAhD,QAAG,GAAH,GAAG,CAAW;QAAmB,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAEjF,KAAK,CAAC,GAAG;QACZ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;QACj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AC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/F,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,OAAO,GAAG,eAAe,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACnD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,KAAK,CAAC,IAAI,CACN,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAC/C,eAAe,CACX,IAAI,EACJ,OAAO,EACP,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CACrC,CACJ,CACJ,CAAC;YACN,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;CACJ"}
@@ -0,0 +1,81 @@
1
+ # summary
2
+
3
+ Reconcile a target org to match the permission set assignment files.
4
+
5
+ # description
6
+
7
+ Load the files, resolve every user and target against the org, diff the desired state against what the org currently has, then add and/or remove assignments per the mode. Additions and removals run through the sObject Collections API with partial success, so one bad record does not roll back the rest. Deletions are capped by --max-deletes and confirmed before they run. Run validate and a --dry-run first.
8
+
9
+ # flags.file.summary
10
+
11
+ YAML file or glob to apply. Repeatable.
12
+
13
+ # flags.mode.summary
14
+
15
+ Which half of the reconcile to run: additive adds only, destructive removes only, sync does both.
16
+
17
+ # flags.max-deletes.summary
18
+
19
+ Abort before any change if the run would remove more than this many assignments.
20
+
21
+ # flags.dry-run.summary
22
+
23
+ Resolve and diff, print the plan, and change nothing.
24
+
25
+ # flags.no-prompt.summary
26
+
27
+ Skip the deletion confirmation prompt. Required to delete in JSON or other non-interactive runs.
28
+
29
+ # confirm.delete
30
+
31
+ This will remove %s assignment(s) from the org. Continue?
32
+
33
+ # summary.dryRun
34
+
35
+ Dry run: %s to add, %s to remove. Nothing was changed.
36
+
37
+ # summary.applied
38
+
39
+ Applied: %s added, %s removed.
40
+
41
+ # summary.declined
42
+
43
+ Aborted at the confirmation prompt. Nothing was changed.
44
+
45
+ # drift.note
46
+
47
+ %s change(s) the %s mode does not act on were skipped (drift). Run plan to see them.
48
+
49
+ # failure.line
50
+
51
+ failed to %s %s on %s: %s
52
+
53
+ # error.invalid
54
+
55
+ The files do not resolve cleanly against the org. Fix the errors above, then re-run.
56
+
57
+ # error.maxDeletes
58
+
59
+ Refusing to remove %s assignment(s): over the --max-deletes limit of %s. Raise the limit or narrow the change.
60
+
61
+ # error.promptInJson
62
+
63
+ Refusing to delete without confirmation in a non-interactive run. Re-run with --no-prompt.
64
+
65
+ # error.failed
66
+
67
+ Some changes failed. See the per-record errors above.
68
+
69
+ # examples
70
+
71
+ - Preview a full reconcile of the dev org without changing anything:
72
+
73
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org dev --mode sync --dry-run
74
+
75
+ - Grant any missing assignments (additive, the default):
76
+
77
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org dev
78
+
79
+ - Full reconcile of production in CI, without prompts:
80
+
81
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org prod --mode sync --no-prompt
@@ -0,0 +1,25 @@
1
+ # summary
2
+
3
+ Generate a YAML file from the current org's permission set assignments.
4
+
5
+ # description
6
+
7
+ Query the target org for every assignable permission set, group, and license assignment held by active users and write them to a single user-keyed YAML file. The result is valid input for check, validate, plan, and apply, so it is a read-only way to bootstrap adoption from an org's current state. Profile-owned permission sets and inactive users are skipped.
8
+
9
+ # flags.output-file.summary
10
+
11
+ Path of the YAML file to write. Created (and its parent directories) if missing, overwritten if present.
12
+
13
+ # success
14
+
15
+ Exported %s assignments across %s users to %s.
16
+
17
+ # examples
18
+
19
+ - Export the dev org's assignments to permissions.yml:
20
+
21
+ <%= config.bin %> <%= command.id %> --target-org dev --output-file permissions.yml
22
+
23
+ - Export a production org into an environment folder:
24
+
25
+ <%= config.bin %> <%= command.id %> --target-org prod --output-file permissions/prod.yml
@@ -0,0 +1,45 @@
1
+ # summary
2
+
3
+ Preview the changes that would reconcile a target org to the assignment files.
4
+
5
+ # description
6
+
7
+ Load the files, resolve every user and target against the org, fetch the org's current assignments, and diff the desired state against them. Read-only: it queries the org but never changes it, so it is the apply pipeline stopping before any DML. The full picture (assignments to add and would-be removes) is always shown regardless of mode, and whatever the chosen mode would not act on is surfaced as drift. Run it before apply to preview what would change.
8
+
9
+ # flags.file.summary
10
+
11
+ YAML file or glob to plan. Repeatable.
12
+
13
+ # flags.mode.summary
14
+
15
+ Which half of the reconcile to preview: additive adds only, destructive removes only, sync does both. Adds and removes are always shown either way.
16
+
17
+ # summary.counts
18
+
19
+ Plan: %s to add, %s to remove, %s unchanged.
20
+
21
+ # summary.next
22
+
23
+ Reviewed the plan? Apply it with the same files: sf ps apply --mode %s
24
+
25
+ # drift.note
26
+
27
+ %s change(s) the %s mode does not act on were surfaced as drift.
28
+
29
+ # error.invalid
30
+
31
+ The files do not resolve cleanly against the org. Fix the errors above, then re-run.
32
+
33
+ # examples
34
+
35
+ - Preview a full reconcile of the dev org:
36
+
37
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org dev --mode sync
38
+
39
+ - Preview only the additions the default additive run would make:
40
+
41
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org dev
42
+
43
+ - Preview a full reconcile of production before applying it:
44
+
45
+ <%= config.bin %> <%= command.id %> --file "permissions/*.yml" --target-org prod --mode sync