@j-schreiber/sf-cli-security-audit 0.4.0 → 0.5.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.
Files changed (148) hide show
  1. package/README.md +20 -5
  2. package/lib/commands/org/audit/init.d.ts +3 -1
  3. package/lib/commands/org/audit/init.js +12 -2
  4. package/lib/commands/org/audit/init.js.map +1 -1
  5. package/lib/commands/org/audit/run.d.ts +1 -1
  6. package/lib/libs/{policies/initialisation → conf-init}/auditConfig.d.ts +9 -1
  7. package/lib/libs/{policies/initialisation → conf-init}/auditConfig.js +4 -6
  8. package/lib/libs/conf-init/auditConfig.js.map +1 -0
  9. package/lib/libs/{policies/initialisation → conf-init}/permissionsClassification.d.ts +4 -4
  10. package/lib/libs/conf-init/permissionsClassification.js +80 -0
  11. package/lib/libs/conf-init/permissionsClassification.js.map +1 -0
  12. package/lib/libs/{policies/initialisation → conf-init}/policyConfigs.d.ts +1 -1
  13. package/lib/libs/{policies/initialisation → conf-init}/policyConfigs.js +8 -10
  14. package/lib/libs/conf-init/policyConfigs.js.map +1 -0
  15. package/lib/libs/conf-init/presets/loose.d.ts +6 -0
  16. package/lib/libs/conf-init/presets/loose.js +35 -0
  17. package/lib/libs/conf-init/presets/loose.js.map +1 -0
  18. package/lib/libs/conf-init/presets/none.d.ts +30 -0
  19. package/lib/libs/conf-init/presets/none.js +54 -0
  20. package/lib/libs/conf-init/presets/none.js.map +1 -0
  21. package/lib/libs/conf-init/presets/strict.d.ts +4 -0
  22. package/lib/libs/conf-init/presets/strict.js +28 -0
  23. package/lib/libs/conf-init/presets/strict.js.map +1 -0
  24. package/lib/libs/conf-init/presets.d.ts +7 -0
  25. package/lib/libs/conf-init/presets.js +20 -0
  26. package/lib/libs/conf-init/presets.js.map +1 -0
  27. package/lib/libs/core/classification-types.d.ts +20 -0
  28. package/lib/libs/core/classification-types.js +23 -0
  29. package/lib/libs/core/classification-types.js.map +1 -0
  30. package/lib/libs/{config/queries.js → core/constants.js} +1 -1
  31. package/lib/libs/core/constants.js.map +1 -0
  32. package/lib/libs/{config/audit-run → core/file-mgmt}/auditConfigFileManager.d.ts +19 -0
  33. package/lib/libs/{config/audit-run → core/file-mgmt}/auditConfigFileManager.js +22 -7
  34. package/lib/libs/core/file-mgmt/auditConfigFileManager.js.map +1 -0
  35. package/lib/libs/{config/audit-run → core/file-mgmt}/schema.d.ts +10 -9
  36. package/lib/libs/{config/audit-run → core/file-mgmt}/schema.js +4 -3
  37. package/lib/libs/core/file-mgmt/schema.js.map +1 -0
  38. package/lib/libs/core/mdapi/mdapiRetriever.d.ts +52 -0
  39. package/lib/libs/core/mdapi/mdapiRetriever.js +116 -0
  40. package/lib/libs/core/mdapi/mdapiRetriever.js.map +1 -0
  41. package/lib/libs/core/mdapi/metadataRegistryEntry.d.ts +39 -0
  42. package/lib/libs/core/mdapi/metadataRegistryEntry.js +31 -0
  43. package/lib/libs/core/mdapi/metadataRegistryEntry.js.map +1 -0
  44. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.d.ts +33 -0
  45. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js +41 -0
  46. package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js.map +1 -0
  47. package/lib/libs/core/mdapi/namedMetadataType.d.ts +20 -0
  48. package/lib/libs/core/mdapi/namedMetadataType.js +36 -0
  49. package/lib/libs/core/mdapi/namedMetadataType.js.map +1 -0
  50. package/lib/libs/core/mdapi/singletonMetadataType.d.ts +21 -0
  51. package/lib/libs/core/mdapi/singletonMetadataType.js +35 -0
  52. package/lib/libs/core/mdapi/singletonMetadataType.js.map +1 -0
  53. package/lib/libs/core/policy-types.d.ts +18 -0
  54. package/lib/libs/core/policy-types.js +28 -0
  55. package/lib/libs/core/policy-types.js.map +1 -0
  56. package/lib/libs/core/registries/connectedApps.d.ts +13 -0
  57. package/lib/libs/{config → core}/registries/connectedApps.js +2 -2
  58. package/lib/libs/core/registries/connectedApps.js.map +1 -0
  59. package/lib/libs/{config → core}/registries/permissionSets.d.ts +6 -0
  60. package/lib/libs/{config → core}/registries/permissionSets.js +1 -1
  61. package/lib/libs/core/registries/permissionSets.js.map +1 -0
  62. package/lib/libs/{config → core}/registries/profiles.d.ts +6 -0
  63. package/lib/libs/{config → core}/registries/profiles.js +2 -2
  64. package/lib/libs/core/registries/profiles.js.map +1 -0
  65. package/lib/libs/{config → core}/registries/ruleRegistry.d.ts +13 -3
  66. package/lib/libs/core/registries/ruleRegistry.js.map +1 -0
  67. package/lib/libs/{policies → core/registries}/rules/allUsedAppsUnderManagement.d.ts +2 -2
  68. package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.js.map +1 -0
  69. package/lib/libs/{policies → core/registries}/rules/enforceCustomPermsClassificationOnProfiles.d.ts +2 -2
  70. package/lib/libs/{policies → core/registries}/rules/enforceCustomPermsClassificationOnProfiles.js +4 -3
  71. package/lib/libs/core/registries/rules/enforceCustomPermsClassificationOnProfiles.js.map +1 -0
  72. package/lib/libs/{policies → core/registries}/rules/enforceUserPermsClassificationOnPermSets.d.ts +2 -2
  73. package/lib/libs/{policies → core/registries}/rules/enforceUserPermsClassificationOnPermSets.js +4 -3
  74. package/lib/libs/core/registries/rules/enforceUserPermsClassificationOnPermSets.js.map +1 -0
  75. package/lib/libs/{policies → core/registries}/rules/enforceUserPermsClassificationOnProfiles.d.ts +2 -2
  76. package/lib/libs/{policies → core/registries}/rules/enforceUserPermsClassificationOnProfiles.js +4 -3
  77. package/lib/libs/core/registries/rules/enforceUserPermsClassificationOnProfiles.js.map +1 -0
  78. package/lib/libs/{policies → core/registries}/rules/noUserCanSelfAuthorize.d.ts +2 -2
  79. package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.js.map +1 -0
  80. package/lib/libs/{policies → core/registries}/rules/policyRule.d.ts +2 -2
  81. package/lib/libs/core/registries/rules/policyRule.js.map +1 -0
  82. package/lib/libs/{policies/interfaces/policyRuleInterfaces.d.ts → core/registries/types.d.ts} +7 -2
  83. package/lib/libs/core/registries/types.js +9 -0
  84. package/lib/libs/core/registries/types.js.map +1 -0
  85. package/lib/libs/{audit/types.d.ts → core/result-types.d.ts} +17 -0
  86. package/lib/libs/core/result-types.js +2 -0
  87. package/lib/libs/core/result-types.js.map +1 -0
  88. package/lib/libs/core/utils.js.map +1 -0
  89. package/lib/libs/policies/auditRun.d.ts +2 -2
  90. package/lib/libs/policies/auditRun.js +2 -2
  91. package/lib/libs/policies/auditRun.js.map +1 -1
  92. package/lib/libs/policies/connectedAppPolicy.d.ts +3 -12
  93. package/lib/libs/policies/connectedAppPolicy.js +6 -6
  94. package/lib/libs/policies/connectedAppPolicy.js.map +1 -1
  95. package/lib/libs/policies/permissionSetPolicy.d.ts +3 -10
  96. package/lib/libs/policies/permissionSetPolicy.js +17 -16
  97. package/lib/libs/policies/permissionSetPolicy.js.map +1 -1
  98. package/lib/libs/policies/policy.d.ts +4 -5
  99. package/lib/libs/policies/policy.js.map +1 -1
  100. package/lib/libs/policies/profilePolicy.d.ts +3 -10
  101. package/lib/libs/policies/profilePolicy.js +24 -31
  102. package/lib/libs/policies/profilePolicy.js.map +1 -1
  103. package/messages/org.audit.init.md +12 -0
  104. package/messages/policyclassifications.md +38 -2
  105. package/oclif.manifest.json +18 -2
  106. package/package.json +1 -1
  107. package/lib/libs/audit/types.js +0 -2
  108. package/lib/libs/audit/types.js.map +0 -1
  109. package/lib/libs/config/audit-run/auditConfigFileManager.js.map +0 -1
  110. package/lib/libs/config/audit-run/schema.js.map +0 -1
  111. package/lib/libs/config/defaultPolicyClassification.d.ts +0 -2
  112. package/lib/libs/config/defaultPolicyClassification.js +0 -63
  113. package/lib/libs/config/defaultPolicyClassification.js.map +0 -1
  114. package/lib/libs/config/queries.js.map +0 -1
  115. package/lib/libs/config/registries/connectedApps.d.ts +0 -5
  116. package/lib/libs/config/registries/connectedApps.js.map +0 -1
  117. package/lib/libs/config/registries/permissionSets.js.map +0 -1
  118. package/lib/libs/config/registries/profiles.js.map +0 -1
  119. package/lib/libs/config/registries/ruleRegistry.js.map +0 -1
  120. package/lib/libs/config/registries/types.d.ts +0 -7
  121. package/lib/libs/config/registries/types.js +0 -2
  122. package/lib/libs/config/registries/types.js.map +0 -1
  123. package/lib/libs/mdapiRetriever.d.ts +0 -18
  124. package/lib/libs/mdapiRetriever.js +0 -60
  125. package/lib/libs/mdapiRetriever.js.map +0 -1
  126. package/lib/libs/policies/initialisation/auditConfig.js.map +0 -1
  127. package/lib/libs/policies/initialisation/permissionsClassification.js +0 -71
  128. package/lib/libs/policies/initialisation/permissionsClassification.js.map +0 -1
  129. package/lib/libs/policies/initialisation/policyConfigs.js.map +0 -1
  130. package/lib/libs/policies/interfaces/policyRuleInterfaces.js +0 -2
  131. package/lib/libs/policies/interfaces/policyRuleInterfaces.js.map +0 -1
  132. package/lib/libs/policies/rules/allUsedAppsUnderManagement.js.map +0 -1
  133. package/lib/libs/policies/rules/enforceCustomPermsClassificationOnProfiles.js.map +0 -1
  134. package/lib/libs/policies/rules/enforceUserPermsClassificationOnPermSets.js.map +0 -1
  135. package/lib/libs/policies/rules/enforceUserPermsClassificationOnProfiles.js.map +0 -1
  136. package/lib/libs/policies/rules/noUserCanSelfAuthorize.js.map +0 -1
  137. package/lib/libs/policies/rules/policyRule.js.map +0 -1
  138. package/lib/libs/policies/types.d.ts +0 -36
  139. package/lib/libs/policies/types.js +0 -45
  140. package/lib/libs/policies/types.js.map +0 -1
  141. package/lib/libs/utils.js.map +0 -1
  142. /package/lib/libs/{config/queries.d.ts → core/constants.d.ts} +0 -0
  143. /package/lib/libs/{config → core}/registries/ruleRegistry.js +0 -0
  144. /package/lib/libs/{policies → core/registries}/rules/allUsedAppsUnderManagement.js +0 -0
  145. /package/lib/libs/{policies → core/registries}/rules/noUserCanSelfAuthorize.js +0 -0
  146. /package/lib/libs/{policies → core/registries}/rules/policyRule.js +0 -0
  147. /package/lib/libs/{utils.d.ts → core/utils.d.ts} +0 -0
  148. /package/lib/libs/{utils.js → core/utils.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classification-types.js","sourceRoot":"","sources":["../../../src/libs/core/classification-types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAaX;AAbD,WAAY,mBAAmB;IAC7B,+EAA+E;IAC/E,0CAAmB,CAAA;IACnB,6DAA6D;IAC7D,4CAAqB,CAAA;IACrB,sEAAsE;IACtE,oCAAa,CAAA;IACb,yDAAyD;IACzD,wCAAiB,CAAA;IACjB,qEAAqE;IACrE,kCAAW,CAAA;IACX,kFAAkF;IAClF,0CAAmB,CAAA;AACrB,CAAC,EAbW,mBAAmB,KAAnB,mBAAmB,QAa9B;AAED,MAAM,UAAU,4BAA4B,CAAC,KAAa;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAiC,EAAE,CAAiC,EAAU,EAAE,CACnH,4BAA4B,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,4BAA4B,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC"}
@@ -3,4 +3,4 @@ export const PROFILES_QUERY = 'SELECT Profile.Name,Profile.UserType,IsCustom FRO
3
3
  export const PERMISSION_SETS_QUERY = 'SELECT Name,Label,IsCustom,NamespacePrefix FROM PermissionSet WHERE IsOwnedByProfile = FALSE AND NamespacePrefix = NULL';
4
4
  export const CONNECTED_APPS_QUERY = 'SELECT Name,OptionsAllowAdminApprovedUsersOnly FROM ConnectedApplication';
5
5
  export const OAUTH_TOKEN_QUERY = 'SELECT User.Username,UseCount,AppName FROM OauthToken';
6
- //# sourceMappingURL=queries.js.map
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/libs/core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,2DAA2D,CAAC;AAC9F,MAAM,CAAC,MAAM,cAAc,GACzB,gGAAgG,CAAC;AACnG,MAAM,CAAC,MAAM,qBAAqB,GAChC,yHAAyH,CAAC;AAC5H,MAAM,CAAC,MAAM,oBAAoB,GAAG,0EAA0E,CAAC;AAC/G,MAAM,CAAC,MAAM,iBAAiB,GAAG,uDAAuD,CAAC"}
@@ -1,6 +1,24 @@
1
1
  import { AuditRunConfig } from './schema.js';
2
+ /**
3
+ * Loads an audit run config with the default file manager
4
+ *
5
+ * @param dirPath
6
+ * @returns
7
+ */
2
8
  export declare const loadAuditConfig: (dirPath: string) => AuditRunConfig;
9
+ /**
10
+ * Saves a new or modified audit run config with the default file manager
11
+ *
12
+ * @param dirPath
13
+ * @param conf
14
+ */
3
15
  export declare const saveAuditConfig: (dirPath: string, conf: AuditRunConfig) => void;
16
+ /**
17
+ * The file manager streamlines initialisation of an audit config from
18
+ * a source directory and writing updated content back to disk. The directory
19
+ * structure is configurable, but most of the time using the default file manager
20
+ * will be enough.
21
+ */
4
22
  export default class AuditConfigFileManager {
5
23
  private directoryStructure;
6
24
  constructor();
@@ -24,3 +42,4 @@ export default class AuditConfigFileManager {
24
42
  private parseSubdir;
25
43
  private writeSubdir;
26
44
  }
45
+ export declare const DefaultFileManager: AuditConfigFileManager;
@@ -1,16 +1,30 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import yaml from 'js-yaml';
4
- import { isEmpty } from '../../utils.js';
4
+ import { isEmpty } from '../utils.js';
5
5
  import { PermissionsConfigFileSchema, PermSetsPolicyFileSchema, PolicyFileSchema, ProfilesPolicyFileSchema, } from './schema.js';
6
- export const loadAuditConfig = (dirPath) => {
7
- const fileManager = new AuditConfigFileManager();
8
- return fileManager.parse(dirPath);
9
- };
6
+ /**
7
+ * Loads an audit run config with the default file manager
8
+ *
9
+ * @param dirPath
10
+ * @returns
11
+ */
12
+ export const loadAuditConfig = (dirPath) => DefaultFileManager.parse(dirPath);
13
+ /**
14
+ * Saves a new or modified audit run config with the default file manager
15
+ *
16
+ * @param dirPath
17
+ * @param conf
18
+ */
10
19
  export const saveAuditConfig = (dirPath, conf) => {
11
- const fileManager = new AuditConfigFileManager();
12
- fileManager.save(dirPath, conf);
20
+ DefaultFileManager.save(dirPath, conf);
13
21
  };
22
+ /**
23
+ * The file manager streamlines initialisation of an audit config from
24
+ * a source directory and writing updated content back to disk. The directory
25
+ * structure is configurable, but most of the time using the default file manager
26
+ * will be enough.
27
+ */
14
28
  export default class AuditConfigFileManager {
15
29
  directoryStructure;
16
30
  constructor() {
@@ -95,4 +109,5 @@ function capitalizeKeys(object) {
95
109
  Object.keys(object).forEach((key) => (newObj[`${key[0].toUpperCase()}${key.slice(1)}`] = object[key]));
96
110
  return newObj;
97
111
  }
112
+ export const DefaultFileManager = new AuditConfigFileManager();
98
113
  //# sourceMappingURL=auditConfigFileManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auditConfigFileManager.js","sourceRoot":"","sources":["../../../../src/libs/core/file-mgmt/auditConfigFileManager.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAGL,2BAA2B,EAC3B,wBAAwB,EACxB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAUrB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAe,EAAkB,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEtG;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,IAAoB,EAAQ,EAAE;IAC7E,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC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I,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,gBAAgB,MAAM,CAAC,CAAC;gBACjF,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YACnE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,cAAc,CAAC,MAA+B;IACrD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,sBAAsB,EAAE,CAAC"}
@@ -1,19 +1,20 @@
1
1
  import z from 'zod';
2
- import { PermissionRiskLevelPresets, PolicyRiskLevel } from '../../policies/types.js';
2
+ import { PermissionRiskLevel } from '../classification-types.js';
3
+ import { ProfilesRiskPreset } from '../policy-types.js';
3
4
  declare const PermissionsClassificationSchema: z.ZodObject<{
4
5
  label: z.ZodOptional<z.ZodString>;
5
6
  reason: z.ZodOptional<z.ZodString>;
6
- classification: z.ZodEnum<typeof PolicyRiskLevel>;
7
+ classification: z.ZodEnum<typeof PermissionRiskLevel>;
7
8
  }, z.z.core.$strip>;
8
9
  declare const PermsClassificationsMapSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
9
10
  label: z.ZodOptional<z.ZodString>;
10
11
  reason: z.ZodOptional<z.ZodString>;
11
- classification: z.ZodEnum<typeof PolicyRiskLevel>;
12
+ classification: z.ZodEnum<typeof PermissionRiskLevel>;
12
13
  }, z.z.core.$strip>>;
13
14
  declare const NamedPermissionsClassificationSchema: z.ZodObject<{
14
15
  label: z.ZodOptional<z.ZodString>;
15
16
  reason: z.ZodOptional<z.ZodString>;
16
- classification: z.ZodEnum<typeof PolicyRiskLevel>;
17
+ classification: z.ZodEnum<typeof PermissionRiskLevel>;
17
18
  name: z.ZodString;
18
19
  }, z.z.core.$strip>;
19
20
  declare const PolicyRuleConfigSchema: z.ZodObject<{
@@ -25,10 +26,10 @@ declare const RuleMapSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
25
26
  config: z.ZodOptional<z.ZodUnknown>;
26
27
  }, z.z.core.$strip>>;
27
28
  declare const PermSetConfig: z.ZodObject<{
28
- preset: z.ZodEnum<typeof PermissionRiskLevelPresets>;
29
+ preset: z.ZodEnum<typeof ProfilesRiskPreset>;
29
30
  }, z.z.core.$strip>;
30
31
  declare const PermSetMap: z.ZodRecord<z.ZodString, z.ZodObject<{
31
- preset: z.ZodEnum<typeof PermissionRiskLevelPresets>;
32
+ preset: z.ZodEnum<typeof ProfilesRiskPreset>;
32
33
  }, z.z.core.$strip>>;
33
34
  export declare const PolicyFileSchema: z.ZodObject<{
34
35
  enabled: z.ZodDefault<z.ZodBoolean>;
@@ -44,7 +45,7 @@ export declare const ProfilesPolicyFileSchema: z.ZodObject<{
44
45
  config: z.ZodOptional<z.ZodUnknown>;
45
46
  }, z.z.core.$strip>>>;
46
47
  profiles: z.ZodRecord<z.ZodString, z.ZodObject<{
47
- preset: z.ZodEnum<typeof PermissionRiskLevelPresets>;
48
+ preset: z.ZodEnum<typeof ProfilesRiskPreset>;
48
49
  }, z.z.core.$strip>>;
49
50
  }, z.z.core.$strip>;
50
51
  export declare const PermSetsPolicyFileSchema: z.ZodObject<{
@@ -54,14 +55,14 @@ export declare const PermSetsPolicyFileSchema: z.ZodObject<{
54
55
  config: z.ZodOptional<z.ZodUnknown>;
55
56
  }, z.z.core.$strip>>>;
56
57
  permissionSets: z.ZodRecord<z.ZodString, z.ZodObject<{
57
- preset: z.ZodEnum<typeof PermissionRiskLevelPresets>;
58
+ preset: z.ZodEnum<typeof ProfilesRiskPreset>;
58
59
  }, z.z.core.$strip>>;
59
60
  }, z.z.core.$strip>;
60
61
  export declare const PermissionsConfigFileSchema: z.ZodObject<{
61
62
  permissions: z.ZodRecord<z.ZodString, z.ZodObject<{
62
63
  label: z.ZodOptional<z.ZodString>;
63
64
  reason: z.ZodOptional<z.ZodString>;
64
- classification: z.ZodEnum<typeof PolicyRiskLevel>;
65
+ classification: z.ZodEnum<typeof PermissionRiskLevel>;
65
66
  }, z.z.core.$strip>>;
66
67
  }, z.z.core.$strip>;
67
68
  export type PermissionsClassification = z.infer<typeof PermissionsClassificationSchema>;
@@ -1,12 +1,13 @@
1
1
  import z from 'zod';
2
- import { PermissionRiskLevelPresets, PolicyRiskLevel } from '../../policies/types.js';
2
+ import { PermissionRiskLevel } from '../classification-types.js';
3
+ import { ProfilesRiskPreset } from '../policy-types.js';
3
4
  const PermissionsClassificationSchema = z.object({
4
5
  /** UI Label */
5
6
  label: z.string().optional(),
6
7
  /** An optional description to explain the classification */
7
8
  reason: z.string().optional(),
8
9
  /** Risk assessment of the permissions */
9
- classification: z.enum(PolicyRiskLevel),
10
+ classification: z.enum(PermissionRiskLevel),
10
11
  });
11
12
  const PermsClassificationsMapSchema = z.record(z.string(), PermissionsClassificationSchema);
12
13
  const NamedPermissionsClassificationSchema = PermissionsClassificationSchema.extend({
@@ -19,7 +20,7 @@ const PolicyRuleConfigSchema = z.object({
19
20
  });
20
21
  const RuleMapSchema = z.record(z.string(), PolicyRuleConfigSchema);
21
22
  const PermSetConfig = z.object({
22
- preset: z.enum(PermissionRiskLevelPresets),
23
+ preset: z.enum(ProfilesRiskPreset),
23
24
  });
24
25
  const PermSetMap = z.record(z.string(), PermSetConfig);
25
26
  // FILE CONTENT SCHEMATA
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/libs/core/file-mgmt/schema.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,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAClC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;CACjC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC9D,QAAQ,EAAE,UAAU;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC9D,cAAc,EAAE,UAAU;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,+BAA+B,CAAC;CACnE,CAAC,CAAC;AA0CH,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC9C,OAAQ,GAAqC,CAAC,OAAO,EAAE,WAAW,KAAK,SAAS,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,OAAQ,GAAyC,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC;AACjF,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { ConnectedAppSettings, PermissionSet, Profile as ProfileMetadata } from '@jsforce/jsforce-node/lib/api/metadata.js';
3
+ import NamedMetadata from './namedMetadataType.js';
4
+ import SingletonMetadata from './singletonMetadataType.js';
5
+ import NamedMetadataQueryable from './namedMetadataToolingQueryable.js';
6
+ export default class MDAPI {
7
+ private connection;
8
+ private cache;
9
+ constructor(connection: Connection);
10
+ /**
11
+ * Resolves one of the pre-configured metadata types and returns
12
+ * a map of resolved names and entire XML content of source file body.
13
+ *
14
+ * @param typeName
15
+ * @param componentNames
16
+ * @returns
17
+ */
18
+ resolve<K extends keyof typeof NamedTypesRegistry>(typeName: K, componentNames: string[]): Promise<NamedReturnTypes[K]>;
19
+ /**
20
+ * Resolves one of the pre-configured metadata types and returns
21
+ * the entire XML content of source file body.
22
+ *
23
+ * @param typeName
24
+ * @returns
25
+ */
26
+ resolveSingleton<K extends keyof typeof SingletonRegistry>(typeName: K): Promise<SingletonReturnTypes[K]>;
27
+ private cacheResults;
28
+ private fetchCached;
29
+ }
30
+ export declare const NamedTypesRegistry: {
31
+ PermissionSet: NamedMetadata<PermissionSetXml, "PermissionSet">;
32
+ Profile: NamedMetadataQueryable<ProfileXml, "Profile">;
33
+ };
34
+ export declare const SingletonRegistry: {
35
+ ConnectedAppSettings: SingletonMetadata<ConnectedAppSettingsXml, "ConnectedAppSettings">;
36
+ };
37
+ type NamedReturnTypes = {
38
+ [K in keyof typeof NamedTypesRegistry]: Awaited<ReturnType<(typeof NamedTypesRegistry)[K]['resolve']>>;
39
+ };
40
+ type SingletonReturnTypes = {
41
+ [K in keyof typeof SingletonRegistry]: Awaited<ReturnType<(typeof SingletonRegistry)[K]['resolve']>>;
42
+ };
43
+ type ProfileXml = {
44
+ Profile: ProfileMetadata;
45
+ };
46
+ type PermissionSetXml = {
47
+ PermissionSet: PermissionSet;
48
+ };
49
+ type ConnectedAppSettingsXml = {
50
+ ConnectedAppSettings: ConnectedAppSettings;
51
+ };
52
+ export {};
@@ -0,0 +1,116 @@
1
+ import { XMLParser } from 'fast-xml-parser';
2
+ import NamedMetadata from './namedMetadataType.js';
3
+ import SingletonMetadata from './singletonMetadataType.js';
4
+ import NamedMetadataQueryable from './namedMetadataToolingQueryable.js';
5
+ export default class MDAPI {
6
+ connection;
7
+ cache;
8
+ constructor(connection) {
9
+ this.connection = connection;
10
+ this.cache = new MetadataCache();
11
+ }
12
+ /**
13
+ * Resolves one of the pre-configured metadata types and returns
14
+ * a map of resolved names and entire XML content of source file body.
15
+ *
16
+ * @param typeName
17
+ * @param componentNames
18
+ * @returns
19
+ */
20
+ async resolve(typeName, componentNames) {
21
+ const retriever = NamedTypesRegistry[typeName];
22
+ const { toRetrieve, cached } = this.fetchCached(componentNames);
23
+ if (toRetrieve.length > 0) {
24
+ const retrieveResults = await retriever.resolve(this.connection, toRetrieve);
25
+ this.cacheResults(retrieveResults);
26
+ return {
27
+ ...cached,
28
+ ...retrieveResults,
29
+ };
30
+ }
31
+ return cached;
32
+ }
33
+ /**
34
+ * Resolves one of the pre-configured metadata types and returns
35
+ * the entire XML content of source file body.
36
+ *
37
+ * @param typeName
38
+ * @returns
39
+ */
40
+ async resolveSingleton(typeName) {
41
+ const retriever = SingletonRegistry[typeName];
42
+ const { toRetrieve, cached } = this.fetchCached([typeName]);
43
+ if (toRetrieve.length > 0) {
44
+ const retrieveResults = await retriever.resolve(this.connection);
45
+ this.cache.set(typeName, retrieveResults);
46
+ return retrieveResults;
47
+ }
48
+ return cached[typeName];
49
+ }
50
+ cacheResults(results) {
51
+ Object.entries(results).forEach(([cname, mdata]) => {
52
+ this.cache.set(cname, mdata);
53
+ });
54
+ }
55
+ fetchCached(componentNames) {
56
+ const toRetrieve = [];
57
+ const cached = {};
58
+ for (const cname of componentNames) {
59
+ if (this.cache.isCached(cname)) {
60
+ cached[cname] = this.cache.fetch(cname);
61
+ }
62
+ else {
63
+ toRetrieve.push(cname);
64
+ }
65
+ }
66
+ return { toRetrieve, cached };
67
+ }
68
+ }
69
+ class MetadataCache {
70
+ components = {};
71
+ isCached(cmpName) {
72
+ return this.components[cmpName] !== undefined && this.components[cmpName] !== null;
73
+ }
74
+ fetch(cmpName) {
75
+ if (!this.isCached(cmpName)) {
76
+ throw new Error('Component not cached. Check first before fetching: ' + cmpName);
77
+ }
78
+ return this.components[cmpName];
79
+ }
80
+ set(cmpName, content) {
81
+ this.components[cmpName] = content;
82
+ }
83
+ }
84
+ export const NamedTypesRegistry = {
85
+ PermissionSet: new NamedMetadata({
86
+ retrieveType: 'PermissionSet',
87
+ rootNodeName: 'PermissionSet',
88
+ parser: new XMLParser({
89
+ isArray: (jpath) => ['userPermissions', 'fieldPermissions', 'customPermissions', 'classAccesses'].includes(jpath),
90
+ }),
91
+ parsePostProcessor: (parseResult) => ({
92
+ ...parseResult,
93
+ userPermissions: parseResult.userPermissions ?? [],
94
+ customPermissions: parseResult.customPermissions ?? [],
95
+ classAccesses: parseResult.classAccesses ?? [],
96
+ }),
97
+ }),
98
+ Profile: new NamedMetadataQueryable({
99
+ objectName: 'Profile',
100
+ nameField: 'Name',
101
+ parsePostProcessor: (parseResult) => ({
102
+ ...parseResult,
103
+ userPermissions: parseResult.userPermissions ?? [],
104
+ customPermissions: parseResult.customPermissions ?? [],
105
+ classAccesses: parseResult.classAccesses ?? [],
106
+ }),
107
+ }),
108
+ };
109
+ export const SingletonRegistry = {
110
+ ConnectedAppSettings: new SingletonMetadata({
111
+ rootNodeName: 'ConnectedAppSettings',
112
+ retrieveName: 'ConnectedApp',
113
+ retrieveType: 'Settings',
114
+ }),
115
+ };
116
+ //# sourceMappingURL=mdapiRetriever.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mdapiRetriever.js","sourceRoot":"","sources":["../../../../src/libs/core/mdapi/mdapiRetriever.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAC3D,OAAO,sBAAsB,MAAM,oCAAoC,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,KAAK;IAGG;IAFnB,KAAK,CAAgB;IAE7B,YAA2B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAClB,QAAW,EACX,cAAwB;QAExB,MAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,EAAE,UAA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AAC,KAAK,CAAC;SAChG,CAAC;QACF,kBAAkB,EAAE,CAAC,WAAW,EAAiB,EAAE,CAAC,CAAC;YACnD,GAAG,WAAW;YACd,eAAe,EAAE,WAAW,CAAC,eAAe,IAAI,EAAE;YAClD,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,IAAI,EAAE;YACtD,aAAa,EAAE,WAAW,CAAC,aAAa,IAAI,EAAE;SAC/C,CAAC;KACH,CAAC;IACF,OAAO,EAAE,IAAI,sBAAsB,CAAwB;QACzD,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,MAAM;QACjB,kBAAkB,EAAE,CAAC,WAAW,EAAmB,EAAE,CAAC,CAAC;YACrD,GAAG,WAAW;YACd,eAAe,EAAE,WAAW,CAAC,eAAe,IAAI,EAAE;YAClD,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,IAAI,EAAE;YACtD,aAAa,EAAE,WAAW,CAAC,aAAa,IAAI,EAAE;SAC/C,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,oBAAoB,EAAE,IAAI,iBAAiB,CAAkD;QAC3F,YAAY,EAAE,sBAAsB;QACpC,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,UAAU;KACzB,CAAC;CACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { PathLike } from 'node:fs';
2
+ import { XMLParser } from 'fast-xml-parser';
3
+ import { ComponentSet, RetrieveResult } from '@salesforce/source-deploy-retrieve';
4
+ import { Connection } from '@salesforce/core';
5
+ export type MetadataRegistryEntryOpts<Type, Key extends keyof Type> = {
6
+ /**
7
+ * Metadata API name of the type.
8
+ */
9
+ retrieveType: string;
10
+ /**
11
+ * Metadata API name entity.
12
+ */
13
+ retrieveName?: string;
14
+ /**
15
+ * Optional XML parser instance. Typically used to fix errors for
16
+ * properties that must be parsed as list.
17
+ */
18
+ parser?: XMLParser;
19
+ /**
20
+ * Name of the root node in XML file content
21
+ */
22
+ rootNodeName: Key;
23
+ /**
24
+ * Post processor function that sanitises the XML parse result
25
+ */
26
+ parsePostProcessor?: (parseResult: Type[Key]) => Type[Key];
27
+ };
28
+ export type NamedMetadataResolver<Type> = {
29
+ resolve(con: Connection, componentNames: string[]): Promise<Record<string, Type>>;
30
+ };
31
+ export default abstract class MetadataRegistryEntry<Type, Key extends keyof Type> {
32
+ private opts;
33
+ parser: XMLParser;
34
+ retrieveType: string;
35
+ rootNodeName: Key;
36
+ constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
37
+ parse(fullFilePath: PathLike): Type[Key];
38
+ }
39
+ export declare function retrieve(compSet: ComponentSet, con: Connection): Promise<RetrieveResult>;
@@ -0,0 +1,31 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { XMLParser } from 'fast-xml-parser';
3
+ export default class MetadataRegistryEntry {
4
+ opts;
5
+ parser;
6
+ retrieveType;
7
+ rootNodeName;
8
+ constructor(opts) {
9
+ this.opts = opts;
10
+ this.retrieveType = this.opts.retrieveType;
11
+ this.parser = this.opts.parser ?? new XMLParser();
12
+ this.rootNodeName = this.opts.rootNodeName;
13
+ }
14
+ parse(fullFilePath) {
15
+ const fileContent = readFileSync(fullFilePath, 'utf-8');
16
+ const parsedContent = this.parser.parse(fileContent);
17
+ if (this.opts.parsePostProcessor) {
18
+ return this.opts.parsePostProcessor(parsedContent[this.rootNodeName]);
19
+ }
20
+ return parsedContent[this.rootNodeName];
21
+ }
22
+ }
23
+ export async function retrieve(compSet, con) {
24
+ const retrieveRequest = await compSet.retrieve({
25
+ usernameOrConnection: con,
26
+ output: '.jsc/retrieves',
27
+ });
28
+ const retrieveResult = await retrieveRequest.pollStatus();
29
+ return retrieveResult;
30
+ }
31
+ //# sourceMappingURL=metadataRegistryEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadataRegistryEntry.js","sourceRoot":"","sources":["../../../../src/libs/core/mdapi/metadataRegistryEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,YAAY,EA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'./metadataRegistryEntry.js';
3
+ export type NamedMetadataQueryableOpts<Type> = {
4
+ /**
5
+ * Object API name to retrieve. Must be available in tooling API
6
+ */
7
+ objectName: string;
8
+ /**
9
+ * Unique name field that is used to retrieve the object
10
+ */
11
+ nameField: string;
12
+ /**
13
+ * Post processor function that sanitises the XML parse result
14
+ */
15
+ parsePostProcessor?: (parseResult: Type) => Type;
16
+ };
17
+ /**
18
+ * The entry is a typical named metadata that is organized in a dedicated source folder
19
+ * where all entities have the same format. The components are queries from tooling API
20
+ * and organized by their developer name.
21
+ */
22
+ export default class NamedMetadataQueryable<Type, Key extends keyof Type> implements NamedMetadataResolver<Type[Key]> {
23
+ private opts;
24
+ constructor(opts: NamedMetadataQueryableOpts<Type[Key]>);
25
+ /**
26
+ * Resolves a set of component names by querying "Metadata" property from tooling API
27
+ *
28
+ * @param con
29
+ * @param componentNames
30
+ * @returns
31
+ */
32
+ resolve(con: Connection, componentNames: string[]): Promise<Record<string, Type[Key]>>;
33
+ }
@@ -0,0 +1,41 @@
1
+ import { isNullish } from '../utils.js';
2
+ /**
3
+ * The entry is a typical named metadata that is organized in a dedicated source folder
4
+ * where all entities have the same format. The components are queries from tooling API
5
+ * and organized by their developer name.
6
+ */
7
+ export default class NamedMetadataQueryable {
8
+ opts;
9
+ constructor(opts) {
10
+ this.opts = opts;
11
+ }
12
+ /**
13
+ * Resolves a set of component names by querying "Metadata" property from tooling API
14
+ *
15
+ * @param con
16
+ * @param componentNames
17
+ * @returns
18
+ */
19
+ async resolve(con, componentNames) {
20
+ const pendingQueries = new Array();
21
+ componentNames.forEach((cname) => {
22
+ const qr = Promise.resolve(con.tooling.query(`SELECT ${this.opts.nameField},Metadata FROM ${this.opts.objectName} WHERE ${this.opts.nameField} = '${cname}'`));
23
+ pendingQueries.push(qr);
24
+ });
25
+ const queryResults = await Promise.all(pendingQueries);
26
+ const resultMap = {};
27
+ queryResults.forEach((qr) => {
28
+ if (qr.totalSize > 0) {
29
+ const record = qr.records[0];
30
+ const identifier = record[this.opts.nameField];
31
+ if (identifier && !isNullish(record.Metadata)) {
32
+ resultMap[identifier] = this.opts.parsePostProcessor
33
+ ? this.opts.parsePostProcessor(record.Metadata)
34
+ : record.Metadata;
35
+ }
36
+ }
37
+ });
38
+ return resultMap;
39
+ }
40
+ }
41
+ //# sourceMappingURL=namedMetadataToolingQueryable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namedMetadataToolingQueryable.js","sourceRoot":"","sources":["../../../../src/libs/core/mdapi/namedMetadataToolingQueryable.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAoBxC;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAsB;IACd;IAA3B,YAA2B,IAA2C;QAA3C,SAAI,GAAJ,IAAI,CAAuC;IAAG,CAAC;IAC1E;;;;;;OAMG;IACI,KAAK,CAAC,OAAO,CAAC,GAAe,EAAE,cAAwB;QAC5D,MAAM,cAAc,GAAG,IAAI,KAAK,EAAmD,CAAC;QACpF,cAAc,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC/B,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CACxB,GAAG,CAAC,OAAO,CAAC,KAAK,CACf,UAAU,IAAI,CAAC,IAAI,CAAC,SAAS,kBAAkB,IAAI,CAAC,IAAI,CAAC,UAAU,UAAU,IAAI,CAAC,IAAI,CAAC,SAAS,OAAO,KAAK,GAAG,CAChH,CACF,CAAC;YACF,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACvD,MAAM,SAAS,GAA8B,EAAE,CAAC;QAChD,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAC1B,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAW,CAAC;gBACzD,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC9C,SAAS,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB;wBAClD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;wBAC/C,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import MetadataRegistryEntry, { MetadataRegistryEntryOpts } from './metadataRegistryEntry.js';
3
+ /**
4
+ * The entry is a typical named metadata that is organized in a dedicated source folder
5
+ * where all entities have the same format. The components are retrieved and organized
6
+ * by their developer name.
7
+ */
8
+ export default class NamedMetadata<Type, Key extends keyof Type> extends MetadataRegistryEntry<Type, Key> {
9
+ constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
10
+ /**
11
+ * Resolves component names, retrieves the metadata and returns
12
+ * as a strongly typed result.
13
+ *
14
+ * @param con
15
+ * @param componentNames
16
+ * @returns
17
+ */
18
+ resolve(con: Connection, componentNames: string[]): Promise<Record<string, Type[Key]>>;
19
+ private parseSourceFiles;
20
+ }
@@ -0,0 +1,36 @@
1
+ import { ComponentSet } from '@salesforce/source-deploy-retrieve';
2
+ import MetadataRegistryEntry, { retrieve } from './metadataRegistryEntry.js';
3
+ /**
4
+ * The entry is a typical named metadata that is organized in a dedicated source folder
5
+ * where all entities have the same format. The components are retrieved and organized
6
+ * by their developer name.
7
+ */
8
+ export default class NamedMetadata extends MetadataRegistryEntry {
9
+ constructor(opts) {
10
+ super(opts);
11
+ }
12
+ /**
13
+ * Resolves component names, retrieves the metadata and returns
14
+ * as a strongly typed result.
15
+ *
16
+ * @param con
17
+ * @param componentNames
18
+ * @returns
19
+ */
20
+ async resolve(con, componentNames) {
21
+ const cmpSet = new ComponentSet(componentNames.map((cname) => ({ type: this.retrieveType, fullName: cname })));
22
+ const retrieveResult = await retrieve(cmpSet, con);
23
+ return this.parseSourceFiles(retrieveResult.components, componentNames);
24
+ }
25
+ parseSourceFiles(componentSet, retrievedNames) {
26
+ const cmps = componentSet.getSourceComponents().toArray();
27
+ const result = {};
28
+ cmps.forEach((sourceComponent) => {
29
+ if (sourceComponent.xml && retrievedNames.includes(sourceComponent.name)) {
30
+ result[sourceComponent.name] = this.parse(sourceComponent.xml);
31
+ }
32
+ });
33
+ return result;
34
+ }
35
+ }
36
+ //# sourceMappingURL=namedMetadataType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namedMetadataType.js","sourceRoot":"","sources":["../../../../src/libs/core/mdapi/namedMetadataType.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,qBAAqB,EAAE,EAA6B,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAExG;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,aAA4C,SAAQ,qBAAgC;IACvG,YAAmB,IAA0C;QAC3D,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IACD;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAAC,GAAe,EAAE,cAAwB;QAC5D,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/G,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAC1E,CAAC;IAEO,gBAAgB,CAAC,YAA0B,EAAE,cAAwB;QAC3E,MAAM,IAAI,GAAG,YAAY,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,CAAC;QAC1D,MAAM,MAAM,GAA8B,EAAE,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;YAC/B,IAAI,eAAe,CAAC,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzE,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YACjE,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import MetadataRegistryEntry, { MetadataRegistryEntryOpts } from './metadataRegistryEntry.js';
3
+ /**
4
+ * The entry is a type that only has one single instance on the org, such as
5
+ * a Setting. The component is typically retrieved by a more generic name and
6
+ * organized & cached by the explicit name.
7
+ */
8
+ export default class SingletonMetadata<Type, Key extends keyof Type> extends MetadataRegistryEntry<Type, Key> {
9
+ retrieveName: string;
10
+ constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
11
+ /**
12
+ * Resolves component names, retrieves the metadata and returns
13
+ * as a strongly typed result.
14
+ *
15
+ * @param con
16
+ * @param componentNames
17
+ * @returns
18
+ */
19
+ resolve(con: Connection): Promise<Type[Key]>;
20
+ private parseSourceFile;
21
+ }
@@ -0,0 +1,35 @@
1
+ import { ComponentSet } from '@salesforce/source-deploy-retrieve';
2
+ import MetadataRegistryEntry, { retrieve } from './metadataRegistryEntry.js';
3
+ /**
4
+ * The entry is a type that only has one single instance on the org, such as
5
+ * a Setting. The component is typically retrieved by a more generic name and
6
+ * organized & cached by the explicit name.
7
+ */
8
+ export default class SingletonMetadata extends MetadataRegistryEntry {
9
+ retrieveName;
10
+ constructor(opts) {
11
+ super(opts);
12
+ this.retrieveName = opts.retrieveName ?? String(this.rootNodeName);
13
+ }
14
+ /**
15
+ * Resolves component names, retrieves the metadata and returns
16
+ * as a strongly typed result.
17
+ *
18
+ * @param con
19
+ * @param componentNames
20
+ * @returns
21
+ */
22
+ async resolve(con) {
23
+ const cmpSet = new ComponentSet([{ type: this.retrieveType, fullName: this.retrieveName }]);
24
+ const retrieveResult = await retrieve(cmpSet, con);
25
+ return this.parseSourceFile(retrieveResult.components);
26
+ }
27
+ parseSourceFile(componentSet) {
28
+ const cmps = componentSet.getSourceComponents({ type: this.retrieveType, fullName: this.retrieveName }).toArray();
29
+ if (cmps.length > 0 && cmps[0].xml) {
30
+ return this.parse(cmps[0].xml);
31
+ }
32
+ throw new Error('Failed to resolve settings for: ' + this.retrieveName);
33
+ }
34
+ }
35
+ //# sourceMappingURL=singletonMetadataType.js.map