jscrambler 6.0.1 → 6.1.1

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