async function deleteAttribute(attributeName) {
const response = await fetch(
`https://dev.app.boop.it/api/v1/attributes/${attributeName}`,
{
method: 'DELETE',
headers: {
'X-API-Key': 'your-api-key'
}
}
);
if (response.status === 204) {
return true; // Successfully deleted
}
if (response.status === 404) {
throw new Error(`Attribute '${attributeName}' not found`);
}
if (response.status === 409) {
const error = await response.json();
throw new Error(`Cannot delete: ${error.message}`);
}
throw new Error(`Unexpected error: ${response.statusText}`);
}
// Safe deletion with confirmation
async function safeDeleteAttribute(attributeName) {
try {
// First check if attribute exists
const attr = await getAttributeDetails(attributeName);
console.warn(
`About to delete attribute '${attributeName}' (${attr['data-format']})`
);
if (attr['attestation-required']) {
console.warn('This is an attestation-required attribute!');
}
// Perform deletion
await deleteAttribute(attributeName);
console.log(`Attribute '${attributeName}' deleted successfully`);
return true;
} catch (error) {
console.error(`Failed to delete attribute: ${error.message}`);
return false;
}
}