diff --git a/packages/client-app/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx b/packages/client-app/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx index afb3d66e8..8f26e48a2 100644 --- a/packages/client-app/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx +++ b/packages/client-app/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx @@ -2,7 +2,7 @@ import {shell} from 'electron' import React from 'react'; import ReactDOM from 'react-dom'; import {RetinaImg} from 'nylas-component-kit'; -import {NylasAPI, Actions} from 'nylas-exports'; +import {NylasAPIRequest, Actions} from 'nylas-exports'; import OnboardingActions from '../onboarding-actions'; import {runAuthValidation} from '../onboarding-helpers'; @@ -135,7 +135,7 @@ const CreatePageForForm = (FormComponent) => { errorFieldNames.push('email'); errorFieldNames.push('username'); } - if (NylasAPI.TimeoutErrorCodes.includes(err.statusCode)) { // timeout + if (NylasAPIRequest.TimeoutErrorCodes.includes(err.statusCode)) { // timeout errorMessage = "We were unable to reach your mail provider. Please try again." } diff --git a/packages/client-app/internal_packages/onboarding/lib/onboarding-actions.es6 b/packages/client-app/internal_packages/onboarding/lib/onboarding-actions.es6 index c2602e76f..33904dfdd 100644 --- a/packages/client-app/internal_packages/onboarding/lib/onboarding-actions.es6 +++ b/packages/client-app/internal_packages/onboarding/lib/onboarding-actions.es6 @@ -5,7 +5,7 @@ const OnboardingActions = Reflux.createActions([ "setAccountType", "moveToPreviousPage", "moveToPage", - "authenticationJSONReceived", + "identityJSONReceived", "accountJSONReceived", ]); diff --git a/packages/client-app/internal_packages/onboarding/lib/onboarding-helpers.es6 b/packages/client-app/internal_packages/onboarding/lib/onboarding-helpers.es6 index 9dafc09cf..0bc738957 100644 --- a/packages/client-app/internal_packages/onboarding/lib/onboarding-helpers.es6 +++ b/packages/client-app/internal_packages/onboarding/lib/onboarding-helpers.es6 @@ -3,14 +3,12 @@ import crypto from 'crypto'; import {CommonProviderSettings} from 'imap-provider-settings'; import { - N1CloudAPI, - NylasAPI, NylasAPIRequest, RegExpUtils, - Utils, MailsyncProcess, } from 'nylas-exports'; +const {makeRequest, rootURLForServer} = NylasAPIRequest; const IMAP_FIELDS = new Set([ "imap_host", @@ -41,40 +39,32 @@ function base64url(inBuffer) { .replace(/\//g, '_'); // Convert '/' to '_' } -const NO_AUTH = { user: '', pass: '', sendImmediately: true }; - -export async function makeGmailOAuthRequest(sessionKey) { - const remoteRequest = new NylasAPIRequest({ - api: N1CloudAPI, - options: { - path: `/auth/gmail/token?key=${sessionKey}`, - method: 'GET', - auth: NO_AUTH, - }, +export function makeGmailOAuthRequest(sessionKey) { + return makeRequest({ + server: 'accounts', + path: `/auth/gmail/token?key=${sessionKey}`, + method: 'GET', + auth: false, }); - return remoteRequest.run() } export async function authIMAPForGmail(tokenData) { - const localRequest = new NylasAPIRequest({ - api: NylasAPI, - options: { - path: `/auth`, - method: 'POST', - auth: NO_AUTH, - timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon - body: { - email: tokenData.email_address, - name: tokenData.name, - provider: 'gmail', - settings: { - xoauth2: tokenData.resolved_settings.xoauth2, - expiry_date: tokenData.resolved_settings.expiry_date, - }, + const localJSON = await makeRequest({ + server: 'accounts', + path: `/auth`, + method: 'POST', + auth: false, + timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon + body: { + email: tokenData.email_address, + name: tokenData.name, + provider: 'gmail', + settings: { + xoauth2: tokenData.resolved_settings.xoauth2, + expiry_date: tokenData.resolved_settings.expiry_date, }, }, }) - const localJSON = await localRequest.run() const account = Object.assign({}, localJSON); account.localToken = localJSON.account_token; account.cloudToken = tokenData.account_token; @@ -86,14 +76,14 @@ export function buildGmailSessionKey() { } export function buildGmailAuthURL(sessionKey) { - return `${N1CloudAPI.APIRoot}/auth/gmail?state=${sessionKey}`; + return `${rootURLForServer('accounts')}/auth/gmail?state=${sessionKey}`; } -export function runAuthValidation(accountInfo) { +export async function runAuthValidation(accountInfo) { const {username, type, email, name} = accountInfo; const data = { - id: Utils.generateTempId(), // TODO BG: Server will decide account ids + id: 'temp', provider: type, name: name, emailAddress: email, @@ -123,32 +113,23 @@ export function runAuthValidation(accountInfo) { // If this succeeds, send the received code to N1 server to register the account // Otherwise process the error message from the server and highlight UI as needed const proc = new MailsyncProcess(NylasEnv.getLoadSettings(), data); - return proc.test().then((accountJSON) => { - return accountJSON; - }); + const {account} = await proc.test(); - // TODO BG Re-enable cloud services - // return n1CloudIMAPAuthRequest.run().then((remoteJSON) => { - // const localSyncIMAPAuthRequest = new NylasAPIRequest({ - // api: NylasAPI, - // options: { - // path: `/auth`, - // method: 'POST', - // timeout: 1000 * 180, // Same timeout as server timeout (most requests are faster than 90s, but server validation can be slow in some cases) - // body: data, - // auth: { - // user: '', - // pass: '', - // sendImmediately: true, - // }, - // }, - // }) - // return localSyncIMAPAuthRequest.run().then((localJSON) => { - // const accountWithTokens = Object.assign({}, localJSON); - // accountWithTokens.localToken = localJSON.account_token; - // accountWithTokens.cloudToken = '';//remoteJSON.account_token; - // return accountWithTokens - // }) + delete data.id; + + const {id, account_token} = await makeRequest({ + server: 'accounts', + path: `/auth`, + method: 'POST', + timeout: 1000 * 180, // Same timeout as server timeout (most requests are faster than 90s, but server validation can be slow in some cases) + body: data, + auth: false, + }) + + return { + account: Object.assign({}, account, {id}), + cloudToken: account_token, + }; } export function isValidHost(value) { diff --git a/packages/client-app/internal_packages/onboarding/lib/onboarding-store.es6 b/packages/client-app/internal_packages/onboarding/lib/onboarding-store.es6 index 3b38af44b..7c86f23bc 100644 --- a/packages/client-app/internal_packages/onboarding/lib/onboarding-store.es6 +++ b/packages/client-app/internal_packages/onboarding/lib/onboarding-store.es6 @@ -18,13 +18,10 @@ class OnboardingStore extends NylasStore { constructor() { super(); - NylasEnv.config.onDidChange('env', this._onEnvChanged); - this._onEnvChanged(); - this.listenTo(OnboardingActions.moveToPreviousPage, this._onMoveToPreviousPage) this.listenTo(OnboardingActions.moveToPage, this._onMoveToPage) this.listenTo(OnboardingActions.accountJSONReceived, this._onAccountJSONReceived) - this.listenTo(OnboardingActions.authenticationJSONReceived, this._onAuthenticationJSONReceived) + this.listenTo(OnboardingActions.identityJSONReceived, this._onIdentityJSONReceived) this.listenTo(OnboardingActions.setAccountInfo, this._onSetAccountInfo); this.listenTo(OnboardingActions.setAccountType, this._onSetAccountType); ipcRenderer.on('set-account-type', (e, type) => { @@ -80,19 +77,6 @@ class OnboardingStore extends NylasStore { } } - _onEnvChanged = () => { - const env = NylasEnv.config.get('env') - if (['development', 'local'].includes(env)) { - this.welcomeRoot = "http://0.0.0.0:5555"; - } else if (env === 'experimental') { - this.welcomeRoot = "https://www-experimental.nylas.com"; - } else if (env === 'staging') { - this.welcomeRoot = "https://www-staging.nylas.com"; - } else { - this.welcomeRoot = "https://nylas.com"; - } - } - _onOnboardingComplete = () => { // When account JSON is received, we want to notify external services // that it succeeded. Unfortunately in this case we're likely to @@ -137,7 +121,7 @@ class OnboardingStore extends NylasStore { this.trigger(); } - _onAuthenticationJSONReceived = async (json) => { + _onIdentityJSONReceived = async (json) => { const isFirstAccount = AccountStore.accounts().length === 0; await IdentityStore.saveIdentity(json); @@ -145,8 +129,8 @@ class OnboardingStore extends NylasStore { setTimeout(() => { if (isFirstAccount) { this._onSetAccountInfo(Object.assign({}, this._accountInfo, { - name: `${json.firstname || ""} ${json.lastname || ""}`, - email: json.email, + name: `${json.firstName || ""} ${json.lastName || ""}`, + email: json.emailAddress, })); OnboardingActions.moveToPage('account-choose'); } else { diff --git a/packages/client-app/internal_packages/onboarding/lib/page-authenticate.jsx b/packages/client-app/internal_packages/onboarding/lib/page-authenticate.jsx index 1045ace3d..f4ff34e65 100644 --- a/packages/client-app/internal_packages/onboarding/lib/page-authenticate.jsx +++ b/packages/client-app/internal_packages/onboarding/lib/page-authenticate.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import {IdentityStore} from 'nylas-exports'; +import {NylasAPIRequest} from 'nylas-exports'; import {Webview} from 'nylas-component-kit'; import OnboardingActions from './onboarding-actions'; @@ -12,18 +12,18 @@ export default class AuthenticatePage extends React.Component { _src() { const n1Version = NylasEnv.getVersion(); - return `${IdentityStore.URLRoot}/onboarding?utm_medium=N1&utm_source=OnboardingPage&N1_version=${n1Version}&client_edition=basic` + return `${NylasAPIRequest.rootURLForServer('identity')}/onboarding?utm_medium=N1&utm_source=OnboardingPage&N1_version=${n1Version}&client_edition=basic` } _onDidFinishLoad = (webview) => { const receiveUserInfo = ` - var a = document.querySelector('#pro-account'); + var a = document.querySelector('#identity-result'); result = a ? a.innerText : null; `; webview.executeJavaScript(receiveUserInfo, false, (result) => { this.setState({ready: true, webviewLoading: false}); if (result !== null) { - OnboardingActions.authenticationJSONReceived(JSON.parse(result)); + OnboardingActions.identityJSONReceived(JSON.parse(atob(result))); } }); diff --git a/packages/client-app/internal_packages/onboarding/lib/page-initial-preferences.cjsx b/packages/client-app/internal_packages/onboarding/lib/page-initial-preferences.cjsx index 510c657ea..55389539e 100644 --- a/packages/client-app/internal_packages/onboarding/lib/page-initial-preferences.cjsx +++ b/packages/client-app/internal_packages/onboarding/lib/page-initial-preferences.cjsx @@ -3,7 +3,7 @@ path = require 'path' fs = require 'fs' _ = require 'underscore' {RetinaImg, Flexbox, ConfigPropContainer, NewsletterSignup} = require 'nylas-component-kit' -{EdgehillAPI, AccountStore} = require 'nylas-exports' +{AccountStore} = require 'nylas-exports' OnboardingActions = require('./onboarding-actions').default # NOTE: Temporarily copied from preferences module diff --git a/packages/client-app/internal_packages/participant-profile/lib/clearbit-data-source.coffee b/packages/client-app/internal_packages/participant-profile/lib/clearbit-data-source.coffee index 523a6de3c..f6626e5e7 100644 --- a/packages/client-app/internal_packages/participant-profile/lib/clearbit-data-source.coffee +++ b/packages/client-app/internal_packages/participant-profile/lib/clearbit-data-source.coffee @@ -1,5 +1,5 @@ # This file is in coffeescript just to use the existential operator! -{AccountStore, LegacyEdgehillAPI} = require 'nylas-exports' +{AccountStore} = require 'nylas-exports' MAX_RETRY = 10 @@ -12,7 +12,7 @@ module.exports = class ClearbitDataSource return Promise.resolve(null) new Promise (resolve, reject) => return; # TODO BG - req = LegacyEdgehillAPI.makeRequest({ + req = LegacyEdXgehillAPI.makeRequest({ authWithNylasAPI: true path: "/proxy/clearbit/#{@clearbitAPI()}/find?email=#{email}", }) diff --git a/packages/client-app/internal_packages/preferences/lib/tabs/preferences-identity.jsx b/packages/client-app/internal_packages/preferences/lib/tabs/preferences-identity.jsx index 2d6aed4ca..6a8280c45 100644 --- a/packages/client-app/internal_packages/preferences/lib/tabs/preferences-identity.jsx +++ b/packages/client-app/internal_packages/preferences/lib/tabs/preferences-identity.jsx @@ -67,7 +67,7 @@ class PreferencesIdentity extends React.Component { render() { const {identity} = this.state; - const {firstname, lastname, email} = identity; + const {firstName, lastName, emailAddress} = identity; const logout = () => Actions.logoutNylasIdentity() @@ -83,8 +83,8 @@ class PreferencesIdentity extends React.Component { />