async function resetAllContractInstances(bru) { const axios = require("axios"); const baseUrl = bru.getEnvVar("baseUrl") || bru.getVar("baseUrl"); const playerId = bru.getEnvVar("playerId") || bru.getVar("playerId"); const jsonHeaders = { headers: { "Content-Type": "application/json" } }; // GET is capped (active + 10 completed); loop until no rows remain so older // completed instances outside the first page are cleared too. const maxPasses = 100; for (let pass = 0; pass < maxPasses; pass += 1) { const listResponse = await axios.get( `${baseUrl}/game/players/${playerId}/contracts`, jsonHeaders, ); if (listResponse.status !== 200) { throw new Error(`contracts GET failed: ${listResponse.status}`); } const ids = (listResponse.data.contracts || []).map((row) => row.contractInstanceId); if (ids.length === 0) { return; } await axios.post( `${baseUrl}/game/players/${playerId}/__dev/quest-fixture`, { schemaVersion: 1, resetContractInstanceIds: ids, }, jsonHeaders, ); } throw new Error( `resetAllContractInstances exceeded ${maxPasses} passes; contract list may still be non-empty`, ); } module.exports = { resetAllContractInstances };