@cookiemunch/sdk 0.6.0 → 0.7.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 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.7.1 (2026-10-24)
6
+
7
+ - Changed: `ConsentInsights.byLanguage` and `timeToDecision` are now filled in — opt-in by the banner's language, and a time-to-decision histogram with its median bucket — or `null` with `notRecorded` saying why.
8
+
9
+ ## 0.7.0 (2026-10-24)
10
+
11
+ - Added: `sandbox.get` / `create` / `delete` — a sandbox organisation made from yours: the same people and plan, never billed, test keys only, every rights request a test.
12
+ - Added: dated API versions — the `apiVersion` client option (sends `CookieMunch-Version`), `versions()`, and `keys.updateSelf({ apiVersion })`. Keys minted from 2026-10-24 are strict about unknown body fields by default; older keys behave as before.
13
+ - Added: `exchangeOperatorToken()` — swap an identity provider's token for a key that lasts at most an hour (RFC 8693 token exchange).
14
+ - Added: `sandbox` and `sandboxOf` on `me()`.
15
+
5
16
  ## 0.6.0 (2026-10-24)
6
17
 
7
18
  - Added: `dsar.openCase` / `getCase` / `cancelCase` / `caseReceipt` / `caseReceiptPdf` / `listByTrace` — rights cases fanned out to every connected system, with one `executeAfter`, a trace and a signed receipt.
package/dist/index.cjs CHANGED
@@ -26,9 +26,11 @@ __export(src_exports, {
26
26
  CookieMunchApiError: () => CookieMunchApiError,
27
27
  DEFAULT_JWKS_URL: () => DEFAULT_JWKS_URL,
28
28
  SDK_VERSION: () => SDK_VERSION,
29
+ TokenExchangeError: () => TokenExchangeError,
29
30
  canaryIdentityFor: () => canaryIdentityFor,
30
31
  consentSignaturePayload: () => consentSignaturePayload,
31
32
  createCookieMunch: () => createCookieMunch,
33
+ exchangeOperatorToken: () => exchangeOperatorToken,
32
34
  getConsent: () => getConsent,
33
35
  isAllowed: () => isAllowed,
34
36
  mintConsentSyncToken: () => mintConsentSyncToken,
@@ -426,8 +428,44 @@ async function runExecutorConformance(o) {
426
428
  }
427
429
  }
428
430
 
431
+ // src/token-exchange.ts
432
+ var TokenExchangeError = class extends Error {
433
+ constructor(error, status, description) {
434
+ super(description ? `${error}: ${description}` : error);
435
+ this.error = error;
436
+ this.status = status;
437
+ this.name = "TokenExchangeError";
438
+ }
439
+ };
440
+ async function exchangeOperatorToken(input) {
441
+ const base = (input.baseUrl ?? "https://api.cookiemunch.net").replace(/\/+$/, "");
442
+ const form = new URLSearchParams({
443
+ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
444
+ subject_token: input.subjectToken,
445
+ subject_token_type: `urn:ietf:params:oauth:token-type:${input.subjectTokenType ?? "access_token"}`,
446
+ scope: input.scope.join(" "),
447
+ resource: input.resource,
448
+ audience: "cookiemunch",
449
+ ...input.expiresIn !== void 0 ? { expires_in: String(input.expiresIn) } : {}
450
+ });
451
+ const res = await (input.fetch ?? fetch)(`${base}/v1/oauth/token`, {
452
+ method: "POST",
453
+ headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
454
+ body: form.toString()
455
+ });
456
+ const body = await res.json().catch(() => ({}));
457
+ if (!res.ok) {
458
+ throw new TokenExchangeError(typeof body.error === "string" ? body.error : `http_${res.status}`, res.status, typeof body.error_description === "string" ? body.error_description : void 0);
459
+ }
460
+ return {
461
+ accessToken: String(body.access_token),
462
+ expiresIn: Number(body.expires_in),
463
+ scope: String(body.scope ?? "").split(" ").filter(Boolean)
464
+ };
465
+ }
466
+
429
467
  // src/index.ts
430
- var SDK_VERSION = "0.6.0";
468
+ var SDK_VERSION = "0.7.1";
431
469
  var CookieMunchApiError = class extends Error {
432
470
  constructor(status, message, code, body) {
433
471
  super(message);
@@ -460,6 +498,7 @@ function createCookieMunch(opts) {
460
498
  async function request(method, path, body, raw = false, extraHeaders = {}) {
461
499
  const headers = { Authorization: `Bearer ${opts.apiKey}`, "User-Agent": opts.userAgent ?? `cookiemunch-js/${SDK_VERSION}`, ...extraHeaders };
462
500
  if (opts.strictUnknownFields && method !== "GET") headers["Prefer"] = "strict-unknown-fields";
501
+ if (opts.apiVersion) headers["CookieMunch-Version"] = opts.apiVersion;
463
502
  if (opts.secretRecipient && method !== "GET") headers["X-Secret-Recipient"] = opts.secretRecipient;
464
503
  for (const [k, v] of Object.entries(opts.headers ?? {})) headers[k] = v;
465
504
  const init = { method, headers };
@@ -803,12 +842,19 @@ function createCookieMunch(opts) {
803
842
  report: (o) => get(`/keys/report${qs({ unusedDays: o?.unusedDays, expiringDays: o?.expiringDays })}`),
804
843
  listStandard: () => get("/keys?shape=standard"),
805
844
  self: () => get("/keys/self"),
845
+ updateSelf: (input) => request("PATCH", "/keys/self", input),
806
846
  rollSelf: () => request("POST", "/keys/self/roll"),
807
847
  vend: (input) => request("POST", "/keys/vend", input),
808
848
  revokeLeaked: (report) => request("POST", "/keys/revoke_leaked", report)
809
849
  },
810
850
  usage: () => get("/usage"),
811
851
  entitlements: () => get("/entitlements"),
852
+ versions: () => get("/versions"),
853
+ sandbox: {
854
+ get: async () => (await get("/sandbox")).sandbox,
855
+ create: (input) => request("POST", "/sandbox", input ?? {}),
856
+ delete: () => request("DELETE", "/sandbox")
857
+ },
812
858
  integrationHealth: (cbid) => get(`/integration-health${qs({ cbid })}`),
813
859
  healthWaivers: {
814
860
  list: (cbid) => get(`/integration-health/waivers${qs({ cbid })}`),
@@ -940,9 +986,11 @@ function createCookieMunch(opts) {
940
986
  CookieMunchApiError,
941
987
  DEFAULT_JWKS_URL,
942
988
  SDK_VERSION,
989
+ TokenExchangeError,
943
990
  canaryIdentityFor,
944
991
  consentSignaturePayload,
945
992
  createCookieMunch,
993
+ exchangeOperatorToken,
946
994
  getConsent,
947
995
  isAllowed,
948
996
  mintConsentSyncToken,