-
Notifications
You must be signed in to change notification settings - Fork 12
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
Update salesforce to use connection
client
#1063
Conversation
remove removeConnection function
moved createConnection to Adaptor.js
Hiya @josephjclark , this one is ready for review. I can't express enough how grateful i am with the unit tests. They helped me a lot on getting this done 🙌🏽 |
packages/salesforce/src/Adaptor.js
Outdated
return commonExecute( | ||
util.loadAnyAscii, | ||
...operations | ||
createConnection, | ||
...flatten(operations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we introduce flatten here? it wasn't here before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephjclark, flatten was there before. I just moved createConnection
from util.js to Adaptor.js and removed removeConnection
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah then I'm getting confused.
Ok, I've looked over this code. You can remove flatten
completely and close #1067. Let's just do this here, it's a simple change and it's getting merged into an epic anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephjclark i have removed the use of flatten
and deleted lodash
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
packages/salesforce/src/Adaptor.js
Outdated
} | ||
const { configuration } = state; | ||
configuration.access_token | ||
? await tokenAuth(configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, sorry, i was just about to merge but this ternary just caught my eye and it's needling me. I think if I let this go I'll regret it forever.
IMO this is a "naughty ternary" because it doesn't return anything. This should really be an if statement.
And something about the structure and naming of this is bothering me 🤔
I would either:
- Move all the code inside this connect function, so that you have a big connect function. I don't really understand why
basicAuth
andtokenAuth
need to be in their own function. We only call them from one place and presumably we're not unit testing them. If you move them inside if/else branches in connect, you can also movecheckConnection
inside (which is what I was getting at before). And I think that simplifies all the code. - Rename
basicAuth
toconnectWithBasicAuth
(because this function does something, it really needs a verb in the name) andtokenAuth
toconnectWithTokenAuth
, then have those functions accept state and return state. Now connect can end withreturn config.access_token? connectWithBasicAuth(state) : connectWithTokenAuth(state)
, which at least feels like a cleaner ternary and a nicer way to end the function.
I haven't seen both approaches written down but my instinct says option 1.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options 1 definitely, it makes the whole implementation of connect
clean, let me work on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiya @josephjclark I have cleanup the connect
function and remove the helper function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephjclark just a heads up, #1070 is rebased against 687-use-client
branch. So that PR should be merged before this one to avoid conflict resolution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mtuchi , I think this is much cleaner 🙌
* wip refactor create connection * fix unit test * wip fix intergration test * remove log * revert use of flatten function remove removeConnection function * improve basicAuth and tokenAuth moved createConnection to Adaptor.js * setup mock connection * remove .skip and .only * cleanup * remove logLevel * remove default configuration * add changeset * use checkConnection in basicAuth and tokenAuth only * move basicAuth, tokenAuth and checkConnection to Adaptor.js * remove array in execute() function * remove flatten from lodash * remove lodash package * update connect function
* wip refactor create connection * fix unit test * wip fix intergration test * remove log * revert use of flatten function remove removeConnection function * improve basicAuth and tokenAuth moved createConnection to Adaptor.js * setup mock connection * remove .skip and .only * cleanup * remove logLevel * remove default configuration * add changeset * use checkConnection in basicAuth and tokenAuth only * move basicAuth, tokenAuth and checkConnection to Adaptor.js * remove array in execute() function * remove flatten from lodash * remove lodash package * update connect function
* update jsforce to v3 (#1060) * update jsforce to v3 * add changeset * Update salesforce to use `connection` client (#1063) * wip refactor create connection * fix unit test * wip fix intergration test * remove log * revert use of flatten function remove removeConnection function * improve basicAuth and tokenAuth moved createConnection to Adaptor.js * setup mock connection * remove .skip and .only * cleanup * remove logLevel * remove default configuration * add changeset * use checkConnection in basicAuth and tokenAuth only * move basicAuth, tokenAuth and checkConnection to Adaptor.js * remove array in execute() function * remove flatten from lodash * remove lodash package * update connect function * Add `http` function in salesforce (#1070) * wip refactor create connection * fix unit test * wip fix intergration test * remove log * revert use of flatten function remove removeConnection function * improve basicAuth and tokenAuth moved createConnection to Adaptor.js * setup mock connection * remove .skip and .only * cleanup * remove logLevel * remove default configuration * add changeset * use checkConnection in basicAuth and tokenAuth only * move basicAuth, tokenAuth and checkConnection to Adaptor.js * remove array in execute() function * remove flatten from lodash * remove lodash package * move http function to http.js * build docs * update unit test * use request helper methods * add unit test for http * add integration test for http * improve logs * add test for query params * add unit test for http.post * add salesforceRequest function use this function in http.js * update test * add changeset * remove json option in FullRequestOption * remove sinon * remove sinon package * move request into http --------- Co-authored-by: Joe Clark <[email protected]> * bump version and update changelog * update changelog --------- Co-authored-by: Emmanuel Evance <[email protected]>
Summary
Replace
state.connection
with a globalconnection
client and update unit testsFixes
salesforce
adaptor to use client Instead ofstate.connection
#687saleforce
remove flatten from lodash #1067Details
configuration-schema
to defaultloginUrl
tohttps://login.salesforce.com
andapiVersion
to50.0
. Because of defaultConnectionConfig in V3. See V3 connection.ts:L109, V3 connection.ts:L111util.createBasicConnection()
.util.createTokenConnection
connect
function for connecting to salesforce using basic or access_tokensetMockConnection()
function, which make it easy to setup fake connectionsetMockConnection()
for setting up fake connectionexecute()
function tocreateConnection
and removedremoveConnection
functionconnection
instead ofstate.connection
lodash
and the use offlatten
in execute functionAI Usage
Please disclose how you've used AI in this work (it's cool, we just want to
know!):
You can read more details in our
Responsible AI Policy
Review Checklist
Before merging, the reviewer should check the following items:
production? Is it safe to release?
dev only changes don't need a changeset.