MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / sweepE2e

Function sweepE2e

apps/host-cloudflare/scripts/preview.ts:320–373  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

318const E2E_MIN_AGE_MS = 24 * 60 * 60 * 1000;
319
320const sweepE2e = async (): Promise<void> => {
321 const now = Date.now();
322 const scripts = await cfList(`/accounts/${ACCOUNT}/workers/scripts`);
323 const stale = scripts.filter((script: any) => {
324 if (!E2E_STACK_PATTERN.test(String(script.id))) return false;
325 const created = Date.parse(script.created_on ?? "");
326 // Skip stacks younger than a day — they may belong to a live suite run.
327 return Number.isFinite(created) && now - created > E2E_MIN_AGE_MS;
328 });
329
330 const databases = stale.length > 0 ? await cfList(`/accounts/${ACCOUNT}/d1/database`) : [];
331 const apps = stale.length > 0 ? await cfList(`/accounts/${ACCOUNT}/access/apps`) : [];
332 for (const script of stale) {
333 const name = String(script.id);
334 await cfOk("DELETE", `/accounts/${ACCOUNT}/workers/scripts/${name}?force=true`);
335 process.stderr.write(`deleted e2e worker ${name}\n`);
336 const database = databases.find((d: any) => d.name === `${name}-db`);
337 if (database) {
338 await cfOk("DELETE", `/accounts/${ACCOUNT}/d1/database/${database.uuid}`);
339 process.stderr.write(`deleted e2e D1 ${name}-db\n`);
340 }
341 const app = apps.find((a: any) => a.name === name);
342 if (app) {
343 await cfOk("DELETE", `/accounts/${ACCOUNT}/access/apps/${app.id}`);
344 process.stderr.write(`deleted e2e Access app ${name}\n`);
345 }
346 }
347
348 // Seat revocation only — the user records stay (harmless), but they stop
349 // counting against the Zero Trust seat quota.
350 const users = await cfList(`/accounts/${ACCOUNT}/access/users`);
351 const seated = users.filter(
352 (user: any) =>
353 String(user.email ?? "").endsWith(E2E_SEAT_DOMAIN) &&
354 (user.access_seat === true || user.gateway_seat === true) &&
355 typeof user.seat_uid === "string",
356 );
357 if (seated.length > 0) {
358 await cfOk(
359 "PATCH",
360 `/accounts/${ACCOUNT}/access/seats`,
361 seated.map((user: any) => ({
362 seat_uid: user.seat_uid,
363 access_seat: false,
364 gateway_seat: false,
365 })),
366 );
367 for (const user of seated) process.stderr.write(`revoked seat for ${user.email}\n`);
368 }
369
370 process.stdout.write(
371 `${JSON.stringify({ deletedStacks: stale.map((s: any) => s.id), revokedSeats: seated.length })}\n`,
372 );
373};
374
375// --- main --------------------------------------------------------------------
376

Callers 1

preview.tsFile · 0.85

Calls 2

cfListFunction · 0.85
cfOkFunction · 0.85

Tested by

no test coverage detected