import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import {procurementNavigation, activeProcurementEntry} from '../resources/js/lib/procurement-navigation.ts'; const base = 'http://127.0.0.1:8005'; const cookies = new Map(); let version = ''; async function request(path, {method = 'GET', body, inertia = false} = {}) { const response = await fetch(base + path, {method, redirect: 'manual', headers: { Accept: 'application/json', Cookie: [...cookies].map(([k,v]) => `${k}=${v}`).join('; '), ...(body ? {'Content-Type': 'application/x-www-form-urlencoded'} : {}), ...(inertia ? {'X-Inertia': 'true', 'X-Inertia-Version': version} : {}), }, ...(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(); let data; try {data = JSON.parse(text);} catch {} if (!data) { const page = text.match(/