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

feat(#6250): use fetch in couch-request #9746

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

dianabarsan
Copy link
Member

@dianabarsan dianabarsan commented Jan 15, 2025

Description

Removes request-promise-native.

#6250

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design.
  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
- handing server sending JSON headers but no content
- double slash paths
- from data -> json

Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
api/tests/mocha/services/rapidpro.spec.js Dismissed Show dismissed Hide dismissed
Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
Signed-off-by: Diana Barsan <[email protected]>
@dianabarsan dianabarsan marked this pull request as ready for review January 21, 2025 05:36
Signed-off-by: Diana Barsan <[email protected]>
shared-libs/couch-request/test/couch-request.js Dismissed Show dismissed Hide dismissed
shared-libs/couch-request/test/couch-request.js Dismissed Show dismissed Hide dismissed
@dianabarsan dianabarsan requested a review from jkuester January 22, 2025 06:03
@dianabarsan
Copy link
Member Author

Hi @jkuester ! Would you mind with some feedback over here? Appreciate it!!!

@jkuester
Copy link
Contributor

👍 Will have a look asap, but might not be until Friday.

Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

Send it! Just a few minor non-blocking comments.

(Also just have to say that I hate JS. With no type safety this kind of refactor is terrifying. AFICT you caught all the user > username, pass > password, and statusCode > status changes, but it is really hard to tell....)


const req = (method, first, second = {}) => {
if (options.auth) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: I wonder if we should throw an exception if we have both options.auth and options.headers.authorization set? (Out of an abundance of caution.) Just very much don't want there to be a misunderstanding about which auth creds are being used for a request.

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 thought about this as well. Now that there are two of us that think about it, I firmly believe it's a good idea :)

setRequestUri(options);
setRequestAuth(options);
setTimeout(options);
const sendJson = setRequestContentType(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: it would read better if you called getSendJson up here and then passed in sendJson as a parameter to setRequestContentType (just weird to return a value from set...).

case methods.HEAD: {
return request.head;

return { options, sendJson };
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: actually, what if we just did not return anything from this function at all? As things are, it is pretty strange that the function accepts the options parameter, mutates the options parameter, then returns an object containing the mutated options parameter. This is not at all how I expected this to work when I first glanced at the code.

Instead, we could change the function name to something like mutateRequestOptions and return nothing. The request function below should be able to calculate const sendJson = options.headers[CONTENT_TYPE] === JSON_HEADER_VALUE; right?

if (!authHeader || !authHeader.startsWith('Basic ')) {
return false;
}
try {
const [username, password] = Buffer.from(authHeader.split(' ')[1], 'base64').toString().split(':');
const [username, password] = atob(authHeader.split(' ')[1]).split(':');
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: why change this? Looks like atob is marked as "legacy" in favor of Buffer.from...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, my bad. I'll switch it back!

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