@broberg/legal 0.9.0 → 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 +43 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -9
- package/dist/index.d.ts +22 -9
- package/dist/index.js +40 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -181,6 +181,17 @@ declare function createLibrary(sources: DocumentSource[], products: ProductFacts
|
|
|
181
181
|
*/
|
|
182
182
|
declare function renderHtml(doc: LegalDocument): string;
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Every {placeholder} replaced by its value. Refuses — by name — a placeholder the document
|
|
186
|
+
* needs that `values` lacks, a key that is not a known merge field, and an empty value: a
|
|
187
|
+
* contract with «{customer.name}» or «» where a name should be must never be signable.
|
|
188
|
+
*/
|
|
189
|
+
declare function fillPlaceholders(doc: LegalDocument, values: Partial<Record<Placeholder, string>>): LegalDocument;
|
|
190
|
+
/** Plain text of a document, deterministic: title, then each section's heading and blocks. */
|
|
191
|
+
declare function renderText(doc: LegalDocument): string;
|
|
192
|
+
/** What BID checks: "sha256:" + hex(sha256(utf8(text))). */
|
|
193
|
+
declare function textHash(text: string): string;
|
|
194
|
+
|
|
184
195
|
declare function sha256Hex(text: string): string;
|
|
185
196
|
|
|
186
197
|
/** Every authored document. Danish is the master and prevails; English (F110.4) mirrors it block for block. */
|
|
@@ -215,14 +226,6 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
215
226
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
216
227
|
};
|
|
217
228
|
|
|
218
|
-
/**
|
|
219
|
-
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
220
|
-
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
221
|
-
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
222
|
-
* user's access token from the BID login — the same token as /api/app/profile.
|
|
223
|
-
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
224
|
-
* point at another user or another product.
|
|
225
|
-
*/
|
|
226
229
|
/** The one place BID's address lives in this package. */
|
|
227
230
|
declare const BID_URL = "https://id.broberg.ai";
|
|
228
231
|
type AcceptedDoc = "terms" | "dpa" | "modules";
|
|
@@ -235,7 +238,13 @@ interface AcceptanceRecord {
|
|
|
235
238
|
/** Epoch ms, set by BID. */
|
|
236
239
|
acceptedAt: number;
|
|
237
240
|
clientId: string;
|
|
241
|
+
/** F110.20 — the person confirmed they may accept on the customer's behalf (required for "dpa"). */
|
|
242
|
+
authorityConfirmed?: boolean;
|
|
243
|
+
/** F110.20 — whether BID mailed the accepting person a copy of the text. */
|
|
244
|
+
copy?: "sent" | "skipped" | "failed";
|
|
238
245
|
}
|
|
246
|
+
/** BID's ceiling for an accepted text (F084.243). */
|
|
247
|
+
declare const MAX_ACCEPTED_TEXT = 200000;
|
|
239
248
|
interface ConsentRecord {
|
|
240
249
|
sub: string;
|
|
241
250
|
product: string;
|
|
@@ -266,6 +275,10 @@ declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
|
266
275
|
doc: AcceptedDoc;
|
|
267
276
|
version: string;
|
|
268
277
|
contentHash: string;
|
|
278
|
+
/** F110.20 — the FILLED text the person accepted (renderText of fillPlaceholders). BID requires it for "dpa"; contentHash must then be textHash(text). */
|
|
279
|
+
text?: string;
|
|
280
|
+
/** F110.20 — the person confirmed they may bind the customer. BID requires true for "dpa". */
|
|
281
|
+
authorityConfirmed?: boolean;
|
|
269
282
|
}): Promise<AcceptanceRecord>;
|
|
270
283
|
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
271
284
|
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
@@ -325,4 +338,4 @@ declare function getDocument(opts: {
|
|
|
325
338
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
326
339
|
declare function resolveTemplate(template: DocumentSource | LegalTemplate, facts: ProductFacts): LegalDocument;
|
|
327
340
|
|
|
328
|
-
export { type AcceptanceRecord, type AcceptedDoc, BID_URL, type BidCallOptions, BidConsentError, type Block, type ConsentRecord, DEFAULT_REFRESH_MS, DOC_IDS, type DocId, type DocumentSource, EXAMPLE_FACTS, type FactKey, LEGAL_API_URL, type LegalCacheOptions, type LegalDocument, type LegalTemplate, type Locale, MASTER_LOCALE, type ModuleTermsFacts, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
|
341
|
+
export { type AcceptanceRecord, type AcceptedDoc, BID_URL, type BidCallOptions, BidConsentError, type Block, type ConsentRecord, DEFAULT_REFRESH_MS, DOC_IDS, type DocId, type DocumentSource, EXAMPLE_FACTS, type FactKey, LEGAL_API_URL, type LegalCacheOptions, type LegalDocument, type LegalTemplate, type Locale, MASTER_LOCALE, MAX_ACCEPTED_TEXT, type ModuleTermsFacts, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, fillPlaceholders, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, renderText, resolveTemplate, sha256Hex, sourceHash, templateHash, textHash, toBidHash, verifyTemplate };
|
package/dist/index.d.ts
CHANGED
|
@@ -181,6 +181,17 @@ declare function createLibrary(sources: DocumentSource[], products: ProductFacts
|
|
|
181
181
|
*/
|
|
182
182
|
declare function renderHtml(doc: LegalDocument): string;
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Every {placeholder} replaced by its value. Refuses — by name — a placeholder the document
|
|
186
|
+
* needs that `values` lacks, a key that is not a known merge field, and an empty value: a
|
|
187
|
+
* contract with «{customer.name}» or «» where a name should be must never be signable.
|
|
188
|
+
*/
|
|
189
|
+
declare function fillPlaceholders(doc: LegalDocument, values: Partial<Record<Placeholder, string>>): LegalDocument;
|
|
190
|
+
/** Plain text of a document, deterministic: title, then each section's heading and blocks. */
|
|
191
|
+
declare function renderText(doc: LegalDocument): string;
|
|
192
|
+
/** What BID checks: "sha256:" + hex(sha256(utf8(text))). */
|
|
193
|
+
declare function textHash(text: string): string;
|
|
194
|
+
|
|
184
195
|
declare function sha256Hex(text: string): string;
|
|
185
196
|
|
|
186
197
|
/** Every authored document. Danish is the master and prevails; English (F110.4) mirrors it block for block. */
|
|
@@ -215,14 +226,6 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
215
226
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
216
227
|
};
|
|
217
228
|
|
|
218
|
-
/**
|
|
219
|
-
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
220
|
-
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
221
|
-
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
222
|
-
* user's access token from the BID login — the same token as /api/app/profile.
|
|
223
|
-
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
224
|
-
* point at another user or another product.
|
|
225
|
-
*/
|
|
226
229
|
/** The one place BID's address lives in this package. */
|
|
227
230
|
declare const BID_URL = "https://id.broberg.ai";
|
|
228
231
|
type AcceptedDoc = "terms" | "dpa" | "modules";
|
|
@@ -235,7 +238,13 @@ interface AcceptanceRecord {
|
|
|
235
238
|
/** Epoch ms, set by BID. */
|
|
236
239
|
acceptedAt: number;
|
|
237
240
|
clientId: string;
|
|
241
|
+
/** F110.20 — the person confirmed they may accept on the customer's behalf (required for "dpa"). */
|
|
242
|
+
authorityConfirmed?: boolean;
|
|
243
|
+
/** F110.20 — whether BID mailed the accepting person a copy of the text. */
|
|
244
|
+
copy?: "sent" | "skipped" | "failed";
|
|
238
245
|
}
|
|
246
|
+
/** BID's ceiling for an accepted text (F084.243). */
|
|
247
|
+
declare const MAX_ACCEPTED_TEXT = 200000;
|
|
239
248
|
interface ConsentRecord {
|
|
240
249
|
sub: string;
|
|
241
250
|
product: string;
|
|
@@ -266,6 +275,10 @@ declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
|
266
275
|
doc: AcceptedDoc;
|
|
267
276
|
version: string;
|
|
268
277
|
contentHash: string;
|
|
278
|
+
/** F110.20 — the FILLED text the person accepted (renderText of fillPlaceholders). BID requires it for "dpa"; contentHash must then be textHash(text). */
|
|
279
|
+
text?: string;
|
|
280
|
+
/** F110.20 — the person confirmed they may bind the customer. BID requires true for "dpa". */
|
|
281
|
+
authorityConfirmed?: boolean;
|
|
269
282
|
}): Promise<AcceptanceRecord>;
|
|
270
283
|
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
271
284
|
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
@@ -325,4 +338,4 @@ declare function getDocument(opts: {
|
|
|
325
338
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
326
339
|
declare function resolveTemplate(template: DocumentSource | LegalTemplate, facts: ProductFacts): LegalDocument;
|
|
327
340
|
|
|
328
|
-
export { type AcceptanceRecord, type AcceptedDoc, BID_URL, type BidCallOptions, BidConsentError, type Block, type ConsentRecord, DEFAULT_REFRESH_MS, DOC_IDS, type DocId, type DocumentSource, EXAMPLE_FACTS, type FactKey, LEGAL_API_URL, type LegalCacheOptions, type LegalDocument, type LegalTemplate, type Locale, MASTER_LOCALE, type ModuleTermsFacts, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
|
341
|
+
export { type AcceptanceRecord, type AcceptedDoc, BID_URL, type BidCallOptions, BidConsentError, type Block, type ConsentRecord, DEFAULT_REFRESH_MS, DOC_IDS, type DocId, type DocumentSource, EXAMPLE_FACTS, type FactKey, LEGAL_API_URL, type LegalCacheOptions, type LegalDocument, type LegalTemplate, type Locale, MASTER_LOCALE, MAX_ACCEPTED_TEXT, type ModuleTermsFacts, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, fillPlaceholders, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, renderText, resolveTemplate, sha256Hex, sourceHash, templateHash, textHash, toBidHash, verifyTemplate };
|
package/dist/index.js
CHANGED
|
@@ -1571,6 +1571,37 @@ function renderHtml(doc) {
|
|
|
1571
1571
|
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>`;
|
|
1572
1572
|
}
|
|
1573
1573
|
|
|
1574
|
+
// src/fill.ts
|
|
1575
|
+
var KNOWN2 = new Set(PLACEHOLDERS);
|
|
1576
|
+
var RE = /\{([a-zA-Z.]+)\}/g;
|
|
1577
|
+
function fillPlaceholders(doc, values) {
|
|
1578
|
+
const unknown = Object.keys(values).filter((k) => !KNOWN2.has(k));
|
|
1579
|
+
if (unknown.length) throw new Error(`unknown placeholder value(s): ${unknown.join(", ")}`);
|
|
1580
|
+
const missing = doc.placeholders.filter((p) => typeof values[p] !== "string" || values[p].trim() === "");
|
|
1581
|
+
if (missing.length) throw new Error(`missing or empty placeholder value(s): ${missing.join(", ")}`);
|
|
1582
|
+
const fill = (s) => s.replace(RE, (whole, name) => KNOWN2.has(name) && values[name] !== void 0 ? values[name] : whole);
|
|
1583
|
+
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) };
|
|
1584
|
+
const { contentHash: _old, ...rest } = doc;
|
|
1585
|
+
const body = { ...rest, title: fill(doc.title), sections: doc.sections.map((s) => ({ ...s, heading: fill(s.heading), blocks: s.blocks.map(block2) })), placeholders: [] };
|
|
1586
|
+
return { ...body, contentHash: sha256Hex(canonicalJson(body)) };
|
|
1587
|
+
}
|
|
1588
|
+
function renderText(doc) {
|
|
1589
|
+
const out = [doc.title, ""];
|
|
1590
|
+
for (const s of doc.sections) {
|
|
1591
|
+
out.push(s.heading);
|
|
1592
|
+
for (const b of s.blocks) {
|
|
1593
|
+
if (b.type === "list") out.push(...b.items.map((i) => `- ${i}`));
|
|
1594
|
+
else if (b.type === "table") out.push(b.head.join(" | "), ...b.rows.map((r) => r.join(" | ")));
|
|
1595
|
+
else out.push(b.text);
|
|
1596
|
+
}
|
|
1597
|
+
out.push("");
|
|
1598
|
+
}
|
|
1599
|
+
return out.join("\n");
|
|
1600
|
+
}
|
|
1601
|
+
function textHash(text) {
|
|
1602
|
+
return `sha256:${sha256Hex(text)}`;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1574
1605
|
// src/content/example.ts
|
|
1575
1606
|
var EXAMPLE_FACTS = {
|
|
1576
1607
|
id: "example",
|
|
@@ -1647,6 +1678,7 @@ function createLegalCache(opts) {
|
|
|
1647
1678
|
|
|
1648
1679
|
// src/bid.ts
|
|
1649
1680
|
var BID_URL = "https://id.broberg.ai";
|
|
1681
|
+
var MAX_ACCEPTED_TEXT = 2e5;
|
|
1650
1682
|
var BidConsentError = class extends Error {
|
|
1651
1683
|
constructor(status, code, message) {
|
|
1652
1684
|
super(message);
|
|
@@ -1679,8 +1711,14 @@ async function call(opts, method, path, body) {
|
|
|
1679
1711
|
}
|
|
1680
1712
|
async function recordAcceptance(opts, a) {
|
|
1681
1713
|
const sent = { doc: a.doc, version: a.version, contentHash: toBidHash(a.contentHash) };
|
|
1714
|
+
if (a.text !== void 0) {
|
|
1715
|
+
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}`);
|
|
1716
|
+
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");
|
|
1717
|
+
sent.text = a.text;
|
|
1718
|
+
}
|
|
1719
|
+
if (a.authorityConfirmed !== void 0) sent.authorityConfirmed = a.authorityConfirmed;
|
|
1682
1720
|
const row = await call(opts, "POST", "/api/app/terms-acceptance", sent);
|
|
1683
|
-
if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
|
|
1721
|
+
if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash || a.authorityConfirmed !== void 0 && row?.authorityConfirmed !== a.authorityConfirmed) {
|
|
1684
1722
|
throw new BidConsentError(200, "not_echoed", "BID's stored acceptance does not match what was sent");
|
|
1685
1723
|
}
|
|
1686
1724
|
return row;
|
|
@@ -1738,6 +1776,6 @@ function resolveTemplate(template, facts) {
|
|
|
1738
1776
|
return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id, stale });
|
|
1739
1777
|
}
|
|
1740
1778
|
|
|
1741
|
-
export { BID_URL, BidConsentError, DEFAULT_REFRESH_MS, DOC_IDS, EXAMPLE_FACTS, LEGAL_API_URL, MASTER_LOCALE, PLACEHOLDERS, SOURCES, canonicalJson, createLegalCache, createLibrary, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
|
1779
|
+
export { BID_URL, BidConsentError, DEFAULT_REFRESH_MS, DOC_IDS, EXAMPLE_FACTS, LEGAL_API_URL, MASTER_LOCALE, MAX_ACCEPTED_TEXT, PLACEHOLDERS, SOURCES, canonicalJson, createLegalCache, createLibrary, fillPlaceholders, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, parityProblems, placeholdersIn, recordAcceptance, recordConsent, renderHtml, renderText, resolveTemplate, sha256Hex, sourceHash, templateHash, textHash, toBidHash, verifyTemplate };
|
|
1742
1780
|
//# sourceMappingURL=index.js.map
|
|
1743
1781
|
//# sourceMappingURL=index.js.map
|