UNPKG

@shopgate/engage

Version:
14 lines 3.33 kB
import _regeneratorRuntime from"@babel/runtime/regenerator";function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{hasWebBridge,hasSGJavaScriptBridge}from'@shopgate/engage/core/helpers';import{GEOLOCATION_ERROR_DENIED}from'@shopgate/engage/core/constants';import grantGeolocationPermissions from"./grantGeolocationPermissions";import GeolocationRequest from"../classes/GeolocationRequest";/** * Determines the geolocation of the user. When not geolocation permissions are granted yet, * the user will be prompted to grant access. * @param {Object} options Action options. * @param {boolean} [options.useSettingsModal=false] Whether in case of declined permissions a modal * shall be presented, which redirects to the app settings. * @param {Object} [options.modal={}] Options for the settings modal. * @param {string} options.modal.title Modal title. * @param {string} options.modal.message Modal message. * @param {string} options.modal.confirm Label for the confirm button. * @param {string} options.modal.dismiss Label for the dismiss button. * @param {Object} options.modal.params Additional parameters for i18n strings. * @return { Function } A redux thunk. */var getGeolocation=function getGeolocation(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var granted,error;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.next=2;return dispatch(grantGeolocationPermissions(_extends({resolveWithData:true},options)));case 2:granted=_context.sent;if(!(_typeof(granted)==='object')){_context.next=5;break;}return _context.abrupt("return",Promise.resolve(granted));case 5:if(granted){_context.next=9;break;}error=new Error('Geolocation permissions not granted.');error.code=GEOLOCATION_ERROR_DENIED;throw error;case 9:return _context.abrupt("return",new GeolocationRequest(!hasSGJavaScriptBridge()||hasWebBridge()).dispatch());case 10:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());};export default getGeolocation;