Priority-Web-SDK btoa "Buffer is not defined" - react-native

I'm building a React Native application using create-react-native-app. The app connects to Priority via the API without error, however when I need to use the Web-SDK to get the options for a choose field it is throwing an error:
SDK Error: ReferenceError: Buffer is not defined
at btoa (C:\...\node_modules\btoa\index.js:8)
at b64encode (C:\...\node_modules\priority-web-sdk\index.js:2744)
at $FormQuery (C:\...\node_modules\priority-web-sdk\index.js:3898)
at $GetRows (C:\...\node_modules\priority-web-sdk\index.js:3957)
at Form_1.GetRows (C:\...\node_modules\priority-web-sdk\index.js:4673)
at C:\...\node_modules\priority-web-sdk\index.js:6234
at tryCallTwo (C:\...\node_modules\promise\setimmediate\core.js:45)
at doResolve (C:\...\node_modules\promise\setimmediate\core.js:200)
at new Promise (C:\...\node_modules\promise\setimmediate\core.js:66)
at Object.gform.getRows (C:\...\node_modules\priority-web-sdk\index.js:6233)
**Actual files paths edited for brevity/privacy.
My code that calls getRows()
return login(configuration)
.then(() => formStart('PORDERS', null, null, configuration.company, 1))
.then(form => myForm = form)
.then(() => myForm.setSearchFilter(filter))
.then(() => myForm.getRows(1))
.then(r => rows = r)
.then(() => myForm.setActiveRow(1))
.then(a => row = a)
.then(() => myForm.choose('STATDES',rows.PORDERS[row.rowindex].STATDES))
.then((response) => {return response.ChooseLine})
.catch(err => console.log('SDK Error: ', err));
This issue popped up recently. It was working fine before. I thought maybe I had upgraded a package incorrectly, so I reverted to a previous version of the yarn.lock file and rebuilt the node_modules folder, but with no success.
I feel like this is more of a yarn/npm package or Priority issue than React-native, but I'm at a loss. Any suggestions on what else I could do?
Update:
The more I work on this and the more I try different things, it feels to me more and more like an issue of my test setup having different native functions than my live set up. Any suggestions on how to check/solve that?

This is fixed in version 1.9.3 of priority-web-sdk.
In addition, here is a link to Priority Master app's repository that is built with react-native: https://github.com/PrioritySoftware/priority-master-react.

Related

Loading Vue devtools in electron in development mode

I was looking for a way to add Vue Devtools to the electron app I was working on. I tried a couple of methods that seemed to be outdated and finally succeded using this package:
electron-devtools-installer which I installed as a DEV dependency.
with this code:
import { app } from 'electron'
import installExtension from 'electron-devtools-installer';
const VUEJS3_DEVTOOLS = 'nhdogjmejiglipccpnnnanhbledajbpd';
...
app.whenReady().then(() => {
installExtension(VUEJS3_DEVTOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
});
but since this was a DEV dependency, the app fails to load due to the missing package in production.
I was wondering if there is a way to dynamicly load the package/extension only if not in production.
It took me many attempts to figure this out since this isn't directly documented anywhere and I lack the experience of loading ES6 modules to think of trying module.default.default.
This is the code that ended up working without issues in both development and production cases:
app.whenReady().then(() => {
if (process.env.DEBUGGING) // replace with whatever you use to check for dev env
import('electron-devtools-installer')
.then(mymodule => {
const installExtension = mymodule.default.default; // Default export
installExtension(mymodule.default.VUEJS_DEVTOOLS) // replace param with the ext ID of your choice
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
There might be a more elegant way to do this but this is all I needed. I am open to hear improvements on this.
Note: replace mymodule.default.VUEJS_DEVTOOLS with any other valid Chrome extension ID. The package has some popular ones built-in: Electron DevTools Installer - GitHub

TypeError:null is not an object(evaluating 'RNFSManager.RNFSFileTypeRegular')

I am currently working on reading a local file in react-native and am running into the following error,
TypeError:null is not an object(evaluating 'RNFSManager.RNFSFileTypeRegular')
The code I am using is taken straight off of the documentation for react-native-fs , using the basic example, from the examples section:
// require the module
var RNFS = require('react-native-fs');
// get a list of files and directories in the main bundle
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
// log the file contents
console.log(contents);
})
.catch((err) => {
console.log(err.message, err.code);
});
If it helps I am using vs when writing this on a Windows 10 computer.
I have tried resetting my cache, reinstalling react-native-fs, and linking react-native-fs, none have solved the problem all resulting in the same error.
I would greatly appreciate any help. Thank you.
In case of iOS message is 'Native module cannot be null', In Android message is 'null is not an object evaluating RNFSManager etc'
Solution for iOS is run pod install in iOS Directory, then react-native run-ios to re-run the app.
Solution for android is react-native link react-native-fs then react-native run-android to re-run the app.

React Native module not working only on iOS

I have recently upgraded my react-native project to 0.60. After upgrading, a native module I have been working with has stopped working on iOS, with the error TypeError: Cannot read property 'show' of undefined.
I have been modifying this native module but the only code I had modified after upgrading to RN 0.60 was Android code. My modified module code is at https://github.com/BradyShober/react-native-braintree-dropin-ui
The file that is calling the module is
import BraintreeDropIn from 'react-native-braintree-dropin-ui';
const showBraintreeUI = async (token, amount) => {
BraintreeDropIn.show({
clientToken: token,
countryCode: 'US',
currencyCode: 'USD',
orderTotal: amount,
googlePay: true,
googleMerchantId: 'merchantID',
applePay: true,
merchantName: "Name",
merchantIdentifier: "ID",
vaultManager: true
})
.then(async (result) => {
console.log(result)
}
catch(error){
console.log(error);
}
})
.catch((error) => {
if (error.code === 'USER_CANCELLATION') {
console.log("User cancelled payment");
}
else {
console.log(error);
}
});
}
export { getBraintreeToken, showBraintreeUI };
The expected result is the opening of the Braintree Drop In UI which works on Android but on iOS is throwing an error TypeError: Cannot read property 'show' of undefined.
I believe this to be an issue with autolinking, I have been able to get it to work if I right click Libraries in Xcode, then Add files and select the module's .xcodeproject and then add the library in Link Binaries with Libraries. I haven't been able to easily find what I would have to change in the module to not have to do those steps as a workaround.
I was able to get it working thanks to some help I got on the Reactiflux discord server. The issue was due to an issue in the module's Podspec that was causing none of the module's source files to be detected. The s.source_files was set to s.source_files = "RNBraintreeDropIn/**/*.{h,m}" instead of s.source_files = "*.{h,m}"

Issue with fetch, response.json()

I am trying to make an api call using fetch method in react-native.
I have rn-fetch-blob for uploading images in one screen which is on another different screen. This particular function was for me to initiate a payment online using paystack. though the issue is not about the paystack because this worked in a new project without having rn-fetch-blob in it.
Secondly if i remove response.json(), it wouldn't return anything but there wouldn't be any error. but with response.json(), if get this error
attempt to invoke interface method 'java.lang.bridge.readablemap. getstring(java.lang.string)' on a null object reference.
I suspect there is a conflict between rn-fetch-blob and fetch because even without using rn-fetch-blob, it runs through perfectly, if i do
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
})
.catch((error) => {
console.error(error);
})
same error comes
i expect a reference value like hyhjgbhgfh
attempt to invoke interface method 'java.lang.bridge.readablemap. getstring(java.lang.string)' on a null object reference.
I logged out response and i saw

Nuxtjs hook system

I wrote my own module for my nuxt.js application. Since upgrading to version 1.4.0 this line:
this.nuxt.plugin('close', () => new Promise((resolve) => server.close(resolve)))
generates following warning:
nuxt.plugin('close',..) is deprecated. Use new hooks system.
However, there does not seem to be any documentation on this 'new hooks system'.
Can anybody tell me what I have to change?
Thank you in advance!
The new hooks are invoked with: this.nuxt.hook(NAME, FN).
// this.nuxt.plugin('close', () => {...})
this.nuxt.hook('close', () => {...})