rflib-plugin 0.21.9 → 0.22.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 +56 -3
- package/lib/commands/rflib/debug/userpermissions/check.d.ts +21 -0
- package/lib/commands/rflib/debug/userpermissions/check.js +100 -0
- package/lib/commands/rflib/debug/userpermissions/check.js.map +1 -0
- package/lib/commands/rflib/logging/flow/instrument.js +30 -8
- package/lib/commands/rflib/logging/flow/instrument.js.map +1 -1
- package/lib/shared/orgClient.d.ts +2 -0
- package/lib/shared/orgClient.js +1 -0
- package/lib/shared/orgClient.js.map +1 -1
- package/lib/shared/packageClient.d.ts +32 -3
- package/lib/shared/packageClient.js +68 -9
- package/lib/shared/packageClient.js.map +1 -1
- package/lib/shared/permissionAggregator.d.ts +15 -0
- package/lib/shared/permissionAggregator.js +5 -5
- package/lib/shared/permissionAggregator.js.map +1 -1
- package/lib/shared/permissionCheck.d.ts +58 -0
- package/lib/shared/permissionCheck.js +365 -0
- package/lib/shared/permissionCheck.js.map +1 -0
- package/messages/rflib.debug.userpermissions.check.md +136 -0
- package/messages/rflib.logging.flow.instrument.md +11 -3
- package/oclif.manifest.json +789 -626
- package/package.json +2 -2
- package/oclif.lock +0 -7314
package/README.md
CHANGED
|
@@ -134,12 +134,12 @@ sf rflib logging flow instrument --target-org myOrg --sourcepath force-app --ski
|
|
|
134
134
|
|
|
135
135
|
The fault paths this command creates log the error and then stop the Flow using the `Terminate Transaction` option of the RFLIB `Log Message` action. That option was added in RFLIB 11.4.0, so a Flow that uses it fails to deploy to an org running an older RFLIB version.
|
|
136
136
|
|
|
137
|
-
To avoid producing Flows that won't deploy, the command checks the RFLIB
|
|
137
|
+
To avoid producing Flows that won't deploy, the command checks the RFLIB version of the target org before it changes any files. It uses the installed RFLIB package or, if RFLIB was deployed as unpackaged source (as in a development org), the `RFLIB_Version` custom label that RFLIB ships with its source:
|
|
138
138
|
|
|
139
139
|
- **RFLIB 11.4.0 or later:** fault paths are instrumented.
|
|
140
|
-
- **An older RFLIB version,
|
|
140
|
+
- **An older RFLIB version, RFLIB not found, or the version can't be determined:** fault paths are skipped and a warning is shown. Flow start and decision logging are still added. Run `sf rflib packages upgrade` to upgrade an installed package, or deploy a newer RFLIB version if RFLIB was deployed as source.
|
|
141
141
|
|
|
142
|
-
The check is a
|
|
142
|
+
The check is a read-only Tooling API query of the org's installed packages (`InstalledSubscriberPackage`), followed by a query of the `RFLIB_Version` custom label (`ExternalString`) if RFLIB is not installed as a package. The command doesn't change or deploy anything to the org; it only edits the Flow files under `--sourcepath`. Pass the org you'll deploy the instrumented Flows to. The flag is required even with `--skip-fault-paths`, although the org isn't queried in that case.
|
|
143
143
|
|
|
144
144
|
#### Features
|
|
145
145
|
|
|
@@ -269,6 +269,59 @@ sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX
|
|
|
269
269
|
|
|
270
270
|
---
|
|
271
271
|
|
|
272
|
+
### `sf rflib debug userpermissions check`
|
|
273
|
+
|
|
274
|
+
Check whether a user has one specific permission, and which profile, permission sets, and permission set groups grant it. Where `userpermissions get` returns the raw permission records, `check` answers a single question with a verdict, which makes it a good fit for scripts and AI agents.
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Can the user edit a field?
|
|
278
|
+
sf rflib debug userpermissions check --target-org myOrg --user jane@example.com --field Account.AnnualRevenue --access edit
|
|
279
|
+
|
|
280
|
+
# Can the user delete Opportunity records?
|
|
281
|
+
sf rflib debug userpermissions check --target-org myOrg --user 0057000000XXXXXX --object Opportunity --access delete
|
|
282
|
+
|
|
283
|
+
# Apex class, Visualforce page, custom permission, and system permission access
|
|
284
|
+
sf rflib debug userpermissions check --target-org myOrg --user jane@example.com --apex-class OrderController
|
|
285
|
+
sf rflib debug userpermissions check --target-org myOrg --user jane@example.com --apex-page OrderPage
|
|
286
|
+
sf rflib debug userpermissions check --target-org myOrg --user jane@example.com --custom-permission Approve_Discounts
|
|
287
|
+
sf rflib debug userpermissions check --target-org myOrg --user jane@example.com --system-permission ModifyAllData
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Example output:
|
|
291
|
+
|
|
292
|
+
```text
|
|
293
|
+
NOT GRANTED: jane@example.com doesn't have Edit access on Account.AnnualRevenue.
|
|
294
|
+
Granted by:
|
|
295
|
+
Permission Set "Sales Reports" (PermissionsEdit)
|
|
296
|
+
Note: The user has field-level access, but no Edit permission on Account, so the field isn't accessible.
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
With `--json`, the result contains `granted`, a one-line `summary`, the granting `sources`, and `notes`. Field checks also return `fieldPermissionGranted` and the user's Read and Edit access on the object (`objectAccess`).
|
|
300
|
+
|
|
301
|
+
The check follows the Salesforce permission rules:
|
|
302
|
+
|
|
303
|
+
- A field is only accessible when the user also has the matching permission on the object. View All Fields on the object grants Read on all of its fields. Fields without field-level security (such as `Id` or `Name`) follow the object permission, and formula and auto-number fields can't be edited.
|
|
304
|
+
- Access to Apex classes and Visualforce pages includes access granted by the Author Apex and Customize Application system permissions.
|
|
305
|
+
- Inactive users are reported in the notes.
|
|
306
|
+
- Sharing and record-level access aren't checked.
|
|
307
|
+
|
|
308
|
+
The command only reads standard setup objects, so the RFLIB package doesn't need to be installed. The running user needs the View Setup and Configuration permission.
|
|
309
|
+
|
|
310
|
+
#### Command Options
|
|
311
|
+
|
|
312
|
+
- `--target-org (-o)`: Username or alias of the target org *(required)*
|
|
313
|
+
- `--user (-u)`: User ID (15 or 18 character) or username *(required)*
|
|
314
|
+
- Exactly one of:
|
|
315
|
+
- `--object (-b)`: Object API name, e.g. `Account`
|
|
316
|
+
- `--field (-f)`: Field in the form `Object.Field`, e.g. `Account.AnnualRevenue`
|
|
317
|
+
- `--apex-class`: Apex class name; use `namespace__Name` or `namespace.Name` for managed classes
|
|
318
|
+
- `--apex-page`: Visualforce page name; use `namespace__Name` for managed pages
|
|
319
|
+
- `--custom-permission`: Custom permission API name
|
|
320
|
+
- `--system-permission`: System permission API name, e.g. `ModifyAllData`, `ViewSetup`, `ApiEnabled`
|
|
321
|
+
- `--access (-a)`: Access level for `--object` or `--field` (default: `read`). Objects: `read`, `create`, `edit`, `delete`, `viewall`, `modifyall`, `viewallfields`. Fields: `read`, `edit`.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
272
325
|
## RFLIB Package Commands
|
|
273
326
|
|
|
274
327
|
### `sf rflib packages upgrade`
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { type CheckUserPermissionResult } from '../../../../shared/orgClient.js';
|
|
3
|
+
export type RflibDebugUserPermissionsCheckResult = CheckUserPermissionResult;
|
|
4
|
+
export default class RflibDebugUserPermissionsCheck extends SfCommand<RflibDebugUserPermissionsCheckResult> {
|
|
5
|
+
static readonly summary: string;
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly examples: string[];
|
|
8
|
+
static readonly flags: {
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
user: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
object: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
field: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
access: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'apex-class': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
'apex-page': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
'custom-permission': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
'system-permission': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<RflibDebugUserPermissionsCheckResult>;
|
|
20
|
+
private report;
|
|
21
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Messages } from '@salesforce/core';
|
|
3
|
+
import { ACCESS_LEVELS, checkUserPermission, } from '../../../../shared/orgClient.js';
|
|
4
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
5
|
+
const messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.check');
|
|
6
|
+
const CHECK_FLAGS = ['object', 'field', 'apex-class', 'apex-page', 'custom-permission', 'system-permission'];
|
|
7
|
+
const SOURCE_LABELS = {
|
|
8
|
+
Profile: 'Profile',
|
|
9
|
+
PermissionSet: 'Permission Set',
|
|
10
|
+
PermissionSetGroup: 'Permission Set Group',
|
|
11
|
+
};
|
|
12
|
+
export default class RflibDebugUserPermissionsCheck extends SfCommand {
|
|
13
|
+
static summary = messages.getMessage('summary');
|
|
14
|
+
static description = messages.getMessage('description');
|
|
15
|
+
static examples = messages.getMessages('examples');
|
|
16
|
+
static flags = {
|
|
17
|
+
'target-org': Flags.requiredOrg({
|
|
18
|
+
summary: messages.getMessage('flags.target-org.summary'),
|
|
19
|
+
description: messages.getMessage('flags.target-org.description'),
|
|
20
|
+
char: 'o',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
user: Flags.string({
|
|
24
|
+
summary: messages.getMessage('flags.user.summary'),
|
|
25
|
+
description: messages.getMessage('flags.user.description'),
|
|
26
|
+
char: 'u',
|
|
27
|
+
required: true,
|
|
28
|
+
}),
|
|
29
|
+
object: Flags.string({
|
|
30
|
+
summary: messages.getMessage('flags.object.summary'),
|
|
31
|
+
description: messages.getMessage('flags.object.description'),
|
|
32
|
+
char: 'b',
|
|
33
|
+
exactlyOne: CHECK_FLAGS,
|
|
34
|
+
}),
|
|
35
|
+
field: Flags.string({
|
|
36
|
+
summary: messages.getMessage('flags.field.summary'),
|
|
37
|
+
description: messages.getMessage('flags.field.description'),
|
|
38
|
+
char: 'f',
|
|
39
|
+
exactlyOne: CHECK_FLAGS,
|
|
40
|
+
}),
|
|
41
|
+
access: Flags.string({
|
|
42
|
+
summary: messages.getMessage('flags.access.summary'),
|
|
43
|
+
description: messages.getMessage('flags.access.description'),
|
|
44
|
+
char: 'a',
|
|
45
|
+
options: ACCESS_LEVELS,
|
|
46
|
+
}),
|
|
47
|
+
'apex-class': Flags.string({
|
|
48
|
+
summary: messages.getMessage('flags.apex-class.summary'),
|
|
49
|
+
description: messages.getMessage('flags.apex-class.description'),
|
|
50
|
+
exactlyOne: CHECK_FLAGS,
|
|
51
|
+
}),
|
|
52
|
+
'apex-page': Flags.string({
|
|
53
|
+
summary: messages.getMessage('flags.apex-page.summary'),
|
|
54
|
+
description: messages.getMessage('flags.apex-page.description'),
|
|
55
|
+
exactlyOne: CHECK_FLAGS,
|
|
56
|
+
}),
|
|
57
|
+
'custom-permission': Flags.string({
|
|
58
|
+
summary: messages.getMessage('flags.custom-permission.summary'),
|
|
59
|
+
description: messages.getMessage('flags.custom-permission.description'),
|
|
60
|
+
exactlyOne: CHECK_FLAGS,
|
|
61
|
+
}),
|
|
62
|
+
'system-permission': Flags.string({
|
|
63
|
+
summary: messages.getMessage('flags.system-permission.summary'),
|
|
64
|
+
description: messages.getMessage('flags.system-permission.description'),
|
|
65
|
+
exactlyOne: CHECK_FLAGS,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
async run() {
|
|
69
|
+
const { flags } = await this.parse(RflibDebugUserPermissionsCheck);
|
|
70
|
+
const conn = flags['target-org'].getConnection(undefined);
|
|
71
|
+
this.spinner.start('Checking user permission...');
|
|
72
|
+
const result = await checkUserPermission(conn, {
|
|
73
|
+
user: flags.user,
|
|
74
|
+
object: flags.object,
|
|
75
|
+
field: flags.field,
|
|
76
|
+
access: flags.access,
|
|
77
|
+
apexClass: flags['apex-class'],
|
|
78
|
+
apexPage: flags['apex-page'],
|
|
79
|
+
customPermission: flags['custom-permission'],
|
|
80
|
+
systemPermission: flags['system-permission'],
|
|
81
|
+
});
|
|
82
|
+
this.spinner.stop();
|
|
83
|
+
this.report(result);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
report(result) {
|
|
87
|
+
this.log(messages.getMessage(result.granted ? 'info.granted' : 'info.notGranted', [result.summary]));
|
|
88
|
+
if (result.sources.length > 0) {
|
|
89
|
+
this.log(messages.getMessage('info.sources'));
|
|
90
|
+
for (const source of result.sources) {
|
|
91
|
+
// Indented here because the message loader strips leading whitespace.
|
|
92
|
+
this.log(` ${messages.getMessage('info.source', [SOURCE_LABELS[source.type], source.name, source.permission])}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const note of result.notes) {
|
|
96
|
+
this.log(messages.getMessage('info.note', [note]));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/debug/userpermissions/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,aAAa,EACb,mBAAmB,GAGpB,MAAM,iCAAiC,CAAC;AAIzC,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,mCAAmC,CAAC,CAAC;AAE5F,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,YAA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AAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CACxG,CAAC;YACJ,CAAC;QACH,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;IACH,CAAC","sourcesContent":["import { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages } from '@salesforce/core';\nimport {\n ACCESS_LEVELS,\n checkUserPermission,\n type CheckUserPermissionResult,\n type PermissionSource,\n} from '../../../../shared/orgClient.js';\n\nexport type RflibDebugUserPermissionsCheckResult = CheckUserPermissionResult;\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.check');\n\nconst CHECK_FLAGS = ['object', 'field', 'apex-class', 'apex-page', 'custom-permission', 'system-permission'];\n\nconst SOURCE_LABELS: Record<PermissionSource['type'], string> = {\n Profile: 'Profile',\n PermissionSet: 'Permission Set',\n PermissionSetGroup: 'Permission Set Group',\n};\n\nexport default class RflibDebugUserPermissionsCheck extends SfCommand<RflibDebugUserPermissionsCheckResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n 'target-org': Flags.requiredOrg({\n summary: messages.getMessage('flags.target-org.summary'),\n description: messages.getMessage('flags.target-org.description'),\n char: 'o',\n required: true,\n }),\n user: Flags.string({\n summary: messages.getMessage('flags.user.summary'),\n description: messages.getMessage('flags.user.description'),\n char: 'u',\n required: true,\n }),\n object: Flags.string({\n summary: messages.getMessage('flags.object.summary'),\n description: messages.getMessage('flags.object.description'),\n char: 'b',\n exactlyOne: CHECK_FLAGS,\n }),\n field: Flags.string({\n summary: messages.getMessage('flags.field.summary'),\n description: messages.getMessage('flags.field.description'),\n char: 'f',\n exactlyOne: CHECK_FLAGS,\n }),\n access: Flags.string({\n summary: messages.getMessage('flags.access.summary'),\n description: messages.getMessage('flags.access.description'),\n char: 'a',\n options: ACCESS_LEVELS,\n }),\n 'apex-class': Flags.string({\n summary: messages.getMessage('flags.apex-class.summary'),\n description: messages.getMessage('flags.apex-class.description'),\n exactlyOne: CHECK_FLAGS,\n }),\n 'apex-page': Flags.string({\n summary: messages.getMessage('flags.apex-page.summary'),\n description: messages.getMessage('flags.apex-page.description'),\n exactlyOne: CHECK_FLAGS,\n }),\n 'custom-permission': Flags.string({\n summary: messages.getMessage('flags.custom-permission.summary'),\n description: messages.getMessage('flags.custom-permission.description'),\n exactlyOne: CHECK_FLAGS,\n }),\n 'system-permission': Flags.string({\n summary: messages.getMessage('flags.system-permission.summary'),\n description: messages.getMessage('flags.system-permission.description'),\n exactlyOne: CHECK_FLAGS,\n }),\n };\n\n public async run(): Promise<RflibDebugUserPermissionsCheckResult> {\n const { flags } = await this.parse(RflibDebugUserPermissionsCheck);\n const conn = flags['target-org'].getConnection(undefined);\n\n this.spinner.start('Checking user permission...');\n const result = await checkUserPermission(conn, {\n user: flags.user,\n object: flags.object,\n field: flags.field,\n access: flags.access,\n apexClass: flags['apex-class'],\n apexPage: flags['apex-page'],\n customPermission: flags['custom-permission'],\n systemPermission: flags['system-permission'],\n });\n this.spinner.stop();\n\n this.report(result);\n return result;\n }\n\n private report(result: CheckUserPermissionResult): void {\n this.log(messages.getMessage(result.granted ? 'info.granted' : 'info.notGranted', [result.summary]));\n if (result.sources.length > 0) {\n this.log(messages.getMessage('info.sources'));\n for (const source of result.sources) {\n // Indented here because the message loader strips leading whitespace.\n this.log(\n ` ${messages.getMessage('info.source', [SOURCE_LABELS[source.type], source.name, source.permission])}`,\n );\n }\n }\n for (const note of result.notes) {\n this.log(messages.getMessage('info.note', [note]));\n }\n }\n}\n"]}
|
|
@@ -11,13 +11,23 @@ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
|
11
11
|
import * as xml2js from 'xml2js';
|
|
12
12
|
import { processWithConcurrency } from '../../../../shared/concurrency.js';
|
|
13
13
|
import { isExcluded } from '../../../../shared/exclude.js';
|
|
14
|
-
import { compareVersions, formatVersion, getInstalledPackages, } from '../../../../shared/packageClient.js';
|
|
14
|
+
import { compareVersions, formatVersion, getInstalledPackages, getRflibVersionFromLabel, RFLIB_VERSION_LABEL, } from '../../../../shared/packageClient.js';
|
|
15
15
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
16
16
|
const messages = Messages.loadMessages('rflib-plugin', 'rflib.logging.flow.instrument');
|
|
17
17
|
const RFLIB_PACKAGE_NAME = 'RFLIB';
|
|
18
18
|
// First RFLIB version whose Log Message flow action has the Terminate Transaction option,
|
|
19
19
|
// which the fault paths created by this command rely on
|
|
20
20
|
const FAULT_PATH_MIN_RFLIB_VERSION = { major: 11, minor: 4, patch: 0, build: 0 };
|
|
21
|
+
// Formats a version the way the RFLIB_Version label shows it, e.g. 11.4.0
|
|
22
|
+
const formatLabelVersion = (version) => `${version.major}.${version.minor}.${version.patch}`;
|
|
23
|
+
// Prefers the installed RFLIB package and falls back to the version label of RFLIB deployed as source
|
|
24
|
+
const getRflibVersion = async (conn) => {
|
|
25
|
+
const [rflibPackage] = await getInstalledPackages(conn, [RFLIB_PACKAGE_NAME]);
|
|
26
|
+
if (rflibPackage)
|
|
27
|
+
return { version: rflibPackage.version, deployedAsSource: false };
|
|
28
|
+
const labelVersion = await getRflibVersionFromLabel(conn);
|
|
29
|
+
return labelVersion && { version: labelVersion, deployedAsSource: true };
|
|
30
|
+
};
|
|
21
31
|
export class FlowInstrumentationService {
|
|
22
32
|
static parser = new xml2js.Parser({
|
|
23
33
|
explicitArray: false,
|
|
@@ -695,20 +705,32 @@ export default class RflibLoggingFlowInstrument extends SfCommand {
|
|
|
695
705
|
this.log(`Modified files: ${this.stats.modifiedFiles}`);
|
|
696
706
|
return { ...this.stats };
|
|
697
707
|
}
|
|
698
|
-
// Fault paths are only instrumented if the RFLIB
|
|
708
|
+
// Fault paths are only instrumented if the RFLIB version in the target org supports terminating the transaction.
|
|
709
|
+
// The version comes from the installed RFLIB package or, in orgs where RFLIB was deployed as source, from its
|
|
710
|
+
// version label. Failing to determine it skips the fault paths rather than failing the command.
|
|
699
711
|
async isFaultPathLoggingSupported(conn) {
|
|
700
|
-
const minVersion =
|
|
701
|
-
|
|
712
|
+
const minVersion = formatLabelVersion(FAULT_PATH_MIN_RFLIB_VERSION);
|
|
713
|
+
let rflib;
|
|
714
|
+
try {
|
|
715
|
+
rflib = await getRflibVersion(conn);
|
|
716
|
+
}
|
|
717
|
+
catch (error) {
|
|
718
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
719
|
+
this.warn(messages.getMessage('warning.faultPaths.versionCheckFailed', [reason, minVersion]));
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
702
722
|
if (!rflib) {
|
|
703
|
-
this.warn(messages.getMessage('warning.faultPaths.rflibNotInstalled', [minVersion]));
|
|
723
|
+
this.warn(messages.getMessage('warning.faultPaths.rflibNotInstalled', [RFLIB_VERSION_LABEL, minVersion]));
|
|
704
724
|
return false;
|
|
705
725
|
}
|
|
706
|
-
const
|
|
726
|
+
const version = rflib.deployedAsSource ? formatLabelVersion(rflib.version) : formatVersion(rflib.version);
|
|
707
727
|
if (compareVersions(rflib.version, FAULT_PATH_MIN_RFLIB_VERSION) < 0) {
|
|
708
|
-
this.warn(
|
|
728
|
+
this.warn(rflib.deployedAsSource
|
|
729
|
+
? messages.getMessage('warning.faultPaths.rflibSourceOutdated', [version, RFLIB_VERSION_LABEL, minVersion])
|
|
730
|
+
: messages.getMessage('warning.faultPaths.rflibOutdated', [version, minVersion]));
|
|
709
731
|
return false;
|
|
710
732
|
}
|
|
711
|
-
this.logger.debug(`RFLIB ${
|
|
733
|
+
this.logger.debug(`RFLIB ${version}${rflib.deployedAsSource ? ' (deployed as source)' : ''} supports fault path logging`);
|
|
712
734
|
return true;
|
|
713
735
|
}
|
|
714
736
|
async findAllFlowFiles(dirPath, excludePattern) {
|