@salesforce/capg-client 0.1.0-beta.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/LICENSE.txt +21 -0
- package/README.md +122 -0
- package/dist/client.d.ts +86 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +167 -0
- package/dist/client.js.map +1 -0
- package/dist/connect-api-client.d.ts +82 -0
- package/dist/connect-api-client.d.ts.map +1 -0
- package/dist/connect-api-client.js +106 -0
- package/dist/connect-api-client.js.map +1 -0
- package/dist/constants.d.ts +64 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +68 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/api.d.ts +79 -0
- package/dist/errors/api.d.ts.map +1 -0
- package/dist/errors/api.js +128 -0
- package/dist/errors/api.js.map +1 -0
- package/dist/errors/auth.d.ts +35 -0
- package/dist/errors/auth.d.ts.map +1 -0
- package/dist/errors/auth.js +50 -0
- package/dist/errors/auth.js.map +1 -0
- package/dist/errors/base.d.ts +103 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +162 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/hub-org.d.ts +108 -0
- package/dist/errors/hub-org.d.ts.map +1 -0
- package/dist/errors/hub-org.js +144 -0
- package/dist/errors/hub-org.js.map +1 -0
- package/dist/errors/index.d.ts +33 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +42 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/network.d.ts +53 -0
- package/dist/errors/network.d.ts.map +1 -0
- package/dist/errors/network.js +77 -0
- package/dist/errors/network.js.map +1 -0
- package/dist/errors/validation.d.ts +69 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +96 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/org-pref-checker.d.ts +129 -0
- package/dist/org-pref-checker.d.ts.map +1 -0
- package/dist/org-pref-checker.js +193 -0
- package/dist/org-pref-checker.js.map +1 -0
- package/dist/policy-fetcher.d.ts +144 -0
- package/dist/policy-fetcher.d.ts.map +1 -0
- package/dist/policy-fetcher.js +241 -0
- package/dist/policy-fetcher.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +532 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/result.d.ts +282 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +351 -0
- package/dist/types/result.js.map +1 -0
- package/dist/utils/error-classifier.d.ts +55 -0
- package/dist/utils/error-classifier.d.ts.map +1 -0
- package/dist/utils/error-classifier.js +90 -0
- package/dist/utils/error-classifier.js.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyFetcher - Fetch governance policies from Salesforce org
|
|
3
|
+
*
|
|
4
|
+
* This module provides the core policy fetching capability for the CAPG client library.
|
|
5
|
+
* It queries the DevOps_GovernancePolicy BPO using SOQL and transforms the results
|
|
6
|
+
* into typed Policy objects.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
* @since v1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import { Connection } from '@salesforce/core';
|
|
12
|
+
import { CAPGError } from './errors/index.js';
|
|
13
|
+
import type { DevopsGovernancePolicy, FetchPoliciesOptions } from './types/index.js';
|
|
14
|
+
import { Result } from './types/result.js';
|
|
15
|
+
/**
|
|
16
|
+
* PolicyFetcher - Fetch governance policies from Salesforce org
|
|
17
|
+
*
|
|
18
|
+
* **Phase 1 vs Phase 2 Behavior**:
|
|
19
|
+
* - **Phase 1** (default, enableDirectBPOQuery=false): Uses Connect API via ConnectAPIClient.
|
|
20
|
+
* Makes HTTP POST requests to /services/data/v62.0/connect/governance/policies.
|
|
21
|
+
* - **Phase 2** (enableDirectBPOQuery=true): Executes SOQL queries against DevopsGovernancePolicy BPO.
|
|
22
|
+
* Direct database access for backwards compatibility and testing.
|
|
23
|
+
*
|
|
24
|
+
* @example Phase 1 usage (default - Connect API)
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const fetcher = new PolicyFetcher();
|
|
27
|
+
* const result = await fetcher.fetchPolicies('myHubOrg');
|
|
28
|
+
* if (isOk(result)) {
|
|
29
|
+
* console.log(`Found ${result.value.length} policies`);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Phase 2 usage (enable direct queries)
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const fetcher = new PolicyFetcher({ enableDirectBPOQuery: true });
|
|
36
|
+
* const result = await fetcher.fetchPolicies('myHubOrg');
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @since v1.0.0
|
|
40
|
+
*/
|
|
41
|
+
export declare class PolicyFetcher {
|
|
42
|
+
/**
|
|
43
|
+
* Optional logger for debug/error output
|
|
44
|
+
*/
|
|
45
|
+
private logger?;
|
|
46
|
+
/**
|
|
47
|
+
* Feature flag: Enable direct BPO query execution
|
|
48
|
+
*
|
|
49
|
+
* - **false** (default): Phase 1 behavior - returns NOT_IMPLEMENTED error
|
|
50
|
+
* - **true**: Phase 2 behavior - executes SOQL queries against DevopsGovernancePolicy BPO
|
|
51
|
+
*
|
|
52
|
+
* @since v1.0.0
|
|
53
|
+
*/
|
|
54
|
+
private enableDirectBPOQuery;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new PolicyFetcher instance
|
|
57
|
+
*
|
|
58
|
+
* @param options - Configuration options
|
|
59
|
+
* @param options.logger - Optional logger with debug/error methods
|
|
60
|
+
* @param options.enableDirectBPOQuery - Enable Phase 2 direct BPO queries (default: false)
|
|
61
|
+
*/
|
|
62
|
+
constructor(options?: {
|
|
63
|
+
logger?: {
|
|
64
|
+
debug: (message: string) => void;
|
|
65
|
+
error: (message: string) => void;
|
|
66
|
+
};
|
|
67
|
+
enableDirectBPOQuery?: boolean;
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Fetch governance policies from the specified org
|
|
71
|
+
*
|
|
72
|
+
* **Phase 1 (default)**: Uses Connect API via ConnectAPIClient. Makes HTTP POST request
|
|
73
|
+
* to /services/data/v62.0/connect/governance/policies.
|
|
74
|
+
*
|
|
75
|
+
* **Phase 2 (opt-in)**: Uses direct SOQL queries against DevopsGovernancePolicy BPO.
|
|
76
|
+
* Enable with: `new PolicyFetcher({ enableDirectBPOQuery: true })`
|
|
77
|
+
*
|
|
78
|
+
* By default, only fetches ENABLED policies. Use options.includeDisabled to fetch all.
|
|
79
|
+
*
|
|
80
|
+
* @param orgAliasOrConnection - Org alias (string) or Connection object
|
|
81
|
+
* @param options - Optional filtering options (currently only includeDisabled)
|
|
82
|
+
* @returns Result containing array of Policy objects or CAPGError
|
|
83
|
+
*
|
|
84
|
+
* @throws {CAPGValidationError} If orgAliasOrConnection is empty string (programmer error)
|
|
85
|
+
* @throws {CAPGValidationError} If Connection resolution fails (invalid org)
|
|
86
|
+
*
|
|
87
|
+
* @since v1.0.0
|
|
88
|
+
*/
|
|
89
|
+
fetchPolicies(orgAliasOrConnection: string | Connection, options?: FetchPoliciesOptions): Promise<Result<DevopsGovernancePolicy[], CAPGError>>;
|
|
90
|
+
/**
|
|
91
|
+
* Resolve org alias or Connection to a Connection object
|
|
92
|
+
*
|
|
93
|
+
* @param orgAliasOrConnection - Org alias (string) or Connection object
|
|
94
|
+
* @returns Result with Connection object or CAPGValidationError
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
private resolveConnection;
|
|
99
|
+
/**
|
|
100
|
+
* Build SOQL query for fetching policies
|
|
101
|
+
*
|
|
102
|
+
* Constructs a SOQL query with appropriate WHERE clauses based on options.
|
|
103
|
+
*
|
|
104
|
+
* @security SOQL Injection Prevention: This method uses ONLY hardcoded string
|
|
105
|
+
* literals in WHERE clauses. No user-supplied values are interpolated into the
|
|
106
|
+
* query string. The includeDisabled flag controls which hardcoded literal is used
|
|
107
|
+
* ("Status = 'ENABLED'" vs none), not dynamic values.
|
|
108
|
+
*
|
|
109
|
+
* @security Known Architecture Deviation: CLAUDE.md specifies using REST API
|
|
110
|
+
* endpoints (/services/data/v62.0/governance/policies?...) with URL parameters.
|
|
111
|
+
* This implementation uses SOQL via connection.query() because REST endpoints
|
|
112
|
+
* are not yet available in the backend. Once REST APIs are available, this
|
|
113
|
+
* method should be replaced with REST parameter construction.
|
|
114
|
+
*
|
|
115
|
+
* @param options - Filtering options (only includeDisabled flag supported)
|
|
116
|
+
* @returns SOQL query string with hardcoded literals only
|
|
117
|
+
*
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
private buildPoliciesQuery;
|
|
121
|
+
/**
|
|
122
|
+
* Transform BPO records to Policy interface
|
|
123
|
+
*
|
|
124
|
+
* Maps actual BPO field names to DevopsGovernancePolicy interface:
|
|
125
|
+
* - Id → policyId
|
|
126
|
+
* - PolicyCode → policyCode
|
|
127
|
+
* - Name → name
|
|
128
|
+
* - Description → description
|
|
129
|
+
* - Category → category
|
|
130
|
+
* - Status → status
|
|
131
|
+
* - RuleContent → ruleContent
|
|
132
|
+
* - PolicySource → policySource
|
|
133
|
+
* - GlobalPolicyVersion → globalPolicyVersion
|
|
134
|
+
* - CreatedDate → (not in interface)
|
|
135
|
+
* - LastModifiedDate → (not in interface)
|
|
136
|
+
*
|
|
137
|
+
* @param records - BPO records from SOQL query
|
|
138
|
+
* @returns Array of DevopsGovernancePolicy objects
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
private transformPolicies;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=policy-fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-fetcher.d.ts","sourceRoot":"","sources":["../src/policy-fetcher.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AAIH,OAAO,EAAE,UAAU,EAAO,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAuB,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAW,MAAM,mBAAmB,CAAC;AA2BpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,CAGb;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB,CAAU;IAEtC;;;;;;OAMG;gBACgB,OAAO,CAAC,EAAE;QAC3B,MAAM,CAAC,EAAE;YAAE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;YAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;SAAE,CAAC;QAChF,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAChC;IAKD;;;;;;;;;;;;;;;;;;;OAmBG;IACU,aAAa,CACxB,oBAAoB,EAAE,MAAM,GAAG,UAAU,EACzC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,EAAE,SAAS,CAAC,CAAC;IA+DvD;;;;;;;OAOG;YACW,iBAAiB;IAwB/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,iBAAiB;CAa1B"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, Salesforce, Inc. All rights reserved.
|
|
3
|
+
* See LICENSE.txt for license terms.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* PolicyFetcher - Fetch governance policies from Salesforce org
|
|
7
|
+
*
|
|
8
|
+
* This module provides the core policy fetching capability for the CAPG client library.
|
|
9
|
+
* It queries the DevOps_GovernancePolicy BPO using SOQL and transforms the results
|
|
10
|
+
* into typed Policy objects.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
* @since v1.0.0
|
|
14
|
+
*/
|
|
15
|
+
/* eslint-disable class-methods-use-this, @typescript-eslint/no-unsafe-call, @typescript-eslint/member-ordering */
|
|
16
|
+
import { Org } from '@salesforce/core';
|
|
17
|
+
import { CAPGValidationError } from './errors/index.js';
|
|
18
|
+
import { ok, err } from './types/result.js';
|
|
19
|
+
import { classifyError } from './utils/error-classifier.js';
|
|
20
|
+
import { SOQL_QUERIES } from './constants.js';
|
|
21
|
+
import { ConnectAPIClient } from './connect-api-client.js';
|
|
22
|
+
/**
|
|
23
|
+
* PolicyFetcher - Fetch governance policies from Salesforce org
|
|
24
|
+
*
|
|
25
|
+
* **Phase 1 vs Phase 2 Behavior**:
|
|
26
|
+
* - **Phase 1** (default, enableDirectBPOQuery=false): Uses Connect API via ConnectAPIClient.
|
|
27
|
+
* Makes HTTP POST requests to /services/data/v62.0/connect/governance/policies.
|
|
28
|
+
* - **Phase 2** (enableDirectBPOQuery=true): Executes SOQL queries against DevopsGovernancePolicy BPO.
|
|
29
|
+
* Direct database access for backwards compatibility and testing.
|
|
30
|
+
*
|
|
31
|
+
* @example Phase 1 usage (default - Connect API)
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const fetcher = new PolicyFetcher();
|
|
34
|
+
* const result = await fetcher.fetchPolicies('myHubOrg');
|
|
35
|
+
* if (isOk(result)) {
|
|
36
|
+
* console.log(`Found ${result.value.length} policies`);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Phase 2 usage (enable direct queries)
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const fetcher = new PolicyFetcher({ enableDirectBPOQuery: true });
|
|
43
|
+
* const result = await fetcher.fetchPolicies('myHubOrg');
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @since v1.0.0
|
|
47
|
+
*/
|
|
48
|
+
export class PolicyFetcher {
|
|
49
|
+
/**
|
|
50
|
+
* Optional logger for debug/error output
|
|
51
|
+
*/
|
|
52
|
+
logger;
|
|
53
|
+
/**
|
|
54
|
+
* Feature flag: Enable direct BPO query execution
|
|
55
|
+
*
|
|
56
|
+
* - **false** (default): Phase 1 behavior - returns NOT_IMPLEMENTED error
|
|
57
|
+
* - **true**: Phase 2 behavior - executes SOQL queries against DevopsGovernancePolicy BPO
|
|
58
|
+
*
|
|
59
|
+
* @since v1.0.0
|
|
60
|
+
*/
|
|
61
|
+
enableDirectBPOQuery;
|
|
62
|
+
/**
|
|
63
|
+
* Create a new PolicyFetcher instance
|
|
64
|
+
*
|
|
65
|
+
* @param options - Configuration options
|
|
66
|
+
* @param options.logger - Optional logger with debug/error methods
|
|
67
|
+
* @param options.enableDirectBPOQuery - Enable Phase 2 direct BPO queries (default: false)
|
|
68
|
+
*/
|
|
69
|
+
constructor(options) {
|
|
70
|
+
this.logger = options?.logger;
|
|
71
|
+
this.enableDirectBPOQuery = options?.enableDirectBPOQuery ?? false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Fetch governance policies from the specified org
|
|
75
|
+
*
|
|
76
|
+
* **Phase 1 (default)**: Uses Connect API via ConnectAPIClient. Makes HTTP POST request
|
|
77
|
+
* to /services/data/v62.0/connect/governance/policies.
|
|
78
|
+
*
|
|
79
|
+
* **Phase 2 (opt-in)**: Uses direct SOQL queries against DevopsGovernancePolicy BPO.
|
|
80
|
+
* Enable with: `new PolicyFetcher({ enableDirectBPOQuery: true })`
|
|
81
|
+
*
|
|
82
|
+
* By default, only fetches ENABLED policies. Use options.includeDisabled to fetch all.
|
|
83
|
+
*
|
|
84
|
+
* @param orgAliasOrConnection - Org alias (string) or Connection object
|
|
85
|
+
* @param options - Optional filtering options (currently only includeDisabled)
|
|
86
|
+
* @returns Result containing array of Policy objects or CAPGError
|
|
87
|
+
*
|
|
88
|
+
* @throws {CAPGValidationError} If orgAliasOrConnection is empty string (programmer error)
|
|
89
|
+
* @throws {CAPGValidationError} If Connection resolution fails (invalid org)
|
|
90
|
+
*
|
|
91
|
+
* @since v1.0.0
|
|
92
|
+
*/
|
|
93
|
+
async fetchPolicies(orgAliasOrConnection, options) {
|
|
94
|
+
// Phase 1: Use Connect API via ConnectAPIClient
|
|
95
|
+
if (!this.enableDirectBPOQuery) {
|
|
96
|
+
// Resolve connection (handles both string alias and Connection object)
|
|
97
|
+
const connectionResult = await this.resolveConnection(orgAliasOrConnection);
|
|
98
|
+
if (!connectionResult.ok) {
|
|
99
|
+
return err(connectionResult.error);
|
|
100
|
+
}
|
|
101
|
+
const connection = connectionResult.value;
|
|
102
|
+
// Create ConnectAPIClient and fetch policies
|
|
103
|
+
const client = new ConnectAPIClient(connection, { logger: this.logger });
|
|
104
|
+
const fetchOptions = {
|
|
105
|
+
includeDisabled: options?.includeDisabled ?? false,
|
|
106
|
+
};
|
|
107
|
+
const response = await client.fetchPolicies(fetchOptions);
|
|
108
|
+
// Transform PolicyResponse to array of policies
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
return err(response.error);
|
|
111
|
+
}
|
|
112
|
+
return ok(response.value.policies);
|
|
113
|
+
}
|
|
114
|
+
// Phase 2: Execute direct BPO queries (existing implementation)
|
|
115
|
+
// Resolve connection (may throw for programmer errors like empty string)
|
|
116
|
+
const connectionResult = await this.resolveConnection(orgAliasOrConnection);
|
|
117
|
+
if (!connectionResult.ok) {
|
|
118
|
+
return err(connectionResult.error);
|
|
119
|
+
}
|
|
120
|
+
const connection = connectionResult.value;
|
|
121
|
+
const query = this.buildPoliciesQuery(options);
|
|
122
|
+
const username = connection.getUsername() ?? 'unknown';
|
|
123
|
+
try {
|
|
124
|
+
this.logger?.debug(`Executing query on org ${username}: ${query}`);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Ignore logger errors
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const result = (await connection.query(query));
|
|
131
|
+
try {
|
|
132
|
+
this.logger?.debug(`Fetched ${result.totalSize} policies`);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Ignore logger errors
|
|
136
|
+
}
|
|
137
|
+
const policies = this.transformPolicies(result.records ?? []);
|
|
138
|
+
return ok(policies);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const capgError = classifyError(error, { username, operation: 'fetching policies' });
|
|
142
|
+
return err(capgError);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Resolve org alias or Connection to a Connection object
|
|
147
|
+
*
|
|
148
|
+
* @param orgAliasOrConnection - Org alias (string) or Connection object
|
|
149
|
+
* @returns Result with Connection object or CAPGValidationError
|
|
150
|
+
*
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
async resolveConnection(orgAliasOrConnection) {
|
|
154
|
+
if (typeof orgAliasOrConnection !== 'string') {
|
|
155
|
+
return ok(orgAliasOrConnection);
|
|
156
|
+
}
|
|
157
|
+
const alias = orgAliasOrConnection.trim();
|
|
158
|
+
if (!alias) {
|
|
159
|
+
// Programmer error - throw immediately
|
|
160
|
+
throw new CAPGValidationError('orgAlias', 'Org alias cannot be empty');
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const org = await Org.create({ aliasOrUsername: alias });
|
|
164
|
+
return ok(org.getConnection());
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// Runtime error - return Result
|
|
168
|
+
return err(new CAPGValidationError('orgAlias', `Invalid org alias '${alias}'. Ensure org is authenticated.`, alias));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Build SOQL query for fetching policies
|
|
173
|
+
*
|
|
174
|
+
* Constructs a SOQL query with appropriate WHERE clauses based on options.
|
|
175
|
+
*
|
|
176
|
+
* @security SOQL Injection Prevention: This method uses ONLY hardcoded string
|
|
177
|
+
* literals in WHERE clauses. No user-supplied values are interpolated into the
|
|
178
|
+
* query string. The includeDisabled flag controls which hardcoded literal is used
|
|
179
|
+
* ("Status = 'ENABLED'" vs none), not dynamic values.
|
|
180
|
+
*
|
|
181
|
+
* @security Known Architecture Deviation: CLAUDE.md specifies using REST API
|
|
182
|
+
* endpoints (/services/data/v62.0/governance/policies?...) with URL parameters.
|
|
183
|
+
* This implementation uses SOQL via connection.query() because REST endpoints
|
|
184
|
+
* are not yet available in the backend. Once REST APIs are available, this
|
|
185
|
+
* method should be replaced with REST parameter construction.
|
|
186
|
+
*
|
|
187
|
+
* @param options - Filtering options (only includeDisabled flag supported)
|
|
188
|
+
* @returns SOQL query string with hardcoded literals only
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
buildPoliciesQuery(options) {
|
|
193
|
+
let query = SOQL_QUERIES.FETCH_POLICIES_BASE;
|
|
194
|
+
const whereClauses = [];
|
|
195
|
+
if (!options?.includeDisabled) {
|
|
196
|
+
whereClauses.push("Status = 'ENABLED'");
|
|
197
|
+
}
|
|
198
|
+
// Note: Surface filtering not supported - field doesn't exist in BPO schema
|
|
199
|
+
// Future: May need to filter by other criteria or use related objects
|
|
200
|
+
if (whereClauses.length > 0) {
|
|
201
|
+
query += ` WHERE ${whereClauses.join(' AND ')}`;
|
|
202
|
+
}
|
|
203
|
+
query += ' ORDER BY PolicyCode ASC';
|
|
204
|
+
return query;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Transform BPO records to Policy interface
|
|
208
|
+
*
|
|
209
|
+
* Maps actual BPO field names to DevopsGovernancePolicy interface:
|
|
210
|
+
* - Id → policyId
|
|
211
|
+
* - PolicyCode → policyCode
|
|
212
|
+
* - Name → name
|
|
213
|
+
* - Description → description
|
|
214
|
+
* - Category → category
|
|
215
|
+
* - Status → status
|
|
216
|
+
* - RuleContent → ruleContent
|
|
217
|
+
* - PolicySource → policySource
|
|
218
|
+
* - GlobalPolicyVersion → globalPolicyVersion
|
|
219
|
+
* - CreatedDate → (not in interface)
|
|
220
|
+
* - LastModifiedDate → (not in interface)
|
|
221
|
+
*
|
|
222
|
+
* @param records - BPO records from SOQL query
|
|
223
|
+
* @returns Array of DevopsGovernancePolicy objects
|
|
224
|
+
*
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
transformPolicies(records) {
|
|
228
|
+
return records.map((record) => ({
|
|
229
|
+
policyId: record.Id,
|
|
230
|
+
policyCode: record.PolicyCode,
|
|
231
|
+
name: record.Name,
|
|
232
|
+
description: record.Description,
|
|
233
|
+
category: record.Category,
|
|
234
|
+
status: record.Status,
|
|
235
|
+
ruleContent: record.RuleContent,
|
|
236
|
+
policySource: record.PolicySource,
|
|
237
|
+
globalPolicyVersion: record.GlobalPolicyVersion,
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=policy-fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-fetcher.js","sourceRoot":"","sources":["../src/policy-fetcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,kHAAkH;AAElH,OAAO,EAAc,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAa,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAU,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAwB3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,aAAa;IACxB;;OAEG;IACK,MAAM,CAGZ;IA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