@cookiemunch/sdk 0.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Every published release, newest first. Dates are the day the version was cut.
4
4
 
5
+ ## 0.5.0 (2026-10-23)
6
+
7
+ - Added: `org.controller.get()` / `set()` / `remove()`: the organisation's own data-controller identity, named in rights-request notices filed without a `cbid`. Needs an unscoped key or the new `rights:write` scope.
8
+ - Added: `consentSyncSecret.get(cbid)` / `rotate(cbid)` / `remove(cbid)`: the per-site secret for hosted cross-device consent sync. `rotate` returns the secret once.
9
+ - Added: `mintConsentSyncToken({ secret, cbid, subject, ttlSeconds })`: signs the short-lived token your server hands the page for `CookieMunch.setSyncToken()`. It runs locally with no request.
10
+ - Added: `preferenceCenter.mintToken({ cbid, email | subjectId, ttlSeconds })`: mints the preference-centre token a signed-in visitor's page passes to `CookieMunch.setSubjectToken()`.
11
+
5
12
  ## 0.4.1 (2026-10-22)
6
13
 
7
14
  - Added: the `referally` cookie preset (`cookieDomain`, `cookieDays`, `category` parameters on `applyCookiePreset`).
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  createCookieMunch: () => createCookieMunch,
27
27
  getConsent: () => getConsent,
28
28
  isAllowed: () => isAllowed,
29
+ mintConsentSyncToken: () => mintConsentSyncToken,
29
30
  parseConsentValue: () => parseConsentValue,
30
31
  readConsent: () => readConsent,
31
32
  verifyWebhookSignature: () => verifyWebhookSignature
@@ -148,8 +149,23 @@ function verifyWebhookSignature(input) {
148
149
  return (0, import_node_crypto.timingSafeEqual)(got, want);
149
150
  }
150
151
 
152
+ // src/consent-sync.ts
153
+ var import_node_crypto2 = require("crypto");
154
+ var SUBJECT_RE = /^[A-Za-z0-9._:@+/=~-]{1,128}$/;
155
+ function mintConsentSyncToken(input) {
156
+ if (!input.secret) throw new Error("mintConsentSyncToken: secret is required");
157
+ if (!input.cbid) throw new Error("mintConsentSyncToken: cbid is required");
158
+ if (!SUBJECT_RE.test(input.subject)) throw new Error("mintConsentSyncToken: subject must be 1\u2013128 characters of A-Z a-z 0-9 . _ : @ + / = ~ -");
159
+ const ttl = Math.floor(input.ttlSeconds ?? 3600);
160
+ if (!(ttl >= 1 && ttl <= 86400)) throw new Error("mintConsentSyncToken: ttlSeconds must be between 1 and 86400");
161
+ const iat = Math.floor((input.now ?? Date.now()) / 1e3);
162
+ const payload = Buffer.from(JSON.stringify({ c: input.cbid, s: input.subject, iat, exp: iat + ttl })).toString("base64url");
163
+ const sig = (0, import_node_crypto2.createHmac)("sha256", input.secret).update(`cms1.${payload}`).digest("base64url");
164
+ return `cms1.${payload}.${sig}`;
165
+ }
166
+
151
167
  // src/index.ts
152
- var SDK_VERSION = "0.4.1";
168
+ var SDK_VERSION = "0.5.0";
153
169
  var CookieMunchApiError = class extends Error {
154
170
  constructor(status, message, code, body) {
155
171
  super(message);
@@ -451,6 +467,9 @@ function createCookieMunch(opts) {
451
467
  save: (subjectId, purposes) => request("POST", "/preferences", { subjectId, purposes }),
452
468
  get: (subjectId) => get(`/preferences/${enc(subjectId)}`)
453
469
  },
470
+ preferenceCenter: {
471
+ mintToken: (input) => request("POST", "/preference-center/tokens", input)
472
+ },
454
473
  members: {
455
474
  list: () => get("/members"),
456
475
  invite: (email, role) => request("POST", "/members", { email, role }),
@@ -481,6 +500,13 @@ function createCookieMunch(opts) {
481
500
  },
482
501
  test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
483
502
  },
503
+ controller: {
504
+ get: () => get("/org/controller"),
505
+ set: (input) => request("PUT", "/org/controller", input),
506
+ remove: async () => {
507
+ await request("DELETE", "/org/controller");
508
+ }
509
+ },
484
510
  rightsCaptcha: {
485
511
  get: () => get("/org/rights-captcha"),
486
512
  set: (input) => request("PUT", "/org/rights-captcha", input),
@@ -529,6 +555,11 @@ function createCookieMunch(opts) {
529
555
  rightsLinks: {
530
556
  create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
531
557
  },
558
+ consentSyncSecret: {
559
+ get: (cbid) => get(`/sites/${enc(cbid)}/consent-sync-secret`),
560
+ rotate: (cbid) => request("POST", `/sites/${enc(cbid)}/consent-sync-secret`),
561
+ remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/consent-sync-secret`)
562
+ },
532
563
  rightsCaptcha: {
533
564
  get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
534
565
  set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
@@ -564,6 +595,7 @@ function createCookieMunch(opts) {
564
595
  createCookieMunch,
565
596
  getConsent,
566
597
  isAllowed,
598
+ mintConsentSyncToken,
567
599
  parseConsentValue,
568
600
  readConsent,
569
601
  verifyWebhookSignature