import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; const base = 'http://127.0.0.1:8005'; const cookies = new Map(); async function request(path, body) { const response = await fetch(base + path, { method: body ? 'POST' : 'GET', redirect: 'manual', headers: { Accept: 'application/json', Cookie: [...cookies] .map(([key, value]) => `${key}=${value}`) .join('; '), ...(body ? { 'Content-Type': 'application/x-www-form-urlencoded', 'X-XSRF-TOKEN': decodeURIComponent( cookies.get('XSRF-TOKEN') ?? '', ), } : {}), }, ...(body ? { body: new URLSearchParams(body) } : {}), }); for (const cookie of response.headers.getSetCookie()) { const pair = cookie.split(';', 1)[0], index = pair.indexOf('='); cookies.set(pair.slice(0, index), pair.slice(index + 1)); } const text = await response.text(); const match = text.match( /