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

Make client isomorphic as a node library #49

Merged
merged 2 commits into from
Jun 15, 2021

Conversation

sfentress
Copy link
Collaborator

This allows the client library to be used in node applications, with the small change that env will be required, and the application will need to pass in an isomorphic replacement for fetch (presumably node-fetch).

This allows the client library to be used in node applications, with
the small change that `env` will be required, and the application will
need to pass in an isomorphic replacement for `fetch` (presumably
`node-fetch`).
Copy link
Member

@scytacki scytacki 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 to me.

I'm going to add @dougmartin as a co-reviewer though just to double check what he thinks.

@scytacki scytacki requested a review from dougmartin June 14, 2021 21:42
Copy link
Member

@dougmartin dougmartin left a comment

Choose a reason for hiding this comment

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

Not required but I made a suggestion for adding an exception if fetch is not resolved.

const {jwt, serviceUrl} = options;
this.jwt = jwt;
this.env = options.env || getEnv();
this.serviceUrl = getServiceUrlFromQueryString() || serviceUrl || getServiceUrlFromEnv(this.env) || serviceUrls.production;
this.fetch = ("fetch" in options) ? options.fetch : fetch;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good to throw an exception here if this.fetch === undefined. This will make debugging easier for future users. The exception could be something like:

new Error("fetch not found in options or window object")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 Sounds good, added.

}
if (options?.body) {
requestOptions.body = JSON.stringify(options.body);
}
return fetch(url, requestOptions)
return this.fetch(url, requestOptions)
Copy link
Member

Choose a reason for hiding this comment

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

See note about throwing an exception in the constructor as this.fetch could be undefined here if not found in the options (node) or in the window object (browser).

@sfentress sfentress merged commit 5a23611 into master Jun 15, 2021
@sfentress sfentress deleted the 178336837-iso-node-client branch June 15, 2021 13:34
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.

None yet

3 participants