A few changes to support linking to K2 via the new GUI

This commit is contained in:
Ben Gotow 2016-10-11 00:44:10 -07:00
parent f9f78968b1
commit e10e51ab5d
10 changed files with 39 additions and 8 deletions

View file

@ -2,6 +2,36 @@ const Serialization = require('../serialization');
const {DatabaseConnector} = require('nylas-core');
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) => {
DatabaseConnector.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}`, auth_token: `${account.id}`})
))
)
});
});
},
});
}
server.route({
method: 'GET',
path: '/account',

View file

@ -14,7 +14,7 @@ module.exports = (sequelize, Sequelize) => {
instanceMethods: {
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
account_id: this.accountId,
object: 'contact',
email: this.email,

View file

@ -40,7 +40,7 @@ module.exports = (sequelize, Sequelize) => {
},
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
object: 'file',
account_id: this.accountId,
message_id: this.messageId,

View file

@ -23,7 +23,7 @@ module.exports = (sequelize, Sequelize) => {
instanceMethods: {
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
account_id: this.accountId,
object: 'folder',
name: this.role,

View file

@ -20,7 +20,7 @@ module.exports = (sequelize, Sequelize) => {
instanceMethods: {
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
account_id: this.accountId,
object: 'label',
name: this.role,

View file

@ -98,7 +98,7 @@ module.exports = (sequelize, Sequelize) => {
// Message though and need to protect `this.date` from null
// errors.
return {
id: this.id,
id: `${this.id}`,
account_id: this.accountId,
object: 'message',
body: this.body,

View file

@ -14,7 +14,7 @@ module.exports = (sequelize, Sequelize) => {
instanceMethods: {
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
type: this.type,
status: this.status,
error: this.error,

View file

@ -49,7 +49,7 @@ module.exports = (sequelize, Sequelize) => {
}
const response = {
id: this.id,
id: `${this.id}`,
object: 'thread',
folders: this.folders,
labels: this.labels,

View file

@ -10,7 +10,7 @@ module.exports = (sequelize, Sequelize) => {
instanceMethods: {
toJSON: function toJSON() {
return {
id: this.id,
id: `${this.id}`,
event: this.event,
object: this.object,
objectId: this.objectId,

View file

@ -4,6 +4,7 @@ apps:
name : api
env :
PORT: 5100
ALLOW_LIST_ACCOUNTS : true
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
GMAIL_CLIENT_ID : "271342407743-nibas08fua1itr1utq9qjladbkv3esdm.apps.googleusercontent.com"