Commit graph

57 commits

Author SHA1 Message Date
Evan Morikawa c299fd9ebe perf(delta): replaces API delta stream with direct in-memory one
Summary:
This replaces the API delta stream with a direct in-memory one

Addresses T7300

Test Plan: manual

Reviewers: jackie, halla, juan

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3548
2016-12-21 18:42:52 -08:00
Juan Tejada 49c61fde0c [local-sync] Fix authentication notifications
Summary:
Associated N1 Diff: D3545

This commit ensures that authh notifications are showed when the
underlying sync worker fails and are cleared when an account is
successfully reconnected

To achieve this, we manually keep track and update syncStates where
appropriate via `Actions.updateAccount`, given that we have access to
N1's version of the account directly from local-sync.
Initially I was considering account delta stream to the cloud-api and the local-api, but that
just complicated things more than it helped.

This commit also fixes a bug with refreshing the gmail token in which we
we were only attempting a token refresh upon restarting the app

This addresses: T7346, T7305, T7335

Test Plan: Manual

Reviewers: halla, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3544
2016-12-21 07:22:39 -05:00
Evan Morikawa 93db26fdc7 [local-sync, isomophic-core] nicer logging 2016-12-20 16:04:28 -08:00
Evan Morikawa 5015d105b8 [isomorphic-core] fix sending on Office 365
Summary:
Fixed sending on Office 365
nodemailer needed a special tls flag beyond the standard SSL.
See: http://stackoverflow.com/questions/29812132/error-sending-email-using-nodemailer-via-office365-smtp-meanjs-scaffold

Test Plan: manual

Reviewers: juan, jackie, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3541
2016-12-20 13:08:30 -08:00
Evan Morikawa d55a2af2cd [cloud-api] refactor cloud API routes to use es6 & fix Gmail Auth
Summary:
This is a refactor of the auth APIs to use async/await. Gmail Auth is
pretty confusing and I wanted to make it cleaner to read and easier to
use. This is also part of the general API upgrade to modern ES6

This also fixes the Gmail auth error we saw at showcase

Test Plan: manual

Reviewers: halla, jackie, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3535
2016-12-19 09:25:07 -08:00
Juan Tejada 5810bb6b79 [local-sync] Fix issue with imap connection mail event
Summary:
See https://github.com/mscdex/node-imap/issues/585 for details.

This issue was causing us constantly run the sync loop without pauses,
i.e. every next sync loop was scheduled immediately.

Currently, when we receive a new `'mail'`event, we trigger a new sync loop. Previously, when this happened while a sync loop was already in progress we would just ignore the event. However, my recent patch keeps track of how many times we tried to start a sync loop while one was already in progress. If the number of times this happens is > 0, it will schedule the next sync loop immediately (as opposed to waiting a constant amount seconds before the next loop).

The problem is that this new logic is making the sync worker always schedule the next sync loop immediately (without pausing for a few seconds). This is due to the following chain of events (assume we are just syncing `all` and `trash` folders):

This commit is a temporary workaround to this problem.

Test Plan: manual

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3537
2016-12-19 08:08:59 -08:00
Evan Morikawa 39b0e6c3ee [isomorphic-core] add office365 in provider list 2016-12-16 18:51:11 -05:00
Juan Tejada abc5f35255 [local-sync] Ensure send runs fast, clean up multisend tasks
Summary:
Associated N1 Diff: D3530

This commit converts multi-send from a 3 step process into a 2 step
process

The first step creates the base message and sends a message per
recipient, each with its customized message body for tracking.

The second step reconciles all sent messages, specifically removing any
sent messages created by gmail, and saving the correct message to the
sent folder

This commit also ensures that we run the send tasks immediately by
ensuring we restart the sync loop if its already running

Test Plan: Manual

Reviewers: evan, jackie, halla

Reviewed By: jackie, halla

Differential Revision: https://phab.nylas.com/D3529
2016-12-16 14:41:20 -08:00
Evan Morikawa d095551e90 [isomorphic-core] add office365 auth support
Summary:
Adds support for office 365
Depends on D3532

Test Plan: manual

Reviewers: jackie, halla, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3533
2016-12-16 16:53:05 -05:00
Karim Hamidou 101b99f4a7 [feat] Refresh Gmail access tokens when needed
Summary:
This is a small patch but it's pretty complex, because of the numbers of moving parts. Gmail has two types of tokens, access and refresh tokens. Access tokens have a limited shelf life of one hour. After that they expire and you need to use your refresh token to get a new one.

We've decided to do the access token generation on the server, because we don't feel comfortable giving our users both our Google client id and secret. To do that, I've added an endpoint, `/gmail/auth/refresh` which returns a valid access token as well as an expiration date for the token.

The only place where we handle token expiration is in the sync workers. Before trying opening a new connection we check if our access token is expired. If yes, we get a new one from the API. If there's an issue doing this, we notify N1 using `NylasAPIHelpers.handleAuthenticationFailure`.

There's a second patch for N1 with tiny related fixes.

Test Plan: Tested manually. Will need to test more in the real world.

Reviewers: evan, jackie, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3522
2016-12-16 11:38:45 -08:00
Evan Morikawa 1d254a7aaa [*] Add basic babel toolchain
Summary:
Adds babel to K2
Creates a simple build script so it'll run on prod.

Test Plan: manual

Reviewers: jackie, halla, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3527
2016-12-16 13:08:21 -05:00
Juan Tejada e17b6d8d17 [local-sync]: Move sendmail-client and errors to isomorphic-core
Summary:
Move sendmail-client and errors to isomorphic-core, given that they will
probably be used by cloud-workers (plugin backends) and cloud-api

Depends on D3510

Test Plan: Manual

Reviewers: halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3512
2016-12-15 12:29:56 -08:00
Juan Tejada b6d8459d50 [local-sync] Report folder syncState to N1
Summary:
Associated N1 diff: D3515

Stop ignoring deltas for Folder.syncState updates

Test Plan: Manual

Reviewers: mark, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3514
2016-12-15 11:08:20 -08:00
Juan Tejada b79488ae43 [local-sync, cloud-api, cloud-workers] Fix msg id collision, tracking and sending issues, some refactoring
Summary:
This diff solves a few separate issues from T7313, T7316, T7282, and it refactors
the send code a little bit.

Initially, the problem that led to this diff was generating message ids that
wouldn't collide (which was causing errors in the message-processor). Collisions
in ids were being caused by messages that contained the exact same participants,
subject and date (most likely due bots or scripts sending emails in quick
succession)

To prevent collisions this commit adds the `message-id` header as part of the
database message id, and ensures that we set it correctly before sending, and
that it remains consistent through send, multi-send, and the sync loop.

During the refactor and review, I removed some code that assumed that we were
syncing drafts (which we aren't), and also fixes a few other known and
unknown issues around sending, message creation, and tracking, like assigning
the correct date header (we were previously assigning the draft creation date
from within N1), fixing the tracking regex, among other smaller bugs/typos.

Will address inline TODOs in a separate diff

Test Plan: TODO!!! I will add tests in another diff

Reviewers: evan, halla, jackie, khamidou

Reviewed By: halla, jackie

Differential Revision: https://phab.nylas.com/D3507
2016-12-14 19:35:48 -08:00
Mark Hahnenberg cfc8d3e315 [local-sync] Implement /thread/search endpoint for generic IMAP
Summary: See title

Test Plan: Run locally

Reviewers: juan, evan

Reviewed By: juan, evan

Maniphest Tasks: T7281

Differential Revision: https://phab.nylas.com/D3498
2016-12-14 11:50:22 -08:00
Mark Hahnenberg b47cd28d89 [local-sync] Implement /threads/search endpoint for Gmail
Summary: See title

Test Plan: Ran it locally

Reviewers: khamidou, juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D3496
2016-12-13 13:44:00 -08:00
Christine Spang 587f7787a6 fix(local-sync): Fix charset interpretation in message parsing
Summary:
This commit fixes the following bugs in message parsing:
- we were unilaterally decoding MIME bodies as UTF-8; instead, decode according
  to the charset data in the mimepart header
- '7bit' content-transfer-encoding means us-ascii, NOT utf-7
- only interpret valid content-transfer-encodings (previously we were trying
  to treat various charsets as transfer-encodings)
- clearer naming: s/values/parsedMessage/
- unify snippet cleanup between plaintext & stripped HTML (merging
  whitespace etc.)

Test Plan: units tests coming

Reviewers: juan

Differential Revision: https://phab.nylas.com/D3491
2016-12-09 11:01:04 -08:00
Evan Morikawa edbf869ff7 [isomorphic-core] add more auth error states 2016-12-07 10:10:49 -08:00
Evan Morikawa 6ac46d1079 remove console log 2016-12-06 17:20:43 -08:00
Evan Morikawa 7e485228af [cloud-api] fix param names 2016-12-06 16:03:31 -08:00
Evan Morikawa 8cbda7505a [*] fix auth 2016-12-06 16:03:31 -08:00
Evan Morikawa 2cbb90bb3b [*] DRY Auth 2016-12-06 16:03:31 -08:00
Evan Morikawa 896f981408 [isomorphic-core] extract AuthHelpers to DRY 2016-12-06 16:03:31 -08:00
Halla Moore e785d73bdc [local-sync, iso-core] feat(send): add finishing touches to gmail multi-send
Delete the sent messages that gmail automatically creates and save our
generic form of the draft as a sent message.
2016-12-06 11:37:47 -08:00
Karim Hamidou 04b1763965 [fix] Fix transaction creation for contacts
Summary:
Fixes T7283. We weren't creating deltas for contacts because we were inserting contacts using `UPSERT`, which requires us to add another sequelize hook.  Unfortunately, support for this hook is only available on sequelize 4.x.

I didn't want to upgrade our sequelize version right now and cause of bunch of mysterious failures, so I've simply changed the `UPSERT` to be either an `INSERT`or `UPDATE`. We didn't really need it anyway.

Test Plan: Checked that N1 was receiving contact deltas.

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T7283

Differential Revision: https://phab.nylas.com/D3481
2016-12-05 15:37:17 -08:00
Halla Moore 6a51036e48 [local-sync, iso-core, cloud-core] feat(send): add multi-send support
Also renames JSONType() -> buildJSONColumnOptions() and
JSONARRAYType() -> buildJSONARRAYColumnOptions() to prevent passing
those return values in as just the type value instead of the entire
options object.
2016-12-02 15:20:31 -08:00
Evan Morikawa d9f3edad0f [isomorphic-core] ignore folder deltas due to just syncState version issues 2016-12-02 16:25:42 -05:00
Juan Tejada f1491fa4cc fix observable disposable 2016-12-02 12:09:35 -08:00
Ben Gotow 5ff7a92197 [*] fix(deltas): 0 as first cursor, deltas from redis are already JSON 2016-12-01 18:54:26 -08:00
Ben Gotow 7712269402 [*] fix(deltas): Cloud-API not filtering deltas at all, refactor a few things
- Don’t need functions in delta.js which must be called to return promsies. Fun of promsies is that you don’t need to care when they’re built to attach a .then.

- Make boundary between route handler and delta stream builder more explicit, don’t do query parsing in helpers, always reply from handler.

- Remove pushJSON extension to outputStream which never actually received JSON.

- Remove `takeUntil` - disposing of the downstream observable should dispose of all the merged/upstream observables

- Rename inflate => stringify since the returned value is a string not an object.

- Remove support for delta streams with no cursors. Don’t think this was supposed to be a feature.

- Add accountId to Transaction models

- Make database hooks shared in isomorphic core
2016-12-01 18:41:46 -08:00
Ben Gotow 4b4ab726e2 [💄] fix eslint issues before they get overwhelming 2016-12-01 15:37:48 -08:00
Juan Tejada 2d932dd090 [*] Generate persistent id for Accounts based on email+settings
This also ensures that we can use the accountId as part of the ids for
other models, like labels and folders

Before this commit, labels and folders with the same name for different
accounts would have the same id, screwing things up in n1
2016-12-01 14:51:33 -08:00
Evan Morikawa aba77ca637 [cloud-api] add npm start for pm2 launch 2016-12-01 16:33:05 -05:00
Ben Gotow 209122c346 [cloud-api] Fix more broken package.jsons 2016-12-01 11:39:25 -08:00
Ben Gotow d8703b90c4 [local-sync] Fix deletion of labels 2016-11-30 16:26:53 -08:00
Juan Tejada 1470565bcf [local-sync] Fix observable for deltas
We were missing a return :'(
2016-11-30 16:12:35 -08:00
Evan Morikawa a36b1e1f28 [*] add delta endpoints and DRY deltaStreamBuilder
[cloud-core] add objectType to Metadata

[*] binding fixes to delta stream
2016-11-30 13:41:09 -05:00
Ben Gotow ece519553f fix(sync): Issue with CONDSTORE args not passed to fetch 2016-11-29 18:02:25 -08:00
Juan Tejada 2fe5f73401 [iso-core] Fix dependencyin model 2016-11-29 11:56:00 -08:00
Evan Morikawa fc24ffea63 [isomorphic-core]: move Transaction model to isomorphic-core 2016-11-29 13:57:19 -05:00
Halla Moore 10f62f6b5a [local-sync, iso-core] feat(send): Support basic sending for gmail accounts 2016-11-28 14:46:31 -08:00
Juan Tejada 64cb03f4cd Move non shared-models to local sync / remove duplicate DatabaseTypes 2016-11-26 12:48:48 -08:00
Ben Gotow cfb1356be6 fix(account): Include name 2016-11-23 15:24:41 -08:00
Ben Gotow e7386ff4ae Gmail auth: resolved settings tests 2016-11-23 15:23:46 -08:00
Ben Gotow 30a94a6c9b [cloud] Store resolved settings for returning to client 2016-11-23 14:51:39 -08:00
Evan Morikawa 78b96d24ca [local-sync] fix promise instance of check 2016-11-23 14:22:38 -08:00
Juan Tejada f98c38fef4 [iso-core]: Make loadModels reusable by cloud-core 2016-11-23 12:16:58 -08:00
Karim Hamidou c05bc8ee63 Remove redis dependency
Conflicts:
	packages/local-sync/src/local-sync-worker/sync-process-manager.js
2016-11-23 11:50:13 -08:00
Juan Tejada f2a032c87c [iso-core]: Update api for loadModels 2016-11-23 11:49:32 -08:00
Juan Tejada 654260b1a5 [iso-core] Use sequelize.import now that eval is enabled 2016-11-23 11:01:29 -08:00