@j-schreiber/sf-cli-security-audit 0.8.1 → 0.8.3

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 (151) hide show
  1. package/lib/commands/org/audit/init.d.ts +19 -0
  2. package/lib/commands/org/audit/init.js +72 -0
  3. package/lib/commands/org/audit/init.js.map +1 -0
  4. package/lib/commands/org/audit/run.d.ts +23 -0
  5. package/lib/commands/org/audit/run.js +124 -0
  6. package/lib/commands/org/audit/run.js.map +1 -0
  7. package/lib/commands/org/scan/user-perms.d.ts +20 -0
  8. package/lib/commands/org/scan/user-perms.js +87 -0
  9. package/lib/commands/org/scan/user-perms.js.map +1 -0
  10. package/lib/libs/conf-init/auditConfig.d.ts +35 -0
  11. package/lib/libs/conf-init/auditConfig.js +41 -0
  12. package/lib/libs/conf-init/auditConfig.js.map +1 -0
  13. package/lib/libs/conf-init/permissionsClassification.d.ts +17 -0
  14. package/lib/libs/conf-init/permissionsClassification.js +80 -0
  15. package/lib/libs/conf-init/permissionsClassification.js.map +1 -0
  16. package/lib/libs/conf-init/policyConfigs.d.ts +31 -0
  17. package/lib/libs/conf-init/policyConfigs.js +91 -0
  18. package/lib/libs/conf-init/policyConfigs.js.map +1 -0
  19. package/lib/libs/conf-init/presets/loose.d.ts +6 -0
  20. package/lib/libs/conf-init/presets/loose.js +85 -0
  21. package/lib/libs/conf-init/presets/loose.js.map +1 -0
  22. package/lib/libs/conf-init/presets/none.d.ts +30 -0
  23. package/lib/libs/conf-init/presets/none.js +54 -0
  24. package/lib/libs/conf-init/presets/none.js.map +1 -0
  25. package/lib/libs/conf-init/presets/strict.d.ts +4 -0
  26. package/lib/libs/conf-init/presets/strict.js +79 -0
  27. package/lib/libs/conf-init/presets/strict.js.map +1 -0
  28. package/lib/libs/conf-init/presets.d.ts +7 -0
  29. package/lib/libs/conf-init/presets.js +20 -0
  30. package/lib/libs/conf-init/presets.js.map +1 -0
  31. package/lib/libs/core/auditRun.d.ts +36 -0
  32. package/lib/libs/core/auditRun.js +86 -0
  33. package/lib/libs/core/auditRun.js.map +1 -0
  34. package/lib/libs/core/classification-types.d.ts +20 -0
  35. package/lib/libs/core/classification-types.js +23 -0
  36. package/lib/libs/core/classification-types.js.map +1 -0
  37. package/lib/libs/core/constants.d.ts +10 -0
  38. package/lib/libs/core/constants.js +20 -0
  39. package/lib/libs/core/constants.js.map +1 -0
  40. package/lib/libs/core/file-mgmt/auditConfigFileManager.d.ts +48 -0
  41. package/lib/libs/core/file-mgmt/auditConfigFileManager.js +145 -0
  42. package/lib/libs/core/file-mgmt/auditConfigFileManager.js.map +1 -0
  43. package/lib/libs/core/file-mgmt/schema.d.ts +123 -0
  44. package/lib/libs/core/file-mgmt/schema.js +69 -0
  45. package/lib/libs/core/file-mgmt/schema.js.map +1 -0
  46. package/lib/libs/core/mdapi/mdapiRetriever.d.ts +54 -0
  47. package/lib/libs/core/mdapi/mdapiRetriever.js +123 -0
  48. package/lib/libs/core/mdapi/mdapiRetriever.js.map +1 -0
  49. package/lib/libs/core/mdapi/metadataRegistryEntry.d.ts +40 -0
  50. package/lib/libs/core/mdapi/metadataRegistryEntry.js +46 -0
  51. package/lib/libs/core/mdapi/metadataRegistryEntry.js.map +1 -0
  52. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.d.ts +33 -0
  53. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js +41 -0
  54. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js.map +1 -0
  55. package/lib/libs/core/mdapi/namedMetadataType.d.ts +20 -0
  56. package/lib/libs/core/mdapi/namedMetadataType.js +41 -0
  57. package/lib/libs/core/mdapi/namedMetadataType.js.map +1 -0
  58. package/lib/libs/core/mdapi/singletonMetadataType.d.ts +21 -0
  59. package/lib/libs/core/mdapi/singletonMetadataType.js +37 -0
  60. package/lib/libs/core/mdapi/singletonMetadataType.js.map +1 -0
  61. package/lib/libs/core/mdapi/usersRepository.d.ts +85 -0
  62. package/lib/libs/core/mdapi/usersRepository.js +126 -0
  63. package/lib/libs/core/mdapi/usersRepository.js.map +1 -0
  64. package/lib/libs/core/policies/connectedAppPolicy.d.ts +10 -0
  65. package/lib/libs/core/policies/connectedAppPolicy.js +78 -0
  66. package/lib/libs/core/policies/connectedAppPolicy.js.map +1 -0
  67. package/lib/libs/core/policies/permissionSetPolicy.d.ts +11 -0
  68. package/lib/libs/core/policies/permissionSetPolicy.js +62 -0
  69. package/lib/libs/core/policies/permissionSetPolicy.js.map +1 -0
  70. package/lib/libs/core/policies/policy.d.ts +31 -0
  71. package/lib/libs/core/policies/policy.js +100 -0
  72. package/lib/libs/core/policies/policy.js.map +1 -0
  73. package/lib/libs/core/policies/profilePolicy.d.ts +11 -0
  74. package/lib/libs/core/policies/profilePolicy.js +64 -0
  75. package/lib/libs/core/policies/profilePolicy.js.map +1 -0
  76. package/lib/libs/core/policies/salesforceStandardTypes.d.ts +58 -0
  77. package/lib/libs/core/policies/salesforceStandardTypes.js +2 -0
  78. package/lib/libs/core/policies/salesforceStandardTypes.js.map +1 -0
  79. package/lib/libs/core/policies/userPolicy.d.ts +11 -0
  80. package/lib/libs/core/policies/userPolicy.js +60 -0
  81. package/lib/libs/core/policies/userPolicy.js.map +1 -0
  82. package/lib/libs/core/policy-types.d.ts +18 -0
  83. package/lib/libs/core/policy-types.js +28 -0
  84. package/lib/libs/core/policy-types.js.map +1 -0
  85. package/lib/libs/core/policyRegistry.d.ts +23 -0
  86. package/lib/libs/core/policyRegistry.js +38 -0
  87. package/lib/libs/core/policyRegistry.js.map +1 -0
  88. package/lib/libs/core/registries/connectedApps.d.ts +13 -0
  89. package/lib/libs/core/registries/connectedApps.js +13 -0
  90. package/lib/libs/core/registries/connectedApps.js.map +1 -0
  91. package/lib/libs/core/registries/helpers/permissionsScanning.d.ts +29 -0
  92. package/lib/libs/core/registries/helpers/permissionsScanning.js +69 -0
  93. package/lib/libs/core/registries/helpers/permissionsScanning.js.map +1 -0
  94. package/lib/libs/core/registries/permissionSets.d.ts +11 -0
  95. package/lib/libs/core/registries/permissionSets.js +11 -0
  96. package/lib/libs/core/registries/permissionSets.js.map +1 -0
  97. package/lib/libs/core/registries/profiles.d.ts +11 -0
  98. package/lib/libs/core/registries/profiles.js +11 -0
  99. package/lib/libs/core/registries/profiles.js.map +1 -0
  100. package/lib/libs/core/registries/ruleRegistry.d.ts +37 -0
  101. package/lib/libs/core/registries/ruleRegistry.js +48 -0
  102. package/lib/libs/core/registries/ruleRegistry.js.map +1 -0
  103. package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.d.ts +7 -0
  104. package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.js +23 -0
  105. package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.js.map +1 -0
  106. package/lib/libs/core/registries/rules/enforcePermissionPresets.d.ts +7 -0
  107. package/lib/libs/core/registries/rules/enforcePermissionPresets.js +58 -0
  108. package/lib/libs/core/registries/rules/enforcePermissionPresets.js.map +1 -0
  109. package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.d.ts +7 -0
  110. package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.js +26 -0
  111. package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.js.map +1 -0
  112. package/lib/libs/core/registries/rules/enforcePermissionsOnUser.d.ts +8 -0
  113. package/lib/libs/core/registries/rules/enforcePermissionsOnUser.js +42 -0
  114. package/lib/libs/core/registries/rules/enforcePermissionsOnUser.js.map +1 -0
  115. package/lib/libs/core/registries/rules/noInactiveUsers.d.ts +9 -0
  116. package/lib/libs/core/registries/rules/noInactiveUsers.js +44 -0
  117. package/lib/libs/core/registries/rules/noInactiveUsers.js.map +1 -0
  118. package/lib/libs/core/registries/rules/noOtherApexApiLogins.d.ts +7 -0
  119. package/lib/libs/core/registries/rules/noOtherApexApiLogins.js +27 -0
  120. package/lib/libs/core/registries/rules/noOtherApexApiLogins.js.map +1 -0
  121. package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.d.ts +7 -0
  122. package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.js +31 -0
  123. package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.js.map +1 -0
  124. package/lib/libs/core/registries/rules/policyRule.d.ts +19 -0
  125. package/lib/libs/core/registries/rules/policyRule.js +32 -0
  126. package/lib/libs/core/registries/rules/policyRule.js.map +1 -0
  127. package/lib/libs/core/registries/types.d.ts +37 -0
  128. package/lib/libs/core/registries/types.js +11 -0
  129. package/lib/libs/core/registries/types.js.map +1 -0
  130. package/lib/libs/core/registries/users.d.ts +10 -0
  131. package/lib/libs/core/registries/users.js +17 -0
  132. package/lib/libs/core/registries/users.js.map +1 -0
  133. package/lib/libs/core/result-types.d.ts +172 -0
  134. package/lib/libs/core/result-types.js +2 -0
  135. package/lib/libs/core/result-types.js.map +1 -0
  136. package/lib/libs/core/utils.d.ts +12 -0
  137. package/lib/libs/core/utils.js +31 -0
  138. package/lib/libs/core/utils.js.map +1 -0
  139. package/lib/libs/quick-scan/types.d.ts +17 -0
  140. package/lib/libs/quick-scan/types.js +2 -0
  141. package/lib/libs/quick-scan/types.js.map +1 -0
  142. package/lib/libs/quick-scan/userPermissionScanner.d.ts +22 -0
  143. package/lib/libs/quick-scan/userPermissionScanner.js +75 -0
  144. package/lib/libs/quick-scan/userPermissionScanner.js.map +1 -0
  145. package/lib/ux/auditRunMultiStage.d.ts +65 -0
  146. package/lib/ux/auditRunMultiStage.js +120 -0
  147. package/lib/ux/auditRunMultiStage.js.map +1 -0
  148. package/oclif.lock +276 -340
  149. package/oclif.manifest.json +253 -2
  150. package/package.json +1 -1
  151. package/bin/dev.js +0 -8
@@ -0,0 +1,62 @@
1
+ import { Messages } from '@salesforce/core';
2
+ import MDAPI from '../mdapi/mdapiRetriever.js';
3
+ import { ProfilesRiskPreset } from '../policy-types.js';
4
+ import { PermissionSetsRegistry } from '../registries/permissionSets.js';
5
+ import Policy, { getTotal } from './policy.js';
6
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
7
+ const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'policies.general');
8
+ export default class PermissionSetPolicy extends Policy {
9
+ config;
10
+ auditContext;
11
+ totalEntities;
12
+ constructor(config, auditContext, registry = PermissionSetsRegistry) {
13
+ super(config, auditContext, registry);
14
+ this.config = config;
15
+ this.auditContext = auditContext;
16
+ this.totalEntities = this.config.permissionSets ? Object.keys(this.config.permissionSets).length : 0;
17
+ }
18
+ async resolveEntities(context) {
19
+ this.emit('entityresolve', {
20
+ total: this.totalEntities,
21
+ resolved: 0,
22
+ });
23
+ const successfullyResolved = {};
24
+ const unresolved = {};
25
+ const retriever = new MDAPI(context.targetOrgConnection);
26
+ const resolvedPermsets = await retriever.resolve('PermissionSet', filterCategorizedPermsets(this.config.permissionSets));
27
+ Object.entries(this.config.permissionSets).forEach(([key, val]) => {
28
+ const resolved = resolvedPermsets[key];
29
+ if (resolved) {
30
+ successfullyResolved[key] = {
31
+ metadata: resolved,
32
+ preset: this.config.permissionSets[key].preset,
33
+ name: key,
34
+ };
35
+ }
36
+ else if (successfullyResolved[key] === undefined) {
37
+ if (val.preset === ProfilesRiskPreset.UNKNOWN) {
38
+ unresolved[key] = { name: key, message: messages.getMessage('preset-unknown', ['Permission Set']) };
39
+ }
40
+ else {
41
+ unresolved[key] = { name: key, message: messages.getMessage('entity-not-found') };
42
+ }
43
+ }
44
+ });
45
+ const result = { resolvedEntities: successfullyResolved, ignoredEntities: Object.values(unresolved) };
46
+ this.emit('entityresolve', {
47
+ total: this.totalEntities,
48
+ resolved: getTotal(result),
49
+ });
50
+ return result;
51
+ }
52
+ }
53
+ function filterCategorizedPermsets(permSets) {
54
+ const filteredNames = [];
55
+ Object.entries(permSets).forEach(([key, val]) => {
56
+ if (val.preset !== ProfilesRiskPreset.UNKNOWN) {
57
+ filteredNames.push(key);
58
+ }
59
+ });
60
+ return filteredNames;
61
+ }
62
+ //# sourceMappingURL=permissionSetPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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I,CAAC,eAAe,EAAE;YACzB,KAAK,EAAE,IAAI,CAAC,aAAa;YACzB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,SAAS,yBAAyB,CAAC,QAA8B;IAC/D,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;QAC9C,IAAI,GAAG,CAAC,MAAM,KAAK,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAC9C,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import EventEmitter from 'node:events';
2
+ import { AuditPolicyResult, EntityResolveError } from '../result-types.js';
3
+ import { AuditRunConfig, BasePolicyFileContent } from '../file-mgmt/schema.js';
4
+ import RuleRegistry, { RegistryRuleResolveResult } from '../registries/ruleRegistry.js';
5
+ import { AuditContext, IPolicy } from '../registries/types.js';
6
+ export type ResolveEntityResult<T> = {
7
+ resolvedEntities: Record<string, T>;
8
+ ignoredEntities: EntityResolveError[];
9
+ };
10
+ export default abstract class Policy<T> extends EventEmitter implements IPolicy {
11
+ config: BasePolicyFileContent;
12
+ auditConfig: AuditRunConfig;
13
+ protected registry: RuleRegistry;
14
+ protected resolvedRules: RegistryRuleResolveResult;
15
+ protected entities?: ResolveEntityResult<T>;
16
+ constructor(config: BasePolicyFileContent, auditConfig: AuditRunConfig, registry: RuleRegistry);
17
+ /**
18
+ * Resolves all entities of the policy.
19
+ */
20
+ resolve(context: AuditContext): Promise<ResolveEntityResult<T>>;
21
+ /**
22
+ * Runs all rules of a policy. If the entities are not yet resolved, they are
23
+ * resolved on the fly before rules are executed.
24
+ *
25
+ * @param context
26
+ * @returns
27
+ */
28
+ run(context: AuditContext): Promise<AuditPolicyResult>;
29
+ protected abstract resolveEntities(context: AuditContext): Promise<ResolveEntityResult<T>>;
30
+ }
31
+ export declare function getTotal(resolveResult: ResolveEntityResult<unknown>): number;
@@ -0,0 +1,100 @@
1
+ import EventEmitter from 'node:events';
2
+ export default class Policy extends EventEmitter {
3
+ config;
4
+ auditConfig;
5
+ registry;
6
+ resolvedRules;
7
+ entities;
8
+ constructor(config, auditConfig, registry) {
9
+ super();
10
+ this.config = config;
11
+ this.auditConfig = auditConfig;
12
+ this.registry = registry;
13
+ this.resolvedRules = registry.resolveRules(config.rules, auditConfig);
14
+ }
15
+ /**
16
+ * Resolves all entities of the policy.
17
+ */
18
+ async resolve(context) {
19
+ // when a policy is disabled, we still want to appear it in audit results
20
+ // as disabled with 0 resolved entities and 0 executed rules
21
+ if (!this.config.enabled) {
22
+ return { resolvedEntities: {}, ignoredEntities: [] };
23
+ }
24
+ if (!this.entities) {
25
+ this.entities = await this.resolveEntities(context);
26
+ }
27
+ return this.entities;
28
+ }
29
+ /**
30
+ * Runs all rules of a policy. If the entities are not yet resolved, they are
31
+ * resolved on the fly before rules are executed.
32
+ *
33
+ * @param context
34
+ * @returns
35
+ */
36
+ async run(context) {
37
+ if (!this.config.enabled) {
38
+ return {
39
+ isCompliant: true,
40
+ enabled: false,
41
+ executedRules: {},
42
+ skippedRules: [],
43
+ auditedEntities: [],
44
+ ignoredEntities: [],
45
+ };
46
+ }
47
+ const resolveResult = await this.resolve(context);
48
+ const ruleResultPromises = new Array();
49
+ for (const rule of this.resolvedRules.enabledRules) {
50
+ ruleResultPromises.push(rule.run({ ...context, resolvedEntities: resolveResult.resolvedEntities }));
51
+ }
52
+ const ruleResults = await Promise.all(ruleResultPromises);
53
+ const executedRules = {};
54
+ for (const ruleResult of ruleResults) {
55
+ const { compliantEntities, violatedEntities } = evalResolvedEntities(ruleResult, resolveResult);
56
+ executedRules[ruleResult.ruleName] = {
57
+ ...ruleResult,
58
+ isCompliant: ruleResult.violations.length === 0,
59
+ compliantEntities,
60
+ violatedEntities,
61
+ };
62
+ }
63
+ return {
64
+ isCompliant: isCompliant(executedRules),
65
+ enabled: true,
66
+ executedRules,
67
+ skippedRules: this.resolvedRules.skippedRules,
68
+ auditedEntities: Object.keys(resolveResult.resolvedEntities),
69
+ ignoredEntities: resolveResult.ignoredEntities,
70
+ };
71
+ }
72
+ }
73
+ function isCompliant(ruleResults) {
74
+ const list = Object.values(ruleResults);
75
+ if (list.length === 0) {
76
+ return true;
77
+ }
78
+ return list.reduce((prevVal, currentVal) => prevVal && currentVal.isCompliant, list[0].isCompliant);
79
+ }
80
+ function evalResolvedEntities(ruleResult, entities) {
81
+ const compliantEntities = [];
82
+ const violatedEntities = new Set();
83
+ ruleResult.violations.forEach((vio) => {
84
+ if (vio.identifier.length > 0) {
85
+ violatedEntities.add(vio.identifier[0]);
86
+ }
87
+ });
88
+ Object.keys(entities.resolvedEntities).forEach((entityIdentifier) => {
89
+ if (!violatedEntities.has(entityIdentifier)) {
90
+ compliantEntities.push(entityIdentifier);
91
+ }
92
+ });
93
+ return { compliantEntities, violatedEntities: Array.from(violatedEntities) };
94
+ }
95
+ export function getTotal(resolveResult) {
96
+ const resolvedCount = resolveResult.resolvedEntities ? Object.keys(resolveResult.resolvedEntities).length : 0;
97
+ const ignoredCount = resolveResult.ignoredEntities ? resolveResult.ignoredEntities.length : 0;
98
+ return resolvedCount + ignoredCount;
99
+ }
100
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../src/libs/core/policies/policy.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAUvC,MAAM,CAAC,OAAO,OAAgB,MAAU,SAAQ,YAAY;IAKjD;IACA;IACG;IANF,aAAa,CAA4B;IACzC,QAAQ,CAA0B;IAE5C,YACS,MAA6B,EAC7B,WAA2B,EACxB,QAAsB;QAEhC,KA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AG,IAAI,GAAG,EAAU,CAAC;IAC3C,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACpC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAClE,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC5C,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,aAA2C;IAClE,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9G,MAAM,YAAY,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO,aAAa,GAAG,YAAY,CAAC;AACtC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AuditRunConfig, ProfilesPolicyFileContent } from '../file-mgmt/schema.js';
2
+ import { AuditContext } from '../registries/types.js';
3
+ import { ResolvedProfile } from '../registries/profiles.js';
4
+ import Policy, { ResolveEntityResult } from './policy.js';
5
+ export default class ProfilePolicy extends Policy<ResolvedProfile> {
6
+ config: ProfilesPolicyFileContent;
7
+ auditConfig: AuditRunConfig;
8
+ private totalEntities;
9
+ constructor(config: ProfilesPolicyFileContent, auditConfig: AuditRunConfig, registry?: import("../registries/profiles.js").default);
10
+ protected resolveEntities(context: AuditContext): Promise<ResolveEntityResult<ResolvedProfile>>;
11
+ }
@@ -0,0 +1,64 @@
1
+ import { Messages } from '@salesforce/core';
2
+ import MDAPI from '../mdapi/mdapiRetriever.js';
3
+ import { ProfilesRiskPreset } from '../policy-types.js';
4
+ import { ProfilesRegistry } from '../registries/profiles.js';
5
+ import Policy, { getTotal } from './policy.js';
6
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
7
+ const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'policies.general');
8
+ export default class ProfilePolicy extends Policy {
9
+ config;
10
+ auditConfig;
11
+ totalEntities;
12
+ constructor(config, auditConfig, registry = ProfilesRegistry) {
13
+ super(config, auditConfig, registry);
14
+ this.config = config;
15
+ this.auditConfig = auditConfig;
16
+ this.totalEntities = this.config.profiles ? Object.keys(this.config.profiles).length : 0;
17
+ }
18
+ async resolveEntities(context) {
19
+ this.emit('entityresolve', {
20
+ total: this.totalEntities,
21
+ resolved: 0,
22
+ });
23
+ const successfullyResolved = {};
24
+ const ignoredEntities = {};
25
+ const definitiveProfiles = this.config.profiles ?? {};
26
+ const classifiedProfiles = [];
27
+ Object.entries(definitiveProfiles).forEach(([profileName, profileDef]) => {
28
+ if (profileDef.preset === ProfilesRiskPreset.UNKNOWN) {
29
+ ignoredEntities[profileName] = {
30
+ name: profileName,
31
+ message: messages.getMessage('preset-unknown', ['Profile']),
32
+ };
33
+ }
34
+ else {
35
+ classifiedProfiles.push(profileName);
36
+ }
37
+ });
38
+ const mdapi = new MDAPI(context.targetOrgConnection);
39
+ const resolvedProfiles = await mdapi.resolve('Profile', classifiedProfiles);
40
+ classifiedProfiles.forEach((profileName) => {
41
+ const resolvedProfile = resolvedProfiles[profileName];
42
+ if (!resolvedProfile) {
43
+ ignoredEntities[profileName] = {
44
+ name: profileName,
45
+ message: messages.getMessage('entity-not-found'),
46
+ };
47
+ }
48
+ else {
49
+ successfullyResolved[profileName] = {
50
+ name: profileName,
51
+ preset: definitiveProfiles[profileName].preset,
52
+ metadata: resolvedProfile,
53
+ };
54
+ }
55
+ });
56
+ const result = { resolvedEntities: successfullyResolved, ignoredEntities: Object.values(ignoredEntities) };
57
+ this.emit('entityresolve', {
58
+ total: this.totalEntities,
59
+ resolved: getTotal(result),
60
+ });
61
+ return result;
62
+ }
63
+ }
64
+ //# sourceMappingURL=profilePolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profilePolicy.js","sourceRoot":"","sources":["../../../../src/libs/core/policies/profilePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,2BAA2B,CAAC;AAC9E,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAuB,MAAM,aAAa,CAAC;AAEpE,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,oCAAoC,EAAE,kBAAkB,CAAC,CAAC;AAEjG,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAuB;IAGvD;IACA;IAHD,aAAa,CAAS;IAC9B,YACS,MAAiC,EACjC,WAA2B,EAClC,QAAQ,GAAG,gBAAgB;QAE3B,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QAJ9B,WAAM,GAAN,MAAM,CAA2B;QACjC,gBAAW,GAAX,WAAW,CAAgB;QAIlC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,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Ae,EAAE,CAAC;gBACrB,eAAe,CAAC,WAAW,CAAC,GAAG;oBAC7B,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC;iBACjD,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,oBAAoB,CAAC,WAAW,CAAC,GAAG;oBAClC,IAAI,EAAE,WAAW;oBACjB,MAAM,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC,MAAM;oBAC9C,QAAQ,EAAE,eAAe;iBAC1B,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;QAC3G,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,KAAK,EAAE,IAAI,CAAC,aAAa;YACzB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ import { Record } from '@jsforce/jsforce-node';
2
+ import { Profile as JsForceProfile } from '@jsforce/jsforce-node/lib/api/metadata.js';
3
+ export type CustomPermission = Record & {
4
+ Id: string;
5
+ MasterLabel: string;
6
+ DeveloperName: string;
7
+ };
8
+ export type ConnectedApp = Record & {
9
+ Id: string;
10
+ Name: string;
11
+ OptionsAllowAdminApprovedUsersOnly: boolean;
12
+ };
13
+ export type OauthToken = Record & {
14
+ Id: string;
15
+ User: Pick<User, 'Username'>;
16
+ AppName: string;
17
+ UseCount: number;
18
+ };
19
+ export type User = Record & {
20
+ Username: string;
21
+ LastLoginDate?: string;
22
+ CreatedDate: string;
23
+ Profile: ProfileBasic;
24
+ };
25
+ export type Profile = ProfileBasic & {
26
+ Metadata: JsForceProfile;
27
+ };
28
+ type ProfileBasic = Record & {
29
+ Id: string;
30
+ Name: string;
31
+ UserType: string;
32
+ };
33
+ export type PermissionSet = Record & {
34
+ Id: string;
35
+ IsOwnedByProfile: boolean;
36
+ IsCustom: boolean;
37
+ Name: string;
38
+ Label: string;
39
+ Profile: ProfileBasic;
40
+ NamespacePrefix?: string;
41
+ };
42
+ export type PermissionSetGroup = Record & {
43
+ DeveloperName: string;
44
+ };
45
+ export type PermissionSetAssignment = Record & {
46
+ AssigneeId: string;
47
+ PermissionSet: Pick<PermissionSet, 'Name'>;
48
+ PermissionSetGroupId?: string;
49
+ PermissionSetGroup?: PermissionSetGroup;
50
+ };
51
+ export type UserLoginsAggregate = Record & {
52
+ LoginType: string;
53
+ Application: string;
54
+ UserId: string;
55
+ LoginCount: number;
56
+ LastLogin: string;
57
+ };
58
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=salesforceStandardTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salesforceStandardTypes.js","sourceRoot":"","sources":["../../../../src/libs/core/policies/salesforceStandardTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { AuditRunConfig, UsersPolicyFileContent } from '../file-mgmt/schema.js';
2
+ import { AuditContext } from '../registries/types.js';
3
+ import { ResolvedUser } from '../registries/users.js';
4
+ import Policy, { ResolveEntityResult } from './policy.js';
5
+ export default class UserPolicy extends Policy<ResolvedUser> {
6
+ config: UsersPolicyFileContent;
7
+ auditConfig: AuditRunConfig;
8
+ private totalEntities;
9
+ constructor(config: UsersPolicyFileContent, auditConfig: AuditRunConfig, registry?: import("../registries/users.js").default);
10
+ protected resolveEntities(context: AuditContext): Promise<ResolveEntityResult<ResolvedUser>>;
11
+ }
@@ -0,0 +1,60 @@
1
+ import { Messages } from '@salesforce/core';
2
+ import { UsersRegistry } from '../registries/users.js';
3
+ import { ProfilesRiskPreset } from '../policy-types.js';
4
+ import UsersRepository from '../mdapi/usersRepository.js';
5
+ import Policy, { getTotal } from './policy.js';
6
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
7
+ const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'policies.general');
8
+ export default class UserPolicy extends Policy {
9
+ config;
10
+ auditConfig;
11
+ totalEntities;
12
+ constructor(config, auditConfig, registry = UsersRegistry) {
13
+ super(config, auditConfig, registry);
14
+ this.config = config;
15
+ this.auditConfig = auditConfig;
16
+ this.totalEntities = this.config.users ? Object.keys(this.config.users).length : 0;
17
+ }
18
+ async resolveEntities(context) {
19
+ this.emit('entityresolve', {
20
+ total: this.totalEntities,
21
+ resolved: 0,
22
+ });
23
+ const usersRepo = new UsersRepository(context.targetOrgConnection);
24
+ const resolvedEntities = {};
25
+ const ignoredEntities = {};
26
+ for (const [userName, userDef] of Object.entries(this.config.users)) {
27
+ if (userDef.role === ProfilesRiskPreset.UNKNOWN) {
28
+ ignoredEntities[userName] = {
29
+ name: userName,
30
+ message: messages.getMessage('user-with-role-unknown'),
31
+ };
32
+ }
33
+ }
34
+ // fetch all users from org and merge with configured users
35
+ const allUsersOnOrg = await usersRepo.resolveAllUsers({
36
+ withLoginHistory: true,
37
+ loginHistoryDaysToAnalyse: this.config.options.analyseLastNDaysOfLoginHistory,
38
+ });
39
+ this.totalEntities = allUsersOnOrg.size;
40
+ this.emit('entityresolve', {
41
+ total: this.totalEntities,
42
+ resolved: 0,
43
+ });
44
+ for (const user of allUsersOnOrg.values()) {
45
+ if (ignoredEntities[user.username] === undefined) {
46
+ resolvedEntities[user.username] = {
47
+ ...user,
48
+ role: this.config.users[user.username]?.role ?? this.config.options.defaultRoleForMissingUsers,
49
+ };
50
+ }
51
+ }
52
+ const result = { resolvedEntities, ignoredEntities: Object.values(ignoredEntities) };
53
+ this.emit('entityresolve', {
54
+ total: this.totalEntities,
55
+ resolved: getTotal(result),
56
+ });
57
+ return result;
58
+ }
59
+ }
60
+ //# sourceMappingURL=userPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userPolicy.js","sourceRoot":"","sources":["../../../../src/libs/core/polic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,EAAE;YACzB,KAAK,EAAE,IAAI,CAAC,aAAa;YACzB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Presets can be assigned to profiles and permission sets.
3
+ * A preset allows permissions up to a fixed risk level.
4
+ */
5
+ export declare enum ProfilesRiskPreset {
6
+ /** Allows up to "Critical" permissions */
7
+ DEVELOPER = "Developer",
8
+ /** Allows up to "High" permissions */
9
+ ADMIN = "Admin",
10
+ /** Allows up to "Medium" permissions */
11
+ POWER_USER = "Power User",
12
+ /** Allows only "Low" permissions */
13
+ STANDARD_USER = "Standard User",
14
+ /** Disables the profile for audit */
15
+ UNKNOWN = "Unknown"
16
+ }
17
+ export declare function resolvePresetOrdinalValue(value: string): number;
18
+ export declare function permissionAllowedInPreset(permClassification: string, preset: string): boolean;
@@ -0,0 +1,28 @@
1
+ import { PermissionRiskLevel, resolveRiskLevelOrdinalValue } from './classification-types.js';
2
+ /**
3
+ * Presets can be assigned to profiles and permission sets.
4
+ * A preset allows permissions up to a fixed risk level.
5
+ */
6
+ export var ProfilesRiskPreset;
7
+ (function (ProfilesRiskPreset) {
8
+ /** Allows up to "Critical" permissions */
9
+ ProfilesRiskPreset["DEVELOPER"] = "Developer";
10
+ /** Allows up to "High" permissions */
11
+ ProfilesRiskPreset["ADMIN"] = "Admin";
12
+ /** Allows up to "Medium" permissions */
13
+ ProfilesRiskPreset["POWER_USER"] = "Power User";
14
+ /** Allows only "Low" permissions */
15
+ ProfilesRiskPreset["STANDARD_USER"] = "Standard User";
16
+ /** Disables the profile for audit */
17
+ ProfilesRiskPreset["UNKNOWN"] = "Unknown";
18
+ })(ProfilesRiskPreset || (ProfilesRiskPreset = {}));
19
+ export function resolvePresetOrdinalValue(value) {
20
+ return Object.keys(ProfilesRiskPreset).indexOf(value.toUpperCase().replace(' ', '_'));
21
+ }
22
+ export function permissionAllowedInPreset(permClassification, preset) {
23
+ // this works, as long as we are mindful when adding new risk levels and presets
24
+ const invertedPermValue = Object.keys(PermissionRiskLevel).length - resolveRiskLevelOrdinalValue(permClassification);
25
+ const invertedPresetValue = Object.keys(ProfilesRiskPreset).length - resolvePresetOrdinalValue(preset);
26
+ return invertedPresetValue >= invertedPermValue;
27
+ }
28
+ //# sourceMappingURL=policy-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-types.js","sourceRoot":"","sources":["../../../src/libs/core/policy-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAE9F;;;GAGG;AACH,MAAM,CAAN,IAAY,kBAWX;AAXD,WAAY,kBAAkB;IAC5B,0CAA0C;IAC1C,6CAAuB,CAAA;IACvB,sCAAsC;IACtC,qCAAe,CAAA;IACf,wCAAwC;IACxC,+CAAyB,CAAA;IACzB,oCAAoC;IACpC,qDAA+B,CAAA;IAC/B,qCAAqC;IACrC,yCAAmB,CAAA;AACrB,CAAC,EAXW,kBAAkB,KAAlB,kBAAkB,QAW7B;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAa;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,kBAA0B,EAAE,MAAc;IAClF,gFAAgF;IAChF,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,4BAA4B,CAAC,kBAAkB,CAAC,CAAC;IACrH,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACvG,OAAO,mBAAmB,IAAI,iBAAiB,CAAC;AAClD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import z from 'zod';
2
+ import { AuditRunConfigClassifications, AuditRunConfigPolicies } from './file-mgmt/schema.js';
3
+ import { Constructor } from './registries/types.js';
4
+ import Policy from './policies/policy.js';
5
+ export declare const classificationDefs: ClassificationRegistry;
6
+ export type PolicyNames = keyof AuditRunConfigPolicies;
7
+ export type ClassificationNames = keyof AuditRunConfigClassifications;
8
+ export type PolicyRegistry = Record<PolicyNames, PolicyRegistryEntry>;
9
+ export declare const policyDefs: PolicyRegistry;
10
+ type PolicyRegistryEntry = ConfigFileDefinition & {
11
+ dependencies?: ConfigFileDependency[];
12
+ handler: Constructor<Policy<unknown>>;
13
+ };
14
+ type ConfigFileDefinition = {
15
+ fileName?: string;
16
+ schema: z.ZodObject;
17
+ };
18
+ type ConfigFileDependency = {
19
+ errorName: string;
20
+ path: string[];
21
+ };
22
+ type ClassificationRegistry = Record<keyof AuditRunConfigClassifications, ConfigFileDefinition>;
23
+ export {};
@@ -0,0 +1,38 @@
1
+ import { PermissionsConfigFileSchema, PermSetsPolicyFileSchema, PolicyFileSchema, ProfilesPolicyFileSchema, UsersPolicyFileSchema, } from './file-mgmt/schema.js';
2
+ import ConnectedAppPolicy from './policies/connectedAppPolicy.js';
3
+ import PermissionSetPolicy from './policies/permissionSetPolicy.js';
4
+ import ProfilePolicy from './policies/profilePolicy.js';
5
+ import UserPolicy from './policies/userPolicy.js';
6
+ export const classificationDefs = {
7
+ userPermissions: {
8
+ schema: PermissionsConfigFileSchema,
9
+ },
10
+ customPermissions: {
11
+ schema: PermissionsConfigFileSchema,
12
+ },
13
+ };
14
+ export const policyDefs = {
15
+ profiles: {
16
+ handler: ProfilePolicy,
17
+ schema: ProfilesPolicyFileSchema,
18
+ dependencies: [
19
+ { path: ['classifications', 'userPermissions'], errorName: 'UserPermClassificationRequiredForProfiles' },
20
+ ],
21
+ },
22
+ permissionSets: {
23
+ handler: PermissionSetPolicy,
24
+ schema: PermSetsPolicyFileSchema,
25
+ dependencies: [
26
+ { path: ['classifications', 'userPermissions'], errorName: 'UserPermClassificationRequiredForPermSets' },
27
+ ],
28
+ },
29
+ connectedApps: {
30
+ handler: ConnectedAppPolicy,
31
+ schema: PolicyFileSchema,
32
+ },
33
+ users: {
34
+ handler: UserPolicy,
35
+ schema: UsersPolicyFileSchema,
36
+ },
37
+ };
38
+ //# sourceMappingURL=policyRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policyRegistry.js","sourceRoot":"","sources":["../../../src/libs/core/policyRegistry.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,2BAA2B,EAC3B,wBAAwB,EACxB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,kBAAkB,MAAM,kCAAkC,CAAC;AAClE,OAAO,mBAAmB,MAAM,mCAAmC,CAAC;AAEpE,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAA2B;IACxD,eAAe,EAAE;QACf,MAAM,EAAE,2BAA2B;KACpC;IACD,iBAAiB,EAAE;QACjB,MAAM,EAAE,2BAA2B;KACpC;CACF,CAAC;AAOF,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,QAAQ,EAAE;QACR,OAAO,EAAE,aAAa;QACtB,MAAM,EAAE,wBAAwB;QAChC,YAAY,EAAE;YACZ,EAAE,IAAI,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,EAAE,SAAS,EAAE,2CAA2C,EAAE;SACzG;KACF;IACD,cAAc,EAAE;QACd,OAAO,EAAE,mBAAmB;QAC5B,MAAM,EAAE,wBAAwB;QAChC,YAAY,EAAE;YACZ,EAAE,IAAI,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,EAAE,SAAS,EAAE,2CAA2C,EAAE;SACzG;KACF;IACD,aAAa,EAAE;QACb,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,gBAAgB;KACzB;IACD,KAAK,EAAE;QACL,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE,qBAAqB;KAC9B;CACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import RuleRegistry from './ruleRegistry.js';
2
+ export type ResolvedConnectedApp = {
3
+ name: string;
4
+ origin: 'Installed' | 'OauthToken' | 'Owned';
5
+ onlyAdminApprovedUsersAllowed: boolean;
6
+ overrideByApiSecurityAccess: boolean;
7
+ useCount: number;
8
+ users: string[];
9
+ };
10
+ export default class ConnectedAppsRuleRegistry extends RuleRegistry {
11
+ constructor();
12
+ }
13
+ export declare const ConnectedAppsRegistry: ConnectedAppsRuleRegistry;
@@ -0,0 +1,13 @@
1
+ import AllUsedAppsUnderManagement from './rules/allUsedAppsUnderManagement.js';
2
+ import NoUserCanSelfAuthorize from './rules/noUserCanSelfAuthorize.js';
3
+ import RuleRegistry from './ruleRegistry.js';
4
+ export default class ConnectedAppsRuleRegistry extends RuleRegistry {
5
+ constructor() {
6
+ super({
7
+ AllUsedAppsUnderManagement,
8
+ NoUserCanSelfAuthorize,
9
+ });
10
+ }
11
+ }
12
+ export const ConnectedAppsRegistry = new ConnectedAppsRuleRegistry();
13
+ //# sourceMappingURL=connectedApps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectedApps.js","sourceRoot":"","sources":["../../../../src/libs/core/registries/connectedApps.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,MAAM,uCAAuC,CAAC;AAC/E,OAAO,sBAAsB,MAAM,mCAAmC,CAAC;AACvE,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAU7C,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,YAAY;IACjE;QACE,KAAK,CAAC;YACJ,0BAA0B;YAC1B,sBAAsB;SACvB,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { Profile } from '@jsforce/jsforce-node/lib/api/metadata.js';
2
+ import { AuditRunConfig, NamedPermissionsClassification } from '../../file-mgmt/schema.js';
3
+ import { ClassificationNames } from '../../policyRegistry.js';
4
+ import { PolicyRuleViolation, RuleComponentMessage } from '../../result-types.js';
5
+ export type ResolvedProfileLike = {
6
+ name: string;
7
+ preset: string;
8
+ metadata: PartialProfileLike;
9
+ };
10
+ export type ScanResult = {
11
+ violations: PolicyRuleViolation[];
12
+ warnings: RuleComponentMessage[];
13
+ };
14
+ export type PartialProfileLike = Pick<Profile, 'userPermissions' | 'customPermissions'>;
15
+ type PermissionsListKey = keyof PartialProfileLike;
16
+ /**
17
+ * Scan userPermissions and customPermissions of a profile or permission set and
18
+ * get a unified scan result with violations (risk level not allowed) and warnings
19
+ * (risk level not classified)
20
+ *
21
+ * @param profileLike
22
+ * @param auditRun
23
+ * @param rootIdentifier Optional root identifier for messages to prepend.
24
+ * @returns
25
+ */
26
+ export declare function scanProfileLike(profileLike: ResolvedProfileLike, auditRun: AuditRunConfig, rootIdentifier?: string[]): ScanResult;
27
+ export declare function scanPermissions(profile: ResolvedProfileLike, permissionListName: PermissionsListKey, auditRun: AuditRunConfig, rootIdentifier?: string[]): ScanResult;
28
+ export declare function resolvePerm(permName: string, auditRun: AuditRunConfig, type: ClassificationNames): NamedPermissionsClassification | undefined;
29
+ export {};