@broberg/legal 0.8.1 → 0.10.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.cjs CHANGED
@@ -184,6 +184,8 @@ function moduleFacts(p) {
184
184
  if (!m.revenueShare.length || Math.abs(total - 100) > 1e-9) throw new Error(`product "${p.id}": revenueShare must add up to 100 %, got ${total}`);
185
185
  return m;
186
186
  }
187
+ var GOOGLE_USER_DATA_POLICY = "https://developers.google.com/terms/api-services-user-data-policy";
188
+ var googleLimitedUse = (name) => `${name}'s use and transfer to any other app of information received from Google APIs will adhere to the Google API Services User Data Policy (${GOOGLE_USER_DATA_POLICY}), including the Limited Use requirements.`;
187
189
  var FACT_TEMPLATES = {
188
190
  da: {
189
191
  hosting: (p, id) => [{ id, type: "table", head: ["Hvad", "Hvor"], rows: p.hosting.map((h) => [h.what, h.where]) }],
@@ -198,6 +200,10 @@ var FACT_TEMPLATES = {
198
200
  text: p.conversationAnalysis ? `${p.name} er omfattet af afsnittet om analyse af samtaler.` : `${p.name} er ikke omfattet af afsnittet om analyse af samtaler.`
199
201
  }
200
202
  ],
203
+ googleApiLimitedUse: (p, id) => p.googleApiLimitedUse ? [
204
+ { id, type: "p", text: `${p.name} henter oplysninger fra Googles API'er. Googles egen erkl\xE6ring om brugen g\xE6lder og st\xE5r her ordret:` },
205
+ { id: `${id}.statement`, type: "p", text: googleLimitedUse(p.name) }
206
+ ] : [],
201
207
  moduleTerms: (p, id) => {
202
208
  const m = moduleFacts(p);
203
209
  return [{
@@ -232,6 +238,10 @@ var FACT_TEMPLATES = {
232
238
  text: p.conversationAnalysis ? `${p.name} is covered by the section on conversation analysis.` : `${p.name} is not covered by the section on conversation analysis.`
233
239
  }
234
240
  ],
241
+ googleApiLimitedUse: (p, id) => p.googleApiLimitedUse ? [
242
+ { id, type: "p", text: `${p.name} receives information from Google APIs. Google's own statement on that use applies, verbatim:` },
243
+ { id: `${id}.statement`, type: "p", text: googleLimitedUse(p.name) }
244
+ ] : [],
235
245
  moduleTerms: (p, id) => {
236
246
  const m = moduleFacts(p);
237
247
  return [{
@@ -483,6 +493,7 @@ var PRIVACY_DA = {
483
493
  blocks: [
484
494
  { id: "deling.p1", type: "p", text: "Vi s\xE6lger aldrig data. Vi bruger disse databehandlere, som kun m\xE5 behandle oplysningerne efter vores instruks:" },
485
495
  { id: "deling.facts", type: "facts", fact: "subprocessors" },
496
+ { id: "deling.google", type: "facts", fact: "googleApiLimitedUse" },
486
497
  { id: "deling.p2", type: "p", text: "Overf\xF8rsel uden for EU sker kun med et gyldigt overf\xF8rselsgrundlag, fx EU-Kommissionens standardkontraktbestemmelser eller EU-US Data Privacy Framework." }
487
498
  ]
488
499
  },
@@ -1001,7 +1012,7 @@ var PRIVACY_EN = {
1001
1012
  effectiveFrom: "2026-11-02",
1002
1013
  material: false,
1003
1014
  draft: false,
1004
- translationOf: { version: "2026-11-02", sourceHash: "28f73420bd8c7fa77d22b17063746e4b71c03e4395be78fdb69100bc6282c4fe" },
1015
+ translationOf: { version: "2026-11-02", sourceHash: "c30a33c005888cd3dbbe62c462235fa31487f2b51821450ecb52e462578ddac6" },
1005
1016
  sections: [
1006
1017
  {
1007
1018
  id: "dataansvarlig",
@@ -1084,6 +1095,7 @@ var PRIVACY_EN = {
1084
1095
  blocks: [
1085
1096
  { id: "deling.p1", type: "p", text: "We never sell data. We use these processors, which may only process the information on our instructions:" },
1086
1097
  { id: "deling.facts", type: "facts", fact: "subprocessors" },
1098
+ { id: "deling.google", type: "facts", fact: "googleApiLimitedUse" },
1087
1099
  { id: "deling.p2", type: "p", text: "Transfers outside the EU only take place with a valid transfer mechanism, e.g. the European Commission's standard contractual clauses or the EU-US Data Privacy Framework." }
1088
1100
  ]
1089
1101
  },
@@ -1561,6 +1573,37 @@ function renderHtml(doc) {
1561
1573
  return `<article class="legal" lang="${doc.locale}" data-legal-doc="${doc.doc}" data-legal-version="${esc(doc.version)}" data-legal-hash="${doc.contentHash}"><h1>${esc(doc.title)}</h1>${draft}${doc.sections.map((s) => `<section data-legal-id="${esc(s.id)}"><h2>${esc(s.heading)}</h2>${s.blocks.map(block).join("")}</section>`).join("")}</article>`;
1562
1574
  }
1563
1575
 
1576
+ // src/fill.ts
1577
+ var KNOWN2 = new Set(PLACEHOLDERS);
1578
+ var RE = /\{([a-zA-Z.]+)\}/g;
1579
+ function fillPlaceholders(doc, values) {
1580
+ const unknown = Object.keys(values).filter((k) => !KNOWN2.has(k));
1581
+ if (unknown.length) throw new Error(`unknown placeholder value(s): ${unknown.join(", ")}`);
1582
+ const missing = doc.placeholders.filter((p) => typeof values[p] !== "string" || values[p].trim() === "");
1583
+ if (missing.length) throw new Error(`missing or empty placeholder value(s): ${missing.join(", ")}`);
1584
+ const fill = (s) => s.replace(RE, (whole, name) => KNOWN2.has(name) && values[name] !== void 0 ? values[name] : whole);
1585
+ const block2 = (b) => b.type === "list" ? { ...b, items: b.items.map(fill) } : b.type === "table" ? { ...b, head: b.head.map(fill), rows: b.rows.map((r) => r.map(fill)) } : { ...b, text: fill(b.text) };
1586
+ const { contentHash: _old, ...rest } = doc;
1587
+ const body = { ...rest, title: fill(doc.title), sections: doc.sections.map((s) => ({ ...s, heading: fill(s.heading), blocks: s.blocks.map(block2) })), placeholders: [] };
1588
+ return { ...body, contentHash: sha256Hex(canonicalJson(body)) };
1589
+ }
1590
+ function renderText(doc) {
1591
+ const out = [doc.title, ""];
1592
+ for (const s of doc.sections) {
1593
+ out.push(s.heading);
1594
+ for (const b of s.blocks) {
1595
+ if (b.type === "list") out.push(...b.items.map((i) => `- ${i}`));
1596
+ else if (b.type === "table") out.push(b.head.join(" | "), ...b.rows.map((r) => r.join(" | ")));
1597
+ else out.push(b.text);
1598
+ }
1599
+ out.push("");
1600
+ }
1601
+ return out.join("\n");
1602
+ }
1603
+ function textHash(text) {
1604
+ return `sha256:${sha256Hex(text)}`;
1605
+ }
1606
+
1564
1607
  // src/content/example.ts
1565
1608
  var EXAMPLE_FACTS = {
1566
1609
  id: "example",
@@ -1637,6 +1680,7 @@ function createLegalCache(opts) {
1637
1680
 
1638
1681
  // src/bid.ts
1639
1682
  var BID_URL = "https://id.broberg.ai";
1683
+ var MAX_ACCEPTED_TEXT = 2e5;
1640
1684
  var BidConsentError = class extends Error {
1641
1685
  constructor(status, code, message) {
1642
1686
  super(message);
@@ -1669,8 +1713,14 @@ async function call(opts, method, path, body) {
1669
1713
  }
1670
1714
  async function recordAcceptance(opts, a) {
1671
1715
  const sent = { doc: a.doc, version: a.version, contentHash: toBidHash(a.contentHash) };
1716
+ if (a.text !== void 0) {
1717
+ if (a.text.length > MAX_ACCEPTED_TEXT) throw new BidConsentError(0, "text_too_long", `the accepted text is ${a.text.length} characters; BID takes at most ${MAX_ACCEPTED_TEXT}`);
1718
+ if (textHash(a.text) !== sent.contentHash) throw new BidConsentError(0, "hash_mismatch", "contentHash is not textHash(text) \u2014 the hash must be over exactly the text the person saw");
1719
+ sent.text = a.text;
1720
+ }
1721
+ if (a.authorityConfirmed !== void 0) sent.authorityConfirmed = a.authorityConfirmed;
1672
1722
  const row = await call(opts, "POST", "/api/app/terms-acceptance", sent);
1673
- if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
1723
+ if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash || a.authorityConfirmed !== void 0 && row?.authorityConfirmed !== a.authorityConfirmed) {
1674
1724
  throw new BidConsentError(200, "not_echoed", "BID's stored acceptance does not match what was sent");
1675
1725
  }
1676
1726
  return row;
@@ -1735,11 +1785,13 @@ exports.DOC_IDS = DOC_IDS;
1735
1785
  exports.EXAMPLE_FACTS = EXAMPLE_FACTS;
1736
1786
  exports.LEGAL_API_URL = LEGAL_API_URL;
1737
1787
  exports.MASTER_LOCALE = MASTER_LOCALE;
1788
+ exports.MAX_ACCEPTED_TEXT = MAX_ACCEPTED_TEXT;
1738
1789
  exports.PLACEHOLDERS = PLACEHOLDERS;
1739
1790
  exports.SOURCES = SOURCES;
1740
1791
  exports.canonicalJson = canonicalJson;
1741
1792
  exports.createLegalCache = createLegalCache;
1742
1793
  exports.createLibrary = createLibrary;
1794
+ exports.fillPlaceholders = fillPlaceholders;
1743
1795
  exports.getAcceptance = getAcceptance;
1744
1796
  exports.getConsent = getConsent;
1745
1797
  exports.getDocument = getDocument;
@@ -1751,10 +1803,12 @@ exports.placeholdersIn = placeholdersIn;
1751
1803
  exports.recordAcceptance = recordAcceptance;
1752
1804
  exports.recordConsent = recordConsent;
1753
1805
  exports.renderHtml = renderHtml;
1806
+ exports.renderText = renderText;
1754
1807
  exports.resolveTemplate = resolveTemplate;
1755
1808
  exports.sha256Hex = sha256Hex;
1756
1809
  exports.sourceHash = sourceHash;
1757
1810
  exports.templateHash = templateHash;
1811
+ exports.textHash = textHash;
1758
1812
  exports.toBidHash = toBidHash;
1759
1813
  exports.verifyTemplate = verifyTemplate;
1760
1814
  //# sourceMappingURL=index.cjs.map