@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/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,9 +102,22 @@ 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
|
-
scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
|
|
103
|
-
scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
|
|
107
|
+
scan: (cbid, o) => request("POST", `/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
|
|
108
|
+
scanStatus: (cbid, o) => get(`/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
|
|
109
|
+
waitForScan: async (cbid, o) => {
|
|
110
|
+
const until = Date.now() + (o?.timeoutMs ?? 12e4);
|
|
111
|
+
for (; ; ) {
|
|
112
|
+
const left = until - Date.now();
|
|
113
|
+
const asked = Math.max(0, Math.min(6e4, left));
|
|
114
|
+
const t0 = Date.now();
|
|
115
|
+
const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
|
|
116
|
+
if (s.status !== "scanning" || until - Date.now() <= 0) return s;
|
|
117
|
+
const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
|
|
118
|
+
if (early > 0) await new Promise((r) => setTimeout(r, early));
|
|
119
|
+
}
|
|
120
|
+
},
|
|
104
121
|
ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
|
|
105
122
|
policy: (cbid, o) => request(
|
|
106
123
|
"GET",
|
|
@@ -114,11 +131,17 @@ function createCookieMunch(opts) {
|
|
|
114
131
|
blocked: (cbid) => get(`/sites/${enc(cbid)}/blocked`),
|
|
115
132
|
importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
|
|
116
133
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
|
|
135
|
+
retireCookie: (cbid, name, input, o) => request("POST", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input ?? {}),
|
|
136
|
+
unretireCookie: (async (cbid, name, o) => {
|
|
137
|
+
const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
|
|
138
|
+
return o?.dryRun ? out : void 0;
|
|
139
|
+
}),
|
|
140
|
+
undeclareCookie: (async (cbid, name, o) => {
|
|
141
|
+
const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
|
|
142
|
+
return o?.dryRun ? out : void 0;
|
|
143
|
+
}),
|
|
144
|
+
declareCookies: (cbid, cookies, o) => request("PUT", `/sites/${enc(cbid)}/cookies${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, { cookies, ...o?.replace ? { replace: true } : {} }),
|
|
122
145
|
snippet: (cbid, opts2) => get(`/sites/${enc(cbid)}/snippet${qs({ blockingmode: opts2?.blockingMode, culture: opts2?.culture })}`),
|
|
123
146
|
previewToken: (cbid, o) => request("POST", `/sites/${enc(cbid)}/preview-token`, o ?? {}),
|
|
124
147
|
verify: (cbid, method) => request("POST", `/sites/${enc(cbid)}/verify`, { method }),
|
|
@@ -185,6 +208,22 @@ function createCookieMunch(opts) {
|
|
|
185
208
|
await request("DELETE", `/brand-kits/${enc(id)}`);
|
|
186
209
|
}
|
|
187
210
|
},
|
|
211
|
+
rightsPage: {
|
|
212
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-page`),
|
|
213
|
+
put: (cbid, page, opts2) => request("PUT", `/sites/${enc(cbid)}/rights-page`, withBase(page, opts2)),
|
|
214
|
+
patch: (cbid, patch, opts2) => request("PATCH", `/sites/${enc(cbid)}/rights-page`, withBase(patch, opts2)),
|
|
215
|
+
dryRun: (cbid, page, opts2) => request(opts2?.mode === "put" ? "PUT" : "PATCH", `/sites/${enc(cbid)}/rights-page?dryRun=1`, page),
|
|
216
|
+
getPublished: (cbid) => get(`/sites/${enc(cbid)}/rights-page/published`),
|
|
217
|
+
publish: (cbid, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/publish`, withBase({}, opts2)),
|
|
218
|
+
versions: (cbid) => get(`/sites/${enc(cbid)}/rights-page/versions`),
|
|
219
|
+
rollback: (cbid, version, opts2) => request("POST", `/sites/${enc(cbid)}/rights-page/rollback`, withBase({ version }, opts2)),
|
|
220
|
+
listDomains: (cbid) => get(`/sites/${enc(cbid)}/rights-page/domains`),
|
|
221
|
+
addDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains`, { hostname }),
|
|
222
|
+
verifyDomain: (cbid, hostname) => request("POST", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}/verify`),
|
|
223
|
+
removeDomain: async (cbid, hostname) => {
|
|
224
|
+
await request("DELETE", `/sites/${enc(cbid)}/rights-page/domains/${enc(hostname)}`);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
188
227
|
identity: {
|
|
189
228
|
resolve: (identifiers) => request("POST", "/identity/resolve", { identifiers }),
|
|
190
229
|
link: (identifiers) => request("POST", "/identity/link", { identifiers }),
|
|
@@ -257,6 +296,10 @@ function createCookieMunch(opts) {
|
|
|
257
296
|
executors: () => get("/dsar/executors"),
|
|
258
297
|
connectExecutor: (input) => request("POST", "/dsar/executors", input),
|
|
259
298
|
updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
|
|
299
|
+
dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
|
|
300
|
+
dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
|
|
301
|
+
testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
|
|
302
|
+
executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
|
|
260
303
|
disconnectExecutor: async (id) => {
|
|
261
304
|
await request("DELETE", `/dsar/executors/${enc(id)}`);
|
|
262
305
|
},
|
|
@@ -287,7 +330,25 @@ function createCookieMunch(opts) {
|
|
|
287
330
|
usage: () => get("/usage"),
|
|
288
331
|
org: {
|
|
289
332
|
get: () => get("/org"),
|
|
290
|
-
update: (patch) => request("PATCH", "/org", patch)
|
|
333
|
+
update: (patch) => request("PATCH", "/org", patch),
|
|
334
|
+
mailProvider: {
|
|
335
|
+
get: () => get("/org/mail-provider"),
|
|
336
|
+
set: (input) => request("PUT", "/org/mail-provider", input),
|
|
337
|
+
remove: async () => {
|
|
338
|
+
await request("DELETE", "/org/mail-provider");
|
|
339
|
+
},
|
|
340
|
+
test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
|
|
341
|
+
},
|
|
342
|
+
rightsCaptcha: {
|
|
343
|
+
get: () => get("/org/rights-captcha"),
|
|
344
|
+
set: (input) => request("PUT", "/org/rights-captcha", input),
|
|
345
|
+
remove: () => request("DELETE", "/org/rights-captcha")
|
|
346
|
+
},
|
|
347
|
+
rightsIdentity: {
|
|
348
|
+
get: () => get("/org/rights-identity"),
|
|
349
|
+
set: (input) => request("PUT", "/org/rights-identity", input),
|
|
350
|
+
remove: () => request("DELETE", "/org/rights-identity")
|
|
351
|
+
}
|
|
291
352
|
},
|
|
292
353
|
audit: (limit) => get(`/audit${qs({ limit })}`),
|
|
293
354
|
assets: {
|
|
@@ -323,6 +384,19 @@ function createCookieMunch(opts) {
|
|
|
323
384
|
deadLetters: () => get("/webhooks/dead-letters"),
|
|
324
385
|
replayDeadLetter: (id) => request("POST", `/webhooks/dead-letters/${enc(id)}/replay`)
|
|
325
386
|
},
|
|
387
|
+
rightsLinks: {
|
|
388
|
+
create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
|
|
389
|
+
},
|
|
390
|
+
rightsCaptcha: {
|
|
391
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
|
|
392
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
|
|
393
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-captcha`)
|
|
394
|
+
},
|
|
395
|
+
rightsIdentity: {
|
|
396
|
+
get: (cbid) => get(`/sites/${enc(cbid)}/rights-identity`),
|
|
397
|
+
set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-identity`, input),
|
|
398
|
+
remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/rights-identity`)
|
|
399
|
+
},
|
|
326
400
|
subjects: {
|
|
327
401
|
consent: (subjectId) => get(`/subjects/${enc(subjectId)}/consent`)
|
|
328
402
|
},
|