@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/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();
|
|
@@ -98,6 +102,7 @@ function createCookieMunch(opts) {
|
|
|
98
102
|
`/sites/${enc(cbid)}/config${qs({ dryRun: 1, keep: opts2?.mode === "put" ? opts2.keep : void 0 })}`,
|
|
99
103
|
config
|
|
100
104
|
),
|
|
105
|
+
lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
|
|
101
106
|
cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
|
|
102
107
|
scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
|
|
103
108
|
scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
|
|
@@ -114,11 +119,12 @@ function createCookieMunch(opts) {
|
|
|
114
119
|
blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
|
|
115
120
|
importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
|
|
116
121
|
applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
|
|
117
|
-
declareCookie: (cbid, name, input) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}`, input),
|
|
118
|
-
undeclareCookie: async (cbid, name) => {
|
|
119
|
-
await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}`);
|
|
120
|
-
|
|
121
|
-
|
|
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 } : {} }),
|
|
122
128
|
snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
|
|
123
129
|
previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
|
|
124
130
|
verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
|
|
@@ -185,6 +191,22 @@ function createCookieMunch(opts) {
|
|
|
185
191
|
await request("DELETE", `/brand-kits/${enc(id)}`);
|
|
186
192
|
}
|
|
187
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
|
+
},
|
|
188
210
|
identity: {
|
|
189
211
|
resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
|
|
190
212
|
link: (identifiers) => request("POST", "/identity/link", { identifiers }),
|
|
@@ -257,6 +279,10 @@ function createCookieMunch(opts) {
|
|
|
257
279
|
executors: () => get("/dsar/executors"),
|
|
258
280
|
connectExecutor: (input) => request("POST", "/dsar/executors", input),
|
|
259
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`),
|
|
260
286
|
disconnectExecutor: async (id) => {
|
|
261
287
|
await request("DELETE", `/dsar/executors/${enc(id)}`);
|
|
262
288
|
},
|
|
@@ -287,7 +313,25 @@ function createCookieMunch(opts) {
|
|
|
287
313
|
usage: () => get("/usage"),
|
|
288
314
|
org: {
|
|
289
315
|
get: () => get("/org"),
|
|
290
|
-
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
|
+
}
|
|
291
335
|
},
|
|
292
336
|
audit: (limit) => get(`/audit${qs({ limit })}`),
|
|
293
337
|
assets: {
|
|
@@ -323,6 +367,19 @@ function createCookieMunch(opts) {
|
|
|
323
367
|
deadLetters: () => get("/webhooks/dead-letters"),
|
|
324
368
|
replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
|
|
325
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
|
+
},
|
|
326
383
|
subjects: {
|
|
327
384
|
consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
|
|
328
385
|
},
|