@cookiemunch/sdk 0.2.0 → 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/dist/index.cjs CHANGED
@@ -225,8 +225,20 @@ function createCookieMunch(opts) {
225
225
  ),
226
226
  lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
227
227
  cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
228
- scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
229
- scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
228
+ scan: (cbid, o) => request("POST", `/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
229
+ scanStatus: (cbid, o) => get(`/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
230
+ waitForScan: async (cbid, o) => {
231
+ const until = Date.now() + (o?.timeoutMs ?? 12e4);
232
+ for (; ; ) {
233
+ const left = until - Date.now();
234
+ const asked = Math.max(0, Math.min(6e4, left));
235
+ const t0 = Date.now();
236
+ const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
237
+ if (s.status !== "scanning" || until - Date.now() <= 0) return s;
238
+ const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
239
+ if (early > 0) await new Promise((r) => setTimeout(r, early));
240
+ }
241
+ },
230
242
  ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
231
243
  policy: (cbid, o) => request(
232
244
  "GET",
@@ -241,6 +253,11 @@ function createCookieMunch(opts) {
241
253
  importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
242
254
  applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
243
255
  declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
256
+ retireCookie: (cbid, name, input, o) => request("POST", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input ?? {}),
257
+ unretireCookie: (async (cbid, name, o) => {
258
+ const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
259
+ return o?.dryRun ? out : void 0;
260
+ }),
244
261
  undeclareCookie: (async (cbid, name, o) => {
245
262
  const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
246
263
  return o?.dryRun ? out : void 0;