@ankhorage/rules-design 0.3.3 → 0.5.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/CHANGELOG.md +12 -0
- package/README.md +3 -2
- package/dist/features/catalog/designRuleProviderManifest.d.ts +1 -1
- package/dist/features/catalog/designRuleProviderManifest.js +3 -2
- package/dist/features/color/createColorPolicyRules.js +1 -1
- package/dist/features/color/createColorRuleSet.js +1 -1
- package/dist/features/provider/createDesignCrapRules.d.ts +4 -0
- package/dist/features/provider/createDesignCrapRules.js +51 -0
- package/dist/features/provider/designRuleProvider.d.ts +3 -3
- package/dist/features/provider/designRuleProvider.js +36 -8
- package/dist/features/provider/selectDesignRuleProfile.d.ts +3 -0
- package/dist/features/provider/selectDesignRuleProfile.js +12 -0
- package/dist/features/spacing-proximity/createSpacingProximityRuleSet.d.ts +2 -2
- package/dist/features/spacing-proximity/createSpacingProximityRuleSet.js +1 -1
- package/dist/features/typography/createTypographyRuleSet.js +1 -1
- package/dist/features/website-assessment/assessContactAddressMarkup.d.ts +3 -0
- package/dist/features/website-assessment/assessContactAddressMarkup.js +46 -0
- package/dist/features/website-assessment/assessCopyrightNotice.d.ts +3 -0
- package/dist/features/website-assessment/assessCopyrightNotice.js +33 -0
- package/dist/features/website-assessment/assessDuplicateMediaUse.d.ts +3 -0
- package/dist/features/website-assessment/assessDuplicateMediaUse.js +55 -0
- package/dist/features/website-assessment/assessLegalNotice.d.ts +3 -0
- package/dist/features/website-assessment/assessLegalNotice.js +44 -0
- package/dist/features/website-assessment/assessPrivacyNotice.d.ts +3 -0
- package/dist/features/website-assessment/assessPrivacyNotice.js +58 -0
- package/dist/features/website-assessment/assessTrackingConsent.d.ts +3 -0
- package/dist/features/website-assessment/assessTrackingConsent.js +63 -0
- package/dist/features/website-assessment/createWebsiteAssessmentRuleSet.d.ts +4 -0
- package/dist/features/website-assessment/createWebsiteAssessmentRuleSet.js +68 -0
- package/dist/features/website-assessment/isWebsiteAssessmentNonNull.d.ts +2 -0
- package/dist/features/website-assessment/isWebsiteAssessmentNonNull.js +5 -0
- package/dist/features/website-assessment/websiteAssessmentDefinitions.d.ts +3 -0
- package/dist/features/website-assessment/websiteAssessmentDefinitions.js +26 -0
- package/dist/features/website-assessment/websiteAssessmentResult.d.ts +3 -0
- package/dist/features/website-assessment/websiteAssessmentResult.js +21 -0
- package/dist/features/website-assessment/websiteAssessmentTestSupport.d.ts +13 -0
- package/dist/features/website-assessment/websiteAssessmentTestSupport.js +53 -0
- package/dist/features/website-assessment/websiteAssessmentValues.d.ts +7 -0
- package/dist/features/website-assessment/websiteAssessmentValues.js +17 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +3 -1
- package/dist/types/designRuleProvider.d.ts +18 -8
- package/dist/types/websiteAssessment.d.ts +35 -0
- package/dist/types/websiteAssessment.js +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9dab376: Add composable website, contact, privacy, tracking, and media assessment rules.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 416c5b3: Register all Design rule families and the C.R.A.P. composition graph through a configured provider factory, with executable C.R.A.P. and 60-30-10 profile selection.
|
|
14
|
+
|
|
3
15
|
## 0.3.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/rules-design
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Declarative catalog for reusable design rules.
|
|
9
9
|
|
|
@@ -23,7 +23,7 @@ ankh rules-design --help
|
|
|
23
23
|
|
|
24
24
|
### Evaluate Design Evidence
|
|
25
25
|
|
|
26
|
-
Register the Design provider
|
|
26
|
+
Register the configured Design provider and evaluate a named profile.
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
29
|
import { createRuleRegistry, evaluateRules } from '@ankhorage/rules';
|
|
@@ -37,3 +37,4 @@ import { createRuleRegistry, evaluateRules } from '@ankhorage/rules';
|
|
|
37
37
|
- [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
|
|
38
38
|
- [Module relationships](././paradox/diagrams/module-relationships.mmd)
|
|
39
39
|
- [Export graph](././paradox/diagrams/export-graph.mmd)
|
|
40
|
+
- [selectDesignRuleProfile sequence](././paradox/diagrams/sequences/select-design-rule-profile.mmd)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DesignRuleProviderManifest } from '../../types/designRuleCatalog';
|
|
2
|
-
/*** Declares
|
|
2
|
+
/*** Declares every central-provider rule identity published through the released package surface. */
|
|
3
3
|
export declare const designRuleProviderManifest: DesignRuleProviderManifest;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { designRuleCatalog } from './designRuleCatalog';
|
|
2
|
+
/*** Declares every central-provider rule identity published through the released package surface. */
|
|
2
3
|
export const designRuleProviderManifest = {
|
|
3
4
|
packageName: '@ankhorage/rules-design',
|
|
4
5
|
providerId: 'ankhorage.rules-design',
|
|
5
|
-
publishedRuleIds:
|
|
6
|
+
publishedRuleIds: designRuleCatalog.map((entry) => entry.id),
|
|
6
7
|
schemaVersion: '1',
|
|
7
8
|
};
|
|
@@ -40,7 +40,7 @@ function createColorPolicyRule(ruleId, policy) {
|
|
|
40
40
|
}
|
|
41
41
|
/*** Assesses each normalized raw observation with the rule-specific trusted policy. */
|
|
42
42
|
function evaluateColorPolicyRule(ruleId, policy, input) {
|
|
43
|
-
const facts =
|
|
43
|
+
const facts = input.context.facts.filter((fact) => fact.kind === ruleId && sameScope(fact, input));
|
|
44
44
|
const observations = facts.map((fact) => ({ fact, observation: parseObservation(fact) }));
|
|
45
45
|
if (facts.length === 0 || observations.some(({ observation }) => observation === undefined))
|
|
46
46
|
return incomplete(ruleId, input);
|
|
@@ -20,7 +20,7 @@ function createUsageRule(policy) {
|
|
|
20
20
|
}
|
|
21
21
|
/*** Keeps exact rule scope, breakpoint, theme, and coverage measurements isolated. */
|
|
22
22
|
function evaluateUsage(input, policy) {
|
|
23
|
-
const facts =
|
|
23
|
+
const facts = input.context.facts.filter((fact) => fact.kind === 'design.color.usage-distribution' && exactScope(fact, input));
|
|
24
24
|
const observations = facts.map(parseObservation);
|
|
25
25
|
if (facts.length === 0 || observations.some((value) => value === undefined))
|
|
26
26
|
return incomplete(input, 'No complete normalized rendered-area fact was supplied.');
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Rule } from '@ankhorage/rules';
|
|
2
|
+
import type { DesignContext } from '../../types/designRuleProvider';
|
|
3
|
+
/*** Creates the five C.R.A.P. composition nodes from the registered atomic Design rules. */
|
|
4
|
+
export declare function createDesignCrapRules(atomicRules: readonly Rule<DesignContext>[]): readonly Rule<DesignContext>[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*** Creates the five C.R.A.P. composition nodes from the registered atomic Design rules. */
|
|
2
|
+
export function createDesignCrapRules(atomicRules) {
|
|
3
|
+
const atomicRuleIds = atomicRules.map((rule) => rule.identity.id);
|
|
4
|
+
return crapDefinitions(atomicRuleIds).map(createDesignCrapRule);
|
|
5
|
+
}
|
|
6
|
+
/*** Declares C.R.A.P. dependencies from canonical atomic IDs without reimplementing group rules. */
|
|
7
|
+
function crapDefinitions(atomicRuleIds) {
|
|
8
|
+
const children = (prefixes) => atomicRuleIds.filter((id) => prefixes.some((prefix) => id.startsWith(prefix)));
|
|
9
|
+
return [
|
|
10
|
+
definition('design.crap.contrast', children(['design.color.', 'design.contrast.']), 'Compose Color and Contrast results into the C.R.A.P. contrast principle.'),
|
|
11
|
+
definition('design.crap.repetition', children(['design.repetition.', 'design.typography.']), 'Compose Repetition and Typography results into the C.R.A.P. repetition principle.'),
|
|
12
|
+
definition('design.crap.alignment', children(['design.alignment.', 'design.layout.', 'design.responsive.']), 'Compose Alignment, Layout, and Responsive results into the C.R.A.P. alignment principle.'),
|
|
13
|
+
definition('design.crap.proximity', children(['design.spacing.', 'design.proximity.']), 'Compose Spacing and Proximity results into the C.R.A.P. proximity principle.'),
|
|
14
|
+
definition('design.crap', [
|
|
15
|
+
'design.crap.contrast',
|
|
16
|
+
'design.crap.repetition',
|
|
17
|
+
'design.crap.alignment',
|
|
18
|
+
'design.crap.proximity',
|
|
19
|
+
], 'Compose exactly four C.R.A.P. principle results without calculating a design score.'),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
/*** Defines one stable composite identity and its evaluator-owned dependency edges. */
|
|
23
|
+
function definition(id, dependencies, summary) {
|
|
24
|
+
return { dependencies, id, summary };
|
|
25
|
+
}
|
|
26
|
+
/*** Adapts one declared C.R.A.P. node to the generic dependency-result contract. */
|
|
27
|
+
function createDesignCrapRule(definition) {
|
|
28
|
+
return {
|
|
29
|
+
defaultSeverity: 'warning',
|
|
30
|
+
dependencies: definition.dependencies.map((ruleId) => ({ ruleId })),
|
|
31
|
+
evaluate: (input) => evaluateDesignCrapRule(definition, input),
|
|
32
|
+
identity: { id: definition.id, version: '1.0.0' },
|
|
33
|
+
summary: definition.summary,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/*** Reports failed child principles as advisory findings while the engine propagates incomplete ones. */
|
|
37
|
+
function evaluateDesignCrapRule(definition, input) {
|
|
38
|
+
const failedChildren = input.dependencyResults.filter((result) => result.status === 'FAIL');
|
|
39
|
+
return failedChildren.length === 0
|
|
40
|
+
? { findings: [], status: 'PASS' }
|
|
41
|
+
: {
|
|
42
|
+
findings: failedChildren.map((result) => ({
|
|
43
|
+
evidence: { childRuleId: result.rule.id, childStatus: result.status },
|
|
44
|
+
message: `${definition.id} includes a failed child rule: ${result.rule.id}.`,
|
|
45
|
+
ruleId: definition.id,
|
|
46
|
+
severity: 'warning',
|
|
47
|
+
subjects: [{ id: input.scope.id, kind: input.scope.kind }],
|
|
48
|
+
})),
|
|
49
|
+
status: 'FAIL',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { DesignRuleProvider } from '../../types/designRuleProvider';
|
|
2
|
-
/***
|
|
3
|
-
export declare
|
|
1
|
+
import type { DesignRuleProvider, DesignRuleProviderOptions } from '../../types/designRuleProvider';
|
|
2
|
+
/*** Creates the complete registered Design provider from its explicit group-local policies. */
|
|
3
|
+
export declare function createDesignRuleProvider(options: DesignRuleProviderOptions): DesignRuleProvider;
|
|
@@ -1,9 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createAccessibilityRules } from '../accessibility/createAccessibilityRules';
|
|
2
|
+
import { createAlignmentRules } from '../alignment/createAlignmentRules';
|
|
3
|
+
import { createColorRuleSet } from '../color/createColorRuleSet';
|
|
4
|
+
import { createContrastRules } from '../contrast/createContrastRules';
|
|
5
|
+
import { createMediaRuleSet } from '../media/createMediaRuleSet';
|
|
6
|
+
import { createRepetitionRules } from '../repetition/createRepetitionRules';
|
|
7
|
+
import { createResponsiveRules } from '../responsive/createResponsiveRules';
|
|
8
|
+
import { createSpacingProximityRuleSet } from '../spacing-proximity/createSpacingProximityRuleSet';
|
|
9
|
+
import { createTypographyRuleSet } from '../typography/createTypographyRuleSet';
|
|
10
|
+
import { createDesignCrapRules } from './createDesignCrapRules';
|
|
11
|
+
/*** Creates the complete registered Design provider from its explicit group-local policies. */
|
|
12
|
+
export function createDesignRuleProvider(options) {
|
|
13
|
+
const atomicRules = createAtomicRules(options);
|
|
14
|
+
return {
|
|
6
15
|
id: 'ankhorage.rules-design',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
packageName: '@ankhorage/rules-design',
|
|
17
|
+
ruleSet: {
|
|
18
|
+
id: 'ankhorage.rules-design',
|
|
19
|
+
rules: [...atomicRules, ...createDesignCrapRules(atomicRules)],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/*** Collects each independently owned atomic contribution at the central registration boundary. */
|
|
24
|
+
function createAtomicRules(options) {
|
|
25
|
+
const ruleSets = [
|
|
26
|
+
createColorRuleSet(options.color),
|
|
27
|
+
{ id: 'ankhorage.rules-design.contrast', rules: createContrastRules() },
|
|
28
|
+
createTypographyRuleSet(options.typography),
|
|
29
|
+
createSpacingProximityRuleSet(),
|
|
30
|
+
{ id: 'ankhorage.rules-design.alignment', rules: createAlignmentRules(options.alignment) },
|
|
31
|
+
{ id: 'ankhorage.rules-design.repetition', rules: createRepetitionRules() },
|
|
32
|
+
{ id: 'ankhorage.rules-design.responsive', rules: createResponsiveRules() },
|
|
33
|
+
{ id: 'ankhorage.rules-design.accessibility', rules: createAccessibilityRules() },
|
|
34
|
+
createMediaRuleSet(options.media),
|
|
35
|
+
];
|
|
36
|
+
return ruleSets.flatMap((ruleSet) => ruleSet.rules);
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { designRuleProfiles } from '../catalog/designRuleProfiles';
|
|
2
|
+
/*** Resolves one named profile independently from the Rule IDs it selects. */
|
|
3
|
+
export function selectDesignRuleProfile(profileId) {
|
|
4
|
+
const profile = designRuleProfiles.find((candidate) => candidate.id === profileId);
|
|
5
|
+
if (profile === undefined)
|
|
6
|
+
throw new RangeError(`Unknown Design profile: ${profileId}.`);
|
|
7
|
+
return { profileId: profile.id, selection: selection(profile.rootRuleIds) };
|
|
8
|
+
}
|
|
9
|
+
/*** Creates a fresh generic selection so callers cannot mutate catalog-owned profile declarations. */
|
|
10
|
+
function selection(rootRuleIds) {
|
|
11
|
+
return { rootRuleIds: [...rootRuleIds] };
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
1
|
import type { RuleSet } from '@ankhorage/rules';
|
|
2
|
+
import type { DesignContext } from '../../types/designRuleProvider';
|
|
3
3
|
/*** Creates the independently owned Spacing and Proximity Rules contribution. */
|
|
4
|
-
export declare function createSpacingProximityRuleSet(): RuleSet<
|
|
4
|
+
export declare function createSpacingProximityRuleSet(): RuleSet<DesignContext>;
|
|
@@ -29,7 +29,7 @@ function createRule(definition) {
|
|
|
29
29
|
return {
|
|
30
30
|
defaultSeverity: definition.severity,
|
|
31
31
|
dependencies: [],
|
|
32
|
-
evaluate: ({ context, scope }) => evaluate(context, definition, scope),
|
|
32
|
+
evaluate: ({ context, scope }) => evaluate(context.facts, definition, scope),
|
|
33
33
|
facets: facets(definition),
|
|
34
34
|
identity: { id: definition.id, version: '1.0.0' },
|
|
35
35
|
requiredCapabilities: [definition.capability],
|
|
@@ -72,7 +72,7 @@ function definition(id, summary, evaluate, measurementsComplete, severity = 'err
|
|
|
72
72
|
}
|
|
73
73
|
/*** Reads scoped Typography facts without discarding malformed or unavailable evidence. */
|
|
74
74
|
function typographyEvidence(context, capability, scope) {
|
|
75
|
-
const factObservations =
|
|
75
|
+
const factObservations = context.facts
|
|
76
76
|
.filter((fact) => fact.kind === capability && fact.scope.id === scope.id && fact.scope.kind === scope.kind)
|
|
77
77
|
.map((fact) => fact.status === 'available' ? parseTypographyObservation(fact.value, fact.id) : []);
|
|
78
78
|
return [
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFact, AssessmentResult } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Assesses semantic contact placement and normalized contact-link matching. */
|
|
3
|
+
export declare function assessContactAddressMarkup(facts: readonly AssessmentFact[]): AssessmentResult;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
3
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
4
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
5
|
+
/*** Assesses semantic contact placement and normalized contact-link matching. */
|
|
6
|
+
export function assessContactAddressMarkup(facts) {
|
|
7
|
+
const observations = validatedWebsiteAssessmentValues(facts.map((fact) => contactObservation(fact.value, fact.id)));
|
|
8
|
+
if (observations === null)
|
|
9
|
+
return websiteAssessmentResult(null);
|
|
10
|
+
return websiteAssessmentResult(observations.flatMap((observation) => observation.context === 'address' && observation.links.every(Boolean)
|
|
11
|
+
? []
|
|
12
|
+
: [
|
|
13
|
+
contactFinding(observation.subject, observation.context === 'address' ? 'contact-link' : 'address-context', observation.id, observation.kind),
|
|
14
|
+
]));
|
|
15
|
+
}
|
|
16
|
+
/*** Parses a contact observation without retaining raw address or link content. */
|
|
17
|
+
function contactObservation(value, id) {
|
|
18
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
19
|
+
if (!Array.isArray(value.contactLinks) ||
|
|
20
|
+
subject === null ||
|
|
21
|
+
value.version !== 1 ||
|
|
22
|
+
(value.addressKind !== 'company' && value.addressKind !== 'person') ||
|
|
23
|
+
(value.addressContext !== 'address' && value.addressContext !== 'other'))
|
|
24
|
+
return null;
|
|
25
|
+
const links = value.contactLinks.map(contactLinkMatch);
|
|
26
|
+
const matches = validatedWebsiteAssessmentValues(links);
|
|
27
|
+
return matches === null
|
|
28
|
+
? null
|
|
29
|
+
: { context: value.addressContext, id, kind: value.addressKind, links: matches, subject };
|
|
30
|
+
}
|
|
31
|
+
/*** Validates a single normalized contact-link match without exposing its target. */
|
|
32
|
+
function contactLinkMatch(value) {
|
|
33
|
+
return isRecord(value) &&
|
|
34
|
+
(value.kind === 'email' || value.kind === 'phone') &&
|
|
35
|
+
typeof value.match === 'boolean'
|
|
36
|
+
? value.match
|
|
37
|
+
: null;
|
|
38
|
+
}
|
|
39
|
+
/*** Creates privacy-safe evidence for a contact semantic defect. */
|
|
40
|
+
function contactFinding(subject, issue, observationId, addressKind) {
|
|
41
|
+
return {
|
|
42
|
+
evidence: { addressKind, issue, observationId },
|
|
43
|
+
message: 'A recognized contact address lacks semantic address context or a matching contact link.',
|
|
44
|
+
subject,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFact, AssessmentResult, WebsiteAssessmentRuleOptions } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Assesses parser-normalized copyright placement and year semantics. */
|
|
3
|
+
export declare function assessCopyrightNotice(facts: readonly AssessmentFact[], options: WebsiteAssessmentRuleOptions): AssessmentResult;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
2
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
3
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
4
|
+
/*** Assesses parser-normalized copyright placement and year semantics. */
|
|
5
|
+
export function assessCopyrightNotice(facts, options) {
|
|
6
|
+
const { referenceYear } = options;
|
|
7
|
+
const observations = validatedWebsiteAssessmentValues(facts.map((fact) => copyrightObservation(fact.value, fact.id)));
|
|
8
|
+
return referenceYear === undefined || observations === null
|
|
9
|
+
? websiteAssessmentResult(null)
|
|
10
|
+
: websiteAssessmentResult(observations.flatMap((observation) => observation.year < referenceYear && !observation.exception
|
|
11
|
+
? [copyrightFinding(observation)]
|
|
12
|
+
: []));
|
|
13
|
+
}
|
|
14
|
+
/*** Parses public parser output required for copyright assessment. */
|
|
15
|
+
function copyrightObservation(value, id) {
|
|
16
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
17
|
+
return value.version === 1 &&
|
|
18
|
+
value.noticeSyntax === 'recognized' &&
|
|
19
|
+
value.siteRole === 'footer' &&
|
|
20
|
+
websiteAssessmentValues.year(value.endYear) &&
|
|
21
|
+
typeof value.exception === 'boolean' &&
|
|
22
|
+
subject !== null
|
|
23
|
+
? { exception: value.exception, id, subject, year: value.endYear }
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
/*** Creates minimal year-only evidence for a stale copyright notice. */
|
|
27
|
+
function copyrightFinding(observation) {
|
|
28
|
+
return {
|
|
29
|
+
evidence: { issue: 'stale-year', noticeId: observation.id, year: observation.year },
|
|
30
|
+
message: 'A recognized copyright notice has a stale year.',
|
|
31
|
+
subject: observation.subject,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
3
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
4
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
5
|
+
/*** Reports repeated editorial identities while exempting system-only reuse. */
|
|
6
|
+
export function assessDuplicateMediaUse(facts) {
|
|
7
|
+
const inventories = validatedWebsiteAssessmentValues(facts.map((fact) => mediaUses(fact.value)));
|
|
8
|
+
if (inventories === null)
|
|
9
|
+
return websiteAssessmentResult(null);
|
|
10
|
+
const observations = inventories.flatMap((inventory) => inventory);
|
|
11
|
+
if (observations.length === 0)
|
|
12
|
+
return websiteAssessmentResult(null);
|
|
13
|
+
const groups = observations.reduce((all, use) => new Map(all).set(use.identity, [...(all.get(use.identity) ?? []), use]), new Map());
|
|
14
|
+
return websiteAssessmentResult([...groups.values()].flatMap((group) => group.length > 1 && group.some((use) => use.role === 'editorial')
|
|
15
|
+
? [duplicateFinding(group)]
|
|
16
|
+
: []));
|
|
17
|
+
}
|
|
18
|
+
/*** Parses one inventory while preserving the distinction between invalid and empty input. */
|
|
19
|
+
function mediaUses(value) {
|
|
20
|
+
if (value.version !== 1 || !Array.isArray(value.uses))
|
|
21
|
+
return null;
|
|
22
|
+
const uses = value.uses.map(mediaUse);
|
|
23
|
+
return validatedWebsiteAssessmentValues(uses);
|
|
24
|
+
}
|
|
25
|
+
/*** Parses a single opaque media use from an identity-bearing inventory entry. */
|
|
26
|
+
function mediaUse(value) {
|
|
27
|
+
if (!isRecord(value))
|
|
28
|
+
return null;
|
|
29
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
30
|
+
const identity = websiteAssessmentValues.text(value.contentHash) ??
|
|
31
|
+
websiteAssessmentValues.text(value.lineageId) ??
|
|
32
|
+
websiteAssessmentValues.text(value.assetId);
|
|
33
|
+
const pageId = websiteAssessmentValues.text(value.pageId);
|
|
34
|
+
const componentId = websiteAssessmentValues.text(value.componentId);
|
|
35
|
+
return subject !== null &&
|
|
36
|
+
identity !== null &&
|
|
37
|
+
pageId !== null &&
|
|
38
|
+
componentId !== null &&
|
|
39
|
+
(value.role === 'editorial' || value.role === 'system')
|
|
40
|
+
? { identity, location: `${pageId}:${componentId}`, role: value.role, subject }
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
/*** Produces sorted opaque evidence for one repeated asset identity. */
|
|
44
|
+
function duplicateFinding(group) {
|
|
45
|
+
const [first] = group;
|
|
46
|
+
return {
|
|
47
|
+
evidence: {
|
|
48
|
+
assetKey: first.identity,
|
|
49
|
+
locations: group.map((use) => use.location).sort(),
|
|
50
|
+
useCount: group.length,
|
|
51
|
+
},
|
|
52
|
+
message: 'A verified asset is reused in multiple editorial content locations.',
|
|
53
|
+
subject: first.subject,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFact, AssessmentResult, WebsiteAssessmentRuleOptions } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Applies configured legal-notice policy to independently observed link facts. */
|
|
3
|
+
export declare function assessLegalNotice(facts: readonly AssessmentFact[], options: WebsiteAssessmentRuleOptions): AssessmentResult;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isStringArray } from '@ankhorage/utility/array';
|
|
2
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
3
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
4
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
5
|
+
/*** Applies configured legal-notice policy to independently observed link facts. */
|
|
6
|
+
export function assessLegalNotice(facts, options) {
|
|
7
|
+
const observations = validatedWebsiteAssessmentValues(facts.map((fact) => legalNoticeObservation(fact.value, fact.id)));
|
|
8
|
+
if (options.legalNoticePolicy === undefined || observations === null)
|
|
9
|
+
return websiteAssessmentResult(null);
|
|
10
|
+
return options.legalNoticePolicy === 'not-required'
|
|
11
|
+
? websiteAssessmentResult([])
|
|
12
|
+
: websiteAssessmentResult(observations.flatMap((observation) => observation.global && observation.reachable && observation.content === 'substantive'
|
|
13
|
+
? []
|
|
14
|
+
: [legalNoticeFinding(observation)]));
|
|
15
|
+
}
|
|
16
|
+
/*** Parses legal notice facts without promoting labels to legal conclusions. */
|
|
17
|
+
function legalNoticeObservation(value, id) {
|
|
18
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
19
|
+
return value.version === 1 &&
|
|
20
|
+
isStringArray(value.labels) &&
|
|
21
|
+
typeof value.global === 'boolean' &&
|
|
22
|
+
typeof value.reachable === 'boolean' &&
|
|
23
|
+
(value.content === 'substantive' ||
|
|
24
|
+
value.content === 'empty' ||
|
|
25
|
+
value.content === 'misleading') &&
|
|
26
|
+
subject !== null
|
|
27
|
+
? { content: value.content, global: value.global, id, reachable: value.reachable, subject }
|
|
28
|
+
: null;
|
|
29
|
+
}
|
|
30
|
+
/*** Creates a normalized legal notice failure without retaining page text. */
|
|
31
|
+
function legalNoticeFinding(observation) {
|
|
32
|
+
return {
|
|
33
|
+
evidence: {
|
|
34
|
+
issue: !observation.reachable
|
|
35
|
+
? 'unreachable'
|
|
36
|
+
: !observation.global
|
|
37
|
+
? 'not-site-wide'
|
|
38
|
+
: 'empty-or-misleading',
|
|
39
|
+
noticeId: observation.id,
|
|
40
|
+
},
|
|
41
|
+
message: 'A configured legal notice is not site-wide, reachable, and substantive.',
|
|
42
|
+
subject: observation.subject,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFact, AssessmentResult, WebsiteAssessmentRuleOptions } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Compares declared privacy purposes with observed processing purposes. */
|
|
3
|
+
export declare function assessPrivacyNotice(facts: readonly AssessmentFact[], options: WebsiteAssessmentRuleOptions): AssessmentResult;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isStringArray } from '@ankhorage/utility/array';
|
|
2
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
3
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
4
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
5
|
+
/*** Compares declared privacy purposes with observed processing purposes. */
|
|
6
|
+
export function assessPrivacyNotice(facts, options) {
|
|
7
|
+
const observations = validatedWebsiteAssessmentValues(facts.map((fact) => privacyNoticeObservation(fact.value, fact.id)));
|
|
8
|
+
if (options.privacyNoticePolicy === undefined || observations === null)
|
|
9
|
+
return websiteAssessmentResult(null);
|
|
10
|
+
return options.privacyNoticePolicy === 'not-required'
|
|
11
|
+
? websiteAssessmentResult([])
|
|
12
|
+
: websiteAssessmentResult(observations.flatMap((observation) => observation.global &&
|
|
13
|
+
observation.reachable &&
|
|
14
|
+
observation.observed.every((purpose) => observation.declared.includes(purpose))
|
|
15
|
+
? []
|
|
16
|
+
: [privacyNoticeFinding(observation)]));
|
|
17
|
+
}
|
|
18
|
+
/*** Parses privacy facts using the fixed policy-purpose vocabulary. */
|
|
19
|
+
function privacyNoticeObservation(value, id) {
|
|
20
|
+
const declared = privacyPurposesFrom(value.declaredPurposes);
|
|
21
|
+
const observed = privacyPurposesFrom(value.observedPurposes);
|
|
22
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
23
|
+
return value.version === 1 &&
|
|
24
|
+
typeof value.global === 'boolean' &&
|
|
25
|
+
typeof value.reachable === 'boolean' &&
|
|
26
|
+
declared !== null &&
|
|
27
|
+
observed !== null &&
|
|
28
|
+
subject !== null
|
|
29
|
+
? { declared, global: value.global, id, observed, reachable: value.reachable, subject }
|
|
30
|
+
: null;
|
|
31
|
+
}
|
|
32
|
+
/*** Accepts only the policy-owned declared and observed processing vocabulary. */
|
|
33
|
+
function privacyPurposesFrom(value) {
|
|
34
|
+
if (!isStringArray(value))
|
|
35
|
+
return null;
|
|
36
|
+
const purposes = value.map(privacyPurpose);
|
|
37
|
+
return validatedWebsiteAssessmentValues(purposes);
|
|
38
|
+
}
|
|
39
|
+
/*** Narrows one declared processing purpose to the policy-owned vocabulary. */
|
|
40
|
+
function privacyPurpose(value) {
|
|
41
|
+
return value === 'analytics' || value === 'contact' ? value : null;
|
|
42
|
+
}
|
|
43
|
+
/*** Creates non-sensitive evidence for a missing privacy declaration. */
|
|
44
|
+
function privacyNoticeFinding(observation) {
|
|
45
|
+
return {
|
|
46
|
+
evidence: {
|
|
47
|
+
issue: !observation.reachable
|
|
48
|
+
? 'unreachable'
|
|
49
|
+
: !observation.global
|
|
50
|
+
? 'not-site-wide'
|
|
51
|
+
: 'undeclared-processing',
|
|
52
|
+
noticeId: observation.id,
|
|
53
|
+
observedPurposeCount: observation.observed.length,
|
|
54
|
+
},
|
|
55
|
+
message: 'The privacy notice is unreachable, not site-wide, or omits an observed processing purpose.',
|
|
56
|
+
subject: observation.subject,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFact, AssessmentResult, WebsiteAssessmentRuleOptions } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Applies an explicit regional policy to complete tracking runtime observations. */
|
|
3
|
+
export declare function assessTrackingConsent(facts: readonly AssessmentFact[], options: WebsiteAssessmentRuleOptions): AssessmentResult;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
import { validatedWebsiteAssessmentValues } from './isWebsiteAssessmentNonNull';
|
|
3
|
+
import { websiteAssessmentResult } from './websiteAssessmentResult';
|
|
4
|
+
import { websiteAssessmentValues } from './websiteAssessmentValues';
|
|
5
|
+
/*** Applies an explicit regional policy to complete tracking runtime observations. */
|
|
6
|
+
export function assessTrackingConsent(facts, options) {
|
|
7
|
+
const policy = options.trackingConsentPolicy;
|
|
8
|
+
const observations = validatedWebsiteAssessmentValues(facts.map((fact) => trackingObservation(fact.value, fact.id)));
|
|
9
|
+
if (policy === undefined || observations === null)
|
|
10
|
+
return websiteAssessmentResult(null);
|
|
11
|
+
return websiteAssessmentResult(observations.flatMap((observation) => trackingFails(observation, policy) ? [trackingFinding(observation, policy)] : []));
|
|
12
|
+
}
|
|
13
|
+
/*** Parses fully covered tracking state observations. */
|
|
14
|
+
function trackingObservation(value, id) {
|
|
15
|
+
const subject = websiteAssessmentValues.subject(value.subject);
|
|
16
|
+
if (value.version !== 1 || subject === null || !Array.isArray(value.states))
|
|
17
|
+
return null;
|
|
18
|
+
const states = validatedWebsiteAssessmentValues(value.states.map(trackingState));
|
|
19
|
+
if (states === null)
|
|
20
|
+
return null;
|
|
21
|
+
return value.classification === 'essential-only'
|
|
22
|
+
? { id, states: [], subject }
|
|
23
|
+
: value.classification === 'optional' && hasCompleteConsentCoverage(states)
|
|
24
|
+
? { id, states, subject }
|
|
25
|
+
: null;
|
|
26
|
+
}
|
|
27
|
+
/*** Requires observations for each state that establishes an optional-tracking decision. */
|
|
28
|
+
function hasCompleteConsentCoverage(states) {
|
|
29
|
+
return ['accepted', 'before-choice', 'rejected'].every((requiredState) => states.some((state) => state.state === requiredState));
|
|
30
|
+
}
|
|
31
|
+
/*** Validates one complete runtime state without retaining tracker values. */
|
|
32
|
+
function trackingState(value) {
|
|
33
|
+
return isRecord(value) &&
|
|
34
|
+
(value.state === 'before-choice' ||
|
|
35
|
+
value.state === 'rejected' ||
|
|
36
|
+
value.state === 'accepted' ||
|
|
37
|
+
value.state === 'withdrawn') &&
|
|
38
|
+
typeof value.optionalTrackingObserved === 'boolean' &&
|
|
39
|
+
value.covered === true
|
|
40
|
+
? { observed: value.optionalTrackingObserved, state: value.state }
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
/*** Applies prior-consent and rejection behavior without assuming a jurisdiction. */
|
|
44
|
+
function trackingFails(observation, policy) {
|
|
45
|
+
return policy === 'eu-eea-prior-consent'
|
|
46
|
+
? observation.states
|
|
47
|
+
.filter((state) => state.state === 'before-choice' || state.state === 'rejected')
|
|
48
|
+
.some((state) => state.observed)
|
|
49
|
+
: observation.states.some((state) => state.state === 'rejected' && state.observed);
|
|
50
|
+
}
|
|
51
|
+
/*** Creates a stable tracking evidence code with no cookie values. */
|
|
52
|
+
function trackingFinding(observation, policy) {
|
|
53
|
+
return {
|
|
54
|
+
evidence: {
|
|
55
|
+
issue: policy === 'eu-eea-prior-consent'
|
|
56
|
+
? 'tracking-before-consent-or-after-rejection'
|
|
57
|
+
: 'tracking-after-rejection',
|
|
58
|
+
observationId: observation.id,
|
|
59
|
+
},
|
|
60
|
+
message: 'Optional tracking was observed in a state disallowed by the configured consent policy.',
|
|
61
|
+
subject: observation.subject,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RuleSet } from '@ankhorage/rules';
|
|
2
|
+
import type { WebsiteAssessmentContext, WebsiteAssessmentRuleOptions } from '../../types/websiteAssessment';
|
|
3
|
+
/*** Creates the separately composable follow-on website and contact assessment rules. */
|
|
4
|
+
export declare function createWebsiteAssessmentRuleSet(options?: WebsiteAssessmentRuleOptions): RuleSet<WebsiteAssessmentContext>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
import { websiteAssessmentDefinitions } from './websiteAssessmentDefinitions';
|
|
3
|
+
/*** Creates the separately composable follow-on website and contact assessment rules. */
|
|
4
|
+
export function createWebsiteAssessmentRuleSet(options = {}) {
|
|
5
|
+
return {
|
|
6
|
+
id: 'ankhorage.rules-design.website-assessment',
|
|
7
|
+
rules: websiteAssessmentDefinitions.map((definition) => createWebsiteAssessmentRule(definition, options)),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/*** Builds one pure Rules adapter around a typed website assessment. */
|
|
11
|
+
function createWebsiteAssessmentRule(definition, options) {
|
|
12
|
+
return {
|
|
13
|
+
defaultSeverity: definition.severity,
|
|
14
|
+
dependencies: [],
|
|
15
|
+
evaluate: ({ context, scope }) => evaluateWebsiteAssessmentRule(definition, options, context.facts, scope),
|
|
16
|
+
identity: { id: definition.id, version: '1.0.0' },
|
|
17
|
+
requiredCapabilities: [definition.capability],
|
|
18
|
+
summary: definition.summary,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/*** Evaluates exact-scope observations and fails closed for missing or malformed facts. */
|
|
22
|
+
function evaluateWebsiteAssessmentRule(definition, options, facts, scope) {
|
|
23
|
+
const scopedFacts = facts.filter((fact) => fact.kind === definition.factKind &&
|
|
24
|
+
fact.scope.id === scope.id &&
|
|
25
|
+
fact.scope.kind === scope.kind);
|
|
26
|
+
const observations = scopedFacts.flatMap(toAssessmentFact);
|
|
27
|
+
if (scopedFacts.length === 0 || observations.length !== scopedFacts.length)
|
|
28
|
+
return incomplete(definition.id, scope);
|
|
29
|
+
const result = definition.evaluate(observations, options);
|
|
30
|
+
return {
|
|
31
|
+
findings: result.findings.map((finding) => ({
|
|
32
|
+
evidence: finding.evidence,
|
|
33
|
+
message: finding.message,
|
|
34
|
+
ruleId: definition.id,
|
|
35
|
+
severity: result.status === 'FAIL' ? definition.severity : 'info',
|
|
36
|
+
subjects: [finding.subject],
|
|
37
|
+
})),
|
|
38
|
+
status: result.status,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/*** Accepts a portable available record only after required fact identity fields are present. */
|
|
42
|
+
function toAssessmentFact(fact) {
|
|
43
|
+
return fact.status === 'available' &&
|
|
44
|
+
nonEmpty(fact.id) &&
|
|
45
|
+
nonEmpty(fact.contentHash) &&
|
|
46
|
+
isRecord(fact.value)
|
|
47
|
+
? [{ id: fact.id, value: fact.value }]
|
|
48
|
+
: [];
|
|
49
|
+
}
|
|
50
|
+
/*** Produces a canonical incomplete outcome without exposing host payloads. */
|
|
51
|
+
function incomplete(id, scope) {
|
|
52
|
+
return {
|
|
53
|
+
findings: [
|
|
54
|
+
{
|
|
55
|
+
evidence: { scopeId: scope.id, scopeKind: scope.kind },
|
|
56
|
+
message: 'Complete validated website assessment observations are unavailable.',
|
|
57
|
+
ruleId: id,
|
|
58
|
+
severity: 'info',
|
|
59
|
+
subjects: [{ id: scope.id, kind: scope.kind }],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
status: 'INCOMPLETE',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/*** Narrows a stable fact identity string. */
|
|
66
|
+
function nonEmpty(value) {
|
|
67
|
+
return value.trim().length > 0;
|
|
68
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*** Returns normalized assessment values only when every array element has been validated. */
|
|
2
|
+
export function validatedWebsiteAssessmentValues(values) {
|
|
3
|
+
const validated = values.filter((value) => value !== null);
|
|
4
|
+
return validated.length === values.length ? validated : null;
|
|
5
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { assessContactAddressMarkup } from './assessContactAddressMarkup';
|
|
2
|
+
import { assessCopyrightNotice } from './assessCopyrightNotice';
|
|
3
|
+
import { assessDuplicateMediaUse } from './assessDuplicateMediaUse';
|
|
4
|
+
import { assessLegalNotice } from './assessLegalNotice';
|
|
5
|
+
import { assessPrivacyNotice } from './assessPrivacyNotice';
|
|
6
|
+
import { assessTrackingConsent } from './assessTrackingConsent';
|
|
7
|
+
/*** Declares the fixed website-assessment catalog without allowing host verdicts as facts. */
|
|
8
|
+
export const websiteAssessmentDefinitions = [
|
|
9
|
+
definition('design.contact.address-markup', 'website.contact-observation', 'warning', 'Recognized contact addresses use semantic markup and valid contact links.', assessContactAddressMarkup),
|
|
10
|
+
definition('design.website.copyright-notice', 'website.copyright-observation', 'warning', 'Recognized copyright notices are available from site-wide footer evidence.', assessCopyrightNotice),
|
|
11
|
+
definition('design.website.legal-notice', 'website.legal-notice-observation', 'warning', 'Configured legal notices are discoverable, reachable, and sufficiently identified.', assessLegalNotice),
|
|
12
|
+
definition('design.website.privacy-notice', 'website.privacy-notice-observation', 'warning', 'Configured privacy notices are reachable and consistent with observed processing.', assessPrivacyNotice),
|
|
13
|
+
definition('design.website.tracking-consent', 'website.tracking-observation', 'error', 'Observed optional tracking follows the configured jurisdiction consent policy.', assessTrackingConsent),
|
|
14
|
+
definition('design.media.duplicate-use', 'website.media-inventory', 'warning', 'Repeated image assets are classified without treating intentional reuse as a defect.', assessDuplicateMediaUse),
|
|
15
|
+
];
|
|
16
|
+
/*** Creates one immutable definition with its capability-owned evaluator. */
|
|
17
|
+
function definition(id, factKind, severity, summary, evaluate) {
|
|
18
|
+
return {
|
|
19
|
+
capability: factKind,
|
|
20
|
+
evaluate,
|
|
21
|
+
factKind,
|
|
22
|
+
id,
|
|
23
|
+
severity,
|
|
24
|
+
summary,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssessmentFinding, AssessmentResult } from '../../types/websiteAssessment';
|
|
2
|
+
/*** Produces deterministic outcomes and generic incomplete evidence for website assessment rules. */
|
|
3
|
+
export declare function websiteAssessmentResult(findings: readonly AssessmentFinding[] | null): AssessmentResult;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*** Produces deterministic outcomes and generic incomplete evidence for website assessment rules. */
|
|
2
|
+
export function websiteAssessmentResult(findings) {
|
|
3
|
+
if (findings === null)
|
|
4
|
+
return {
|
|
5
|
+
findings: [
|
|
6
|
+
{
|
|
7
|
+
evidence: { reason: 'incomplete-observation' },
|
|
8
|
+
message: 'The supplied structured observations are insufficient for a safe assessment.',
|
|
9
|
+
subject: incompleteSubject,
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
status: 'INCOMPLETE',
|
|
13
|
+
};
|
|
14
|
+
return findings.length === 0
|
|
15
|
+
? { findings: [], status: 'PASS' }
|
|
16
|
+
: {
|
|
17
|
+
findings: [...findings].sort((left, right) => left.subject.id.localeCompare(right.subject.id)),
|
|
18
|
+
status: 'FAIL',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const incompleteSubject = { id: 'website-assessment', kind: 'website' };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AvailableFactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
|
+
import { type JsonValue } from '@ankhorage/rules';
|
|
3
|
+
declare const options: {
|
|
4
|
+
readonly legalNoticePolicy: "required";
|
|
5
|
+
readonly privacyNoticePolicy: "required";
|
|
6
|
+
readonly referenceYear: 2026;
|
|
7
|
+
readonly trackingConsentPolicy: "eu-eea-prior-consent";
|
|
8
|
+
};
|
|
9
|
+
/*** Evaluates one website assessment rule through the public Rules engine boundary. */
|
|
10
|
+
export declare function evaluateWebsiteAssessment(ruleId: string, facts: readonly AvailableFactEnvelope[], override?: Partial<typeof options>): import("@ankhorage/rules").RuleResult;
|
|
11
|
+
/*** Builds an available opaque test fact with a real SHA-256 content hash. */
|
|
12
|
+
export declare function websiteAssessmentFact(kind: string, value: JsonValue): AvailableFactEnvelope;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { evaluateRules } from '@ankhorage/rules';
|
|
3
|
+
import { createWebsiteAssessmentRuleSet } from './createWebsiteAssessmentRuleSet';
|
|
4
|
+
const scope = { id: 'site', kind: 'website' };
|
|
5
|
+
const options = {
|
|
6
|
+
legalNoticePolicy: 'required',
|
|
7
|
+
privacyNoticePolicy: 'required',
|
|
8
|
+
referenceYear: 2026,
|
|
9
|
+
trackingConsentPolicy: 'eu-eea-prior-consent',
|
|
10
|
+
};
|
|
11
|
+
/*** Evaluates one website assessment rule through the public Rules engine boundary. */
|
|
12
|
+
export function evaluateWebsiteAssessment(ruleId, facts, override = {}) {
|
|
13
|
+
const rule = createWebsiteAssessmentRuleSet({ ...options, ...override }).rules.find((candidate) => candidate.identity.id === ruleId);
|
|
14
|
+
if (rule === undefined)
|
|
15
|
+
throw new Error(`Missing rule ${ruleId}`);
|
|
16
|
+
const [result] = evaluateRules({ facts }, [rule], {
|
|
17
|
+
capabilities: rule.requiredCapabilities,
|
|
18
|
+
scope,
|
|
19
|
+
}).results;
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/*** Builds an available opaque test fact with a real SHA-256 content hash. */
|
|
23
|
+
export function websiteAssessmentFact(kind, value) {
|
|
24
|
+
const hash = createHash('sha256').update(canonical(value)).digest('hex');
|
|
25
|
+
return {
|
|
26
|
+
contentHash: `sha256:${hash}`,
|
|
27
|
+
id: `${kind}:${hash.slice(0, 12)}`,
|
|
28
|
+
kind,
|
|
29
|
+
provenance: {
|
|
30
|
+
collectedAt: '2026-11-11T00:00:00.000Z',
|
|
31
|
+
producer: { id: 'fixture', version: '1' },
|
|
32
|
+
source: { id: 'fixture', revision: null },
|
|
33
|
+
},
|
|
34
|
+
schemaVersion: 1,
|
|
35
|
+
scope: {
|
|
36
|
+
...scope,
|
|
37
|
+
target: { kind: 'application', projectId: 'project', targetId: 'site', tenantId: 'tenant' },
|
|
38
|
+
},
|
|
39
|
+
status: 'available',
|
|
40
|
+
value,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/*** Produces a stable serialization for real test content hashes. */
|
|
44
|
+
function canonical(value) {
|
|
45
|
+
if (Array.isArray(value))
|
|
46
|
+
return `[${value.map(canonical).join(',')}]`;
|
|
47
|
+
if (value !== null && typeof value === 'object')
|
|
48
|
+
return `{${Object.entries(value)
|
|
49
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
50
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`)
|
|
51
|
+
.join(',')}}`;
|
|
52
|
+
return JSON.stringify(value);
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonValue, RuleSubject } from '@ankhorage/rules';
|
|
2
|
+
/*** Validates privacy-safe, normalized values shared by website assessment rules. */
|
|
3
|
+
export declare const websiteAssessmentValues: {
|
|
4
|
+
subject(value: unknown): RuleSubject | null;
|
|
5
|
+
text(value: unknown): string | null;
|
|
6
|
+
year(value: JsonValue | undefined): value is number;
|
|
7
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
/*** Validates privacy-safe, normalized values shared by website assessment rules. */
|
|
3
|
+
export const websiteAssessmentValues = {
|
|
4
|
+
subject(value) {
|
|
5
|
+
if (!isRecord(value))
|
|
6
|
+
return null;
|
|
7
|
+
const id = this.text(value.id);
|
|
8
|
+
const kind = this.text(value.kind);
|
|
9
|
+
return id === null || kind === null ? null : { id, kind };
|
|
10
|
+
},
|
|
11
|
+
text(value) {
|
|
12
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : null;
|
|
13
|
+
},
|
|
14
|
+
year(value) {
|
|
15
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 1000 && value <= 9999;
|
|
16
|
+
},
|
|
17
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export { designRuleCatalog } from './features/catalog/designRuleCatalog';
|
|
|
2
2
|
export { designRuleProfiles } from './features/catalog/designRuleProfiles';
|
|
3
3
|
export { designRuleProviderManifest } from './features/catalog/designRuleProviderManifest';
|
|
4
4
|
export { filterDesignRuleCatalog } from './features/catalog/filterDesignRuleCatalog';
|
|
5
|
-
export {
|
|
5
|
+
export { createDesignRuleProvider } from './features/provider/designRuleProvider';
|
|
6
|
+
export { selectDesignRuleProfile } from './features/provider/selectDesignRuleProfile';
|
|
7
|
+
export { createWebsiteAssessmentRuleSet } from './features/website-assessment/createWebsiteAssessmentRuleSet';
|
|
6
8
|
export type { DesignAssessmentKind, DesignRuleCatalogEntry, DesignRuleCatalogFilter, DesignRuleEvidence, DesignRulePlanningManifest, DesignRuleProfile, DesignRuleProviderManifest, DesignRuleScope, DesignRuleStatus, } from './types/designRuleCatalog';
|
|
7
|
-
export type { DesignContext,
|
|
9
|
+
export type { DesignContext, DesignRuleProfileSelection, DesignRuleProvider, DesignRuleProviderOptions, } from './types/designRuleProvider';
|
|
10
|
+
export type { WebsiteAssessmentRuleOptions } from './types/websiteAssessment';
|
package/dist/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { designRuleCatalog } from './features/catalog/designRuleCatalog';
|
|
|
2
2
|
export { designRuleProfiles } from './features/catalog/designRuleProfiles';
|
|
3
3
|
export { designRuleProviderManifest } from './features/catalog/designRuleProviderManifest';
|
|
4
4
|
export { filterDesignRuleCatalog } from './features/catalog/filterDesignRuleCatalog';
|
|
5
|
-
export {
|
|
5
|
+
export { createDesignRuleProvider } from './features/provider/designRuleProvider';
|
|
6
|
+
export { selectDesignRuleProfile } from './features/provider/selectDesignRuleProfile';
|
|
7
|
+
export { createWebsiteAssessmentRuleSet } from './features/website-assessment/createWebsiteAssessmentRuleSet';
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import type { FactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
|
-
import type { RuleSet } from '@ankhorage/rules';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
import type { RuleSelection, RuleSet } from '@ankhorage/rules';
|
|
3
|
+
import type { AlignmentRuleOptions } from '../features/alignment/createAlignmentRules';
|
|
4
|
+
import type { ColorRulePolicy } from '../features/color/createColorRuleSet';
|
|
5
|
+
import type { MediaRuleOptions } from '../features/media/createMediaRuleSet';
|
|
6
|
+
import type { TypographyRulePolicy } from './typography';
|
|
8
7
|
/*** The minimal context shared by Design rules without prescribing its source. */
|
|
9
8
|
export interface DesignContext {
|
|
10
|
-
readonly
|
|
11
|
-
|
|
9
|
+
readonly facts: readonly FactEnvelope[];
|
|
10
|
+
}
|
|
11
|
+
/*** Configures the group-local policy needed to create one complete Design provider. */
|
|
12
|
+
export interface DesignRuleProviderOptions {
|
|
13
|
+
readonly alignment?: AlignmentRuleOptions;
|
|
14
|
+
readonly color: ColorRulePolicy;
|
|
15
|
+
readonly media?: MediaRuleOptions;
|
|
16
|
+
readonly typography: TypographyRulePolicy;
|
|
12
17
|
}
|
|
13
18
|
/*** The public identity and generic Rules contribution for the Design provider. */
|
|
14
19
|
export interface DesignRuleProvider {
|
|
@@ -16,3 +21,8 @@ export interface DesignRuleProvider {
|
|
|
16
21
|
readonly packageName: '@ankhorage/rules-design';
|
|
17
22
|
readonly ruleSet: RuleSet<DesignContext>;
|
|
18
23
|
}
|
|
24
|
+
/*** Maps a named Design profile to the generic Rules engine selection contract. */
|
|
25
|
+
export interface DesignRuleProfileSelection {
|
|
26
|
+
readonly profileId: string;
|
|
27
|
+
readonly selection: RuleSelection;
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FactEnvelope } from '@ankhorage/contracts/rules';
|
|
2
|
+
import type { JsonValue, RuleSubject } from '@ankhorage/rules';
|
|
3
|
+
/*** Configures explicit policies for the independently composable website assessment RuleSet. */
|
|
4
|
+
export interface WebsiteAssessmentRuleOptions {
|
|
5
|
+
readonly legalNoticePolicy?: 'not-required' | 'required';
|
|
6
|
+
readonly privacyNoticePolicy?: 'not-required' | 'required';
|
|
7
|
+
readonly referenceYear?: number;
|
|
8
|
+
readonly trackingConsentPolicy?: 'ch-information-and-objection' | 'eu-eea-prior-consent';
|
|
9
|
+
}
|
|
10
|
+
type WebsiteAssessmentRuleId = 'design.contact.address-markup' | 'design.website.copyright-notice' | 'design.website.legal-notice' | 'design.website.privacy-notice' | 'design.website.tracking-consent' | 'design.media.duplicate-use';
|
|
11
|
+
export interface WebsiteAssessmentContext {
|
|
12
|
+
readonly facts: readonly FactEnvelope[];
|
|
13
|
+
}
|
|
14
|
+
export interface AssessmentFact {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly value: Readonly<Record<string, JsonValue>>;
|
|
17
|
+
}
|
|
18
|
+
export interface AssessmentFinding {
|
|
19
|
+
readonly evidence: Readonly<Record<string, JsonValue>>;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
readonly subject: RuleSubject;
|
|
22
|
+
}
|
|
23
|
+
export interface AssessmentResult {
|
|
24
|
+
readonly findings: readonly AssessmentFinding[];
|
|
25
|
+
readonly status: 'FAIL' | 'INCOMPLETE' | 'PASS';
|
|
26
|
+
}
|
|
27
|
+
export interface AssessmentDefinition {
|
|
28
|
+
readonly capability: string;
|
|
29
|
+
readonly factKind: string;
|
|
30
|
+
readonly id: WebsiteAssessmentRuleId;
|
|
31
|
+
readonly severity: 'error' | 'warning';
|
|
32
|
+
readonly summary: string;
|
|
33
|
+
readonly evaluate: (facts: readonly AssessmentFact[], options: WebsiteAssessmentRuleOptions) => AssessmentResult;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
File without changes
|