@broberg/legal 0.1.0 → 0.2.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 +123 -17
- package/dist/index.cjs +64 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -20
- package/dist/index.d.ts +36 -20
- package/dist/index.js +60 -109
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,26 +1,132 @@
|
|
|
1
1
|
# @broberg/legal
|
|
2
2
|
|
|
3
|
-
**Status: 0.
|
|
3
|
+
**Status: 0.2.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`:
|
|
8
22
|
|
|
9
23
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
};
|
|
14
43
|
```
|
|
15
44
|
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
|
|
51
|
+
### 2. Get the texts: the npm package (recommended for JS/TS)
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { getDocument, renderHtml } from "@broberg/legal"; // pin an exact version
|
|
55
|
+
import { FACTS } from "./legal/facts";
|
|
56
|
+
|
|
57
|
+
const doc = getDocument({ doc: "privacy", locale: "da", facts: FACTS });
|
|
58
|
+
doc.title; doc.version; doc.effectiveFrom; doc.draft; doc.contentHash;
|
|
59
|
+
renderHtml(doc); // semantic HTML with data-legal-id on every section and block; style it yourself
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The texts ship **inside** the package, so your site needs no network for them and cannot lose them
|
|
63
|
+
when legal.broberg.ai is down. New texts reach you as a new package version; components sends a
|
|
64
|
+
release report saying whether the wording changed.
|
|
65
|
+
|
|
66
|
+
### 3. Or get them over HTTP (any stack)
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
GET https://legal.broberg.ai/v1/documents → { documents: [{ doc, locale, version, effectiveFrom, draft, hash }] }
|
|
70
|
+
GET https://legal.broberg.ai/v1/{doc}.{da|en}.json → the template: sections with facts slots open, + version, draft, stale, hash
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Fill the slots with your facts: in JS/TS, `resolveTemplate(template, FACTS)` from this package. In
|
|
74
|
+
another language, render each `facts` block like this: `hosting` is a table (What | Where);
|
|
75
|
+
`dataCategories` is a list; `subprocessors` is a table (Vendor | Used for | Where | Transfer);
|
|
76
|
+
`conversationAnalysis` is one sentence saying whether your product is covered by the section on
|
|
77
|
+
conversation analysis. A missing English translation falls back to Danish; `stale: true` means the
|
|
78
|
+
English text is older than the Danish one, so show the Danish one or a notice.
|
|
79
|
+
|
|
80
|
+
### 4. Cache: keep your own copy, and only fetch a new edition when there is one (HTTP route)
|
|
81
|
+
|
|
82
|
+
Your terms page must never go down because legal.broberg.ai is down or being updated.
|
|
83
|
+
|
|
84
|
+
1. **Keep a snapshot in your repo or build** (`legal/snapshot/{doc}.{locale}.json`, the templates as
|
|
85
|
+
fetched). Your pages render from the snapshot. They never call the API on a page view.
|
|
86
|
+
2. **Check for a new edition at most once a day:** `GET /v1/documents` and compare each `hash` with
|
|
87
|
+
your snapshot's. Same hash means there is nothing to do.
|
|
88
|
+
3. **Only when a hash changed:** fetch that template, check it (it parses, `hash` matches the list,
|
|
89
|
+
`sections` is not empty), then replace the snapshot file in one step (write to a temp file, then
|
|
90
|
+
rename).
|
|
91
|
+
4. **If anything fails** (timeout, 5xx, a check fails), keep the old snapshot, log it, and try again
|
|
92
|
+
tomorrow. Never empty a page because a fetch failed.
|
|
93
|
+
5. Every answer carries an `ETag` and `cache-control: public, max-age=86400`. A request with
|
|
94
|
+
`If-None-Match: "<hash>"` answers an empty `304` when nothing changed.
|
|
95
|
+
|
|
96
|
+
The service runs cold: the first call after a quiet spell takes a second or two. That is fine for a
|
|
97
|
+
daily check and one more reason never to call it on a page view.
|
|
98
|
+
|
|
99
|
+
### 5. Show the documents on YOUR site
|
|
100
|
+
|
|
101
|
+
- One page per document on your own domain, for example `/vilkaar`, `/privatliv`, `/tillid`.
|
|
102
|
+
`dpa` and `support` belong in customer contracts (Contract Manager fills `{customer.name}` and the
|
|
103
|
+
other placeholders); a public site shows `terms`, `privacy` and `trust`.
|
|
104
|
+
- Style and re-flow freely. **Never edit the text.**
|
|
105
|
+
- Show the version and the «gælder fra» date (`version`, `effectiveFrom`). While `draft` is true, show
|
|
106
|
+
the «UDKAST» marker (`renderHtml` does it for you).
|
|
107
|
+
- Link all of them in your footer. **Never link users to legal.broberg.ai**; it redirects to broberg.ai.
|
|
108
|
+
|
|
109
|
+
### 6. Acceptance
|
|
110
|
+
|
|
111
|
+
Terms are accepted at sign-up with an **unticked** «Jeg accepterer vilkårene» checkbox; the privacy
|
|
112
|
+
policy is linked and shown, never "accepted". Store `{ doc, version, contentHash }` with the
|
|
113
|
+
acceptance, so "which text did they accept?" has an exact answer.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Reference
|
|
118
|
+
|
|
119
|
+
- `getDocument({ doc, locale, facts })`: a finished document from the bundled templates plus your facts.
|
|
120
|
+
- `getTemplate({ doc, locale })`: the template, as the API serves it. `listDocuments()`: what `/v1/documents` serves.
|
|
121
|
+
- `resolveTemplate(template, facts)`: a finished document from a template you fetched. It gives the
|
|
122
|
+
same `contentHash` as `getDocument` with the same facts.
|
|
123
|
+
- `renderHtml(document)`: semantic HTML. `EXAMPLE_FACTS`: a filled-in example.
|
|
124
|
+
- **contentHash** = sha256 of the canonical JSON of the finished document; **hash** = the same for a template.
|
|
125
|
+
- **Placeholders** (`{customer.name}` and the rest) are a fixed list; an unknown one is refused.
|
|
24
126
|
- Zero dependencies (a built-in SHA-256, proven against FIPS vectors and node:crypto).
|
|
25
127
|
|
|
26
|
-
|
|
128
|
+
**0.2.0 (F110.14), breaking:** the fleet product registry and `library` are gone, and
|
|
129
|
+
`getDocument` takes `facts` instead of `product`. The per-product HTTP routes and the human pages are
|
|
130
|
+
gone too: legal.broberg.ai is an API.
|
|
131
|
+
|
|
132
|
+
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,80 @@ 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
|
+
};
|
|
811
742
|
|
|
812
743
|
// src/index.ts
|
|
813
|
-
|
|
744
|
+
function pick(doc, locale) {
|
|
745
|
+
const master = SOURCES.find((s) => s.doc === doc && s.locale === MASTER_LOCALE);
|
|
746
|
+
if (!master) throw new Error(`no document "${doc}"`);
|
|
747
|
+
const src = SOURCES.find((s) => s.doc === doc && s.locale === locale) ?? master;
|
|
748
|
+
const stale = src.locale !== MASTER_LOCALE && src.translationOf?.sourceHash !== sourceHash(master);
|
|
749
|
+
return { src, stale };
|
|
750
|
+
}
|
|
751
|
+
function getTemplate(opts) {
|
|
752
|
+
const { src, stale } = pick(opts.doc, opts.locale);
|
|
753
|
+
return { ...src, stale, hash: templateHash(src) };
|
|
754
|
+
}
|
|
755
|
+
function listDocuments() {
|
|
756
|
+
return SOURCES.map((s) => ({ doc: s.doc, locale: s.locale, version: s.version, effectiveFrom: s.effectiveFrom, draft: s.draft, hash: templateHash(s) }));
|
|
757
|
+
}
|
|
758
|
+
function getDocument(opts) {
|
|
759
|
+
return createLibrary(SOURCES, [opts.facts]).getDocument({ doc: opts.doc, locale: opts.locale, product: opts.facts.id });
|
|
760
|
+
}
|
|
761
|
+
function resolveTemplate(template, facts) {
|
|
762
|
+
const { doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections } = template;
|
|
763
|
+
return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id });
|
|
764
|
+
}
|
|
814
765
|
|
|
815
766
|
exports.DOC_IDS = DOC_IDS;
|
|
767
|
+
exports.EXAMPLE_FACTS = EXAMPLE_FACTS;
|
|
816
768
|
exports.MASTER_LOCALE = MASTER_LOCALE;
|
|
817
769
|
exports.PLACEHOLDERS = PLACEHOLDERS;
|
|
818
|
-
exports.PRODUCTS = PRODUCTS;
|
|
819
770
|
exports.SOURCES = SOURCES;
|
|
820
771
|
exports.canonicalJson = canonicalJson;
|
|
821
772
|
exports.createLibrary = createLibrary;
|
|
822
773
|
exports.getDocument = getDocument;
|
|
823
|
-
exports.
|
|
774
|
+
exports.getTemplate = getTemplate;
|
|
775
|
+
exports.listDocuments = listDocuments;
|
|
824
776
|
exports.placeholdersIn = placeholdersIn;
|
|
825
777
|
exports.renderHtml = renderHtml;
|
|
778
|
+
exports.resolveTemplate = resolveTemplate;
|
|
826
779
|
exports.sha256Hex = sha256Hex;
|
|
827
780
|
exports.sourceHash = sourceHash;
|
|
781
|
+
exports.templateHash = templateHash;
|
|
828
782
|
//# sourceMappingURL=index.cjs.map
|
|
829
783
|
//# sourceMappingURL=index.cjs.map
|