commercelayer-sdk icon indicating copy to clipboard operation
commercelayer-sdk copied to clipboard

Remove Axios to make isomorphic ?

Open osseonews opened this issue 1 year ago • 8 comments

Any chance you can build a isomorphic SDK here? Currently, you use axios for the fetch in client.ts, which makes it impossible to use this SDK on the newer edge platforms like Cloudflare Workers (NextJs Edge also, which runs on Cloudflare) or Deno. I believe if you just switched the client to simply use standard fetch, it would work fine on Cloudflare Workers/Deno.

osseonews avatar May 04 '23 09:05 osseonews

Hi @osseonews currently an isomorphic SDK is not in our plans but in the latest version of the SDK we added the adapter option that can be used when creating the client to define e acustom adapter for Axios (1.x)

pviti avatar Jul 27 '23 13:07 pviti

fetch doesn't support proxy feature, and this lib use proxy stuff from axios;

fetch minimal node.js version is 18;

suhaotian avatar Mar 11 '24 05:03 suhaotian

Hi @suhaotian 👋

If we will add the support for fetch we'll modify also the support for proxies or we will remove it at all for the moment.

The SDK version which will include the support for fetch will work only with Node.js >=20.x

pviti avatar Mar 11 '24 10:03 pviti

Commenting to track this issue and show support for this change. I'm currently writing fetch requests to commerce layer in server components to take advantage of NextJS RSCs. Would be great to use this library instead.

michaelmerrill avatar Mar 13 '24 19:03 michaelmerrill

@suhaotian I think I will give xior a try (well, I'll try to find time to do it 🙂)

pviti avatar Mar 15 '24 11:03 pviti

@pviti Thanks for give a try of xior!

I clone the code, after install and run pnpm test, but test failed, any documentation of how to run tests locally?

image

suhaotian avatar Mar 15 '24 12:03 suhaotian

You need a .env file in your project root dir with the following variables: CL_SDK_ORGANIZATION=<your-organization-slug> CL_SDK_CLIENT_ID=<application-client-id> CL_SDK_CLIENT_SECRET=<application-client-secret>

Tests execute some real calls to the API so you should use a TEST application (you can create one inside the Commerce Layer's dashboard)

pviti avatar Mar 15 '24 12:03 pviti

@pviti Thanks Now it's work, but still some tests failed, what I missing? image

suhaotian avatar Mar 15 '24 13:03 suhaotian