jscrambler 6.4.20 → 6.4.23
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/CHANGELOG.md +14 -0
- package/dist/bin/jscrambler.js +154 -202
- package/dist/cleanup-input-fields.js +7 -8
- package/dist/client.js +69 -76
- package/dist/config.js +2 -3
- package/dist/constants.js +12 -10
- package/dist/generate-signed-params.js +13 -11
- package/dist/get-protection-default-fragments.js +42 -99
- package/dist/index.js +834 -1689
- package/dist/introspection.js +50 -172
- package/dist/mutations.js +70 -82
- package/dist/queries.js +33 -32
- package/dist/utils.js +2 -2
- package/dist/zip.js +110 -197
- package/package.json +27 -25
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("core-js/modules/es.symbol.description.js");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
require("
|
|
9
|
-
require("core-js");
|
|
8
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
9
|
+
require("core-js/modules/es.promise.finally.js");
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _axios = _interopRequireDefault(require("axios"));
|
|
12
12
|
var _lodash = _interopRequireDefault(require("lodash.defaults"));
|
|
13
|
-
var
|
|
13
|
+
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
14
14
|
var _config2 = _interopRequireDefault(require("./config"));
|
|
15
15
|
var _generateSignedParams = _interopRequireDefault(require("./generate-signed-params"));
|
|
16
16
|
var _client = _interopRequireDefault(require("./client"));
|
|
@@ -21,27 +21,23 @@ var _zip = require("./zip");
|
|
|
21
21
|
var introspection = _interopRequireWildcard(require("./introspection"));
|
|
22
22
|
var _utils = require("./utils");
|
|
23
23
|
var _getProtectionDefaultFragments = _interopRequireDefault(require("./get-protection-default-fragments"));
|
|
24
|
-
function _getRequireWildcardCache(
|
|
25
|
-
function _interopRequireWildcard(
|
|
24
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
function
|
|
28
|
-
function
|
|
29
|
-
function
|
|
30
|
-
function
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var APP_URL = 'https://app.jscrambler.com';
|
|
42
|
-
var POLLING_MIN_INTERVAL = 1000;
|
|
43
|
-
var POLLING_MAX_INTERVAL = 10000;
|
|
44
|
-
var INCREASE_POLL_INTERVAL_EVERY = 30000;
|
|
27
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
29
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
31
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable no-console */
|
|
32
|
+
const {
|
|
33
|
+
intoObjectType
|
|
34
|
+
} = introspection;
|
|
35
|
+
const debug = !!process.env.DEBUG;
|
|
36
|
+
const APP_URL = 'https://app.jscrambler.com';
|
|
37
|
+
const POLLING_MIN_INTERVAL = 1000;
|
|
38
|
+
const POLLING_MAX_INTERVAL = 10000;
|
|
39
|
+
const INCREASE_POLL_INTERVAL_EVERY = 30000;
|
|
40
|
+
const MAX_PRINTED_ERRORS = 3;
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* Calculate polling interval for protection and instrumentation.
|
|
@@ -50,19 +46,17 @@ var INCREASE_POLL_INTERVAL_EVERY = 30000;
|
|
|
50
46
|
* @returns {number|number}
|
|
51
47
|
*/
|
|
52
48
|
function getPollingInterval(start) {
|
|
53
|
-
|
|
49
|
+
const pollingInterval = POLLING_MIN_INTERVAL * Math.ceil((Date.now() - start) / INCREASE_POLL_INTERVAL_EVERY);
|
|
54
50
|
return pollingInterval >= POLLING_MAX_INTERVAL ? POLLING_MAX_INTERVAL : pollingInterval;
|
|
55
51
|
}
|
|
56
52
|
function errorHandler(res) {
|
|
57
53
|
if (res.errors && res.errors.length) {
|
|
58
|
-
res.errors.forEach(
|
|
54
|
+
res.errors.forEach(error => {
|
|
59
55
|
throw new Error("Error: ".concat(error.message));
|
|
60
56
|
});
|
|
61
57
|
}
|
|
62
58
|
if (res.data && res.data.errors) {
|
|
63
|
-
res.data.errors.forEach(
|
|
64
|
-
return console.error(e.message);
|
|
65
|
-
});
|
|
59
|
+
res.data.errors.forEach(e => console.error(e.message));
|
|
66
60
|
throw new Error('GraphQL Query Error');
|
|
67
61
|
}
|
|
68
62
|
if (res.message) {
|
|
@@ -71,17 +65,28 @@ function errorHandler(res) {
|
|
|
71
65
|
return res;
|
|
72
66
|
}
|
|
73
67
|
function printSourcesErrors(errors) {
|
|
74
|
-
console.error('
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
console.error('Source errors:');
|
|
69
|
+
for (let i = 0; i < Math.min(MAX_PRINTED_ERRORS, errors.length); i++) {
|
|
70
|
+
let sourceErrorsMessage = errors[i].line ? ':' + errors[i].line + ':' + errors[i].column + ': ' : ': ';
|
|
71
|
+
console.error('- ' + errors[i].filename + sourceErrorsMessage + errors[i].message);
|
|
72
|
+
}
|
|
73
|
+
const errorsLeft = errors.length - MAX_PRINTED_ERRORS;
|
|
74
|
+
if (errorsLeft > 0) {
|
|
75
|
+
if (errorsLeft === 1) {
|
|
76
|
+
console.error('There is 1 more error.');
|
|
77
|
+
} else {
|
|
78
|
+
console.error('There are ' + errorsLeft + ' more errors.');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
console.error();
|
|
77
82
|
}
|
|
78
83
|
function normalizeParameters(parameters) {
|
|
79
|
-
|
|
84
|
+
let result;
|
|
80
85
|
if (!Array.isArray(parameters)) {
|
|
81
86
|
result = [];
|
|
82
|
-
Object.keys(parameters).forEach(
|
|
87
|
+
Object.keys(parameters).forEach(name => {
|
|
83
88
|
result.push({
|
|
84
|
-
name
|
|
89
|
+
name,
|
|
85
90
|
options: parameters[name]
|
|
86
91
|
});
|
|
87
92
|
});
|
|
@@ -91,13 +96,13 @@ function normalizeParameters(parameters) {
|
|
|
91
96
|
return result;
|
|
92
97
|
}
|
|
93
98
|
function buildFinalConfig(configPathOrObject) {
|
|
94
|
-
|
|
99
|
+
const _config = typeof configPathOrObject === 'string' ? require(configPathOrObject) : configPathOrObject;
|
|
95
100
|
return (0, _lodash.default)(_config, _config2.default);
|
|
96
101
|
}
|
|
97
|
-
var _default = {
|
|
102
|
+
var _default = exports.default = {
|
|
98
103
|
Client: _client.default,
|
|
99
104
|
config: _config2.default,
|
|
100
|
-
queries
|
|
105
|
+
queries,
|
|
101
106
|
generateSignedParams: _generateSignedParams.default,
|
|
102
107
|
/**
|
|
103
108
|
* Remove and Add application sources
|
|
@@ -111,103 +116,62 @@ var _default = {
|
|
|
111
116
|
* }} opts
|
|
112
117
|
* @returns {Promise<{extension: string, filename: string, content: *}>}
|
|
113
118
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
zipped = _context.sent;
|
|
158
|
-
_context.next = 22;
|
|
159
|
-
break;
|
|
160
|
-
case 17:
|
|
161
|
-
if (!sources) {
|
|
162
|
-
_context.next = 22;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
if (debug) {
|
|
166
|
-
console.log('Creating zip from sources');
|
|
167
|
-
}
|
|
168
|
-
_context.next = 21;
|
|
169
|
-
return (0, _zip.zipSources)(sources);
|
|
170
|
-
case 21:
|
|
171
|
-
zipped = _context.sent;
|
|
172
|
-
case 22:
|
|
173
|
-
if (!zipped) {
|
|
174
|
-
_context.next = 33;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
_context.next = 25;
|
|
178
|
-
return zipped.generateAsync({
|
|
179
|
-
type: 'base64',
|
|
180
|
-
compression: 'DEFLATE',
|
|
181
|
-
compressionOptions: {
|
|
182
|
-
// 1 - 9 (max compression)
|
|
183
|
-
level: 5
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
case 25:
|
|
187
|
-
content = _context.sent;
|
|
188
|
-
if (debug) {
|
|
189
|
-
console.log('Adding sources to application');
|
|
190
|
-
}
|
|
191
|
-
source = {
|
|
192
|
-
content: content,
|
|
193
|
-
filename: 'application.zip',
|
|
194
|
-
extension: 'zip'
|
|
195
|
-
};
|
|
196
|
-
_context.t0 = errorHandler;
|
|
197
|
-
_context.next = 31;
|
|
198
|
-
return _this.addApplicationSource(client, applicationId, source);
|
|
199
|
-
case 31:
|
|
200
|
-
_context.t1 = _context.sent;
|
|
201
|
-
(0, _context.t0)(_context.t1);
|
|
202
|
-
case 33:
|
|
203
|
-
return _context.abrupt("return", source);
|
|
204
|
-
case 34:
|
|
205
|
-
case "end":
|
|
206
|
-
return _context.stop();
|
|
207
|
-
}
|
|
119
|
+
async updateApplicationSources(client, applicationId, _ref) {
|
|
120
|
+
let {
|
|
121
|
+
sources,
|
|
122
|
+
filesSrc,
|
|
123
|
+
cwd,
|
|
124
|
+
appProfiling
|
|
125
|
+
} = _ref;
|
|
126
|
+
if (sources || filesSrc && filesSrc.length) {
|
|
127
|
+
// prevent removing sources if profiling state is READY
|
|
128
|
+
if (appProfiling && appProfiling.data && appProfiling.data.state === 'READY') {
|
|
129
|
+
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*.');
|
|
130
|
+
}
|
|
131
|
+
const removeSourceRes = await this.removeSourceFromApplication(client, '', applicationId);
|
|
132
|
+
errorHandler(removeSourceRes);
|
|
133
|
+
}
|
|
134
|
+
let zipped;
|
|
135
|
+
let source;
|
|
136
|
+
if (filesSrc && filesSrc.length) {
|
|
137
|
+
let _filesSrc = [];
|
|
138
|
+
for (let i = 0, l = filesSrc.length; i < l; i += 1) {
|
|
139
|
+
if (typeof filesSrc[i] === 'string') {
|
|
140
|
+
_filesSrc = _filesSrc.concat((0, _utils.getMatchedFiles)(filesSrc[i]));
|
|
141
|
+
} else {
|
|
142
|
+
_filesSrc.push(filesSrc[i]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (debug) {
|
|
146
|
+
console.log('Creating zip from source files');
|
|
147
|
+
}
|
|
148
|
+
zipped = await (0, _zip.zip)(_filesSrc, cwd);
|
|
149
|
+
} else if (sources) {
|
|
150
|
+
if (debug) {
|
|
151
|
+
console.log('Creating zip from sources');
|
|
152
|
+
}
|
|
153
|
+
zipped = await (0, _zip.zipSources)(sources);
|
|
154
|
+
}
|
|
155
|
+
if (zipped) {
|
|
156
|
+
const content = await zipped.generateAsync({
|
|
157
|
+
type: 'base64',
|
|
158
|
+
compression: 'DEFLATE',
|
|
159
|
+
compressionOptions: {
|
|
160
|
+
// 1 - 9 (max compression)
|
|
161
|
+
level: 5
|
|
208
162
|
}
|
|
209
|
-
}
|
|
210
|
-
|
|
163
|
+
});
|
|
164
|
+
if (debug) {
|
|
165
|
+
console.log('Adding sources to application');
|
|
166
|
+
}
|
|
167
|
+
source = {
|
|
168
|
+
content,
|
|
169
|
+
filename: 'application.zip',
|
|
170
|
+
extension: 'zip'
|
|
171
|
+
};
|
|
172
|
+
errorHandler(await this.addApplicationSource(client, applicationId, source));
|
|
173
|
+
}
|
|
174
|
+
return source;
|
|
211
175
|
},
|
|
212
176
|
// This method is a shortcut method that accepts an object with everything needed
|
|
213
177
|
// for the entire process of requesting an application protection and downloading
|
|
@@ -252,379 +216,275 @@ var _default = {
|
|
|
252
216
|
// endpoint than the default one, useful if you're running an enterprise version of
|
|
253
217
|
// Jscrambler or if you're provided access to beta features of our product.
|
|
254
218
|
//
|
|
255
|
-
|
|
256
|
-
var
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
219
|
+
async protectAndDownload(configPathOrObject, destCallback) {
|
|
220
|
+
var _this = this;
|
|
221
|
+
const start = Date.now();
|
|
222
|
+
const finalConfig = buildFinalConfig(configPathOrObject);
|
|
223
|
+
const {
|
|
224
|
+
applicationId,
|
|
225
|
+
host,
|
|
226
|
+
port,
|
|
227
|
+
basePath,
|
|
228
|
+
protocol,
|
|
229
|
+
cafile,
|
|
230
|
+
keys,
|
|
231
|
+
sources,
|
|
232
|
+
stream = true,
|
|
233
|
+
cwd,
|
|
234
|
+
params,
|
|
235
|
+
applicationTypes,
|
|
236
|
+
languageSpecifications,
|
|
237
|
+
sourceMaps,
|
|
238
|
+
randomizationSeed,
|
|
239
|
+
areSubscribersOrdered,
|
|
240
|
+
useRecommendedOrder,
|
|
241
|
+
bail = true,
|
|
242
|
+
jscramblerVersion,
|
|
243
|
+
debugMode,
|
|
244
|
+
proxy,
|
|
245
|
+
utc,
|
|
246
|
+
clientId,
|
|
247
|
+
tolerateMinification,
|
|
248
|
+
codeHardeningThreshold,
|
|
249
|
+
useProfilingData,
|
|
250
|
+
browsers,
|
|
251
|
+
useAppClassification,
|
|
252
|
+
profilingDataMode,
|
|
253
|
+
removeProfilingData,
|
|
254
|
+
skipSources,
|
|
255
|
+
inputSymbolTable,
|
|
256
|
+
entryPoint,
|
|
257
|
+
excludeList,
|
|
258
|
+
numberOfProtections,
|
|
259
|
+
ensureCodeAnnotation,
|
|
260
|
+
forceAppEnvironment
|
|
261
|
+
} = finalConfig;
|
|
262
|
+
const {
|
|
263
|
+
accessKey,
|
|
264
|
+
secretKey
|
|
265
|
+
} = keys;
|
|
266
|
+
const client = new this.Client({
|
|
267
|
+
accessKey,
|
|
268
|
+
secretKey,
|
|
269
|
+
host,
|
|
270
|
+
port,
|
|
271
|
+
basePath,
|
|
272
|
+
protocol,
|
|
273
|
+
cafile,
|
|
274
|
+
jscramblerVersion,
|
|
275
|
+
proxy,
|
|
276
|
+
utc,
|
|
277
|
+
clientId
|
|
278
|
+
});
|
|
279
|
+
let filesSrc = finalConfig.filesSrc;
|
|
280
|
+
let filesDest = finalConfig.filesDest;
|
|
281
|
+
if (sources) {
|
|
282
|
+
filesSrc = undefined;
|
|
283
|
+
}
|
|
284
|
+
if (destCallback) {
|
|
285
|
+
filesDest = undefined;
|
|
286
|
+
}
|
|
287
|
+
if (!applicationId) {
|
|
288
|
+
throw new Error('Required *applicationId* not provided');
|
|
289
|
+
}
|
|
290
|
+
if (!filesDest && !destCallback) {
|
|
291
|
+
throw new Error('Required *filesDest* not provided');
|
|
292
|
+
}
|
|
293
|
+
let source;
|
|
294
|
+
if (!skipSources) {
|
|
295
|
+
const appProfiling = await this.getApplicationProfiling(client, applicationId).catch(e => {
|
|
296
|
+
if (typeof profilingDataMode === 'string' && profilingDataMode !== 'off') {
|
|
297
|
+
switch (e.statusCode) {
|
|
298
|
+
case _constants.HTTP_STATUS_CODES.FORBIDDEN:
|
|
299
|
+
throw new Error("No ".concat(profilingDataMode, " profiling feature in your plan. Please set profilingDataMode to \"off\" or contact the Jscrambler Support."));
|
|
300
|
+
case _constants.HTTP_STATUS_CODES.NOT_FOUND:
|
|
301
|
+
if (profilingDataMode === 'automatic') {
|
|
302
|
+
throw new Error('You can not use the automatic mode without previous profiling having been done.');
|
|
327
303
|
}
|
|
328
|
-
_context4.next = 20;
|
|
329
|
-
return _this2.deleteProfiling(client, appProfiling.data.id);
|
|
330
|
-
case 20:
|
|
331
|
-
appProfiling.data.state = 'DELETED';
|
|
332
|
-
case 21:
|
|
333
|
-
_context4.next = 23;
|
|
334
|
-
return _this2.updateApplicationSources(client, applicationId, {
|
|
335
|
-
sources: sources,
|
|
336
|
-
filesSrc: filesSrc,
|
|
337
|
-
cwd: cwd,
|
|
338
|
-
appProfiling: appProfiling
|
|
339
|
-
});
|
|
340
|
-
case 23:
|
|
341
|
-
source = _context4.sent;
|
|
342
|
-
_context4.next = 27;
|
|
343
304
|
break;
|
|
344
|
-
case
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
updateData = {
|
|
348
|
-
debugMode: !!debugMode,
|
|
349
|
-
tolerateMinification: tolerateMinification,
|
|
350
|
-
codeHardeningThreshold: codeHardeningThreshold
|
|
351
|
-
};
|
|
352
|
-
if (params && Object.keys(params).length) {
|
|
353
|
-
updateData.parameters = normalizeParameters(params);
|
|
354
|
-
updateData.areSubscribersOrdered = Array.isArray(params);
|
|
355
|
-
}
|
|
356
|
-
dataToValidate = {
|
|
357
|
-
applicationTypes: applicationTypes,
|
|
358
|
-
areSubscribersOrdered: areSubscribersOrdered,
|
|
359
|
-
browsers: browsers,
|
|
360
|
-
languageSpecifications: languageSpecifications,
|
|
361
|
-
profilingDataMode: profilingDataMode,
|
|
362
|
-
sourceMaps: sourceMaps,
|
|
363
|
-
useAppClassification: useAppClassification,
|
|
364
|
-
ensureCodeAnnotation: ensureCodeAnnotation,
|
|
365
|
-
useProfilingData: useProfilingData,
|
|
366
|
-
useRecommendedOrder: useRecommendedOrder
|
|
367
|
-
};
|
|
368
|
-
for (prop in dataToValidate) {
|
|
369
|
-
value = dataToValidate[prop];
|
|
370
|
-
if (typeof value !== 'undefined') {
|
|
371
|
-
updateData[prop] = value;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
if (!(updateData.parameters || updateData.applicationTypes || updateData.languageSpecifications || updateData.browsers || typeof updateData.areSubscribersOrdered !== 'undefined')) {
|
|
375
|
-
_context4.next = 41;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
if (debug) {
|
|
379
|
-
console.log('Updating parameters of protection');
|
|
380
|
-
}
|
|
381
|
-
_context4.next = 35;
|
|
382
|
-
return intoObjectType(client, updateData, 'ApplicationUpdate');
|
|
383
|
-
case 35:
|
|
384
|
-
applicationUpdate = _context4.sent;
|
|
385
|
-
_context4.next = 38;
|
|
386
|
-
return _this2.updateApplication(client, applicationUpdate, undefined, applicationId);
|
|
387
|
-
case 38:
|
|
388
|
-
updateApplicationRes = _context4.sent;
|
|
389
|
-
if (debug) {
|
|
390
|
-
console.log('Finished updating parameters of protection');
|
|
391
|
-
console.error(updateApplicationRes);
|
|
305
|
+
case _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE:
|
|
306
|
+
if (profilingDataMode === 'automatic') {
|
|
307
|
+
throw e;
|
|
392
308
|
}
|
|
393
|
-
errorHandler(updateApplicationRes);
|
|
394
|
-
case 41:
|
|
395
|
-
if (debug) {
|
|
396
|
-
console.log('Creating Application Protection');
|
|
397
|
-
}
|
|
398
|
-
protectionOptions = _objectSpread(_objectSpread({}, updateData), {}, {
|
|
399
|
-
bail: bail,
|
|
400
|
-
entryPoint: entryPoint,
|
|
401
|
-
excludeList: excludeList,
|
|
402
|
-
inputSymbolTable: inputSymbolTable,
|
|
403
|
-
randomizationSeed: randomizationSeed,
|
|
404
|
-
source: source,
|
|
405
|
-
tolerateMinification: tolerateMinification,
|
|
406
|
-
numberOfProtections: numberOfProtections,
|
|
407
|
-
forceAppEnvironment: forceAppEnvironment
|
|
408
|
-
});
|
|
409
|
-
if (finalConfig.inputSymbolTable) {
|
|
410
|
-
// Note: we can not use the fs.promises API because some users may not have node 10.
|
|
411
|
-
// Once node 10 is old enough to be safe to assume that all users will have it, this
|
|
412
|
-
// should be safe to replace with `await fs.promises.readFile`.
|
|
413
|
-
inputSymbolTableContents = _fs.default.readFileSync(finalConfig.inputSymbolTable, 'utf-8');
|
|
414
|
-
protectionOptions.inputSymbolTable = inputSymbolTableContents;
|
|
415
|
-
}
|
|
416
|
-
_context4.next = 46;
|
|
417
|
-
return _this2.createApplicationProtections(client, applicationId, protectionOptions);
|
|
418
|
-
case 46:
|
|
419
|
-
createApplicationProtectionRes = _context4.sent;
|
|
420
|
-
errorHandler(createApplicationProtectionRes);
|
|
421
|
-
protectionIds = createApplicationProtectionRes.data.protections.map(function (_ref2) {
|
|
422
|
-
var _id = _ref2._id;
|
|
423
|
-
return _id;
|
|
424
|
-
});
|
|
425
|
-
onExitCancelProtection = /*#__PURE__*/function () {
|
|
426
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
427
|
-
var i, protectionId;
|
|
428
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
429
|
-
while (1) {
|
|
430
|
-
switch (_context2.prev = _context2.next) {
|
|
431
|
-
case 0:
|
|
432
|
-
i = 0;
|
|
433
|
-
case 1:
|
|
434
|
-
if (!(i < protectionIds.length)) {
|
|
435
|
-
_context2.next = 15;
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
protectionId = protectionIds[i];
|
|
439
|
-
_context2.prev = 3;
|
|
440
|
-
_context2.next = 6;
|
|
441
|
-
return _this2.cancelProtection(client, protectionId, applicationId);
|
|
442
|
-
case 6:
|
|
443
|
-
console.log('** Protection %s WAS CANCELLED **', protectionId);
|
|
444
|
-
_context2.next = 12;
|
|
445
|
-
break;
|
|
446
|
-
case 9:
|
|
447
|
-
_context2.prev = 9;
|
|
448
|
-
_context2.t0 = _context2["catch"](3);
|
|
449
|
-
if (debug) {
|
|
450
|
-
console.error(_context2.t0);
|
|
451
|
-
}
|
|
452
|
-
case 12:
|
|
453
|
-
i++;
|
|
454
|
-
_context2.next = 1;
|
|
455
|
-
break;
|
|
456
|
-
case 15:
|
|
457
|
-
process.exit(1);
|
|
458
|
-
case 16:
|
|
459
|
-
case "end":
|
|
460
|
-
return _context2.stop();
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}, _callee2, null, [[3, 9]]);
|
|
464
|
-
}));
|
|
465
|
-
return function onExitCancelProtection() {
|
|
466
|
-
return _ref3.apply(this, arguments);
|
|
467
|
-
};
|
|
468
|
-
}();
|
|
469
|
-
process.once('SIGINT', onExitCancelProtection).once('SIGTERM', onExitCancelProtection);
|
|
470
|
-
_context4.t0 = _this2;
|
|
471
|
-
_context4.t1 = client;
|
|
472
|
-
_context4.t2 = applicationId;
|
|
473
|
-
_context4.t3 = protectionIds;
|
|
474
|
-
_context4.next = 57;
|
|
475
|
-
return (0, _getProtectionDefaultFragments.default)(client);
|
|
476
|
-
case 57:
|
|
477
|
-
_context4.t4 = _context4.sent;
|
|
478
|
-
_context4.next = 60;
|
|
479
|
-
return _context4.t0.pollProtections.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
|
|
480
|
-
case 60:
|
|
481
|
-
processedProtections = _context4.sent;
|
|
482
|
-
process.removeListener('SIGINT', onExitCancelProtection).removeListener('SIGTERM', onExitCancelProtection);
|
|
483
|
-
handleProtection = /*#__PURE__*/function () {
|
|
484
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(protection) {
|
|
485
|
-
var _ref5,
|
|
486
|
-
_ref5$outPrefix,
|
|
487
|
-
outPrefix,
|
|
488
|
-
_ref5$printProtection,
|
|
489
|
-
printProtectionId,
|
|
490
|
-
sourcesErrors,
|
|
491
|
-
download,
|
|
492
|
-
_args3 = arguments;
|
|
493
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
494
|
-
while (1) {
|
|
495
|
-
switch (_context3.prev = _context3.next) {
|
|
496
|
-
case 0:
|
|
497
|
-
_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;
|
|
498
|
-
if (protection.growthWarning) {
|
|
499
|
-
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, "."));
|
|
500
|
-
}
|
|
501
|
-
if (protection.hasForcedDateLock) {
|
|
502
|
-
console.warn("Warning: Since your plan is a Trial, your protected files will stop working on ".concat(protection.parameters.find(function (p) {
|
|
503
|
-
return p.name === 'dateLock' && p.options.endDate;
|
|
504
|
-
}).options.endDate));
|
|
505
|
-
}
|
|
506
|
-
if (debug) {
|
|
507
|
-
console.log('Finished protecting');
|
|
508
|
-
}
|
|
509
|
-
if (protection.deprecations) {
|
|
510
|
-
protection.deprecations.forEach(function (deprecation) {
|
|
511
|
-
if (deprecation.type === 'Transformation') {
|
|
512
|
-
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is no longer maintained. Please consider removing it from your configuration."));
|
|
513
|
-
} else if (deprecation.type && deprecation.entity) {
|
|
514
|
-
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is deprecated."));
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
sourcesErrors = [];
|
|
519
|
-
protection.sources.forEach(function (s) {
|
|
520
|
-
if (s.isSource && s.errorMessages && s.errorMessages.length > 0) {
|
|
521
|
-
sourcesErrors.push.apply(sourcesErrors, _toConsumableArray(s.errorMessages.map(function (e) {
|
|
522
|
-
return _objectSpread({
|
|
523
|
-
filename: s.filename
|
|
524
|
-
}, e);
|
|
525
|
-
})));
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
if (!(protection.state === 'errored')) {
|
|
529
|
-
_context3.next = 15;
|
|
530
|
-
break;
|
|
531
|
-
}
|
|
532
|
-
console.error('Global protection errors:');
|
|
533
|
-
console.error("- ".concat(protection.errorMessage));
|
|
534
|
-
console.error('');
|
|
535
|
-
if (sourcesErrors.length > 0) {
|
|
536
|
-
printSourcesErrors(sourcesErrors);
|
|
537
|
-
}
|
|
538
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
539
|
-
case 15:
|
|
540
|
-
if (!(sourcesErrors.length > 0)) {
|
|
541
|
-
_context3.next = 22;
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
if (!protection.bail) {
|
|
545
|
-
_context3.next = 21;
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
printSourcesErrors(sourcesErrors);
|
|
549
|
-
throw new Error('Your protection has failed.');
|
|
550
|
-
case 21:
|
|
551
|
-
sourcesErrors.forEach(function (e) {
|
|
552
|
-
return console.warn("Non-fatal error: \"".concat(e.message, "\" in ").concat(e.filename));
|
|
553
|
-
});
|
|
554
|
-
case 22:
|
|
555
|
-
if (debug) {
|
|
556
|
-
console.log('Downloading protection result');
|
|
557
|
-
}
|
|
558
|
-
_context3.next = 25;
|
|
559
|
-
return _this2.downloadApplicationProtection(client, protection._id);
|
|
560
|
-
case 25:
|
|
561
|
-
download = _context3.sent;
|
|
562
|
-
errorHandler(download);
|
|
563
|
-
if (debug) {
|
|
564
|
-
console.log('Unzipping files');
|
|
565
|
-
}
|
|
566
|
-
_context3.next = 30;
|
|
567
|
-
return (0, _zip.unzip)(download, (filesDest ? "".concat(filesDest).concat(outPrefix) : filesDest) || destCallback, stream);
|
|
568
|
-
case 30:
|
|
569
|
-
if (debug) {
|
|
570
|
-
console.log('Finished unzipping files');
|
|
571
|
-
}
|
|
572
|
-
if (printProtectionId) {
|
|
573
|
-
console.log(protection._id);
|
|
574
|
-
}
|
|
575
|
-
return _context3.abrupt("return", protection._id);
|
|
576
|
-
case 33:
|
|
577
|
-
case "end":
|
|
578
|
-
return _context3.stop();
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}, _callee3);
|
|
582
|
-
}));
|
|
583
|
-
return function handleProtection(_x) {
|
|
584
|
-
return _ref4.apply(this, arguments);
|
|
585
|
-
};
|
|
586
|
-
}();
|
|
587
|
-
if (!(processedProtections.length === 1)) {
|
|
588
|
-
_context4.next = 65;
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
return _context4.abrupt("return", handleProtection(processedProtections[0]));
|
|
592
|
-
case 65:
|
|
593
|
-
console.log("Protections stored in ".concat(filesDest, "/[protection-id]"));
|
|
594
|
-
i = 0;
|
|
595
|
-
case 67:
|
|
596
|
-
if (!(i < processedProtections.length)) {
|
|
597
|
-
_context4.next = 80;
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
protection = processedProtections[i];
|
|
601
|
-
_context4.prev = 69;
|
|
602
|
-
_context4.next = 72;
|
|
603
|
-
return handleProtection(protection, {
|
|
604
|
-
outPrefix: "/".concat(protection._id, "/"),
|
|
605
|
-
printProtectionId: false
|
|
606
|
-
});
|
|
607
|
-
case 72:
|
|
608
|
-
_context4.next = 77;
|
|
609
|
-
break;
|
|
610
|
-
case 74:
|
|
611
|
-
_context4.prev = 74;
|
|
612
|
-
_context4.t5 = _context4["catch"](69);
|
|
613
|
-
console.error(_context4.t5);
|
|
614
|
-
case 77:
|
|
615
|
-
i++;
|
|
616
|
-
_context4.next = 67;
|
|
617
|
-
break;
|
|
618
|
-
case 80:
|
|
619
|
-
console.log("Runtime: ".concat(processedProtections.length, " protections in ").concat(Math.round((Date.now() - start) / 1000), "s"));
|
|
620
|
-
return _context4.abrupt("return", protectionIds);
|
|
621
|
-
case 82:
|
|
622
|
-
case "end":
|
|
623
|
-
return _context4.stop();
|
|
624
309
|
}
|
|
625
310
|
}
|
|
626
|
-
}
|
|
627
|
-
|
|
311
|
+
});
|
|
312
|
+
if (appProfiling && removeProfilingData) {
|
|
313
|
+
await this.deleteProfiling(client, appProfiling.data.id);
|
|
314
|
+
appProfiling.data.state = 'DELETED';
|
|
315
|
+
}
|
|
316
|
+
source = await this.updateApplicationSources(client, applicationId, {
|
|
317
|
+
sources,
|
|
318
|
+
filesSrc,
|
|
319
|
+
cwd,
|
|
320
|
+
appProfiling
|
|
321
|
+
});
|
|
322
|
+
} else {
|
|
323
|
+
console.log('Update source files SKIPPED');
|
|
324
|
+
}
|
|
325
|
+
const updateData = {
|
|
326
|
+
debugMode: !!debugMode,
|
|
327
|
+
tolerateMinification,
|
|
328
|
+
codeHardeningThreshold
|
|
329
|
+
};
|
|
330
|
+
if (params && Object.keys(params).length) {
|
|
331
|
+
updateData.parameters = normalizeParameters(params);
|
|
332
|
+
updateData.areSubscribersOrdered = Array.isArray(params);
|
|
333
|
+
}
|
|
334
|
+
const dataToValidate = {
|
|
335
|
+
applicationTypes,
|
|
336
|
+
areSubscribersOrdered,
|
|
337
|
+
browsers,
|
|
338
|
+
languageSpecifications,
|
|
339
|
+
profilingDataMode,
|
|
340
|
+
sourceMaps,
|
|
341
|
+
useAppClassification,
|
|
342
|
+
ensureCodeAnnotation,
|
|
343
|
+
useProfilingData,
|
|
344
|
+
useRecommendedOrder
|
|
345
|
+
};
|
|
346
|
+
for (const prop in dataToValidate) {
|
|
347
|
+
const value = dataToValidate[prop];
|
|
348
|
+
if (typeof value !== 'undefined') {
|
|
349
|
+
updateData[prop] = value;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (updateData.parameters || updateData.applicationTypes || updateData.languageSpecifications || updateData.browsers || typeof updateData.areSubscribersOrdered !== 'undefined') {
|
|
353
|
+
if (debug) {
|
|
354
|
+
console.log('Updating parameters of protection');
|
|
355
|
+
}
|
|
356
|
+
const applicationUpdate = await intoObjectType(client, updateData, 'ApplicationUpdate');
|
|
357
|
+
const updateApplicationRes = await this.updateApplication(client, applicationUpdate, undefined, applicationId);
|
|
358
|
+
if (debug) {
|
|
359
|
+
console.log('Finished updating parameters of protection');
|
|
360
|
+
console.error(updateApplicationRes);
|
|
361
|
+
}
|
|
362
|
+
errorHandler(updateApplicationRes);
|
|
363
|
+
}
|
|
364
|
+
if (debug) {
|
|
365
|
+
console.log('Creating Application Protection');
|
|
366
|
+
}
|
|
367
|
+
const protectionOptions = _objectSpread(_objectSpread({}, updateData), {}, {
|
|
368
|
+
bail,
|
|
369
|
+
entryPoint,
|
|
370
|
+
excludeList,
|
|
371
|
+
inputSymbolTable,
|
|
372
|
+
randomizationSeed,
|
|
373
|
+
source,
|
|
374
|
+
tolerateMinification,
|
|
375
|
+
numberOfProtections,
|
|
376
|
+
forceAppEnvironment
|
|
377
|
+
});
|
|
378
|
+
if (finalConfig.inputSymbolTable) {
|
|
379
|
+
const inputSymbolTableContents = await _promises.default.readFile(finalConfig.inputSymbolTable, 'utf-8');
|
|
380
|
+
protectionOptions.inputSymbolTable = inputSymbolTableContents;
|
|
381
|
+
}
|
|
382
|
+
const createApplicationProtectionRes = await this.createApplicationProtections(client, applicationId, protectionOptions);
|
|
383
|
+
errorHandler(createApplicationProtectionRes);
|
|
384
|
+
const protectionIds = createApplicationProtectionRes.data.protections.map(_ref2 => {
|
|
385
|
+
let {
|
|
386
|
+
_id
|
|
387
|
+
} = _ref2;
|
|
388
|
+
return _id;
|
|
389
|
+
});
|
|
390
|
+
const onExitCancelProtection = async () => {
|
|
391
|
+
for (let i = 0; i < protectionIds.length; i++) {
|
|
392
|
+
const protectionId = protectionIds[i];
|
|
393
|
+
try {
|
|
394
|
+
await this.cancelProtection(client, protectionId, applicationId);
|
|
395
|
+
console.log('** Protection %s WAS CANCELLED **', protectionId);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
if (debug) {
|
|
398
|
+
console.error(e);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
process.exit(1);
|
|
403
|
+
};
|
|
404
|
+
process.once('SIGINT', onExitCancelProtection).once('SIGTERM', onExitCancelProtection);
|
|
405
|
+
const processedProtections = await this.pollProtections(client, applicationId, protectionIds, await (0, _getProtectionDefaultFragments.default)(client));
|
|
406
|
+
process.removeListener('SIGINT', onExitCancelProtection).removeListener('SIGTERM', onExitCancelProtection);
|
|
407
|
+
const handleProtection = async function (protection) {
|
|
408
|
+
let {
|
|
409
|
+
outPrefix = '',
|
|
410
|
+
printProtectionId = true
|
|
411
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
412
|
+
if (protection.growthWarning) {
|
|
413
|
+
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, "."));
|
|
414
|
+
}
|
|
415
|
+
if (protection.hasForcedDateLock) {
|
|
416
|
+
console.warn("Warning: Since your plan is a Trial, your protected files will stop working on ".concat(protection.parameters.find(p => p.name === 'dateLock' && p.options.endDate).options.endDate));
|
|
417
|
+
}
|
|
418
|
+
if (debug) {
|
|
419
|
+
console.log('Finished protecting');
|
|
420
|
+
}
|
|
421
|
+
if (protection.deprecations) {
|
|
422
|
+
protection.deprecations.forEach(deprecation => {
|
|
423
|
+
if (deprecation.type === 'Transformation') {
|
|
424
|
+
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is no longer maintained. Please consider removing it from your configuration."));
|
|
425
|
+
} else if (deprecation.type && deprecation.entity) {
|
|
426
|
+
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is deprecated."));
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
const sourcesErrors = [];
|
|
431
|
+
protection.sources.forEach(s => {
|
|
432
|
+
if (s.isSource && s.errorMessages && s.errorMessages.length > 0) {
|
|
433
|
+
sourcesErrors.push(...s.errorMessages.map(e => _objectSpread({
|
|
434
|
+
filename: s.filename
|
|
435
|
+
}, e)));
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
if (protection.state === 'errored') {
|
|
439
|
+
console.error('Global protection errors:');
|
|
440
|
+
console.error("- ".concat(protection.errorMessage));
|
|
441
|
+
console.error('');
|
|
442
|
+
if (sourcesErrors.length > 0) {
|
|
443
|
+
printSourcesErrors(sourcesErrors);
|
|
444
|
+
}
|
|
445
|
+
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
446
|
+
} else if (sourcesErrors.length > 0) {
|
|
447
|
+
if (protection.bail) {
|
|
448
|
+
printSourcesErrors(sourcesErrors);
|
|
449
|
+
throw new Error('Your protection has failed.');
|
|
450
|
+
} else {
|
|
451
|
+
sourcesErrors.forEach(e => console.warn("Non-fatal error: \"".concat(e.message, "\" in ").concat(e.filename)));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (debug) {
|
|
455
|
+
console.log('Downloading protection result');
|
|
456
|
+
}
|
|
457
|
+
const download = await _this.downloadApplicationProtection(client, protection._id);
|
|
458
|
+
errorHandler(download);
|
|
459
|
+
if (debug) {
|
|
460
|
+
console.log('Unzipping files');
|
|
461
|
+
}
|
|
462
|
+
await (0, _zip.unzip)(download, (filesDest ? "".concat(filesDest).concat(outPrefix) : filesDest) || destCallback, stream);
|
|
463
|
+
if (debug) {
|
|
464
|
+
console.log('Finished unzipping files');
|
|
465
|
+
}
|
|
466
|
+
if (printProtectionId) {
|
|
467
|
+
console.log(protection._id);
|
|
468
|
+
}
|
|
469
|
+
return protection._id;
|
|
470
|
+
};
|
|
471
|
+
if (processedProtections.length === 1) {
|
|
472
|
+
return handleProtection(processedProtections[0]);
|
|
473
|
+
}
|
|
474
|
+
console.log("Protections stored in ".concat(filesDest, "/[protection-id]"));
|
|
475
|
+
for (let i = 0; i < processedProtections.length; i++) {
|
|
476
|
+
const protection = processedProtections[i];
|
|
477
|
+
try {
|
|
478
|
+
await handleProtection(protection, {
|
|
479
|
+
outPrefix: "/".concat(protection._id, "/"),
|
|
480
|
+
printProtectionId: false
|
|
481
|
+
});
|
|
482
|
+
} catch (e) {
|
|
483
|
+
console.error(e);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
console.log("Runtime: ".concat(processedProtections.length, " protections in ").concat(Math.round((Date.now() - start) / 1000), "s"));
|
|
487
|
+
return protectionIds;
|
|
628
488
|
},
|
|
629
489
|
/**
|
|
630
490
|
* Instrument and download application sources for profiling purposes
|
|
@@ -632,112 +492,90 @@ var _default = {
|
|
|
632
492
|
* @param {function} [destCallback]
|
|
633
493
|
* @returns {Promise<string>}
|
|
634
494
|
*/
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
case 30:
|
|
720
|
-
download = _context5.sent;
|
|
721
|
-
errorHandler(download);
|
|
722
|
-
if (debug) {
|
|
723
|
-
console.log('Unzipping files');
|
|
724
|
-
}
|
|
725
|
-
_context5.next = 35;
|
|
726
|
-
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
727
|
-
case 35:
|
|
728
|
-
if (debug) {
|
|
729
|
-
console.log('Finished unzipping files');
|
|
730
|
-
}
|
|
731
|
-
console.warn("\n WARNING: DO NOT SEND THIS CODE TO PRODUCTION AS IT IS NOT PROTECTED\n ");
|
|
732
|
-
console.log("Application ".concat(applicationId, " was instrumented. Bootstrap your instrumented application and run *--start-profiling* command."));
|
|
733
|
-
return _context5.abrupt("return", instrumentation.data.id);
|
|
734
|
-
case 39:
|
|
735
|
-
case "end":
|
|
736
|
-
return _context5.stop();
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}, _callee5);
|
|
740
|
-
}))();
|
|
495
|
+
async instrumentAndDownload(configPathOrObject, destCallback) {
|
|
496
|
+
const finalConfig = buildFinalConfig(configPathOrObject);
|
|
497
|
+
const {
|
|
498
|
+
applicationId,
|
|
499
|
+
host,
|
|
500
|
+
port,
|
|
501
|
+
basePath,
|
|
502
|
+
protocol,
|
|
503
|
+
cafile,
|
|
504
|
+
keys,
|
|
505
|
+
sources,
|
|
506
|
+
stream = true,
|
|
507
|
+
cwd,
|
|
508
|
+
jscramblerVersion,
|
|
509
|
+
proxy,
|
|
510
|
+
utc,
|
|
511
|
+
skipSources,
|
|
512
|
+
clientId
|
|
513
|
+
} = finalConfig;
|
|
514
|
+
const {
|
|
515
|
+
accessKey,
|
|
516
|
+
secretKey
|
|
517
|
+
} = keys;
|
|
518
|
+
const client = new this.Client({
|
|
519
|
+
accessKey,
|
|
520
|
+
secretKey,
|
|
521
|
+
host,
|
|
522
|
+
port,
|
|
523
|
+
basePath,
|
|
524
|
+
protocol,
|
|
525
|
+
cafile,
|
|
526
|
+
jscramblerVersion,
|
|
527
|
+
proxy,
|
|
528
|
+
utc,
|
|
529
|
+
clientId
|
|
530
|
+
});
|
|
531
|
+
let {
|
|
532
|
+
filesSrc,
|
|
533
|
+
filesDest
|
|
534
|
+
} = finalConfig;
|
|
535
|
+
if (sources) {
|
|
536
|
+
filesSrc = undefined;
|
|
537
|
+
}
|
|
538
|
+
if (destCallback) {
|
|
539
|
+
filesDest = undefined;
|
|
540
|
+
}
|
|
541
|
+
if (!applicationId) {
|
|
542
|
+
throw new Error('Required *applicationId* not provided');
|
|
543
|
+
}
|
|
544
|
+
if (!filesDest && !destCallback) {
|
|
545
|
+
throw new Error('Required *filesDest* not provided');
|
|
546
|
+
}
|
|
547
|
+
if (!skipSources) {
|
|
548
|
+
await this.updateApplicationSources(client, applicationId, {
|
|
549
|
+
sources,
|
|
550
|
+
filesSrc,
|
|
551
|
+
cwd
|
|
552
|
+
});
|
|
553
|
+
} else {
|
|
554
|
+
console.log('Update source files SKIPPED');
|
|
555
|
+
}
|
|
556
|
+
let instrumentation = await this.startInstrumentation(client, applicationId);
|
|
557
|
+
errorHandler(instrumentation);
|
|
558
|
+
const onExitCancelInstrumentation = () => {
|
|
559
|
+
this.deleteProfiling(client, instrumentation.data.id).then(() => console.log('\n** Instrumentation %s WAS CANCELLED **', instrumentation.data.id)).catch(() => debug && console.error(e)).finally(() => process.exit(1));
|
|
560
|
+
};
|
|
561
|
+
process.once('SIGINT', onExitCancelInstrumentation).once('SIGTERM', onExitCancelInstrumentation);
|
|
562
|
+
instrumentation = await this.pollInstrumentation(client, instrumentation.data.id);
|
|
563
|
+
process.removeListener('SIGINT', onExitCancelInstrumentation).removeListener('SIGTERM', onExitCancelInstrumentation);
|
|
564
|
+
if (debug) {
|
|
565
|
+
console.log("Finished instrumention with id ".concat(instrumentation.data.id, ". Downloading..."));
|
|
566
|
+
}
|
|
567
|
+
const download = await this.downloadApplicationInstrumented(client, instrumentation.data.id);
|
|
568
|
+
errorHandler(download);
|
|
569
|
+
if (debug) {
|
|
570
|
+
console.log('Unzipping files');
|
|
571
|
+
}
|
|
572
|
+
await (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
573
|
+
if (debug) {
|
|
574
|
+
console.log('Finished unzipping files');
|
|
575
|
+
}
|
|
576
|
+
console.warn("\n WARNING: DO NOT SEND THIS CODE TO PRODUCTION AS IT IS NOT PROTECTED\n ");
|
|
577
|
+
console.log("Application ".concat(applicationId, " was instrumented. Bootstrap your instrumented application and run *--start-profiling* command."));
|
|
578
|
+
return instrumentation.data.id;
|
|
741
579
|
},
|
|
742
580
|
/**
|
|
743
581
|
* Change the profiling run stat.
|
|
@@ -747,186 +585,157 @@ var _default = {
|
|
|
747
585
|
* @param {string} nextStepMessage
|
|
748
586
|
* @returns {Promise<string>} The previous state
|
|
749
587
|
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
});
|
|
800
|
-
case 15:
|
|
801
|
-
console.log("Profiling was ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
|
|
802
|
-
case 16:
|
|
803
|
-
case "end":
|
|
804
|
-
return _context6.stop();
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}, _callee6);
|
|
808
|
-
}))();
|
|
588
|
+
async setProfilingState(configPathOrObject, state, label, nextStepMessage) {
|
|
589
|
+
const finalConfig = buildFinalConfig(configPathOrObject);
|
|
590
|
+
const {
|
|
591
|
+
keys,
|
|
592
|
+
host,
|
|
593
|
+
port,
|
|
594
|
+
basePath,
|
|
595
|
+
protocol,
|
|
596
|
+
cafile,
|
|
597
|
+
applicationId,
|
|
598
|
+
proxy,
|
|
599
|
+
utc,
|
|
600
|
+
jscramblerVersion,
|
|
601
|
+
clientId
|
|
602
|
+
} = finalConfig;
|
|
603
|
+
const {
|
|
604
|
+
accessKey,
|
|
605
|
+
secretKey
|
|
606
|
+
} = keys;
|
|
607
|
+
const client = new this.Client({
|
|
608
|
+
accessKey,
|
|
609
|
+
secretKey,
|
|
610
|
+
host,
|
|
611
|
+
port,
|
|
612
|
+
basePath,
|
|
613
|
+
protocol,
|
|
614
|
+
cafile,
|
|
615
|
+
proxy,
|
|
616
|
+
utc,
|
|
617
|
+
jscramblerVersion,
|
|
618
|
+
clientId
|
|
619
|
+
});
|
|
620
|
+
const instrumentation = await client.get('/profiling-run', {
|
|
621
|
+
applicationId
|
|
622
|
+
}).catch(e => {
|
|
623
|
+
if (e.statusCode !== 404) throw e;
|
|
624
|
+
});
|
|
625
|
+
if (!instrumentation) {
|
|
626
|
+
throw new Error('There is no active profiling run. Instrument your application first.');
|
|
627
|
+
}
|
|
628
|
+
const previousState = instrumentation.data.state;
|
|
629
|
+
if (previousState === state) {
|
|
630
|
+
console.log("Profiling was already ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
await client.patch("/profiling-run/".concat(instrumentation.data.id), {
|
|
634
|
+
state
|
|
635
|
+
});
|
|
636
|
+
console.log("Profiling was ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
|
|
809
637
|
},
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
case 17:
|
|
859
|
-
_context7.next = 19;
|
|
860
|
-
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
861
|
-
case 19:
|
|
862
|
-
case "end":
|
|
863
|
-
return _context7.stop();
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
}, _callee7, null, [[8, 14]]);
|
|
867
|
-
}))();
|
|
638
|
+
async downloadSourceMaps(configs, destCallback) {
|
|
639
|
+
const {
|
|
640
|
+
keys,
|
|
641
|
+
host,
|
|
642
|
+
port,
|
|
643
|
+
basePath,
|
|
644
|
+
protocol,
|
|
645
|
+
cafile,
|
|
646
|
+
stream = true,
|
|
647
|
+
filesDest,
|
|
648
|
+
filesSrc,
|
|
649
|
+
protectionId,
|
|
650
|
+
jscramblerVersion,
|
|
651
|
+
utc,
|
|
652
|
+
proxy
|
|
653
|
+
} = configs;
|
|
654
|
+
const {
|
|
655
|
+
accessKey,
|
|
656
|
+
secretKey
|
|
657
|
+
} = keys;
|
|
658
|
+
const client = new this.Client({
|
|
659
|
+
accessKey,
|
|
660
|
+
secretKey,
|
|
661
|
+
host,
|
|
662
|
+
port,
|
|
663
|
+
basePath,
|
|
664
|
+
protocol,
|
|
665
|
+
cafile,
|
|
666
|
+
jscramblerVersion,
|
|
667
|
+
utc,
|
|
668
|
+
proxy
|
|
669
|
+
});
|
|
670
|
+
if (!filesDest && !destCallback) {
|
|
671
|
+
throw new Error('Required *filesDest* not provided');
|
|
672
|
+
}
|
|
673
|
+
if (!protectionId) {
|
|
674
|
+
throw new Error('Required *protectionId* not provided');
|
|
675
|
+
}
|
|
676
|
+
if (filesSrc) {
|
|
677
|
+
console.warn('[Warning] Ignoring sources supplied. Downloading source maps of given protection');
|
|
678
|
+
}
|
|
679
|
+
let download;
|
|
680
|
+
try {
|
|
681
|
+
download = await this.downloadSourceMapsRequest(client, protectionId);
|
|
682
|
+
} catch (e) {
|
|
683
|
+
errorHandler(e);
|
|
684
|
+
}
|
|
685
|
+
await (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
868
686
|
},
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
(0, _zip.outputFileSync)(_path.default.join(filesDest, "".concat(protectionId, "_symbolTable.json")), download);
|
|
922
|
-
}
|
|
923
|
-
case 18:
|
|
924
|
-
case "end":
|
|
925
|
-
return _context8.stop();
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
}, _callee8, null, [[8, 14]]);
|
|
929
|
-
}))();
|
|
687
|
+
async downloadSymbolTable(configs, destCallback) {
|
|
688
|
+
const {
|
|
689
|
+
keys,
|
|
690
|
+
host,
|
|
691
|
+
port,
|
|
692
|
+
basePath,
|
|
693
|
+
protocol,
|
|
694
|
+
cafile,
|
|
695
|
+
stream = true,
|
|
696
|
+
filesDest,
|
|
697
|
+
filesSrc,
|
|
698
|
+
protectionId,
|
|
699
|
+
jscramblerVersion,
|
|
700
|
+
utc,
|
|
701
|
+
proxy
|
|
702
|
+
} = configs;
|
|
703
|
+
const {
|
|
704
|
+
accessKey,
|
|
705
|
+
secretKey
|
|
706
|
+
} = keys;
|
|
707
|
+
const client = new this.Client({
|
|
708
|
+
accessKey,
|
|
709
|
+
secretKey,
|
|
710
|
+
host,
|
|
711
|
+
port,
|
|
712
|
+
basePath,
|
|
713
|
+
protocol,
|
|
714
|
+
cafile,
|
|
715
|
+
jscramblerVersion,
|
|
716
|
+
utc,
|
|
717
|
+
proxy
|
|
718
|
+
});
|
|
719
|
+
if (!filesDest && !destCallback) {
|
|
720
|
+
throw new Error('Required *filesDest* not provided');
|
|
721
|
+
}
|
|
722
|
+
if (!protectionId) {
|
|
723
|
+
throw new Error('Required *protectionId* not provided');
|
|
724
|
+
}
|
|
725
|
+
if (filesSrc) {
|
|
726
|
+
console.warn('[Warning] Ignoring sources supplied. Downloading symbol table of given protection');
|
|
727
|
+
}
|
|
728
|
+
let download;
|
|
729
|
+
try {
|
|
730
|
+
download = await this.downloadSymbolTableRequest(client, protectionId);
|
|
731
|
+
} catch (e) {
|
|
732
|
+
errorHandler(e);
|
|
733
|
+
}
|
|
734
|
+
if (typeof destCallback === 'function') {
|
|
735
|
+
destCallback(download, filesDest);
|
|
736
|
+
} else {
|
|
737
|
+
(0, _zip.outputFileSync)(_path.default.join(filesDest, "".concat(protectionId, "_symbolTable.json")), download);
|
|
738
|
+
}
|
|
930
739
|
},
|
|
931
740
|
/**
|
|
932
741
|
* Polls a instrumentation every POLLING_INTERVALms until the state be equal to
|
|
@@ -936,731 +745,227 @@ var _default = {
|
|
|
936
745
|
* @returns {Promise<object>}
|
|
937
746
|
* @throws {Error} due to errors in instrumentation process or user cancel the operation
|
|
938
747
|
*/
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
_context9.t0 = instrumentation.data.state;
|
|
960
|
-
_context9.next = _context9.t0 === 'DELETED' ? 6 : _context9.t0 === 'FAILED_INSTRUMENTATION' ? 7 : _context9.t0 === 'FINISHED_INSTRUMENTATION' ? 9 : 10;
|
|
961
|
-
break;
|
|
962
|
-
case 6:
|
|
963
|
-
throw new Error('Protection canceled by user');
|
|
964
|
-
case 7:
|
|
965
|
-
instrumentation.errors = instrumentation.errors.concat(instrumentation.data.instrumentationErrors.map(function (e) {
|
|
966
|
-
return {
|
|
967
|
-
message: "".concat(e.message, " at ").concat(e.fileName, ":").concat(e.lineNumber)
|
|
968
|
-
};
|
|
969
|
-
}));
|
|
970
|
-
return _context9.abrupt("return", errorHandler(instrumentation));
|
|
971
|
-
case 9:
|
|
972
|
-
return _context9.abrupt("return", instrumentation);
|
|
973
|
-
case 10:
|
|
974
|
-
_context9.next = 12;
|
|
975
|
-
return new Promise(function (resolve) {
|
|
976
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
977
|
-
});
|
|
978
|
-
case 12:
|
|
979
|
-
return _context9.abrupt("return", poll());
|
|
980
|
-
case 13:
|
|
981
|
-
case "end":
|
|
982
|
-
return _context9.stop();
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}, _callee9);
|
|
986
|
-
}));
|
|
987
|
-
return function poll() {
|
|
988
|
-
return _ref6.apply(this, arguments);
|
|
989
|
-
};
|
|
990
|
-
}();
|
|
991
|
-
return _context10.abrupt("return", poll());
|
|
992
|
-
case 3:
|
|
993
|
-
case "end":
|
|
994
|
-
return _context10.stop();
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}, _callee10);
|
|
998
|
-
}))();
|
|
748
|
+
async pollInstrumentation(client, instrumentationId) {
|
|
749
|
+
const start = Date.now();
|
|
750
|
+
const poll = async () => {
|
|
751
|
+
const instrumentation = await this.getInstrumentation(client, instrumentationId);
|
|
752
|
+
switch (instrumentation.data.state) {
|
|
753
|
+
case 'DELETED':
|
|
754
|
+
throw new Error('Protection canceled by user');
|
|
755
|
+
case 'FAILED_INSTRUMENTATION':
|
|
756
|
+
instrumentation.errors = instrumentation.errors.concat(instrumentation.data.instrumentationErrors.map(e => ({
|
|
757
|
+
message: "".concat(e.message, " at ").concat(e.fileName, ":").concat(e.lineNumber)
|
|
758
|
+
})));
|
|
759
|
+
return errorHandler(instrumentation);
|
|
760
|
+
case 'FINISHED_INSTRUMENTATION':
|
|
761
|
+
return instrumentation;
|
|
762
|
+
default:
|
|
763
|
+
await new Promise(resolve => setTimeout(resolve, getPollingInterval(start)));
|
|
764
|
+
return poll();
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
return poll();
|
|
999
768
|
},
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
return action();
|
|
1012
|
-
case 4:
|
|
1013
|
-
return _context11.abrupt("return", _context11.sent);
|
|
1014
|
-
case 7:
|
|
1015
|
-
_context11.prev = 7;
|
|
1016
|
-
_context11.t0 = _context11["catch"](1);
|
|
1017
|
-
if (!(retriesLeft <= 0)) {
|
|
1018
|
-
_context11.next = 11;
|
|
1019
|
-
break;
|
|
1020
|
-
}
|
|
1021
|
-
throw _context11.t0;
|
|
1022
|
-
case 11:
|
|
1023
|
-
if (!(_context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE && _context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.GATEWAY_TIMEOUT)) {
|
|
1024
|
-
_context11.next = 13;
|
|
1025
|
-
break;
|
|
1026
|
-
}
|
|
1027
|
-
throw _context11.t0;
|
|
1028
|
-
case 13:
|
|
1029
|
-
// Retry
|
|
1030
|
-
if (debug) {
|
|
1031
|
-
console.log('Retrying request');
|
|
1032
|
-
}
|
|
1033
|
-
retriesLeft--;
|
|
1034
|
-
case 15:
|
|
1035
|
-
_context11.next = 1;
|
|
1036
|
-
break;
|
|
1037
|
-
case 17:
|
|
1038
|
-
case "end":
|
|
1039
|
-
return _context11.stop();
|
|
1040
|
-
}
|
|
769
|
+
async withRetries(action) {
|
|
770
|
+
let retriesLeft = _config2.default.maxRetries;
|
|
771
|
+
for (;;) {
|
|
772
|
+
try {
|
|
773
|
+
return await action();
|
|
774
|
+
} catch (e) {
|
|
775
|
+
if (retriesLeft <= 0) {
|
|
776
|
+
throw e;
|
|
777
|
+
}
|
|
778
|
+
if (e.statusCode !== _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE && e.statusCode !== _constants.HTTP_STATUS_CODES.GATEWAY_TIMEOUT) {
|
|
779
|
+
throw e;
|
|
1041
780
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
781
|
+
// Retry
|
|
782
|
+
if (debug) {
|
|
783
|
+
console.log('Retrying request');
|
|
784
|
+
}
|
|
785
|
+
retriesLeft--;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
1044
788
|
},
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
return _this8.getApplicationProtection(client, applicationId, protectionId, fragments);
|
|
1064
|
-
});
|
|
1065
|
-
case 2:
|
|
1066
|
-
applicationProtection = _context12.sent;
|
|
1067
|
-
if (!applicationProtection.errors) {
|
|
1068
|
-
_context12.next = 8;
|
|
1069
|
-
break;
|
|
1070
|
-
}
|
|
1071
|
-
console.log('Error polling protection', applicationProtection.errors);
|
|
1072
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
1073
|
-
case 8:
|
|
1074
|
-
state = applicationProtection.data.applicationProtection.state;
|
|
1075
|
-
if (!(state !== 'finished' && state !== 'errored' && state !== 'canceled')) {
|
|
1076
|
-
_context12.next = 15;
|
|
1077
|
-
break;
|
|
1078
|
-
}
|
|
1079
|
-
_context12.next = 12;
|
|
1080
|
-
return new Promise(function (resolve) {
|
|
1081
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
1082
|
-
});
|
|
1083
|
-
case 12:
|
|
1084
|
-
return _context12.abrupt("return", poll());
|
|
1085
|
-
case 15:
|
|
1086
|
-
if (!(state === 'canceled')) {
|
|
1087
|
-
_context12.next = 19;
|
|
1088
|
-
break;
|
|
1089
|
-
}
|
|
1090
|
-
throw new Error('Protection canceled by user');
|
|
1091
|
-
case 19:
|
|
1092
|
-
return _context12.abrupt("return", applicationProtection.data.applicationProtection);
|
|
1093
|
-
case 20:
|
|
1094
|
-
case "end":
|
|
1095
|
-
return _context12.stop();
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
}, _callee12);
|
|
1099
|
-
}));
|
|
1100
|
-
return function poll() {
|
|
1101
|
-
return _ref7.apply(this, arguments);
|
|
1102
|
-
};
|
|
1103
|
-
}();
|
|
1104
|
-
return _context13.abrupt("return", poll());
|
|
1105
|
-
case 3:
|
|
1106
|
-
case "end":
|
|
1107
|
-
return _context13.stop();
|
|
1108
|
-
}
|
|
789
|
+
async pollProtection(client, applicationId, protectionId, fragments) {
|
|
790
|
+
const start = Date.now();
|
|
791
|
+
const poll = async () => {
|
|
792
|
+
const applicationProtection = await this.withRetries(() => this.getApplicationProtection(client, applicationId, protectionId, fragments));
|
|
793
|
+
if (applicationProtection.errors) {
|
|
794
|
+
console.log('Error polling protection', applicationProtection.errors);
|
|
795
|
+
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
796
|
+
} else {
|
|
797
|
+
const {
|
|
798
|
+
state
|
|
799
|
+
} = applicationProtection.data.applicationProtection;
|
|
800
|
+
if (state !== 'finished' && state !== 'errored' && state !== 'canceled') {
|
|
801
|
+
await new Promise(resolve => setTimeout(resolve, getPollingInterval(start)));
|
|
802
|
+
return poll();
|
|
803
|
+
} else if (state === 'canceled') {
|
|
804
|
+
throw new Error('Protection canceled by user');
|
|
805
|
+
} else {
|
|
806
|
+
return applicationProtection.data.applicationProtection;
|
|
1109
807
|
}
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
return poll();
|
|
1112
811
|
},
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
1154
|
-
case 8:
|
|
1155
|
-
ended = applicationProtections.data.applicationProtections.filter(function (_ref9) {
|
|
1156
|
-
var state = _ref9.state;
|
|
1157
|
-
return state === 'finished' || state === 'errored' || state === 'canceled';
|
|
1158
|
-
}); // print progress
|
|
1159
|
-
ended.filter(function (_ref10) {
|
|
1160
|
-
var _id = _ref10._id,
|
|
1161
|
-
state = _ref10.state;
|
|
1162
|
-
return !seen[_id] && state !== 'canceled';
|
|
1163
|
-
}).forEach(function (_ref11) {
|
|
1164
|
-
var _id = _ref11._id,
|
|
1165
|
-
startedAt = _ref11.startedAt,
|
|
1166
|
-
finishedAt = _ref11.finishedAt,
|
|
1167
|
-
state = _ref11.state;
|
|
1168
|
-
seen[_id] = true;
|
|
1169
|
-
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"));
|
|
1170
|
-
});
|
|
1171
|
-
if (!(ended.length < protectionIds.length)) {
|
|
1172
|
-
_context14.next = 14;
|
|
1173
|
-
break;
|
|
1174
|
-
}
|
|
1175
|
-
_context14.next = 13;
|
|
1176
|
-
return new Promise(function (resolve) {
|
|
1177
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
1178
|
-
});
|
|
1179
|
-
case 13:
|
|
1180
|
-
return _context14.abrupt("return", poll());
|
|
1181
|
-
case 14:
|
|
1182
|
-
return _context14.abrupt("return", applicationProtections.data.applicationProtections);
|
|
1183
|
-
case 15:
|
|
1184
|
-
case "end":
|
|
1185
|
-
return _context14.stop();
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}, _callee14);
|
|
1189
|
-
}));
|
|
1190
|
-
return function poll() {
|
|
1191
|
-
return _ref8.apply(this, arguments);
|
|
1192
|
-
};
|
|
1193
|
-
}();
|
|
1194
|
-
return _context15.abrupt("return", poll());
|
|
1195
|
-
case 9:
|
|
1196
|
-
case "end":
|
|
1197
|
-
return _context15.stop();
|
|
1198
|
-
}
|
|
812
|
+
async pollProtections(client, applicationId, protectionIds, fragments) {
|
|
813
|
+
if (protectionIds.length === 1) {
|
|
814
|
+
return [await this.pollProtection(client, applicationId, protectionIds[0], fragments)];
|
|
815
|
+
}
|
|
816
|
+
const start = Date.now();
|
|
817
|
+
let seen = {};
|
|
818
|
+
const poll = async () => {
|
|
819
|
+
const applicationProtections = await this.withRetries(() => this.getApplicationProtections(client, applicationId, {
|
|
820
|
+
protectionIds
|
|
821
|
+
}, fragments.applicationProtection, ["$protectionIds: [String]"]));
|
|
822
|
+
if (applicationProtections.errors) {
|
|
823
|
+
console.log('Error polling protection', applicationProtections.errors);
|
|
824
|
+
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
825
|
+
} else {
|
|
826
|
+
const ended = applicationProtections.data.applicationProtections.filter(_ref3 => {
|
|
827
|
+
let {
|
|
828
|
+
state
|
|
829
|
+
} = _ref3;
|
|
830
|
+
return state === 'finished' || state === 'errored' || state === 'canceled';
|
|
831
|
+
});
|
|
832
|
+
// print progress
|
|
833
|
+
ended.filter(_ref4 => {
|
|
834
|
+
let {
|
|
835
|
+
_id,
|
|
836
|
+
state
|
|
837
|
+
} = _ref4;
|
|
838
|
+
return !seen[_id] && state !== 'canceled';
|
|
839
|
+
}).forEach(_ref5 => {
|
|
840
|
+
let {
|
|
841
|
+
_id,
|
|
842
|
+
startedAt,
|
|
843
|
+
finishedAt,
|
|
844
|
+
state
|
|
845
|
+
} = _ref5;
|
|
846
|
+
seen[_id] = true;
|
|
847
|
+
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"));
|
|
848
|
+
});
|
|
849
|
+
if (ended.length < protectionIds.length) {
|
|
850
|
+
await new Promise(resolve => setTimeout(resolve, getPollingInterval(start)));
|
|
851
|
+
return poll();
|
|
1199
852
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
853
|
+
return applicationProtections.data.applicationProtections;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
return poll();
|
|
1202
857
|
},
|
|
1203
858
|
//
|
|
1204
|
-
|
|
1205
|
-
return
|
|
1206
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1207
|
-
while (1) {
|
|
1208
|
-
switch (_context16.prev = _context16.next) {
|
|
1209
|
-
case 0:
|
|
1210
|
-
return _context16.abrupt("return", client.post('/application', mutations.createApplication(data, fragments)));
|
|
1211
|
-
case 1:
|
|
1212
|
-
case "end":
|
|
1213
|
-
return _context16.stop();
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
}, _callee16);
|
|
1217
|
-
}))();
|
|
859
|
+
async createApplication(client, data, fragments) {
|
|
860
|
+
return client.post('/application', mutations.createApplication(data, fragments));
|
|
1218
861
|
},
|
|
1219
862
|
//
|
|
1220
|
-
|
|
1221
|
-
return
|
|
1222
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1223
|
-
while (1) {
|
|
1224
|
-
switch (_context17.prev = _context17.next) {
|
|
1225
|
-
case 0:
|
|
1226
|
-
return _context17.abrupt("return", client.post('/application', mutations.duplicateApplication(data, fragments)));
|
|
1227
|
-
case 1:
|
|
1228
|
-
case "end":
|
|
1229
|
-
return _context17.stop();
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
}, _callee17);
|
|
1233
|
-
}))();
|
|
863
|
+
async duplicateApplication(client, data, fragments) {
|
|
864
|
+
return client.post('/application', mutations.duplicateApplication(data, fragments));
|
|
1234
865
|
},
|
|
1235
866
|
//
|
|
1236
|
-
|
|
1237
|
-
return
|
|
1238
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1239
|
-
while (1) {
|
|
1240
|
-
switch (_context18.prev = _context18.next) {
|
|
1241
|
-
case 0:
|
|
1242
|
-
return _context18.abrupt("return", client.post('/application', mutations.removeApplication(id)));
|
|
1243
|
-
case 1:
|
|
1244
|
-
case "end":
|
|
1245
|
-
return _context18.stop();
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
}, _callee18);
|
|
1249
|
-
}))();
|
|
867
|
+
async removeApplication(client, id) {
|
|
868
|
+
return client.post('/application', mutations.removeApplication(id));
|
|
1250
869
|
},
|
|
1251
870
|
//
|
|
1252
|
-
|
|
1253
|
-
return
|
|
1254
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1255
|
-
while (1) {
|
|
1256
|
-
switch (_context19.prev = _context19.next) {
|
|
1257
|
-
case 0:
|
|
1258
|
-
return _context19.abrupt("return", client.post('/application', mutations.removeProtection(id, appId, fragments)));
|
|
1259
|
-
case 1:
|
|
1260
|
-
case "end":
|
|
1261
|
-
return _context19.stop();
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
}, _callee19);
|
|
1265
|
-
}))();
|
|
871
|
+
async removeProtection(client, id, appId, fragments) {
|
|
872
|
+
return client.post('/application', mutations.removeProtection(id, appId, fragments));
|
|
1266
873
|
},
|
|
1267
874
|
//
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1272
|
-
while (1) {
|
|
1273
|
-
switch (_context20.prev = _context20.next) {
|
|
1274
|
-
case 0:
|
|
1275
|
-
_context20.next = 2;
|
|
1276
|
-
return mutations.cancelProtection(id, appId, fragments);
|
|
1277
|
-
case 2:
|
|
1278
|
-
mutation = _context20.sent;
|
|
1279
|
-
return _context20.abrupt("return", client.post('/application', mutation));
|
|
1280
|
-
case 4:
|
|
1281
|
-
case "end":
|
|
1282
|
-
return _context20.stop();
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
}, _callee20);
|
|
1286
|
-
}))();
|
|
875
|
+
async cancelProtection(client, id, appId, fragments) {
|
|
876
|
+
const mutation = await mutations.cancelProtection(id, appId, fragments);
|
|
877
|
+
return client.post('/application', mutation);
|
|
1287
878
|
},
|
|
1288
879
|
//
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1293
|
-
while (1) {
|
|
1294
|
-
switch (_context21.prev = _context21.next) {
|
|
1295
|
-
case 0:
|
|
1296
|
-
_context21.next = 2;
|
|
1297
|
-
return mutations.updateApplication(applicationData, fragments, applicationId);
|
|
1298
|
-
case 2:
|
|
1299
|
-
mutation = _context21.sent;
|
|
1300
|
-
return _context21.abrupt("return", client.post('/application', mutation));
|
|
1301
|
-
case 4:
|
|
1302
|
-
case "end":
|
|
1303
|
-
return _context21.stop();
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}, _callee21);
|
|
1307
|
-
}))();
|
|
880
|
+
async updateApplication(client, applicationData, fragments, applicationId) {
|
|
881
|
+
const mutation = await mutations.updateApplication(applicationData, fragments, applicationId);
|
|
882
|
+
return client.post('/application', mutation);
|
|
1308
883
|
},
|
|
1309
884
|
//
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1314
|
-
while (1) {
|
|
1315
|
-
switch (_context22.prev = _context22.next) {
|
|
1316
|
-
case 0:
|
|
1317
|
-
_context22.next = 2;
|
|
1318
|
-
return mutations.unlockApplication(application, fragments);
|
|
1319
|
-
case 2:
|
|
1320
|
-
mutation = _context22.sent;
|
|
1321
|
-
return _context22.abrupt("return", client.post('/application', mutation));
|
|
1322
|
-
case 4:
|
|
1323
|
-
case "end":
|
|
1324
|
-
return _context22.stop();
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
}, _callee22);
|
|
1328
|
-
}))();
|
|
885
|
+
async unlockApplication(client, application, fragments) {
|
|
886
|
+
const mutation = await mutations.unlockApplication(application, fragments);
|
|
887
|
+
return client.post('/application', mutation);
|
|
1329
888
|
},
|
|
1330
889
|
//
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1335
|
-
while (1) {
|
|
1336
|
-
switch (_context23.prev = _context23.next) {
|
|
1337
|
-
case 0:
|
|
1338
|
-
_context23.next = 2;
|
|
1339
|
-
return queries.getApplication(applicationId, fragments, params);
|
|
1340
|
-
case 2:
|
|
1341
|
-
query = _context23.sent;
|
|
1342
|
-
return _context23.abrupt("return", client.get('/application', query));
|
|
1343
|
-
case 4:
|
|
1344
|
-
case "end":
|
|
1345
|
-
return _context23.stop();
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
}, _callee23);
|
|
1349
|
-
}))();
|
|
890
|
+
async getApplication(client, applicationId, fragments, params) {
|
|
891
|
+
const query = await queries.getApplication(applicationId, fragments, params);
|
|
892
|
+
return client.get('/application', query);
|
|
1350
893
|
},
|
|
1351
894
|
//
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1356
|
-
while (1) {
|
|
1357
|
-
switch (_context24.prev = _context24.next) {
|
|
1358
|
-
case 0:
|
|
1359
|
-
_context24.next = 2;
|
|
1360
|
-
return queries.getApplicationSource(sourceId, fragments, limits);
|
|
1361
|
-
case 2:
|
|
1362
|
-
query = _context24.sent;
|
|
1363
|
-
return _context24.abrupt("return", client.get('/application', query));
|
|
1364
|
-
case 4:
|
|
1365
|
-
case "end":
|
|
1366
|
-
return _context24.stop();
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
}, _callee24);
|
|
1370
|
-
}))();
|
|
895
|
+
async getApplicationSource(client, sourceId, fragments, limits) {
|
|
896
|
+
const query = await queries.getApplicationSource(sourceId, fragments, limits);
|
|
897
|
+
return client.get('/application', query);
|
|
1371
898
|
},
|
|
1372
899
|
//
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1377
|
-
while (1) {
|
|
1378
|
-
switch (_context25.prev = _context25.next) {
|
|
1379
|
-
case 0:
|
|
1380
|
-
query = queries.getApplicationProtections(applicationId, params, fragments, queryArgs);
|
|
1381
|
-
return _context25.abrupt("return", client.get('/application', query));
|
|
1382
|
-
case 2:
|
|
1383
|
-
case "end":
|
|
1384
|
-
return _context25.stop();
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
}, _callee25);
|
|
1388
|
-
}))();
|
|
900
|
+
async getApplicationProtections(client, applicationId, params, fragments, queryArgs) {
|
|
901
|
+
const query = queries.getApplicationProtections(applicationId, params, fragments, queryArgs);
|
|
902
|
+
return client.get('/application', query);
|
|
1389
903
|
},
|
|
1390
904
|
//
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1395
|
-
while (1) {
|
|
1396
|
-
switch (_context26.prev = _context26.next) {
|
|
1397
|
-
case 0:
|
|
1398
|
-
_context26.next = 2;
|
|
1399
|
-
return queries.getApplicationProtectionsCount(applicationId, fragments);
|
|
1400
|
-
case 2:
|
|
1401
|
-
query = _context26.sent;
|
|
1402
|
-
return _context26.abrupt("return", client.get('/application', query));
|
|
1403
|
-
case 4:
|
|
1404
|
-
case "end":
|
|
1405
|
-
return _context26.stop();
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
}, _callee26);
|
|
1409
|
-
}))();
|
|
905
|
+
async getApplicationProtectionsCount(client, applicationId, fragments) {
|
|
906
|
+
const query = await queries.getApplicationProtectionsCount(applicationId, fragments);
|
|
907
|
+
return client.get('/application', query);
|
|
1410
908
|
},
|
|
1411
909
|
//
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1416
|
-
while (1) {
|
|
1417
|
-
switch (_context27.prev = _context27.next) {
|
|
1418
|
-
case 0:
|
|
1419
|
-
_context27.next = 2;
|
|
1420
|
-
return mutations.createTemplate(template, fragments);
|
|
1421
|
-
case 2:
|
|
1422
|
-
mutation = _context27.sent;
|
|
1423
|
-
return _context27.abrupt("return", client.post('/application', mutation));
|
|
1424
|
-
case 4:
|
|
1425
|
-
case "end":
|
|
1426
|
-
return _context27.stop();
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
}, _callee27);
|
|
1430
|
-
}))();
|
|
910
|
+
async createTemplate(client, template, fragments) {
|
|
911
|
+
const mutation = await mutations.createTemplate(template, fragments);
|
|
912
|
+
return client.post('/application', mutation);
|
|
1431
913
|
},
|
|
1432
914
|
//
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1437
|
-
while (1) {
|
|
1438
|
-
switch (_context28.prev = _context28.next) {
|
|
1439
|
-
case 0:
|
|
1440
|
-
_context28.next = 2;
|
|
1441
|
-
return mutations.removeTemplate(id);
|
|
1442
|
-
case 2:
|
|
1443
|
-
mutation = _context28.sent;
|
|
1444
|
-
return _context28.abrupt("return", client.post('/application', mutation));
|
|
1445
|
-
case 4:
|
|
1446
|
-
case "end":
|
|
1447
|
-
return _context28.stop();
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
}, _callee28);
|
|
1451
|
-
}))();
|
|
915
|
+
async removeTemplate(client, id) {
|
|
916
|
+
const mutation = await mutations.removeTemplate(id);
|
|
917
|
+
return client.post('/application', mutation);
|
|
1452
918
|
},
|
|
1453
919
|
//
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1458
|
-
while (1) {
|
|
1459
|
-
switch (_context29.prev = _context29.next) {
|
|
1460
|
-
case 0:
|
|
1461
|
-
_context29.next = 2;
|
|
1462
|
-
return queries.getTemplates(fragments);
|
|
1463
|
-
case 2:
|
|
1464
|
-
query = _context29.sent;
|
|
1465
|
-
return _context29.abrupt("return", client.get('/application', query));
|
|
1466
|
-
case 4:
|
|
1467
|
-
case "end":
|
|
1468
|
-
return _context29.stop();
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}, _callee29);
|
|
1472
|
-
}))();
|
|
920
|
+
async getTemplates(client, fragments) {
|
|
921
|
+
const query = await queries.getTemplates(fragments);
|
|
922
|
+
return client.get('/application', query);
|
|
1473
923
|
},
|
|
1474
924
|
//
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
1479
|
-
while (1) {
|
|
1480
|
-
switch (_context30.prev = _context30.next) {
|
|
1481
|
-
case 0:
|
|
1482
|
-
_context30.next = 2;
|
|
1483
|
-
return queries.getApplications(fragments, params);
|
|
1484
|
-
case 2:
|
|
1485
|
-
query = _context30.sent;
|
|
1486
|
-
return _context30.abrupt("return", client.get('/application', query));
|
|
1487
|
-
case 4:
|
|
1488
|
-
case "end":
|
|
1489
|
-
return _context30.stop();
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
}, _callee30);
|
|
1493
|
-
}))();
|
|
925
|
+
async getApplications(client, fragments, params) {
|
|
926
|
+
const query = await queries.getApplications(fragments, params);
|
|
927
|
+
return client.get('/application', query);
|
|
1494
928
|
},
|
|
1495
929
|
//
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
return
|
|
1499
|
-
var mutation;
|
|
1500
|
-
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
1501
|
-
while (1) {
|
|
1502
|
-
switch (_context31.prev = _context31.next) {
|
|
1503
|
-
case 0:
|
|
1504
|
-
_context31.next = 2;
|
|
1505
|
-
return mutations.addApplicationSource(applicationId, applicationSource, fragments);
|
|
1506
|
-
case 2:
|
|
1507
|
-
mutation = _context31.sent;
|
|
1508
|
-
return _context31.abrupt("return", _this10.withRetries(function () {
|
|
1509
|
-
return client.post('/application', mutation);
|
|
1510
|
-
}));
|
|
1511
|
-
case 4:
|
|
1512
|
-
case "end":
|
|
1513
|
-
return _context31.stop();
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
}, _callee31);
|
|
1517
|
-
}))();
|
|
930
|
+
async addApplicationSource(client, applicationId, applicationSource, fragments) {
|
|
931
|
+
const mutation = await mutations.addApplicationSource(applicationId, applicationSource, fragments);
|
|
932
|
+
return this.withRetries(() => client.post('/application', mutation));
|
|
1518
933
|
},
|
|
1519
934
|
//
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
while (1) {
|
|
1525
|
-
switch (_context32.prev = _context32.next) {
|
|
1526
|
-
case 0:
|
|
1527
|
-
_context32.next = 2;
|
|
1528
|
-
return getFileFromUrl(client, url);
|
|
1529
|
-
case 2:
|
|
1530
|
-
file = _context32.sent;
|
|
1531
|
-
_context32.next = 5;
|
|
1532
|
-
return mutations.addApplicationSource(applicationId, file, fragments);
|
|
1533
|
-
case 5:
|
|
1534
|
-
mutation = _context32.sent;
|
|
1535
|
-
return _context32.abrupt("return", client.post('/application', mutation));
|
|
1536
|
-
case 7:
|
|
1537
|
-
case "end":
|
|
1538
|
-
return _context32.stop();
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
}, _callee32);
|
|
1542
|
-
}))();
|
|
935
|
+
async addApplicationSourceFromURL(client, applicationId, url, fragments) {
|
|
936
|
+
const file = await getFileFromUrl(client, url);
|
|
937
|
+
const mutation = await mutations.addApplicationSource(applicationId, file, fragments);
|
|
938
|
+
return client.post('/application', mutation);
|
|
1543
939
|
},
|
|
1544
940
|
//
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
1549
|
-
while (1) {
|
|
1550
|
-
switch (_context33.prev = _context33.next) {
|
|
1551
|
-
case 0:
|
|
1552
|
-
_context33.next = 2;
|
|
1553
|
-
return mutations.updateApplicationSource(applicationSource, fragments);
|
|
1554
|
-
case 2:
|
|
1555
|
-
mutation = _context33.sent;
|
|
1556
|
-
return _context33.abrupt("return", client.post('/application', mutation));
|
|
1557
|
-
case 4:
|
|
1558
|
-
case "end":
|
|
1559
|
-
return _context33.stop();
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
}, _callee33);
|
|
1563
|
-
}))();
|
|
941
|
+
async updateApplicationSource(client, applicationSource, fragments) {
|
|
942
|
+
const mutation = await mutations.updateApplicationSource(applicationSource, fragments);
|
|
943
|
+
return client.post('/application', mutation);
|
|
1564
944
|
},
|
|
1565
945
|
//
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
return
|
|
1569
|
-
var mutation;
|
|
1570
|
-
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
1571
|
-
while (1) {
|
|
1572
|
-
switch (_context34.prev = _context34.next) {
|
|
1573
|
-
case 0:
|
|
1574
|
-
_context34.next = 2;
|
|
1575
|
-
return mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
|
|
1576
|
-
case 2:
|
|
1577
|
-
mutation = _context34.sent;
|
|
1578
|
-
return _context34.abrupt("return", _this11.withRetries(function () {
|
|
1579
|
-
return client.post('/application', mutation);
|
|
1580
|
-
}));
|
|
1581
|
-
case 4:
|
|
1582
|
-
case "end":
|
|
1583
|
-
return _context34.stop();
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
}, _callee34);
|
|
1587
|
-
}))();
|
|
946
|
+
async removeSourceFromApplication(client, sourceId, applicationId, fragments) {
|
|
947
|
+
const mutation = await mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
|
|
948
|
+
return this.withRetries(() => client.post('/application', mutation));
|
|
1588
949
|
},
|
|
1589
950
|
//
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
1594
|
-
while (1) {
|
|
1595
|
-
switch (_context35.prev = _context35.next) {
|
|
1596
|
-
case 0:
|
|
1597
|
-
_context35.next = 2;
|
|
1598
|
-
return mutations.applyTemplate(templateId, appId, fragments);
|
|
1599
|
-
case 2:
|
|
1600
|
-
mutation = _context35.sent;
|
|
1601
|
-
return _context35.abrupt("return", client.post('/application', mutation));
|
|
1602
|
-
case 4:
|
|
1603
|
-
case "end":
|
|
1604
|
-
return _context35.stop();
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
}, _callee35);
|
|
1608
|
-
}))();
|
|
951
|
+
async applyTemplate(client, templateId, appId, fragments) {
|
|
952
|
+
const mutation = await mutations.applyTemplate(templateId, appId, fragments);
|
|
953
|
+
return client.post('/application', mutation);
|
|
1609
954
|
},
|
|
1610
955
|
//
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
1615
|
-
while (1) {
|
|
1616
|
-
switch (_context36.prev = _context36.next) {
|
|
1617
|
-
case 0:
|
|
1618
|
-
_context36.next = 2;
|
|
1619
|
-
return mutations.updateTemplate(template, fragments);
|
|
1620
|
-
case 2:
|
|
1621
|
-
mutation = _context36.sent;
|
|
1622
|
-
return _context36.abrupt("return", client.post('/application', mutation));
|
|
1623
|
-
case 4:
|
|
1624
|
-
case "end":
|
|
1625
|
-
return _context36.stop();
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
}, _callee36);
|
|
1629
|
-
}))();
|
|
956
|
+
async updateTemplate(client, template, fragments) {
|
|
957
|
+
const mutation = await mutations.updateTemplate(template, fragments);
|
|
958
|
+
return client.post('/application', mutation);
|
|
1630
959
|
},
|
|
1631
|
-
|
|
1632
|
-
return
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
switch (_context37.prev = _context37.next) {
|
|
1636
|
-
case 0:
|
|
1637
|
-
return _context37.abrupt("return", client.get('/profiling-run', {
|
|
1638
|
-
applicationId: applicationId
|
|
1639
|
-
}));
|
|
1640
|
-
case 1:
|
|
1641
|
-
case "end":
|
|
1642
|
-
return _context37.stop();
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}, _callee37);
|
|
1646
|
-
}))();
|
|
960
|
+
async getApplicationProfiling(client, applicationId) {
|
|
961
|
+
return client.get('/profiling-run', {
|
|
962
|
+
applicationId
|
|
963
|
+
});
|
|
1647
964
|
},
|
|
1648
|
-
|
|
1649
|
-
return
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
switch (_context38.prev = _context38.next) {
|
|
1653
|
-
case 0:
|
|
1654
|
-
return _context38.abrupt("return", client.patch("/profiling-run/".concat(profilingId), {
|
|
1655
|
-
state: 'DELETED'
|
|
1656
|
-
}));
|
|
1657
|
-
case 1:
|
|
1658
|
-
case "end":
|
|
1659
|
-
return _context38.stop();
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
}, _callee38);
|
|
1663
|
-
}))();
|
|
965
|
+
async deleteProfiling(client, profilingId) {
|
|
966
|
+
return client.patch("/profiling-run/".concat(profilingId), {
|
|
967
|
+
state: 'DELETED'
|
|
968
|
+
});
|
|
1664
969
|
},
|
|
1665
970
|
/**
|
|
1666
971
|
* Starts a new instrumentation process.
|
|
@@ -1669,63 +974,24 @@ var _default = {
|
|
|
1669
974
|
* @param applicationId
|
|
1670
975
|
* @returns {Promise<*>}
|
|
1671
976
|
*/
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
if (e.statusCode !== 404) throw e;
|
|
1683
|
-
});
|
|
1684
|
-
case 2:
|
|
1685
|
-
instrumentation = _context39.sent;
|
|
1686
|
-
if (!instrumentation) {
|
|
1687
|
-
_context39.next = 6;
|
|
1688
|
-
break;
|
|
1689
|
-
}
|
|
1690
|
-
_context39.next = 6;
|
|
1691
|
-
return _this12.deleteProfiling(client, instrumentation.data.id);
|
|
1692
|
-
case 6:
|
|
1693
|
-
return _context39.abrupt("return", client.post('/profiling-run', {
|
|
1694
|
-
applicationId: applicationId
|
|
1695
|
-
}));
|
|
1696
|
-
case 7:
|
|
1697
|
-
case "end":
|
|
1698
|
-
return _context39.stop();
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}, _callee39);
|
|
1702
|
-
}))();
|
|
977
|
+
async startInstrumentation(client, applicationId) {
|
|
978
|
+
const instrumentation = await this.getApplicationProfiling(client, applicationId).catch(e => {
|
|
979
|
+
if (e.statusCode !== 404) throw e;
|
|
980
|
+
});
|
|
981
|
+
if (instrumentation) {
|
|
982
|
+
await this.deleteProfiling(client, instrumentation.data.id);
|
|
983
|
+
}
|
|
984
|
+
return client.post('/profiling-run', {
|
|
985
|
+
applicationId
|
|
986
|
+
});
|
|
1703
987
|
},
|
|
1704
988
|
//
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
case 0:
|
|
1712
|
-
_context40.next = 2;
|
|
1713
|
-
return introspection.mutation(client, 'createApplicationProtection');
|
|
1714
|
-
case 2:
|
|
1715
|
-
_yield$introspection$ = _context40.sent;
|
|
1716
|
-
args = _yield$introspection$.args;
|
|
1717
|
-
_context40.next = 6;
|
|
1718
|
-
return mutations.createApplicationProtection(applicationId, fragments, protectionOptions, args);
|
|
1719
|
-
case 6:
|
|
1720
|
-
mutation = _context40.sent;
|
|
1721
|
-
return _context40.abrupt("return", client.post('/application', mutation));
|
|
1722
|
-
case 8:
|
|
1723
|
-
case "end":
|
|
1724
|
-
return _context40.stop();
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
}, _callee40);
|
|
1728
|
-
}))();
|
|
989
|
+
async createApplicationProtection(client, applicationId, protectionOptions, fragments) {
|
|
990
|
+
const {
|
|
991
|
+
args
|
|
992
|
+
} = await introspection.mutation(client, 'createApplicationProtection');
|
|
993
|
+
const mutation = await mutations.createApplicationProtection(applicationId, fragments, protectionOptions, args);
|
|
994
|
+
return client.post('/application', mutation);
|
|
1729
995
|
},
|
|
1730
996
|
/**
|
|
1731
997
|
* Create one or more application protections at once
|
|
@@ -1736,155 +1002,61 @@ var _default = {
|
|
|
1736
1002
|
* @param {object} fragments
|
|
1737
1003
|
* @returns {Promise<{data: {protections: Array.<{_id}>}, errors: Array}>}
|
|
1738
1004
|
*/
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
case 7:
|
|
1764
|
-
_context41.next = 9;
|
|
1765
|
-
return introspection.mutation(client, 'createApplicationProtections');
|
|
1766
|
-
case 9:
|
|
1767
|
-
mutationType = _context41.sent;
|
|
1768
|
-
if (!mutationType) {
|
|
1769
|
-
console.error("\"Create multiple protections at once\" it's only available on Jscrambler version 7.2 and above.");
|
|
1770
|
-
process.exit(1);
|
|
1771
|
-
}
|
|
1772
|
-
_context41.next = 13;
|
|
1773
|
-
return mutations.createApplicationProtections(applicationId, fragments, protectionOptions, mutationType.args);
|
|
1774
|
-
case 13:
|
|
1775
|
-
mutation = _context41.sent;
|
|
1776
|
-
_context41.next = 16;
|
|
1777
|
-
return client.post('/application', mutation);
|
|
1778
|
-
case 16:
|
|
1779
|
-
result = _context41.sent;
|
|
1780
|
-
if (result.data && result.data.createApplicationProtections) {
|
|
1781
|
-
result.data.protections = result.data.createApplicationProtections.protections;
|
|
1782
|
-
delete result.data.createApplicationProtections;
|
|
1783
|
-
}
|
|
1784
|
-
case 18:
|
|
1785
|
-
return _context41.abrupt("return", result);
|
|
1786
|
-
case 19:
|
|
1787
|
-
case "end":
|
|
1788
|
-
return _context41.stop();
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
}, _callee41);
|
|
1792
|
-
}))();
|
|
1005
|
+
async createApplicationProtections(client, applicationId, protectionOptions, fragments) {
|
|
1006
|
+
let result;
|
|
1007
|
+
if (!protectionOptions.numberOfProtections || protectionOptions.numberOfProtections < 2) {
|
|
1008
|
+
result = await this.createApplicationProtection(client, applicationId, _objectSpread(_objectSpread({}, protectionOptions), {}, {
|
|
1009
|
+
numberOfProtections: undefined
|
|
1010
|
+
}), fragments);
|
|
1011
|
+
if (result.data && result.data.createApplicationProtection) {
|
|
1012
|
+
result.data.protections = [result.data.createApplicationProtection];
|
|
1013
|
+
delete result.data.createApplicationProtection;
|
|
1014
|
+
}
|
|
1015
|
+
} else {
|
|
1016
|
+
const mutationType = await introspection.mutation(client, 'createApplicationProtections');
|
|
1017
|
+
if (!mutationType) {
|
|
1018
|
+
console.error("\"Create multiple protections at once\" it's only available on Jscrambler version 7.2 and above.");
|
|
1019
|
+
process.exit(1);
|
|
1020
|
+
}
|
|
1021
|
+
const mutation = await mutations.createApplicationProtections(applicationId, fragments, protectionOptions, mutationType.args);
|
|
1022
|
+
result = await client.post('/application', mutation);
|
|
1023
|
+
if (result.data && result.data.createApplicationProtections) {
|
|
1024
|
+
result.data.protections = result.data.createApplicationProtections.protections;
|
|
1025
|
+
delete result.data.createApplicationProtections;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return result;
|
|
1793
1029
|
},
|
|
1794
1030
|
/**
|
|
1795
1031
|
* @param {object} client
|
|
1796
1032
|
* @param {string} instrumentationId
|
|
1797
1033
|
* @returns {Promise<object>}
|
|
1798
1034
|
*/
|
|
1799
|
-
|
|
1800
|
-
return
|
|
1801
|
-
return _regeneratorRuntime().wrap(function _callee42$(_context42) {
|
|
1802
|
-
while (1) {
|
|
1803
|
-
switch (_context42.prev = _context42.next) {
|
|
1804
|
-
case 0:
|
|
1805
|
-
return _context42.abrupt("return", client.get("/profiling-run/".concat(instrumentationId)));
|
|
1806
|
-
case 1:
|
|
1807
|
-
case "end":
|
|
1808
|
-
return _context42.stop();
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
}, _callee42);
|
|
1812
|
-
}))();
|
|
1035
|
+
async getInstrumentation(client, instrumentationId) {
|
|
1036
|
+
return client.get("/profiling-run/".concat(instrumentationId));
|
|
1813
1037
|
},
|
|
1814
1038
|
//
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
return _regeneratorRuntime().wrap(function _callee43$(_context43) {
|
|
1819
|
-
while (1) {
|
|
1820
|
-
switch (_context43.prev = _context43.next) {
|
|
1821
|
-
case 0:
|
|
1822
|
-
_context43.next = 2;
|
|
1823
|
-
return queries.getProtection(applicationId, protectionId, fragments);
|
|
1824
|
-
case 2:
|
|
1825
|
-
query = _context43.sent;
|
|
1826
|
-
return _context43.abrupt("return", client.get('/application', query));
|
|
1827
|
-
case 4:
|
|
1828
|
-
case "end":
|
|
1829
|
-
return _context43.stop();
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}, _callee43);
|
|
1833
|
-
}))();
|
|
1039
|
+
async getApplicationProtection(client, applicationId, protectionId, fragments) {
|
|
1040
|
+
const query = await queries.getProtection(applicationId, protectionId, fragments);
|
|
1041
|
+
return client.get('/application', query);
|
|
1834
1042
|
},
|
|
1835
1043
|
//
|
|
1836
|
-
|
|
1837
|
-
return
|
|
1838
|
-
return _regeneratorRuntime().wrap(function _callee44$(_context44) {
|
|
1839
|
-
while (1) {
|
|
1840
|
-
switch (_context44.prev = _context44.next) {
|
|
1841
|
-
case 0:
|
|
1842
|
-
return _context44.abrupt("return", client.get("/application/sourceMaps/".concat(protectionId), null, false));
|
|
1843
|
-
case 1:
|
|
1844
|
-
case "end":
|
|
1845
|
-
return _context44.stop();
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
}, _callee44);
|
|
1849
|
-
}))();
|
|
1044
|
+
async downloadSourceMapsRequest(client, protectionId) {
|
|
1045
|
+
return client.get("/application/sourceMaps/".concat(protectionId), null, false);
|
|
1850
1046
|
},
|
|
1851
|
-
|
|
1852
|
-
return
|
|
1853
|
-
return _regeneratorRuntime().wrap(function _callee45$(_context45) {
|
|
1854
|
-
while (1) {
|
|
1855
|
-
switch (_context45.prev = _context45.next) {
|
|
1856
|
-
case 0:
|
|
1857
|
-
return _context45.abrupt("return", client.get("/application/symbolTable/".concat(protectionId), null, false));
|
|
1858
|
-
case 1:
|
|
1859
|
-
case "end":
|
|
1860
|
-
return _context45.stop();
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
}, _callee45);
|
|
1864
|
-
}))();
|
|
1047
|
+
async downloadSymbolTableRequest(client, protectionId) {
|
|
1048
|
+
return client.get("/application/symbolTable/".concat(protectionId), null, false);
|
|
1865
1049
|
},
|
|
1866
1050
|
//
|
|
1867
|
-
|
|
1868
|
-
return
|
|
1869
|
-
return _regeneratorRuntime().wrap(function _callee46$(_context46) {
|
|
1870
|
-
while (1) {
|
|
1871
|
-
switch (_context46.prev = _context46.next) {
|
|
1872
|
-
case 0:
|
|
1873
|
-
return _context46.abrupt("return", client.get("/application/download/".concat(protectionId), null, false));
|
|
1874
|
-
case 1:
|
|
1875
|
-
case "end":
|
|
1876
|
-
return _context46.stop();
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
}, _callee46);
|
|
1880
|
-
}))();
|
|
1051
|
+
async downloadApplicationProtection(client, protectionId) {
|
|
1052
|
+
return client.get("/application/download/".concat(protectionId), null, false);
|
|
1881
1053
|
},
|
|
1882
1054
|
/**
|
|
1883
1055
|
* @param {object} client
|
|
1884
1056
|
* @param {string} instrumentationId
|
|
1885
1057
|
* @returns {*}
|
|
1886
1058
|
*/
|
|
1887
|
-
downloadApplicationInstrumented
|
|
1059
|
+
downloadApplicationInstrumented(client, instrumentationId) {
|
|
1888
1060
|
return client.get("/profiling-run/".concat(instrumentationId, "/instrumented-bundle"), null, false);
|
|
1889
1061
|
},
|
|
1890
1062
|
/**
|
|
@@ -1895,50 +1067,23 @@ var _default = {
|
|
|
1895
1067
|
* @param {String} field args field to introspect
|
|
1896
1068
|
* @returns {Boolean} true if the field is supported, false otherwise
|
|
1897
1069
|
*/
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
return instrospectionType(client, methodName);
|
|
1910
|
-
case 4:
|
|
1911
|
-
result = _context47.sent;
|
|
1912
|
-
if (!(!result || !result.args)) {
|
|
1913
|
-
_context47.next = 8;
|
|
1914
|
-
break;
|
|
1915
|
-
}
|
|
1916
|
-
debug && console.log("Method *".concat(methodName, "* not found."));
|
|
1917
|
-
return _context47.abrupt("return", false);
|
|
1918
|
-
case 8:
|
|
1919
|
-
dataArg = result.args.find(function (arg) {
|
|
1920
|
-
return arg.name === 'data';
|
|
1921
|
-
});
|
|
1922
|
-
isFieldSupported = dataArg && dataArg.type.inputFields.some(function (e) {
|
|
1923
|
-
return e.name === field;
|
|
1924
|
-
});
|
|
1925
|
-
return _context47.abrupt("return", isFieldSupported);
|
|
1926
|
-
case 11:
|
|
1927
|
-
case "end":
|
|
1928
|
-
return _context47.stop();
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
}, _callee47);
|
|
1932
|
-
}))();
|
|
1070
|
+
async introspectFieldOnMethod(config, queryOrMutation, methodName, field) {
|
|
1071
|
+
const instrospectionType = queryOrMutation.toLowerCase() === 'mutation' ? introspection.mutation : introspection.query;
|
|
1072
|
+
const client = new this.Client(_objectSpread({}, config));
|
|
1073
|
+
const result = await instrospectionType(client, methodName);
|
|
1074
|
+
if (!result || !result.args) {
|
|
1075
|
+
debug && console.log("Method *".concat(methodName, "* not found."));
|
|
1076
|
+
return false;
|
|
1077
|
+
}
|
|
1078
|
+
const dataArg = result.args.find(arg => arg.name === 'data');
|
|
1079
|
+
const isFieldSupported = dataArg && dataArg.type.inputFields.some(e => e.name === field);
|
|
1080
|
+
return isFieldSupported;
|
|
1933
1081
|
}
|
|
1934
1082
|
};
|
|
1935
|
-
exports.default = _default;
|
|
1936
1083
|
function getFileFromUrl(client, url) {
|
|
1937
|
-
return _axios.default.get(url).then(
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
};
|
|
1943
|
-
});
|
|
1084
|
+
return _axios.default.get(url).then(res => ({
|
|
1085
|
+
content: res.data,
|
|
1086
|
+
filename: _path.default.basename(url),
|
|
1087
|
+
extension: _path.default.extname(url).substr(1)
|
|
1088
|
+
}));
|
|
1944
1089
|
}
|