async function waitForExport(intentId) {
for (;;) {
const response = await fetch(
`${process.env.GROUND_API}/v2/microvaults/authorizations/${intentId}`,
{ headers: { Authorization: `Bearer ${process.env.GROUND_API_KEY}` } },
);
if (!response.ok) throw new Error(await response.text());
const authorization = await response.json();
if (["confirmed", "executed"].includes(authorization.status)) return authorization;
if (["rejected", "superseded", "expired"].includes(authorization.status)) {
throw new Error(`Export ended with ${authorization.status}`);
}
await new Promise((resolve) => setTimeout(resolve, 1500));
}
}