@cookiemunch/sdk 0.1.1 → 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 +8 -1
- package/dist/index.cjs +65 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +662 -21
- package/dist/index.d.ts +662 -21
- package/dist/index.js +65 -8
- 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,6 +223,7 @@ 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
228
|
scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
|
|
224
229
|
scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
|
|
@@ -235,11 +240,12 @@ function createCookieMunch(opts) {
|
|
|
235
240
|
blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
|
|
236
241
|
importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
|
|
237
242
|
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
|
-
undeclareCookie: async (cbid, name) => {
|
|
240
|
-
await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}`);
|
|
241
|
-
|
|
242
|
-
|
|
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 } : {} }),
|
|
243
249
|
snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
|
|
244
250
|
previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
|
|
245
251
|
verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
|
|
@@ -306,6 +312,22 @@ function createCookieMunch(opts) {
|
|
|
306
312
|
await request("DELETE", `/brand-kits/${enc(id)}`);
|
|
307
313
|
}
|
|
308
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
|
+
},
|
|
309
331
|
identity: {
|
|
310
332
|
resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
|
|
311
333
|
link: (identifiers) => request("POST", "/identity/link", { identifiers }),
|
|
@@ -378,6 +400,10 @@ function createCookieMunch(opts) {
|
|
|
378
400
|
executors: () => get("/dsar/executors"),
|
|
379
401
|
connectExecutor: (input) => request("POST", "/dsar/executors", input),
|
|
380
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`),
|
|
381
407
|
disconnectExecutor: async (id) => {
|
|
382
408
|
await request("DELETE", `/dsar/executors/${enc(id)}`);
|
|
383
409
|
},
|
|
@@ -408,7 +434,25 @@ function createCookieMunch(opts) {
|
|
|
408
434
|
usage: () => get("/usage"),
|
|
409
435
|
org: {
|
|
410
436
|
get: () => get("/org"),
|
|
411
|
-
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
|
+
}
|
|
412
456
|
},
|
|
413
457
|
audit: (limit) => get(`/audit${qs({ limit })}`),
|
|
414
458
|
assets: {
|
|
@@ -444,6 +488,19 @@ function createCookieMunch(opts) {
|
|
|
444
488
|
deadLetters: () => get("/webhooks/dead-letters"),
|
|
445
489
|
replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
|
|
446
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
|
+
},
|
|
447
504
|
subjects: {
|
|
448
505
|
consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
|
|
449
506
|
},
|