@broberg/legal 0.3.1 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @broberg/legal
2
2
 
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).**
3
+ **Status: 0.5.0. All five documents are v1.0, approved by the owner's lawyer (2/11 2026): `draft: false`, version and «gælder fra» 2026-11-02.**
4
4
 
5
5
  One set of legal documents for every broberg.ai product: `terms`, `privacy`, `trust`, `dpa` and
6
6
  `support`. The text is the same everywhere. Danish is the master and prevails; English sits beside it.
@@ -127,11 +127,48 @@ daily check and one more reason never to call it on a page view.
127
127
  the «UDKAST» marker (`renderHtml` does it for you).
128
128
  - Link all of them in your footer. **Never link users to legal.broberg.ai**; it redirects to broberg.ai.
129
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.
130
+ ### 6. Acceptance and consent: always «Samtykke» in BID
131
+
132
+ **Every app with login stores BOTH terms acceptances AND GDPR consents in BID («Samtykke» /
133
+ «Consent» on the BID account), and nowhere else** (owner's rule, 1/11 2026; components F110.6). Withdrawing a consent
134
+ also goes through BID. Never keep your own table for either.
135
+
136
+ - **Terms** are accepted at sign-up with an **unticked** «Jeg accepterer vilkårene» checkbox. Your
137
+ app SERVER records it in BID with the user's access token:
138
+ `POST /api/app/terms-acceptance { doc: "terms", version, contentHash: "sha256:<hex>" }`. It reads
139
+ the latest with `GET /api/app/terms-acceptance?doc=terms`. Ask again only when the current terms
140
+ are `material: true` and newer than the user's latest acceptance.
141
+ - **The privacy policy is never accepted.** It is linked and shown.
142
+ - **GDPR consent** (for example the physio apps' part-4 analysis) is its own thing: voluntary, never
143
+ a condition of use, and as easy to withdraw as to give. Record it with
144
+ `POST /api/app/consents { purpose, granted: true|false, version, contentHash }`. Before you use
145
+ the data, read the current state with `GET /api/app/consents?purpose=…`. The user can withdraw in
146
+ the app AND on their BID account; a withdrawal made in BID shows up on your next GET. Purposes
147
+ come from a fixed list in BID; ask bid to add yours.
148
+ - The app derives the product from your login client, so you can only touch your own users and your
149
+ own product.
150
+ - **Register your document pages with bid** (for example `terms → https://jams.party/vilkaar`) when
151
+ you start recording acceptances. BID's «Samtykke» page links «Læs vilkårene» to that address; an
152
+ app never sends a URL itself.
153
+ - **The routes are live (BID 2/11 2026), and this package has the calls** (server-side, with the
154
+ user's access token):
155
+
156
+ ```ts
157
+ import { getAcceptance, needsReaccept, recordAcceptance, recordConsent, getConsent, getTemplate } from "@broberg/legal";
158
+ const terms = getTemplate({ doc: "terms", locale: "da" });
159
+ const latest = await getAcceptance({ accessToken }, "terms");
160
+ if (needsReaccept(latest, terms)) { /* show the unticked checkbox; on accept: */
161
+ await recordAcceptance({ accessToken }, { doc: "terms", version: terms.version, contentHash: terms.hash });
162
+ }
163
+ const consent = await getConsent({ accessToken }, "health-text-analysis"); // read BEFORE using the data
164
+ await recordConsent({ accessToken }, { purpose: "health-text-analysis", granted: false, version, contentHash }); // withdraw
165
+ ```
166
+
167
+ Each record call returns the row BID stored, and throws `BidConsentError` if that row does not
168
+ match what you sent. Errors carry `status` and `code` (`invalid_token`, `invalid_doc`, …). BID's
169
+ «Samtykke» page shows only the version the user accepted; whether they must accept again is your
170
+ app's question, answered by `needsReaccept`. Rows stay (with only the user id) if the account is
171
+ deleted (owner 2/11 2026).
135
172
 
136
173
  ---
137
174
 
@@ -149,6 +186,10 @@ acceptance, so "which text did they accept?" has an exact answer.
149
186
  - **Placeholders** (`{customer.name}` and the rest) are a fixed list; an unknown one is refused.
150
187
  - Zero dependencies (a built-in SHA-256, proven against FIPS vectors and node:crypto).
151
188
 
189
+ **0.5.0 (F110.3):** v1.0 — the owner's lawyer has reviewed and approved all five documents. `draft` is now `false` everywhere (no «UDKAST» marker), and `version`/`effectiveFrom` move to `2026-11-02`. The wording is unchanged. **Terms are `material`, so `needsReaccept` answers `true` for anyone who accepted the draft (2026-11-01):** they are asked once to accept the approved v1.0, which is the point. The version stays an ISO date on purpose — it is compared as a string, and «1.0» would sort before «2026-11-01» and silently skip that re-acceptance.
190
+
191
+ **0.4.0 (F110.6):** BID calls: `recordAcceptance`/`getAcceptance`, `recordConsent`/`getConsent`, `needsReaccept`, `BidConsentError`, `BID_URL`. Additive.
192
+
152
193
  **0.3.1 (F110.16):** terms (da) «Dit indhold» no longer promises «pseudonymiseret analyse» for every product. Whether a product analyses is said only in the privacy policy, per product (facts.conversationAnalysis). The terms text and its hash changed (still a draft). Found by jam.
153
194
 
154
195
  **0.3.0 (F110.15):** `createLegalCache` (ported from jam's F001.79), `verifyTemplate`, `LEGAL_API_URL`;
package/dist/index.cjs CHANGED
@@ -249,10 +249,10 @@ var TERMS_DA = {
249
249
  doc: "terms",
250
250
  locale: "da",
251
251
  title: "Vilk\xE5r for brug",
252
- version: "2026-11-01",
253
- effectiveFrom: "2026-11-01",
252
+ version: "2026-11-02",
253
+ effectiveFrom: "2026-11-02",
254
254
  material: true,
255
- draft: true,
255
+ draft: false,
256
256
  sections: [
257
257
  {
258
258
  id: "hvem",
@@ -320,10 +320,10 @@ var PRIVACY_DA = {
320
320
  doc: "privacy",
321
321
  locale: "da",
322
322
  title: "Privatlivspolitik",
323
- version: "2026-11-01",
324
- effectiveFrom: "2026-11-01",
323
+ version: "2026-11-02",
324
+ effectiveFrom: "2026-11-02",
325
325
  material: false,
326
- draft: true,
326
+ draft: false,
327
327
  sections: [
328
328
  {
329
329
  id: "dataansvarlig",
@@ -441,10 +441,10 @@ var TRUST_DA = {
441
441
  doc: "trust",
442
442
  locale: "da",
443
443
  title: "Tillid og sikkerhed",
444
- version: "2026-11-01",
445
- effectiveFrom: "2026-11-01",
444
+ version: "2026-11-02",
445
+ effectiveFrom: "2026-11-02",
446
446
  material: false,
447
- draft: true,
447
+ draft: false,
448
448
  sections: [
449
449
  {
450
450
  id: "kort",
@@ -499,10 +499,10 @@ var DPA_DA = {
499
499
  doc: "dpa",
500
500
  locale: "da",
501
501
  title: "Databehandleraftale",
502
- version: "2026-11-01",
503
- effectiveFrom: "2026-11-01",
502
+ version: "2026-11-02",
503
+ effectiveFrom: "2026-11-02",
504
504
  material: true,
505
- draft: true,
505
+ draft: false,
506
506
  sections: [
507
507
  {
508
508
  id: "parter",
@@ -610,10 +610,10 @@ var SUPPORT_DA = {
610
610
  doc: "support",
611
611
  locale: "da",
612
612
  title: "Supportaftale",
613
- version: "2026-11-01",
614
- effectiveFrom: "2026-11-01",
613
+ version: "2026-11-02",
614
+ effectiveFrom: "2026-11-02",
615
615
  material: true,
616
- draft: true,
616
+ draft: false,
617
617
  sections: [
618
618
  {
619
619
  id: "parter",
@@ -786,6 +786,68 @@ function createLegalCache(opts) {
786
786
  };
787
787
  }
788
788
 
789
+ // src/bid.ts
790
+ var BID_URL = "https://id.broberg.ai";
791
+ var BidConsentError = class extends Error {
792
+ constructor(status, code, message) {
793
+ super(message);
794
+ this.status = status;
795
+ this.code = code;
796
+ this.name = "BidConsentError";
797
+ }
798
+ status;
799
+ code;
800
+ };
801
+ function toBidHash(contentHash) {
802
+ return contentHash.startsWith("sha256:") ? contentHash : `sha256:${contentHash}`;
803
+ }
804
+ async function call(opts, method, path, body) {
805
+ const res = await (opts.fetch ?? fetch)(`${opts.baseUrl ?? BID_URL}${path}`, {
806
+ method,
807
+ headers: { authorization: `Bearer ${opts.accessToken}`, ...body ? { "content-type": "application/json" } : {} },
808
+ body: body ? JSON.stringify(body) : void 0,
809
+ signal: AbortSignal.timeout(1e4)
810
+ });
811
+ let json = null;
812
+ try {
813
+ json = await res.json();
814
+ } catch {
815
+ }
816
+ if (!res.ok) {
817
+ throw new BidConsentError(res.status, json?.error ?? `http_${res.status}`, `BID answered ${res.status}${json?.error ? ` ${json.error}` : ""} on ${method} ${path}`);
818
+ }
819
+ return json;
820
+ }
821
+ async function recordAcceptance(opts, a) {
822
+ const sent = { doc: a.doc, version: a.version, contentHash: toBidHash(a.contentHash) };
823
+ const row = await call(opts, "POST", "/api/app/terms-acceptance", sent);
824
+ if (row?.doc !== sent.doc || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
825
+ throw new BidConsentError(200, "not_echoed", "BID's stored acceptance does not match what was sent");
826
+ }
827
+ return row;
828
+ }
829
+ async function getAcceptance(opts, doc) {
830
+ const r = await call(opts, "GET", `/api/app/terms-acceptance?doc=${encodeURIComponent(doc)}`);
831
+ return r?.acceptance ?? null;
832
+ }
833
+ async function recordConsent(opts, c) {
834
+ const sent = { purpose: c.purpose, granted: c.granted, version: c.version, contentHash: toBidHash(c.contentHash) };
835
+ const row = await call(opts, "POST", "/api/app/consents", sent);
836
+ if (row?.purpose !== sent.purpose || row?.granted !== sent.granted || row?.version !== sent.version || row?.contentHash !== sent.contentHash) {
837
+ throw new BidConsentError(200, "not_echoed", "BID's stored consent does not match what was sent");
838
+ }
839
+ return row;
840
+ }
841
+ async function getConsent(opts, purpose) {
842
+ const r = await call(opts, "GET", `/api/app/consents?purpose=${encodeURIComponent(purpose)}`);
843
+ return r?.consent ?? null;
844
+ }
845
+ function needsReaccept(latest, current) {
846
+ if (!latest) return true;
847
+ if (latest.version === current.version) return false;
848
+ return current.material && current.version > latest.version;
849
+ }
850
+
789
851
  // src/index.ts
790
852
  function pick(doc, locale) {
791
853
  const master = SOURCES.find((s) => s.doc === doc && s.locale === MASTER_LOCALE);
@@ -815,6 +877,8 @@ function resolveTemplate(template, facts) {
815
877
  return createLibrary([{ doc, locale, title, version, effectiveFrom, material, draft, translationOf, sections }], [facts]).getDocument({ doc, locale, product: facts.id });
816
878
  }
817
879
 
880
+ exports.BID_URL = BID_URL;
881
+ exports.BidConsentError = BidConsentError;
818
882
  exports.DEFAULT_REFRESH_MS = DEFAULT_REFRESH_MS;
819
883
  exports.DOC_IDS = DOC_IDS;
820
884
  exports.EXAMPLE_FACTS = EXAMPLE_FACTS;
@@ -825,15 +889,21 @@ exports.SOURCES = SOURCES;
825
889
  exports.canonicalJson = canonicalJson;
826
890
  exports.createLegalCache = createLegalCache;
827
891
  exports.createLibrary = createLibrary;
892
+ exports.getAcceptance = getAcceptance;
893
+ exports.getConsent = getConsent;
828
894
  exports.getDocument = getDocument;
829
895
  exports.getTemplate = getTemplate;
830
896
  exports.listDocuments = listDocuments;
897
+ exports.needsReaccept = needsReaccept;
831
898
  exports.placeholdersIn = placeholdersIn;
899
+ exports.recordAcceptance = recordAcceptance;
900
+ exports.recordConsent = recordConsent;
832
901
  exports.renderHtml = renderHtml;
833
902
  exports.resolveTemplate = resolveTemplate;
834
903
  exports.sha256Hex = sha256Hex;
835
904
  exports.sourceHash = sourceHash;
836
905
  exports.templateHash = templateHash;
906
+ exports.toBidHash = toBidHash;
837
907
  exports.verifyTemplate = verifyTemplate;
838
908
  //# sourceMappingURL=index.cjs.map
839
909
  //# sourceMappingURL=index.cjs.map