jscrambler 6.4.21 → 6.4.24
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 +20 -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 +40 -98
- package/dist/index.js +823 -1690
- 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,28 +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;
|
|
45
|
-
var MAX_PRINTED_ERRORS = 3;
|
|
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;
|
|
46
41
|
|
|
47
42
|
/**
|
|
48
43
|
* Calculate polling interval for protection and instrumentation.
|
|
@@ -51,19 +46,17 @@ var MAX_PRINTED_ERRORS = 3;
|
|
|
51
46
|
* @returns {number|number}
|
|
52
47
|
*/
|
|
53
48
|
function getPollingInterval(start) {
|
|
54
|
-
|
|
49
|
+
const pollingInterval = POLLING_MIN_INTERVAL * Math.ceil((Date.now() - start) / INCREASE_POLL_INTERVAL_EVERY);
|
|
55
50
|
return pollingInterval >= POLLING_MAX_INTERVAL ? POLLING_MAX_INTERVAL : pollingInterval;
|
|
56
51
|
}
|
|
57
52
|
function errorHandler(res) {
|
|
58
53
|
if (res.errors && res.errors.length) {
|
|
59
|
-
res.errors.forEach(
|
|
54
|
+
res.errors.forEach(error => {
|
|
60
55
|
throw new Error("Error: ".concat(error.message));
|
|
61
56
|
});
|
|
62
57
|
}
|
|
63
58
|
if (res.data && res.data.errors) {
|
|
64
|
-
res.data.errors.forEach(
|
|
65
|
-
return console.error(e.message);
|
|
66
|
-
});
|
|
59
|
+
res.data.errors.forEach(e => console.error(e.message));
|
|
67
60
|
throw new Error('GraphQL Query Error');
|
|
68
61
|
}
|
|
69
62
|
if (res.message) {
|
|
@@ -73,11 +66,11 @@ function errorHandler(res) {
|
|
|
73
66
|
}
|
|
74
67
|
function printSourcesErrors(errors) {
|
|
75
68
|
console.error('Source errors:');
|
|
76
|
-
for (
|
|
77
|
-
|
|
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 + ': ' : ': ';
|
|
78
71
|
console.error('- ' + errors[i].filename + sourceErrorsMessage + errors[i].message);
|
|
79
72
|
}
|
|
80
|
-
|
|
73
|
+
const errorsLeft = errors.length - MAX_PRINTED_ERRORS;
|
|
81
74
|
if (errorsLeft > 0) {
|
|
82
75
|
if (errorsLeft === 1) {
|
|
83
76
|
console.error('There is 1 more error.');
|
|
@@ -88,12 +81,12 @@ function printSourcesErrors(errors) {
|
|
|
88
81
|
console.error();
|
|
89
82
|
}
|
|
90
83
|
function normalizeParameters(parameters) {
|
|
91
|
-
|
|
84
|
+
let result;
|
|
92
85
|
if (!Array.isArray(parameters)) {
|
|
93
86
|
result = [];
|
|
94
|
-
Object.keys(parameters).forEach(
|
|
87
|
+
Object.keys(parameters).forEach(name => {
|
|
95
88
|
result.push({
|
|
96
|
-
name
|
|
89
|
+
name,
|
|
97
90
|
options: parameters[name]
|
|
98
91
|
});
|
|
99
92
|
});
|
|
@@ -103,13 +96,13 @@ function normalizeParameters(parameters) {
|
|
|
103
96
|
return result;
|
|
104
97
|
}
|
|
105
98
|
function buildFinalConfig(configPathOrObject) {
|
|
106
|
-
|
|
99
|
+
const _config = typeof configPathOrObject === 'string' ? require(configPathOrObject) : configPathOrObject;
|
|
107
100
|
return (0, _lodash.default)(_config, _config2.default);
|
|
108
101
|
}
|
|
109
|
-
var _default = {
|
|
102
|
+
var _default = exports.default = {
|
|
110
103
|
Client: _client.default,
|
|
111
104
|
config: _config2.default,
|
|
112
|
-
queries
|
|
105
|
+
queries,
|
|
113
106
|
generateSignedParams: _generateSignedParams.default,
|
|
114
107
|
/**
|
|
115
108
|
* Remove and Add application sources
|
|
@@ -123,103 +116,62 @@ var _default = {
|
|
|
123
116
|
* }} opts
|
|
124
117
|
* @returns {Promise<{extension: string, filename: string, content: *}>}
|
|
125
118
|
*/
|
|
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
|
-
case 8:
|
|
151
|
-
if (!(filesSrc && filesSrc.length)) {
|
|
152
|
-
_context.next = 17;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
_filesSrc = [];
|
|
156
|
-
for (i = 0, l = filesSrc.length; i < l; i += 1) {
|
|
157
|
-
if (typeof filesSrc[i] === 'string') {
|
|
158
|
-
_filesSrc = _filesSrc.concat((0, _utils.getMatchedFiles)(filesSrc[i]));
|
|
159
|
-
} else {
|
|
160
|
-
_filesSrc.push(filesSrc[i]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (debug) {
|
|
164
|
-
console.log('Creating zip from source files');
|
|
165
|
-
}
|
|
166
|
-
_context.next = 14;
|
|
167
|
-
return (0, _zip.zip)(_filesSrc, cwd);
|
|
168
|
-
case 14:
|
|
169
|
-
zipped = _context.sent;
|
|
170
|
-
_context.next = 22;
|
|
171
|
-
break;
|
|
172
|
-
case 17:
|
|
173
|
-
if (!sources) {
|
|
174
|
-
_context.next = 22;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
if (debug) {
|
|
178
|
-
console.log('Creating zip from sources');
|
|
179
|
-
}
|
|
180
|
-
_context.next = 21;
|
|
181
|
-
return (0, _zip.zipSources)(sources);
|
|
182
|
-
case 21:
|
|
183
|
-
zipped = _context.sent;
|
|
184
|
-
case 22:
|
|
185
|
-
if (!zipped) {
|
|
186
|
-
_context.next = 33;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
_context.next = 25;
|
|
190
|
-
return zipped.generateAsync({
|
|
191
|
-
type: 'base64',
|
|
192
|
-
compression: 'DEFLATE',
|
|
193
|
-
compressionOptions: {
|
|
194
|
-
// 1 - 9 (max compression)
|
|
195
|
-
level: 5
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
case 25:
|
|
199
|
-
content = _context.sent;
|
|
200
|
-
if (debug) {
|
|
201
|
-
console.log('Adding sources to application');
|
|
202
|
-
}
|
|
203
|
-
source = {
|
|
204
|
-
content: content,
|
|
205
|
-
filename: 'application.zip',
|
|
206
|
-
extension: 'zip'
|
|
207
|
-
};
|
|
208
|
-
_context.t0 = errorHandler;
|
|
209
|
-
_context.next = 31;
|
|
210
|
-
return _this.addApplicationSource(client, applicationId, source);
|
|
211
|
-
case 31:
|
|
212
|
-
_context.t1 = _context.sent;
|
|
213
|
-
(0, _context.t0)(_context.t1);
|
|
214
|
-
case 33:
|
|
215
|
-
return _context.abrupt("return", source);
|
|
216
|
-
case 34:
|
|
217
|
-
case "end":
|
|
218
|
-
return _context.stop();
|
|
219
|
-
}
|
|
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]);
|
|
220
143
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
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
|
|
162
|
+
}
|
|
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;
|
|
223
175
|
},
|
|
224
176
|
// This method is a shortcut method that accepts an object with everything needed
|
|
225
177
|
// for the entire process of requesting an application protection and downloading
|
|
@@ -264,379 +216,275 @@ var _default = {
|
|
|
264
216
|
// endpoint than the default one, useful if you're running an enterprise version of
|
|
265
217
|
// Jscrambler or if you're provided access to beta features of our product.
|
|
266
218
|
//
|
|
267
|
-
|
|
268
|
-
var
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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.');
|
|
339
303
|
}
|
|
340
|
-
_context4.next = 20;
|
|
341
|
-
return _this2.deleteProfiling(client, appProfiling.data.id);
|
|
342
|
-
case 20:
|
|
343
|
-
appProfiling.data.state = 'DELETED';
|
|
344
|
-
case 21:
|
|
345
|
-
_context4.next = 23;
|
|
346
|
-
return _this2.updateApplicationSources(client, applicationId, {
|
|
347
|
-
sources: sources,
|
|
348
|
-
filesSrc: filesSrc,
|
|
349
|
-
cwd: cwd,
|
|
350
|
-
appProfiling: appProfiling
|
|
351
|
-
});
|
|
352
|
-
case 23:
|
|
353
|
-
source = _context4.sent;
|
|
354
|
-
_context4.next = 27;
|
|
355
304
|
break;
|
|
356
|
-
case
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
updateData = {
|
|
360
|
-
debugMode: !!debugMode,
|
|
361
|
-
tolerateMinification: tolerateMinification,
|
|
362
|
-
codeHardeningThreshold: codeHardeningThreshold
|
|
363
|
-
};
|
|
364
|
-
if (params && Object.keys(params).length) {
|
|
365
|
-
updateData.parameters = normalizeParameters(params);
|
|
366
|
-
updateData.areSubscribersOrdered = Array.isArray(params);
|
|
367
|
-
}
|
|
368
|
-
dataToValidate = {
|
|
369
|
-
applicationTypes: applicationTypes,
|
|
370
|
-
areSubscribersOrdered: areSubscribersOrdered,
|
|
371
|
-
browsers: browsers,
|
|
372
|
-
languageSpecifications: languageSpecifications,
|
|
373
|
-
profilingDataMode: profilingDataMode,
|
|
374
|
-
sourceMaps: sourceMaps,
|
|
375
|
-
useAppClassification: useAppClassification,
|
|
376
|
-
ensureCodeAnnotation: ensureCodeAnnotation,
|
|
377
|
-
useProfilingData: useProfilingData,
|
|
378
|
-
useRecommendedOrder: useRecommendedOrder
|
|
379
|
-
};
|
|
380
|
-
for (prop in dataToValidate) {
|
|
381
|
-
value = dataToValidate[prop];
|
|
382
|
-
if (typeof value !== 'undefined') {
|
|
383
|
-
updateData[prop] = value;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (!(updateData.parameters || updateData.applicationTypes || updateData.languageSpecifications || updateData.browsers || typeof updateData.areSubscribersOrdered !== 'undefined')) {
|
|
387
|
-
_context4.next = 41;
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
if (debug) {
|
|
391
|
-
console.log('Updating parameters of protection');
|
|
392
|
-
}
|
|
393
|
-
_context4.next = 35;
|
|
394
|
-
return intoObjectType(client, updateData, 'ApplicationUpdate');
|
|
395
|
-
case 35:
|
|
396
|
-
applicationUpdate = _context4.sent;
|
|
397
|
-
_context4.next = 38;
|
|
398
|
-
return _this2.updateApplication(client, applicationUpdate, undefined, applicationId);
|
|
399
|
-
case 38:
|
|
400
|
-
updateApplicationRes = _context4.sent;
|
|
401
|
-
if (debug) {
|
|
402
|
-
console.log('Finished updating parameters of protection');
|
|
403
|
-
console.error(updateApplicationRes);
|
|
404
|
-
}
|
|
405
|
-
errorHandler(updateApplicationRes);
|
|
406
|
-
case 41:
|
|
407
|
-
if (debug) {
|
|
408
|
-
console.log('Creating Application Protection');
|
|
409
|
-
}
|
|
410
|
-
protectionOptions = _objectSpread(_objectSpread({}, updateData), {}, {
|
|
411
|
-
bail: bail,
|
|
412
|
-
entryPoint: entryPoint,
|
|
413
|
-
excludeList: excludeList,
|
|
414
|
-
inputSymbolTable: inputSymbolTable,
|
|
415
|
-
randomizationSeed: randomizationSeed,
|
|
416
|
-
source: source,
|
|
417
|
-
tolerateMinification: tolerateMinification,
|
|
418
|
-
numberOfProtections: numberOfProtections,
|
|
419
|
-
forceAppEnvironment: forceAppEnvironment
|
|
420
|
-
});
|
|
421
|
-
if (finalConfig.inputSymbolTable) {
|
|
422
|
-
// Note: we can not use the fs.promises API because some users may not have node 10.
|
|
423
|
-
// Once node 10 is old enough to be safe to assume that all users will have it, this
|
|
424
|
-
// should be safe to replace with `await fs.promises.readFile`.
|
|
425
|
-
inputSymbolTableContents = _fs.default.readFileSync(finalConfig.inputSymbolTable, 'utf-8');
|
|
426
|
-
protectionOptions.inputSymbolTable = inputSymbolTableContents;
|
|
305
|
+
case _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE:
|
|
306
|
+
if (profilingDataMode === 'automatic') {
|
|
307
|
+
throw e;
|
|
427
308
|
}
|
|
428
|
-
_context4.next = 46;
|
|
429
|
-
return _this2.createApplicationProtections(client, applicationId, protectionOptions);
|
|
430
|
-
case 46:
|
|
431
|
-
createApplicationProtectionRes = _context4.sent;
|
|
432
|
-
errorHandler(createApplicationProtectionRes);
|
|
433
|
-
protectionIds = createApplicationProtectionRes.data.protections.map(function (_ref2) {
|
|
434
|
-
var _id = _ref2._id;
|
|
435
|
-
return _id;
|
|
436
|
-
});
|
|
437
|
-
onExitCancelProtection = /*#__PURE__*/function () {
|
|
438
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
439
|
-
var i, protectionId;
|
|
440
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
441
|
-
while (1) {
|
|
442
|
-
switch (_context2.prev = _context2.next) {
|
|
443
|
-
case 0:
|
|
444
|
-
i = 0;
|
|
445
|
-
case 1:
|
|
446
|
-
if (!(i < protectionIds.length)) {
|
|
447
|
-
_context2.next = 15;
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
protectionId = protectionIds[i];
|
|
451
|
-
_context2.prev = 3;
|
|
452
|
-
_context2.next = 6;
|
|
453
|
-
return _this2.cancelProtection(client, protectionId, applicationId);
|
|
454
|
-
case 6:
|
|
455
|
-
console.log('** Protection %s WAS CANCELLED **', protectionId);
|
|
456
|
-
_context2.next = 12;
|
|
457
|
-
break;
|
|
458
|
-
case 9:
|
|
459
|
-
_context2.prev = 9;
|
|
460
|
-
_context2.t0 = _context2["catch"](3);
|
|
461
|
-
if (debug) {
|
|
462
|
-
console.error(_context2.t0);
|
|
463
|
-
}
|
|
464
|
-
case 12:
|
|
465
|
-
i++;
|
|
466
|
-
_context2.next = 1;
|
|
467
|
-
break;
|
|
468
|
-
case 15:
|
|
469
|
-
process.exit(1);
|
|
470
|
-
case 16:
|
|
471
|
-
case "end":
|
|
472
|
-
return _context2.stop();
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}, _callee2, null, [[3, 9]]);
|
|
476
|
-
}));
|
|
477
|
-
return function onExitCancelProtection() {
|
|
478
|
-
return _ref3.apply(this, arguments);
|
|
479
|
-
};
|
|
480
|
-
}();
|
|
481
|
-
process.once('SIGINT', onExitCancelProtection).once('SIGTERM', onExitCancelProtection);
|
|
482
|
-
_context4.t0 = _this2;
|
|
483
|
-
_context4.t1 = client;
|
|
484
|
-
_context4.t2 = applicationId;
|
|
485
|
-
_context4.t3 = protectionIds;
|
|
486
|
-
_context4.next = 57;
|
|
487
|
-
return (0, _getProtectionDefaultFragments.default)(client);
|
|
488
|
-
case 57:
|
|
489
|
-
_context4.t4 = _context4.sent;
|
|
490
|
-
_context4.next = 60;
|
|
491
|
-
return _context4.t0.pollProtections.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3, _context4.t4);
|
|
492
|
-
case 60:
|
|
493
|
-
processedProtections = _context4.sent;
|
|
494
|
-
process.removeListener('SIGINT', onExitCancelProtection).removeListener('SIGTERM', onExitCancelProtection);
|
|
495
|
-
handleProtection = /*#__PURE__*/function () {
|
|
496
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(protection) {
|
|
497
|
-
var _ref5,
|
|
498
|
-
_ref5$outPrefix,
|
|
499
|
-
outPrefix,
|
|
500
|
-
_ref5$printProtection,
|
|
501
|
-
printProtectionId,
|
|
502
|
-
sourcesErrors,
|
|
503
|
-
download,
|
|
504
|
-
_args3 = arguments;
|
|
505
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
506
|
-
while (1) {
|
|
507
|
-
switch (_context3.prev = _context3.next) {
|
|
508
|
-
case 0:
|
|
509
|
-
_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;
|
|
510
|
-
if (protection.growthWarning) {
|
|
511
|
-
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, "."));
|
|
512
|
-
}
|
|
513
|
-
if (protection.hasForcedDateLock) {
|
|
514
|
-
console.warn("Warning: Since your plan is a Trial, your protected files will stop working on ".concat(protection.parameters.find(function (p) {
|
|
515
|
-
return p.name === 'dateLock' && p.options.endDate;
|
|
516
|
-
}).options.endDate));
|
|
517
|
-
}
|
|
518
|
-
if (debug) {
|
|
519
|
-
console.log('Finished protecting');
|
|
520
|
-
}
|
|
521
|
-
if (protection.deprecations) {
|
|
522
|
-
protection.deprecations.forEach(function (deprecation) {
|
|
523
|
-
if (deprecation.type === 'Transformation') {
|
|
524
|
-
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is no longer maintained. Please consider removing it from your configuration."));
|
|
525
|
-
} else if (deprecation.type && deprecation.entity) {
|
|
526
|
-
console.warn("Warning: ".concat(deprecation.type, " ").concat(deprecation.entity, " is deprecated."));
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
sourcesErrors = [];
|
|
531
|
-
protection.sources.forEach(function (s) {
|
|
532
|
-
if (s.isSource && s.errorMessages && s.errorMessages.length > 0) {
|
|
533
|
-
sourcesErrors.push.apply(sourcesErrors, _toConsumableArray(s.errorMessages.map(function (e) {
|
|
534
|
-
return _objectSpread({
|
|
535
|
-
filename: s.filename
|
|
536
|
-
}, e);
|
|
537
|
-
})));
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
if (!(protection.state === 'errored')) {
|
|
541
|
-
_context3.next = 15;
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
console.error('Global protection errors:');
|
|
545
|
-
console.error("- ".concat(protection.errorMessage));
|
|
546
|
-
console.error('');
|
|
547
|
-
if (sourcesErrors.length > 0) {
|
|
548
|
-
printSourcesErrors(sourcesErrors);
|
|
549
|
-
}
|
|
550
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
551
|
-
case 15:
|
|
552
|
-
if (!(sourcesErrors.length > 0)) {
|
|
553
|
-
_context3.next = 22;
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
if (!protection.bail) {
|
|
557
|
-
_context3.next = 21;
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
printSourcesErrors(sourcesErrors);
|
|
561
|
-
throw new Error('Your protection has failed.');
|
|
562
|
-
case 21:
|
|
563
|
-
sourcesErrors.forEach(function (e) {
|
|
564
|
-
return console.warn("Non-fatal error: \"".concat(e.message, "\" in ").concat(e.filename));
|
|
565
|
-
});
|
|
566
|
-
case 22:
|
|
567
|
-
if (debug) {
|
|
568
|
-
console.log('Downloading protection result');
|
|
569
|
-
}
|
|
570
|
-
_context3.next = 25;
|
|
571
|
-
return _this2.downloadApplicationProtection(client, protection._id);
|
|
572
|
-
case 25:
|
|
573
|
-
download = _context3.sent;
|
|
574
|
-
errorHandler(download);
|
|
575
|
-
if (debug) {
|
|
576
|
-
console.log('Unzipping files');
|
|
577
|
-
}
|
|
578
|
-
_context3.next = 30;
|
|
579
|
-
return (0, _zip.unzip)(download, (filesDest ? "".concat(filesDest).concat(outPrefix) : filesDest) || destCallback, stream);
|
|
580
|
-
case 30:
|
|
581
|
-
if (debug) {
|
|
582
|
-
console.log('Finished unzipping files');
|
|
583
|
-
}
|
|
584
|
-
if (printProtectionId) {
|
|
585
|
-
console.log(protection._id);
|
|
586
|
-
}
|
|
587
|
-
return _context3.abrupt("return", protection._id);
|
|
588
|
-
case 33:
|
|
589
|
-
case "end":
|
|
590
|
-
return _context3.stop();
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}, _callee3);
|
|
594
|
-
}));
|
|
595
|
-
return function handleProtection(_x) {
|
|
596
|
-
return _ref4.apply(this, arguments);
|
|
597
|
-
};
|
|
598
|
-
}();
|
|
599
|
-
if (!(processedProtections.length === 1)) {
|
|
600
|
-
_context4.next = 65;
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
return _context4.abrupt("return", handleProtection(processedProtections[0]));
|
|
604
|
-
case 65:
|
|
605
|
-
console.log("Protections stored in ".concat(filesDest, "/[protection-id]"));
|
|
606
|
-
i = 0;
|
|
607
|
-
case 67:
|
|
608
|
-
if (!(i < processedProtections.length)) {
|
|
609
|
-
_context4.next = 80;
|
|
610
|
-
break;
|
|
611
|
-
}
|
|
612
|
-
protection = processedProtections[i];
|
|
613
|
-
_context4.prev = 69;
|
|
614
|
-
_context4.next = 72;
|
|
615
|
-
return handleProtection(protection, {
|
|
616
|
-
outPrefix: "/".concat(protection._id, "/"),
|
|
617
|
-
printProtectionId: false
|
|
618
|
-
});
|
|
619
|
-
case 72:
|
|
620
|
-
_context4.next = 77;
|
|
621
|
-
break;
|
|
622
|
-
case 74:
|
|
623
|
-
_context4.prev = 74;
|
|
624
|
-
_context4.t5 = _context4["catch"](69);
|
|
625
|
-
console.error(_context4.t5);
|
|
626
|
-
case 77:
|
|
627
|
-
i++;
|
|
628
|
-
_context4.next = 67;
|
|
629
|
-
break;
|
|
630
|
-
case 80:
|
|
631
|
-
console.log("Runtime: ".concat(processedProtections.length, " protections in ").concat(Math.round((Date.now() - start) / 1000), "s"));
|
|
632
|
-
return _context4.abrupt("return", protectionIds);
|
|
633
|
-
case 82:
|
|
634
|
-
case "end":
|
|
635
|
-
return _context4.stop();
|
|
636
309
|
}
|
|
637
310
|
}
|
|
638
|
-
}
|
|
639
|
-
|
|
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;
|
|
640
488
|
},
|
|
641
489
|
/**
|
|
642
490
|
* Instrument and download application sources for profiling purposes
|
|
@@ -644,112 +492,90 @@ var _default = {
|
|
|
644
492
|
* @param {function} [destCallback]
|
|
645
493
|
* @returns {Promise<string>}
|
|
646
494
|
*/
|
|
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
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
case 30:
|
|
732
|
-
download = _context5.sent;
|
|
733
|
-
errorHandler(download);
|
|
734
|
-
if (debug) {
|
|
735
|
-
console.log('Unzipping files');
|
|
736
|
-
}
|
|
737
|
-
_context5.next = 35;
|
|
738
|
-
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
739
|
-
case 35:
|
|
740
|
-
if (debug) {
|
|
741
|
-
console.log('Finished unzipping files');
|
|
742
|
-
}
|
|
743
|
-
console.warn("\n WARNING: DO NOT SEND THIS CODE TO PRODUCTION AS IT IS NOT PROTECTED\n ");
|
|
744
|
-
console.log("Application ".concat(applicationId, " was instrumented. Bootstrap your instrumented application and run *--start-profiling* command."));
|
|
745
|
-
return _context5.abrupt("return", instrumentation.data.id);
|
|
746
|
-
case 39:
|
|
747
|
-
case "end":
|
|
748
|
-
return _context5.stop();
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}, _callee5);
|
|
752
|
-
}))();
|
|
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;
|
|
753
579
|
},
|
|
754
580
|
/**
|
|
755
581
|
* Change the profiling run stat.
|
|
@@ -759,186 +585,157 @@ var _default = {
|
|
|
759
585
|
* @param {string} nextStepMessage
|
|
760
586
|
* @returns {Promise<string>} The previous state
|
|
761
587
|
*/
|
|
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
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
});
|
|
812
|
-
case 15:
|
|
813
|
-
console.log("Profiling was ".concat(label, " for application ").concat(applicationId, ". ").concat(nextStepMessage));
|
|
814
|
-
case 16:
|
|
815
|
-
case "end":
|
|
816
|
-
return _context6.stop();
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}, _callee6);
|
|
820
|
-
}))();
|
|
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));
|
|
821
637
|
},
|
|
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
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
case 17:
|
|
871
|
-
_context7.next = 19;
|
|
872
|
-
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
873
|
-
case 19:
|
|
874
|
-
case "end":
|
|
875
|
-
return _context7.stop();
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}, _callee7, null, [[8, 14]]);
|
|
879
|
-
}))();
|
|
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);
|
|
880
686
|
},
|
|
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
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
(0, _zip.outputFileSync)(_path.default.join(filesDest, "".concat(protectionId, "_symbolTable.json")), download);
|
|
934
|
-
}
|
|
935
|
-
case 18:
|
|
936
|
-
case "end":
|
|
937
|
-
return _context8.stop();
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
}, _callee8, null, [[8, 14]]);
|
|
941
|
-
}))();
|
|
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
|
+
}
|
|
942
739
|
},
|
|
943
740
|
/**
|
|
944
741
|
* Polls a instrumentation every POLLING_INTERVALms until the state be equal to
|
|
@@ -948,731 +745,227 @@ var _default = {
|
|
|
948
745
|
* @returns {Promise<object>}
|
|
949
746
|
* @throws {Error} due to errors in instrumentation process or user cancel the operation
|
|
950
747
|
*/
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
_context9.t0 = instrumentation.data.state;
|
|
972
|
-
_context9.next = _context9.t0 === 'DELETED' ? 6 : _context9.t0 === 'FAILED_INSTRUMENTATION' ? 7 : _context9.t0 === 'FINISHED_INSTRUMENTATION' ? 9 : 10;
|
|
973
|
-
break;
|
|
974
|
-
case 6:
|
|
975
|
-
throw new Error('Protection canceled by user');
|
|
976
|
-
case 7:
|
|
977
|
-
instrumentation.errors = instrumentation.errors.concat(instrumentation.data.instrumentationErrors.map(function (e) {
|
|
978
|
-
return {
|
|
979
|
-
message: "".concat(e.message, " at ").concat(e.fileName, ":").concat(e.lineNumber)
|
|
980
|
-
};
|
|
981
|
-
}));
|
|
982
|
-
return _context9.abrupt("return", errorHandler(instrumentation));
|
|
983
|
-
case 9:
|
|
984
|
-
return _context9.abrupt("return", instrumentation);
|
|
985
|
-
case 10:
|
|
986
|
-
_context9.next = 12;
|
|
987
|
-
return new Promise(function (resolve) {
|
|
988
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
989
|
-
});
|
|
990
|
-
case 12:
|
|
991
|
-
return _context9.abrupt("return", poll());
|
|
992
|
-
case 13:
|
|
993
|
-
case "end":
|
|
994
|
-
return _context9.stop();
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}, _callee9);
|
|
998
|
-
}));
|
|
999
|
-
return function poll() {
|
|
1000
|
-
return _ref6.apply(this, arguments);
|
|
1001
|
-
};
|
|
1002
|
-
}();
|
|
1003
|
-
return _context10.abrupt("return", poll());
|
|
1004
|
-
case 3:
|
|
1005
|
-
case "end":
|
|
1006
|
-
return _context10.stop();
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
}, _callee10);
|
|
1010
|
-
}))();
|
|
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();
|
|
1011
768
|
},
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
_context11.prev = 7;
|
|
1028
|
-
_context11.t0 = _context11["catch"](1);
|
|
1029
|
-
if (!(retriesLeft <= 0)) {
|
|
1030
|
-
_context11.next = 11;
|
|
1031
|
-
break;
|
|
1032
|
-
}
|
|
1033
|
-
throw _context11.t0;
|
|
1034
|
-
case 11:
|
|
1035
|
-
if (!(_context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.SERVICE_UNAVAILABLE && _context11.t0.statusCode !== _constants.HTTP_STATUS_CODES.GATEWAY_TIMEOUT)) {
|
|
1036
|
-
_context11.next = 13;
|
|
1037
|
-
break;
|
|
1038
|
-
}
|
|
1039
|
-
throw _context11.t0;
|
|
1040
|
-
case 13:
|
|
1041
|
-
// Retry
|
|
1042
|
-
if (debug) {
|
|
1043
|
-
console.log('Retrying request');
|
|
1044
|
-
}
|
|
1045
|
-
retriesLeft--;
|
|
1046
|
-
case 15:
|
|
1047
|
-
_context11.next = 1;
|
|
1048
|
-
break;
|
|
1049
|
-
case 17:
|
|
1050
|
-
case "end":
|
|
1051
|
-
return _context11.stop();
|
|
1052
|
-
}
|
|
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;
|
|
780
|
+
}
|
|
781
|
+
// Retry
|
|
782
|
+
if (debug) {
|
|
783
|
+
console.log('Retrying request');
|
|
1053
784
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
785
|
+
retriesLeft--;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
1056
788
|
},
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
return _this8.getApplicationProtection(client, applicationId, protectionId, fragments);
|
|
1076
|
-
});
|
|
1077
|
-
case 2:
|
|
1078
|
-
applicationProtection = _context12.sent;
|
|
1079
|
-
if (!applicationProtection.errors) {
|
|
1080
|
-
_context12.next = 8;
|
|
1081
|
-
break;
|
|
1082
|
-
}
|
|
1083
|
-
console.log('Error polling protection', applicationProtection.errors);
|
|
1084
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
1085
|
-
case 8:
|
|
1086
|
-
state = applicationProtection.data.applicationProtection.state;
|
|
1087
|
-
if (!(state !== 'finished' && state !== 'errored' && state !== 'canceled')) {
|
|
1088
|
-
_context12.next = 15;
|
|
1089
|
-
break;
|
|
1090
|
-
}
|
|
1091
|
-
_context12.next = 12;
|
|
1092
|
-
return new Promise(function (resolve) {
|
|
1093
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
1094
|
-
});
|
|
1095
|
-
case 12:
|
|
1096
|
-
return _context12.abrupt("return", poll());
|
|
1097
|
-
case 15:
|
|
1098
|
-
if (!(state === 'canceled')) {
|
|
1099
|
-
_context12.next = 19;
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
throw new Error('Protection canceled by user');
|
|
1103
|
-
case 19:
|
|
1104
|
-
return _context12.abrupt("return", applicationProtection.data.applicationProtection);
|
|
1105
|
-
case 20:
|
|
1106
|
-
case "end":
|
|
1107
|
-
return _context12.stop();
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
}, _callee12);
|
|
1111
|
-
}));
|
|
1112
|
-
return function poll() {
|
|
1113
|
-
return _ref7.apply(this, arguments);
|
|
1114
|
-
};
|
|
1115
|
-
}();
|
|
1116
|
-
return _context13.abrupt("return", poll());
|
|
1117
|
-
case 3:
|
|
1118
|
-
case "end":
|
|
1119
|
-
return _context13.stop();
|
|
1120
|
-
}
|
|
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;
|
|
1121
807
|
}
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
return poll();
|
|
1124
811
|
},
|
|
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
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
throw new Error("Protection failed. For more information visit: ".concat(APP_URL, "."));
|
|
1166
|
-
case 8:
|
|
1167
|
-
ended = applicationProtections.data.applicationProtections.filter(function (_ref9) {
|
|
1168
|
-
var state = _ref9.state;
|
|
1169
|
-
return state === 'finished' || state === 'errored' || state === 'canceled';
|
|
1170
|
-
}); // print progress
|
|
1171
|
-
ended.filter(function (_ref10) {
|
|
1172
|
-
var _id = _ref10._id,
|
|
1173
|
-
state = _ref10.state;
|
|
1174
|
-
return !seen[_id] && state !== 'canceled';
|
|
1175
|
-
}).forEach(function (_ref11) {
|
|
1176
|
-
var _id = _ref11._id,
|
|
1177
|
-
startedAt = _ref11.startedAt,
|
|
1178
|
-
finishedAt = _ref11.finishedAt,
|
|
1179
|
-
state = _ref11.state;
|
|
1180
|
-
seen[_id] = true;
|
|
1181
|
-
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"));
|
|
1182
|
-
});
|
|
1183
|
-
if (!(ended.length < protectionIds.length)) {
|
|
1184
|
-
_context14.next = 14;
|
|
1185
|
-
break;
|
|
1186
|
-
}
|
|
1187
|
-
_context14.next = 13;
|
|
1188
|
-
return new Promise(function (resolve) {
|
|
1189
|
-
return setTimeout(resolve, getPollingInterval(start));
|
|
1190
|
-
});
|
|
1191
|
-
case 13:
|
|
1192
|
-
return _context14.abrupt("return", poll());
|
|
1193
|
-
case 14:
|
|
1194
|
-
return _context14.abrupt("return", applicationProtections.data.applicationProtections);
|
|
1195
|
-
case 15:
|
|
1196
|
-
case "end":
|
|
1197
|
-
return _context14.stop();
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
}, _callee14);
|
|
1201
|
-
}));
|
|
1202
|
-
return function poll() {
|
|
1203
|
-
return _ref8.apply(this, arguments);
|
|
1204
|
-
};
|
|
1205
|
-
}();
|
|
1206
|
-
return _context15.abrupt("return", poll());
|
|
1207
|
-
case 9:
|
|
1208
|
-
case "end":
|
|
1209
|
-
return _context15.stop();
|
|
1210
|
-
}
|
|
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();
|
|
1211
852
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
853
|
+
return applicationProtections.data.applicationProtections;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
return poll();
|
|
1214
857
|
},
|
|
1215
858
|
//
|
|
1216
|
-
|
|
1217
|
-
return
|
|
1218
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1219
|
-
while (1) {
|
|
1220
|
-
switch (_context16.prev = _context16.next) {
|
|
1221
|
-
case 0:
|
|
1222
|
-
return _context16.abrupt("return", client.post('/application', mutations.createApplication(data, fragments)));
|
|
1223
|
-
case 1:
|
|
1224
|
-
case "end":
|
|
1225
|
-
return _context16.stop();
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
}, _callee16);
|
|
1229
|
-
}))();
|
|
859
|
+
async createApplication(client, data, fragments) {
|
|
860
|
+
return client.post('/application', mutations.createApplication(data, fragments));
|
|
1230
861
|
},
|
|
1231
862
|
//
|
|
1232
|
-
|
|
1233
|
-
return
|
|
1234
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1235
|
-
while (1) {
|
|
1236
|
-
switch (_context17.prev = _context17.next) {
|
|
1237
|
-
case 0:
|
|
1238
|
-
return _context17.abrupt("return", client.post('/application', mutations.duplicateApplication(data, fragments)));
|
|
1239
|
-
case 1:
|
|
1240
|
-
case "end":
|
|
1241
|
-
return _context17.stop();
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}, _callee17);
|
|
1245
|
-
}))();
|
|
863
|
+
async duplicateApplication(client, data, fragments) {
|
|
864
|
+
return client.post('/application', mutations.duplicateApplication(data, fragments));
|
|
1246
865
|
},
|
|
1247
866
|
//
|
|
1248
|
-
|
|
1249
|
-
return
|
|
1250
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1251
|
-
while (1) {
|
|
1252
|
-
switch (_context18.prev = _context18.next) {
|
|
1253
|
-
case 0:
|
|
1254
|
-
return _context18.abrupt("return", client.post('/application', mutations.removeApplication(id)));
|
|
1255
|
-
case 1:
|
|
1256
|
-
case "end":
|
|
1257
|
-
return _context18.stop();
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
}, _callee18);
|
|
1261
|
-
}))();
|
|
867
|
+
async removeApplication(client, id) {
|
|
868
|
+
return client.post('/application', mutations.removeApplication(id));
|
|
1262
869
|
},
|
|
1263
870
|
//
|
|
1264
|
-
|
|
1265
|
-
return
|
|
1266
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1267
|
-
while (1) {
|
|
1268
|
-
switch (_context19.prev = _context19.next) {
|
|
1269
|
-
case 0:
|
|
1270
|
-
return _context19.abrupt("return", client.post('/application', mutations.removeProtection(id, appId, fragments)));
|
|
1271
|
-
case 1:
|
|
1272
|
-
case "end":
|
|
1273
|
-
return _context19.stop();
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
}, _callee19);
|
|
1277
|
-
}))();
|
|
871
|
+
async removeProtection(client, id, appId, fragments) {
|
|
872
|
+
return client.post('/application', mutations.removeProtection(id, appId, fragments));
|
|
1278
873
|
},
|
|
1279
874
|
//
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1284
|
-
while (1) {
|
|
1285
|
-
switch (_context20.prev = _context20.next) {
|
|
1286
|
-
case 0:
|
|
1287
|
-
_context20.next = 2;
|
|
1288
|
-
return mutations.cancelProtection(id, appId, fragments);
|
|
1289
|
-
case 2:
|
|
1290
|
-
mutation = _context20.sent;
|
|
1291
|
-
return _context20.abrupt("return", client.post('/application', mutation));
|
|
1292
|
-
case 4:
|
|
1293
|
-
case "end":
|
|
1294
|
-
return _context20.stop();
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
}, _callee20);
|
|
1298
|
-
}))();
|
|
875
|
+
async cancelProtection(client, id, appId, fragments) {
|
|
876
|
+
const mutation = await mutations.cancelProtection(id, appId, fragments);
|
|
877
|
+
return client.post('/application', mutation);
|
|
1299
878
|
},
|
|
1300
879
|
//
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1305
|
-
while (1) {
|
|
1306
|
-
switch (_context21.prev = _context21.next) {
|
|
1307
|
-
case 0:
|
|
1308
|
-
_context21.next = 2;
|
|
1309
|
-
return mutations.updateApplication(applicationData, fragments, applicationId);
|
|
1310
|
-
case 2:
|
|
1311
|
-
mutation = _context21.sent;
|
|
1312
|
-
return _context21.abrupt("return", client.post('/application', mutation));
|
|
1313
|
-
case 4:
|
|
1314
|
-
case "end":
|
|
1315
|
-
return _context21.stop();
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
}, _callee21);
|
|
1319
|
-
}))();
|
|
880
|
+
async updateApplication(client, applicationData, fragments, applicationId) {
|
|
881
|
+
const mutation = await mutations.updateApplication(applicationData, fragments, applicationId);
|
|
882
|
+
return client.post('/application', mutation);
|
|
1320
883
|
},
|
|
1321
884
|
//
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1326
|
-
while (1) {
|
|
1327
|
-
switch (_context22.prev = _context22.next) {
|
|
1328
|
-
case 0:
|
|
1329
|
-
_context22.next = 2;
|
|
1330
|
-
return mutations.unlockApplication(application, fragments);
|
|
1331
|
-
case 2:
|
|
1332
|
-
mutation = _context22.sent;
|
|
1333
|
-
return _context22.abrupt("return", client.post('/application', mutation));
|
|
1334
|
-
case 4:
|
|
1335
|
-
case "end":
|
|
1336
|
-
return _context22.stop();
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
}, _callee22);
|
|
1340
|
-
}))();
|
|
885
|
+
async unlockApplication(client, application, fragments) {
|
|
886
|
+
const mutation = await mutations.unlockApplication(application, fragments);
|
|
887
|
+
return client.post('/application', mutation);
|
|
1341
888
|
},
|
|
1342
889
|
//
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1347
|
-
while (1) {
|
|
1348
|
-
switch (_context23.prev = _context23.next) {
|
|
1349
|
-
case 0:
|
|
1350
|
-
_context23.next = 2;
|
|
1351
|
-
return queries.getApplication(applicationId, fragments, params);
|
|
1352
|
-
case 2:
|
|
1353
|
-
query = _context23.sent;
|
|
1354
|
-
return _context23.abrupt("return", client.get('/application', query));
|
|
1355
|
-
case 4:
|
|
1356
|
-
case "end":
|
|
1357
|
-
return _context23.stop();
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
}, _callee23);
|
|
1361
|
-
}))();
|
|
890
|
+
async getApplication(client, applicationId, fragments, params) {
|
|
891
|
+
const query = await queries.getApplication(applicationId, fragments, params);
|
|
892
|
+
return client.get('/application', query);
|
|
1362
893
|
},
|
|
1363
894
|
//
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1368
|
-
while (1) {
|
|
1369
|
-
switch (_context24.prev = _context24.next) {
|
|
1370
|
-
case 0:
|
|
1371
|
-
_context24.next = 2;
|
|
1372
|
-
return queries.getApplicationSource(sourceId, fragments, limits);
|
|
1373
|
-
case 2:
|
|
1374
|
-
query = _context24.sent;
|
|
1375
|
-
return _context24.abrupt("return", client.get('/application', query));
|
|
1376
|
-
case 4:
|
|
1377
|
-
case "end":
|
|
1378
|
-
return _context24.stop();
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
}, _callee24);
|
|
1382
|
-
}))();
|
|
895
|
+
async getApplicationSource(client, sourceId, fragments, limits) {
|
|
896
|
+
const query = await queries.getApplicationSource(sourceId, fragments, limits);
|
|
897
|
+
return client.get('/application', query);
|
|
1383
898
|
},
|
|
1384
899
|
//
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1389
|
-
while (1) {
|
|
1390
|
-
switch (_context25.prev = _context25.next) {
|
|
1391
|
-
case 0:
|
|
1392
|
-
query = queries.getApplicationProtections(applicationId, params, fragments, queryArgs);
|
|
1393
|
-
return _context25.abrupt("return", client.get('/application', query));
|
|
1394
|
-
case 2:
|
|
1395
|
-
case "end":
|
|
1396
|
-
return _context25.stop();
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}, _callee25);
|
|
1400
|
-
}))();
|
|
900
|
+
async getApplicationProtections(client, applicationId, params, fragments, queryArgs) {
|
|
901
|
+
const query = queries.getApplicationProtections(applicationId, params, fragments, queryArgs);
|
|
902
|
+
return client.get('/application', query);
|
|
1401
903
|
},
|
|
1402
904
|
//
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1407
|
-
while (1) {
|
|
1408
|
-
switch (_context26.prev = _context26.next) {
|
|
1409
|
-
case 0:
|
|
1410
|
-
_context26.next = 2;
|
|
1411
|
-
return queries.getApplicationProtectionsCount(applicationId, fragments);
|
|
1412
|
-
case 2:
|
|
1413
|
-
query = _context26.sent;
|
|
1414
|
-
return _context26.abrupt("return", client.get('/application', query));
|
|
1415
|
-
case 4:
|
|
1416
|
-
case "end":
|
|
1417
|
-
return _context26.stop();
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}, _callee26);
|
|
1421
|
-
}))();
|
|
905
|
+
async getApplicationProtectionsCount(client, applicationId, fragments) {
|
|
906
|
+
const query = await queries.getApplicationProtectionsCount(applicationId, fragments);
|
|
907
|
+
return client.get('/application', query);
|
|
1422
908
|
},
|
|
1423
909
|
//
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1428
|
-
while (1) {
|
|
1429
|
-
switch (_context27.prev = _context27.next) {
|
|
1430
|
-
case 0:
|
|
1431
|
-
_context27.next = 2;
|
|
1432
|
-
return mutations.createTemplate(template, fragments);
|
|
1433
|
-
case 2:
|
|
1434
|
-
mutation = _context27.sent;
|
|
1435
|
-
return _context27.abrupt("return", client.post('/application', mutation));
|
|
1436
|
-
case 4:
|
|
1437
|
-
case "end":
|
|
1438
|
-
return _context27.stop();
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
}, _callee27);
|
|
1442
|
-
}))();
|
|
910
|
+
async createTemplate(client, template, fragments) {
|
|
911
|
+
const mutation = await mutations.createTemplate(template, fragments);
|
|
912
|
+
return client.post('/application', mutation);
|
|
1443
913
|
},
|
|
1444
914
|
//
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1449
|
-
while (1) {
|
|
1450
|
-
switch (_context28.prev = _context28.next) {
|
|
1451
|
-
case 0:
|
|
1452
|
-
_context28.next = 2;
|
|
1453
|
-
return mutations.removeTemplate(id);
|
|
1454
|
-
case 2:
|
|
1455
|
-
mutation = _context28.sent;
|
|
1456
|
-
return _context28.abrupt("return", client.post('/application', mutation));
|
|
1457
|
-
case 4:
|
|
1458
|
-
case "end":
|
|
1459
|
-
return _context28.stop();
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
}, _callee28);
|
|
1463
|
-
}))();
|
|
915
|
+
async removeTemplate(client, id) {
|
|
916
|
+
const mutation = await mutations.removeTemplate(id);
|
|
917
|
+
return client.post('/application', mutation);
|
|
1464
918
|
},
|
|
1465
919
|
//
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1470
|
-
while (1) {
|
|
1471
|
-
switch (_context29.prev = _context29.next) {
|
|
1472
|
-
case 0:
|
|
1473
|
-
_context29.next = 2;
|
|
1474
|
-
return queries.getTemplates(fragments);
|
|
1475
|
-
case 2:
|
|
1476
|
-
query = _context29.sent;
|
|
1477
|
-
return _context29.abrupt("return", client.get('/application', query));
|
|
1478
|
-
case 4:
|
|
1479
|
-
case "end":
|
|
1480
|
-
return _context29.stop();
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
}, _callee29);
|
|
1484
|
-
}))();
|
|
920
|
+
async getTemplates(client, fragments) {
|
|
921
|
+
const query = await queries.getTemplates(fragments);
|
|
922
|
+
return client.get('/application', query);
|
|
1485
923
|
},
|
|
1486
924
|
//
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
1491
|
-
while (1) {
|
|
1492
|
-
switch (_context30.prev = _context30.next) {
|
|
1493
|
-
case 0:
|
|
1494
|
-
_context30.next = 2;
|
|
1495
|
-
return queries.getApplications(fragments, params);
|
|
1496
|
-
case 2:
|
|
1497
|
-
query = _context30.sent;
|
|
1498
|
-
return _context30.abrupt("return", client.get('/application', query));
|
|
1499
|
-
case 4:
|
|
1500
|
-
case "end":
|
|
1501
|
-
return _context30.stop();
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}, _callee30);
|
|
1505
|
-
}))();
|
|
925
|
+
async getApplications(client, fragments, params) {
|
|
926
|
+
const query = await queries.getApplications(fragments, params);
|
|
927
|
+
return client.get('/application', query);
|
|
1506
928
|
},
|
|
1507
929
|
//
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
return
|
|
1511
|
-
var mutation;
|
|
1512
|
-
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
1513
|
-
while (1) {
|
|
1514
|
-
switch (_context31.prev = _context31.next) {
|
|
1515
|
-
case 0:
|
|
1516
|
-
_context31.next = 2;
|
|
1517
|
-
return mutations.addApplicationSource(applicationId, applicationSource, fragments);
|
|
1518
|
-
case 2:
|
|
1519
|
-
mutation = _context31.sent;
|
|
1520
|
-
return _context31.abrupt("return", _this10.withRetries(function () {
|
|
1521
|
-
return client.post('/application', mutation);
|
|
1522
|
-
}));
|
|
1523
|
-
case 4:
|
|
1524
|
-
case "end":
|
|
1525
|
-
return _context31.stop();
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
}, _callee31);
|
|
1529
|
-
}))();
|
|
930
|
+
async addApplicationSource(client, applicationId, applicationSource, fragments) {
|
|
931
|
+
const mutation = await mutations.addApplicationSource(applicationId, applicationSource, fragments);
|
|
932
|
+
return this.withRetries(() => client.post('/application', mutation));
|
|
1530
933
|
},
|
|
1531
934
|
//
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
while (1) {
|
|
1537
|
-
switch (_context32.prev = _context32.next) {
|
|
1538
|
-
case 0:
|
|
1539
|
-
_context32.next = 2;
|
|
1540
|
-
return getFileFromUrl(client, url);
|
|
1541
|
-
case 2:
|
|
1542
|
-
file = _context32.sent;
|
|
1543
|
-
_context32.next = 5;
|
|
1544
|
-
return mutations.addApplicationSource(applicationId, file, fragments);
|
|
1545
|
-
case 5:
|
|
1546
|
-
mutation = _context32.sent;
|
|
1547
|
-
return _context32.abrupt("return", client.post('/application', mutation));
|
|
1548
|
-
case 7:
|
|
1549
|
-
case "end":
|
|
1550
|
-
return _context32.stop();
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}, _callee32);
|
|
1554
|
-
}))();
|
|
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);
|
|
1555
939
|
},
|
|
1556
940
|
//
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
1561
|
-
while (1) {
|
|
1562
|
-
switch (_context33.prev = _context33.next) {
|
|
1563
|
-
case 0:
|
|
1564
|
-
_context33.next = 2;
|
|
1565
|
-
return mutations.updateApplicationSource(applicationSource, fragments);
|
|
1566
|
-
case 2:
|
|
1567
|
-
mutation = _context33.sent;
|
|
1568
|
-
return _context33.abrupt("return", client.post('/application', mutation));
|
|
1569
|
-
case 4:
|
|
1570
|
-
case "end":
|
|
1571
|
-
return _context33.stop();
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
}, _callee33);
|
|
1575
|
-
}))();
|
|
941
|
+
async updateApplicationSource(client, applicationSource, fragments) {
|
|
942
|
+
const mutation = await mutations.updateApplicationSource(applicationSource, fragments);
|
|
943
|
+
return client.post('/application', mutation);
|
|
1576
944
|
},
|
|
1577
945
|
//
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
return
|
|
1581
|
-
var mutation;
|
|
1582
|
-
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
1583
|
-
while (1) {
|
|
1584
|
-
switch (_context34.prev = _context34.next) {
|
|
1585
|
-
case 0:
|
|
1586
|
-
_context34.next = 2;
|
|
1587
|
-
return mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
|
|
1588
|
-
case 2:
|
|
1589
|
-
mutation = _context34.sent;
|
|
1590
|
-
return _context34.abrupt("return", _this11.withRetries(function () {
|
|
1591
|
-
return client.post('/application', mutation);
|
|
1592
|
-
}));
|
|
1593
|
-
case 4:
|
|
1594
|
-
case "end":
|
|
1595
|
-
return _context34.stop();
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
}, _callee34);
|
|
1599
|
-
}))();
|
|
946
|
+
async removeSourceFromApplication(client, sourceId, applicationId, fragments) {
|
|
947
|
+
const mutation = await mutations.removeSourceFromApplication(sourceId, applicationId, fragments);
|
|
948
|
+
return this.withRetries(() => client.post('/application', mutation));
|
|
1600
949
|
},
|
|
1601
950
|
//
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
1606
|
-
while (1) {
|
|
1607
|
-
switch (_context35.prev = _context35.next) {
|
|
1608
|
-
case 0:
|
|
1609
|
-
_context35.next = 2;
|
|
1610
|
-
return mutations.applyTemplate(templateId, appId, fragments);
|
|
1611
|
-
case 2:
|
|
1612
|
-
mutation = _context35.sent;
|
|
1613
|
-
return _context35.abrupt("return", client.post('/application', mutation));
|
|
1614
|
-
case 4:
|
|
1615
|
-
case "end":
|
|
1616
|
-
return _context35.stop();
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
}, _callee35);
|
|
1620
|
-
}))();
|
|
951
|
+
async applyTemplate(client, templateId, appId, fragments) {
|
|
952
|
+
const mutation = await mutations.applyTemplate(templateId, appId, fragments);
|
|
953
|
+
return client.post('/application', mutation);
|
|
1621
954
|
},
|
|
1622
955
|
//
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
1627
|
-
while (1) {
|
|
1628
|
-
switch (_context36.prev = _context36.next) {
|
|
1629
|
-
case 0:
|
|
1630
|
-
_context36.next = 2;
|
|
1631
|
-
return mutations.updateTemplate(template, fragments);
|
|
1632
|
-
case 2:
|
|
1633
|
-
mutation = _context36.sent;
|
|
1634
|
-
return _context36.abrupt("return", client.post('/application', mutation));
|
|
1635
|
-
case 4:
|
|
1636
|
-
case "end":
|
|
1637
|
-
return _context36.stop();
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
}, _callee36);
|
|
1641
|
-
}))();
|
|
956
|
+
async updateTemplate(client, template, fragments) {
|
|
957
|
+
const mutation = await mutations.updateTemplate(template, fragments);
|
|
958
|
+
return client.post('/application', mutation);
|
|
1642
959
|
},
|
|
1643
|
-
|
|
1644
|
-
return
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
switch (_context37.prev = _context37.next) {
|
|
1648
|
-
case 0:
|
|
1649
|
-
return _context37.abrupt("return", client.get('/profiling-run', {
|
|
1650
|
-
applicationId: applicationId
|
|
1651
|
-
}));
|
|
1652
|
-
case 1:
|
|
1653
|
-
case "end":
|
|
1654
|
-
return _context37.stop();
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
}, _callee37);
|
|
1658
|
-
}))();
|
|
960
|
+
async getApplicationProfiling(client, applicationId) {
|
|
961
|
+
return client.get('/profiling-run', {
|
|
962
|
+
applicationId
|
|
963
|
+
});
|
|
1659
964
|
},
|
|
1660
|
-
|
|
1661
|
-
return
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
switch (_context38.prev = _context38.next) {
|
|
1665
|
-
case 0:
|
|
1666
|
-
return _context38.abrupt("return", client.patch("/profiling-run/".concat(profilingId), {
|
|
1667
|
-
state: 'DELETED'
|
|
1668
|
-
}));
|
|
1669
|
-
case 1:
|
|
1670
|
-
case "end":
|
|
1671
|
-
return _context38.stop();
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
}, _callee38);
|
|
1675
|
-
}))();
|
|
965
|
+
async deleteProfiling(client, profilingId) {
|
|
966
|
+
return client.patch("/profiling-run/".concat(profilingId), {
|
|
967
|
+
state: 'DELETED'
|
|
968
|
+
});
|
|
1676
969
|
},
|
|
1677
970
|
/**
|
|
1678
971
|
* Starts a new instrumentation process.
|
|
@@ -1681,63 +974,24 @@ var _default = {
|
|
|
1681
974
|
* @param applicationId
|
|
1682
975
|
* @returns {Promise<*>}
|
|
1683
976
|
*/
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
if (e.statusCode !== 404) throw e;
|
|
1695
|
-
});
|
|
1696
|
-
case 2:
|
|
1697
|
-
instrumentation = _context39.sent;
|
|
1698
|
-
if (!instrumentation) {
|
|
1699
|
-
_context39.next = 6;
|
|
1700
|
-
break;
|
|
1701
|
-
}
|
|
1702
|
-
_context39.next = 6;
|
|
1703
|
-
return _this12.deleteProfiling(client, instrumentation.data.id);
|
|
1704
|
-
case 6:
|
|
1705
|
-
return _context39.abrupt("return", client.post('/profiling-run', {
|
|
1706
|
-
applicationId: applicationId
|
|
1707
|
-
}));
|
|
1708
|
-
case 7:
|
|
1709
|
-
case "end":
|
|
1710
|
-
return _context39.stop();
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
}, _callee39);
|
|
1714
|
-
}))();
|
|
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
|
+
});
|
|
1715
987
|
},
|
|
1716
988
|
//
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
case 0:
|
|
1724
|
-
_context40.next = 2;
|
|
1725
|
-
return introspection.mutation(client, 'createApplicationProtection');
|
|
1726
|
-
case 2:
|
|
1727
|
-
_yield$introspection$ = _context40.sent;
|
|
1728
|
-
args = _yield$introspection$.args;
|
|
1729
|
-
_context40.next = 6;
|
|
1730
|
-
return mutations.createApplicationProtection(applicationId, fragments, protectionOptions, args);
|
|
1731
|
-
case 6:
|
|
1732
|
-
mutation = _context40.sent;
|
|
1733
|
-
return _context40.abrupt("return", client.post('/application', mutation));
|
|
1734
|
-
case 8:
|
|
1735
|
-
case "end":
|
|
1736
|
-
return _context40.stop();
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
}, _callee40);
|
|
1740
|
-
}))();
|
|
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);
|
|
1741
995
|
},
|
|
1742
996
|
/**
|
|
1743
997
|
* Create one or more application protections at once
|
|
@@ -1748,155 +1002,61 @@ var _default = {
|
|
|
1748
1002
|
* @param {object} fragments
|
|
1749
1003
|
* @returns {Promise<{data: {protections: Array.<{_id}>}, errors: Array}>}
|
|
1750
1004
|
*/
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
case 7:
|
|
1776
|
-
_context41.next = 9;
|
|
1777
|
-
return introspection.mutation(client, 'createApplicationProtections');
|
|
1778
|
-
case 9:
|
|
1779
|
-
mutationType = _context41.sent;
|
|
1780
|
-
if (!mutationType) {
|
|
1781
|
-
console.error("\"Create multiple protections at once\" it's only available on Jscrambler version 7.2 and above.");
|
|
1782
|
-
process.exit(1);
|
|
1783
|
-
}
|
|
1784
|
-
_context41.next = 13;
|
|
1785
|
-
return mutations.createApplicationProtections(applicationId, fragments, protectionOptions, mutationType.args);
|
|
1786
|
-
case 13:
|
|
1787
|
-
mutation = _context41.sent;
|
|
1788
|
-
_context41.next = 16;
|
|
1789
|
-
return client.post('/application', mutation);
|
|
1790
|
-
case 16:
|
|
1791
|
-
result = _context41.sent;
|
|
1792
|
-
if (result.data && result.data.createApplicationProtections) {
|
|
1793
|
-
result.data.protections = result.data.createApplicationProtections.protections;
|
|
1794
|
-
delete result.data.createApplicationProtections;
|
|
1795
|
-
}
|
|
1796
|
-
case 18:
|
|
1797
|
-
return _context41.abrupt("return", result);
|
|
1798
|
-
case 19:
|
|
1799
|
-
case "end":
|
|
1800
|
-
return _context41.stop();
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
}, _callee41);
|
|
1804
|
-
}))();
|
|
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;
|
|
1805
1029
|
},
|
|
1806
1030
|
/**
|
|
1807
1031
|
* @param {object} client
|
|
1808
1032
|
* @param {string} instrumentationId
|
|
1809
1033
|
* @returns {Promise<object>}
|
|
1810
1034
|
*/
|
|
1811
|
-
|
|
1812
|
-
return
|
|
1813
|
-
return _regeneratorRuntime().wrap(function _callee42$(_context42) {
|
|
1814
|
-
while (1) {
|
|
1815
|
-
switch (_context42.prev = _context42.next) {
|
|
1816
|
-
case 0:
|
|
1817
|
-
return _context42.abrupt("return", client.get("/profiling-run/".concat(instrumentationId)));
|
|
1818
|
-
case 1:
|
|
1819
|
-
case "end":
|
|
1820
|
-
return _context42.stop();
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
}, _callee42);
|
|
1824
|
-
}))();
|
|
1035
|
+
async getInstrumentation(client, instrumentationId) {
|
|
1036
|
+
return client.get("/profiling-run/".concat(instrumentationId));
|
|
1825
1037
|
},
|
|
1826
1038
|
//
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
return _regeneratorRuntime().wrap(function _callee43$(_context43) {
|
|
1831
|
-
while (1) {
|
|
1832
|
-
switch (_context43.prev = _context43.next) {
|
|
1833
|
-
case 0:
|
|
1834
|
-
_context43.next = 2;
|
|
1835
|
-
return queries.getProtection(applicationId, protectionId, fragments);
|
|
1836
|
-
case 2:
|
|
1837
|
-
query = _context43.sent;
|
|
1838
|
-
return _context43.abrupt("return", client.get('/application', query));
|
|
1839
|
-
case 4:
|
|
1840
|
-
case "end":
|
|
1841
|
-
return _context43.stop();
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
}, _callee43);
|
|
1845
|
-
}))();
|
|
1039
|
+
async getApplicationProtection(client, applicationId, protectionId, fragments) {
|
|
1040
|
+
const query = await queries.getProtection(applicationId, protectionId, fragments);
|
|
1041
|
+
return client.get('/application', query);
|
|
1846
1042
|
},
|
|
1847
1043
|
//
|
|
1848
|
-
|
|
1849
|
-
return
|
|
1850
|
-
return _regeneratorRuntime().wrap(function _callee44$(_context44) {
|
|
1851
|
-
while (1) {
|
|
1852
|
-
switch (_context44.prev = _context44.next) {
|
|
1853
|
-
case 0:
|
|
1854
|
-
return _context44.abrupt("return", client.get("/application/sourceMaps/".concat(protectionId), null, false));
|
|
1855
|
-
case 1:
|
|
1856
|
-
case "end":
|
|
1857
|
-
return _context44.stop();
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
}, _callee44);
|
|
1861
|
-
}))();
|
|
1044
|
+
async downloadSourceMapsRequest(client, protectionId) {
|
|
1045
|
+
return client.get("/application/sourceMaps/".concat(protectionId), null, false);
|
|
1862
1046
|
},
|
|
1863
|
-
|
|
1864
|
-
return
|
|
1865
|
-
return _regeneratorRuntime().wrap(function _callee45$(_context45) {
|
|
1866
|
-
while (1) {
|
|
1867
|
-
switch (_context45.prev = _context45.next) {
|
|
1868
|
-
case 0:
|
|
1869
|
-
return _context45.abrupt("return", client.get("/application/symbolTable/".concat(protectionId), null, false));
|
|
1870
|
-
case 1:
|
|
1871
|
-
case "end":
|
|
1872
|
-
return _context45.stop();
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
}, _callee45);
|
|
1876
|
-
}))();
|
|
1047
|
+
async downloadSymbolTableRequest(client, protectionId) {
|
|
1048
|
+
return client.get("/application/symbolTable/".concat(protectionId), null, false);
|
|
1877
1049
|
},
|
|
1878
1050
|
//
|
|
1879
|
-
|
|
1880
|
-
return
|
|
1881
|
-
return _regeneratorRuntime().wrap(function _callee46$(_context46) {
|
|
1882
|
-
while (1) {
|
|
1883
|
-
switch (_context46.prev = _context46.next) {
|
|
1884
|
-
case 0:
|
|
1885
|
-
return _context46.abrupt("return", client.get("/application/download/".concat(protectionId), null, false));
|
|
1886
|
-
case 1:
|
|
1887
|
-
case "end":
|
|
1888
|
-
return _context46.stop();
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
}, _callee46);
|
|
1892
|
-
}))();
|
|
1051
|
+
async downloadApplicationProtection(client, protectionId) {
|
|
1052
|
+
return client.get("/application/download/".concat(protectionId), null, false);
|
|
1893
1053
|
},
|
|
1894
1054
|
/**
|
|
1895
1055
|
* @param {object} client
|
|
1896
1056
|
* @param {string} instrumentationId
|
|
1897
1057
|
* @returns {*}
|
|
1898
1058
|
*/
|
|
1899
|
-
downloadApplicationInstrumented
|
|
1059
|
+
downloadApplicationInstrumented(client, instrumentationId) {
|
|
1900
1060
|
return client.get("/profiling-run/".concat(instrumentationId, "/instrumented-bundle"), null, false);
|
|
1901
1061
|
},
|
|
1902
1062
|
/**
|
|
@@ -1907,50 +1067,23 @@ var _default = {
|
|
|
1907
1067
|
* @param {String} field args field to introspect
|
|
1908
1068
|
* @returns {Boolean} true if the field is supported, false otherwise
|
|
1909
1069
|
*/
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
return instrospectionType(client, methodName);
|
|
1922
|
-
case 4:
|
|
1923
|
-
result = _context47.sent;
|
|
1924
|
-
if (!(!result || !result.args)) {
|
|
1925
|
-
_context47.next = 8;
|
|
1926
|
-
break;
|
|
1927
|
-
}
|
|
1928
|
-
debug && console.log("Method *".concat(methodName, "* not found."));
|
|
1929
|
-
return _context47.abrupt("return", false);
|
|
1930
|
-
case 8:
|
|
1931
|
-
dataArg = result.args.find(function (arg) {
|
|
1932
|
-
return arg.name === 'data';
|
|
1933
|
-
});
|
|
1934
|
-
isFieldSupported = dataArg && dataArg.type.inputFields.some(function (e) {
|
|
1935
|
-
return e.name === field;
|
|
1936
|
-
});
|
|
1937
|
-
return _context47.abrupt("return", isFieldSupported);
|
|
1938
|
-
case 11:
|
|
1939
|
-
case "end":
|
|
1940
|
-
return _context47.stop();
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
}, _callee47);
|
|
1944
|
-
}))();
|
|
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;
|
|
1945
1081
|
}
|
|
1946
1082
|
};
|
|
1947
|
-
exports.default = _default;
|
|
1948
1083
|
function getFileFromUrl(client, url) {
|
|
1949
|
-
return _axios.default.get(url).then(
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
};
|
|
1955
|
-
});
|
|
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
|
+
}));
|
|
1956
1089
|
}
|