@holmdigital/engine 3.3.13 → 4.0.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/dist/index.js CHANGED
@@ -961,7 +961,7 @@ __export(index_exports, {
961
961
  getStandardsVersion: () => getStandardsVersion,
962
962
  isInterstitialPage: () => isInterstitialPage,
963
963
  probeWithoutJavaScript: () => probeWithoutJavaScript,
964
- resolveNationalLawReference: () => resolveNationalLawReference,
964
+ resolveNationalLawReference: () => import_standards.resolveNationalLawReference,
965
965
  selectMappedRuleId: () => selectMappedRuleId,
966
966
  setLanguage: () => setLanguage,
967
967
  t: () => t,
@@ -1146,6 +1146,7 @@ function evaluateNoScriptCoverage(textLengthWithoutJs, textLengthWithJs, hasNoSc
1146
1146
  async function probeWithoutJavaScript(browser, options) {
1147
1147
  const page = await browser.newPage();
1148
1148
  try {
1149
+ if (options.preparePage) await options.preparePage(page);
1149
1150
  if (options.userAgent) await page.setUserAgent(options.userAgent);
1150
1151
  if (options.viewport) await page.setViewport(options.viewport);
1151
1152
  await page.setJavaScriptEnabled(false);
@@ -1169,6 +1170,146 @@ async function probeWithoutJavaScript(browser, options) {
1169
1170
  }
1170
1171
  }
1171
1172
 
1173
+ // src/core/network-guard.ts
1174
+ init_cjs_shims();
1175
+ var import_promises = require("dns/promises");
1176
+ var import_node_net = require("net");
1177
+ var PrivateHostError = class extends Error {
1178
+ host;
1179
+ reason;
1180
+ constructor(url, host, reason) {
1181
+ super(
1182
+ `Refusing to scan '${url}': ${host} resolves to ${reason}. Private and internal addresses are blocked by default, so the engine cannot be used to reach internal services. To scan your own local development server, pass --allow-private-hosts (library: allowPrivateHosts: true).`
1183
+ );
1184
+ this.name = "PrivateHostError";
1185
+ this.host = host;
1186
+ this.reason = reason;
1187
+ }
1188
+ };
1189
+ function blockedIPv4(ip) {
1190
+ const p = ip.split(".").map(Number);
1191
+ if (p.length !== 4 || p.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return "a malformed IPv4 address";
1192
+ const [a, b] = p;
1193
+ if (a === 0) return "this-network 0.0.0.0/8";
1194
+ if (a === 10) return "private 10.0.0.0/8";
1195
+ if (a === 127) return "loopback 127.0.0.0/8";
1196
+ if (a === 169 && b === 254) {
1197
+ return ip === "169.254.169.254" ? "the cloud metadata service 169.254.169.254" : "link-local 169.254.0.0/16";
1198
+ }
1199
+ if (a === 172 && b >= 16 && b <= 31) return "private 172.16.0.0/12";
1200
+ if (a === 192 && b === 168) return "private 192.168.0.0/16";
1201
+ if (a === 100 && b >= 64 && b <= 127) return "carrier-grade NAT 100.64.0.0/10";
1202
+ if (a === 192 && b === 0) return "IETF protocol assignments 192.0.0.0/24";
1203
+ if (a >= 224) return "multicast or reserved 224.0.0.0/4";
1204
+ return null;
1205
+ }
1206
+ function blockedIPv6(ip) {
1207
+ const lower = ip.toLowerCase();
1208
+ const mapped = lower.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
1209
+ if (mapped) return blockedIPv4(mapped[1]);
1210
+ if (lower === "::1") return "loopback ::1";
1211
+ if (lower === "::") return "unspecified ::";
1212
+ if (/^f[cd]/.test(lower)) return "unique local fc00::/7";
1213
+ if (/^fe[89ab]/.test(lower)) return "link-local fe80::/10";
1214
+ if (/^ff/.test(lower)) return "multicast ff00::/8";
1215
+ return null;
1216
+ }
1217
+ var systemResolver = (hostname) => (0, import_promises.lookup)(hostname, { all: true });
1218
+ async function blockedHostReason(hostname, resolve = systemResolver) {
1219
+ const host = hostname.replace(/^\[|\]$/g, "");
1220
+ const literal = (0, import_node_net.isIP)(host);
1221
+ if (literal === 4) return blockedIPv4(host);
1222
+ if (literal === 6) return blockedIPv6(host);
1223
+ let addresses;
1224
+ try {
1225
+ addresses = await resolve(host);
1226
+ } catch {
1227
+ return "an address that could not be resolved (blocked: the guard fails closed)";
1228
+ }
1229
+ if (addresses.length === 0) return "no address (blocked: the guard fails closed)";
1230
+ for (const { address, family } of addresses) {
1231
+ const reason = family === 6 ? blockedIPv6(address) : blockedIPv4(address);
1232
+ if (reason) return reason;
1233
+ }
1234
+ return null;
1235
+ }
1236
+ async function assertPublicHost(url, resolve = systemResolver) {
1237
+ const { hostname } = new URL(url);
1238
+ const reason = await blockedHostReason(hostname, resolve);
1239
+ if (reason) throw new PrivateHostError(url, hostname, reason);
1240
+ }
1241
+ var LOCAL_SCHEMES = /* @__PURE__ */ new Set(["data:", "blob:", "about:"]);
1242
+ async function guardPage(page, resolve = systemResolver) {
1243
+ const verdicts = /* @__PURE__ */ new Map();
1244
+ const blocked = [];
1245
+ const verdictFor = (hostname) => {
1246
+ let verdict = verdicts.get(hostname);
1247
+ if (!verdict) {
1248
+ verdict = blockedHostReason(hostname, resolve);
1249
+ verdicts.set(hostname, verdict);
1250
+ }
1251
+ return verdict;
1252
+ };
1253
+ await page.setRequestInterception(true);
1254
+ page.on("request", (request) => {
1255
+ void (async () => {
1256
+ let reason;
1257
+ let host = "";
1258
+ try {
1259
+ const target = new URL(request.url());
1260
+ host = target.hostname;
1261
+ if (LOCAL_SCHEMES.has(target.protocol)) {
1262
+ reason = null;
1263
+ } else if (target.protocol === "http:" || target.protocol === "https:") {
1264
+ reason = await verdictFor(target.hostname);
1265
+ } else {
1266
+ reason = `the unsupported scheme ${target.protocol}`;
1267
+ }
1268
+ } catch {
1269
+ reason = "an address the guard could not check";
1270
+ }
1271
+ try {
1272
+ if (reason) {
1273
+ blocked.push({ url: request.url(), host, reason });
1274
+ await request.abort("blockedbyclient");
1275
+ } else {
1276
+ await request.continue();
1277
+ }
1278
+ } catch {
1279
+ }
1280
+ })();
1281
+ });
1282
+ return () => [...blocked];
1283
+ }
1284
+
1285
+ // src/core/browser-launch.ts
1286
+ init_cjs_shims();
1287
+ function puppeteerArgsFromEnv(env = process.env) {
1288
+ return (env.PUPPETEER_ARGS ?? "").split(/\s+/).filter(Boolean);
1289
+ }
1290
+ function sandboxRequested(policy, env = process.env) {
1291
+ return policy.sandbox !== false && !puppeteerArgsFromEnv(env).includes("--no-sandbox");
1292
+ }
1293
+ function chromeLaunchArgs(policy, env = process.env) {
1294
+ return [
1295
+ ...policy.sandbox === false ? ["--no-sandbox", "--disable-setuid-sandbox"] : [],
1296
+ ...policy.invalidHttpsCert ? ["--ignore-certificate-errors", "--allow-insecure-localhost"] : [],
1297
+ ...policy.extraArgs ?? [],
1298
+ ...puppeteerArgsFromEnv(env)
1299
+ ];
1300
+ }
1301
+ function explainLaunchFailure(error, policy, env = process.env) {
1302
+ const original = error instanceof Error ? error : new Error(String(error));
1303
+ if (!sandboxRequested(policy, env) || !/sandbox|user namespace|setuid|crbug\.com\/638180/i.test(original.message)) {
1304
+ return original;
1305
+ }
1306
+ const chromeSaid = original.message.split("\n").find((line) => /sandbox|namespace|setuid/i.test(line))?.trim() ?? original.message.split("\n")[0];
1307
+ return new Error(
1308
+ `Chrome could not start its sandbox. The sandbox is on by default because the engine renders third-party pages. Chrome cannot use it when running as root (for example in a container without a USER) or where unprivileged user namespaces are restricted (for example on Ubuntu 24.04 CI runners). Either run as a regular user in an environment that allows the sandbox, or disable it explicitly with --no-sandbox (library: sandbox: false, or PUPPETEER_ARGS="--no-sandbox"). Only disable it for pages you trust.
1309
+ Chrome said: ${chromeSaid}`
1310
+ );
1311
+ }
1312
+
1172
1313
  // src/core/regulatory-scanner.ts
1173
1314
  var import_node_fs = require("fs");
1174
1315
  function wcagTagToCriterion(tag) {
@@ -1228,7 +1369,7 @@ function isInterstitialPage(pageTitle, hasMetaRefresh, bodyTextLength) {
1228
1369
  return false;
1229
1370
  }
1230
1371
  function getEngineVersion() {
1231
- return "3.3.13";
1372
+ return "4.0.0";
1232
1373
  }
1233
1374
  function getStandardsVersion() {
1234
1375
  try {
@@ -1242,6 +1383,7 @@ function getStandardsVersion() {
1242
1383
  var SCAN_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
1243
1384
  var RegulatoryScanner = class {
1244
1385
  browser = null;
1386
+ blockedRequests = () => [];
1245
1387
  options;
1246
1388
  htmlValidator;
1247
1389
  constructor(options) {
@@ -1278,6 +1420,9 @@ var RegulatoryScanner = class {
1278
1420
  let interstitialSuspected;
1279
1421
  let passedCount = 0;
1280
1422
  try {
1423
+ if (!this.options.allowPrivateHosts) {
1424
+ await assertPublicHost(this.options.url);
1425
+ }
1281
1426
  await this.initBrowser();
1282
1427
  const page = await this.getPage();
1283
1428
  if (this.options.viewport) {
@@ -1292,6 +1437,10 @@ var RegulatoryScanner = class {
1292
1437
  });
1293
1438
  break;
1294
1439
  } catch (e) {
1440
+ const stopped = this.blockedRequests()[0];
1441
+ if (stopped && e instanceof Error && e.message.includes("ERR_BLOCKED_BY_CLIENT")) {
1442
+ throw new PrivateHostError(this.options.url, stopped.host, `${stopped.reason}, reached during navigation (for example through a redirect)`);
1443
+ }
1295
1444
  retries--;
1296
1445
  if (retries === 0) throw e;
1297
1446
  this.log(`Navigation failed, retrying... (${retries} attempts left)`);
@@ -1371,6 +1520,11 @@ var RegulatoryScanner = class {
1371
1520
  }
1372
1521
  const scanDuration = Date.now() - startTime;
1373
1522
  const result = this.generateResultPackage(allReports, passedCount, scanDuration, pageTitle, pageLanguage, interstitialSuspected);
1523
+ const blockedCount = this.blockedRequests().length;
1524
+ if (blockedCount > 0) {
1525
+ result.metadata.blockedPrivateRequests = blockedCount;
1526
+ this.log(`Sp\xE4rrade ${blockedCount} f\xF6rfr\xE5gningar till privata eller interna adresser (Intern #53).`);
1527
+ }
1374
1528
  if (result.complianceStatus !== "INCONCLUSIVE") {
1375
1529
  if (htmlValidation) {
1376
1530
  result.htmlValidation = htmlValidation;
@@ -1385,20 +1539,27 @@ var RegulatoryScanner = class {
1385
1539
  }
1386
1540
  }
1387
1541
  async initBrowser() {
1388
- this.browser = await import_puppeteer.default.launch({
1389
- headless: this.options.headless,
1390
- args: [
1391
- "--no-sandbox",
1392
- "--disable-setuid-sandbox",
1393
- "--disable-blink-features=AutomationControlled",
1394
- // Gömmer att det är en robot
1395
- ...this.options.invalidHttpsCert ? ["--ignore-certificate-errors", "--allow-insecure-localhost"] : []
1396
- ]
1397
- });
1542
+ const policy = {
1543
+ sandbox: this.options.sandbox,
1544
+ invalidHttpsCert: this.options.invalidHttpsCert,
1545
+ extraArgs: ["--disable-blink-features=AutomationControlled"]
1546
+ // Gömmer att det är en robot
1547
+ };
1548
+ try {
1549
+ this.browser = await import_puppeteer.default.launch({
1550
+ headless: this.options.headless,
1551
+ args: chromeLaunchArgs(policy)
1552
+ });
1553
+ } catch (e) {
1554
+ throw explainLaunchFailure(e, policy);
1555
+ }
1398
1556
  }
1399
1557
  async getPage() {
1400
1558
  if (!this.browser) throw new Error("Browser not initialized");
1401
1559
  const page = await this.browser.newPage();
1560
+ if (!this.options.allowPrivateHosts) {
1561
+ this.blockedRequests = await guardPage(page);
1562
+ }
1402
1563
  await page.setUserAgent(SCAN_USER_AGENT);
1403
1564
  return page;
1404
1565
  }
@@ -1425,7 +1586,11 @@ var RegulatoryScanner = class {
1425
1586
  // vi skulle mäta två olika sidor, inte JS-effekten.
1426
1587
  url: this.options.url,
1427
1588
  userAgent: SCAN_USER_AGENT,
1428
- viewport: this.options.viewport
1589
+ viewport: this.options.viewport,
1590
+ // Sondens sida får samma spärr som huvudsidan.
1591
+ preparePage: this.options.allowPrivateHosts ? void 0 : async (probePage) => {
1592
+ await guardPage(probePage);
1593
+ }
1429
1594
  });
1430
1595
  return evaluateNoScriptCoverage(
1431
1596
  measurement.textLength,
@@ -1848,7 +2013,7 @@ var import_react = __toESM(require("react"));
1848
2013
  var import_server = require("react-dom/server");
1849
2014
  var import_components = require("@holmdigital/components");
1850
2015
  var import_standards = require("@holmdigital/standards");
1851
- var import_promises = __toESM(require("fs/promises"));
2016
+ var import_promises2 = __toESM(require("fs/promises"));
1852
2017
  var import_path = __toESM(require("path"));
1853
2018
 
1854
2019
  // src/reporting/badge-generator.ts
@@ -1925,65 +2090,46 @@ var RESPONSE_TIME_DEFAULT = {
1925
2090
  "en-ca": "2 days",
1926
2091
  "en-au": "2 days"
1927
2092
  };
1928
- var NATIONAL_LAW_FALLBACK = {
1929
- en: "applicable accessibility requirements",
1930
- sv: "g\xE4llande tillg\xE4nglighetskrav",
1931
- no: "gjeldende tilgjengelighetskrav",
1932
- da: "g\xE6ldende tilg\xE6ngelighedskrav",
1933
- fi: "sovellettavat saavutettavuusvaatimukset",
1934
- de: "die geltenden Barrierefreiheitsanforderungen",
1935
- nl: "de geldende toegankelijkheidseisen",
1936
- fr: "la r\xE9glementation d'accessibilit\xE9 applicable",
1937
- es: "los requisitos de accesibilidad aplicables",
1938
- it: "i requisiti di accessibilit\xE0 applicabili",
1939
- pt: "os requisitos de acessibilidade aplic\xE1veis",
1940
- pl: "obowi\u0105zuj\u0105ce wymagania dost\u0119pno\u015Bci"
1941
- };
1942
- function resolveNationalLawReference(country, sector, lang = "en") {
1943
- const inForce = (law2) => !!law2 && law2.inForce !== false;
1944
- if (country === "AU") {
1945
- const ddaLaw = (0, import_standards.getNationalLaws)("AU").find((l) => l.euFramework === "DDA" && inForce(l));
1946
- return ddaLaw ? `${ddaLaw.fullName}` : "Disability Discrimination Act 1992 (Cth)";
1947
- }
1948
- if (country === "US") {
1949
- const usLaws = (0, import_standards.getNationalLaws)("US").filter(inForce);
1950
- const adaLaw = usLaws.find((l) => l.euFramework === "ADA" && l.scope === sector);
1951
- if (adaLaw) {
1952
- if (sector === "public") {
1953
- const s508 = usLaws.find((l) => l.id === "us-508");
1954
- return s508 ? `${adaLaw.fullName} (${adaLaw.law}) & ${s508.fullName} (${s508.law})` : `${adaLaw.fullName} (${adaLaw.law})`;
1955
- }
1956
- const hhs504 = usLaws.find((l) => l.euFramework === "REHAB" && l.scope === "private");
1957
- return hhs504 ? `${adaLaw.fullName} (${adaLaw.law}) & ${hhs504.fullName} (${hhs504.law})` : `${adaLaw.fullName} (${adaLaw.law})`;
1958
- }
1959
- }
1960
- const law = (0, import_standards.getNationalLawForSector)(country, sector);
1961
- if (law) {
1962
- const shortName = law.law.trim();
1963
- const longName = law.fullName.trim();
1964
- const redundant = longName === shortName || longName.startsWith(shortName);
1965
- return redundant ? longName : `${longName} (${shortName})`;
1966
- }
1967
- const langKey = lang.split("-")[0];
1968
- return NATIONAL_LAW_FALLBACK[langKey] ?? NATIONAL_LAW_FALLBACK.en;
2093
+ var REVIEWER_PLACEHOLDERS = [
2094
+ "{<extern akt\xF6r>}",
2095
+ "{<ekstern akt\xF8r>}",
2096
+ "{<ekstern aktor>}",
2097
+ "{<ulkoinen taho>}",
2098
+ "{<externe partij>}",
2099
+ "{<externer Dritter>}",
2100
+ "{<tiers externe>}",
2101
+ "{<tercero externo>}",
2102
+ "{<terza parte>}",
2103
+ "{<terceiro externo>}",
2104
+ "{<podmiot zewn\u0119trzny>}",
2105
+ "{<third party>}"
2106
+ ];
2107
+ function resolveSwedishEnforcementContent(enforcementBody, nationalLaw) {
2108
+ return `${enforcementBody} har ansvaret f\xF6r tillsyn \xF6ver ${nationalLaw}. Du kan anm\xE4la till ${enforcementBody} om du tycker att v\xE5r digitala service har brister i tillg\xE4nglighet.
2109
+
2110
+ Du kan ocks\xE5 anm\xE4la till ${enforcementBody} om du tycker att v\xE5r bed\xF6mning av vad som \xE4r osk\xE4ligt betungande ska granskas, om du tycker att v\xE5r tillg\xE4nglighetsredog\xF6relse har brister eller om du tycker att vi inte har hanterat din beg\xE4ran om tillg\xE4ngligg\xF6rande korrekt.
2111
+
2112
+ Du kan anm\xE4la direkt till Digg via tj\xE4nsten f\xF6r anm\xE4lan om bristande tillg\xE4nglighet: https://www.digg.se/tdosanmalan`;
1969
2113
  }
1970
2114
  async function generateStatementContent(result, lang = "en", format = "html", metadata) {
2115
+ const reviewMethod = metadata?.reviewMethod;
2116
+ const reviewerName = typeof metadata?.reviewer?.name === "string" ? metadata.reviewer.name.trim() : "";
2117
+ if (reviewMethod === "external-review" && reviewerName === "") {
2118
+ throw new Error(
2119
+ "reviewMethod 'external-review' requires metadata.reviewer with a non-empty name: the organisation that performed the review, e.g. { reviewMethod: 'external-review', reviewer: { name: 'Example Audit AB' } }. The statement names it as the reviewer. Use 'self-assessment' (the default) if the statement is based on your own testing, such as this scan."
2120
+ );
2121
+ }
1971
2122
  const templatePath = import_path.default.join(__dirname, "templates", `${lang}.json`);
1972
2123
  let template;
1973
2124
  try {
1974
- const data = await import_promises.default.readFile(templatePath, "utf-8");
2125
+ const data = await import_promises2.default.readFile(templatePath, "utf-8");
1975
2126
  template = JSON.parse(data);
1976
2127
  } catch {
1977
2128
  throw new Error(
1978
2129
  `Accessibility statement template not found for locale "${lang}". Expected file at: ${templatePath}`
1979
2130
  );
1980
2131
  }
1981
- let complianceLevel = "full";
1982
- if (result.stats.critical > 0 || result.legalSummary && result.legalSummary.eaaDeadlineViolations > 0) {
1983
- complianceLevel = "non-compliant";
1984
- } else if (result.score < 100) {
1985
- complianceLevel = "partial";
1986
- }
2132
+ const complianceLevel = "partial";
1987
2133
  const issuesMap = /* @__PURE__ */ new Map();
1988
2134
  violationsOf(result.reports).forEach((report) => {
1989
2135
  if (!issuesMap.has(report.ruleId)) {
@@ -2032,7 +2178,7 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2032
2178
  ];
2033
2179
  for (const p of possiblePaths) {
2034
2180
  try {
2035
- const logoBuffer = await import_promises.default.readFile(p);
2181
+ const logoBuffer = await import_promises2.default.readFile(p);
2036
2182
  logoUrl = `data:image/jpeg;base64,${logoBuffer.toString("base64")}`;
2037
2183
  break;
2038
2184
  } catch {
@@ -2054,6 +2200,10 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2054
2200
  name: "HolmDigital Regulatory Engine",
2055
2201
  url: "https://holmdigital.se"
2056
2202
  },
2203
+ // Intern #95: HTML-utlåtandet renderas av komponenten, så metodvalet och
2204
+ // granskaren måste följa med dit. Annars gäller valet bara Markdown.
2205
+ reviewMethod,
2206
+ reviewer: metadata?.reviewer,
2057
2207
  logoUrl,
2058
2208
  // Placeholders make it obvious the consumer must supply real contact info.
2059
2209
  // Previous fallback leaked HolmDigital's own contact details into customer statements.
@@ -2146,15 +2296,10 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2146
2296
  "{<m\xE9thode>}": props.evaluationMethod || "Automated Scan",
2147
2297
  "{<m\xE9todo>}": props.evaluationMethod || "Automated Scan",
2148
2298
  "{<method>}": props.evaluationMethod || "Automated Scan",
2149
- "{<extern akt\xF6r>}": props.generatorTool?.name || "HolmDigital Engine",
2150
- "{<ekstern akt\xF8r>}": props.generatorTool?.name || "HolmDigital Engine",
2151
- "{<ekstern aktor>}": props.generatorTool?.name || "HolmDigital Engine",
2152
- "{<ulkoinen taho>}": props.generatorTool?.name || "HolmDigital Engine",
2153
- "{<externe partij>}": props.generatorTool?.name || "HolmDigital Engine",
2154
- "{<externer Dritter>}": props.generatorTool?.name || "HolmDigital Engine",
2155
- "{<tiers externe>}": props.generatorTool?.name || "HolmDigital Engine",
2156
- "{<tercero externo>}": props.generatorTool?.name || "HolmDigital Engine",
2157
- "{<third party>}": props.generatorTool?.name || "HolmDigital Engine",
2299
+ // Intern #95: granskarens plats fylls bara ur reviewer, aldrig ur
2300
+ // generatorTool. Den renderas bara när metodvalet är en uttalad
2301
+ // extern granskning, och då är namnet kontrollerat ovan.
2302
+ ...Object.fromEntries(REVIEWER_PLACEHOLDERS.map((p) => [p, reviewerName])),
2158
2303
  "{<enforcement_body>}": (() => {
2159
2304
  if (country === "US") {
2160
2305
  const adaLaw = (0, import_standards.getNationalLaws)("US").find((l) => l.euFramework === "ADA" && l.scope === sector && l.inForce !== false);
@@ -2162,7 +2307,7 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2162
2307
  }
2163
2308
  return (0, import_standards.getEnforcementBody)(country, sector);
2164
2309
  })(),
2165
- "{<national_law>}": resolveNationalLawReference(country, sector, lang),
2310
+ "{<national_law>}": (0, import_standards.resolveNationalLawReference)(country, sector, lang),
2166
2311
  "{<ahrc_url>}": "https://www.humanrights.gov.au/complaints",
2167
2312
  "{<brister>}": nonComplianceItems.length > 0 ? nonComplianceItems.map((item) => `* ${item}`).join("\n") : lang === "sv" ? "Inga k\xE4nda brister." : "No known issues.",
2168
2313
  "{<puutteet>}": nonComplianceItems.length > 0 ? nonComplianceItems.map((item) => `* ${item}`).join("\n") : lang === "fi" ? "Ei tiedossa olevia puutteita." : "No known issues.",
@@ -2176,7 +2321,17 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2176
2321
  "{<braki>}": nonComplianceItems.length > 0 ? nonComplianceItems.map((item) => `* ${item}`).join("\n") : "Brak znanych problem\xF3w.",
2177
2322
  "{<issues>}": nonComplianceItems.length > 0 ? nonComplianceItems.map((item) => `* ${item}`).join("\n") : "No known issues."
2178
2323
  };
2179
- const processText = (text) => {
2324
+ const choiceIndex = (kind, parts) => {
2325
+ if (kind === "method") {
2326
+ if (reviewMethod === "external-review") return 1;
2327
+ if (reviewMethod === "no-review") return parts > 2 ? 2 : 1;
2328
+ return 0;
2329
+ }
2330
+ if (complianceLevel === "partial") return 1;
2331
+ if (complianceLevel === "non-compliant") return parts > 2 ? 2 : 1;
2332
+ return 0;
2333
+ };
2334
+ const processText = (text, kind = "compliance") => {
2180
2335
  let processed = text;
2181
2336
  processed = processed.replace(/\[([\s\S]*?)\]/g, (_match, content2) => {
2182
2337
  if (content2.includes("{<svarstid>}") || content2.includes("{<svartid>}") || content2.includes("{<response time>}")) {
@@ -2190,27 +2345,28 @@ async function generateStatementContent(result, lang = "en", format = "html", me
2190
2345
  }
2191
2346
  return content2;
2192
2347
  });
2348
+ const values = [];
2193
2349
  processed = processed.replace(/\{<[^>]+>\}/g, (match) => {
2194
- return substitutions[match] !== void 0 ? substitutions[match] : match;
2350
+ values.push(substitutions[match] !== void 0 ? substitutions[match] : match);
2351
+ return `\uE000${values.length - 1}\uE000`;
2195
2352
  });
2196
2353
  processed = processed.replace(/\{([^{}]*?)\}/g, (_match, content2) => {
2197
2354
  const parts = content2.split("/");
2198
2355
  if (parts.length >= 2) {
2199
- let idx = 0;
2200
- if (complianceLevel === "partial") idx = 1;
2201
- if (complianceLevel === "non-compliant") idx = parts.length > 2 ? 2 : 1;
2202
- return parts[idx].trim();
2356
+ return parts[choiceIndex(kind, parts.length)].trim();
2203
2357
  }
2204
2358
  return _match;
2205
2359
  });
2206
- return processed;
2360
+ return processed.replace(/\uE000(\d+)\uE000/g, (_m, i) => values[Number(i)]);
2207
2361
  };
2208
2362
  const title = processText(template.title);
2209
2363
  const intro = processText(template.intro);
2210
2364
  const enforcementBody = String(substitutions["{<enforcement_body>}"] ?? "").trim();
2211
2365
  const sections = template.sections.map((s) => {
2212
2366
  if (s.id === "enforcement" && enforcementBody === "") return null;
2213
- const body = processText(s.content).trim();
2367
+ if (s.sectors && !s.sectors.includes(sector)) return null;
2368
+ const delad = s.id === "enforcement" ? (0, import_standards.getEnforcementStatementText)(country, sector, lang) : null;
2369
+ const body = (delad ?? (s.id === "enforcement" && country === "SE" && lang === "sv" && sector === "public" ? resolveSwedishEnforcementContent(enforcementBody, substitutions["{<national_law>}"] ?? "") : processText(s.content, s.id === "testing" ? "method" : "compliance"))).trim();
2214
2370
  if (body === "") return null;
2215
2371
  return s.title ? `## ${s.title}
2216
2372
 
@@ -2230,8 +2386,8 @@ Generated using [${props.generatorTool?.name || "HolmDigital Engine"}](${props.g
2230
2386
  async function generateStatement(result, outputPath, lang = "en", format = "html", metadata) {
2231
2387
  const content = await generateStatementContent(result, lang, format, metadata);
2232
2388
  const dir = import_path.default.dirname(outputPath);
2233
- await import_promises.default.mkdir(dir, { recursive: true });
2234
- await import_promises.default.writeFile(outputPath, content, "utf-8");
2389
+ await import_promises2.default.mkdir(dir, { recursive: true });
2390
+ await import_promises2.default.writeFile(outputPath, content, "utf-8");
2235
2391
  }
2236
2392
  // Annotate the CommonJS export names for ESM import in node:
2237
2393
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  resolveNationalLawReference,
18
18
  selectMappedRuleId,
19
19
  wcagTagToCriterion
20
- } from "./chunk-UWT7ZJVZ.mjs";
20
+ } from "./chunk-6NKLALDW.mjs";
21
21
  import {
22
22
  getCurrentLang,
23
23
  setLanguage,
@@ -3,7 +3,7 @@ import {
3
3
  impactBreakdown,
4
4
  klarsprakLegalLine,
5
5
  languageDisplayName
6
- } from "./chunk-W2H46SI5.mjs";
6
+ } from "./chunk-M6ATPKNB.mjs";
7
7
  import {
8
8
  getCurrentLang,
9
9
  setLanguage,
@@ -20,12 +20,12 @@
20
20
  {
21
21
  "id": "enforcement",
22
22
  "title": "Durchsetzungsverfahren",
23
- "content": "Die {<enforcement_body>} ist für die Überwachung der Anforderungen gemäß {<national_law>} zuständig. Wenn Sie auf unsere Benachrichtigungen oder Anfragen keine zufriedenstellende Antwort erhalten haben, können Sie sich an {<enforcement_body>} wenden.\n\nSie können auch eine Beschwerde bei {<enforcement_body>} einreichen, wenn Sie der Meinung sind, dass unsere Einschätzung einer unverhältnismäßigen Belastung überprüft werden sollte, wenn Sie Mängel in unserer Barrierefreiheitserklärung feststellen oder wenn Sie der Meinung sind, dass wir Ihren Antrag auf barrierefreie Bereitstellung von Inhalten nicht korrekt bearbeitet haben."
23
+ "content": "Die {<enforcement_body>} ist für die Überwachung der Einhaltung von {<national_law>} zuständig. Wenn Sie auf unsere Benachrichtigungen oder Anfragen keine zufriedenstellende Antwort erhalten haben, können Sie sich an {<enforcement_body>} wenden.\n\nSie können auch eine Beschwerde bei {<enforcement_body>} einreichen, wenn Sie der Meinung sind, dass unsere Einschätzung einer unverhältnismäßigen Belastung überprüft werden sollte, wenn Sie Mängel in unserer Barrierefreiheitserklärung feststellen oder wenn Sie der Meinung sind, dass wir Ihren Antrag auf barrierefreie Bereitstellung von Inhalten nicht korrekt bearbeitet haben."
24
24
  },
25
25
  {
26
26
  "id": "technical",
27
27
  "title": "Technische Informationen zur Barrierefreiheit der Website",
28
- "content": "{Diese Website ist vollständig mit den Anforderungen gemäß {<national_law>} vereinbar./Diese Website ist wegen der folgenden Unvereinbarkeiten teilweise mit den Anforderungen gemäß {<national_law>} vereinbar./Diese Website ist nicht mit den Anforderungen gemäß {<national_law>} vereinbar.}"
28
+ "content": "{Diese Website ist vollständig mit {<national_law>} vereinbar./Diese Website ist wegen der folgenden Unvereinbarkeiten teilweise mit {<national_law>} vereinbar./Diese Website ist nicht mit {<national_law>} vereinbar.}"
29
29
  },
30
30
  {
31
31
  "id": "testing",
@@ -29,6 +29,7 @@
29
29
  },
30
30
  {
31
31
  "id": "dta-policy",
32
+ "sectors": ["public"],
32
33
  "title": "Australian Government digital policy",
33
34
  "content": "Federal government agencies are subject to the Digital Transformation Agency (DTA) Digital Experience Policy, which has included the Digital Inclusion Standard since 1 January 2025 for new services and 1 July 2025 for existing services. The Digital Inclusion Standard requires Commonwealth agencies to meet WCAG 2.2 Level AA.\n\nThis statement was prepared in accordance with best practice guidance from the DTA and the Australian Human Rights Commission (AHRC)."
34
35
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holmdigital/engine",
3
- "version": "3.3.13",
3
+ "version": "4.0.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -84,8 +84,8 @@
84
84
  "node": ">=22.22.0"
85
85
  },
86
86
  "dependencies": {
87
- "@holmdigital/components": "^4.0.2",
88
- "@holmdigital/standards": "^4.2.2",
87
+ "@holmdigital/components": "^4.2.0",
88
+ "@holmdigital/standards": "^5.0.0",
89
89
  "axe-core": "^4.13.0",
90
90
  "chalk": "^6.0.0",
91
91
  "commander": "^15.0.0",