sf-plugin-permission-sets 0.0.0-dev.9 → 0.2.0
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.
- package/README.md +126 -79
- package/lib/adapters/connection-org-client.d.ts +16 -0
- package/lib/adapters/connection-org-client.js +248 -0
- package/lib/adapters/connection-org-client.js.map +1 -0
- package/lib/commands/ps/apply.d.ts +27 -0
- package/lib/commands/ps/apply.js +125 -0
- package/lib/commands/ps/apply.js.map +1 -0
- package/lib/commands/ps/check.d.ts +18 -0
- package/lib/commands/ps/check.js +46 -0
- package/lib/commands/ps/check.js.map +1 -0
- package/lib/commands/ps/export.d.ts +17 -0
- package/lib/commands/ps/export.js +29 -0
- package/lib/commands/ps/export.js.map +1 -0
- package/lib/commands/ps/plan.d.ts +22 -0
- package/lib/commands/ps/plan.js +78 -0
- package/lib/commands/ps/plan.js.map +1 -0
- package/lib/commands/ps/validate.d.ts +19 -0
- package/lib/commands/ps/validate.js +48 -0
- package/lib/commands/ps/validate.js.map +1 -0
- package/lib/core/diff.d.ts +9 -0
- package/lib/core/diff.js +53 -0
- package/lib/core/diff.js.map +1 -0
- package/lib/core/finding.d.ts +39 -0
- package/lib/core/finding.js +68 -0
- package/lib/core/finding.js.map +1 -0
- package/lib/core/load.d.ts +3 -0
- package/lib/core/load.js +53 -0
- package/lib/core/load.js.map +1 -0
- package/lib/core/model.d.ts +68 -0
- package/lib/core/model.js +2 -0
- package/lib/core/model.js.map +1 -0
- package/lib/core/normalize.d.ts +14 -0
- package/lib/core/normalize.js +44 -0
- package/lib/core/normalize.js.map +1 -0
- package/lib/core/parse.d.ts +9 -0
- package/lib/core/parse.js +20 -0
- package/lib/core/parse.js.map +1 -0
- package/lib/core/report.d.ts +7 -0
- package/lib/core/report.js +62 -0
- package/lib/core/report.js.map +1 -0
- package/lib/core/resolve.d.ts +19 -0
- package/lib/core/resolve.js +88 -0
- package/lib/core/resolve.js.map +1 -0
- package/lib/core/schema.d.ts +32 -0
- package/lib/core/schema.js +30 -0
- package/lib/core/schema.js.map +1 -0
- package/lib/core/serialize.d.ts +8 -0
- package/lib/core/serialize.js +34 -0
- package/lib/core/serialize.js.map +1 -0
- package/lib/services/adapters/org-client.d.ts +21 -0
- package/lib/services/adapters/org-client.js +2 -0
- package/lib/services/adapters/org-client.js.map +1 -0
- package/lib/services/apply.d.ts +41 -0
- package/lib/services/apply.js +118 -0
- package/lib/services/apply.js.map +1 -0
- package/lib/services/check.d.ts +17 -0
- package/lib/services/check.js +25 -0
- package/lib/services/check.js.map +1 -0
- package/lib/services/export.d.ts +13 -0
- package/lib/services/export.js +25 -0
- package/lib/services/export.js.map +1 -0
- package/lib/services/plan.d.ts +36 -0
- package/lib/services/plan.js +71 -0
- package/lib/services/plan.js.map +1 -0
- package/lib/services/validate.d.ts +20 -0
- package/lib/services/validate.js +43 -0
- package/lib/services/validate.js.map +1 -0
- package/messages/ps.apply.md +81 -0
- package/messages/ps.check.md +33 -0
- package/messages/ps.export.md +25 -0
- package/messages/ps.plan.md +45 -0
- package/messages/ps.validate.md +29 -0
- package/oclif.lock +570 -1
- package/oclif.manifest.json +364 -9
- package/package.json +22 -31
- package/lib/commands/ps/info.d.ts +0 -11
- package/lib/commands/ps/info.js +0 -17
- package/lib/commands/ps/info.js.map +0 -1
- package/messages/ps.info.md +0 -17
package/lib/core/load.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { globby } from 'globby';
|
|
3
|
+
import { parseFile } from './parse.js';
|
|
4
|
+
import { validateFile } from './schema.js';
|
|
5
|
+
import { normalize } from './normalize.js';
|
|
6
|
+
import { noFilesError } from './finding.js';
|
|
7
|
+
/** Process one file's text through parse, validate, and normalize. Pure, no disk. */
|
|
8
|
+
function checkContent(text, file) {
|
|
9
|
+
const parsed = parseFile(text, file);
|
|
10
|
+
if (!parsed.data) {
|
|
11
|
+
return { assignments: [], findings: parsed.findings };
|
|
12
|
+
}
|
|
13
|
+
const validated = validateFile(parsed.data, file);
|
|
14
|
+
if (!validated.data) {
|
|
15
|
+
return { assignments: [], findings: [...parsed.findings, ...validated.findings] };
|
|
16
|
+
}
|
|
17
|
+
const normalized = normalize(validated.data, file);
|
|
18
|
+
return {
|
|
19
|
+
assignments: normalized.assignments,
|
|
20
|
+
findings: [...parsed.findings, ...validated.findings, ...normalized.findings],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Expand the globs, read every matched file, and merge into one model by union. */
|
|
24
|
+
export async function loadFiles(patterns) {
|
|
25
|
+
const files = await globby(patterns);
|
|
26
|
+
if (files.length === 0) {
|
|
27
|
+
return {
|
|
28
|
+
files,
|
|
29
|
+
assignments: [],
|
|
30
|
+
findings: [noFilesError(patterns)],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const findings = [];
|
|
34
|
+
const collected = [];
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
// eslint-disable-next-line no-await-in-loop
|
|
37
|
+
const text = await readFile(file, 'utf8');
|
|
38
|
+
const res = checkContent(text, file);
|
|
39
|
+
findings.push(...res.findings);
|
|
40
|
+
collected.push(...res.assignments);
|
|
41
|
+
}
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
const assignments = [];
|
|
44
|
+
for (const assignment of collected) {
|
|
45
|
+
const dedupeKey = `${assignment.assignee} ${assignment.kind} ${assignment.target}`;
|
|
46
|
+
if (seen.has(dedupeKey))
|
|
47
|
+
continue;
|
|
48
|
+
seen.add(dedupeKey);
|
|
49
|
+
assignments.push(assignment);
|
|
50
|
+
}
|
|
51
|
+
return { files, assignments, findings };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/core/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM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AK;YACL,WAAW,EAAE,EAAE;YACf,QAAQ,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;SACrC,CAAC;IACN,CAAC;IAED,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,MAAM,SAAS,GAAwB,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,4CAA4C;QAC5C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/B,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,WAAW,GAAwB,EAAE,CAAC;IAE5C,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,GAAG,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;QACnF,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,SAAS;QAClC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpB,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Finding } from './finding.js';
|
|
2
|
+
export type Kind = 'permissionSet' | 'permissionSetGroup' | 'permissionSetLicense';
|
|
3
|
+
export type DesiredAssignment = {
|
|
4
|
+
assignee: string;
|
|
5
|
+
kind: Kind;
|
|
6
|
+
target: string;
|
|
7
|
+
/** ISO 8601 datetime the grant should expire, if any. Only permission sets and groups support it. */
|
|
8
|
+
expiration?: string;
|
|
9
|
+
};
|
|
10
|
+
/** A user as it exists in the org, in domain terms (no SObject field names). */
|
|
11
|
+
export type OrgUser = {
|
|
12
|
+
id: string;
|
|
13
|
+
username: string;
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** A target (permission set, group, or license) as it exists in the org. */
|
|
17
|
+
export type OrgTarget = {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
/** An assignment that currently exists in the org, carrying its record id for deletion. */
|
|
22
|
+
export type ActualAssignment = {
|
|
23
|
+
recordId: string;
|
|
24
|
+
assignee: string;
|
|
25
|
+
kind: Kind;
|
|
26
|
+
target: string;
|
|
27
|
+
/** The expiration the org has on record, if any. */
|
|
28
|
+
expiration?: string;
|
|
29
|
+
};
|
|
30
|
+
/** An existing assignment whose expiration should change. `expiration` undefined clears it. */
|
|
31
|
+
export type AssignmentUpdate = {
|
|
32
|
+
recordId: string;
|
|
33
|
+
assignee: string;
|
|
34
|
+
kind: Kind;
|
|
35
|
+
target: string;
|
|
36
|
+
expiration?: string;
|
|
37
|
+
};
|
|
38
|
+
/** A resolved managed target: its kind and the org id it resolved to. */
|
|
39
|
+
export type TargetRef = {
|
|
40
|
+
kind: Kind;
|
|
41
|
+
id: string;
|
|
42
|
+
};
|
|
43
|
+
/** A desired assignment resolved to the ids needed to insert it. */
|
|
44
|
+
export type ResolvedAddition = DesiredAssignment & {
|
|
45
|
+
assigneeId: string;
|
|
46
|
+
targetId: string;
|
|
47
|
+
};
|
|
48
|
+
/** The change set between the desired model and the org's current state. */
|
|
49
|
+
export type Diff = {
|
|
50
|
+
toAdd: DesiredAssignment[];
|
|
51
|
+
toUpdate: AssignmentUpdate[];
|
|
52
|
+
toRemove: ActualAssignment[];
|
|
53
|
+
unchanged: ActualAssignment[];
|
|
54
|
+
};
|
|
55
|
+
/** The per-record result of one add or remove, for partial-success reporting. */
|
|
56
|
+
export type AssignmentOutcome = {
|
|
57
|
+
assignee: string;
|
|
58
|
+
kind: Kind;
|
|
59
|
+
target: string;
|
|
60
|
+
operation: 'add' | 'update' | 'remove';
|
|
61
|
+
success: boolean;
|
|
62
|
+
message?: string;
|
|
63
|
+
};
|
|
64
|
+
export type LoadResult = {
|
|
65
|
+
files: string[];
|
|
66
|
+
assignments: DesiredAssignment[];
|
|
67
|
+
findings: Finding[];
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FileShape } from './schema.js';
|
|
2
|
+
import { DesiredAssignment, Kind } from './model.js';
|
|
3
|
+
import { Finding } from './finding.js';
|
|
4
|
+
export type ScopeKey = 'permissionSets' | 'permissionSetGroups' | 'permissionSetLicenses';
|
|
5
|
+
/** The (kind, file scope key) pairing, in canonical order. Shared with serialize. */
|
|
6
|
+
export declare const kindKeys: Array<[Kind, ScopeKey]>;
|
|
7
|
+
/**
|
|
8
|
+
* Turn a validated file into canonical (assignee, kind, target) tuples, and
|
|
9
|
+
* emit the structural findings: duplicate targets, empty lists, empty users.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalize(data: FileShape, file: string): {
|
|
12
|
+
assignments: DesiredAssignment[];
|
|
13
|
+
findings: Finding[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { emptyListWarning, dupTargetWarning, emptyUserWarning } from './finding.js';
|
|
2
|
+
/** The (kind, file scope key) pairing, in canonical order. Shared with serialize. */
|
|
3
|
+
export const kindKeys = [
|
|
4
|
+
['permissionSet', 'permissionSets'],
|
|
5
|
+
['permissionSetGroup', 'permissionSetGroups'],
|
|
6
|
+
['permissionSetLicense', 'permissionSetLicenses'],
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Turn a validated file into canonical (assignee, kind, target) tuples, and
|
|
10
|
+
* emit the structural findings: duplicate targets, empty lists, empty users.
|
|
11
|
+
*/
|
|
12
|
+
export function normalize(data, file) {
|
|
13
|
+
const assignments = [];
|
|
14
|
+
const findings = [];
|
|
15
|
+
for (const [username, entry] of Object.entries(data.users)) {
|
|
16
|
+
let scopeCount = 0;
|
|
17
|
+
for (const [kind, key] of kindKeys) {
|
|
18
|
+
const list = entry[key];
|
|
19
|
+
if (!list)
|
|
20
|
+
continue;
|
|
21
|
+
if (list.length === 0) {
|
|
22
|
+
findings.push(emptyListWarning(username, key, file));
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
scopeCount += 1;
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const item of list) {
|
|
28
|
+
const target = typeof item === 'string' ? item : item.name;
|
|
29
|
+
const expiration = typeof item === 'string' ? undefined : item.expiration;
|
|
30
|
+
if (seen.has(target)) {
|
|
31
|
+
findings.push(dupTargetWarning(username, target, key, file));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
seen.add(target);
|
|
35
|
+
assignments.push({ assignee: username, kind, target, ...(expiration ? { expiration } : {}) });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (scopeCount === 0) {
|
|
39
|
+
findings.push(emptyUserWarning(username, file));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { assignments, findings };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/core/normalize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAI7F,qFAAqF;AACrF,MAAM,CAAC,MAAM,QAAQ,GAA4B;IAC7C,CAAC,eAAe,EAAE,gBAAgB,CAAC;IACnC,CAAC,oBAAoB,EAAE,qB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C7D,SAAS;gBACb,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACjB,WAAW,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAClG,CAAC;QACL,CAAC;QAED,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC;IACL,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Finding } from './finding.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read one file's text into a plain object. Reports invalid YAML and duplicate
|
|
4
|
+
* keys (uniqueKeys), and treats an empty document as a warning.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseFile(text: string, file: string): {
|
|
7
|
+
data?: unknown;
|
|
8
|
+
findings: Finding[];
|
|
9
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parseDocument } from 'yaml';
|
|
2
|
+
import { yamlError, emptyFileWarning } from './finding.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read one file's text into a plain object. Reports invalid YAML and duplicate
|
|
5
|
+
* keys (uniqueKeys), and treats an empty document as a warning.
|
|
6
|
+
*/
|
|
7
|
+
export function parseFile(text, file) {
|
|
8
|
+
const doc = parseDocument(text, { uniqueKeys: true });
|
|
9
|
+
if (doc.errors.length > 0) {
|
|
10
|
+
return {
|
|
11
|
+
findings: doc.errors.map((err) => yamlError(err.message, file, err.linePos?.[0]?.line)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const data = doc.toJS();
|
|
15
|
+
if (data == null) {
|
|
16
|
+
return { findings: [emptyFileWarning(file)] };
|
|
17
|
+
}
|
|
18
|
+
return { data, findings: [] };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/core/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAW,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEpE;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAY;IAChD,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtD,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO;YACH,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;SAC1F,CAAC;IACN,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAa,CAAC;IACnC,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACf,OAAO,EAAE,QAAQ,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Diff } from './model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Render a diff as a plan, grouped by kind then target, with `+` adds, `~` expiration
|
|
4
|
+
* updates, `-` removes, and `=` unchanged. Timed grants carry their expiration. Shared
|
|
5
|
+
* by plan and apply.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatDiff(diff: Diff): string[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { kindKeys } from './normalize.js';
|
|
2
|
+
function bucketFor(byKind, kind, target) {
|
|
3
|
+
let byTarget = byKind.get(kind);
|
|
4
|
+
if (!byTarget) {
|
|
5
|
+
byTarget = new Map();
|
|
6
|
+
byKind.set(kind, byTarget);
|
|
7
|
+
}
|
|
8
|
+
let bucket = byTarget.get(target);
|
|
9
|
+
if (!bucket) {
|
|
10
|
+
bucket = { adds: new Map(), updates: new Map(), removes: new Set(), unchanged: new Map() };
|
|
11
|
+
byTarget.set(target, bucket);
|
|
12
|
+
}
|
|
13
|
+
return bucket;
|
|
14
|
+
}
|
|
15
|
+
/** An assignee line, annotated with its expiration when there is one. */
|
|
16
|
+
function withExpiry(assignee, expiration) {
|
|
17
|
+
return expiration ? `${assignee} (expires ${expiration})` : assignee;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Render a diff as a plan, grouped by kind then target, with `+` adds, `~` expiration
|
|
21
|
+
* updates, `-` removes, and `=` unchanged. Timed grants carry their expiration. Shared
|
|
22
|
+
* by plan and apply.
|
|
23
|
+
*/
|
|
24
|
+
export function formatDiff(diff) {
|
|
25
|
+
const byKind = new Map();
|
|
26
|
+
for (const assignment of diff.toAdd) {
|
|
27
|
+
bucketFor(byKind, assignment.kind, assignment.target).adds.set(assignment.assignee, assignment.expiration);
|
|
28
|
+
}
|
|
29
|
+
for (const update of diff.toUpdate) {
|
|
30
|
+
bucketFor(byKind, update.kind, update.target).updates.set(update.assignee, update.expiration);
|
|
31
|
+
}
|
|
32
|
+
for (const assignment of diff.toRemove) {
|
|
33
|
+
bucketFor(byKind, assignment.kind, assignment.target).removes.add(assignment.assignee);
|
|
34
|
+
}
|
|
35
|
+
for (const assignment of diff.unchanged) {
|
|
36
|
+
bucketFor(byKind, assignment.kind, assignment.target).unchanged.set(assignment.assignee, assignment.expiration);
|
|
37
|
+
}
|
|
38
|
+
const lines = [];
|
|
39
|
+
for (const [kind, scopeKey] of kindKeys) {
|
|
40
|
+
const byTarget = byKind.get(kind);
|
|
41
|
+
if (!byTarget)
|
|
42
|
+
continue;
|
|
43
|
+
lines.push(`${scopeKey}:`);
|
|
44
|
+
for (const [target, bucket] of [...byTarget].sort((left, right) => left[0].localeCompare(right[0]))) {
|
|
45
|
+
lines.push(` ${target}`);
|
|
46
|
+
for (const assignee of [...bucket.adds.keys()].sort()) {
|
|
47
|
+
lines.push(` + ${withExpiry(assignee, bucket.adds.get(assignee))}`);
|
|
48
|
+
}
|
|
49
|
+
for (const assignee of [...bucket.updates.keys()].sort()) {
|
|
50
|
+
const expiration = bucket.updates.get(assignee);
|
|
51
|
+
lines.push(` ~ ${expiration ? withExpiry(assignee, expiration) : `${assignee} (expiry cleared)`}`);
|
|
52
|
+
}
|
|
53
|
+
for (const assignee of [...bucket.removes].sort())
|
|
54
|
+
lines.push(` - ${assignee}`);
|
|
55
|
+
for (const assignee of [...bucket.unchanged.keys()].sort()) {
|
|
56
|
+
lines.push(` = ${withExpiry(assignee, bucket.unchanged.get(assignee))}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return lines;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/core/report.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS1C,SAAS,SAAS,CAAC,MAA0C,EAAE,IAAU,EAAE,MAAc;IACrF,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QA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I,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACvD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAChD,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,mBAAmB,EAAE,CAAC,CAAC;YAC1G,CAAC;YACD,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE;gBAAE,KAAK,CAAC,IAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;YACnF,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACzD,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;YAChF,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DesiredAssignment, Kind, OrgTarget, OrgUser } from './model.js';
|
|
2
|
+
import { Finding } from './finding.js';
|
|
3
|
+
export declare const kinds: Kind[];
|
|
4
|
+
/** The distinct usernames assigned across all assignments. */
|
|
5
|
+
export declare function distinctAssignees(assignments: DesiredAssignment[]): string[];
|
|
6
|
+
/** The distinct targets of one kind across all assignments. */
|
|
7
|
+
export declare function distinctTargets(assignments: DesiredAssignment[], kind: Kind): string[];
|
|
8
|
+
/** Every declared user must exist in the org and be active. */
|
|
9
|
+
export declare function evaluateUsers(declared: string[], found: OrgUser[]): Finding[];
|
|
10
|
+
/**
|
|
11
|
+
* Every declared target of one kind must resolve to exactly one record in the
|
|
12
|
+
* org. `found` is the list of matching identifiers the org returned; matching is
|
|
13
|
+
* case-insensitive, mirroring how the org compares them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function evaluateTargets(kind: Kind, declared: string[], found: string[]): Finding[];
|
|
16
|
+
/** Index active users by lowercased username to their org id, for building assignments. */
|
|
17
|
+
export declare function indexUsersById(found: OrgUser[]): Map<string, string>;
|
|
18
|
+
/** Index targets by lowercased name to their org id, skipping names that resolve ambiguously. */
|
|
19
|
+
export declare function indexTargetsById(found: OrgTarget[]): Map<string, string>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { userNotFoundError, userInactiveError, targetNotFoundError, targetAmbiguousError } from './finding.js';
|
|
2
|
+
/** Human label per kind, used in findings. Domain wording, not SObject names. */
|
|
3
|
+
const kindLabels = {
|
|
4
|
+
permissionSet: 'permission set',
|
|
5
|
+
permissionSetGroup: 'permission set group',
|
|
6
|
+
permissionSetLicense: 'permission set license',
|
|
7
|
+
};
|
|
8
|
+
export const kinds = Object.keys(kindLabels);
|
|
9
|
+
function distinct(values) {
|
|
10
|
+
return [...new Set(values)];
|
|
11
|
+
}
|
|
12
|
+
/** The distinct usernames assigned across all assignments. */
|
|
13
|
+
export function distinctAssignees(assignments) {
|
|
14
|
+
return distinct(assignments.map((assignment) => assignment.assignee));
|
|
15
|
+
}
|
|
16
|
+
/** The distinct targets of one kind across all assignments. */
|
|
17
|
+
export function distinctTargets(assignments, kind) {
|
|
18
|
+
return distinct(assignments.filter((assignment) => assignment.kind === kind).map((assignment) => assignment.target));
|
|
19
|
+
}
|
|
20
|
+
/** Every declared user must exist in the org and be active. */
|
|
21
|
+
export function evaluateUsers(declared, found) {
|
|
22
|
+
const byName = new Map();
|
|
23
|
+
for (const user of found) {
|
|
24
|
+
byName.set(user.username.toLowerCase(), user);
|
|
25
|
+
}
|
|
26
|
+
const findings = [];
|
|
27
|
+
for (const username of declared) {
|
|
28
|
+
const user = byName.get(username.toLowerCase());
|
|
29
|
+
if (!user) {
|
|
30
|
+
findings.push(userNotFoundError(username));
|
|
31
|
+
}
|
|
32
|
+
else if (!user.isActive) {
|
|
33
|
+
findings.push(userInactiveError(username));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return findings;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Every declared target of one kind must resolve to exactly one record in the
|
|
40
|
+
* org. `found` is the list of matching identifiers the org returned; matching is
|
|
41
|
+
* case-insensitive, mirroring how the org compares them.
|
|
42
|
+
*/
|
|
43
|
+
export function evaluateTargets(kind, declared, found) {
|
|
44
|
+
const label = kindLabels[kind];
|
|
45
|
+
const counts = new Map();
|
|
46
|
+
for (const name of found) {
|
|
47
|
+
const key = name.toLowerCase();
|
|
48
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
49
|
+
}
|
|
50
|
+
const findings = [];
|
|
51
|
+
for (const target of declared) {
|
|
52
|
+
const count = counts.get(target.toLowerCase()) ?? 0;
|
|
53
|
+
if (count === 0) {
|
|
54
|
+
findings.push(targetNotFoundError(target, label));
|
|
55
|
+
}
|
|
56
|
+
else if (count > 1) {
|
|
57
|
+
findings.push(targetAmbiguousError(target, label));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return findings;
|
|
61
|
+
}
|
|
62
|
+
/** Index active users by lowercased username to their org id, for building assignments. */
|
|
63
|
+
export function indexUsersById(found) {
|
|
64
|
+
const byName = new Map();
|
|
65
|
+
for (const user of found) {
|
|
66
|
+
if (user.isActive) {
|
|
67
|
+
byName.set(user.username.toLowerCase(), user.id);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return byName;
|
|
71
|
+
}
|
|
72
|
+
/** Index targets by lowercased name to their org id, skipping names that resolve ambiguously. */
|
|
73
|
+
export function indexTargetsById(found) {
|
|
74
|
+
const counts = new Map();
|
|
75
|
+
for (const target of found) {
|
|
76
|
+
const key = target.name.toLowerCase();
|
|
77
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
const byName = new Map();
|
|
80
|
+
for (const target of found) {
|
|
81
|
+
const key = target.name.toLowerCase();
|
|
82
|
+
if (counts.get(key) === 1) {
|
|
83
|
+
byName.set(key, target.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return byName;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/core/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAExH,iFAAiF;AACjF,MAAM,UAAU,GAAyB;IACrC,aAAa,EAAE,gBAAgB;IAC/B,kBAAkB,EAAE,sBAAsB;IAC1C,oBAAoB,EAAE,wBAAwB;CACjD,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAW,CAAC;AAEvD,SAAS,QAAQ,CAAC,MAAgB;IAC9B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAAC,WAAgC;IAC9D,OAAO,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,eAAe,CAAC,WAAgC,EAAE,IAAU;IACxE,OAAO,QAAQ,CACX,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,C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,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACtC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Finding } from './finding.js';
|
|
3
|
+
export declare const userEntrySchema: z.ZodObject<{
|
|
4
|
+
permissionSets: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
expiration: z.ZodISODateTime;
|
|
7
|
+
}, z.core.$strict>]>>>;
|
|
8
|
+
permissionSetGroups: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
expiration: z.ZodISODateTime;
|
|
11
|
+
}, z.core.$strict>]>>>;
|
|
12
|
+
permissionSetLicenses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export declare const fileSchema: z.ZodObject<{
|
|
15
|
+
users: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
16
|
+
permissionSets: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
expiration: z.ZodISODateTime;
|
|
19
|
+
}, z.core.$strict>]>>>;
|
|
20
|
+
permissionSetGroups: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
expiration: z.ZodISODateTime;
|
|
23
|
+
}, z.core.$strict>]>>>;
|
|
24
|
+
permissionSetLicenses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
export type FileShape = z.infer<typeof fileSchema>;
|
|
28
|
+
/** Validate a parsed object against the file contract, turning issues into findings. */
|
|
29
|
+
export declare function validateFile(data: unknown, file: string): {
|
|
30
|
+
data?: FileShape;
|
|
31
|
+
findings: Finding[];
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { schemaError } from './finding.js';
|
|
3
|
+
/** A target with an expiration: the object form of an entry. */
|
|
4
|
+
const expiringTarget = z.strictObject({
|
|
5
|
+
name: z.string().min(1),
|
|
6
|
+
expiration: z.iso.datetime({ offset: true }),
|
|
7
|
+
});
|
|
8
|
+
/** An entry is either a bare target name or a name with an expiration. */
|
|
9
|
+
const expiringList = z.array(z.union([z.string().min(1), expiringTarget])).optional();
|
|
10
|
+
/** Licenses cannot expire (PermissionSetLicenseAssign has no ExpirationDate), so names only. */
|
|
11
|
+
const plainList = z.array(z.string().min(1)).optional();
|
|
12
|
+
export const userEntrySchema = z.strictObject({
|
|
13
|
+
permissionSets: expiringList,
|
|
14
|
+
permissionSetGroups: expiringList,
|
|
15
|
+
permissionSetLicenses: plainList,
|
|
16
|
+
});
|
|
17
|
+
export const fileSchema = z.strictObject({
|
|
18
|
+
users: z.record(z.string().min(1), userEntrySchema),
|
|
19
|
+
});
|
|
20
|
+
/** Validate a parsed object against the file contract, turning issues into findings. */
|
|
21
|
+
export function validateFile(data, file) {
|
|
22
|
+
const parsed = fileSchema.safeParse(data);
|
|
23
|
+
if (parsed.success) {
|
|
24
|
+
return { data: parsed.data, findings: [] };
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
findings: parsed.error.issues.map((issue) => schemaError(issue.path.join('.') || '(root)', issue.message, file)),
|
|
28
|
+
};
|
|
29
|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a,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,CACxC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CACrE;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DesiredAssignment } from './model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emit canonical assignments back to a user-keyed YAML document: the inverse of
|
|
4
|
+
* normalize. Usernames and targets are sorted and de-duplicated so the output is
|
|
5
|
+
* deterministic, empty scopes are omitted, and an assignment with an expiration
|
|
6
|
+
* is written as the object form so it round-trips through the schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function serializeAssignments(assignments: DesiredAssignment[]): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { stringify } from 'yaml';
|
|
2
|
+
import { kindKeys } from './normalize.js';
|
|
3
|
+
/**
|
|
4
|
+
* Emit canonical assignments back to a user-keyed YAML document: the inverse of
|
|
5
|
+
* normalize. Usernames and targets are sorted and de-duplicated so the output is
|
|
6
|
+
* deterministic, empty scopes are omitted, and an assignment with an expiration
|
|
7
|
+
* is written as the object form so it round-trips through the schema.
|
|
8
|
+
*/
|
|
9
|
+
export function serializeAssignments(assignments) {
|
|
10
|
+
const usernames = [...new Set(assignments.map((assignment) => assignment.assignee))].sort();
|
|
11
|
+
const users = {};
|
|
12
|
+
for (const username of usernames) {
|
|
13
|
+
const entry = {};
|
|
14
|
+
for (const [kind, key] of kindKeys) {
|
|
15
|
+
const expirationByTarget = new Map();
|
|
16
|
+
for (const assignment of assignments) {
|
|
17
|
+
const mine = assignment.assignee === username && assignment.kind === kind;
|
|
18
|
+
if (mine && !expirationByTarget.has(assignment.target)) {
|
|
19
|
+
expirationByTarget.set(assignment.target, assignment.expiration);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const entries = [...expirationByTarget.keys()].sort().map((target) => {
|
|
23
|
+
const expiration = expirationByTarget.get(target);
|
|
24
|
+
return expiration ? { name: target, expiration } : target;
|
|
25
|
+
});
|
|
26
|
+
if (entries.length > 0) {
|
|
27
|
+
entry[key] = entries;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
users[username] = entry;
|
|
31
|
+
}
|
|
32
|
+
return stringify({ users });
|
|
33
|
+
}
|
|
34
|
+
//# 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;AAEjC,OAAO,EAAE,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAQpD;;;;;GAKG;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,GAAwB,EAAE,CAAC;IAEtC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAgC,EAAE,CAAC;QAE9C,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;YACjC,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA8B,CAAC;YACjE,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACnC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,KAAK,QAAQ,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC;gBAC1E,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBACrD,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;gBACrE,CAAC;YACL,CAAC;YAED,MAAM,OAAO,GAAsB,CAAC,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBACpF,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAClD,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;YAC9D,CAAC,CAAC,CAAC;YAEH,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,21 @@
|
|
|
1
|
+
import { ActualAssignment, AssignmentOutcome, AssignmentUpdate, 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
|
+
/** Update the expiration of the given assignments, reporting per-record success or failure. */
|
|
18
|
+
updateAssignments(updates: AssignmentUpdate[]): Promise<AssignmentOutcome[]>;
|
|
19
|
+
/** Delete the given assignments by record id, reporting per-record success or failure. */
|
|
20
|
+
removeAssignments(removals: ActualAssignment[]): Promise<AssignmentOutcome[]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-client.js","sourceRoot":"","sources":["../../../src/services/adapters/org-client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
updates: number;
|
|
20
|
+
removes: number;
|
|
21
|
+
};
|
|
22
|
+
outcomes: AssignmentOutcome[];
|
|
23
|
+
status: ApplyStatus;
|
|
24
|
+
failed: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Online apply: load the files, resolve every reference to an org id, diff against
|
|
28
|
+
* the org's current state, then add and/or remove per the mode. Deletions are
|
|
29
|
+
* capped by maxDeletes and gated by an injected confirmation.
|
|
30
|
+
*/
|
|
31
|
+
export declare class ApplyService {
|
|
32
|
+
private readonly org;
|
|
33
|
+
private readonly files;
|
|
34
|
+
private readonly input;
|
|
35
|
+
private readonly confirmDeletions;
|
|
36
|
+
constructor(org: OrgClient, files: string[], input: ApplyInput, confirmDeletions: (count: number) => Promise<boolean>);
|
|
37
|
+
run(): Promise<ApplyResult>;
|
|
38
|
+
/** Look every declared reference up in the org, returning findings and the id maps. */
|
|
39
|
+
private resolve;
|
|
40
|
+
private execute;
|
|
41
|
+
}
|