jscrambler 6.0.4 → 6.1.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.
package/dist/index.js CHANGED
@@ -1,87 +1,93 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ 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); }
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = void 0;
6
9
 
7
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
10
+ require("regenerator-runtime");
8
11
 
9
- require('babel-polyfill');
12
+ require("core-js");
10
13
 
11
- var _path = require('path');
14
+ var _path = _interopRequireDefault(require("path"));
12
15
 
13
- var _path2 = _interopRequireDefault(_path);
16
+ var _axios = _interopRequireDefault(require("axios"));
14
17
 
15
- var _axios = require('axios');
18
+ var _lodash = _interopRequireDefault(require("lodash.defaults"));
16
19
 
17
- var _axios2 = _interopRequireDefault(_axios);
20
+ var _fs = _interopRequireDefault(require("fs"));
18
21
 
19
- var _lodash = require('lodash.defaults');
22
+ var _config2 = _interopRequireDefault(require("./config"));
20
23
 
21
- var _lodash2 = _interopRequireDefault(_lodash);
24
+ var _generateSignedParams = _interopRequireDefault(require("./generate-signed-params"));
22
25
 
23
- var _fs = require('fs');
26
+ var _client = _interopRequireDefault(require("./client"));
24
27
 
25
- var _fs2 = _interopRequireDefault(_fs);
28
+ var mutations = _interopRequireWildcard(require("./mutations"));
26
29
 
27
- var _config2 = require('./config');
30
+ var queries = _interopRequireWildcard(require("./queries"));
28
31
 
29
- var _config3 = _interopRequireDefault(_config2);
32
+ var _constants = require("./constants");
30
33
 
31
- var _generateSignedParams = require('./generate-signed-params');
34
+ var _zip = require("./zip");
32
35
 
33
- var _generateSignedParams2 = _interopRequireDefault(_generateSignedParams);
36
+ var introspection = _interopRequireWildcard(require("./introspection"));
34
37
 
35
- var _client = require('./client');
38
+ var _utils = require("./utils");
36
39
 
37
- var _client2 = _interopRequireDefault(_client);
40
+ var _getProtectionDefaultFragments = _interopRequireDefault(require("./get-protection-default-fragments"));
38
41
 
39
- var _mutations = require('./mutations');
42
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
40
43
 
41
- var mutations = _interopRequireWildcard(_mutations);
44
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
42
45
 
43
- var _queries = require('./queries');
46
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
47
 
45
- var queries = _interopRequireWildcard(_queries);
48
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
46
49
 
47
- var _constants = require('./constants');
50
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
48
51
 
49
- var _zip = require('./zip');
52
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
50
53
 
51
- var _introspection = require('./introspection');
54
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
52
55
 
53
- var introspection = _interopRequireWildcard(_introspection);
56
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
54
57
 
55
- var _utils = require('./utils');
58
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
56
59
 
57
- var _getProtectionDefaultFragments = require('./get-protection-default-fragments');
60
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
58
61
 
59
- var _getProtectionDefaultFragments2 = _interopRequireDefault(_getProtectionDefaultFragments);
62
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
60
63
 
61
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
64
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
62
65
 
63
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
66
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
64
67
 
65
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
68
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
66
69
 
67
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /* eslint-disable no-console */
70
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
68
71
 
72
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
69
73
 
70
- var intoObjectType = introspection.intoObjectType;
74
+ 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); } }
71
75
 
76
+ 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); }); }; }
72
77
 
78
+ var intoObjectType = introspection.intoObjectType;
73
79
  var debug = !!process.env.DEBUG;
74
80
  var APP_URL = 'https://app.jscrambler.com';
75
81
  var POLLING_MIN_INTERVAL = 1000;
76
82
  var POLLING_MAX_INTERVAL = 10000;
77
83
  var INCREASE_POLL_INTERVAL_EVERY = 30000;
78
-
79
84
  /**
80
85
  * Calculate polling interval for protection and instrumentation.
81
86
  * Upper limit of {POLLING_MAX_INTERVAL}.
82
87
  * @param start
83
88
  * @returns {number|number}
84
89
  */
90
+
85
91
  function getPollingInterval(start) {
86
92
  var pollingInterval = POLLING_MIN_INTERVAL * Math.ceil((Date.now() - start) / INCREASE_POLL_INTERVAL_EVERY);
87
93
  return pollingInterval >= POLLING_MAX_INTERVAL ? POLLING_MAX_INTERVAL : pollingInterval;
@@ -90,7 +96,7 @@ function getPollingInterval(start) {
90
96
  function errorHandler(res) {
91
97
  if (res.errors && res.errors.length) {
92
98
  res.errors.forEach(function (error) {
93
- throw new Error('Error: ' + error.message);
99
+ throw new Error("Error: ".concat(error.message));
94
100
  });
95
101
  }
96
102
 
@@ -102,7 +108,7 @@ function errorHandler(res) {
102
108
  }
103
109
 
104
110
  if (res.message) {
105
- throw new Error('Error: ' + res.message);
111
+ throw new Error("Error: ".concat(res.message));
106
112
  }
107
113
 
108
114
  return res;
@@ -115,7 +121,7 @@ function printSourcesErrors(errors) {
115
121
  }
116
122
 
117
123
  function normalizeParameters(parameters) {
118
- var result = void 0;
124
+ var result;
119
125
 
120
126
  if (!Array.isArray(parameters)) {
121
127
  result = [];
@@ -135,13 +141,14 @@ function normalizeParameters(parameters) {
135
141
  function buildFinalConfig(configPathOrObject) {
136
142
  var _config = typeof configPathOrObject === 'string' ? require(configPathOrObject) : configPathOrObject;
137
143
 
138
- return (0, _lodash2.default)(_config, _config3.default);
144
+ return (0, _lodash.default)(_config, _config2.default);
139
145
  }
140
146
 
141
- exports.default = {
142
- Client: _client2.default,
143
- config: _config3.default,
144
- generateSignedParams: _generateSignedParams2.default,
147
+ var _default = {
148
+ Client: _client.default,
149
+ config: _config2.default,
150
+ generateSignedParams: _generateSignedParams.default,
151
+
145
152
  /**
146
153
  * Remove and Add application sources
147
154
  * @param {object} client
@@ -154,45 +161,37 @@ exports.default = {
154
161
  * }} opts
155
162
  * @returns {Promise<{extension: string, filename: string, content: *}>}
156
163
  */
157
- updateApplicationSources: function () {
158
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(client, applicationId, _ref) {
159
- var _this = this;
164
+ updateApplicationSources: function updateApplicationSources(client, applicationId, _ref) {
165
+ var _this = this;
160
166
 
161
- var sources = _ref.sources,
162
- filesSrc = _ref.filesSrc,
163
- cwd = _ref.cwd,
164
- appProfiling = _ref.appProfiling;
165
-
166
- var promise, zipped, source, _filesSrc, i, l, content;
167
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
168
+ var sources, filesSrc, cwd, appProfiling, promise, zipped, source, _filesSrc, i, l, content;
167
169
 
168
170
  return regeneratorRuntime.wrap(function _callee$(_context) {
169
171
  while (1) {
170
172
  switch (_context.prev = _context.next) {
171
173
  case 0:
174
+ sources = _ref.sources, filesSrc = _ref.filesSrc, cwd = _ref.cwd, appProfiling = _ref.appProfiling;
172
175
  promise = null;
173
176
 
174
177
  if (!(sources || filesSrc && filesSrc.length)) {
175
- _context.next = 5;
178
+ _context.next = 6;
176
179
  break;
177
180
  }
178
181
 
179
182
  if (!(appProfiling && appProfiling.data && appProfiling.data.state === 'READY')) {
180
- _context.next = 4;
183
+ _context.next = 5;
181
184
  break;
182
185
  }
183
186
 
184
187
  throw new Error('You have a finished Profiling for this application so you are NOT ALLOWED to update sources. To override this behavior use *--remove-profiling-data* or *--skip-sources*.');
185
188
 
186
- case 4:
187
-
188
- promise = this.removeSourceFromApplication(client, '', applicationId);
189
-
190
189
  case 5:
191
- zipped = void 0;
192
- source = void 0;
190
+ promise = _this.removeSourceFromApplication(client, '', applicationId);
193
191
 
192
+ case 6:
194
193
  if (!(filesSrc && filesSrc.length)) {
195
- _context.next = 16;
194
+ _context.next = 15;
196
195
  break;
197
196
  }
198
197
 
@@ -210,17 +209,17 @@ exports.default = {
210
209
  console.log('Creating zip from source files');
211
210
  }
212
211
 
213
- _context.next = 13;
212
+ _context.next = 12;
214
213
  return (0, _zip.zip)(_filesSrc, cwd);
215
214
 
216
- case 13:
215
+ case 12:
217
216
  zipped = _context.sent;
218
- _context.next = 21;
217
+ _context.next = 20;
219
218
  break;
220
219
 
221
- case 16:
220
+ case 15:
222
221
  if (!sources) {
223
- _context.next = 21;
222
+ _context.next = 20;
224
223
  break;
225
224
  }
226
225
 
@@ -228,27 +227,26 @@ exports.default = {
228
227
  console.log('Creating zip from sources');
229
228
  }
230
229
 
231
- _context.next = 20;
230
+ _context.next = 19;
232
231
  return (0, _zip.zipSources)(sources);
233
232
 
234
- case 20:
233
+ case 19:
235
234
  zipped = _context.sent;
236
235
 
237
- case 21:
236
+ case 20:
238
237
  if (!zipped) {
239
- _context.next = 28;
238
+ _context.next = 27;
240
239
  break;
241
240
  }
242
241
 
243
- _context.next = 24;
242
+ _context.next = 23;
244
243
  return zipped.generateAsync({
245
244
  type: 'base64'
246
245
  });
247
246
 
248
- case 24:
247
+ case 23:
249
248
  content = _context.sent;
250
249
 
251
-
252
250
  if (debug) {
253
251
  console.log('Adding sources to application');
254
252
  }
@@ -258,33 +256,27 @@ exports.default = {
258
256
  filename: 'application.zip',
259
257
  extension: 'zip'
260
258
  };
261
-
262
259
  promise.then(function (removeRes) {
263
260
  errorHandler(removeRes);
264
-
265
261
  return _this.addApplicationSource(client, applicationId, source);
266
262
  }).then(errorHandler).catch(function (e) {
267
- console.warn('Update application sources failed with ' + e.message);
263
+ console.warn("Update application sources failed with ".concat(e.message));
268
264
  });
269
265
 
270
- case 28:
271
- return _context.abrupt('return', { source: source, promise: promise });
266
+ case 27:
267
+ return _context.abrupt("return", {
268
+ source: source,
269
+ promise: promise
270
+ });
272
271
 
273
- case 29:
274
- case 'end':
272
+ case 28:
273
+ case "end":
275
274
  return _context.stop();
276
275
  }
277
276
  }
278
- }, _callee, this);
279
- }));
280
-
281
- function updateApplicationSources(_x, _x2, _x3) {
282
- return _ref2.apply(this, arguments);
283
- }
284
-
285
- return updateApplicationSources;
286
- }(),
287
-
277
+ }, _callee);
278
+ }))();
279
+ },
288
280
  // This method is a shortcut method that accepts an object with everything needed
289
281
  // for the entire process of requesting an application protection and downloading
290
282
  // that same protection when the same ends.
@@ -328,20 +320,21 @@ exports.default = {
328
320
  // endpoint than the default one, useful if you're running an enterprise version of
329
321
  // Jscrambler or if you're provided access to beta features of our product.
330
322
  //
331
- protectAndDownload: function () {
332
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(configPathOrObject, destCallback) {
333
- var _this2 = this;
323
+ protectAndDownload: function protectAndDownload(configPathOrObject, destCallback) {
324
+ var _this2 = this;
334
325
 
335
- var finalConfig, applicationId, host, port, basePath, protocol, cafile, keys, sources, _finalConfig$stream, stream, cwd, params, applicationTypes, languageSpecifications, sourceMaps, randomizationSeed, areSubscribersOrdered, useRecommendedOrder, _finalConfig$bail, bail, jscramblerVersion, debugMode, proxy, utc, clientId, tolerateMinification, codeHardeningThreshold, useProfilingData, browsers, useAppClassification, profilingDataMode, removeProfilingData, skipSources, inputSymbolTable, entryPoint, excludeList, forceAppEnvironment, accessKey, secretKey, client, filesSrc, filesDest, source, updateApplicationSourcePromise, appProfiling, _ref4, updateData, dataToValidate, prop, value, applicationUpdate, updateApplicationRes, protectionOptions, inputSymbolTableContents, _ref5, _ref6, createApplicationProtectionRes, protectionId, onExitCancelProtection, protection, sourcesErrors, download;
326
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
327
+ var start, finalConfig, applicationId, host, port, basePath, protocol, cafile, keys, sources, _finalConfig$stream, stream, cwd, params, applicationTypes, languageSpecifications, sourceMaps, randomizationSeed, areSubscribersOrdered, useRecommendedOrder, _finalConfig$bail, bail, jscramblerVersion, debugMode, proxy, utc, clientId, tolerateMinification, codeHardeningThreshold, useProfilingData, browsers, useAppClassification, profilingDataMode, removeProfilingData, skipSources, inputSymbolTable, entryPoint, excludeList, numberOfProtections, forceAppEnvironment, accessKey, secretKey, client, filesSrc, filesDest, source, updateApplicationSourcePromise, appProfiling, _yield$_this2$updateA, updateData, dataToValidate, prop, value, applicationUpdate, updateApplicationRes, protectionOptions, inputSymbolTableContents, _yield$Promise$all, _yield$Promise$all2, createApplicationProtectionRes, protectionIds, onExitCancelProtection, processedProtections, handleProtection, i, protection;
336
328
 
337
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
329
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
338
330
  while (1) {
339
- switch (_context2.prev = _context2.next) {
331
+ switch (_context4.prev = _context4.next) {
340
332
  case 0:
333
+ start = Date.now();
341
334
  finalConfig = buildFinalConfig(configPathOrObject);
342
- applicationId = finalConfig.applicationId, host = finalConfig.host, port = finalConfig.port, basePath = finalConfig.basePath, protocol = finalConfig.protocol, cafile = finalConfig.cafile, keys = finalConfig.keys, sources = finalConfig.sources, _finalConfig$stream = finalConfig.stream, stream = _finalConfig$stream === undefined ? true : _finalConfig$stream, cwd = finalConfig.cwd, params = finalConfig.params, applicationTypes = finalConfig.applicationTypes, languageSpecifications = finalConfig.languageSpecifications, sourceMaps = finalConfig.sourceMaps, randomizationSeed = finalConfig.randomizationSeed, areSubscribersOrdered = finalConfig.areSubscribersOrdered, useRecommendedOrder = finalConfig.useRecommendedOrder, _finalConfig$bail = finalConfig.bail, bail = _finalConfig$bail === undefined ? true : _finalConfig$bail, jscramblerVersion = finalConfig.jscramblerVersion, debugMode = finalConfig.debugMode, proxy = finalConfig.proxy, utc = finalConfig.utc, clientId = finalConfig.clientId, tolerateMinification = finalConfig.tolerateMinification, codeHardeningThreshold = finalConfig.codeHardeningThreshold, useProfilingData = finalConfig.useProfilingData, browsers = finalConfig.browsers, useAppClassification = finalConfig.useAppClassification, profilingDataMode = finalConfig.profilingDataMode, removeProfilingData = finalConfig.removeProfilingData, skipSources = finalConfig.skipSources, inputSymbolTable = finalConfig.inputSymbolTable, entryPoint = finalConfig.entryPoint, excludeList = finalConfig.excludeList, forceAppEnvironment = finalConfig.forceAppEnvironment;
335
+ applicationId = finalConfig.applicationId, host = finalConfig.host, port = finalConfig.port, basePath = finalConfig.basePath, protocol = finalConfig.protocol, cafile = finalConfig.cafile, keys = finalConfig.keys, sources = finalConfig.sources, _finalConfig$stream = finalConfig.stream, stream = _finalConfig$stream === void 0 ? true : _finalConfig$stream, cwd = finalConfig.cwd, params = finalConfig.params, applicationTypes = finalConfig.applicationTypes, languageSpecifications = finalConfig.languageSpecifications, sourceMaps = finalConfig.sourceMaps, randomizationSeed = finalConfig.randomizationSeed, areSubscribersOrdered = finalConfig.areSubscribersOrdered, useRecommendedOrder = finalConfig.useRecommendedOrder, _finalConfig$bail = finalConfig.bail, bail = _finalConfig$bail === void 0 ? true : _finalConfig$bail, jscramblerVersion = finalConfig.jscramblerVersion, debugMode = finalConfig.debugMode, proxy = finalConfig.proxy, utc = finalConfig.utc, clientId = finalConfig.clientId, tolerateMinification = finalConfig.tolerateMinification, codeHardeningThreshold = finalConfig.codeHardeningThreshold, useProfilingData = finalConfig.useProfilingData, browsers = finalConfig.browsers, useAppClassification = finalConfig.useAppClassification, profilingDataMode = finalConfig.profilingDataMode, removeProfilingData = finalConfig.removeProfilingData, skipSources = finalConfig.skipSources, inputSymbolTable = finalConfig.inputSymbolTable, entryPoint = finalConfig.entryPoint, excludeList = finalConfig.excludeList, numberOfProtections = finalConfig.numberOfProtections, forceAppEnvironment = finalConfig.forceAppEnvironment;
343
336
  accessKey = keys.accessKey, secretKey = keys.secretKey;
344
- client = new this.Client({
337
+ client = new _this2.Client({
345
338
  accessKey: accessKey,
346
339
  secretKey: secretKey,
347
340
  host: host,
@@ -357,7 +350,6 @@ exports.default = {
357
350
  filesSrc = finalConfig.filesSrc;
358
351
  filesDest = finalConfig.filesDest;
359
352
 
360
-
361
353
  if (sources) {
362
354
  filesSrc = undefined;
363
355
  }
@@ -367,50 +359,48 @@ exports.default = {
367
359
  }
368
360
 
369
361
  if (applicationId) {
370
- _context2.next = 10;
362
+ _context4.next = 11;
371
363
  break;
372
364
  }
373
365
 
374
366
  throw new Error('Required *applicationId* not provided');
375
367
 
376
- case 10:
368
+ case 11:
377
369
  if (!(!filesDest && !destCallback)) {
378
- _context2.next = 12;
370
+ _context4.next = 13;
379
371
  break;
380
372
  }
381
373
 
382
374
  throw new Error('Required *filesDest* not provided');
383
375
 
384
- case 12:
385
- source = void 0, updateApplicationSourcePromise = void 0;
386
-
376
+ case 13:
387
377
  if (skipSources) {
388
- _context2.next = 28;
378
+ _context4.next = 28;
389
379
  break;
390
380
  }
391
381
 
392
- _context2.next = 16;
393
- return this.getApplicationProfiling(client, applicationId).catch(function (e) {
382
+ _context4.next = 16;
383
+ return _this2.getApplicationProfiling(client, applicationId).catch(function (e) {
394
384
  if (![_constants.HTTP_STATUS_CODES.NOT_FOUND, _constants.HTTP_STATUS_CODES.FORBIDDEN, _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE].includes(e.statusCode)) throw e;
395
385
  });
396
386
 
397
387
  case 16:
398
- appProfiling = _context2.sent;
388
+ appProfiling = _context4.sent;
399
389
 
400
390
  if (!(appProfiling && removeProfilingData)) {
401
- _context2.next = 21;
391
+ _context4.next = 21;
402
392
  break;
403
393
  }
404
394
 
405
- _context2.next = 20;
406
- return this.deleteProfiling(client, appProfiling.data.id);
395
+ _context4.next = 20;
396
+ return _this2.deleteProfiling(client, appProfiling.data.id);
407
397
 
408
398
  case 20:
409
399
  appProfiling.data.state = 'DELETED';
410
400
 
411
401
  case 21:
412
- _context2.next = 23;
413
- return this.updateApplicationSources(client, applicationId, {
402
+ _context4.next = 23;
403
+ return _this2.updateApplicationSources(client, applicationId, {
414
404
  sources: sources,
415
405
  filesSrc: filesSrc,
416
406
  cwd: cwd,
@@ -418,10 +408,10 @@ exports.default = {
418
408
  });
419
409
 
420
410
  case 23:
421
- _ref4 = _context2.sent;
422
- source = _ref4.source;
423
- updateApplicationSourcePromise = _ref4.promise;
424
- _context2.next = 29;
411
+ _yield$_this2$updateA = _context4.sent;
412
+ source = _yield$_this2$updateA.source;
413
+ updateApplicationSourcePromise = _yield$_this2$updateA.promise;
414
+ _context4.next = 29;
425
415
  break;
426
416
 
427
417
  case 28:
@@ -435,7 +425,6 @@ exports.default = {
435
425
  codeHardeningThreshold: codeHardeningThreshold
436
426
  };
437
427
 
438
-
439
428
  if (params && Object.keys(params).length) {
440
429
  updateData.parameters = normalizeParameters(params);
441
430
  updateData.areSubscribersOrdered = Array.isArray(params);
@@ -453,7 +442,6 @@ exports.default = {
453
442
  useRecommendedOrder: useRecommendedOrder
454
443
  };
455
444
 
456
-
457
445
  for (prop in dataToValidate) {
458
446
  value = dataToValidate[prop];
459
447
 
@@ -463,7 +451,7 @@ exports.default = {
463
451
  }
464
452
 
465
453
  if (!(updateData.parameters || updateData.applicationTypes || updateData.languageSpecifications || updateData.browsers || typeof updateData.areSubscribersOrdered !== 'undefined')) {
466
- _context2.next = 43;
454
+ _context4.next = 43;
467
455
  break;
468
456
  }
469
457
 
@@ -471,31 +459,31 @@ exports.default = {
471
459
  console.log('Updating parameters of protection');
472
460
  }
473
461
 
474
- _context2.next = 37;
462
+ _context4.next = 37;
475
463
  return intoObjectType(client, updateData, 'Application');
476
464
 
477
465
  case 37:
478
- applicationUpdate = _context2.sent;
479
- _context2.next = 40;
480
- return this.updateApplication(client, applicationUpdate);
466
+ applicationUpdate = _context4.sent;
467
+ _context4.next = 40;
468
+ return _this2.updateApplication(client, applicationUpdate);
481
469
 
482
470
  case 40:
483
- updateApplicationRes = _context2.sent;
471
+ updateApplicationRes = _context4.sent;
484
472
 
485
473
  if (debug) {
486
474
  console.log('Finished updating parameters of protection');
487
475
  console.error(updateApplicationRes);
488
476
  }
477
+
489
478
  errorHandler(updateApplicationRes);
490
479
 
491
480
  case 43:
492
-
493
481
  if (debug) {
494
482
  console.log('Creating Application Protection');
495
483
  }
496
484
 
497
485
  delete updateData._id;
498
- protectionOptions = Object.assign({}, updateData, {
486
+ protectionOptions = _objectSpread(_objectSpread({}, updateData), {}, {
499
487
  bail: bail,
500
488
  entryPoint: entryPoint,
501
489
  excludeList: excludeList,
@@ -503,168 +491,276 @@ exports.default = {
503
491
  randomizationSeed: randomizationSeed,
504
492
  source: source,
505
493
  tolerateMinification: tolerateMinification,
494
+ numberOfProtections: numberOfProtections,
506
495
  forceAppEnvironment: forceAppEnvironment
507
496
  });
508
497
 
509
-
510
498
  if (finalConfig.inputSymbolTable) {
511
499
  // Note: we can not use the fs.promises API because some users may not have node 10.
512
500
  // Once node 10 is old enough to be safe to assume that all users will have it, this
513
501
  // should be safe to replace with `await fs.promises.readFile`.
514
- inputSymbolTableContents = _fs2.default.readFileSync(finalConfig.inputSymbolTable, 'utf-8');
515
-
502
+ inputSymbolTableContents = _fs.default.readFileSync(finalConfig.inputSymbolTable, 'utf-8');
516
503
  protectionOptions.inputSymbolTable = inputSymbolTableContents;
517
504
  }
518
505
 
519
- _context2.next = 49;
520
- return Promise.all([this.createApplicationProtection(client, applicationId, protectionOptions), updateApplicationSourcePromise]);
506
+ _context4.next = 49;
507
+ return Promise.all([_this2.createApplicationProtections(client, applicationId, protectionOptions), updateApplicationSourcePromise]);
521
508
 
522
509
  case 49:
523
- _ref5 = _context2.sent;
524
- _ref6 = _slicedToArray(_ref5, 1);
525
- createApplicationProtectionRes = _ref6[0];
526
-
510
+ _yield$Promise$all = _context4.sent;
511
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 1);
512
+ createApplicationProtectionRes = _yield$Promise$all2[0];
527
513
  errorHandler(createApplicationProtectionRes);
514
+ protectionIds = createApplicationProtectionRes.data.protections.map(function (_ref2) {
515
+ var _id = _ref2._id;
516
+ return _id;
517
+ });
528
518
 
529
- protectionId = createApplicationProtectionRes.data.createApplicationProtection._id;
519
+ onExitCancelProtection = /*#__PURE__*/function () {
520
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
521
+ var i, protectionId;
522
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
523
+ while (1) {
524
+ switch (_context2.prev = _context2.next) {
525
+ case 0:
526
+ i = 0;
530
527
 
531
- onExitCancelProtection = function onExitCancelProtection() {
532
- _this2.cancelProtection(client, protectionId, applicationId).then(function () {
533
- return console.log('\n** Protection %s WAS CANCELLED **', protectionId);
534
- }).catch(function () {
535
- return debug && console.error(e);
536
- }).finally(function () {
537
- return process.exit(1);
538
- });
539
- };
528
+ case 1:
529
+ if (!(i < protectionIds.length)) {
530
+ _context2.next = 15;
531
+ break;
532
+ }
540
533
 
541
- process.once('SIGINT', onExitCancelProtection).once('SIGTERM', onExitCancelProtection);
534
+ protectionId = protectionIds[i];
535
+ _context2.prev = 3;
536
+ _context2.next = 6;
537
+ return _this2.cancelProtection(client, protectionId, applicationId);
538
+
539
+ case 6:
540
+ console.log('** Protection %s WAS CANCELLED **', protectionId);
541
+ _context2.next = 12;
542
+ break;
543
+
544
+ case 9:
545
+ _context2.prev = 9;
546
+ _context2.t0 = _context2["catch"](3);
547
+
548
+ if (debug) {
549
+ console.error(_context2.t0);
550
+ }
551
+
552
+ case 12:
553
+ i++;
554
+ _context2.next = 1;
555
+ break;
556
+
557
+ case 15:
558
+ process.exit(1);
559
+
560
+ case 16:
561
+ case "end":
562
+ return _context2.stop();
563
+ }
564
+ }
565
+ }, _callee2, null, [[3, 9]]);
566
+ }));
567
+
568
+ return function onExitCancelProtection() {
569
+ return _ref3.apply(this, arguments);
570
+ };
571
+ }();
542
572
 
543
- _context2.t0 = this;
544
- _context2.t1 = client;
545
- _context2.t2 = applicationId;
546
- _context2.t3 = protectionId;
547
- _context2.next = 62;
548
- return (0, _getProtectionDefaultFragments2.default)(client);
573
+ process.once('SIGINT', onExitCancelProtection).once('SIGTERM', onExitCancelProtection);
574
+ _context4.t0 = _this2;
575
+ _context4.t1 = client;
576
+ _context4.t2 = applicationId;
577
+ _context4.t3 = protectionIds;
578
+ _context4.next = 62;
579
+ return (0, _getProtectionDefaultFragments.default)(client);
549
580
 
550
581
  case 62:
551
- _context2.t4 = _context2.sent;
552
- _context2.next = 65;
553
- return _context2.t0.pollProtection.call(_context2.t0, _context2.t1, _context2.t2, _context2.t3, _context2.t4);
582
+ _context4.t4 = _context4.sent;
583
+ _context4.next = 65;
584
+ return _context4.t0.pollProtections.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
554
585
 
555
586
  case 65:
556
- protection = _context2.sent;
587
+ processedProtections = _context4.sent;
588
+ process.removeListener('SIGINT', onExitCancelProtection).removeListener('SIGTERM', onExitCancelProtection);
557
589
 
590
+ handleProtection = /*#__PURE__*/function () {
591
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(protection) {
592
+ var _ref5,
593
+ _ref5$outPrefix,
594
+ outPrefix,
595
+ _ref5$printProtection,
596
+ printProtectionId,
597
+ sourcesErrors,
598
+ download,
599
+ _args3 = arguments;
600
+
601
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
602
+ while (1) {
603
+ switch (_context3.prev = _context3.next) {
604
+ case 0:
605
+ _ref5 = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}, _ref5$outPrefix = _ref5.outPrefix, outPrefix = _ref5$outPrefix === void 0 ? '' : _ref5$outPrefix, _ref5$printProtection = _ref5.printProtectionId, printProtectionId = _ref5$printProtection === void 0 ? true : _ref5$printProtection;
558
606
 
559
- process.removeListener('SIGINT', onExitCancelProtection).removeListener('SIGTERM', onExitCancelProtection);
607
+ if (protection.growthWarning) {
608
+ console.warn("Warning: Your protected application has surpassed a reasonable file growth.\nFor more information on what might have caused this, please see the Protection Report.\nLink: ".concat(APP_URL, "."));
609
+ }
560
610
 
561
- if (protection.growthWarning) {
562
- console.warn('Warning: Your protected application has surpassed a reasonable file growth.\nFor more information on what might have caused this, please see the Protection Report.\nLink: ' + APP_URL + '.');
563
- }
564
- if (debug) {
565
- console.log('Finished protecting');
566
- }
611
+ if (debug) {
612
+ console.log('Finished protecting');
613
+ }
567
614
 
568
- if (protection.deprecations) {
569
- protection.deprecations.forEach(function (deprecation) {
570
- if (deprecation.type === 'Transformation') {
571
- console.warn('Warning: ' + deprecation.type + ' ' + deprecation.entity + ' is no longer maintained. Please consider removing it from your configuration.');
572
- } else if (deprecation.type && deprecation.entity) {
573
- console.warn('Warning: ' + deprecation.type + ' ' + deprecation.entity + ' is deprecated.');
574
- }
575
- });
576
- }
615
+ if (protection.deprecations) {
616
+ protection.deprecations.forEach(function (deprecation) {
617
+ if (deprecation.type === 'Transformation') {
618
+ console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is no longer maintained. Please consider removing it from your configuration."));
619
+ } else if (deprecation.type && deprecation.entity) {
620
+ console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is deprecated."));
621
+ }
622
+ });
623
+ }
577
624
 
578
- sourcesErrors = [];
625
+ sourcesErrors = [];
626
+ protection.sources.forEach(function (s) {
627
+ if (s.errorMessages && s.errorMessages.length > 0) {
628
+ sourcesErrors.push.apply(sourcesErrors, _toConsumableArray(s.errorMessages.map(function (e) {
629
+ return _objectSpread({
630
+ filename: s.filename
631
+ }, e);
632
+ })));
633
+ }
634
+ });
579
635
 
636
+ if (!(protection.state === 'errored')) {
637
+ _context3.next = 14;
638
+ break;
639
+ }
580
640
 
581
- protection.sources.forEach(function (s) {
582
- if (s.errorMessages && s.errorMessages.length > 0) {
583
- sourcesErrors.push.apply(sourcesErrors, _toConsumableArray(s.errorMessages.map(function (e) {
584
- return Object.assign({
585
- filename: s.filename
586
- }, e);
587
- })));
588
- }
589
- });
641
+ console.error('Global protection errors:');
642
+ console.error("- ".concat(protection.errorMessage));
643
+ console.error('');
590
644
 
591
- if (!(protection.state === 'errored')) {
592
- _context2.next = 80;
593
- break;
594
- }
645
+ if (sourcesErrors.length > 0) {
646
+ printSourcesErrors(sourcesErrors);
647
+ }
595
648
 
596
- console.error('Global protection errors:');
597
- console.error('- ' + protection.errorMessage);
598
- console.error('');
599
- if (sourcesErrors.length > 0) {
600
- printSourcesErrors(sourcesErrors);
601
- }
602
- throw new Error('Protection failed. For more information visit: ' + APP_URL + '.');
649
+ throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
603
650
 
604
- case 80:
605
- if (!(sourcesErrors.length > 0)) {
606
- _context2.next = 87;
607
- break;
608
- }
651
+ case 14:
652
+ if (!(sourcesErrors.length > 0)) {
653
+ _context3.next = 21;
654
+ break;
655
+ }
609
656
 
610
- if (!protection.bail) {
611
- _context2.next = 86;
612
- break;
613
- }
657
+ if (!protection.bail) {
658
+ _context3.next = 20;
659
+ break;
660
+ }
614
661
 
615
- printSourcesErrors(sourcesErrors);
616
- throw new Error('Your protection has failed.');
662
+ printSourcesErrors(sourcesErrors);
663
+ throw new Error('Your protection has failed.');
617
664
 
618
- case 86:
619
- sourcesErrors.forEach(function (e) {
620
- return console.warn('Non-fatal error: "' + e.message + '" in ' + e.filename);
621
- });
665
+ case 20:
666
+ sourcesErrors.forEach(function (e) {
667
+ return console.warn("Non-fatal error: \"".concat(e.message, "\" in ").concat(e.filename));
668
+ });
622
669
 
623
- case 87:
670
+ case 21:
671
+ if (debug) {
672
+ console.log('Downloading protection result');
673
+ }
624
674
 
625
- if (debug) {
626
- console.log('Downloading protection result');
627
- }
628
- _context2.next = 90;
629
- return this.downloadApplicationProtection(client, protectionId);
675
+ _context3.next = 24;
676
+ return _this2.downloadApplicationProtection(client, protection._id);
630
677
 
631
- case 90:
632
- download = _context2.sent;
678
+ case 24:
679
+ download = _context3.sent;
680
+ errorHandler(download);
633
681
 
682
+ if (debug) {
683
+ console.log('Unzipping files');
684
+ }
634
685
 
635
- errorHandler(download);
686
+ _context3.next = 29;
687
+ return (0, _zip.unzip)(download, (filesDest ? "".concat(filesDest).concat(outPrefix) : filesDest) || destCallback, stream);
636
688
 
637
- if (debug) {
638
- console.log('Unzipping files');
689
+ case 29:
690
+ if (debug) {
691
+ console.log('Finished unzipping files');
692
+ }
693
+
694
+ if (printProtectionId) {
695
+ console.log(protection._id);
696
+ }
697
+
698
+ return _context3.abrupt("return", protection._id);
699
+
700
+ case 32:
701
+ case "end":
702
+ return _context3.stop();
703
+ }
704
+ }
705
+ }, _callee3);
706
+ }));
707
+
708
+ return function handleProtection(_x) {
709
+ return _ref4.apply(this, arguments);
710
+ };
711
+ }();
712
+
713
+ if (!(processedProtections.length === 1)) {
714
+ _context4.next = 70;
715
+ break;
639
716
  }
640
717
 
641
- _context2.next = 95;
642
- return (0, _zip.unzip)(download, filesDest || destCallback, stream);
718
+ return _context4.abrupt("return", handleProtection(processedProtections[0]));
643
719
 
644
- case 95:
720
+ case 70:
721
+ console.log("Protections stored in ".concat(filesDest, "/[protection-id]"));
722
+ i = 0;
645
723
 
646
- if (debug) {
647
- console.log('Finished unzipping files');
724
+ case 72:
725
+ if (!(i < processedProtections.length)) {
726
+ _context4.next = 85;
727
+ break;
648
728
  }
649
729
 
650
- console.log(protectionId);
730
+ protection = processedProtections[i];
731
+ _context4.prev = 74;
732
+ _context4.next = 77;
733
+ return handleProtection(protection, {
734
+ outPrefix: "/".concat(protection._id, "/"),
735
+ printProtectionId: false
736
+ });
737
+
738
+ case 77:
739
+ _context4.next = 82;
740
+ break;
651
741
 
652
- return _context2.abrupt('return', protectionId);
742
+ case 79:
743
+ _context4.prev = 79;
744
+ _context4.t5 = _context4["catch"](74);
745
+ console.error(_context4.t5);
653
746
 
654
- case 98:
655
- case 'end':
656
- return _context2.stop();
657
- }
658
- }
659
- }, _callee2, this);
660
- }));
747
+ case 82:
748
+ i++;
749
+ _context4.next = 72;
750
+ break;
661
751
 
662
- function protectAndDownload(_x4, _x5) {
663
- return _ref3.apply(this, arguments);
664
- }
752
+ case 85:
753
+ console.log("Runtime: ".concat(processedProtections.length, " protections in ").concat(Math.round((Date.now() - start) / 1000), "s"));
754
+ return _context4.abrupt("return", protectionIds);
665
755
 
666
- return protectAndDownload;
667
- }(),
756
+ case 87:
757
+ case "end":
758
+ return _context4.stop();
759
+ }
760
+ }
761
+ }, _callee4, null, [[74, 79]]);
762
+ }))();
763
+ },
668
764
 
669
765
  /**
670
766
  * Instrument and download application sources for profiling purposes
@@ -672,20 +768,20 @@ exports.default = {
672
768
  * @param {function} [destCallback]
673
769
  * @returns {Promise<string>}
674
770
  */
675
- instrumentAndDownload: function () {
676
- var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(configPathOrObject, destCallback) {
677
- var _this3 = this;
771
+ instrumentAndDownload: function instrumentAndDownload(configPathOrObject, destCallback) {
772
+ var _this3 = this;
678
773
 
679
- var finalConfig, applicationId, host, port, basePath, protocol, cafile, keys, sources, _finalConfig$stream2, stream, cwd, jscramblerVersion, proxy, utc, skipSources, clientId, accessKey, secretKey, client, filesSrc, filesDest, instrumentation, onExitCancelInstrumentation, download;
774
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
775
+ var finalConfig, applicationId, host, port, basePath, protocol, cafile, keys, sources, _finalConfig$stream2, stream, cwd, jscramblerVersion, proxy, utc, skipSources, clientId, accessKey, secretKey, client, filesSrc, filesDest, _yield$_this3$updateA, updateApplicationSourcePromise, instrumentation, onExitCancelInstrumentation, download;
680
776
 
681
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
777
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
682
778
  while (1) {
683
- switch (_context3.prev = _context3.next) {
779
+ switch (_context5.prev = _context5.next) {
684
780
  case 0:
685
781
  finalConfig = buildFinalConfig(configPathOrObject);
686
- applicationId = finalConfig.applicationId, host = finalConfig.host, port = finalConfig.port, basePath = finalConfig.basePath, protocol = finalConfig.protocol, cafile = finalConfig.cafile, keys = finalConfig.keys, sources = finalConfig.sources, _finalConfig$stream2 = finalConfig.stream, stream = _finalConfig$stream2 === undefined ? true : _finalConfig$stream2, cwd = finalConfig.cwd, jscramblerVersion = finalConfig.jscramblerVersion, proxy = finalConfig.proxy, utc = finalConfig.utc, skipSources = finalConfig.skipSources, clientId = finalConfig.clientId;
782
+ applicationId = finalConfig.applicationId, host = finalConfig.host, port = finalConfig.port, basePath = finalConfig.basePath, protocol = finalConfig.protocol, cafile = finalConfig.cafile, keys = finalConfig.keys, sources = finalConfig.sources, _finalConfig$stream2 = finalConfig.stream, stream = _finalConfig$stream2 === void 0 ? true : _finalConfig$stream2, cwd = finalConfig.cwd, jscramblerVersion = finalConfig.jscramblerVersion, proxy = finalConfig.proxy, utc = finalConfig.utc, skipSources = finalConfig.skipSources, clientId = finalConfig.clientId;
687
783
  accessKey = keys.accessKey, secretKey = keys.secretKey;
688
- client = new this.Client({
784
+ client = new _this3.Client({
689
785
  accessKey: accessKey,
690
786
  secretKey: secretKey,
691
787
  host: host,
@@ -700,7 +796,6 @@ exports.default = {
700
796
  });
701
797
  filesSrc = finalConfig.filesSrc, filesDest = finalConfig.filesDest;
702
798
 
703
-
704
799
  if (sources) {
705
800
  filesSrc = undefined;
706
801
  }
@@ -710,7 +805,7 @@ exports.default = {
710
805
  }
711
806
 
712
807
  if (applicationId) {
713
- _context3.next = 9;
808
+ _context5.next = 9;
714
809
  break;
715
810
  }
716
811
 
@@ -718,7 +813,7 @@ exports.default = {
718
813
 
719
814
  case 9:
720
815
  if (!(!filesDest && !destCallback)) {
721
- _context3.next = 11;
816
+ _context5.next = 11;
722
817
  break;
723
818
  }
724
819
 
@@ -726,31 +821,36 @@ exports.default = {
726
821
 
727
822
  case 11:
728
823
  if (skipSources) {
729
- _context3.next = 16;
824
+ _context5.next = 20;
730
825
  break;
731
826
  }
732
827
 
733
- _context3.next = 14;
734
- return this.updateApplicationSources(client, applicationId, {
828
+ _context5.next = 14;
829
+ return _this3.updateApplicationSources(client, applicationId, {
735
830
  sources: sources,
736
831
  filesSrc: filesSrc,
737
832
  cwd: cwd
738
833
  });
739
834
 
740
835
  case 14:
741
- _context3.next = 17;
836
+ _yield$_this3$updateA = _context5.sent;
837
+ updateApplicationSourcePromise = _yield$_this3$updateA.promise;
838
+ _context5.next = 18;
839
+ return updateApplicationSourcePromise;
840
+
841
+ case 18:
842
+ _context5.next = 21;
742
843
  break;
743
844
 
744
- case 16:
845
+ case 20:
745
846
  console.log('Update source files SKIPPED');
746
847
 
747
- case 17:
748
- _context3.next = 19;
749
- return this.startInstrumentation(client, applicationId);
750
-
751
- case 19:
752
- instrumentation = _context3.sent;
848
+ case 21:
849
+ _context5.next = 23;
850
+ return _this3.startInstrumentation(client, applicationId);
753
851
 
852
+ case 23:
853
+ instrumentation = _context5.sent;
754
854
  errorHandler(instrumentation);
755
855
 
756
856
  onExitCancelInstrumentation = function onExitCancelInstrumentation() {
@@ -764,62 +864,48 @@ exports.default = {
764
864
  };
765
865
 
766
866
  process.once('SIGINT', onExitCancelInstrumentation).once('SIGTERM', onExitCancelInstrumentation);
867
+ _context5.next = 29;
868
+ return _this3.pollInstrumentation(client, instrumentation.data.id);
767
869
 
768
- _context3.next = 25;
769
- return this.pollInstrumentation(client, instrumentation.data.id);
770
-
771
- case 25:
772
- instrumentation = _context3.sent;
773
-
774
-
870
+ case 29:
871
+ instrumentation = _context5.sent;
775
872
  process.removeListener('SIGINT', onExitCancelInstrumentation).removeListener('SIGTERM', onExitCancelInstrumentation);
776
873
 
777
874
  if (debug) {
778
- console.log('Finished instrumention with id ' + instrumentation.data.id + '. Downloading...');
875
+ console.log("Finished instrumention with id ".concat(instrumentation.data.id, ". Downloading..."));
779
876
  }
780
877
 
781
- _context3.next = 30;
782
- return this.downloadApplicationInstrumented(client, instrumentation.data.id);
783
-
784
- case 30:
785
- download = _context3.sent;
878
+ _context5.next = 34;
879
+ return _this3.downloadApplicationInstrumented(client, instrumentation.data.id);
786
880
 
881
+ case 34:
882
+ download = _context5.sent;
787
883
  errorHandler(download);
788
884
 
789
885
  if (debug) {
790
886
  console.log('Unzipping files');
791
887
  }
792
888
 
793
- _context3.next = 35;
889
+ _context5.next = 39;
794
890
  return (0, _zip.unzip)(download, filesDest || destCallback, stream);
795
891
 
796
- case 35:
797
-
892
+ case 39:
798
893
  if (debug) {
799
894
  console.log('Finished unzipping files');
800
895
  }
801
896
 
802
- console.warn('\n WARNING: DO NOT SEND THIS CODE TO PRODUCTION AS IT IS NOT PROTECTED\n ');
803
-
804
- console.log('Application ' + applicationId + ' was instrumented. Bootstrap your instrumented application and run *--start-profiling* command.');
897
+ console.warn("\n WARNING: DO NOT SEND THIS CODE TO PRODUCTION AS IT IS NOT PROTECTED\n ");
898
+ console.log("Application ".concat(applicationId, " was instrumented. Bootstrap your instrumented application and run *--start-profiling* command."));
899
+ return _context5.abrupt("return", instrumentation.data.id);
805
900
 
806
- return _context3.abrupt('return', instrumentation.data.id);
807
-
808
- case 39:
809
- case 'end':
810
- return _context3.stop();
901
+ case 43:
902
+ case "end":
903
+ return _context5.stop();
811
904
  }
812
905
  }
813
- }, _callee3, this);
814
- }));
815
-
816
- function instrumentAndDownload(_x6, _x7) {
817
- return _ref7.apply(this, arguments);
818
- }
819
-
820
- return instrumentAndDownload;
821
- }(),
822
-
906
+ }, _callee5);
907
+ }))();
908
+ },
823
909
 
824
910
  /**
825
911
  * Change the profiling run stat.
@@ -829,17 +915,19 @@ exports.default = {
829
915
  * @param {string} nextStepMessage
830
916
  * @returns {Promise<string>} The previous state
831
917
  */
832
- setProfilingState: function () {
833
- var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(configPathOrObject, state, label, nextStepMessage) {
918
+ setProfilingState: function setProfilingState(configPathOrObject, state, label, nextStepMessage) {
919
+ var _this4 = this;
920
+
921
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
834
922
  var finalConfig, keys, host, port, basePath, protocol, cafile, applicationId, proxy, utc, jscramblerVersion, clientId, accessKey, secretKey, client, instrumentation, previousState;
835
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
923
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
836
924
  while (1) {
837
- switch (_context4.prev = _context4.next) {
925
+ switch (_context6.prev = _context6.next) {
838
926
  case 0:
839
927
  finalConfig = buildFinalConfig(configPathOrObject);
840
928
  keys = finalConfig.keys, host = finalConfig.host, port = finalConfig.port, basePath = finalConfig.basePath, protocol = finalConfig.protocol, cafile = finalConfig.cafile, applicationId = finalConfig.applicationId, proxy = finalConfig.proxy, utc = finalConfig.utc, jscramblerVersion = finalConfig.jscramblerVersion, clientId = finalConfig.clientId;
841
929
  accessKey = keys.accessKey, secretKey = keys.secretKey;
842
- client = new this.Client({
930
+ client = new _this4.Client({
843
931
  accessKey: accessKey,
844
932
  secretKey: secretKey,
845
933
  host: host,
@@ -852,16 +940,18 @@ exports.default = {
852
940
  jscramblerVersion: jscramblerVersion,
853
941
  clientId: clientId
854
942
  });
855
- _context4.next = 6;
856
- return client.get('/profiling-run', { applicationId: applicationId }).catch(function (e) {
943
+ _context6.next = 6;
944
+ return client.get('/profiling-run', {
945
+ applicationId: applicationId
946
+ }).catch(function (e) {
857
947
  if (e.statusCode !== 404) throw e;
858
948
  });
859
949
 
860
950
  case 6:
861
- instrumentation = _context4.sent;
951
+ instrumentation = _context6.sent;
862
952
 
863
953
  if (instrumentation) {
864
- _context4.next = 9;
954
+ _context6.next = 9;
865
955
  break;
866
956
  }
867
957
 
@@ -871,48 +961,43 @@ exports.default = {
871
961
  previousState = instrumentation.data.state;
872
962
 
873
963
  if (!(previousState === state)) {
874
- _context4.next = 13;
964
+ _context6.next = 13;
875
965
  break;
876
966
  }
877
967
 
878
- console.log('Profiling was already ' + label + ' for application ' + applicationId + '. ' + nextStepMessage);
879
- return _context4.abrupt('return');
968
+ console.log("Profiling was already ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
969
+ return _context6.abrupt("return");
880
970
 
881
971
  case 13:
882
- _context4.next = 15;
883
- return client.patch('/profiling-run/' + instrumentation.data.id, {
972
+ _context6.next = 15;
973
+ return client.patch("/profiling-run/".concat(instrumentation.data.id), {
884
974
  state: state
885
975
  });
886
976
 
887
977
  case 15:
888
-
889
- console.log('Profiling was ' + label + ' for application ' + applicationId + '. ' + nextStepMessage);
978
+ console.log("Profiling was ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
890
979
 
891
980
  case 16:
892
- case 'end':
893
- return _context4.stop();
981
+ case "end":
982
+ return _context6.stop();
894
983
  }
895
984
  }
896
- }, _callee4, this);
897
- }));
898
-
899
- function setProfilingState(_x8, _x9, _x10, _x11) {
900
- return _ref8.apply(this, arguments);
901
- }
985
+ }, _callee6);
986
+ }))();
987
+ },
988
+ downloadSourceMaps: function downloadSourceMaps(configs, destCallback) {
989
+ var _this5 = this;
902
990
 
903
- return setProfilingState;
904
- }(),
905
- downloadSourceMaps: function () {
906
- var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(configs, destCallback) {
991
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
907
992
  var keys, host, port, basePath, protocol, cafile, _configs$stream, stream, filesDest, filesSrc, protectionId, jscramblerVersion, utc, proxy, accessKey, secretKey, client, download;
908
993
 
909
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
994
+ return regeneratorRuntime.wrap(function _callee7$(_context7) {
910
995
  while (1) {
911
- switch (_context5.prev = _context5.next) {
996
+ switch (_context7.prev = _context7.next) {
912
997
  case 0:
913
- keys = configs.keys, host = configs.host, port = configs.port, basePath = configs.basePath, protocol = configs.protocol, cafile = configs.cafile, _configs$stream = configs.stream, stream = _configs$stream === undefined ? true : _configs$stream, filesDest = configs.filesDest, filesSrc = configs.filesSrc, protectionId = configs.protectionId, jscramblerVersion = configs.jscramblerVersion, utc = configs.utc, proxy = configs.proxy;
998
+ keys = configs.keys, host = configs.host, port = configs.port, basePath = configs.basePath, protocol = configs.protocol, cafile = configs.cafile, _configs$stream = configs.stream, stream = _configs$stream === void 0 ? true : _configs$stream, filesDest = configs.filesDest, filesSrc = configs.filesSrc, protectionId = configs.protectionId, jscramblerVersion = configs.jscramblerVersion, utc = configs.utc, proxy = configs.proxy;
914
999
  accessKey = keys.accessKey, secretKey = keys.secretKey;
915
- client = new this.Client({
1000
+ client = new _this5.Client({
916
1001
  accessKey: accessKey,
917
1002
  secretKey: secretKey,
918
1003
  host: host,
@@ -926,7 +1011,7 @@ exports.default = {
926
1011
  });
927
1012
 
928
1013
  if (!(!filesDest && !destCallback)) {
929
- _context5.next = 5;
1014
+ _context7.next = 5;
930
1015
  break;
931
1016
  }
932
1017
 
@@ -934,62 +1019,56 @@ exports.default = {
934
1019
 
935
1020
  case 5:
936
1021
  if (protectionId) {
937
- _context5.next = 7;
1022
+ _context7.next = 7;
938
1023
  break;
939
1024
  }
940
1025
 
941
1026
  throw new Error('Required *protectionId* not provided');
942
1027
 
943
1028
  case 7:
944
-
945
1029
  if (filesSrc) {
946
1030
  console.warn('[Warning] Ignoring sources supplied. Downloading source maps of given protection');
947
1031
  }
948
- download = void 0;
949
- _context5.prev = 9;
950
- _context5.next = 12;
951
- return this.downloadSourceMapsRequest(client, protectionId);
952
1032
 
953
- case 12:
954
- download = _context5.sent;
955
- _context5.next = 18;
956
- break;
1033
+ _context7.prev = 8;
1034
+ _context7.next = 11;
1035
+ return _this5.downloadSourceMapsRequest(client, protectionId);
957
1036
 
958
- case 15:
959
- _context5.prev = 15;
960
- _context5.t0 = _context5['catch'](9);
1037
+ case 11:
1038
+ download = _context7.sent;
1039
+ _context7.next = 17;
1040
+ break;
961
1041
 
962
- errorHandler(_context5.t0);
1042
+ case 14:
1043
+ _context7.prev = 14;
1044
+ _context7.t0 = _context7["catch"](8);
1045
+ errorHandler(_context7.t0);
963
1046
 
964
- case 18:
965
- _context5.next = 20;
1047
+ case 17:
1048
+ _context7.next = 19;
966
1049
  return (0, _zip.unzip)(download, filesDest || destCallback, stream);
967
1050
 
968
- case 20:
969
- case 'end':
970
- return _context5.stop();
1051
+ case 19:
1052
+ case "end":
1053
+ return _context7.stop();
971
1054
  }
972
1055
  }
973
- }, _callee5, this, [[9, 15]]);
974
- }));
975
-
976
- function downloadSourceMaps(_x12, _x13) {
977
- return _ref9.apply(this, arguments);
978
- }
1056
+ }, _callee7, null, [[8, 14]]);
1057
+ }))();
1058
+ },
1059
+ downloadSymbolTable: function downloadSymbolTable(configs, destCallback) {
1060
+ var _this6 = this;
979
1061
 
980
- return downloadSourceMaps;
981
- }(),
982
- downloadSymbolTable: function () {
983
- var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(configs, destCallback) {
1062
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
984
1063
  var keys, host, port, basePath, protocol, cafile, _configs$stream2, stream, filesDest, filesSrc, protectionId, jscramblerVersion, utc, proxy, accessKey, secretKey, client, download;
985
1064
 
986
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
1065
+ return regeneratorRuntime.wrap(function _callee8$(_context8) {
987
1066
  while (1) {
988
- switch (_context6.prev = _context6.next) {
1067
+ switch (_context8.prev = _context8.next) {
989
1068
  case 0:
990
- keys = configs.keys, host = configs.host, port = configs.port, basePath = configs.basePath, protocol = configs.protocol, cafile = configs.cafile, _configs$stream2 = configs.stream, stream = _configs$stream2 === undefined ? true : _configs$stream2, filesDest = configs.filesDest, filesSrc = configs.filesSrc, protectionId = configs.protectionId, jscramblerVersion = configs.jscramblerVersion, utc = configs.utc, proxy = configs.proxy;
1069
+ keys = configs.keys, host = configs.host, port = configs.port, basePath = configs.basePath, protocol = configs.protocol, cafile = configs.cafile, _configs$stream2 = configs.stream, stream = _configs$stream2 === void 0 ? true : _configs$stream2, filesDest = configs.filesDest, filesSrc = configs.filesSrc, protectionId = configs.protectionId, jscramblerVersion = configs.jscramblerVersion, utc = configs.utc, proxy = configs.proxy;
991
1070
  accessKey = keys.accessKey, secretKey = keys.secretKey;
992
- client = new this.Client({
1071
+ client = new _this6.Client({
993
1072
  accessKey: accessKey,
994
1073
  secretKey: secretKey,
995
1074
  host: host,
@@ -1003,7 +1082,7 @@ exports.default = {
1003
1082
  });
1004
1083
 
1005
1084
  if (!(!filesDest && !destCallback)) {
1006
- _context6.next = 5;
1085
+ _context8.next = 5;
1007
1086
  break;
1008
1087
  }
1009
1088
 
@@ -1011,55 +1090,46 @@ exports.default = {
1011
1090
 
1012
1091
  case 5:
1013
1092
  if (protectionId) {
1014
- _context6.next = 7;
1093
+ _context8.next = 7;
1015
1094
  break;
1016
1095
  }
1017
1096
 
1018
1097
  throw new Error('Required *protectionId* not provided');
1019
1098
 
1020
1099
  case 7:
1021
-
1022
1100
  if (filesSrc) {
1023
1101
  console.warn('[Warning] Ignoring sources supplied. Downloading symbol table of given protection');
1024
1102
  }
1025
- download = void 0;
1026
- _context6.prev = 9;
1027
- _context6.next = 12;
1028
- return this.downloadSymbolTableRequest(client, protectionId);
1029
-
1030
- case 12:
1031
- download = _context6.sent;
1032
- _context6.next = 18;
1033
- break;
1034
1103
 
1035
- case 15:
1036
- _context6.prev = 15;
1037
- _context6.t0 = _context6['catch'](9);
1104
+ _context8.prev = 8;
1105
+ _context8.next = 11;
1106
+ return _this6.downloadSymbolTableRequest(client, protectionId);
1038
1107
 
1039
- errorHandler(_context6.t0);
1108
+ case 11:
1109
+ download = _context8.sent;
1110
+ _context8.next = 17;
1111
+ break;
1040
1112
 
1041
- case 18:
1113
+ case 14:
1114
+ _context8.prev = 14;
1115
+ _context8.t0 = _context8["catch"](8);
1116
+ errorHandler(_context8.t0);
1042
1117
 
1118
+ case 17:
1043
1119
  if (typeof destCallback === 'function') {
1044
1120
  destCallback(download, filesDest);
1045
1121
  } else {
1046
- (0, _zip.outputFileSync)(_path2.default.join(filesDest, protectionId + '_symbolTable.json'), download);
1122
+ (0, _zip.outputFileSync)(_path.default.join(filesDest, "".concat(protectionId, "_symbolTable.json")), download);
1047
1123
  }
1048
1124
 
1049
- case 19:
1050
- case 'end':
1051
- return _context6.stop();
1125
+ case 18:
1126
+ case "end":
1127
+ return _context8.stop();
1052
1128
  }
1053
1129
  }
1054
- }, _callee6, this, [[9, 15]]);
1055
- }));
1056
-
1057
- function downloadSymbolTable(_x14, _x15) {
1058
- return _ref10.apply(this, arguments);
1059
- }
1060
-
1061
- return downloadSymbolTable;
1062
- }(),
1130
+ }, _callee8, null, [[8, 14]]);
1131
+ }))();
1132
+ },
1063
1133
 
1064
1134
  /**
1065
1135
  * Polls a instrumentation every POLLING_INTERVALms until the state be equal to
@@ -1069,31 +1139,31 @@ exports.default = {
1069
1139
  * @returns {Promise<object>}
1070
1140
  * @throws {Error} due to errors in instrumentation process or user cancel the operation
1071
1141
  */
1072
- pollInstrumentation: function () {
1073
- var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(client, instrumentationId) {
1074
- var _this4 = this;
1142
+ pollInstrumentation: function pollInstrumentation(client, instrumentationId) {
1143
+ var _this7 = this;
1075
1144
 
1145
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
1076
1146
  var start, poll;
1077
- return regeneratorRuntime.wrap(function _callee8$(_context8) {
1147
+ return regeneratorRuntime.wrap(function _callee10$(_context10) {
1078
1148
  while (1) {
1079
- switch (_context8.prev = _context8.next) {
1149
+ switch (_context10.prev = _context10.next) {
1080
1150
  case 0:
1081
1151
  start = Date.now();
1082
1152
 
1083
- poll = function () {
1084
- var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
1153
+ poll = /*#__PURE__*/function () {
1154
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
1085
1155
  var instrumentation;
1086
- return regeneratorRuntime.wrap(function _callee7$(_context7) {
1156
+ return regeneratorRuntime.wrap(function _callee9$(_context9) {
1087
1157
  while (1) {
1088
- switch (_context7.prev = _context7.next) {
1158
+ switch (_context9.prev = _context9.next) {
1089
1159
  case 0:
1090
- _context7.next = 2;
1091
- return _this4.getInstrumentation(client, instrumentationId);
1160
+ _context9.next = 2;
1161
+ return _this7.getInstrumentation(client, instrumentationId);
1092
1162
 
1093
1163
  case 2:
1094
- instrumentation = _context7.sent;
1095
- _context7.t0 = instrumentation.data.state;
1096
- _context7.next = _context7.t0 === 'DELETED' ? 6 : _context7.t0 === 'FAILED_INSTRUMENTATION' ? 7 : _context7.t0 === 'FINISHED_INSTRUMENTATION' ? 9 : 10;
1164
+ instrumentation = _context9.sent;
1165
+ _context9.t0 = instrumentation.data.state;
1166
+ _context9.next = _context9.t0 === 'DELETED' ? 6 : _context9.t0 === 'FAILED_INSTRUMENTATION' ? 7 : _context9.t0 === 'FINISHED_INSTRUMENTATION' ? 9 : 10;
1097
1167
  break;
1098
1168
 
1099
1169
  case 6:
@@ -1102,865 +1172,798 @@ exports.default = {
1102
1172
  case 7:
1103
1173
  instrumentation.errors = instrumentation.errors.concat(instrumentation.data.instrumentationErrors.map(function (e) {
1104
1174
  return {
1105
- message: e.message + ' at ' + e.fileName + ':' + e.lineNumber
1175
+ message: "".concat(e.message, " at ").concat(e.fileName, ":").concat(e.lineNumber)
1106
1176
  };
1107
1177
  }));
1108
- return _context7.abrupt('return', errorHandler(instrumentation));
1178
+ return _context9.abrupt("return", errorHandler(instrumentation));
1109
1179
 
1110
1180
  case 9:
1111
- return _context7.abrupt('return', instrumentation);
1181
+ return _context9.abrupt("return", instrumentation);
1112
1182
 
1113
1183
  case 10:
1114
- _context7.next = 12;
1184
+ _context9.next = 12;
1115
1185
  return new Promise(function (resolve) {
1116
1186
  return setTimeout(resolve, getPollingInterval(start));
1117
1187
  });
1118
1188
 
1119
1189
  case 12:
1120
- return _context7.abrupt('return', poll());
1190
+ return _context9.abrupt("return", poll());
1121
1191
 
1122
1192
  case 13:
1123
- case 'end':
1124
- return _context7.stop();
1193
+ case "end":
1194
+ return _context9.stop();
1125
1195
  }
1126
1196
  }
1127
- }, _callee7, _this4);
1197
+ }, _callee9);
1128
1198
  }));
1129
1199
 
1130
1200
  return function poll() {
1131
- return _ref12.apply(this, arguments);
1201
+ return _ref6.apply(this, arguments);
1132
1202
  };
1133
1203
  }();
1134
1204
 
1135
- return _context8.abrupt('return', poll());
1205
+ return _context10.abrupt("return", poll());
1136
1206
 
1137
1207
  case 3:
1138
- case 'end':
1139
- return _context8.stop();
1208
+ case "end":
1209
+ return _context10.stop();
1140
1210
  }
1141
1211
  }
1142
- }, _callee8, this);
1143
- }));
1144
-
1145
- function pollInstrumentation(_x16, _x17) {
1146
- return _ref11.apply(this, arguments);
1147
- }
1148
-
1149
- return pollInstrumentation;
1150
- }(),
1151
- withRetries: function () {
1152
- var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(action) {
1212
+ }, _callee10);
1213
+ }))();
1214
+ },
1215
+ withRetries: function withRetries(action) {
1216
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
1153
1217
  var retriesLeft;
1154
- return regeneratorRuntime.wrap(function _callee9$(_context9) {
1218
+ return regeneratorRuntime.wrap(function _callee11$(_context11) {
1155
1219
  while (1) {
1156
- switch (_context9.prev = _context9.next) {
1220
+ switch (_context11.prev = _context11.next) {
1157
1221
  case 0:
1158
- retriesLeft = _config3.default.maxRetries;
1222
+ retriesLeft = _config2.default.maxRetries;
1159
1223
 
1160
1224
  case 1:
1161
- _context9.prev = 1;
1162
- _context9.next = 4;
1225
+ _context11.prev = 1;
1226
+ _context11.next = 4;
1163
1227
  return action();
1164
1228
 
1165
1229
  case 4:
1166
- return _context9.abrupt('return', _context9.sent);
1230
+ return _context11.abrupt("return", _context11.sent);
1167
1231
 
1168
1232
  case 7:
1169
- _context9.prev = 7;
1170
- _context9.t0 = _context9['catch'](1);
1233
+ _context11.prev = 7;
1234
+ _context11.t0 = _context11["catch"](1);
1171
1235
 
1172
1236
  if (!(retriesLeft <= 0)) {
1173
- _context9.next = 11;
1237
+ _context11.next = 11;
1174
1238
  break;
1175
1239
  }
1176
1240
 
1177
- throw _context9.t0;
1241
+ throw _context11.t0;
1178
1242
 
1179
1243
  case 11:
1180
- if (!(_context9.t0.statusCode !== _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE && _context9.t0.statusCode !== _constants.HTTP_STATUS_CODES.GATEWAY_TIMEOUT)) {
1181
- _context9.next = 13;
1244
+ if (!(_context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE && _context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.GATEWAY_TIMEOUT)) {
1245
+ _context11.next = 13;
1182
1246
  break;
1183
1247
  }
1184
1248
 
1185
- throw _context9.t0;
1249
+ throw _context11.t0;
1186
1250
 
1187
1251
  case 13:
1188
1252
  // Retry
1189
1253
  if (debug) {
1190
1254
  console.log('Retrying request');
1191
1255
  }
1256
+
1192
1257
  retriesLeft--;
1193
1258
 
1194
1259
  case 15:
1195
- _context9.next = 1;
1260
+ _context11.next = 1;
1196
1261
  break;
1197
1262
 
1198
1263
  case 17:
1199
- case 'end':
1200
- return _context9.stop();
1264
+ case "end":
1265
+ return _context11.stop();
1201
1266
  }
1202
1267
  }
1203
- }, _callee9, this, [[1, 7]]);
1204
- }));
1205
-
1206
- function withRetries(_x18) {
1207
- return _ref13.apply(this, arguments);
1208
- }
1209
-
1210
- return withRetries;
1211
- }(),
1212
- pollProtection: function () {
1213
- var _ref14 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(client, applicationId, protectionId, fragments) {
1214
- var _this5 = this;
1268
+ }, _callee11, null, [[1, 7]]);
1269
+ }))();
1270
+ },
1271
+ pollProtection: function pollProtection(client, applicationId, protectionId, fragments) {
1272
+ var _this8 = this;
1215
1273
 
1274
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
1216
1275
  var start, poll;
1217
- return regeneratorRuntime.wrap(function _callee11$(_context11) {
1276
+ return regeneratorRuntime.wrap(function _callee13$(_context13) {
1218
1277
  while (1) {
1219
- switch (_context11.prev = _context11.next) {
1278
+ switch (_context13.prev = _context13.next) {
1220
1279
  case 0:
1221
1280
  start = Date.now();
1222
1281
 
1223
- poll = function () {
1224
- var _ref15 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
1282
+ poll = /*#__PURE__*/function () {
1283
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
1225
1284
  var applicationProtection, state;
1226
- return regeneratorRuntime.wrap(function _callee10$(_context10) {
1285
+ return regeneratorRuntime.wrap(function _callee12$(_context12) {
1227
1286
  while (1) {
1228
- switch (_context10.prev = _context10.next) {
1287
+ switch (_context12.prev = _context12.next) {
1229
1288
  case 0:
1230
- _context10.next = 2;
1231
- return _this5.withRetries(function () {
1232
- return _this5.getApplicationProtection(client, applicationId, protectionId, fragments);
1289
+ _context12.next = 2;
1290
+ return _this8.withRetries(function () {
1291
+ return _this8.getApplicationProtection(client, applicationId, protectionId, fragments);
1233
1292
  });
1234
1293
 
1235
1294
  case 2:
1236
- applicationProtection = _context10.sent;
1295
+ applicationProtection = _context12.sent;
1237
1296
 
1238
1297
  if (!applicationProtection.errors) {
1239
- _context10.next = 8;
1298
+ _context12.next = 8;
1240
1299
  break;
1241
1300
  }
1242
1301
 
1243
1302
  console.log('Error polling protection', applicationProtection.errors);
1244
-
1245
- throw new Error('Protection failed. For more information visit: ' + APP_URL + '.');
1303
+ throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
1246
1304
 
1247
1305
  case 8:
1248
1306
  state = applicationProtection.data.applicationProtection.state;
1249
1307
 
1250
1308
  if (!(state !== 'finished' && state !== 'errored' && state !== 'canceled')) {
1251
- _context10.next = 15;
1309
+ _context12.next = 15;
1252
1310
  break;
1253
1311
  }
1254
1312
 
1255
- _context10.next = 12;
1313
+ _context12.next = 12;
1256
1314
  return new Promise(function (resolve) {
1257
1315
  return setTimeout(resolve, getPollingInterval(start));
1258
1316
  });
1259
1317
 
1260
1318
  case 12:
1261
- return _context10.abrupt('return', poll());
1319
+ return _context12.abrupt("return", poll());
1262
1320
 
1263
1321
  case 15:
1264
1322
  if (!(state === 'canceled')) {
1265
- _context10.next = 19;
1323
+ _context12.next = 19;
1266
1324
  break;
1267
1325
  }
1268
1326
 
1269
1327
  throw new Error('Protection canceled by user');
1270
1328
 
1271
1329
  case 19:
1272
- return _context10.abrupt('return', applicationProtection.data.applicationProtection);
1330
+ return _context12.abrupt("return", applicationProtection.data.applicationProtection);
1273
1331
 
1274
1332
  case 20:
1275
- case 'end':
1276
- return _context10.stop();
1333
+ case "end":
1334
+ return _context12.stop();
1277
1335
  }
1278
1336
  }
1279
- }, _callee10, _this5);
1337
+ }, _callee12);
1280
1338
  }));
1281
1339
 
1282
1340
  return function poll() {
1283
- return _ref15.apply(this, arguments);
1341
+ return _ref7.apply(this, arguments);
1284
1342
  };
1285
1343
  }();
1286
1344
 
1287
- return _context11.abrupt('return', poll());
1345
+ return _context13.abrupt("return", poll());
1288
1346
 
1289
1347
  case 3:
1290
- case 'end':
1291
- return _context11.stop();
1348
+ case "end":
1349
+ return _context13.stop();
1292
1350
  }
1293
1351
  }
1294
- }, _callee11, this);
1295
- }));
1296
-
1297
- function pollProtection(_x19, _x20, _x21, _x22) {
1298
- return _ref14.apply(this, arguments);
1299
- }
1352
+ }, _callee13);
1353
+ }))();
1354
+ },
1355
+ pollProtections: function pollProtections(client, applicationId, protectionIds, fragments) {
1356
+ var _this9 = this;
1300
1357
 
1301
- return pollProtection;
1302
- }(),
1303
-
1304
- //
1305
- createApplication: function () {
1306
- var _ref16 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(client, data, fragments) {
1307
- return regeneratorRuntime.wrap(function _callee12$(_context12) {
1358
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
1359
+ var start, seen, poll;
1360
+ return regeneratorRuntime.wrap(function _callee15$(_context15) {
1308
1361
  while (1) {
1309
- switch (_context12.prev = _context12.next) {
1362
+ switch (_context15.prev = _context15.next) {
1310
1363
  case 0:
1311
- return _context12.abrupt('return', client.post('/application', mutations.createApplication(data, fragments)));
1364
+ if (!(protectionIds.length === 1)) {
1365
+ _context15.next = 5;
1366
+ break;
1367
+ }
1312
1368
 
1313
- case 1:
1314
- case 'end':
1315
- return _context12.stop();
1316
- }
1317
- }
1318
- }, _callee12, this);
1319
- }));
1369
+ _context15.next = 3;
1370
+ return _this9.pollProtection(client, applicationId, protectionIds[0], fragments);
1320
1371
 
1321
- function createApplication(_x23, _x24, _x25) {
1322
- return _ref16.apply(this, arguments);
1323
- }
1372
+ case 3:
1373
+ _context15.t0 = _context15.sent;
1374
+ return _context15.abrupt("return", [_context15.t0]);
1324
1375
 
1325
- return createApplication;
1326
- }(),
1376
+ case 5:
1377
+ start = Date.now();
1378
+ seen = {};
1327
1379
 
1328
- //
1329
- duplicateApplication: function () {
1330
- var _ref17 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(client, data, fragments) {
1331
- return regeneratorRuntime.wrap(function _callee13$(_context13) {
1332
- while (1) {
1333
- switch (_context13.prev = _context13.next) {
1334
- case 0:
1335
- return _context13.abrupt('return', client.post('/application', mutations.duplicateApplication(data, fragments)));
1380
+ poll = /*#__PURE__*/function () {
1381
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
1382
+ var applicationProtections, ended;
1383
+ return regeneratorRuntime.wrap(function _callee14$(_context14) {
1384
+ while (1) {
1385
+ switch (_context14.prev = _context14.next) {
1386
+ case 0:
1387
+ _context14.next = 2;
1388
+ return _this9.withRetries(function () {
1389
+ return _this9.getApplicationProtections(client, applicationId, {
1390
+ protectionIds: protectionIds
1391
+ }, fragments.applicationProtection, ["$protectionIds: [String]"]);
1392
+ });
1336
1393
 
1337
- case 1:
1338
- case 'end':
1339
- return _context13.stop();
1340
- }
1341
- }
1342
- }, _callee13, this);
1343
- }));
1394
+ case 2:
1395
+ applicationProtections = _context14.sent;
1344
1396
 
1345
- function duplicateApplication(_x26, _x27, _x28) {
1346
- return _ref17.apply(this, arguments);
1347
- }
1397
+ if (!applicationProtections.errors) {
1398
+ _context14.next = 8;
1399
+ break;
1400
+ }
1348
1401
 
1349
- return duplicateApplication;
1350
- }(),
1402
+ console.log('Error polling protection', applicationProtections.errors);
1403
+ throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
1351
1404
 
1352
- //
1353
- removeApplication: function () {
1354
- var _ref18 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(client, id) {
1355
- return regeneratorRuntime.wrap(function _callee14$(_context14) {
1356
- while (1) {
1357
- switch (_context14.prev = _context14.next) {
1358
- case 0:
1359
- return _context14.abrupt('return', client.post('/application', mutations.removeApplication(id)));
1405
+ case 8:
1406
+ ended = applicationProtections.data.applicationProtections.filter(function (_ref9) {
1407
+ var state = _ref9.state;
1408
+ return state === 'finished' || state === 'errored' || state === 'canceled';
1409
+ }); // print progress
1410
+
1411
+ ended.filter(function (_ref10) {
1412
+ var _id = _ref10._id,
1413
+ state = _ref10.state;
1414
+ return !seen[_id] && state !== 'canceled';
1415
+ }).forEach(function (_ref11) {
1416
+ var _id = _ref11._id,
1417
+ startedAt = _ref11.startedAt,
1418
+ finishedAt = _ref11.finishedAt,
1419
+ state = _ref11.state;
1420
+ seen[_id] = true;
1421
+ console.log("[".concat(Object.keys(seen).length, "/").concat(protectionIds.length, "] Protection=").concat(_id, ", state=").concat(state, ", build-time=").concat(Math.round((new Date(finishedAt) - new Date(startedAt)) / 1000), "s"));
1422
+ });
1360
1423
 
1361
- case 1:
1362
- case 'end':
1363
- return _context14.stop();
1364
- }
1365
- }
1366
- }, _callee14, this);
1367
- }));
1424
+ if (!(ended.length < protectionIds.length)) {
1425
+ _context14.next = 14;
1426
+ break;
1427
+ }
1368
1428
 
1369
- function removeApplication(_x29, _x30) {
1370
- return _ref18.apply(this, arguments);
1371
- }
1429
+ _context14.next = 13;
1430
+ return new Promise(function (resolve) {
1431
+ return setTimeout(resolve, getPollingInterval(start));
1432
+ });
1372
1433
 
1373
- return removeApplication;
1374
- }(),
1434
+ case 13:
1435
+ return _context14.abrupt("return", poll());
1375
1436
 
1376
- //
1377
- removeProtection: function () {
1378
- var _ref19 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(client, id, appId, fragments) {
1379
- return regeneratorRuntime.wrap(function _callee15$(_context15) {
1380
- while (1) {
1381
- switch (_context15.prev = _context15.next) {
1382
- case 0:
1383
- return _context15.abrupt('return', client.post('/application', mutations.removeProtection(id, appId, fragments)));
1437
+ case 14:
1438
+ return _context14.abrupt("return", applicationProtections.data.applicationProtections);
1384
1439
 
1385
- case 1:
1386
- case 'end':
1387
- return _context15.stop();
1388
- }
1389
- }
1390
- }, _callee15, this);
1391
- }));
1440
+ case 15:
1441
+ case "end":
1442
+ return _context14.stop();
1443
+ }
1444
+ }
1445
+ }, _callee14);
1446
+ }));
1392
1447
 
1393
- function removeProtection(_x31, _x32, _x33, _x34) {
1394
- return _ref19.apply(this, arguments);
1395
- }
1448
+ return function poll() {
1449
+ return _ref8.apply(this, arguments);
1450
+ };
1451
+ }();
1396
1452
 
1397
- return removeProtection;
1398
- }(),
1453
+ return _context15.abrupt("return", poll());
1399
1454
 
1455
+ case 9:
1456
+ case "end":
1457
+ return _context15.stop();
1458
+ }
1459
+ }
1460
+ }, _callee15);
1461
+ }))();
1462
+ },
1400
1463
  //
1401
- cancelProtection: function () {
1402
- var _ref20 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16(client, id, appId, fragments) {
1403
- var mutation;
1464
+ createApplication: function createApplication(client, data, fragments) {
1465
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
1404
1466
  return regeneratorRuntime.wrap(function _callee16$(_context16) {
1405
1467
  while (1) {
1406
1468
  switch (_context16.prev = _context16.next) {
1407
1469
  case 0:
1408
- _context16.next = 2;
1409
- return mutations.cancelProtection(id, appId, fragments);
1410
-
1411
- case 2:
1412
- mutation = _context16.sent;
1413
- return _context16.abrupt('return', client.post('/application', mutation));
1470
+ return _context16.abrupt("return", client.post('/application', mutations.createApplication(data, fragments)));
1414
1471
 
1415
- case 4:
1416
- case 'end':
1472
+ case 1:
1473
+ case "end":
1417
1474
  return _context16.stop();
1418
1475
  }
1419
1476
  }
1420
- }, _callee16, this);
1421
- }));
1422
-
1423
- function cancelProtection(_x35, _x36, _x37, _x38) {
1424
- return _ref20.apply(this, arguments);
1425
- }
1426
-
1427
- return cancelProtection;
1428
- }(),
1429
-
1477
+ }, _callee16);
1478
+ }))();
1479
+ },
1430
1480
  //
1431
- updateApplication: function () {
1432
- var _ref21 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17(client, application, fragments) {
1433
- var mutation;
1481
+ duplicateApplication: function duplicateApplication(client, data, fragments) {
1482
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
1434
1483
  return regeneratorRuntime.wrap(function _callee17$(_context17) {
1435
1484
  while (1) {
1436
1485
  switch (_context17.prev = _context17.next) {
1437
1486
  case 0:
1438
- _context17.next = 2;
1439
- return mutations.updateApplication(application, fragments);
1487
+ return _context17.abrupt("return", client.post('/application', mutations.duplicateApplication(data, fragments)));
1440
1488
 
1441
- case 2:
1442
- mutation = _context17.sent;
1443
- return _context17.abrupt('return', client.post('/application', mutation));
1444
-
1445
- case 4:
1446
- case 'end':
1489
+ case 1:
1490
+ case "end":
1447
1491
  return _context17.stop();
1448
1492
  }
1449
1493
  }
1450
- }, _callee17, this);
1451
- }));
1452
-
1453
- function updateApplication(_x39, _x40, _x41) {
1454
- return _ref21.apply(this, arguments);
1455
- }
1456
-
1457
- return updateApplication;
1458
- }(),
1459
-
1494
+ }, _callee17);
1495
+ }))();
1496
+ },
1460
1497
  //
1461
- unlockApplication: function () {
1462
- var _ref22 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18(client, application, fragments) {
1463
- var mutation;
1498
+ removeApplication: function removeApplication(client, id) {
1499
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
1464
1500
  return regeneratorRuntime.wrap(function _callee18$(_context18) {
1465
1501
  while (1) {
1466
1502
  switch (_context18.prev = _context18.next) {
1467
1503
  case 0:
1468
- _context18.next = 2;
1469
- return mutations.unlockApplication(application, fragments);
1470
-
1471
- case 2:
1472
- mutation = _context18.sent;
1473
- return _context18.abrupt('return', client.post('/application', mutation));
1504
+ return _context18.abrupt("return", client.post('/application', mutations.removeApplication(id)));
1474
1505
 
1475
- case 4:
1476
- case 'end':
1506
+ case 1:
1507
+ case "end":
1477
1508
  return _context18.stop();
1478
1509
  }
1479
1510
  }
1480
- }, _callee18, this);
1481
- }));
1482
-
1483
- function unlockApplication(_x42, _x43, _x44) {
1484
- return _ref22.apply(this, arguments);
1485
- }
1486
-
1487
- return unlockApplication;
1488
- }(),
1489
-
1511
+ }, _callee18);
1512
+ }))();
1513
+ },
1490
1514
  //
1491
- getApplication: function () {
1492
- var _ref23 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19(client, applicationId, fragments, params) {
1493
- var query;
1515
+ removeProtection: function removeProtection(client, id, appId, fragments) {
1516
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
1494
1517
  return regeneratorRuntime.wrap(function _callee19$(_context19) {
1495
1518
  while (1) {
1496
1519
  switch (_context19.prev = _context19.next) {
1497
1520
  case 0:
1498
- _context19.next = 2;
1499
- return queries.getApplication(applicationId, fragments, params);
1500
-
1501
- case 2:
1502
- query = _context19.sent;
1503
- return _context19.abrupt('return', client.get('/application', query));
1521
+ return _context19.abrupt("return", client.post('/application', mutations.removeProtection(id, appId, fragments)));
1504
1522
 
1505
- case 4:
1506
- case 'end':
1523
+ case 1:
1524
+ case "end":
1507
1525
  return _context19.stop();
1508
1526
  }
1509
1527
  }
1510
- }, _callee19, this);
1511
- }));
1512
-
1513
- function getApplication(_x45, _x46, _x47, _x48) {
1514
- return _ref23.apply(this, arguments);
1515
- }
1516
-
1517
- return getApplication;
1518
- }(),
1519
-
1528
+ }, _callee19);
1529
+ }))();
1530
+ },
1520
1531
  //
1521
- getApplicationSource: function () {
1522
- var _ref24 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20(client, sourceId, fragments, limits) {
1523
- var query;
1532
+ cancelProtection: function cancelProtection(client, id, appId, fragments) {
1533
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
1534
+ var mutation;
1524
1535
  return regeneratorRuntime.wrap(function _callee20$(_context20) {
1525
1536
  while (1) {
1526
1537
  switch (_context20.prev = _context20.next) {
1527
1538
  case 0:
1528
1539
  _context20.next = 2;
1529
- return queries.getApplicationSource(sourceId, fragments, limits);
1540
+ return mutations.cancelProtection(id, appId, fragments);
1530
1541
 
1531
1542
  case 2:
1532
- query = _context20.sent;
1533
- return _context20.abrupt('return', client.get('/application', query));
1543
+ mutation = _context20.sent;
1544
+ return _context20.abrupt("return", client.post('/application', mutation));
1534
1545
 
1535
1546
  case 4:
1536
- case 'end':
1547
+ case "end":
1537
1548
  return _context20.stop();
1538
1549
  }
1539
1550
  }
1540
- }, _callee20, this);
1541
- }));
1542
-
1543
- function getApplicationSource(_x49, _x50, _x51, _x52) {
1544
- return _ref24.apply(this, arguments);
1545
- }
1546
-
1547
- return getApplicationSource;
1548
- }(),
1549
-
1551
+ }, _callee20);
1552
+ }))();
1553
+ },
1550
1554
  //
1551
- getApplicationProtections: function () {
1552
- var _ref25 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21(client, applicationId, params, fragments) {
1553
- var query;
1555
+ updateApplication: function updateApplication(client, application, fragments) {
1556
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
1557
+ var mutation;
1554
1558
  return regeneratorRuntime.wrap(function _callee21$(_context21) {
1555
1559
  while (1) {
1556
1560
  switch (_context21.prev = _context21.next) {
1557
1561
  case 0:
1558
1562
  _context21.next = 2;
1559
- return queries.getApplicationProtections(applicationId, params, fragments);
1563
+ return mutations.updateApplication(application, fragments);
1560
1564
 
1561
1565
  case 2:
1562
- query = _context21.sent;
1563
- return _context21.abrupt('return', client.get('/application', query));
1566
+ mutation = _context21.sent;
1567
+ return _context21.abrupt("return", client.post('/application', mutation));
1564
1568
 
1565
1569
  case 4:
1566
- case 'end':
1570
+ case "end":
1567
1571
  return _context21.stop();
1568
1572
  }
1569
1573
  }
1570
- }, _callee21, this);
1571
- }));
1572
-
1573
- function getApplicationProtections(_x53, _x54, _x55, _x56) {
1574
- return _ref25.apply(this, arguments);
1575
- }
1576
-
1577
- return getApplicationProtections;
1578
- }(),
1579
-
1574
+ }, _callee21);
1575
+ }))();
1576
+ },
1580
1577
  //
1581
- getApplicationProtectionsCount: function () {
1582
- var _ref26 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22(client, applicationId, fragments) {
1583
- var query;
1578
+ unlockApplication: function unlockApplication(client, application, fragments) {
1579
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() {
1580
+ var mutation;
1584
1581
  return regeneratorRuntime.wrap(function _callee22$(_context22) {
1585
1582
  while (1) {
1586
1583
  switch (_context22.prev = _context22.next) {
1587
1584
  case 0:
1588
1585
  _context22.next = 2;
1589
- return queries.getApplicationProtectionsCount(applicationId, fragments);
1586
+ return mutations.unlockApplication(application, fragments);
1590
1587
 
1591
1588
  case 2:
1592
- query = _context22.sent;
1593
- return _context22.abrupt('return', client.get('/application', query));
1589
+ mutation = _context22.sent;
1590
+ return _context22.abrupt("return", client.post('/application', mutation));
1594
1591
 
1595
1592
  case 4:
1596
- case 'end':
1593
+ case "end":
1597
1594
  return _context22.stop();
1598
1595
  }
1599
1596
  }
1600
- }, _callee22, this);
1601
- }));
1602
-
1603
- function getApplicationProtectionsCount(_x57, _x58, _x59) {
1604
- return _ref26.apply(this, arguments);
1605
- }
1606
-
1607
- return getApplicationProtectionsCount;
1608
- }(),
1609
-
1597
+ }, _callee22);
1598
+ }))();
1599
+ },
1610
1600
  //
1611
- createTemplate: function () {
1612
- var _ref27 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23(client, template, fragments) {
1613
- var mutation;
1601
+ getApplication: function getApplication(client, applicationId, fragments, params) {
1602
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23() {
1603
+ var query;
1614
1604
  return regeneratorRuntime.wrap(function _callee23$(_context23) {
1615
1605
  while (1) {
1616
1606
  switch (_context23.prev = _context23.next) {
1617
1607
  case 0:
1618
1608
  _context23.next = 2;
1619
- return mutations.createTemplate(template, fragments);
1609
+ return queries.getApplication(applicationId, fragments, params);
1620
1610
 
1621
1611
  case 2:
1622
- mutation = _context23.sent;
1623
- return _context23.abrupt('return', client.post('/application', mutation));
1612
+ query = _context23.sent;
1613
+ return _context23.abrupt("return", client.get('/application', query));
1624
1614
 
1625
1615
  case 4:
1626
- case 'end':
1616
+ case "end":
1627
1617
  return _context23.stop();
1628
1618
  }
1629
1619
  }
1630
- }, _callee23, this);
1631
- }));
1632
-
1633
- function createTemplate(_x60, _x61, _x62) {
1634
- return _ref27.apply(this, arguments);
1635
- }
1636
-
1637
- return createTemplate;
1638
- }(),
1639
-
1620
+ }, _callee23);
1621
+ }))();
1622
+ },
1640
1623
  //
1641
- removeTemplate: function () {
1642
- var _ref28 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24(client, id) {
1643
- var mutation;
1624
+ getApplicationSource: function getApplicationSource(client, sourceId, fragments, limits) {
1625
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24() {
1626
+ var query;
1644
1627
  return regeneratorRuntime.wrap(function _callee24$(_context24) {
1645
1628
  while (1) {
1646
1629
  switch (_context24.prev = _context24.next) {
1647
1630
  case 0:
1648
1631
  _context24.next = 2;
1649
- return mutations.removeTemplate(id);
1632
+ return queries.getApplicationSource(sourceId, fragments, limits);
1650
1633
 
1651
1634
  case 2:
1652
- mutation = _context24.sent;
1653
- return _context24.abrupt('return', client.post('/application', mutation));
1635
+ query = _context24.sent;
1636
+ return _context24.abrupt("return", client.get('/application', query));
1654
1637
 
1655
1638
  case 4:
1656
- case 'end':
1639
+ case "end":
1657
1640
  return _context24.stop();
1658
1641
  }
1659
1642
  }
1660
- }, _callee24, this);
1661
- }));
1662
-
1663
- function removeTemplate(_x63, _x64) {
1664
- return _ref28.apply(this, arguments);
1665
- }
1666
-
1667
- return removeTemplate;
1668
- }(),
1669
-
1643
+ }, _callee24);
1644
+ }))();
1645
+ },
1670
1646
  //
1671
- getTemplates: function () {
1672
- var _ref29 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25(client, fragments) {
1647
+ getApplicationProtections: function getApplicationProtections(client, applicationId, params, fragments, queryArgs) {
1648
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25() {
1673
1649
  var query;
1674
1650
  return regeneratorRuntime.wrap(function _callee25$(_context25) {
1675
1651
  while (1) {
1676
1652
  switch (_context25.prev = _context25.next) {
1677
1653
  case 0:
1678
- _context25.next = 2;
1679
- return queries.getTemplates(fragments);
1654
+ query = queries.getApplicationProtections(applicationId, params, fragments, queryArgs);
1655
+ return _context25.abrupt("return", client.get('/application', query));
1680
1656
 
1681
1657
  case 2:
1682
- query = _context25.sent;
1683
- return _context25.abrupt('return', client.get('/application', query));
1684
-
1685
- case 4:
1686
- case 'end':
1658
+ case "end":
1687
1659
  return _context25.stop();
1688
1660
  }
1689
1661
  }
1690
- }, _callee25, this);
1691
- }));
1692
-
1693
- function getTemplates(_x65, _x66) {
1694
- return _ref29.apply(this, arguments);
1695
- }
1696
-
1697
- return getTemplates;
1698
- }(),
1699
-
1662
+ }, _callee25);
1663
+ }))();
1664
+ },
1700
1665
  //
1701
- getApplications: function () {
1702
- var _ref30 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26(client, fragments, params) {
1666
+ getApplicationProtectionsCount: function getApplicationProtectionsCount(client, applicationId, fragments) {
1667
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26() {
1703
1668
  var query;
1704
1669
  return regeneratorRuntime.wrap(function _callee26$(_context26) {
1705
1670
  while (1) {
1706
1671
  switch (_context26.prev = _context26.next) {
1707
1672
  case 0:
1708
1673
  _context26.next = 2;
1709
- return queries.getApplications(fragments, params);
1674
+ return queries.getApplicationProtectionsCount(applicationId, fragments);
1710
1675
 
1711
1676
  case 2:
1712
1677
  query = _context26.sent;
1713
- return _context26.abrupt('return', client.get('/application', query));
1678
+ return _context26.abrupt("return", client.get('/application', query));
1714
1679
 
1715
1680
  case 4:
1716
- case 'end':
1681
+ case "end":
1717
1682
  return _context26.stop();
1718
1683
  }
1719
1684
  }
1720
- }, _callee26, this);
1721
- }));
1722
-
1723
- function getApplications(_x67, _x68, _x69) {
1724
- return _ref30.apply(this, arguments);
1725
- }
1726
-
1727
- return getApplications;
1728
- }(),
1729
-
1685
+ }, _callee26);
1686
+ }))();
1687
+ },
1730
1688
  //
1731
- addApplicationSource: function () {
1732
- var _ref31 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee27(client, applicationId, applicationSource, fragments) {
1689
+ createTemplate: function createTemplate(client, template, fragments) {
1690
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee27() {
1733
1691
  var mutation;
1734
1692
  return regeneratorRuntime.wrap(function _callee27$(_context27) {
1735
1693
  while (1) {
1736
1694
  switch (_context27.prev = _context27.next) {
1737
1695
  case 0:
1738
1696
  _context27.next = 2;
1739
- return mutations.addApplicationSource(applicationId, applicationSource, fragments);
1697
+ return mutations.createTemplate(template, fragments);
1740
1698
 
1741
1699
  case 2:
1742
1700
  mutation = _context27.sent;
1743
- return _context27.abrupt('return', this.withRetries(function () {
1744
- return client.post('/application', mutation);
1745
- }));
1701
+ return _context27.abrupt("return", client.post('/application', mutation));
1746
1702
 
1747
1703
  case 4:
1748
- case 'end':
1704
+ case "end":
1749
1705
  return _context27.stop();
1750
1706
  }
1751
1707
  }
1752
- }, _callee27, this);
1753
- }));
1754
-
1755
- function addApplicationSource(_x70, _x71, _x72, _x73) {
1756
- return _ref31.apply(this, arguments);
1757
- }
1758
-
1759
- return addApplicationSource;
1760
- }(),
1761
-
1708
+ }, _callee27);
1709
+ }))();
1710
+ },
1762
1711
  //
1763
- addApplicationSourceFromURL: function () {
1764
- var _ref32 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee28(client, applicationId, url, fragments) {
1765
- var file, mutation;
1712
+ removeTemplate: function removeTemplate(client, id) {
1713
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee28() {
1714
+ var mutation;
1766
1715
  return regeneratorRuntime.wrap(function _callee28$(_context28) {
1767
1716
  while (1) {
1768
1717
  switch (_context28.prev = _context28.next) {
1769
1718
  case 0:
1770
1719
  _context28.next = 2;
1771
- return getFileFromUrl(client, url);
1720
+ return mutations.removeTemplate(id);
1772
1721
 
1773
1722
  case 2:
1774
- file = _context28.sent;
1775
- _context28.next = 5;
1776
- return mutations.addApplicationSource(applicationId, file, fragments);
1777
-
1778
- case 5:
1779
1723
  mutation = _context28.sent;
1780
- return _context28.abrupt('return', client.post('/application', mutation));
1724
+ return _context28.abrupt("return", client.post('/application', mutation));
1781
1725
 
1782
- case 7:
1783
- case 'end':
1726
+ case 4:
1727
+ case "end":
1784
1728
  return _context28.stop();
1785
1729
  }
1786
1730
  }
1787
- }, _callee28, this);
1788
- }));
1789
-
1790
- function addApplicationSourceFromURL(_x74, _x75, _x76, _x77) {
1791
- return _ref32.apply(this, arguments);
1792
- }
1793
-
1794
- return addApplicationSourceFromURL;
1795
- }(),
1796
-
1731
+ }, _callee28);
1732
+ }))();
1733
+ },
1797
1734
  //
1798
- updateApplicationSource: function () {
1799
- var _ref33 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee29(client, applicationSource, fragments) {
1800
- var mutation;
1735
+ getTemplates: function getTemplates(client, fragments) {
1736
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee29() {
1737
+ var query;
1801
1738
  return regeneratorRuntime.wrap(function _callee29$(_context29) {
1802
1739
  while (1) {
1803
1740
  switch (_context29.prev = _context29.next) {
1804
1741
  case 0:
1805
1742
  _context29.next = 2;
1806
- return mutations.updateApplicationSource(applicationSource, fragments);
1743
+ return queries.getTemplates(fragments);
1807
1744
 
1808
1745
  case 2:
1809
- mutation = _context29.sent;
1810
- return _context29.abrupt('return', client.post('/application', mutation));
1746
+ query = _context29.sent;
1747
+ return _context29.abrupt("return", client.get('/application', query));
1811
1748
 
1812
1749
  case 4:
1813
- case 'end':
1750
+ case "end":
1814
1751
  return _context29.stop();
1815
1752
  }
1816
1753
  }
1817
- }, _callee29, this);
1818
- }));
1819
-
1820
- function updateApplicationSource(_x78, _x79, _x80) {
1821
- return _ref33.apply(this, arguments);
1822
- }
1823
-
1824
- return updateApplicationSource;
1825
- }(),
1826
-
1754
+ }, _callee29);
1755
+ }))();
1756
+ },
1827
1757
  //
1828
- removeSourceFromApplication: function () {
1829
- var _ref34 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30(client, sourceId, applicationId, fragments) {
1830
- var mutation;
1758
+ getApplications: function getApplications(client, fragments, params) {
1759
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30() {
1760
+ var query;
1831
1761
  return regeneratorRuntime.wrap(function _callee30$(_context30) {
1832
1762
  while (1) {
1833
1763
  switch (_context30.prev = _context30.next) {
1834
1764
  case 0:
1835
1765
  _context30.next = 2;
1836
- return mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
1766
+ return queries.getApplications(fragments, params);
1837
1767
 
1838
1768
  case 2:
1839
- mutation = _context30.sent;
1840
- return _context30.abrupt('return', this.withRetries(function () {
1841
- return client.post('/application', mutation);
1842
- }));
1769
+ query = _context30.sent;
1770
+ return _context30.abrupt("return", client.get('/application', query));
1843
1771
 
1844
1772
  case 4:
1845
- case 'end':
1773
+ case "end":
1846
1774
  return _context30.stop();
1847
1775
  }
1848
1776
  }
1849
- }, _callee30, this);
1850
- }));
1851
-
1852
- function removeSourceFromApplication(_x81, _x82, _x83, _x84) {
1853
- return _ref34.apply(this, arguments);
1854
- }
1855
-
1856
- return removeSourceFromApplication;
1857
- }(),
1858
-
1777
+ }, _callee30);
1778
+ }))();
1779
+ },
1859
1780
  //
1860
- applyTemplate: function () {
1861
- var _ref35 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee31(client, templateId, appId, fragments) {
1781
+ addApplicationSource: function addApplicationSource(client, applicationId, applicationSource, fragments) {
1782
+ var _this10 = this;
1783
+
1784
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee31() {
1862
1785
  var mutation;
1863
1786
  return regeneratorRuntime.wrap(function _callee31$(_context31) {
1864
1787
  while (1) {
1865
1788
  switch (_context31.prev = _context31.next) {
1866
1789
  case 0:
1867
1790
  _context31.next = 2;
1868
- return mutations.applyTemplate(templateId, appId, fragments);
1791
+ return mutations.addApplicationSource(applicationId, applicationSource, fragments);
1869
1792
 
1870
1793
  case 2:
1871
1794
  mutation = _context31.sent;
1872
- return _context31.abrupt('return', client.post('/application', mutation));
1795
+ return _context31.abrupt("return", _this10.withRetries(function () {
1796
+ return client.post('/application', mutation);
1797
+ }));
1873
1798
 
1874
1799
  case 4:
1875
- case 'end':
1800
+ case "end":
1876
1801
  return _context31.stop();
1877
1802
  }
1878
1803
  }
1879
- }, _callee31, this);
1880
- }));
1881
-
1882
- function applyTemplate(_x85, _x86, _x87, _x88) {
1883
- return _ref35.apply(this, arguments);
1884
- }
1885
-
1886
- return applyTemplate;
1887
- }(),
1888
-
1804
+ }, _callee31);
1805
+ }))();
1806
+ },
1889
1807
  //
1890
- updateTemplate: function () {
1891
- var _ref36 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee32(client, template, fragments) {
1892
- var mutation;
1808
+ addApplicationSourceFromURL: function addApplicationSourceFromURL(client, applicationId, url, fragments) {
1809
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee32() {
1810
+ var file, mutation;
1893
1811
  return regeneratorRuntime.wrap(function _callee32$(_context32) {
1894
1812
  while (1) {
1895
1813
  switch (_context32.prev = _context32.next) {
1896
1814
  case 0:
1897
1815
  _context32.next = 2;
1898
- return mutations.updateTemplate(template, fragments);
1816
+ return getFileFromUrl(client, url);
1899
1817
 
1900
1818
  case 2:
1819
+ file = _context32.sent;
1820
+ _context32.next = 5;
1821
+ return mutations.addApplicationSource(applicationId, file, fragments);
1822
+
1823
+ case 5:
1901
1824
  mutation = _context32.sent;
1902
- return _context32.abrupt('return', client.post('/application', mutation));
1825
+ return _context32.abrupt("return", client.post('/application', mutation));
1903
1826
 
1904
- case 4:
1905
- case 'end':
1827
+ case 7:
1828
+ case "end":
1906
1829
  return _context32.stop();
1907
1830
  }
1908
1831
  }
1909
- }, _callee32, this);
1910
- }));
1911
-
1912
- function updateTemplate(_x89, _x90, _x91) {
1913
- return _ref36.apply(this, arguments);
1914
- }
1915
-
1916
- return updateTemplate;
1917
- }(),
1918
- getApplicationProfiling: function () {
1919
- var _ref37 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee33(client, applicationId) {
1832
+ }, _callee32);
1833
+ }))();
1834
+ },
1835
+ //
1836
+ updateApplicationSource: function updateApplicationSource(client, applicationSource, fragments) {
1837
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee33() {
1838
+ var mutation;
1920
1839
  return regeneratorRuntime.wrap(function _callee33$(_context33) {
1921
1840
  while (1) {
1922
1841
  switch (_context33.prev = _context33.next) {
1923
1842
  case 0:
1924
- return _context33.abrupt('return', client.get('/profiling-run', { applicationId: applicationId }));
1843
+ _context33.next = 2;
1844
+ return mutations.updateApplicationSource(applicationSource, fragments);
1925
1845
 
1926
- case 1:
1927
- case 'end':
1846
+ case 2:
1847
+ mutation = _context33.sent;
1848
+ return _context33.abrupt("return", client.post('/application', mutation));
1849
+
1850
+ case 4:
1851
+ case "end":
1928
1852
  return _context33.stop();
1929
1853
  }
1930
1854
  }
1931
- }, _callee33, this);
1932
- }));
1933
-
1934
- function getApplicationProfiling(_x92, _x93) {
1935
- return _ref37.apply(this, arguments);
1936
- }
1855
+ }, _callee33);
1856
+ }))();
1857
+ },
1858
+ //
1859
+ removeSourceFromApplication: function removeSourceFromApplication(client, sourceId, applicationId, fragments) {
1860
+ var _this11 = this;
1937
1861
 
1938
- return getApplicationProfiling;
1939
- }(),
1940
- deleteProfiling: function () {
1941
- var _ref38 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee34(client, profilingId) {
1862
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee34() {
1863
+ var mutation;
1942
1864
  return regeneratorRuntime.wrap(function _callee34$(_context34) {
1943
1865
  while (1) {
1944
1866
  switch (_context34.prev = _context34.next) {
1945
1867
  case 0:
1946
- return _context34.abrupt('return', client.patch('/profiling-run/' + profilingId, {
1947
- state: 'DELETED'
1868
+ _context34.next = 2;
1869
+ return mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
1870
+
1871
+ case 2:
1872
+ mutation = _context34.sent;
1873
+ return _context34.abrupt("return", _this11.withRetries(function () {
1874
+ return client.post('/application', mutation);
1948
1875
  }));
1949
1876
 
1950
- case 1:
1951
- case 'end':
1877
+ case 4:
1878
+ case "end":
1952
1879
  return _context34.stop();
1953
1880
  }
1954
1881
  }
1955
- }, _callee34, this);
1956
- }));
1882
+ }, _callee34);
1883
+ }))();
1884
+ },
1885
+ //
1886
+ applyTemplate: function applyTemplate(client, templateId, appId, fragments) {
1887
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee35() {
1888
+ var mutation;
1889
+ return regeneratorRuntime.wrap(function _callee35$(_context35) {
1890
+ while (1) {
1891
+ switch (_context35.prev = _context35.next) {
1892
+ case 0:
1893
+ _context35.next = 2;
1894
+ return mutations.applyTemplate(templateId, appId, fragments);
1895
+
1896
+ case 2:
1897
+ mutation = _context35.sent;
1898
+ return _context35.abrupt("return", client.post('/application', mutation));
1899
+
1900
+ case 4:
1901
+ case "end":
1902
+ return _context35.stop();
1903
+ }
1904
+ }
1905
+ }, _callee35);
1906
+ }))();
1907
+ },
1908
+ //
1909
+ updateTemplate: function updateTemplate(client, template, fragments) {
1910
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee36() {
1911
+ var mutation;
1912
+ return regeneratorRuntime.wrap(function _callee36$(_context36) {
1913
+ while (1) {
1914
+ switch (_context36.prev = _context36.next) {
1915
+ case 0:
1916
+ _context36.next = 2;
1917
+ return mutations.updateTemplate(template, fragments);
1957
1918
 
1958
- function deleteProfiling(_x94, _x95) {
1959
- return _ref38.apply(this, arguments);
1960
- }
1919
+ case 2:
1920
+ mutation = _context36.sent;
1921
+ return _context36.abrupt("return", client.post('/application', mutation));
1961
1922
 
1962
- return deleteProfiling;
1963
- }(),
1923
+ case 4:
1924
+ case "end":
1925
+ return _context36.stop();
1926
+ }
1927
+ }
1928
+ }, _callee36);
1929
+ }))();
1930
+ },
1931
+ getApplicationProfiling: function getApplicationProfiling(client, applicationId) {
1932
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee37() {
1933
+ return regeneratorRuntime.wrap(function _callee37$(_context37) {
1934
+ while (1) {
1935
+ switch (_context37.prev = _context37.next) {
1936
+ case 0:
1937
+ return _context37.abrupt("return", client.get('/profiling-run', {
1938
+ applicationId: applicationId
1939
+ }));
1940
+
1941
+ case 1:
1942
+ case "end":
1943
+ return _context37.stop();
1944
+ }
1945
+ }
1946
+ }, _callee37);
1947
+ }))();
1948
+ },
1949
+ deleteProfiling: function deleteProfiling(client, profilingId) {
1950
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee38() {
1951
+ return regeneratorRuntime.wrap(function _callee38$(_context38) {
1952
+ while (1) {
1953
+ switch (_context38.prev = _context38.next) {
1954
+ case 0:
1955
+ return _context38.abrupt("return", client.patch("/profiling-run/".concat(profilingId), {
1956
+ state: 'DELETED'
1957
+ }));
1958
+
1959
+ case 1:
1960
+ case "end":
1961
+ return _context38.stop();
1962
+ }
1963
+ }
1964
+ }, _callee38);
1965
+ }))();
1966
+ },
1964
1967
 
1965
1968
  /**
1966
1969
  * Starts a new instrumentation process.
@@ -1969,211 +1972,248 @@ exports.default = {
1969
1972
  * @param applicationId
1970
1973
  * @returns {Promise<*>}
1971
1974
  */
1972
- startInstrumentation: function () {
1973
- var _ref39 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee35(client, applicationId) {
1975
+ startInstrumentation: function startInstrumentation(client, applicationId) {
1976
+ var _this12 = this;
1977
+
1978
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee39() {
1974
1979
  var instrumentation;
1975
- return regeneratorRuntime.wrap(function _callee35$(_context35) {
1980
+ return regeneratorRuntime.wrap(function _callee39$(_context39) {
1976
1981
  while (1) {
1977
- switch (_context35.prev = _context35.next) {
1982
+ switch (_context39.prev = _context39.next) {
1978
1983
  case 0:
1979
- _context35.next = 2;
1980
- return this.getApplicationProfiling(client, applicationId).catch(function (e) {
1984
+ _context39.next = 2;
1985
+ return _this12.getApplicationProfiling(client, applicationId).catch(function (e) {
1981
1986
  if (e.statusCode !== 404) throw e;
1982
1987
  });
1983
1988
 
1984
1989
  case 2:
1985
- instrumentation = _context35.sent;
1990
+ instrumentation = _context39.sent;
1986
1991
 
1987
1992
  if (!instrumentation) {
1988
- _context35.next = 6;
1993
+ _context39.next = 6;
1989
1994
  break;
1990
1995
  }
1991
1996
 
1992
- _context35.next = 6;
1993
- return this.deleteProfiling(client, instrumentation.data.id);
1997
+ _context39.next = 6;
1998
+ return _this12.deleteProfiling(client, instrumentation.data.id);
1994
1999
 
1995
2000
  case 6:
1996
- return _context35.abrupt('return', client.post('/profiling-run', { applicationId: applicationId }));
2001
+ return _context39.abrupt("return", client.post('/profiling-run', {
2002
+ applicationId: applicationId
2003
+ }));
1997
2004
 
1998
2005
  case 7:
1999
- case 'end':
2000
- return _context35.stop();
2006
+ case "end":
2007
+ return _context39.stop();
2001
2008
  }
2002
2009
  }
2003
- }, _callee35, this);
2004
- }));
2005
-
2006
- function startInstrumentation(_x96, _x97) {
2007
- return _ref39.apply(this, arguments);
2008
- }
2009
-
2010
- return startInstrumentation;
2011
- }(),
2012
-
2010
+ }, _callee39);
2011
+ }))();
2012
+ },
2013
2013
  //
2014
- createApplicationProtection: function () {
2015
- var _ref40 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee36(client, applicationId, protectionOptions, fragments) {
2016
- var _ref41, args, mutation;
2014
+ createApplicationProtection: function createApplicationProtection(client, applicationId, protectionOptions, fragments) {
2015
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee40() {
2016
+ var _yield$introspection$, args, mutation;
2017
2017
 
2018
- return regeneratorRuntime.wrap(function _callee36$(_context36) {
2018
+ return regeneratorRuntime.wrap(function _callee40$(_context40) {
2019
2019
  while (1) {
2020
- switch (_context36.prev = _context36.next) {
2020
+ switch (_context40.prev = _context40.next) {
2021
2021
  case 0:
2022
- _context36.next = 2;
2022
+ _context40.next = 2;
2023
2023
  return introspection.mutation(client, 'createApplicationProtection');
2024
2024
 
2025
2025
  case 2:
2026
- _ref41 = _context36.sent;
2027
- args = _ref41.args;
2028
- _context36.next = 6;
2026
+ _yield$introspection$ = _context40.sent;
2027
+ args = _yield$introspection$.args;
2028
+ _context40.next = 6;
2029
2029
  return mutations.createApplicationProtection(applicationId, fragments, protectionOptions, args);
2030
2030
 
2031
2031
  case 6:
2032
- mutation = _context36.sent;
2033
- return _context36.abrupt('return', client.post('/application', mutation));
2032
+ mutation = _context40.sent;
2033
+ return _context40.abrupt("return", client.post('/application', mutation));
2034
2034
 
2035
2035
  case 8:
2036
- case 'end':
2037
- return _context36.stop();
2036
+ case "end":
2037
+ return _context40.stop();
2038
2038
  }
2039
2039
  }
2040
- }, _callee36, this);
2041
- }));
2040
+ }, _callee40);
2041
+ }))();
2042
+ },
2042
2043
 
2043
- function createApplicationProtection(_x98, _x99, _x100, _x101) {
2044
- return _ref40.apply(this, arguments);
2045
- }
2044
+ /**
2045
+ * Create one or more application protections at once
2046
+ * @param {JscramblerClient} client
2047
+ * @param {string} applicationId
2048
+ * @param {object} protectionOptions
2049
+ * @param {number} [protectionOptions.numberOfProtections]
2050
+ * @param {object} fragments
2051
+ * @returns {Promise<{data: {protections: Array.<{_id}>}, errors: Array}>}
2052
+ */
2053
+ createApplicationProtections: function createApplicationProtections(client, applicationId, protectionOptions, fragments) {
2054
+ var _this13 = this;
2046
2055
 
2047
- return createApplicationProtection;
2048
- }(),
2056
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee41() {
2057
+ var result, mutationType, mutation;
2058
+ return regeneratorRuntime.wrap(function _callee41$(_context41) {
2059
+ while (1) {
2060
+ switch (_context41.prev = _context41.next) {
2061
+ case 0:
2062
+ if (!(!protectionOptions.numberOfProtections || protectionOptions.numberOfProtections < 2)) {
2063
+ _context41.next = 7;
2064
+ break;
2065
+ }
2066
+
2067
+ _context41.next = 3;
2068
+ return _this13.createApplicationProtection(client, applicationId, _objectSpread(_objectSpread({}, protectionOptions), {}, {
2069
+ numberOfProtections: undefined
2070
+ }), fragments);
2071
+
2072
+ case 3:
2073
+ result = _context41.sent;
2074
+
2075
+ if (result.data && result.data.createApplicationProtection) {
2076
+ result.data.protections = [result.data.createApplicationProtection];
2077
+ delete result.data.createApplicationProtection;
2078
+ }
2079
+
2080
+ _context41.next = 18;
2081
+ break;
2082
+
2083
+ case 7:
2084
+ _context41.next = 9;
2085
+ return introspection.mutation(client, 'createApplicationProtections');
2086
+
2087
+ case 9:
2088
+ mutationType = _context41.sent;
2089
+
2090
+ if (!mutationType) {
2091
+ console.error("\"Create multiple protections at once\" it's only available on Jscrambler version 7.2 and above.");
2092
+ process.exit(1);
2093
+ }
2094
+
2095
+ _context41.next = 13;
2096
+ return mutations.createApplicationProtections(applicationId, fragments, protectionOptions, mutationType.args);
2097
+
2098
+ case 13:
2099
+ mutation = _context41.sent;
2100
+ _context41.next = 16;
2101
+ return client.post('/application', mutation);
2102
+
2103
+ case 16:
2104
+ result = _context41.sent;
2105
+
2106
+ if (result.data && result.data.createApplicationProtections) {
2107
+ result.data.protections = result.data.createApplicationProtections.protections;
2108
+ delete result.data.createApplicationProtections;
2109
+ }
2110
+
2111
+ case 18:
2112
+ return _context41.abrupt("return", result);
2113
+
2114
+ case 19:
2115
+ case "end":
2116
+ return _context41.stop();
2117
+ }
2118
+ }
2119
+ }, _callee41);
2120
+ }))();
2121
+ },
2049
2122
 
2050
2123
  /**
2051
2124
  * @param {object} client
2052
2125
  * @param {string} instrumentationId
2053
2126
  * @returns {Promise<object>}
2054
2127
  */
2055
- getInstrumentation: function () {
2056
- var _ref42 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee37(client, instrumentationId) {
2057
- return regeneratorRuntime.wrap(function _callee37$(_context37) {
2128
+ getInstrumentation: function getInstrumentation(client, instrumentationId) {
2129
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee42() {
2130
+ return regeneratorRuntime.wrap(function _callee42$(_context42) {
2058
2131
  while (1) {
2059
- switch (_context37.prev = _context37.next) {
2132
+ switch (_context42.prev = _context42.next) {
2060
2133
  case 0:
2061
- return _context37.abrupt('return', client.get('/profiling-run/' + instrumentationId));
2134
+ return _context42.abrupt("return", client.get("/profiling-run/".concat(instrumentationId)));
2062
2135
 
2063
2136
  case 1:
2064
- case 'end':
2065
- return _context37.stop();
2137
+ case "end":
2138
+ return _context42.stop();
2066
2139
  }
2067
2140
  }
2068
- }, _callee37, this);
2069
- }));
2070
-
2071
- function getInstrumentation(_x102, _x103) {
2072
- return _ref42.apply(this, arguments);
2073
- }
2074
-
2075
- return getInstrumentation;
2076
- }(),
2077
-
2141
+ }, _callee42);
2142
+ }))();
2143
+ },
2078
2144
  //
2079
- getApplicationProtection: function () {
2080
- var _ref43 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee38(client, applicationId, protectionId, fragments) {
2145
+ getApplicationProtection: function getApplicationProtection(client, applicationId, protectionId, fragments) {
2146
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee43() {
2081
2147
  var query;
2082
- return regeneratorRuntime.wrap(function _callee38$(_context38) {
2148
+ return regeneratorRuntime.wrap(function _callee43$(_context43) {
2083
2149
  while (1) {
2084
- switch (_context38.prev = _context38.next) {
2150
+ switch (_context43.prev = _context43.next) {
2085
2151
  case 0:
2086
- _context38.next = 2;
2152
+ _context43.next = 2;
2087
2153
  return queries.getProtection(applicationId, protectionId, fragments);
2088
2154
 
2089
2155
  case 2:
2090
- query = _context38.sent;
2091
- return _context38.abrupt('return', client.get('/application', query));
2156
+ query = _context43.sent;
2157
+ return _context43.abrupt("return", client.get('/application', query));
2092
2158
 
2093
2159
  case 4:
2094
- case 'end':
2095
- return _context38.stop();
2160
+ case "end":
2161
+ return _context43.stop();
2096
2162
  }
2097
2163
  }
2098
- }, _callee38, this);
2099
- }));
2100
-
2101
- function getApplicationProtection(_x104, _x105, _x106, _x107) {
2102
- return _ref43.apply(this, arguments);
2103
- }
2104
-
2105
- return getApplicationProtection;
2106
- }(),
2107
-
2164
+ }, _callee43);
2165
+ }))();
2166
+ },
2108
2167
  //
2109
- downloadSourceMapsRequest: function () {
2110
- var _ref44 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee39(client, protectionId) {
2111
- return regeneratorRuntime.wrap(function _callee39$(_context39) {
2168
+ downloadSourceMapsRequest: function downloadSourceMapsRequest(client, protectionId) {
2169
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee44() {
2170
+ return regeneratorRuntime.wrap(function _callee44$(_context44) {
2112
2171
  while (1) {
2113
- switch (_context39.prev = _context39.next) {
2172
+ switch (_context44.prev = _context44.next) {
2114
2173
  case 0:
2115
- return _context39.abrupt('return', client.get('/application/sourceMaps/' + protectionId, null, false));
2174
+ return _context44.abrupt("return", client.get("/application/sourceMaps/".concat(protectionId), null, false));
2116
2175
 
2117
2176
  case 1:
2118
- case 'end':
2119
- return _context39.stop();
2177
+ case "end":
2178
+ return _context44.stop();
2120
2179
  }
2121
2180
  }
2122
- }, _callee39, this);
2123
- }));
2124
-
2125
- function downloadSourceMapsRequest(_x108, _x109) {
2126
- return _ref44.apply(this, arguments);
2127
- }
2128
-
2129
- return downloadSourceMapsRequest;
2130
- }(),
2131
- downloadSymbolTableRequest: function () {
2132
- var _ref45 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee40(client, protectionId) {
2133
- return regeneratorRuntime.wrap(function _callee40$(_context40) {
2181
+ }, _callee44);
2182
+ }))();
2183
+ },
2184
+ downloadSymbolTableRequest: function downloadSymbolTableRequest(client, protectionId) {
2185
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee45() {
2186
+ return regeneratorRuntime.wrap(function _callee45$(_context45) {
2134
2187
  while (1) {
2135
- switch (_context40.prev = _context40.next) {
2188
+ switch (_context45.prev = _context45.next) {
2136
2189
  case 0:
2137
- return _context40.abrupt('return', client.get('/application/symbolTable/' + protectionId, null, false));
2190
+ return _context45.abrupt("return", client.get("/application/symbolTable/".concat(protectionId), null, false));
2138
2191
 
2139
2192
  case 1:
2140
- case 'end':
2141
- return _context40.stop();
2193
+ case "end":
2194
+ return _context45.stop();
2142
2195
  }
2143
2196
  }
2144
- }, _callee40, this);
2145
- }));
2146
-
2147
- function downloadSymbolTableRequest(_x110, _x111) {
2148
- return _ref45.apply(this, arguments);
2149
- }
2150
-
2151
- return downloadSymbolTableRequest;
2152
- }(),
2153
-
2197
+ }, _callee45);
2198
+ }))();
2199
+ },
2154
2200
  //
2155
- downloadApplicationProtection: function () {
2156
- var _ref46 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee41(client, protectionId) {
2157
- return regeneratorRuntime.wrap(function _callee41$(_context41) {
2201
+ downloadApplicationProtection: function downloadApplicationProtection(client, protectionId) {
2202
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee46() {
2203
+ return regeneratorRuntime.wrap(function _callee46$(_context46) {
2158
2204
  while (1) {
2159
- switch (_context41.prev = _context41.next) {
2205
+ switch (_context46.prev = _context46.next) {
2160
2206
  case 0:
2161
- return _context41.abrupt('return', client.get('/application/download/' + protectionId, null, false));
2207
+ return _context46.abrupt("return", client.get("/application/download/".concat(protectionId), null, false));
2162
2208
 
2163
2209
  case 1:
2164
- case 'end':
2165
- return _context41.stop();
2210
+ case "end":
2211
+ return _context46.stop();
2166
2212
  }
2167
2213
  }
2168
- }, _callee41, this);
2169
- }));
2170
-
2171
- function downloadApplicationProtection(_x112, _x113) {
2172
- return _ref46.apply(this, arguments);
2173
- }
2174
-
2175
- return downloadApplicationProtection;
2176
- }(),
2214
+ }, _callee46);
2215
+ }))();
2216
+ },
2177
2217
 
2178
2218
  /**
2179
2219
  * @param {object} client
@@ -2181,7 +2221,7 @@ exports.default = {
2181
2221
  * @returns {*}
2182
2222
  */
2183
2223
  downloadApplicationInstrumented: function downloadApplicationInstrumented(client, instrumentationId) {
2184
- return client.get('/profiling-run/' + instrumentationId + '/instrumented-bundle', null, false);
2224
+ return client.get("/profiling-run/".concat(instrumentationId, "/instrumented-bundle"), null, false);
2185
2225
  },
2186
2226
 
2187
2227
  /**
@@ -2192,28 +2232,30 @@ exports.default = {
2192
2232
  * @param {String} field args field to introspect
2193
2233
  * @returns {Boolean} true if the field is supported, false otherwise
2194
2234
  */
2195
- introspectFieldOnMethod: function () {
2196
- var _ref47 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee42(config, queryOrMutation, methodName, field) {
2235
+ introspectFieldOnMethod: function introspectFieldOnMethod(config, queryOrMutation, methodName, field) {
2236
+ var _this14 = this;
2237
+
2238
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee47() {
2197
2239
  var instrospectionType, client, result, dataArg, isFieldSupported;
2198
- return regeneratorRuntime.wrap(function _callee42$(_context42) {
2240
+ return regeneratorRuntime.wrap(function _callee47$(_context47) {
2199
2241
  while (1) {
2200
- switch (_context42.prev = _context42.next) {
2242
+ switch (_context47.prev = _context47.next) {
2201
2243
  case 0:
2202
2244
  instrospectionType = queryOrMutation.toLowerCase() === 'mutation' ? introspection.mutation : introspection.query;
2203
- client = new this.Client(Object.assign({}, config));
2204
- _context42.next = 4;
2245
+ client = new _this14.Client(_objectSpread({}, config));
2246
+ _context47.next = 4;
2205
2247
  return instrospectionType(client, methodName);
2206
2248
 
2207
2249
  case 4:
2208
- result = _context42.sent;
2250
+ result = _context47.sent;
2209
2251
 
2210
2252
  if (!(!result || !result.args)) {
2211
- _context42.next = 8;
2253
+ _context47.next = 8;
2212
2254
  break;
2213
2255
  }
2214
2256
 
2215
- debug && console.log('Method *' + methodName + '* not found.');
2216
- return _context42.abrupt('return', false);
2257
+ debug && console.log("Method *".concat(methodName, "* not found."));
2258
+ return _context47.abrupt("return", false);
2217
2259
 
2218
2260
  case 8:
2219
2261
  dataArg = result.args.find(function (arg) {
@@ -2222,31 +2264,25 @@ exports.default = {
2222
2264
  isFieldSupported = dataArg && dataArg.type.inputFields.some(function (e) {
2223
2265
  return e.name === field;
2224
2266
  });
2225
- return _context42.abrupt('return', isFieldSupported);
2267
+ return _context47.abrupt("return", isFieldSupported);
2226
2268
 
2227
2269
  case 11:
2228
- case 'end':
2229
- return _context42.stop();
2270
+ case "end":
2271
+ return _context47.stop();
2230
2272
  }
2231
2273
  }
2232
- }, _callee42, this);
2233
- }));
2234
-
2235
- function introspectFieldOnMethod(_x114, _x115, _x116, _x117) {
2236
- return _ref47.apply(this, arguments);
2237
- }
2238
-
2239
- return introspectFieldOnMethod;
2240
- }()
2274
+ }, _callee47);
2275
+ }))();
2276
+ }
2241
2277
  };
2242
-
2278
+ exports.default = _default;
2243
2279
 
2244
2280
  function getFileFromUrl(client, url) {
2245
- return _axios2.default.get(url).then(function (res) {
2281
+ return _axios.default.get(url).then(function (res) {
2246
2282
  return {
2247
2283
  content: res.data,
2248
- filename: _path2.default.basename(url),
2249
- extension: _path2.default.extname(url).substr(1)
2284
+ filename: _path.default.basename(url),
2285
+ extension: _path.default.extname(url).substr(1)
2250
2286
  };
2251
2287
  });
2252
2288
  }