@cclabsnz/sf-audit 1.6.0 → 1.6.1
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 +18 -0
- package/lib/checks/impl/EnhancedDomainsCheck.js +18 -4
- package/package.json +9 -13
- package/lib/findings/ComplianceMapping.d.ts +0 -3
- package/lib/findings/ComplianceMapping.js +0 -75
- package/lib/queries/QueryDefinition.d.ts +0 -48
- package/lib/queries/QueryDefinition.js +0 -11
- package/lib/queries/QueryRegistry.d.ts +0 -13
- package/lib/queries/QueryRegistry.js +0 -93
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @cclabsnz/sf-audit
|
|
2
2
|
|
|
3
|
+
[](https://github.com/cclabsnz/sf-audit-plugin/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/cclabsnz/sf-audit-plugin/actions/workflows/codeql.yml)
|
|
5
|
+
[](https://securityscorecards.dev/viewer/?uri=github.com/cclabsnz/sf-audit-plugin)
|
|
6
|
+
[](https://www.npmjs.com/package/@cclabsnz/sf-audit)
|
|
7
|
+
[](https://www.npmjs.com/package/@cclabsnz/sf-audit#provenance)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
3
10
|
A Salesforce CLI (`sf`) plugin that runs a complete, **read-only** security audit against any Salesforce org, risk-scores it with an A–F grade, and turns the result into a report your security team (or your client's) can act on.
|
|
4
11
|
|
|
5
12
|
- **88 read-only checks** across identity, access, data, code, integrations, monitoring, and Agentforce / GenAI
|
|
@@ -294,6 +301,15 @@ Findings are mapped to controls across eight security and privacy frameworks. Th
|
|
|
294
301
|
|
|
295
302
|
**No warranty.** This software is provided "as is", without warranty of any kind, express or implied. To the maximum extent permitted by law, the authors and CloudCounsel Limited accept no liability for any loss, damage, or claim arising from use of this tool or reliance on its output. Findings are informational and should be validated by a qualified Salesforce security practitioner before any remediation action is taken.
|
|
296
303
|
|
|
304
|
+
## Trust & verification
|
|
305
|
+
|
|
306
|
+
Because this tool authenticates against production orgs, "is it safe to run?" deserves a verifiable answer, not just a claim. Here's how you can check for yourself:
|
|
307
|
+
|
|
308
|
+
- **Read-only, enforced in CI.** The "no writes to your org" promise is a passing test, not a footnote. `test/unit/api/readonly-invariant.test.ts` statically scans the entire source tree and fails the build if any jsforce mutation API, HTTP write verb, or bulk/composite write path ever appears. Every org request funnels through `src/api/*ClientImpl.ts`, which issue only SOQL queries, REST **GET**s, and Metadata reads.
|
|
309
|
+
- **What you install matches the public source.** Releases are published from GitHub Actions with [npm provenance](https://docs.npmjs.com/generating-provenance-statements) — the npm page shows a signed attestation linking the tarball to the exact public commit that built it, so you can audit the code on GitHub and trust the bytes `sf plugins install` pulls down.
|
|
310
|
+
- **Independent scans.** [CodeQL](https://github.com/cclabsnz/sf-audit-plugin/security/code-scanning) static analysis and an [OpenSSF Scorecard](https://securityscorecards.dev/viewer/?uri=github.com/cclabsnz/sf-audit-plugin) supply-chain review run on every change (badges above), and Dependabot plus a CI `pnpm audit` gate keep dependencies current. Each release ships a CycloneDX SBOM.
|
|
311
|
+
- **Least privilege & disclosure.** See [PERMISSIONS.md](PERMISSIONS.md) for the minimal access it needs and [SECURITY.md](SECURITY.md) for private vulnerability reporting.
|
|
312
|
+
|
|
297
313
|
## Scoring
|
|
298
314
|
|
|
299
315
|
Each finding is assigned a risk level with a corresponding weight:
|
|
@@ -582,3 +598,5 @@ npm test # run all tests
|
|
|
582
598
|
npm run test:unit # unit tests only
|
|
583
599
|
npm run clean # remove compiled output
|
|
584
600
|
```
|
|
601
|
+
|
|
602
|
+
Maintainers: see **[docs/RELEASE.md](docs/RELEASE.md)** for the release checklist and the one-time repository-hardening steps (npm provenance token, branch protection, and the CodeQL / Scorecard setup behind the badges above).
|
|
@@ -9,8 +9,21 @@
|
|
|
9
9
|
// 1. My Domain exists (prerequisite)
|
|
10
10
|
// 2. The instance URL uses the enhanced domain format (contains .my.salesforce.com or .develop.my.salesforce.com)
|
|
11
11
|
// 3. Org is not still on a shared instance URL like na1.salesforce.com
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// Patterns are matched against the parsed hostname and anchored to its end, so a URL
|
|
13
|
+
// that merely *contains* the string (e.g. https://evil.example.com/x.my.salesforce.com)
|
|
14
|
+
// cannot be mistaken for an enhanced-domain org. All enhanced variants
|
|
15
|
+
// (sandbox/develop/scratch) are subdomains of my.salesforce.com, so one suffix suffices.
|
|
16
|
+
const ENHANCED_DOMAIN_PATTERN = /\.my\.salesforce\.com$/i;
|
|
17
|
+
const LEGACY_INSTANCE_PATTERN = /^[a-z]{2}\d+\.salesforce\.com$/i;
|
|
18
|
+
/** Parse the hostname from an instance URL; fall back to the raw string if unparseable. */
|
|
19
|
+
function hostnameOf(url) {
|
|
20
|
+
try {
|
|
21
|
+
return new URL(url).hostname;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
14
27
|
export class EnhancedDomainsCheck {
|
|
15
28
|
id = 'enhanced-domains';
|
|
16
29
|
name = 'Enhanced Domains';
|
|
@@ -36,9 +49,10 @@ export class EnhancedDomainsCheck {
|
|
|
36
49
|
}
|
|
37
50
|
const { MyDomain: myDomain, IsSandbox: isSandbox } = org;
|
|
38
51
|
const instanceUrl = baseUrl;
|
|
52
|
+
const instanceHost = hostnameOf(instanceUrl);
|
|
39
53
|
// Check if Enhanced Domains is active based on the instance URL format
|
|
40
|
-
const hasEnhancedDomainUrl = ENHANCED_DOMAIN_PATTERN.test(
|
|
41
|
-
const hasLegacyUrl = LEGACY_INSTANCE_PATTERN.test(
|
|
54
|
+
const hasEnhancedDomainUrl = ENHANCED_DOMAIN_PATTERN.test(instanceHost);
|
|
55
|
+
const hasLegacyUrl = LEGACY_INSTANCE_PATTERN.test(instanceHost);
|
|
42
56
|
const hasMyDomain = !!myDomain;
|
|
43
57
|
if (!hasMyDomain) {
|
|
44
58
|
findings.push({
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclabsnz/sf-audit",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Salesforce Security Audit — native sf plugin",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@10.33.0",
|
|
7
8
|
"main": "lib/index.js",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "tsc -p tsconfig.json",
|
|
10
|
-
"test": "node --experimental-vm-modules node_modules/jest
|
|
11
|
-
"test:unit": "node --experimental-vm-modules node_modules/jest
|
|
11
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --passWithNoTests",
|
|
12
|
+
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js test/unit --passWithNoTests",
|
|
12
13
|
"prepack": "npm run build",
|
|
13
14
|
"clean": "rm -rf lib"
|
|
14
15
|
},
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
"zod": "^3"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
23
|
+
"@jest/globals": "^29.7.0",
|
|
22
24
|
"@types/jest": "^29",
|
|
23
25
|
"@types/node": "^22",
|
|
24
26
|
"jest": "^29",
|
|
@@ -57,16 +59,10 @@
|
|
|
57
59
|
"pnpm": {
|
|
58
60
|
"overrides": {
|
|
59
61
|
"form-data": "^4.0.6",
|
|
60
|
-
"js-yaml@3": "^3.15.0"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"handlebars": "^4.7.9",
|
|
65
|
-
"minimatch@5": {
|
|
66
|
-
"brace-expansion": "^2.0.3"
|
|
67
|
-
},
|
|
68
|
-
"minimatch@10": {
|
|
69
|
-
"brace-expansion": "^5.0.5"
|
|
62
|
+
"js-yaml@3": "^3.15.0",
|
|
63
|
+
"handlebars": "^4.7.9",
|
|
64
|
+
"brace-expansion": "^5.0.8",
|
|
65
|
+
"fast-uri@3": "^3.1.4"
|
|
70
66
|
}
|
|
71
67
|
},
|
|
72
68
|
"files": [
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// Maps each SecurityCheck `id` to its compliance framework references.
|
|
2
|
-
// Tags use the format: <Framework>-<Control> e.g. OWASP-A01, SOC2-CC6.1, ISO-A.9.2, SBS-<domain>-<num>
|
|
3
|
-
export const COMPLIANCE_MAP = {
|
|
4
|
-
'users-and-admins': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-ACS-004'],
|
|
5
|
-
'permissions': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-002', 'SBS-ACS-005'],
|
|
6
|
-
'inactive-users': ['OWASP-A01', 'SOC2-CC6.2', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.5', 'SBS-ACS-007'],
|
|
7
|
-
'login-session': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
8
|
-
'ip-restrictions': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-AUTH-003'],
|
|
9
|
-
'password-session-policy': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
10
|
-
'field-level-security': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.5'],
|
|
11
|
-
'sharing-model': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
12
|
-
'public-group-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
13
|
-
'guest-user-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-CPORTAL-002'],
|
|
14
|
-
'apex-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-001'],
|
|
15
|
-
'flows-without-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-004'],
|
|
16
|
-
'connected-apps': ['OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-OAUTH-001', 'SBS-OAUTH-002', 'SBS-DEP-006'],
|
|
17
|
-
'remote-sites': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32', 'SBS-INT-002'],
|
|
18
|
-
'csp-trusted-sites': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
19
|
-
'named-credentials': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-INT-003'],
|
|
20
|
-
'hardcoded-credentials': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-DEP-005'],
|
|
21
|
-
'custom-settings': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'GDPR-Art.32'],
|
|
22
|
-
'health-check': ['OWASP-A05', 'SOC2-CC7.1', 'ISO-A.12.6', 'GDPR-Art.32', 'SBS-SECCONF-001', 'SBS-SECCONF-002'],
|
|
23
|
-
'audit-trail': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-002'],
|
|
24
|
-
'code-security': ['OWASP-A03', 'OWASP-A05', 'SOC2-CC7.2', 'ISO-A.14.2', 'GDPR-Art.32', 'SBS-CODE-002'],
|
|
25
|
-
'api-limits': ['OWASP-A05', 'SOC2-CC9.1', 'ISO-A.12.6', 'GDPR-Art.32', 'SBS-MON-005'],
|
|
26
|
-
'scheduled-apex': ['OWASP-A05', 'SOC2-CC7.2', 'ISO-A.12.1', 'GDPR-Art.32'],
|
|
27
|
-
// Net-new SBS checks
|
|
28
|
-
'standard-profiles': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-005'],
|
|
29
|
-
'sso-enforcement': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-001', 'SBS-AUTH-002'],
|
|
30
|
-
'mfa-enforcement': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-004'],
|
|
31
|
-
'api-client-permission': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-ACS-006'],
|
|
32
|
-
'integration-users': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-007', 'SBS-ACS-008', 'SBS-ACS-009'],
|
|
33
|
-
'content-links': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.13.2', 'GDPR-Art.32', 'SBS-FILE-001', 'SBS-FILE-002', 'SBS-FILE-003'],
|
|
34
|
-
'field-history-tracking': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-DATA-004'],
|
|
35
|
-
'data-classification': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.8.2', 'HIPAA-164.514', 'GDPR-Art.30', 'SBS-DATA-001', 'SBS-DATA-002', 'SBS-DATA-003'],
|
|
36
|
-
'deployment-identity': ['OWASP-A05', 'SOC2-CC8.1', 'ISO-A.12.1', 'GDPR-Art.32', 'SBS-DEP-001', 'SBS-DEP-003'],
|
|
37
|
-
'apex-logging': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'GDPR-Art.32', 'SBS-CODE-003', 'SBS-CODE-004'],
|
|
38
|
-
'event-monitoring': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-001', 'SBS-INT-004'],
|
|
39
|
-
'siem-integration': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003', 'SBS-MON-004'],
|
|
40
|
-
// Additional security checks
|
|
41
|
-
'apex-crud-fls': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
42
|
-
'apex-rest-endpoint': ['OWASP-A01', 'OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32'],
|
|
43
|
-
'visualforce-xss': ['OWASP-A03', 'SOC2-CC6.1', 'ISO-A.14.2', 'GDPR-Art.32'],
|
|
44
|
-
'certificate-expiry': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.10.1', 'HIPAA-164.312e', 'GDPR-Art.32'],
|
|
45
|
-
'installed-packages': ['OWASP-A06', 'SOC2-CC9.2', 'ISO-A.14.2', 'GDPR-Art.32'],
|
|
46
|
-
'trusted-ip-ranges': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-003'],
|
|
47
|
-
'anonymous-apex-audit': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'GDPR-Art.32'],
|
|
48
|
-
'debug-log-access': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32'],
|
|
49
|
-
'connected-app-inactivity': ['OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.2', 'GDPR-Art.32'],
|
|
50
|
-
'my-domain-login-policy': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-001'],
|
|
51
|
-
'high-assurance-session': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
52
|
-
'enhanced-domains': ['OWASP-A05', 'SOC2-CC6.1', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
53
|
-
// Recent Salesforce MFA improvements
|
|
54
|
-
'internal-user-mfa': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-004'],
|
|
55
|
-
'mfa-registration': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
56
|
-
'mfa-method-strength': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
57
|
-
// Platform hygiene + API security
|
|
58
|
-
'release-updates': ['OWASP-A06', 'SOC2-CC7.1', 'ISO-A.12.6', 'GDPR-Art.32'],
|
|
59
|
-
'legacy-api-version': ['OWASP-A06', 'SOC2-CC6.4', 'ISO-A.12.6', 'GDPR-Art.32'],
|
|
60
|
-
'connected-app-scope': ['OWASP-A01', 'OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-OAUTH-002'],
|
|
61
|
-
// Threat detection + hacker attack surface coverage
|
|
62
|
-
'transaction-security-policy': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003'],
|
|
63
|
-
'failed-login-detection': ['OWASP-A07', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003'],
|
|
64
|
-
'experience-cloud-site': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-003'],
|
|
65
|
-
'custom-labels-credential': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
66
|
-
'report-folder-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
67
|
-
// Attack-chain ingredient checks
|
|
68
|
-
'escalation-perms': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-ACS-004'],
|
|
69
|
-
'cors-allowlist': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
70
|
-
'guest-executable-apex': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-001', 'SBS-CPORTAL-002'],
|
|
71
|
-
};
|
|
72
|
-
export function getComplianceTags(checkId) {
|
|
73
|
-
return COMPLIANCE_MAP[checkId] ?? [];
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=ComplianceMapping.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const QueryDefinitionSchema: z.ZodObject<{
|
|
3
|
-
api: z.ZodEnum<["soql", "tooling", "rest"]>;
|
|
4
|
-
soql: z.ZodOptional<z.ZodString>;
|
|
5
|
-
path: z.ZodOptional<z.ZodString>;
|
|
6
|
-
description: z.ZodString;
|
|
7
|
-
fallbackOnError: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
-
minApiVersion: z.ZodOptional<z.ZodString>;
|
|
9
|
-
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
api: "soql" | "tooling" | "rest";
|
|
11
|
-
description: string;
|
|
12
|
-
fallbackOnError: boolean;
|
|
13
|
-
path?: string | undefined;
|
|
14
|
-
soql?: string | undefined;
|
|
15
|
-
minApiVersion?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
api: "soql" | "tooling" | "rest";
|
|
18
|
-
description: string;
|
|
19
|
-
path?: string | undefined;
|
|
20
|
-
soql?: string | undefined;
|
|
21
|
-
fallbackOnError?: boolean | undefined;
|
|
22
|
-
minApiVersion?: string | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
export type QueryDefinition = z.infer<typeof QueryDefinitionSchema>;
|
|
25
|
-
export declare const QueryFileSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
26
|
-
api: z.ZodEnum<["soql", "tooling", "rest"]>;
|
|
27
|
-
soql: z.ZodOptional<z.ZodString>;
|
|
28
|
-
path: z.ZodOptional<z.ZodString>;
|
|
29
|
-
description: z.ZodString;
|
|
30
|
-
fallbackOnError: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
-
minApiVersion: z.ZodOptional<z.ZodString>;
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
api: "soql" | "tooling" | "rest";
|
|
34
|
-
description: string;
|
|
35
|
-
fallbackOnError: boolean;
|
|
36
|
-
path?: string | undefined;
|
|
37
|
-
soql?: string | undefined;
|
|
38
|
-
minApiVersion?: string | undefined;
|
|
39
|
-
}, {
|
|
40
|
-
api: "soql" | "tooling" | "rest";
|
|
41
|
-
description: string;
|
|
42
|
-
path?: string | undefined;
|
|
43
|
-
soql?: string | undefined;
|
|
44
|
-
fallbackOnError?: boolean | undefined;
|
|
45
|
-
minApiVersion?: string | undefined;
|
|
46
|
-
}>>;
|
|
47
|
-
export type QueryFile = z.infer<typeof QueryFileSchema>;
|
|
48
|
-
//# sourceMappingURL=QueryDefinition.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export const QueryDefinitionSchema = z.object({
|
|
3
|
-
api: z.enum(['soql', 'tooling', 'rest']),
|
|
4
|
-
soql: z.string().optional(),
|
|
5
|
-
path: z.string().optional(),
|
|
6
|
-
description: z.string(),
|
|
7
|
-
fallbackOnError: z.boolean().default(false),
|
|
8
|
-
minApiVersion: z.string().optional(),
|
|
9
|
-
});
|
|
10
|
-
export const QueryFileSchema = z.record(z.string(), QueryDefinitionSchema);
|
|
11
|
-
//# sourceMappingURL=QueryDefinition.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type QueryDefinition } from './QueryDefinition.js';
|
|
2
|
-
import type { QueryResult } from '../api/SoqlClient.js';
|
|
3
|
-
import type { AuditContext } from '../context/AuditContext.js';
|
|
4
|
-
export declare class QueryRegistry {
|
|
5
|
-
private readonly map;
|
|
6
|
-
private constructor();
|
|
7
|
-
static load(configDir: string): QueryRegistry;
|
|
8
|
-
get(id: string): QueryDefinition;
|
|
9
|
-
execute<T>(id: string, ctx: AuditContext): Promise<T[] | null>;
|
|
10
|
-
executeQuery<T>(id: string, ctx: AuditContext): Promise<QueryResult<T> | null>;
|
|
11
|
-
getAll(): ReadonlyMap<string, QueryDefinition>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=QueryRegistry.d.ts.map
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import { QueryFileSchema } from './QueryDefinition.js';
|
|
4
|
-
function warnFallback(id, err) {
|
|
5
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6
|
-
process.stderr.write(`[QueryRegistry] Query '${id}' failed (fallbackOnError): ${msg}\n`);
|
|
7
|
-
}
|
|
8
|
-
export class QueryRegistry {
|
|
9
|
-
map;
|
|
10
|
-
constructor(entries) {
|
|
11
|
-
this.map = entries;
|
|
12
|
-
}
|
|
13
|
-
static load(configDir) {
|
|
14
|
-
const queryDir = path.join(configDir, 'config', 'queries');
|
|
15
|
-
const files = ['soql.json', 'tooling.json'];
|
|
16
|
-
const entries = new Map();
|
|
17
|
-
for (const file of files) {
|
|
18
|
-
const filePath = path.join(queryDir, file);
|
|
19
|
-
let raw;
|
|
20
|
-
try {
|
|
21
|
-
raw = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
throw new Error(`QueryRegistry: failed to read ${filePath}: ${err.message}`);
|
|
25
|
-
}
|
|
26
|
-
const parsed = QueryFileSchema.safeParse(raw);
|
|
27
|
-
if (!parsed.success) {
|
|
28
|
-
throw new Error(`QueryRegistry: invalid schema in ${file}:\n${parsed.error.message}`);
|
|
29
|
-
}
|
|
30
|
-
for (const [key, def] of Object.entries(parsed.data)) {
|
|
31
|
-
if (entries.has(key)) {
|
|
32
|
-
throw new Error(`QueryRegistry: duplicate key '${key}' found in ${file}`);
|
|
33
|
-
}
|
|
34
|
-
entries.set(key, def);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return new QueryRegistry(entries);
|
|
38
|
-
}
|
|
39
|
-
get(id) {
|
|
40
|
-
const def = this.map.get(id);
|
|
41
|
-
if (!def) {
|
|
42
|
-
throw new Error(`QueryRegistry: unknown query key '${id}'`);
|
|
43
|
-
}
|
|
44
|
-
return def;
|
|
45
|
-
}
|
|
46
|
-
async execute(id, ctx) {
|
|
47
|
-
const def = this.get(id);
|
|
48
|
-
try {
|
|
49
|
-
if (def.api === 'soql') {
|
|
50
|
-
if (!def.soql)
|
|
51
|
-
throw new Error(`Query '${id}' has api='soql' but no soql field`);
|
|
52
|
-
return await ctx.soql.queryAll(def.soql);
|
|
53
|
-
}
|
|
54
|
-
if (def.api === 'tooling') {
|
|
55
|
-
if (!def.soql)
|
|
56
|
-
throw new Error(`Query '${id}' has api='tooling' but no soql field`);
|
|
57
|
-
return await ctx.tooling.query(def.soql);
|
|
58
|
-
}
|
|
59
|
-
throw new Error(`QueryRegistry.execute: api='rest' entries cannot be executed here. ` +
|
|
60
|
-
`Use ctx.rest.get() or ctx.tooling.getRecord() directly. Key: '${id}'`);
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
if (def.fallbackOnError) {
|
|
64
|
-
warnFallback(id, err);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async executeQuery(id, ctx) {
|
|
71
|
-
const def = this.get(id);
|
|
72
|
-
if (def.api !== 'soql') {
|
|
73
|
-
throw new Error(`QueryRegistry.executeQuery: query '${id}' must have api='soql'`);
|
|
74
|
-
}
|
|
75
|
-
if (!def.soql) {
|
|
76
|
-
throw new Error(`Query '${id}' has api='soql' but no soql field`);
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return await ctx.soql.query(def.soql);
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
if (def.fallbackOnError) {
|
|
83
|
-
warnFallback(id, err);
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
getAll() {
|
|
90
|
-
return this.map;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=QueryRegistry.js.map
|