Skip to content

Instantly share code, notes, and snippets.

@Woody88
Created July 31, 2018 02:25
Show Gist options
  • Select an option

  • Save Woody88/dca0f790f26e102b92f98f00303f6211 to your computer and use it in GitHub Desktop.

Select an option

Save Woody88/dca0f790f26e102b92f98f00303f6211 to your computer and use it in GitHub Desktop.
exports.mkClient = function(){
var jsforce = require('jsforce');
return new jsforce.Client();
}
exports.getConnection = function(client, loginProps, connectionCancel, connectionError, left, right){
return function(onError, onSuccess) {
function loginHandler(err, result){
if (err != null)
return left( connectionError( err.message ) );
if (result === 'cancel')
return left( connectionCancel );
if (result === 'connect')
return right( right( client ) );
}
client.login(loginProps, loginHandler);
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
}
}
}
module Client where
import Data.Either (Either(..))
import Data.Function.Uncurried
import Effect.Aff.Compat
import Types
data ConnectionError = ConnectionCancel | ConnectionError String
type BrowserProps
= { width :: Int
, height :: Int
}
type LoginProps
= { browserProps :: BrowserProps
, scope :: Int
}
foreign import mkClient :: Client
foreign import getConnection :: Fn6 Client LoginProps ConnectionError (String -> ConnectionError) (ConnectionError -> Either ConnectionError Connection) (Connection -> Either ConnectionError Connection) (EffectFnAff (Either ConnectionError Connection)) -> EffectFnAff (Either ConnectionError Connection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment