commerce-sdk-isomorphic icon indicating copy to clipboard operation
commerce-sdk-isomorphic copied to clipboard

[Feature] Allow providing your own implementation of fetch

Open opepin opened this issue 1 year ago • 4 comments

Allow providing your own implementation of fetch by delaying caching from instanciation to first call.

Fetch can now be instrumented for performance monitoring/error or data capture. https://docs.logrocket.com/docs/troubleshooting-sessions#network-requests-are-missing-or-not-being-recorded

opepin avatar Jun 08 '24 18:06 opepin

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Olivier Pepin <o***@m***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.

salesforce-cla[bot] avatar Jun 08 '24 18:06 salesforce-cla[bot]

Hi @opepin, thanks for creating this PR. Would you be willing to provide some documentation/example on how you would pass in a custom implementation of a fetch call and adding a unit test?

joeluong-sfcc avatar Jun 28 '24 21:06 joeluong-sfcc

I don't have a unit test, but the idea would be to override the window.fetch method :

const { fetch: originalFetch } = window;

window.fetch = async (...args) => { let [resource, config ] = args; console.log('request interceptor before') const response = await originalFetch(resource, config); console.log('request interceptor after') return response; };

before calling the api

opepin avatar Jul 03 '24 14:07 opepin

fixes #159

opepin avatar Aug 23 '24 20:08 opepin