Refractoring Stage 2 Add Refractor plan.md
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
const { randomUUID } = require('node:crypto');
|
||||
|
||||
function createAccountStore(secureStore, { createId = randomUUID } = {}) {
|
||||
return {
|
||||
async load() {
|
||||
try {
|
||||
const stored = await secureStore.load();
|
||||
if (Array.isArray(stored.accounts)) return stored;
|
||||
if (stored.email) {
|
||||
const account = { ...stored, id: stored.id || createId() };
|
||||
const migrated = { accounts: [account], activeId: account.id };
|
||||
await secureStore.save(migrated);
|
||||
return migrated;
|
||||
}
|
||||
return { accounts: [], activeId: null };
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') return null;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
save(store) {
|
||||
return secureStore.save(store);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { createAccountStore };
|
||||
Reference in New Issue
Block a user