Full Lifecycle with Deletion
This example covers creating, updating, and deleting master and content files, including changing the master file password.
import { Ulda } from '@zeroam/ulda'; async function fullLifecycle() { const ulda = new Ulda('your_api_key', 'https://api.0am.ch', true); const masterFileName = 'tempVault'; // Unique per API key const password = 'tempPass789'; const newPassword = 'newPass999'; try { // Create and connect to master file await ulda.createMasterFile(masterFileName, password); await ulda.connect(masterFileName, password); // Create content file const data = { note: 'Temporary note' }; await ulda.createContentFile(data, 'tempNote'); // Unique in master file console.log('Created note:', ulda.data['tempNote'].content); // Update content file await ulda.data['tempNote'].update({ note: 'Updated note', priority: 'high' }); console.log('Updated note:', ulda.data['tempNote'].content); // Change master file password await ulda.changeMasterFilePassword(newPassword); await ulda.connect(masterFileName, newPassword); console.log('Master file password changed'); // Delete content file await ulda.data['tempNote'].delete(); // Delete master file await ulda.deleteMasterFile(); } catch (error) { console.error('Error:', error.message); } } fullLifecycle().catch(console.error);
Success Output:
Created note: { note: 'Temporary note' } Updated note: { note: 'Updated note', priority: 'high' } Master file password changed
Notes:
- Outputs reflect successful
createContentFile
,update
,changeMasterFilePassword
,deleteContentFile
, anddeleteMasterFile
operations. - Deletion outputs use
'Success'
based on{ status: true }
return values.