@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 +8 -1
- package/dist/index.cjs +74 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +761 -26
- package/dist/index.d.ts +761 -26
- package/dist/index.js +74 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -28,13 +28,15 @@ function verifyWebhookSignature(input) {
|
|
|
28
28
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var CookieMunchApiError = class extends Error {
|
|
31
|
-
constructor(status, message, code) {
|
|
31
|
+
constructor(status, message, code, body) {
|
|
32
32
|
super(message);
|
|
33
33
|
this.name = "CookieMunchApiError";
|
|
34
34
|
this.status = status;
|
|
35
35
|
if (code !== void 0) this.code = code;
|
|
36
|
+
if (body !== void 0) this.body = body;
|
|
36
37
|
}
|
|
37
38
|
};
|
|
39
|
+
var withBase = (doc, opts) => opts?.baseUpdatedAt !== void 0 ? { ...doc, baseUpdatedAt: opts.baseUpdatedAt } : doc;
|
|
38
40
|
function qs(query) {
|
|
39
41
|
if (!query) return "";
|
|
40
42
|
const parts = [];
|
|
@@ -61,13 +63,15 @@ function createCookieMunch(opts) {
|
|
|
61
63
|
if (!res.ok) {
|
|
62
64
|
let message = `request failed with status ${res.status}`;
|
|
63
65
|
let code;
|
|
66
|
+
let parsed;
|
|
64
67
|
try {
|
|
65
68
|
const data = await res.json();
|
|
69
|
+
parsed = data;
|
|
66
70
|
if (typeof data.error === "string") message = data.error;
|
|
67
71
|
if (typeof data.code === "string") code = data.code;
|
|
68
72
|
} catch {
|
|
69
73
|
}
|
|
70
|
-
throw new CookieMunchApiError(res.status, message, code);
|
|
74
|
+
throw new CookieMunchApiError(res.status, message, code, parsed);
|
|
71
75
|
}
|
|
72
76
|
if (res.status === 204) return void 0;
|
|
73
77
|
if (raw) return res.text();
|
|
@@ -91,9 +95,14 @@ function createCookieMunch(opts) {
|
|
|
91
95
|
await request("DELETE", `/sites/${enc(cbid)}`);
|
|
92
96
|
},
|
|
93
97
|
getConfig: (cbid) => get(`/sites/${enc(cbid)}/config`),
|
|
94
|
-
putConfig: (cbid, config) => request("PUT", `/sites/${enc(cbid)}/config`, config),
|
|
98
|
+
putConfig: (cbid, config, opts2) => request("PUT", `/sites/${enc(cbid)}/config${qs({ keep: opts2?.keep })}`, config),
|
|
95
99
|
patchConfig: (cbid, config) => request("PATCH", `/sites/${enc(cbid)}/config`, config),
|
|
96
|
-
dryRunConfig: (cbid, config, opts2) => request(
|
|
100
|
+
dryRunConfig: (cbid, config, opts2) => request(
|
|
101
|
+
opts2?.mode === "put" ? "PUT" : "PATCH",
|
|
102
|
+
`/sites/${enc(cbid)}/config${qs({ dryRun: 1, keep: opts2?.mode === "put" ? opts2.keep : void 0 })}`,
|
|
103
|
+
config
|
|
104
|
+
),
|
|
105
|
+
lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
|
|
97
106
|
cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
|
|
98
107
|
scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
|
|
99
108
|
scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
|
|
@@ -109,6 +118,13 @@ function createCookieMunch(opts) {
|
|
|
109
118
|
banner: (cbid) => get(`/sites/${enc(cbid)}/banner`),
|
|
110
119
|
blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
|
|
111
120
|
importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
|
|
121
|
+
applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
|
|
122
|
+
declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
|
|
123
|
+
undeclareCookie: (async (cbid, name, o) => {
|
|
124
|
+
const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
|
|
125
|
+
return o?.dryRun ? out : void 0;
|
|
126
|
+
}),
|
|
127
|
+
declareCookies: (cbid, cookies, o) => request("PUT", `/sites/${enc(cbid)}/cookies${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, { cookies, ...o?.replace ? { replace: true } : {} }),
|
|
112
128
|
snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
|
|
113
129
|
previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
|
|
114
130
|
verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
|
|
@@ -156,7 +172,8 @@ function createCookieMunch(opts) {
|
|
|
156
172
|
export: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/export`, { cbid, stamp }),
|
|
157
173
|
delete: async (id) => {
|
|
158
174
|
await request("DELETE", `/dsar/${enc(id)}`);
|
|
159
|
-
}
|
|
175
|
+
},
|
|
176
|
+
markTest: (id) => request("POST", `/dsar/${enc(id)}/mark-test`)
|
|
160
177
|
},
|
|
161
178
|
vendors: {
|
|
162
179
|
list: () => get("/vendors"),
|
|
@@ -174,6 +191,22 @@ function createCookieMunch(opts) {
|
|
|
174
191
|
await request("DELETE", `/brand-kits/${enc(id)}`);
|
|
175
192
|
}
|
|
176
193
|
},
|
|
194
|
+
rightsPage: {
|
|
195
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-page`),
|
|
196
|
+
put: (cbid, page, opts2) => request("PUT", `/sites/${enc(cbid)}/rights-page`, withBase(page, opts2)),
|
|
197
|
+
patch: (cbid, patch, opts2) => request("PATCH", `/sites/${enc(cbid)}/rights-page`, withBase(patch, opts2)),
|
|
198
|
+
dryRun: (cbid, page, opts2) => request(opts2?.mode === "put" ? "PUT" : "PATCH", `/sites/${enc(cbid)}/rights-page?dryRun=1`, page),
|
|
199
|
+
getPublished: (cbid) => get(`/sites/${enc(cbid)}/rights-page/published`),
|
|
200
|
+
publish: (cbid, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/publish`, withBase({}, opts2)),
|
|
201
|
+
versions: (cbid) => get(`/sites/${enc(cbid)}/rights-page/versions`),
|
|
202
|
+
rollback: (cbid, version, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/rollback`, withBase({ version }, opts2)),
|
|
203
|
+
listDomains: (cbid) => get(`/sites/${enc(cbid)}/rights-page/domains`),
|
|
204
|
+
addDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains`, { hostname }),
|
|
205
|
+
verifyDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}/verify`),
|
|
206
|
+
removeDomain: async (cbid, hostname) => {
|
|
207
|
+
await request("DELETE", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}`);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
177
210
|
identity: {
|
|
178
211
|
resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
|
|
179
212
|
link: (identifiers) => request("POST", "/identity/link", { identifiers }),
|
|
@@ -246,6 +279,10 @@ function createCookieMunch(opts) {
|
|
|
246
279
|
executors: () => get("/dsar/executors"),
|
|
247
280
|
connectExecutor: (input) => request("POST", "/dsar/executors", input),
|
|
248
281
|
updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
|
|
282
|
+
dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
|
|
283
|
+
dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
|
|
284
|
+
testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
|
|
285
|
+
executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
|
|
249
286
|
disconnectExecutor: async (id) => {
|
|
250
287
|
await request("DELETE", `/dsar/executors/${enc(id)}`);
|
|
251
288
|
},
|
|
@@ -276,7 +313,25 @@ function createCookieMunch(opts) {
|
|
|
276
313
|
usage: () => get("/usage"),
|
|
277
314
|
org: {
|
|
278
315
|
get: () => get("/org"),
|
|
279
|
-
update: (patch) => request("PATCH", "/org", patch)
|
|
316
|
+
update: (patch) => request("PATCH", "/org", patch),
|
|
317
|
+
mailProvider: {
|
|
318
|
+
get: () => get("/org/mail-provider"),
|
|
319
|
+
set: (input) => request("PUT", "/org/mail-provider", input),
|
|
320
|
+
remove: async () => {
|
|
321
|
+
await request("DELETE", "/org/mail-provider");
|
|
322
|
+
},
|
|
323
|
+
test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
|
|
324
|
+
},
|
|
325
|
+
rightsCaptcha: {
|
|
326
|
+
get: () => get("/org/rights-captcha"),
|
|
327
|
+
set: (input) => request("PUT", "/org/rights-captcha", input),
|
|
328
|
+
remove: () => request("DELETE", "/org/rights-captcha")
|
|
329
|
+
},
|
|
330
|
+
rightsIdentity: {
|
|
331
|
+
get: () => get("/org/rights-identity"),
|
|
332
|
+
set: (input) => request("PUT", "/org/rights-identity", input),
|
|
333
|
+
remove: () => request("DELETE", "/org/rights-identity")
|
|
334
|
+
}
|
|
280
335
|
},
|
|
281
336
|
audit: (limit) => get(`/audit${qs({ limit })}`),
|
|
282
337
|
assets: {
|
|
@@ -312,6 +367,19 @@ function createCookieMunch(opts) {
|
|
|
312
367
|
deadLetters: () => get("/webhooks/dead-letters"),
|
|
313
368
|
replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
|
|
314
369
|
},
|
|
370
|
+
rightsLinks: {
|
|
371
|
+
create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
|
|
372
|
+
},
|
|
373
|
+
rightsCaptcha: {
|
|
374
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
|
|
375
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
|
|
376
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-captcha`)
|
|
377
|
+
},
|
|
378
|
+
rightsIdentity: {
|
|
379
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-identity`),
|
|
380
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-identity`, input),
|
|
381
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-identity`)
|
|
382
|
+
},
|
|
315
383
|
subjects: {
|
|
316
384
|
consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
|
|
317
385
|
},
|