@broberg/legal 0.3.0 → 0.4.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 +47 -6
- package/dist/index.cjs +71 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +64 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -178,6 +178,80 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
178
178
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
179
179
|
};
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
183
|
+
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
184
|
+
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
185
|
+
* user's access token from the BID login — the same token as /api/app/profile.
|
|
186
|
+
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
187
|
+
* point at another user or another product.
|
|
188
|
+
*/
|
|
189
|
+
/** The one place BID's address lives in this package. */
|
|
190
|
+
declare const BID_URL = "https://id.broberg.ai";
|
|
191
|
+
type AcceptedDoc = "terms" | "dpa";
|
|
192
|
+
interface AcceptanceRecord {
|
|
193
|
+
sub: string;
|
|
194
|
+
product: string;
|
|
195
|
+
doc: AcceptedDoc;
|
|
196
|
+
version: string;
|
|
197
|
+
contentHash: string;
|
|
198
|
+
/** Epoch ms, set by BID. */
|
|
199
|
+
acceptedAt: number;
|
|
200
|
+
clientId: string;
|
|
201
|
+
}
|
|
202
|
+
interface ConsentRecord {
|
|
203
|
+
sub: string;
|
|
204
|
+
product: string;
|
|
205
|
+
purpose: string;
|
|
206
|
+
granted: boolean;
|
|
207
|
+
version: string;
|
|
208
|
+
contentHash: string;
|
|
209
|
+
/** Epoch ms, set by BID. */
|
|
210
|
+
at: number;
|
|
211
|
+
/** "bid-account" when the user withdrew on their BID account. */
|
|
212
|
+
clientId: string;
|
|
213
|
+
}
|
|
214
|
+
interface BidCallOptions {
|
|
215
|
+
/** The user's access token from the BID login. Never a token of yours. */
|
|
216
|
+
accessToken: string;
|
|
217
|
+
fetch?: typeof fetch;
|
|
218
|
+
baseUrl?: string;
|
|
219
|
+
}
|
|
220
|
+
declare class BidConsentError extends Error {
|
|
221
|
+
readonly status: number;
|
|
222
|
+
readonly code: string;
|
|
223
|
+
constructor(status: number, code: string, message: string);
|
|
224
|
+
}
|
|
225
|
+
/** Our hashes are 64 hex; BID wants «sha256:<64 hex>». Accepts either. */
|
|
226
|
+
declare function toBidHash(contentHash: string): string;
|
|
227
|
+
/** Record that the user accepted this version of a document. Returns the row BID stored (read back). */
|
|
228
|
+
declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
229
|
+
doc: AcceptedDoc;
|
|
230
|
+
version: string;
|
|
231
|
+
contentHash: string;
|
|
232
|
+
}): Promise<AcceptanceRecord>;
|
|
233
|
+
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
234
|
+
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
235
|
+
/** Record a GDPR consent given (granted:true) or withdrawn (granted:false). Returns the stored row (read back). */
|
|
236
|
+
declare function recordConsent(opts: BidCallOptions, c: {
|
|
237
|
+
purpose: string;
|
|
238
|
+
granted: boolean;
|
|
239
|
+
version: string;
|
|
240
|
+
contentHash: string;
|
|
241
|
+
}): Promise<ConsentRecord>;
|
|
242
|
+
/** The CURRENT state of a consent for YOUR product (latest row), or null if never asked. Read it before you use the data. */
|
|
243
|
+
declare function getConsent(opts: BidCallOptions, purpose: string): Promise<ConsentRecord | null>;
|
|
244
|
+
/**
|
|
245
|
+
* Must the user accept the terms again? Yes when they never accepted, or when the
|
|
246
|
+
* current terms are a MATERIAL change and newer than what they accepted. A
|
|
247
|
+
* non-material change is announced, not re-asked (terms «Ændringer»).
|
|
248
|
+
* Versions are ISO dates, so they compare as strings.
|
|
249
|
+
*/
|
|
250
|
+
declare function needsReaccept(latest: Pick<AcceptanceRecord, "version"> | null, current: {
|
|
251
|
+
version: string;
|
|
252
|
+
material: boolean;
|
|
253
|
+
}): boolean;
|
|
254
|
+
|
|
181
255
|
/** A template as the API serves it: the authored document with its facts slots, plus its hash. */
|
|
182
256
|
interface LegalTemplate extends DocumentSource {
|
|
183
257
|
/** A translation made from an older master — show the Danish one or a notice. */
|
|
@@ -214,4 +288,4 @@ declare function getDocument(opts: {
|
|
|
214
288
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
215
289
|
declare function resolveTemplate(template: DocumentSource, facts: ProductFacts): LegalDocument;
|
|
216
290
|
|
|
217
|
-
export { type Block, 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, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getDocument, getTemplate, listDocuments, placeholdersIn, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, verifyTemplate };
|
|
291
|
+
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, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,80 @@ declare function createLegalCache(opts: LegalCacheOptions): {
|
|
|
178
178
|
settled(doc: DocId, locale: Locale): Promise<void>;
|
|
179
179
|
};
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* F110.6 — terms acceptances and GDPR consents live in BID («Samtykke» on the BID
|
|
183
|
+
* account), never in an app's own database (owner, 1/11 2026; D-ae49a8). These are
|
|
184
|
+
* thin, typed calls to BID's app API. Call them from your app's SERVER with the
|
|
185
|
+
* user's access token from the BID login — the same token as /api/app/profile.
|
|
186
|
+
* BID derives the user (sub) and the product from that token; nothing you send can
|
|
187
|
+
* point at another user or another product.
|
|
188
|
+
*/
|
|
189
|
+
/** The one place BID's address lives in this package. */
|
|
190
|
+
declare const BID_URL = "https://id.broberg.ai";
|
|
191
|
+
type AcceptedDoc = "terms" | "dpa";
|
|
192
|
+
interface AcceptanceRecord {
|
|
193
|
+
sub: string;
|
|
194
|
+
product: string;
|
|
195
|
+
doc: AcceptedDoc;
|
|
196
|
+
version: string;
|
|
197
|
+
contentHash: string;
|
|
198
|
+
/** Epoch ms, set by BID. */
|
|
199
|
+
acceptedAt: number;
|
|
200
|
+
clientId: string;
|
|
201
|
+
}
|
|
202
|
+
interface ConsentRecord {
|
|
203
|
+
sub: string;
|
|
204
|
+
product: string;
|
|
205
|
+
purpose: string;
|
|
206
|
+
granted: boolean;
|
|
207
|
+
version: string;
|
|
208
|
+
contentHash: string;
|
|
209
|
+
/** Epoch ms, set by BID. */
|
|
210
|
+
at: number;
|
|
211
|
+
/** "bid-account" when the user withdrew on their BID account. */
|
|
212
|
+
clientId: string;
|
|
213
|
+
}
|
|
214
|
+
interface BidCallOptions {
|
|
215
|
+
/** The user's access token from the BID login. Never a token of yours. */
|
|
216
|
+
accessToken: string;
|
|
217
|
+
fetch?: typeof fetch;
|
|
218
|
+
baseUrl?: string;
|
|
219
|
+
}
|
|
220
|
+
declare class BidConsentError extends Error {
|
|
221
|
+
readonly status: number;
|
|
222
|
+
readonly code: string;
|
|
223
|
+
constructor(status: number, code: string, message: string);
|
|
224
|
+
}
|
|
225
|
+
/** Our hashes are 64 hex; BID wants «sha256:<64 hex>». Accepts either. */
|
|
226
|
+
declare function toBidHash(contentHash: string): string;
|
|
227
|
+
/** Record that the user accepted this version of a document. Returns the row BID stored (read back). */
|
|
228
|
+
declare function recordAcceptance(opts: BidCallOptions, a: {
|
|
229
|
+
doc: AcceptedDoc;
|
|
230
|
+
version: string;
|
|
231
|
+
contentHash: string;
|
|
232
|
+
}): Promise<AcceptanceRecord>;
|
|
233
|
+
/** The user's latest acceptance of a document for YOUR product, or null. */
|
|
234
|
+
declare function getAcceptance(opts: BidCallOptions, doc: AcceptedDoc): Promise<AcceptanceRecord | null>;
|
|
235
|
+
/** Record a GDPR consent given (granted:true) or withdrawn (granted:false). Returns the stored row (read back). */
|
|
236
|
+
declare function recordConsent(opts: BidCallOptions, c: {
|
|
237
|
+
purpose: string;
|
|
238
|
+
granted: boolean;
|
|
239
|
+
version: string;
|
|
240
|
+
contentHash: string;
|
|
241
|
+
}): Promise<ConsentRecord>;
|
|
242
|
+
/** The CURRENT state of a consent for YOUR product (latest row), or null if never asked. Read it before you use the data. */
|
|
243
|
+
declare function getConsent(opts: BidCallOptions, purpose: string): Promise<ConsentRecord | null>;
|
|
244
|
+
/**
|
|
245
|
+
* Must the user accept the terms again? Yes when they never accepted, or when the
|
|
246
|
+
* current terms are a MATERIAL change and newer than what they accepted. A
|
|
247
|
+
* non-material change is announced, not re-asked (terms «Ændringer»).
|
|
248
|
+
* Versions are ISO dates, so they compare as strings.
|
|
249
|
+
*/
|
|
250
|
+
declare function needsReaccept(latest: Pick<AcceptanceRecord, "version"> | null, current: {
|
|
251
|
+
version: string;
|
|
252
|
+
material: boolean;
|
|
253
|
+
}): boolean;
|
|
254
|
+
|
|
181
255
|
/** A template as the API serves it: the authored document with its facts slots, plus its hash. */
|
|
182
256
|
interface LegalTemplate extends DocumentSource {
|
|
183
257
|
/** A translation made from an older master — show the Danish one or a notice. */
|
|
@@ -214,4 +288,4 @@ declare function getDocument(opts: {
|
|
|
214
288
|
/** A finished document from a template you fetched from the API + your own facts. */
|
|
215
289
|
declare function resolveTemplate(template: DocumentSource, facts: ProductFacts): LegalDocument;
|
|
216
290
|
|
|
217
|
-
export { type Block, 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, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getDocument, getTemplate, listDocuments, placeholdersIn, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, verifyTemplate };
|
|
291
|
+
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, PLACEHOLDERS, type Placeholder, type ProductFacts, type ResolvedBlock, type ResolvedSection, SOURCES, type Section, canonicalJson, createLegalCache, createLibrary, getAcceptance, getConsent, getDocument, getTemplate, listDocuments, needsReaccept, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
package/dist/index.js
CHANGED
|
@@ -279,7 +279,7 @@ var TERMS_DA = {
|
|
|
279
279
|
id: "indhold",
|
|
280
280
|
heading: "Dit indhold",
|
|
281
281
|
blocks: [
|
|
282
|
-
{ id: "indhold.p1", type: "p", text: "Du ejer det indhold, du l\xE6gger i tjenesten. Vi bruger det til at levere tjenesten til dig og dem, du deler med, og som beskrevet i privatlivspolitikken
|
|
282
|
+
{ id: "indhold.p1", type: "p", text: "Du ejer det indhold, du l\xE6gger i tjenesten. Vi bruger det til at levere tjenesten til dig og dem, du deler med, og som beskrevet i privatlivspolitikken." }
|
|
283
283
|
]
|
|
284
284
|
},
|
|
285
285
|
{
|
|
@@ -784,6 +784,68 @@ function createLegalCache(opts) {
|
|
|
784
784
|
};
|
|
785
785
|
}
|
|
786
786
|
|
|
787
|
+
// src/bid.ts
|
|
788
|
+
var BID_URL = "https://id.broberg.ai";
|
|
789
|
+
var BidConsentError = class extends Error {
|
|
790
|
+
constructor(status, code, message) {
|
|
791
|
+
super(message);
|
|
792
|
+
this.status = status;
|
|
793
|
+
this.code = code;
|
|
794
|
+
this.name = "BidConsentError";
|
|
795
|
+
}
|
|
796
|
+
status;
|
|
797
|
+
code;
|
|
798
|
+
};
|
|
799
|
+
function toBidHash(contentHash) {
|
|
800
|
+
return contentHash.startsWith("sha256:") ? contentHash : `sha256:${contentHash}`;
|
|
801
|
+
}
|
|
802
|
+
async function call(opts, method, path, body) {
|
|
803
|
+
const res = await (opts.fetch ?? fetch)(`${opts.baseUrl ?? BID_URL}${path}`, {
|
|
804
|
+
method,
|
|
805
|
+
headers: { authorization: `Bearer ${opts.accessToken}`, ...body ? { "content-type": "application/json" } : {} },
|
|
806
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
807
|
+
signal: AbortSignal.timeout(1e4)
|
|
808
|
+
});
|
|
809
|
+
let json = null;
|
|
810
|
+
try {
|
|
811
|
+
json = await res.json();
|
|
812
|
+
} catch {
|
|
813
|
+
}
|
|
814
|
+
if (!res.ok) {
|
|
815
|
+
throw new BidConsentError(res.status, json?.error ?? `http_${res.status}`, `BID answered ${res.status}${json?.error ? ` ${json.error}` : ""} on ${method} ${path}`);
|
|
816
|
+
}
|
|
817
|
+
return json;
|
|
818
|
+
}
|
|
819
|
+
async function recordAcceptance(opts, a) {
|
|
820
|
+
const sent = { doc: a.doc, version: a.version, contentHash: toBidHash(a.contentHash) };
|
|
821
|
+
const row = await call(opts, "POST", "/api/app/terms-acceptance", sent);
|
|
822
|
+
if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
|
|
823
|
+
throw new BidConsentError(200, "not_echoed", "BID's stored acceptance does not match what was sent");
|
|
824
|
+
}
|
|
825
|
+
return row;
|
|
826
|
+
}
|
|
827
|
+
async function getAcceptance(opts, doc) {
|
|
828
|
+
const r = await call(opts, "GET", `/api/app/terms-acceptance?doc=${encodeURIComponent(doc)}`);
|
|
829
|
+
return r?.acceptance ?? null;
|
|
830
|
+
}
|
|
831
|
+
async function recordConsent(opts, c) {
|
|
832
|
+
const sent = { purpose: c.purpose, granted: c.granted, version: c.version, contentHash: toBidHash(c.contentHash) };
|
|
833
|
+
const row = await call(opts, "POST", "/api/app/consents", sent);
|
|
834
|
+
if (row?.purpose !== sent.purpose || row?.granted !== sent.granted || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
|
|
835
|
+
throw new BidConsentError(200, "not_echoed", "BID's stored consent does not match what was sent");
|
|
836
|
+
}
|
|
837
|
+
return row;
|
|
838
|
+
}
|
|
839
|
+
async function getConsent(opts, purpose) {
|
|
840
|
+
const r = await call(opts, "GET", `/api/app/consents?purpose=${encodeURIComponent(purpose)}`);
|
|
841
|
+
return r?.consent ?? null;
|
|
842
|
+
}
|
|
843
|
+
function needsReaccept(latest, current) {
|
|
844
|
+
if (!latest) return true;
|
|
845
|
+
if (latest.version === current.version) return false;
|
|
846
|
+
return current.material && current.version > latest.version;
|
|
847
|
+
}
|
|
848
|
+
|
|
787
849
|
// src/index.ts
|
|
788
850
|
function pick(doc, locale) {
|
|
789
851
|
const master = SOURCES.find((s) => s.doc === doc && s.locale === MASTER_LOCALE);
|
|
@@ -813,6 +875,6 @@ function resolveTemplate(template, facts) {
|
|
|
813
875
|
return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id });
|
|
814
876
|
}
|
|
815
877
|
|
|
816
|
-
export { DEFAULT_REFRESH_MS, DOC_IDS, EXAMPLE_FACTS, LEGAL_API_URL, MASTER_LOCALE, PLACEHOLDERS, SOURCES, canonicalJson, createLegalCache, createLibrary, getDocument, getTemplate, listDocuments, placeholdersIn, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, verifyTemplate };
|
|
878
|
+
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, placeholdersIn, recordAcceptance, recordConsent, renderHtml, resolveTemplate, sha256Hex, sourceHash, templateHash, toBidHash, verifyTemplate };
|
|
817
879
|
//# sourceMappingURL=index.js.map
|
|
818
880
|
//# sourceMappingURL=index.js.map
|