@bigbinary/neeto-commons-rn 1.0.87 → 1.0.89
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.rootUrlCreator=exports.configureAxiosHeaders=exports.configureAxios=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _neetouiRn=require("@bigbinary/neetoui-rn");var _axios=_interopRequireDefault(require("axios"));var _reactNativeConfig=_interopRequireDefault(require("react-native-config"));var _reactNativeDeviceInfo=_interopRequireDefault(require("react-native-device-info"));var _bugsnag=require("../bugsnag");var _constants=require("../../constants");var _keychain=require("../../helpers/keychain");var _auth=require("../../slices/auth");var _asyncStore=require("../../helpers/asyncStore");var _store=require("../../store");var _paramsSerializer=_interopRequireDefault(require("./paramsSerializer"));_axios.default.defaults.headers.common={accept:"application/json"};var rootUrlCreator=exports.rootUrlCreator=function rootUrlCreator(_ref){var subdomain=_ref.subdomain;return"http"+(_reactNativeConfig.default.IS_DEV?"":"s")+"://"+subdomain+_reactNativeConfig.default.URL_SUFFIX;};var handleSuccessResponse=function handleSuccessResponse(response){return response;};var handleErrorRequest=function handleErrorRequest(error){return console.error(error);};var handleErrorResponse=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(error){var _error$response,_error$response2,_error$response3,_error$response3$data,_error$response4,_error$response4$data;if(((_error$response=error.response)==null?void 0:_error$response.status)===404){(0,_bugsnag.bugsnagErrorHandler)(error,"axiosErrorHandler");}if(((_error$response2=error.response)==null?void 0:_error$response2.status)===401){var _error$response$data;_neetouiRn.Toast.show({type:"error",text2:_store.Store.getState().auth.name?"Your session has expired. Please log in again.":(_error$response$data=error.response.data)==null?void 0:_error$response$data.error});(0,_asyncStore.removeItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);yield(0,_keychain.removeSecureValue)("userAuth");_store.Store.dispatch((0,_auth.logoutUserAction)());}else if((_error$response3=error.response)!=null&&(_error$response3$data=_error$response3.data)!=null&&_error$response3$data.errors){error.response.data.errors.map(function(error){_neetouiRn.Toast.show({type:"error",text2:error});});}else if(typeof((_error$response4=error.response)==null?void 0:(_error$response4$data=_error$response4.data)==null?void 0:_error$response4$data.error)==="object"){var _Object$values,_error$response5,_error$response5$data;_neetouiRn.Toast.show({type:"error",text2:((_Object$values=Object.values((_error$response5=error.response)==null?void 0:(_error$response5$data=_error$response5.data)==null?void 0:_error$response5$data.error))==null?void 0:_Object$values[0])||"Something went wrong"});}else{var _error$response6,_error$response6$data;_neetouiRn.Toast.show({type:"error",text2:((_error$response6=error.response)==null?void 0:(_error$response6$data=_error$response6.data)==null?void 0:_error$response6$data.error)||error.message});}return Promise.reject(error);});return function handleErrorResponse(_x){return _ref2.apply(this,arguments);};}();var registerResponseIntercept=function registerResponseIntercept(){_axios.default.interceptors.response.use(handleSuccessResponse,handleErrorResponse);};var registerRequestIntercept=function registerRequestIntercept(){_axios.default.interceptors.request.use(function(){var _ref3=(0,_asyncToGenerator2.default)(function*(request){var _store$auth;var config=yield configureAxiosHeaders(request);var store=_store.Store.getState();var subdomain=(store==null?void 0:(_store$auth=store.auth)==null?void 0:_store$auth.subdomain)||"app";config.baseURL=rootUrlCreator({subdomain:subdomain});return config;});return function(_x2){return _ref3.apply(this,arguments);};}(),handleErrorRequest);};var configureAxiosHeaders=exports.configureAxiosHeaders=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(request){var authValue=yield(0,_keychain.getSecureValue)("userAuth");var userAuthData=authValue&&JSON.parse(authValue);if(userAuthData){request.headers["x-auth-token"]=userAuthData.authToken;request.headers["x-auth-email"]=userAuthData.email;request.headers["x-client-version"]=_reactNativeDeviceInfo.default.getVersion();request.headers["x-client-name"]=_reactNative.Platform.OS+" "+_reactNativeConfig.default.APP_DISPLAY_NAME;}return request;});return function configureAxiosHeaders(_x3){return _ref4.apply(this,arguments);};}();var configureAxios=exports.configureAxios=function configureAxios(){registerResponseIntercept();registerRequestIntercept();(0,_paramsSerializer.default)();};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _axios=_interopRequireDefault(require("axios"));var _qs=_interopRequireDefault(require("qs"));var setParamsSerializer=function setParamsSerializer(){_axios.default.defaults.paramsSerializer=function(params){return _qs.default.stringify(params,{arrayFormat:"brackets"});};};var _default=exports.default=setParamsSerializer;
|
|
@@ -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 _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 usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn,_ref){var handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();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 events=initializeNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"){initializePN();}},[initializePN,isLoggedIn,appState]);var initializePN=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var notificationPermission=yield(0,_reactNativePermissions.checkNotifications)();if(["blocked","unavailable"].includes(notificationPermission.status)){return;}var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(isRegisteredAlready&&storedDeviceToken)return;registerForRemoteNotifications();});return function initializePN(){return _ref2.apply(this,arguments);};}();var registerForRemoteNotifications=function registerForRemoteNotifications(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(
|
|
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 _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,_ref){var handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();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 events=initializeNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"){initializePN();}},[initializePN,isLoggedIn,appState]);var initializePN=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var notificationPermission=yield(0,_reactNativePermissions.checkNotifications)();if(["blocked","unavailable"].includes(notificationPermission.status)){return;}var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(isRegisteredAlready&&storedDeviceToken)return;registerForRemoteNotifications();});return function initializePN(){return _ref2.apply(this,arguments);};}();var registerForRemoteNotifications=function registerForRemoteNotifications(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(){var isRegistered=false;return function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;if(isRegistered)return;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){isRegistered=true;var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};var notificationDeviceId=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(typeof notificationDeviceId!=="string"){registerToken(payload,{onError:function onError(){return isRegistered=false;}});}}});return function(_x){return _ref3.apply(this,arguments);};}();}();_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(event){return registerDeviceOnce(event);});_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});};var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4;var notificationId=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload.notification_id)||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:(_notification$payload3=_notification$payload2.aps)==null?void 0:(_notification$payload4=_notification$payload3.alert)==null?void 0:_notification$payload4.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});var initializeNotificationEvents=function initializeNotificationEvents(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload5,_notification$payload6,_notification$payload7;_reactNativeNotifications.Notifications.postLocalNotification({body:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5["gcm.notification.body"],title:notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"],url:notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.url});}completion({alert:true,sound:true,badge:false});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(_,completion){completion({alert:true,sound:true,badge:false});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});if(_reactNative.Platform.OS==="android"){_reactNativeNotifications.Notifications.setNotificationChannel({channelId:"default",name:"default",importance:5,enableLights:true,enableVibration:true,showBadge:true});}return[foregroundEvent,backgroundEvent,openedEvent];};return[];};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-rn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.89",
|
|
4
4
|
"main": ".",
|
|
5
5
|
"files": [
|
|
6
6
|
"api",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"formik": "^2.2.9",
|
|
64
64
|
"immutable": "^4.2.2",
|
|
65
65
|
"memoize-one": "^6.0.0",
|
|
66
|
+
"qs": "^6.11.2",
|
|
66
67
|
"ramda": "^0.28.0",
|
|
67
68
|
"react-content-loader": "^6.1.0",
|
|
68
69
|
"react-native-background-timer": "^2.4.1",
|
package/config/axios.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.rootUrlCreator=exports.configureAxiosHeaders=exports.configureAxios=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _reactNative=require("react-native");var _neetouiRn=require("@bigbinary/neetoui-rn");var _axios=_interopRequireDefault(require("axios"));var _reactNativeConfig=_interopRequireDefault(require("react-native-config"));var _reactNativeDeviceInfo=_interopRequireDefault(require("react-native-device-info"));var _bugsnag=require("./bugsnag");var _constants=require("../constants");var _keychain=require("../helpers/keychain");var _auth=require("../slices/auth");var _asyncStore=require("../helpers/asyncStore");var _store=require("../store");_axios.default.defaults.headers.common={accept:"application/json"};var rootUrlCreator=exports.rootUrlCreator=function rootUrlCreator(_ref){var subdomain=_ref.subdomain;return"http"+(_reactNativeConfig.default.IS_DEV?"":"s")+"://"+subdomain+_reactNativeConfig.default.URL_SUFFIX;};var handleSuccessResponse=function handleSuccessResponse(response){return response;};var handleErrorRequest=function handleErrorRequest(error){return console.error(error);};var handleErrorResponse=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(error){var _error$response,_error$response2,_error$response3,_error$response3$data,_error$response4,_error$response4$data;if(((_error$response=error.response)==null?void 0:_error$response.status)===404){(0,_bugsnag.bugsnagErrorHandler)(error,"axiosErrorHandler");}if(((_error$response2=error.response)==null?void 0:_error$response2.status)===401){var _error$response$data;_neetouiRn.Toast.show({type:"error",text2:_store.Store.getState().auth.name?"Your session has expired. Please log in again.":(_error$response$data=error.response.data)==null?void 0:_error$response$data.error});(0,_asyncStore.removeItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);yield(0,_keychain.removeSecureValue)("userAuth");_store.Store.dispatch((0,_auth.logoutUserAction)());}else if((_error$response3=error.response)!=null&&(_error$response3$data=_error$response3.data)!=null&&_error$response3$data.errors){error.response.data.errors.map(function(error){_neetouiRn.Toast.show({type:"error",text2:error});});}else if(typeof((_error$response4=error.response)==null?void 0:(_error$response4$data=_error$response4.data)==null?void 0:_error$response4$data.error)==="object"){var _Object$values,_error$response5,_error$response5$data;_neetouiRn.Toast.show({type:"error",text2:((_Object$values=Object.values((_error$response5=error.response)==null?void 0:(_error$response5$data=_error$response5.data)==null?void 0:_error$response5$data.error))==null?void 0:_Object$values[0])||"Something went wrong"});}else{var _error$response6,_error$response6$data;_neetouiRn.Toast.show({type:"error",text2:((_error$response6=error.response)==null?void 0:(_error$response6$data=_error$response6.data)==null?void 0:_error$response6$data.error)||error.message});}return Promise.reject(error);});return function handleErrorResponse(_x){return _ref2.apply(this,arguments);};}();var registerResponseIntercept=function registerResponseIntercept(){_axios.default.interceptors.response.use(handleSuccessResponse,handleErrorResponse);};var registerRequestIntercept=function registerRequestIntercept(){_axios.default.interceptors.request.use(function(){var _ref3=(0,_asyncToGenerator2.default)(function*(request){var _store$auth;var config=yield configureAxiosHeaders(request);var store=_store.Store.getState();var subdomain=(store==null?void 0:(_store$auth=store.auth)==null?void 0:_store$auth.subdomain)||"app";config.baseURL=rootUrlCreator({subdomain:subdomain});return config;});return function(_x2){return _ref3.apply(this,arguments);};}(),handleErrorRequest);};var configureAxiosHeaders=exports.configureAxiosHeaders=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(request){var authValue=yield(0,_keychain.getSecureValue)("userAuth");var userAuthData=authValue&&JSON.parse(authValue);if(userAuthData){request.headers["x-auth-token"]=userAuthData.authToken;request.headers["x-auth-email"]=userAuthData.email;request.headers["x-client-version"]=_reactNativeDeviceInfo.default.getVersion();request.headers["x-client-name"]=_reactNative.Platform.OS+" "+_reactNativeConfig.default.APP_DISPLAY_NAME;}return request;});return function configureAxiosHeaders(_x3){return _ref4.apply(this,arguments);};}();var configureAxios=exports.configureAxios=function configureAxios(){registerResponseIntercept();registerRequestIntercept();};
|