@cookiemunch/sdk 0.1.1 → 0.3.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 +8 -1
- package/dist/index.cjs +84 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +762 -24
- package/dist/index.d.ts +762 -24
- package/dist/index.js +84 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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://
|
|
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();
|
|
@@ -219,9 +223,22 @@ function createCookieMunch(opts) {
|
|
|
219
223
|
`/sites/${enc(cbid)}/config${qs({ dryRun: 1, keep: opts2?.mode === "put" ? opts2.keep : void 0 })}`,
|
|
220
224
|
config
|
|
221
225
|
),
|
|
226
|
+
lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
|
|
222
227
|
cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
|
|
223
|
-
scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
|
|
224
|
-
scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
|
|
228
|
+
scan: (cbid, o) => request("POST", `/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
|
|
229
|
+
scanStatus: (cbid, o) => get(`/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
|
|
230
|
+
waitForScan: async (cbid, o) => {
|
|
231
|
+
const until = Date.now() + (o?.timeoutMs ?? 12e4);
|
|
232
|
+
for (; ; ) {
|
|
233
|
+
const left = until - Date.now();
|
|
234
|
+
const asked = Math.max(0, Math.min(6e4, left));
|
|
235
|
+
const t0 = Date.now();
|
|
236
|
+
const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
|
|
237
|
+
if (s.status !== "scanning" || until - Date.now() <= 0) return s;
|
|
238
|
+
const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
|
|
239
|
+
if (early > 0) await new Promise((r) => setTimeout(r, early));
|
|
240
|
+
}
|
|
241
|
+
},
|
|
225
242
|
ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
|
|
226
243
|
policy: (cbid, o) => request(
|
|
227
244
|
"GET",
|
|
@@ -235,11 +252,17 @@ function createCookieMunch(opts) {
|
|
|
235
252
|
blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
|
|
236
253
|
importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
|
|
237
254
|
applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
|
|
238
|
-
declareCookie: (cbid, name, input) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}`, input),
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
255
|
+
declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
|
|
256
|
+
retireCookie: (cbid, name, input, o) => request("POST", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input ?? {}),
|
|
257
|
+
unretireCookie: (async (cbid, name, o) => {
|
|
258
|
+
const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
|
|
259
|
+
return o?.dryRun ? out : void 0;
|
|
260
|
+
}),
|
|
261
|
+
undeclareCookie: (async (cbid, name, o) => {
|
|
262
|
+
const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
|
|
263
|
+
return o?.dryRun ? out : void 0;
|
|
264
|
+
}),
|
|
265
|
+
declareCookies: (cbid, cookies, o) => request("PUT", `/sites/${enc(cbid)}/cookies${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, { cookies, ...o?.replace ? { replace: true } : {} }),
|
|
243
266
|
snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
|
|
244
267
|
previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
|
|
245
268
|
verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
|
|
@@ -306,6 +329,22 @@ function createCookieMunch(opts) {
|
|
|
306
329
|
await request("DELETE", `/brand-kits/${enc(id)}`);
|
|
307
330
|
}
|
|
308
331
|
},
|
|
332
|
+
rightsPage: {
|
|
333
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-page`),
|
|
334
|
+
put: (cbid, page, opts2) => request("PUT", `/sites/${enc(cbid)}/rights-page`, withBase(page, opts2)),
|
|
335
|
+
patch: (cbid, patch, opts2) => request("PATCH", `/sites/${enc(cbid)}/rights-page`, withBase(patch, opts2)),
|
|
336
|
+
dryRun: (cbid, page, opts2) => request(opts2?.mode === "put" ? "PUT" : "PATCH", `/sites/${enc(cbid)}/rights-page?dryRun=1`, page),
|
|
337
|
+
getPublished: (cbid) => get(`/sites/${enc(cbid)}/rights-page/published`),
|
|
338
|
+
publish: (cbid, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/publish`, withBase({}, opts2)),
|
|
339
|
+
versions: (cbid) => get(`/sites/${enc(cbid)}/rights-page/versions`),
|
|
340
|
+
rollback: (cbid, version, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/rollback`, withBase({ version }, opts2)),
|
|
341
|
+
listDomains: (cbid) => get(`/sites/${enc(cbid)}/rights-page/domains`),
|
|
342
|
+
addDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains`, { hostname }),
|
|
343
|
+
verifyDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}/verify`),
|
|
344
|
+
removeDomain: async (cbid, hostname) => {
|
|
345
|
+
await request("DELETE", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}`);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
309
348
|
identity: {
|
|
310
349
|
resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
|
|
311
350
|
link: (identifiers) => request("POST", "/identity/link", { identifiers }),
|
|
@@ -378,6 +417,10 @@ function createCookieMunch(opts) {
|
|
|
378
417
|
executors: () => get("/dsar/executors"),
|
|
379
418
|
connectExecutor: (input) => request("POST", "/dsar/executors", input),
|
|
380
419
|
updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
|
|
420
|
+
dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
|
|
421
|
+
dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
|
|
422
|
+
testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
|
|
423
|
+
executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
|
|
381
424
|
disconnectExecutor: async (id) => {
|
|
382
425
|
await request("DELETE", `/dsar/executors/${enc(id)}`);
|
|
383
426
|
},
|
|
@@ -408,7 +451,25 @@ function createCookieMunch(opts) {
|
|
|
408
451
|
usage: () => get("/usage"),
|
|
409
452
|
org: {
|
|
410
453
|
get: () => get("/org"),
|
|
411
|
-
update: (patch) => request("PATCH", "/org", patch)
|
|
454
|
+
update: (patch) => request("PATCH", "/org", patch),
|
|
455
|
+
mailProvider: {
|
|
456
|
+
get: () => get("/org/mail-provider"),
|
|
457
|
+
set: (input) => request("PUT", "/org/mail-provider", input),
|
|
458
|
+
remove: async () => {
|
|
459
|
+
await request("DELETE", "/org/mail-provider");
|
|
460
|
+
},
|
|
461
|
+
test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
|
|
462
|
+
},
|
|
463
|
+
rightsCaptcha: {
|
|
464
|
+
get: () => get("/org/rights-captcha"),
|
|
465
|
+
set: (input) => request("PUT", "/org/rights-captcha", input),
|
|
466
|
+
remove: () => request("DELETE", "/org/rights-captcha")
|
|
467
|
+
},
|
|
468
|
+
rightsIdentity: {
|
|
469
|
+
get: () => get("/org/rights-identity"),
|
|
470
|
+
set: (input) => request("PUT", "/org/rights-identity", input),
|
|
471
|
+
remove: () => request("DELETE", "/org/rights-identity")
|
|
472
|
+
}
|
|
412
473
|
},
|
|
413
474
|
audit: (limit) => get(`/audit${qs({ limit })}`),
|
|
414
475
|
assets: {
|
|
@@ -444,6 +505,19 @@ function createCookieMunch(opts) {
|
|
|
444
505
|
deadLetters: () => get("/webhooks/dead-letters"),
|
|
445
506
|
replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
|
|
446
507
|
},
|
|
508
|
+
rightsLinks: {
|
|
509
|
+
create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
|
|
510
|
+
},
|
|
511
|
+
rightsCaptcha: {
|
|
512
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
|
|
513
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
|
|
514
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-captcha`)
|
|
515
|
+
},
|
|
516
|
+
rightsIdentity: {
|
|
517
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-identity`),
|
|
518
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-identity`, input),
|
|
519
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-identity`)
|
|
520
|
+
},
|
|
447
521
|
subjects: {
|
|
448
522
|
consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
|
|
449
523
|
},
|