@bigbinary/neeto-commons-rn 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.isNetworkError=exports.handleNetworkError=void 0;var _neetouiRn=require("@bigbinary/neetoui-rn");var _localization=require("../../localization");var isNetworkError=exports.isNetworkError=function isNetworkError(error){var networkErrorPatterns=[/network\s*error/i,/network\s*request\s*failed/i,/no\s*internet\s*connection/i,/timeout/i,/econnrefused/i,/econnreset/i,/enetdown/i,/enetunreach/i,/ehostdown/i,/ehostunreach/i];return networkErrorPatterns.some(function(pattern){return pattern.test(error.message)||pattern.test(error.toString());});};var handleNetworkError=exports.handleNetworkError=function handleNetworkError(error){var showToast=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;if(isNetworkError(error)){if(showToast){_neetouiRn.Toast.show({type:"error",text2:_localization.strings.en.errors.axios.networkError||"Please check your internet connection and try again"});}return true;}return false;};
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.isNetworkError=exports.isEventErrorsNetworkRelated=exports.handleNetworkError=void 0;var _neetouiRn=require("@bigbinary/neetoui-rn");var _localization=require("../../localization");var isNetworkError=exports.isNetworkError=function isNetworkError(error){var networkErrorPatterns=[/network\s*error/i,/network\s*request\s*failed/i,/no\s*internet\s*connection/i,/timeout/i,/econnrefused/i,/econnreset/i,/enetdown/i,/enetunreach/i,/ehostdown/i,/ehostunreach/i];return networkErrorPatterns.some(function(pattern){return pattern.test(error.message)||pattern.test(error.toString());});};var isEventErrorsNetworkRelated=exports.isEventErrorsNetworkRelated=function isEventErrorsNetworkRelated(event){return event.errors.some(function(error){return isNetworkError({message:error.errorMessage});});};var handleNetworkError=exports.handleNetworkError=function handleNetworkError(error){var showToast=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;if(isNetworkError(error)){if(showToast){_neetouiRn.Toast.show({type:"error",text2:_localization.strings.en.errors.axios.networkError||"Please check your internet connection and try again"});}return true;}return false;};
package/config/bugsnag.js CHANGED
@@ -1 +1 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.configureBugsnag=exports.bugsnagErrorHandler=void 0;var _pluginReactNavigation=_interopRequireDefault(require("@bugsnag/plugin-react-navigation"));var _reactNative=_interopRequireDefault(require("@bugsnag/react-native"));var _store=require("../store");var _networkErrorHandler=require("./axios/networkErrorHandler");var bugsnagErrorHandler=exports.bugsnagErrorHandler=function bugsnagErrorHandler(err,origin){if(!__DEV__){_reactNative.default.notify(err,function(event){if((0,_networkErrorHandler.isNetworkError)(err)){return false;}event.severity="warning";event.context=origin;return true;});}};var configureBugsnag=exports.configureBugsnag=function configureBugsnag(){if(!__DEV__){var auth=_store.Store.getState().auth;_reactNative.default.start({onError:function onError(event){auth.email&&event.setUser(auth.name,auth.email);if(event.errors.some(function(error){return(0,_networkErrorHandler.isNetworkError)({message:error.errorMessage});})){event.ignore();}},plugins:[new _pluginReactNavigation.default()],discardClasses:["NetworkError"]});}};
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.configureBugsnag=exports.bugsnagErrorHandler=void 0;var _pluginReactNavigation=_interopRequireDefault(require("@bugsnag/plugin-react-navigation"));var _reactNative=_interopRequireDefault(require("@bugsnag/react-native"));var _store=require("../store");var _networkErrorHandler=require("./axios/networkErrorHandler");var bugsnagErrorHandler=exports.bugsnagErrorHandler=function bugsnagErrorHandler(err,origin){if(!__DEV__){_reactNative.default.notify(err,function(event){if((0,_networkErrorHandler.isNetworkError)(err)){return false;}event.severity="warning";event.context=origin;return true;});}};var configureBugsnag=exports.configureBugsnag=function configureBugsnag(){if(!__DEV__){var auth=_store.Store.getState().auth;_reactNative.default.start({enabledReleaseStages:["production","staging"],onError:function onError(event){var _event$device;if(auth.email){event.setUser(auth.name,auth.email);}if((_event$device=event.device)!=null&&_event$device.emulator){return false;}if((0,_networkErrorHandler.isEventErrorsNetworkRelated)(event)){return false;}return true;},plugins:[new _pluginReactNavigation.default()],discardClasses:["NetworkError","AnrLinkError","NdkLinkError"]});}};
@@ -1 +1 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var _store=require("../../store");var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{handleClick:function handleClick(){}},handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useState=(0,_react.useState)(false),_useState2=(0,_slicedToArray2.default)(_useState,2),notificationPermission=_useState2[0],setNotificationPermission=_useState2[1];var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var checkPermission=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){try{if(_reactNative.Platform.OS==="android"&&_reactNative.Platform.Version<33){setNotificationPermission(true);return;}var _yield$checkNotificat=yield(0,_reactNativePermissions.checkNotifications)(),status=_yield$checkNotificat.status;setNotificationPermission(status===_reactNativePermissions.RESULTS.GRANTED);}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}});return function checkPermission(){return _ref2.apply(this,arguments);};}();if(appState==="active"){checkPermission();}},[appState]);var registerNotificationEvents=(0,_react.useCallback)(function(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4,_notification$payload5;var notificationTitle=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload["gcm.notification.title"])||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:_notification$payload2.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload3=notification.payload)==null?void 0:_notification$payload3["gcm.notification.body"])||(notification==null?void 0:(_notification$payload4=notification.payload)==null?void 0:_notification$payload4.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default",sound:"default"});}completion({alert:true,sound:true,badge:true});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload6,_notification$payload7,_notification$payload8,_notification$payload9,_notification$payload0;var notificationTitle=(notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"])||(notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload8=notification.payload)==null?void 0:_notification$payload8["gcm.notification.body"])||(notification==null?void 0:(_notification$payload9=notification.payload)==null?void 0:_notification$payload9.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload0=notification.payload)==null?void 0:_notification$payload0.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default",sound:"default"});}completion({alert:true,sound:true,badge:true});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});var registeredEvent=_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;var isLoggedIn=((_Store$getState=_store.Store.getState())==null?void 0:(_Store$getState$auth=_Store$getState.auth)==null?void 0:_Store$getState$auth.isLoggedIn)||false;if(!isLoggedIn||!event.deviceToken)return;var storedToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(storedToken===event.deviceToken)return;var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};registerToken(payload,{onSuccess:function(){var _onSuccess=(0,_asyncToGenerator2.default)(function*(){yield(0,_asyncStore.setItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN,event.deviceToken);});function onSuccess(){return _onSuccess.apply(this,arguments);}return onSuccess;}()});});return function(_x){return _ref3.apply(this,arguments);};}());var registrationFailedEvent=_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});if(_reactNative.Platform.OS==="android"){var defaultNotificationChannel={channelId:"default",name:"Default Channel",importance:5,sound:"default",enableVibration:true,enableLights:true,showBadge:true};var channel01NotificationChannel={channelId:"channel_01",name:"Channel 01",importance:5,enableLights:true,enableVibration:true,showBadge:true};_reactNativeNotifications.Notifications.setNotificationChannel(defaultNotificationChannel);_reactNativeNotifications.Notifications.setNotificationChannel(channel01NotificationChannel);}return[foregroundEvent,backgroundEvent,openedEvent,registeredEvent,registrationFailedEvent];},[registerToken]);(0,_react.useEffect)(function(){var events=registerNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[registerNotificationEvents]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"&&notificationPermission){initializePN();}},[initializePN,isLoggedIn,appState,notificationPermission]);var registerForRemoteNotifications=(0,_react.useCallback)(function(){_reactNativeNotifications.Notifications.registerRemoteNotifications();},[]);var initializePN=(0,_react.useCallback)(function(){try{registerForRemoteNotifications();}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}},[registerForRemoteNotifications]);var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload1,_notification$payload10,_notification$payload11,_notification$payload12;var notificationId=(notification==null?void 0:(_notification$payload1=notification.payload)==null?void 0:_notification$payload1.notification_id)||(notification==null?void 0:(_notification$payload10=notification.payload)==null?void 0:(_notification$payload11=_notification$payload10.aps)==null?void 0:(_notification$payload12=_notification$payload11.alert)==null?void 0:_notification$payload12.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});return[];};
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var _store=require("../../store");var pendingRegistrationToken=null;var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{handleClick:function handleClick(){}},handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useState=(0,_react.useState)(false),_useState2=(0,_slicedToArray2.default)(_useState,2),notificationPermission=_useState2[0],setNotificationPermission=_useState2[1];var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var checkPermission=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){try{if(_reactNative.Platform.OS==="android"&&_reactNative.Platform.Version<33){setNotificationPermission(true);return;}var _yield$checkNotificat=yield(0,_reactNativePermissions.checkNotifications)(),status=_yield$checkNotificat.status;setNotificationPermission(status===_reactNativePermissions.RESULTS.GRANTED);}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}});return function checkPermission(){return _ref2.apply(this,arguments);};}();if(appState==="active"){checkPermission();}},[appState]);var registerNotificationEvents=(0,_react.useCallback)(function(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4,_notification$payload5;var notificationTitle=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload["gcm.notification.title"])||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:_notification$payload2.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload3=notification.payload)==null?void 0:_notification$payload3["gcm.notification.body"])||(notification==null?void 0:(_notification$payload4=notification.payload)==null?void 0:_notification$payload4.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default",sound:"default"});}completion({alert:true,sound:true,badge:true});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload6,_notification$payload7,_notification$payload8,_notification$payload9,_notification$payload0;var notificationTitle=(notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"])||(notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload8=notification.payload)==null?void 0:_notification$payload8["gcm.notification.body"])||(notification==null?void 0:(_notification$payload9=notification.payload)==null?void 0:_notification$payload9.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload0=notification.payload)==null?void 0:_notification$payload0.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default",sound:"default"});}completion({alert:true,sound:true,badge:true});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});var registeredEvent=_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;var isLoggedIn=((_Store$getState=_store.Store.getState())==null?void 0:(_Store$getState$auth=_Store$getState.auth)==null?void 0:_Store$getState$auth.isLoggedIn)||false;if(!isLoggedIn||!event.deviceToken)return;if(pendingRegistrationToken===event.deviceToken)return;pendingRegistrationToken=event.deviceToken;var storedToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(storedToken===event.deviceToken){pendingRegistrationToken=null;return;}var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};registerToken(payload,{onSuccess:function(){var _onSuccess=(0,_asyncToGenerator2.default)(function*(){yield(0,_asyncStore.setItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN,event.deviceToken);pendingRegistrationToken=null;});function onSuccess(){return _onSuccess.apply(this,arguments);}return onSuccess;}(),onError:function onError(){pendingRegistrationToken=null;}});});return function(_x){return _ref3.apply(this,arguments);};}());var registrationFailedEvent=_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});if(_reactNative.Platform.OS==="android"){var defaultNotificationChannel={channelId:"default",name:"Default Channel",importance:5,sound:"default",enableVibration:true,enableLights:true,showBadge:true};var channel01NotificationChannel={channelId:"channel_01",name:"Channel 01",importance:5,enableLights:true,enableVibration:true,showBadge:true};_reactNativeNotifications.Notifications.setNotificationChannel(defaultNotificationChannel);_reactNativeNotifications.Notifications.setNotificationChannel(channel01NotificationChannel);}return[foregroundEvent,backgroundEvent,openedEvent,registeredEvent,registrationFailedEvent];},[registerToken]);(0,_react.useEffect)(function(){var events=registerNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[registerNotificationEvents]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"&&notificationPermission){initializePN();}},[initializePN,isLoggedIn,appState,notificationPermission]);var registerForRemoteNotifications=(0,_react.useCallback)(function(){_reactNativeNotifications.Notifications.registerRemoteNotifications();},[]);var initializePN=(0,_react.useCallback)(function(){try{registerForRemoteNotifications();}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}},[registerForRemoteNotifications]);var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload1,_notification$payload10,_notification$payload11,_notification$payload12;var notificationId=(notification==null?void 0:(_notification$payload1=notification.payload)==null?void 0:_notification$payload1.notification_id)||(notification==null?void 0:(_notification$payload10=notification.payload)==null?void 0:(_notification$payload11=_notification$payload10.aps)==null?void 0:(_notification$payload12=_notification$payload11.alert)==null?void 0:_notification$payload12.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});return[];};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-rn",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "main": ".",
5
5
  "files": [
6
6
  "api",