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

Update salesforce to use connection client #1063

Merged
merged 18 commits into from
Mar 21, 2025
Merged

Conversation

mtuchi
Copy link
Collaborator

@mtuchi mtuchi commented Mar 18, 2025

Summary

Replace state.connection with a global connection client and update unit tests

Fixes

Details

  • Update configuration-schema to default loginUrl to https://login.salesforce.com and apiVersion to 50.0. Because of defaultConnectionConfig in V3. See V3 connection.ts:L109, V3 connection.ts:L111
  • Removed util.createBasicConnection().
  • Removed util.createTokenConnection
  • Add connect function for connecting to salesforce using basic or access_token
  • Add setMockConnection() function, which make it easy to setup fake connection
  • Update unit test to use setMockConnection() for setting up fake connection
  • Update execute() function to createConnection and removed removeConnection function
  • Update all Adaptor function to use the global connection instead of state.connection
  • Remove lodash and the use of flatten in execute function

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to
know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our
Responsible AI Policy

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • NA: If this is a new adaptor, added the adaptor on marketing website ?
  • NA: If this PR includes breaking changes, do we need to update any jobs in
    production? Is it safe to release?
  • Are there any unit tests?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.
  • Have you ticked a box under AI Usage?

@mtuchi mtuchi changed the title 687 use client Update salesforce to use connection client Mar 18, 2025
@mtuchi mtuchi requested a review from josephjclark March 19, 2025 17:12
@mtuchi mtuchi marked this pull request as ready for review March 19, 2025 17:12
@mtuchi
Copy link
Collaborator Author

mtuchi commented Mar 19, 2025

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 🙌🏽

return commonExecute(
util.loadAnyAscii,
...operations
createConnection,
...flatten(operations)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great, thanks!

@mtuchi mtuchi requested a review from josephjclark March 20, 2025 09:01
@josephjclark josephjclark mentioned this pull request Mar 20, 2025
12 tasks
}
const { configuration } = state;
configuration.access_token
? await tokenAuth(configuration)
Copy link
Collaborator

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:

  1. Move all the code inside this connect function, so that you have a big connect function. I don't really understand why basicAuth and tokenAuth 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 move checkConnection inside (which is what I was getting at before). And I think that simplifies all the code.
  2. Rename basicAuth to connectWithBasicAuth (because this function does something, it really needs a verb in the name) and tokenAuth to connectWithTokenAuth, then have those functions accept state and return state. Now connect can end with return 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?

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

@mtuchi mtuchi requested a review from josephjclark March 21, 2025 11:08
Copy link
Collaborator

@josephjclark josephjclark left a 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 🙌

@josephjclark josephjclark merged commit 1ecbaed into epic/salesforce Mar 21, 2025
2 checks passed
@josephjclark josephjclark deleted the 687-use-client branch March 21, 2025 14:56
mtuchi added a commit that referenced this pull request Mar 31, 2025
* 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
mtuchi added a commit that referenced this pull request Mar 31, 2025
* 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
josephjclark added a commit that referenced this pull request Apr 2, 2025
* 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]>
@mtuchi mtuchi self-assigned this Apr 2, 2025
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.

2 participants