@cookiemunch/sdk 0.4.1 → 0.5.1
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 +11 -0
- package/dist/index.cjs +34 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -4
- package/dist/index.d.ts +101 -4
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Every published release, newest first. Dates are the day the version was cut.
|
|
4
4
|
|
|
5
|
+
## 0.5.1 (2026-10-23)
|
|
6
|
+
|
|
7
|
+
- Fixed: `sites.waitForScan` no longer sends one extra poll in the last few milliseconds before its deadline when the server answers at once.
|
|
8
|
+
|
|
9
|
+
## 0.5.0 (2026-10-23)
|
|
10
|
+
|
|
11
|
+
- 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.
|
|
12
|
+
- Added: `consentSyncSecret.get(cbid)` / `rotate(cbid)` / `remove(cbid)`: the per-site secret for hosted cross-device consent sync. `rotate` returns the secret once.
|
|
13
|
+
- 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.
|
|
14
|
+
- Added: `preferenceCenter.mintToken({ cbid, email | subjectId, ttlSeconds })`: mints the preference-centre token a signed-in visitor's page passes to `CookieMunch.setSubjectToken()`.
|
|
15
|
+
|
|
5
16
|
## 0.4.1 (2026-10-22)
|
|
6
17
|
|
|
7
18
|
- 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.
|
|
168
|
+
var SDK_VERSION = "0.5.1";
|
|
153
169
|
var CookieMunchApiError = class extends Error {
|
|
154
170
|
constructor(status, message, code, body) {
|
|
155
171
|
super(message);
|
|
@@ -241,7 +257,7 @@ function createCookieMunch(opts) {
|
|
|
241
257
|
const asked = Math.max(0, Math.min(6e4, left));
|
|
242
258
|
const t0 = Date.now();
|
|
243
259
|
const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
|
|
244
|
-
if (s.status !== "scanning" || until - Date.now()
|
|
260
|
+
if (s.status !== "scanning" || until - Date.now() < 50) return s;
|
|
245
261
|
const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
|
|
246
262
|
if (early > 0) await new Promise((r) => setTimeout(r, early));
|
|
247
263
|
}
|
|
@@ -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
|