mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-06 12:44:30 +08:00
[local-sync] remove /account API endpoint
Summary: It turns out we don't ever use the /account API endpoint. The GET /accounts endpoint was designed to query all accounts connected to a system for old K2, but we don't use that anymore. The environment variable protecting the endpoint isn't set anywhere. We used to `GET /account` from the N1 AccountStore to attempt to refresh the health of the accounts. The accompianing diff to this one makes that obsolete. We never need to query for the account health since the sync loop pushes it to us through `Actions.updateAccount`. We also never `DELETE /account` because our local-sync runs a function called `ensureK2Consistency` that compares its DB against the Nylas Mail `AccountStore`. This file has always been a huge source of confusion to me and a massive red herring for anyone trying to understand how the account system work. The accompyaning diff has more comments explaining the existing system Depends on https://phab.nylas.com/D3770 Test Plan: Manually boot N1. Ensure existing account works. Add a new account. Remove an account. Open the developer tools and check that all the tabs still work. Lots of grepping through the code base. Reviewers: halla, mark, juan, khamidou Reviewed By: juan, khamidou Differential Revision: https://phab.nylas.com/D3769
This commit is contained in:
parent
0b89947c13
commit
ddcd097c9b
1 changed files with 0 additions and 79 deletions
|
@ -1,79 +0,0 @@
|
|||
const Serialization = require('../serialization');
|
||||
const LocalDatabaseConnector = require('../../shared/local-database-connector');
|
||||
|
||||
module.exports = (server) => {
|
||||
if (process.env.ALLOW_LIST_ACCOUNTS) {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/accounts',
|
||||
config: {
|
||||
auth: false,
|
||||
description: 'Returns all accounts, only in dev mode. Only intended to easily link N1.',
|
||||
tags: ['accounts'],
|
||||
},
|
||||
handler: (request, reply) => {
|
||||
LocalDatabaseConnector.forShared().then((db) => {
|
||||
const {Account, AccountToken} = db;
|
||||
|
||||
// N1 assumes that the local sync engine uses the account IDs as the
|
||||
// auth tokens. K2 supports real auth tokens out of the box, but we
|
||||
// create ones that have value = accountId.
|
||||
Account.all().then((accounts) => {
|
||||
Promise.all(
|
||||
accounts.map(({id}) => AccountToken.create({accountId: id, value: id})
|
||||
)).finally(() =>
|
||||
reply(accounts.map((account) =>
|
||||
Object.assign(account.toJSON(), {id: `${account.id}`, account_token: `${account.id}`})
|
||||
))
|
||||
)
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/account',
|
||||
config: {
|
||||
description: 'Returns the current account.',
|
||||
notes: 'Notes go here',
|
||||
tags: ['accounts'],
|
||||
validate: {
|
||||
params: {
|
||||
},
|
||||
},
|
||||
response: {
|
||||
schema: Serialization.jsonSchema('Account'),
|
||||
},
|
||||
},
|
||||
handler: (request, reply) => {
|
||||
const account = request.auth.credentials;
|
||||
reply(Serialization.jsonStringify(account));
|
||||
},
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'DELETE',
|
||||
path: '/account',
|
||||
config: {
|
||||
description: 'Deletes the current account and all data from the Nylas Cloud.',
|
||||
notes: 'Notes go here',
|
||||
tags: ['accounts'],
|
||||
validate: {
|
||||
params: {
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: (request, reply) => {
|
||||
const account = request.auth.credentials;
|
||||
account.destroy().then((saved) =>
|
||||
LocalDatabaseConnector.destroyAccountDatabase(saved.id).then(() =>
|
||||
reply(Serialization.jsonStringify({status: 'success'}))
|
||||
)
|
||||
).catch((err) => {
|
||||
reply(err).code(500);
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Add table
Reference in a new issue