Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding serialize and resume to guardianJs transactions #24

Merged
merged 4 commits into from
Mar 1, 2017

Conversation

joseluisdiaz
Copy link
Member

@joseluisdiaz joseluisdiaz commented Feb 22, 2017

  • new factory for client (websocket/pooling)
  • new factory for transaction (fromStartFlow/fromTransactionState)
  • new .serialize method on Transaction
  • new .resume method in guardianJS to continue from a seralized transaction.

@joseluisdiaz joseluisdiaz force-pushed the serialize-deserialize branch 4 times, most recently from 204e4b1 to 8dab8ad Compare February 24, 2017 16:31
@joseluisdiaz joseluisdiaz changed the title WIP: adding serialize and resume to guardianJs transactions Adding serialize and resume to guardianJs transactions Feb 24, 2017
README.md Outdated
```js
var serializedTransaction = secureStorage.get('guardiantx');

auth0GuardianJS.start({ transport: 'pooling' }, serializedTransaction, function(err, transaction) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resume

README.md Outdated
@@ -292,6 +292,35 @@ auth0GuardianJS.start(function(err, transaction) {
//...
});
```
### auth0GuardianJS.resume(options, transactionState, callback)
This continues a transaction saved by `transaction.serialize()`. The option parameter provides
the final user the opportunity to specify which kind of `client` to use. That been:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client ?? what's client? later it's used as transport: { transport: 'pooling' }

Something like this might sound better:

The option parameter provides the final user the opportunity to specify which kind of transport to use, the options being:

README.md Outdated
@@ -389,6 +418,12 @@ recovery code is the new recovery code you must show to the user from him to sav
transaction.recover({ recoveryCode: recoveryCode });
```

#### transaction.serialize()
The .serialize() method creates a regular javascript Object that should remind opaque

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a "plain" object, or something better? A javascript object might have functions and other things in it. Maybe a plain JSON Object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like plain

lib/index.js Outdated
self.socketClient = socketClient(self.serviceUrl);
}
}
self.socketClient = clientFactory({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientFactory.create will look better, just like transactionFactory.fromXX
otherwise the require should have a better name, like:

var createClient = require('./utils/client_factory');

so the function call is more understandable

return;
}

callback(null, tx);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

       try {
         const tx = transactionFactory.fromTransactionState(transactionState, {
           transactionEventsReceiver: self.socketClient,
           httpClient: self.httpClient
         });
         callback(null, tx);
       } catch (transactionBuildingErr) {
         callback(transactionBuildingErr);
       }

@@ -24,7 +24,7 @@ var eventSequencer = require('../utils/event_sequencer');
var eventListenerHub = require('../utils/event_listener_hub');

/**
* @public
* @public||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -74,6 +74,7 @@ function transaction(data, options) {
self.txId = data.transactionToken.getDecoded().txid;
self.transactionToken = data.transactionToken;
self.transactionEventsReceiver = options.transactionEventsReceiver;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -136,8 +137,34 @@ function transaction(data, options) {
return self;
}


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

var pooling = require('./polling_client');
var socketio = require('./socket_client');

module.exports = function factory(options) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export an object with a function create or something like that instead of the function directly. otherwise client_factory is not a good name

@joseluisdiaz
Copy link
Member Author

@nikolaseu addressed most of your comments; i realized that we needed a new test for guardianjs.resume. I rewrite the commits history, sorry about this.

Copy link

@fiddur fiddur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posting a partial review. Will continue soon.

@@ -48,4 +48,11 @@ enrollment.prototype.getPhoneNumber = function getPhoneNumber() {
return this.data.phoneNumber;
};

/**
* @returns @see constructor.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only @see is enough here :)

README.md Outdated
the final user the opportunity to specify which kind of `transport` to use. That been:

- `socket`: a socket.io transport
- `pooling`: a pooling transport.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"polling". "pooling" refers to a "pool" with several connections to pick from, "polling" refers to "poll" to see if something is done...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The option parameter" -> "The options parameter"

"That been:" -> "Options include:"

README.md Outdated
@@ -389,6 +418,12 @@ recovery code is the new recovery code you must show to the user from him to sav
transaction.recover({ recoveryCode: recoveryCode });
```

#### transaction.serialize()
The .serialize() method creates a plain javascript Object that should remind opaque
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/remind/remain/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...I'm not sure what is meant here, with the object being opaque to the end user. In all examples, the object is not sent to the end user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point; to 'library user' or 'library client' i meant.

lib/index.js Outdated

/**
* @public
*
* Post result to url using an standard form
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Post result to url using a standard form"

* @param {object} transactionState.availableAuthenticationMethods
*
* @param {EventEmitter} options.transactionEventsReceiver
* Receiver for transaction events; it will receive backend related transaction events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space

lib/index.js Outdated
@@ -128,6 +122,70 @@ auth0GuardianJS.prototype.start = function start(callback) {
/**
* @public
*
* This takes a parameter what transaction.serialize returns to
* resume the transaction with auth0-mfa-api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Takes a parameter returned from transaction.serialize to resume the transaction with auth0-mfa-api"

Correct me if I'm not interpreting it correctly, though

README.md Outdated
- `socket`: a socket.io transport
- `pooling`: a pooling transport.

The default one is `socket`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If not set, the socket transport is used as default"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And polling again :)

Copy link

@fiddur fiddur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it's a lot of changes... We really should have a test coverage setup (like istanbul) to not miss adding tests for any added/changed function.

@@ -0,0 +1,20 @@
var pooling = require('./polling_client');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polling!

@joseluisdiaz joseluisdiaz force-pushed the serialize-deserialize branch from 10ee80e to 40821ba Compare March 1, 2017 12:31
@joseluisdiaz joseluisdiaz merged commit 290c3aa into auth0:master Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants