@shopgate/pwa-core 6.22.4 → 6.23.0-beta.2

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,78 @@
1
+ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}import _regeneratorRuntime from"@babel/runtime/regenerator";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);});};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}/* eslint-disable class-methods-use-this */import Request from"../Request";import AppCommand from"../AppCommand";import event from"../Event";import requestBuffer from"../RequestBuffer";import{logger}from"../../helpers";import logGroup from"../../helpers/logGroup";var DEFAULT_LIB_VERSION='25.0';/**
2
+ * The AppCommandRequest class is the base class to implement request like app commands that have a
3
+ * corresponding app event that delivers response data.
4
+ * It contains the logic which in necessary to establish the process of sending an
5
+ * app command and receiving an associated event.
6
+ */var AppCommandRequest=/*#__PURE__*/function(_Request){_inherits(AppCommandRequest,_Request);var _super=_createSuper(AppCommandRequest);/**
7
+ * The constructor.
8
+ * @param {string} commandName The name of the command which is dispatched to the app.
9
+ * @param {string} eventName The event name which is called by the app to deliver the data.
10
+ */function AppCommandRequest(commandName,eventName){var _this;_classCallCheck(this,AppCommandRequest);_this=_super.call(this);_this.commandName=commandName;_this.eventName=eventName||"".concat(commandName,"Response");_this.commandParams=null;_this.libVersion=DEFAULT_LIB_VERSION;_this.logColor='#9a9800';event.registerEvent(_this.eventName);_this.createSerial(_this.commandName);_this.createEventCallbackName(_this.eventName);return _this;}/**
11
+ * Sets the parameters for the app command.
12
+ * @param {Object} [commandParams=null] The parameters.
13
+ * @return {AppCommandRequest}
14
+ */_createClass(AppCommandRequest,[{key:"setCommandParams",value:function setCommandParams(){var commandParams=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;this.commandParams=commandParams;return this;}/**
15
+ * Sets the minimum lib version for the app command.
16
+ * @param {string} [libVersion="25.0"] The lib version.
17
+ * @return {AppCommandRequest}
18
+ */},{key:"setLibVersion",value:function setLibVersion(){var libVersion=arguments.length>0&&arguments[0]!==undefined?arguments[0]:DEFAULT_LIB_VERSION;this.libVersion=libVersion;return this;}/**
19
+ * Cleans up the instance after a successful or failed request.
20
+ * @private
21
+ * @param {Function} requestCallback The event callback that processes the response.
22
+ * @return {AppCommandRequest}
23
+ */},{key:"cleanUpRequest",value:function cleanUpRequest(requestCallback){// Remove the event listener entry.
24
+ event.removeCallback(this.getEventCallbackName(),requestCallback);// Remove the request from the buffer.
25
+ requestBuffer.remove(this.serial);return this;}/**
26
+ * Validates the command params before dispatch.
27
+ *
28
+ * This method is supposed to be overwritten by an inheriting class. It's invoked with the
29
+ * currently configured command params object.
30
+ * @param {Object} commandParams The params of the command to be dispatched
31
+ * @return {boolean}
32
+ */},{key:"validateCommandParams",value:function validateCommandParams(){return true;}/**
33
+ * Creates a title for the app command request log.
34
+ *
35
+ * This method is supposed to be overwritten by an inheriting class to enable customization of
36
+ * log output.
37
+ * @returns {string}
38
+ */},{key:"getRequestLogTitle",value:function getRequestLogTitle(){return"AppCommandRequest %c".concat(this.commandName);}/**
39
+ * Creates a title for the app command response log.
40
+ *
41
+ * This method is supposed to be overwritten by an inheriting class to enable customization of
42
+ * log output.
43
+ * @returns {string}
44
+ */},{key:"getResponseLogTitle",value:function getResponseLogTitle(){return"AppCommandResponse %c".concat(this.commandName);}/**
45
+ * Creates payload for the app command response log.
46
+ *
47
+ * This default handler expects the command serial as first and the request response as
48
+ * second command response event parameter. If the class is used for request commands with a
49
+ * different response even payload, this method needs to be overwritten.
50
+ * @param {string} serial The serial that was used to identify the response callback.
51
+ * @param {Object} response The response object for the request
52
+ * @returns {Object}
53
+ */},{key:"getResponseLogPayload",value:function getResponseLogPayload(serial,response){return response;}/**
54
+ * App command response handler. Can be used to implement custom logic for handling the incoming
55
+ * data.
56
+ *
57
+ * This default handler expects the command serial as first and the request response as
58
+ * second command response event parameter. If the class is used for request commands with a
59
+ * different response event payload, this method needs to be overwritten.
60
+ * @param {Function} resolve Resolve callback of the promise returned by the dispatch method
61
+ * of the AppCommandRequest instance.
62
+ * @param {Function} reject Reject callback of the promise returned by the dispatch method
63
+ * of the AppCommandRequest instance.
64
+ * @param {string} serial The serial that was used to identify the response callback.
65
+ * @param {Object} response The response object for the request
66
+ */},{key:"onResponse",value:function onResponse(resolve,reject,serial,response){resolve(response);}/**
67
+ * Dispatches the app request command.
68
+ * @private
69
+ * @param {Function} resolve The resolve() callback of the dispatch promise.
70
+ * @param {Function} reject The reject() callback of the dispatch promise.
71
+ */},{key:"onDispatch",value:function(){var _onDispatch=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve,reject){var _this2=this;var message,requestCallback,command,success;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(!(this.validateCommandParams(this.commandParams)===false)){_context.next=5;break;}// In case of an error log a message and reject the request promise.
72
+ message="".concat(this.commandName," - invalid command parameters passed");logger.error(message,this.commandParams);reject(new Error(message));return _context.abrupt("return");case 5:/**
73
+ * The event callback for the command response.
74
+ */requestCallback=function requestCallback(){for(var _len=arguments.length,params=new Array(_len),_key=0;_key<_len;_key++){params[_key]=arguments[_key];}logGroup(_this2.getResponseLogTitle(),_this2.getResponseLogPayload.apply(_this2,params)||{},_this2.logColor);_this2.cleanUpRequest(requestCallback);_this2.onResponse.apply(_this2,[resolve,reject].concat(params));};// Add the request to the buffer.
75
+ requestBuffer.add(this,this.serial);// Add the event callback for the response.
76
+ event.addCallback(this.getEventCallbackName(),requestCallback);// Prepare the command.
77
+ command=new AppCommand().setCommandName(this.commandName).setLibVersion(this.libVersion).setCommandParams(_extends({serial:this.serial},this.commandParams&&_extends({},this.commandParams)));// Try to dispatch the command.
78
+ _context.next=11;return command.dispatch();case 11:success=_context.sent;if(!(success===false)){_context.next=16;break;}this.cleanUpRequest(requestCallback);reject(new Error("".concat(this.commandName," command dispatch failed")));return _context.abrupt("return");case 16:logGroup(this.getRequestLogTitle(),this.commandParams||{},this.logColor);case 17:case"end":return _context.stop();}}},_callee,this);}));function onDispatch(_x,_x2){return _onDispatch.apply(this,arguments);}return onDispatch;}()}]);return AppCommandRequest;}(Request);/* eslint-enable class-methods-use-this */export default AppCommandRequest;
@@ -1,4 +1,4 @@
1
- function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}import _regeneratorRuntime from"@babel/runtime/regenerator";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);});};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _get(){if(typeof Reflect!=="undefined"&&Reflect.get){_get=Reflect.get;}else{_get=function _get(target,property,receiver){var base=_superPropBase(target,property);if(!base)return;var desc=Object.getOwnPropertyDescriptor(base,property);if(desc.get){return desc.get.call(arguments.length<3?target:receiver);}return desc.value;};}return _get.apply(this,arguments);}function _superPropBase(object,property){while(!Object.prototype.hasOwnProperty.call(object,property)){object=_getPrototypeOf(object);if(object===null)break;}return object;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import Request from"../Request";import AppCommand from"../AppCommand";import event from"../Event";import requestBuffer from"../RequestBuffer";import{logger,hasSGJavaScriptBridge}from"../../helpers";import logGroup from"../../helpers/logGroup";import{PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED,PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_NOT_SUPPORTED,PERMISSION_ID_PUSH,PERMISSION_ID_CAMERA,PERMISSION_ID_LOCATION}from"../../constants/AppPermissions";var MOCK_PERMISSIONS_KEY='sg-mocked-app-permissions';var getMockedAppPermissions;/**
1
+ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _get(){if(typeof Reflect!=="undefined"&&Reflect.get){_get=Reflect.get;}else{_get=function _get(target,property,receiver){var base=_superPropBase(target,property);if(!base)return;var desc=Object.getOwnPropertyDescriptor(base,property);if(desc.get){return desc.get.call(arguments.length<3?target:receiver);}return desc.value;};}return _get.apply(this,arguments);}function _superPropBase(object,property){while(!Object.prototype.hasOwnProperty.call(object,property)){object=_getPrototypeOf(object);if(object===null)break;}return object;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import AppCommandRequest from"../AppCommandRequest";import{hasSGJavaScriptBridge}from"../../helpers";import{PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED,PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_NOT_SUPPORTED,PERMISSION_ID_PUSH,PERMISSION_ID_CAMERA,PERMISSION_ID_LOCATION}from"../../constants/AppPermissions";var MOCK_PERMISSIONS_KEY='sg-mocked-app-permissions';var getMockedAppPermissions;/**
2
2
  * In development within the browser, app permissions can be mocked by calling a global functions
3
3
  * on the MockedPermissions object. The values are persisted in local storage, so that they survive
4
4
  * reload of the PWA.
@@ -35,49 +35,22 @@ localStorage.setItem(MOCK_PERMISSIONS_KEY,JSON.stringify(current));};/**
35
35
  * Prepare global object in DEV environment to mock app permissions
36
36
  */var obj={setGetAppPermissionsResponse:function setGetAppPermissionsResponse(permissionId){var status=arguments.length>1&&arguments[1]!==undefined?arguments[1]:PERMISSION_STATUS_GRANTED;setMockedAppPermission('get',permissionId,status);},setRequestAppPermissionsResponse:function setRequestAppPermissionsResponse(permissionId){var status=arguments.length>1&&arguments[1]!==undefined?arguments[1]:PERMISSION_STATUS_GRANTED;setMockedAppPermission('request',permissionId,status);}};// Populate useful constants
37
37
  obj.STATUS_GRANTED=PERMISSION_STATUS_GRANTED;obj.STATUS_DENIED=PERMISSION_STATUS_DENIED;obj.STATUS_NOT_DETERMINED=PERMISSION_STATUS_NOT_DETERMINED;obj.STATUS_NOT_SUPPORTED=PERMISSION_STATUS_NOT_SUPPORTED;obj.ID_PUSH=PERMISSION_ID_PUSH;obj.ID_CAMERA=PERMISSION_ID_CAMERA;obj.ID_LOCATION=PERMISSION_ID_LOCATION;window.MockedAppPermissions=obj;}/**
38
- * The AppPermissionsRequest class is be base class for app permission related request.
38
+ * The AppPermissionsRequest class is the base class for app permission related requests.
39
39
  * It contains the logic which in necessary to establish the process of sending an
40
40
  * app command and receiving an associated event.
41
- */var AppPermissionsRequest=/*#__PURE__*/function(_Request){_inherits(AppPermissionsRequest,_Request);var _super=_createSuper(AppPermissionsRequest);/**
41
+ */var AppPermissionsRequest=/*#__PURE__*/function(_AppCommandRequest){_inherits(AppPermissionsRequest,_AppCommandRequest);var _super=_createSuper(AppPermissionsRequest);/**
42
42
  * The constructor.
43
43
  * @param {string} commandName The name of the command which is dispatched to the app.
44
44
  * @param {string} eventName The event name which is called by the app to deliver the data.
45
- */function AppPermissionsRequest(commandName,eventName){var _this;_classCallCheck(this,AppPermissionsRequest);_this=_super.call(this);_this.commandName=commandName;_this.eventName=eventName;_this.commandParams=null;_this.libVersion='18.0';_this.createSerial(_this.commandName);_this.createEventCallbackName(_this.eventName);return _this;}/**
46
- * Sets the parameters for the app command.
47
- * @private
48
- * @param {Object} commandParams The parameters.
49
- * @return {AppPermissionsRequest}
50
- */_createClass(AppPermissionsRequest,[{key:"setCommandParams",value:function setCommandParams(commandParams){this.commandParams=commandParams;return this;}/**
51
- * Cleans up the instance after a successful or failed permissions request.
52
- * @private
53
- * @param {Function} requestCallback The event callback that processes the response.
54
- * @return {AppPermissionsRequest}
55
- */},{key:"cleanUpRequest",value:function cleanUpRequest(requestCallback){// Remove the event listener entry.
56
- event.removeCallback(this.getEventCallbackName(),requestCallback);// Remove the request from the buffer.
57
- requestBuffer.remove(this.serial);return this;}/* eslint-disable class-methods-use-this */ /**
58
- * Validates the command params before dispatch.
59
- * @private
60
- * @abstract
61
- * @throws {Error}
62
- */},{key:"validateCommandParams",value:function validateCommandParams(){throw new Error('validateCommandParams needs to be overwritten by inherited class.');}/* eslint-enable class-methods-use-this */ /**
63
- * Dispatches the app permissions command.
64
- * @private
65
- * @param {Function} resolve The resolve() callback of the dispatch promise.
66
- * @param {Function} reject The reject() callback of the dispatch promise.
67
- */},{key:"onDispatch",value:function(){var _onDispatch=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve,reject){var _this2=this;var requestType,message,requestCallback,command,success;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// Prepare the request type for logging.
68
- requestType=this.commandName.replace('AppPermissions','');// Validate the command parameters.
69
- if(!(this.validateCommandParams(this.commandParams)===false)){_context.next=6;break;}// In case of an error log a message and reject the request promise.
70
- message="".concat(this.commandName," - invalid command parameters passed");logger.error(message,this.commandParams);reject(new Error(message));return _context.abrupt("return");case 6:/**
71
- * The event callback for the permissions response.
72
- * @param {string} serial The serial that was used to identify the callback.
73
- * @param {Array} permissions An array with the current app permissions.
74
- */requestCallback=function requestCallback(serial,permissions){logGroup("AppPermissionsResponse %c".concat(requestType),permissions,'#9a9800');_this2.cleanUpRequest(requestCallback);resolve(permissions);};// Add the request to the buffer.
75
- requestBuffer.add(this,this.serial);// Add the event callback for the response.
76
- event.addCallback(this.getEventCallbackName(),requestCallback);// Prepare the permissions command.
77
- command=new AppCommand().setCommandName(this.commandName).setLibVersion(this.libVersion).setCommandParams(_extends({serial:this.serial},this.commandParams&&_extends({},this.commandParams)));// Try to dispatch the command.
78
- _context.next=12;return command.dispatch();case 12:success=_context.sent;if(!(success===false)){_context.next=17;break;}this.cleanUpRequest(requestCallback);reject(new Error("".concat(this.commandName," command dispatch failed")));return _context.abrupt("return");case 17:logGroup("AppPermissionsRequest %c".concat(requestType),this.commandParams,'#adab00');case 18:case"end":return _context.stop();}}},_callee,this);}));function onDispatch(_x,_x2){return _onDispatch.apply(this,arguments);}return onDispatch;}()/**
45
+ */function AppPermissionsRequest(commandName,eventName){var _this;_classCallCheck(this,AppPermissionsRequest);_this=_super.call(this,commandName,eventName);_this.setLibVersion('18.0');return _this;}/**
46
+ * Creates title for the app command request log
47
+ * @returns {string}
48
+ */_createClass(AppPermissionsRequest,[{key:"getRequestLogTitle",value:function getRequestLogTitle(){var requestType=this.commandName.replace('AppPermissions','');return"AppPermissionsRequest %c".concat(requestType);}/**
49
+ * Creates title for the app command response log
50
+ * @returns {string}
51
+ */},{key:"getResponseLogTitle",value:function getResponseLogTitle(){var requestType=this.commandName.replace('AppPermissions','');return"AppPermissionsResponse %c".concat(requestType);}/**
79
52
  * Dispatches the request.
80
53
  * @return {Promise} A promise that is fulfilled when a response is received for this request.
81
- */},{key:"dispatch",value:function dispatch(){var _this3=this;if(!hasSGJavaScriptBridge()){// Mock the response in browser environments, so that the permissions are always granted.
54
+ */},{key:"dispatch",value:function dispatch(){var _this2=this;if(!hasSGJavaScriptBridge()){// Mock the response in browser environments, so that the permissions are always granted.
82
55
  var permissionIds=this.commandParams.permissionIds;var permissions=this.commandParams.permissions;if(permissions){permissionIds=permissions.map(function(permission){return permission.permissionId;});}var result=permissionIds.map(function(permissionId){var status=PERMISSION_STATUS_GRANTED;// Use mocked permissions if available
83
- if(typeof getMockedAppPermissions==='function'){var _permissionMock$permi;var permissionMock=getMockedAppPermissions();var type=_this3.commandName==='getAppPermissions'?'get':'request';status=(permissionMock===null||permissionMock===void 0?void 0:(_permissionMock$permi=permissionMock[permissionId])===null||_permissionMock$permi===void 0?void 0:_permissionMock$permi[type])||PERMISSION_STATUS_GRANTED;}return{permissionId:permissionId,status:status};});return Promise.resolve(result);}return _get(_getPrototypeOf(AppPermissionsRequest.prototype),"dispatch",this).call(this);}}]);return AppPermissionsRequest;}(Request);export default AppPermissionsRequest;
56
+ if(typeof getMockedAppPermissions==='function'){var _permissionMock$permi;var permissionMock=getMockedAppPermissions();var type=_this2.commandName==='getAppPermissions'?'get':'request';status=(permissionMock===null||permissionMock===void 0?void 0:(_permissionMock$permi=permissionMock[permissionId])===null||_permissionMock$permi===void 0?void 0:_permissionMock$permi[type])||PERMISSION_STATUS_GRANTED;}return{permissionId:permissionId,status:status};});return Promise.resolve(result);}return _get(_getPrototypeOf(AppPermissionsRequest.prototype),"dispatch",this).call(this);}}]);return AppPermissionsRequest;}(AppCommandRequest);export default AppPermissionsRequest;
@@ -3,7 +3,7 @@ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeo
3
3
  * permissions by the operation system e.g. location or camera access.
4
4
  */var GetAppPermissionsRequest=/*#__PURE__*/function(_AppPermissionsReques){_inherits(GetAppPermissionsRequest,_AppPermissionsReques);var _super=_createSuper(GetAppPermissionsRequest);/**
5
5
  * The constructor.
6
- */function GetAppPermissionsRequest(){_classCallCheck(this,GetAppPermissionsRequest);return _super.call(this,'getAppPermissions','getAppPermissionsResponse');}/**
6
+ */function GetAppPermissionsRequest(){_classCallCheck(this,GetAppPermissionsRequest);return _super.call(this,'getAppPermissions');}/**
7
7
  * Sets the desired permission ids for the request.
8
8
  * @param {Array} [permissionIds=[]] The permission ids.
9
9
  * @return {GetAppPermissionsRequest}
@@ -3,7 +3,7 @@ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeo
3
3
  * additional permissions from the operating system e.g. location or camera access.
4
4
  */var RequestAppPermissionsRequest=/*#__PURE__*/function(_AppPermissionsReques){_inherits(RequestAppPermissionsRequest,_AppPermissionsReques);var _super=_createSuper(RequestAppPermissionsRequest);/**
5
5
  * The constructor.
6
- */function RequestAppPermissionsRequest(){_classCallCheck(this,RequestAppPermissionsRequest);return _super.call(this,'requestAppPermissions','requestAppPermissionsResponse');}/**
6
+ */function RequestAppPermissionsRequest(){_classCallCheck(this,RequestAppPermissionsRequest);return _super.call(this,'requestAppPermissions');}/**
7
7
  * Sets the desired permissions for the request.
8
8
  * @param {Array} permissions The permissions.
9
9
  * @return {RequestAppPermissionsRequest}
@@ -1,8 +1,8 @@
1
- function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import EventEmitter from'events';import{logger}from"../../helpers";var HANDLER_ADD='add';var HANDLER_REMOVE='remove';/**
1
+ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import EventEmitter from'events';import{logger}from"../../helpers";var HANDLER_ADD='add';var HANDLER_REMOVE='remove';/* eslint-disable extra-rules/potential-point-free */ /**
2
2
  * Event class.
3
3
  */var Event=/*#__PURE__*/function(_EventEmitter){_inherits(Event,_EventEmitter);var _super=_createSuper(Event);/**
4
4
  * Constructor.
5
- */function Event(){var _this;_classCallCheck(this,Event);_this=_super.call(this);_this.setMaxListeners(20);/**
5
+ */function Event(){var _this;_classCallCheck(this,Event);_this=_super.call(this);_this.events=new Set();_this.setMaxListeners(20);/**
6
6
  * A global implementation of the call function to make it accessible to the app.
7
7
  *
8
8
  * We have to check here if there is already a __call from the cake2 project present.
@@ -11,10 +11,13 @@ function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeo
11
11
  var legacy=window.SGEvent.__call;if(typeof legacy!=='function'){// eslint-disable-next-line no-underscore-dangle
12
12
  window.SGEvent.__call=_this.call.bind(_assertThisInitialized(_this));}else{// eslint-disable-next-line no-underscore-dangle
13
13
  window.SGEvent.__call=function(){var _this2;legacy.apply(void 0,arguments);(_this2=_this).call.apply(_this2,arguments);};}return _this;}/**
14
+ * Registers a new event
15
+ * @param {string} eventName The new event name
16
+ */_createClass(Event,[{key:"registerEvent",value:function registerEvent(eventName){this.events.add(eventName);}/**
14
17
  * Registers a callback function for one or multiple events.
15
18
  * @param {string} events A single event or multiple events separated by comma.
16
19
  * @param {Function} callback The callback function.
17
- */_createClass(Event,[{key:"addCallback",value:function addCallback(events,callback){this.handleCallbacks(HANDLER_ADD,events,callback);}/**
20
+ */},{key:"addCallback",value:function addCallback(events,callback){this.handleCallbacks(HANDLER_ADD,events,callback);}/**
18
21
  * De-registers a callback function for one or multiple events.
19
22
  * @param {string} events A single event or multiple events separated by comma.
20
23
  * @param {Function} callback The callback function.
@@ -36,6 +39,6 @@ window.SGEvent.__call=function(){var _this2;legacy.apply(void 0,arguments);(_thi
36
39
  * When these commands were fired, a serial was created in order
37
40
  * to identify an appropriate callback event.
38
41
  * To identify these callbacks, the serial has to be decoded from the parameter list.
39
- */if(['pipelineResponse','httpResponse'].includes(event)){eventName+=":".concat(parameters[1]);}else if(['dataResponse','webStorageResponse','getAppPermissionsResponse','requestAppPermissionsResponse'].includes(event)){eventName+=":".concat(parameters[0]);}var calledEvent=this.emit.apply(this,[eventName].concat(parameters));if(!calledEvent){logger.warn("Attempt to call unknown event: ".concat(eventName));}}}]);return Event;}(EventEmitter);// TODO:
42
+ */if(['pipelineResponse','httpResponse'].includes(event)){eventName+=":".concat(parameters[1]);}else if(['dataResponse','webStorageResponse'].includes(event)||Array.from(this.events).includes(event)){eventName+=":".concat(parameters[0]);}var calledEvent=this.emit.apply(this,[eventName].concat(parameters));if(!calledEvent){logger.warn("Attempt to call unknown event: ".concat(eventName));}}}]);return Event;}(EventEmitter);/* eslint-enable extra-rules/potential-point-free */ // TODO:
40
43
  // We need this as a temporary solution because of double node_modules form extensions and theme.
41
44
  if(!window.TmpEventInstance){window.TmpEventInstance=new Event();}export default window.TmpEventInstance;
@@ -3,7 +3,7 @@
3
3
  */export var PERMISSION_ID_LOCATION='location';export var PERMISSION_ID_CAMERA='camera';// Only available on Android
4
4
  export var PERMISSION_ID_PHONE='phone';export var PERMISSION_ID_BACKGROUND_LOCATION='background_location';// Only available in iOS
5
5
  export var PERMISSION_ID_PUSH='push';// Only available on iOS
6
- export var PERMISSION_ID_BACKGROUND_APP_REFRESH='backgroundAppRefresh';export var availablePermissionsIds=[PERMISSION_ID_BACKGROUND_APP_REFRESH,PERMISSION_ID_BACKGROUND_LOCATION,PERMISSION_ID_CAMERA,PERMISSION_ID_LOCATION,PERMISSION_ID_PHONE,PERMISSION_ID_PUSH];/**
6
+ export var PERMISSION_ID_BACKGROUND_APP_REFRESH='backgroundAppRefresh';export var PERMISSION_ID_APP_TRACKING_TRANSPARENCY='appTrackingTransparency';export var availablePermissionsIds=[PERMISSION_ID_BACKGROUND_APP_REFRESH,PERMISSION_ID_BACKGROUND_LOCATION,PERMISSION_ID_CAMERA,PERMISSION_ID_LOCATION,PERMISSION_ID_PHONE,PERMISSION_ID_PUSH,PERMISSION_ID_APP_TRACKING_TRANSPARENCY];/**
7
7
  * Permission usages.
8
8
  */ /**
9
9
  * @deprecated Use PERMISSION_USAGE_ALWAYS instead
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-core",
3
- "version": "6.22.4",
3
+ "version": "6.23.0-beta.2",
4
4
  "description": "Core library for the Shopgate Connect PWA.",
5
5
  "author": "Support <support@shopgate.com>",
6
6
  "license": "Apache-2.0",