@j-schreiber/sf-cli-security-audit 0.4.1 → 0.6.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 +20 -5
- package/lib/commands/org/audit/init.d.ts +2 -0
- package/lib/commands/org/audit/init.js +10 -0
- package/lib/commands/org/audit/init.js.map +1 -1
- package/lib/commands/org/scan/user-perms.d.ts +20 -0
- package/lib/commands/org/scan/user-perms.js +88 -0
- package/lib/commands/org/scan/user-perms.js.map +1 -0
- package/lib/libs/conf-init/auditConfig.d.ts +8 -0
- package/lib/libs/conf-init/auditConfig.js +3 -2
- package/lib/libs/conf-init/auditConfig.js.map +1 -1
- package/lib/libs/conf-init/permissionsClassification.d.ts +3 -2
- package/lib/libs/conf-init/permissionsClassification.js +37 -27
- package/lib/libs/conf-init/permissionsClassification.js.map +1 -1
- package/lib/libs/conf-init/presets/loose.d.ts +6 -0
- package/lib/libs/conf-init/presets/loose.js +35 -0
- package/lib/libs/conf-init/presets/loose.js.map +1 -0
- package/lib/libs/conf-init/presets/none.d.ts +30 -0
- package/lib/libs/conf-init/presets/none.js +54 -0
- package/lib/libs/conf-init/presets/none.js.map +1 -0
- package/lib/libs/conf-init/presets/strict.d.ts +4 -0
- package/lib/libs/conf-init/presets/strict.js +28 -0
- package/lib/libs/conf-init/presets/strict.js.map +1 -0
- package/lib/libs/conf-init/presets.d.ts +7 -0
- package/lib/libs/conf-init/presets.js +20 -0
- package/lib/libs/conf-init/presets.js.map +1 -0
- package/lib/libs/core/classification-types.d.ts +1 -1
- package/lib/libs/core/classification-types.js +1 -1
- package/lib/libs/core/classification-types.js.map +1 -1
- package/lib/libs/core/constants.d.ts +1 -0
- package/lib/libs/core/constants.js +4 -0
- package/lib/libs/core/constants.js.map +1 -1
- package/lib/libs/core/file-mgmt/auditConfigFileManager.d.ts +1 -0
- package/lib/libs/core/file-mgmt/auditConfigFileManager.js +49 -4
- package/lib/libs/core/file-mgmt/auditConfigFileManager.js.map +1 -1
- package/lib/libs/core/mdapi/mdapiRetriever.d.ts +12 -68
- package/lib/libs/core/mdapi/mdapiRetriever.js +20 -90
- package/lib/libs/core/mdapi/mdapiRetriever.js.map +1 -1
- package/lib/libs/core/mdapi/metadataRegistryEntry.d.ts +40 -0
- package/lib/libs/core/mdapi/metadataRegistryEntry.js +46 -0
- package/lib/libs/core/mdapi/metadataRegistryEntry.js.map +1 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.d.ts +33 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js +41 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js.map +1 -0
- package/lib/libs/core/mdapi/namedMetadataType.d.ts +20 -0
- package/lib/libs/core/mdapi/namedMetadataType.js +41 -0
- package/lib/libs/core/mdapi/namedMetadataType.js.map +1 -0
- package/lib/libs/core/mdapi/singletonMetadataType.d.ts +21 -0
- package/lib/libs/core/mdapi/singletonMetadataType.js +37 -0
- package/lib/libs/core/mdapi/singletonMetadataType.js.map +1 -0
- package/lib/libs/core/utils.d.ts +2 -0
- package/lib/libs/core/utils.js +6 -0
- package/lib/libs/core/utils.js.map +1 -1
- package/lib/libs/policies/profilePolicy.js +21 -28
- package/lib/libs/policies/profilePolicy.js.map +1 -1
- package/lib/libs/quick-scan/types.d.ts +17 -0
- package/lib/libs/quick-scan/types.js +2 -0
- package/lib/libs/quick-scan/types.js.map +1 -0
- package/lib/libs/quick-scan/userPermissionScanner.d.ts +22 -0
- package/lib/libs/quick-scan/userPermissionScanner.js +75 -0
- package/lib/libs/quick-scan/userPermissionScanner.js.map +1 -0
- package/messages/org.audit.init.md +12 -0
- package/messages/org.audit.run.md +12 -0
- package/messages/org.scan.user-perms.md +31 -0
- package/messages/policyclassifications.md +38 -2
- package/oclif.manifest.json +96 -2
- package/package.json +1 -1
- package/lib/libs/conf-init/defaultPolicyClassification.d.ts +0 -2
- package/lib/libs/conf-init/defaultPolicyClassification.js +0 -63
- package/lib/libs/conf-init/defaultPolicyClassification.js.map +0 -1
|
@@ -13,7 +13,7 @@ export declare enum PermissionRiskLevel {
|
|
|
13
13
|
MEDIUM = "Medium",
|
|
14
14
|
/** Regular user permissions, typically needed for day-to-day work */
|
|
15
15
|
LOW = "Low",
|
|
16
|
-
/** Not categorized or unknown permission */
|
|
16
|
+
/** Not categorized or unknown permission. Will be ignored but create a warning */
|
|
17
17
|
UNKNOWN = "Unknown"
|
|
18
18
|
}
|
|
19
19
|
export declare function resolveRiskLevelOrdinalValue(value: string): number;
|
|
@@ -13,7 +13,7 @@ export var PermissionRiskLevel;
|
|
|
13
13
|
PermissionRiskLevel["MEDIUM"] = "Medium";
|
|
14
14
|
/** Regular user permissions, typically needed for day-to-day work */
|
|
15
15
|
PermissionRiskLevel["LOW"] = "Low";
|
|
16
|
-
/** Not categorized or unknown permission */
|
|
16
|
+
/** Not categorized or unknown permission. Will be ignored but create a warning */
|
|
17
17
|
PermissionRiskLevel["UNKNOWN"] = "Unknown";
|
|
18
18
|
})(PermissionRiskLevel || (PermissionRiskLevel = {}));
|
|
19
19
|
export function resolveRiskLevelOrdinalValue(value) {
|
|
@@ -1 +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,
|
|
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,3 +3,4 @@ export declare const PROFILES_QUERY = "SELECT Profile.Name,Profile.UserType,IsCu
|
|
|
3
3
|
export declare const PERMISSION_SETS_QUERY = "SELECT Name,Label,IsCustom,NamespacePrefix FROM PermissionSet WHERE IsOwnedByProfile = FALSE AND NamespacePrefix = NULL";
|
|
4
4
|
export declare const CONNECTED_APPS_QUERY = "SELECT Name,OptionsAllowAdminApprovedUsersOnly FROM ConnectedApplication";
|
|
5
5
|
export declare const OAUTH_TOKEN_QUERY = "SELECT User.Username,UseCount,AppName FROM OauthToken";
|
|
6
|
+
export declare const RETRIEVE_CACHE: string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// QUERIES
|
|
1
3
|
export const CUSTOM_PERMS_QUERY = 'SELECT Id,MasterLabel,DeveloperName FROM CustomPermission';
|
|
2
4
|
export const PROFILES_QUERY = 'SELECT Profile.Name,Profile.UserType,IsCustom FROM PermissionSet WHERE IsOwnedByProfile = TRUE';
|
|
3
5
|
export const PERMISSION_SETS_QUERY = 'SELECT Name,Label,IsCustom,NamespacePrefix FROM PermissionSet WHERE IsOwnedByProfile = FALSE AND NamespacePrefix = NULL';
|
|
4
6
|
export const CONNECTED_APPS_QUERY = 'SELECT Name,OptionsAllowAdminApprovedUsersOnly FROM ConnectedApplication';
|
|
5
7
|
export const OAUTH_TOKEN_QUERY = 'SELECT User.Username,UseCount,AppName FROM OauthToken';
|
|
8
|
+
// PATHS
|
|
9
|
+
export const RETRIEVE_CACHE = path.join('.jsc', 'retrieves');
|
|
6
10
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +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
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/libs/core/constants.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,UAAU;AACV,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;AAEzF,QAAQ;AACR,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import yaml from 'js-yaml';
|
|
4
|
-
import {
|
|
4
|
+
import { Messages } from '@salesforce/core';
|
|
5
|
+
import { capitalize, isEmpty, uncapitalize } from '../utils.js';
|
|
5
6
|
import { PermissionsConfigFileSchema, PermSetsPolicyFileSchema, PolicyFileSchema, ProfilesPolicyFileSchema, } from './schema.js';
|
|
7
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
|
+
const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'org.audit.run');
|
|
6
9
|
/**
|
|
7
10
|
* Loads an audit run config with the default file manager
|
|
8
11
|
*
|
|
@@ -32,9 +35,15 @@ export default class AuditConfigFileManager {
|
|
|
32
35
|
policies: {
|
|
33
36
|
profiles: {
|
|
34
37
|
schema: ProfilesPolicyFileSchema,
|
|
38
|
+
dependencies: [
|
|
39
|
+
{ path: ['classifications', 'userPermissions'], errorName: 'UserPermClassificationRequiredForProfiles' },
|
|
40
|
+
],
|
|
35
41
|
},
|
|
36
42
|
permissionSets: {
|
|
37
43
|
schema: PermSetsPolicyFileSchema,
|
|
44
|
+
dependencies: [
|
|
45
|
+
{ path: ['classifications', 'userPermissions'], errorName: 'UserPermClassificationRequiredForPermSets' },
|
|
46
|
+
],
|
|
38
47
|
},
|
|
39
48
|
connectedApps: {
|
|
40
49
|
schema: PolicyFileSchema,
|
|
@@ -60,7 +69,10 @@ export default class AuditConfigFileManager {
|
|
|
60
69
|
parse(dirPath) {
|
|
61
70
|
const classifications = this.parseSubdir(dirPath, 'classifications');
|
|
62
71
|
const policies = capitalizeKeys(this.parseSubdir(dirPath, 'policies'));
|
|
63
|
-
|
|
72
|
+
const conf = { classifications, policies };
|
|
73
|
+
assertIsMinimalConfig(conf, dirPath);
|
|
74
|
+
this.validateDependencies(conf);
|
|
75
|
+
return conf;
|
|
64
76
|
}
|
|
65
77
|
/**
|
|
66
78
|
* Writes a full audit config to disk. If the config was not
|
|
@@ -94,7 +106,7 @@ export default class AuditConfigFileManager {
|
|
|
94
106
|
return;
|
|
95
107
|
}
|
|
96
108
|
Object.entries(configFiles).forEach(([fileKey, confFile]) => {
|
|
97
|
-
const uncapitalizedKey =
|
|
109
|
+
const uncapitalizedKey = uncapitalize(fileKey);
|
|
98
110
|
const fileDef = dirConf[uncapitalizedKey];
|
|
99
111
|
if (fileDef && !isEmpty(confFile.content)) {
|
|
100
112
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -103,11 +115,44 @@ export default class AuditConfigFileManager {
|
|
|
103
115
|
}
|
|
104
116
|
});
|
|
105
117
|
}
|
|
118
|
+
validateDependencies(conf) {
|
|
119
|
+
Object.keys(conf.policies).forEach((policyName) => {
|
|
120
|
+
const policyDef = this.directoryStructure.policies[uncapitalize(policyName)];
|
|
121
|
+
if (policyDef?.dependencies) {
|
|
122
|
+
policyDef.dependencies.forEach((dependency) => {
|
|
123
|
+
if (!dependencyExists(dependency.path, conf)) {
|
|
124
|
+
throw messages.createError(dependency.errorName);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
106
130
|
}
|
|
107
131
|
function capitalizeKeys(object) {
|
|
108
132
|
const newObj = {};
|
|
109
|
-
Object.keys(object).forEach((key) => (newObj[
|
|
133
|
+
Object.keys(object).forEach((key) => (newObj[capitalize(key)] = object[key]));
|
|
110
134
|
return newObj;
|
|
111
135
|
}
|
|
136
|
+
function dependencyExists(fullPath, rootNode) {
|
|
137
|
+
const dep = traverseDependencyPath(fullPath, rootNode);
|
|
138
|
+
return Boolean(dep);
|
|
139
|
+
}
|
|
140
|
+
function traverseDependencyPath(remainingPath, rootNode) {
|
|
141
|
+
if (remainingPath.length >= 2) {
|
|
142
|
+
return traverseDependencyPath(remainingPath.slice(1), rootNode[remainingPath[0]]);
|
|
143
|
+
}
|
|
144
|
+
else if (remainingPath.length === 0) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return rootNode[remainingPath[0]];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function assertIsMinimalConfig(conf, dirPath) {
|
|
152
|
+
if (Object.keys(conf.policies).length === 0) {
|
|
153
|
+
const formattedDirPath = !dirPath || dirPath.length === 0 ? '<root-dir>' : dirPath;
|
|
154
|
+
throw messages.createError('NoAuditConfigFound', [formattedDirPath]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
112
157
|
export const DefaultFileManager = new AuditConfigFileManager();
|
|
113
158
|
//# sourceMappingURL=auditConfigFileManager.js.map
|
|
@@ -1 +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;
|
|
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,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAGL,2BAA2B,EAC3B,wBAAwB,EACxB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,oCAAoC,EAA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AC;QAC5C,MAAM,gBAAgB,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;QACnF,MAAM,QAAQ,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { PathLike } from 'node:fs';
|
|
2
1
|
import { Connection } from '@salesforce/core';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
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';
|
|
5
6
|
export default class MDAPI {
|
|
6
7
|
private connection;
|
|
8
|
+
private static retrievers;
|
|
7
9
|
private cache;
|
|
8
10
|
constructor(connection: Connection);
|
|
11
|
+
static create(connection: Connection): MDAPI;
|
|
9
12
|
/**
|
|
10
13
|
* Resolves one of the pre-configured metadata types and returns
|
|
11
14
|
* a map of resolved names and entire XML content of source file body.
|
|
@@ -14,7 +17,7 @@ export default class MDAPI {
|
|
|
14
17
|
* @param componentNames
|
|
15
18
|
* @returns
|
|
16
19
|
*/
|
|
17
|
-
resolve<K extends keyof typeof NamedTypesRegistry>(typeName:
|
|
20
|
+
resolve<K extends keyof typeof NamedTypesRegistry>(typeName: K, componentNames: string[]): Promise<NamedReturnTypes[K]>;
|
|
18
21
|
/**
|
|
19
22
|
* Resolves one of the pre-configured metadata types and returns
|
|
20
23
|
* the entire XML content of source file body.
|
|
@@ -22,75 +25,13 @@ export default class MDAPI {
|
|
|
22
25
|
* @param typeName
|
|
23
26
|
* @returns
|
|
24
27
|
*/
|
|
25
|
-
resolveSingleton<K extends keyof typeof SingletonRegistry>(typeName:
|
|
28
|
+
resolveSingleton<K extends keyof typeof SingletonRegistry>(typeName: K): Promise<SingletonReturnTypes[K]>;
|
|
26
29
|
private cacheResults;
|
|
27
30
|
private fetchCached;
|
|
28
31
|
}
|
|
29
|
-
type MetadataRegistryEntryOpts<Type, Key extends keyof Type> = {
|
|
30
|
-
/**
|
|
31
|
-
* Metadata API name of the type.
|
|
32
|
-
*/
|
|
33
|
-
retrieveType: string;
|
|
34
|
-
/**
|
|
35
|
-
* Metadata API name entity.
|
|
36
|
-
*/
|
|
37
|
-
retrieveName?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Optional XML parser instance. Typically used to fix errors for
|
|
40
|
-
* properties that must be parsed as list.
|
|
41
|
-
*/
|
|
42
|
-
parser?: XMLParser;
|
|
43
|
-
/**
|
|
44
|
-
* Name of the root node in XML file content
|
|
45
|
-
*/
|
|
46
|
-
rootNodeName: Key;
|
|
47
|
-
/**
|
|
48
|
-
* Post processor function that sanitises the XML parse result
|
|
49
|
-
*/
|
|
50
|
-
parsePostProcessor?: (parseResult: Type[Key]) => Type[Key];
|
|
51
|
-
};
|
|
52
|
-
declare abstract class MetadataRegistryEntry<Type, Key extends keyof Type> {
|
|
53
|
-
private opts;
|
|
54
|
-
parser: XMLParser;
|
|
55
|
-
retrieveType: string;
|
|
56
|
-
rootNodeName: Key;
|
|
57
|
-
constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
|
|
58
|
-
parse(fullFilePath: PathLike): Type[Key];
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The entry is a type that only has one single instance on the org, such as
|
|
62
|
-
* a Setting. The component is retrieved by its root node name
|
|
63
|
-
* (e.g. ConnectedAppSettings, AccountSettings, etc).
|
|
64
|
-
*/
|
|
65
|
-
declare class SingletonMetadata<Type, Key extends keyof Type> extends MetadataRegistryEntry<Type, Key> {
|
|
66
|
-
retrieveName: string;
|
|
67
|
-
constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
|
|
68
|
-
/**
|
|
69
|
-
* Resolves component names, retrieves the metadata and returns
|
|
70
|
-
* as a strongly typed result.
|
|
71
|
-
*
|
|
72
|
-
* @param con
|
|
73
|
-
* @param componentNames
|
|
74
|
-
* @returns
|
|
75
|
-
*/
|
|
76
|
-
resolve(con: Connection): Promise<Type[Key]>;
|
|
77
|
-
private parseSourceFile;
|
|
78
|
-
}
|
|
79
|
-
declare class NamedMetadata<Type, Key extends keyof Type> extends MetadataRegistryEntry<Type, Key> {
|
|
80
|
-
constructor(opts: MetadataRegistryEntryOpts<Type, Key>);
|
|
81
|
-
/**
|
|
82
|
-
* Resolves component names, retrieves the metadata and returns
|
|
83
|
-
* as a strongly typed result.
|
|
84
|
-
*
|
|
85
|
-
* @param con
|
|
86
|
-
* @param componentNames
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
resolve(con: Connection, componentNames: string[]): Promise<Record<string, Type[Key]>>;
|
|
90
|
-
private parseSourceFiles;
|
|
91
|
-
}
|
|
92
32
|
export declare const NamedTypesRegistry: {
|
|
93
33
|
PermissionSet: NamedMetadata<PermissionSetXml, "PermissionSet">;
|
|
34
|
+
Profile: NamedMetadataQueryable<ProfileXml, "Profile">;
|
|
94
35
|
};
|
|
95
36
|
export declare const SingletonRegistry: {
|
|
96
37
|
ConnectedAppSettings: SingletonMetadata<ConnectedAppSettingsXml, "ConnectedAppSettings">;
|
|
@@ -101,6 +42,9 @@ type NamedReturnTypes = {
|
|
|
101
42
|
type SingletonReturnTypes = {
|
|
102
43
|
[K in keyof typeof SingletonRegistry]: Awaited<ReturnType<(typeof SingletonRegistry)[K]['resolve']>>;
|
|
103
44
|
};
|
|
45
|
+
type ProfileXml = {
|
|
46
|
+
Profile: ProfileMetadata;
|
|
47
|
+
};
|
|
104
48
|
type PermissionSetXml = {
|
|
105
49
|
PermissionSet: PermissionSet;
|
|
106
50
|
};
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
|
|
3
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';
|
|
4
5
|
export default class MDAPI {
|
|
5
6
|
connection;
|
|
7
|
+
static retrievers = new Map();
|
|
6
8
|
cache;
|
|
7
9
|
constructor(connection) {
|
|
8
10
|
this.connection = connection;
|
|
9
11
|
this.cache = new MetadataCache();
|
|
10
12
|
}
|
|
13
|
+
static create(connection) {
|
|
14
|
+
if (!this.retrievers.has(connection.instanceUrl)) {
|
|
15
|
+
this.retrievers.set(connection.instanceUrl, new MDAPI(connection));
|
|
16
|
+
}
|
|
17
|
+
return this.retrievers.get(connection.instanceUrl);
|
|
18
|
+
}
|
|
11
19
|
/**
|
|
12
20
|
* Resolves one of the pre-configured metadata types and returns
|
|
13
21
|
* a map of resolved names and entire XML content of source file body.
|
|
@@ -80,94 +88,6 @@ class MetadataCache {
|
|
|
80
88
|
this.components[cmpName] = content;
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
|
-
class MetadataRegistryEntry {
|
|
84
|
-
opts;
|
|
85
|
-
parser;
|
|
86
|
-
retrieveType;
|
|
87
|
-
rootNodeName;
|
|
88
|
-
constructor(opts) {
|
|
89
|
-
this.opts = opts;
|
|
90
|
-
this.retrieveType = this.opts.retrieveType;
|
|
91
|
-
this.parser = this.opts.parser ?? new XMLParser();
|
|
92
|
-
this.rootNodeName = this.opts.rootNodeName;
|
|
93
|
-
}
|
|
94
|
-
parse(fullFilePath) {
|
|
95
|
-
const fileContent = readFileSync(fullFilePath, 'utf-8');
|
|
96
|
-
const parsedContent = this.parser.parse(fileContent);
|
|
97
|
-
if (this.opts.parsePostProcessor) {
|
|
98
|
-
return this.opts.parsePostProcessor(parsedContent[this.rootNodeName]);
|
|
99
|
-
}
|
|
100
|
-
return parsedContent[this.rootNodeName];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* The entry is a type that only has one single instance on the org, such as
|
|
105
|
-
* a Setting. The component is retrieved by its root node name
|
|
106
|
-
* (e.g. ConnectedAppSettings, AccountSettings, etc).
|
|
107
|
-
*/
|
|
108
|
-
class SingletonMetadata extends MetadataRegistryEntry {
|
|
109
|
-
retrieveName;
|
|
110
|
-
constructor(opts) {
|
|
111
|
-
super(opts);
|
|
112
|
-
this.retrieveName = opts.retrieveName ?? String(this.rootNodeName);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Resolves component names, retrieves the metadata and returns
|
|
116
|
-
* as a strongly typed result.
|
|
117
|
-
*
|
|
118
|
-
* @param con
|
|
119
|
-
* @param componentNames
|
|
120
|
-
* @returns
|
|
121
|
-
*/
|
|
122
|
-
async resolve(con) {
|
|
123
|
-
const cmpSet = new ComponentSet([{ type: this.retrieveType, fullName: this.retrieveName }]);
|
|
124
|
-
const retrieveResult = await retrieve(cmpSet, con);
|
|
125
|
-
return this.parseSourceFile(retrieveResult.components);
|
|
126
|
-
}
|
|
127
|
-
parseSourceFile(componentSet) {
|
|
128
|
-
const cmps = componentSet.getSourceComponents({ type: this.retrieveType, fullName: this.retrieveName }).toArray();
|
|
129
|
-
if (cmps.length > 0 && cmps[0].xml) {
|
|
130
|
-
return this.parse(cmps[0].xml);
|
|
131
|
-
}
|
|
132
|
-
throw new Error('Failed to resolve settings for: ' + this.retrieveName);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
class NamedMetadata extends MetadataRegistryEntry {
|
|
136
|
-
constructor(opts) {
|
|
137
|
-
super(opts);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Resolves component names, retrieves the metadata and returns
|
|
141
|
-
* as a strongly typed result.
|
|
142
|
-
*
|
|
143
|
-
* @param con
|
|
144
|
-
* @param componentNames
|
|
145
|
-
* @returns
|
|
146
|
-
*/
|
|
147
|
-
async resolve(con, componentNames) {
|
|
148
|
-
const cmpSet = new ComponentSet(componentNames.map((cname) => ({ type: this.retrieveType, fullName: cname })));
|
|
149
|
-
const retrieveResult = await retrieve(cmpSet, con);
|
|
150
|
-
return this.parseSourceFiles(retrieveResult.components, componentNames);
|
|
151
|
-
}
|
|
152
|
-
parseSourceFiles(componentSet, retrievedNames) {
|
|
153
|
-
const cmps = componentSet.getSourceComponents().toArray();
|
|
154
|
-
const result = {};
|
|
155
|
-
cmps.forEach((sourceComponent) => {
|
|
156
|
-
if (sourceComponent.xml && retrievedNames.includes(sourceComponent.name)) {
|
|
157
|
-
result[sourceComponent.name] = this.parse(sourceComponent.xml);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async function retrieve(compSet, con) {
|
|
164
|
-
const retrieveRequest = await compSet.retrieve({
|
|
165
|
-
usernameOrConnection: con,
|
|
166
|
-
output: '.jsc/retrieves',
|
|
167
|
-
});
|
|
168
|
-
const retrieveResult = await retrieveRequest.pollStatus();
|
|
169
|
-
return retrieveResult;
|
|
170
|
-
}
|
|
171
91
|
export const NamedTypesRegistry = {
|
|
172
92
|
PermissionSet: new NamedMetadata({
|
|
173
93
|
retrieveType: 'PermissionSet',
|
|
@@ -182,6 +102,16 @@ export const NamedTypesRegistry = {
|
|
|
182
102
|
classAccesses: parseResult.classAccesses ?? [],
|
|
183
103
|
}),
|
|
184
104
|
}),
|
|
105
|
+
Profile: new NamedMetadataQueryable({
|
|
106
|
+
objectName: 'Profile',
|
|
107
|
+
nameField: 'Name',
|
|
108
|
+
parsePostProcessor: (parseResult) => ({
|
|
109
|
+
...parseResult,
|
|
110
|
+
userPermissions: parseResult.userPermissions ?? [],
|
|
111
|
+
customPermissions: parseResult.customPermissions ?? [],
|
|
112
|
+
classAccesses: parseResult.classAccesses ?? [],
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
185
115
|
};
|
|
186
116
|
export const SingletonRegistry = {
|
|
187
117
|
ConnectedAppSettings: new SingletonMetadata({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdapiRetriever.js","sourceRoot":"","sources":["../../../../src/libs/core/mdapi/mdapiRetriever.ts"],"names":[],"mappings":"
|
|
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;IAIG;IAHnB,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAC;IAC7C,KAAK,CAAgB;IAE7B,YAA2B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,UAAsB;QACzC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAE,CAAC;IACtD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAClB,QAAW,EACX,cAAwB;QAExB,MAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC/C,M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AC,QAAQ,CAAC,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,40 @@
|
|
|
1
|
+
import { PathLike } from 'node:fs';
|
|
2
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
3
|
+
import { ComponentSet, FileResponse, 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>;
|
|
40
|
+
export declare function cleanRetrieveDir(files: FileResponse[]): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
4
|
+
import { RETRIEVE_CACHE } from '../constants.js';
|
|
5
|
+
export default class MetadataRegistryEntry {
|
|
6
|
+
opts;
|
|
7
|
+
parser;
|
|
8
|
+
retrieveType;
|
|
9
|
+
rootNodeName;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
this.retrieveType = this.opts.retrieveType;
|
|
13
|
+
this.parser = this.opts.parser ?? new XMLParser();
|
|
14
|
+
this.rootNodeName = this.opts.rootNodeName;
|
|
15
|
+
}
|
|
16
|
+
parse(fullFilePath) {
|
|
17
|
+
const fileContent = readFileSync(fullFilePath, 'utf-8');
|
|
18
|
+
const parsedContent = this.parser.parse(fileContent);
|
|
19
|
+
if (this.opts.parsePostProcessor) {
|
|
20
|
+
return this.opts.parsePostProcessor(parsedContent[this.rootNodeName]);
|
|
21
|
+
}
|
|
22
|
+
return parsedContent[this.rootNodeName];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function retrieve(compSet, con) {
|
|
26
|
+
const retrieveRequest = await compSet.retrieve({
|
|
27
|
+
usernameOrConnection: con,
|
|
28
|
+
output: RETRIEVE_CACHE,
|
|
29
|
+
});
|
|
30
|
+
const retrieveResult = await retrieveRequest.pollStatus();
|
|
31
|
+
return retrieveResult;
|
|
32
|
+
}
|
|
33
|
+
export function cleanRetrieveDir(files) {
|
|
34
|
+
const dirNames = new Set();
|
|
35
|
+
files.forEach((file) => {
|
|
36
|
+
if (file.filePath) {
|
|
37
|
+
const dirName = path.dirname(path.normalize(file.filePath));
|
|
38
|
+
const parts = dirName.split(path.sep).filter((dirPart) => dirPart.startsWith('metadataPackage_'));
|
|
39
|
+
parts.forEach((mdPart) => dirNames.add(mdPart));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
dirNames.forEach((dir) => {
|
|
43
|
+
rmSync(path.join(RETRIEVE_CACHE, dir), { recursive: true });
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# 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,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,MAAM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I,EAAE,EAAE;QACrB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC;YAClG,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { NamedMetadataResolver } from './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
|
+
}
|