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(mondo-fetch): Added mondo fetch #571

Merged
merged 38 commits into from
Mar 21, 2024
Merged

feat(mondo-fetch): Added mondo fetch #571

merged 38 commits into from
Mar 21, 2024

Conversation

MicahRus
Copy link
Contributor

@MicahRus MicahRus commented Mar 19, 2024

  • Updated base package manger to pnpm
  • Added mondo-fetch

@MicahRus MicahRus force-pushed the feat/add-mondo-fetch branch from ef7a85a to 12f75f6 Compare March 20, 2024 00:08
@MicahRus MicahRus requested a review from a team March 20, 2024 02:43
packages/mondo-fetch/src/index.ts Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/test/index.spec.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/test.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/types.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved

const authorizationToken = requestOptions?.authorizationToken || this.authorizationToken
if (authorizationToken)
Object.assign(headers, {Authorization: `Bearer ${authorizationToken}`})
Copy link
Contributor

Choose a reason for hiding this comment

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

This forces us to use bearer token all the time, and if we have other types, will not work. Maybe we need to think about haveing this as a union of different type of authorization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely agree.
I think as we're using bearer token for most situations this is fine. We can always come back and add it when necessary.

Just being conscious that it would be good to get this landed and being used.

Copy link

@fmac123 fmac123 left a comment

Choose a reason for hiding this comment

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

yep

packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
* @param body Optional parameter that contains a payload to send with the request @default undefined
* @param onBehalfOf An optional user identifier that will be provided to each request @default undefined
*/
export interface RequestOptions {

Choose a reason for hiding this comment

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

I think support for headers and query parameters is required for a http client

packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
packages/mondo-fetch/src/index.ts Outdated Show resolved Hide resolved
message: `The request has reached the maximum duration of ${timeout} milliseconds`,
})

const message = 'We were not able to determine the type of error for the failed request'

Choose a reason for hiding this comment

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

Fetch often throws when you get cors errors and destination not found errors. We could do a bit more checking on the error name to get a nice message

Choose a reason for hiding this comment

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

Also, don't think we should be logging in here. Libraries in my opinion should not log and instead interact purely through values. Logs you can't control or hide as users is annoying.

Comment on lines +2 to +5
export enum ContentTypes {
XFORM = 'application/x-www-form-urlencoded',
JSON = 'application/json; charset=utf-8'
}

Choose a reason for hiding this comment

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

Content types need to be more flexible. In HTML spec, content type can be any of the iana mime types. Might be better with a string union of common types and string to get intellisense

https://www.iana.org/assignments/media-types/media-types.xhtml

@MicahRus MicahRus enabled auto-merge March 21, 2024 04:12
Signed-off-by: github-actions <[email protected]>
@MicahRus MicahRus merged commit 4266e06 into main Mar 21, 2024
4 checks passed
@MicahRus MicahRus deleted the feat/add-mondo-fetch branch March 21, 2024 04:14
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.

5 participants