@broberg/legal 0.1.0 → 0.3.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/README.md +150 -17
- package/dist/index.cjs +120 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -20
- package/dist/index.d.ts +62 -20
- package/dist/index.js +112 -109
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,26 +1,159 @@
|
|
|
1
1
|
# @broberg/legal
|
|
2
2
|
|
|
3
|
-
**Status: 0.
|
|
3
|
+
**Status: 0.3.0. Every document is a DRAFT (`draft: true`, rendered as «UDKAST») until the owner's lawyer has reviewed it (F110.3).**
|
|
4
4
|
|
|
5
|
-
One set of legal documents for every broberg.ai product
|
|
6
|
-
`support
|
|
7
|
-
|
|
5
|
+
One set of legal documents for every broberg.ai product: `terms`, `privacy`, `trust`, `dpa` and
|
|
6
|
+
`support`. The text is the same everywhere. Danish is the master and prevails; English sits beside it.
|
|
7
|
+
**components writes the text; each product fills in its OWN facts and shows the documents on its OWN
|
|
8
|
+
site.** legal.broberg.ai is an API, not a website: anything there that is not the API sends visitors
|
|
9
|
+
to broberg.ai.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## MUST: how a product shows its legal documents
|
|
14
|
+
|
|
15
|
+
Every product with a visible service shows these documents and never writes its own (owner decision
|
|
16
|
+
D-7effa0). This is a fixed onboarding step for every new project (the TERMS/GDPR card). Six steps:
|
|
17
|
+
|
|
18
|
+
### 1. Write your product's facts, once, in YOUR repo
|
|
19
|
+
|
|
20
|
+
The texts have open slots (`facts` blocks) for what differs per product. You fill them with a
|
|
21
|
+
`ProductFacts` object kept in your own repo, for example `legal/facts.ts`:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import type { ProductFacts } from "@broberg/legal";
|
|
25
|
+
|
|
26
|
+
export const FACTS: ProductFacts = {
|
|
27
|
+
id: "jam", // your product id: lower-case, stable
|
|
28
|
+
name: "Jam", // the name users know
|
|
29
|
+
hosting: [ // where data is stored and processed
|
|
30
|
+
{ what: "Appen", where: "Stockholm, Sverige (EU)" },
|
|
31
|
+
{ what: "Databasen", where: "Amsterdam, Holland (EU)" },
|
|
32
|
+
],
|
|
33
|
+
dataCategories: [ // what personal data you hold
|
|
34
|
+
"Navn, e-mail og profilbillede fra login",
|
|
35
|
+
"Dit indhold, som du selv gemmer",
|
|
36
|
+
],
|
|
37
|
+
subprocessors: [ // every vendor that touches personal data
|
|
38
|
+
{ name: "Fly.io", purpose: "Drift af app og database", location: "Sverige og Holland", transfer: "Databehandleraftale med EU-standardkontrakter" },
|
|
39
|
+
],
|
|
40
|
+
conversationAnalysis: true, // does the four-part conversation analysis apply?
|
|
41
|
+
healthData: false, // health data (GDPR art. 9)? physio apps: read docs/guides/health-data-physio.md
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- List only facts that are TRUE today. If you are unsure, leave it out and ask; never guess.
|
|
46
|
+
- Facts are data, never prose. Do not type a vendor name or an exception into the text. The package
|
|
47
|
+
turns your facts into tables and sentences through fixed templates.
|
|
48
|
+
- The facts change when your product changes (a new vendor, a new region). Update the file in the
|
|
49
|
+
same change.
|
|
50
|
+
- **Prove your facts with a test (recommended; jam does this):** for every vendor in `subprocessors`,
|
|
51
|
+
require evidence in your code, such as an import (`/mistral/i`), an env key (`R2_ACCESS_KEY_ID`) or
|
|
52
|
+
`primary_region` in fly.toml. Then the facts cannot promise a vendor you do not use, and adding a new
|
|
53
|
+
integration fails the test until the facts file says so too.
|
|
54
|
+
|
|
55
|
+
### 2. Get the texts: the npm package (recommended for JS/TS)
|
|
8
56
|
|
|
9
57
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
58
|
+
import { getDocument, renderHtml } from "@broberg/legal"; // pin an exact version
|
|
59
|
+
import { FACTS } from "./legal/facts";
|
|
60
|
+
|
|
61
|
+
const doc = getDocument({ doc: "privacy", locale: "da", facts: FACTS });
|
|
62
|
+
doc.title; doc.version; doc.effectiveFrom; doc.draft; doc.contentHash;
|
|
63
|
+
renderHtml(doc); // semantic HTML with data-legal-id on every section and block; style it yourself
|
|
14
64
|
```
|
|
15
65
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
66
|
+
The texts ship **inside** the package, so your site needs no network for them and cannot lose them
|
|
67
|
+
when legal.broberg.ai is down. New texts reach you as a new package version; components sends a
|
|
68
|
+
release report saying whether the wording changed.
|
|
69
|
+
|
|
70
|
+
**Want new texts without redeploying? (recommended for a running server; ported from jam)**
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createLegalCache } from "@broberg/legal";
|
|
74
|
+
const legal = createLegalCache({ facts: FACTS }); // once, at start
|
|
75
|
+
const doc = legal.get("privacy", "da"); // on every page view: never waits, never fails
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`get` answers at once from the latest good template, starting with the one bundled in the package.
|
|
79
|
+
At most once a day per document it checks the API in the background (`If-None-Match`). It swaps in
|
|
80
|
+
a newer template only if that template verifies AND resolves with your facts. Any failure keeps
|
|
81
|
+
the old one. The cache lives in memory, so a restart starts again from the bundled texts.
|
|
82
|
+
|
|
83
|
+
### 3. Or get them over HTTP (any stack)
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
GET https://legal.broberg.ai/v1/documents → { documents: [{ doc, locale, version, effectiveFrom, draft, hash }] }
|
|
87
|
+
GET https://legal.broberg.ai/v1/{doc}.{da|en}.json → the template: sections with facts slots open, + version, draft, stale, hash
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Fill the slots with your facts: in JS/TS, `resolveTemplate(template, FACTS)` from this package. In
|
|
91
|
+
another language, render each `facts` block like this: `hosting` is a table (What | Where);
|
|
92
|
+
`dataCategories` is a list; `subprocessors` is a table (Vendor | Used for | Where | Transfer);
|
|
93
|
+
`conversationAnalysis` is one sentence saying whether your product is covered by the section on
|
|
94
|
+
conversation analysis. A missing English translation falls back to Danish; `stale: true` means the
|
|
95
|
+
English text is older than the Danish one, so show the Danish one or a notice.
|
|
96
|
+
|
|
97
|
+
### 4. Cache: keep your own copy, and only fetch a new edition when there is one (HTTP route)
|
|
98
|
+
|
|
99
|
+
Your terms page must never go down because legal.broberg.ai is down or being updated.
|
|
100
|
+
|
|
101
|
+
1. **Keep a snapshot in your repo or build** (`legal/snapshot/{doc}.{locale}.json`, the templates as
|
|
102
|
+
fetched). Your pages render from the snapshot. They never call the API on a page view.
|
|
103
|
+
2. **Check for a new edition at most once a day:** `GET /v1/documents` and compare each `hash` with
|
|
104
|
+
your snapshot's. Same hash means there is nothing to do.
|
|
105
|
+
3. **Only when a hash changed:** fetch that template and check it: in JS/TS with `verifyTemplate(t)`,
|
|
106
|
+
and its `hash` must equal the one in the list. Then replace the snapshot file in one step (write to
|
|
107
|
+
a temp file, then rename). **Trap:** the hash covers the template WITHOUT the response's own
|
|
108
|
+
`stale` and `hash` fields. Recomputing it over the whole response never matches. Without the
|
|
109
|
+
package: drop those two fields, then take sha256 of the canonical JSON (keys sorted, no spaces).
|
|
110
|
+
4. **If anything fails** (timeout, 5xx, a check fails), keep the old snapshot, log it, and try again
|
|
111
|
+
tomorrow. Never empty a page because a fetch failed.
|
|
112
|
+
5. Every answer carries an `ETag` and `cache-control: public, max-age=86400`. A request with
|
|
113
|
+
`If-None-Match: "<hash>"` answers an empty `304` when nothing changed.
|
|
114
|
+
|
|
115
|
+
The service runs cold: the first call after a quiet spell takes a second or two. That is fine for a
|
|
116
|
+
daily check and one more reason never to call it on a page view.
|
|
117
|
+
|
|
118
|
+
### 5. Show the documents on YOUR site
|
|
119
|
+
|
|
120
|
+
- One page per document on your own domain, for example `/vilkaar`, `/privatliv`, `/tillid`.
|
|
121
|
+
`dpa` and `support` belong in customer contracts (Contract Manager fills `{customer.name}` and the
|
|
122
|
+
other placeholders); a public site shows `terms`, `privacy` and `trust`.
|
|
123
|
+
- Style and re-flow freely. **Never edit the text.** Drawing the blocks (`p`, `note`, `list`,
|
|
124
|
+
`table`) yourself in your own design instead of using `renderHtml` is fully fine, as long as the
|
|
125
|
+
text is verbatim. `renderHtml` is a convenience, not a requirement.
|
|
126
|
+
- Show the version and the «gælder fra» date (`version`, `effectiveFrom`). While `draft` is true, show
|
|
127
|
+
the «UDKAST» marker (`renderHtml` does it for you).
|
|
128
|
+
- Link all of them in your footer. **Never link users to legal.broberg.ai**; it redirects to broberg.ai.
|
|
129
|
+
|
|
130
|
+
### 6. Acceptance
|
|
131
|
+
|
|
132
|
+
Terms are accepted at sign-up with an **unticked** «Jeg accepterer vilkårene» checkbox; the privacy
|
|
133
|
+
policy is linked and shown, never "accepted". Store `{ doc, version, contentHash }` with the
|
|
134
|
+
acceptance, so "which text did they accept?" has an exact answer.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Reference
|
|
139
|
+
|
|
140
|
+
- `getDocument({ doc, locale, facts })`: a finished document from the bundled templates plus your facts.
|
|
141
|
+
- `getTemplate({ doc, locale })`: the template, as the API serves it. `listDocuments()`: what `/v1/documents` serves.
|
|
142
|
+
- `resolveTemplate(template, facts)`: a finished document from a template you fetched. It gives the
|
|
143
|
+
same `contentHash` as `getDocument` with the same facts.
|
|
144
|
+
- `renderHtml(document)`: semantic HTML. `EXAMPLE_FACTS`: a filled-in example.
|
|
145
|
+
- `createLegalCache({ facts, fetch?, refreshMs?, baseUrl?, onKeepOld? })` → `{ get(doc, locale), settled(doc, locale) }`.
|
|
146
|
+
- `verifyTemplate(t)`: true when a fetched template has sections and its hash matches its authored
|
|
147
|
+
content. `LEGAL_API_URL`: the API's address, in one place.
|
|
148
|
+
- **contentHash** = sha256 of the canonical JSON of the finished document; **hash** = the same for a template.
|
|
149
|
+
- **Placeholders** (`{customer.name}` and the rest) are a fixed list; an unknown one is refused.
|
|
24
150
|
- Zero dependencies (a built-in SHA-256, proven against FIPS vectors and node:crypto).
|
|
25
151
|
|
|
26
|
-
|
|
152
|
+
**0.3.0 (F110.15):** `createLegalCache` (ported from jam's F001.79), `verifyTemplate`, `LEGAL_API_URL`;
|
|
153
|
+
README §4 trap fixed. Additive; the texts are unchanged.
|
|
154
|
+
|
|
155
|
+
**0.2.0 (F110.14), breaking:** the fleet product registry and `library` are gone, and
|
|
156
|
+
`getDocument` takes `facts` instead of `product`. The per-product HTTP routes and the human pages are
|
|
157
|
+
gone too: legal.broberg.ai is an API.
|
|
158
|
+
|
|
159
|
+
Plan: `docs/features/F110-legal-documents.md`, `docs/features/F110.14-legal-is-an-api.md`.
|
package/dist/index.cjs
CHANGED
|
@@ -158,6 +158,9 @@ function canonicalJson(value) {
|
|
|
158
158
|
const obj = value;
|
|
159
159
|
return `{${Object.keys(obj).filter((k) => obj[k] !== void 0).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(",")}}`;
|
|
160
160
|
}
|
|
161
|
+
function templateHash(src) {
|
|
162
|
+
return sha256Hex(canonicalJson(src));
|
|
163
|
+
}
|
|
161
164
|
function sourceHash(src) {
|
|
162
165
|
return sha256Hex(canonicalJson({ doc: src.doc, version: src.version, sections: src.sections }));
|
|
163
166
|
}
|
|
@@ -241,112 +244,6 @@ function createLibrary(sources, products) {
|
|
|
241
244
|
return { getDocument: getDocument2, products: () => [...byProduct.keys()], sources: () => [...sources] };
|
|
242
245
|
}
|
|
243
246
|
|
|
244
|
-
// src/render.ts
|
|
245
|
-
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
246
|
-
function block(b) {
|
|
247
|
-
const id = ` data-legal-id="${esc(b.id)}"`;
|
|
248
|
-
switch (b.type) {
|
|
249
|
-
case "p":
|
|
250
|
-
return `<p${id}>${esc(b.text)}</p>`;
|
|
251
|
-
case "note":
|
|
252
|
-
return `<p class="legal-note"${id}>${esc(b.text)}</p>`;
|
|
253
|
-
case "list":
|
|
254
|
-
return `<ul${id}>${b.items.map((i) => `<li>${esc(i)}</li>`).join("")}</ul>`;
|
|
255
|
-
case "table":
|
|
256
|
-
return `<table${id}><thead><tr>${b.head.map((h) => `<th>${esc(h)}</th>`).join("")}</tr></thead><tbody>${b.rows.map((r) => `<tr>${r.map((c) => `<td>${esc(c)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function renderHtml(doc) {
|
|
260
|
-
const draft = doc.draft ? `<p class="legal-draft" data-legal-id="draft">${doc.locale === "da" ? "UDKAST \u2014 ikke g\xE6ldende endnu" : "DRAFT \u2014 not yet in force"}</p>` : "";
|
|
261
|
-
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>`;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/content/products.ts
|
|
265
|
-
var PRODUCTS = [
|
|
266
|
-
{
|
|
267
|
-
id: "default",
|
|
268
|
-
name: "broberg.ai",
|
|
269
|
-
hosting: [{ what: "Vores egne tjenester", where: "Stockholm, Sverige (EU)" }],
|
|
270
|
-
dataCategories: ["Navn", "E-mailadresse", "Indhold du selv indtaster", "Tekniske oplysninger (fx IP-adresse og tidspunkt)"],
|
|
271
|
-
subprocessors: [
|
|
272
|
-
{ name: "Fly.io", purpose: "Hosting af vores tjenester", location: "Stockholm, Sverige", transfer: "EU-US Data Privacy Framework" },
|
|
273
|
-
{ name: "Mistral AI", purpose: "AI-sprogmodeller", location: "Frankrig", transfer: "Inden for EU" },
|
|
274
|
-
{ name: "Resend", purpose: "Afsendelse af e-mail", location: "Irland", transfer: "Data Privacy Framework + standardkontrakt" }
|
|
275
|
-
],
|
|
276
|
-
conversationAnalysis: true,
|
|
277
|
-
healthData: false
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
id: "broberg-ai",
|
|
281
|
-
name: "broberg.ai",
|
|
282
|
-
hosting: [
|
|
283
|
-
{ what: "Websitet", where: "Stockholm, Sverige (EU)" },
|
|
284
|
-
{ what: "AI-assistenten Aidan", where: "Paris, Frankrig (EU)" }
|
|
285
|
-
],
|
|
286
|
-
dataCategories: [
|
|
287
|
-
"Navn og kontaktoplysninger, du selv oplyser",
|
|
288
|
-
"Indholdet af din henvendelse eller samtale med Aidan",
|
|
289
|
-
"Tekniske oplysninger (IP-adresse, tidspunkt, hentet side)",
|
|
290
|
-
"Anonym bes\xF8gsstatistik"
|
|
291
|
-
],
|
|
292
|
-
subprocessors: [
|
|
293
|
-
{ name: "broberg.ai HelpDesk", purpose: "Supportsystem", location: "Stockholm, Sverige", transfer: "Samme virksomhed" },
|
|
294
|
-
{ name: "Mistral AI", purpose: "Sprogmodellen bag Aidan", location: "Frankrig", transfer: "Inden for EU" },
|
|
295
|
-
{ name: "Resend", purpose: "Afsendelse af e-mail", location: "Irland", transfer: "Data Privacy Framework + standardkontrakt" },
|
|
296
|
-
{ name: "Cloudflare", purpose: "Robotv\xE6rn p\xE5 kontaktformularen", location: "EU / globalt", transfer: "Data Privacy Framework + standardkontrakt" },
|
|
297
|
-
{ name: "Fly.io", purpose: "Hosting af websitet", location: "Stockholm, Sverige", transfer: "EU-US Data Privacy Framework" },
|
|
298
|
-
{ name: "Upmetrics", purpose: "Driftsoverv\xE5gning og anonym bes\xF8gsstatistik", location: "Stockholm, Sverige", transfer: "Samme virksomhed" }
|
|
299
|
-
],
|
|
300
|
-
conversationAnalysis: true,
|
|
301
|
-
healthData: false
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
id: "jam",
|
|
305
|
-
name: "Jam",
|
|
306
|
-
hosting: [
|
|
307
|
-
{ what: "Appen", where: "Stockholm, Sverige (EU)" },
|
|
308
|
-
{ what: "Databasen", where: "Amsterdam, Holland (EU)" },
|
|
309
|
-
{ what: "Filer og billeder", where: "EU" },
|
|
310
|
-
{ what: "AI", where: "Paris, Frankrig (EU)" },
|
|
311
|
-
{ what: "Mail", where: "Irland (EU)" }
|
|
312
|
-
],
|
|
313
|
-
dataCategories: [
|
|
314
|
-
"Navn, e-mail og profilbillede fra login",
|
|
315
|
-
"Dit indhold: Jams, samlinger, sedler og klip du selv v\xE6lger at gemme",
|
|
316
|
-
"Medlemskaber og roller"
|
|
317
|
-
],
|
|
318
|
-
subprocessors: [
|
|
319
|
-
{ name: "Fly.io", purpose: "Drift af app, database og stemmeserver", location: "Sverige og Holland", transfer: "Databehandleraftale med EU-standardkontrakter" },
|
|
320
|
-
{ name: "Cloudflare", purpose: "Filer og billeder (R2)", location: "EU", transfer: "Databehandleraftale med EU-standardkontrakter" },
|
|
321
|
-
{ name: "Mistral AI", purpose: "AI p\xE5 tavlen", location: "Frankrig", transfer: "Inden for EU" },
|
|
322
|
-
{ name: "Resend", purpose: "Mail (invitationer, login-koder)", location: "Irland", transfer: "Databehandleraftale med EU-standardkontrakter" },
|
|
323
|
-
{ name: "Upmetrics", purpose: "Fejloverv\xE5gning", location: "Sverige", transfer: "Samme virksomhed" },
|
|
324
|
-
{ name: "BID", purpose: "Login", location: "Sverige", transfer: "Samme virksomhed" }
|
|
325
|
-
],
|
|
326
|
-
conversationAnalysis: true,
|
|
327
|
-
healthData: false
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
id: "fd-sundhed",
|
|
331
|
-
name: "FysioDanmark Aalborg",
|
|
332
|
-
hosting: [{ what: "Platformen", where: "Stockholm, Sverige (EU)" }],
|
|
333
|
-
dataCategories: [
|
|
334
|
-
"Navn og kontaktoplysninger",
|
|
335
|
-
"Oplysninger om dit forl\xF8b, som du eller din behandler registrerer",
|
|
336
|
-
"Helbredsoplysninger (s\xE6rlig kategori \u2014 se afsnittet om analyse)"
|
|
337
|
-
],
|
|
338
|
-
subprocessors: [
|
|
339
|
-
{ name: "Fly.io", purpose: "Hosting", location: "Stockholm, Sverige", transfer: "EU-US Data Privacy Framework" },
|
|
340
|
-
{ name: "Supabase", purpose: "Database og login", location: "Stockholm, Sverige", transfer: "EU's standardkontrakt" },
|
|
341
|
-
{ name: "Mistral AI", purpose: "AI-sprogmodeller", location: "Frankrig", transfer: "Inden for EU" },
|
|
342
|
-
{ name: "Resend", purpose: "Afsendelse af e-mail", location: "Irland", transfer: "Data Privacy Framework + standardkontrakt" },
|
|
343
|
-
{ name: "Upmetrics", purpose: "Fejloverv\xE5gning", location: "Stockholm, Sverige", transfer: "Samme virksomhed" }
|
|
344
|
-
],
|
|
345
|
-
conversationAnalysis: true,
|
|
346
|
-
healthData: true
|
|
347
|
-
}
|
|
348
|
-
];
|
|
349
|
-
|
|
350
247
|
// src/content/terms.da.ts
|
|
351
248
|
var TERMS_DA = {
|
|
352
249
|
doc: "terms",
|
|
@@ -807,23 +704,136 @@ var SUPPORT_DA = {
|
|
|
807
704
|
|
|
808
705
|
// src/content/index.ts
|
|
809
706
|
var SOURCES = [TERMS_DA, PRIVACY_DA, TRUST_DA, DPA_DA, SUPPORT_DA];
|
|
810
|
-
|
|
707
|
+
|
|
708
|
+
// src/render.ts
|
|
709
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
710
|
+
function block(b) {
|
|
711
|
+
const id = ` data-legal-id="${esc(b.id)}"`;
|
|
712
|
+
switch (b.type) {
|
|
713
|
+
case "p":
|
|
714
|
+
return `<p${id}>${esc(b.text)}</p>`;
|
|
715
|
+
case "note":
|
|
716
|
+
return `<p class="legal-note"${id}>${esc(b.text)}</p>`;
|
|
717
|
+
case "list":
|
|
718
|
+
return `<ul${id}>${b.items.map((i) => `<li>${esc(i)}</li>`).join("")}</ul>`;
|
|
719
|
+
case "table":
|
|
720
|
+
return `<table${id}><thead><tr>${b.head.map((h) => `<th>${esc(h)}</th>`).join("")}</tr></thead><tbody>${b.rows.map((r) => `<tr>${r.map((c) => `<td>${esc(c)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function renderHtml(doc) {
|
|
724
|
+
const draft = doc.draft ? `<p class="legal-draft" data-legal-id="draft">${doc.locale === "da" ? "UDKAST \u2014 ikke g\xE6ldende endnu" : "DRAFT \u2014 not yet in force"}</p>` : "";
|
|
725
|
+
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>`;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/content/example.ts
|
|
729
|
+
var EXAMPLE_FACTS = {
|
|
730
|
+
id: "example",
|
|
731
|
+
name: "Eksempel-produktet",
|
|
732
|
+
hosting: [{ what: "Vores egne tjenester", where: "Stockholm, Sverige (EU)" }],
|
|
733
|
+
dataCategories: ["Navn", "E-mailadresse", "Indhold du selv indtaster", "Tekniske oplysninger (fx IP-adresse og tidspunkt)"],
|
|
734
|
+
subprocessors: [
|
|
735
|
+
{ name: "Fly.io", purpose: "Hosting af vores tjenester", location: "Stockholm, Sverige", transfer: "EU-US Data Privacy Framework" },
|
|
736
|
+
{ name: "Mistral AI", purpose: "AI-sprogmodeller", location: "Frankrig", transfer: "Inden for EU" },
|
|
737
|
+
{ name: "Resend", purpose: "Afsendelse af e-mail", location: "Irland", transfer: "Data Privacy Framework + standardkontrakt" }
|
|
738
|
+
],
|
|
739
|
+
conversationAnalysis: true,
|
|
740
|
+
healthData: false
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// src/cache.ts
|
|
744
|
+
var LEGAL_API_URL = "https://legal.broberg.ai/v1";
|
|
745
|
+
var DEFAULT_REFRESH_MS = 24 * 60 * 60 * 1e3;
|
|
746
|
+
function createLegalCache(opts) {
|
|
747
|
+
const fetchImpl = opts.fetch ?? fetch;
|
|
748
|
+
const refreshMs = opts.refreshMs ?? DEFAULT_REFRESH_MS;
|
|
749
|
+
const baseUrl = opts.baseUrl ?? LEGAL_API_URL;
|
|
750
|
+
const now = opts.now ?? Date.now;
|
|
751
|
+
const keepOld = opts.onKeepOld ?? ((key, reason) => console.warn(`[legal] keeping the old ${key}: ${reason}`));
|
|
752
|
+
const cache = /* @__PURE__ */ new Map();
|
|
753
|
+
async function refresh(e, key) {
|
|
754
|
+
try {
|
|
755
|
+
const res = await fetchImpl(`${baseUrl}/${key}.json`, { headers: { "if-none-match": `"${e.template.hash}"` }, signal: AbortSignal.timeout(8e3) });
|
|
756
|
+
if (res.status === 304) return;
|
|
757
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
758
|
+
const t = await res.json();
|
|
759
|
+
if (!verifyTemplate(t)) throw new Error("the template does not verify (no sections, or its hash does not match its content)");
|
|
760
|
+
resolveTemplate(t, opts.facts);
|
|
761
|
+
e.template = t;
|
|
762
|
+
} catch (err) {
|
|
763
|
+
keepOld(key, err.message);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
/** The finished document for your product — immediately; starts a background refresh when one is due. */
|
|
768
|
+
get(doc, locale) {
|
|
769
|
+
const key = `${doc}.${locale}`;
|
|
770
|
+
let e = cache.get(key);
|
|
771
|
+
if (!e) cache.set(key, e = { template: getTemplate({ doc, locale }), checkedAt: -Infinity });
|
|
772
|
+
const t = now();
|
|
773
|
+
if (t - e.checkedAt >= refreshMs && !e.inFlight) {
|
|
774
|
+
e.checkedAt = t;
|
|
775
|
+
const entry = e;
|
|
776
|
+
entry.inFlight = refresh(entry, key).finally(() => {
|
|
777
|
+
entry.inFlight = void 0;
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
return resolveTemplate(e.template, opts.facts);
|
|
781
|
+
},
|
|
782
|
+
/** Resolves when a refresh in flight for this document has finished (tests, warm-up). */
|
|
783
|
+
settled(doc, locale) {
|
|
784
|
+
return cache.get(`${doc}.${locale}`)?.inFlight ?? Promise.resolve();
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
811
788
|
|
|
812
789
|
// src/index.ts
|
|
813
|
-
|
|
790
|
+
function pick(doc, locale) {
|
|
791
|
+
const master = SOURCES.find((s) => s.doc === doc && s.locale === MASTER_LOCALE);
|
|
792
|
+
if (!master) throw new Error(`no document "${doc}"`);
|
|
793
|
+
const src = SOURCES.find((s) => s.doc === doc && s.locale === locale) ?? master;
|
|
794
|
+
const stale = src.locale !== MASTER_LOCALE && src.translationOf?.sourceHash !== sourceHash(master);
|
|
795
|
+
return { src, stale };
|
|
796
|
+
}
|
|
797
|
+
function getTemplate(opts) {
|
|
798
|
+
const { src, stale } = pick(opts.doc, opts.locale);
|
|
799
|
+
return { ...src, stale, hash: templateHash(src) };
|
|
800
|
+
}
|
|
801
|
+
function verifyTemplate(t) {
|
|
802
|
+
if (!t || typeof t !== "object") return false;
|
|
803
|
+
const { hash, stale: _stale, ...authored } = t;
|
|
804
|
+
if (typeof hash !== "string" || !Array.isArray(authored.sections) || authored.sections.length === 0) return false;
|
|
805
|
+
return templateHash(authored) === hash;
|
|
806
|
+
}
|
|
807
|
+
function listDocuments() {
|
|
808
|
+
return SOURCES.map((s) => ({ doc: s.doc, locale: s.locale, version: s.version, effectiveFrom: s.effectiveFrom, draft: s.draft, hash: templateHash(s) }));
|
|
809
|
+
}
|
|
810
|
+
function getDocument(opts) {
|
|
811
|
+
return createLibrary(SOURCES, [opts.facts]).getDocument({ doc: opts.doc, locale: opts.locale, product: opts.facts.id });
|
|
812
|
+
}
|
|
813
|
+
function resolveTemplate(template, facts) {
|
|
814
|
+
const { doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections } = template;
|
|
815
|
+
return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id });
|
|
816
|
+
}
|
|
814
817
|
|
|
818
|
+
exports.DEFAULT_REFRESH_MS = DEFAULT_REFRESH_MS;
|
|
815
819
|
exports.DOC_IDS = DOC_IDS;
|
|
820
|
+
exports.EXAMPLE_FACTS = EXAMPLE_FACTS;
|
|
821
|
+
exports.LEGAL_API_URL = LEGAL_API_URL;
|
|
816
822
|
exports.MASTER_LOCALE = MASTER_LOCALE;
|
|
817
823
|
exports.PLACEHOLDERS = PLACEHOLDERS;
|
|
818
|
-
exports.PRODUCTS = PRODUCTS;
|
|
819
824
|
exports.SOURCES = SOURCES;
|
|
820
825
|
exports.canonicalJson = canonicalJson;
|
|
826
|
+
exports.createLegalCache = createLegalCache;
|
|
821
827
|
exports.createLibrary = createLibrary;
|
|
822
828
|
exports.getDocument = getDocument;
|
|
823
|
-
exports.
|
|
829
|
+
exports.getTemplate = getTemplate;
|
|
830
|
+
exports.listDocuments = listDocuments;
|
|
824
831
|
exports.placeholdersIn = placeholdersIn;
|
|
825
832
|
exports.renderHtml = renderHtml;
|
|
833
|
+
exports.resolveTemplate = resolveTemplate;
|
|
826
834
|
exports.sha256Hex = sha256Hex;
|
|
827
835
|
exports.sourceHash = sourceHash;
|
|
836
|
+
exports.templateHash = templateHash;
|
|
837
|
+
exports.verifyTemplate = verifyTemplate;
|
|
828
838
|
//# sourceMappingURL=index.cjs.map
|
|
829
839
|
//# sourceMappingURL=index.cjs.map
|