@cclabsnz/sf-core 0.1.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/LICENSE +201 -0
- package/README.md +88 -0
- package/lib/api/ApiError.d.ts +6 -0
- package/lib/api/ApiError.js +6 -0
- package/lib/api/MetadataClient.d.ts +4 -0
- package/lib/api/MetadataClient.js +2 -0
- package/lib/api/MetadataClientImpl.d.ts +8 -0
- package/lib/api/MetadataClientImpl.js +22 -0
- package/lib/api/RestClient.d.ts +6 -0
- package/lib/api/RestClient.js +2 -0
- package/lib/api/RestClientImpl.d.ts +10 -0
- package/lib/api/RestClientImpl.js +45 -0
- package/lib/api/SoqlClient.d.ts +10 -0
- package/lib/api/SoqlClient.js +2 -0
- package/lib/api/SoqlClientImpl.d.ts +9 -0
- package/lib/api/SoqlClientImpl.js +19 -0
- package/lib/api/ToolingClient.d.ts +5 -0
- package/lib/api/ToolingClient.js +2 -0
- package/lib/api/ToolingClientImpl.d.ts +10 -0
- package/lib/api/ToolingClientImpl.js +29 -0
- package/lib/api/index.d.ts +9 -0
- package/lib/api/index.js +5 -0
- package/lib/context/AuditCache.d.ts +78 -0
- package/lib/context/AuditCache.js +2 -0
- package/lib/context/AuditContext.d.ts +19 -0
- package/lib/context/AuditContext.js +2 -0
- package/lib/context/OrgInfo.d.ts +9 -0
- package/lib/context/OrgInfo.js +2 -0
- package/lib/context/OrgMetrics.d.ts +20 -0
- package/lib/context/OrgMetrics.js +20 -0
- package/lib/events/EventBaselineStore.d.ts +16 -0
- package/lib/events/EventBaselineStore.js +55 -0
- package/lib/events/eventLogAccess.d.ts +14 -0
- package/lib/events/eventLogAccess.js +33 -0
- package/lib/events/eventLogQuery.d.ts +21 -0
- package/lib/events/eventLogQuery.js +34 -0
- package/lib/events/pullEventLogs.d.ts +51 -0
- package/lib/events/pullEventLogs.js +79 -0
- package/lib/findings/RiskLevel.d.ts +3 -0
- package/lib/findings/RiskLevel.js +2 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +19 -0
- package/lib/platform/apexRepository.d.ts +50 -0
- package/lib/platform/apexRepository.js +69 -0
- package/lib/platform/concurrency.d.ts +10 -0
- package/lib/platform/concurrency.js +21 -0
- package/lib/platform/flowRepository.d.ts +72 -0
- package/lib/platform/flowRepository.js +87 -0
- package/lib/platform/index.d.ts +7 -0
- package/lib/platform/index.js +7 -0
- package/lib/platform/salesforceId.d.ts +29 -0
- package/lib/platform/salesforceId.js +41 -0
- package/lib/renderers/html-utils.d.ts +2 -0
- package/lib/renderers/html-utils.js +8 -0
- package/lib/report/branding.d.ts +18 -0
- package/lib/report/branding.js +19 -0
- package/lib/report/fonts.d.ts +9 -0
- package/lib/report/fonts.js +37 -0
- package/lib/schemas/index.d.ts +133 -0
- package/lib/schemas/index.js +21 -0
- package/lib/testing/invariants.d.ts +61 -0
- package/lib/testing/invariants.js +104 -0
- package/package.json +72 -0
- package/schemas/coupling-graph.schema.json +77 -0
- package/schemas/landscape-manifest.schema.json +134 -0
- package/schemas/process-graph.schema.json +71 -0
- package/src/assets/fonts/NOTICE.md +22 -0
- package/src/assets/fonts/OFL.txt +93 -0
- package/src/assets/fonts/dm-sans-italic-latin.woff2 +0 -0
- package/src/assets/fonts/dm-sans-normal-latin.woff2 +0 -0
- package/src/assets/fonts/dm-serif-display-italic-latin.woff2 +0 -0
- package/src/assets/fonts/dm-serif-display-normal-latin.woff2 +0 -0
- package/src/assets/fonts/fira-code-400-latin.woff2 +0 -0
- package/src/assets/fonts/fira-sans-400-latin.woff2 +0 -0
- package/src/assets/fonts/fira-sans-600-latin.woff2 +0 -0
- package/src/assets/fonts/fira-sans-700-latin.woff2 +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isSalesforceId } from './salesforceId.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read access to Flow metadata, encoding two platform facts that are easy to get wrong:
|
|
4
|
+
*
|
|
5
|
+
* 1. **`FlowDefinitionView` is a STANDARD object, not a Tooling one.** Querying it through
|
|
6
|
+
* the Tooling endpoint answers `sObject type 'FlowDefinitionView' is not supported.`
|
|
7
|
+
* 2. **`Flow.Metadata` *is* Tooling, and is strictly one row per query.** An `Id IN (...)`
|
|
8
|
+
* batch is rejected: *"When retrieving results with Metadata or FullName fields, the
|
|
9
|
+
* query qualifications must specify no more than one row for retrieval."* Concurrency is
|
|
10
|
+
* the only lever for bulk reads — see `mapWithConcurrency`.
|
|
11
|
+
*
|
|
12
|
+
* Errors are never swallowed here; callers decide how to report a degraded run.
|
|
13
|
+
*/
|
|
14
|
+
export class FlowRepository {
|
|
15
|
+
soql;
|
|
16
|
+
tooling;
|
|
17
|
+
constructor(soql, tooling) {
|
|
18
|
+
this.soql = soql;
|
|
19
|
+
this.tooling = tooling;
|
|
20
|
+
}
|
|
21
|
+
/** Flow definitions and their version Ids. Standard API. */
|
|
22
|
+
async listDefinitions() {
|
|
23
|
+
const rows = await this.soql.queryAll('SELECT ApiName, IsActive, ActiveVersionId, LatestVersionId FROM FlowDefinitionView');
|
|
24
|
+
return rows.map((r) => ({
|
|
25
|
+
apiName: r.ApiName,
|
|
26
|
+
isActive: r.IsActive,
|
|
27
|
+
activeVersionId: r.ActiveVersionId ?? null,
|
|
28
|
+
latestVersionId: r.LatestVersionId ?? null,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
/** Trigger configuration per flow, for automation counting. Standard API. */
|
|
32
|
+
async listTriggerViews() {
|
|
33
|
+
const rows = await this.soql.queryAll('SELECT TriggerType, TriggerObjectOrEventLabel, IsActive FROM FlowDefinitionView');
|
|
34
|
+
return rows.map((r) => ({
|
|
35
|
+
triggerType: r.TriggerType ?? null,
|
|
36
|
+
triggerObjectOrEventLabel: r.TriggerObjectOrEventLabel ?? null,
|
|
37
|
+
isActive: r.IsActive,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pick the version to analyse per definition, dropping managed-package flows whose version
|
|
42
|
+
* "Id" is a durable name rather than an Id. Pure — no org access.
|
|
43
|
+
*/
|
|
44
|
+
static selectVersions(definitions, opts = {}) {
|
|
45
|
+
const versions = [];
|
|
46
|
+
let managedSkipped = 0;
|
|
47
|
+
for (const d of definitions) {
|
|
48
|
+
const versionId = opts.includeInactive ? d.latestVersionId ?? d.activeVersionId : d.activeVersionId;
|
|
49
|
+
if (!versionId)
|
|
50
|
+
continue;
|
|
51
|
+
if (!opts.includeInactive && !d.isActive)
|
|
52
|
+
continue;
|
|
53
|
+
if (!isSalesforceId(versionId)) {
|
|
54
|
+
managedSkipped++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
versions.push({ id: versionId, apiName: d.apiName });
|
|
58
|
+
}
|
|
59
|
+
return { versions, managedSkipped };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The structured metadata for one flow version (equivalent to its XML), or null if the
|
|
63
|
+
* org returned no row. Tooling API, one row per call — see the class doc.
|
|
64
|
+
*/
|
|
65
|
+
async fetchMetadata(versionId) {
|
|
66
|
+
if (!isSalesforceId(versionId)) {
|
|
67
|
+
throw new Error(`Refusing to query Flow metadata for non-Id value '${versionId}'`);
|
|
68
|
+
}
|
|
69
|
+
const rows = await this.tooling.query(`SELECT Id, Metadata FROM Flow WHERE Id = '${versionId}'`);
|
|
70
|
+
return rows[0]?.Metadata ?? null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Active flow versions with their run mode. Tooling, but deliberately *without* Metadata —
|
|
74
|
+
* selecting it would impose the one-row-per-query rule and make this unusable in bulk.
|
|
75
|
+
*/
|
|
76
|
+
async listActiveVersions() {
|
|
77
|
+
const rows = await this.tooling.query("SELECT Id, MasterLabel, ProcessType, Status, RunInMode FROM Flow WHERE Status = 'Active'");
|
|
78
|
+
return rows.map((r) => ({
|
|
79
|
+
id: r.Id,
|
|
80
|
+
masterLabel: r.MasterLabel,
|
|
81
|
+
processType: r.ProcessType ?? null,
|
|
82
|
+
status: r.Status ?? null,
|
|
83
|
+
runInMode: r.RunInMode ?? null,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=flowRepository.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { isSalesforceId, describeSalesforceError, usableApexBody, qualifiedName, } from './salesforceId.js';
|
|
2
|
+
export { mapWithConcurrency } from './concurrency.js';
|
|
3
|
+
export { FlowRepository } from './flowRepository.js';
|
|
4
|
+
export type { FlowDefinitionRecord, FlowTriggerRecord, FlowVersionRef, SelectedFlowVersions, ActiveFlowVersion, } from './flowRepository.js';
|
|
5
|
+
export { ApexRepository } from './apexRepository.js';
|
|
6
|
+
export type { ApexClassRecord, ApexTriggerRecord, ApexScopeOptions } from './apexRepository.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Platform-behaviour layer: how Salesforce actually answers, kept in one place so a plugin
|
|
2
|
+
// cannot rediscover it by shipping the bug first.
|
|
3
|
+
export { isSalesforceId, describeSalesforceError, usableApexBody, qualifiedName, } from './salesforceId.js';
|
|
4
|
+
export { mapWithConcurrency } from './concurrency.js';
|
|
5
|
+
export { FlowRepository } from './flowRepository.js';
|
|
6
|
+
export { ApexRepository } from './apexRepository.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small facts about how the Salesforce platform actually behaves, learned the hard way by
|
|
3
|
+
* running against real orgs. They live in core so a plugin cannot rediscover them by
|
|
4
|
+
* shipping the bug first.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* True for a real 15- or 18-character Salesforce Id.
|
|
8
|
+
*
|
|
9
|
+
* Not every Id-shaped field contains one: `FlowDefinitionView.ActiveVersionId` returns a
|
|
10
|
+
* durable name (`ns__Flow-1`) for managed-package flows. Feeding that to a WHERE clause
|
|
11
|
+
* yields `invalid ID field`, once per row.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSalesforceId(value: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Salesforce error text flattened to a single line and trimmed to fit in a note.
|
|
16
|
+
*
|
|
17
|
+
* Retrieval code must never swallow these. A bare `catch {}` is how `intel map` silently
|
|
18
|
+
* produced an Apex-only graph against a real org for an entire milestone — the operator
|
|
19
|
+
* could not tell a permissions problem from a wrong-API bug.
|
|
20
|
+
*/
|
|
21
|
+
export declare function describeSalesforceError(e: unknown, maxLength?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Managed-package Apex bodies come back as the literal string `(hidden)`. Treat that as
|
|
24
|
+
* absent rather than as source — a SymbolTable may still be available for the same class.
|
|
25
|
+
*/
|
|
26
|
+
export declare function usableApexBody(body: string | null | undefined): string | null;
|
|
27
|
+
/** `ns__Name` for namespaced components, plain `Name` otherwise. */
|
|
28
|
+
export declare function qualifiedName(name: string, namespacePrefix: string | null | undefined): string;
|
|
29
|
+
//# sourceMappingURL=salesforceId.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small facts about how the Salesforce platform actually behaves, learned the hard way by
|
|
3
|
+
* running against real orgs. They live in core so a plugin cannot rediscover them by
|
|
4
|
+
* shipping the bug first.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* True for a real 15- or 18-character Salesforce Id.
|
|
8
|
+
*
|
|
9
|
+
* Not every Id-shaped field contains one: `FlowDefinitionView.ActiveVersionId` returns a
|
|
10
|
+
* durable name (`ns__Flow-1`) for managed-package flows. Feeding that to a WHERE clause
|
|
11
|
+
* yields `invalid ID field`, once per row.
|
|
12
|
+
*/
|
|
13
|
+
export function isSalesforceId(value) {
|
|
14
|
+
return /^[a-zA-Z0-9]{15}$|^[a-zA-Z0-9]{18}$/.test(value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Salesforce error text flattened to a single line and trimmed to fit in a note.
|
|
18
|
+
*
|
|
19
|
+
* Retrieval code must never swallow these. A bare `catch {}` is how `intel map` silently
|
|
20
|
+
* produced an Apex-only graph against a real org for an entire milestone — the operator
|
|
21
|
+
* could not tell a permissions problem from a wrong-API bug.
|
|
22
|
+
*/
|
|
23
|
+
export function describeSalesforceError(e, maxLength = 180) {
|
|
24
|
+
const raw = e instanceof Error ? e.message : String(e);
|
|
25
|
+
const oneLine = raw.replace(/\s+/g, ' ').trim();
|
|
26
|
+
return oneLine.length > maxLength ? `${oneLine.slice(0, maxLength - 3)}…` : oneLine;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Managed-package Apex bodies come back as the literal string `(hidden)`. Treat that as
|
|
30
|
+
* absent rather than as source — a SymbolTable may still be available for the same class.
|
|
31
|
+
*/
|
|
32
|
+
export function usableApexBody(body) {
|
|
33
|
+
if (!body)
|
|
34
|
+
return null;
|
|
35
|
+
return body.trim() === '(hidden)' ? null : body;
|
|
36
|
+
}
|
|
37
|
+
/** `ns__Name` for namespaced components, plain `Name` otherwise. */
|
|
38
|
+
export function qualifiedName(name, namespacePrefix) {
|
|
39
|
+
return namespacePrefix ? `${namespacePrefix}__${name}` : name;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=salesforceId.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Branding {
|
|
2
|
+
firmName: string;
|
|
3
|
+
primary: string;
|
|
4
|
+
ink: string;
|
|
5
|
+
bg: string;
|
|
6
|
+
bgAlt: string;
|
|
7
|
+
muted: string;
|
|
8
|
+
border: string;
|
|
9
|
+
fontDisplay: string;
|
|
10
|
+
fontBody: string;
|
|
11
|
+
contact: string;
|
|
12
|
+
logoPath?: string;
|
|
13
|
+
preparedFor?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const DEFAULT_BRANDING: Branding;
|
|
16
|
+
export type BrandingOverrides = Partial<Branding>;
|
|
17
|
+
export declare function resolveBranding(overrides: BrandingOverrides | undefined, preparedFor: string | undefined): Branding;
|
|
18
|
+
//# sourceMappingURL=branding.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const DEFAULT_BRANDING = {
|
|
2
|
+
firmName: 'CloudCounsel Limited',
|
|
3
|
+
primary: '#3a5a82',
|
|
4
|
+
ink: '#1a1d24',
|
|
5
|
+
bg: '#faf6ef',
|
|
6
|
+
bgAlt: '#f7f7f2',
|
|
7
|
+
muted: '#636770',
|
|
8
|
+
border: '#e9e9e3',
|
|
9
|
+
fontDisplay: 'DM Serif Display',
|
|
10
|
+
fontBody: 'DM Sans',
|
|
11
|
+
contact: 'hello@cloudcounsel.co.nz',
|
|
12
|
+
};
|
|
13
|
+
export function resolveBranding(overrides, preparedFor) {
|
|
14
|
+
const merged = { ...DEFAULT_BRANDING, ...(overrides ?? {}) };
|
|
15
|
+
if (preparedFor)
|
|
16
|
+
merged.preparedFor = preparedFor;
|
|
17
|
+
return merged;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=branding.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function fontFaceCss(): string;
|
|
2
|
+
/**
|
|
3
|
+
* Fira Sans/Fira Code faces for the sf-audit HTML reports, embedded as data URIs so a
|
|
4
|
+
* generated report never calls out to Google Fonts when a client opens it. Only the
|
|
5
|
+
* weights the report stylesheet actually uses are shipped (400/600/700 Sans, 400 Code);
|
|
6
|
+
* `font-weight: 800` resolves to the 700 face, matching the previous CDN behaviour.
|
|
7
|
+
*/
|
|
8
|
+
export declare function firaFontFaceCss(): string;
|
|
9
|
+
//# sourceMappingURL=fonts.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
// Resolves to <packageRoot>/src/assets/fonts from both lib/report (compiled) and src/report (ts-jest).
|
|
6
|
+
const FONT_DIR = join(HERE, '..', '..', 'src', 'assets', 'fonts');
|
|
7
|
+
function dataUri(file) {
|
|
8
|
+
const buf = readFileSync(join(FONT_DIR, file));
|
|
9
|
+
return `data:font/woff2;base64,${buf.toString('base64')}`;
|
|
10
|
+
}
|
|
11
|
+
function face(family, style, file, weight) {
|
|
12
|
+
const w = weight === undefined ? '' : `font-weight:${weight};`;
|
|
13
|
+
return `@font-face{font-family: '${family}';font-style:${style};${w}font-display:swap;src:url(${dataUri(file)}) format('woff2');}`;
|
|
14
|
+
}
|
|
15
|
+
export function fontFaceCss() {
|
|
16
|
+
return [
|
|
17
|
+
face('DM Sans', 'normal', 'dm-sans-normal-latin.woff2'),
|
|
18
|
+
face('DM Sans', 'italic', 'dm-sans-italic-latin.woff2'),
|
|
19
|
+
face('DM Serif Display', 'normal', 'dm-serif-display-normal-latin.woff2'),
|
|
20
|
+
face('DM Serif Display', 'italic', 'dm-serif-display-italic-latin.woff2'),
|
|
21
|
+
].join('\n');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Fira Sans/Fira Code faces for the sf-audit HTML reports, embedded as data URIs so a
|
|
25
|
+
* generated report never calls out to Google Fonts when a client opens it. Only the
|
|
26
|
+
* weights the report stylesheet actually uses are shipped (400/600/700 Sans, 400 Code);
|
|
27
|
+
* `font-weight: 800` resolves to the 700 face, matching the previous CDN behaviour.
|
|
28
|
+
*/
|
|
29
|
+
export function firaFontFaceCss() {
|
|
30
|
+
return [
|
|
31
|
+
face('Fira Sans', 'normal', 'fira-sans-400-latin.woff2', 400),
|
|
32
|
+
face('Fira Sans', 'normal', 'fira-sans-600-latin.woff2', 600),
|
|
33
|
+
face('Fira Sans', 'normal', 'fira-sans-700-latin.woff2', 700),
|
|
34
|
+
face('Fira Code', 'normal', 'fira-code-400-latin.woff2', 400),
|
|
35
|
+
].join('\n');
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=fonts.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export type EvidenceTier = 'A' | 'B' | 'C' | 'D';
|
|
2
|
+
export type CouplingOperation = 'read' | 'create' | 'update' | 'delete';
|
|
3
|
+
export type CouplingConfidence = 'high' | 'approximate';
|
|
4
|
+
export interface CouplingGraphProvenance {
|
|
5
|
+
tool: 'orgintel';
|
|
6
|
+
toolVersion: string;
|
|
7
|
+
generatedAt: string;
|
|
8
|
+
orgId: string;
|
|
9
|
+
evidenceTier: EvidenceTier;
|
|
10
|
+
}
|
|
11
|
+
export interface CouplingGraphNode {
|
|
12
|
+
object: string;
|
|
13
|
+
custom: boolean;
|
|
14
|
+
automationCounts: {
|
|
15
|
+
flows: number;
|
|
16
|
+
triggers: number;
|
|
17
|
+
approvals: number;
|
|
18
|
+
};
|
|
19
|
+
recordCount90d: number;
|
|
20
|
+
}
|
|
21
|
+
export interface CouplingComponentRef {
|
|
22
|
+
type: string;
|
|
23
|
+
name: string;
|
|
24
|
+
confidence: CouplingConfidence;
|
|
25
|
+
}
|
|
26
|
+
export interface CouplingGraphEdge {
|
|
27
|
+
from: string;
|
|
28
|
+
to: string;
|
|
29
|
+
weight: number;
|
|
30
|
+
operations: CouplingOperation[];
|
|
31
|
+
components: CouplingComponentRef[];
|
|
32
|
+
}
|
|
33
|
+
export interface CouplingGraph {
|
|
34
|
+
version: 1;
|
|
35
|
+
provenance: CouplingGraphProvenance;
|
|
36
|
+
nodes: CouplingGraphNode[];
|
|
37
|
+
edges: CouplingGraphEdge[];
|
|
38
|
+
}
|
|
39
|
+
export type ProcessNodeKind = 'state' | 'automation' | 'human' | 'integration';
|
|
40
|
+
export interface ProcessNode {
|
|
41
|
+
id: string;
|
|
42
|
+
kind: ProcessNodeKind;
|
|
43
|
+
label: string;
|
|
44
|
+
object?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ProcessObserved {
|
|
47
|
+
count: number;
|
|
48
|
+
p50_mins: number;
|
|
49
|
+
error_rate: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ProcessEdge {
|
|
52
|
+
from: string;
|
|
53
|
+
to: string;
|
|
54
|
+
trigger: string;
|
|
55
|
+
observed?: ProcessObserved;
|
|
56
|
+
}
|
|
57
|
+
export interface ProcessReferenceModel {
|
|
58
|
+
id: string | null;
|
|
59
|
+
version: string | null;
|
|
60
|
+
source: string | null;
|
|
61
|
+
}
|
|
62
|
+
export interface ProcessGraphProvenance {
|
|
63
|
+
tool: 'orgintel';
|
|
64
|
+
toolVersion: string;
|
|
65
|
+
generatedAt: string;
|
|
66
|
+
orgId: string;
|
|
67
|
+
referenceModel?: ProcessReferenceModel;
|
|
68
|
+
}
|
|
69
|
+
export interface ProcessGraph {
|
|
70
|
+
version: 1;
|
|
71
|
+
anchorObject: string;
|
|
72
|
+
provenance: ProcessGraphProvenance;
|
|
73
|
+
nodes: ProcessNode[];
|
|
74
|
+
edges: ProcessEdge[];
|
|
75
|
+
}
|
|
76
|
+
export interface LayoutCoord {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
}
|
|
80
|
+
export interface LandscapeManifestProvenance {
|
|
81
|
+
tool: 'orgintel';
|
|
82
|
+
toolVersion: string;
|
|
83
|
+
generatedAt: string;
|
|
84
|
+
orgId: string;
|
|
85
|
+
}
|
|
86
|
+
export interface L0Cluster {
|
|
87
|
+
id: string;
|
|
88
|
+
label: string;
|
|
89
|
+
objects: string[];
|
|
90
|
+
layout: LayoutCoord;
|
|
91
|
+
metrics: {
|
|
92
|
+
objects: number;
|
|
93
|
+
automations: number;
|
|
94
|
+
recordCount90d: number;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface L1PerCluster {
|
|
98
|
+
clusterId: string;
|
|
99
|
+
graphRef: string;
|
|
100
|
+
anchorObject: string;
|
|
101
|
+
layout: Record<string, LayoutCoord>;
|
|
102
|
+
}
|
|
103
|
+
export interface L2PerAnchor {
|
|
104
|
+
anchorObject: string;
|
|
105
|
+
processGraphRef: string | null;
|
|
106
|
+
}
|
|
107
|
+
export interface LandscapeManifest {
|
|
108
|
+
version: 1;
|
|
109
|
+
provenance: LandscapeManifestProvenance;
|
|
110
|
+
levels: {
|
|
111
|
+
L0_landscape: {
|
|
112
|
+
clusters: L0Cluster[];
|
|
113
|
+
};
|
|
114
|
+
L1_domain: {
|
|
115
|
+
perCluster: L1PerCluster[];
|
|
116
|
+
};
|
|
117
|
+
L2_process: {
|
|
118
|
+
perAnchor: L2PerAnchor[];
|
|
119
|
+
};
|
|
120
|
+
L3_transition: {
|
|
121
|
+
reserved: true;
|
|
122
|
+
};
|
|
123
|
+
L4_component: {
|
|
124
|
+
flowSummaryRefs: string[];
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export type SchemaName = 'coupling-graph' | 'process-graph' | 'landscape-manifest';
|
|
129
|
+
/** Absolute path to a schema JSON file. */
|
|
130
|
+
export declare function schemaPath(name: SchemaName): string;
|
|
131
|
+
/** Parsed JSON Schema object for the given contract. */
|
|
132
|
+
export declare function loadSchema(name: SchemaName): unknown;
|
|
133
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Typed interfaces for the OrgIntel IR contracts. The authoritative JSON Schema
|
|
2
|
+
// files live in `packages/core/schemas/*.schema.json`; these interfaces mirror them.
|
|
3
|
+
// Version fields start at 1 and are the product's stable contract.
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Schema file access — resolves `<packageRoot>/schemas` from both lib/ (compiled)
|
|
9
|
+
// and src/ (ts-jest), mirroring the font-asset resolution in report/fonts.ts.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const SCHEMA_DIR = join(HERE, '..', '..', 'schemas');
|
|
13
|
+
/** Absolute path to a schema JSON file. */
|
|
14
|
+
export function schemaPath(name) {
|
|
15
|
+
return join(SCHEMA_DIR, `${name}.schema.json`);
|
|
16
|
+
}
|
|
17
|
+
/** Parsed JSON Schema object for the given contract. */
|
|
18
|
+
export function loadSchema(name) {
|
|
19
|
+
return JSON.parse(readFileSync(schemaPath(name), 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared static-analysis guards behind the two promises every CloudCounsel plugin makes:
|
|
3
|
+
* it never writes to your org, and nothing it produces phones home.
|
|
4
|
+
*
|
|
5
|
+
* These live in core, and each package runs them against its OWN `src/`, so a package
|
|
6
|
+
* cannot silently opt out by forgetting to register somewhere central — and a violation
|
|
7
|
+
* fails the build of the package that introduced it.
|
|
8
|
+
*
|
|
9
|
+
* Both guards are deliberately token-based rather than type-aware: a green result means
|
|
10
|
+
* the forbidden shape does not appear anywhere in source, which is a claim a sceptical
|
|
11
|
+
* reader can re-derive with grep. Patterns avoid collisions with JS built-ins (Map#delete,
|
|
12
|
+
* Object.create) so passing is meaningful rather than merely quiet.
|
|
13
|
+
*/
|
|
14
|
+
/** One offending source line. */
|
|
15
|
+
export interface InvariantViolation {
|
|
16
|
+
/** Path relative to the scanned `src/`. */
|
|
17
|
+
file: string;
|
|
18
|
+
/** 1-indexed line number. */
|
|
19
|
+
line: number;
|
|
20
|
+
/** Human-readable rule label. */
|
|
21
|
+
rule: string;
|
|
22
|
+
/** The offending line, trimmed. */
|
|
23
|
+
snippet: string;
|
|
24
|
+
}
|
|
25
|
+
export type InvariantRule = readonly [label: string, pattern: RegExp];
|
|
26
|
+
/**
|
|
27
|
+
* Org-mutation tokens. Every CloudCounsel plugin is strictly read-only: SOQL / Tooling /
|
|
28
|
+
* REST GET / Metadata reads only.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ORG_WRITE_RULES: readonly InvariantRule[];
|
|
31
|
+
/**
|
|
32
|
+
* Network-egress tokens. The only network destination these tools may contact is the
|
|
33
|
+
* Salesforce org the operator authenticated against — via the core REST/SOQL/Tooling
|
|
34
|
+
* clients. No telemetry, no analytics, no LLM calls, and no remote assets in generated
|
|
35
|
+
* reports (an audit report carries sensitive findings and is often opened offline, so it
|
|
36
|
+
* must not fetch script, styles or fonts from a third party when a client opens it).
|
|
37
|
+
*/
|
|
38
|
+
export declare const NETWORK_EGRESS_RULES: readonly InvariantRule[];
|
|
39
|
+
/** Recursively collect `.ts` source files (excluding declaration files) under `dir`. */
|
|
40
|
+
export declare function collectSourceFiles(dir: string): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Scan every source file under `srcDir` for lines matching any rule.
|
|
43
|
+
*
|
|
44
|
+
* A line carrying an `invariant:allow` comment is skipped, so a reviewed false positive
|
|
45
|
+
* has an explicit, greppable escape hatch rather than forcing the rule to be weakened.
|
|
46
|
+
* The legacy `readonly-invariant:allow` spelling is honoured too.
|
|
47
|
+
*/
|
|
48
|
+
export declare function findInvariantViolations(srcDir: string, rules: readonly InvariantRule[]): InvariantViolation[];
|
|
49
|
+
/** Render violations as a reviewable multi-line report. */
|
|
50
|
+
export declare function formatViolations(violations: readonly InvariantViolation[]): string;
|
|
51
|
+
/**
|
|
52
|
+
* Source files under `srcDir` that call the global fetch, as `src`-relative paths.
|
|
53
|
+
*
|
|
54
|
+
* Scanned line-by-line rather than whole-file so the `invariant:allow` escape hatch works
|
|
55
|
+
* here too — otherwise a doc comment mentioning the call by name would be indistinguishable
|
|
56
|
+
* from a real call site.
|
|
57
|
+
*/
|
|
58
|
+
export declare function filesUsingFetch(srcDir: string): string[];
|
|
59
|
+
/** True if any fetch call in the file carries an explicit `method:` option (i.e. is not a GET). */
|
|
60
|
+
export declare function fetchUsesNonGetMethod(file: string): boolean;
|
|
61
|
+
//# sourceMappingURL=invariants.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Org-mutation tokens. Every CloudCounsel plugin is strictly read-only: SOQL / Tooling /
|
|
5
|
+
* REST GET / Metadata reads only.
|
|
6
|
+
*/
|
|
7
|
+
export const ORG_WRITE_RULES = [
|
|
8
|
+
['HTTP write verb (method: POST/PUT/PATCH/DELETE)', /method\s*:\s*['"`](?:POST|PUT|PATCH|DELETE)['"`]/i],
|
|
9
|
+
['jsforce SObject write', /\.sobject\([^)]*\)\s*\.\s*(?:create|update|insert|upsert|destroy|delete)\b/i],
|
|
10
|
+
['jsforce connection write', /\bconn(?:ection)?\s*\.\s*(?:create|update|insert|upsert|destroy|delete)\b/i],
|
|
11
|
+
['Metadata API write', /\.\s*metadata\s*\.\s*(?:create|update|upsert|delete|rename|deploy)\b/i],
|
|
12
|
+
['Tooling API write', /\.\s*tooling\s*\.\s*(?:create|update|upsert|destroy|delete)\b/i],
|
|
13
|
+
['Bulk API job', /\.\s*bulk2?\s*\./i],
|
|
14
|
+
['Composite write graph', /\.\s*(?:compositeGraph|createBatch|createJob)\b/i],
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Network-egress tokens. The only network destination these tools may contact is the
|
|
18
|
+
* Salesforce org the operator authenticated against — via the core REST/SOQL/Tooling
|
|
19
|
+
* clients. No telemetry, no analytics, no LLM calls, and no remote assets in generated
|
|
20
|
+
* reports (an audit report carries sensitive findings and is often opened offline, so it
|
|
21
|
+
* must not fetch script, styles or fonts from a third party when a client opens it).
|
|
22
|
+
*/
|
|
23
|
+
export const NETWORK_EGRESS_RULES = [
|
|
24
|
+
[
|
|
25
|
+
'remote asset in generated HTML (<script src>/<link href>/@import)',
|
|
26
|
+
/<script[^>]+src\s*=\s*["'`]?\s*https?:|<link[^>]+href\s*=\s*["'`]?\s*https?:|@import\s+url\(\s*["']?https?:/i,
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'third-party HTTP client',
|
|
30
|
+
/(?:from\s+|require\()\s*['"](?:axios|got|node-fetch|undici|superagent|request|phin|ky)['"]/i,
|
|
31
|
+
],
|
|
32
|
+
['raw node http/https module', /(?:from\s+|require\()\s*['"](?:node:)?https?['"]/i],
|
|
33
|
+
[
|
|
34
|
+
'telemetry / analytics / LLM endpoint',
|
|
35
|
+
/api\.openai\.com|api\.anthropic\.com|generativelanguage\.googleapis\.com|sentry\.io|segment\.(?:io|com)|posthog\.com|mixpanel\.com|google-analytics\.com|amplitude\.com/i,
|
|
36
|
+
],
|
|
37
|
+
['websocket client', /\bnew\s+WebSocket\s*\(|(?:from\s+|require\()\s*['"]ws['"]/i],
|
|
38
|
+
];
|
|
39
|
+
/** Recursively collect `.ts` source files (excluding declaration files) under `dir`. */
|
|
40
|
+
export function collectSourceFiles(dir) {
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const entry of readdirSync(dir)) {
|
|
43
|
+
const full = join(dir, entry);
|
|
44
|
+
if (statSync(full).isDirectory()) {
|
|
45
|
+
out.push(...collectSourceFiles(full));
|
|
46
|
+
}
|
|
47
|
+
else if (entry.endsWith('.ts') && !entry.endsWith('.d.ts')) {
|
|
48
|
+
out.push(full);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scan every source file under `srcDir` for lines matching any rule.
|
|
55
|
+
*
|
|
56
|
+
* A line carrying an `invariant:allow` comment is skipped, so a reviewed false positive
|
|
57
|
+
* has an explicit, greppable escape hatch rather than forcing the rule to be weakened.
|
|
58
|
+
* The legacy `readonly-invariant:allow` spelling is honoured too.
|
|
59
|
+
*/
|
|
60
|
+
export function findInvariantViolations(srcDir, rules) {
|
|
61
|
+
const violations = [];
|
|
62
|
+
for (const file of collectSourceFiles(srcDir)) {
|
|
63
|
+
const rel = relative(srcDir, file).split('\\').join('/');
|
|
64
|
+
readFileSync(file, 'utf8')
|
|
65
|
+
.split('\n')
|
|
66
|
+
.forEach((line, i) => {
|
|
67
|
+
if (line.includes('invariant:allow'))
|
|
68
|
+
return;
|
|
69
|
+
for (const [rule, pattern] of rules) {
|
|
70
|
+
if (pattern.test(line)) {
|
|
71
|
+
violations.push({ file: rel, line: i + 1, rule, snippet: line.trim() });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return violations;
|
|
77
|
+
}
|
|
78
|
+
/** Render violations as a reviewable multi-line report. */
|
|
79
|
+
export function formatViolations(violations) {
|
|
80
|
+
return violations.map((v) => `${v.file}:${v.line} [${v.rule}] ${v.snippet}`).join('\n');
|
|
81
|
+
}
|
|
82
|
+
const FETCH_CALL = /\bfetch\s*\(/;
|
|
83
|
+
/**
|
|
84
|
+
* Source files under `srcDir` that call the global fetch, as `src`-relative paths.
|
|
85
|
+
*
|
|
86
|
+
* Scanned line-by-line rather than whole-file so the `invariant:allow` escape hatch works
|
|
87
|
+
* here too — otherwise a doc comment mentioning the call by name would be indistinguishable
|
|
88
|
+
* from a real call site.
|
|
89
|
+
*/
|
|
90
|
+
export function filesUsingFetch(srcDir) {
|
|
91
|
+
const hits = [];
|
|
92
|
+
for (const file of collectSourceFiles(srcDir)) {
|
|
93
|
+
const lines = readFileSync(file, 'utf8').split('\n');
|
|
94
|
+
const calls = lines.some((line) => !line.includes('invariant:allow') && FETCH_CALL.test(line));
|
|
95
|
+
if (calls)
|
|
96
|
+
hits.push(relative(srcDir, file).split('\\').join('/'));
|
|
97
|
+
}
|
|
98
|
+
return hits;
|
|
99
|
+
}
|
|
100
|
+
/** True if any fetch call in the file carries an explicit `method:` option (i.e. is not a GET). */
|
|
101
|
+
export function fetchUsesNonGetMethod(file) {
|
|
102
|
+
return /fetch\s*\([^;]*method\s*:/is.test(readFileSync(file, 'utf8'));
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=invariants.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclabsnz/sf-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared platform layer for CloudCounsel Salesforce sf plugins \u2014 API clients, org context, event log pull, report shell, and versioned IR schemas.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./testing": {
|
|
15
|
+
"types": "./lib/testing/invariants.d.ts",
|
|
16
|
+
"default": "./lib/testing/invariants.js"
|
|
17
|
+
},
|
|
18
|
+
"./schemas/*": "./schemas/*"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --passWithNoTests",
|
|
23
|
+
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js test/unit --passWithNoTests",
|
|
24
|
+
"prepack": "npm run build",
|
|
25
|
+
"clean": "rm -rf lib",
|
|
26
|
+
"prepare": "git config core.hooksPath .githooks 2>/dev/null || true"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@salesforce/core": "^8"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@jest/globals": "^29.7.0",
|
|
33
|
+
"@types/jest": "^29",
|
|
34
|
+
"@types/node": "^22",
|
|
35
|
+
"jest": "^29",
|
|
36
|
+
"ts-jest": "^29",
|
|
37
|
+
"ts-node": "^10.9.2",
|
|
38
|
+
"typescript": "^5"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"/lib",
|
|
45
|
+
"/schemas",
|
|
46
|
+
"/src/assets",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"README.md",
|
|
49
|
+
"!/lib/**/*.map"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/cclabsnz/sf-core.git"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/cclabsnz/sf-core#readme",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/cclabsnz/sf-core/issues"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"salesforce",
|
|
61
|
+
"sf-plugin",
|
|
62
|
+
"sfdx",
|
|
63
|
+
"security",
|
|
64
|
+
"audit",
|
|
65
|
+
"tooling-api"
|
|
66
|
+
],
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"provenance": true
|
|
70
|
+
},
|
|
71
|
+
"packageManager": "pnpm@10.33.0"
|
|
72
|
+
}
|