@cookiemunch/sdk 0.2.0 → 0.4.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/dist/index.cjs CHANGED
@@ -175,6 +175,7 @@ function createCookieMunch(opts) {
175
175
  if (!doFetch) throw new Error("No fetch available; pass { fetch } in CookieMunchOptions.");
176
176
  async function request(method, path, body, raw = false) {
177
177
  const headers = { Authorization: `Bearer ${opts.apiKey}` };
178
+ if (opts.strictUnknownFields && method !== "GET") headers["Prefer"] = "strict-unknown-fields";
178
179
  const init = { method, headers };
179
180
  if (body !== void 0) {
180
181
  headers["Content-Type"] = "application/json";
@@ -212,9 +213,13 @@ function createCookieMunch(opts) {
212
213
  list: () => get("/sites"),
213
214
  create: (input) => request("POST", "/sites", input),
214
215
  get: (cbid) => get(`/sites/${enc(cbid)}`),
216
+ update: (cbid, patch, o) => request("PATCH", `/sites/${enc(cbid)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, patch),
215
217
  delete: async (cbid) => {
216
218
  await request("DELETE", `/sites/${enc(cbid)}`);
217
219
  },
220
+ listPartners: (cbid) => get(`/sites/${enc(cbid)}/partners`),
221
+ linkPartner: (cbid, input, o) => request("POST", `/sites/${enc(cbid)}/partners${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
222
+ unlinkPartner: (cbid, linkId) => request("DELETE", `/sites/${enc(cbid)}/partners/${enc(linkId)}`),
218
223
  getConfig: (cbid) => get(`/sites/${enc(cbid)}/config`),
219
224
  putConfig: (cbid, config, opts2) => request("PUT", `/sites/${enc(cbid)}/config${qs({ keep: opts2?.keep })}`, config),
220
225
  patchConfig: (cbid, config) => request("PATCH", `/sites/${enc(cbid)}/config`, config),
@@ -225,8 +230,20 @@ function createCookieMunch(opts) {
225
230
  ),
226
231
  lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
227
232
  cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
228
- scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
229
- scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
233
+ scan: (cbid, o) => request("POST", `/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
234
+ scanStatus: (cbid, o) => get(`/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
235
+ waitForScan: async (cbid, o) => {
236
+ const until = Date.now() + (o?.timeoutMs ?? 12e4);
237
+ for (; ; ) {
238
+ const left = until - Date.now();
239
+ const asked = Math.max(0, Math.min(6e4, left));
240
+ const t0 = Date.now();
241
+ const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
242
+ if (s.status !== "scanning" || until - Date.now() <= 0) return s;
243
+ const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
244
+ if (early > 0) await new Promise((r) => setTimeout(r, early));
245
+ }
246
+ },
230
247
  ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
231
248
  policy: (cbid, o) => request(
232
249
  "GET",
@@ -241,6 +258,19 @@ function createCookieMunch(opts) {
241
258
  importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
242
259
  applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
243
260
  declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
261
+ retireCookie: (cbid, name, input, o) => request("POST", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input ?? {}),
262
+ unretireCookie: (async (cbid, name, o) => {
263
+ const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
264
+ return o?.dryRun ? out : void 0;
265
+ }),
266
+ cookiePresets: (cbid) => get(`/sites/${enc(cbid)}/cookies/presets`),
267
+ applyCookiePreset: (cbid, vendor, params, o) => request("PUT", `/sites/${enc(cbid)}/cookies/presets/${enc(vendor)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, params ?? {}),
268
+ removeCookiePreset: (cbid, vendor, o) => request("DELETE", `/sites/${enc(cbid)}/cookies/presets/${enc(vendor)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`),
269
+ deleteObservedCookie: (async (cbid, name, o) => {
270
+ const out = await request("DELETE", `/sites/${enc(cbid)}/observed-cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
271
+ return o?.dryRun ? out : void 0;
272
+ }),
273
+ purgeObservedCookies: (cbid, input, o) => request("POST", `/sites/${enc(cbid)}/observed-cookies/purge${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
244
274
  undeclareCookie: (async (cbid, name, o) => {
245
275
  const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
246
276
  return o?.dryRun ? out : void 0;
@@ -287,7 +317,7 @@ function createCookieMunch(opts) {
287
317
  list: () => get("/dsar"),
288
318
  get: (id) => get(`/dsar/${enc(id)}`),
289
319
  create: (input) => request("POST", "/dsar", input),
290
- advance: (id, toStatus) => request("POST", `/dsar/${enc(id)}/advance`, { toStatus }),
320
+ advance: (id, toStatus, opts2) => request("POST", `/dsar/${enc(id)}/advance`, { toStatus, ...opts2?.messageToSubject !== void 0 ? { messageToSubject: opts2.messageToSubject } : {} }),
291
321
  response: (id) => request("GET", `/dsar/${enc(id)}/response`, void 0, true),
292
322
  erase: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/erase`, { cbid, stamp }),
293
323
  export: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/export`, { cbid, stamp }),
@@ -401,6 +431,9 @@ function createCookieMunch(opts) {
401
431
  connectExecutor: (input) => request("POST", "/dsar/executors", input),
402
432
  updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
403
433
  dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
434
+ executorPresets: () => get("/dsar/executors/presets"),
435
+ upgradeExecutorPreset: (id, input = {}) => request("POST", `/dsar/executors/${enc(id)}/upgrade-preset`, input),
436
+ dryRunUpgradeExecutorPreset: (id, input = {}) => request("POST", `/dsar/executors/${enc(id)}/upgrade-preset?dryRun=1`, input),
404
437
  dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
405
438
  testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
406
439
  executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
@@ -429,9 +462,12 @@ function createCookieMunch(opts) {
429
462
  await request("DELETE", `/keys/${enc(prefix)}`);
430
463
  },
431
464
  roll: (prefix) => request("POST", `/keys/${enc(prefix)}/roll`),
432
- update: (prefix, patch) => request("PATCH", `/keys/${enc(prefix)}`, patch)
465
+ update: (prefix, patch) => request("PATCH", `/keys/${enc(prefix)}`, patch),
466
+ report: (o) => get(`/keys/report${qs({ unusedDays: o?.unusedDays, expiringDays: o?.expiringDays })}`)
433
467
  },
434
468
  usage: () => get("/usage"),
469
+ integrationHealth: (cbid) => get(`/integration-health${qs({ cbid })}`),
470
+ provision: (input, o) => request("POST", `/provision${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
435
471
  org: {
436
472
  get: () => get("/org"),
437
473
  update: (patch) => request("PATCH", "/org", patch),