@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.js CHANGED
@@ -54,6 +54,7 @@ function createCookieMunch(opts) {
54
54
  if (!doFetch) throw new Error("No fetch available; pass { fetch } in CookieMunchOptions.");
55
55
  async function request(method, path, body, raw = false) {
56
56
  const headers = { Authorization: `Bearer ${opts.apiKey}` };
57
+ if (opts.strictUnknownFields && method !== "GET") headers["Prefer"] = "strict-unknown-fields";
57
58
  const init = { method, headers };
58
59
  if (body !== void 0) {
59
60
  headers["Content-Type"] = "application/json";
@@ -91,9 +92,13 @@ function createCookieMunch(opts) {
91
92
  list: () => get("/sites"),
92
93
  create: (input) => request("POST", "/sites", input),
93
94
  get: (cbid) => get(`/sites/${enc(cbid)}`),
95
+ update: (cbid, patch, o) => request("PATCH", `/sites/${enc(cbid)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, patch),
94
96
  delete: async (cbid) => {
95
97
  await request("DELETE", `/sites/${enc(cbid)}`);
96
98
  },
99
+ listPartners: (cbid) => get(`/sites/${enc(cbid)}/partners`),
100
+ linkPartner: (cbid, input, o) => request("POST", `/sites/${enc(cbid)}/partners${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
101
+ unlinkPartner: (cbid, linkId) => request("DELETE", `/sites/${enc(cbid)}/partners/${enc(linkId)}`),
97
102
  getConfig: (cbid) => get(`/sites/${enc(cbid)}/config`),
98
103
  putConfig: (cbid, config, opts2) => request("PUT", `/sites/${enc(cbid)}/config${qs({ keep: opts2?.keep })}`, config),
99
104
  patchConfig: (cbid, config) => request("PATCH", `/sites/${enc(cbid)}/config`, config),
@@ -104,8 +109,20 @@ function createCookieMunch(opts) {
104
109
  ),
105
110
  lintConfig: (cbid, config, opts2) => request("POST", `/sites/${enc(cbid)}/config/lint${qs({ replace: opts2?.replace ? 1 : void 0 })}`, config),
106
111
  cookies: (cbid) => get(`/sites/${enc(cbid)}/cookies`),
107
- scan: (cbid) => request("POST", `/sites/${enc(cbid)}/scan`),
108
- scanStatus: (cbid) => get(`/sites/${enc(cbid)}/scan`),
112
+ scan: (cbid, o) => request("POST", `/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
113
+ scanStatus: (cbid, o) => get(`/sites/${enc(cbid)}/scan${qs({ wait: o?.wait })}`),
114
+ waitForScan: async (cbid, o) => {
115
+ const until = Date.now() + (o?.timeoutMs ?? 12e4);
116
+ for (; ; ) {
117
+ const left = until - Date.now();
118
+ const asked = Math.max(0, Math.min(6e4, left));
119
+ const t0 = Date.now();
120
+ const s = await get(`/sites/${enc(cbid)}/scan${qs({ wait: asked / 1e3 })}`);
121
+ if (s.status !== "scanning" || until - Date.now() <= 0) return s;
122
+ const early = Math.min(1e3, until - Date.now()) - (Date.now() - t0);
123
+ if (early > 0) await new Promise((r) => setTimeout(r, early));
124
+ }
125
+ },
109
126
  ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
110
127
  policy: (cbid, o) => request(
111
128
  "GET",
@@ -120,6 +137,19 @@ function createCookieMunch(opts) {
120
137
  importDeclaration: (cbid, data) => request("POST", `/sites/${enc(cbid)}/import`, { data }),
121
138
  applyImport: (cbid, data, o) => request("POST", `/sites/${enc(cbid)}/import${qs({ apply: "1", overwrite: o?.overwrite ? "1" : void 0 })}`, { data }),
122
139
  declareCookie: (cbid, name, input, o) => request("PUT", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
140
+ retireCookie: (cbid, name, input, o) => request("POST", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input ?? {}),
141
+ unretireCookie: (async (cbid, name, o) => {
142
+ const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}/retire${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
143
+ return o?.dryRun ? out : void 0;
144
+ }),
145
+ cookiePresets: (cbid) => get(`/sites/${enc(cbid)}/cookies/presets`),
146
+ applyCookiePreset: (cbid, vendor, params, o) => request("PUT", `/sites/${enc(cbid)}/cookies/presets/${enc(vendor)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, params ?? {}),
147
+ removeCookiePreset: (cbid, vendor, o) => request("DELETE", `/sites/${enc(cbid)}/cookies/presets/${enc(vendor)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`),
148
+ deleteObservedCookie: (async (cbid, name, o) => {
149
+ const out = await request("DELETE", `/sites/${enc(cbid)}/observed-cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
150
+ return o?.dryRun ? out : void 0;
151
+ }),
152
+ purgeObservedCookies: (cbid, input, o) => request("POST", `/sites/${enc(cbid)}/observed-cookies/purge${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
123
153
  undeclareCookie: (async (cbid, name, o) => {
124
154
  const out = await request("DELETE", `/sites/${enc(cbid)}/cookies/${enc(name)}${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`);
125
155
  return o?.dryRun ? out : void 0;
@@ -166,7 +196,7 @@ function createCookieMunch(opts) {
166
196
  list: () => get("/dsar"),
167
197
  get: (id) => get(`/dsar/${enc(id)}`),
168
198
  create: (input) => request("POST", "/dsar", input),
169
- advance: (id, toStatus) => request("POST", `/dsar/${enc(id)}/advance`, { toStatus }),
199
+ advance: (id, toStatus, opts2) => request("POST", `/dsar/${enc(id)}/advance`, { toStatus, ...opts2?.messageToSubject !== void 0 ? { messageToSubject: opts2.messageToSubject } : {} }),
170
200
  response: (id) => request("GET", `/dsar/${enc(id)}/response`, void 0, true),
171
201
  erase: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/erase`, { cbid, stamp }),
172
202
  export: (id, cbid, stamp) => request("POST", `/dsar/${enc(id)}/export`, { cbid, stamp }),
@@ -280,6 +310,9 @@ function createCookieMunch(opts) {
280
310
  connectExecutor: (input) => request("POST", "/dsar/executors", input),
281
311
  updateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}`, patch),
282
312
  dryRunConnectExecutor: (input) => request("POST", "/dsar/executors?dryRun=1", input),
313
+ executorPresets: () => get("/dsar/executors/presets"),
314
+ upgradeExecutorPreset: (id, input = {}) => request("POST", `/dsar/executors/${enc(id)}/upgrade-preset`, input),
315
+ dryRunUpgradeExecutorPreset: (id, input = {}) => request("POST", `/dsar/executors/${enc(id)}/upgrade-preset?dryRun=1`, input),
283
316
  dryRunUpdateExecutor: (id, patch) => request("PATCH", `/dsar/executors/${enc(id)}?dryRun=1`, patch),
284
317
  testExecutorWebhook: (id, delivery) => request("POST", `/dsar/executors/${enc(id)}/webhook/test`, delivery),
285
318
  executorWebhookDeliveries: (id) => get(`/dsar/executors/${enc(id)}/webhook/deliveries`),
@@ -308,9 +341,12 @@ function createCookieMunch(opts) {
308
341
  await request("DELETE", `/keys/${enc(prefix)}`);
309
342
  },
310
343
  roll: (prefix) => request("POST", `/keys/${enc(prefix)}/roll`),
311
- update: (prefix, patch) => request("PATCH", `/keys/${enc(prefix)}`, patch)
344
+ update: (prefix, patch) => request("PATCH", `/keys/${enc(prefix)}`, patch),
345
+ report: (o) => get(`/keys/report${qs({ unusedDays: o?.unusedDays, expiringDays: o?.expiringDays })}`)
312
346
  },
313
347
  usage: () => get("/usage"),
348
+ integrationHealth: (cbid) => get(`/integration-health${qs({ cbid })}`),
349
+ provision: (input, o) => request("POST", `/provision${qs({ dryRun: o?.dryRun ? "1" : void 0 })}`, input),
314
350
  org: {
315
351
  get: () => get("/org"),
316
352
  update: (patch) => request("PATCH", "/org", patch),