@cookiemunch/sdk 0.4.0 → 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 ADDED
@@ -0,0 +1,51 @@
1
+ # Changelog: @cookiemunch/sdk
2
+
3
+ Every published release, newest first. Dates are the day the version was cut.
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
+
12
+ ## 0.4.1 (2026-10-22)
13
+
14
+ - Added: the `referally` cookie preset (`cookieDomain`, `cookieDays`, `category` parameters on `applyCookiePreset`).
15
+ - Added: every request sends `User-Agent: cookiemunch-js/<version>`; set your own with the `userAgent` option.
16
+
17
+ ## 0.4.0 (2026-10-19)
18
+
19
+ - Added: site PATCH (rename or move a site, keeping its cbid), integration health, `provision` and partner links.
20
+ - Added: the executor presets and canary health checks for connected systems; `connectExecutor` takes a `preset`.
21
+ - Added: declaration presets for the platforms a site is built on, observed-cookie removal and storage types on declarations.
22
+ - Added: opt-in strict writes and API key hygiene (`X-14`, `X-15`).
23
+
24
+ ## 0.3.0 (2026-10-15)
25
+
26
+ - Added: `retireCookie` and `unretireCookie`.
27
+ - Added: `scan` can wait for the result, and `waitForScan`.
28
+
29
+ ## 0.2.0 (2026-10-15)
30
+
31
+ - Added: executor webhook test and delivery log, with dry runs.
32
+ - Added: `purposes` (per-language text) and `dryRun` on declared cookies; `?lang=` on the public cookie feed.
33
+ - Added: document verification on rights-request intake answers (`trustEmailClaim`, `oidc_jwt`).
34
+ - Added: rights-page identity configuration.
35
+ - Fixed: design warnings say what happened and notices are not blamed on Accept.
36
+
37
+ ## 0.1.2 (2026-10-15)
38
+
39
+ - Changed: the package builds standalone from its public repository and is published with npm provenance.
40
+
41
+ ## 0.1.1 (2026-10-14)
42
+
43
+ - Added: `declareCookie`, bulk declare, `undeclareCookie` and applying a scan import.
44
+ - Added: `PUT ?keep=unspecified` and `null` in a PATCH removes the key.
45
+ - Added: `dryRunConfig`, and `lintConfig` with `designWarnings` on every config read and write.
46
+ - Added: `client.rightsPage`: draft, dry run, publish, versions, rollback (with `baseUpdatedAt` conflicts), custom domains, mail provider and account-linked rights links.
47
+ - Fixed: per-claim CNAME targets; a hostname already pointing at us is proven with the TXT token.
48
+
49
+ ## 0.1.0 (2026-10-14)
50
+
51
+ - First release: a typed client for the Cookie Munch Developer API (`/v1`): sites, config, consent log and stats, DSAR, vendors and RoPA.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cookie Munch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -22,9 +22,11 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  CONSENT_COOKIE_NAME: () => CONSENT_COOKIE_NAME,
24
24
  CookieMunchApiError: () => CookieMunchApiError,
25
+ SDK_VERSION: () => SDK_VERSION,
25
26
  createCookieMunch: () => createCookieMunch,
26
27
  getConsent: () => getConsent,
27
28
  isAllowed: () => isAllowed,
29
+ mintConsentSyncToken: () => mintConsentSyncToken,
28
30
  parseConsentValue: () => parseConsentValue,
29
31
  readConsent: () => readConsent,
30
32
  verifyWebhookSignature: () => verifyWebhookSignature
@@ -147,7 +149,23 @@ function verifyWebhookSignature(input) {
147
149
  return (0, import_node_crypto.timingSafeEqual)(got, want);
148
150
  }
149
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
+
150
167
  // src/index.ts
168
+ var SDK_VERSION = "0.5.0";
151
169
  var CookieMunchApiError = class extends Error {
152
170
  constructor(status, message, code, body) {
153
171
  super(message);
@@ -174,7 +192,7 @@ function createCookieMunch(opts) {
174
192
  const doFetch = opts.fetch ?? globalThis.fetch;
175
193
  if (!doFetch) throw new Error("No fetch available; pass { fetch } in CookieMunchOptions.");
176
194
  async function request(method, path, body, raw = false) {
177
- const headers = { Authorization: `Bearer ${opts.apiKey}` };
195
+ const headers = { Authorization: `Bearer ${opts.apiKey}`, "User-Agent": opts.userAgent ?? `cookiemunch-js/${SDK_VERSION}` };
178
196
  if (opts.strictUnknownFields && method !== "GET") headers["Prefer"] = "strict-unknown-fields";
179
197
  const init = { method, headers };
180
198
  if (body !== void 0) {
@@ -449,6 +467,9 @@ function createCookieMunch(opts) {
449
467
  save: (subjectId, purposes) => request("POST", "/preferences", { subjectId, purposes }),
450
468
  get: (subjectId) => get(`/preferences/${enc(subjectId)}`)
451
469
  },
470
+ preferenceCenter: {
471
+ mintToken: (input) => request("POST", "/preference-center/tokens", input)
472
+ },
452
473
  members: {
453
474
  list: () => get("/members"),
454
475
  invite: (email, role) => request("POST", "/members", { email, role }),
@@ -479,6 +500,13 @@ function createCookieMunch(opts) {
479
500
  },
480
501
  test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
481
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
+ },
482
510
  rightsCaptcha: {
483
511
  get: () => get("/org/rights-captcha"),
484
512
  set: (input) => request("PUT", "/org/rights-captcha", input),
@@ -527,6 +555,11 @@ function createCookieMunch(opts) {
527
555
  rightsLinks: {
528
556
  create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
529
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
+ },
530
563
  rightsCaptcha: {
531
564
  get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
532
565
  set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
@@ -558,9 +591,11 @@ function createCookieMunch(opts) {
558
591
  0 && (module.exports = {
559
592
  CONSENT_COOKIE_NAME,
560
593
  CookieMunchApiError,
594
+ SDK_VERSION,
561
595
  createCookieMunch,
562
596
  getConsent,
563
597
  isAllowed,
598
+ mintConsentSyncToken,
564
599
  parseConsentValue,
565
600
  readConsent,
566
601
  verifyWebhookSignature