SalesforceCommerceCloud / commerce-sdk-isomorphic

Browser & Node.js JavaScript client for B2C Commerce API
https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/
BSD 3-Clause "New" or "Revised" License
42 stars 20 forks source link

Expo-Crypto for RN #154

Open FerVillanuevas opened 4 months ago

FerVillanuevas commented 4 months ago

For RN there is not a Crypto library.

So we should use expo-crypto and make an alias to crypto

RN Config

Install Bable Module Resolver

Update babel.config.js

module.exports = function (api) { api.cache(true); return { presets: ["babel-preset-expo"], plugins: [ [ "module-resolver", { alias: { crypto: "expo-crypto", }, }, ], ], }; };

So we are telling to RN that the crypto lib is expo-crypto insted of crypto, the fact is expo-crypto has different methods, so we need to verify if is RN or Brower/Node then if is react native call the methods from expo.

There is an issue, navigator.product its depreacted, but other that this config works as expect and all test passed

FerVillanuevas commented 4 months ago

Fix crypto on RN

https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/issues/108

joeluong-sfcc commented 2 months ago

Hi @FerVillanuevas, just to clarify, adding this fix does not work with react native out of the box, is that correct? Additional configuration is needed on the react native side on top of this fix in order for the commerce-sdk-isomorphic to work with react native.

Ideally things would work out of the box for all environments, browser/node/react native without additional configuration. In your manual testing, were you able to find a library that provides the same functionality as crypto that works on all environments, potentially something like crypto-js?