@cookiemunch/sdk 0.1.0 → 0.2.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
@@ -9,7 +9,7 @@ import { createCookieMunch, CookieMunchApiError } from '@cookiemunch/sdk';
9
9
 
10
10
  const fc = createCookieMunch({
11
11
  apiKey: process.env.COOKIEMUNCH_API_KEY!, // "fck_…"
12
- baseUrl: 'https://cmp.example.com', // "/v1" is appended automatically
12
+ baseUrl: 'https://api.cookiemunch.net', // "/v1" is appended automatically
13
13
  });
14
14
 
15
15
  const sites = await fc.sites.list();
@@ -30,11 +30,18 @@ runtimes; it defaults to the global `fetch`.
30
30
 
31
31
  - `me()`
32
32
  - `sites.list() / create(input) / get(cbid) / delete(cbid) / getConfig(cbid) / putConfig(cbid, config)`
33
+ - `sites.lintConfig(cbid, config, { replace? })` — consent-button parity: is Accept all pushed harder than Reject all? Returns `designWarnings`, `score`, `suggestedReject`; nothing is saved. Every config read/write also carries `designWarnings`.
33
34
  - `consent.stats(cbid, {from?,to?}) / log(cbid, {from?,to?,limit?}) / export(cbid, {from?,to?}) / receipt(cbid, stamp)`
34
35
  - `dsar.list() / create(input) / advance(id, toStatus)`
35
36
  - `vendors.list() / create(input)`
36
37
  - `ropa.list() / create(input)`
37
38
  - `webhooks.list() / create(input)`
39
+ - `rightsPage.get(cbid) / put(cbid, page, {baseUpdatedAt?}) / patch(cbid, patch, {baseUpdatedAt?}) / dryRun(cbid, page, {mode?}) / getPublished(cbid) / publish(cbid, {baseUpdatedAt?}) / versions(cbid) / rollback(cbid, version, {baseUpdatedAt?})` — pass the draft's `updatedAt` as `baseUpdatedAt` so a newer save is a 409 `draft_conflict`, never overwritten or published unseen; a rollback replaces the draft
40
+ - `rightsPage.listDomains(cbid) / addDomain(cbid, hostname) / verifyDomain(cbid, hostname) / removeDomain(cbid, hostname)` — the rights page on your own hostname
41
+ - `rightsLinks.create(cbid, { subject, rights?, ttlSeconds? })` — a signed, single-use rights-page link for a signed-in person
42
+ - `org.mailProvider.get() / set(input) / test(to?) / remove()` — your own provider for rights-request mail
43
+
44
+ These are the most used; the client covers every `/v1` operation (see the typed `CookieMunchClient`).
38
45
 
39
46
  `export()` returns the raw CSV string; all other methods return parsed JSON. Any
40
47
  non-2xx response throws a `CookieMunchApiError { status, code?, message }`. Error `code`
package/dist/index.cjs CHANGED
@@ -149,13 +149,15 @@ function verifyWebhookSignature(input) {
149
149
 
150
150
  // src/index.ts
151
151
  var CookieMunchApiError = class extends Error {
152
- constructor(status, message, code) {
152
+ constructor(status, message, code, body) {
153
153
  super(message);
154
154
  this.name = "CookieMunchApiError";
155
155
  this.status = status;
156
156
  if (code !== void 0) this.code = code;
157
+ if (body !== void 0) this.body = body;
157
158
  }
158
159
  };
160
+ var withBase = (doc, opts) => opts?.baseUpdatedAt !== void 0 ? { ...doc, baseUpdatedAt: opts.baseUpdatedAt } : doc;
159
161
  function qs(query) {
160
162
  if (!query) return "";
161
163
  const parts = [];
@@ -182,13 +184,15 @@ function createCookieMunch(opts) {
182
184
  if (!res.ok) {
183
185
  let message = `request failed with status ${res.status}`;
184
186
  let code;
187
+ let parsed;
185
188
  try {
186
189
  const data = await res.json();
190
+ parsed = data;
187
191
  if (typeof data.error === "string") message = data.error;
188
192
  if (typeof data.code === "string") code = data.code;
189
193
  } catch {
190
194
  }
191
- throw new CookieMunchApiError(res.status, message, code);
195
+ throw new CookieMunchApiError(res.status, message, code, parsed);
192
196
  }
193
197
  if (res.status === 204) return void 0;
194
198
  if (raw) return res.text();
@@ -212,9 +216,14 @@ function createCookieMunch(opts) {
212
216
  await request("DELETE", `/sites/${enc(cbid)}`);
213
217
  },
214
218
  getConfig: (cbid) => get(`/sites/${enc(cbid)}/config`),
215
- putConfig: (cbid, config) => request("PUT", `/sites/${enc(cbid)}/config`, config),
219
+ putConfig: (cbid, config, opts2) => request("PUT", `/sites/${enc(cbid)}/config${qs({ keep: opts2?.keep })}`, config),
216
220
  patchConfig: (cbid, config) => request("PATCH", `/sites/${enc(cbid)}/config`, config),
217
- dryRunConfig: (cbid, config, opts2) => request(opts2?.mode === "put" ? "PUT" : "PATCH", `/sites/${enc(cbid)}/config?dryRun=1`, config),
221
+ dryRunConfig: (cbid, config, opts2) => request(
222
+ opts2?.mode === "put" ? "PUT" : "PATCH",
223
+ `/sites/${enc(cbid)}/config${qs({ dryRun: 1, keep: opts2?.mode === "put" ? opts2.keep : void 0 })}`,
224
+ config
225
+ ),
226
+ lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
218
227
  cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
219
228
  scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
220
229
  scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
@@ -230,6 +239,13 @@ function createCookieMunch(opts) {
230
239
  banner: (cbid) => get(`/sites/${enc(cbid)}/banner`),
231
240
  blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
232
241
  importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
242
+ applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
243
+ declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
244
+ undeclareCookie: (async (cbid, name, o) => {
245
+ const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
246
+ return o?.dryRun ? out : void 0;
247
+ }),
248
+ declareCookies: (cbid, cookies, o) => request("PUT", `/sites/${enc(cbid)}/cookies${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, { cookies, ...o?.replace ? { replace: true } : {} }),
233
249
  snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
234
250
  previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
235
251
  verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
@@ -277,7 +293,8 @@ function createCookieMunch(opts) {
277
293
  export: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/export`, { cbid, stamp }),
278
294
  delete: async (id) => {
279
295
  await request("DELETE", `/dsar/${enc(id)}`);
280
- }
296
+ },
297
+ markTest: (id) => request("POST", `/dsar/${enc(id)}/mark-test`)
281
298
  },
282
299
  vendors: {
283
300
  list: () => get("/vendors"),
@@ -295,6 +312,22 @@ function createCookieMunch(opts) {
295
312
  await request("DELETE", `/brand-kits/${enc(id)}`);
296
313
  }
297
314
  },
315
+ rightsPage: {
316
+ get: (cbid) => get(`/sites/${enc(cbid)}/rights-page`),
317
+ put: (cbid, page, opts2) => request("PUT", `/sites/${enc(cbid)}/rights-page`, withBase(page, opts2)),
318
+ patch: (cbid, patch, opts2) => request("PATCH", `/sites/${enc(cbid)}/rights-page`, withBase(patch, opts2)),
319
+ dryRun: (cbid, page, opts2) => request(opts2?.mode === "put" ? "PUT" : "PATCH", `/sites/${enc(cbid)}/rights-page?dryRun=1`, page),
320
+ getPublished: (cbid) => get(`/sites/${enc(cbid)}/rights-page/published`),
321
+ publish: (cbid, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/publish`, withBase({}, opts2)),
322
+ versions: (cbid) => get(`/sites/${enc(cbid)}/rights-page/versions`),
323
+ rollback: (cbid, version, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/rollback`, withBase({ version }, opts2)),
324
+ listDomains: (cbid) => get(`/sites/${enc(cbid)}/rights-page/domains`),
325
+ addDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains`, { hostname }),
326
+ verifyDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}/verify`),
327
+ removeDomain: async (cbid, hostname) => {
328
+ await request("DELETE", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}`);
329
+ }
330
+ },
298
331
  identity: {
299
332
  resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
300
333
  link: (identifiers) => request("POST", "/identity/link", { identifiers }),
@@ -367,6 +400,10 @@ function createCookieMunch(opts) {
367
400
  executors: () => get("/dsar/executors"),
368
401
  connectExecutor: (input) => request("POST", "/dsar/executors", input),
369
402
  updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
403
+ dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
404
+ dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
405
+ testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
406
+ executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
370
407
  disconnectExecutor: async (id) => {
371
408
  await request("DELETE", `/dsar/executors/${enc(id)}`);
372
409
  },
@@ -397,7 +434,25 @@ function createCookieMunch(opts) {
397
434
  usage: () => get("/usage"),
398
435
  org: {
399
436
  get: () => get("/org"),
400
- update: (patch) => request("PATCH", "/org", patch)
437
+ update: (patch) => request("PATCH", "/org", patch),
438
+ mailProvider: {
439
+ get: () => get("/org/mail-provider"),
440
+ set: (input) => request("PUT", "/org/mail-provider", input),
441
+ remove: async () => {
442
+ await request("DELETE", "/org/mail-provider");
443
+ },
444
+ test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
445
+ },
446
+ rightsCaptcha: {
447
+ get: () => get("/org/rights-captcha"),
448
+ set: (input) => request("PUT", "/org/rights-captcha", input),
449
+ remove: () => request("DELETE", "/org/rights-captcha")
450
+ },
451
+ rightsIdentity: {
452
+ get: () => get("/org/rights-identity"),
453
+ set: (input) => request("PUT", "/org/rights-identity", input),
454
+ remove: () => request("DELETE", "/org/rights-identity")
455
+ }
401
456
  },
402
457
  audit: (limit) => get(`/audit${qs({ limit })}`),
403
458
  assets: {
@@ -433,6 +488,19 @@ function createCookieMunch(opts) {
433
488
  deadLetters: () => get("/webhooks/dead-letters"),
434
489
  replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
435
490
  },
491
+ rightsLinks: {
492
+ create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
493
+ },
494
+ rightsCaptcha: {
495
+ get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
496
+ set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
497
+ remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-captcha`)
498
+ },
499
+ rightsIdentity: {
500
+ get: (cbid) => get(`/sites/${enc(cbid)}/rights-identity`),
501
+ set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-identity`, input),
502
+ remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-identity`)
503
+ },
436
504
  subjects: {
437
505
  consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
438
506
  },