@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 +56 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.js +53 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -80,6 +80,12 @@ interface ProductFacts {
|
|
|
80
80
|
healthData: boolean;
|
|
81
81
|
/** F110.17 — only a platform with third-party modules (an App Store) sets this; the "modules" document needs it. */
|
|
82
82
|
modules?: ModuleTermsFacts;
|
|
83
|
+
/**
|
|
84
|
+
* F110.18 — the product reads Google user data through Google APIs (e.g. a gmail scope).
|
|
85
|
+
* Google's brand verification requires its Limited Use statement VERBATIM in the privacy
|
|
86
|
+
* policy; true renders it. Omitted/false: the document is unchanged (same contentHash).
|
|
87
|
+
*/
|
|
88
|
+
googleApiLimitedUse?: boolean;
|
|
83
89
|
}
|
|
84
90
|
/** The numbers and channels in the module-owner terms. The PRODUCT decides them; the text never contains them. */
|
|
85
91
|
interface ModuleTermsFacts {
|
|
@@ -102,7 +108,7 @@ interface ModuleTermsFacts {
|
|
|
102
108
|
complaintsResponse: string;
|
|
103
109
|
exportDays: number;
|
|
104
110
|
}
|
|
105
|
-
type FactKey = "hosting" | "dataCategories" | "subprocessors" | "conversationAnalysis" | "moduleTerms";
|
|
111
|
+
type FactKey = "hosting" | "dataCategories" | "subprocessors" | "conversationAnalysis" | "moduleTerms" | "googleApiLimitedUse";
|
|
106
112
|
/** The merge fields Contract Manager fills (contract-manager #5608, 31 Oct 2026). */
|
|
107
113
|
declare const PLACEHOLDERS: readonly ["customer.name", "customer.altName", "customer.cvr", "customer.companyForm", "customer.address", "customer.contact.name", "customer.contact.email", "customer.contact.phone", "provider.name", "provider.cvr", "provider.address", "provider.contact.name", "provider.contact.email", "contract.id", "contract.title", "contract.version", "contract.date", "contract.startDate"];
|
|
108
114
|
type Placeholder = (typeof PLACEHOLDERS)[number];
|
|
@@ -175,6 +181,17 @@ declare function createLibrary(sources: DocumentSource[], products: ProductFacts
|
|
|
175
181
|
*/
|
|
176
182
|
declare function renderHtml(doc: LegalDocument): string;
|
|
177
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
|
+
|
|
178
195
|
declare function sha256Hex(text: string): string;
|
|
179
196
|
|
|
180
197
|
/** Every authored document. Danish is the master and prevails; English (F110.4) mirrors it block for block. */
|
|
@@ -209,14 +226,6 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
209
226
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
210
227
|
};
|
|
211
228
|
|
|
212
|
-
/**
|
|
213
|
-
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
214
|
-
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
215
|
-
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
216
|
-
* user's access token from the BID login — the same token as /api/app/profile.
|
|
217
|
-
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
218
|
-
* point at another user or another product.
|
|
219
|
-
*/
|
|
220
229
|
/** The one place BID's address lives in this package. */
|
|
221
230
|
declare const BID_URL = "https://id.broberg.ai";
|
|
222
231
|
type AcceptedDoc = "terms" | "dpa" | "modules";
|
|
@@ -229,7 +238,13 @@ interface AcceptanceRecord {
|
|
|
229
238
|
/** Epoch ms, set by BID. */
|
|
230
239
|
acceptedAt: number;
|
|
231
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";
|
|
232
245
|
}
|
|
246
|
+
/** BID's ceiling for an accepted text (F084.243). */
|
|
247
|
+
declare const MAX_ACCEPTED_TEXT = 200000;
|
|
233
248
|
interface ConsentRecord {
|
|
234
249
|
sub: string;
|
|
235
250
|
product: string;
|
|
@@ -260,6 +275,10 @@ declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
|
260
275
|
doc: AcceptedDoc;
|
|
261
276
|
version: string;
|
|
262
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;
|
|
263
282
|
}): Promise<AcceptanceRecord>;
|
|
264
283
|
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
265
284
|
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
@@ -319,4 +338,4 @@ declare function getDocument(opts: {
|
|
|
319
338
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
320
339
|
declare function resolveTemplate(template: DocumentSource | LegalTemplate, facts: ProductFacts): LegalDocument;
|
|
321
340
|
|
|
322
|
-
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
|
@@ -80,6 +80,12 @@ interface ProductFacts {
|
|
|
80
80
|
healthData: boolean;
|
|
81
81
|
/** F110.17 — only a platform with third-party modules (an App Store) sets this; the "modules" document needs it. */
|
|
82
82
|
modules?: ModuleTermsFacts;
|
|
83
|
+
/**
|
|
84
|
+
* F110.18 — the product reads Google user data through Google APIs (e.g. a gmail scope).
|
|
85
|
+
* Google's brand verification requires its Limited Use statement VERBATIM in the privacy
|
|
86
|
+
* policy; true renders it. Omitted/false: the document is unchanged (same contentHash).
|
|
87
|
+
*/
|
|
88
|
+
googleApiLimitedUse?: boolean;
|
|
83
89
|
}
|
|
84
90
|
/** The numbers and channels in the module-owner terms. The PRODUCT decides them; the text never contains them. */
|
|
85
91
|
interface ModuleTermsFacts {
|
|
@@ -102,7 +108,7 @@ interface ModuleTermsFacts {
|
|
|
102
108
|
complaintsResponse: string;
|
|
103
109
|
exportDays: number;
|
|
104
110
|
}
|
|
105
|
-
type FactKey = "hosting" | "dataCategories" | "subprocessors" | "conversationAnalysis" | "moduleTerms";
|
|
111
|
+
type FactKey = "hosting" | "dataCategories" | "subprocessors" | "conversationAnalysis" | "moduleTerms" | "googleApiLimitedUse";
|
|
106
112
|
/** The merge fields Contract Manager fills (contract-manager #5608, 31 Oct 2026). */
|
|
107
113
|
declare const PLACEHOLDERS: readonly ["customer.name", "customer.altName", "customer.cvr", "customer.companyForm", "customer.address", "customer.contact.name", "customer.contact.email", "customer.contact.phone", "provider.name", "provider.cvr", "provider.address", "provider.contact.name", "provider.contact.email", "contract.id", "contract.title", "contract.version", "contract.date", "contract.startDate"];
|
|
108
114
|
type Placeholder = (typeof PLACEHOLDERS)[number];
|
|
@@ -175,6 +181,17 @@ declare function createLibrary(sources: DocumentSource[], products: ProductFacts
|
|
|
175
181
|
*/
|
|
176
182
|
declare function renderHtml(doc: LegalDocument): string;
|
|
177
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
|
+
|
|
178
195
|
declare function sha256Hex(text: string): string;
|
|
179
196
|
|
|
180
197
|
/** Every authored document. Danish is the master and prevails; English (F110.4) mirrors it block for block. */
|
|
@@ -209,14 +226,6 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
209
226
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
210
227
|
};
|
|
211
228
|
|
|
212
|
-
/**
|
|
213
|
-
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
214
|
-
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
215
|
-
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
216
|
-
* user's access token from the BID login — the same token as /api/app/profile.
|
|
217
|
-
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
218
|
-
* point at another user or another product.
|
|
219
|
-
*/
|
|
220
229
|
/** The one place BID's address lives in this package. */
|
|
221
230
|
declare const BID_URL = "https://id.broberg.ai";
|
|
222
231
|
type AcceptedDoc = "terms" | "dpa" | "modules";
|
|
@@ -229,7 +238,13 @@ interface AcceptanceRecord {
|
|
|
229
238
|
/** Epoch ms, set by BID. */
|
|
230
239
|
acceptedAt: number;
|
|
231
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";
|
|
232
245
|
}
|
|
246
|
+
/** BID's ceiling for an accepted text (F084.243). */
|
|
247
|
+
declare const MAX_ACCEPTED_TEXT = 200000;
|
|
233
248
|
interface ConsentRecord {
|
|
234
249
|
sub: string;
|
|
235
250
|
product: string;
|
|
@@ -260,6 +275,10 @@ declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
|
260
275
|
doc: AcceptedDoc;
|
|
261
276
|
version: string;
|
|
262
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;
|
|
263
282
|
}): Promise<AcceptanceRecord>;
|
|
264
283
|
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
265
284
|
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
@@ -319,4 +338,4 @@ declare function getDocument(opts: {
|
|
|
319
338
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
320
339
|
declare function resolveTemplate(template: DocumentSource | LegalTemplate, facts: ProductFacts): LegalDocument;
|
|
321
340
|
|
|
322
|
-
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
|
@@ -182,6 +182,8 @@ function moduleFacts(p) {
|
|
|
182
182
|
if (!m.revenueShare.length || Math.abs(total - 100) > 1e-9) throw new Error(`product "${p.id}": revenueShare must add up to 100 %, got ${total}`);
|
|
183
183
|
return m;
|
|
184
184
|
}
|
|
185
|
+
var GOOGLE_USER_DATA_POLICY = "https://developers.google.com/terms/api-services-user-data-policy";
|
|
186
|
+
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.`;
|
|
185
187
|
var FACT_TEMPLATES = {
|
|
186
188
|
da: {
|
|
187
189
|
hosting: (p, id) => [{ id, type: "table", head: ["Hvad", "Hvor"], rows: p.hosting.map((h) => [h.what, h.where]) }],
|
|
@@ -196,6 +198,10 @@ var FACT_TEMPLATES = {
|
|
|
196
198
|
text: p.conversationAnalysis ? `${p.name} er omfattet af afsnittet om analyse af samtaler.` : `${p.name} er ikke omfattet af afsnittet om analyse af samtaler.`
|
|
197
199
|
}
|
|
198
200
|
],
|
|
201
|
+
googleApiLimitedUse: (p, id) => p.googleApiLimitedUse ? [
|
|
202
|
+
{ 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:` },
|
|
203
|
+
{ id: `${id}.statement`, type: "p", text: googleLimitedUse(p.name) }
|
|
204
|
+
] : [],
|
|
199
205
|
moduleTerms: (p, id) => {
|
|
200
206
|
const m = moduleFacts(p);
|
|
201
207
|
return [{
|
|
@@ -230,6 +236,10 @@ var FACT_TEMPLATES = {
|
|
|
230
236
|
text: p.conversationAnalysis ? `${p.name} is covered by the section on conversation analysis.` : `${p.name} is not covered by the section on conversation analysis.`
|
|
231
237
|
}
|
|
232
238
|
],
|
|
239
|
+
googleApiLimitedUse: (p, id) => p.googleApiLimitedUse ? [
|
|
240
|
+
{ id, type: "p", text: `${p.name} receives information from Google APIs. Google's own statement on that use applies, verbatim:` },
|
|
241
|
+
{ id: `${id}.statement`, type: "p", text: googleLimitedUse(p.name) }
|
|
242
|
+
] : [],
|
|
233
243
|
moduleTerms: (p, id) => {
|
|
234
244
|
const m = moduleFacts(p);
|
|
235
245
|
return [{
|
|
@@ -481,6 +491,7 @@ var PRIVACY_DA = {
|
|
|
481
491
|
blocks: [
|
|
482
492
|
{ id: "deling.p1", type: "p", text: "Vi s\xE6lger aldrig data. Vi bruger disse databehandlere, som kun m\xE5 behandle oplysningerne efter vores instruks:" },
|
|
483
493
|
{ id: "deling.facts", type: "facts", fact: "subprocessors" },
|
|
494
|
+
{ id: "deling.google", type: "facts", fact: "googleApiLimitedUse" },
|
|
484
495
|
{ 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." }
|
|
485
496
|
]
|
|
486
497
|
},
|
|
@@ -999,7 +1010,7 @@ var PRIVACY_EN = {
|
|
|
999
1010
|
effectiveFrom: "2026-11-02",
|
|
1000
1011
|
material: false,
|
|
1001
1012
|
draft: false,
|
|
1002
|
-
translationOf: { version: "2026-11-02", sourceHash: "
|
|
1013
|
+
translationOf: { version: "2026-11-02", sourceHash: "c30a33c005888cd3dbbe62c462235fa31487f2b51821450ecb52e462578ddac6" },
|
|
1003
1014
|
sections: [
|
|
1004
1015
|
{
|
|
1005
1016
|
id: "dataansvarlig",
|
|
@@ -1082,6 +1093,7 @@ var PRIVACY_EN = {
|
|
|
1082
1093
|
blocks: [
|
|
1083
1094
|
{ id: "deling.p1", type: "p", text: "We never sell data. We use these processors, which may only process the information on our instructions:" },
|
|
1084
1095
|
{ id: "deling.facts", type: "facts", fact: "subprocessors" },
|
|
1096
|
+
{ id: "deling.google", type: "facts", fact: "googleApiLimitedUse" },
|
|
1085
1097
|
{ 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." }
|
|
1086
1098
|
]
|
|
1087
1099
|
},
|
|
@@ -1559,6 +1571,37 @@ function renderHtml(doc) {
|
|
|
1559
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>`;
|
|
1560
1572
|
}
|
|
1561
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
|
+
|
|
1562
1605
|
// src/content/example.ts
|
|
1563
1606
|
var EXAMPLE_FACTS = {
|
|
1564
1607
|
id: "example",
|
|
@@ -1635,6 +1678,7 @@ function createLegalCache(opts) {
|
|
|
1635
1678
|
|
|
1636
1679
|
// src/bid.ts
|
|
1637
1680
|
var BID_URL = "https://id.broberg.ai";
|
|
1681
|
+
var MAX_ACCEPTED_TEXT = 2e5;
|
|
1638
1682
|
var BidConsentError = class extends Error {
|
|
1639
1683
|
constructor(status, code, message) {
|
|
1640
1684
|
super(message);
|
|
@@ -1667,8 +1711,14 @@ async function call(opts, method, path, body) {
|
|
|
1667
1711
|
}
|
|
1668
1712
|
async function recordAcceptance(opts, a) {
|
|
1669
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;
|
|
1670
1720
|
const row = await call(opts, "POST", "/api/app/terms-acceptance", sent);
|
|
1671
|
-
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) {
|
|
1672
1722
|
throw new BidConsentError(200, "not_echoed", "BID's stored acceptance does not match what was sent");
|
|
1673
1723
|
}
|
|
1674
1724
|
return row;
|
|
@@ -1726,6 +1776,6 @@ function resolveTemplate(template, facts) {
|
|
|
1726
1776
|
return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id, stale });
|
|
1727
1777
|
}
|
|
1728
1778
|
|
|
1729
|
-
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 };
|
|
1730
1780
|
//# sourceMappingURL=index.js.map
|
|
1731
1781
|
//# sourceMappingURL=index.js.map
|