@shopgate/pwa-core 7.30.0-alpha.6 → 7.30.0-alpha.8

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.
Files changed (85) hide show
  1. package/classes/AppCommand/index.js +115 -11
  2. package/classes/AppCommand/spec.js +260 -6
  3. package/classes/AppCommandRequest/index.js +129 -20
  4. package/classes/AppPermissionsRequest/AppPermissionsRequest.js +45 -7
  5. package/classes/AppPermissionsRequest/GetAppPermissionsRequest.js +48 -9
  6. package/classes/AppPermissionsRequest/RequestAppPermissionsRequest.js +54 -9
  7. package/classes/Bridge/index.js +34 -4
  8. package/classes/Bridge/spec.js +24 -1
  9. package/classes/BrightnessRequest/index.js +59 -10
  10. package/classes/BrightnessRequest/spec.js +111 -6
  11. package/classes/BrowserConnector/index.js +180 -26
  12. package/classes/Conditioner/index.js +74 -8
  13. package/classes/Conditioner/spec.js +75 -1
  14. package/classes/DataRequest/index.js +116 -13
  15. package/classes/DevServerBridge/index.js +86 -9
  16. package/classes/DevServerBridge/spec.js +231 -14
  17. package/classes/ErrorManager/index.js +144 -20
  18. package/classes/ErrorManager/spec.js +244 -2
  19. package/classes/Event/index.js +101 -15
  20. package/classes/HttpRequest/index.js +182 -21
  21. package/classes/PipelineDependencies/index.js +42 -6
  22. package/classes/PipelineDependencies/spec.js +46 -3
  23. package/classes/PipelineManager/index.js +517 -71
  24. package/classes/PipelineManager/spec.js +733 -15
  25. package/classes/PipelineRequest/index.js +167 -19
  26. package/classes/PipelineRequest/mock.js +118 -21
  27. package/classes/PipelineRequest/spec.js +333 -2
  28. package/classes/PipelineSequence/index.js +34 -6
  29. package/classes/Request/index.js +61 -13
  30. package/classes/RequestBuffer/index.js +43 -6
  31. package/classes/RequestManager/index.js +216 -33
  32. package/classes/RequestManager/spec.js +188 -1
  33. package/classes/Scanner/index.js +246 -67
  34. package/classes/ScannerEvent/index.js +23 -9
  35. package/classes/ScannerEventHandler/index.js +39 -16
  36. package/classes/ScannerEventListener/index.js +84 -24
  37. package/classes/ScannerManager/ScanProcessingError.js +11 -3
  38. package/classes/ScannerManager/index.js +133 -21
  39. package/classes/WebStorageRequest/index.js +76 -9
  40. package/commands/analyticsSetCustomValues.js +8 -2
  41. package/commands/appPermissions.js +10 -3
  42. package/commands/brightness.js +33 -5
  43. package/commands/broadcastEvent.js +8 -2
  44. package/commands/cleanTab.js +11 -3
  45. package/commands/closeInAppBrowser.js +22 -2
  46. package/commands/flushTab.js +8 -2
  47. package/commands/getWebStorageEntry.js +11 -2
  48. package/commands/hideMenuBar.js +8 -2
  49. package/commands/hideNavigationBar.js +8 -2
  50. package/commands/hideSplashScreen.js +8 -2
  51. package/commands/onload.js +13 -3
  52. package/commands/openAppSettings.js +8 -2
  53. package/commands/openPage.js +8 -2
  54. package/commands/openPageExtern.js +8 -2
  55. package/commands/performCommandsAfterDelay.js +11 -3
  56. package/commands/plotProjects.js +65 -7
  57. package/commands/popTabToRoot.js +11 -3
  58. package/commands/registerEvents.js +10 -2
  59. package/commands/scanner.js +76 -7
  60. package/commands/setCookie.js +8 -2
  61. package/commands/setDebugLoggingEnabled.js +8 -2
  62. package/commands/setScrollingEnabled.js +7 -2
  63. package/commands/setWebStorageEntry.js +8 -2
  64. package/commands/shareItem.js +18 -2
  65. package/commands/showNavigationBar.js +8 -2
  66. package/commands/showTab.js +13 -2
  67. package/commands/unifiedTracking.js +128 -30
  68. package/constants/AppCommands.js +6 -1
  69. package/constants/AppEvents.js +9 -1
  70. package/constants/AppPermissions.js +57 -13
  71. package/constants/Command.js +1 -1
  72. package/constants/ErrorHandleTypes.js +2 -1
  73. package/constants/ErrorManager.js +15 -1
  74. package/constants/Pipeline.js +52 -17
  75. package/constants/ProcessTypes.js +3 -1
  76. package/constants/RequestManagerModes.js +19 -7
  77. package/constants/RequestTypes.js +2 -1
  78. package/constants/Scanner.js +39 -10
  79. package/constants/Trilean.js +6 -1
  80. package/emitters/ui.js +2 -1
  81. package/helpers/index.js +66 -8
  82. package/helpers/logGroup.js +56 -8
  83. package/helpers/version.js +216 -22
  84. package/index.js +60 -5
  85. package/package.json +1 -1
@@ -1,33 +1,137 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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 _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 _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 _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);return Constructor;}import{logger,hasSGJavaScriptBridge}from"../../helpers";import{isValidVersion,getLibVersion,isVersionAtLeast}from"../../helpers/version";import logGroup from"../../helpers/logGroup";import*as appCommands from"../../constants/AppCommands";import Bridge from"../Bridge";/**
1
+ import { logger, hasSGJavaScriptBridge } from "../../helpers";
2
+ import { isValidVersion, getLibVersion, isVersionAtLeast } from "../../helpers/version";
3
+ import logGroup from "../../helpers/logGroup";
4
+ import * as appCommands from "../../constants/AppCommands";
5
+ import Bridge from "../Bridge";
6
+
7
+ /**
2
8
  * The app command class.
3
- */var AppCommand=/*#__PURE__*/function(){/**
9
+ */
10
+ class AppCommand {
11
+ /**
4
12
  * @param {boolean} log Whether the command will be logged.
5
13
  * @param {boolean} checkLibVersion Whether the lib version will be checked before dispatch.
6
- */function AppCommand(){var log=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var checkLibVersion=arguments.length>1&&arguments[1]!==undefined?arguments[1]:hasSGJavaScriptBridge();_classCallCheck(this,AppCommand);this.log=log;this.checkLibVersion=checkLibVersion;this.name='';this.params=null;this.libVersion='9.0';this.commandsWithoutLog=[appCommands.COMMAND_SEND_PIPELINE_REQUEST,appCommands.COMMAND_SEND_HTTP_REQUEST,appCommands.COMMAND_GET_WEBSTORAGE_ENTRY];}/**
14
+ */
15
+ constructor(log = true, checkLibVersion = hasSGJavaScriptBridge()) {
16
+ this.log = log;
17
+ this.checkLibVersion = checkLibVersion;
18
+ this.name = '';
19
+ this.params = null;
20
+ this.libVersion = '9.0';
21
+ this.commandsWithoutLog = [appCommands.COMMAND_SEND_PIPELINE_REQUEST, appCommands.COMMAND_SEND_HTTP_REQUEST, appCommands.COMMAND_GET_WEBSTORAGE_ENTRY];
22
+ }
23
+
24
+ /**
7
25
  * Sets the command name.
8
26
  * @param {string} name The command name.
9
27
  * @return {AppCommand}
10
- */return _createClass(AppCommand,[{key:"setCommandName",value:function setCommandName(name){if(typeof name==='string'){this.name=name;}else{logger.error('Invalid command name',name);}return this;}/**
28
+ */
29
+ setCommandName(name) {
30
+ if (typeof name === 'string') {
31
+ this.name = name;
32
+ } else {
33
+ logger.error('Invalid command name', name);
34
+ }
35
+ return this;
36
+ }
37
+
38
+ /**
11
39
  * Sets the command params.
12
40
  * @param {Object} [params=null] The command params.
13
41
  * @return {AppCommand}
14
- */},{key:"setCommandParams",value:function setCommandParams(params){if(params&&_typeof(params)==='object'&&params.constructor===Object){this.params=params;}else{logger.error('Invalid command params',params);}return this;}/**
42
+ */
43
+ setCommandParams(params) {
44
+ if (params && typeof params === 'object' && params.constructor === Object) {
45
+ this.params = params;
46
+ } else {
47
+ logger.error('Invalid command params', params);
48
+ }
49
+ return this;
50
+ }
51
+
52
+ /**
15
53
  * Sets the minimum required shopgate lib version for the command.
16
54
  * @param {string} libVersion The library version.
17
55
  * @return {AppCommand}
18
- */},{key:"setLibVersion",value:function setLibVersion(libVersion){if(isValidVersion(libVersion)){this.libVersion=libVersion;}else{logger.error('Invalid lib version',libVersion);}return this;}/**
56
+ */
57
+ setLibVersion(libVersion) {
58
+ if (isValidVersion(libVersion)) {
59
+ this.libVersion = libVersion;
60
+ } else {
61
+ logger.error('Invalid lib version', libVersion);
62
+ }
63
+ return this;
64
+ }
65
+
66
+ /**
19
67
  * Logs the command to the console.
20
68
  * @private
21
69
  * @return {AppCommand}
22
- */},{key:"logCommand",value:function logCommand(){if(this.log&&!this.commandsWithoutLog.includes(this.name)){var title="AppCommand %c".concat(this.name);logGroup(title,this.params||{},'#8e44ad');}return this;}/**
70
+ */
71
+ logCommand() {
72
+ if (this.log && !this.commandsWithoutLog.includes(this.name)) {
73
+ const title = `AppCommand %c${this.name}`;
74
+ logGroup(title, this.params || {}, '#8e44ad');
75
+ }
76
+ return this;
77
+ }
78
+
79
+ /**
23
80
  * Creates the command object which will be dispatched through the JavaScript bridge.
24
81
  * @return {Object|null}
25
- */},{key:"buildCommand",value:function buildCommand(){var command=this.name?_extends({c:this.name},this.params&&{p:this.params}):null;return command;}/**
82
+ */
83
+ buildCommand() {
84
+ const command = this.name ? {
85
+ c: this.name,
86
+ ...(this.params && {
87
+ p: this.params
88
+ })
89
+ } : null;
90
+ return command;
91
+ }
92
+
93
+ /**
26
94
  * Dispatches the command to the app.
27
95
  * The returned promise will not be rejected for now in error cases to avoid the necessity
28
96
  * of refactoring within existing code. But it resolves with FALSE in those cases.
29
97
  * @param {Object} [params] The command params.
30
98
  * @return {Promise<boolean>}
31
- */},{key:"dispatch",value:function(){var _dispatch=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(params){var command,appLibVersion,appHasSupport,bridge;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(params){this.setCommandParams(params);}command=this.buildCommand();// Only proceed if the command is valid.
32
- if(!(command===null)){_context.next=5;break;}logger.error("Dispatch aborted for invalid command. name: \"".concat(this.name,"\" | params:"),this.params);return _context.abrupt("return",false);case 5:appLibVersion=this.libVersion;appHasSupport=true;// Perform a libVersion check if the flag is active.
33
- if(!this.checkLibVersion){_context.next=12;break;}_context.next=10;return getLibVersion();case 10:appLibVersion=_context.sent;appHasSupport=isVersionAtLeast(this.libVersion,appLibVersion);case 12:if(appHasSupport){_context.next=15;break;}logger.warn("The command \"".concat(this.name,"\" is not supported by LibVersion (required ").concat(this.libVersion," | current ").concat(appLibVersion,")"));return _context.abrupt("return",false);case 15:bridge=new Bridge();_context.prev=16;bridge.dispatchCommand(command,appLibVersion);this.logCommand();_context.next=25;break;case 21:_context.prev=21;_context.t0=_context["catch"](16);logger.error(_context.t0);return _context.abrupt("return",false);case 25:return _context.abrupt("return",true);case 26:case"end":return _context.stop();}},_callee,this,[[16,21]]);}));function dispatch(_x){return _dispatch.apply(this,arguments);}return dispatch;}()}]);}();export default AppCommand;
99
+ */
100
+ async dispatch(params) {
101
+ if (params) {
102
+ this.setCommandParams(params);
103
+ }
104
+ const command = this.buildCommand();
105
+
106
+ // Only proceed if the command is valid.
107
+ if (command === null) {
108
+ logger.error(`Dispatch aborted for invalid command. name: "${this.name}" | params:`, this.params);
109
+ return false;
110
+ }
111
+ let appLibVersion = this.libVersion;
112
+ let appHasSupport = true;
113
+
114
+ // Perform a libVersion check if the flag is active.
115
+ if (this.checkLibVersion) {
116
+ // Gather the libVersion of the app and check if it supports the command.
117
+ appLibVersion = await getLibVersion();
118
+ appHasSupport = isVersionAtLeast(this.libVersion, appLibVersion);
119
+ }
120
+
121
+ // Only proceed if the command is supported by the app.
122
+ if (!appHasSupport) {
123
+ logger.warn(`The command "${this.name}" is not supported by LibVersion (required ${this.libVersion} | current ${appLibVersion})`);
124
+ return false;
125
+ }
126
+ const bridge = new Bridge();
127
+ try {
128
+ bridge.dispatchCommand(command, appLibVersion);
129
+ this.logCommand();
130
+ } catch (exception) {
131
+ logger.error(exception);
132
+ return false;
133
+ }
134
+ return true;
135
+ }
136
+ }
137
+ export default AppCommand;
@@ -1,8 +1,262 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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{hasSGJavaScriptBridge}from"../../helpers";import{defaultClientInformation}from"../../helpers/version";import AppCommand from"./index";jest.unmock("./index.js");// Mocks for the logger.
2
- var mockedLoggerError=jest.fn();var mockedLoggerWarn=jest.fn();jest.mock("../../helpers",function(){return{logger:{error:function error(){mockedLoggerError.apply(void 0,arguments);},warn:function warn(){mockedLoggerWarn.apply(void 0,arguments);},log:function log(){}},hasSGJavaScriptBridge:jest.fn().mockReturnValue(false),useBrowserConnector:function useBrowserConnector(){return false;}};});var mockedLogGroup=jest.fn();// eslint-disable-next-line extra-rules/potential-point-free
3
- jest.mock("../../helpers/logGroup",function(){return function logGroup(){mockedLogGroup.apply(void 0,arguments);};});// Mock of the DevServer bridge.
4
- var mockedBridgeDispatch=jest.fn();jest.mock("../DevServerBridge",function(){return function(){return{dispatchCommandsForVersion:mockedBridgeDispatch};};});// Mock of the client information web storage.
5
- var mockedClientInformation=null;jest.mock("../../commands/getWebStorageEntry",function(){return jest.fn().mockImplementation(function(){return{then:function then(cb){cb({value:mockedClientInformation});}};});});var defaultLibVersion=defaultClientInformation.libVersion;/**
1
+ import { hasSGJavaScriptBridge } from "../../helpers";
2
+ import { defaultClientInformation } from "../../helpers/version";
3
+ import AppCommand from "./index";
4
+ jest.unmock("./index.js");
5
+
6
+ // Mocks for the logger.
7
+ const mockedLoggerError = jest.fn();
8
+ const mockedLoggerWarn = jest.fn();
9
+ jest.mock("../../helpers", () => ({
10
+ logger: {
11
+ error: (...args) => {
12
+ mockedLoggerError(...args);
13
+ },
14
+ warn: (...args) => {
15
+ mockedLoggerWarn(...args);
16
+ },
17
+ log: () => {}
18
+ },
19
+ hasSGJavaScriptBridge: jest.fn().mockReturnValue(false),
20
+ useBrowserConnector: () => false
21
+ }));
22
+ const mockedLogGroup = jest.fn();
23
+ // eslint-disable-next-line extra-rules/potential-point-free
24
+ jest.mock("../../helpers/logGroup", () => function logGroup(...args) {
25
+ mockedLogGroup(...args);
26
+ });
27
+ let mockedBridgeDispatch = jest.fn();
28
+
29
+ /* eslint-disable require-jsdoc, class-methods-use-this */
30
+ jest.mock("../DevServerBridge", () => {
31
+ class DevServerBridge {
32
+ dispatchCommandsForVersion(...args) {
33
+ return mockedBridgeDispatch(...args);
34
+ }
35
+ }
36
+ return {
37
+ __esModule: true,
38
+ default: DevServerBridge
39
+ };
40
+ });
41
+ /* eslint-enable require-jsdoc, class-methods-use-this */
42
+
43
+ // Mock of the client information web storage.
44
+ let mockedClientInformation = null;
45
+ jest.mock("../../commands/getWebStorageEntry", () => jest.fn().mockImplementation(() => ({
46
+ then(cb) {
47
+ cb({
48
+ value: mockedClientInformation
49
+ });
50
+ }
51
+ })));
52
+ const defaultLibVersion = defaultClientInformation.libVersion;
53
+
54
+ /**
6
55
  * Updates the mocked client information.
7
56
  * @param {string} libVersion The libVersion.
8
- */var setClientInformation=function setClientInformation(){var libVersion=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultLibVersion;mockedClientInformation={libVersion:libVersion};};describe('AppCommand',function(){var instance;beforeEach(function(){setClientInformation();mockedLoggerError.mockClear();mockedLoggerWarn.mockClear();mockedLogGroup.mockClear();mockedBridgeDispatch.mockClear();instance=new AppCommand(true,true);});describe('.constructor()',function(){it('should construct as expected without parameters',function(){instance=new AppCommand();expect(instance.log).toBe(true);expect(instance.checkLibVersion).toBe(false);});it('should construct as expected when the SGJavaScriptBridge was detected',function(){hasSGJavaScriptBridge.mockReturnValueOnce(true);instance=new AppCommand();expect(instance.log).toBe(true);expect(instance.checkLibVersion).toBe(true);});it('should construct as expected when log parameter is false',function(){instance=new AppCommand(false,true);expect(instance.log).toBe(false);expect(instance.checkLibVersion).toBe(true);});});describe('.setCommandName()',function(){it('should set a valid value',function(){var value='sendPipelineRequest';var command=instance.setCommandName(value);expect(command).toEqual(instance);expect(command.name).toEqual(value);});it('should not set an invalid value',function(){var initial=instance.name;var command=instance.setCommandName(17.3);expect(command).toEqual(instance);expect(command.name).toEqual(initial);expect(mockedLoggerError).toHaveBeenCalledTimes(1);});});describe('.setCommandParams()',function(){it('should set a valid value',function(){var value={paramOne:'foo',paramTwo:1337};var command=instance.setCommandParams(value);expect(command).toEqual(instance);expect(command.params).toEqual(value);});it('should not set an invalid value',function(){var initial=instance.params;var command=instance.setCommandParams('sendPipelineRequest');expect(command).toEqual(instance);expect(command.params).toEqual(initial);expect(mockedLoggerError).toHaveBeenCalledTimes(1);});});describe('.setLibVersion()',function(){it('should set a valid value',function(){var value='17.2';var command=instance.setLibVersion(value);expect(command).toEqual(instance);expect(command.libVersion).toEqual(value);});it('should not set an invalid value',function(){var initial=instance.libVersion;var command=instance.setLibVersion('sendPipelineRequest');expect(command).toEqual(instance);expect(command.libVersion).toEqual(initial);expect(mockedLoggerError).toHaveBeenCalledTimes(1);});});describe('.logCommand',function(){it('should log a command',function(){instance.setCommandName('openPage');var command=instance.logCommand();expect(command).toEqual(instance);expect(mockedLogGroup).toHaveBeenCalledTimes(1);});it('should not log a command when logging is turned off',function(){instance=new AppCommand(false);instance.setCommandName('openPage');var command=instance.logCommand();expect(command).toEqual(instance);expect(mockedLogGroup).toHaveBeenCalledTimes(0);});it('should not log a command when it is blacklisted',function(){instance.setCommandName('sendPipelineRequest');var command=instance.logCommand();expect(command).toEqual(instance);expect(mockedLogGroup).toHaveBeenCalledTimes(0);});});describe('.buildCommand()',function(){it('should build a command when name and params are set',function(){var name='sendPipelineRequest';var params={paramOne:'foo',paramTwo:1337};var expected={c:name,p:params};instance.setCommandName(name);instance.setCommandParams(params);var result=instance.buildCommand();expect(result).toEqual(expected);});it('should build a command when only the name is set',function(){var name='sendPipelineRequest';var expected={c:name};instance.setCommandName(name);var result=instance.buildCommand();expect(result).toEqual(expected);});it('should not build a command when no name is set',function(){var params={paramOne:'foo',paramTwo:1337};instance.setCommandParams(params);var result=instance.buildCommand();expect(result).toEqual(null);});});describe('.dispatch()',function(){it('should dispatch as expected',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var name,result;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:name='sendPipelineRequest';instance.setCommandName(name);_context.next=4;return instance.dispatch();case 4:result=_context.sent;expect(result).toBe(true);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);expect(mockedBridgeDispatch.mock.calls[0][0][0].c).toBe(name);expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(defaultLibVersion);expect(mockedLoggerError).toHaveBeenCalledTimes(0);expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);case 11:case"end":return _context.stop();}},_callee);})));it('should set the params if passed to dispatch',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){var params,result;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:params={paramOne:'foo',paramTwo:1337};instance.setCommandName('sendPipelineRequest');_context2.next=4;return instance.dispatch(params);case 4:result=_context2.sent;expect(result).toBe(true);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);expect(mockedBridgeDispatch.mock.calls[0][0][0].p).toEqual(params);expect(mockedLoggerError).toHaveBeenCalledTimes(0);expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);case 10:case"end":return _context2.stop();}},_callee2);})));it('should not dispatch when no command was set up',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){var result;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:_context3.next=2;return instance.dispatch();case 2:result=_context3.sent;expect(result).toBe(false);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);expect(mockedLoggerError).toHaveBeenCalledTimes(1);expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);case 7:case"end":return _context3.stop();}},_callee3);})));it('should not dispatch when the command is not supported by the app',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){var libVersion,result;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:libVersion=(Number.parseFloat(defaultLibVersion)+1).toFixed(1);instance.setCommandName('sendPipelineRequest');instance.setLibVersion(libVersion);_context4.next=5;return instance.dispatch();case 5:result=_context4.sent;expect(result).toBe(false);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);expect(mockedLoggerError).toHaveBeenCalledTimes(0);expect(mockedLoggerWarn).toHaveBeenCalledTimes(1);case 10:case"end":return _context4.stop();}},_callee4);})));it('should dispatch when the command is not supported by the app but the check is off',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){var libVersion,result;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:libVersion=(Number.parseFloat(defaultLibVersion)+1).toFixed(1);instance=new AppCommand(true,false);instance.setCommandName('sendPipelineRequest');instance.setLibVersion(libVersion);_context5.next=6;return instance.dispatch();case 6:result=_context5.sent;expect(result).toBe(true);expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(libVersion);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);expect(mockedLoggerError).toHaveBeenCalledTimes(0);expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);case 12:case"end":return _context5.stop();}},_callee5);})));it('should handle errors during bridge dispatch',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var name,result;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:mockedBridgeDispatch=jest.fn().mockImplementation(function(){throw new Error();});name='sendPipelineRequest';instance.setCommandName(name);_context6.next=5;return instance.dispatch();case 5:result=_context6.sent;expect(result).toBe(false);expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);expect(mockedLoggerError).toHaveBeenCalledTimes(1);expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);case 10:case"end":return _context6.stop();}},_callee6);})));});});
57
+ */
58
+ const setClientInformation = (libVersion = defaultLibVersion) => {
59
+ mockedClientInformation = {
60
+ libVersion
61
+ };
62
+ };
63
+ describe('AppCommand', () => {
64
+ let instance;
65
+ beforeEach(() => {
66
+ setClientInformation();
67
+ mockedLoggerError.mockClear();
68
+ mockedLoggerWarn.mockClear();
69
+ mockedLogGroup.mockClear();
70
+ mockedBridgeDispatch.mockClear();
71
+ instance = new AppCommand(true, true);
72
+ });
73
+ describe('.constructor()', () => {
74
+ it('should construct as expected without parameters', () => {
75
+ instance = new AppCommand();
76
+ expect(instance.log).toBe(true);
77
+ expect(instance.checkLibVersion).toBe(false);
78
+ });
79
+ it('should construct as expected when the SGJavaScriptBridge was detected', () => {
80
+ hasSGJavaScriptBridge.mockReturnValueOnce(true);
81
+ instance = new AppCommand();
82
+ expect(instance.log).toBe(true);
83
+ expect(instance.checkLibVersion).toBe(true);
84
+ });
85
+ it('should construct as expected when log parameter is false', () => {
86
+ instance = new AppCommand(false, true);
87
+ expect(instance.log).toBe(false);
88
+ expect(instance.checkLibVersion).toBe(true);
89
+ });
90
+ });
91
+ describe('.setCommandName()', () => {
92
+ it('should set a valid value', () => {
93
+ const value = 'sendPipelineRequest';
94
+ const command = instance.setCommandName(value);
95
+ expect(command).toEqual(instance);
96
+ expect(command.name).toEqual(value);
97
+ });
98
+ it('should not set an invalid value', () => {
99
+ const initial = instance.name;
100
+ const command = instance.setCommandName(17.3);
101
+ expect(command).toEqual(instance);
102
+ expect(command.name).toEqual(initial);
103
+ expect(mockedLoggerError).toHaveBeenCalledTimes(1);
104
+ });
105
+ });
106
+ describe('.setCommandParams()', () => {
107
+ it('should set a valid value', () => {
108
+ const value = {
109
+ paramOne: 'foo',
110
+ paramTwo: 1337
111
+ };
112
+ const command = instance.setCommandParams(value);
113
+ expect(command).toEqual(instance);
114
+ expect(command.params).toEqual(value);
115
+ });
116
+ it('should not set an invalid value', () => {
117
+ const initial = instance.params;
118
+ const command = instance.setCommandParams('sendPipelineRequest');
119
+ expect(command).toEqual(instance);
120
+ expect(command.params).toEqual(initial);
121
+ expect(mockedLoggerError).toHaveBeenCalledTimes(1);
122
+ });
123
+ });
124
+ describe('.setLibVersion()', () => {
125
+ it('should set a valid value', () => {
126
+ const value = '17.2';
127
+ const command = instance.setLibVersion(value);
128
+ expect(command).toEqual(instance);
129
+ expect(command.libVersion).toEqual(value);
130
+ });
131
+ it('should not set an invalid value', () => {
132
+ const initial = instance.libVersion;
133
+ const command = instance.setLibVersion('sendPipelineRequest');
134
+ expect(command).toEqual(instance);
135
+ expect(command.libVersion).toEqual(initial);
136
+ expect(mockedLoggerError).toHaveBeenCalledTimes(1);
137
+ });
138
+ });
139
+ describe('.logCommand', () => {
140
+ it('should log a command', () => {
141
+ instance.setCommandName('openPage');
142
+ const command = instance.logCommand();
143
+ expect(command).toEqual(instance);
144
+ expect(mockedLogGroup).toHaveBeenCalledTimes(1);
145
+ });
146
+ it('should not log a command when logging is turned off', () => {
147
+ instance = new AppCommand(false);
148
+ instance.setCommandName('openPage');
149
+ const command = instance.logCommand();
150
+ expect(command).toEqual(instance);
151
+ expect(mockedLogGroup).toHaveBeenCalledTimes(0);
152
+ });
153
+ it('should not log a command when it is blacklisted', () => {
154
+ instance.setCommandName('sendPipelineRequest');
155
+ const command = instance.logCommand();
156
+ expect(command).toEqual(instance);
157
+ expect(mockedLogGroup).toHaveBeenCalledTimes(0);
158
+ });
159
+ });
160
+ describe('.buildCommand()', () => {
161
+ it('should build a command when name and params are set', () => {
162
+ const name = 'sendPipelineRequest';
163
+ const params = {
164
+ paramOne: 'foo',
165
+ paramTwo: 1337
166
+ };
167
+ const expected = {
168
+ c: name,
169
+ p: params
170
+ };
171
+ instance.setCommandName(name);
172
+ instance.setCommandParams(params);
173
+ const result = instance.buildCommand();
174
+ expect(result).toEqual(expected);
175
+ });
176
+ it('should build a command when only the name is set', () => {
177
+ const name = 'sendPipelineRequest';
178
+ const expected = {
179
+ c: name
180
+ };
181
+ instance.setCommandName(name);
182
+ const result = instance.buildCommand();
183
+ expect(result).toEqual(expected);
184
+ });
185
+ it('should not build a command when no name is set', () => {
186
+ const params = {
187
+ paramOne: 'foo',
188
+ paramTwo: 1337
189
+ };
190
+ instance.setCommandParams(params);
191
+ const result = instance.buildCommand();
192
+ expect(result).toEqual(null);
193
+ });
194
+ });
195
+ describe('.dispatch()', () => {
196
+ it('should dispatch as expected', async () => {
197
+ const name = 'sendPipelineRequest';
198
+ instance.setCommandName(name);
199
+ const result = await instance.dispatch();
200
+ expect(result).toBe(true);
201
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
202
+ expect(mockedBridgeDispatch.mock.calls[0][0][0].c).toBe(name);
203
+ expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(defaultLibVersion);
204
+ expect(mockedLoggerError).toHaveBeenCalledTimes(0);
205
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
206
+ });
207
+ it('should set the params if passed to dispatch', async () => {
208
+ const params = {
209
+ paramOne: 'foo',
210
+ paramTwo: 1337
211
+ };
212
+ instance.setCommandName('sendPipelineRequest');
213
+ const result = await instance.dispatch(params);
214
+ expect(result).toBe(true);
215
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
216
+ expect(mockedBridgeDispatch.mock.calls[0][0][0].p).toEqual(params);
217
+ expect(mockedLoggerError).toHaveBeenCalledTimes(0);
218
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
219
+ });
220
+ it('should not dispatch when no command was set up', async () => {
221
+ const result = await instance.dispatch();
222
+ expect(result).toBe(false);
223
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);
224
+ expect(mockedLoggerError).toHaveBeenCalledTimes(1);
225
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
226
+ });
227
+ it('should not dispatch when the command is not supported by the app', async () => {
228
+ const libVersion = (Number.parseFloat(defaultLibVersion) + 1).toFixed(1);
229
+ instance.setCommandName('sendPipelineRequest');
230
+ instance.setLibVersion(libVersion);
231
+ const result = await instance.dispatch();
232
+ expect(result).toBe(false);
233
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(0);
234
+ expect(mockedLoggerError).toHaveBeenCalledTimes(0);
235
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(1);
236
+ });
237
+ it('should dispatch when the command is not supported by the app but the check is off', async () => {
238
+ const libVersion = (Number.parseFloat(defaultLibVersion) + 1).toFixed(1);
239
+ instance = new AppCommand(true, false);
240
+ instance.setCommandName('sendPipelineRequest');
241
+ instance.setLibVersion(libVersion);
242
+ const result = await instance.dispatch();
243
+ expect(result).toBe(true);
244
+ expect(mockedBridgeDispatch.mock.calls[0][1]).toBe(libVersion);
245
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
246
+ expect(mockedLoggerError).toHaveBeenCalledTimes(0);
247
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
248
+ });
249
+ it('should handle errors during bridge dispatch', async () => {
250
+ mockedBridgeDispatch = jest.fn().mockImplementation(() => {
251
+ throw new Error();
252
+ });
253
+ const name = 'sendPipelineRequest';
254
+ instance.setCommandName(name);
255
+ const result = await instance.dispatch();
256
+ expect(result).toBe(false);
257
+ expect(mockedBridgeDispatch).toHaveBeenCalledTimes(1);
258
+ expect(mockedLoggerError).toHaveBeenCalledTimes(1);
259
+ expect(mockedLoggerWarn).toHaveBeenCalledTimes(0);
260
+ });
261
+ });
262
+ });
@@ -1,47 +1,105 @@
1
- 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);});};}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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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);}/* 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';/**
1
+ /* eslint-disable class-methods-use-this */
2
+ import Request from "../Request";
3
+ import AppCommand from "../AppCommand";
4
+ import event from "../Event";
5
+ import requestBuffer from "../RequestBuffer";
6
+ import { logger } from "../../helpers";
7
+ import logGroup from "../../helpers/logGroup";
8
+ const DEFAULT_LIB_VERSION = '25.0';
9
+
10
+ /**
2
11
  * The AppCommandRequest class is the base class to implement request like app commands that have a
3
12
  * corresponding app event that delivers response data.
4
13
  * It contains the logic which in necessary to establish the process of sending an
5
14
  * app command and receiving an associated event.
6
- */var AppCommandRequest=/*#__PURE__*/function(_Request){/**
15
+ */
16
+ class AppCommandRequest extends Request {
17
+ /**
7
18
  * The constructor.
8
19
  * @param {string} commandName The name of the command which is dispatched to the app.
9
20
  * @param {string} eventName The event name which is called by the app to deliver the data.
10
- */function AppCommandRequest(commandName,eventName){var _this2;_classCallCheck(this,AppCommandRequest);_this2=_callSuper(this,AppCommandRequest);_this2.commandName=commandName;_this2.eventName=eventName||"".concat(commandName,"Response");_this2.commandParams=null;_this2.libVersion=DEFAULT_LIB_VERSION;_this2.logColor='#9a9800';event.registerEvent(_this2.eventName);_this2.createSerial(_this2.commandName);_this2.createEventCallbackName(_this2.eventName);return _this2;}/**
21
+ */
22
+ constructor(commandName, eventName) {
23
+ super();
24
+ this.commandName = commandName;
25
+ this.eventName = eventName || `${commandName}Response`;
26
+ this.commandParams = null;
27
+ this.libVersion = DEFAULT_LIB_VERSION;
28
+ this.logColor = '#9a9800';
29
+ event.registerEvent(this.eventName);
30
+ this.createSerial(this.commandName);
31
+ this.createEventCallbackName(this.eventName);
32
+ }
33
+
34
+ /**
11
35
  * Sets the parameters for the app command.
12
36
  * @param {Object} [commandParams=null] The parameters.
13
37
  * @return {AppCommandRequest}
14
- */_inherits(AppCommandRequest,_Request);return _createClass(AppCommandRequest,[{key:"setCommandParams",value:function setCommandParams(){var commandParams=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;this.commandParams=commandParams;return this;}/**
38
+ */
39
+ setCommandParams(commandParams = null) {
40
+ this.commandParams = commandParams;
41
+ return this;
42
+ }
43
+
44
+ /**
15
45
  * Sets the minimum lib version for the app command.
16
46
  * @param {string} [libVersion="25.0"] The lib version.
17
47
  * @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;}/**
48
+ */
49
+ setLibVersion(libVersion = DEFAULT_LIB_VERSION) {
50
+ this.libVersion = libVersion;
51
+ return this;
52
+ }
53
+
54
+ /**
19
55
  * Cleans up the instance after a successful or failed request.
20
56
  * @private
21
57
  * @param {Function} requestCallback The event callback that processes the response.
22
58
  * @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;}/**
59
+ */
60
+ cleanUpRequest(requestCallback) {
61
+ // Remove the event listener entry.
62
+ event.removeCallback(this.getEventCallbackName(), requestCallback);
63
+ // Remove the request from the buffer.
64
+ requestBuffer.remove(this.serial);
65
+ return this;
66
+ }
67
+
68
+ /**
26
69
  * Validates the command params before dispatch.
27
70
  *
28
71
  * This method is supposed to be overwritten by an inheriting class. It's invoked with the
29
72
  * currently configured command params object.
30
73
  * @param {Object} commandParams The params of the command to be dispatched
31
74
  * @return {boolean}
32
- */},{key:"validateCommandParams",value:function validateCommandParams(){return true;}/**
75
+ */
76
+ validateCommandParams() {
77
+ return true;
78
+ }
79
+
80
+ /**
33
81
  * Creates a title for the app command request log.
34
82
  *
35
83
  * This method is supposed to be overwritten by an inheriting class to enable customization of
36
84
  * log output.
37
85
  * @returns {string}
38
- */},{key:"getRequestLogTitle",value:function getRequestLogTitle(){return"AppCommandRequest %c".concat(this.commandName);}/**
86
+ */
87
+ getRequestLogTitle() {
88
+ return `AppCommandRequest %c${this.commandName}`;
89
+ }
90
+
91
+ /**
39
92
  * Creates a title for the app command response log.
40
93
  *
41
94
  * This method is supposed to be overwritten by an inheriting class to enable customization of
42
95
  * log output.
43
96
  * @returns {string}
44
- */},{key:"getResponseLogTitle",value:function getResponseLogTitle(){return"AppCommandResponse %c".concat(this.commandName);}/**
97
+ */
98
+ getResponseLogTitle() {
99
+ return `AppCommandResponse %c${this.commandName}`;
100
+ }
101
+
102
+ /**
45
103
  * Creates payload for the app command response log.
46
104
  *
47
105
  * This default handler expects the command serial as first and the request response as
@@ -50,7 +108,12 @@ requestBuffer.remove(this.serial);return this;}/**
50
108
  * @param {string} serial The serial that was used to identify the response callback.
51
109
  * @param {Object} response The response object for the request
52
110
  * @returns {Object}
53
- */},{key:"getResponseLogPayload",value:function getResponseLogPayload(serial,response){return response;}/**
111
+ */
112
+ getResponseLogPayload(serial, response) {
113
+ return response;
114
+ }
115
+
116
+ /**
54
117
  * App command response handler. Can be used to implement custom logic for handling the incoming
55
118
  * data.
56
119
  *
@@ -63,16 +126,62 @@ requestBuffer.remove(this.serial);return this;}/**
63
126
  * of the AppCommandRequest instance.
64
127
  * @param {string} serial The serial that was used to identify the response callback.
65
128
  * @param {Object} response The response object for the request
66
- */},{key:"onResponse",value:function onResponse(resolve,reject,serial,response){resolve(response);}/**
129
+ */
130
+ onResponse(resolve, reject, serial, response) {
131
+ resolve(response);
132
+ }
133
+
134
+ /**
67
135
  * Dispatches the app request command.
68
136
  * @private
69
137
  * @param {Function} resolve The resolve() callback of the dispatch promise.
70
138
  * @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 _this3=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:/**
139
+ */
140
+ async onDispatch(resolve, reject) {
141
+ // Validate the command parameters.
142
+ if (this.validateCommandParams(this.commandParams) === false) {
143
+ // In case of an error log a message and reject the request promise.
144
+ const message = `${this.commandName} - invalid command parameters passed`;
145
+ logger.error(message, this.commandParams);
146
+ reject(new Error(message));
147
+ return;
148
+ }
149
+
150
+ /**
73
151
  * 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(_this3.getResponseLogTitle(),_this3.getResponseLogPayload.apply(_this3,params)||{},_this3.logColor);_this3.cleanUpRequest(requestCallback);_this3.onResponse.apply(_this3,[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;}()}]);}(Request);/* eslint-enable class-methods-use-this */export default AppCommandRequest;
152
+ */
153
+ const requestCallback = (...params) => {
154
+ logGroup(this.getResponseLogTitle(), this.getResponseLogPayload(...params) || {}, this.logColor);
155
+ this.cleanUpRequest(requestCallback);
156
+ this.onResponse(resolve, reject, ...params);
157
+ };
158
+
159
+ // Add the request to the buffer.
160
+ requestBuffer.add(this, this.serial);
161
+ // Add the event callback for the response.
162
+ event.addCallback(this.getEventCallbackName(), requestCallback);
163
+
164
+ // Prepare the command.
165
+ const command = new AppCommand().setCommandName(this.commandName).setLibVersion(this.libVersion).setCommandParams({
166
+ serial: this.serial,
167
+ ...(this.commandParams && {
168
+ ...this.commandParams
169
+ })
170
+ });
171
+
172
+ // Try to dispatch the command.
173
+ const success = await command.dispatch();
174
+
175
+ // If the dispatch of the command failed revert everything and reject the promise.
176
+ if (success === false) {
177
+ this.cleanUpRequest(requestCallback);
178
+ reject(new Error(`${this.commandName} command dispatch failed`));
179
+ return;
180
+ }
181
+ logGroup(this.getRequestLogTitle(), this.commandParams || {}, this.logColor);
182
+ }
183
+ }
184
+
185
+ /* eslint-enable class-methods-use-this */
186
+
187
+ export default AppCommandRequest;